BuddyPress - Version 2.0.4

Version Description

See: http://codex.buddypress.org/releases/version-2-0-4/

Download this release

Release Info

Developer boonebgorges
Plugin Icon 128x128 BuddyPress
Version 2.0.4
Comparing to
See all releases

Code changes from version 2.4.0-rc1 to 2.0.4

Files changed (51) hide show
  1. .travis.yml +48 -0
  2. bp-activity/admin/css/admin-rtl.css +0 -87
  3. bp-activity/admin/css/admin-rtl.min.css +0 -1
  4. bp-activity/admin/css/admin.css +0 -7
  5. bp-activity/admin/css/admin.min.css +1 -1
  6. bp-activity/admin/js/admin.js +17 -20
  7. bp-activity/admin/js/admin.min.js +1 -2
  8. bp-activity/bp-activity-actions.php +91 -274
  9. bp-activity/bp-activity-admin.php +258 -523
  10. bp-activity/bp-activity-akismet.php +103 -162
  11. bp-activity/bp-activity-cache.php +10 -12
  12. bp-activity/bp-activity-classes.php +1675 -7
  13. bp-activity/bp-activity-cssjs.php +0 -75
  14. bp-activity/bp-activity-filters.php +73 -323
  15. bp-activity/bp-activity-functions.php +567 -1708
  16. bp-activity/bp-activity-loader.php +90 -115
  17. bp-activity/bp-activity-notifications.php +59 -219
  18. bp-activity/bp-activity-screens.php +64 -194
  19. bp-activity/bp-activity-template.php +847 -2007
  20. bp-activity/classes/class-bp-activity-activity.php +0 -1793
  21. bp-activity/classes/class-bp-activity-feed.php +0 -447
  22. bp-activity/classes/class-bp-activity-query.php +0 -246
  23. bp-activity/css/mentions-rtl.css +0 -93
  24. bp-activity/css/mentions-rtl.min.css +0 -1
  25. bp-activity/css/mentions.css +0 -93
  26. bp-activity/css/mentions.min.css +0 -1
  27. bp-activity/js/mentions.js +0 -255
  28. bp-activity/js/mentions.min.js +0 -2
  29. bp-blogs/bp-blogs-actions.php +3 -2
  30. bp-blogs/bp-blogs-activity.php +107 -305
  31. bp-blogs/bp-blogs-buddybar.php +78 -0
  32. bp-blogs/bp-blogs-cache.php +23 -14
  33. bp-blogs/bp-blogs-classes.php +518 -3
  34. bp-blogs/bp-blogs-filters.php +5 -93
  35. bp-blogs/bp-blogs-functions.php +298 -523
  36. bp-blogs/bp-blogs-loader.php +42 -143
  37. bp-blogs/bp-blogs-screens.php +28 -60
  38. bp-blogs/bp-blogs-template.php +251 -645
  39. bp-blogs/bp-blogs-widgets.php +34 -63
  40. bp-blogs/classes/class-bp-blogs-blog.php +0 -619
  41. bp-core/admin/{bp-core-admin-actions.php → bp-core-actions.php} +36 -98
  42. bp-core/admin/{bp-core-admin-components.php → bp-core-components.php} +25 -45
  43. bp-core/admin/{bp-core-admin-functions.php → bp-core-functions.php} +146 -214
  44. bp-core/admin/{bp-core-admin-schema.php → bp-core-schema.php} +134 -244
  45. bp-core/admin/{bp-core-admin-settings.php → bp-core-settings.php} +91 -117
  46. bp-core/admin/{bp-core-admin-slugs.php → bp-core-slugs.php} +19 -41
  47. bp-core/admin/{bp-core-admin-tools.php → bp-core-tools.php} +22 -87
  48. bp-core/admin/css/common-rtl.css +0 -258
  49. bp-core/admin/css/common-rtl.min.css +0 -1
  50. bp-core/admin/css/common.css +290 -115
  51. bp-core/admin/css/common.min.css +1 -1
.travis.yml ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ language: php
2
+
3
+ php:
4
+ - 5.2
5
+ - 5.3
6
+ - 5.4
7
+ - 5.5
8
+
9
+ env:
10
+ - WP_VERSION=trunk WP_MULTISITE=0
11
+ - WP_VERSION=tags/3.8.1 WP_MULTISITE=0
12
+ - WP_VERSION=tags/3.7.1 WP_MULTISITE=0
13
+ - WP_VERSION=trunk WP_MULTISITE=1
14
+ - WP_VERSION=tags/3.8.1 WP_MULTISITE=1
15
+ - WP_VERSION=tags/3.7.1 WP_MULTISITE=1
16
+
17
+ before_script:
18
+ # set up WP install
19
+ - WP_CORE_DIR=/tmp/wordpress/
20
+ - mkdir -p $WP_CORE_DIR
21
+ - svn co --ignore-externals https://develop.svn.wordpress.org/$WP_VERSION $WP_CORE_DIR
22
+ - plugin_slug=$(basename $(pwd))
23
+ - plugin_dir=$WP_CORE_DIR/src/wp-content/plugins/$plugin_slug
24
+ - cd ..
25
+ - mv $plugin_slug $plugin_dir
26
+ # set up tests config
27
+ - cd $WP_CORE_DIR
28
+ - cp wp-tests-config-sample.php wp-tests-config.php
29
+ - sed -i "s/youremptytestdbnamehere/wordpress_test/" wp-tests-config.php
30
+ - sed -i "s/yourusernamehere/root/" wp-tests-config.php
31
+ - sed -i "s/yourpasswordhere//" wp-tests-config.php
32
+ # disable WP_DEBUG for PHP 5.5 due to ext/mysqli E_DEPRECATED errors
33
+ - if [[ "$TRAVIS_PHP_VERSION" == 5.5* ]] ; then sed -i "s:define( 'WP_DEBUG://define( 'WP_DEBUG:" wp-tests-config.php; fi;
34
+ # set up database
35
+ - mysql -e 'CREATE DATABASE wordpress_test;' -uroot
36
+ # prepare for running the tests
37
+ - cd $plugin_dir/tests
38
+
39
+ script: phpunit
40
+
41
+ notifications:
42
+ email: false
43
+
44
+ irc:
45
+ channels:
46
+ - "irc.freenode.net#buddypress-dev"
47
+ template:
48
+ - "Build %{build_number} (%{branch} - %{commit}): %{message} %{build_url}"
bp-activity/admin/css/admin-rtl.css DELETED
@@ -1,87 +0,0 @@
1
- .akismet-status {
2
- float: left;
3
- }
4
- .akismet-status a {
5
- color: #AAA;
6
- font-style: italic;
7
- }
8
- .akismet-history {
9
- margin: 13px;
10
- }
11
- .akismet-history div {
12
- margin-bottom: 13px;
13
- }
14
- .akismet-history span {
15
- color: #999;
16
- }
17
-
18
- #wp-bp-activities-wrap {
19
- padding: 5px 0;
20
- }
21
- #bp-activities {
22
- height: 120px;
23
- }
24
- #bp-replyhead {
25
- font-size: 1em;
26
- line-height: 1.4em;
27
- margin: 0;
28
- }
29
- #bp-replysubmit {
30
- margin: 0;
31
- padding: 0 0 3px;
32
- text-align: center;
33
- }
34
- #bp-replysubmit .error {
35
- color: red;
36
- line-height: 21px;
37
- text-align: center;
38
- vertical-align: center;
39
- }
40
- #bp-replysubmit img.waiting {
41
- float: left;
42
- padding: 4px 10px 0;
43
- vertical-align: top;
44
- }
45
- #bp-activities-form .column-response img {
46
- float: right;
47
- margin-bottom: 5px;
48
- margin-left: 10px;
49
- margin-top: 1px;
50
- }
51
- .activity-errors {
52
- list-style-type: disc;
53
- margin-right: 2em;
54
- }
55
-
56
- #bp_activity_action div.inside,
57
- #bp_activity_content div.inside {
58
- line-height: 0;
59
- }
60
- #bp_activity_action h3,
61
- #bp_activity_content h3 {
62
- cursor: auto;
63
- }
64
- #bp_activity_action td.mceIframeContainer,
65
- #bp_activity_content td.mceIframeContainer {
66
- background-color: white;
67
- }
68
- #post-body #bp-activities-action_resize,
69
- #post-body #bp-activities-content_resize {
70
- position: inherit;
71
- margin-top: -2px;
72
- }
73
- #bp_activity_link input {
74
- width: 99%;
75
- }
76
- #bp-activities-primaryid {
77
- margin-bottom: 1em;
78
- }
79
- .column-action {
80
- width: 12%;
81
- }
82
-
83
- @media screen and (max-width: 782px) {
84
- body.toplevel_page_bp-activity .wp-list-table tr:not(.inline-edit-row):not(.no-items) td:not(.check-column) {
85
- display: table-cell;
86
- }
87
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-activity/admin/css/admin-rtl.min.css DELETED
@@ -1 +0,0 @@
1
- .akismet-status{float:left}.akismet-status a{color:#AAA;font-style:italic}.akismet-history{margin:13px}.akismet-history div{margin-bottom:13px}.akismet-history span{color:#999}#wp-bp-activities-wrap{padding:5px 0}#bp-activities{height:120px}#bp-replyhead{font-size:1em;line-height:1.4em;margin:0}#bp-replysubmit{margin:0;padding:0 0 3px;text-align:center}#bp-replysubmit .error{color:red;line-height:21px;text-align:center;vertical-align:center}#bp-replysubmit img.waiting{float:left;padding:4px 10px 0;vertical-align:top}#bp-activities-form .column-response img{float:right;margin-bottom:5px;margin-left:10px;margin-top:1px}.activity-errors{list-style-type:disc;margin-right:2em}#bp_activity_action div.inside,#bp_activity_content div.inside{line-height:0}#bp_activity_action h3,#bp_activity_content h3{cursor:auto}#bp_activity_action td.mceIframeContainer,#bp_activity_content td.mceIframeContainer{background-color:#fff}#post-body #bp-activities-action_resize,#post-body #bp-activities-content_resize{position:inherit;margin-top:-2px}#bp_activity_link input{width:99%}#bp-activities-primaryid{margin-bottom:1em}.column-action{width:12%}@media screen and (max-width:782px){body.toplevel_page_bp-activity .wp-list-table tr:not(.inline-edit-row):not(.no-items) td:not(.check-column){display:table-cell}}
 
bp-activity/admin/css/admin.css CHANGED
@@ -44,7 +44,6 @@
44
  }
45
  #bp-activities-form .column-response img {
46
  float: left;
47
- margin-bottom: 5px;
48
  margin-right: 10px;
49
  margin-top: 1px;
50
  }
@@ -78,10 +77,4 @@
78
  }
79
  .column-action {
80
  width: 12%;
81
- }
82
-
83
- @media screen and (max-width: 782px) {
84
- body.toplevel_page_bp-activity .wp-list-table tr:not(.inline-edit-row):not(.no-items) td:not(.check-column) {
85
- display: table-cell;
86
- }
87
  }
44
  }
45
  #bp-activities-form .column-response img {
46
  float: left;
 
47
  margin-right: 10px;
48
  margin-top: 1px;
49
  }
77
  }
78
  .column-action {
79
  width: 12%;
 
 
 
 
 
 
80
  }
bp-activity/admin/css/admin.min.css CHANGED
@@ -1 +1 @@
1
- .akismet-status{float:right}.akismet-status a{color:#AAA;font-style:italic}.akismet-history{margin:13px}.akismet-history div{margin-bottom:13px}.akismet-history span{color:#999}#wp-bp-activities-wrap{padding:5px 0}#bp-activities{height:120px}#bp-replyhead{font-size:1em;line-height:1.4em;margin:0}#bp-replysubmit{margin:0;padding:0 0 3px;text-align:center}#bp-replysubmit .error{color:red;line-height:21px;text-align:center;vertical-align:center}#bp-replysubmit img.waiting{float:right;padding:4px 10px 0;vertical-align:top}#bp-activities-form .column-response img{float:left;margin-bottom:5px;margin-right:10px;margin-top:1px}.activity-errors{list-style-type:disc;margin-left:2em}#bp_activity_action div.inside,#bp_activity_content div.inside{line-height:0}#bp_activity_action h3,#bp_activity_content h3{cursor:auto}#bp_activity_action td.mceIframeContainer,#bp_activity_content td.mceIframeContainer{background-color:#fff}#post-body #bp-activities-action_resize,#post-body #bp-activities-content_resize{position:inherit;margin-top:-2px}#bp_activity_link input{width:99%}#bp-activities-primaryid{margin-bottom:1em}.column-action{width:12%}@media screen and (max-width:782px){body.toplevel_page_bp-activity .wp-list-table tr:not(.inline-edit-row):not(.no-items) td:not(.check-column){display:table-cell}}
1
+ .akismet-status{float:right}.akismet-status a{color:#AAA;font-style:italic}.akismet-history{margin:13px}.akismet-history div{margin-bottom:13px}.akismet-history span{color:#999}#wp-bp-activities-wrap{padding:5px 0}#bp-activities{height:120px}#bp-replyhead{font-size:1em;line-height:1.4em;margin:0}#bp-replysubmit{margin:0;padding:0 0 3px;text-align:center}#bp-replysubmit .error{color:red;line-height:21px;text-align:center;vertical-align:center}#bp-replysubmit img.waiting{float:right;padding:4px 10px 0;vertical-align:top}#bp-activities-form .column-response img{float:left;margin-right:10px;margin-top:1px}.activity-errors{list-style-type:disc;margin-left:2em}#bp_activity_action div.inside,#bp_activity_content div.inside{line-height:0}#bp_activity_action h3,#bp_activity_content h3{cursor:auto}#bp_activity_action td.mceIframeContainer,#bp_activity_content td.mceIframeContainer{background-color:white}#post-body #bp-activities-action_resize,#post-body #bp-activities-content_resize{position:inherit;margin-top:-2px}#bp_activity_link input{width:99%}#bp-activities-primaryid{margin-bottom:1em}.column-action{width:12%}
bp-activity/admin/js/admin.js CHANGED
@@ -1,17 +1,16 @@
1
- /* global bp_activity_admin_vars, postboxes, wpAjax */
2
  (function( $ ) {
3
 
4
  /**
5
  * Activity reply object for the activity index screen
6
  *
7
- * @since 1.6.0
8
  */
9
  var activityReply = {
10
 
11
  /**
12
  * Attach event handler functions to the relevant elements.
13
  *
14
- * @since 1.6.0
15
  */
16
  init : function() {
17
  $(document).on( 'click', '.row-actions a.reply', activityReply.open );
@@ -20,7 +19,7 @@ var activityReply = {
20
 
21
  // Close textarea on escape
22
  $(document).on( 'keyup', '#bp-activities:visible', function( e ) {
23
- if ( 27 === e.which ) {
24
  activityReply.close();
25
  }
26
  });
@@ -29,9 +28,9 @@ var activityReply = {
29
  /**
30
  * Reveals the entire row when "reply" is pressed.
31
  *
32
- * @since 1.6.0
33
  */
34
- open : function() {
35
  // Hide the container row, and move it to the new location
36
  var box = $( '#bp-activities-container' ).hide();
37
  $( this ).parents( 'tr' ).after( box );
@@ -46,11 +45,11 @@ var activityReply = {
46
  /**
47
  * Hide and reset the entire row when "cancel", or escape, are pressed.
48
  *
49
- * @since 1.6.0
50
  */
51
- close : function() {
52
  // Hide the container row
53
- $('#bp-activities-container').fadeOut( '200', function () {
54
 
55
  // Empty and unfocus the text area
56
  $( '#bp-activities' ).val( '' ).blur();
@@ -66,9 +65,9 @@ var activityReply = {
66
  /**
67
  * Submits "form" via AJAX back to WordPress.
68
  *
69
- * @since 1.6.0
70
  */
71
- send : function() {
72
  // Hide any existing error message, and show the loading spinner
73
  $( '#bp-replysubmit .error' ).hide();
74
  $( '#bp-replysubmit .waiting' ).show();
@@ -100,7 +99,7 @@ var activityReply = {
100
  /**
101
  * send() error message handler
102
  *
103
- * @since 1.6.0
104
  */
105
  error : function( r ) {
106
  var er = r.statusText;
@@ -118,13 +117,13 @@ var activityReply = {
118
  /**
119
  * send() success handler
120
  *
121
- * @since 1.6.0
122
  */
123
  show : function ( xml ) {
124
  var bg, id, response;
125
 
126
  // Handle any errors in the response
127
- if ( typeof( xml ) === 'string' ) {
128
  activityReply.error( { 'responseText': xml } );
129
  return false;
130
  }
@@ -137,7 +136,7 @@ var activityReply = {
137
  response = response.responses[0];
138
 
139
  // Close and reset the reply row, and add the new Activity item into the list.
140
- $('#bp-activities-container').fadeOut( '200', function () {
141
 
142
  // Empty and unfocus the text area
143
  $( '#bp-activities' ).val( '' ).blur();
@@ -165,11 +164,9 @@ $(document).ready( function () {
165
  $( '#bp_activity_action h3, #bp_activity_content h3' ).unbind( 'click' );
166
 
167
  // redo the post box toggles to reset the one made by comment.js in favor
168
- // of activity administration page id so that metaboxes are still collapsible
169
  // in single Activity Administration screen.
170
- if ( typeof postboxes !== 'undefined' ) {
171
- postboxes.add_postbox_toggles( bp_activity_admin_vars.page );
172
- }
173
  });
174
 
175
- })(jQuery);
 
1
  (function( $ ) {
2
 
3
  /**
4
  * Activity reply object for the activity index screen
5
  *
6
+ * @since BuddyPress (1.6)
7
  */
8
  var activityReply = {
9
 
10
  /**
11
  * Attach event handler functions to the relevant elements.
12
  *
13
+ * @since BuddyPress (1.6)
14
  */
15
  init : function() {
16
  $(document).on( 'click', '.row-actions a.reply', activityReply.open );
19
 
20
  // Close textarea on escape
21
  $(document).on( 'keyup', '#bp-activities:visible', function( e ) {
22
+ if ( 27 == e.which ) {
23
  activityReply.close();
24
  }
25
  });
28
  /**
29
  * Reveals the entire row when "reply" is pressed.
30
  *
31
+ * @since BuddyPress (1.6)
32
  */
33
+ open : function( e ) {
34
  // Hide the container row, and move it to the new location
35
  var box = $( '#bp-activities-container' ).hide();
36
  $( this ).parents( 'tr' ).after( box );
45
  /**
46
  * Hide and reset the entire row when "cancel", or escape, are pressed.
47
  *
48
+ * @since BuddyPress (1.6)
49
  */
50
+ close : function( e ) {
51
  // Hide the container row
52
+ $('#bp-activities-container').fadeOut( '200', function () {
53
 
54
  // Empty and unfocus the text area
55
  $( '#bp-activities' ).val( '' ).blur();
65
  /**
66
  * Submits "form" via AJAX back to WordPress.
67
  *
68
+ * @since BuddyPress (1.6)
69
  */
70
+ send : function( e ) {
71
  // Hide any existing error message, and show the loading spinner
72
  $( '#bp-replysubmit .error' ).hide();
73
  $( '#bp-replysubmit .waiting' ).show();
99
  /**
100
  * send() error message handler
101
  *
102
+ * @since BuddyPress (1.6)
103
  */
104
  error : function( r ) {
105
  var er = r.statusText;
117
  /**
118
  * send() success handler
119
  *
120
+ * @since BuddyPress (1.6)
121
  */
122
  show : function ( xml ) {
123
  var bg, id, response;
124
 
125
  // Handle any errors in the response
126
+ if ( typeof( xml ) == 'string' ) {
127
  activityReply.error( { 'responseText': xml } );
128
  return false;
129
  }
136
  response = response.responses[0];
137
 
138
  // Close and reset the reply row, and add the new Activity item into the list.
139
+ $('#bp-activities-container').fadeOut( '200', function () {
140
 
141
  // Empty and unfocus the text area
142
  $( '#bp-activities' ).val( '' ).blur();
164
  $( '#bp_activity_action h3, #bp_activity_content h3' ).unbind( 'click' );
165
 
166
  // redo the post box toggles to reset the one made by comment.js in favor
167
+ // of activity administration page id so that metaboxes are still collapsible
168
  // in single Activity Administration screen.
169
+ postboxes.add_postbox_toggles( bp_activity_admin_vars.page );
 
 
170
  });
171
 
172
+ })(jQuery);
bp-activity/admin/js/admin.min.js CHANGED
@@ -1,2 +1 @@
1
- /*! buddypress - v2.4.0 - 2015-10-29 4:00:53 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
+ (function(b){var a={init:function(){b(document).on("click",".row-actions a.reply",a.open);b(document).on("click","#bp-activities-container a.cancel",a.close);b(document).on("click","#bp-activities-container a.save",a.send);b(document).on("keyup","#bp-activities:visible",function(c){if(27==c.which){a.close()}})},open:function(d){var c=b("#bp-activities-container").hide();b(this).parents("tr").after(c);c.fadeIn("300");b("#bp-activities").focus();return false},close:function(c){b("#bp-activities-container").fadeOut("200",function(){b("#bp-activities").val("").blur();b("#bp-replysubmit .error").html("").hide();b("#bp-replysubmit .waiting").hide()});return false},send:function(d){b("#bp-replysubmit .error").hide();b("#bp-replysubmit .waiting").show();var c={};c["_ajax_nonce-bp-activity-admin-reply"]=b('#bp-activities-container input[name="_ajax_nonce-bp-activity-admin-reply"]').val();c.action="bp-activity-admin-reply";c.content=b("#bp-activities").val();c.parent_id=b("#bp-activities-container").prev().data("parent_id");c.root_id=b("#bp-activities-container").prev().data("root_id");b.ajax({data:c,type:"POST",url:ajaxurl,error:function(e){a.error(e)},success:function(e){a.show(e)}});return false},error:function(c){var d=c.statusText;b("#bp-replysubmit .waiting").hide();if(c.responseText){d=c.responseText.replace(/<.[^<>]*?>/g,"")}if(d){b("#bp-replysubmit .error").html(d).show()}},show:function(d){var e,f,c;if(typeof(d)=="string"){a.error({responseText:d});return false}c=wpAjax.parseAjaxResponse(d);if(c.errors){a.error({responseText:wpAjax.broken});return false}c=c.responses[0];b("#bp-activities-container").fadeOut("200",function(){b("#bp-activities").val("").blur();b("#bp-replysubmit .error").html("").hide();b("#bp-replysubmit .waiting").hide();b("#bp-activities-container").before(c.data);f=b("#activity-"+c.id);e=f.closest(".widefat").css("backgroundColor");f.animate({backgroundColor:"#CEB"},300).animate({backgroundColor:e},300)})}};b(document).ready(function(){a.init();b("#bp_activity_action h3, #bp_activity_content h3").unbind("click");postboxes.add_postbox_toggles(bp_activity_admin_vars.page)})})(jQuery);
 
bp-activity/bp-activity-actions.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  /**
3
  * Action functions are exactly the same as screen functions, however they do
4
  * not have a template screen associated with them. Usually they will send the
@@ -8,23 +9,17 @@
8
  * @subpackage ActivityActions
9
  */
10
 
11
- // Exit if accessed directly.
12
- defined( 'ABSPATH' ) || exit;
13
 
14
  /**
15
  * Allow core components and dependent plugins to register activity actions.
16
  *
17
- * @since 1.2.0
18
  *
19
  * @uses do_action() To call 'bp_register_activity_actions' hook.
20
  */
21
  function bp_register_activity_actions() {
22
-
23
- /**
24
- * Fires on bp_init to allow core components and dependent plugins to register activity actions.
25
- *
26
- * @since 1.2.0
27
- */
28
  do_action( 'bp_register_activity_actions' );
29
  }
30
  add_action( 'bp_init', 'bp_register_activity_actions', 8 );
@@ -32,8 +27,9 @@ add_action( 'bp_init', 'bp_register_activity_actions', 8 );
32
  /**
33
  * Catch and route requests for single activity item permalinks.
34
  *
35
- * @since 1.2.0
36
  *
 
37
  * @uses bp_is_activity_component()
38
  * @uses bp_is_current_action()
39
  * @uses bp_action_variable()
@@ -50,15 +46,15 @@ add_action( 'bp_init', 'bp_register_activity_actions', 8 );
50
  */
51
  function bp_activity_action_permalink_router() {
52
 
53
- // Not viewing activity.
54
  if ( ! bp_is_activity_component() || ! bp_is_current_action( 'p' ) )
55
  return false;
56
 
57
- // No activity to display.
58
  if ( ! bp_action_variable( 0 ) || ! is_numeric( bp_action_variable( 0 ) ) )
59
  return false;
60
 
61
- // Get the activity details.
62
  $activity = bp_activity_get_specific( array( 'activity_ids' => bp_action_variable( 0 ), 'show_hidden' => true ) );
63
 
64
  // 404 if activity does not exist
@@ -69,49 +65,43 @@ function bp_activity_action_permalink_router() {
69
  $activity = $activity['activities'][0];
70
  }
71
 
72
- // Do not redirect at default.
73
  $redirect = false;
74
 
75
- // Redirect based on the type of activity.
76
  if ( bp_is_active( 'groups' ) && $activity->component == buddypress()->groups->id ) {
77
 
78
- // Activity is a user update.
79
  if ( ! empty( $activity->user_id ) ) {
80
  $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/';
81
 
82
- // Activity is something else.
83
  } else {
84
 
85
- // Set redirect to group activity stream.
86
  if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) ) {
87
  $redirect = bp_get_group_permalink( $group ) . bp_get_activity_slug() . '/' . $activity->id . '/';
88
  }
89
  }
90
 
91
- // Set redirect to users' activity stream.
92
- } elseif ( ! empty( $activity->user_id ) ) {
93
  $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/';
94
  }
95
 
96
- // If set, add the original query string back onto the redirect URL.
97
  if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
98
  $query_frags = array();
99
  wp_parse_str( $_SERVER['QUERY_STRING'], $query_frags );
100
  $redirect = add_query_arg( urlencode_deep( $query_frags ), $redirect );
101
  }
102
 
103
- /**
104
- * Filter the intended redirect url before the redirect occurs for the single activity item.
105
- *
106
- * @since 1.2.2
107
- *
108
- * @param array Array with url to redirect to and activity related to the redirect.
109
- */
110
  if ( ! $redirect = apply_filters_ref_array( 'bp_activity_permalink_redirect_url', array( $redirect, &$activity ) ) ) {
111
  bp_core_redirect( bp_get_root_domain() );
112
  }
113
 
114
- // Redirect to the actual activity permalink page.
115
  bp_core_redirect( $redirect );
116
  }
117
  add_action( 'bp_actions', 'bp_activity_action_permalink_router' );
@@ -119,7 +109,9 @@ add_action( 'bp_actions', 'bp_activity_action_permalink_router' );
119
  /**
120
  * Delete specific activity item and redirect to previous page.
121
  *
122
- * @since 1.1.0
 
 
123
  *
124
  * @uses bp_is_activity_component()
125
  * @uses bp_is_current_action()
@@ -132,59 +124,43 @@ add_action( 'bp_actions', 'bp_activity_action_permalink_router' );
132
  * @uses do_action() Calls 'bp_activity_action_delete_activity' hook to allow actions to be taken after the activity is deleted.
133
  * @uses bp_core_redirect()
134
  *
135
- * @param int $activity_id Activity id to be deleted. Defaults to 0.
136
  * @return bool False on failure.
137
  */
138
  function bp_activity_action_delete_activity( $activity_id = 0 ) {
139
 
140
- // Not viewing activity or action is not delete.
141
  if ( !bp_is_activity_component() || !bp_is_current_action( 'delete' ) )
142
  return false;
143
 
144
  if ( empty( $activity_id ) && bp_action_variable( 0 ) )
145
  $activity_id = (int) bp_action_variable( 0 );
146
 
147
- // Not viewing a specific activity item.
148
  if ( empty( $activity_id ) )
149
  return false;
150
 
151
- // Check the nonce.
152
  check_admin_referer( 'bp_activity_delete_link' );
153
 
154
- // Load up the activity item.
155
  $activity = new BP_Activity_Activity( $activity_id );
156
 
157
- // Check access.
158
  if ( ! bp_activity_user_can_delete( $activity ) )
159
  return false;
160
 
161
- /**
162
- * Fires before the deletion so plugins can still fetch information about it.
163
- *
164
- * @since 1.5.0
165
- *
166
- * @param int $activity_id The activity ID.
167
- * @param int $user_id The user associated with the activity.
168
- */
169
  do_action( 'bp_activity_before_action_delete_activity', $activity_id, $activity->user_id );
170
 
171
- // Delete the activity item and provide user feedback.
172
  if ( bp_activity_delete( array( 'id' => $activity_id, 'user_id' => $activity->user_id ) ) )
173
  bp_core_add_message( __( 'Activity deleted successfully', 'buddypress' ) );
174
  else
175
  bp_core_add_message( __( 'There was an error when deleting that activity', 'buddypress' ), 'error' );
176
 
177
- /**
178
- * Fires after the deletion so plugins can act afterwards based on the activity.
179
- *
180
- * @since 1.1.0
181
- *
182
- * @param int $activity_id The activity ID.
183
- * @param int $user_id The user associated with the activity.
184
- */
185
  do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id );
186
 
187
- // Check for the redirect query arg, otherwise let WP handle things.
188
  if ( !empty( $_GET['redirect_to'] ) )
189
  bp_core_redirect( esc_url( $_GET['redirect_to'] ) );
190
  else
@@ -195,22 +171,23 @@ add_action( 'bp_actions', 'bp_activity_action_delete_activity' );
195
  /**
196
  * Mark specific activity item as spam and redirect to previous page.
197
  *
198
- * @since 1.6.0
199
  *
 
200
  * @param int $activity_id Activity id to be deleted. Defaults to 0.
201
  * @return bool False on failure.
202
  */
203
  function bp_activity_action_spam_activity( $activity_id = 0 ) {
204
- $bp = buddypress();
205
 
206
- // Not viewing activity, or action is not spam, or Akismet isn't present.
207
  if ( !bp_is_activity_component() || !bp_is_current_action( 'spam' ) || empty( $bp->activity->akismet ) )
208
  return false;
209
 
210
  if ( empty( $activity_id ) && bp_action_variable( 0 ) )
211
  $activity_id = (int) bp_action_variable( 0 );
212
 
213
- // Not viewing a specific activity item.
214
  if ( empty( $activity_id ) )
215
  return false;
216
 
@@ -218,42 +195,27 @@ function bp_activity_action_spam_activity( $activity_id = 0 ) {
218
  if ( !bp_activity_user_can_mark_spam() )
219
  return false;
220
 
221
- // Load up the activity item.
222
  $activity = new BP_Activity_Activity( $activity_id );
223
  if ( empty( $activity->id ) )
224
  return false;
225
 
226
- // Check nonce.
227
  check_admin_referer( 'bp_activity_akismet_spam_' . $activity->id );
228
 
229
- /**
230
- * Fires before the marking activity as spam so plugins can modify things if they want to.
231
- *
232
- * @since 1.6.0
233
- *
234
- * @param int $activity_id Activity ID to be marked as spam.
235
- * @param object $activity Activity object for the ID to be marked as spam.
236
- */
237
  do_action( 'bp_activity_before_action_spam_activity', $activity->id, $activity );
238
 
239
- // Mark as spam.
240
  bp_activity_mark_as_spam( $activity );
241
  $activity->save();
242
 
243
- // Tell the user the spamming has been successful.
244
  bp_core_add_message( __( 'The activity item has been marked as spam and is no longer visible.', 'buddypress' ) );
245
 
246
- /**
247
- * Fires after the marking activity as spam so plugins can act afterwards based on the activity.
248
- *
249
- * @since 1.6.0
250
- *
251
- * @param int $activity_id Activity ID that was marked as spam.
252
- * @param int $user_id User ID associated with activity.
253
- */
254
  do_action( 'bp_activity_action_spam_activity', $activity_id, $activity->user_id );
255
 
256
- // Check for the redirect query arg, otherwise let WP handle things.
257
  if ( !empty( $_GET['redirect_to'] ) )
258
  bp_core_redirect( esc_url( $_GET['redirect_to'] ) );
259
  else
@@ -264,7 +226,7 @@ add_action( 'bp_actions', 'bp_activity_action_spam_activity' );
264
  /**
265
  * Post user/group activity update.
266
  *
267
- * @since 1.2.0
268
  *
269
  * @uses is_user_logged_in()
270
  * @uses bp_is_activity_component()
@@ -284,83 +246,52 @@ add_action( 'bp_actions', 'bp_activity_action_spam_activity' );
284
  */
285
  function bp_activity_action_post_update() {
286
 
287
- // Do not proceed if user is not logged in, not viewing activity, or not posting.
288
  if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'post' ) )
289
  return false;
290
 
291
- // Check the nonce.
292
  check_admin_referer( 'post_update', '_wpnonce_post_update' );
293
 
294
- /**
295
- * Filters the content provided in the activity input field.
296
- *
297
- * @since 1.2.0
298
- *
299
- * @param string $value Activity message being posted.
300
- */
301
  $content = apply_filters( 'bp_activity_post_update_content', $_POST['whats-new'] );
302
 
303
  if ( ! empty( $_POST['whats-new-post-object'] ) ) {
304
-
305
- /**
306
- * Filters the item type that the activity update should be associated with.
307
- *
308
- * @since 1.2.0
309
- *
310
- * @param string $value Item type to associate with.
311
- */
312
  $object = apply_filters( 'bp_activity_post_update_object', $_POST['whats-new-post-object'] );
313
  }
314
 
315
  if ( ! empty( $_POST['whats-new-post-in'] ) ) {
316
-
317
- /**
318
- * Filters what component the activity is being to.
319
- *
320
- * @since 1.2.0
321
- *
322
- * @param string $value Chosen component to post activity to.
323
- */
324
  $item_id = apply_filters( 'bp_activity_post_update_item_id', $_POST['whats-new-post-in'] );
325
  }
326
 
327
- // No activity content so provide feedback and redirect.
328
  if ( empty( $content ) ) {
329
  bp_core_add_message( __( 'Please enter some content to post.', 'buddypress' ), 'error' );
330
  bp_core_redirect( wp_get_referer() );
331
  }
332
 
333
- // No existing item_id.
334
  if ( empty( $item_id ) ) {
335
  $activity_id = bp_activity_post_update( array( 'content' => $content ) );
336
 
337
- // Post to groups object.
338
- } elseif ( 'groups' == $object && bp_is_active( 'groups' ) ) {
339
  if ( (int) $item_id ) {
340
  $activity_id = groups_post_update( array( 'content' => $content, 'group_id' => $item_id ) );
341
  }
342
 
 
343
  } else {
344
-
345
- /**
346
- * Filters activity object for BuddyPress core and plugin authors before posting activity update.
347
- *
348
- * @since 1.2.0
349
- *
350
- * @param string $object Activity item being associated to.
351
- * @param string $item_id Component ID being posted to.
352
- * @param string $content Activity content being posted.
353
- */
354
  $activity_id = apply_filters( 'bp_activity_custom_update', $object, $item_id, $content );
355
  }
356
 
357
- // Provide user feedback.
358
  if ( !empty( $activity_id ) )
359
  bp_core_add_message( __( 'Update Posted!', 'buddypress' ) );
360
  else
361
- bp_core_add_message( __( 'There was an error when posting your update. Please try again.', 'buddypress' ), 'error' );
362
 
363
- // Redirect.
364
  bp_core_redirect( wp_get_referer() );
365
  }
366
  add_action( 'bp_actions', 'bp_activity_action_post_update' );
@@ -368,7 +299,7 @@ add_action( 'bp_actions', 'bp_activity_action_post_update' );
368
  /**
369
  * Post new activity comment.
370
  *
371
- * @since 1.2.0
372
  *
373
  * @uses is_user_logged_in()
374
  * @uses bp_is_activity_component()
@@ -388,25 +319,10 @@ function bp_activity_action_post_comment() {
388
  if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'reply' ) )
389
  return false;
390
 
391
- // Check the nonce.
392
  check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );
393
 
394
- /**
395
- * Filters the activity ID a comment will be in reply to.
396
- *
397
- * @since 1.2.0
398
- *
399
- * @param string $value ID of the activity being replied to.
400
- */
401
  $activity_id = apply_filters( 'bp_activity_post_comment_activity_id', $_POST['comment_form_id'] );
402
-
403
- /**
404
- * Filters the comment content for a comment reply.
405
- *
406
- * @since 1.2.0
407
- *
408
- * @param string $value Comment content being posted.
409
- */
410
  $content = apply_filters( 'bp_activity_post_comment_content', $_POST['ac_input_' . $activity_id] );
411
 
412
  if ( empty( $content ) ) {
@@ -423,7 +339,7 @@ function bp_activity_action_post_comment() {
423
  if ( !empty( $comment_id ) )
424
  bp_core_add_message( __( 'Reply Posted!', 'buddypress' ) );
425
  else
426
- bp_core_add_message( __( 'There was an error posting that reply. Please try again.', 'buddypress' ), 'error' );
427
 
428
  bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
429
  }
@@ -432,7 +348,7 @@ add_action( 'bp_actions', 'bp_activity_action_post_comment' );
432
  /**
433
  * Mark activity as favorite.
434
  *
435
- * @since 1.2.0
436
  *
437
  * @uses is_user_logged_in()
438
  * @uses bp_is_activity_component()
@@ -451,13 +367,13 @@ function bp_activity_action_mark_favorite() {
451
  if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'favorite' ) )
452
  return false;
453
 
454
- // Check the nonce.
455
  check_admin_referer( 'mark_favorite' );
456
 
457
  if ( bp_activity_add_user_favorite( bp_action_variable( 0 ) ) )
458
  bp_core_add_message( __( 'Activity marked as favorite.', 'buddypress' ) );
459
  else
460
- bp_core_add_message( __( 'There was an error marking that activity as a favorite. Please try again.', 'buddypress' ), 'error' );
461
 
462
  bp_core_redirect( wp_get_referer() . '#activity-' . bp_action_variable( 0 ) );
463
  }
@@ -466,7 +382,7 @@ add_action( 'bp_actions', 'bp_activity_action_mark_favorite' );
466
  /**
467
  * Remove activity from favorites.
468
  *
469
- * @since 1.2.0
470
  *
471
  * @uses is_user_logged_in()
472
  * @uses bp_is_activity_component()
@@ -485,13 +401,13 @@ function bp_activity_action_remove_favorite() {
485
  if ( ! is_user_logged_in() || ! bp_is_activity_component() || ! bp_is_current_action( 'unfavorite' ) )
486
  return false;
487
 
488
- // Check the nonce.
489
  check_admin_referer( 'unmark_favorite' );
490
 
491
  if ( bp_activity_remove_user_favorite( bp_action_variable( 0 ) ) )
492
  bp_core_add_message( __( 'Activity removed as favorite.', 'buddypress' ) );
493
  else
494
- bp_core_add_message( __( 'There was an error removing that activity as a favorite. Please try again.', 'buddypress' ), 'error' );
495
 
496
  bp_core_redirect( wp_get_referer() . '#activity-' . bp_action_variable( 0 ) );
497
  }
@@ -500,8 +416,9 @@ add_action( 'bp_actions', 'bp_activity_action_remove_favorite' );
500
  /**
501
  * Load the sitewide activity feed.
502
  *
503
- * @since 1.0.0
504
  *
 
505
  * @uses bp_is_activity_component()
506
  * @uses bp_is_current_action()
507
  * @uses bp_is_user()
@@ -510,17 +427,17 @@ add_action( 'bp_actions', 'bp_activity_action_remove_favorite' );
510
  * @return bool False on failure.
511
  */
512
  function bp_activity_action_sitewide_feed() {
513
- $bp = buddypress();
514
 
515
  if ( ! bp_is_activity_component() || ! bp_is_current_action( 'feed' ) || bp_is_user() || ! empty( $bp->groups->current_group ) )
516
  return false;
517
 
518
- // Setup the feed.
519
  buddypress()->activity->feed = new BP_Activity_Feed( array(
520
  'id' => 'sitewide',
521
 
522
  /* translators: Sitewide activity RSS title - "[Site Name] | Site Wide Activity" */
523
- 'title' => sprintf( __( '%s | Site-Wide Activity', 'buddypress' ), bp_get_site_name() ),
524
 
525
  'link' => bp_get_activity_directory_permalink(),
526
  'description' => __( 'Activity feed for the entire site.', 'buddypress' ),
@@ -532,7 +449,7 @@ add_action( 'bp_actions', 'bp_activity_action_sitewide_feed' );
532
  /**
533
  * Load a user's personal activity feed.
534
  *
535
- * @since 1.0.0
536
  *
537
  * @uses bp_is_user_activity()
538
  * @uses bp_is_current_action()
@@ -545,7 +462,7 @@ function bp_activity_action_personal_feed() {
545
  return false;
546
  }
547
 
548
- // Setup the feed.
549
  buddypress()->activity->feed = new BP_Activity_Feed( array(
550
  'id' => 'personal',
551
 
@@ -562,7 +479,7 @@ add_action( 'bp_actions', 'bp_activity_action_personal_feed' );
562
  /**
563
  * Load a user's friends' activity feed.
564
  *
565
- * @since 1.0.0
566
  *
567
  * @uses bp_is_active()
568
  * @uses bp_is_user_activity()
@@ -578,7 +495,7 @@ function bp_activity_action_friends_feed() {
578
  return false;
579
  }
580
 
581
- // Setup the feed.
582
  buddypress()->activity->feed = new BP_Activity_Feed( array(
583
  'id' => 'friends',
584
 
@@ -595,7 +512,7 @@ add_action( 'bp_actions', 'bp_activity_action_friends_feed' );
595
  /**
596
  * Load the activity feed for a user's groups.
597
  *
598
- * @since 1.2.0
599
  *
600
  * @uses bp_is_active()
601
  * @uses bp_is_user_activity()
@@ -611,11 +528,11 @@ function bp_activity_action_my_groups_feed() {
611
  return false;
612
  }
613
 
614
- // Get displayed user's group IDs.
615
  $groups = groups_get_user_groups();
616
  $group_ids = implode( ',', $groups['groups'] );
617
 
618
- // Setup the feed.
619
  buddypress()->activity->feed = new BP_Activity_Feed( array(
620
  'id' => 'mygroups',
621
 
@@ -623,7 +540,7 @@ function bp_activity_action_my_groups_feed() {
623
  'title' => sprintf( __( '%1$s | %2$s | Group Activity', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ),
624
 
625
  'link' => trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_groups_slug() ),
626
- 'description' => sprintf( __( "Public group activity feed of which %s is a member.", 'buddypress' ), bp_get_displayed_user_fullname() ),
627
  'activity_args' => array(
628
  'object' => buddypress()->groups->id,
629
  'primary_id' => $group_ids,
@@ -636,7 +553,7 @@ add_action( 'bp_actions', 'bp_activity_action_my_groups_feed' );
636
  /**
637
  * Load a user's @mentions feed.
638
  *
639
- * @since 1.2.0
640
  *
641
  * @uses bp_is_user_activity()
642
  * @uses bp_is_current_action()
@@ -654,7 +571,7 @@ function bp_activity_action_mentions_feed() {
654
  return false;
655
  }
656
 
657
- // Setup the feed.
658
  buddypress()->activity->feed = new BP_Activity_Feed( array(
659
  'id' => 'mentions',
660
 
@@ -673,7 +590,7 @@ add_action( 'bp_actions', 'bp_activity_action_mentions_feed' );
673
  /**
674
  * Load a user's favorites feed.
675
  *
676
- * @since 1.2.0
677
  *
678
  * @uses bp_is_user_activity()
679
  * @uses bp_is_current_action()
@@ -687,11 +604,11 @@ function bp_activity_action_favorites_feed() {
687
  return false;
688
  }
689
 
690
- // Get displayed user's favorite activity IDs.
691
  $favs = bp_activity_get_user_favorites( bp_displayed_user_id() );
692
  $fav_ids = implode( ',', (array) $favs );
693
 
694
- // Setup the feed.
695
  buddypress()->activity->feed = new BP_Activity_Feed( array(
696
  'id' => 'favorites',
697
 
@@ -708,125 +625,25 @@ add_action( 'bp_actions', 'bp_activity_action_favorites_feed' );
708
  /**
709
  * Loads Akismet filtering for activity.
710
  *
711
- * @since 1.6.0
712
- * @since 2.3.0 We only support Akismet 3+.
 
713
  */
714
  function bp_activity_setup_akismet() {
715
- $bp = buddypress();
716
-
717
- // Bail if Akismet is not active.
718
- if ( ! defined( 'AKISMET_VERSION' ) ) {
719
- return;
720
- }
721
 
722
- // Bail if older version of Akismet.
723
- if ( ! class_exists( 'Akismet' ) ) {
724
  return;
725
- }
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
- /**
733
- * Filters if BuddyPress Activity Akismet support has been disabled by another plugin.
734
- *
735
- * @since 1.6.0
736
- *
737
- * @param bool $value Return value of bp_is_akismet_active boolean function.
738
- */
739
- if ( ! apply_filters( 'bp_activity_use_akismet', bp_is_akismet_active() ) ) {
740
  return;
741
- }
742
 
743
- // Instantiate Akismet for BuddyPress.
744
  $bp->activity->akismet = new BP_Akismet();
745
  }
746
-
747
- /**
748
- * AJAX endpoint for Suggestions API lookups.
749
- *
750
- * @since 2.1.0
751
- */
752
- function bp_ajax_get_suggestions() {
753
- if ( ! bp_is_user_active() || empty( $_GET['term'] ) || empty( $_GET['type'] ) ) {
754
- wp_send_json_error( 'missing_parameter' );
755
- exit;
756
- }
757
-
758
- $args = array(
759
- 'term' => sanitize_text_field( $_GET['term'] ),
760
- 'type' => sanitize_text_field( $_GET['type'] ),
761
- );
762
-
763
- // Support per-Group suggestions.
764
- if ( ! empty( $_GET['group-id'] ) ) {
765
- $args['group_id'] = absint( $_GET['group-id'] );
766
- }
767
-
768
- $results = bp_core_get_suggestions( $args );
769
-
770
- if ( is_wp_error( $results ) ) {
771
- wp_send_json_error( $results->get_error_message() );
772
- exit;
773
- }
774
-
775
- wp_send_json_success( $results );
776
- }
777
- add_action( 'wp_ajax_bp_get_suggestions', 'bp_ajax_get_suggestions' );
778
-
779
- /**
780
- * Detect a change in post type status, and initiate an activity update if necessary.
781
- *
782
- * @since 2.2.0
783
- *
784
- * @todo Support untrashing better.
785
- *
786
- * @param string $new_status New status for the post.
787
- * @param string $old_status Old status for the post.
788
- * @param object $post Post data.
789
- */
790
- function bp_activity_catch_transition_post_type_status( $new_status, $old_status, $post ) {
791
- if ( ! post_type_supports( $post->post_type, 'buddypress-activity' ) ) {
792
- return;
793
- }
794
-
795
- // This is an edit.
796
- if ( $new_status === $old_status ) {
797
- // An edit of an existing post should update the existing activity item.
798
- if ( $new_status == 'publish' ) {
799
- bp_activity_post_type_update( $post );
800
- }
801
-
802
- return;
803
- }
804
-
805
- // Publishing a previously unpublished post.
806
- if ( 'publish' === $new_status ) {
807
- // Untrashing the post type - nothing here yet.
808
- if ( 'trash' == $old_status ) {
809
-
810
- /**
811
- * Fires if untrashing post in a post type.
812
- *
813
- * This is a variable filter that is dependent on the post type
814
- * being untrashed.
815
- *
816
- * @since 2.2.0
817
- *
818
- * @param WP_Post $post Post data.
819
- */
820
- do_action( 'bp_activity_post_type_untrash_' . $post->post_type, $post );
821
- } else {
822
- // Record the post.
823
- bp_activity_post_type_publish( $post->ID, $post );
824
- }
825
-
826
- // Unpublishing a previously published post.
827
- } elseif ( 'publish' === $old_status ) {
828
- // Some form of pending status - only remove the activity entry.
829
- bp_activity_post_type_unpublish( $post->ID, $post );
830
- }
831
- }
832
- add_action( 'transition_post_status', 'bp_activity_catch_transition_post_type_status', 10, 3 );
1
  <?php
2
+
3
  /**
4
  * Action functions are exactly the same as screen functions, however they do
5
  * not have a template screen associated with them. Usually they will send the
9
  * @subpackage ActivityActions
10
  */
11
 
12
+ // Exit if accessed directly
13
+ if ( !defined( 'ABSPATH' ) ) exit;
14
 
15
  /**
16
  * Allow core components and dependent plugins to register activity actions.
17
  *
18
+ * @since BuddyPress (1.2)
19
  *
20
  * @uses do_action() To call 'bp_register_activity_actions' hook.
21
  */
22
  function bp_register_activity_actions() {
 
 
 
 
 
 
23
  do_action( 'bp_register_activity_actions' );
24
  }
25
  add_action( 'bp_init', 'bp_register_activity_actions', 8 );
27
  /**
28
  * Catch and route requests for single activity item permalinks.
29
  *
30
+ * @since BuddyPress (1.2)
31
  *
32
+ * @global object $bp BuddyPress global settings
33
  * @uses bp_is_activity_component()
34
  * @uses bp_is_current_action()
35
  * @uses bp_action_variable()
46
  */
47
  function bp_activity_action_permalink_router() {
48
 
49
+ // Not viewing activity
50
  if ( ! bp_is_activity_component() || ! bp_is_current_action( 'p' ) )
51
  return false;
52
 
53
+ // No activity to display
54
  if ( ! bp_action_variable( 0 ) || ! is_numeric( bp_action_variable( 0 ) ) )
55
  return false;
56
 
57
+ // Get the activity details
58
  $activity = bp_activity_get_specific( array( 'activity_ids' => bp_action_variable( 0 ), 'show_hidden' => true ) );
59
 
60
  // 404 if activity does not exist
65
  $activity = $activity['activities'][0];
66
  }
67
 
68
+ // Do not redirect at default
69
  $redirect = false;
70
 
71
+ // Redirect based on the type of activity
72
  if ( bp_is_active( 'groups' ) && $activity->component == buddypress()->groups->id ) {
73
 
74
+ // Activity is a user update
75
  if ( ! empty( $activity->user_id ) ) {
76
  $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/';
77
 
78
+ // Activity is something else
79
  } else {
80
 
81
+ // Set redirect to group activity stream
82
  if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) ) {
83
  $redirect = bp_get_group_permalink( $group ) . bp_get_activity_slug() . '/' . $activity->id . '/';
84
  }
85
  }
86
 
87
+ // Set redirect to users' activity stream
88
+ } else if ( ! empty( $activity->user_id ) ) {
89
  $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/';
90
  }
91
 
92
+ // If set, add the original query string back onto the redirect URL
93
  if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
94
  $query_frags = array();
95
  wp_parse_str( $_SERVER['QUERY_STRING'], $query_frags );
96
  $redirect = add_query_arg( urlencode_deep( $query_frags ), $redirect );
97
  }
98
 
99
+ // Allow redirect to be filtered
 
 
 
 
 
 
100
  if ( ! $redirect = apply_filters_ref_array( 'bp_activity_permalink_redirect_url', array( $redirect, &$activity ) ) ) {
101
  bp_core_redirect( bp_get_root_domain() );
102
  }
103
 
104
+ // Redirect to the actual activity permalink page
105
  bp_core_redirect( $redirect );
106
  }
107
  add_action( 'bp_actions', 'bp_activity_action_permalink_router' );
109
  /**
110
  * Delete specific activity item and redirect to previous page.
111
  *
112
+ * @since BuddyPress (1.1)
113
+ *
114
+ * @param int $activity_id Activity id to be deleted. Defaults to 0.
115
  *
116
  * @uses bp_is_activity_component()
117
  * @uses bp_is_current_action()
124
  * @uses do_action() Calls 'bp_activity_action_delete_activity' hook to allow actions to be taken after the activity is deleted.
125
  * @uses bp_core_redirect()
126
  *
 
127
  * @return bool False on failure.
128
  */
129
  function bp_activity_action_delete_activity( $activity_id = 0 ) {
130
 
131
+ // Not viewing activity or action is not delete
132
  if ( !bp_is_activity_component() || !bp_is_current_action( 'delete' ) )
133
  return false;
134
 
135
  if ( empty( $activity_id ) && bp_action_variable( 0 ) )
136
  $activity_id = (int) bp_action_variable( 0 );
137
 
138
+ // Not viewing a specific activity item
139
  if ( empty( $activity_id ) )
140
  return false;
141
 
142
+ // Check the nonce
143
  check_admin_referer( 'bp_activity_delete_link' );
144
 
145
+ // Load up the activity item
146
  $activity = new BP_Activity_Activity( $activity_id );
147
 
148
+ // Check access
149
  if ( ! bp_activity_user_can_delete( $activity ) )
150
  return false;
151
 
152
+ // Call the action before the delete so plugins can still fetch information about it
 
 
 
 
 
 
 
153
  do_action( 'bp_activity_before_action_delete_activity', $activity_id, $activity->user_id );
154
 
155
+ // Delete the activity item and provide user feedback
156
  if ( bp_activity_delete( array( 'id' => $activity_id, 'user_id' => $activity->user_id ) ) )
157
  bp_core_add_message( __( 'Activity deleted successfully', 'buddypress' ) );
158
  else
159
  bp_core_add_message( __( 'There was an error when deleting that activity', 'buddypress' ), 'error' );
160
 
 
 
 
 
 
 
 
 
161
  do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id );
162
 
163
+ // Check for the redirect query arg, otherwise let WP handle things
164
  if ( !empty( $_GET['redirect_to'] ) )
165
  bp_core_redirect( esc_url( $_GET['redirect_to'] ) );
166
  else
171
  /**
172
  * Mark specific activity item as spam and redirect to previous page.
173
  *
174
+ * @since BuddyPress (1.6)
175
  *
176
+ * @global object $bp BuddyPress global settings
177
  * @param int $activity_id Activity id to be deleted. Defaults to 0.
178
  * @return bool False on failure.
179
  */
180
  function bp_activity_action_spam_activity( $activity_id = 0 ) {
181
+ global $bp;
182
 
183
+ // Not viewing activity, or action is not spam, or Akismet isn't present
184
  if ( !bp_is_activity_component() || !bp_is_current_action( 'spam' ) || empty( $bp->activity->akismet ) )
185
  return false;
186
 
187
  if ( empty( $activity_id ) && bp_action_variable( 0 ) )
188
  $activity_id = (int) bp_action_variable( 0 );
189
 
190
+ // Not viewing a specific activity item
191
  if ( empty( $activity_id ) )
192
  return false;
193
 
195
  if ( !bp_activity_user_can_mark_spam() )
196
  return false;
197
 
198
+ // Load up the activity item
199
  $activity = new BP_Activity_Activity( $activity_id );
200
  if ( empty( $activity->id ) )
201
  return false;
202
 
203
+ // Check nonce
204
  check_admin_referer( 'bp_activity_akismet_spam_' . $activity->id );
205
 
206
+ // Call an action before the spamming so plugins can modify things if they want to
 
 
 
 
 
 
 
207
  do_action( 'bp_activity_before_action_spam_activity', $activity->id, $activity );
208
 
209
+ // Mark as spam
210
  bp_activity_mark_as_spam( $activity );
211
  $activity->save();
212
 
213
+ // Tell the user the spamming has been succesful
214
  bp_core_add_message( __( 'The activity item has been marked as spam and is no longer visible.', 'buddypress' ) );
215
 
 
 
 
 
 
 
 
 
216
  do_action( 'bp_activity_action_spam_activity', $activity_id, $activity->user_id );
217
 
218
+ // Check for the redirect query arg, otherwise let WP handle things
219
  if ( !empty( $_GET['redirect_to'] ) )
220
  bp_core_redirect( esc_url( $_GET['redirect_to'] ) );
221
  else
226
  /**
227
  * Post user/group activity update.
228
  *
229
+ * @since BuddyPress (1.2)
230
  *
231
  * @uses is_user_logged_in()
232
  * @uses bp_is_activity_component()
246
  */
247
  function bp_activity_action_post_update() {
248
 
249
+ // Do not proceed if user is not logged in, not viewing activity, or not posting
250
  if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'post' ) )
251
  return false;
252
 
253
+ // Check the nonce
254
  check_admin_referer( 'post_update', '_wpnonce_post_update' );
255
 
256
+ // Get activity info
 
 
 
 
 
 
257
  $content = apply_filters( 'bp_activity_post_update_content', $_POST['whats-new'] );
258
 
259
  if ( ! empty( $_POST['whats-new-post-object'] ) ) {
 
 
 
 
 
 
 
 
260
  $object = apply_filters( 'bp_activity_post_update_object', $_POST['whats-new-post-object'] );
261
  }
262
 
263
  if ( ! empty( $_POST['whats-new-post-in'] ) ) {
 
 
 
 
 
 
 
 
264
  $item_id = apply_filters( 'bp_activity_post_update_item_id', $_POST['whats-new-post-in'] );
265
  }
266
 
267
+ // No activity content so provide feedback and redirect
268
  if ( empty( $content ) ) {
269
  bp_core_add_message( __( 'Please enter some content to post.', 'buddypress' ), 'error' );
270
  bp_core_redirect( wp_get_referer() );
271
  }
272
 
273
+ // No existing item_id
274
  if ( empty( $item_id ) ) {
275
  $activity_id = bp_activity_post_update( array( 'content' => $content ) );
276
 
277
+ // Post to groups object
278
+ } else if ( 'groups' == $object && bp_is_active( 'groups' ) ) {
279
  if ( (int) $item_id ) {
280
  $activity_id = groups_post_update( array( 'content' => $content, 'group_id' => $item_id ) );
281
  }
282
 
283
+ // Special circumstance so let filters handle it
284
  } else {
 
 
 
 
 
 
 
 
 
 
285
  $activity_id = apply_filters( 'bp_activity_custom_update', $object, $item_id, $content );
286
  }
287
 
288
+ // Provide user feedback
289
  if ( !empty( $activity_id ) )
290
  bp_core_add_message( __( 'Update Posted!', 'buddypress' ) );
291
  else
292
+ bp_core_add_message( __( 'There was an error when posting your update, please try again.', 'buddypress' ), 'error' );
293
 
294
+ // Redirect
295
  bp_core_redirect( wp_get_referer() );
296
  }
297
  add_action( 'bp_actions', 'bp_activity_action_post_update' );
299
  /**
300
  * Post new activity comment.
301
  *
302
+ * @since BuddyPress (1.2)
303
  *
304
  * @uses is_user_logged_in()
305
  * @uses bp_is_activity_component()
319
  if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'reply' ) )
320
  return false;
321
 
322
+ // Check the nonce
323
  check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );
324
 
 
 
 
 
 
 
 
325
  $activity_id = apply_filters( 'bp_activity_post_comment_activity_id', $_POST['comment_form_id'] );
 
 
 
 
 
 
 
 
326
  $content = apply_filters( 'bp_activity_post_comment_content', $_POST['ac_input_' . $activity_id] );
327
 
328
  if ( empty( $content ) ) {
339
  if ( !empty( $comment_id ) )
340
  bp_core_add_message( __( 'Reply Posted!', 'buddypress' ) );
341
  else
342
+ bp_core_add_message( __( 'There was an error posting that reply, please try again.', 'buddypress' ), 'error' );
343
 
344
  bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
345
  }
348
  /**
349
  * Mark activity as favorite.
350
  *
351
+ * @since BuddyPress (1.2)
352
  *
353
  * @uses is_user_logged_in()
354
  * @uses bp_is_activity_component()
367
  if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'favorite' ) )
368
  return false;
369
 
370
+ // Check the nonce
371
  check_admin_referer( 'mark_favorite' );
372
 
373
  if ( bp_activity_add_user_favorite( bp_action_variable( 0 ) ) )
374
  bp_core_add_message( __( 'Activity marked as favorite.', 'buddypress' ) );
375
  else
376
+ bp_core_add_message( __( 'There was an error marking that activity as a favorite, please try again.', 'buddypress' ), 'error' );
377
 
378
  bp_core_redirect( wp_get_referer() . '#activity-' . bp_action_variable( 0 ) );
379
  }
382
  /**
383
  * Remove activity from favorites.
384
  *
385
+ * @since BuddyPress (1.2)
386
  *
387
  * @uses is_user_logged_in()
388
  * @uses bp_is_activity_component()
401
  if ( ! is_user_logged_in() || ! bp_is_activity_component() || ! bp_is_current_action( 'unfavorite' ) )
402
  return false;
403
 
404
+ // Check the nonce
405
  check_admin_referer( 'unmark_favorite' );
406
 
407
  if ( bp_activity_remove_user_favorite( bp_action_variable( 0 ) ) )
408
  bp_core_add_message( __( 'Activity removed as favorite.', 'buddypress' ) );
409
  else
410
+ bp_core_add_message( __( 'There was an error removing that activity as a favorite, please try again.', 'buddypress' ), 'error' );
411
 
412
  bp_core_redirect( wp_get_referer() . '#activity-' . bp_action_variable( 0 ) );
413
  }
416
  /**
417
  * Load the sitewide activity feed.
418
  *
419
+ * @since BuddyPress (1.0)
420
  *
421
+ * @global object $bp BuddyPress global settings
422
  * @uses bp_is_activity_component()
423
  * @uses bp_is_current_action()
424
  * @uses bp_is_user()
427
  * @return bool False on failure.
428
  */
429
  function bp_activity_action_sitewide_feed() {
430
+ global $bp;
431
 
432
  if ( ! bp_is_activity_component() || ! bp_is_current_action( 'feed' ) || bp_is_user() || ! empty( $bp->groups->current_group ) )
433
  return false;
434
 
435
+ // setup the feed
436
  buddypress()->activity->feed = new BP_Activity_Feed( array(
437
  'id' => 'sitewide',
438
 
439
  /* translators: Sitewide activity RSS title - "[Site Name] | Site Wide Activity" */
440
+ 'title' => sprintf( __( '%s | Site Wide Activity', 'buddypress' ), bp_get_site_name() ),
441
 
442
  'link' => bp_get_activity_directory_permalink(),
443
  'description' => __( 'Activity feed for the entire site.', 'buddypress' ),
449
  /**
450
  * Load a user's personal activity feed.
451
  *
452
+ * @since BuddyPress (1.0)
453
  *
454
  * @uses bp_is_user_activity()
455
  * @uses bp_is_current_action()
462
  return false;
463
  }
464
 
465
+ // setup the feed
466
  buddypress()->activity->feed = new BP_Activity_Feed( array(
467
  'id' => 'personal',
468
 
479
  /**
480
  * Load a user's friends' activity feed.
481
  *
482
+ * @since BuddyPress (1.0)
483
  *
484
  * @uses bp_is_active()
485
  * @uses bp_is_user_activity()
495
  return false;
496
  }
497
 
498
+ // setup the feed
499
  buddypress()->activity->feed = new BP_Activity_Feed( array(
500
  'id' => 'friends',
501
 
512
  /**
513
  * Load the activity feed for a user's groups.
514
  *
515
+ * @since BuddyPress (1.2)
516
  *
517
  * @uses bp_is_active()
518
  * @uses bp_is_user_activity()
528
  return false;
529
  }
530
 
531
+ // get displayed user's group IDs
532
  $groups = groups_get_user_groups();
533
  $group_ids = implode( ',', $groups['groups'] );
534
 
535
+ // setup the feed
536
  buddypress()->activity->feed = new BP_Activity_Feed( array(
537
  'id' => 'mygroups',
538
 
540
  'title' => sprintf( __( '%1$s | %2$s | Group Activity', 'buddypress' ), bp_get_site_name(), bp_get_displayed_user_fullname() ),
541
 
542
  'link' => trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_groups_slug() ),
543
+ 'description' => sprintf( __( "Public group activity feed of which %s is a member of.", 'buddypress' ), bp_get_displayed_user_fullname() ),
544
  'activity_args' => array(
545
  'object' => buddypress()->groups->id,
546
  'primary_id' => $group_ids,
553
  /**
554
  * Load a user's @mentions feed.
555
  *
556
+ * @since BuddyPress (1.2)
557
  *
558
  * @uses bp_is_user_activity()
559
  * @uses bp_is_current_action()
571
  return false;
572
  }
573
 
574
+ // setup the feed
575
  buddypress()->activity->feed = new BP_Activity_Feed( array(
576
  'id' => 'mentions',
577
 
590
  /**
591
  * Load a user's favorites feed.
592
  *
593
+ * @since BuddyPress (1.2)
594
  *
595
  * @uses bp_is_user_activity()
596
  * @uses bp_is_current_action()
604
  return false;
605
  }
606
 
607
+ // get displayed user's favorite activity IDs
608
  $favs = bp_activity_get_user_favorites( bp_displayed_user_id() );
609
  $fav_ids = implode( ',', (array) $favs );
610
 
611
+ // setup the feed
612
  buddypress()->activity->feed = new BP_Activity_Feed( array(
613
  'id' => 'favorites',
614
 
625
  /**
626
  * Loads Akismet filtering for activity.
627
  *
628
+ * @since BuddyPress (1.6)
629
+ *
630
+ * @global object $bp BuddyPress global settings
631
  */
632
  function bp_activity_setup_akismet() {
633
+ global $bp;
 
 
 
 
 
634
 
635
+ // Bail if Akismet is not active
636
+ if ( ! defined( 'AKISMET_VERSION' ) )
637
  return;
 
638
 
639
+ // Bail if no Akismet key is set
640
+ if ( ! bp_get_option( 'wordpress_api_key' ) && ! defined( 'WPCOM_API_KEY' ) )
641
  return;
 
642
 
643
+ // Bail if BuddyPress Activity Akismet support has been disabled by another plugin
644
+ if ( ! apply_filters( 'bp_activity_use_akismet', bp_is_akismet_active() ) )
 
 
 
 
 
 
645
  return;
 
646
 
647
+ // Instantiate Akismet for BuddyPress
648
  $bp->activity->akismet = new BP_Akismet();
649
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-activity/bp-activity-admin.php CHANGED
@@ -6,31 +6,31 @@
6
  * help text, on which this implementation is heavily based.
7
  *
8
  * @package BuddyPress
9
- * @subpackage ActivityAdmin
10
- * @since 1.6.0
11
  */
12
 
13
- // Exit if accessed directly.
14
- defined( 'ABSPATH' ) || exit;
15
 
16
- // Include WP's list table class.
17
  if ( !class_exists( 'WP_List_Table' ) ) require( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
18
 
19
- // Per_page screen option. Has to be hooked in extremely early.
20
  if ( is_admin() && ! empty( $_REQUEST['page'] ) && 'bp-activity' == $_REQUEST['page'] )
21
  add_filter( 'set-screen-option', 'bp_activity_admin_screen_options', 10, 3 );
22
 
23
  /**
24
  * Register the Activity component admin screen.
25
  *
26
- * @since 1.6.0
27
  */
28
  function bp_activity_add_admin_menu() {
29
 
30
- // Add our screen.
31
  $hook = add_menu_page(
32
- _x( 'Activity', 'Admin Dashbord SWA page title', 'buddypress' ),
33
- _x( 'Activity', 'Admin Dashbord SWA menu', 'buddypress' ),
34
  'bp_moderate',
35
  'bp-activity',
36
  'bp_activity_admin',
@@ -49,10 +49,10 @@ add_action( bp_core_admin_hook(), 'bp_activity_add_admin_menu' );
49
  * which all appear together in the middle of the Dashboard menu. This function
50
  * adds the Activity page to the array of these menu items.
51
  *
52
- * @since 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' );
@@ -66,10 +66,10 @@ add_filter( 'bp_admin_menu_order', 'bp_activity_admin_menu_order' );
66
  * Processes requests to add new activity comments, and echoes HTML for a new
67
  * table row.
68
  *
69
- * @since 1.6.0
70
  */
71
  function bp_activity_admin_reply() {
72
- // Check nonce.
73
  check_ajax_referer( 'bp-activity-admin-reply', '_ajax_nonce-bp-activity-admin-reply' );
74
 
75
  $parent_id = ! empty( $_REQUEST['parent_id'] ) ? (int) $_REQUEST['parent_id'] : 0;
@@ -79,15 +79,15 @@ function bp_activity_admin_reply() {
79
  if ( empty( $parent_id ) )
80
  die( '-1' );
81
 
82
- // If $root_id not set (e.g. for root items), use $parent_id.
83
  if ( empty( $root_id ) )
84
  $root_id = $parent_id;
85
 
86
- // Check that a reply has been entered.
87
  if ( empty( $_REQUEST['content'] ) )
88
  die( __( 'ERROR: Please type a reply.', 'buddypress' ) );
89
 
90
- // Check parent activity exists.
91
  $parent_activity = new BP_Activity_Activity( $parent_id );
92
  if ( empty( $parent_activity->component ) )
93
  die( __( 'ERROR: The item you are trying to reply to cannot be found, or it has been deleted.', 'buddypress' ) );
@@ -97,25 +97,25 @@ function bp_activity_admin_reply() {
97
  if ( ! current_user_can( 'bp_moderate' ) )
98
  die( '-1' );
99
 
100
- // Add new activity comment.
101
  $new_activity_id = bp_activity_new_comment( array(
102
- 'activity_id' => $root_id, // ID of the root activity item.
103
  'content' => $_REQUEST['content'],
104
- 'parent_id' => $parent_id, // ID of a parent comment.
105
  ) );
106
 
107
- // Fetch the new activity item, as we need it to create table markup to return.
108
  $new_activity = new BP_Activity_Activity( $new_activity_id );
109
 
110
- // This needs to be set for the BP_Activity_List_Table constructor to work.
111
  set_current_screen( 'toplevel_page_bp-activity' );
112
 
113
- // Set up an output buffer.
114
  ob_start();
115
  $list_table = new BP_Activity_List_Table();
116
  $list_table->single_row( (array) $new_activity );
117
 
118
- // Get table markup.
119
  $response = array(
120
  'data' => ob_get_contents(),
121
  'id' => $new_activity_id,
@@ -124,7 +124,7 @@ function bp_activity_admin_reply() {
124
  );
125
  ob_end_clean();
126
 
127
- // Send response.
128
  $r = new WP_Ajax_Response();
129
  $r->add( $response );
130
  $r->send();
@@ -136,10 +136,11 @@ add_action( 'wp_ajax_bp-activity-admin-reply', 'bp_activity_admin_reply' );
136
  /**
137
  * Handle save/update of screen options for the Activity component admin screen.
138
  *
139
- * @since 1.6.0
140
  *
141
- * @param string $value Will always be false unless another plugin filters it first.
142
- * @param string $option Screen option name.
 
143
  * @param string $new_value Screen option form value.
144
  * @return string Option value. False to abandon update.
145
  */
@@ -147,7 +148,7 @@ function bp_activity_admin_screen_options( $value, $option, $new_value ) {
147
  if ( 'toplevel_page_bp_activity_per_page' != $option && 'toplevel_page_bp_activity_network_per_page' != $option )
148
  return $value;
149
 
150
- // Per page.
151
  $new_value = (int) $new_value;
152
  if ( $new_value < 1 || $new_value > 999 )
153
  return $value;
@@ -158,9 +159,8 @@ function bp_activity_admin_screen_options( $value, $option, $new_value ) {
158
  /**
159
  * Hide the advanced edit meta boxes by default, so we don't clutter the screen.
160
  *
161
- * @since 1.6.0
162
  *
163
- * @param array $hidden Array of items to hide.
164
  * @param WP_Screen $screen Screen identifier.
165
  * @return array Hidden Meta Boxes.
166
  */
@@ -168,17 +168,9 @@ function bp_activity_admin_edit_hidden_metaboxes( $hidden, $screen ) {
168
  if ( empty( $screen->id ) || 'toplevel_page_bp-activity' != $screen->id && 'toplevel_page_bp-activity_network' != $screen->id )
169
  return $hidden;
170
 
171
- // Hide the primary link meta box by default.
172
  $hidden = array_merge( (array) $hidden, array( 'bp_activity_itemids', 'bp_activity_link', 'bp_activity_type', 'bp_activity_userid', ) );
173
 
174
- /**
175
- * Filters default hidden metaboxes so plugins can alter list.
176
- *
177
- * @since 1.6.0
178
- *
179
- * @param array $hidden Default metaboxes to hide.
180
- * @param WP_Screen $screen Screen identifier.
181
- */
182
  return apply_filters( 'bp_hide_meta_boxes', array_unique( $hidden ), $screen );
183
  }
184
  add_filter( 'default_hidden_meta_boxes', 'bp_activity_admin_edit_hidden_metaboxes', 10, 2 );
@@ -188,12 +180,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 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() {
@@ -201,23 +193,17 @@ function bp_activity_admin_load() {
201
 
202
  $bp = buddypress();
203
 
204
- // Decide whether to load the dev version of the CSS and JavaScript.
205
  $min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : 'min.';
206
 
207
  $doaction = bp_admin_list_table_current_bulk_action();
208
 
209
- /**
210
- * Fires at top of Activity admin page.
211
- *
212
- * @since 1.6.0
213
- *
214
- * @param string $doaction Current $_GET action being performed in admin screen.
215
- */
216
  do_action( 'bp_activity_admin_load', $doaction );
217
 
218
- // Edit screen.
219
  if ( 'edit' == $doaction && ! empty( $_GET['aid'] ) ) {
220
- // Columns screen option.
221
  add_screen_option( 'layout_columns', array( 'default' => 2, 'max' => 2, ) );
222
 
223
  get_current_screen()->add_help_tab( array(
@@ -234,16 +220,16 @@ function bp_activity_admin_load() {
234
  'title' => __( 'Item, Link, Type', 'buddypress' ),
235
  'content' =>
236
  '<p>' . __( '<strong>Primary Item/Secondary Item</strong> - These identify the object that created the activity. For example, the fields could reference a comment left on a specific site. Some types of activity may only use one, or none, of these fields.', 'buddypress' ) . '</p>' .
237
- '<p>' . __( '<strong>Link</strong> - Used by some types of activity (e.g blog posts and comments, and forum topics and replies) to store a link back to the original content.', 'buddypress' ) . '</p>' .
238
  '<p>' . __( '<strong>Type</strong> - Each distinct kind of activity has its own type. For example, <code>created_group</code> is used when a group is created and <code>joined_group</code> is used when a user joins a group.', 'buddypress' ) . '</p>' .
239
  '<p>' . __( 'For information about when and how BuddyPress uses all of these settings, see the Managing Activity link in the panel to the side.', 'buddypress' ) . '</p>'
240
  ) );
241
 
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="https://codex.buddypress.org/administrator-guide/activity-stream-management-panels/">Managing Activity</a>', 'buddypress' ) . '</p>' .
246
- '<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
247
  );
248
 
249
  // Register metaboxes for the edit screen.
@@ -253,27 +239,20 @@ 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
- /**
257
- * Fires after the registration of all of the default activity meta boxes.
258
- *
259
- * @since 2.4.0
260
- */
261
- do_action( 'bp_activity_admin_meta_boxes' );
262
-
263
- // Enqueue JavaScript files.
264
  wp_enqueue_script( 'postbox' );
265
  wp_enqueue_script( 'dashboard' );
266
  wp_enqueue_script( 'comment' );
267
 
268
- // Index screen.
269
  } else {
270
- // Create the Activity screen list table.
271
  $bp_activity_list_table = new BP_Activity_List_Table();
272
 
273
- // The per_page screen option.
274
  add_screen_option( 'per_page', array( 'label' => _x( 'Activity', 'Activity items per page (screen options)', 'buddypress' )) );
275
 
276
- // Help panel - overview text.
277
  get_current_screen()->add_help_tab( array(
278
  'id' => 'bp-activity-overview',
279
  'title' => __( 'Overview', 'buddypress' ),
@@ -282,7 +261,7 @@ function bp_activity_admin_load() {
282
  '<p>' . __( 'There are many different types of activities. Some are generated automatically by BuddyPress and other plugins, and some are entered directly by a user in the form of status update. To help manage the different activity types, use the filter dropdown box to switch between them.', 'buddypress' ) . '</p>'
283
  ) );
284
 
285
- // Help panel - moderation text.
286
  get_current_screen()->add_help_tab( array(
287
  'id' => 'bp-activity-moderating',
288
  'title' => __( 'Moderating Activity', 'buddypress' ),
@@ -291,79 +270,61 @@ function bp_activity_admin_load() {
291
  '<p>' . __( "In the <strong>In Response To</strong> column, if the activity was in reply to another activity, it shows that activity's author's picture and name, and a link to that activity on your live site. If there is a small bubble, the number in it shows how many other activities are related to this one; these are usually comments. Clicking the bubble will filter the activity screen to show only related activity items.", 'buddypress' ) . '</p>'
292
  ) );
293
 
294
- // Help panel - sidebar links.
295
  get_current_screen()->set_help_sidebar(
296
  '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
297
- '<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
298
  );
299
  }
300
 
301
- // Enqueue CSS and JavaScript.
302
  wp_enqueue_script( 'bp_activity_admin_js', $bp->plugin_url . "bp-activity/admin/js/admin.{$min}js", array( 'jquery', 'wp-ajax-response' ), bp_get_version(), true );
303
  wp_localize_script( 'bp_activity_admin_js', 'bp_activity_admin_vars', array(
304
  'page' => get_current_screen()->id
305
  ) );
306
  wp_enqueue_style( 'bp_activity_admin_css', $bp->plugin_url . "bp-activity/admin/css/admin.{$min}css", array(), bp_get_version() );
307
 
308
- wp_style_add_data( 'bp_activity_admin_css', 'rtl', true );
309
- if ( $min ) {
310
- wp_style_add_data( 'bp_activity_admin_css', 'suffix', $min );
311
- }
312
-
313
- /**
314
- * Fires after the activity js and style has been enqueued.
315
- *
316
- * @since 2.4.0
317
- */
318
- do_action( 'bp_activity_admin_enqueue_scripts' );
319
-
320
- // Handle spam/un-spam/delete of activities.
321
  if ( !empty( $doaction ) && ! in_array( $doaction, array( '-1', 'edit', 'save', ) ) ) {
322
 
323
- // Build redirection URL.
324
  $redirect_to = remove_query_arg( array( 'aid', 'deleted', 'error', 'spammed', 'unspammed', ), wp_get_referer() );
325
  $redirect_to = add_query_arg( 'paged', $bp_activity_list_table->get_pagenum(), $redirect_to );
326
 
327
- // Get activity IDs.
328
  $activity_ids = array_map( 'absint', (array) $_REQUEST['aid'] );
329
 
330
- /**
331
- * Filters list of IDs being spammed/un-spammed/deleted.
332
- *
333
- * @since 1.6.0
334
- *
335
- * @param array $activity_ids Activity IDs to spam/un-spam/delete.
336
- */
337
  $activity_ids = apply_filters( 'bp_activity_admin_action_activity_ids', $activity_ids );
338
 
339
  // Is this a bulk request?
340
  if ( 'bulk_' == substr( $doaction, 0, 5 ) && ! empty( $_REQUEST['aid'] ) ) {
341
- // Check this is a valid form submission.
342
  check_admin_referer( 'bulk-activities' );
343
 
344
- // Trim 'bulk_' off the action name to avoid duplicating a ton of code.
345
  $doaction = substr( $doaction, 5 );
346
 
347
  // This is a request to delete, spam, or un-spam, a single item.
348
  } elseif ( !empty( $_REQUEST['aid'] ) ) {
349
 
350
- // Check this is a valid form submission.
351
  check_admin_referer( 'spam-activity_' . $activity_ids[0] );
352
  }
353
 
354
- // Initialise counters for how many of each type of item we perform an action on.
355
  $deleted = $spammed = $unspammed = 0;
356
 
357
- // Store any errors that occurs when updating the database items.
358
  $errors = array();
359
 
360
  // "We'd like to shoot the monster, could you move, please?"
361
  foreach ( $activity_ids as $activity_id ) {
362
  // @todo: Check the permissions on each
363
  //if ( ! current_user_can( 'bp_edit_activity', $activity_id ) )
364
- // continue;
365
 
366
- // Get the activity from the database.
367
  $activity = new BP_Activity_Activity( $activity_id );
368
  if ( empty( $activity->component ) ) {
369
  $errors[] = $activity_id;
@@ -391,7 +352,7 @@ function bp_activity_admin_load() {
391
  bp_activity_mark_as_ham( $activity );
392
  $result = $activity->save();
393
 
394
- // Check for any error during activity save.
395
  if ( ! $result )
396
  $errors[] = $activity->id;
397
  else
@@ -402,7 +363,7 @@ function bp_activity_admin_load() {
402
  bp_activity_mark_as_spam( $activity );
403
  $result = $activity->save();
404
 
405
- // Check for any error during activity save.
406
  if ( ! $result )
407
  $errors[] = $activity->id;
408
  else
@@ -413,21 +374,11 @@ function bp_activity_admin_load() {
413
  break;
414
  }
415
 
416
- // Release memory.
417
  unset( $activity );
418
  }
419
 
420
- /**
421
- * Fires before redirect for plugins to do something with activity.
422
- *
423
- * Passes an activity array counts how many were spam, not spam, deleted, and IDs that were errors.
424
- *
425
- * @since 1.6.0
426
- *
427
- * @param array $value Array holding spam, not spam, deleted counts, error IDs.
428
- * @param string $redirect_to URL to redirect to.
429
- * @param array $activity_ids Original array of activity IDs.
430
- */
431
  do_action( 'bp_activity_admin_action_after', array( $spammed, $unspammed, $deleted, $errors ), $redirect_to, $activity_ids );
432
 
433
  // Add arguments to the redirect URL so that on page reload, we can easily display what we've just done.
@@ -440,87 +391,82 @@ function bp_activity_admin_load() {
440
  if ( $deleted )
441
  $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to );
442
 
443
- // If an error occurred, pass back the activity ID that failed.
444
  if ( ! empty( $errors ) )
445
  $redirect_to = add_query_arg( 'error', implode ( ',', array_map( 'absint', $errors ) ), $redirect_to );
446
 
447
- /**
448
- * Filters redirect URL after activity spamming/un-spamming/deletion occurs.
449
- *
450
- * @since 1.6.0
451
- *
452
- * @param string $redirect_to URL to redirect to.
453
- */
454
  wp_redirect( apply_filters( 'bp_activity_admin_action_redirect', $redirect_to ) );
455
  exit;
456
 
457
 
458
- // Save the edit.
459
  } elseif ( $doaction && 'save' == $doaction ) {
460
- // Build redirection URL.
461
  $redirect_to = remove_query_arg( array( 'action', 'aid', 'deleted', 'error', 'spammed', 'unspammed', ), $_SERVER['REQUEST_URI'] );
462
 
463
- // Get activity ID.
464
  $activity_id = (int) $_REQUEST['aid'];
465
 
466
- // Check this is a valid form submission.
467
  check_admin_referer( 'edit-activity_' . $activity_id );
468
 
469
- // Get the activity from the database.
470
  $activity = new BP_Activity_Activity( $activity_id );
471
 
472
- // If the activity doesn't exist, just redirect back to the index.
473
  if ( empty( $activity->component ) ) {
474
  wp_redirect( $redirect_to );
475
  exit;
476
  }
477
 
478
- // Check the form for the updated properties.
479
- // Store any error that occurs when updating the database item.
 
480
  $error = 0;
481
 
482
- // Activity spam status.
483
  $prev_spam_status = $new_spam_status = false;
484
  if ( ! empty( $_POST['activity_status'] ) ) {
485
  $prev_spam_status = $activity->is_spam;
486
  $new_spam_status = ( 'spam' == $_POST['activity_status'] ) ? true : false;
487
  }
488
 
489
- // Activity action.
490
  if ( isset( $_POST['bp-activities-action'] ) )
491
  $activity->action = $_POST['bp-activities-action'];
492
 
493
- // Activity content.
494
  if ( isset( $_POST['bp-activities-content'] ) )
495
  $activity->content = $_POST['bp-activities-content'];
496
 
497
- // Activity primary link.
498
  if ( ! empty( $_POST['bp-activities-link'] ) )
499
  $activity->primary_link = $_POST['bp-activities-link'];
500
 
501
- // Activity user ID.
502
  if ( ! empty( $_POST['bp-activities-userid'] ) )
503
  $activity->user_id = (int) $_POST['bp-activities-userid'];
504
 
505
- // Activity item primary ID.
506
  if ( isset( $_POST['bp-activities-primaryid'] ) )
507
  $activity->item_id = (int) $_POST['bp-activities-primaryid'];
508
 
509
- // Activity item secondary ID.
510
  if ( isset( $_POST['bp-activities-secondaryid'] ) )
511
  $activity->secondary_item_id = (int) $_POST['bp-activities-secondaryid'];
512
 
513
- // Activity type.
514
  if ( ! empty( $_POST['bp-activities-type'] ) ) {
515
  $actions = bp_activity_admin_get_activity_actions();
516
 
517
- // Check that the new type is a registered activity type.
518
  if ( in_array( $_POST['bp-activities-type'], $actions ) ) {
519
  $activity->type = $_POST['bp-activities-type'];
520
  }
521
  }
522
 
523
- // Activity timestamp.
524
  if ( ! empty( $_POST['aa'] ) && ! empty( $_POST['mm'] ) && ! empty( $_POST['jj'] ) && ! empty( $_POST['hh'] ) && ! empty( $_POST['mn'] ) && ! empty( $_POST['ss'] ) ) {
525
  $aa = $_POST['aa'];
526
  $mm = $_POST['mm'];
@@ -536,7 +482,7 @@ function bp_activity_admin_load() {
536
  $mn = ( $mn > 59 ) ? $mn -60 : $mn;
537
  $ss = ( $ss > 59 ) ? $ss -60 : $ss;
538
 
539
- // Reconstruct the date into a timestamp.
540
  $gmt_date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
541
 
542
  $activity->date_recorded = $gmt_date;
@@ -550,38 +496,26 @@ function bp_activity_admin_load() {
550
  bp_activity_mark_as_ham( $activity );
551
  }
552
 
553
- // Save.
554
  $result = $activity->save();
555
 
556
- // Clear the activity stream first page cache, in case this activity's timestamp was changed.
557
  wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
558
 
559
- // Check for any error during activity save.
560
  if ( false === $result )
561
  $error = $activity->id;
562
 
563
- /**
564
- * Fires before redirect so plugins can do something first on save action.
565
- *
566
- * @since 1.6.0
567
- *
568
- * @param array Array holding activity object and ID that holds error.
569
- */
570
  do_action_ref_array( 'bp_activity_admin_edit_after', array( &$activity, $error ) );
571
 
572
- // If an error occurred, pass back the activity ID that failed.
573
  if ( $error )
574
  $redirect_to = add_query_arg( 'error', (int) $error, $redirect_to );
575
  else
576
  $redirect_to = add_query_arg( 'updated', (int) $activity->id, $redirect_to );
577
 
578
- /**
579
- * Filters URL to redirect to after saving.
580
- *
581
- * @since 1.6.0
582
- *
583
- * @param string $redirect_to URL to redirect to.
584
- */
585
  wp_redirect( apply_filters( 'bp_activity_admin_edit_redirect', $redirect_to ) );
586
  exit;
587
 
@@ -596,17 +530,17 @@ function bp_activity_admin_load() {
596
  /**
597
  * Output the Activity component admin screens.
598
  *
599
- * @since 1.6.0
600
  */
601
  function bp_activity_admin() {
602
- // Decide whether to load the index or edit screen.
603
  $doaction = ! empty( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
604
 
605
- // Display the single activity edit screen.
606
  if ( 'edit' == $doaction && ! empty( $_GET['aid'] ) )
607
  bp_activity_admin_edit();
608
 
609
- // Otherwise, display the Activity index screen.
610
  else
611
  bp_activity_admin_index();
612
  }
@@ -614,7 +548,7 @@ function bp_activity_admin() {
614
  /**
615
  * Display the single activity edit screen.
616
  *
617
- * @since 1.6.0
618
  */
619
  function bp_activity_admin_edit() {
620
 
@@ -623,7 +557,7 @@ function bp_activity_admin_edit() {
623
  if ( ! is_super_admin() )
624
  die( '-1' );
625
 
626
- // Get the activity from the database.
627
  $activity = bp_activity_get( array(
628
  'in' => ! empty( $_REQUEST['aid'] ) ? (int) $_REQUEST['aid'] : 0,
629
  'max' => 1,
@@ -635,32 +569,27 @@ function bp_activity_admin_edit() {
635
  if ( ! empty( $activity['activities'][0] ) ) {
636
  $activity = $activity['activities'][0];
637
 
638
- // Workaround to use WP's touch_time() without duplicating that function.
639
  $GLOBALS['comment'] = new stdClass;
640
  $GLOBALS['comment']->comment_date = $activity->date_recorded;
641
  } else {
642
  $activity = '';
643
  }
644
 
645
- // Construct URL for form.
646
  $form_url = remove_query_arg( array( 'action', 'deleted', 'error', 'spammed', 'unspammed', ), $_SERVER['REQUEST_URI'] );
647
  $form_url = add_query_arg( 'action', 'save', $form_url );
648
 
649
- /**
650
- * Fires before activity edit form is displays so plugins can modify the activity.
651
- *
652
- * @since 1.6.0
653
- *
654
- * @param array $value Array holding single activity object that was passed by reference.
655
- */
656
  do_action_ref_array( 'bp_activity_admin_edit', array( &$activity ) ); ?>
657
 
658
  <div class="wrap">
 
659
  <h2><?php printf( __( 'Editing Activity (ID #%s)', 'buddypress' ), number_format_i18n( (int) $_REQUEST['aid'] ) ); ?></h2>
660
 
661
  <?php if ( ! empty( $activity ) ) : ?>
662
 
663
- <form action="<?php echo esc_url( $form_url ); ?>" id="bp-activities-edit-form" method="post">
664
  <div id="poststuff">
665
 
666
  <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
@@ -699,10 +628,7 @@ function bp_activity_admin_edit() {
699
  </form>
700
 
701
  <?php else : ?>
702
- <p>
703
- <?php _e( 'No activity found with this ID.', 'buddypress' ); ?>
704
- <a href="<?php echo esc_url( bp_get_admin_url( 'admin.php?page=bp-activity' ) ); ?>"><?php _e( 'Go back and try again.', 'buddypress' ); ?></a>
705
- </p>
706
  <?php endif; ?>
707
 
708
  </div><!-- .wrap -->
@@ -713,7 +639,7 @@ function bp_activity_admin_edit() {
713
  /**
714
  * Status metabox for the Activity admin edit screen.
715
  *
716
- * @since 1.6.0
717
  *
718
  * @param object $item Activity item.
719
  */
@@ -733,17 +659,17 @@ function bp_activity_admin_edit_metabox_status( $item ) {
733
 
734
  <div id="misc-publishing-actions">
735
  <div class="misc-pub-section" id="comment-status-radio">
736
- <label class="approved" for="activity-status-approved"><input type="radio" name="activity_status" id="activity-status-approved" value="ham" <?php checked( $item->is_spam, 0 ); ?>><?php _e( 'Approved', 'buddypress' ); ?></label><br />
737
- <label class="spam" for="activity-status-spam"><input type="radio" name="activity_status" id="activity-status-spam" value="spam" <?php checked( $item->is_spam, 1 ); ?>><?php _e( 'Spam', 'buddypress' ); ?></label>
738
  </div>
739
 
740
  <div class="misc-pub-section curtime misc-pub-section-last">
741
  <?php
742
- // Translators: Publish box date format, see http://php.net/date.
743
  $datef = __( 'M j, Y @ G:i', 'buddypress' );
744
  $date = date_i18n( $datef, strtotime( $item->date_recorded ) );
745
  ?>
746
- <span id="timestamp"><?php printf( __( 'Submitted on: %s', 'buddypress' ), '<strong>' . $date . '</strong>' ); ?></span>&nbsp;<a href="#edit_timestamp" class="edit-timestamp hide-if-no-js" tabindex='4'><?php _e( 'Edit', 'buddypress' ); ?></a>
747
 
748
  <div id='timestampdiv' class='hide-if-js'>
749
  <?php touch_time( 1, 0, 5 ); ?>
@@ -756,7 +682,7 @@ function bp_activity_admin_edit_metabox_status( $item ) {
756
 
757
  <div id="major-publishing-actions">
758
  <div id="publishing-action">
759
- <?php submit_button( __( 'Update', 'buddypress' ), 'primary', 'save', false ); ?>
760
  </div>
761
  <div class="clear"></div>
762
  </div><!-- #major-publishing-actions -->
@@ -769,7 +695,7 @@ function bp_activity_admin_edit_metabox_status( $item ) {
769
  /**
770
  * Primary link metabox for the Activity admin edit screen.
771
  *
772
- * @since 1.6.0
773
  *
774
  * @param object $item Activity item.
775
  */
@@ -777,8 +703,8 @@ function bp_activity_admin_edit_metabox_link( $item ) {
777
  ?>
778
 
779
  <label class="screen-reader-text" for="bp-activities-link"><?php _e( 'Link', 'buddypress' ); ?></label>
780
- <input type="url" name="bp-activities-link" id="bp-activities-link" value="<?php echo esc_url( $item->primary_link ); ?>" aria-describedby="bp-activities-link-description" />
781
- <p id="bp-activities-link-description"><?php _e( 'Activity generated by posts and comments, forum topics and replies, and some plugins, uses the link field for a permalink back to the content item.', 'buddypress' ); ?></p>
782
 
783
  <?php
784
  }
@@ -786,7 +712,7 @@ function bp_activity_admin_edit_metabox_link( $item ) {
786
  /**
787
  * User ID metabox for the Activity admin edit screen.
788
  *
789
- * @since 1.6.0
790
  *
791
  * @param object $item Activity item.
792
  */
@@ -794,7 +720,7 @@ function bp_activity_admin_edit_metabox_userid( $item ) {
794
  ?>
795
 
796
  <label class="screen-reader-text" for="bp-activities-userid"><?php _e( 'Author ID', 'buddypress' ); ?></label>
797
- <input type="number" name="bp-activities-userid" id="bp-activities-userid" value="<?php echo esc_attr( $item->user_id ); ?>" min="1" />
798
 
799
  <?php
800
  }
@@ -804,15 +730,15 @@ function bp_activity_admin_edit_metabox_userid( $item ) {
804
  *
805
  * Format is [activity_type] => Pretty name for activity type.
806
  *
807
- * @since 2.0.0
808
  *
809
- * @return array $actions
810
  */
811
  function bp_activity_admin_get_activity_actions() {
812
  $actions = array();
813
 
814
  // Walk through the registered actions, and build an array of actions/values.
815
- foreach ( bp_activity_get_actions() as $action ) {
816
  $action = array_values( (array) $action );
817
 
818
  for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ ) {
@@ -820,47 +746,47 @@ function bp_activity_admin_get_activity_actions() {
820
  }
821
  }
822
 
823
- // This was a mis-named activity type from before BP 1.6.
824
  unset( $actions['friends_register_activity_action'] );
825
 
826
- // Sort array by the human-readable value.
827
  natsort( $actions );
828
 
829
  return $actions;
830
  }
831
 
832
  /**
833
- * Activity type metabox for the Activity admin edit screen.
 
 
834
  *
835
- * @since 1.6.0
836
  *
837
  * @param object $item Activity item.
838
  */
839
  function bp_activity_admin_edit_metabox_type( $item ) {
840
- $bp = buddypress();
841
 
842
  $actions = array();
843
  $selected = $item->type;
844
 
845
  // Walk through the registered actions, and build an array of actions/values.
846
- foreach ( bp_activity_get_actions() as $action ) {
847
  $action = array_values( (array) $action );
848
 
849
  for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ )
850
  $actions[ $action[$i]['key'] ] = $action[$i]['value'];
851
  }
852
 
853
- // This was a mis-named activity type from before BP 1.6.
854
  unset( $actions['friends_register_activity_action'] );
855
 
856
- // Sort array by the human-readable value.
857
  natsort( $actions );
858
 
859
- /*
860
- * If the activity type is not registered properly (eg, a plugin has
861
- * not called bp_activity_set_action()), add the raw type to the end
862
- * of the list.
863
- */
864
  if ( ! isset( $actions[ $selected ] ) ) {
865
  _doing_it_wrong( __FUNCTION__, sprintf( __( 'This activity item has a type (%s) that is not registered using bp_activity_set_action(), so no label is available.', 'buddypress' ), $selected ), '2.0.0' );
866
  $actions[ $selected ] = $selected;
@@ -868,8 +794,7 @@ function bp_activity_admin_edit_metabox_type( $item ) {
868
 
869
  ?>
870
 
871
- <label for="bp-activities-type" class="screen-reader-text"><?php esc_html_e( 'Select activity type', 'buddypress' ); ?></label>
872
- <select name="bp-activities-type" id="bp-activities-type">
873
  <?php foreach ( $actions as $k => $v ) : ?>
874
  <option value="<?php echo esc_attr( $k ); ?>" <?php selected( $k, $selected ); ?>><?php echo esc_html( $v ); ?></option>
875
  <?php endforeach; ?>
@@ -881,7 +806,7 @@ function bp_activity_admin_edit_metabox_type( $item ) {
881
  /**
882
  * Primary item ID/Secondary item ID metabox for the Activity admin edit screen.
883
  *
884
- * @since 1.6.0
885
  *
886
  * @param object $item Activity item.
887
  */
@@ -903,17 +828,18 @@ function bp_activity_admin_edit_metabox_itemids( $item ) {
903
  /**
904
  * Display the Activity admin index screen, which contains a list of all the activities.
905
  *
906
- * @since 1.6.0
907
  *
908
- * @global BP_Activity_List_Table $bp_activity_list_table Activity screen list table.
909
- * @global string $plugin_page The current plugin page.
 
910
  */
911
  function bp_activity_admin_index() {
912
  global $bp_activity_list_table, $plugin_page;
913
 
914
  $messages = array();
915
 
916
- // If the user has just made a change to an activity item, build status messages.
917
  if ( ! empty( $_REQUEST['deleted'] ) || ! empty( $_REQUEST['spammed'] ) || ! empty( $_REQUEST['unspammed'] ) || ! empty( $_REQUEST['error'] ) || ! empty( $_REQUEST['updated'] ) ) {
918
  $deleted = ! empty( $_REQUEST['deleted'] ) ? (int) $_REQUEST['deleted'] : 0;
919
  $errors = ! empty( $_REQUEST['error'] ) ? $_REQUEST['error'] : '';
@@ -923,14 +849,14 @@ function bp_activity_admin_index() {
923
 
924
  $errors = array_map( 'absint', explode( ',', $errors ) );
925
 
926
- // Make sure we don't get any empty values in $errors.
927
  for ( $i = 0, $errors_count = count( $errors ); $i < $errors_count; $i++ ) {
928
  if ( 0 === $errors[$i] ) {
929
  unset( $errors[$i] );
930
  }
931
  }
932
 
933
- // Reindex array.
934
  $errors = array_values( $errors );
935
 
936
  if ( $deleted > 0 )
@@ -944,9 +870,9 @@ function bp_activity_admin_index() {
944
  $error_msg = __( 'Errors occurred when trying to update these activity items:', 'buddypress' );
945
  $error_msg .= '<ul class="activity-errors">';
946
 
947
- // Display each error as a list item.
948
  foreach ( $errors as $error ) {
949
- // Translators: This is a bulleted list of item IDs.
950
  $error_msg .= '<li>' . sprintf( __( '#%s', 'buddypress' ), number_format_i18n( $error ) ) . '</li>';
951
  }
952
 
@@ -962,27 +888,22 @@ function bp_activity_admin_index() {
962
  $messages[] = sprintf( _n( '%s activity item has been successfully unspammed.', '%s activity items have been successfully unspammed.', $unspammed, 'buddypress' ), number_format_i18n( $unspammed ) );
963
 
964
  if ( $updated > 0 )
965
- $messages[] = __( 'The activity item has been updated successfully.', 'buddypress' );
966
  }
967
 
968
- // Prepare the activity items for display.
969
  $bp_activity_list_table->prepare_items();
970
 
971
- /**
972
- * Fires before edit form is displayed so plugins can modify the activity messages.
973
- *
974
- * @since 1.6.0
975
- *
976
- * @param array $messages Array of messages to display at top of page.
977
- */
978
  do_action( 'bp_activity_admin_index', $messages ); ?>
979
 
980
  <div class="wrap">
 
981
  <h2>
982
  <?php if ( !empty( $_REQUEST['aid'] ) ) : ?>
983
  <?php printf( __( 'Activity related to ID #%s', 'buddypress' ), number_format_i18n( (int) $_REQUEST['aid'] ) ); ?>
984
  <?php else : ?>
985
- <?php _ex( 'Activity', 'Admin SWA page', 'buddypress' ); ?>
986
  <?php endif; ?>
987
 
988
  <?php if ( !empty( $_REQUEST['s'] ) ) : ?>
@@ -990,12 +911,12 @@ function bp_activity_admin_index() {
990
  <?php endif; ?>
991
  </h2>
992
 
993
- <?php // If the user has just made a change to an activity item, display the status messages. ?>
994
  <?php if ( !empty( $messages ) ) : ?>
995
  <div id="moderated" class="<?php echo ( ! empty( $_REQUEST['error'] ) ) ? 'error' : 'updated'; ?>"><p><?php echo implode( "<br/>\n", $messages ); ?></p></div>
996
  <?php endif; ?>
997
 
998
- <?php // Display each activity on its own row. ?>
999
  <?php $bp_activity_list_table->views(); ?>
1000
 
1001
  <form id="bp-activities-form" action="" method="get">
@@ -1004,7 +925,7 @@ function bp_activity_admin_index() {
1004
  <?php $bp_activity_list_table->display(); ?>
1005
  </form>
1006
 
1007
- <?php // This markup is used for the reply form. ?>
1008
  <table style="display: none;">
1009
  <tr id="bp-activities-container" style="display: none;">
1010
  <td colspan="4">
@@ -1017,7 +938,7 @@ function bp_activity_admin_index() {
1017
  <a href="#" class="cancel button-secondary alignleft"><?php _e( 'Cancel', 'buddypress' ); ?></a>
1018
  <a href="#" class="save button-primary alignright"><?php _e( 'Reply', 'buddypress' ); ?></a>
1019
 
1020
- <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
1021
  <span class="error" style="display:none;"></span>
1022
  <br class="clear" />
1023
  </p>
@@ -1036,54 +957,44 @@ function bp_activity_admin_index() {
1036
  /**
1037
  * List table class for the Activity component admin page.
1038
  *
1039
- * @since 1.6.0
1040
  */
1041
  class BP_Activity_List_Table extends WP_List_Table {
1042
 
1043
  /**
1044
  * What type of view is being displayed?
1045
  *
1046
- * E.g. "all", "pending", "approved", "spam"...
1047
  *
1048
- * @since 1.6.0
1049
- * @var string $view
1050
  */
1051
  public $view = 'all';
1052
 
1053
  /**
1054
  * How many activity items have been marked as spam.
1055
  *
1056
- * @since 1.6.0
1057
- * @var int $spam_count
1058
  */
1059
  public $spam_count = 0;
1060
 
1061
  /**
1062
  * Store activity-to-user-ID mappings for use in the In Response To column.
1063
  *
1064
- * @since 1.6.0
1065
- * @var array $activity_user_id
1066
  */
1067
  protected $activity_user_id = array();
1068
 
1069
- /**
1070
- * If users can comment on blog & forum activity items.
1071
- *
1072
- * @link https://buddypress.trac.wordpress.org/ticket/6277
1073
- *
1074
- * @since 2.2.2
1075
- * @var bool $disable_blogforum_comments
1076
- */
1077
- public $disable_blogforum_comments = false;
1078
-
1079
  /**
1080
  * Constructor.
1081
  *
1082
- * @since 1.6.0
1083
  */
1084
  public function __construct() {
1085
 
1086
- // See if activity commenting is enabled for blog / forum activity items.
1087
  $this->disable_blogforum_comments = bp_disable_blogforum_comments();
1088
 
1089
  // Define singular and plural labels, as well as whether we support AJAX.
@@ -1098,38 +1009,38 @@ class BP_Activity_List_Table extends WP_List_Table {
1098
  /**
1099
  * Handle filtering of data, sorting, pagination, and any other data manipulation prior to rendering.
1100
  *
1101
- * @since 1.6.0
1102
  */
1103
  function prepare_items() {
1104
 
1105
- // Option defaults.
1106
  $filter = array();
1107
  $include_id = false;
1108
  $search_terms = false;
1109
  $sort = 'DESC';
1110
  $spam = 'ham_only';
1111
 
1112
- // Set current page.
1113
  $page = $this->get_pagenum();
1114
 
1115
- // Set per page from the screen options.
1116
  $per_page = $this->get_items_per_page( str_replace( '-', '_', "{$this->screen->id}_per_page" ) );
1117
 
1118
- // Check if we're on the "Spam" view.
1119
  if ( !empty( $_REQUEST['activity_status'] ) && 'spam' == $_REQUEST['activity_status'] ) {
1120
  $spam = 'spam_only';
1121
  $this->view = 'spam';
1122
  }
1123
 
1124
- // Sort order.
1125
  if ( !empty( $_REQUEST['order'] ) && 'desc' != $_REQUEST['order'] )
1126
  $sort = 'ASC';
1127
 
1128
- // Order by.
1129
  /*if ( !empty( $_REQUEST['orderby'] ) ) {
1130
  }*/
1131
 
1132
- // Filter.
1133
  if ( !empty( $_REQUEST['activity_type'] ) )
1134
  $filter = array( 'action' => $_REQUEST['activity_type'] );
1135
 
@@ -1141,17 +1052,16 @@ class BP_Activity_List_Table extends WP_List_Table {
1141
  if ( !empty( $_REQUEST['aid'] ) )
1142
  $include_id = (int) $_REQUEST['aid'];
1143
 
1144
- // Get the spam total (ignoring any search query or filter).
1145
  $spams = bp_activity_get( array(
1146
  'display_comments' => 'stream',
1147
  'show_hidden' => true,
1148
  'spam' => 'spam_only',
1149
- 'count_total' => 'count_query',
1150
  ) );
1151
  $this->spam_count = $spams['total'];
1152
  unset( $spams );
1153
 
1154
- // Get the activities from the database.
1155
  $activities = bp_activity_get( array(
1156
  'display_comments' => 'stream',
1157
  'filter' => $filter,
@@ -1160,33 +1070,32 @@ class BP_Activity_List_Table extends WP_List_Table {
1160
  'per_page' => $per_page,
1161
  'search_terms' => $search_terms,
1162
  'show_hidden' => true,
1163
- // 'sort' => $sort,
1164
  'spam' => $spam,
1165
- 'count_total' => 'count_query',
1166
  ) );
1167
 
1168
- // If we're viewing a specific activity, flatten all activities into a single array.
1169
  if ( $include_id ) {
1170
  $activities['activities'] = BP_Activity_List_Table::flatten_activity_array( $activities['activities'] );
1171
  $activities['total'] = count( $activities['activities'] );
1172
 
1173
- // Sort the array by the activity object's date_recorded value.
1174
  usort( $activities['activities'], create_function( '$a, $b', 'return $a->date_recorded > $b->date_recorded;' ) );
1175
  }
1176
 
1177
- // The bp_activity_get function returns an array of objects; cast these to arrays for WP_List_Table.
1178
  $new_activities = array();
1179
  foreach ( $activities['activities'] as $activity_item ) {
1180
  $new_activities[] = (array) $activity_item;
1181
 
1182
- // Build an array of activity-to-user ID mappings for better efficiency in the In Response To column.
1183
  $this->activity_user_id[$activity_item->id] = $activity_item->user_id;
1184
  }
1185
 
1186
- // Set raw data to display.
1187
  $this->items = $new_activities;
1188
 
1189
- // Store information needed for handling table pagination.
1190
  $this->set_pagination_args( array(
1191
  'per_page' => $per_page,
1192
  'total_items' => $activities['total'],
@@ -1200,7 +1109,7 @@ class BP_Activity_List_Table extends WP_List_Table {
1200
  /**
1201
  * Get an array of all the columns on the page.
1202
  *
1203
- * @since 1.6.0
1204
  *
1205
  * @return array Column headers.
1206
  */
@@ -1209,27 +1118,15 @@ class BP_Activity_List_Table extends WP_List_Table {
1209
  $this->get_columns(),
1210
  array(),
1211
  $this->get_sortable_columns(),
1212
- $this->get_default_primary_column_name(),
1213
  );
1214
 
1215
  return $this->_column_headers;
1216
  }
1217
 
1218
- /**
1219
- * Get name of default primary column
1220
- *
1221
- * @since 2.3.3
1222
- *
1223
- * @return string
1224
- */
1225
- protected function get_default_primary_column_name() {
1226
- return 'author';
1227
- }
1228
-
1229
  /**
1230
  * Display a message on screen when no items are found (e.g. no search matches).
1231
  *
1232
- * @since 1.6.0
1233
  */
1234
  function no_items() {
1235
  _e( 'No activities found.', 'buddypress' );
@@ -1238,12 +1135,14 @@ class BP_Activity_List_Table extends WP_List_Table {
1238
  /**
1239
  * Output the Activity data table.
1240
  *
1241
- * @since 1.6.0
1242
- */
1243
  function display() {
 
 
1244
  $this->display_tablenav( 'top' ); ?>
1245
 
1246
- <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>" cellspacing="0">
1247
  <thead>
1248
  <tr>
1249
  <?php $this->print_column_headers(); ?>
@@ -1268,7 +1167,7 @@ class BP_Activity_List_Table extends WP_List_Table {
1268
  /**
1269
  * Generate content for a single row of the table.
1270
  *
1271
- * @since 1.6.0
1272
  *
1273
  * @param object $item The current item.
1274
  */
@@ -1297,26 +1196,16 @@ class BP_Activity_List_Table extends WP_List_Table {
1297
  /**
1298
  * Get the list of views available on this table (e.g. "all", "spam").
1299
  *
1300
- * @since 1.6.0
1301
  */
1302
  function get_views() {
1303
- $url_base = add_query_arg( array( 'page' => 'bp-activity' ), bp_get_admin_url( 'admin.php' ) ); ?>
1304
 
1305
  <ul class="subsubsub">
1306
- <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>
1307
- <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>
1308
-
1309
- <?php
1310
 
1311
- /**
1312
- * Fires inside listing of views so plugins can add their own.
1313
- *
1314
- * @since 1.6.0
1315
- *
1316
- * @param string $url_base Current URL base for view.
1317
- * @param string $view Current view being displayed.
1318
- */
1319
- do_action( 'bp_activity_list_table_get_views', $url_base, $this->view ); ?>
1320
  </ul>
1321
  <?php
1322
  }
@@ -1324,7 +1213,7 @@ class BP_Activity_List_Table extends WP_List_Table {
1324
  /**
1325
  * Get bulk actions.
1326
  *
1327
- * @since 1.6.0
1328
  *
1329
  * @return array Key/value pairs for the bulk actions dropdown.
1330
  */
@@ -1334,40 +1223,26 @@ class BP_Activity_List_Table extends WP_List_Table {
1334
  $actions['bulk_ham'] = __( 'Not Spam', 'buddypress' );
1335
  $actions['bulk_delete'] = __( 'Delete Permanently', 'buddypress' );
1336
 
1337
- /**
1338
- * Filters the default bulk actions so plugins can add custom actions.
1339
- *
1340
- * @since 1.6.0
1341
- *
1342
- * @param array $actions Default available actions for bulk operations.
1343
- */
1344
  return apply_filters( 'bp_activity_list_table_get_bulk_actions', $actions );
1345
  }
1346
 
1347
  /**
1348
  * Get the table column titles.
1349
  *
1350
- * @since 1.6.0
1351
  *
1352
  * @see WP_List_Table::single_row_columns()
1353
  *
1354
  * @return array The columns to appear in the Activity list table.
1355
  */
1356
  function get_columns() {
1357
- /**
1358
- * Filters the titles for the columns for the activity list table.
1359
- *
1360
- * @since 2.4.0
1361
- *
1362
- * @param array $value Array of slugs and titles for the columns.
1363
- */
1364
- return apply_filters( 'bp_activity_list_table_get_columns', array(
1365
  'cb' => '<input name type="checkbox" />',
1366
- 'author' => _x('Author', 'Admin SWA column header', 'buddypress' ),
1367
- 'comment' => _x( 'Activity', 'Admin SWA column header', 'buddypress' ),
1368
- 'action' => _x( 'Action', 'Admin SWA column header', 'buddypress' ),
1369
- 'response' => _x( 'In Response To', 'Admin SWA column header', 'buddypress' ),
1370
- ) );
1371
  }
1372
 
1373
  /**
@@ -1375,7 +1250,7 @@ class BP_Activity_List_Table extends WP_List_Table {
1375
  *
1376
  * Currently, returns an empty array (no columns are sortable).
1377
  *
1378
- * @since 1.6.0
1379
  * @todo For this to work, BP_Activity_Activity::get() needs updating
1380
  * to support ordering by specific fields.
1381
  *
@@ -1392,49 +1267,28 @@ class BP_Activity_List_Table extends WP_List_Table {
1392
  /**
1393
  * Markup for the "filter" part of the form (i.e. which activity type to display).
1394
  *
1395
- * @since 1.6.0
1396
  *
1397
  * @param string $which 'top' or 'bottom'.
1398
  */
1399
  function extra_tablenav( $which ) {
1400
-
1401
- // Bail on bottom table nav.
1402
- if ( 'bottom' === $which ) {
1403
  return;
1404
- }
1405
 
1406
- // Is any filter currently selected?
1407
- $selected = ( ! empty( $_REQUEST['activity_type'] ) ) ? $_REQUEST['activity_type'] : '';
1408
 
1409
- // Get the actions.
1410
- $activity_actions = bp_activity_get_actions(); ?>
 
 
1411
 
1412
  <div class="alignleft actions">
1413
- <label for="activity-type" class="screen-reader-text"><?php _e( 'Filter by activity type', 'buddypress' ); ?></label>
1414
- <select name="activity_type" id="activity-type">
1415
- <option value="" <?php selected( ! $selected ); ?>><?php _e( 'View all actions', 'buddypress' ); ?></option>
1416
-
1417
- <?php foreach ( $activity_actions as $component => $actions ) : ?>
1418
-
1419
- <optgroup label="<?php echo ucfirst( $component ); ?>">
1420
-
1421
- <?php foreach ( $actions as $action_key => $action_values ) : ?>
1422
-
1423
- <?php
1424
-
1425
- // Skip the incorrectly named pre-1.6 action.
1426
- if ( 'friends_register_activity_action' !== $action_key ) : ?>
1427
-
1428
- <option value="<?php echo esc_attr( $action_key ); ?>" <?php selected( $action_key, $selected ); ?>><?php echo esc_html( $action_values[ 'value' ] ); ?></option>
1429
-
1430
- <?php endif; ?>
1431
-
1432
- <?php endforeach; ?>
1433
-
1434
- </optgroup>
1435
 
 
 
1436
  <?php endforeach; ?>
1437
-
1438
  </select>
1439
 
1440
  <?php submit_button( __( 'Filter', 'buddypress' ), 'secondary', false, false, array( 'id' => 'post-query-submit' ) ); ?>
@@ -1443,41 +1297,10 @@ class BP_Activity_List_Table extends WP_List_Table {
1443
  <?php
1444
  }
1445
 
1446
- /**
1447
- * Override WP_List_Table::row_actions().
1448
- *
1449
- * Basically a duplicate of the row_actions() method, but removes the
1450
- * unnecessary <button> addition.
1451
- *
1452
- * @since 2.3.3
1453
- * @since 2.3.4 Visibility set to public for compatibility with WP < 4.0.0.
1454
- *
1455
- * @param array $actions The list of actions.
1456
- * @param bool $always_visible Whether the actions should be always visible.
1457
- * @return string
1458
- */
1459
- public function row_actions( $actions, $always_visible = false ) {
1460
- $action_count = count( $actions );
1461
- $i = 0;
1462
-
1463
- if ( !$action_count )
1464
- return '';
1465
-
1466
- $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
1467
- foreach ( $actions as $action => $link ) {
1468
- ++$i;
1469
- ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
1470
- $out .= "<span class='$action'>$link$sep</span>";
1471
- }
1472
- $out .= '</div>';
1473
-
1474
- return $out;
1475
- }
1476
-
1477
  /**
1478
  * Checkbox column markup.
1479
  *
1480
- * @since 1.6.0
1481
  *
1482
  * @see WP_List_Table::single_row_columns()
1483
  *
@@ -1490,7 +1313,7 @@ class BP_Activity_List_Table extends WP_List_Table {
1490
  /**
1491
  * Author column markup.
1492
  *
1493
- * @since 1.6.0
1494
  *
1495
  * @see WP_List_Table::single_row_columns()
1496
  *
@@ -1503,7 +1326,7 @@ class BP_Activity_List_Table extends WP_List_Table {
1503
  /**
1504
  * Action column markup.
1505
  *
1506
- * @since 2.0.0
1507
  *
1508
  * @see WP_List_Table::single_row_columns()
1509
  *
@@ -1524,20 +1347,20 @@ class BP_Activity_List_Table extends WP_List_Table {
1524
  *
1525
  * Called "comment" in the CSS so we can re-use some WP core CSS.
1526
  *
1527
- * @since 1.6.0
1528
  *
1529
  * @see WP_List_Table::single_row_columns()
1530
  *
1531
  * @param array $item A singular item (one full row).
1532
  */
1533
  function column_comment( $item ) {
1534
- // Determine what type of item (row) we're dealing with.
1535
  if ( $item['is_spam'] )
1536
  $item_status = 'spam';
1537
  else
1538
  $item_status = 'all';
1539
 
1540
- // Preorder items: Reply | Edit | Spam | Delete Permanently.
1541
  $actions = array(
1542
  'reply' => '',
1543
  'edit' => '',
@@ -1545,7 +1368,7 @@ class BP_Activity_List_Table extends WP_List_Table {
1545
  'delete' => '',
1546
  );
1547
 
1548
- // Build actions URLs.
1549
  $base_url = bp_get_admin_url( 'admin.php?page=bp-activity&amp;aid=' . $item['id'] );
1550
  $spam_nonce = esc_html( '_wpnonce=' . wp_create_nonce( 'spam-activity_' . $item['id'] ) );
1551
 
@@ -1554,8 +1377,9 @@ class BP_Activity_List_Table extends WP_List_Table {
1554
  $ham_url = $base_url . "&amp;action=ham&amp;$spam_nonce";
1555
  $spam_url = $base_url . "&amp;action=spam&amp;$spam_nonce";
1556
 
1557
- // Rollover actions.
1558
- // Reply - JavaScript only; implemented by AJAX.
 
1559
  if ( 'spam' != $item_status ) {
1560
  if ( $this->can_comment( $item ) ) {
1561
  $actions['reply'] = sprintf( '<a href="#" class="reply hide-if-no-js">%s</a>', __( 'Reply', 'buddypress' ) );
@@ -1563,152 +1387,70 @@ class BP_Activity_List_Table extends WP_List_Table {
1563
  $actions['reply'] = sprintf( '<span class="form-input-tip" title="%s">%s</span>', __( 'Replies are disabled for this activity item', 'buddypress' ), __( 'Replies disabled', 'buddypress' ) );
1564
  }
1565
 
1566
- // Edit.
1567
  $actions['edit'] = sprintf( '<a href="%s">%s</a>', $edit_url, __( 'Edit', 'buddypress' ) );
1568
  }
1569
 
1570
- // Spam/unspam.
1571
  if ( 'spam' == $item_status )
1572
  $actions['unspam'] = sprintf( '<a href="%s">%s</a>', $ham_url, __( 'Not Spam', 'buddypress' ) );
1573
  else
1574
  $actions['spam'] = sprintf( '<a href="%s">%s</a>', $spam_url, __( 'Spam', 'buddypress' ) );
1575
 
1576
- // Delete.
1577
  $actions['delete'] = sprintf( '<a href="%s" onclick="%s">%s</a>', $delete_url, "javascript:return confirm('" . esc_js( __( 'Are you sure?', 'buddypress' ) ) . "'); ", __( 'Delete Permanently', 'buddypress' ) );
1578
 
1579
- // Start timestamp.
1580
  echo '<div class="submitted-on">';
1581
 
1582
- /**
1583
- * Filters available actions for plugins to alter.
1584
- *
1585
- * @since 1.6.0
1586
- *
1587
- * @param array $actions Array of available actions user could use.
1588
- * @param array $item Current item being added to page.
1589
- */
1590
  $actions = apply_filters( 'bp_activity_admin_comment_row_actions', array_filter( $actions ), $item );
1591
 
1592
  /* translators: 2: activity admin ui date/time */
1593
- printf(
1594
- __( 'Submitted on <a href="%1$s">%2$s at %3$s</a>', 'buddypress' ),
1595
- bp_activity_get_permalink( $item['id'] ),
1596
- date_i18n( bp_get_option( 'date_format' ), strtotime( $item['date_recorded'] ) ),
1597
- get_date_from_gmt( $item['date_recorded'], bp_get_option( 'time_format' ) )
1598
- );
1599
 
1600
- // End timestamp.
1601
  echo '</div>';
1602
 
1603
- // Get activity content - if not set, use the action.
1604
  if ( ! empty( $item['content'] ) ) {
1605
-
1606
- /**
1607
- * Filters current activity item content.
1608
- *
1609
- * @since 1.2.0
1610
- *
1611
- * @param array $item Array index holding current activity item content.
1612
- */
1613
  $content = apply_filters_ref_array( 'bp_get_activity_content_body', array( $item['content'] ) );
1614
  } else {
1615
- /**
1616
- * Filters current activity item action.
1617
- *
1618
- * @since 1.2.0
1619
- *
1620
- * @var array $item Array index holding current activity item action.
1621
- */
1622
  $content = apply_filters_ref_array( 'bp_get_activity_action', array( $item['action'] ) );
1623
  }
1624
 
1625
- /**
1626
- * Filter here to add extra output to the activity content into the Administration.
1627
- *
1628
- * @since 2.4.0
1629
- *
1630
- * @param string $content The activity content.
1631
- * @param array $item The activity object converted into an array.
1632
- */
1633
- echo apply_filters( 'bp_activity_admin_comment_content', $content, $item ) . ' ' . $this->row_actions( $actions );
1634
  }
1635
 
1636
  /**
1637
  * "In response to" column markup.
1638
  *
1639
- * @since 1.6.0
1640
  *
1641
  * @see WP_List_Table::single_row_columns()
1642
  *
1643
  * @param array $item A singular item (one full row).
1644
  */
1645
  function column_response( $item ) {
1646
-
1647
  // Is $item is a root activity?
1648
- ?>
1649
-
1650
- <div class="response-links">
1651
-
1652
- <?php
1653
- // Activity permalink
1654
- $activity_permalink = '';
1655
- if ( ! $item['is_spam'] ) {
1656
- $activity_permalink = '<a href="' . bp_activity_get_permalink( $item['id'], (object) $item ) . '" class="comments-view-item-link">' . __( 'View Activity', 'buddypress' ) . '</a>';
1657
- }
1658
-
1659
- /**
1660
- * Filters default list of default root activity types.
1661
- *
1662
- * @since 1.6.0
1663
- *
1664
- * @param array $value Array of default activity types.
1665
- * @param array $item Current item being displayed.
1666
- */
1667
  if ( empty( $item['item_id'] ) || ! in_array( $item['type'], apply_filters( 'bp_activity_admin_root_activity_types', array( 'activity_comment' ), $item ) ) ) {
1668
- echo $activity_permalink;
1669
-
1670
  $comment_count = !empty( $item['children'] ) ? bp_activity_recurse_comment_count( (object) $item ) : 0;
1671
  $root_activity_url = bp_get_admin_url( 'admin.php?page=bp-activity&amp;aid=' . $item['id'] );
1672
 
1673
- // If the activity has comments, display a link to the activity's permalink, with its comment count in a speech bubble.
1674
  if ( $comment_count ) {
1675
  $title_attr = sprintf( _n( '%s related activity', '%s related activities', $comment_count, 'buddypress' ), number_format_i18n( $comment_count ) );
1676
- printf( '<a href="%1$s" title="%2$s" class="post-com-count post-com-count-approved"><span class="comment-count comment-count-approved">%3$s</span></a>', esc_url( $root_activity_url ), esc_attr( $title_attr ), number_format_i18n( $comment_count ) );
1677
  }
1678
 
1679
- // For non-root activities, display a link to the replied-to activity's author's profile.
1680
  } else {
1681
  echo '<strong>' . get_avatar( $this->get_activity_user_id( $item['item_id'] ), '32' ) . ' ' . bp_core_get_userlink( $this->get_activity_user_id( $item['item_id'] ) ) . '</strong><br />';
1682
- echo $activity_permalink;
1683
  }
1684
- ?>
1685
-
1686
- </div>
1687
 
1688
- <?php
1689
- }
1690
-
1691
- /**
1692
- * Allow plugins to add their custom column.
1693
- *
1694
- * @since 2.4.0
1695
- *
1696
- * @param array $item Information about the current row.
1697
- * @param string $column_name The column name.
1698
- * @return string
1699
- */
1700
- public function column_default( $item = array(), $column_name = '' ) {
1701
-
1702
- /**
1703
- * Filters a string to allow plugins to add custom column content.
1704
- *
1705
- * @since 2.4.0
1706
- *
1707
- * @param string $value Empty string.
1708
- * @param string $column_name Name of the column being rendered.
1709
- * @param array $item The current activity item in the loop.
1710
- */
1711
- return apply_filters( 'bp_activity_admin_get_custom_column', '', $column_name, $item );
1712
  }
1713
 
1714
  /**
@@ -1717,7 +1459,7 @@ class BP_Activity_List_Table extends WP_List_Table {
1717
  * Wraps bp_activity_get_specific(), with some additional logic for
1718
  * avoiding duplicate queries.
1719
  *
1720
- * @since 1.6.0
1721
  *
1722
  * @param int $activity_id Activity ID to retrieve User ID for.
1723
  * @return int User ID of the activity item in question.
@@ -1727,24 +1469,24 @@ class BP_Activity_List_Table extends WP_List_Table {
1727
  if ( ! empty( $this->activity_user_id[$activity_id] ) ) {
1728
  return $this->activity_user_id[$activity_id];
1729
 
1730
- /*
1731
  * We don't have a mapping. This means the $activity_id is not on the current
1732
  * page of results, so fetch its details from the database.
1733
  */
1734
  } else {
1735
  $activity = bp_activity_get_specific( array( 'activity_ids' => $activity_id, 'show_hidden' => true, 'spam' => 'all', ) );
1736
 
1737
- /*
1738
  * If, somehow, the referenced activity has been deleted, leaving its associated
1739
- * activities as orphans, use the logged in user's ID to avoid errors.
1740
  */
1741
  if ( empty( $activity['activities'] ) )
1742
  return bp_loggedin_user_id();
1743
 
1744
- // Store the new activity/user ID mapping for any later re-use.
1745
  $this->activity_user_id[ $activity['activities'][0]->id ] = $activity['activities'][0]->user_id;
1746
 
1747
- // Return the user ID.
1748
  return $activity['activities'][0]->user_id;
1749
  }
1750
  }
@@ -1753,14 +1495,14 @@ class BP_Activity_List_Table extends WP_List_Table {
1753
  * Checks if an activity item can be replied to.
1754
  *
1755
  * This method merges functionality from {@link bp_activity_can_comment()} and
1756
- * {@link bp_blogs_disable_activity_commenting()}. This is done because the activity
1757
  * list table doesn't use a BuddyPress activity loop, which prevents those
1758
  * functions from working as intended.
1759
  *
1760
- * @since 2.0.0
1761
  *
1762
  * @param array $item An array version of the BP_Activity_Activity object.
1763
- * @return bool $can_comment
1764
  */
1765
  protected function can_comment( $item ) {
1766
  $can_comment = true;
@@ -1775,25 +1517,25 @@ class BP_Activity_List_Table extends WP_List_Table {
1775
  break;
1776
  }
1777
 
1778
- // Activity comments supported.
1779
  } else {
1780
- // Activity comment.
1781
  if ( 'activity_comment' == $item['type'] ) {
1782
- // Blogs.
1783
  if ( bp_is_active( 'blogs' ) ) {
1784
- // Grab the parent activity entry.
1785
  $parent_activity = new BP_Activity_Activity( $item['item_id'] );
1786
 
1787
- // Fetch blog post comment depth and if the blog post's comments are open.
1788
  bp_blogs_setup_activity_loop_globals( $parent_activity );
1789
 
1790
- // Check if the activity item can be replied to.
1791
  if ( false === bp_blogs_can_comment_reply( true, $item ) ) {
1792
  $can_comment = false;
1793
  }
1794
  }
1795
 
1796
- // Blog post.
1797
  } elseif ( 'new_blog_post' == $item['type'] ) {
1798
  if ( bp_is_active( 'blogs' ) ) {
1799
  bp_blogs_setup_activity_loop_globals( (object) $item );
@@ -1805,13 +1547,6 @@ class BP_Activity_List_Table extends WP_List_Table {
1805
  }
1806
  }
1807
 
1808
- /**
1809
- * Filters if an activity item can be commented on or not.
1810
- *
1811
- * @since 2.0.0
1812
- *
1813
- * @param bool $can_comment Whether an activity item can be commented on or not.
1814
- */
1815
  return apply_filters( 'bp_activity_list_table_can_comment', $can_comment );
1816
  }
1817
 
@@ -1821,7 +1556,7 @@ class BP_Activity_List_Table extends WP_List_Table {
1821
  * In some cases, BuddyPress gives us a structured tree of activity
1822
  * items plus their comments. This method converts it to a flat array.
1823
  *
1824
- * @since 1.6.0
1825
  *
1826
  * @param array $tree Source array.
1827
  * @return array Flattened array.
6
  * help text, on which this implementation is heavily based.
7
  *
8
  * @package BuddyPress
9
+ * @since BuddyPress (1.6.0)
10
+ * @subpackage Activity
11
  */
12
 
13
+ // Exit if accessed directly
14
+ if ( !defined( 'ABSPATH' ) ) exit;
15
 
16
+ // Include WP's list table class
17
  if ( !class_exists( 'WP_List_Table' ) ) require( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
18
 
19
+ // per_page screen option. Has to be hooked in extremely early.
20
  if ( is_admin() && ! empty( $_REQUEST['page'] ) && 'bp-activity' == $_REQUEST['page'] )
21
  add_filter( 'set-screen-option', 'bp_activity_admin_screen_options', 10, 3 );
22
 
23
  /**
24
  * Register the Activity component admin screen.
25
  *
26
+ * @since BuddyPress (1.6)
27
  */
28
  function bp_activity_add_admin_menu() {
29
 
30
+ // Add our screen
31
  $hook = add_menu_page(
32
+ __( 'Activity', 'buddypress' ),
33
+ __( 'Activity', 'buddypress' ),
34
  'bp_moderate',
35
  'bp-activity',
36
  'bp_activity_admin',
49
  * which all appear together in the middle of the Dashboard menu. This function
50
  * adds the Activity page to the array of these menu items.
51
  *
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' );
66
  * Processes requests to add new activity comments, and echoes HTML for a new
67
  * table row.
68
  *
69
+ * @since BuddyPress (1.6.0)
70
  */
71
  function bp_activity_admin_reply() {
72
+ // Check nonce
73
  check_ajax_referer( 'bp-activity-admin-reply', '_ajax_nonce-bp-activity-admin-reply' );
74
 
75
  $parent_id = ! empty( $_REQUEST['parent_id'] ) ? (int) $_REQUEST['parent_id'] : 0;
79
  if ( empty( $parent_id ) )
80
  die( '-1' );
81
 
82
+ // If $root_id not set (e.g. for root items), use $parent_id
83
  if ( empty( $root_id ) )
84
  $root_id = $parent_id;
85
 
86
+ // Check that a reply has been entered
87
  if ( empty( $_REQUEST['content'] ) )
88
  die( __( 'ERROR: Please type a reply.', 'buddypress' ) );
89
 
90
+ // Check parent activity exists
91
  $parent_activity = new BP_Activity_Activity( $parent_id );
92
  if ( empty( $parent_activity->component ) )
93
  die( __( 'ERROR: The item you are trying to reply to cannot be found, or it has been deleted.', 'buddypress' ) );
97
  if ( ! current_user_can( 'bp_moderate' ) )
98
  die( '-1' );
99
 
100
+ // Add new activity comment
101
  $new_activity_id = bp_activity_new_comment( array(
102
+ 'activity_id' => $root_id, // ID of the root activity item
103
  'content' => $_REQUEST['content'],
104
+ 'parent_id' => $parent_id, // ID of a parent comment
105
  ) );
106
 
107
+ // Fetch the new activity item, as we need it to create table markup to return
108
  $new_activity = new BP_Activity_Activity( $new_activity_id );
109
 
110
+ // This needs to be set for the BP_Activity_List_Table constructor to work
111
  set_current_screen( 'toplevel_page_bp-activity' );
112
 
113
+ // Set up an output buffer
114
  ob_start();
115
  $list_table = new BP_Activity_List_Table();
116
  $list_table->single_row( (array) $new_activity );
117
 
118
+ // Get table markup
119
  $response = array(
120
  'data' => ob_get_contents(),
121
  'id' => $new_activity_id,
124
  );
125
  ob_end_clean();
126
 
127
+ // Send response
128
  $r = new WP_Ajax_Response();
129
  $r->add( $response );
130
  $r->send();
136
  /**
137
  * Handle save/update of screen options for the Activity component admin screen.
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
  */
148
  if ( 'toplevel_page_bp_activity_per_page' != $option && 'toplevel_page_bp_activity_network_per_page' != $option )
149
  return $value;
150
 
151
+ // Per page
152
  $new_value = (int) $new_value;
153
  if ( $new_value < 1 || $new_value > 999 )
154
  return $value;
159
  /**
160
  * Hide the advanced edit meta boxes by default, so we don't clutter the screen.
161
  *
162
+ * @since BuddyPress (1.6.0)
163
  *
 
164
  * @param WP_Screen $screen Screen identifier.
165
  * @return array Hidden Meta Boxes.
166
  */
168
  if ( empty( $screen->id ) || 'toplevel_page_bp-activity' != $screen->id && 'toplevel_page_bp-activity_network' != $screen->id )
169
  return $hidden;
170
 
171
+ // Hide the primary link meta box by default
172
  $hidden = array_merge( (array) $hidden, array( 'bp_activity_itemids', 'bp_activity_link', 'bp_activity_type', 'bp_activity_userid', ) );
173
 
 
 
 
 
 
 
 
 
174
  return apply_filters( 'bp_hide_meta_boxes', array_unique( $hidden ), $screen );
175
  }
176
  add_filter( 'default_hidden_meta_boxes', 'bp_activity_admin_edit_hidden_metaboxes', 10, 2 );
180
  *
181
  * Does the following:
182
  * - Register contextual help and screen options for this admin page.
183
+ * - Enqueues scripts and styles
184
+ * - Catches POST and GET requests related to Activity
185
  *
186
+ * @since BuddyPress (1.6.0)
187
  *
188
+ * @global object $bp BuddyPress global settings.
189
  * @global BP_Activity_List_Table $bp_activity_list_table Activity screen list table.
190
  */
191
  function bp_activity_admin_load() {
193
 
194
  $bp = buddypress();
195
 
196
+ // Decide whether to load the dev version of the CSS and JavaScript
197
  $min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : 'min.';
198
 
199
  $doaction = bp_admin_list_table_current_bulk_action();
200
 
201
+ // Call an action for plugins to hook in early
 
 
 
 
 
 
202
  do_action( 'bp_activity_admin_load', $doaction );
203
 
204
+ // Edit screen
205
  if ( 'edit' == $doaction && ! empty( $_GET['aid'] ) ) {
206
+ // columns screen option
207
  add_screen_option( 'layout_columns', array( 'default' => 2, 'max' => 2, ) );
208
 
209
  get_current_screen()->add_help_tab( array(
220
  'title' => __( 'Item, Link, Type', 'buddypress' ),
221
  'content' =>
222
  '<p>' . __( '<strong>Primary Item/Secondary Item</strong> - These identify the object that created the activity. For example, the fields could reference a comment left on a specific site. Some types of activity may only use one, or none, of these fields.', 'buddypress' ) . '</p>' .
223
+ '<p>' . __( '<strong>Link</strong> - Activity generated by posts and comments, forum topics and replies, and some plugins, uses the link field for a permalink back to the content item. Some types of activity may not use this field, even if it has been set.', 'buddypress' ) . '</p>' .
224
  '<p>' . __( '<strong>Type</strong> - Each distinct kind of activity has its own type. For example, <code>created_group</code> is used when a group is created and <code>joined_group</code> is used when a user joins a group.', 'buddypress' ) . '</p>' .
225
  '<p>' . __( 'For information about when and how BuddyPress uses all of these settings, see the Managing Activity link in the panel to the side.', 'buddypress' ) . '</p>'
226
  ) );
227
 
228
+ // Help panel - sidebar links
229
  get_current_screen()->set_help_sidebar(
230
  '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
231
+ '<p>' . __( '<a href="http://codex.buddypress.org/buddypress-site-administration/managing-activity/">Managing Activity</a>', 'buddypress' ) . '</p>' .
232
+ '<p>' . __( '<a href="http://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
233
  );
234
 
235
  // Register metaboxes for the edit screen.
239
  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' );
240
  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' );
241
 
242
+ // Enqueue javascripts
 
 
 
 
 
 
 
243
  wp_enqueue_script( 'postbox' );
244
  wp_enqueue_script( 'dashboard' );
245
  wp_enqueue_script( 'comment' );
246
 
247
+ // Index screen
248
  } else {
249
+ // Create the Activity screen list table
250
  $bp_activity_list_table = new BP_Activity_List_Table();
251
 
252
+ // per_page screen option
253
  add_screen_option( 'per_page', array( 'label' => _x( 'Activity', 'Activity items per page (screen options)', 'buddypress' )) );
254
 
255
+ // Help panel - overview text
256
  get_current_screen()->add_help_tab( array(
257
  'id' => 'bp-activity-overview',
258
  'title' => __( 'Overview', 'buddypress' ),
261
  '<p>' . __( 'There are many different types of activities. Some are generated automatically by BuddyPress and other plugins, and some are entered directly by a user in the form of status update. To help manage the different activity types, use the filter dropdown box to switch between them.', 'buddypress' ) . '</p>'
262
  ) );
263
 
264
+ // Help panel - moderation text
265
  get_current_screen()->add_help_tab( array(
266
  'id' => 'bp-activity-moderating',
267
  'title' => __( 'Moderating Activity', 'buddypress' ),
270
  '<p>' . __( "In the <strong>In Response To</strong> column, if the activity was in reply to another activity, it shows that activity's author's picture and name, and a link to that activity on your live site. If there is a small bubble, the number in it shows how many other activities are related to this one; these are usually comments. Clicking the bubble will filter the activity screen to show only related activity items.", 'buddypress' ) . '</p>'
271
  ) );
272
 
273
+ // Help panel - sidebar links
274
  get_current_screen()->set_help_sidebar(
275
  '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
276
+ '<p>' . __( '<a href="http://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
277
  );
278
  }
279
 
280
+ // Enqueue CSS and JavaScript
281
  wp_enqueue_script( 'bp_activity_admin_js', $bp->plugin_url . "bp-activity/admin/js/admin.{$min}js", array( 'jquery', 'wp-ajax-response' ), bp_get_version(), true );
282
  wp_localize_script( 'bp_activity_admin_js', 'bp_activity_admin_vars', array(
283
  'page' => get_current_screen()->id
284
  ) );
285
  wp_enqueue_style( 'bp_activity_admin_css', $bp->plugin_url . "bp-activity/admin/css/admin.{$min}css", array(), bp_get_version() );
286
 
287
+ // Handle spam/un-spam/delete of activities
 
 
 
 
 
 
 
 
 
 
 
 
288
  if ( !empty( $doaction ) && ! in_array( $doaction, array( '-1', 'edit', 'save', ) ) ) {
289
 
290
+ // Build redirection URL
291
  $redirect_to = remove_query_arg( array( 'aid', 'deleted', 'error', 'spammed', 'unspammed', ), wp_get_referer() );
292
  $redirect_to = add_query_arg( 'paged', $bp_activity_list_table->get_pagenum(), $redirect_to );
293
 
294
+ // Get activity IDs
295
  $activity_ids = array_map( 'absint', (array) $_REQUEST['aid'] );
296
 
297
+ // Call a filter for plugins to modify the requested activities to load
 
 
 
 
 
 
298
  $activity_ids = apply_filters( 'bp_activity_admin_action_activity_ids', $activity_ids );
299
 
300
  // Is this a bulk request?
301
  if ( 'bulk_' == substr( $doaction, 0, 5 ) && ! empty( $_REQUEST['aid'] ) ) {
302
+ // Check this is a valid form submission
303
  check_admin_referer( 'bulk-activities' );
304
 
305
+ // Trim 'bulk_' off the action name to avoid duplicating a ton of code
306
  $doaction = substr( $doaction, 5 );
307
 
308
  // This is a request to delete, spam, or un-spam, a single item.
309
  } elseif ( !empty( $_REQUEST['aid'] ) ) {
310
 
311
+ // Check this is a valid form submission
312
  check_admin_referer( 'spam-activity_' . $activity_ids[0] );
313
  }
314
 
315
+ // Initialise counters for how many of each type of item we perform an action on
316
  $deleted = $spammed = $unspammed = 0;
317
 
318
+ // Store any errors that occurs when updating the database items
319
  $errors = array();
320
 
321
  // "We'd like to shoot the monster, could you move, please?"
322
  foreach ( $activity_ids as $activity_id ) {
323
  // @todo: Check the permissions on each
324
  //if ( ! current_user_can( 'bp_edit_activity', $activity_id ) )
325
+ // continue;
326
 
327
+ // Get the activity from the database
328
  $activity = new BP_Activity_Activity( $activity_id );
329
  if ( empty( $activity->component ) ) {
330
  $errors[] = $activity_id;
352
  bp_activity_mark_as_ham( $activity );
353
  $result = $activity->save();
354
 
355
+ // Check for any error during activity save
356
  if ( ! $result )
357
  $errors[] = $activity->id;
358
  else
363
  bp_activity_mark_as_spam( $activity );
364
  $result = $activity->save();
365
 
366
+ // Check for any error during activity save
367
  if ( ! $result )
368
  $errors[] = $activity->id;
369
  else
374
  break;
375
  }
376
 
377
+ // Release memory
378
  unset( $activity );
379
  }
380
 
381
+ // Call actions for plugins to do something before we redirect
 
 
 
 
 
 
 
 
 
 
382
  do_action( 'bp_activity_admin_action_after', array( $spammed, $unspammed, $deleted, $errors ), $redirect_to, $activity_ids );
383
 
384
  // Add arguments to the redirect URL so that on page reload, we can easily display what we've just done.
391
  if ( $deleted )
392
  $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to );
393
 
394
+ // If an error occurred, pass back the activity ID that failed
395
  if ( ! empty( $errors ) )
396
  $redirect_to = add_query_arg( 'error', implode ( ',', array_map( 'absint', $errors ) ), $redirect_to );
397
 
398
+ // Redirect
 
 
 
 
 
 
399
  wp_redirect( apply_filters( 'bp_activity_admin_action_redirect', $redirect_to ) );
400
  exit;
401
 
402
 
403
+ // Save the edit
404
  } elseif ( $doaction && 'save' == $doaction ) {
405
+ // Build redirection URL
406
  $redirect_to = remove_query_arg( array( 'action', 'aid', 'deleted', 'error', 'spammed', 'unspammed', ), $_SERVER['REQUEST_URI'] );
407
 
408
+ // Get activity ID
409
  $activity_id = (int) $_REQUEST['aid'];
410
 
411
+ // Check this is a valid form submission
412
  check_admin_referer( 'edit-activity_' . $activity_id );
413
 
414
+ // Get the activity from the database
415
  $activity = new BP_Activity_Activity( $activity_id );
416
 
417
+ // If the activity doesn't exist, just redirect back to the index
418
  if ( empty( $activity->component ) ) {
419
  wp_redirect( $redirect_to );
420
  exit;
421
  }
422
 
423
+ // Check the form for the updated properties
424
+
425
+ // Store any error that occurs when updating the database item
426
  $error = 0;
427
 
428
+ // Activity spam status
429
  $prev_spam_status = $new_spam_status = false;
430
  if ( ! empty( $_POST['activity_status'] ) ) {
431
  $prev_spam_status = $activity->is_spam;
432
  $new_spam_status = ( 'spam' == $_POST['activity_status'] ) ? true : false;
433
  }
434
 
435
+ // Activity action
436
  if ( isset( $_POST['bp-activities-action'] ) )
437
  $activity->action = $_POST['bp-activities-action'];
438
 
439
+ // Activity content
440
  if ( isset( $_POST['bp-activities-content'] ) )
441
  $activity->content = $_POST['bp-activities-content'];
442
 
443
+ // Activity primary link
444
  if ( ! empty( $_POST['bp-activities-link'] ) )
445
  $activity->primary_link = $_POST['bp-activities-link'];
446
 
447
+ // Activity user ID
448
  if ( ! empty( $_POST['bp-activities-userid'] ) )
449
  $activity->user_id = (int) $_POST['bp-activities-userid'];
450
 
451
+ // Activity item primary ID
452
  if ( isset( $_POST['bp-activities-primaryid'] ) )
453
  $activity->item_id = (int) $_POST['bp-activities-primaryid'];
454
 
455
+ // Activity item secondary ID
456
  if ( isset( $_POST['bp-activities-secondaryid'] ) )
457
  $activity->secondary_item_id = (int) $_POST['bp-activities-secondaryid'];
458
 
459
+ // Activity type
460
  if ( ! empty( $_POST['bp-activities-type'] ) ) {
461
  $actions = bp_activity_admin_get_activity_actions();
462
 
463
+ // Check that the new type is a registered activity type
464
  if ( in_array( $_POST['bp-activities-type'], $actions ) ) {
465
  $activity->type = $_POST['bp-activities-type'];
466
  }
467
  }
468
 
469
+ // Activity timestamp
470
  if ( ! empty( $_POST['aa'] ) && ! empty( $_POST['mm'] ) && ! empty( $_POST['jj'] ) && ! empty( $_POST['hh'] ) && ! empty( $_POST['mn'] ) && ! empty( $_POST['ss'] ) ) {
471
  $aa = $_POST['aa'];
472
  $mm = $_POST['mm'];
482
  $mn = ( $mn > 59 ) ? $mn -60 : $mn;
483
  $ss = ( $ss > 59 ) ? $ss -60 : $ss;
484
 
485
+ // Reconstruct the date into a timestamp
486
  $gmt_date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
487
 
488
  $activity->date_recorded = $gmt_date;
496
  bp_activity_mark_as_ham( $activity );
497
  }
498
 
499
+ // Save
500
  $result = $activity->save();
501
 
502
+ // Clear the activity stream first page cache, in case this activity's timestamp was changed
503
  wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
504
 
505
+ // Check for any error during activity save
506
  if ( false === $result )
507
  $error = $activity->id;
508
 
509
+ // Call actions for plugins to do something before we redirect
 
 
 
 
 
 
510
  do_action_ref_array( 'bp_activity_admin_edit_after', array( &$activity, $error ) );
511
 
512
+ // If an error occurred, pass back the activity ID that failed
513
  if ( $error )
514
  $redirect_to = add_query_arg( 'error', (int) $error, $redirect_to );
515
  else
516
  $redirect_to = add_query_arg( 'updated', (int) $activity->id, $redirect_to );
517
 
518
+ // Redirect
 
 
 
 
 
 
519
  wp_redirect( apply_filters( 'bp_activity_admin_edit_redirect', $redirect_to ) );
520
  exit;
521
 
530
  /**
531
  * Output the Activity component admin screens.
532
  *
533
+ * @since BuddyPress (1.6.0)
534
  */
535
  function bp_activity_admin() {
536
+ // Decide whether to load the index or edit screen
537
  $doaction = ! empty( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
538
 
539
+ // Display the single activity edit screen
540
  if ( 'edit' == $doaction && ! empty( $_GET['aid'] ) )
541
  bp_activity_admin_edit();
542
 
543
+ // Otherwise, display the Activity index screen
544
  else
545
  bp_activity_admin_index();
546
  }
548
  /**
549
  * Display the single activity edit screen.
550
  *
551
+ * @since BuddyPress (1.6.0)
552
  */
553
  function bp_activity_admin_edit() {
554
 
557
  if ( ! is_super_admin() )
558
  die( '-1' );
559
 
560
+ // Get the activity from the database
561
  $activity = bp_activity_get( array(
562
  'in' => ! empty( $_REQUEST['aid'] ) ? (int) $_REQUEST['aid'] : 0,
563
  'max' => 1,
569
  if ( ! empty( $activity['activities'][0] ) ) {
570
  $activity = $activity['activities'][0];
571
 
572
+ // Workaround to use WP's touch_time() without duplicating that function
573
  $GLOBALS['comment'] = new stdClass;
574
  $GLOBALS['comment']->comment_date = $activity->date_recorded;
575
  } else {
576
  $activity = '';
577
  }
578
 
579
+ // Construct URL for form
580
  $form_url = remove_query_arg( array( 'action', 'deleted', 'error', 'spammed', 'unspammed', ), $_SERVER['REQUEST_URI'] );
581
  $form_url = add_query_arg( 'action', 'save', $form_url );
582
 
583
+ // Call an action for plugins to modify the activity before we display the edit form
 
 
 
 
 
 
584
  do_action_ref_array( 'bp_activity_admin_edit', array( &$activity ) ); ?>
585
 
586
  <div class="wrap">
587
+ <?php screen_icon( 'buddypress-activity' ); ?>
588
  <h2><?php printf( __( 'Editing Activity (ID #%s)', 'buddypress' ), number_format_i18n( (int) $_REQUEST['aid'] ) ); ?></h2>
589
 
590
  <?php if ( ! empty( $activity ) ) : ?>
591
 
592
+ <form action="<?php echo esc_attr( $form_url ); ?>" id="bp-activities-edit-form" method="post">
593
  <div id="poststuff">
594
 
595
  <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
628
  </form>
629
 
630
  <?php else : ?>
631
+ <p><?php printf( __( 'No activity found with this ID. <a href="%s">Go back and try again</a>.', 'buddypress' ), esc_url( bp_get_admin_url( 'admin.php?page=bp-activity' ) ) ); ?></p>
 
 
 
632
  <?php endif; ?>
633
 
634
  </div><!-- .wrap -->
639
  /**
640
  * Status metabox for the Activity admin edit screen.
641
  *
642
+ * @since BuddyPress (1.6.0)
643
  *
644
  * @param object $item Activity item.
645
  */
659
 
660
  <div id="misc-publishing-actions">
661
  <div class="misc-pub-section" id="comment-status-radio">
662
+ <label class="approved"><input type="radio" name="activity_status" value="ham" <?php checked( $item->is_spam, 0 ); ?>><?php _e( 'Approved', 'buddypress' ); ?></label><br />
663
+ <label class="spam"><input type="radio" name="activity_status" value="spam" <?php checked( $item->is_spam, 1 ); ?>><?php _e( 'Spam', 'buddypress' ); ?></label>
664
  </div>
665
 
666
  <div class="misc-pub-section curtime misc-pub-section-last">
667
  <?php
668
+ // translators: Publish box date format, see http://php.net/date
669
  $datef = __( 'M j, Y @ G:i', 'buddypress' );
670
  $date = date_i18n( $datef, strtotime( $item->date_recorded ) );
671
  ?>
672
+ <span id="timestamp"><?php printf( __( 'Submitted on: <strong>%1$s</strong>', 'buddypress' ), $date ); ?></span>&nbsp;<a href="#edit_timestamp" class="edit-timestamp hide-if-no-js" tabindex='4'><?php _e( 'Edit', 'buddypress' ); ?></a>
673
 
674
  <div id='timestampdiv' class='hide-if-js'>
675
  <?php touch_time( 1, 0, 5 ); ?>
682
 
683
  <div id="major-publishing-actions">
684
  <div id="publishing-action">
685
+ <?php submit_button( __( 'Update', 'buddypress' ), 'primary', 'save', false, array( 'tabindex' => '4' ) ); ?>
686
  </div>
687
  <div class="clear"></div>
688
  </div><!-- #major-publishing-actions -->
695
  /**
696
  * Primary link metabox for the Activity admin edit screen.
697
  *
698
+ * @since BuddyPress (1.6.0)
699
  *
700
  * @param object $item Activity item.
701
  */
703
  ?>
704
 
705
  <label class="screen-reader-text" for="bp-activities-link"><?php _e( 'Link', 'buddypress' ); ?></label>
706
+ <input type="url" name="bp-activities-link" value="<?php echo esc_url( $item->primary_link ); ?>" />
707
+ <p><?php _e( 'Activity generated by posts and comments, forum topics and replies, and some plugins, uses the link field for a permalink back to the content item.', 'buddypress' ); ?></p>
708
 
709
  <?php
710
  }
712
  /**
713
  * User ID metabox for the Activity admin edit screen.
714
  *
715
+ * @since BuddyPress (1.6.0)
716
  *
717
  * @param object $item Activity item.
718
  */
720
  ?>
721
 
722
  <label class="screen-reader-text" for="bp-activities-userid"><?php _e( 'Author ID', 'buddypress' ); ?></label>
723
+ <input type="number" name="bp-activities-userid" value="<?php echo esc_attr( $item->user_id ); ?>" min="1" />
724
 
725
  <?php
726
  }
730
  *
731
  * Format is [activity_type] => Pretty name for activity type.
732
  *
733
+ * @since BuddyPress (2.0.0)
734
  *
735
+ * @return array
736
  */
737
  function bp_activity_admin_get_activity_actions() {
738
  $actions = array();
739
 
740
  // Walk through the registered actions, and build an array of actions/values.
741
+ foreach ( buddypress()->activity->actions as $action ) {
742
  $action = array_values( (array) $action );
743
 
744
  for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ ) {
746
  }
747
  }
748
 
749
+ // This was a mis-named activity type from before BP 1.6
750
  unset( $actions['friends_register_activity_action'] );
751
 
752
+ // Sort array by the human-readable value
753
  natsort( $actions );
754
 
755
  return $actions;
756
  }
757
 
758
  /**
759
+ * Activity type metabox for the Activity admin edit screen
760
+ *
761
+ * @since BuddyPress (1.6.0)
762
  *
763
+ * @global object $bp BuddyPress global settings.
764
  *
765
  * @param object $item Activity item.
766
  */
767
  function bp_activity_admin_edit_metabox_type( $item ) {
768
+ global $bp;
769
 
770
  $actions = array();
771
  $selected = $item->type;
772
 
773
  // Walk through the registered actions, and build an array of actions/values.
774
+ foreach ( $bp->activity->actions as $action ) {
775
  $action = array_values( (array) $action );
776
 
777
  for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ )
778
  $actions[ $action[$i]['key'] ] = $action[$i]['value'];
779
  }
780
 
781
+ // This was a mis-named activity type from before BP 1.6
782
  unset( $actions['friends_register_activity_action'] );
783
 
784
+ // Sort array by the human-readable value
785
  natsort( $actions );
786
 
787
+ // If the activity type is not registered properly (eg, a plugin has
788
+ // not called bp_activity_set_action()), add the raw type to the end
789
+ // of the list
 
 
790
  if ( ! isset( $actions[ $selected ] ) ) {
791
  _doing_it_wrong( __FUNCTION__, sprintf( __( 'This activity item has a type (%s) that is not registered using bp_activity_set_action(), so no label is available.', 'buddypress' ), $selected ), '2.0.0' );
792
  $actions[ $selected ] = $selected;
794
 
795
  ?>
796
 
797
+ <select name="bp-activities-type">
 
798
  <?php foreach ( $actions as $k => $v ) : ?>
799
  <option value="<?php echo esc_attr( $k ); ?>" <?php selected( $k, $selected ); ?>><?php echo esc_html( $v ); ?></option>
800
  <?php endforeach; ?>
806
  /**
807
  * Primary item ID/Secondary item ID metabox for the Activity admin edit screen.
808
  *
809
+ * @since BuddyPress (1.6.0)
810
  *
811
  * @param object $item Activity item.
812
  */
828
  /**
829
  * Display the Activity admin index screen, which contains a list of all the activities.
830
  *
831
+ * @since BuddyPress (1.6.0)
832
  *
833
+ * @global BP_Activity_List_Table $bp_activity_list_table Activity screen list
834
+ * table.
835
+ * @global string $plugin_page The current plugin page.
836
  */
837
  function bp_activity_admin_index() {
838
  global $bp_activity_list_table, $plugin_page;
839
 
840
  $messages = array();
841
 
842
+ // If the user has just made a change to an activity item, build status messages
843
  if ( ! empty( $_REQUEST['deleted'] ) || ! empty( $_REQUEST['spammed'] ) || ! empty( $_REQUEST['unspammed'] ) || ! empty( $_REQUEST['error'] ) || ! empty( $_REQUEST['updated'] ) ) {
844
  $deleted = ! empty( $_REQUEST['deleted'] ) ? (int) $_REQUEST['deleted'] : 0;
845
  $errors = ! empty( $_REQUEST['error'] ) ? $_REQUEST['error'] : '';
849
 
850
  $errors = array_map( 'absint', explode( ',', $errors ) );
851
 
852
+ // Make sure we don't get any empty values in $errors
853
  for ( $i = 0, $errors_count = count( $errors ); $i < $errors_count; $i++ ) {
854
  if ( 0 === $errors[$i] ) {
855
  unset( $errors[$i] );
856
  }
857
  }
858
 
859
+ // Reindex array
860
  $errors = array_values( $errors );
861
 
862
  if ( $deleted > 0 )
870
  $error_msg = __( 'Errors occurred when trying to update these activity items:', 'buddypress' );
871
  $error_msg .= '<ul class="activity-errors">';
872
 
873
+ // Display each error as a list item
874
  foreach ( $errors as $error ) {
875
+ // Translators: This is a bulleted list of item IDs
876
  $error_msg .= '<li>' . sprintf( __( '#%s', 'buddypress' ), number_format_i18n( $error ) ) . '</li>';
877
  }
878
 
888
  $messages[] = sprintf( _n( '%s activity item has been successfully unspammed.', '%s activity items have been successfully unspammed.', $unspammed, 'buddypress' ), number_format_i18n( $unspammed ) );
889
 
890
  if ( $updated > 0 )
891
+ $messages[] = __( 'The activity item has been updated succesfully.', 'buddypress' );
892
  }
893
 
894
+ // Prepare the activity items for display
895
  $bp_activity_list_table->prepare_items();
896
 
897
+ // Call an action for plugins to modify the activity before we display the edit form
 
 
 
 
 
 
898
  do_action( 'bp_activity_admin_index', $messages ); ?>
899
 
900
  <div class="wrap">
901
+ <?php screen_icon( 'buddypress-activity' ); ?>
902
  <h2>
903
  <?php if ( !empty( $_REQUEST['aid'] ) ) : ?>
904
  <?php printf( __( 'Activity related to ID #%s', 'buddypress' ), number_format_i18n( (int) $_REQUEST['aid'] ) ); ?>
905
  <?php else : ?>
906
+ <?php _e( 'Activity', 'buddypress' ); ?>
907
  <?php endif; ?>
908
 
909
  <?php if ( !empty( $_REQUEST['s'] ) ) : ?>
911
  <?php endif; ?>
912
  </h2>
913
 
914
+ <?php // If the user has just made a change to an activity item, display the status messages ?>
915
  <?php if ( !empty( $messages ) ) : ?>
916
  <div id="moderated" class="<?php echo ( ! empty( $_REQUEST['error'] ) ) ? 'error' : 'updated'; ?>"><p><?php echo implode( "<br/>\n", $messages ); ?></p></div>
917
  <?php endif; ?>
918
 
919
+ <?php // Display each activity on its own row ?>
920
  <?php $bp_activity_list_table->views(); ?>
921
 
922
  <form id="bp-activities-form" action="" method="get">
925
  <?php $bp_activity_list_table->display(); ?>
926
  </form>
927
 
928
+ <?php // This markup is used for the reply form ?>
929
  <table style="display: none;">
930
  <tr id="bp-activities-container" style="display: none;">
931
  <td colspan="4">
938
  <a href="#" class="cancel button-secondary alignleft"><?php _e( 'Cancel', 'buddypress' ); ?></a>
939
  <a href="#" class="save button-primary alignright"><?php _e( 'Reply', 'buddypress' ); ?></a>
940
 
941
+ <img class="waiting" style="display:none;" src="<?php echo esc_url( bp_get_admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
942
  <span class="error" style="display:none;"></span>
943
  <br class="clear" />
944
  </p>
957
  /**
958
  * List table class for the Activity component admin page.
959
  *
960
+ * @since BuddyPress (1.6)
961
  */
962
  class BP_Activity_List_Table extends WP_List_Table {
963
 
964
  /**
965
  * What type of view is being displayed?
966
  *
967
+ * e.g. "all", "pending", "approved", "spam"...
968
  *
969
+ * @since BuddyPress (1.6.0)
970
+ * @var string
971
  */
972
  public $view = 'all';
973
 
974
  /**
975
  * How many activity items have been marked as spam.
976
  *
977
+ * @since BuddyPress (1.6.0)
978
+ * @var int
979
  */
980
  public $spam_count = 0;
981
 
982
  /**
983
  * Store activity-to-user-ID mappings for use in the In Response To column.
984
  *
985
+ * @since BuddyPress (1.6.0)
986
+ * @var array
987
  */
988
  protected $activity_user_id = array();
989
 
 
 
 
 
 
 
 
 
 
 
990
  /**
991
  * Constructor.
992
  *
993
+ * @since BuddyPress (1.6.0)
994
  */
995
  public function __construct() {
996
 
997
+ // See if activity commenting is enabled for blog / forum activity items
998
  $this->disable_blogforum_comments = bp_disable_blogforum_comments();
999
 
1000
  // Define singular and plural labels, as well as whether we support AJAX.
1009
  /**
1010
  * Handle filtering of data, sorting, pagination, and any other data manipulation prior to rendering.
1011
  *
1012
+ * @since BuddyPress (1.6.0)
1013
  */
1014
  function prepare_items() {
1015
 
1016
+ // Option defaults
1017
  $filter = array();
1018
  $include_id = false;
1019
  $search_terms = false;
1020
  $sort = 'DESC';
1021
  $spam = 'ham_only';
1022
 
1023
+ // Set current page
1024
  $page = $this->get_pagenum();
1025
 
1026
+ // Set per page from the screen options
1027
  $per_page = $this->get_items_per_page( str_replace( '-', '_', "{$this->screen->id}_per_page" ) );
1028
 
1029
+ // Check if we're on the "Spam" view
1030
  if ( !empty( $_REQUEST['activity_status'] ) && 'spam' == $_REQUEST['activity_status'] ) {
1031
  $spam = 'spam_only';
1032
  $this->view = 'spam';
1033
  }
1034
 
1035
+ // Sort order
1036
  if ( !empty( $_REQUEST['order'] ) && 'desc' != $_REQUEST['order'] )
1037
  $sort = 'ASC';
1038
 
1039
+ // Order by
1040
  /*if ( !empty( $_REQUEST['orderby'] ) ) {
1041
  }*/
1042
 
1043
+ // Filter
1044
  if ( !empty( $_REQUEST['activity_type'] ) )
1045
  $filter = array( 'action' => $_REQUEST['activity_type'] );
1046
 
1052
  if ( !empty( $_REQUEST['aid'] ) )
1053
  $include_id = (int) $_REQUEST['aid'];
1054
 
1055
+ // Get the spam total (ignoring any search query or filter)
1056
  $spams = bp_activity_get( array(
1057
  'display_comments' => 'stream',
1058
  'show_hidden' => true,
1059
  'spam' => 'spam_only',
 
1060
  ) );
1061
  $this->spam_count = $spams['total'];
1062
  unset( $spams );
1063
 
1064
+ // Get the activities from the database
1065
  $activities = bp_activity_get( array(
1066
  'display_comments' => 'stream',
1067
  'filter' => $filter,
1070
  'per_page' => $per_page,
1071
  'search_terms' => $search_terms,
1072
  'show_hidden' => true,
1073
+ //'sort' => $sort,
1074
  'spam' => $spam,
 
1075
  ) );
1076
 
1077
+ // If we're viewing a specific activity, flatten all activites into a single array.
1078
  if ( $include_id ) {
1079
  $activities['activities'] = BP_Activity_List_Table::flatten_activity_array( $activities['activities'] );
1080
  $activities['total'] = count( $activities['activities'] );
1081
 
1082
+ // Sort the array by the activity object's date_recorded value
1083
  usort( $activities['activities'], create_function( '$a, $b', 'return $a->date_recorded > $b->date_recorded;' ) );
1084
  }
1085
 
1086
+ // bp_activity_get returns an array of objects; cast these to arrays for WP_List_Table.
1087
  $new_activities = array();
1088
  foreach ( $activities['activities'] as $activity_item ) {
1089
  $new_activities[] = (array) $activity_item;
1090
 
1091
+ // Build an array of activity-to-user ID mappings for better efficency in the In Response To column
1092
  $this->activity_user_id[$activity_item->id] = $activity_item->user_id;
1093
  }
1094
 
1095
+ // Set raw data to display
1096
  $this->items = $new_activities;
1097
 
1098
+ // Store information needed for handling table pagination
1099
  $this->set_pagination_args( array(
1100
  'per_page' => $per_page,
1101
  'total_items' => $activities['total'],
1109
  /**
1110
  * Get an array of all the columns on the page.
1111
  *
1112
+ * @since BuddyPress (1.6.0)
1113
  *
1114
  * @return array Column headers.
1115
  */
1118
  $this->get_columns(),
1119
  array(),
1120
  $this->get_sortable_columns(),
 
1121
  );
1122
 
1123
  return $this->_column_headers;
1124
  }
1125
 
 
 
 
 
 
 
 
 
 
 
 
1126
  /**
1127
  * Display a message on screen when no items are found (e.g. no search matches).
1128
  *
1129
+ * @since BuddyPress (1.6.0)
1130
  */
1131
  function no_items() {
1132
  _e( 'No activities found.', 'buddypress' );
1135
  /**
1136
  * Output the Activity data table.
1137
  *
1138
+ * @since BuddyPress (1.6.0)
1139
+ */
1140
  function display() {
1141
+ extract( $this->_args );
1142
+
1143
  $this->display_tablenav( 'top' ); ?>
1144
 
1145
+ <table class="<?php echo implode( ' ', $this->get_table_classes() ); ?>" cellspacing="0">
1146
  <thead>
1147
  <tr>
1148
  <?php $this->print_column_headers(); ?>
1167
  /**
1168
  * Generate content for a single row of the table.
1169
  *
1170
+ * @since BuddyPress (1.6.0)
1171
  *
1172
  * @param object $item The current item.
1173
  */
1196
  /**
1197
  * Get the list of views available on this table (e.g. "all", "spam").
1198
  *
1199
+ * @since BuddyPress (1.6.0)
1200
  */
1201
  function get_views() {
1202
+ $url_base = bp_get_admin_url( 'admin.php?page=bp-activity' ); ?>
1203
 
1204
  <ul class="subsubsub">
1205
+ <li class="all"><a href="<?php echo esc_attr( esc_url( $url_base ) ); ?>" class="<?php if ( 'spam' != $this->view ) echo 'current'; ?>"><?php _e( 'All', 'buddypress' ); ?></a> |</li>
1206
+ <li class="spam"><a href="<?php echo esc_attr( 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>
 
 
1207
 
1208
+ <?php do_action( 'bp_activity_list_table_get_views', $url_base, $this->view ); ?>
 
 
 
 
 
 
 
 
1209
  </ul>
1210
  <?php
1211
  }
1213
  /**
1214
  * Get bulk actions.
1215
  *
1216
+ * @since BuddyPress (1.6.0)
1217
  *
1218
  * @return array Key/value pairs for the bulk actions dropdown.
1219
  */
1223
  $actions['bulk_ham'] = __( 'Not Spam', 'buddypress' );
1224
  $actions['bulk_delete'] = __( 'Delete Permanently', 'buddypress' );
1225
 
 
 
 
 
 
 
 
1226
  return apply_filters( 'bp_activity_list_table_get_bulk_actions', $actions );
1227
  }
1228
 
1229
  /**
1230
  * Get the table column titles.
1231
  *
1232
+ * @since BuddyPress (1.6.0)
1233
  *
1234
  * @see WP_List_Table::single_row_columns()
1235
  *
1236
  * @return array The columns to appear in the Activity list table.
1237
  */
1238
  function get_columns() {
1239
+ return array(
 
 
 
 
 
 
 
1240
  'cb' => '<input name type="checkbox" />',
1241
+ 'author' => __( 'Author', 'buddypress' ),
1242
+ 'comment' => __( 'Activity', 'buddypress' ),
1243
+ 'action' => __( 'Action', 'buddypress' ),
1244
+ 'response' => __( 'In Response To', 'buddypress' ),
1245
+ );
1246
  }
1247
 
1248
  /**
1250
  *
1251
  * Currently, returns an empty array (no columns are sortable).
1252
  *
1253
+ * @since BuddyPress (1.6.0)
1254
  * @todo For this to work, BP_Activity_Activity::get() needs updating
1255
  * to support ordering by specific fields.
1256
  *
1267
  /**
1268
  * Markup for the "filter" part of the form (i.e. which activity type to display).
1269
  *
1270
+ * @since BuddyPress (1.6.0)
1271
  *
1272
  * @param string $which 'top' or 'bottom'.
1273
  */
1274
  function extra_tablenav( $which ) {
1275
+ if ( 'bottom' == $which )
 
 
1276
  return;
 
1277
 
1278
+ $selected = !empty( $_REQUEST['activity_type'] ) ? $_REQUEST['activity_type'] : '';
 
1279
 
1280
+ // Get all types of activities, and sort alphabetically.
1281
+ $actions = bp_activity_get_types();
1282
+ natsort( $actions );
1283
+ ?>
1284
 
1285
  <div class="alignleft actions">
1286
+ <select name="activity_type">
1287
+ <option value="" <?php selected( !$selected ); ?>><?php _e( 'Show all activity types', 'buddypress' ); ?></option>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1288
 
1289
+ <?php foreach ( $actions as $k => $v ) : ?>
1290
+ <option value="<?php echo esc_attr( $k ); ?>" <?php selected( $k, $selected ); ?>><?php echo esc_html( $v ); ?></option>
1291
  <?php endforeach; ?>
 
1292
  </select>
1293
 
1294
  <?php submit_button( __( 'Filter', 'buddypress' ), 'secondary', false, false, array( 'id' => 'post-query-submit' ) ); ?>
1297
  <?php
1298
  }
1299
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1300
  /**
1301
  * Checkbox column markup.
1302
  *
1303
+ * @since BuddyPress (1.6.0)
1304
  *
1305
  * @see WP_List_Table::single_row_columns()
1306
  *
1313
  /**
1314
  * Author column markup.
1315
  *
1316
+ * @since BuddyPress (1.6.0)
1317
  *
1318
  * @see WP_List_Table::single_row_columns()
1319
  *
1326
  /**
1327
  * Action column markup.
1328
  *
1329
+ * @since BuddyPress (2.0.0)
1330
  *
1331
  * @see WP_List_Table::single_row_columns()
1332
  *
1347
  *
1348
  * Called "comment" in the CSS so we can re-use some WP core CSS.
1349
  *
1350
+ * @since BuddyPress (1.6.0)
1351
  *
1352
  * @see WP_List_Table::single_row_columns()
1353
  *
1354
  * @param array $item A singular item (one full row).
1355
  */
1356
  function column_comment( $item ) {
1357
+ // Determine what type of item (row) we're dealing with
1358
  if ( $item['is_spam'] )
1359
  $item_status = 'spam';
1360
  else
1361
  $item_status = 'all';
1362
 
1363
+ // Preorder items: Reply | Edit | Spam | Delete Permanently
1364
  $actions = array(
1365
  'reply' => '',
1366
  'edit' => '',
1368
  'delete' => '',
1369
  );
1370
 
1371
+ // Build actions URLs
1372
  $base_url = bp_get_admin_url( 'admin.php?page=bp-activity&amp;aid=' . $item['id'] );
1373
  $spam_nonce = esc_html( '_wpnonce=' . wp_create_nonce( 'spam-activity_' . $item['id'] ) );
1374
 
1377
  $ham_url = $base_url . "&amp;action=ham&amp;$spam_nonce";
1378
  $spam_url = $base_url . "&amp;action=spam&amp;$spam_nonce";
1379
 
1380
+ // Rollover actions
1381
+
1382
+ // Reply - javascript only; implemented by AJAX.
1383
  if ( 'spam' != $item_status ) {
1384
  if ( $this->can_comment( $item ) ) {
1385
  $actions['reply'] = sprintf( '<a href="#" class="reply hide-if-no-js">%s</a>', __( 'Reply', 'buddypress' ) );
1387
  $actions['reply'] = sprintf( '<span class="form-input-tip" title="%s">%s</span>', __( 'Replies are disabled for this activity item', 'buddypress' ), __( 'Replies disabled', 'buddypress' ) );
1388
  }
1389
 
1390
+ // Edit
1391
  $actions['edit'] = sprintf( '<a href="%s">%s</a>', $edit_url, __( 'Edit', 'buddypress' ) );
1392
  }
1393
 
1394
+ // Spam/unspam
1395
  if ( 'spam' == $item_status )
1396
  $actions['unspam'] = sprintf( '<a href="%s">%s</a>', $ham_url, __( 'Not Spam', 'buddypress' ) );
1397
  else
1398
  $actions['spam'] = sprintf( '<a href="%s">%s</a>', $spam_url, __( 'Spam', 'buddypress' ) );
1399
 
1400
+ // Delete
1401
  $actions['delete'] = sprintf( '<a href="%s" onclick="%s">%s</a>', $delete_url, "javascript:return confirm('" . esc_js( __( 'Are you sure?', 'buddypress' ) ) . "'); ", __( 'Delete Permanently', 'buddypress' ) );
1402
 
1403
+ // Start timestamp
1404
  echo '<div class="submitted-on">';
1405
 
1406
+ // Other plugins can filter which actions are shown
 
 
 
 
 
 
 
1407
  $actions = apply_filters( 'bp_activity_admin_comment_row_actions', array_filter( $actions ), $item );
1408
 
1409
  /* translators: 2: activity admin ui date/time */
1410
+ printf( __( 'Submitted on <a href="%1$s">%2$s at %3$s</a>', 'buddypress' ), bp_activity_get_permalink( $item['id'] ), get_date_from_gmt( $item['date_recorded'], get_option( 'date_format' ) ), get_date_from_gmt( $item['date_recorded'], get_option( 'time_format' ) ) );
 
 
 
 
 
1411
 
1412
+ // End timestamp
1413
  echo '</div>';
1414
 
1415
+ // Get activity content - if not set, use the action
1416
  if ( ! empty( $item['content'] ) ) {
 
 
 
 
 
 
 
 
1417
  $content = apply_filters_ref_array( 'bp_get_activity_content_body', array( $item['content'] ) );
1418
  } else {
 
 
 
 
 
 
 
1419
  $content = apply_filters_ref_array( 'bp_get_activity_action', array( $item['action'] ) );
1420
  }
1421
 
1422
+ echo $content . ' ' . $this->row_actions( $actions );
 
 
 
 
 
 
 
 
1423
  }
1424
 
1425
  /**
1426
  * "In response to" column markup.
1427
  *
1428
+ * @since BuddyPress (1.6.0)
1429
  *
1430
  * @see WP_List_Table::single_row_columns()
1431
  *
1432
  * @param array $item A singular item (one full row).
1433
  */
1434
  function column_response( $item ) {
 
1435
  // Is $item is a root activity?
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1436
  if ( empty( $item['item_id'] ) || ! in_array( $item['type'], apply_filters( 'bp_activity_admin_root_activity_types', array( 'activity_comment' ), $item ) ) ) {
 
 
1437
  $comment_count = !empty( $item['children'] ) ? bp_activity_recurse_comment_count( (object) $item ) : 0;
1438
  $root_activity_url = bp_get_admin_url( 'admin.php?page=bp-activity&amp;aid=' . $item['id'] );
1439
 
1440
+ // If the activity has comments, display a link to the activity's permalink, with its comment count in a speech bubble
1441
  if ( $comment_count ) {
1442
  $title_attr = sprintf( _n( '%s related activity', '%s related activities', $comment_count, 'buddypress' ), number_format_i18n( $comment_count ) );
1443
+ printf( '<a href="%1$s" title="%2$s" class="post-com-count"><span class="comment-count">%3$s</span></a>', esc_url( $root_activity_url ), esc_attr( $title_attr ), number_format_i18n( $comment_count ) );
1444
  }
1445
 
1446
+ // For non-root activities, display a link to the replied-to activity's author's profile
1447
  } else {
1448
  echo '<strong>' . get_avatar( $this->get_activity_user_id( $item['item_id'] ), '32' ) . ' ' . bp_core_get_userlink( $this->get_activity_user_id( $item['item_id'] ) ) . '</strong><br />';
 
1449
  }
 
 
 
1450
 
1451
+ // Activity permalink
1452
+ if ( ! $item['is_spam'] )
1453
+ printf( __( '<a href="%1$s">View Activity</a>', 'buddypress' ), bp_activity_get_permalink( $item['id'], (object) $item ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1454
  }
1455
 
1456
  /**
1459
  * Wraps bp_activity_get_specific(), with some additional logic for
1460
  * avoiding duplicate queries.
1461
  *
1462
+ * @since BuddyPress (1.6.0)
1463
  *
1464
  * @param int $activity_id Activity ID to retrieve User ID for.
1465
  * @return int User ID of the activity item in question.
1469
  if ( ! empty( $this->activity_user_id[$activity_id] ) ) {
1470
  return $this->activity_user_id[$activity_id];
1471
 
1472
+ /**
1473
  * We don't have a mapping. This means the $activity_id is not on the current
1474
  * page of results, so fetch its details from the database.
1475
  */
1476
  } else {
1477
  $activity = bp_activity_get_specific( array( 'activity_ids' => $activity_id, 'show_hidden' => true, 'spam' => 'all', ) );
1478
 
1479
+ /**
1480
  * If, somehow, the referenced activity has been deleted, leaving its associated
1481
+ * activites as orphans, use the logged in user's ID to avoid errors.
1482
  */
1483
  if ( empty( $activity['activities'] ) )
1484
  return bp_loggedin_user_id();
1485
 
1486
+ // Store the new activity/user ID mapping for any later re-use
1487
  $this->activity_user_id[ $activity['activities'][0]->id ] = $activity['activities'][0]->user_id;
1488
 
1489
+ // Return the user ID
1490
  return $activity['activities'][0]->user_id;
1491
  }
1492
  }
1495
  * Checks if an activity item can be replied to.
1496
  *
1497
  * This method merges functionality from {@link bp_activity_can_comment()} and
1498
+ * {@link bp_blogs_disable_activity_commenting()}. This is done because the activity
1499
  * list table doesn't use a BuddyPress activity loop, which prevents those
1500
  * functions from working as intended.
1501
  *
1502
+ * @since BuddyPress (2.0.0)
1503
  *
1504
  * @param array $item An array version of the BP_Activity_Activity object.
1505
+ * @return bool
1506
  */
1507
  protected function can_comment( $item ) {
1508
  $can_comment = true;
1517
  break;
1518
  }
1519
 
1520
+ // activity comments supported
1521
  } else {
1522
+ // activity comment
1523
  if ( 'activity_comment' == $item['type'] ) {
1524
+ // blogs
1525
  if ( bp_is_active( 'blogs' ) ) {
1526
+ // grab the parent activity entry
1527
  $parent_activity = new BP_Activity_Activity( $item['item_id'] );
1528
 
1529
+ // fetch blog post comment depth and if the blog post's comments are open
1530
  bp_blogs_setup_activity_loop_globals( $parent_activity );
1531
 
1532
+ // check if the activity item can be replied to
1533
  if ( false === bp_blogs_can_comment_reply( true, $item ) ) {
1534
  $can_comment = false;
1535
  }
1536
  }
1537
 
1538
+ // blog post
1539
  } elseif ( 'new_blog_post' == $item['type'] ) {
1540
  if ( bp_is_active( 'blogs' ) ) {
1541
  bp_blogs_setup_activity_loop_globals( (object) $item );
1547
  }
1548
  }
1549
 
 
 
 
 
 
 
 
1550
  return apply_filters( 'bp_activity_list_table_can_comment', $can_comment );
1551
  }
1552
 
1556
  * In some cases, BuddyPress gives us a structured tree of activity
1557
  * items plus their comments. This method converts it to a flat array.
1558
  *
1559
+ * @since BuddyPress (1.6.0)
1560
  *
1561
  * @param array $tree Source array.
1562
  * @return array Flattened array.
bp-activity/bp-activity-akismet.php CHANGED
@@ -3,34 +3,32 @@
3
  * Akismet support for BuddyPress' Activity Stream.
4
  *
5
  * @package BuddyPress
6
- * @subpackage ActivityAkismet
7
- * @since 1.6.0
8
  */
9
 
10
- // Exit if accessed directly.
11
- defined( 'ABSPATH' ) || exit;
12
 
13
  /**
14
  * Akismet support for the Activity component.
15
  *
16
- * @since 1.6.0
17
- * @since 2.3.0 We only support Akismet 3+.
18
  */
19
  class BP_Akismet {
20
-
21
  /**
22
  * The activity last marked as spam.
23
  *
24
- * @since 1.6.0
25
- *
26
  * @var BP_Activity_Activity
 
27
  */
28
  protected $last_activity = null;
29
 
30
  /**
31
  * Constructor.
32
  *
33
- * @since 1.6.0
34
  */
35
  public function __construct() {
36
  $this->setup_actions();
@@ -39,28 +37,28 @@ class BP_Akismet {
39
  /**
40
  * Hook Akismet into the activity stream.
41
  *
42
- * @since 1.6.0
43
  */
44
  protected function setup_actions() {
45
- // Add nonces to activity stream lists.
46
  add_action( 'bp_after_activity_post_form', array( $this, 'add_activity_stream_nonce' ) );
47
  add_action( 'bp_activity_entry_comments', array( $this, 'add_activity_stream_nonce' ) );
48
 
49
- // Add a "mark as spam" button to individual activity items.
50
  add_action( 'bp_activity_entry_meta', array( $this, 'add_activity_spam_button' ) );
51
  add_action( 'bp_activity_comment_options', array( $this, 'add_activity_comment_spam_button' ) );
52
 
53
- // Check activity for spam.
54
  add_action( 'bp_activity_before_save', array( $this, 'check_activity' ), 4, 1 );
55
 
56
- // Tidy up member's latest (activity) update.
57
  add_action( 'bp_activity_posted_update', array( $this, 'check_member_activity_update' ), 1, 3 );
58
 
59
- // Hooks to extend Activity core spam/ham functions for Akismet.
60
  add_action( 'bp_activity_mark_as_spam', array( $this, 'mark_as_spam' ), 10, 2 );
61
  add_action( 'bp_activity_mark_as_ham', array( $this, 'mark_as_ham' ), 10, 2 );
62
 
63
- // Hook into the Activity wp-admin screen.
64
  add_action( 'bp_activity_admin_comment_row_actions', array( $this, 'comment_row_action' ), 10, 2 );
65
  add_action( 'bp_activity_admin_load', array( $this, 'add_history_metabox' ) );
66
  }
@@ -71,9 +69,9 @@ class BP_Akismet {
71
  * This function lifted with love from the Akismet WordPress plugin's
72
  * akismet_comment_row_action() function. Thanks!
73
  *
74
- * @since 1.6.0
75
  *
76
- * @param array $actions The hover links.
77
  * @param array $activity The activity for the current row being processed.
78
  * @return array The hover links.
79
  */
@@ -83,7 +81,7 @@ class BP_Akismet {
83
  $desc = '';
84
 
85
  if ( !$user_result || $user_result == $akismet_result ) {
86
- // Show the original Akismet result if the user hasn't overridden it, or if their decision was the same.
87
  if ( 'true' == $akismet_result && $activity['is_spam'] )
88
  $desc = __( 'Flagged as spam by Akismet', 'buddypress' );
89
 
@@ -99,7 +97,7 @@ class BP_Akismet {
99
  $desc = sprintf( __( 'Un-spammed by %s', 'buddypress' ), $who );
100
  }
101
 
102
- // Add a History item to the hover links, just after Edit.
103
  if ( $akismet_result ) {
104
  $b = array();
105
  foreach ( $actions as $k => $item ) {
@@ -114,13 +112,6 @@ class BP_Akismet {
114
  if ( $desc )
115
  echo '<span class="akismet-status"><a href="' . esc_url( bp_get_admin_url( 'admin.php?page=bp-activity&amp;action=edit&aid=' . $activity['id'] ) ) . '#bp_activity_history">' . htmlspecialchars( $desc ) . '</a></span>';
116
 
117
- /**
118
- * Filters the list of actions for the current activity's row.
119
- *
120
- * @since 1.6.0
121
- *
122
- * @param array $actions Array of available actions for the current activity item's row.
123
- */
124
  return apply_filters( 'bp_akismet_comment_row_action', $actions );
125
  }
126
 
@@ -131,15 +122,15 @@ class BP_Akismet {
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 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';
140
  $value = '_bp_as_nonce_' . bp_loggedin_user_id();
141
 
142
- // If we're in the activity stream loop, we can use the current item's ID to make the nonce unique.
143
  if ( 'bp_activity_entry_comments' == current_filter() ) {
144
  $form_id .= '_' . bp_get_activity_id();
145
  $value .= '_' . bp_get_activity_id();
@@ -160,13 +151,13 @@ class BP_Akismet {
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 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,7 +177,7 @@ class BP_Akismet {
186
  *
187
  * This function is intended to be used inside the activity stream loop.
188
  *
189
- * @since 1.6.0
190
  */
191
  public function add_activity_spam_button() {
192
  if ( !bp_activity_user_can_mark_spam() )
@@ -214,7 +205,7 @@ class BP_Akismet {
214
  *
215
  * This function is intended to be used inside the activity stream loop.
216
  *
217
- * @since 1.6.0
218
  */
219
  public function add_activity_comment_spam_button() {
220
  if ( !bp_activity_user_can_mark_spam() )
@@ -241,91 +232,56 @@ class BP_Akismet {
241
  /**
242
  * Get a filterable list of activity types that Akismet should automatically check for spam.
243
  *
244
- * @since 1.6.0
245
  *
246
  * @static
247
  *
248
- * @return array $value List of activity types.
249
  */
250
  public static function get_activity_types() {
251
-
252
- /**
253
- * Filters the list of activity types that Akismet should automatically check for spam.
254
- *
255
- * @since 1.6.0
256
- *
257
- * @param array Array of default activity types for Akismet to check.
258
- */
259
  return apply_filters( 'bp_akismet_get_activity_types', array( 'activity_comment', 'activity_update' ) );
260
  }
261
 
262
  /**
263
  * Mark activity item as spam.
264
  *
265
- * @since 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().
274
  $this->last_activity = $activity;
275
 
276
- /**
277
- * Fires after marking an activity item has been marked as spam.
278
- *
279
- * @since 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
  }
289
 
290
  /**
291
  * Mark activity item as ham.
292
  *
293
- * @since 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.
302
  if ( 'true' == bp_activity_get_meta( $activity->id, '_bp_akismet_result' ) && !bp_activity_get_meta( $activity->id, '_bp_akismet_user_result' ) )
303
  $activity->content = bp_activity_at_name_filter( $activity->content, $activity->id );
304
 
305
- /**
306
- * Fires after marking an activity item has been marked as ham.
307
- *
308
- * @since 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
  }
318
 
319
  /**
320
  * Build a data package for the Akismet service to inspect.
321
  *
322
- * @since 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
- * @return array $activity_data
329
  */
330
  public static function build_akismet_data_package( $activity ) {
331
  $userdata = get_userdata( $activity->user_id );
@@ -339,7 +295,7 @@ class BP_Akismet {
339
  $activity_data['comment_type'] = $activity->type;
340
  $activity_data['permalink'] = bp_activity_get_permalink( $activity->id, $activity );
341
  $activity_data['user_ID'] = $userdata->ID;
342
- $activity_data['user_role'] = Akismet::get_user_roles( $userdata->ID );
343
 
344
  /**
345
  * Get the nonce if the new activity was submitted through the "what's up, Paul?" form.
@@ -355,21 +311,13 @@ class BP_Akismet {
355
  elseif ( !empty( $activity->secondary_item_id ) && !empty( $_POST['_bp_as_nonce_' . $activity->secondary_item_id] ) )
356
  $activity_data['akismet_comment_nonce'] = wp_verify_nonce( $_POST["_bp_as_nonce_{$activity->secondary_item_id}"], "_bp_as_nonce_{$userdata->ID}_{$activity->secondary_item_id}" ) ? 'passed' : 'failed';
357
 
358
- /**
359
- * Filters activity data before being sent to Akismet to inspect.
360
- *
361
- * @since 1.6.0
362
- *
363
- * @param array $activity_data Array of activity data for Akismet to inspect.
364
- * @param BP_Activity_Activity $activity Activity item data.
365
- */
366
  return apply_filters( 'bp_akismet_build_akismet_data_package', $activity_data, $activity );
367
  }
368
 
369
  /**
370
  * Check if the activity item is spam or ham.
371
  *
372
- * @since 1.6.0
373
  *
374
  * @see http://akismet.com/development/api/
375
  * @todo Spam counter?
@@ -382,46 +330,38 @@ class BP_Akismet {
382
  if ( !in_array( $activity->type, BP_Akismet::get_activity_types() ) )
383
  return;
384
 
385
- // Make sure last_activity is clear to avoid any confusion.
386
  $this->last_activity = null;
387
 
388
- // Build data package for Akismet.
389
  $activity_data = BP_Akismet::build_akismet_data_package( $activity );
390
 
391
- // Check with Akismet to see if this is spam.
392
  $activity_data = $this->send_akismet_request( $activity_data, 'check', 'spam' );
393
 
394
- // Record this item.
395
  $this->last_activity = $activity;
396
 
397
- // Store a copy of the data that was submitted to Akismet.
398
  $this->last_activity->akismet_submission = $activity_data;
399
 
400
- // Spam.
401
  if ( 'true' == $activity_data['bp_as_result'] ) {
402
- /**
403
- * Fires after an activity item has been proven to be spam, but before officially being marked as spam.
404
- *
405
- * @since 1.6.0
406
- *
407
- * @param BP_Activity_Activity $activity The activity item proven to be spam.
408
- * @param array $activity_data Array of activity data for item including
409
- * Akismet check results data.
410
- */
411
  do_action_ref_array( 'bp_activity_akismet_spam_caught', array( &$activity, $activity_data ) );
412
 
413
- // Mark as spam.
414
  bp_activity_mark_as_spam( $activity, 'by_akismet' );
415
  }
416
 
417
- // Update activity meta after a spam check.
418
  add_action( 'bp_activity_after_save', array( $this, 'update_activity_akismet_meta' ), 1, 1 );
419
  }
420
 
421
  /**
422
  * Update activity meta after a manual spam change (user-initiated).
423
  *
424
- * @since 1.6.0
425
  *
426
  * @param BP_Activity_Activity $activity The activity to check.
427
  */
@@ -438,7 +378,7 @@ class BP_Akismet {
438
  /**
439
  * Update activity meta after a manual ham change (user-initiated).
440
  *
441
- * @since 1.6.0
442
  *
443
  * @param BP_Activity_Activity $activity The activity to check.
444
  */
@@ -455,12 +395,12 @@ class BP_Akismet {
455
  /**
456
  * Update activity meta after an automatic spam check (not user-initiated).
457
  *
458
- * @since 1.6.0
459
  *
460
  * @param BP_Activity_Activity $activity The activity to check.
461
  */
462
  public function update_activity_akismet_meta( $activity ) {
463
- // Check we're dealing with what was last updated by Akismet.
464
  if ( empty( $this->last_activity ) || !empty( $this->last_activity ) && $activity->id != $this->last_activity->id )
465
  return;
466
 
@@ -468,12 +408,12 @@ class BP_Akismet {
468
  if ( !in_array( $this->last_activity->type, BP_Akismet::get_activity_types() ) )
469
  return;
470
 
471
- // Spam.
472
  if ( 'true' == $this->last_activity->akismet_submission['bp_as_result'] ) {
473
  bp_activity_update_meta( $activity->id, '_bp_akismet_result', 'true' );
474
  $this->update_activity_history( $activity->id, __( 'Akismet caught this item as spam', 'buddypress' ), 'check-spam' );
475
 
476
- // Not spam.
477
  } elseif ( 'false' == $this->last_activity->akismet_submission['bp_as_result'] ) {
478
  bp_activity_update_meta( $activity->id, '_bp_akismet_result', 'false' );
479
  $this->update_activity_history( $activity->id, __( 'Akismet cleared this item', 'buddypress' ), 'check-ham' );
@@ -484,24 +424,33 @@ class BP_Akismet {
484
  $this->update_activity_history( $activity->id, sprintf( __( 'Akismet was unable to check this item (response: %s), will automatically retry again later.', 'buddypress' ), $this->last_activity->akismet_submission['bp_as_result'] ), 'check-error' );
485
  }
486
 
487
- // Record the original data which was submitted to Akismet for checking.
488
  bp_activity_update_meta( $activity->id, '_bp_akismet_submission', $this->last_activity->akismet_submission );
489
  }
490
 
491
  /**
492
  * Contact Akismet to check if this is spam or ham.
493
  *
494
- * Props to WordPress core Akismet plugin for a lot of this.
 
 
495
  *
496
- * @since 1.6.0
 
497
  *
498
- * @param array $activity_data Packet of information to submit to Akismet.
499
- * @param string $check "check" or "submit".
500
- * @param string $spam "spam" or "ham".
501
  * @return array $activity_data Activity data, with Akismet data added.
502
  */
503
  public function send_akismet_request( $activity_data, $check = 'check', $spam = 'spam' ) {
504
- $query_string = $path = '';
 
 
 
 
 
 
505
 
506
  $activity_data['blog'] = bp_get_option( 'home' );
507
  $activity_data['blog_charset'] = bp_get_option( 'blog_charset' );
@@ -510,25 +459,25 @@ class BP_Akismet {
510
  $activity_data['user_agent'] = bp_core_current_user_ua();
511
  $activity_data['user_ip'] = bp_core_current_user_ip();
512
 
513
- if ( Akismet::is_test_mode() )
514
  $activity_data['is_test'] = 'true';
515
 
516
- // Loop through _POST args and rekey strings.
517
  foreach ( $_POST as $key => $value )
518
  if ( is_string( $value ) && 'cookie' != $key )
519
  $activity_data['POST_' . $key] = $value;
520
 
521
- // Keys to ignore.
522
  $ignore = array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' );
523
 
524
- // Loop through _SERVER args and remove whitelisted keys.
525
  foreach ( $_SERVER as $key => $value ) {
526
 
527
- // Key should not be ignored.
528
  if ( !in_array( $key, $ignore ) && is_string( $value ) ) {
529
  $activity_data[$key] = $value;
530
 
531
- // Key should be ignored.
532
  } else {
533
  $activity_data[$key] = '';
534
  }
@@ -538,22 +487,22 @@ class BP_Akismet {
538
  $query_string .= $key . '=' . urlencode( stripslashes( $data ) ) . '&';
539
 
540
  if ( 'check' == $check )
541
- $path = 'comment-check';
542
  elseif ( 'submit' == $check )
543
- $path = 'submit-' . $spam;
544
 
545
- // Send to Akismet.
546
  add_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) );
547
- $response = Akismet::http_post( $query_string, $path );
548
  remove_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) );
549
 
550
- // Get the response.
551
  if ( ! empty( $response[1] ) && ! is_wp_error( $response[1] ) )
552
  $activity_data['bp_as_result'] = $response[1];
553
  else
554
  $activity_data['bp_as_result'] = false;
555
 
556
- // Perform a daily tidy up.
557
  if ( ! wp_next_scheduled( 'bp_activity_akismet_delete_old_metadata' ) )
558
  wp_schedule_event( time(), 'daily', 'bp_activity_akismet_delete_old_metadata' );
559
 
@@ -563,7 +512,7 @@ class BP_Akismet {
563
  /**
564
  * Filters user agent when sending to Akismet to add BuddyPress info.
565
  *
566
- * @since 1.6.0
567
  *
568
  * @param string $user_agent User agent string, as generated by Akismet.
569
  * @return string $user_agent Modified user agent string.
@@ -576,25 +525,25 @@ class BP_Akismet {
576
  /**
577
  * Adds a "History" meta box to the activity edit screen.
578
  *
579
- * @since 1.6.0
580
  *
581
  * @param string $screen_action The type of screen that has been requested.
582
  */
583
  function add_history_metabox( $screen_action ) {
584
- // Only proceed if we're on the edit screen.
585
  if ( 'edit' != $screen_action )
586
  return;
587
 
588
- // Display meta box with a low priority (low position on screen by default).
589
  add_meta_box( 'bp_activity_history', __( 'Activity History', 'buddypress' ), array( $this, 'history_metabox' ), get_current_screen()->id, 'normal', 'low' );
590
  }
591
 
592
  /**
593
  * History meta box for the Activity admin edit screen.
594
  *
595
- * @since 1.6.0
596
  *
597
- * @see https://buddypress.trac.wordpress.org/ticket/3907
598
  * @todo Update activity meta to allow >1 record with the same key (iterate through $history).
599
  *
600
  * @param object $item Activity item.
@@ -606,35 +555,35 @@ class BP_Akismet {
606
  return;
607
 
608
  echo '<div class="akismet-history"><div>';
609
- printf( _x( '%1$s &mdash; %2$s', 'x hours ago - akismet cleared this item', 'buddypress' ), '<span>' . bp_core_time_since( $history[2] ) . '</span>', esc_html( $history[1] ) );
610
  echo '</div></div>';
611
  }
612
 
613
  /**
614
  * Update an activity item's Akismet history.
615
  *
616
- * @since 1.6.0
617
  *
618
- * @param int $activity_id Activity item ID.
619
- * @param string $message Human-readable description of what's changed.
620
- * @param string $event The type of check we were carrying out.
621
  */
622
  public function update_activity_history( $activity_id = 0, $message = '', $event = '' ) {
623
  $event = array(
624
  'event' => $event,
625
  'message' => $message,
626
- 'time' => Akismet::_get_microtime(),
627
  'user' => bp_loggedin_user_id(),
628
  );
629
 
630
- // Save the history data.
631
  bp_activity_update_meta( $activity_id, '_bp_akismet_history', $event );
632
  }
633
 
634
  /**
635
  * Get an activity item's Akismet history.
636
  *
637
- * @since 1.6.0
638
  *
639
  * @param int $activity_id Activity item ID.
640
  * @return array The activity item's Akismet history.
@@ -644,7 +593,7 @@ class BP_Akismet {
644
  if ( $history === false )
645
  $history = array();
646
 
647
- // Sort it by the time recorded.
648
  usort( $history, 'akismet_cmp_time' );
649
 
650
  return $history;
@@ -652,30 +601,22 @@ class BP_Akismet {
652
  }
653
 
654
  /**
655
- * Delete old spam activity meta data.
656
  *
657
  * This is done as a clean-up mechanism, as _bp_akismet_submission meta can
658
  * grow to be quite large.
659
  *
660
- * @since 1.6.0
661
  *
 
662
  * @global wpdb $wpdb WordPress database object.
663
  */
664
  function bp_activity_akismet_delete_old_metadata() {
665
- global $wpdb;
666
 
667
- $bp = buddypress();
668
-
669
- /**
670
- * Filters the threshold for how many days old Akismet metadata needs to be before being automatically deleted.
671
- *
672
- * @since 1.6.0
673
- *
674
- * @param integer 15 How many days old metadata needs to be.
675
- */
676
  $interval = apply_filters( 'bp_activity_akismet_delete_meta_interval', 15 );
677
 
678
- // Enforce a minimum of 1 day.
679
  $interval = max( 1, absint( $interval ) );
680
 
681
  // _bp_akismet_submission meta values are large, so expire them after $interval days regardless of the activity status
3
  * Akismet support for BuddyPress' Activity Stream.
4
  *
5
  * @package BuddyPress
6
+ * @since BuddyPress (1.6)
7
+ * @subpackage Activity
8
  */
9
 
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
 
13
  /**
14
  * Akismet support for the Activity component.
15
  *
16
+ * @since BuddyPress (1.6)
 
17
  */
18
  class BP_Akismet {
 
19
  /**
20
  * The activity last marked as spam.
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
  /**
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
44
  add_action( 'bp_after_activity_post_form', array( $this, 'add_activity_stream_nonce' ) );
45
  add_action( 'bp_activity_entry_comments', array( $this, 'add_activity_stream_nonce' ) );
46
 
47
+ // Add a "mark as spam" button to individual activity items
48
  add_action( 'bp_activity_entry_meta', array( $this, 'add_activity_spam_button' ) );
49
  add_action( 'bp_activity_comment_options', array( $this, 'add_activity_comment_spam_button' ) );
50
 
51
+ // Check activity for spam
52
  add_action( 'bp_activity_before_save', array( $this, 'check_activity' ), 4, 1 );
53
 
54
+ // Tidy up member's latest (activity) update
55
  add_action( 'bp_activity_posted_update', array( $this, 'check_member_activity_update' ), 1, 3 );
56
 
57
+ // Hooks to extend Activity core spam/ham functions for Akismet
58
  add_action( 'bp_activity_mark_as_spam', array( $this, 'mark_as_spam' ), 10, 2 );
59
  add_action( 'bp_activity_mark_as_ham', array( $this, 'mark_as_ham' ), 10, 2 );
60
 
61
+ // Hook into the Activity wp-admin screen
62
  add_action( 'bp_activity_admin_comment_row_actions', array( $this, 'comment_row_action' ), 10, 2 );
63
  add_action( 'bp_activity_admin_load', array( $this, 'add_history_metabox' ) );
64
  }
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
  */
81
  $desc = '';
82
 
83
  if ( !$user_result || $user_result == $akismet_result ) {
84
+ // Show the original Akismet result if the user hasn't overridden it, or if their decision was the same
85
  if ( 'true' == $akismet_result && $activity['is_spam'] )
86
  $desc = __( 'Flagged as spam by Akismet', 'buddypress' );
87
 
97
  $desc = sprintf( __( 'Un-spammed by %s', 'buddypress' ), $who );
98
  }
99
 
100
+ // add a History item to the hover links, just after Edit
101
  if ( $akismet_result ) {
102
  $b = array();
103
  foreach ( $actions as $k => $item ) {
112
  if ( $desc )
113
  echo '<span class="akismet-status"><a href="' . esc_url( bp_get_admin_url( 'admin.php?page=bp-activity&amp;action=edit&aid=' . $activity['id'] ) ) . '#bp_activity_history">' . htmlspecialchars( $desc ) . '</a></span>';
114
 
 
 
 
 
 
 
 
115
  return apply_filters( 'bp_akismet_comment_row_action', $actions );
116
  }
117
 
122
  * the reply form of each activity item. The nonces are, in turn, used
123
  * by Akismet to help detect spam activity.
124
  *
125
+ * @since BuddyPress (1.6)
126
  *
127
+ * @see http://plugins.trac.wordpress.org/ticket/1232
128
  */
129
  public function add_activity_stream_nonce() {
130
  $form_id = '_bp_as_nonce';
131
  $value = '_bp_as_nonce_' . bp_loggedin_user_id();
132
 
133
+ // If we're in the activity stream loop, we can use the current item's ID to make the nonce unique
134
  if ( 'bp_activity_entry_comments' == current_filter() ) {
135
  $form_id .= '_' . bp_get_activity_id();
136
  $value .= '_' . bp_get_activity_id();
151
  * This can't be done in BP_Akismet::check_activity() due to the
152
  * default AJAX implementation; see bp_dtheme_post_update().
153
  *
154
+ * @since BuddyPress (1.6)
155
  *
156
  * @see bp_dtheme_post_update()
157
  *
158
+ * @param string $content Activity update text.
159
+ * @param int $user_id User ID.
160
+ * @param int $activity_id Activity ID.
161
  */
162
  public function check_member_activity_update( $content, $user_id, $activity_id ) {
163
  // By default, only handle activity updates and activity comments.
177
  *
178
  * This function is intended to be used inside the activity stream loop.
179
  *
180
+ * @since BuddyPress (1.6)
181
  */
182
  public function add_activity_spam_button() {
183
  if ( !bp_activity_user_can_mark_spam() )
205
  *
206
  * This function is intended to be used inside the activity stream loop.
207
  *
208
+ * @since BuddyPress (1.6)
209
  */
210
  public function add_activity_comment_spam_button() {
211
  if ( !bp_activity_user_can_mark_spam() )
232
  /**
233
  * Get a filterable list of activity types that Akismet should automatically check for spam.
234
  *
235
+ * @since BuddyPress (1.6)
236
  *
237
  * @static
238
  *
239
+ * @return array List of activity types.
240
  */
241
  public static function get_activity_types() {
 
 
 
 
 
 
 
 
242
  return apply_filters( 'bp_akismet_get_activity_types', array( 'activity_comment', 'activity_update' ) );
243
  }
244
 
245
  /**
246
  * Mark activity item as spam.
247
  *
248
+ * @since BuddyPress (1.6)
249
  *
250
+ * @param BP_Activity_Activity $activity
251
+ * @param string $source Either "by_a_person" (e.g. a person has manually marked the activity as spam) or "by_akismet" (automatically spammed).
 
 
252
  */
253
  public function mark_as_spam( $activity, $source ) {
254
+ // Record this item so we can do some tidyup in BP_Akismet::check_member_activity_update()
255
  $this->last_activity = $activity;
256
 
 
 
 
 
 
 
 
 
 
 
 
257
  do_action( 'bp_activity_akismet_mark_as_spam', $activity, $source );
258
  }
259
 
260
  /**
261
  * Mark activity item as ham.
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 ham) or "by_akismet" (automatically hammed).
 
 
267
  */
268
  public function mark_as_ham( $activity, $source ) {
269
  // If the activity was, originally, automatically marked as spam by Akismet, run the @mentions filter as it would have been skipped.
270
  if ( 'true' == bp_activity_get_meta( $activity->id, '_bp_akismet_result' ) && !bp_activity_get_meta( $activity->id, '_bp_akismet_user_result' ) )
271
  $activity->content = bp_activity_at_name_filter( $activity->content, $activity->id );
272
 
 
 
 
 
 
 
 
 
 
 
 
273
  do_action( 'bp_activity_akismet_mark_as_ham', $activity, $source );
274
  }
275
 
276
  /**
277
  * Build a data package for the Akismet service to inspect.
278
  *
279
+ * @since BuddyPress (1.6)
280
  *
281
  * @see http://akismet.com/development/api/#comment-check
282
  * @static
283
  *
284
  * @param BP_Activity_Activity $activity Activity item data.
 
285
  */
286
  public static function build_akismet_data_package( $activity ) {
287
  $userdata = get_userdata( $activity->user_id );
295
  $activity_data['comment_type'] = $activity->type;
296
  $activity_data['permalink'] = bp_activity_get_permalink( $activity->id, $activity );
297
  $activity_data['user_ID'] = $userdata->ID;
298
+ $activity_data['user_role'] = akismet_get_user_roles( $userdata->ID );
299
 
300
  /**
301
  * Get the nonce if the new activity was submitted through the "what's up, Paul?" form.
311
  elseif ( !empty( $activity->secondary_item_id ) && !empty( $_POST['_bp_as_nonce_' . $activity->secondary_item_id] ) )
312
  $activity_data['akismet_comment_nonce'] = wp_verify_nonce( $_POST["_bp_as_nonce_{$activity->secondary_item_id}"], "_bp_as_nonce_{$userdata->ID}_{$activity->secondary_item_id}" ) ? 'passed' : 'failed';
313
 
 
 
 
 
 
 
 
 
314
  return apply_filters( 'bp_akismet_build_akismet_data_package', $activity_data, $activity );
315
  }
316
 
317
  /**
318
  * Check if the activity item is spam or ham.
319
  *
320
+ * @since BuddyPress (1.6)
321
  *
322
  * @see http://akismet.com/development/api/
323
  * @todo Spam counter?
330
  if ( !in_array( $activity->type, BP_Akismet::get_activity_types() ) )
331
  return;
332
 
333
+ // Make sure last_activity is clear to avoid any confusion
334
  $this->last_activity = null;
335
 
336
+ // Build data package for Akismet
337
  $activity_data = BP_Akismet::build_akismet_data_package( $activity );
338
 
339
+ // Check with Akismet to see if this is spam
340
  $activity_data = $this->send_akismet_request( $activity_data, 'check', 'spam' );
341
 
342
+ // Record this item
343
  $this->last_activity = $activity;
344
 
345
+ // Store a copy of the data that was submitted to Akismet
346
  $this->last_activity->akismet_submission = $activity_data;
347
 
348
+ // Spam
349
  if ( 'true' == $activity_data['bp_as_result'] ) {
350
+ // Action for plugin authors
 
 
 
 
 
 
 
 
351
  do_action_ref_array( 'bp_activity_akismet_spam_caught', array( &$activity, $activity_data ) );
352
 
353
+ // Mark as spam
354
  bp_activity_mark_as_spam( $activity, 'by_akismet' );
355
  }
356
 
357
+ // Update activity meta after a spam check
358
  add_action( 'bp_activity_after_save', array( $this, 'update_activity_akismet_meta' ), 1, 1 );
359
  }
360
 
361
  /**
362
  * Update activity meta after a manual spam change (user-initiated).
363
  *
364
+ * @since BuddyPress (1.6)
365
  *
366
  * @param BP_Activity_Activity $activity The activity to check.
367
  */
378
  /**
379
  * Update activity meta after a manual ham change (user-initiated).
380
  *
381
+ * @since BuddyPress (1.6)
382
  *
383
  * @param BP_Activity_Activity $activity The activity to check.
384
  */
395
  /**
396
  * Update activity meta after an automatic spam check (not user-initiated).
397
  *
398
+ * @since BuddyPress (1.6)
399
  *
400
  * @param BP_Activity_Activity $activity The activity to check.
401
  */
402
  public function update_activity_akismet_meta( $activity ) {
403
+ // Check we're dealing with what was last updated by Akismet
404
  if ( empty( $this->last_activity ) || !empty( $this->last_activity ) && $activity->id != $this->last_activity->id )
405
  return;
406
 
408
  if ( !in_array( $this->last_activity->type, BP_Akismet::get_activity_types() ) )
409
  return;
410
 
411
+ // Spam
412
  if ( 'true' == $this->last_activity->akismet_submission['bp_as_result'] ) {
413
  bp_activity_update_meta( $activity->id, '_bp_akismet_result', 'true' );
414
  $this->update_activity_history( $activity->id, __( 'Akismet caught this item as spam', 'buddypress' ), 'check-spam' );
415
 
416
+ // Not spam
417
  } elseif ( 'false' == $this->last_activity->akismet_submission['bp_as_result'] ) {
418
  bp_activity_update_meta( $activity->id, '_bp_akismet_result', 'false' );
419
  $this->update_activity_history( $activity->id, __( 'Akismet cleared this item', 'buddypress' ), 'check-ham' );
424
  $this->update_activity_history( $activity->id, sprintf( __( 'Akismet was unable to check this item (response: %s), will automatically retry again later.', 'buddypress' ), $this->last_activity->akismet_submission['bp_as_result'] ), 'check-error' );
425
  }
426
 
427
+ // Record the original data which was submitted to Akismet for checking
428
  bp_activity_update_meta( $activity->id, '_bp_akismet_submission', $this->last_activity->akismet_submission );
429
  }
430
 
431
  /**
432
  * Contact Akismet to check if this is spam or ham.
433
  *
434
+ * Props to WordPress core Akismet plugin for alot of this.
435
+ *
436
+ * @since BuddyPress (1.6)
437
  *
438
+ * @global string $akismet_api_host
439
+ * @global string $akismet_api_port
440
  *
441
+ * @param array $activity_data Packet of information to submit to Akismet.
442
+ * @param string $check "check" or "submit".
443
+ * @param string $spam "spam" or "ham".
444
  * @return array $activity_data Activity data, with Akismet data added.
445
  */
446
  public function send_akismet_request( $activity_data, $check = 'check', $spam = 'spam' ) {
447
+ global $akismet_api_host, $akismet_api_port;
448
+
449
+ // Check that host and port are set, if not, set them
450
+ if ( function_exists( 'akismet_init' ) && ( empty( $akismet_api_host ) || empty( $akismet_api_port ) ) )
451
+ akismet_init();
452
+
453
+ $query_string = $path = $response = '';
454
 
455
  $activity_data['blog'] = bp_get_option( 'home' );
456
  $activity_data['blog_charset'] = bp_get_option( 'blog_charset' );
459
  $activity_data['user_agent'] = bp_core_current_user_ua();
460
  $activity_data['user_ip'] = bp_core_current_user_ip();
461
 
462
+ if ( akismet_test_mode() )
463
  $activity_data['is_test'] = 'true';
464
 
465
+ // Loop through _POST args and rekey strings
466
  foreach ( $_POST as $key => $value )
467
  if ( is_string( $value ) && 'cookie' != $key )
468
  $activity_data['POST_' . $key] = $value;
469
 
470
+ // Keys to ignore
471
  $ignore = array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' );
472
 
473
+ // Loop through _SERVER args and remove whitelisted keys
474
  foreach ( $_SERVER as $key => $value ) {
475
 
476
+ // Key should not be ignored
477
  if ( !in_array( $key, $ignore ) && is_string( $value ) ) {
478
  $activity_data[$key] = $value;
479
 
480
+ // Key should be ignored
481
  } else {
482
  $activity_data[$key] = '';
483
  }
487
  $query_string .= $key . '=' . urlencode( stripslashes( $data ) ) . '&';
488
 
489
  if ( 'check' == $check )
490
+ $path = '/1.1/comment-check';
491
  elseif ( 'submit' == $check )
492
+ $path = '/1.1/submit-' . $spam;
493
 
494
+ // Send to Akismet
495
  add_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) );
496
+ $response = akismet_http_post( $query_string, $akismet_api_host, $path, $akismet_api_port );
497
  remove_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) );
498
 
499
+ // Get the response
500
  if ( ! empty( $response[1] ) && ! is_wp_error( $response[1] ) )
501
  $activity_data['bp_as_result'] = $response[1];
502
  else
503
  $activity_data['bp_as_result'] = false;
504
 
505
+ // Perform a daily tidy up
506
  if ( ! wp_next_scheduled( 'bp_activity_akismet_delete_old_metadata' ) )
507
  wp_schedule_event( time(), 'daily', 'bp_activity_akismet_delete_old_metadata' );
508
 
512
  /**
513
  * Filters user agent when sending to Akismet to add BuddyPress info.
514
  *
515
+ * @since BuddyPress (1.6)
516
  *
517
  * @param string $user_agent User agent string, as generated by Akismet.
518
  * @return string $user_agent Modified user agent string.
525
  /**
526
  * Adds a "History" meta box to the activity edit screen.
527
  *
528
+ * @since BuddyPress (1.6)
529
  *
530
  * @param string $screen_action The type of screen that has been requested.
531
  */
532
  function add_history_metabox( $screen_action ) {
533
+ // Only proceed if we're on the edit screen
534
  if ( 'edit' != $screen_action )
535
  return;
536
 
537
+ // Display meta box with a low priority (low position on screen by default)
538
  add_meta_box( 'bp_activity_history', __( 'Activity History', 'buddypress' ), array( $this, 'history_metabox' ), get_current_screen()->id, 'normal', 'low' );
539
  }
540
 
541
  /**
542
  * History meta box for the Activity admin edit screen.
543
  *
544
+ * @since BuddyPress (1.6)
545
  *
546
+ * @see http://buddypress.trac.wordpress.org/ticket/3907
547
  * @todo Update activity meta to allow >1 record with the same key (iterate through $history).
548
  *
549
  * @param object $item Activity item.
555
  return;
556
 
557
  echo '<div class="akismet-history"><div>';
558
+ printf( _x( '<span>%1$s</span> &mdash; %2$s', 'x hours ago - akismet cleared this item', 'buddypress' ), bp_core_time_since( $history[2] ), esc_html( $history[1] ) );
559
  echo '</div></div>';
560
  }
561
 
562
  /**
563
  * Update an activity item's Akismet history.
564
  *
565
+ * @since BuddyPress (1.6)
566
  *
567
+ * @param int $activity_id Activity item ID.
568
+ * @param string $message Human-readable description of what's changed.
569
+ * @param string $event The type of check we were carrying out.
570
  */
571
  public function update_activity_history( $activity_id = 0, $message = '', $event = '' ) {
572
  $event = array(
573
  'event' => $event,
574
  'message' => $message,
575
+ 'time' => akismet_microtime(),
576
  'user' => bp_loggedin_user_id(),
577
  );
578
 
579
+ // Save the history data
580
  bp_activity_update_meta( $activity_id, '_bp_akismet_history', $event );
581
  }
582
 
583
  /**
584
  * Get an activity item's Akismet history.
585
  *
586
+ * @since BuddyPress (1.6)
587
  *
588
  * @param int $activity_id Activity item ID.
589
  * @return array The activity item's Akismet history.
593
  if ( $history === false )
594
  $history = array();
595
 
596
+ // Sort it by the time recorded
597
  usort( $history, 'akismet_cmp_time' );
598
 
599
  return $history;
601
  }
602
 
603
  /**
604
+ * Delete old spam activity meta data
605
  *
606
  * This is done as a clean-up mechanism, as _bp_akismet_submission meta can
607
  * grow to be quite large.
608
  *
609
+ * @since BuddyPress (1.6)
610
  *
611
+ * @global object $bp BuddyPress global settings.
612
  * @global wpdb $wpdb WordPress database object.
613
  */
614
  function bp_activity_akismet_delete_old_metadata() {
615
+ global $bp, $wpdb;
616
 
 
 
 
 
 
 
 
 
 
617
  $interval = apply_filters( 'bp_activity_akismet_delete_meta_interval', 15 );
618
 
619
+ // Enforce a minimum of 1 day
620
  $interval = max( 1, absint( $interval ) );
621
 
622
  // _bp_akismet_submission meta values are large, so expire them after $interval days regardless of the activity status
bp-activity/bp-activity-cache.php CHANGED
@@ -1,14 +1,13 @@
1
  <?php
 
2
  /**
3
  * Functions related to the BuddyPress Activity component and the WP Cache.
4
  *
5
- * @since 1.6.0
6
- * @package BuddyPress
7
- * @subpackage ActivityCache
8
  */
9
 
10
- // Exit if accessed directly.
11
- defined( 'ABSPATH' ) || exit;
12
 
13
  /**
14
  * Slurp up activitymeta for a specified set of activity items.
@@ -17,11 +16,11 @@ defined( 'ABSPATH' ) || exit;
17
  * in $activity_ids and adds it to the WP cache. This improves efficiency when
18
  * using querying activitymeta inline.
19
  *
20
- * @param int|string|array|bool $activity_ids Accepts a single activity ID, or a comma-
21
- * separated list or array of activity ids.
22
  */
23
  function bp_activity_update_meta_cache( $activity_ids = false ) {
24
- $bp = buddypress();
25
 
26
  $cache_args = array(
27
  'object_ids' => $activity_ids,
@@ -38,20 +37,19 @@ function bp_activity_update_meta_cache( $activity_ids = false ) {
38
  /**
39
  * Clear a cached activity item when that item is updated.
40
  *
41
- * @since 2.0.0
42
  *
43
- * @param BP_Activity_Activity $activity Activity object.
44
  */
45
  function bp_activity_clear_cache_for_activity( $activity ) {
46
  wp_cache_delete( $activity->id, 'bp_activity' );
47
- wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
48
  }
49
  add_action( 'bp_activity_after_save', 'bp_activity_clear_cache_for_activity' );
50
 
51
  /**
52
  * Clear cached data for deleted activity items.
53
  *
54
- * @since 2.0.0
55
  *
56
  * @param array $deleted_ids IDs of deleted activity items.
57
  */
1
  <?php
2
+
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
10
+ if ( !defined( 'ABSPATH' ) ) exit;
11
 
12
  /**
13
  * Slurp up activitymeta for a specified set of activity items.
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
  /**
38
  * Clear a cached activity item when that item is updated.
39
  *
40
+ * @since 2.0
41
  *
42
+ * @param BP_Activity_Activity $activity
43
  */
44
  function bp_activity_clear_cache_for_activity( $activity ) {
45
  wp_cache_delete( $activity->id, 'bp_activity' );
 
46
  }
47
  add_action( 'bp_activity_after_save', 'bp_activity_clear_cache_for_activity' );
48
 
49
  /**
50
  * Clear cached data for deleted activity items.
51
  *
52
+ * @since 2.0
53
  *
54
  * @param array $deleted_ids IDs of deleted activity items.
55
  */
bp-activity/bp-activity-classes.php CHANGED
@@ -1,14 +1,1682 @@
1
  <?php
2
  /**
3
- * BuddyPress Activity Classes.
4
  *
5
  * @package BuddyPress
6
- * @subpackage ActivityClasses
7
  */
8
 
9
- // Exit if accessed directly.
10
- defined( 'ABSPATH' ) || exit;
11
 
12
- require dirname( __FILE__ ) . '/classes/class-bp-activity-activity.php';
13
- require dirname( __FILE__ ) . '/classes/class-bp-activity-feed.php';
14
- require dirname( __FILE__ ) . '/classes/class-bp-activity-query.php';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
  /**
3
+ * BuddyPress Activity Classes
4
  *
5
  * @package BuddyPress
6
+ * @subpackage Activity
7
  */
8
 
9
+ // Exit if accessed directly
10
+ if ( !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, $bp;
139
+
140
+ $row = wp_cache_get( $this->id, 'bp_activity' );
141
+
142
+ if ( false === $row ) {
143
+ $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id = %d", $this->id ) );
144
+
145
+ wp_cache_set( $this->id, $row, 'bp_activity' );
146
+ }
147
+
148
+ if ( ! empty( $row ) ) {
149
+ $this->id = $row->id;
150
+ $this->item_id = $row->item_id;
151
+ $this->secondary_item_id = $row->secondary_item_id;
152
+ $this->user_id = $row->user_id;
153
+ $this->primary_link = $row->primary_link;
154
+ $this->component = $row->component;
155
+ $this->type = $row->type;
156
+ $this->action = $row->action;
157
+ $this->content = $row->content;
158
+ $this->date_recorded = $row->date_recorded;
159
+ $this->hide_sitewide = $row->hide_sitewide;
160
+ $this->mptt_left = $row->mptt_left;
161
+ $this->mptt_right = $row->mptt_right;
162
+ $this->is_spam = $row->is_spam;
163
+ }
164
+
165
+ // Generate dynamic 'action' when possible
166
+ $action = bp_activity_generate_action_string( $this );
167
+ if ( false !== $action ) {
168
+ $this->action = $action;
169
+
170
+ // If no callback is available, use the literal string from
171
+ // the database row
172
+ } else if ( ! empty( $row->action ) ) {
173
+ $this->action = $row->action;
174
+
175
+ // Provide a fallback to avoid PHP notices
176
+ } else {
177
+ $this->action = '';
178
+ }
179
+ }
180
+
181
+ /**
182
+ * Save the activity item to the database.
183
+ *
184
+ * @return bool True on success.
185
+ */
186
+ public function save() {
187
+ global $wpdb, $bp;
188
+
189
+ $this->id = apply_filters_ref_array( 'bp_activity_id_before_save', array( $this->id, &$this ) );
190
+ $this->item_id = apply_filters_ref_array( 'bp_activity_item_id_before_save', array( $this->item_id, &$this ) );
191
+ $this->secondary_item_id = apply_filters_ref_array( 'bp_activity_secondary_item_id_before_save', array( $this->secondary_item_id, &$this ) );
192
+ $this->user_id = apply_filters_ref_array( 'bp_activity_user_id_before_save', array( $this->user_id, &$this ) );
193
+ $this->primary_link = apply_filters_ref_array( 'bp_activity_primary_link_before_save', array( $this->primary_link, &$this ) );
194
+ $this->component = apply_filters_ref_array( 'bp_activity_component_before_save', array( $this->component, &$this ) );
195
+ $this->type = apply_filters_ref_array( 'bp_activity_type_before_save', array( $this->type, &$this ) );
196
+ $this->action = apply_filters_ref_array( 'bp_activity_action_before_save', array( $this->action, &$this ) );
197
+ $this->content = apply_filters_ref_array( 'bp_activity_content_before_save', array( $this->content, &$this ) );
198
+ $this->date_recorded = apply_filters_ref_array( 'bp_activity_date_recorded_before_save', array( $this->date_recorded, &$this ) );
199
+ $this->hide_sitewide = apply_filters_ref_array( 'bp_activity_hide_sitewide_before_save', array( $this->hide_sitewide, &$this ) );
200
+ $this->mptt_left = apply_filters_ref_array( 'bp_activity_mptt_left_before_save', array( $this->mptt_left, &$this ) );
201
+ $this->mptt_right = apply_filters_ref_array( 'bp_activity_mptt_right_before_save', array( $this->mptt_right, &$this ) );
202
+ $this->is_spam = apply_filters_ref_array( 'bp_activity_is_spam_before_save', array( $this->is_spam, &$this ) );
203
+
204
+ // Use this, not the filters above
205
+ do_action_ref_array( 'bp_activity_before_save', array( &$this ) );
206
+
207
+ if ( !$this->component || !$this->type )
208
+ return false;
209
+
210
+ if ( !$this->primary_link )
211
+ $this->primary_link = bp_loggedin_user_domain();
212
+
213
+ // If we have an existing ID, update the activity item, otherwise insert it.
214
+ if ( $this->id )
215
+ $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 );
216
+ else
217
+ $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 );
218
+
219
+ if ( false === $wpdb->query( $q ) )
220
+ return false;
221
+
222
+ // If this is a new activity item, set the $id property
223
+ if ( empty( $this->id ) )
224
+ $this->id = $wpdb->insert_id;
225
+
226
+ // If an existing activity item, prevent any changes to the content generating new @mention notifications.
227
+ else
228
+ add_filter( 'bp_activity_at_name_do_notifications', '__return_false' );
229
+
230
+ do_action_ref_array( 'bp_activity_after_save', array( &$this ) );
231
+
232
+ return true;
233
+ }
234
+
235
+ /** Static Methods ***************************************************/
236
+
237
+ /**
238
+ * Get activity items, as specified by parameters
239
+ *
240
+ * @see BP_Activity_Activity::get_filter_sql() for a description of the
241
+ * 'filter' parameter.
242
+ * @see WP_Meta_Query::queries for a description of the 'meta_query'
243
+ * parameter format.
244
+ *
245
+ * @param array $args {
246
+ * An array of arguments. All items are optional.
247
+ * @type int $page Which page of results to fetch. Using page=1
248
+ * without per_page will result in no pagination.
249
+ * Default: 1.
250
+ * @type int|bool $per_page Number of results per page. Default: 25.
251
+ * @type int|bool $max Maximum number of results to return.
252
+ * Default: false (unlimited).
253
+ * @type string $sort ASC or DESC. Default: 'DESC'.
254
+ * @type array $exclude Array of activity IDs to exclude.
255
+ * Default: false.
256
+ * @type array $in Array of ids to limit query by (IN).
257
+ * Default: false.
258
+ * @type array $meta_query An array of meta_query conditions.
259
+ * See WP_Meta_Query::queries for description.
260
+ * @type array $filter See BP_Activity_Activity::get_filter_sql().
261
+ * @type string $search_terms Limit results by a search term.
262
+ * Default: false.
263
+ * @type bool $display_comments Whether to include activity comments.
264
+ * Default: false.
265
+ * @type bool $show_hidden Whether to show items marked hide_sitewide.
266
+ * Default: false.
267
+ * @type string $spam Spam status. Default: 'ham_only'.
268
+ * @type bool $update_meta_cache Whether to pre-fetch metadata for
269
+ * queried activity items. Default: true.
270
+ * }
271
+ * @return array The array returned has two keys:
272
+ * - 'total' is the count of located activities
273
+ * - 'activities' is an array of the located activities
274
+ */
275
+ public static function get( $args = array() ) {
276
+ global $wpdb, $bp;
277
+
278
+ // Backward compatibility with old method of passing arguments
279
+ if ( !is_array( $args ) || func_num_args() > 1 ) {
280
+ _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__ ) );
281
+
282
+ $old_args_keys = array(
283
+ 0 => 'max',
284
+ 1 => 'page',
285
+ 2 => 'per_page',
286
+ 3 => 'sort',
287
+ 4 => 'search_terms',
288
+ 5 => 'filter',
289
+ 6 => 'display_comments',
290
+ 7 => 'show_hidden',
291
+ 8 => 'exclude',
292
+ 9 => 'in',
293
+ 10 => 'spam'
294
+ );
295
+
296
+ $func_args = func_get_args();
297
+ $args = bp_core_parse_args_array( $old_args_keys, $func_args );
298
+ }
299
+
300
+ $defaults = array(
301
+ 'page' => 1, // The current page
302
+ 'per_page' => 25, // Activity items per page
303
+ 'max' => false, // Max number of items to return
304
+ 'sort' => 'DESC', // ASC or DESC
305
+ 'exclude' => false, // Array of ids to exclude
306
+ 'in' => false, // Array of ids to limit query by (IN)
307
+ 'meta_query' => false, // Filter by activitymeta
308
+ 'filter' => false, // See self::get_filter_sql()
309
+ 'search_terms' => false, // Terms to search by
310
+ 'display_comments' => false, // Whether to include activity comments
311
+ 'show_hidden' => false, // Show items marked hide_sitewide
312
+ 'spam' => 'ham_only', // Spam status
313
+ 'update_meta_cache' => true,
314
+ );
315
+ $r = wp_parse_args( $args, $defaults );
316
+ extract( $r );
317
+
318
+ // Select conditions
319
+ $select_sql = "SELECT DISTINCT a.id";
320
+
321
+ $from_sql = " FROM {$bp->activity->table_name} a";
322
+
323
+ $join_sql = '';
324
+
325
+ // Where conditions
326
+ $where_conditions = array();
327
+
328
+ // Spam
329
+ if ( 'ham_only' == $spam )
330
+ $where_conditions['spam_sql'] = 'a.is_spam = 0';
331
+ elseif ( 'spam_only' == $spam )
332
+ $where_conditions['spam_sql'] = 'a.is_spam = 1';
333
+
334
+ // Searching
335
+ if ( $search_terms ) {
336
+ $search_terms = esc_sql( $search_terms );
337
+ $where_conditions['search_sql'] = "a.content LIKE '%%" . esc_sql( like_escape( $search_terms ) ) . "%%'";
338
+ }
339
+
340
+ // Filtering
341
+ if ( $filter && $filter_sql = BP_Activity_Activity::get_filter_sql( $filter ) )
342
+ $where_conditions['filter_sql'] = $filter_sql;
343
+
344
+ // Sorting
345
+ if ( $sort != 'ASC' && $sort != 'DESC' )
346
+ $sort = 'DESC';
347
+
348
+ // Hide Hidden Items?
349
+ if ( !$show_hidden )
350
+ $where_conditions['hidden_sql'] = "a.hide_sitewide = 0";
351
+
352
+ // Exclude specified items
353
+ if ( !empty( $exclude ) ) {
354
+ $exclude = implode( ',', wp_parse_id_list( $exclude ) );
355
+ $where_conditions['exclude'] = "a.id NOT IN ({$exclude})";
356
+ }
357
+
358
+ // The specific ids to which you want to limit the query
359
+ if ( !empty( $in ) ) {
360
+ $in = implode( ',', wp_parse_id_list( $in ) );
361
+ $where_conditions['in'] = "a.id IN ({$in})";
362
+ }
363
+
364
+ // Process meta_query into SQL
365
+ $meta_query_sql = self::get_meta_query_sql( $meta_query );
366
+
367
+ if ( ! empty( $meta_query_sql['join'] ) ) {
368
+ $join_sql .= $meta_query_sql['join'];
369
+ }
370
+
371
+ if ( ! empty( $meta_query_sql['where'] ) ) {
372
+ $where_conditions[] = $meta_query_sql['where'];
373
+ }
374
+
375
+ // Alter the query based on whether we want to show activity item
376
+ // comments in the stream like normal comments or threaded below
377
+ // the activity.
378
+ if ( false === $display_comments || 'threaded' === $display_comments ) {
379
+ $where_conditions[] = "a.type != 'activity_comment'";
380
+ }
381
+
382
+ // Exclude 'last_activity' items unless the 'action' filter has
383
+ // been explicitly set
384
+ if ( empty( $filter['object'] ) ) {
385
+ $where_conditions[] = "a.type != 'last_activity'";
386
+ }
387
+
388
+ // Filter the where conditions
389
+ $where_conditions = apply_filters( 'bp_activity_get_where_conditions', $where_conditions, $r, $select_sql, $from_sql, $join_sql );
390
+
391
+ // Join the where conditions together
392
+ $where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
393
+
394
+ // Define the preferred order for indexes
395
+ $indexes = apply_filters( 'bp_activity_preferred_index_order', array( 'user_id', 'item_id', 'secondary_item_id', 'date_recorded', 'component', 'type', 'hide_sitewide', 'is_spam' ) );
396
+
397
+ foreach( $indexes as $key => $index ) {
398
+ if ( false !== strpos( $where_sql, $index ) ) {
399
+ $the_index = $index;
400
+ break; // Take the first one we find
401
+ }
402
+ }
403
+
404
+ if ( !empty( $the_index ) ) {
405
+ $index_hint_sql = "USE INDEX ({$the_index})";
406
+ } else {
407
+ $index_hint_sql = '';
408
+ }
409
+
410
+ // Sanitize page and per_page parameters
411
+ $page = absint( $page );
412
+ $per_page = absint( $per_page );
413
+
414
+ // Filter and return true to use the legacy query structure (not recommended)
415
+ if ( apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, $r ) ) {
416
+
417
+ // Legacy queries joined against the user table
418
+ $select_sql = "SELECT DISTINCT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name";
419
+ $from_sql = " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID";
420
+
421
+ if ( ! empty( $page ) && ! empty( $per_page ) ) {
422
+ $pag_sql = $wpdb->prepare( "LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page );
423
+ $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 ) );
424
+ } else {
425
+ $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 ) );
426
+ }
427
+
428
+ } else {
429
+
430
+ // Query first for activity IDs
431
+ $activity_ids_sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort}";
432
+
433
+ if ( ! empty( $per_page ) && ! empty( $page ) ) {
434
+ $activity_ids_sql .= $wpdb->prepare( " LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page );
435
+ }
436
+
437
+ $activity_ids_sql = apply_filters( 'bp_activity_paged_activities_sql', $activity_ids_sql, $r );
438
+
439
+ $activity_ids = $wpdb->get_col( $activity_ids_sql );
440
+ $activities = self::get_activity_data( $activity_ids );
441
+ }
442
+
443
+ $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 );
444
+ $total_activities = $wpdb->get_var( $total_activities_sql );
445
+
446
+ // Get the fullnames of users so we don't have to query in the loop
447
+ $activities = self::append_user_fullnames( $activities );
448
+
449
+ // Get activity meta
450
+ $activity_ids = array();
451
+ foreach ( (array) $activities as $activity ) {
452
+ $activity_ids[] = $activity->id;
453
+ }
454
+
455
+ if ( ! empty( $activity_ids ) && $update_meta_cache ) {
456
+ bp_activity_update_meta_cache( $activity_ids );
457
+ }
458
+
459
+ if ( $activities && $display_comments )
460
+ $activities = BP_Activity_Activity::append_comments( $activities, $spam );
461
+
462
+ // Pre-fetch data associated with activity users and other objects
463
+ BP_Activity_Activity::prefetch_object_data( $activities );
464
+
465
+ // Generate action strings
466
+ $activities = BP_Activity_Activity::generate_action_strings( $activities );
467
+
468
+ // If $max is set, only return up to the max results
469
+ if ( !empty( $max ) ) {
470
+ if ( (int) $total_activities > (int) $max )
471
+ $total_activities = $max;
472
+ }
473
+
474
+ return array( 'activities' => $activities, 'total' => (int) $total_activities );
475
+ }
476
+
477
+ /**
478
+ * Convert activity IDs to activity objects, as expected in template loop.
479
+ *
480
+ * @since 2.0
481
+ *
482
+ * @param array $activity_ids Array of activity IDs.
483
+ * @return array
484
+ */
485
+ protected static function get_activity_data( $activity_ids = array() ) {
486
+ global $wpdb;
487
+
488
+ // Bail if no activity ID's passed
489
+ if ( empty( $activity_ids ) ) {
490
+ return array();
491
+ }
492
+
493
+ // Get BuddyPress
494
+ $bp = buddypress();
495
+
496
+ $activities = array();
497
+ $uncached_ids = bp_get_non_cached_ids( $activity_ids, 'bp_activity' );
498
+
499
+ // Prime caches as necessary
500
+ if ( ! empty( $uncached_ids ) ) {
501
+ // Format the activity ID's for use in the query below
502
+ $uncached_ids_sql = implode( ',', wp_parse_id_list( $uncached_ids ) );
503
+
504
+ // Fetch data from activity table, preserving order
505
+ $queried_adata = $wpdb->get_results( "SELECT * FROM {$bp->activity->table_name} WHERE id IN ({$uncached_ids_sql})");
506
+
507
+ // Put that data into the placeholders created earlier,
508
+ // and add it to the cache
509
+ foreach ( (array) $queried_adata as $adata ) {
510
+ wp_cache_set( $adata->id, $adata, 'bp_activity' );
511
+ }
512
+ }
513
+
514
+ // Now fetch data from the cache
515
+ foreach ( $activity_ids as $activity_id ) {
516
+ $activities[] = wp_cache_get( $activity_id, 'bp_activity' );
517
+ }
518
+
519
+ // Then fetch user data
520
+ $user_query = new BP_User_Query( array(
521
+ 'user_ids' => wp_list_pluck( $activities, 'user_id' ),
522
+ 'populate_extras' => false,
523
+ ) );
524
+
525
+ // Associated located user data with activity items
526
+ foreach ( $activities as $a_index => $a_item ) {
527
+ $a_user_id = intval( $a_item->user_id );
528
+ $a_user = isset( $user_query->results[ $a_user_id ] ) ? $user_query->results[ $a_user_id ] : '';
529
+
530
+ if ( !empty( $a_user ) ) {
531
+ $activities[ $a_index ]->user_email = $a_user->user_email;
532
+ $activities[ $a_index ]->user_nicename = $a_user->user_nicename;
533
+ $activities[ $a_index ]->user_login = $a_user->user_login;
534
+ $activities[ $a_index ]->display_name = $a_user->display_name;
535
+ }
536
+ }
537
+
538
+ return $activities;
539
+ }
540
+
541
+ /**
542
+ * Append xProfile fullnames to an activity array.
543
+ *
544
+ * @since BuddyPress (2.0.0)
545
+ *
546
+ * @param array $activities Activities array.
547
+ * @return array
548
+ */
549
+ protected static function append_user_fullnames( $activities ) {
550
+ global $wpdb;
551
+
552
+ if ( bp_is_active( 'xprofile' ) && ! empty( $activities ) ) {
553
+ $activity_user_ids = wp_list_pluck( $activities, 'user_id' );
554
+
555
+ if ( ! empty( $activity_user_ids ) ) {
556
+ $fullnames = bp_core_get_user_displaynames( $activity_user_ids );
557
+ if ( ! empty( $fullnames ) ) {
558
+ foreach ( (array) $activities as $i => $activity ) {
559
+ if ( ! empty( $fullnames[ $activity->user_id ] ) ) {
560
+ $activities[ $i ]->user_fullname = $fullnames[ $activity->user_id ];
561
+ }
562
+ }
563
+ }
564
+ }
565
+ }
566
+
567
+ return $activities;
568
+ }
569
+
570
+ /**
571
+ * Pre-fetch data for objects associated with activity items.
572
+ *
573
+ * Activity items are associated with users, and often with other
574
+ * BuddyPress data objects. Here, we pre-fetch data about these
575
+ * associated objects, so that inline lookups - done primarily when
576
+ * building action strings - do not result in excess database queries.
577
+ *
578
+ * The only object data required for activity component activity types
579
+ * (activity_update and activity_comment) is related to users, and that
580
+ * info is fetched separately in BP_Activity_Activity::get_activity_data().
581
+ * So this method contains nothing but a filter that allows other
582
+ * components, such as bp-friends and bp-groups, to hook in and prime
583
+ * their own caches at the beginning of an activity loop.
584
+ *
585
+ * @since BuddyPress (2.0.0)
586
+ *
587
+ * @param array $activities Array of activities.
588
+ */
589
+ protected static function prefetch_object_data( $activities ) {
590
+ return apply_filters( 'bp_activity_prefetch_object_data', $activities );
591
+ }
592
+
593
+ /**
594
+ * Generate action strings for the activities located in BP_Activity_Activity::get().
595
+ *
596
+ * If no string can be dynamically generated for a given item
597
+ * (typically because the activity type has not been properly
598
+ * registered), the static 'action' value pulled from the database will
599
+ * be left in place.
600
+ *
601
+ * @since BuddyPress (2.0.0)
602
+ *
603
+ * @param array $activities Array of activities.
604
+ * @return array
605
+ */
606
+ protected static function generate_action_strings( $activities ) {
607
+ foreach ( $activities as $key => $activity ) {
608
+ $generated_action = bp_activity_generate_action_string( $activity );
609
+ if ( false !== $generated_action ) {
610
+ $activity->action = $generated_action;
611
+ }
612
+
613
+ $activities[ $key ] = $activity;
614
+ }
615
+
616
+ return $activities;
617
+ }
618
+
619
+ /**
620
+ * Get the SQL for the 'meta_query' param in BP_Activity_Activity::get().
621
+ *
622
+ * We use WP_Meta_Query to do the heavy lifting of parsing the
623
+ * meta_query array and creating the necessary SQL clauses. However,
624
+ * since BP_Activity_Activity::get() builds its SQL differently than
625
+ * WP_Query, we have to alter the return value (stripping the leading
626
+ * AND keyword from the 'where' clause).
627
+ *
628
+ * @since BuddyPress (1.8)
629
+ *
630
+ * @param array $meta_query An array of meta_query filters. See the
631
+ * documentation for WP_Meta_Query for details.
632
+ * @return array $sql_array 'join' and 'where' clauses.
633
+ */
634
+ public static function get_meta_query_sql( $meta_query = array() ) {
635
+ global $wpdb;
636
+
637
+ $sql_array = array(
638
+ 'join' => '',
639
+ 'where' => '',
640
+ );
641
+
642
+ if ( ! empty( $meta_query ) ) {
643
+ $activity_meta_query = new WP_Meta_Query( $meta_query );
644
+
645
+ // WP_Meta_Query expects the table name at
646
+ // $wpdb->activitymeta
647
+ $wpdb->activitymeta = buddypress()->activity->table_name_meta;
648
+
649
+ $meta_sql = $activity_meta_query->get_sql( 'activity', 'a', 'id' );
650
+
651
+ // Strip the leading AND - BP handles it in get()
652
+ $sql_array['where'] = preg_replace( '/^\sAND/', '', $meta_sql['where'] );
653
+ $sql_array['join'] = $meta_sql['join'];
654
+ }
655
+
656
+ return $sql_array;
657
+ }
658
+
659
+ /**
660
+ * In BuddyPress 1.2.x, this was used to retrieve specific activity stream items (for example, on an activity's permalink page).
661
+ *
662
+ * As of 1.5.x, use BP_Activity_Activity::get() with an 'in' parameter instead.
663
+ *
664
+ * @since BuddyPress (1.2)
665
+ *
666
+ * @deprecated 1.5
667
+ * @deprecated Use BP_Activity_Activity::get() with an 'in' parameter instead.
668
+ *
669
+ * @param mixed $activity_ids Array or comma-separated string of activity IDs to retrieve
670
+ * @param int $max Maximum number of results to return. (Optional; default is no maximum)
671
+ * @param int $page The set of results that the user is viewing. Used in pagination. (Optional; default is 1)
672
+ * @param int $per_page Specifies how many results per page. Used in pagination. (Optional; default is 25)
673
+ * @param string MySQL column sort; ASC or DESC. (Optional; default is DESC)
674
+ * @param bool $display_comments Retrieve an activity item's associated comments or not. (Optional; default is false)
675
+ * @return array
676
+ */
677
+ public static function get_specific( $activity_ids, $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $display_comments = false ) {
678
+ _deprecated_function( __FUNCTION__, '1.5', 'Use BP_Activity_Activity::get() with the "in" parameter instead.' );
679
+ return BP_Activity_Activity::get( $max, $page, $per_page, $sort, false, false, $display_comments, false, false, $activity_ids );
680
+ }
681
+
682
+ /**
683
+ * Get the first activity ID that matches a set of criteria.
684
+ *
685
+ * @param int $user_id The user ID to filter by.
686
+ * @param string $component The component to filter by.
687
+ * @param string $type The activity type to filter by.
688
+ * @param int $item_id The associated item to filter by.
689
+ * @param int $secondary_item_id The secondary associated item to filter by.
690
+ * @param string $action The action to filter by.
691
+ * @param string $content The content to filter by.
692
+ * @param string $date_recorded The date to filter by.
693
+ * @return int|bool Activity ID on success, false if none is found.
694
+ */
695
+ public static function get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content, $date_recorded ) {
696
+ global $bp, $wpdb;
697
+
698
+ $where_args = false;
699
+
700
+ if ( !empty( $user_id ) )
701
+ $where_args[] = $wpdb->prepare( "user_id = %d", $user_id );
702
+
703
+ if ( !empty( $component ) )
704
+ $where_args[] = $wpdb->prepare( "component = %s", $component );
705
+
706
+ if ( !empty( $type ) )
707
+ $where_args[] = $wpdb->prepare( "type = %s", $type );
708
+
709
+ if ( !empty( $item_id ) )
710
+ $where_args[] = $wpdb->prepare( "item_id = %d", $item_id );
711
+
712
+ if ( !empty( $secondary_item_id ) )
713
+ $where_args[] = $wpdb->prepare( "secondary_item_id = %d", $secondary_item_id );
714
+
715
+ if ( !empty( $action ) )
716
+ $where_args[] = $wpdb->prepare( "action = %s", $action );
717
+
718
+ if ( !empty( $content ) )
719
+ $where_args[] = $wpdb->prepare( "content = %s", $content );
720
+
721
+ if ( !empty( $date_recorded ) )
722
+ $where_args[] = $wpdb->prepare( "date_recorded = %s", $date_recorded );
723
+
724
+ if ( !empty( $where_args ) )
725
+ $where_sql = 'WHERE ' . join( ' AND ', $where_args );
726
+ else
727
+ return false;
728
+
729
+ return $wpdb->get_var( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" );
730
+ }
731
+
732
+ /**
733
+ * Delete activity items from the database.
734
+ *
735
+ * To delete a specific activity item, pass an 'id' parameter.
736
+ * Otherwise use the filters.
737
+ *
738
+ * @since BuddyPress (1.2)
739
+ *
740
+ * @param array $args {
741
+ * @int $id Optional. The ID of a specific item to delete.
742
+ * @string $action Optional. The action to filter by.
743
+ * @string $content Optional. The content to filter by.
744
+ * @string $component Optional. The component name to filter by.
745
+ * @string $type Optional. The activity type to filter by.
746
+ * @string $primary_link Optional. The primary URL to filter by.
747
+ * @int $user_id Optional. The user ID to filter by.
748
+ * @int $item_id Optional. The associated item ID to filter by.
749
+ * @int $secondary_item_id Optional. The secondary associated item ID to filter by.
750
+ * @string $date_recorded Optional. The date to filter by.
751
+ * @int $hide_sitewide Optional. Default: false.
752
+ * }
753
+ * @return array|bool An array of deleted activity IDs on success, false on failure.
754
+ */
755
+ public static function delete( $args = array() ) {
756
+ global $wpdb, $bp;
757
+
758
+ $defaults = array(
759
+ 'id' => false,
760
+ 'action' => false,
761
+ 'content' => false,
762
+ 'component' => false,
763
+ 'type' => false,
764
+ 'primary_link' => false,
765
+ 'user_id' => false,
766
+ 'item_id' => false,
767
+ 'secondary_item_id' => false,
768
+ 'date_recorded' => false,
769
+ 'hide_sitewide' => false
770
+ );
771
+ $params = wp_parse_args( $args, $defaults );
772
+ extract( $params );
773
+
774
+ $where_args = false;
775
+
776
+ if ( !empty( $id ) )
777
+ $where_args[] = $wpdb->prepare( "id = %d", $id );
778
+
779
+ if ( !empty( $user_id ) )
780
+ $where_args[] = $wpdb->prepare( "user_id = %d", $user_id );
781
+
782
+ if ( !empty( $action ) )
783
+ $where_args[] = $wpdb->prepare( "action = %s", $action );
784
+
785
+ if ( !empty( $content ) )
786
+ $where_args[] = $wpdb->prepare( "content = %s", $content );
787
+
788
+ if ( !empty( $component ) )
789
+ $where_args[] = $wpdb->prepare( "component = %s", $component );
790
+
791
+ if ( !empty( $type ) )
792
+ $where_args[] = $wpdb->prepare( "type = %s", $type );
793
+
794
+ if ( !empty( $primary_link ) )
795
+ $where_args[] = $wpdb->prepare( "primary_link = %s", $primary_link );
796
+
797
+ if ( !empty( $item_id ) )
798
+ $where_args[] = $wpdb->prepare( "item_id = %d", $item_id );
799
+
800
+ if ( !empty( $secondary_item_id ) )
801
+ $where_args[] = $wpdb->prepare( "secondary_item_id = %d", $secondary_item_id );
802
+
803
+ if ( !empty( $date_recorded ) )
804
+ $where_args[] = $wpdb->prepare( "date_recorded = %s", $date_recorded );
805
+
806
+ if ( !empty( $hide_sitewide ) )
807
+ $where_args[] = $wpdb->prepare( "hide_sitewide = %d", $hide_sitewide );
808
+
809
+ if ( !empty( $where_args ) )
810
+ $where_sql = 'WHERE ' . join( ' AND ', $where_args );
811
+ else
812
+ return false;
813
+
814
+ // Fetch the activity IDs so we can delete any comments for this activity item
815
+ $activity_ids = $wpdb->get_col( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" );
816
+
817
+ if ( ! $wpdb->query( "DELETE FROM {$bp->activity->table_name} {$where_sql}" ) ) {
818
+ return false;
819
+ }
820
+
821
+ // Handle accompanying activity comments and meta deletion
822
+ if ( $activity_ids ) {
823
+ $activity_ids_comma = implode( ',', wp_parse_id_list( $activity_ids ) );
824
+ $activity_comments_where_sql = "WHERE type = 'activity_comment' AND item_id IN ({$activity_ids_comma})";
825
+
826
+ // Fetch the activity comment IDs for our deleted activity items
827
+ $activity_comment_ids = $wpdb->get_col( "SELECT id FROM {$bp->activity->table_name} {$activity_comments_where_sql}" );
828
+
829
+ // We have activity comments!
830
+ if ( ! empty( $activity_comment_ids ) ) {
831
+ // Delete activity comments
832
+ $wpdb->query( "DELETE FROM {$bp->activity->table_name} {$activity_comments_where_sql}" );
833
+
834
+ // Merge activity IDs with activity comment IDs
835
+ $activity_ids = array_merge( $activity_ids, $activity_comment_ids );
836
+ }
837
+
838
+ // Delete all activity meta entries for activity items and activity comments
839
+ BP_Activity_Activity::delete_activity_meta_entries( $activity_ids );
840
+ }
841
+
842
+ return $activity_ids;
843
+ }
844
+
845
+ /**
846
+ * Delete the comments associated with a set of activity items.
847
+ *
848
+ * @since BuddyPress (1.2)
849
+ *
850
+ * @todo Mark as deprecated? Method is no longer used internally.
851
+ *
852
+ * @param array $activity_ids Activity IDs whose comments should be deleted.
853
+ * @param bool $delete_meta Should we delete the activity meta items for these comments?
854
+ * @return bool True on success.
855
+ */
856
+ public static function delete_activity_item_comments( $activity_ids = array(), $delete_meta = true ) {
857
+ global $bp, $wpdb;
858
+
859
+ $delete_meta = (bool) $delete_meta;
860
+
861
+ $activity_ids = implode( ',', wp_parse_id_list( $activity_ids ) );
862
+
863
+ if ( $delete_meta ) {
864
+ // Fetch the activity comment IDs for our deleted activity items
865
+ $activity_comment_ids = $wpdb->get_col( "SELECT id FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND item_id IN ({$activity_ids})" );
866
+
867
+ if ( ! empty( $activity_comment_ids ) ) {
868
+ self::delete_activity_meta_entries( $activity_comment_ids );
869
+ }
870
+ }
871
+
872
+ return $wpdb->query( "DELETE FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND item_id IN ({$activity_ids})" );
873
+ }
874
+
875
+ /**
876
+ * Delete the meta entries associated with a set of activity items.
877
+ *
878
+ * @since BuddyPress (1.2)
879
+ *
880
+ * @param array $activity_ids Activity IDs whose meta should be deleted.
881
+ * @return bool True on success.
882
+ */
883
+ public static function delete_activity_meta_entries( $activity_ids = array() ) {
884
+ $activity_ids = wp_parse_id_list( $activity_ids );
885
+
886
+ foreach ( $activity_ids as $activity_id ) {
887
+ bp_activity_delete_meta( $activity_id );
888
+ }
889
+
890
+ return true;
891
+ }
892
+
893
+ /**
894
+ * Append activity comments to their associated activity items.
895
+ *
896
+ * @since BuddyPress (1.2)
897
+ *
898
+ * @global wpdb $wpdb WordPress database object
899
+ *
900
+ * @param array $activities Activities to fetch comments for.
901
+ * @param bool $spam Optional. 'ham_only' (default), 'spam_only' or 'all'.
902
+ * @return array The updated activities with nested comments.
903
+ */
904
+ public static function append_comments( $activities, $spam = 'ham_only' ) {
905
+ $activity_comments = array();
906
+
907
+ // Now fetch the activity comments and parse them into the correct position in the activities array.
908
+ foreach ( (array) $activities as $activity ) {
909
+ $top_level_parent_id = 'activity_comment' == $activity->type ? $activity->item_id : 0;
910
+ $activity_comments[$activity->id] = BP_Activity_Activity::get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right, $spam, $top_level_parent_id );
911
+ }
912
+
913
+ // Merge the comments with the activity items
914
+ foreach ( (array) $activities as $key => $activity ) {
915
+ if ( isset( $activity_comments[$activity->id] ) ) {
916
+ $activities[$key]->children = $activity_comments[$activity->id];
917
+ }
918
+ }
919
+
920
+ return $activities;
921
+ }
922
+
923
+ /**
924
+ * Get activity comments that are associated with a specific activity ID.
925
+ *
926
+ * @since BuddyPress (1.2)
927
+ *
928
+ * @global BuddyPress $bp The one true BuddyPress instance.
929
+ * @global wpdb $wpdb WordPress database object.
930
+ *
931
+ * @param int $activity_id Activity ID to fetch comments for.
932
+ * @param int $left Left-most node boundary.
933
+ * @param into $right Right-most node boundary.
934
+ * @param bool $spam Optional. 'ham_only' (default), 'spam_only' or 'all'.
935
+ * @param int $top_level_parent_id Optional. The id of the root-level parent activity item.
936
+ * @return array The updated activities with nested comments.
937
+ */
938
+ public static function get_activity_comments( $activity_id, $left, $right, $spam = 'ham_only', $top_level_parent_id = 0 ) {
939
+ global $wpdb, $bp;
940
+
941
+ if ( empty( $top_level_parent_id ) ) {
942
+ $top_level_parent_id = $activity_id;
943
+ }
944
+
945
+ $comments = wp_cache_get( $activity_id, 'bp_activity_comments' );
946
+
947
+ // We store the string 'none' to cache the fact that the
948
+ // activity item has no comments
949
+ if ( 'none' === $comments ) {
950
+ $comments = false;
951
+
952
+ // A true cache miss
953
+ } else if ( empty( $comments ) ) {
954
+
955
+ // Select the user's fullname with the query
956
+ if ( bp_is_active( 'xprofile' ) ) {
957
+ $fullname_select = ", pd.value as user_fullname";
958
+ $fullname_from = ", {$bp->profile->table_name_data} pd ";
959
+ $fullname_where = "AND pd.user_id = a.user_id AND pd.field_id = 1";
960
+
961
+ // Prevent debug errors
962
+ } else {
963
+ $fullname_select = $fullname_from = $fullname_where = '';
964
+ }
965
+
966
+ // Don't retrieve activity comments marked as spam
967
+ if ( 'ham_only' == $spam ) {
968
+ $spam_sql = 'AND a.is_spam = 0';
969
+ } elseif ( 'spam_only' == $spam ) {
970
+ $spam_sql = 'AND a.is_spam = 1';
971
+ } else {
972
+ $spam_sql = '';
973
+ }
974
+
975
+ // Legacy query - not recommended
976
+ $func_args = func_get_args();
977
+ if ( apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, $func_args ) ) {
978
+ $sql = apply_filters( 'bp_activity_comments_user_join_filter', $wpdb->prepare( "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp->activity->table_name} a, {$wpdb->users} u{$fullname_from} WHERE u.ID = a.user_id {$fullname_where} AND a.type = 'activity_comment' {$spam_sql} AND a.item_id = %d AND a.mptt_left > %d AND a.mptt_left < %d ORDER BY a.date_recorded ASC", $top_level_parent_id, $left, $right ), $activity_id, $left, $right, $spam_sql );
979
+
980
+ $descendants = $wpdb->get_results( $sql );
981
+
982
+ // We use the mptt BETWEEN clause to limit returned
983
+ // descendants to the correct part of the tree.
984
+ } else {
985
+ $sql = $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} a WHERE a.type = 'activity_comment' {$spam_sql} AND a.item_id = %d and a.mptt_left > %d AND a.mptt_left < %d ORDER BY a.date_recorded ASC", $top_level_parent_id, $left, $right );
986
+
987
+ $descendant_ids = $wpdb->get_col( $sql );
988
+ $descendants = self::get_activity_data( $descendant_ids );
989
+ $descendants = self::append_user_fullnames( $descendants );
990
+ }
991
+
992
+ $ref = array();
993
+
994
+ // Loop descendants and build an assoc array
995
+ foreach ( (array) $descendants as $d ) {
996
+ $d->children = array();
997
+
998
+ // If we have a reference on the parent
999
+ if ( isset( $ref[ $d->secondary_item_id ] ) ) {
1000
+ $ref[ $d->secondary_item_id ]->children[ $d->id ] = $d;
1001
+ $ref[ $d->id ] =& $ref[ $d->secondary_item_id ]->children[ $d->id ];
1002
+
1003
+ // If we don't have a reference on the parent, put in the root level
1004
+ } else {
1005
+ $comments[ $d->id ] = $d;
1006
+ $ref[ $d->id ] =& $comments[ $d->id ];
1007
+ }
1008
+ }
1009
+
1010
+ // Calculate depth for each item
1011
+ foreach ( $ref as &$r ) {
1012
+ $depth = 1;
1013
+ $parent_id = $r->secondary_item_id;
1014
+ while ( $parent_id !== $r->item_id ) {
1015
+ $depth++;
1016
+
1017
+ // When display_comments=stream, the
1018
+ // parent comment may not be part of
1019
+ // the returned results, so we manually
1020
+ // fetch it
1021
+ if ( empty( $ref[ $parent_id ] ) ) {
1022
+ $direct_parent = new BP_Activity_Activity( $parent_id );
1023
+ if ( isset( $direct_parent->secondary_item_id ) ) {
1024
+ $parent_id = $direct_parent->secondary_item_id;
1025
+ } else {
1026
+ // Something went wrong
1027
+ // Short-circuit the
1028
+ // depth calculation
1029
+ $parent_id = $r->item_id;
1030
+ }
1031
+ } else {
1032
+ $parent_id = $ref[ $parent_id ]->secondary_item_id;
1033
+ }
1034
+ }
1035
+ $r->depth = $depth;
1036
+ }
1037
+
1038
+ // If we cache a value of false, it'll count as a cache
1039
+ // miss the next time the activity comments are fetched.
1040
+ // Storing the string 'none' is a hack workaround to
1041
+ // avoid unnecessary queries.
1042
+ if ( false === $comments ) {
1043
+ $cache_value = 'none';
1044
+ } else {
1045
+ $cache_value = $comments;
1046
+ }
1047
+
1048
+ wp_cache_set( $activity_id, $cache_value, 'bp_activity_comments' );
1049
+ }
1050
+
1051
+ return $comments;
1052
+ }
1053
+
1054
+ /**
1055
+ * Rebuild nested comment tree under an activity or activity comment.
1056
+ *
1057
+ * @since BuddyPress (1.2)
1058
+ *
1059
+ * @global BuddyPress $bp The one true BuddyPress instance.
1060
+ * @global wpdb $wpdb WordPress database object.
1061
+ *
1062
+ * @param int $parent_id ID of an activty or activity comment.
1063
+ * @param int $left Node boundary start for activity or activity comment.
1064
+ * @return int Right node boundary of activity or activity comment.
1065
+ */
1066
+ public static function rebuild_activity_comment_tree( $parent_id, $left = 1 ) {
1067
+ global $wpdb, $bp;
1068
+
1069
+ // The right value of this node is the left value + 1
1070
+ $right = $left + 1;
1071
+
1072
+ // Get all descendants of this node
1073
+ $descendants = BP_Activity_Activity::get_child_comments( $parent_id );
1074
+
1075
+ // Loop the descendants and recalculate the left and right values
1076
+ foreach ( (array) $descendants as $descendant )
1077
+ $right = BP_Activity_Activity::rebuild_activity_comment_tree( $descendant->id, $right );
1078
+
1079
+ // We've got the left value, and now that we've processed the children
1080
+ // of this node we also know the right value
1081
+ if ( 1 == $left )
1082
+ $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE id = %d", $left, $right, $parent_id ) );
1083
+ else
1084
+ $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE type = 'activity_comment' AND id = %d", $left, $right, $parent_id ) );
1085
+
1086
+ // Return the right value of this node + 1
1087
+ return $right + 1;
1088
+ }
1089
+
1090
+ /**
1091
+ * Get child comments of an activity or activity comment.
1092
+ *
1093
+ * @since BuddyPress (1.2)
1094
+ *
1095
+ * @global BuddyPress $bp The one true BuddyPress instance.
1096
+ * @global wpdb $wpdb WordPress database object.
1097
+ *
1098
+ * @param int $parent_id ID of an activty or activity comment.
1099
+ * @return object Numerically indexed array of child comments.
1100
+ */
1101
+ public static function get_child_comments( $parent_id ) {
1102
+ global $bp, $wpdb;
1103
+
1104
+ return $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND secondary_item_id = %d", $parent_id ) );
1105
+ }
1106
+
1107
+ /**
1108
+ * Get a list of components that have recorded activity associated with them.
1109
+ *
1110
+ * @param bool $skip_last_activity If true, components will not be
1111
+ * included if the only activity type associated with them is
1112
+ * 'last_activity'. (Since 2.0.0, 'last_activity' is stored in
1113
+ * the activity table, but these items are not full-fledged
1114
+ * activity items.) Default: true.
1115
+ * @return array List of component names.
1116
+ */
1117
+ public static function get_recorded_components( $skip_last_activity = true ) {
1118
+ global $wpdb, $bp;
1119
+
1120
+ if ( $skip_last_activity ) {
1121
+ $components = $wpdb->get_col( "SELECT DISTINCT component FROM {$bp->activity->table_name} WHERE action != '' AND action != 'last_activity' ORDER BY component ASC" );
1122
+ } else {
1123
+ $components = $wpdb->get_col( "SELECT DISTINCT component FROM {$bp->activity->table_name} ORDER BY component ASC" );
1124
+ }
1125
+
1126
+ return $components;
1127
+ }
1128
+
1129
+ /**
1130
+ * Get sitewide activity items for use in an RSS feed.
1131
+ *
1132
+ * @param int $limit Optional. Number of items to fetch. Default: 35.
1133
+ * @return array $activity_feed List of activity items, with RSS data added.
1134
+ */
1135
+ public static function get_sitewide_items_for_feed( $limit = 35 ) {
1136
+ $activities = bp_activity_get_sitewide( array( 'max' => $limit ) );
1137
+ $activity_feed = array();
1138
+
1139
+ for ( $i = 0, $count = count( $activities ); $i < $count; ++$i ) {
1140
+ $title = explode( '<span', $activities[$i]['content'] );
1141
+ $activity_feed[$i]['title'] = trim( strip_tags( $title[0] ) );
1142
+ $activity_feed[$i]['link'] = $activities[$i]['primary_link'];
1143
+ $activity_feed[$i]['description'] = @sprintf( $activities[$i]['content'], '' );
1144
+ $activity_feed[$i]['pubdate'] = $activities[$i]['date_recorded'];
1145
+ }
1146
+
1147
+ return $activity_feed;
1148
+ }
1149
+
1150
+ /**
1151
+ * Create SQL IN clause for filter queries.
1152
+ *
1153
+ * @since BuddyPress (1.5)
1154
+ *
1155
+ * @see BP_Activity_Activity::get_filter_sql()
1156
+ *
1157
+ * @param string $field The database field.
1158
+ * @param array|bool $items The values for the IN clause, or false when none are found.
1159
+ */
1160
+ public static function get_in_operator_sql( $field, $items ) {
1161
+ global $wpdb;
1162
+
1163
+ // split items at the comma
1164
+ if ( ! is_array( $items ) ) {
1165
+ $items = explode( ',', $items );
1166
+ }
1167
+
1168
+ // array of prepared integers or quoted strings
1169
+ $items_prepared = array();
1170
+
1171
+ // clean up and format each item
1172
+ foreach ( $items as $item ) {
1173
+ // clean up the string
1174
+ $item = trim( $item );
1175
+ // pass everything through prepare for security and to safely quote strings
1176
+ $items_prepared[] = ( is_numeric( $item ) ) ? $wpdb->prepare( '%d', $item ) : $wpdb->prepare( '%s', $item );
1177
+ }
1178
+
1179
+ // build IN operator sql syntax
1180
+ if ( count( $items_prepared ) )
1181
+ return sprintf( '%s IN ( %s )', trim( $field ), implode( ',', $items_prepared ) );
1182
+ else
1183
+ return false;
1184
+ }
1185
+
1186
+ /**
1187
+ * Create filter SQL clauses.
1188
+ *
1189
+ * @since BuddyPress (1.5.0)
1190
+ *
1191
+ * @param array $filter_array {
1192
+ * Fields and values to filter by.
1193
+ * @type array|string|id $user_id User ID(s).
1194
+ * @type array|string $object Corresponds to the 'component'
1195
+ * column in the database.
1196
+ * @type array|string $action Corresponds to the 'type' column
1197
+ * in the database.
1198
+ * @type array|string|int $primary_id Corresponds to the 'item_id'
1199
+ * column in the database.
1200
+ * @type array|string|int $secondary_id Corresponds to the
1201
+ * 'secondary_item_id' column in the database.
1202
+ * @type int $offset Return only those items with an ID greater
1203
+ * than the offset value.
1204
+ * @type string $since Return only those items that have a
1205
+ * date_recorded value greater than a given MySQL-formatted
1206
+ * date.
1207
+ * }
1208
+ * @return string The filter clause, for use in a SQL query.
1209
+ */
1210
+ public static function get_filter_sql( $filter_array ) {
1211
+
1212
+ $filter_sql = array();
1213
+
1214
+ if ( !empty( $filter_array['user_id'] ) ) {
1215
+ $user_sql = BP_Activity_Activity::get_in_operator_sql( 'a.user_id', $filter_array['user_id'] );
1216
+ if ( !empty( $user_sql ) )
1217
+ $filter_sql[] = $user_sql;
1218
+ }
1219
+
1220
+ if ( !empty( $filter_array['object'] ) ) {
1221
+ $object_sql = BP_Activity_Activity::get_in_operator_sql( 'a.component', $filter_array['object'] );
1222
+ if ( !empty( $object_sql ) )
1223
+ $filter_sql[] = $object_sql;
1224
+ }
1225
+
1226
+ if ( !empty( $filter_array['action'] ) ) {
1227
+ $action_sql = BP_Activity_Activity::get_in_operator_sql( 'a.type', $filter_array['action'] );
1228
+ if ( ! empty( $action_sql ) )
1229
+ $filter_sql[] = $action_sql;
1230
+ }
1231
+
1232
+ if ( !empty( $filter_array['primary_id'] ) ) {
1233
+ $pid_sql = BP_Activity_Activity::get_in_operator_sql( 'a.item_id', $filter_array['primary_id'] );
1234
+ if ( !empty( $pid_sql ) )
1235
+ $filter_sql[] = $pid_sql;
1236
+ }
1237
+
1238
+ if ( !empty( $filter_array['secondary_id'] ) ) {
1239
+ $sid_sql = BP_Activity_Activity::get_in_operator_sql( 'a.secondary_item_id', $filter_array['secondary_id'] );
1240
+ if ( !empty( $sid_sql ) )
1241
+ $filter_sql[] = $sid_sql;
1242
+ }
1243
+
1244
+ if ( ! empty( $filter_array['offset'] ) ) {
1245
+ $sid_sql = absint( $filter_array['offset'] );
1246
+ $filter_sql[] = "a.id >= {$sid_sql}";
1247
+ }
1248
+
1249
+ if ( ! empty( $filter_array['since'] ) ) {
1250
+ // Validate that this is a proper Y-m-d H:i:s date
1251
+ // Trick: parse to UNIX date then translate back
1252
+ $translated_date = date( 'Y-m-d H:i:s', strtotime( $filter_array['since'] ) );
1253
+ if ( $translated_date === $filter_array['since'] ) {
1254
+ $filter_sql[] = "a.date_recorded > '{$translated_date}'";
1255
+ }
1256
+ }
1257
+
1258
+ if ( empty( $filter_sql ) )
1259
+ return false;
1260
+
1261
+ return join( ' AND ', $filter_sql );
1262
+ }
1263
+
1264
+ /**
1265
+ * Get the date/time of last recorded activity.
1266
+ *
1267
+ * @since BuddyPress (1.2)
1268
+ *
1269
+ * @return string ISO timestamp.
1270
+ */
1271
+ public static function get_last_updated() {
1272
+ global $bp, $wpdb;
1273
+
1274
+ return $wpdb->get_var( "SELECT date_recorded FROM {$bp->activity->table_name} ORDER BY date_recorded DESC LIMIT 1" );
1275
+ }
1276
+
1277
+ /**
1278
+ * Get favorite count for a given user.
1279
+ *
1280
+ * @since BuddyPress (1.2)
1281
+ *
1282
+ * @param int The ID of the user whose favorites you're counting.
1283
+ * @return int A count of the user's favorites.
1284
+ */
1285
+ public static function total_favorite_count( $user_id ) {
1286
+ if ( !$favorite_activity_entries = bp_get_user_meta( $user_id, 'bp_favorite_activities', true ) )
1287
+ return 0;
1288
+
1289
+ return count( maybe_unserialize( $favorite_activity_entries ) );
1290
+ }
1291
+
1292
+ /**
1293
+ * Check whether an activity item exists with a given string content.
1294
+ *
1295
+ * @param string $content The content to filter by.
1296
+ * @return int|bool The ID of the first matching item if found, otherwise false.
1297
+ */
1298
+ public static function check_exists_by_content( $content ) {
1299
+ global $wpdb, $bp;
1300
+
1301
+ return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE content = %s", $content ) );
1302
+ }
1303
+
1304
+ /**
1305
+ * Hide all activity for a given user.
1306
+ *
1307
+ * @param int $user_id The ID of the user whose activity you want to mark hidden.
1308
+ * @param int
1309
+ */
1310
+ public static function hide_all_for_user( $user_id ) {
1311
+ global $wpdb, $bp;
1312
+
1313
+ return $wpdb->get_var( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET hide_sitewide = 1 WHERE user_id = %d", $user_id ) );
1314
+ }
1315
+ }
1316
+
1317
+ /**
1318
+ * Create a RSS feed using the activity component.
1319
+ *
1320
+ * You should only construct a new feed when you've validated that you're on
1321
+ * the appropriate screen.
1322
+ *
1323
+ * See {@link bp_activity_action_sitewide_feed()} as an example.
1324
+ *
1325
+ * Accepted parameters:
1326
+ * id - internal id for the feed; should be alphanumeric only
1327
+ * (required)
1328
+ * title - RSS feed title
1329
+ * link - Relevant link for the RSS feed
1330
+ * description - RSS feed description
1331
+ * ttl - Time-to-live (see inline doc in constructor)
1332
+ * update_period - Part of the syndication module (see inline doc in
1333
+ * constructor for more info)
1334
+ * update_frequency - Part of the syndication module (see inline doc in
1335
+ * constructor for more info)
1336
+ * max - Number of feed items to display
1337
+ * activity_args - Arguments passed to {@link bp_has_activities()}
1338
+ *
1339
+ * @since BuddyPress (1.8)
1340
+ */
1341
+ class BP_Activity_Feed {
1342
+ /**
1343
+ * Holds our custom class properties.
1344
+ *
1345
+ * These variables are stored in a protected array that is magically
1346
+ * updated using PHP 5.2+ methods.
1347
+ *
1348
+ * @see BP_Feed::__construct() This is where $data is added
1349
+ * @var array
1350
+ */
1351
+ protected $data;
1352
+
1353
+ /**
1354
+ * Magic method for checking the existence of a certain data variable.
1355
+ *
1356
+ * @param string $key
1357
+ */
1358
+ public function __isset( $key ) { return isset( $this->data[$key] ); }
1359
+
1360
+ /**
1361
+ * Magic method for getting a certain data variable.
1362
+ *
1363
+ * @param string $key
1364
+ */
1365
+ public function __get( $key ) { return isset( $this->data[$key] ) ? $this->data[$key] : null; }
1366
+
1367
+ /**
1368
+ * Constructor.
1369
+ *
1370
+ * @param array $args Optional
1371
+ */
1372
+ public function __construct( $args = array() ) {
1373
+ // If feeds are disabled, stop now!
1374
+ if ( false === (bool) apply_filters( 'bp_activity_enable_feeds', true ) ) {
1375
+ global $wp_query;
1376
+
1377
+ // set feed flag to false
1378
+ $wp_query->is_feed = false;
1379
+
1380
+ return false;
1381
+ }
1382
+
1383
+ // Setup data
1384
+ $this->data = wp_parse_args( $args, array(
1385
+ // Internal identifier for the RSS feed - should be alphanumeric only
1386
+ 'id' => '',
1387
+
1388
+ // RSS title - should be plain-text
1389
+ 'title' => '',
1390
+
1391
+ // relevant link for the RSS feed
1392
+ 'link' => '',
1393
+
1394
+ // RSS description - should be plain-text
1395
+ 'description' => '',
1396
+
1397
+ // Time-to-live - number of minutes to cache the data before an aggregator
1398
+ // requests it again. This is only acknowledged if the RSS client supports it
1399
+ //
1400
+ // See: http://www.rssboard.org/rss-profile#element-channel-ttl
1401
+ // http://www.kbcafe.com/rss/rssfeedstate.html#ttl
1402
+ 'ttl' => '30',
1403
+
1404
+ // Syndication module - similar to ttl, but not really supported by RSS
1405
+ // clients
1406
+ //
1407
+ // See: http://web.resource.org/rss/1.0/modules/syndication/#description
1408
+ // http://www.kbcafe.com/rss/rssfeedstate.html#syndicationmodule
1409
+ 'update_period' => 'hourly',
1410
+ 'update_frequency' => 2,
1411
+
1412
+ // Number of items to display
1413
+ 'max' => 50,
1414
+
1415
+ // Activity arguments passed to bp_has_activities()
1416
+ 'activity_args' => array()
1417
+ ) );
1418
+
1419
+ // Plugins can use this filter to modify the feed before it is setup
1420
+ do_action_ref_array( 'bp_activity_feed_prefetch', array( &$this ) );
1421
+
1422
+ // Setup class properties
1423
+ $this->setup_properties();
1424
+
1425
+ // Check if id is valid
1426
+ if ( empty( $this->id ) ) {
1427
+ _doing_it_wrong( 'BP_Activity_Feed', __( "RSS feed 'id' must be defined", 'buddypress' ), 'BP 1.8' );
1428
+ return false;
1429
+ }
1430
+
1431
+ // Plugins can use this filter to modify the feed after it's setup
1432
+ do_action_ref_array( 'bp_activity_feed_postfetch', array( &$this ) );
1433
+
1434
+ // Setup feed hooks
1435
+ $this->setup_hooks();
1436
+
1437
+ // Output the feed
1438
+ $this->output();
1439
+
1440
+ // Kill the rest of the output
1441
+ die();
1442
+ }
1443
+
1444
+ /** SETUP ****************************************************************/
1445
+
1446
+ /**
1447
+ * Setup and validate the class properties.
1448
+ *
1449
+ * @access protected
1450
+ */
1451
+ protected function setup_properties() {
1452
+ $this->id = sanitize_title( $this->id );
1453
+ $this->title = strip_tags( $this->title );
1454
+ $this->link = esc_url_raw( $this->link );
1455
+ $this->description = strip_tags( $this->description );
1456
+ $this->ttl = (int) $this->ttl;
1457
+ $this->update_period = strip_tags( $this->update_period );
1458
+ $this->update_frequency = (int) $this->update_frequency;
1459
+
1460
+ $this->activity_args = wp_parse_args( $this->activity_args, array(
1461
+ 'max' => $this->max,
1462
+ 'per_page' => $this->max,
1463
+ 'display_comments' => 'stream'
1464
+ ) );
1465
+
1466
+ }
1467
+
1468
+ /**
1469
+ * Setup some hooks that are used in the feed.
1470
+ *
1471
+ * Currently, these hooks are used to maintain backwards compatibility with
1472
+ * the RSS feeds previous to BP 1.8.
1473
+ *
1474
+ * @access protected
1475
+ */
1476
+ protected function setup_hooks() {
1477
+ add_action( 'bp_activity_feed_rss_attributes', array( $this, 'backpat_rss_attributes' ) );
1478
+ add_action( 'bp_activity_feed_channel_elements', array( $this, 'backpat_channel_elements' ) );
1479
+ add_action( 'bp_activity_feed_item_elements', array( $this, 'backpat_item_elements' ) );
1480
+ }
1481
+
1482
+ /** BACKPAT HOOKS ********************************************************/
1483
+
1484
+ /**
1485
+ * Fire a hook to ensure backward compatibility for RSS attributes.
1486
+ */
1487
+ public function backpat_rss_attributes() {
1488
+ do_action( 'bp_activity_' . $this->id . '_feed' );
1489
+ }
1490
+
1491
+ /**
1492
+ * Fire a hook to ensure backward compatibility for channel elements.
1493
+ */
1494
+ public function backpat_channel_elements() {
1495
+ do_action( 'bp_activity_' . $this->id . '_feed_head' );
1496
+ }
1497
+
1498
+ /**
1499
+ * Fire a hook to ensure backward compatibility for item elements.
1500
+ */
1501
+ public function backpat_item_elements() {
1502
+ switch ( $this->id ) {
1503
+
1504
+ // sitewide and friends feeds use the 'personal' hook
1505
+ case 'sitewide' :
1506
+ case 'friends' :
1507
+ $id = 'personal';
1508
+
1509
+ break;
1510
+
1511
+ default :
1512
+ $id = $this->id;
1513
+
1514
+ break;
1515
+ }
1516
+
1517
+ do_action( 'bp_activity_' . $id . '_feed_item' );
1518
+ }
1519
+
1520
+ /** HELPERS **************************************************************/
1521
+
1522
+ /**
1523
+ * Output the feed's item content.
1524
+ *
1525
+ * @access protected
1526
+ */
1527
+ protected function feed_content() {
1528
+ bp_activity_content_body();
1529
+
1530
+ switch ( $this->id ) {
1531
+
1532
+ // also output parent activity item if we're on a specific feed
1533
+ case 'favorites' :
1534
+ case 'friends' :
1535
+ case 'mentions' :
1536
+ case 'personal' :
1537
+
1538
+ if ( 'activity_comment' == bp_get_activity_action_name() ) :
1539
+ ?>
1540
+ <strong><?php _e( 'In reply to', 'buddypress' ) ?></strong> -
1541
+ <?php bp_activity_parent_content() ?>
1542
+ <?php
1543
+ endif;
1544
+
1545
+ break;
1546
+ }
1547
+ }
1548
+
1549
+ /**
1550
+ * Sets various HTTP headers related to Content-Type and browser caching.
1551
+ *
1552
+ * Most of this class method is derived from {@link WP::send_headers()}.
1553
+ *
1554
+ * @since BuddyPress (1.9.0)
1555
+ *
1556
+ * @access protected
1557
+ */
1558
+ protected function http_headers() {
1559
+ // set up some additional headers if not on a directory page
1560
+ // this is done b/c BP uses pseudo-pages
1561
+ if ( ! bp_is_directory() ) {
1562
+ global $wp_query;
1563
+
1564
+ $wp_query->is_404 = false;
1565
+ status_header( 200 );
1566
+ }
1567
+
1568
+ // Set content-type
1569
+ @header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
1570
+
1571
+ // Cache-related variables
1572
+ $last_modified = mysql2date( 'D, d M Y H:i:s O', bp_activity_get_last_updated(), false );
1573
+ $modified_timestamp = strtotime( $last_modified );
1574
+ $etag = md5( $last_modified );
1575
+
1576
+ // Set cache-related headers
1577
+ @header( 'Last-Modified: ' . $last_modified );
1578
+ @header( 'Pragma: no-cache' );
1579
+ @header( 'ETag: ' . '"' . $etag . '"' );
1580
+
1581
+ // First commit of BuddyPress! (Easter egg)
1582
+ @header( 'Expires: Tue, 25 Mar 2008 17:13:55 GMT');
1583
+
1584
+ // Get ETag from supported user agents
1585
+ if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ) {
1586
+ $client_etag = wp_unslash( $_SERVER['HTTP_IF_NONE_MATCH'] );
1587
+
1588
+ // Remove quotes from ETag
1589
+ $client_etag = trim( $client_etag, '"' );
1590
+
1591
+ // Strip suffixes from ETag if they exist (eg. "-gzip")
1592
+ if ( $etag_suffix_pos = strpos( $client_etag, '-' ) ) {
1593
+ $client_etag = substr( $client_etag, 0, $etag_suffix_pos );
1594
+ }
1595
+
1596
+ // No ETag found
1597
+ } else {
1598
+ $client_etag = false;
1599
+ }
1600
+
1601
+ // Get client last modified timestamp from supported user agents
1602
+ $client_last_modified = empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ? '' : trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
1603
+ $client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0;
1604
+
1605
+ // Set 304 status if feed hasn't been updated since last fetch
1606
+ if ( ( $client_last_modified && $client_etag ) ?
1607
+ ( ( $client_modified_timestamp >= $modified_timestamp ) && ( $client_etag == $etag ) ) :
1608
+ ( ( $client_modified_timestamp >= $modified_timestamp ) || ( $client_etag == $etag ) ) ) {
1609
+ $status = 304;
1610
+ } else {
1611
+ $status = false;
1612
+ }
1613
+
1614
+ // If feed hasn't changed as reported by the user agent, set 304 status header
1615
+ if ( ! empty( $status ) ) {
1616
+ status_header( $status );
1617
+
1618
+ // cached response, so stop now!
1619
+ if ( $status == 304 ) {
1620
+ exit();
1621
+ }
1622
+ }
1623
+ }
1624
+
1625
+ /** OUTPUT ***************************************************************/
1626
+
1627
+ /**
1628
+ * Output the RSS feed.
1629
+ *
1630
+ * @access protected
1631
+ */
1632
+ protected function output() {
1633
+ $this->http_headers();
1634
+ echo '<?xml version="1.0" encoding="' . get_option( 'blog_charset' ) . '"?'.'>';
1635
+ ?>
1636
+
1637
+ <rss version="2.0"
1638
+ xmlns:content="http://purl.org/rss/1.0/modules/content/"
1639
+ xmlns:atom="http://www.w3.org/2005/Atom"
1640
+ xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
1641
+ xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
1642
+ <?php do_action( 'bp_activity_feed_rss_attributes' ); ?>
1643
+ >
1644
+
1645
+ <channel>
1646
+ <title><?php echo $this->title; ?></title>
1647
+ <link><?php echo $this->link; ?></link>
1648
+ <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
1649
+ <description><?php echo $this->description ?></description>
1650
+ <lastBuildDate><?php echo mysql2date( 'D, d M Y H:i:s O', bp_activity_get_last_updated(), false ); ?></lastBuildDate>
1651
+ <generator>http://buddypress.org/?v=<?php bp_version(); ?></generator>
1652
+ <language><?php bloginfo_rss( 'language' ); ?></language>
1653
+ <ttl><?php echo $this->ttl; ?></ttl>
1654
+ <sy:updatePeriod><?php echo $this->update_period; ?></sy:updatePeriod>
1655
+ <sy:updateFrequency><?php echo $this->update_frequency; ?></sy:updateFrequency>
1656
+ <?php do_action( 'bp_activity_feed_channel_elements' ); ?>
1657
+
1658
+ <?php if ( bp_has_activities( $this->activity_args ) ) : ?>
1659
+ <?php while ( bp_activities() ) : bp_the_activity(); ?>
1660
+ <item>
1661
+ <guid isPermaLink="false"><?php bp_activity_feed_item_guid(); ?></guid>
1662
+ <title><?php echo stripslashes( bp_get_activity_feed_item_title() ); ?></title>
1663
+ <link><?php bp_activity_thread_permalink() ?></link>
1664
+ <pubDate><?php echo mysql2date( 'D, d M Y H:i:s O', bp_get_activity_feed_item_date(), false ); ?></pubDate>
1665
+
1666
+ <?php if ( bp_get_activity_feed_item_description() ) : ?>
1667
+ <content:encoded><![CDATA[<?php $this->feed_content(); ?>]]></content:encoded>
1668
+ <?php endif; ?>
1669
+
1670
+ <?php if ( bp_activity_can_comment() ) : ?>
1671
+ <slash:comments><?php bp_activity_comment_count(); ?></slash:comments>
1672
+ <?php endif; ?>
1673
+
1674
+ <?php do_action( 'bp_activity_feed_item_elements' ); ?>
1675
+ </item>
1676
+ <?php endwhile; ?>
1677
+
1678
+ <?php endif; ?>
1679
+ </channel>
1680
+ </rss><?php
1681
+ }
1682
+ }
bp-activity/bp-activity-cssjs.php DELETED
@@ -1,75 +0,0 @@
1
- <?php
2
- /**
3
- * Activity component CSS/JS
4
- *
5
- * @package BuddyPress
6
- * @subpackage ActivityScripts
7
- */
8
-
9
- // Exit if accessed directly.
10
- defined( 'ABSPATH' ) || exit;
11
-
12
- /**
13
- * Enqueue @mentions JS.
14
- *
15
- * @since 2.1.0
16
- */
17
- function bp_activity_mentions_script() {
18
- if ( ! bp_activity_maybe_load_mentions_scripts() ) {
19
- return;
20
- }
21
-
22
- // Special handling for New/Edit screens in wp-admin.
23
- if ( is_admin() ) {
24
- if (
25
- ! get_current_screen() ||
26
- ! in_array( get_current_screen()->base, array( 'page', 'post' ) ) ||
27
- ! post_type_supports( get_current_screen()->post_type, 'editor' ) ) {
28
- return;
29
- }
30
- }
31
-
32
-
33
- $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
34
-
35
- wp_enqueue_script( 'bp-mentions', buddypress()->plugin_url . "bp-activity/js/mentions{$min}.js", array( 'jquery', 'jquery-atwho' ), bp_get_version(), true );
36
- wp_enqueue_style( 'bp-mentions-css', buddypress()->plugin_url . "bp-activity/css/mentions{$min}.css", array(), bp_get_version() );
37
-
38
- wp_style_add_data( 'bp-mentions-css', 'rtl', true );
39
- if ( $min ) {
40
- wp_style_add_data( 'bp-mentions-css', 'suffix', $min );
41
- }
42
-
43
- // If the script has been enqueued, let's attach our mentions TinyMCE init callback.
44
- add_filter( 'tiny_mce_before_init', 'bp_add_mentions_on_tinymce_init', 10, 2 );
45
-
46
- /**
47
- * Fires at the end of the Activity Mentions script.
48
- *
49
- * This is the hook where BP components can add their own prefetched results
50
- * friends to the page for quicker @mentions lookups.
51
- *
52
- * @since 2.1.0
53
- */
54
- do_action( 'bp_activity_mentions_prime_results' );
55
- }
56
- add_action( 'bp_enqueue_scripts', 'bp_activity_mentions_script' );
57
- add_action( 'bp_admin_enqueue_scripts', 'bp_activity_mentions_script' );
58
-
59
- /**
60
- * Bind the mentions listener to a wp_editor instance when TinyMCE initializes.
61
- *
62
- * @since 2.3.3
63
- *
64
- * @param array $settings An array with TinyMCE config.
65
- * @param string $editor_id Unique editor identifier, e.g. 'content'.
66
- * @return array $mceInit An array with TinyMCE config.
67
- */
68
- function bp_add_mentions_on_tinymce_init( $settings, $editor_id ) {
69
- // We only apply the mentions init to the visual post editor in the WP dashboard.
70
- if ( 'content' === $editor_id ) {
71
- $settings['init_instance_callback'] = 'window.bp.mentions.tinyMCEinit';
72
- }
73
-
74
- return $settings;
75
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-activity/bp-activity-filters.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  /**
3
  * Filters related to the Activity component.
4
  *
@@ -6,12 +7,12 @@
6
  * @subpackage ActivityFilters
7
  */
8
 
9
- // Exit if accessed directly.
10
- defined( 'ABSPATH' ) || exit;
11
 
12
  /** Filters *******************************************************************/
13
 
14
- // Apply WordPress defined filters.
15
  add_filter( 'bp_get_activity_action', 'bp_activity_filter_kses', 1 );
16
  add_filter( 'bp_get_activity_content_body', 'bp_activity_filter_kses', 1 );
17
  add_filter( 'bp_get_activity_content', 'bp_activity_filter_kses', 1 );
@@ -21,7 +22,7 @@ add_filter( 'bp_get_activity_latest_update_excerpt', 'bp_activity_filter_kses',
21
  add_filter( 'bp_get_activity_feed_item_description', 'bp_activity_filter_kses', 1 );
22
  add_filter( 'bp_activity_content_before_save', 'bp_activity_filter_kses', 1 );
23
  add_filter( 'bp_activity_action_before_save', 'bp_activity_filter_kses', 1 );
24
- add_filter( 'bp_activity_latest_update_content', 'bp_activity_filter_kses', 1 );
25
 
26
  add_filter( 'bp_get_activity_action', 'force_balance_tags' );
27
  add_filter( 'bp_get_activity_content_body', 'force_balance_tags' );
@@ -77,7 +78,7 @@ add_filter( 'bp_get_activity_feed_item_description', 'stripslashes_deep', 5 );
77
 
78
  add_filter( 'bp_activity_primary_link_before_save', 'esc_url_raw' );
79
 
80
- // Apply BuddyPress-defined filters.
81
  add_filter( 'bp_get_activity_content', 'bp_activity_make_nofollow_filter' );
82
  add_filter( 'bp_get_activity_content_body', 'bp_activity_make_nofollow_filter' );
83
  add_filter( 'bp_get_activity_parent_content', 'bp_activity_make_nofollow_filter' );
@@ -95,15 +96,12 @@ add_filter( 'bp_get_activity_parent_content', 'bp_create_excerpt' );
95
  add_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
96
  add_filter( 'bp_get_activity_content', 'bp_activity_truncate_entry', 5 );
97
 
98
- add_filter( 'bp_get_total_favorite_count_for_user', 'bp_core_number_format' );
99
- add_filter( 'bp_get_total_mention_count_for_user', 'bp_core_number_format' );
100
-
101
  /** Actions *******************************************************************/
102
 
103
- // At-name filter.
104
  add_action( 'bp_activity_before_save', 'bp_activity_at_name_filter_updates' );
105
 
106
- // Activity stream moderation.
107
  add_action( 'bp_activity_before_save', 'bp_activity_check_moderation_keys', 2, 1 );
108
  add_action( 'bp_activity_before_save', 'bp_activity_check_blacklist_keys', 2, 1 );
109
 
@@ -112,7 +110,7 @@ add_action( 'bp_activity_before_save', 'bp_activity_check_blacklist_keys', 2, 1
112
  /**
113
  * Types of activity stream items to moderate.
114
  *
115
- * @since 1.6.0
116
  *
117
  * @return array $types List of the activity types to moderate.
118
  */
@@ -121,32 +119,24 @@ function bp_activity_get_moderated_activity_types() {
121
  'activity_comment',
122
  'activity_update'
123
  );
124
-
125
- /**
126
- * Filters the default activity types that BuddyPress should moderate.
127
- *
128
- * @since 1.6.0
129
- *
130
- * @param array $types Default activity types to moderate.
131
- */
132
  return apply_filters( 'bp_activity_check_activity_types', $types );
133
  }
134
 
135
  /**
136
  * Moderate the posted activity item, if it contains moderate keywords.
137
  *
138
- * @since 1.6.0
139
  *
140
  * @param BP_Activity_Activity $activity The activity object to check.
141
  */
142
  function bp_activity_check_moderation_keys( $activity ) {
143
 
144
- // Only check specific types of activity updates.
145
  if ( !in_array( $activity->type, bp_activity_get_moderated_activity_types() ) )
146
  return;
147
 
148
  // Unset the activity component so activity stream update fails
149
- // @todo This is temporary until some kind of moderation is built.
150
  if ( !bp_core_check_for_moderation( $activity->user_id, '', $activity->content ) )
151
  $activity->component = false;
152
  }
@@ -154,17 +144,17 @@ function bp_activity_check_moderation_keys( $activity ) {
154
  /**
155
  * Mark the posted activity as spam, if it contains blacklist keywords.
156
  *
157
- * @since 1.6.0
158
  *
159
  * @param BP_Activity_Activity $activity The activity object to check.
160
  */
161
  function bp_activity_check_blacklist_keys( $activity ) {
162
 
163
- // Only check specific types of activity updates.
164
  if ( ! in_array( $activity->type, bp_activity_get_moderated_activity_types() ) )
165
  return;
166
 
167
- // Mark as spam.
168
  if ( ! bp_core_check_for_blacklist( $activity->user_id, '', $activity->content ) )
169
  bp_activity_mark_as_spam( $activity, 'by_blacklist' );
170
  }
@@ -172,7 +162,7 @@ function bp_activity_check_blacklist_keys( $activity ) {
172
  /**
173
  * Custom kses filtering for activity content.
174
  *
175
- * @since 1.1.0
176
  *
177
  * @uses apply_filters() To call the 'bp_activity_allowed_tags' hook.
178
  * @uses wp_kses()
@@ -184,13 +174,11 @@ function bp_activity_filter_kses( $content ) {
184
  global $allowedtags;
185
 
186
  $activity_allowedtags = $allowedtags;
 
 
187
  $activity_allowedtags['a']['class'] = array();
188
  $activity_allowedtags['a']['id'] = array();
189
  $activity_allowedtags['a']['rel'] = array();
190
- $activity_allowedtags['a']['title'] = array();
191
- $activity_allowedtags['b'] = array();
192
- $activity_allowedtags['code'] = array();
193
- $activity_allowedtags['i'] = array();
194
  $activity_allowedtags['img'] = array();
195
  $activity_allowedtags['img']['src'] = array();
196
  $activity_allowedtags['img']['alt'] = array();
@@ -199,17 +187,8 @@ function bp_activity_filter_kses( $content ) {
199
  $activity_allowedtags['img']['class'] = array();
200
  $activity_allowedtags['img']['id'] = array();
201
  $activity_allowedtags['img']['title'] = array();
202
- $activity_allowedtags['span'] = array();
203
- $activity_allowedtags['span']['class'] = array();
204
-
205
 
206
- /**
207
- * Filters the allowed HTML tags for BuddyPress Activity content.
208
- *
209
- * @since 1.2.0
210
- *
211
- * @param array $value Array of allowed HTML tags and attributes.
212
- */
213
  $activity_allowedtags = apply_filters( 'bp_activity_allowed_tags', $activity_allowedtags );
214
  return wp_kses( $content, $activity_allowedtags );
215
  }
@@ -217,10 +196,10 @@ function bp_activity_filter_kses( $content ) {
217
  /**
218
  * Find and link @-mentioned users in the contents of a given item.
219
  *
220
- * @since 1.2.0
221
  *
222
- * @param string $content The contents of a given item.
223
- * @param int $activity_id The activity id. Deprecated.
224
  * @return string $content Content filtered for mentions.
225
  */
226
  function bp_activity_at_name_filter( $content, $activity_id = 0 ) {
@@ -230,7 +209,7 @@ function bp_activity_at_name_filter( $content, $activity_id = 0 ) {
230
  return $content;
231
  }
232
 
233
- // Try to find mentions.
234
  $usernames = bp_activity_find_mentions( $content );
235
 
236
  // No mentions? Stop now!
@@ -238,11 +217,11 @@ function bp_activity_at_name_filter( $content, $activity_id = 0 ) {
238
  return $content;
239
 
240
  // We don't want to link @mentions that are inside of links, so we
241
- // temporarily remove them.
242
  $replace_count = 0;
243
  $replacements = array();
244
  foreach ( $usernames as $username ) {
245
- // Prevent @ name linking inside <a> tags.
246
  preg_match_all( '/(<a.*?(?!<\/a>)@' . $username . '.*?<\/a>)/', $content, $content_matches );
247
  if ( ! empty( $content_matches[1] ) ) {
248
  foreach ( $content_matches[1] as $replacement ) {
@@ -253,19 +232,19 @@ function bp_activity_at_name_filter( $content, $activity_id = 0 ) {
253
  }
254
  }
255
 
256
- // Linkify the mentions with the username.
257
  foreach ( (array) $usernames as $user_id => $username ) {
258
  $content = preg_replace( '/(@' . $username . '\b)/', "<a href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $content );
259
  }
260
 
261
- // Put everything back.
262
  if ( ! empty( $replacements ) ) {
263
  foreach ( $replacements as $placeholder => $original ) {
264
  $content = str_replace( $placeholder, $original, $content );
265
  }
266
  }
267
 
268
- // Return the content.
269
  return $content;
270
  }
271
 
@@ -275,11 +254,11 @@ function bp_activity_at_name_filter( $content, $activity_id = 0 ) {
275
  * If mentions are found, replace @mention text with user links and add our
276
  * hook to send mention notifications after the activity item is saved.
277
  *
278
- * @since 1.5.0
279
  *
280
  * @uses bp_activity_find_mentions()
281
  *
282
- * @param BP_Activity_Activity $activity Activity Object.
283
  */
284
  function bp_activity_at_name_filter_updates( $activity ) {
285
  // Are mentions disabled?
@@ -291,20 +270,20 @@ function bp_activity_at_name_filter_updates( $activity ) {
291
  if ( ! empty( $activity->is_spam ) )
292
  return;
293
 
294
- // Try to find mentions.
295
  $usernames = bp_activity_find_mentions( $activity->content );
296
 
297
  // We have mentions!
298
  if ( ! empty( $usernames ) ) {
299
- // Replace @mention text with userlinks.
300
  foreach( (array) $usernames as $user_id => $username ) {
301
  $activity->content = preg_replace( '/(@' . $username . '\b)/', "<a href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $activity->content );
302
  }
303
 
304
- // Add our hook to send @mention emails after the activity item is saved.
305
  add_action( 'bp_activity_after_save', 'bp_activity_at_name_send_emails' );
306
 
307
- // Temporary variable to avoid having to run bp_activity_find_mentions() again.
308
  buddypress()->activity->mentioned_users = $usernames;
309
  }
310
  }
@@ -312,12 +291,12 @@ function bp_activity_at_name_filter_updates( $activity ) {
312
  /**
313
  * Sends emails and BP notifications for users @-mentioned in an activity item.
314
  *
315
- * @since 1.7.0
316
  *
317
  * @uses bp_activity_at_message_notification()
318
  * @uses bp_activity_update_mention_count_for_user()
319
  *
320
- * @param BP_Activity_Activity $activity The BP_Activity_Activity object.
321
  */
322
  function bp_activity_at_name_send_emails( $activity ) {
323
  // Are mentions disabled?
@@ -329,28 +308,20 @@ function bp_activity_at_name_send_emails( $activity ) {
329
  if ( empty( buddypress()->activity->mentioned_users ) )
330
  return;
331
 
332
- // Grab our temporary variable from bp_activity_at_name_filter_updates().
333
  $usernames = buddypress()->activity->mentioned_users;
334
 
335
- // Get rid of temporary variable.
336
  unset( buddypress()->activity->mentioned_users );
337
 
338
- // Send @mentions and setup BP notifications.
339
  foreach( (array) $usernames as $user_id => $username ) {
340
-
341
- /**
342
- * Filters BuddyPress' ability to send email notifications for @mentions.
343
- *
344
- * @since 1.6.0
345
- *
346
- * @param bool $value Whether or not BuddyPress should send a notification to the mentioned users.
347
- * @param array $usernames Array of users potentially notified.
348
- */
349
  if ( apply_filters( 'bp_activity_at_name_do_notifications', true, $usernames ) ) {
350
  bp_activity_at_message_notification( $activity->id, $user_id );
351
  }
352
 
353
- // Updates mention count for the user.
354
  bp_activity_update_mention_count_for_user( $user_id, $activity->id );
355
  }
356
  }
@@ -358,7 +329,7 @@ function bp_activity_at_name_send_emails( $activity ) {
358
  /**
359
  * Catch links in activity text so rel=nofollow can be added.
360
  *
361
- * @since 1.2.0
362
  *
363
  * @param string $text Activity text.
364
  * @return string $text Text with rel=nofollow added to any links.
@@ -370,10 +341,12 @@ function bp_activity_make_nofollow_filter( $text ) {
370
  /**
371
  * Add rel=nofollow to a link.
372
  *
373
- * @since 1.2.0
 
 
374
  *
375
  * @param array $matches Items matched by preg_replace_callback() in bp_activity_make_nofollow_filter().
376
- * @return string $text Link with rel=nofollow added.
377
  */
378
  function bp_activity_make_nofollow_filter_callback( $matches ) {
379
  $text = $matches[1];
@@ -384,9 +357,7 @@ function bp_activity_make_nofollow_filter( $text ) {
384
  /**
385
  * Truncate long activity entries when viewed in activity streams.
386
  *
387
- * This method can only be used inside the Activity loop.
388
- *
389
- * @since 1.5.0
390
  *
391
  * @uses bp_is_single_activity()
392
  * @uses apply_filters() To call the 'bp_activity_excerpt_append_text' hook.
@@ -402,71 +373,33 @@ function bp_activity_make_nofollow_filter( $text ) {
402
  function bp_activity_truncate_entry( $text ) {
403
  global $activities_template;
404
 
405
- /**
406
- * Provides a filter that lets you choose whether to skip this filter on a per-activity basis.
407
- *
408
- * @since 2.3.0
409
- *
410
- * @param bool $value If true, text should be checked to see if it needs truncating.
411
- */
412
- $maybe_truncate_text = apply_filters(
413
- 'bp_activity_maybe_truncate_entry',
414
- isset( $activities_template->activity->type ) && ! in_array( $activities_template->activity->type, array( 'new_blog_post', ), true )
415
- );
416
-
417
- // The full text of the activity update should always show on the single activity screen.
418
- if ( ! $maybe_truncate_text || bp_is_single_activity() ) {
419
  return $text;
420
- }
421
 
422
- /**
423
- * Filters the appended text for the activity excerpt.
424
- *
425
- * @since 1.5.0
426
- *
427
- * @param string $value Internationalized "Read more" text.
428
- */
429
  $append_text = apply_filters( 'bp_activity_excerpt_append_text', __( '[Read more]', 'buddypress' ) );
430
-
431
- /**
432
- * Filters the excerpt length for the activity excerpt.
433
- *
434
- * @since 1.5.0
435
- *
436
- * @param int $value Number indicating how many words to trim the excerpt down to.
437
- */
438
  $excerpt_length = apply_filters( 'bp_activity_excerpt_length', 358 );
439
 
440
- // Run the text through the excerpt function. If it's too short, the original text will be returned.
 
441
  $excerpt = bp_create_excerpt( $text, $excerpt_length, array( 'ending' => __( '&hellip;', 'buddypress' ) ) );
442
 
443
- /*
444
- * If the text returned by bp_create_excerpt() is different from the original text (ie it's
445
- * been truncated), add the "Read More" link. Note that bp_create_excerpt() is stripping
446
- * shortcodes, so we have strip them from the $text before the comparison.
447
- */
448
  if ( $excerpt != strip_shortcodes( $text ) ) {
449
  $id = !empty( $activities_template->activity->current_comment->id ) ? 'acomment-read-more-' . $activities_template->activity->current_comment->id : 'activity-read-more-' . bp_get_activity_id();
450
 
451
  $excerpt = sprintf( '%1$s<span class="activity-read-more" id="%2$s"><a href="%3$s" rel="nofollow">%4$s</a></span>', $excerpt, $id, bp_get_activity_thread_permalink(), $append_text );
452
  }
453
 
454
- /**
455
- * Filters the composite activity excerpt entry.
456
- *
457
- * @since 1.5.0
458
- *
459
- * @param string $excerpt Excerpt text and markup to be displayed.
460
- * @param string $text The original activity entry text.
461
- * @param string $append_text The final append text applied.
462
- */
463
  return apply_filters( 'bp_activity_truncate_entry', $excerpt, $text, $append_text );
464
  }
465
 
466
  /**
467
- * Include extra JavaScript dependencies for activity component.
468
  *
469
- * @since 2.0.0
470
  *
471
  * @uses bp_activity_do_heartbeat() to check if heartbeat is required.
472
  *
@@ -488,9 +421,9 @@ add_filter( 'bp_core_get_js_dependencies', 'bp_activity_get_js_dependencies', 10
488
  * We use these classes to avoid pagination issues when items are loaded
489
  * dynamically into the activity stream.
490
  *
491
- * @since 2.0.0
492
  *
493
- * @param string $classes Array of classes for most recent activity item.
494
  * @return string $classes
495
  */
496
  function bp_activity_newest_class( $classes = '' ) {
@@ -507,9 +440,9 @@ function bp_activity_newest_class( $classes = '' ) {
507
  /**
508
  * Check if Activity Heartbeat feature i on to add a timestamp class.
509
  *
510
- * @since 2.0.0
511
  *
512
- * @param string $classes Array of classes for timestamp.
513
  * @return string $classes
514
  */
515
  function bp_activity_timestamp_class( $classes = '' ) {
@@ -523,7 +456,7 @@ function bp_activity_timestamp_class( $classes = '' ) {
523
  if ( empty( $activity_date ) ) {
524
  return $classes;
525
  }
526
-
527
  $classes .= ' date-recorded-' . strtotime( $activity_date );
528
 
529
  return $classes;
@@ -533,35 +466,33 @@ add_filter( 'bp_get_activity_css_class', 'bp_activity_timestamp_class', 9, 1 );
533
  /**
534
  * Use WordPress Heartbeat API to check for latest activity update.
535
  *
536
- * @since 2.0.0
537
  *
538
- * @uses bp_activity_get_last_updated() to get the recorded date of the last activity.
539
  *
540
- * @param array $response Array containing Heartbeat API response.
541
- * @param array $data Array containing data for Heartbeat API response.
542
  * @return array $response
543
  */
544
  function bp_activity_heartbeat_last_recorded( $response = array(), $data = array() ) {
 
 
545
  if ( empty( $data['bp_activity_last_recorded'] ) ) {
546
  return $response;
547
  }
548
 
549
  // Use the querystring argument stored in the cookie (to preserve
550
- // filters), but force the offset to get only new items.
551
  $activity_latest_args = bp_parse_args(
552
  bp_ajax_querystring( 'activity' ),
553
  array( 'since' => date( 'Y-m-d H:i:s', $data['bp_activity_last_recorded'] ) ),
554
  'activity_latest_args'
555
  );
556
 
557
- if ( ! empty( $data['bp_activity_last_recorded_search_terms'] ) && empty( $activity_latest_args['search_terms'] ) ) {
558
- $activity_latest_args['search_terms'] = addslashes( $data['bp_activity_last_recorded_search_terms'] );
559
- }
560
-
561
  $newest_activities = array();
562
  $last_activity_recorded = 0;
563
 
564
- // Temporarily add a just-posted class for new activity items.
565
  add_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 );
566
 
567
  ob_start();
@@ -582,7 +513,7 @@ function bp_activity_heartbeat_last_recorded( $response = array(), $data = array
582
  $newest_activities['last_recorded'] = $last_activity_recorded;
583
  ob_end_clean();
584
 
585
- // Remove the temporary filter.
586
  remove_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 );
587
 
588
  if ( ! empty( $newest_activities['last_recorded'] ) ) {
@@ -597,7 +528,7 @@ add_filter( 'heartbeat_nopriv_received', 'bp_activity_heartbeat_last_recorded',
597
  /**
598
  * Set the strings for WP HeartBeat API where needed.
599
  *
600
- * @since 2.0.0
601
  *
602
  * @param array $strings Localized strings.
603
  * @return array $strings
@@ -610,26 +541,14 @@ function bp_activity_heartbeat_strings( $strings = array() ) {
610
 
611
  $global_pulse = 0;
612
 
613
- /**
614
- * Filter that checks whether the global heartbeat settings already exist.
615
- *
616
- * @since 2.0.0
617
- *
618
- * @param array $value Heartbeat settings array.
619
- */
620
  $heartbeat_settings = apply_filters( 'heartbeat_settings', array() );
621
  if ( ! empty( $heartbeat_settings['interval'] ) ) {
622
  // 'Fast' is 5
623
  $global_pulse = is_numeric( $heartbeat_settings['interval'] ) ? absint( $heartbeat_settings['interval'] ) : 5;
624
  }
625
 
626
- /**
627
- * Filters the pulse frequency to be used for the BuddyPress Activity heartbeat.
628
- *
629
- * @since 2.0.0
630
- *
631
- * @param int $value The frequency in seconds between pulses.
632
- */
633
  $bp_activity_pulse = apply_filters( 'bp_activity_heartbeat_pulse', 15 );
634
 
635
  /**
@@ -652,172 +571,3 @@ function bp_activity_heartbeat_strings( $strings = array() ) {
652
  return $strings;
653
  }
654
  add_filter( 'bp_core_get_js_strings', 'bp_activity_heartbeat_strings', 10, 1 );
655
-
656
- /** Scopes ********************************************************************/
657
-
658
- /**
659
- * Set up activity arguments for use with the 'just-me' scope.
660
- *
661
- * @since 2.2.0
662
- *
663
- * @param array $retval Empty array by default.
664
- * @param array $filter Current activity arguments.
665
- * @return array $retval
666
- */
667
- function bp_activity_filter_just_me_scope( $retval = array(), $filter = array() ) {
668
-
669
- // Determine the user_id.
670
- if ( ! empty( $filter['user_id'] ) ) {
671
- $user_id = $filter['user_id'];
672
- } else {
673
- $user_id = bp_displayed_user_id()
674
- ? bp_displayed_user_id()
675
- : bp_loggedin_user_id();
676
- }
677
-
678
- // Should we show all items regardless of sitewide visibility?
679
- $show_hidden = array();
680
- if ( ! empty( $user_id ) && $user_id !== bp_loggedin_user_id() ) {
681
- $show_hidden = array(
682
- 'column' => 'hide_sitewide',
683
- 'value' => 0
684
- );
685
- }
686
-
687
- $retval = array(
688
- 'relation' => 'AND',
689
- array(
690
- 'column' => 'user_id',
691
- 'value' => $user_id
692
- ),
693
- $show_hidden,
694
-
695
- // Overrides.
696
- 'override' => array(
697
- 'display_comments' => 'stream',
698
- 'filter' => array( 'user_id' => 0 ),
699
- 'show_hidden' => true
700
- ),
701
- );
702
-
703
- return $retval;
704
- }
705
- add_filter( 'bp_activity_set_just-me_scope_args', 'bp_activity_filter_just_me_scope', 10, 2 );
706
-
707
- /**
708
- * Set up activity arguments for use with the 'favorites' scope.
709
- *
710
- * @since 2.2.0
711
- *
712
- * @param array $retval Empty array by default.
713
- * @param array $filter Current activity arguments.
714
- * @return array $retval
715
- */
716
- function bp_activity_filter_favorites_scope( $retval = array(), $filter = array() ) {
717
-
718
- // Determine the user_id.
719
- if ( ! empty( $filter['user_id'] ) ) {
720
- $user_id = $filter['user_id'];
721
- } else {
722
- $user_id = bp_displayed_user_id()
723
- ? bp_displayed_user_id()
724
- : bp_loggedin_user_id();
725
- }
726
-
727
- // Determine the favorites.
728
- $favs = bp_activity_get_user_favorites( $user_id );
729
- if ( empty( $favs ) ) {
730
- $favs = array( 0 );
731
- }
732
-
733
- // Should we show all items regardless of sitewide visibility?
734
- $show_hidden = array();
735
- if ( ! empty( $user_id ) && ( $user_id !== bp_loggedin_user_id() ) ) {
736
- $show_hidden = array(
737
- 'column' => 'hide_sitewide',
738
- 'value' => 0
739
- );
740
- }
741
-
742
- $retval = array(
743
- 'relation' => 'AND',
744
- array(
745
- 'column' => 'id',
746
- 'compare' => 'IN',
747
- 'value' => (array) $favs
748
- ),
749
- $show_hidden,
750
-
751
- // Overrides.
752
- 'override' => array(
753
- 'display_comments' => true,
754
- 'filter' => array( 'user_id' => 0 ),
755
- 'show_hidden' => true
756
- ),
757
- );
758
-
759
- return $retval;
760
- }
761
- add_filter( 'bp_activity_set_favorites_scope_args', 'bp_activity_filter_favorites_scope', 10, 2 );
762
-
763
-
764
- /**
765
- * Set up activity arguments for use with the 'favorites' scope.
766
- *
767
- * @since 2.2.0
768
- *
769
- * @param array $retval Empty array by default.
770
- * @param array $filter Current activity arguments.
771
- * @return array $retval
772
- */
773
- function bp_activity_filter_mentions_scope( $retval = array(), $filter = array() ) {
774
-
775
- // Are mentions disabled?
776
- if ( ! bp_activity_do_mentions() ) {
777
- return $retval;
778
- }
779
-
780
- // Determine the user_id.
781
- if ( ! empty( $filter['user_id'] ) ) {
782
- $user_id = $filter['user_id'];
783
- } else {
784
- $user_id = bp_displayed_user_id()
785
- ? bp_displayed_user_id()
786
- : bp_loggedin_user_id();
787
- }
788
-
789
- // Should we show all items regardless of sitewide visibility?
790
- $show_hidden = array();
791
- if ( ! empty( $user_id ) && $user_id !== bp_loggedin_user_id() ) {
792
- $show_hidden = array(
793
- 'column' => 'hide_sitewide',
794
- 'value' => 0
795
- );
796
- }
797
-
798
- $retval = array(
799
- 'relation' => 'AND',
800
- array(
801
- 'column' => 'content',
802
- 'compare' => 'LIKE',
803
-
804
- // Start search at @ symbol and stop search at closing tag delimiter.
805
- 'value' => '@' . bp_activity_get_user_mentionname( $user_id ) . '<'
806
- ),
807
- $show_hidden,
808
-
809
- // Overrides.
810
- 'override' => array(
811
-
812
- // Clear search terms so 'mentions' scope works with other scopes.
813
- 'search_terms' => false,
814
-
815
- 'display_comments' => 'stream',
816
- 'filter' => array( 'user_id' => 0 ),
817
- 'show_hidden' => true
818
- ),
819
- );
820
-
821
- return $retval;
822
- }
823
- add_filter( 'bp_activity_set_mentions_scope_args', 'bp_activity_filter_mentions_scope', 10, 2 );
1
  <?php
2
+
3
  /**
4
  * Filters related to the Activity component.
5
  *
7
  * @subpackage ActivityFilters
8
  */
9
 
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
 
13
  /** Filters *******************************************************************/
14
 
15
+ // Apply WordPress defined filters
16
  add_filter( 'bp_get_activity_action', 'bp_activity_filter_kses', 1 );
17
  add_filter( 'bp_get_activity_content_body', 'bp_activity_filter_kses', 1 );
18
  add_filter( 'bp_get_activity_content', 'bp_activity_filter_kses', 1 );
22
  add_filter( 'bp_get_activity_feed_item_description', 'bp_activity_filter_kses', 1 );
23
  add_filter( 'bp_activity_content_before_save', 'bp_activity_filter_kses', 1 );
24
  add_filter( 'bp_activity_action_before_save', 'bp_activity_filter_kses', 1 );
25
+ add_filter( 'bp_activity_latest_update_content', 'wp_filter_kses', 1 );
26
 
27
  add_filter( 'bp_get_activity_action', 'force_balance_tags' );
28
  add_filter( 'bp_get_activity_content_body', 'force_balance_tags' );
78
 
79
  add_filter( 'bp_activity_primary_link_before_save', 'esc_url_raw' );
80
 
81
+ // Apply BuddyPress-defined filters
82
  add_filter( 'bp_get_activity_content', 'bp_activity_make_nofollow_filter' );
83
  add_filter( 'bp_get_activity_content_body', 'bp_activity_make_nofollow_filter' );
84
  add_filter( 'bp_get_activity_parent_content', 'bp_activity_make_nofollow_filter' );
96
  add_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
97
  add_filter( 'bp_get_activity_content', 'bp_activity_truncate_entry', 5 );
98
 
 
 
 
99
  /** Actions *******************************************************************/
100
 
101
+ // At-name filter
102
  add_action( 'bp_activity_before_save', 'bp_activity_at_name_filter_updates' );
103
 
104
+ // Activity stream moderation
105
  add_action( 'bp_activity_before_save', 'bp_activity_check_moderation_keys', 2, 1 );
106
  add_action( 'bp_activity_before_save', 'bp_activity_check_blacklist_keys', 2, 1 );
107
 
110
  /**
111
  * Types of activity stream items to moderate.
112
  *
113
+ * @since BuddyPress (1.6)
114
  *
115
  * @return array $types List of the activity types to moderate.
116
  */
119
  'activity_comment',
120
  'activity_update'
121
  );
 
 
 
 
 
 
 
 
122
  return apply_filters( 'bp_activity_check_activity_types', $types );
123
  }
124
 
125
  /**
126
  * Moderate the posted activity item, if it contains moderate keywords.
127
  *
128
+ * @since BuddyPress (1.6)
129
  *
130
  * @param BP_Activity_Activity $activity The activity object to check.
131
  */
132
  function bp_activity_check_moderation_keys( $activity ) {
133
 
134
+ // Only check specific types of activity updates
135
  if ( !in_array( $activity->type, bp_activity_get_moderated_activity_types() ) )
136
  return;
137
 
138
  // Unset the activity component so activity stream update fails
139
+ // @todo This is temporary until some kind of moderation is built
140
  if ( !bp_core_check_for_moderation( $activity->user_id, '', $activity->content ) )
141
  $activity->component = false;
142
  }
144
  /**
145
  * Mark the posted activity as spam, if it contains blacklist keywords.
146
  *
147
+ * @since BuddyPress (1.6)
148
  *
149
  * @param BP_Activity_Activity $activity The activity object to check.
150
  */
151
  function bp_activity_check_blacklist_keys( $activity ) {
152
 
153
+ // Only check specific types of activity updates
154
  if ( ! in_array( $activity->type, bp_activity_get_moderated_activity_types() ) )
155
  return;
156
 
157
+ // Mark as spam
158
  if ( ! bp_core_check_for_blacklist( $activity->user_id, '', $activity->content ) )
159
  bp_activity_mark_as_spam( $activity, 'by_blacklist' );
160
  }
162
  /**
163
  * Custom kses filtering for activity content.
164
  *
165
+ * @since BuddyPress (1.1)
166
  *
167
  * @uses apply_filters() To call the 'bp_activity_allowed_tags' hook.
168
  * @uses wp_kses()
174
  global $allowedtags;
175
 
176
  $activity_allowedtags = $allowedtags;
177
+ $activity_allowedtags['span'] = array();
178
+ $activity_allowedtags['span']['class'] = array();
179
  $activity_allowedtags['a']['class'] = array();
180
  $activity_allowedtags['a']['id'] = array();
181
  $activity_allowedtags['a']['rel'] = array();
 
 
 
 
182
  $activity_allowedtags['img'] = array();
183
  $activity_allowedtags['img']['src'] = array();
184
  $activity_allowedtags['img']['alt'] = array();
187
  $activity_allowedtags['img']['class'] = array();
188
  $activity_allowedtags['img']['id'] = array();
189
  $activity_allowedtags['img']['title'] = array();
190
+ $activity_allowedtags['code'] = array();
 
 
191
 
 
 
 
 
 
 
 
192
  $activity_allowedtags = apply_filters( 'bp_activity_allowed_tags', $activity_allowedtags );
193
  return wp_kses( $content, $activity_allowedtags );
194
  }
196
  /**
197
  * Find and link @-mentioned users in the contents of a given item.
198
  *
199
+ * @since BuddyPress (1.2.0)
200
  *
201
+ * @param string $content The contents of a given item.
202
+ * @param int $activity_id The activity id. Deprecated.
203
  * @return string $content Content filtered for mentions.
204
  */
205
  function bp_activity_at_name_filter( $content, $activity_id = 0 ) {
209
  return $content;
210
  }
211
 
212
+ // Try to find mentions
213
  $usernames = bp_activity_find_mentions( $content );
214
 
215
  // No mentions? Stop now!
217
  return $content;
218
 
219
  // We don't want to link @mentions that are inside of links, so we
220
+ // temporarily remove them
221
  $replace_count = 0;
222
  $replacements = array();
223
  foreach ( $usernames as $username ) {
224
+ // prevent @ name linking inside <a> tags
225
  preg_match_all( '/(<a.*?(?!<\/a>)@' . $username . '.*?<\/a>)/', $content, $content_matches );
226
  if ( ! empty( $content_matches[1] ) ) {
227
  foreach ( $content_matches[1] as $replacement ) {
232
  }
233
  }
234
 
235
+ // Linkify the mentions with the username
236
  foreach ( (array) $usernames as $user_id => $username ) {
237
  $content = preg_replace( '/(@' . $username . '\b)/', "<a href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $content );
238
  }
239
 
240
+ // put everything back
241
  if ( ! empty( $replacements ) ) {
242
  foreach ( $replacements as $placeholder => $original ) {
243
  $content = str_replace( $placeholder, $original, $content );
244
  }
245
  }
246
 
247
+ // Return the content
248
  return $content;
249
  }
250
 
254
  * If mentions are found, replace @mention text with user links and add our
255
  * hook to send mention notifications after the activity item is saved.
256
  *
257
+ * @since BuddyPress (1.5)
258
  *
259
  * @uses bp_activity_find_mentions()
260
  *
261
+ * @param BP_Activity_Activity $activity
262
  */
263
  function bp_activity_at_name_filter_updates( $activity ) {
264
  // Are mentions disabled?
270
  if ( ! empty( $activity->is_spam ) )
271
  return;
272
 
273
+ // Try to find mentions
274
  $usernames = bp_activity_find_mentions( $activity->content );
275
 
276
  // We have mentions!
277
  if ( ! empty( $usernames ) ) {
278
+ // Replace @mention text with userlinks
279
  foreach( (array) $usernames as $user_id => $username ) {
280
  $activity->content = preg_replace( '/(@' . $username . '\b)/', "<a href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $activity->content );
281
  }
282
 
283
+ // Add our hook to send @mention emails after the activity item is saved
284
  add_action( 'bp_activity_after_save', 'bp_activity_at_name_send_emails' );
285
 
286
+ // temporary variable to avoid having to run bp_activity_find_mentions() again
287
  buddypress()->activity->mentioned_users = $usernames;
288
  }
289
  }
291
  /**
292
  * Sends emails and BP notifications for users @-mentioned in an activity item.
293
  *
294
+ * @since BuddyPress (1.7)
295
  *
296
  * @uses bp_activity_at_message_notification()
297
  * @uses bp_activity_update_mention_count_for_user()
298
  *
299
+ * @param BP_Activity_Activity $activity The BP_Activity_Activity object
300
  */
301
  function bp_activity_at_name_send_emails( $activity ) {
302
  // Are mentions disabled?
308
  if ( empty( buddypress()->activity->mentioned_users ) )
309
  return;
310
 
311
+ // Grab our temporary variable from bp_activity_at_name_filter_updates()
312
  $usernames = buddypress()->activity->mentioned_users;
313
 
314
+ // Get rid of temporary variable
315
  unset( buddypress()->activity->mentioned_users );
316
 
317
+ // Send @mentions and setup BP notifications
318
  foreach( (array) $usernames as $user_id => $username ) {
319
+ // If you want to disable notifications, you can use this filter to stop email sending
 
 
 
 
 
 
 
 
320
  if ( apply_filters( 'bp_activity_at_name_do_notifications', true, $usernames ) ) {
321
  bp_activity_at_message_notification( $activity->id, $user_id );
322
  }
323
 
324
+ // Updates mention count for the user
325
  bp_activity_update_mention_count_for_user( $user_id, $activity->id );
326
  }
327
  }
329
  /**
330
  * Catch links in activity text so rel=nofollow can be added.
331
  *
332
+ * @since BuddyPress (1.2)
333
  *
334
  * @param string $text Activity text.
335
  * @return string $text Text with rel=nofollow added to any links.
341
  /**
342
  * Add rel=nofollow to a link.
343
  *
344
+ * @since BuddyPress (1.2)
345
+ *
346
+ * @param array $matches
347
  *
348
  * @param array $matches Items matched by preg_replace_callback() in bp_activity_make_nofollow_filter().
349
+ * @return string $text Link with rel=nofollow added
350
  */
351
  function bp_activity_make_nofollow_filter_callback( $matches ) {
352
  $text = $matches[1];
357
  /**
358
  * Truncate long activity entries when viewed in activity streams.
359
  *
360
+ * @since BuddyPress (1.5)
 
 
361
  *
362
  * @uses bp_is_single_activity()
363
  * @uses apply_filters() To call the 'bp_activity_excerpt_append_text' hook.
373
  function bp_activity_truncate_entry( $text ) {
374
  global $activities_template;
375
 
376
+ // The full text of the activity update should always show on the single activity screen
377
+ if ( bp_is_single_activity() )
 
 
 
 
 
 
 
 
 
 
 
 
378
  return $text;
 
379
 
 
 
 
 
 
 
 
380
  $append_text = apply_filters( 'bp_activity_excerpt_append_text', __( '[Read more]', 'buddypress' ) );
 
 
 
 
 
 
 
 
381
  $excerpt_length = apply_filters( 'bp_activity_excerpt_length', 358 );
382
 
383
+ // Run the text through the excerpt function. If it's too short, the original text will be
384
+ // returned.
385
  $excerpt = bp_create_excerpt( $text, $excerpt_length, array( 'ending' => __( '&hellip;', 'buddypress' ) ) );
386
 
387
+ // If the text returned by bp_create_excerpt() is different from the original text (ie it's
388
+ // been truncated), add the "Read More" link. Note that bp_create_excerpt() is stripping
389
+ // shortcodes, so we have strip them from the $text before the comparison
 
 
390
  if ( $excerpt != strip_shortcodes( $text ) ) {
391
  $id = !empty( $activities_template->activity->current_comment->id ) ? 'acomment-read-more-' . $activities_template->activity->current_comment->id : 'activity-read-more-' . bp_get_activity_id();
392
 
393
  $excerpt = sprintf( '%1$s<span class="activity-read-more" id="%2$s"><a href="%3$s" rel="nofollow">%4$s</a></span>', $excerpt, $id, bp_get_activity_thread_permalink(), $append_text );
394
  }
395
 
 
 
 
 
 
 
 
 
 
396
  return apply_filters( 'bp_activity_truncate_entry', $excerpt, $text, $append_text );
397
  }
398
 
399
  /**
400
+ * Include extra javascript dependencies for activity component.
401
  *
402
+ * @since BuddyPress (2.0.0)
403
  *
404
  * @uses bp_activity_do_heartbeat() to check if heartbeat is required.
405
  *
421
  * We use these classes to avoid pagination issues when items are loaded
422
  * dynamically into the activity stream.
423
  *
424
+ * @since BuddyPress (2.0.0)
425
  *
426
+ * @param string $classes
427
  * @return string $classes
428
  */
429
  function bp_activity_newest_class( $classes = '' ) {
440
  /**
441
  * Check if Activity Heartbeat feature i on to add a timestamp class.
442
  *
443
+ * @since BuddyPress (2.0.0)
444
  *
445
+ * @param string $classes
446
  * @return string $classes
447
  */
448
  function bp_activity_timestamp_class( $classes = '' ) {
456
  if ( empty( $activity_date ) ) {
457
  return $classes;
458
  }
459
+
460
  $classes .= ' date-recorded-' . strtotime( $activity_date );
461
 
462
  return $classes;
466
  /**
467
  * Use WordPress Heartbeat API to check for latest activity update.
468
  *
469
+ * @since BuddyPress (2.0.0)
470
  *
471
+ * @uses bp_activity_get_last_updated() to get the recorded date of the last activity
472
  *
473
+ * @param array $response
474
+ * @param array $data
475
  * @return array $response
476
  */
477
  function bp_activity_heartbeat_last_recorded( $response = array(), $data = array() ) {
478
+ $bp = buddypress();
479
+
480
  if ( empty( $data['bp_activity_last_recorded'] ) ) {
481
  return $response;
482
  }
483
 
484
  // Use the querystring argument stored in the cookie (to preserve
485
+ // filters), but force the offset to get only new items
486
  $activity_latest_args = bp_parse_args(
487
  bp_ajax_querystring( 'activity' ),
488
  array( 'since' => date( 'Y-m-d H:i:s', $data['bp_activity_last_recorded'] ) ),
489
  'activity_latest_args'
490
  );
491
 
 
 
 
 
492
  $newest_activities = array();
493
  $last_activity_recorded = 0;
494
 
495
+ // Temporarly add a just-posted class for new activity items
496
  add_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 );
497
 
498
  ob_start();
513
  $newest_activities['last_recorded'] = $last_activity_recorded;
514
  ob_end_clean();
515
 
516
+ // Remove the temporary filter
517
  remove_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 );
518
 
519
  if ( ! empty( $newest_activities['last_recorded'] ) ) {
528
  /**
529
  * Set the strings for WP HeartBeat API where needed.
530
  *
531
+ * @since BuddyPress (2.0.0)
532
  *
533
  * @param array $strings Localized strings.
534
  * @return array $strings
541
 
542
  $global_pulse = 0;
543
 
544
+ // Check whether the global heartbeat settings already exist.
 
 
 
 
 
 
545
  $heartbeat_settings = apply_filters( 'heartbeat_settings', array() );
546
  if ( ! empty( $heartbeat_settings['interval'] ) ) {
547
  // 'Fast' is 5
548
  $global_pulse = is_numeric( $heartbeat_settings['interval'] ) ? absint( $heartbeat_settings['interval'] ) : 5;
549
  }
550
 
551
+ // Filter here to specify a BP-specific pulse frequency
 
 
 
 
 
 
552
  $bp_activity_pulse = apply_filters( 'bp_activity_heartbeat_pulse', 15 );
553
 
554
  /**
571
  return $strings;
572
  }
573
  add_filter( 'bp_core_get_js_strings', 'bp_activity_heartbeat_strings', 10, 1 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-activity/bp-activity-functions.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  /**
3
  * BuddyPress Activity Functions.
4
  *
@@ -8,18 +9,22 @@
8
  * @subpackage ActivityFunctions
9
  */
10
 
11
- // Exit if accessed directly.
12
- defined( 'ABSPATH' ) || exit;
13
 
14
  /**
15
  * Check whether the $bp global lists an activity directory page.
16
  *
17
- * @since 1.5.0
 
 
18
  *
19
  * @return bool True if activity directory page is found, otherwise false.
20
  */
21
  function bp_activity_has_directory() {
22
- return (bool) !empty( buddypress()->pages->activity->id );
 
 
23
  }
24
 
25
  /**
@@ -27,95 +32,56 @@ function bp_activity_has_directory() {
27
  *
28
  * The Mentions feature does a number of things, all of which will be turned
29
  * off if you disable mentions:
30
- * - Detecting and auto-linking @username in all BP/WP content.
31
  * - Sending BP notifications and emails to users when they are mentioned
32
- * using the @username syntax.
33
- * - The Public Message button on user profiles.
34
  *
35
  * Mentions are enabled by default. To disable, put the following line in
36
  * bp-custom.php or your theme's functions.php file:
37
  *
38
  * add_filter( 'bp_activity_do_mentions', '__return_false' );
39
  *
40
- * @since 1.8.0
41
  *
42
  * @uses apply_filters() To call 'bp_activity_do_mentions' hook.
43
  *
44
  * @return bool $retval True to enable mentions, false to disable.
45
  */
46
  function bp_activity_do_mentions() {
47
-
48
- /**
49
- * Filters whether or not mentions are enabled.
50
- *
51
- * @since 1.8.0
52
- *
53
- * @param bool $enabled True to enable mentions, false to disable.
54
- */
55
  return (bool) apply_filters( 'bp_activity_do_mentions', true );
56
  }
57
 
58
- /**
59
- * Should BuddyPress load the mentions scripts and related assets, including results to prime the
60
- * mentions suggestions?
61
- *
62
- * @since 2.1.0
63
- *
64
- * @return bool True if mentions scripts should be loaded.
65
- */
66
- function bp_activity_maybe_load_mentions_scripts() {
67
- $mentions_enabled = bp_activity_do_mentions() && bp_is_user_active();
68
- $load_mentions = $mentions_enabled && ( bp_is_activity_component() || is_admin() );
69
-
70
- /**
71
- * Filters whether or not BuddyPress should load mentions scripts and assets.
72
- *
73
- * @since 2.1.0
74
- *
75
- * @param bool $load_mentions True to load mentions assets, false otherwise.
76
- * @param bool $mentions_enabled True if mentions are enabled.
77
- */
78
- return (bool) apply_filters( 'bp_activity_maybe_load_mentions_scripts', $load_mentions, $mentions_enabled );
79
- }
80
-
81
  /**
82
  * Locate usernames in an activity content string, as designated by an @ sign.
83
  *
84
- * @since 1.5.0
85
  *
86
- * @param string $content The content of the activity, usually found in
87
- * $activity->content.
88
- * @return array|bool Associative array with user ID as key and username as
89
- * value. Boolean false if no mentions found.
90
  */
91
  function bp_activity_find_mentions( $content ) {
92
-
93
  $pattern = '/[@]+([A-Za-z0-9-_\.@]+)\b/';
94
  preg_match_all( $pattern, $content, $usernames );
95
 
96
- // Make sure there's only one instance of each username.
97
- $usernames = array_unique( $usernames[1] );
98
-
99
- // Bail if no usernames.
100
- if ( empty( $usernames ) ) {
101
  return false;
102
- }
103
 
104
  $mentioned_users = array();
105
 
106
- // We've found some mentions! Check to see if users exist.
107
- foreach( (array) array_values( $usernames ) as $username ) {
108
  $user_id = bp_activity_get_userid_from_mentionname( $username );
109
 
110
- // The user ID exists, so let's add it to our array.
111
  if ( ! empty( $user_id ) ) {
112
- $mentioned_users[ $user_id ] = $username;
113
  }
114
  }
115
 
116
- if ( empty( $mentioned_users ) ) {
117
  return false;
118
- }
119
 
120
  return $mentioned_users;
121
  }
@@ -123,7 +89,7 @@ function bp_activity_find_mentions( $content ) {
123
  /**
124
  * Reset a user's unread mentions list and count.
125
  *
126
- * @since 1.5.0
127
  *
128
  * @uses bp_delete_user_meta()
129
  *
@@ -131,7 +97,7 @@ function bp_activity_find_mentions( $content ) {
131
  */
132
  function bp_activity_clear_new_mentions( $user_id ) {
133
  bp_delete_user_meta( $user_id, 'bp_new_mention_count' );
134
- bp_delete_user_meta( $user_id, 'bp_new_mentions' );
135
  }
136
 
137
  /**
@@ -142,35 +108,30 @@ function bp_activity_clear_new_mentions( $user_id ) {
142
  *
143
  * Currently, only used in {@link bp_activity_delete()}.
144
  *
145
- * @since 1.5.0
146
  *
147
  * @uses bp_activity_find_mentions()
148
  * @uses bp_activity_update_mention_count_for_user()
149
  *
150
- * @param int $activity_id The unique id for the activity item.
151
- * @param string $action Can be 'delete' or 'add'. Defaults to 'add'.
152
- * @return bool
153
  */
154
  function bp_activity_adjust_mention_count( $activity_id = 0, $action = 'add' ) {
155
-
156
- // Bail if no activity ID passed.
157
- if ( empty( $activity_id ) ) {
158
  return false;
159
- }
160
 
161
- // Get activity object.
162
- $activity = new BP_Activity_Activity( (int) $activity_id );
163
 
164
- // Try to find mentions.
165
  $usernames = bp_activity_find_mentions( strip_tags( $activity->content ) );
166
 
167
- // Still empty? Stop now.
168
- if ( empty( $usernames ) ) {
169
  return false;
170
- }
171
 
172
- // Increment mention count foreach mentioned user.
173
- foreach( (array) array_keys( $usernames ) as $user_id ) {
174
  bp_activity_update_mention_count_for_user( $user_id, $activity_id, $action );
175
  }
176
  }
@@ -181,30 +142,24 @@ function bp_activity_adjust_mention_count( $activity_id = 0, $action = 'add' ) {
181
  * This function should be used when you've already parsed your activity item
182
  * for @mentions.
183
  *
184
- * @since 1.7.0
185
  *
186
  * @uses bp_get_user_meta()
187
  * @uses bp_update_user_meta()
188
  *
189
- * @param int $user_id The user ID.
190
- * @param int $activity_id The unique ID for the activity item.
191
- * @param string $action 'delete' or 'add'. Default: 'add'.
192
  * @return bool
193
  */
194
  function bp_activity_update_mention_count_for_user( $user_id, $activity_id, $action = 'add' ) {
195
-
196
- if ( empty( $user_id ) || empty( $activity_id ) ) {
197
  return false;
198
- }
199
 
200
- // Adjust the mention list and count for the member.
201
  $new_mention_count = (int) bp_get_user_meta( $user_id, 'bp_new_mention_count', true );
202
- $new_mentions = bp_get_user_meta( $user_id, 'bp_new_mentions', true );
203
-
204
- // Make sure new mentions is an array.
205
- if ( empty( $new_mentions ) ) {
206
  $new_mentions = array();
207
- }
208
 
209
  switch ( $action ) {
210
  case 'delete' :
@@ -225,10 +180,10 @@ function bp_activity_update_mention_count_for_user( $user_id, $activity_id, $act
225
  break;
226
  }
227
 
228
- // Get an updated mention count.
229
  $new_mention_count = count( $new_mentions );
230
 
231
- // Resave the user_meta.
232
  bp_update_user_meta( $user_id, 'bp_new_mention_count', $new_mention_count );
233
  bp_update_user_meta( $user_id, 'bp_new_mentions', $new_mentions );
234
 
@@ -238,10 +193,9 @@ function bp_activity_update_mention_count_for_user( $user_id, $activity_id, $act
238
  /**
239
  * Determine a user's "mentionname", the name used for that user in @-mentions.
240
  *
241
- * @since 1.9.0
242
  *
243
- * @param int|string $user_id ID of the user to get @-mention name for.
244
- * @return string $mentionname User name appropriate for @-mentions.
245
  */
246
  function bp_activity_get_user_mentionname( $user_id ) {
247
  $mentionname = '';
@@ -262,24 +216,21 @@ function bp_activity_get_user_mentionname( $user_id ) {
262
  /**
263
  * Get a user ID from a "mentionname", the name used for a user in @-mentions.
264
  *
265
- * @since 1.9.0
266
  *
267
- * @param string $mentionname Username of user in @-mentions.
268
  * @return int|bool ID of the user, if one is found. Otherwise false.
269
  */
270
  function bp_activity_get_userid_from_mentionname( $mentionname ) {
271
  $user_id = false;
272
 
273
- /*
274
- * In username compatibility mode, hyphens are ambiguous between
275
- * actual hyphens and converted spaces.
276
- *
277
- * @todo There is the potential for username clashes between 'foo bar'
278
- * and 'foo-bar' in compatibility mode. Come up with a system for
279
- * unique mentionnames.
280
- */
281
  if ( bp_is_username_compatibility_mode() ) {
282
- // First, try the raw username.
283
  $userdata = get_user_by( 'login', $mentionname );
284
 
285
  // Doing a direct query to use proper regex. Necessary to
@@ -293,7 +244,7 @@ function bp_activity_get_userid_from_mentionname( $mentionname ) {
293
  }
294
 
295
  // When username compatibility mode is disabled, the mentionname is
296
- // the same as the nicename.
297
  } else {
298
  $user_id = bp_core_get_userid_from_nicename( $mentionname );
299
  }
@@ -318,32 +269,28 @@ function bp_activity_get_userid_from_mentionname( $mentionname ) {
318
  * panel, and dynamic action generation (which is essential for multilingual
319
  * sites, etc) will not work.
320
  *
321
- * @since 1.1.0
322
  *
323
- * @param string $component_id The unique string ID of the component.
324
- * @param string $type The action type.
325
- * @param string $description The action description.
326
- * @param callable|bool $format_callback Callback for formatting the action string.
327
- * @param string|bool $label String to describe this action in the activity stream filter dropdown.
328
- * @param array $context Optional. Activity stream contexts where the filter should appear.
329
- * Values: 'activity', 'member', 'member_groups', 'group'.
330
- * @param int $position Optional. The position of the action when listed in dropdowns.
331
  * @return bool False if any param is empty, otherwise true.
332
  */
333
- function bp_activity_set_action( $component_id, $type, $description, $format_callback = false, $label = false, $context = array(), $position = 0 ) {
334
  $bp = buddypress();
335
 
336
- // Return false if any of the above values are not set.
337
  if ( empty( $component_id ) || empty( $type ) || empty( $description ) ) {
338
  return false;
339
  }
340
 
341
- // Set activity action.
342
  if ( ! isset( $bp->activity->actions ) || ! is_object( $bp->activity->actions ) ) {
343
  $bp->activity->actions = new stdClass;
344
  }
345
 
346
- // Verify callback.
347
  if ( ! is_callable( $format_callback ) ) {
348
  $format_callback = '';
349
  }
@@ -352,273 +299,41 @@ function bp_activity_set_action( $component_id, $type, $description, $format_cal
352
  $bp->activity->actions->{$component_id} = new stdClass;
353
  }
354
 
355
- /**
356
- * Filters the action type being set for the current activity item.
357
- *
358
- * @since 1.1.0
359
- *
360
- * @param array $array Array of arguments for action type being set.
361
- * @param string $component_id ID of the current component being set.
362
- * @param string $type Action type being set.
363
- * @param string $description Action description for action being set.
364
- * @param callable $format_callback Callback for formatting the action string.
365
- * @param string $label String to describe this action in the activity stream filter dropdown.
366
- * @param array $context Activity stream contexts where the filter should appear. 'activity', 'member',
367
- * 'member_groups', 'group'.
368
- */
369
  $bp->activity->actions->{$component_id}->{$type} = apply_filters( 'bp_activity_set_action', array(
370
  'key' => $type,
371
  'value' => $description,
372
  'format_callback' => $format_callback,
373
- 'label' => $label,
374
- 'context' => $context,
375
- 'position' => $position,
376
- ), $component_id, $type, $description, $format_callback, $label, $context );
377
 
378
  return true;
379
  }
380
 
381
  /**
382
- * Set tracking arguments for a given post type.
383
- *
384
- * @since 2.2.0
385
- *
386
- * @global $wp_post_types
387
- *
388
- * @param string $post_type The name of the post type, as registered with WordPress. Eg 'post' or 'page'.
389
- * @param array $args {
390
- * An associative array of tracking parameters. All items are optional.
391
- * @type string $bp_activity_admin_filter String to use in the Dashboard > Activity dropdown.
392
- * @type string $bp_activity_front_filter String to use in frontend dropdown.
393
- * @type string $bp_activity_new_post String format to use for generating the activity action. Should be a
394
- * translatable string where %1$s is replaced by a user link and %2$s is
395
- * the URL of the newly created post.
396
- * @type string $bp_activity_new_post_ms String format to use for generating the activity action on Multisite.
397
- * Should be a translatable string where %1$s is replaced by a user link,
398
- * %2$s is the URL of the newly created post, and %3$s is a link to
399
- * the site.
400
- * @type string $component_id ID of the BuddyPress component to associate the activity item.
401
- * @type string $action_id Value for the 'type' param of the new activity item.
402
- * @type callable $format_callback Callback for formatting the activity action string.
403
- * Default: 'bp_activity_format_activity_action_custom_post_type_post'.
404
- * @type array $contexts The directory contexts in which the filter will show.
405
- * Default: array( 'activity' ).
406
- * @type array $position Position of the item in filter dropdowns.
407
- * @type string $singular Singular, translatable name of the post type item. If no value is
408
- * provided, it's pulled from the 'singular_name' of the post type.
409
- * @type bool $activity_comment Whether to allow comments on the activity items. Defaults to true if
410
- * the post type does not natively support comments, otherwise false.
411
- * }
412
- * @return bool
413
- */
414
- function bp_activity_set_post_type_tracking_args( $post_type = '', $args = array() ) {
415
- global $wp_post_types;
416
-
417
- if ( empty( $wp_post_types[ $post_type ] ) || ! post_type_supports( $post_type, 'buddypress-activity' ) || ! is_array( $args ) ) {
418
- return false;
419
- }
420
-
421
- // Labels are loaded into the post type object.
422
- foreach ( array( 'bp_activity_admin_filter', 'bp_activity_front_filter', 'bp_activity_new_post', 'bp_activity_new_post_ms' ) as $label_type ) {
423
- if ( ! empty( $args[ $label_type ] ) ) {
424
- $wp_post_types[ $post_type ]->labels->{$label_type} = $args[ $label_type ];
425
- unset( $args[ $post_type ] );
426
- }
427
- }
428
-
429
- // If there are any additional args, put them in the bp_activity attribute of the post type.
430
- if ( ! empty( $args ) ) {
431
- $wp_post_types[ $post_type ]->bp_activity = $args;
432
- }
433
- }
434
-
435
- /**
436
- * Get tracking arguments for a specific post type.
437
- *
438
- * @since 2.2.0
439
- *
440
- * @param string $post_type Name of the post type.
441
- * @return object The tracking arguments of the post type.
442
- */
443
- function bp_activity_get_post_type_tracking_args( $post_type ) {
444
- if ( ! post_type_supports( $post_type, 'buddypress-activity' ) ) {
445
- return false;
446
- }
447
-
448
- $post_type_object = get_post_type_object( $post_type );
449
-
450
- $post_type_activity = array(
451
- 'component_id' => buddypress()->activity->id,
452
- 'action_id' => 'new_' . $post_type,
453
- 'format_callback' => 'bp_activity_format_activity_action_custom_post_type_post',
454
- 'front_filter' => $post_type_object->labels->name,
455
- 'contexts' => array( 'activity' ),
456
- 'position' => 0,
457
- 'singular' => strtolower( $post_type_object->labels->singular_name ),
458
- 'activity_comment' => ! post_type_supports( $post_type, 'comments' ),
459
- );
460
-
461
- if ( ! empty( $post_type_object->bp_activity ) ) {
462
- $post_type_activity = bp_parse_args( (array) $post_type_object->bp_activity, $post_type_activity, $post_type . '_tracking_args' );
463
- }
464
-
465
- $post_type_activity = (object) $post_type_activity;
466
-
467
- // Try to get the admin filter from the post type labels.
468
- if ( ! empty( $post_type_object->labels->bp_activity_admin_filter ) ) {
469
- $post_type_activity->admin_filter = $post_type_object->labels->bp_activity_admin_filter;
470
-
471
- // Fall back to a generic name.
472
- } else {
473
- $post_type_activity->admin_filter = _x( 'New item published', 'Post Type generic activity post admin filter', 'buddypress' );
474
- }
475
-
476
- // Check for the front filter in the post type labels.
477
- if ( ! empty( $post_type_object->labels->bp_activity_front_filter ) ) {
478
- $post_type_activity->front_filter = $post_type_object->labels->bp_activity_front_filter;
479
- }
480
-
481
- // Try to get the action for new post type action on non-multisite installations.
482
- if ( ! empty( $post_type_object->labels->bp_activity_new_post ) ) {
483
- $post_type_activity->new_post_type_action = $post_type_object->labels->bp_activity_new_post;
484
- }
485
-
486
- // Try to get the action for new post type action on multisite installations.
487
- if ( ! empty( $post_type_object->labels->bp_activity_new_post_ms ) ) {
488
- $post_type_activity->new_post_type_action_ms = $post_type_object->labels->bp_activity_new_post_ms;
489
- }
490
-
491
- /**
492
- * Filters tracking arguments for a specific post type.
493
- *
494
- * @since 2.2.0
495
- *
496
- * @param object $post_type_activity The tracking arguments of the post type.
497
- * @param string $post_type Name of the post type.
498
- */
499
- return apply_filters( 'bp_activity_get_post_type_tracking_args', $post_type_activity, $post_type );
500
- }
501
-
502
- /**
503
- * Get tracking arguments for all post types.
504
- *
505
- * @since 2.2.0
506
- *
507
- * @return array List of post types with their tracking arguments.
508
- */
509
- function bp_activity_get_post_types_tracking_args() {
510
- // Fetch all public post types.
511
- $post_types = get_post_types( array( 'public' => true ), 'names' );
512
-
513
- $post_types_tracking_args = array();
514
-
515
- foreach ( $post_types as $post_type ) {
516
- $track_post_type = bp_activity_get_post_type_tracking_args( $post_type );
517
-
518
- if ( ! empty( $track_post_type ) ) {
519
- $post_types_tracking_args[ $track_post_type->action_id ] = $track_post_type;
520
- }
521
-
522
- }
523
-
524
- /**
525
- * Filters tracking arguments for all post types.
526
- *
527
- * @since 2.2.0
528
- *
529
- * @param array $post_types_tracking_args Array of post types with
530
- * their tracking arguments.
531
- */
532
- return apply_filters( 'bp_activity_get_post_types_tracking_args', $post_types_tracking_args );
533
- }
534
-
535
- /**
536
- * Get all components' activity actions, sorted by their position attribute.
537
- *
538
- * @since 2.2.0
539
- *
540
- * @return object Actions ordered by their position.
541
- */
542
- function bp_activity_get_actions() {
543
- $bp = buddypress();
544
-
545
- $post_types = bp_activity_get_post_types_tracking_args();
546
-
547
- // Create the actions for the post types, if they haven't already been created.
548
- if ( ! empty( $post_types ) ) {
549
- foreach ( $post_types as $post_type ) {
550
- if ( isset( $bp->activity->actions->{$post_type->component_id}->{$post_type->action_id} ) ) {
551
- continue;
552
- }
553
-
554
- bp_activity_set_action(
555
- $post_type->component_id,
556
- $post_type->action_id,
557
- $post_type->admin_filter,
558
- $post_type->format_callback,
559
- $post_type->front_filter,
560
- $post_type->contexts,
561
- $post_type->position
562
- );
563
- }
564
- }
565
-
566
- // Sort the actions by their position within each component.
567
- foreach ( $bp->activity->actions as $component => $actions ) {
568
- $actions = (array) $actions;
569
- $temp = bp_sort_by_key( $actions, 'position', 'num' );
570
-
571
- // Restore keys.
572
- $bp->activity->actions->{$component} = new stdClass;
573
- foreach ( $temp as $key_ordered ) {
574
- $bp->activity->actions->{$component}->{$key_ordered['key']} = $key_ordered;
575
- }
576
- }
577
-
578
- return $bp->activity->actions;
579
- }
580
-
581
- /**
582
- * Retrieve the current action from a component and key.
583
  *
584
- * @since 1.1.0
585
  *
 
586
  * @uses apply_filters() To call the 'bp_activity_get_action' hook.
587
  *
588
  * @param string $component_id The unique string ID of the component.
589
- * @param string $key The action key.
590
  * @return string|bool Action value if found, otherwise false.
591
  */
592
  function bp_activity_get_action( $component_id, $key ) {
 
593
 
594
- // Return false if any of the above values are not set.
595
- if ( empty( $component_id ) || empty( $key ) ) {
596
  return false;
597
- }
598
-
599
- $actions = bp_activity_get_actions();
600
- $retval = false;
601
-
602
- if ( isset( $actions->{$component_id}->{$key} ) ) {
603
- $retval = $actions->{$component_id}->{$key};
604
- }
605
 
606
- /**
607
- * Filters the current action by component and key.
608
- *
609
- * @since 1.1.0
610
- *
611
- * @param string|bool $retval The action key.
612
- * @param string $component_id The unique string ID of the component.
613
- * @param string $key The action key.
614
- */
615
- return apply_filters( 'bp_activity_get_action', $retval, $component_id, $key );
616
  }
617
 
618
  /**
619
  * Fetch details of all registered activity types.
620
  *
621
- * @since 1.7.0
622
  *
623
  * @return array array( type => description ), ...
624
  */
@@ -626,24 +341,16 @@ function bp_activity_get_types() {
626
  $actions = array();
627
 
628
  // Walk through the registered actions, and build an array of actions/values.
629
- foreach ( bp_activity_get_actions() as $action ) {
630
  $action = array_values( (array) $action );
631
 
632
- for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ ) {
633
  $actions[ $action[$i]['key'] ] = $action[$i]['value'];
634
- }
635
  }
636
 
637
- // This was a mis-named activity type from before BP 1.6.
638
  unset( $actions['friends_register_activity_action'] );
639
 
640
- /**
641
- * Filters the available activity types.
642
- *
643
- * @since 1.7.0
644
- *
645
- * @param array $actions Array of registered activity types.
646
- */
647
  return apply_filters( 'bp_activity_get_types', $actions );
648
  }
649
 
@@ -652,7 +359,7 @@ function bp_activity_get_types() {
652
  /**
653
  * Get a users favorite activity stream items.
654
  *
655
- * @since 1.2.0
656
  *
657
  * @uses bp_get_user_meta()
658
  * @uses apply_filters() To call the 'bp_activity_get_user_favorites' hook.
@@ -662,28 +369,20 @@ function bp_activity_get_types() {
662
  */
663
  function bp_activity_get_user_favorites( $user_id = 0 ) {
664
 
665
- // Fallback to logged in user if no user_id is passed.
666
- if ( empty( $user_id ) ) {
667
  $user_id = bp_displayed_user_id();
668
- }
669
 
670
- // Get favorites for user.
671
  $favs = bp_get_user_meta( $user_id, 'bp_favorite_activities', true );
672
 
673
- /**
674
- * Filters the favorited activity items for a specified user.
675
- *
676
- * @since 1.2.0
677
- *
678
- * @param array $favs Array of user's favorited activity items.
679
- */
680
  return apply_filters( 'bp_activity_get_user_favorites', $favs );
681
  }
682
 
683
  /**
684
  * Add an activity stream item as a favorite for a user.
685
  *
686
- * @since 1.2.0
687
  *
688
  * @uses is_user_logged_in()
689
  * @uses bp_get_user_meta()
@@ -694,68 +393,51 @@ function bp_activity_get_user_favorites( $user_id = 0 ) {
694
  * @uses do_action() To call the 'bp_activity_add_user_favorite_fail' hook.
695
  *
696
  * @param int $activity_id ID of the activity item being favorited.
697
- * @param int $user_id ID of the user favoriting the activity item.
698
  * @return bool True on success, false on failure.
699
  */
700
  function bp_activity_add_user_favorite( $activity_id, $user_id = 0 ) {
701
 
702
- // Favorite activity stream items are for logged in users only.
703
- if ( ! is_user_logged_in() ) {
704
  return false;
705
- }
706
 
707
- // Fallback to logged in user if no user_id is passed.
708
- if ( empty( $user_id ) ) {
709
  $user_id = bp_loggedin_user_id();
710
- }
711
 
712
  $my_favs = bp_get_user_meta( $user_id, 'bp_favorite_activities', true );
713
  if ( empty( $my_favs ) || ! is_array( $my_favs ) ) {
714
  $my_favs = array();
715
  }
716
 
717
- // Bail if the user has already favorited this activity item.
718
  if ( in_array( $activity_id, $my_favs ) ) {
719
  return false;
720
  }
721
 
722
- // Add to user's favorites.
723
  $my_favs[] = $activity_id;
724
 
725
- // Update the total number of users who have favorited this activity.
726
  $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' );
727
  $fav_count = !empty( $fav_count ) ? (int) $fav_count + 1 : 1;
728
 
729
- // Update user meta.
730
  bp_update_user_meta( $user_id, 'bp_favorite_activities', $my_favs );
731
 
732
- // Update activity meta counts.
733
  if ( bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count ) ) {
734
 
735
- /**
736
- * Fires if bp_activity_update_meta() for favorite_count is successful and before returning a true value for success.
737
- *
738
- * @since 1.2.1
739
- *
740
- * @param int $activity_id ID of the activity item being favorited.
741
- * @param int $user_id ID of the user doing the favoriting.
742
- */
743
  do_action( 'bp_activity_add_user_favorite', $activity_id, $user_id );
744
 
745
- // Success.
746
  return true;
747
 
748
- // Saving meta was unsuccessful for an unknown reason.
749
  } else {
750
-
751
- /**
752
- * Fires if bp_activity_update_meta() for favorite_count is unsuccessful and before returning a false value for failure.
753
- *
754
- * @since 1.5.0
755
- *
756
- * @param int $activity_id ID of the activity item being favorited.
757
- * @param int $user_id ID of the user doing the favoriting.
758
- */
759
  do_action( 'bp_activity_add_user_favorite_fail', $activity_id, $user_id );
760
 
761
  return false;
@@ -765,7 +447,7 @@ function bp_activity_add_user_favorite( $activity_id, $user_id = 0 ) {
765
  /**
766
  * Remove an activity stream item as a favorite for a user.
767
  *
768
- * @since 1.2.0
769
  *
770
  * @uses is_user_logged_in()
771
  * @uses bp_get_user_meta()
@@ -775,67 +457,57 @@ function bp_activity_add_user_favorite( $activity_id, $user_id = 0 ) {
775
  * @uses do_action() To call the 'bp_activity_remove_user_favorite' hook.
776
  *
777
  * @param int $activity_id ID of the activity item being unfavorited.
778
- * @param int $user_id ID of the user unfavoriting the activity item.
779
  * @return bool True on success, false on failure.
780
  */
781
  function bp_activity_remove_user_favorite( $activity_id, $user_id = 0 ) {
782
 
783
- // Favorite activity stream items are for logged in users only.
784
- if ( ! is_user_logged_in() ) {
785
  return false;
786
- }
787
 
788
- // Fallback to logged in user if no user_id is passed.
789
- if ( empty( $user_id ) ) {
790
  $user_id = bp_loggedin_user_id();
791
- }
792
 
793
  $my_favs = bp_get_user_meta( $user_id, 'bp_favorite_activities', true );
794
  $my_favs = array_flip( (array) $my_favs );
795
 
796
- // Bail if the user has not previously favorited the item.
797
  if ( ! isset( $my_favs[ $activity_id ] ) ) {
798
  return false;
799
  }
800
 
801
- // Remove the fav from the user's favs.
802
  unset( $my_favs[$activity_id] );
803
  $my_favs = array_unique( array_flip( $my_favs ) );
804
 
805
- // Update the total number of users who have favorited this activity.
806
- $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' );
807
- if ( ! empty( $fav_count ) ) {
808
 
809
- // Deduct from total favorites.
810
  if ( bp_activity_update_meta( $activity_id, 'favorite_count', (int) $fav_count - 1 ) ) {
811
 
812
- // Update users favorites.
813
  if ( bp_update_user_meta( $user_id, 'bp_favorite_activities', $my_favs ) ) {
814
 
815
- /**
816
- * Fires if bp_update_user_meta() is successful and before returning a true value for success.
817
- *
818
- * @since 1.2.1
819
- *
820
- * @param int $activity_id ID of the activity item being unfavorited.
821
- * @param int $user_id ID of the user doing the unfavoriting.
822
- */
823
  do_action( 'bp_activity_remove_user_favorite', $activity_id, $user_id );
824
 
825
- // Success.
826
  return true;
827
 
828
- // Error updating.
829
  } else {
830
  return false;
831
  }
832
 
833
- // Error updating favorite count.
834
  } else {
835
  return false;
836
  }
837
 
838
- // Error getting favorite count.
839
  } else {
840
  return false;
841
  }
@@ -844,7 +516,7 @@ function bp_activity_remove_user_favorite( $activity_id, $user_id = 0 ) {
844
  /**
845
  * Check whether an activity item exists with a given content string.
846
  *
847
- * @since 1.1.0
848
  *
849
  * @uses BP_Activity_Activity::check_exists_by_content() {@link BP_Activity_Activity}
850
  * @uses apply_filters() To call the 'bp_activity_check_exists_by_content' hook.
@@ -853,21 +525,13 @@ function bp_activity_remove_user_favorite( $activity_id, $user_id = 0 ) {
853
  * @return int|null The ID of the located activity item. Null if none is found.
854
  */
855
  function bp_activity_check_exists_by_content( $content ) {
856
-
857
- /**
858
- * Filters the results of the check for whether an activity item exists by specified content.
859
- *
860
- * @since 1.1.0
861
- *
862
- * @param BP_Activity_Activity $content_exists ID of the activity if found, else null.
863
- */
864
  return apply_filters( 'bp_activity_check_exists_by_content', BP_Activity_Activity::check_exists_by_content( $content ) );
865
  }
866
 
867
  /**
868
  * Retrieve the last time activity was updated.
869
  *
870
- * @since 1.0.0
871
  *
872
  * @uses BP_Activity_Activity::get_last_updated() {@link BP_Activity_Activity}
873
  * @uses apply_filters() To call the 'bp_activity_get_last_updated' hook.
@@ -875,21 +539,13 @@ function bp_activity_check_exists_by_content( $content ) {
875
  * @return string Date last updated.
876
  */
877
  function bp_activity_get_last_updated() {
878
-
879
- /**
880
- * Filters the value for the last updated time for an activity item.
881
- *
882
- * @since 1.1.0
883
- *
884
- * @param BP_Activity_Activity $last_updated Date last updated.
885
- */
886
  return apply_filters( 'bp_activity_get_last_updated', BP_Activity_Activity::get_last_updated() );
887
  }
888
 
889
  /**
890
  * Retrieve the number of favorite activity stream items a user has.
891
  *
892
- * @since 1.2.0
893
  *
894
  * @uses BP_Activity_Activity::total_favorite_count() {@link BP_Activity_Activity}
895
  *
@@ -898,10 +554,9 @@ function bp_activity_get_last_updated() {
898
  */
899
  function bp_activity_total_favorites_for_user( $user_id = 0 ) {
900
 
901
- // Fallback on displayed user, and then logged in user.
902
- if ( empty( $user_id ) ) {
903
  $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
904
- }
905
 
906
  return BP_Activity_Activity::total_favorite_count( $user_id );
907
  }
@@ -911,30 +566,32 @@ function bp_activity_total_favorites_for_user( $user_id = 0 ) {
911
  /**
912
  * Delete a meta entry from the DB for an activity stream item.
913
  *
914
- * @since 1.2.0
915
  *
916
  * @global object $wpdb WordPress database access object.
917
- *
918
- * @param int $activity_id ID of the activity item whose metadata is being deleted.
919
- * @param string $meta_key Optional. The key of the metadata being deleted. If
920
- * omitted, all metadata associated with the activity
921
- * item will be deleted.
922
- * @param string $meta_value Optional. If present, the metadata will only be
923
- * deleted if the meta_value matches this parameter.
924
- * @param bool $delete_all Optional. If true, delete matching metadata entries
925
- * for all objects, ignoring the specified object_id. Otherwise,
926
- * only delete matching metadata entries for the specified
927
- * activity item. Default: false.
 
928
  * @return bool True on success, false on failure.
929
  */
930
  function bp_activity_delete_meta( $activity_id, $meta_key = '', $meta_value = '', $delete_all = false ) {
 
931
 
932
- // Legacy - if no meta_key is passed, delete all for the item.
933
  if ( empty( $meta_key ) ) {
934
  $all_meta = bp_activity_get_meta( $activity_id );
935
  $keys = ! empty( $all_meta ) ? array_keys( $all_meta ) : array();
936
 
937
- // With no meta_key, ignore $delete_all.
938
  $delete_all = false;
939
  } else {
940
  $keys = array( $meta_key );
@@ -954,17 +611,17 @@ function bp_activity_delete_meta( $activity_id, $meta_key = '', $meta_value = ''
954
  /**
955
  * Get metadata for a given activity item.
956
  *
957
- * @since 1.2.0
958
  *
959
  * @uses apply_filters() To call the 'bp_activity_get_meta' hook.
960
  *
961
- * @param int $activity_id ID of the activity item whose metadata is being requested.
962
- * @param string $meta_key Optional. If present, only the metadata matching
963
- * that meta key will be returned. Otherwise, all metadata for the
964
- * activity item will be fetched.
965
- * @param bool $single Optional. If true, return only the first value of the
966
- * specified meta_key. This parameter has no effect if meta_key is not
967
- * specified. Default: true.
968
  * @return mixed The meta value(s) being requested.
969
  */
970
  function bp_activity_get_meta( $activity_id = 0, $meta_key = '', $single = true ) {
@@ -972,32 +629,25 @@ function bp_activity_get_meta( $activity_id = 0, $meta_key = '', $single = true
972
  $retval = get_metadata( 'activity', $activity_id, $meta_key, $single );
973
  remove_filter( 'query', 'bp_filter_metaid_column_name' );
974
 
975
- /**
976
- * Filters the metadata for a specified activity item.
977
- *
978
- * @since 1.5.0
979
- *
980
- * @param mixed $retval The meta values for the activity item.
981
- * @param int $activity_id ID of the activity item.
982
- * @param string $meta_key Meta key for the value being requested.
983
- * @param bool $single Whether to return one matched meta key row or all.
984
- */
985
  return apply_filters( 'bp_activity_get_meta', $retval, $activity_id, $meta_key, $single );
986
  }
987
 
988
  /**
989
  * Update a piece of activity meta.
990
  *
991
- * @since 1.2.0
992
  *
993
- * @param int $activity_id ID of the activity item whose metadata is being updated.
994
- * @param string $meta_key Key of the metadata being updated.
995
- * @param mixed $meta_value Value to be set.
996
- * @param mixed $prev_value Optional. If specified, only update existing metadata entries
997
- * with the specified value. Otherwise, update all entries.
 
 
998
  * @return bool|int Returns false on failure. On successful update of existing
999
- * metadata, returns true. On successful creation of new metadata,
1000
- * returns the integer ID of the new metadata row.
1001
  */
1002
  function bp_activity_update_meta( $activity_id, $meta_key, $meta_value, $prev_value = '' ) {
1003
  add_filter( 'query', 'bp_filter_metaid_column_name' );
@@ -1010,14 +660,14 @@ function bp_activity_update_meta( $activity_id, $meta_key, $meta_value, $prev_va
1010
  /**
1011
  * Add a piece of activity metadata.
1012
  *
1013
- * @since 2.0.0
1014
  *
1015
- * @param int $activity_id ID of the activity item.
1016
- * @param string $meta_key Metadata key.
1017
- * @param mixed $meta_value Metadata value.
1018
- * @param bool $unique Optional. Whether to enforce a single metadata value for the
1019
- * given key. If true, and the object already has a value for
1020
- * the key, no change will be made. Default: false.
1021
  * @return int|bool The meta ID on successful update, false on failure.
1022
  */
1023
  function bp_activity_add_meta( $activity_id, $meta_key, $meta_value, $unique = false ) {
@@ -1033,7 +683,7 @@ function bp_activity_add_meta( $activity_id, $meta_key, $meta_value, $unique = f
1033
  /**
1034
  * Completely remove a user's activity data.
1035
  *
1036
- * @since 1.5.0
1037
  *
1038
  * @uses is_user_logged_in()
1039
  * @uses bp_activity_delete()
@@ -1042,32 +692,24 @@ function bp_activity_add_meta( $activity_id, $meta_key, $meta_value, $unique = f
1042
  * @uses do_action() To call the 'bp_activity_remove_all_user_data' hook.
1043
  *
1044
  * @param int $user_id ID of the user whose activity is being deleted.
1045
- * @return bool
1046
  */
1047
  function bp_activity_remove_all_user_data( $user_id = 0 ) {
1048
 
1049
- // Do not delete user data unless a logged in user says so.
1050
- if ( empty( $user_id ) || ! is_user_logged_in() ) {
1051
  return false;
1052
- }
1053
 
1054
- // Clear the user's activity from the sitewide stream and clear their activity tables.
1055
  bp_activity_delete( array( 'user_id' => $user_id ) );
1056
 
1057
- // Remove any usermeta.
1058
- bp_delete_user_meta( $user_id, 'bp_latest_update' );
1059
  bp_delete_user_meta( $user_id, 'bp_favorite_activities' );
1060
 
1061
  // Execute additional code
1062
  do_action( 'bp_activity_remove_data', $user_id ); // Deprecated! Do not use!
1063
 
1064
- /**
1065
- * Fires after the removal of all of a user's activity data.
1066
- *
1067
- * @since 1.5.0
1068
- *
1069
- * @param int $user_id ID of the user being deleted.
1070
- */
1071
  do_action( 'bp_activity_remove_all_user_data', $user_id );
1072
  }
1073
  add_action( 'wpmu_delete_user', 'bp_activity_remove_all_user_data' );
@@ -1076,68 +718,52 @@ add_action( 'delete_user', 'bp_activity_remove_all_user_data' );
1076
  /**
1077
  * Mark all of the user's activity as spam.
1078
  *
1079
- * @since 1.6.0
1080
  *
1081
  * @global object $wpdb WordPress database access object.
 
1082
  *
1083
  * @param int $user_id ID of the user whose activity is being spammed.
1084
- * @return bool
1085
  */
1086
  function bp_activity_spam_all_user_data( $user_id = 0 ) {
1087
- global $wpdb;
1088
 
1089
- // Do not delete user data unless a logged in user says so.
1090
- if ( empty( $user_id ) || ! is_user_logged_in() ) {
1091
  return false;
1092
- }
1093
 
1094
  // Get all the user's activities.
1095
- $activities = bp_activity_get( array(
1096
- 'display_comments' => 'stream',
1097
- 'filter' => array( 'user_id' => $user_id ),
1098
- 'show_hidden' => true
1099
- ) );
1100
-
1101
- $bp = buddypress();
1102
 
1103
- // Mark each as spam.
1104
  foreach ( (array) $activities['activities'] as $activity ) {
1105
 
1106
- // Create an activity object.
1107
  $activity_obj = new BP_Activity_Activity;
1108
- foreach ( $activity as $k => $v ) {
1109
  $activity_obj->$k = $v;
1110
- }
1111
 
1112
- // Mark as spam.
1113
  bp_activity_mark_as_spam( $activity_obj );
1114
 
1115
  /*
1116
  * If Akismet is present, update the activity history meta.
1117
  *
1118
  * This is usually taken care of when BP_Activity_Activity::save() happens, but
1119
- * as we're going to be updating all the activity statuses directly, for efficiency,
1120
  * we need to update manually.
1121
  */
1122
- if ( ! empty( $bp->activity->akismet ) ) {
1123
  $bp->activity->akismet->update_activity_spam_meta( $activity_obj );
1124
- }
1125
 
1126
- // Tidy up.
1127
  unset( $activity_obj );
1128
  }
1129
 
1130
- // Mark all of this user's activities as spam.
1131
  $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_spam = 1 WHERE user_id = %d", $user_id ) );
1132
 
1133
- /**
1134
- * Fires after all activity data from a user has been marked as spam.
1135
- *
1136
- * @since 1.6.0
1137
- *
1138
- * @param int $user_id ID of the user whose activity is being marked as spam.
1139
- * @param array $activities Array of activity items being marked as spam.
1140
- */
1141
  do_action( 'bp_activity_spam_all_user_data', $user_id, $activities['activities'] );
1142
  }
1143
  add_action( 'bp_make_spam_user', 'bp_activity_spam_all_user_data' );
@@ -1145,105 +771,80 @@ add_action( 'bp_make_spam_user', 'bp_activity_spam_all_user_data' );
1145
  /**
1146
  * Mark all of the user's activity as ham (not spam).
1147
  *
1148
- * @since 1.6.0
1149
  *
1150
  * @global object $wpdb WordPress database access object.
 
1151
  *
1152
  * @param int $user_id ID of the user whose activity is being hammed.
1153
- * @return bool
1154
  */
1155
  function bp_activity_ham_all_user_data( $user_id = 0 ) {
1156
- global $wpdb;
1157
 
1158
- // Do not delete user data unless a logged in user says so.
1159
- if ( empty( $user_id ) || ! is_user_logged_in() ) {
1160
  return false;
1161
- }
1162
 
1163
  // Get all the user's activities.
1164
- $activities = bp_activity_get( array(
1165
- 'display_comments' => 'stream',
1166
- 'filter' => array( 'user_id' => $user_id ),
1167
- 'show_hidden' => true,
1168
- 'spam' => 'all'
1169
- ) );
1170
 
1171
- $bp = buddypress();
1172
-
1173
- // Mark each as not spam.
1174
  foreach ( (array) $activities['activities'] as $activity ) {
1175
 
1176
- // Create an activity object.
1177
  $activity_obj = new BP_Activity_Activity;
1178
- foreach ( $activity as $k => $v ) {
1179
  $activity_obj->$k = $v;
1180
- }
1181
 
1182
- // Mark as not spam.
1183
  bp_activity_mark_as_ham( $activity_obj );
1184
 
1185
  /*
1186
  * If Akismet is present, update the activity history meta.
1187
  *
1188
  * This is usually taken care of when BP_Activity_Activity::save() happens, but
1189
- * as we're going to be updating all the activity statuses directly, for efficiency,
1190
  * we need to update manually.
1191
  */
1192
- if ( ! empty( $bp->activity->akismet ) ) {
1193
  $bp->activity->akismet->update_activity_ham_meta( $activity_obj );
1194
- }
1195
 
1196
- // Tidy up.
1197
  unset( $activity_obj );
1198
  }
1199
 
1200
- // Mark all of this user's activities as not spam.
1201
  $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_spam = 0 WHERE user_id = %d", $user_id ) );
1202
 
1203
- /**
1204
- * Fires after all activity data from a user has been marked as ham.
1205
- *
1206
- * @since 1.6.0
1207
- *
1208
- * @param int $user_id ID of the user whose activity is being marked as ham.
1209
- * @param array $activities Array of activity items being marked as ham.
1210
- */
1211
  do_action( 'bp_activity_ham_all_user_data', $user_id, $activities['activities'] );
1212
  }
1213
  add_action( 'bp_make_ham_user', 'bp_activity_ham_all_user_data' );
1214
 
1215
  /**
1216
- * Register the activity stream actions for updates.
1217
  *
1218
- * @since 1.6.0
 
 
1219
  */
1220
  function bp_activity_register_activity_actions() {
1221
- $bp = buddypress();
1222
 
1223
  bp_activity_set_action(
1224
  $bp->activity->id,
1225
  'activity_update',
1226
  __( 'Posted a status update', 'buddypress' ),
1227
- 'bp_activity_format_activity_action_activity_update',
1228
- __( 'Updates', 'buddypress' ),
1229
- array( 'activity', 'group', 'member', 'member_groups' )
1230
  );
1231
 
1232
  bp_activity_set_action(
1233
  $bp->activity->id,
1234
  'activity_comment',
1235
  __( 'Replied to a status update', 'buddypress' ),
1236
- 'bp_activity_format_activity_action_activity_comment',
1237
- __( 'Activity Comments', 'buddypress' )
1238
  );
1239
 
1240
- /**
1241
- * Fires at the end of the activity actions registration.
1242
- *
1243
- * Allows plugin authors to add their own activity actions alongside the core actions.
1244
- *
1245
- * @since 1.6.0
1246
- */
1247
  do_action( 'bp_activity_register_activity_actions' );
1248
 
1249
  // Backpat. Don't use this.
@@ -1256,36 +857,27 @@ add_action( 'bp_register_activity_actions', 'bp_activity_register_activity_actio
1256
  *
1257
  * @param object $activity Activity data object.
1258
  * @return string|bool Returns false if no callback is found, otherwise returns
1259
- * the formatted action string.
1260
  */
1261
  function bp_activity_generate_action_string( $activity ) {
1262
-
1263
- // Check for valid input.
1264
  if ( empty( $activity->component ) || empty( $activity->type ) ) {
1265
  return false;
1266
  }
1267
 
1268
- // Check for registered format callback.
1269
- $actions = bp_activity_get_actions();
1270
- if ( empty( $actions->{$activity->component}->{$activity->type}['format_callback'] ) ) {
1271
  return false;
1272
  }
1273
 
1274
- // We apply the format_callback as a filter.
1275
- add_filter( 'bp_activity_generate_action_string', $actions->{$activity->component}->{$activity->type}['format_callback'], 10, 2 );
1276
 
1277
- /**
1278
- * Filters the string for the activity action being returned.
1279
- *
1280
- * @since 2.0.0
1281
- *
1282
- * @param BP_Activity_Activity $action Action string being requested.
1283
- * @param BP_Activity_Activity $activity Activity item object.
1284
- */
1285
  $action = apply_filters( 'bp_activity_generate_action_string', $activity->action, $activity );
1286
 
1287
- // Remove the filter for future activity items.
1288
- remove_filter( 'bp_activity_generate_action_string', $actions->{$activity->component}->{$activity->type}['format_callback'], 10, 2 );
1289
 
1290
  return $action;
1291
  }
@@ -1293,107 +885,32 @@ function bp_activity_generate_action_string( $activity ) {
1293
  /**
1294
  * Format 'activity_update' activity actions.
1295
  *
1296
- * @since 2.0.0
1297
  *
1298
- * @param string $action Static activity action.
1299
  * @param object $activity Activity data object.
1300
- * @return string $action
1301
  */
1302
  function bp_activity_format_activity_action_activity_update( $action, $activity ) {
1303
  $action = sprintf( __( '%s posted an update', 'buddypress' ), bp_core_get_userlink( $activity->user_id ) );
1304
-
1305
- /**
1306
- * Filters the formatted activity action update string.
1307
- *
1308
- * @since 1.2.0
1309
- *
1310
- * @param string $action Activity action string value.
1311
- * @param BP_Activity_Activity $activity Activity item object.
1312
- */
1313
  return apply_filters( 'bp_activity_new_update_action', $action, $activity );
1314
  }
1315
 
1316
  /**
1317
  * Format 'activity_comment' activity actions.
1318
  *
1319
- * @since 2.0.0
1320
  *
1321
- * @param string $action Static activity action.
1322
  * @param object $activity Activity data object.
1323
- * @return string $action
1324
  */
1325
  function bp_activity_format_activity_action_activity_comment( $action, $activity ) {
1326
  $action = sprintf( __( '%s posted a new activity comment', 'buddypress' ), bp_core_get_userlink( $activity->user_id ) );
1327
-
1328
- /**
1329
- * Filters the formatted activity action comment string.
1330
- *
1331
- * @since 1.2.0
1332
- *
1333
- * @param string $action Activity action string value.
1334
- * @param BP_Activity_Activity $activity Activity item object.
1335
- */
1336
  return apply_filters( 'bp_activity_comment_action', $action, $activity );
1337
  }
1338
 
1339
- /**
1340
- * Format activity action strings for custom post types.
1341
- *
1342
- * @since 2.2.0
1343
- *
1344
- * @param string $action Static activity action.
1345
- * @param object $activity Activity data object.
1346
- * @return string $action
1347
- */
1348
- function bp_activity_format_activity_action_custom_post_type_post( $action, $activity ) {
1349
- $bp = buddypress();
1350
-
1351
- // Fetch all the tracked post types once.
1352
- if ( empty( $bp->activity->track ) ) {
1353
- $bp->activity->track = bp_activity_get_post_types_tracking_args();
1354
- }
1355
-
1356
- if ( empty( $activity->type ) || empty( $bp->activity->track[ $activity->type ] ) ) {
1357
- return $action;
1358
- }
1359
-
1360
- $user_link = bp_core_get_userlink( $activity->user_id );
1361
- $blog_url = get_home_url( $activity->item_id );
1362
-
1363
- if ( empty( $activity->post_url ) ) {
1364
- $post_url = add_query_arg( 'p', $activity->secondary_item_id, trailingslashit( $blog_url ) );
1365
- } else {
1366
- $post_url = $activity->post_url;
1367
- }
1368
-
1369
- if ( is_multisite() ) {
1370
- $blog_link = '<a href="' . esc_url( $blog_url ) . '">' . get_blog_option( $activity->item_id, 'blogname' ) . '</a>';
1371
-
1372
- if ( ! empty( $bp->activity->track[ $activity->type ]->new_post_type_action_ms ) ) {
1373
- $action = sprintf( $bp->activity->track[ $activity->type ]->new_post_type_action_ms, $user_link, $post_url, $blog_link );
1374
- } else {
1375
- $action = sprintf( _x( '%1$s wrote a new <a href="%2$s">item</a>, on the site %3$s', 'Activity Custom Post Type post action', 'buddypress' ), $user_link, esc_url( $post_url ), $blog_link );
1376
- }
1377
- } else {
1378
- if ( ! empty( $bp->activity->track[ $activity->type ]->new_post_type_action ) ) {
1379
- $action = sprintf( $bp->activity->track[ $activity->type ]->new_post_type_action, $user_link, $post_url );
1380
- } else {
1381
- $action = sprintf( _x( '%1$s wrote a new <a href="%2$s">item</a>', 'Activity Custom Post Type post action', 'buddypress' ), $user_link, esc_url( $post_url ) );
1382
- }
1383
- }
1384
-
1385
- /**
1386
- * Filters the formatted custom post type activity post action string.
1387
- *
1388
- * @since 2.2.0
1389
- *
1390
- * @param string $action Activity action string value.
1391
- * @param BP_Activity_Activity $activity Activity item object.
1392
- */
1393
- return apply_filters( 'bp_activity_custom_post_type_post_action', $action, $activity );
1394
- }
1395
-
1396
- /*
1397
  * Business functions are where all the magic happens in BuddyPress. They will
1398
  * handle the actual saving or manipulation of information. Usually they will
1399
  * hand off to a database class for data access, then return
@@ -1403,14 +920,13 @@ function bp_activity_format_activity_action_custom_post_type_post( $action, $act
1403
  /**
1404
  * Retrieve an activity or activities.
1405
  *
1406
- * The bp_activity_get() function shares all arguments with BP_Activity_Activity::get().
1407
- * The following is a list of bp_activity_get() parameters that have different
1408
  * default values from BP_Activity_Activity::get() (value in parentheses is
1409
  * the default for the bp_activity_get()).
1410
  * - 'per_page' (false)
1411
  *
1412
- * @since 1.2.0
1413
- * @since 2.4.0 Introduced the `$fields` parameter.
1414
  *
1415
  * @see BP_Activity_Activity::get() For more information on accepted arguments
1416
  * and the format of the returned value.
@@ -1420,14 +936,12 @@ function bp_activity_format_activity_action_custom_post_type_post( $action, $act
1420
  * @uses BP_Activity_Activity::get() {@link BP_Activity_Activity}
1421
  * @uses apply_filters_ref_array() To call the 'bp_activity_get' hook.
1422
  *
1423
- * @param array|string $args See BP_Activity_Activity::get() for description.
1424
  * @return array $activity See BP_Activity_Activity::get() for description.
1425
  */
1426
  function bp_activity_get( $args = '' ) {
1427
-
1428
- $r = bp_parse_args( $args, array(
1429
  'max' => false, // Maximum number of results to return
1430
- 'fields' => 'all',
1431
  'page' => 1, // page 1 without a per_page will result in no pagination.
1432
  'per_page' => false, // results per page
1433
  'sort' => 'DESC', // sort ASC or DESC
@@ -1435,254 +949,211 @@ function bp_activity_get( $args = '' ) {
1435
 
1436
  'search_terms' => false, // Pass search terms as a string
1437
  'meta_query' => false, // Filter by activity meta. See WP_Meta_Query for format
1438
- 'date_query' => false, // Filter by date. See first parameter of WP_Date_Query for format
1439
- 'filter_query' => false,
1440
  'show_hidden' => false, // Show activity items that are hidden site-wide?
1441
- 'exclude' => false, // Comma-separated list of activity IDs to exclude.
1442
- 'in' => false, // Comma-separated list or array of activity IDs to which you
1443
- // want to limit the query.
1444
  'spam' => 'ham_only', // 'ham_only' (default), 'spam_only' or 'all'.
1445
  'update_meta_cache' => true,
1446
- 'count_total' => false,
1447
- 'scope' => false,
1448
 
1449
  /**
1450
  * Pass filters as an array -- all filter items can be multiple values comma separated:
1451
  * array(
1452
- * 'user_id' => false, // User ID to filter on.
1453
- * 'object' => false, // Object to filter on e.g. groups, profile, status, friends.
1454
- * 'action' => false, // Action to filter on e.g. activity_update, profile_updated.
1455
- * 'primary_id' => false, // Object ID to filter on e.g. a group_id or forum_id or blog_id etc.
1456
- * 'secondary_id' => false, // Secondary object ID to filter on e.g. a post_id.
1457
  * );
1458
  */
1459
  'filter' => array()
1460
- ) );
 
 
1461
 
1462
  // Attempt to return a cached copy of the first page of sitewide activity.
1463
- if ( ( 1 === (int) $r['page'] ) && empty( $r['max'] ) && ( 'all' === $r['fields'] ) && empty( $r['search_terms'] ) && empty( $r['meta_query'] ) && empty( $r['date_query'] ) && empty( $r['filter_query'] ) && empty( $r['filter'] ) && empty( $r['scope'] )&& empty( $r['exclude'] ) && empty( $r['in'] ) && ( 'DESC' === $r['sort'] ) && empty( $r['exclude'] ) && ( 'ham_only' === $r['spam'] ) ) {
1464
-
1465
- $activity = wp_cache_get( 'bp_activity_sitewide_front', 'bp' );
1466
- if ( false === $activity ) {
1467
-
1468
- $activity = BP_Activity_Activity::get( array(
1469
- 'page' => $r['page'],
1470
- 'per_page' => $r['per_page'],
1471
- 'max' => $r['max'],
1472
- 'fields' => $r['fields'],
1473
- 'sort' => $r['sort'],
1474
- 'search_terms' => $r['search_terms'],
1475
- 'meta_query' => $r['meta_query'],
1476
- 'date_query' => $r['date_query'],
1477
- 'filter_query' => $r['filter_query'],
1478
- 'filter' => $r['filter'],
1479
- 'scope' => $r['scope'],
1480
- 'display_comments' => $r['display_comments'],
1481
- 'show_hidden' => $r['show_hidden'],
1482
- 'spam' => $r['spam'],
1483
- 'update_meta_cache' => $r['update_meta_cache'],
1484
- 'count_total' => $r['count_total'],
1485
- ) );
1486
-
1487
  wp_cache_set( 'bp_activity_sitewide_front', $activity, 'bp' );
1488
  }
1489
 
1490
  } else {
1491
- $activity = BP_Activity_Activity::get( array(
1492
- 'page' => $r['page'],
1493
- 'per_page' => $r['per_page'],
1494
- 'max' => $r['max'],
1495
- 'sort' => $r['sort'],
1496
- 'search_terms' => $r['search_terms'],
1497
- 'meta_query' => $r['meta_query'],
1498
- 'date_query' => $r['date_query'],
1499
- 'filter_query' => $r['filter_query'],
1500
- 'filter' => $r['filter'],
1501
- 'scope' => $r['scope'],
1502
- 'display_comments' => $r['display_comments'],
1503
- 'show_hidden' => $r['show_hidden'],
1504
- 'exclude' => $r['exclude'],
1505
- 'in' => $r['in'],
1506
- 'spam' => $r['spam'],
1507
- 'count_total' => $r['count_total'],
1508
- ) );
1509
  }
1510
 
1511
- /**
1512
- * Filters the requested activity item(s).
1513
- *
1514
- * @since 1.2.0
1515
- *
1516
- * @param BP_Activity_Activity $activity Requested activity object.
1517
- * @param array $r Arguments used for the activity query.
1518
- */
1519
  return apply_filters_ref_array( 'bp_activity_get', array( &$activity, &$r ) );
1520
  }
1521
 
1522
  /**
1523
  * Fetch specific activity items.
1524
  *
1525
- * @since 1.2.0
1526
  *
1527
- * @see BP_Activity_Activity::get() For more information on accepted arguments.
1528
  * @uses wp_parse_args()
1529
- * @uses apply_filters() To call the 'bp_activity_get_specific' hook.
1530
  * @uses BP_Activity_Activity::get() {@link BP_Activity_Activity}
1531
  *
1532
- * @param array|string $args {
1533
  * All arguments and defaults are shared with BP_Activity_Activity::get(),
1534
  * except for the following:
1535
  * @type string|int|array Single activity ID, comma-separated list of IDs,
1536
- * or array of IDs.
1537
  * }
1538
  * @return array $activity See BP_Activity_Activity::get() for description.
1539
  */
1540
  function bp_activity_get_specific( $args = '' ) {
1541
-
1542
- $r = bp_parse_args( $args, array(
1543
- 'activity_ids' => false, // A single activity_id or array of IDs.
1544
- 'display_comments' => false, // True or false to display threaded comments for these specific activity items.
1545
- 'max' => false, // Maximum number of results to return.
1546
- 'page' => 1, // Page 1 without a per_page will result in no pagination.
1547
- 'per_page' => false, // Results per page.
1548
- 'show_hidden' => true, // When fetching specific items, show all.
1549
- 'sort' => 'DESC', // Sort ASC or DESC
1550
- 'spam' => 'ham_only', // Retrieve items marked as spam.
1551
  'update_meta_cache' => true,
1552
- ) );
 
 
1553
 
1554
  $get_args = array(
1555
- 'display_comments' => $r['display_comments'],
1556
- 'in' => $r['activity_ids'],
1557
- 'max' => $r['max'],
1558
- 'page' => $r['page'],
1559
- 'per_page' => $r['per_page'],
1560
- 'show_hidden' => $r['show_hidden'],
1561
- 'sort' => $r['sort'],
1562
- 'spam' => $r['spam'],
1563
- 'update_meta_cache' => $r['update_meta_cache'],
1564
  );
1565
-
1566
- /**
1567
- * Filters the requested specific activity item.
1568
- *
1569
- * @since 1.2.0
1570
- *
1571
- * @param BP_Activity_Activity $activity Requested activity object.
1572
- * @param array $args Original passed in arguments.
1573
- * @param array $get_args Constructed arguments used with request.
1574
- */
1575
  return apply_filters( 'bp_activity_get_specific', BP_Activity_Activity::get( $get_args ), $args, $get_args );
1576
  }
1577
 
1578
  /**
1579
  * Add an activity item.
1580
  *
1581
- * @since 1.1.0
1582
  *
1583
  * @uses wp_parse_args()
1584
  * @uses BP_Activity_Activity::save() {@link BP_Activity_Activity}
1585
  * @uses BP_Activity_Activity::rebuild_activity_comment_tree() {@link BP_Activity_Activity}
1586
  * @uses wp_cache_delete()
1587
- * @uses do_action() To call the 'bp_activity_add' hook.
1588
  *
1589
- * @param array|string $args {
1590
  * An array of arguments.
1591
- * @type int|bool $id Pass an activity ID to update an existing item, or
1592
- * false to create a new item. Default: false.
1593
- * @type string $action Optional. The activity action/description, typically
1594
- * something like "Joe posted an update". Values passed to this param
1595
- * will be stored in the database and used as a fallback for when the
1596
- * activity item's format_callback cannot be found (eg, when the
1597
- * component is disabled). As long as you have registered a
1598
- * format_callback for your $type, it is unnecessary to include this
1599
- * argument - BP will generate it automatically.
1600
- * See {@link bp_activity_set_action()}.
1601
- * @type string $content Optional. The content of the activity item.
1602
- * @type string $component The unique name of the component associated with
1603
- * the activity item - 'groups', 'profile', etc.
1604
- * @type string $type The specific activity type, used for directory
1605
- * filtering. 'new_blog_post', 'activity_update', etc.
1606
- * @type string $primary_link Optional. The URL for this item, as used in
1607
- * RSS feeds. Defaults to the URL for this activity
1608
- * item's permalink page.
1609
- * @type int|bool $user_id Optional. The ID of the user associated with the activity
1610
- * item. May be set to false or 0 if the item is not related
1611
- * to any user. Default: the ID of the currently logged-in user.
1612
- * @type int $item_id Optional. The ID of the associated item.
1613
- * @type int $secondary_item_id Optional. The ID of a secondary associated item.
1614
- * @type string $date_recorded Optional. The GMT time, in Y-m-d h:i:s format, when
1615
- * the item was recorded. Defaults to the current time.
1616
- * @type bool $hide_sitewide Should the item be hidden on sitewide streams?
1617
- * Default: false.
1618
- * @type bool $is_spam Should the item be marked as spam? Default: false.
1619
  * }
1620
  * @return int|bool The ID of the activity on success. False on error.
1621
  */
1622
  function bp_activity_add( $args = '' ) {
1623
 
1624
- $r = bp_parse_args( $args, array(
1625
- 'id' => false, // Pass an existing activity ID to update an existing entry.
1626
- 'action' => '', // The activity action - e.g. "Jon Doe posted an update"
1627
- 'content' => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!"
1628
- 'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent.
1629
- 'type' => false, // The activity type e.g. activity_update, profile_updated.
1630
- 'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink).
1631
- 'user_id' => bp_loggedin_user_id(), // Optional: The user to record the activity for, can be false if this activity is not for a user.
1632
- 'item_id' => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id.
1633
- 'secondary_item_id' => false, // Optional: A second ID used to further filter e.g. a comment_id.
1634
- 'recorded_time' => bp_core_current_time(), // The GMT time that this activity was recorded.
1635
- 'hide_sitewide' => false, // Should this be hidden on the sitewide activity stream?
1636
- 'is_spam' => false, // Is this activity item to be marked as spam?
1637
- ), 'activity_add' );
1638
-
1639
- // Make sure we are backwards compatible.
1640
- if ( empty( $r['component'] ) && !empty( $r['component_name'] ) ) {
1641
- $r['component'] = $r['component_name'];
1642
- }
1643
 
1644
- if ( empty( $r['type'] ) && !empty( $r['component_action'] ) ) {
1645
- $r['type'] = $r['component_action'];
1646
- }
1647
 
1648
- // Setup activity to be added.
1649
- $activity = new BP_Activity_Activity( $r['id'] );
1650
- $activity->user_id = $r['user_id'];
1651
- $activity->component = $r['component'];
1652
- $activity->type = $r['type'];
1653
- $activity->content = $r['content'];
1654
- $activity->primary_link = $r['primary_link'];
1655
- $activity->item_id = $r['item_id'];
1656
- $activity->secondary_item_id = $r['secondary_item_id'];
1657
- $activity->date_recorded = $r['recorded_time'];
1658
- $activity->hide_sitewide = $r['hide_sitewide'];
1659
- $activity->is_spam = $r['is_spam'];
1660
- $activity->action = ! empty( $r['action'] )
1661
- ? $r['action']
1662
- : bp_activity_generate_action_string( $activity );
1663
-
1664
- if ( ! $activity->save() ) {
1665
- return false;
1666
- }
1667
 
1668
- // If this is an activity comment, rebuild the tree.
1669
- if ( 'activity_comment' === $activity->type ) {
1670
- // Also clear the comment cache for the parent activity ID.
1671
- wp_cache_delete( $activity->item_id, 'bp_activity_comments' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1672
 
 
 
1673
  BP_Activity_Activity::rebuild_activity_comment_tree( $activity->item_id );
1674
- }
1675
 
1676
  wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
1677
-
1678
- /**
1679
- * Fires at the end of the execution of adding a new activity item, before returning the new activity item ID.
1680
- *
1681
- * @since 1.1.0
1682
- *
1683
- * @param array $r Array of parsed arguments for the activity item being added.
1684
- */
1685
- do_action( 'bp_activity_add', $r );
1686
 
1687
  return $activity->id;
1688
  }
@@ -1690,8 +1161,9 @@ function bp_activity_add( $args = '' ) {
1690
  /**
1691
  * Post an activity update.
1692
  *
1693
- * @since 1.2.0
1694
  *
 
1695
  * @uses wp_parse_args()
1696
  * @uses bp_is_user_inactive()
1697
  * @uses bp_core_get_userlink()
@@ -1703,440 +1175,122 @@ function bp_activity_add( $args = '' ) {
1703
  * @uses wp_filter_kses()
1704
  * @uses do_action() To call the 'bp_activity_posted_update' hook.
1705
  *
1706
- * @param array|string $args {
1707
  * @type string $content The content of the activity update.
1708
- * @type int $user_id Optional. Defaults to the logged-in user.
1709
  * }
1710
- * @return int $activity_id The activity id.
1711
  */
1712
  function bp_activity_post_update( $args = '' ) {
 
1713
 
1714
- $r = wp_parse_args( $args, array(
1715
  'content' => false,
1716
  'user_id' => bp_loggedin_user_id()
1717
- ) );
 
 
1718
 
1719
- if ( empty( $r['content'] ) || !strlen( trim( $r['content'] ) ) ) {
1720
  return false;
1721
- }
1722
 
1723
- if ( bp_is_user_inactive( $r['user_id'] ) ) {
1724
  return false;
1725
- }
1726
-
1727
- // Record this on the user's profile.
1728
- $activity_content = $r['content'];
1729
- $primary_link = bp_core_get_userlink( $r['user_id'], false, true );
1730
-
1731
- /**
1732
- * Filters the new activity content for current activity item.
1733
- *
1734
- * @since 1.2.0
1735
- *
1736
- * @param string $activity_content Activity content posted by user.
1737
- */
1738
- $add_content = apply_filters( 'bp_activity_new_update_content', $activity_content );
1739
 
1740
- /**
1741
- * Filters the activity primary link for current activity item.
1742
- *
1743
- * @since 1.2.0
1744
- *
1745
- * @param string $primary_link Link to the profile for the user who posted the activity.
1746
- */
1747
- $add_primary_link = apply_filters( 'bp_activity_new_update_primary_link', $primary_link );
1748
 
1749
- // Now write the values.
1750
  $activity_id = bp_activity_add( array(
1751
- 'user_id' => $r['user_id'],
1752
- 'content' => $add_content,
1753
- 'primary_link' => $add_primary_link,
1754
- 'component' => buddypress()->activity->id,
1755
  'type' => 'activity_update',
1756
  ) );
1757
 
1758
- /**
1759
- * Filters the latest update content for the activity item.
1760
- *
1761
- * @since 1.6.0
1762
- *
1763
- * @param string $r Content of the activity update.
1764
- * @param string $activity_content Content of the activity update.
1765
- */
1766
- $activity_content = apply_filters( 'bp_activity_latest_update_content', $r['content'], $activity_content );
1767
 
1768
  // Add this update to the "latest update" usermeta so it can be fetched anywhere.
1769
- bp_update_user_meta( bp_loggedin_user_id(), 'bp_latest_update', array(
1770
- 'id' => $activity_id,
1771
- 'content' => $activity_content
1772
- ) );
1773
 
1774
- /**
1775
- * Fires at the end of an activity post update, before returning the updated activity item ID.
1776
- *
1777
- * @since 1.2.0
1778
- *
1779
- * @param string $content Content of the activity post update.
1780
- * @param int $user_id ID of the user posting the activity update.
1781
- * @param int $activity_id ID of the activity item being updated.
1782
- */
1783
- do_action( 'bp_activity_posted_update', $r['content'], $r['user_id'], $activity_id );
1784
 
1785
  return $activity_id;
1786
  }
1787
 
1788
- /**
1789
- * Create an activity item for a newly published post type post.
1790
- *
1791
- * @since 2.2.0
1792
- *
1793
- * @param int $post_id ID of the new post.
1794
- * @param WP_Post $post Post object.
1795
- * @param int $user_id ID of the post author.
1796
- * @return int|bool The ID of the activity on success. False on error.
1797
- */
1798
- function bp_activity_post_type_publish( $post_id = 0, $post = null, $user_id = 0 ) {
1799
-
1800
- if ( ! is_a( $post, 'WP_Post' ) ) {
1801
- return;
1802
- }
1803
-
1804
- // Get the post type tracking args.
1805
- $activity_post_object = bp_activity_get_post_type_tracking_args( $post->post_type );
1806
-
1807
- if ( 'publish' != $post->post_status || ! empty( $post->post_password ) || empty( $activity_post_object->action_id ) ) {
1808
- return;
1809
- }
1810
-
1811
- if ( empty( $post_id ) ) {
1812
- $post_id = $post->ID;
1813
- }
1814
-
1815
- $blog_id = get_current_blog_id();
1816
-
1817
- if ( empty( $user_id ) ) {
1818
- $user_id = (int) $post->post_author;
1819
- }
1820
-
1821
- // Bail if an activity item already exists for this post.
1822
- $existing = bp_activity_get( array(
1823
- 'filter' => array(
1824
- 'action' => $activity_post_object->action_id,
1825
- 'primary_id' => $blog_id,
1826
- 'secondary_id' => $post_id,
1827
- )
1828
- ) );
1829
-
1830
- if ( ! empty( $existing['activities'] ) ) {
1831
- return;
1832
- }
1833
-
1834
- /**
1835
- * Filters whether or not to post the activity.
1836
- *
1837
- * This is a variable filter, dependent on the post type,
1838
- * that lets components or plugins bail early if needed.
1839
- *
1840
- * @since 2.2.0
1841
- *
1842
- * @param bool $value Whether or not to continue.
1843
- * @param int $blog_id ID of the current site.
1844
- * @param int $post_id ID of the current post being published.
1845
- * @param int $user_id ID of the current user or post author.
1846
- */
1847
- if ( false === apply_filters( "bp_activity_{$post->post_type}_pre_publish", true, $blog_id, $post_id, $user_id ) ) {
1848
- return;
1849
- }
1850
-
1851
- // Record this in activity streams.
1852
- $blog_url = get_home_url( $blog_id );
1853
- $post_url = add_query_arg(
1854
- 'p',
1855
- $post_id,
1856
- trailingslashit( $blog_url )
1857
- );
1858
-
1859
- // Backward compatibility filters for the 'blogs' component.
1860
- if ( 'blogs' == $activity_post_object->component_id ) {
1861
- $activity_content = apply_filters( 'bp_blogs_activity_new_post_content', $post->post_content, $post, $post_url, $post->post_type );
1862
- $activity_primary_link = apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_url, $post_id, $post->post_type );
1863
- } else {
1864
- $activity_content = $post->post_content;
1865
- $activity_primary_link = $post_url;
1866
- }
1867
-
1868
- $activity_args = array(
1869
- 'user_id' => $user_id,
1870
- 'content' => $activity_content,
1871
- 'primary_link' => $activity_primary_link,
1872
- 'component' => $activity_post_object->component_id,
1873
- 'type' => $activity_post_object->action_id,
1874
- 'item_id' => $blog_id,
1875
- 'secondary_item_id' => $post_id,
1876
- 'recorded_time' => $post->post_date_gmt,
1877
- );
1878
-
1879
- if ( ! empty( $activity_args['content'] ) ) {
1880
- // Create the excerpt.
1881
- $activity_summary = bp_activity_create_summary( $activity_args['content'], $activity_args );
1882
-
1883
- // Backward compatibility filter for blog posts.
1884
- if ( 'blogs' == $activity_post_object->component_id ) {
1885
- $activity_args['content'] = apply_filters( 'bp_blogs_record_activity_content', $activity_summary, $activity_args['content'], $activity_args, $post->post_type );
1886
- } else {
1887
- $activity_args['content'] = $activity_summary;
1888
- }
1889
- }
1890
-
1891
- // Set up the action by using the format functions.
1892
- $action_args = array_merge( $activity_args, array(
1893
- 'post_title' => $post->post_title,
1894
- 'post_url' => $post_url,
1895
- ) );
1896
-
1897
- $activity_args['action'] = call_user_func_array( $activity_post_object->format_callback, array( '', (object) $action_args ) );
1898
-
1899
- // Make sure the action is set.
1900
- if ( empty( $activity_args['action'] ) ) {
1901
- return;
1902
- } else {
1903
- // Backward compatibility filter for the blogs component.
1904
- if ( 'blogs' == $activity_post_object->component_id ) {
1905
- $activity_args['action'] = apply_filters( 'bp_blogs_record_activity_action', $activity_args['action'] );
1906
- }
1907
- }
1908
-
1909
- $activity_id = bp_activity_add( $activity_args );
1910
-
1911
- /**
1912
- * Fires after the publishing of an activity item for a newly published post type post.
1913
- *
1914
- * @since 2.2.0
1915
- *
1916
- * @param int $activity_id ID of the newly published activity item.
1917
- * @param WP_Post $post Post object.
1918
- * @param array $activity_args Array of activity arguments.
1919
- */
1920
- do_action( 'bp_activity_post_type_published', $activity_id, $post, $activity_args );
1921
-
1922
- return $activity_id;
1923
- }
1924
-
1925
- /**
1926
- * Update the activity item for a custom post type entry.
1927
- *
1928
- * @since 2.2.0
1929
- *
1930
- * @param WP_Post $post Post item.
1931
- * @return bool True on success, false on failure.
1932
- */
1933
- function bp_activity_post_type_update( $post = null ) {
1934
-
1935
- if ( ! is_a( $post, 'WP_Post' ) ) {
1936
- return;
1937
- }
1938
-
1939
- // Get the post type tracking args.
1940
- $activity_post_object = bp_activity_get_post_type_tracking_args( $post->post_type );
1941
-
1942
- if ( empty( $activity_post_object->action_id ) ) {
1943
- return;
1944
- }
1945
-
1946
- $activity_id = bp_activity_get_activity_id( array(
1947
- 'component' => $activity_post_object->component_id,
1948
- 'item_id' => get_current_blog_id(),
1949
- 'secondary_item_id' => $post->ID,
1950
- 'type' => $activity_post_object->action_id,
1951
- ) );
1952
-
1953
- // Activity ID doesn't exist, so stop!
1954
- if ( empty( $activity_id ) ) {
1955
- return;
1956
- }
1957
-
1958
- // Delete the activity if the post was updated with a password.
1959
- if ( ! empty( $post->post_password ) ) {
1960
- bp_activity_delete( array( 'id' => $activity_id ) );
1961
- }
1962
-
1963
- // Update the activity entry.
1964
- $activity = new BP_Activity_Activity( $activity_id );
1965
-
1966
- if ( ! empty( $post->post_content ) ) {
1967
- $activity_summary = bp_activity_create_summary( $post->post_content, (array) $activity );
1968
-
1969
- // Backward compatibility filter for the blogs component.
1970
- if ( 'blogs' == $activity_post_object->component_id ) {
1971
- $activity->content = apply_filters( 'bp_blogs_record_activity_content', $activity_summary, $post->post_content, (array) $activity, $post->post_type );
1972
- } else {
1973
- $activity->content = $activity_summary;
1974
- }
1975
- }
1976
-
1977
- // Save the updated activity.
1978
- $updated = $activity->save();
1979
-
1980
- /**
1981
- * Fires after the updating of an activity item for a custom post type entry.
1982
- *
1983
- * @since 2.2.0
1984
- *
1985
- * @param WP_Post $post Post object.
1986
- * @param BP_Activity_Activity $activity Activity object.
1987
- */
1988
- do_action( 'bp_activity_post_type_updated', $post, $activity );
1989
-
1990
- return $updated;
1991
- }
1992
-
1993
- /**
1994
- * Unpublish an activity for the custom post type.
1995
- *
1996
- * @since 2.2.0
1997
- *
1998
- * @param int $post_id ID of the post being unpublished.
1999
- * @param WP_Post $post Post object.
2000
- * @return bool True on success, false on failure.
2001
- */
2002
- function bp_activity_post_type_unpublish( $post_id = 0, $post = null ) {
2003
-
2004
- if ( ! is_a( $post, 'WP_Post' ) ) {
2005
- return;
2006
- }
2007
-
2008
- // Get the post type tracking args.
2009
- $activity_post_object = bp_activity_get_post_type_tracking_args( $post->post_type );
2010
-
2011
- if ( empty( $activity_post_object->action_id ) ) {
2012
- return;
2013
- }
2014
-
2015
- if ( empty( $post_id ) ) {
2016
- $post_id = $post->ID;
2017
- }
2018
-
2019
- $delete_activity_args = array(
2020
- 'item_id' => get_current_blog_id(),
2021
- 'secondary_item_id' => $post_id,
2022
- 'component' => $activity_post_object->component_id,
2023
- 'type' => $activity_post_object->action_id,
2024
- 'user_id' => false,
2025
- );
2026
-
2027
- $deleted = bp_activity_delete_by_item_id( $delete_activity_args );
2028
-
2029
- /**
2030
- * Fires after the unpublishing for the custom post type.
2031
- *
2032
- * @since 2.2.0
2033
- *
2034
- * @param array $delete_activity_args Array of arguments for activity deletion.
2035
- * @param WP_Post $post Post object.
2036
- * @param bool $activity Whether or not the activity was successfully deleted.
2037
- */
2038
- do_action( 'bp_activity_post_type_unpublished', $delete_activity_args, $post, $deleted );
2039
-
2040
- return $deleted;
2041
- }
2042
-
2043
  /**
2044
  * Add an activity comment.
2045
  *
2046
- * @since 1.2.0
2047
  *
 
2048
  * @uses wp_parse_args()
2049
  * @uses bp_activity_add()
2050
  * @uses apply_filters() To call the 'bp_activity_comment_action' hook.
2051
  * @uses apply_filters() To call the 'bp_activity_comment_content' hook.
 
2052
  * @uses wp_cache_delete()
2053
  * @uses do_action() To call the 'bp_activity_comment_posted' hook.
2054
  *
2055
- * @param array|string $args {
2056
- * @type int $id Optional. Pass an ID to update an existing comment.
2057
- * @type string $content The content of the comment.
2058
- * @type int $user_id Optional. The ID of the user making the comment.
2059
- * Defaults to the ID of the logged-in user.
2060
- * @type int $activity_id The ID of the "root" activity item, ie the oldest
2061
- * ancestor of the comment.
2062
- * @type int $parent_id Optional. The ID of the parent activity item, ie the item to
2063
- * which the comment is an immediate reply. If not provided,
2064
- * this value defaults to the $activity_id.
2065
  * }
2066
  * @return int|bool The ID of the comment on success, otherwise false.
2067
  */
2068
  function bp_activity_new_comment( $args = '' ) {
2069
- $bp = buddypress();
2070
- $errors = new WP_Error();
2071
- $feedback = __( 'There was an error posting your reply. Please try again.', 'buddypress' );
2072
 
2073
- if ( empty( $bp->activity->errors ) ) {
2074
- $bp->activity->errors = array();
2075
- }
2076
-
2077
- $r = wp_parse_args( $args, array(
2078
  'id' => false,
2079
  'content' => false,
2080
  'user_id' => bp_loggedin_user_id(),
2081
- 'activity_id' => false, // ID of the root activity item.
2082
- 'parent_id' => false // ID of a parent comment (optional).
2083
  ) );
2084
 
2085
- // Bail if missing necessary data.
2086
- if ( empty( $r['content'] ) || empty( $r['user_id'] ) || empty( $r['activity_id'] ) ) {
2087
- $errors->add( 'missing_data', $feedback );
2088
- $bp->activity->errors['new_comment'] = $errors;
2089
 
 
 
2090
  return false;
2091
  }
2092
 
2093
- // Maybe set current activity ID as the parent.
2094
- if ( empty( $r['parent_id'] ) ) {
2095
- $r['parent_id'] = $r['activity_id'];
2096
  }
2097
 
2098
- $activity_id = $r['activity_id'];
2099
-
2100
- // Get the parent activity.
2101
  $activity = new BP_Activity_Activity( $activity_id );
2102
-
2103
- // Bail if the parent activity does not exist.
2104
- if ( empty( $activity->date_recorded ) ) {
2105
- $errors->add( 'missing_activity', __( 'Sorry, the item you are replying to no longer exists.', 'buddypress' ) );
2106
- $bp->activity->errors['new_comment'] = $errors;
2107
-
2108
- return false;
2109
- }
2110
-
2111
- // Check to see if the parent activity is hidden, and if so, hide this comment publicly.
2112
  $is_hidden = ( (int) $activity->hide_sitewide ) ? 1 : 0;
2113
 
2114
- /**
2115
- * Filters the content of a new comment.
2116
- *
2117
- * @since 1.2.0
2118
- *
2119
- * @param string $r Content for the newly posted comment.
2120
- */
2121
- $comment_content = apply_filters( 'bp_activity_comment_content', $r['content'] );
2122
-
2123
- // Insert the activity comment.
2124
  $comment_id = bp_activity_add( array(
2125
- 'id' => $r['id'],
2126
- 'content' => $comment_content,
2127
  'component' => buddypress()->activity->id,
2128
  'type' => 'activity_comment',
2129
- 'user_id' => $r['user_id'],
2130
  'item_id' => $activity_id,
2131
- 'secondary_item_id' => $r['parent_id'],
2132
  'hide_sitewide' => $is_hidden
2133
  ) );
2134
 
2135
- // Comment caches are stored only with the top-level item.
2136
  wp_cache_delete( $activity_id, 'bp_activity_comments' );
2137
 
2138
- // Walk the tree to clear caches for all parent items.
2139
- $clear_id = $r['parent_id'];
2140
  while ( $clear_id != $activity_id ) {
2141
  $clear_object = new BP_Activity_Activity( $clear_id );
2142
  wp_cache_delete( $clear_id, 'bp_activity' );
@@ -2144,21 +1298,7 @@ function bp_activity_new_comment( $args = '' ) {
2144
  }
2145
  wp_cache_delete( $activity_id, 'bp_activity' );
2146
 
2147
- /**
2148
- * Fires near the end of an activity comment posting, before the returning of the comment ID.
2149
- *
2150
- * @since 1.2.0
2151
- *
2152
- * @param int $comment_id ID of the newly posted activity comment.
2153
- * @param array $r Array of parsed comment arguments.
2154
- * @param BP_Activity_Activity $activity Activity item being commented on.
2155
- */
2156
- do_action( 'bp_activity_comment_posted', $comment_id, $r, $activity );
2157
-
2158
- if ( empty( $comment_id ) ) {
2159
- $errors->add( 'comment_failed', $feedback );
2160
- $bp->activity->errors['new_comment'] = $errors;
2161
- }
2162
 
2163
  return $comment_id;
2164
  }
@@ -2166,19 +1306,18 @@ function bp_activity_new_comment( $args = '' ) {
2166
  /**
2167
  * Fetch the activity_id for an existing activity entry in the DB.
2168
  *
2169
- * @since 1.2.0
2170
  *
2171
  * @see BP_Activity_Activity::get() For more information on accepted arguments.
2172
  * @uses wp_parse_args()
2173
  * @uses apply_filters() To call the 'bp_activity_get_activity_id' hook.
2174
  * @uses BP_Activity_Activity::save() {@link BP_Activity_Activity}
2175
  *
2176
- * @param array|string $args See BP_Activity_Activity::get() for description.
2177
  * @return int $activity_id The ID of the activity item found.
2178
  */
2179
  function bp_activity_get_activity_id( $args = '' ) {
2180
-
2181
- $r = bp_parse_args( $args, array(
2182
  'user_id' => false,
2183
  'component' => false,
2184
  'type' => false,
@@ -2187,25 +1326,12 @@ function bp_activity_get_activity_id( $args = '' ) {
2187
  'action' => false,
2188
  'content' => false,
2189
  'date_recorded' => false,
2190
- ) );
2191
 
2192
- /**
2193
- * Filters the activity ID being requested.
2194
- *
2195
- * @since 1.2.0
2196
- *
2197
- * @param BP_Activity_Activity $value ID returned by BP_Activity_Activity get_id() method with provided arguments.
2198
- */
2199
- return apply_filters( 'bp_activity_get_activity_id', BP_Activity_Activity::get_id(
2200
- $r['user_id'],
2201
- $r['component'],
2202
- $r['type'],
2203
- $r['item_id'],
2204
- $r['secondary_item_id'],
2205
- $r['action'],
2206
- $r['content'],
2207
- $r['date_recorded']
2208
- ) );
2209
  }
2210
 
2211
  /**
@@ -2221,7 +1347,7 @@ function bp_activity_get_activity_id( $args = '' ) {
2221
  *
2222
  * If you are deleting an activity comment please use bp_activity_delete_comment();
2223
  *
2224
- * @since 1.0.0
2225
  *
2226
  * @see BP_Activity_Activity::get() For more information on accepted arguments.
2227
  * @uses wp_parse_args()
@@ -2234,17 +1360,16 @@ function bp_activity_get_activity_id( $args = '' ) {
2234
  * @uses do_action() To call the 'bp_activity_deleted_activities' hook.
2235
  * @uses wp_cache_delete()
2236
  *
2237
- * @param array|string $args To delete specific activity items, use
2238
- * $args = array( 'id' => $ids ); Otherwise, to use
2239
- * filters for item deletion, the argument format is
2240
- * the same as BP_Activity_Activity::get().
2241
- * See that method for a description.
2242
  * @return bool True on success, false on failure.
2243
  */
2244
  function bp_activity_delete( $args = '' ) {
2245
 
2246
- // Pass one or more the of following variables to delete by those variables.
2247
- $args = bp_parse_args( $args, array(
2248
  'id' => false,
2249
  'action' => false,
2250
  'content' => false,
@@ -2256,29 +1381,23 @@ function bp_activity_delete( $args = '' ) {
2256
  'secondary_item_id' => false,
2257
  'date_recorded' => false,
2258
  'hide_sitewide' => false
2259
- ) );
 
 
2260
 
2261
- /**
2262
- * Fires before an activity item proceeds to be deleted.
2263
- *
2264
- * @since 1.5.0
2265
- *
2266
- * @param array $args Array of arguments to be used with the activity deletion.
2267
- */
2268
  do_action( 'bp_before_activity_delete', $args );
2269
 
2270
- // Adjust the new mention count of any mentioned member.
2271
  bp_activity_adjust_mention_count( $args['id'], 'delete' );
2272
 
2273
- $activity_ids_deleted = BP_Activity_Activity::delete( $args );
2274
- if ( empty( $activity_ids_deleted ) ) {
2275
  return false;
2276
- }
2277
 
2278
- // Check if the user's latest update has been deleted.
2279
- $user_id = empty( $args['user_id'] )
2280
- ? bp_loggedin_user_id()
2281
- : $args['user_id'];
 
2282
 
2283
  $latest_update = bp_get_user_meta( $user_id, 'bp_latest_update', true );
2284
  if ( !empty( $latest_update ) ) {
@@ -2287,22 +1406,7 @@ function bp_activity_delete( $args = '' ) {
2287
  }
2288
  }
2289
 
2290
- /**
2291
- * Fires after the activity item has been deleted.
2292
- *
2293
- * @since 1.0.0
2294
- *
2295
- * @param array $args Array of arguments used with the activity deletion.
2296
- */
2297
  do_action( 'bp_activity_delete', $args );
2298
-
2299
- /**
2300
- * Fires after the activity item has been deleted.
2301
- *
2302
- * @since 1.2.0
2303
- *
2304
- * @param array $activity_ids_deleted Array of affected activity item IDs.
2305
- */
2306
  do_action( 'bp_activity_deleted_activities', $activity_ids_deleted );
2307
 
2308
  wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
@@ -2315,37 +1419,40 @@ function bp_activity_delete( $args = '' ) {
2315
  *
2316
  * You should use bp_activity_delete() instead.
2317
  *
2318
- * @since 1.1.0
2319
- * @deprecated 1.2.0
2320
  *
2321
  * @uses wp_parse_args()
2322
  * @uses bp_activity_delete()
2323
  *
2324
- * @param array|string $args See BP_Activity_Activity::get for a
2325
- * description of accepted arguments.
 
2326
  * @return bool True on success, false on failure.
2327
  */
2328
  function bp_activity_delete_by_item_id( $args = '' ) {
2329
 
2330
- $r = bp_parse_args( $args, array(
2331
  'item_id' => false,
2332
  'component' => false,
2333
  'type' => false,
2334
  'user_id' => false,
2335
  'secondary_item_id' => false
2336
- ) );
 
 
2337
 
2338
- return bp_activity_delete( $r );
2339
  }
2340
 
2341
  /**
2342
  * Delete an activity item by activity id.
2343
  *
2344
- * @since 1.1.0
2345
  *
2346
  * @uses bp_activity_delete()
2347
  *
2348
- * @param int $activity_id ID of the activity item to be deleted.
2349
  * @return bool True on success, false on failure.
2350
  */
2351
  function bp_activity_delete_by_activity_id( $activity_id ) {
@@ -2357,24 +1464,19 @@ function bp_activity_delete( $args = '' ) {
2357
  *
2358
  * You should use bp_activity_delete() instead.
2359
  *
2360
- * @since 1.1.0
2361
- * @deprecated 1.2.0
2362
  *
2363
  * @uses bp_activity_delete()
2364
  *
2365
- * @param int $user_id The user id.
2366
- * @param string $content The activity id.
2367
  * @param string $component The activity component.
2368
- * @param string $type The activity type.
2369
  * @return bool True on success, false on failure.
2370
  */
2371
  function bp_activity_delete_by_content( $user_id, $content, $component, $type ) {
2372
- return bp_activity_delete( array(
2373
- 'user_id' => $user_id,
2374
- 'content' => $content,
2375
- 'component' => $component,
2376
- 'type' => $type
2377
- ) );
2378
  }
2379
 
2380
  /**
@@ -2382,26 +1484,23 @@ function bp_activity_delete( $args = '' ) {
2382
  *
2383
  * You should use bp_activity_delete() instead.
2384
  *
2385
- * @since 1.1.0
2386
- * @deprecated 1.2.0
2387
  *
2388
  * @uses bp_activity_delete()
2389
  *
2390
- * @param int $user_id The user id.
2391
  * @param string $component The activity component.
2392
  * @return bool True on success, false on failure.
2393
  */
2394
  function bp_activity_delete_for_user_by_component( $user_id, $component ) {
2395
- return bp_activity_delete( array(
2396
- 'user_id' => $user_id,
2397
- 'component' => $component
2398
- ) );
2399
  }
2400
 
2401
  /**
2402
  * Delete an activity comment.
2403
  *
2404
- * @since 1.2.0
2405
  *
2406
  * @uses apply_filters() To call the 'bp_activity_delete_comment_pre' hook.
2407
  * @uses bp_activity_delete_children()
@@ -2415,49 +1514,27 @@ function bp_activity_delete( $args = '' ) {
2415
  *
2416
  * @param int $activity_id The ID of the "root" activity, ie the comment's
2417
  * oldest ancestor.
2418
- * @param int $comment_id The ID of the comment to be deleted.
2419
- * @return bool True on success, false on failure.
2420
  */
2421
  function bp_activity_delete_comment( $activity_id, $comment_id ) {
2422
-
2423
- /**
2424
- * Filters whether BuddyPress should delete an activity comment or not.
2425
- *
2426
  * You may want to hook into this filter if you want to override this function and
2427
  * handle the deletion of child comments differently. Make sure you return false.
2428
- *
2429
- * @since 1.2.0
2430
- *
2431
- * @param bool $value Whether BuddyPress should continue or not.
2432
- * @param int $activity_id ID of the root activity item being deleted.
2433
- * @param int $comment_id ID of the comment being deleted.
2434
  */
2435
- if ( ! apply_filters( 'bp_activity_delete_comment_pre', true, $activity_id, $comment_id ) ) {
2436
  return false;
2437
- }
2438
 
2439
  // Delete any children of this comment.
2440
  bp_activity_delete_children( $activity_id, $comment_id );
2441
 
2442
- // Delete the actual comment.
2443
- if ( ! bp_activity_delete( array( 'id' => $comment_id, 'type' => 'activity_comment' ) ) ) {
2444
  return false;
2445
- }
2446
 
2447
- // Purge comment cache for the root activity update.
2448
- wp_cache_delete( $activity_id, 'bp_activity_comments' );
2449
-
2450
- // Recalculate the comment tree.
2451
  BP_Activity_Activity::rebuild_activity_comment_tree( $activity_id );
2452
 
2453
- /**
2454
- * Fires at the end of the deletion of an activity comment, before returning success.
2455
- *
2456
- * @since 1.2.0
2457
- *
2458
- * @param int $activity_id ID of the activity that has had a comment deleted from.
2459
- * @param int $comment_id ID of the comment that was deleted.
2460
- */
2461
  do_action( 'bp_activity_delete_comment', $activity_id, $comment_id );
2462
 
2463
  return true;
@@ -2466,7 +1543,7 @@ function bp_activity_delete_comment( $activity_id, $comment_id ) {
2466
  /**
2467
  * Delete an activity comment's children.
2468
  *
2469
- * @since 1.2.0
2470
  *
2471
  * @uses BP_Activity_Activity::get_child_comments() {@link BP_Activity_Activity}
2472
  * @uses bp_activity_delete_children()
@@ -2474,26 +1551,16 @@ function bp_activity_delete_comment( $activity_id, $comment_id ) {
2474
  *
2475
  * @param int $activity_id The ID of the "root" activity, ie the
2476
  * comment's oldest ancestor.
2477
- * @param int $comment_id The ID of the comment to be deleted.
2478
  */
2479
- function bp_activity_delete_children( $activity_id, $comment_id ) {
2480
-
2481
- // Get activity children to delete.
2482
- $children = BP_Activity_Activity::get_child_comments( $comment_id );
2483
-
2484
  // Recursively delete all children of this comment.
2485
- if ( ! empty( $children ) ) {
2486
  foreach( (array) $children as $child ) {
2487
  bp_activity_delete_children( $activity_id, $child->id );
2488
  }
2489
  }
2490
-
2491
- // Delete the comment itself.
2492
- bp_activity_delete( array(
2493
- 'secondary_item_id' => $comment_id,
2494
- 'type' => 'activity_comment',
2495
- 'item_id' => $activity_id
2496
- ) );
2497
  }
2498
 
2499
  /**
@@ -2504,39 +1571,26 @@ function bp_activity_delete_comment( $activity_id, $comment_id ) {
2504
  * be sure to pass the full $activity_obj parameter as well, if you already
2505
  * have it available.
2506
  *
2507
- * @since 1.2.0
2508
  *
2509
  * @uses bp_get_root_domain()
2510
  * @uses bp_get_activity_root_slug()
2511
  * @uses apply_filters_ref_array() To call the 'bp_activity_get_permalink' hook.
2512
  *
2513
- * @param int $activity_id The unique id of the activity object.
2514
- * @param object|bool $activity_obj Optional. The activity object.
2515
  * @return string $link Permalink for the activity item.
2516
  */
2517
  function bp_activity_get_permalink( $activity_id, $activity_obj = false ) {
2518
- $bp = buddypress();
2519
 
2520
- if ( empty( $activity_obj ) ) {
2521
  $activity_obj = new BP_Activity_Activity( $activity_id );
2522
- }
2523
 
2524
  if ( isset( $activity_obj->current_comment ) ) {
2525
  $activity_obj = $activity_obj->current_comment;
2526
  }
2527
 
2528
- $use_primary_links = array(
2529
- 'new_blog_post',
2530
- 'new_blog_comment',
2531
- 'new_forum_topic',
2532
- 'new_forum_post',
2533
- );
2534
-
2535
- if ( ! empty( $bp->activity->track ) ) {
2536
- $use_primary_links = array_merge( $use_primary_links, array_keys( $bp->activity->track ) );
2537
- }
2538
-
2539
- if ( false !== array_search( $activity_obj->type, $use_primary_links ) ) {
2540
  $link = $activity_obj->primary_link;
2541
  } else {
2542
  if ( 'activity_comment' == $activity_obj->type ) {
@@ -2546,20 +1600,13 @@ function bp_activity_get_permalink( $activity_id, $activity_obj = false ) {
2546
  }
2547
  }
2548
 
2549
- /**
2550
- * Filters the activity permalink for the specified activity item.
2551
- *
2552
- * @since 1.2.0
2553
- *
2554
- * @param array $array Array holding activity permalink and activity item object.
2555
- */
2556
  return apply_filters_ref_array( 'bp_activity_get_permalink', array( $link, &$activity_obj ) );
2557
  }
2558
 
2559
  /**
2560
  * Hide a user's activity.
2561
  *
2562
- * @since 1.2.0
2563
  *
2564
  * @uses BP_Activity_Activity::hide_all_for_user() {@link BP_Activity_Activity}
2565
  *
@@ -2580,17 +1627,15 @@ function bp_activity_hide_user_activity( $user_id ) {
2580
  * through the content, grabs the first image and converts it to a thumbnail,
2581
  * and removes the rest of the images from the string.
2582
  *
2583
- * As of BuddyPress 2.3, this function is no longer in use.
2584
- *
2585
- * @since 1.2.0
2586
  *
2587
  * @uses esc_attr()
2588
- * @uses apply_filters() To call the 'bp_activity_thumbnail_content_images' hook.
2589
  *
2590
- * @param string $content The content of the activity item.
2591
- * @param string|bool $link Optional. The unescaped URL that the image should link
2592
- * to. If absent, the image will not be a link.
2593
- * @param array|bool $args Optional. The args passed to the activity
2594
  * creation function (eg bp_blogs_record_activity()).
2595
  * @return string $content The content with images stripped and replaced with a
2596
  * single thumb.
@@ -2599,28 +1644,21 @@ function bp_activity_thumbnail_content_images( $content, $link = false, $args =
2599
 
2600
  preg_match_all( '/<img[^>]*>/Ui', $content, $matches );
2601
 
2602
- // Remove <img> tags. Also remove caption shortcodes and caption text if present.
2603
  $content = preg_replace('|(\[caption(.*?)\])?<img[^>]*>([^\[\[]*\[\/caption\])?|', '', $content );
2604
 
2605
  if ( !empty( $matches ) && !empty( $matches[0] ) ) {
 
 
2606
 
2607
- // Get the SRC value.
2608
- preg_match( '/<img.*?(src\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $src );
2609
-
2610
- // Get the width and height.
2611
  preg_match( '/<img.*?(height\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $height );
2612
  preg_match( '/<img.*?(width\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $width );
2613
 
2614
- if ( ! empty( $src ) ) {
2615
- $src = substr( substr( str_replace( 'src=', '', $src[1] ), 0, -1 ), 1 );
2616
-
2617
- if ( isset( $width[1] ) ) {
2618
- $width = substr( substr( str_replace( 'width=', '', $width[1] ), 0, -1 ), 1 );
2619
- }
2620
-
2621
- if ( isset( $height[1] ) ) {
2622
- $height = substr( substr( str_replace( 'height=', '', $height[1] ), 0, -1 ), 1 );
2623
- }
2624
 
2625
  if ( empty( $width ) || empty( $height ) ) {
2626
  $width = 100;
@@ -2640,289 +1678,97 @@ function bp_activity_thumbnail_content_images( $content, $link = false, $args =
2640
  }
2641
  }
2642
 
2643
- /**
2644
- * Filters the activity content that had a thumbnail replace images.
2645
- *
2646
- * @since 1.2.0
2647
- *
2648
- * @param string $content Activity content that had images replaced in.
2649
- * @param array $matches Array of all image tags found in the posted content.
2650
- * @param array $args Arguments passed into function creating the activity update.
2651
- */
2652
  return apply_filters( 'bp_activity_thumbnail_content_images', $content, $matches, $args );
2653
  }
2654
 
2655
- /**
2656
- * Create a rich summary of an activity item for the activity stream.
2657
- *
2658
- * More than just a simple excerpt, the summary could contain oEmbeds and other types of media.
2659
- * Currently, it's only used for blog post items, but it will probably be used for all types of
2660
- * activity in the future.
2661
- *
2662
- * @since 2.3.0
2663
- *
2664
- * @param string $content The content of the activity item.
2665
- * @param array $activity The data passed to bp_activity_add() or the values
2666
- * from an Activity obj.
2667
- * @return string $summary
2668
- */
2669
- function bp_activity_create_summary( $content, $activity ) {
2670
- $args = array(
2671
- 'width' => isset( $GLOBALS['content_width'] ) ? (int) $GLOBALS['content_width'] : 'medium',
2672
- );
2673
-
2674
- // Get the WP_Post object if this activity type is a blog post.
2675
- if ( $activity['type'] === 'new_blog_post' ) {
2676
- $content = get_post( $activity['secondary_item_id'] );
2677
- }
2678
-
2679
- /**
2680
- * Filter the class name of the media extractor when creating an Activity summary.
2681
- *
2682
- * Use this filter to change the media extractor used to extract media info for the activity item.
2683
- *
2684
- * @since 2.3.0
2685
- *
2686
- * @param string $extractor Class name.
2687
- * @param string $content The content of the activity item.
2688
- * @param array $activity The data passed to bp_activity_add() or the values from an Activity obj.
2689
- */
2690
- $extractor = apply_filters( 'bp_activity_create_summary_extractor_class', 'BP_Media_Extractor', $content, $activity );
2691
- $extractor = new $extractor;
2692
-
2693
- /**
2694
- * Filter the arguments passed to the media extractor when creating an Activity summary.
2695
- *
2696
- * @since 2.3.0
2697
- *
2698
- * @param array $args Array of bespoke data for the media extractor.
2699
- * @param string $content The content of the activity item.
2700
- * @param array $activity The data passed to bp_activity_add() or the values from an Activity obj.
2701
- * @param BP_Media_Extractor $extractor The media extractor object.
2702
- */
2703
- $args = apply_filters( 'bp_activity_create_summary_extractor_args', $args, $content, $activity, $extractor );
2704
-
2705
-
2706
- // Extract media information from the $content.
2707
- $media = $extractor->extract( $content, BP_Media_Extractor::ALL, $args );
2708
-
2709
- // If we converted $content to an object earlier, flip it back to a string.
2710
- if ( is_a( $content, 'WP_Post' ) ) {
2711
- $content = $content->post_content;
2712
- }
2713
-
2714
- $para_count = substr_count( strtolower( wpautop( $content ) ), '<p>' );
2715
- $has_audio = ! empty( $media['has']['audio'] ) && $media['has']['audio'];
2716
- $has_videos = ! empty( $media['has']['videos'] ) && $media['has']['videos'];
2717
- $has_feat_image = ! empty( $media['has']['featured_images'] ) && $media['has']['featured_images'];
2718
- $has_galleries = ! empty( $media['has']['galleries'] ) && $media['has']['galleries'];
2719
- $has_images = ! empty( $media['has']['images'] ) && $media['has']['images'];
2720
- $has_embeds = false;
2721
-
2722
- // Embeds must be subtracted from the paragraph count.
2723
- if ( ! empty( $media['has']['embeds'] ) ) {
2724
- $has_embeds = $media['has']['embeds'] > 0;
2725
- $para_count -= count( $media['has']['embeds'] );
2726
- }
2727
-
2728
- $extracted_media = array();
2729
- $use_media_type = '';
2730
- $image_source = '';
2731
-
2732
- // If it's a short article and there's an embed/audio/video, use it.
2733
- if ( $para_count <= 3 ) {
2734
- if ( $has_embeds ) {
2735
- $use_media_type = 'embeds';
2736
- } elseif ( $has_audio ) {
2737
- $use_media_type = 'audio';
2738
- } elseif ( $has_videos ) {
2739
- $use_media_type = 'videos';
2740
- }
2741
- }
2742
-
2743
- // If not, or in any other situation, try to use an image.
2744
- if ( ! $use_media_type && $has_images ) {
2745
- $use_media_type = 'images';
2746
- $image_source = 'html';
2747
-
2748
- // Featured Image > Galleries > inline <img>.
2749
- if ( $has_feat_image ) {
2750
- $image_source = 'featured_images';
2751
-
2752
- } elseif ( $has_galleries ) {
2753
- $image_source = 'galleries';
2754
- }
2755
- }
2756
-
2757
- // Extract an item from the $media results.
2758
- if ( $use_media_type ) {
2759
- if ( $use_media_type === 'images' ) {
2760
- $extracted_media = wp_list_filter( $media[ $use_media_type ], array( 'source' => $image_source ) );
2761
- $extracted_media = array_shift( $extracted_media );
2762
- } else {
2763
- $extracted_media = array_shift( $media[ $use_media_type ] );
2764
- }
2765
-
2766
- /**
2767
- * Filter the results of the media extractor when creating an Activity summary.
2768
- *
2769
- * @since 2.3.0
2770
- *
2771
- * @param array $extracted_media Extracted media item. See {@link BP_Media_Extractor::extract()} for format.
2772
- * @param string $content Content of the activity item.
2773
- * @param array $activity The data passed to bp_activity_add() or the values from an Activity obj.
2774
- * @param array $media All results from the media extraction.
2775
- * See {@link BP_Media_Extractor::extract()} for format.
2776
- * @param string $use_media_type The kind of media item that was preferentially extracted.
2777
- * @param string $image_source If $use_media_type was "images", the preferential source of the image.
2778
- * Otherwise empty.
2779
- */
2780
- $extracted_media = apply_filters(
2781
- 'bp_activity_create_summary_extractor_result',
2782
- $extracted_media,
2783
- $content,
2784
- $activity,
2785
- $media,
2786
- $use_media_type,
2787
- $image_source
2788
- );
2789
- }
2790
-
2791
- // Generate a text excerpt for this activity item (and remove any oEmbeds URLs).
2792
- $summary = strip_shortcodes( html_entity_decode( strip_tags( $content ) ) );
2793
- $summary = bp_create_excerpt( preg_replace( '#^\s*(https?://[^\s"]+)\s*$#im', '', $summary ) );
2794
-
2795
- if ( $use_media_type === 'embeds' ) {
2796
- $summary .= PHP_EOL . PHP_EOL . $extracted_media['url'];
2797
- } elseif ( $use_media_type === 'images' ) {
2798
- $summary .= sprintf( ' <img src="%s">', esc_url( $extracted_media['url'] ) );
2799
- } elseif ( in_array( $use_media_type, array( 'audio', 'videos' ), true ) ) {
2800
- $summary .= PHP_EOL . PHP_EOL . $extracted_media['original']; // Full shortcode.
2801
- }
2802
-
2803
- /**
2804
- * Filters the newly-generated summary for the activity item.
2805
- *
2806
- * @since 2.3.0
2807
- *
2808
- * @param string $summary Activity summary HTML.
2809
- * @param string $content Content of the activity item.
2810
- * @param array $activity The data passed to bp_activity_add() or the values from an Activity obj.
2811
- * @param array $extracted_media Media item extracted. See {@link BP_Media_Extractor::extract()} for format.
2812
- */
2813
- return apply_filters( 'bp_activity_create_summary', $summary, $content, $activity, $extracted_media );
2814
- }
2815
-
2816
  /**
2817
  * Fetch whether the current user is allowed to mark items as spam.
2818
  *
2819
- * @since 1.6.0
2820
  *
2821
  * @return bool True if user is allowed to mark activity items as spam.
2822
  */
2823
  function bp_activity_user_can_mark_spam() {
2824
-
2825
- /**
2826
- * Filters whether the current user should be able to mark items as spam.
2827
- *
2828
- * @since 1.6.0
2829
- *
2830
- * @param bool $moderate Whether or not the current user has bp_moderate capability.
2831
- */
2832
  return apply_filters( 'bp_activity_user_can_mark_spam', bp_current_user_can( 'bp_moderate' ) );
2833
  }
2834
 
2835
  /**
2836
  * Mark an activity item as spam.
2837
  *
2838
- * @since 1.6.0
 
 
2839
  *
2840
  * @param BP_Activity_Activity $activity The activity item to be spammed.
2841
- * @param string $source Optional. Default is "by_a_person" (ie, a person has
2842
- * manually marked the activity as spam). BP core also
2843
- * accepts 'by_akismet'.
2844
  */
2845
  function bp_activity_mark_as_spam( &$activity, $source = 'by_a_person' ) {
2846
- $bp = buddypress();
2847
 
2848
  $activity->is_spam = 1;
2849
 
2850
- // Clear the activity stream first page cache.
2851
  wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
2852
 
2853
- // Clear the activity comment cache for this activity item.
2854
  wp_cache_delete( $activity->id, 'bp_activity_comments' );
2855
 
2856
- // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity.
2857
  if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) {
2858
  remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4, 1 );
2859
 
2860
- // Build data package for Akismet.
2861
  $activity_data = BP_Akismet::build_akismet_data_package( $activity );
2862
 
2863
- // Tell Akismet this is spam.
2864
  $activity_data = $bp->activity->akismet->send_akismet_request( $activity_data, 'submit', 'spam' );
2865
 
2866
- // Update meta.
2867
  add_action( 'bp_activity_after_save', array( $bp->activity->akismet, 'update_activity_spam_meta' ), 1, 1 );
2868
  }
2869
 
2870
- /**
2871
- * Fires at the end of the process to mark an activity item as spam.
2872
- *
2873
- * @since 1.6.0
2874
- *
2875
- * @param BP_Activity_Activity $activity Activity item being marked as spam.
2876
- * @param string $source Source of determination of spam status. For example
2877
- * "by_a_person" or "by_akismet".
2878
- */
2879
  do_action( 'bp_activity_mark_as_spam', $activity, $source );
2880
  }
2881
 
2882
  /**
2883
  * Mark an activity item as ham.
2884
  *
2885
- * @since 1.6.0
2886
  *
2887
- * @param BP_Activity_Activity $activity The activity item to be hammed. Passed by reference.
2888
- * @param string $source Optional. Default is "by_a_person" (ie, a person has
2889
- * manually marked the activity as spam). BP core also accepts
2890
- * 'by_akismet'.
 
 
2891
  */
2892
  function bp_activity_mark_as_ham( &$activity, $source = 'by_a_person' ) {
2893
- $bp = buddypress();
2894
 
2895
  $activity->is_spam = 0;
2896
 
2897
- // Clear the activity stream first page cache.
2898
  wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
2899
 
2900
- // Clear the activity comment cache for this activity item.
2901
  wp_cache_delete( $activity->id, 'bp_activity_comments' );
2902
 
2903
- // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity.
2904
  if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) {
2905
  remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4, 1 );
2906
 
2907
- // Build data package for Akismet.
2908
  $activity_data = BP_Akismet::build_akismet_data_package( $activity );
2909
 
2910
- // Tell Akismet this is spam.
2911
  $activity_data = $bp->activity->akismet->send_akismet_request( $activity_data, 'submit', 'ham' );
2912
 
2913
- // Update meta.
2914
  add_action( 'bp_activity_after_save', array( $bp->activity->akismet, 'update_activity_ham_meta' ), 1, 1 );
2915
  }
2916
 
2917
- /**
2918
- * Fires at the end of the process to mark an activity item as ham.
2919
- *
2920
- * @since 1.6.0
2921
- *
2922
- * @param BP_Activity_Activity $activity Activity item being marked as ham.
2923
- * @param string $source Source of determination of ham status. For example
2924
- * "by_a_person" or "by_akismet".
2925
- */
2926
  do_action( 'bp_activity_mark_as_ham', $activity, $source );
2927
  }
2928
 
@@ -2939,12 +1785,11 @@ function bp_activity_mark_as_ham( &$activity, $source = 'by_a_person' ) {
2939
  * This does not cover recursive activity comments, as they do not use a real loop.
2940
  * For that, see {@link bp_activity_comment_embed()}.
2941
  *
2942
- * @since 1.5.0
2943
  *
2944
  * @see BP_Embed
2945
  * @see bp_embed_activity_cache()
2946
  * @see bp_embed_activity_save_cache()
2947
- *
2948
  * @uses add_filter() To attach 'bp_get_activity_id' to 'embed_post_id'.
2949
  * @uses add_filter() To attach 'bp_embed_activity_cache' to 'bp_embed_get_cache'.
2950
  * @uses add_action() To attach 'bp_embed_activity_save_cache' to 'bp_embed_update_cache'.
@@ -2964,12 +1809,11 @@ add_action( 'activity_loop_start', 'bp_activity_embed' );
2964
  * necessary to grab each comment's embeds from the cache, or put them in
2965
  * the cache if they are not there yet.
2966
  *
2967
- * @since 1.5.0
2968
  *
2969
  * @see BP_Embed
2970
  * @see bp_embed_activity_cache()
2971
  * @see bp_embed_activity_save_cache()
2972
- *
2973
  * @uses add_filter() To attach 'bp_get_activity_comment_id' to 'embed_post_id'.
2974
  * @uses add_filter() To attach 'bp_embed_activity_cache' to 'bp_embed_get_cache'.
2975
  * @uses add_action() To attach 'bp_embed_activity_save_cache' to 'bp_embed_update_cache'.
@@ -2984,9 +1828,10 @@ add_action( 'bp_before_activity_comment', 'bp_activity_comment_embed' );
2984
  /**
2985
  * When a user clicks on a "Read More" item, make sure embeds are correctly parsed and shown for the expanded content.
2986
  *
2987
- * @since 1.5.0
2988
  *
2989
  * @see BP_Embed
 
2990
  * @uses add_filter() To attach create_function() to 'embed_post_id'.
2991
  * @uses add_filter() To attach 'bp_embed_activity_cache' to 'bp_embed_get_cache'.
2992
  * @uses add_action() To attach 'bp_embed_activity_save_cache' to 'bp_embed_update_cache'.
@@ -2994,14 +1839,15 @@ add_action( 'bp_before_activity_comment', 'bp_activity_comment_embed' );
2994
  * @param object $activity The activity that is being expanded.
2995
  */
2996
  function bp_dtheme_embed_read_more( $activity ) {
2997
- buddypress()->activity->read_more_id = $activity->id;
2998
 
2999
- add_filter( 'embed_post_id', create_function( '', 'return buddypress()->activity->read_more_id;' ) );
3000
- add_filter( 'bp_embed_get_cache', 'bp_embed_activity_cache', 10, 3 );
3001
- add_action( 'bp_embed_update_cache', 'bp_embed_activity_save_cache', 10, 3 );
 
 
3002
  }
3003
- add_action( 'bp_dtheme_get_single_activity_content', 'bp_dtheme_embed_read_more' );
3004
- add_action( 'bp_legacy_theme_get_single_activity_content', 'bp_dtheme_embed_read_more' );
3005
 
3006
  /**
3007
  * Clean up 'embed_post_id' filter after comment recursion.
@@ -3009,7 +1855,7 @@ add_action( 'bp_legacy_theme_get_single_activity_content', 'bp_dtheme_embed_read
3009
  * This filter must be removed so that the non-comment filters take over again
3010
  * once the comments are done being processed.
3011
  *
3012
- * @since 1.5.0
3013
  *
3014
  * @see bp_activity_comment_embed()
3015
  * @uses remove_filter() To remove 'bp_get_activity_comment_id' from 'embed_post_id'.
@@ -3024,14 +1870,14 @@ add_action( 'bp_after_activity_comment', 'bp_activity_comment_embed_after_recurs
3024
  *
3025
  * Used during {@link BP_Embed::parse_oembed()} via {@link bp_activity_embed()}.
3026
  *
3027
- * @since 1.5.0
3028
  *
3029
  * @see BP_Embed::parse_oembed()
3030
  * @uses bp_activity_get_meta()
3031
  *
3032
- * @param string $cache An empty string passed by BP_Embed::parse_oembed() for
3033
- * functions like this one to filter.
3034
- * @param int $id The ID of the activity item.
3035
  * @param string $cachekey The cache key generated in BP_Embed::parse_oembed().
3036
  * @return mixed The cached embeds for this activity item.
3037
  */
@@ -3044,15 +1890,16 @@ function bp_embed_activity_cache( $cache, $id, $cachekey ) {
3044
  *
3045
  * Used during {@link BP_Embed::parse_oembed()} via {@link bp_activity_embed()}.
3046
  *
3047
- * @since 1.5.0
3048
  *
3049
  * @see BP_Embed::parse_oembed()
3050
  * @uses bp_activity_update_meta()
3051
  *
3052
- * @param string $cache An empty string passed by BP_Embed::parse_oembed() for
3053
- * functions like this one to filter.
 
3054
  * @param string $cachekey The cache key generated in BP_Embed::parse_oembed().
3055
- * @param int $id The ID of the activity item.
3056
  */
3057
  function bp_embed_activity_save_cache( $cache, $cachekey, $id ) {
3058
  bp_activity_update_meta( $id, $cachekey, $cache );
@@ -3061,13 +1908,16 @@ function bp_embed_activity_save_cache( $cache, $cachekey, $id ) {
3061
  /**
3062
  * Should we use Heartbeat to refresh activities?
3063
  *
3064
- * @since 2.0.0
3065
  *
3066
- * @uses bp_is_activity_heartbeat_active() to check if heartbeat setting is on.
3067
  * @uses bp_is_activity_directory() to check if the current page is the activity
3068
  * directory.
 
3069
  * @uses bp_is_group_activity() to check if on a single group, the current page
3070
  * is the group activities.
 
 
3071
  *
3072
  * @return bool True if activity heartbeat is enabled, otherwise false.
3073
  */
@@ -3078,9 +1928,18 @@ function bp_activity_do_heartbeat() {
3078
  return $retval;
3079
  }
3080
 
3081
- if ( bp_is_activity_directory() || bp_is_group_activity() ) {
3082
  $retval = true;
3083
  }
3084
 
 
 
 
 
 
 
 
 
 
3085
  return $retval;
3086
  }
1
  <?php
2
+
3
  /**
4
  * BuddyPress Activity Functions.
5
  *
9
  * @subpackage ActivityFunctions
10
  */
11
 
12
+ // Exit if accessed directly
13
+ if ( !defined( 'ABSPATH' ) ) exit;
14
 
15
  /**
16
  * Check whether the $bp global lists an activity directory page.
17
  *
18
+ * @since BuddyPress (1.5)
19
+ *
20
+ * @global object $bp BuddyPress global settings
21
  *
22
  * @return bool True if activity directory page is found, otherwise false.
23
  */
24
  function bp_activity_has_directory() {
25
+ global $bp;
26
+
27
+ return (bool) !empty( $bp->pages->activity->id );
28
  }
29
 
30
  /**
32
  *
33
  * The Mentions feature does a number of things, all of which will be turned
34
  * off if you disable mentions:
35
+ * - Detecting and auto-linking @username in all BP/WP content
36
  * - Sending BP notifications and emails to users when they are mentioned
37
+ * using the @username syntax
38
+ * - The Public Message button on user profiles
39
  *
40
  * Mentions are enabled by default. To disable, put the following line in
41
  * bp-custom.php or your theme's functions.php file:
42
  *
43
  * add_filter( 'bp_activity_do_mentions', '__return_false' );
44
  *
45
+ * @since BuddyPress (1.8)
46
  *
47
  * @uses apply_filters() To call 'bp_activity_do_mentions' hook.
48
  *
49
  * @return bool $retval True to enable mentions, false to disable.
50
  */
51
  function bp_activity_do_mentions() {
 
 
 
 
 
 
 
 
52
  return (bool) apply_filters( 'bp_activity_do_mentions', true );
53
  }
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  /**
56
  * Locate usernames in an activity content string, as designated by an @ sign.
57
  *
58
+ * @since BuddyPress (1.5)
59
  *
60
+ * @param string $content The content of the activity, usually found in $activity->content.
61
+ * @return array|bool Associative array with user ID as key and username as value. Boolean false if no mentions found.
 
 
62
  */
63
  function bp_activity_find_mentions( $content ) {
 
64
  $pattern = '/[@]+([A-Za-z0-9-_\.@]+)\b/';
65
  preg_match_all( $pattern, $content, $usernames );
66
 
67
+ // Make sure there's only one instance of each username
68
+ if ( !$usernames = array_unique( $usernames[1] ) )
 
 
 
69
  return false;
 
70
 
71
  $mentioned_users = array();
72
 
73
+ // We've found some mentions! Check to see if users exist
74
+ foreach( (array) $usernames as $key => $username ) {
75
  $user_id = bp_activity_get_userid_from_mentionname( $username );
76
 
77
+ // user ID exists, so let's add it to our array
78
  if ( ! empty( $user_id ) ) {
79
+ $mentioned_users[$user_id] = $username;
80
  }
81
  }
82
 
83
+ if ( empty( $mentioned_users ) )
84
  return false;
 
85
 
86
  return $mentioned_users;
87
  }
89
  /**
90
  * Reset a user's unread mentions list and count.
91
  *
92
+ * @since BuddyPress (1.5)
93
  *
94
  * @uses bp_delete_user_meta()
95
  *
97
  */
98
  function bp_activity_clear_new_mentions( $user_id ) {
99
  bp_delete_user_meta( $user_id, 'bp_new_mention_count' );
100
+ bp_delete_user_meta( $user_id, 'bp_new_mentions' );
101
  }
102
 
103
  /**
108
  *
109
  * Currently, only used in {@link bp_activity_delete()}.
110
  *
111
+ * @since BuddyPress (1.5)
112
  *
113
  * @uses bp_activity_find_mentions()
114
  * @uses bp_activity_update_mention_count_for_user()
115
  *
116
+ * @param int $activity_id The unique id for the activity item.
117
+ * @param string $action Can be 'delete' or 'add'. Defaults to 'add'.
 
118
  */
119
  function bp_activity_adjust_mention_count( $activity_id = 0, $action = 'add' ) {
120
+ if ( empty( $activity_id ) )
 
 
121
  return false;
 
122
 
123
+ // Get activity object
124
+ $activity = new BP_Activity_Activity( (int) $activity_id );
125
 
126
+ // Try to find mentions
127
  $usernames = bp_activity_find_mentions( strip_tags( $activity->content ) );
128
 
129
+ // Still empty? Stop now
130
+ if ( empty( $usernames ) )
131
  return false;
 
132
 
133
+ // Increment mention count foreach mentioned user
134
+ foreach( (array) $usernames as $user_id => $username ) {
135
  bp_activity_update_mention_count_for_user( $user_id, $activity_id, $action );
136
  }
137
  }
142
  * This function should be used when you've already parsed your activity item
143
  * for @mentions.
144
  *
145
+ * @since BuddyPress (1.7)
146
  *
147
  * @uses bp_get_user_meta()
148
  * @uses bp_update_user_meta()
149
  *
150
+ * @param int $user_id The user ID.
151
+ * @param int $activity_id The unique ID for the activity item.
152
+ * @param string $action 'delete' or 'add'. Default: 'add'.
153
  * @return bool
154
  */
155
  function bp_activity_update_mention_count_for_user( $user_id, $activity_id, $action = 'add' ) {
156
+ if ( empty( $user_id ) || empty( $activity_id ) )
 
157
  return false;
 
158
 
159
+ // Adjust the mention list and count for the member
160
  $new_mention_count = (int) bp_get_user_meta( $user_id, 'bp_new_mention_count', true );
161
+ if ( !$new_mentions = bp_get_user_meta( $user_id, 'bp_new_mentions', true ) )
 
 
 
162
  $new_mentions = array();
 
163
 
164
  switch ( $action ) {
165
  case 'delete' :
180
  break;
181
  }
182
 
183
+ // Get an updated mention count
184
  $new_mention_count = count( $new_mentions );
185
 
186
+ // Resave the user_meta
187
  bp_update_user_meta( $user_id, 'bp_new_mention_count', $new_mention_count );
188
  bp_update_user_meta( $user_id, 'bp_new_mentions', $new_mentions );
189
 
193
  /**
194
  * Determine a user's "mentionname", the name used for that user in @-mentions.
195
  *
196
+ * @since BuddyPress (1.9.0)
197
  *
198
+ * @return string User name appropriate for @-mentions.
 
199
  */
200
  function bp_activity_get_user_mentionname( $user_id ) {
201
  $mentionname = '';
216
  /**
217
  * Get a user ID from a "mentionname", the name used for a user in @-mentions.
218
  *
219
+ * @since BuddyPress (1.9.0)
220
  *
 
221
  * @return int|bool ID of the user, if one is found. Otherwise false.
222
  */
223
  function bp_activity_get_userid_from_mentionname( $mentionname ) {
224
  $user_id = false;
225
 
226
+ // In username compatibility mode, hyphens are ambiguous between
227
+ // actual hyphens and converted spaces.
228
+ //
229
+ // @todo There is the potential for username clashes between 'foo bar'
230
+ // and 'foo-bar' in compatibility mode. Come up with a system for
231
+ // unique mentionnames.
 
 
232
  if ( bp_is_username_compatibility_mode() ) {
233
+ // First, try the raw username
234
  $userdata = get_user_by( 'login', $mentionname );
235
 
236
  // Doing a direct query to use proper regex. Necessary to
244
  }
245
 
246
  // When username compatibility mode is disabled, the mentionname is
247
+ // the same as the nicename
248
  } else {
249
  $user_id = bp_core_get_userid_from_nicename( $mentionname );
250
  }
269
  * panel, and dynamic action generation (which is essential for multilingual
270
  * sites, etc) will not work.
271
  *
272
+ * @since BuddyPress (1.1.0)
273
  *
274
+ * @param string $component_id The unique string ID of the component.
275
+ * @param string $type The action type.
276
+ * @param string $description The action description.
277
+ * @param callable $format_callback Callback for formatting the action string.
 
 
 
 
278
  * @return bool False if any param is empty, otherwise true.
279
  */
280
+ function bp_activity_set_action( $component_id, $type, $description, $format_callback = false ) {
281
  $bp = buddypress();
282
 
283
+ // Return false if any of the above values are not set
284
  if ( empty( $component_id ) || empty( $type ) || empty( $description ) ) {
285
  return false;
286
  }
287
 
288
+ // Set activity action
289
  if ( ! isset( $bp->activity->actions ) || ! is_object( $bp->activity->actions ) ) {
290
  $bp->activity->actions = new stdClass;
291
  }
292
 
293
+ // Verify callback
294
  if ( ! is_callable( $format_callback ) ) {
295
  $format_callback = '';
296
  }
299
  $bp->activity->actions->{$component_id} = new stdClass;
300
  }
301
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
  $bp->activity->actions->{$component_id}->{$type} = apply_filters( 'bp_activity_set_action', array(
303
  'key' => $type,
304
  'value' => $description,
305
  'format_callback' => $format_callback,
306
+ ), $component_id, $type, $description, $format_callback );
 
 
 
307
 
308
  return true;
309
  }
310
 
311
  /**
312
+ * Retreive the current action from a component and key.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
313
  *
314
+ * @since BuddyPress (1.1)
315
  *
316
+ * @global object $bp BuddyPress global settings.
317
  * @uses apply_filters() To call the 'bp_activity_get_action' hook.
318
  *
319
  * @param string $component_id The unique string ID of the component.
320
+ * @param string $key The action key.
321
  * @return string|bool Action value if found, otherwise false.
322
  */
323
  function bp_activity_get_action( $component_id, $key ) {
324
+ global $bp;
325
 
326
+ // Return false if any of the above values are not set
327
+ if ( empty( $component_id ) || empty( $key ) )
328
  return false;
 
 
 
 
 
 
 
 
329
 
330
+ return apply_filters( 'bp_activity_get_action', $bp->activity->actions->{$component_id}->{$key}, $component_id, $key );
 
 
 
 
 
 
 
 
 
331
  }
332
 
333
  /**
334
  * Fetch details of all registered activity types.
335
  *
336
+ * @since BuddyPress (1.7)
337
  *
338
  * @return array array( type => description ), ...
339
  */
341
  $actions = array();
342
 
343
  // Walk through the registered actions, and build an array of actions/values.
344
+ foreach ( buddypress()->activity->actions as $action ) {
345
  $action = array_values( (array) $action );
346
 
347
+ for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ )
348
  $actions[ $action[$i]['key'] ] = $action[$i]['value'];
 
349
  }
350
 
351
+ // This was a mis-named activity type from before BP 1.6
352
  unset( $actions['friends_register_activity_action'] );
353
 
 
 
 
 
 
 
 
354
  return apply_filters( 'bp_activity_get_types', $actions );
355
  }
356
 
359
  /**
360
  * Get a users favorite activity stream items.
361
  *
362
+ * @since BuddyPress (1.2)
363
  *
364
  * @uses bp_get_user_meta()
365
  * @uses apply_filters() To call the 'bp_activity_get_user_favorites' hook.
369
  */
370
  function bp_activity_get_user_favorites( $user_id = 0 ) {
371
 
372
+ // Fallback to logged in user if no user_id is passed
373
+ if ( empty( $user_id ) )
374
  $user_id = bp_displayed_user_id();
 
375
 
376
+ // Get favorites for user
377
  $favs = bp_get_user_meta( $user_id, 'bp_favorite_activities', true );
378
 
 
 
 
 
 
 
 
379
  return apply_filters( 'bp_activity_get_user_favorites', $favs );
380
  }
381
 
382
  /**
383
  * Add an activity stream item as a favorite for a user.
384
  *
385
+ * @since BuddyPress (1.2)
386
  *
387
  * @uses is_user_logged_in()
388
  * @uses bp_get_user_meta()
393
  * @uses do_action() To call the 'bp_activity_add_user_favorite_fail' hook.
394
  *
395
  * @param int $activity_id ID of the activity item being favorited.
396
+ * @param int $user_id ID of the user favoriting the activity item.
397
  * @return bool True on success, false on failure.
398
  */
399
  function bp_activity_add_user_favorite( $activity_id, $user_id = 0 ) {
400
 
401
+ // Favorite activity stream items are for logged in users only
402
+ if ( !is_user_logged_in() )
403
  return false;
 
404
 
405
+ // Fallback to logged in user if no user_id is passed
406
+ if ( empty( $user_id ) )
407
  $user_id = bp_loggedin_user_id();
 
408
 
409
  $my_favs = bp_get_user_meta( $user_id, 'bp_favorite_activities', true );
410
  if ( empty( $my_favs ) || ! is_array( $my_favs ) ) {
411
  $my_favs = array();
412
  }
413
 
414
+ // Bail if the user has already favorited this activity item
415
  if ( in_array( $activity_id, $my_favs ) ) {
416
  return false;
417
  }
418
 
419
+ // Add to user's favorites
420
  $my_favs[] = $activity_id;
421
 
422
+ // Update the total number of users who have favorited this activity
423
  $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' );
424
  $fav_count = !empty( $fav_count ) ? (int) $fav_count + 1 : 1;
425
 
426
+ // Update user meta
427
  bp_update_user_meta( $user_id, 'bp_favorite_activities', $my_favs );
428
 
429
+ // Update activity meta counts
430
  if ( bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count ) ) {
431
 
432
+ // Execute additional code
 
 
 
 
 
 
 
433
  do_action( 'bp_activity_add_user_favorite', $activity_id, $user_id );
434
 
435
+ // Success
436
  return true;
437
 
438
+ // Saving meta was unsuccessful for an unknown reason
439
  } else {
440
+ // Execute additional code
 
 
 
 
 
 
 
 
441
  do_action( 'bp_activity_add_user_favorite_fail', $activity_id, $user_id );
442
 
443
  return false;
447
  /**
448
  * Remove an activity stream item as a favorite for a user.
449
  *
450
+ * @since BuddyPress (1.2)
451
  *
452
  * @uses is_user_logged_in()
453
  * @uses bp_get_user_meta()
457
  * @uses do_action() To call the 'bp_activity_remove_user_favorite' hook.
458
  *
459
  * @param int $activity_id ID of the activity item being unfavorited.
460
+ * @param int $user_id ID of the user unfavoriting the activity item.
461
  * @return bool True on success, false on failure.
462
  */
463
  function bp_activity_remove_user_favorite( $activity_id, $user_id = 0 ) {
464
 
465
+ // Favorite activity stream items are for logged in users only
466
+ if ( !is_user_logged_in() )
467
  return false;
 
468
 
469
+ // Fallback to logged in user if no user_id is passed
470
+ if ( empty( $user_id ) )
471
  $user_id = bp_loggedin_user_id();
 
472
 
473
  $my_favs = bp_get_user_meta( $user_id, 'bp_favorite_activities', true );
474
  $my_favs = array_flip( (array) $my_favs );
475
 
476
+ // Bail if the user has not previously favorited the item
477
  if ( ! isset( $my_favs[ $activity_id ] ) ) {
478
  return false;
479
  }
480
 
481
+ // Remove the fav from the user's favs
482
  unset( $my_favs[$activity_id] );
483
  $my_favs = array_unique( array_flip( $my_favs ) );
484
 
485
+ // Update the total number of users who have favorited this activity
486
+ if ( $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' ) ) {
 
487
 
488
+ // Deduct from total favorites
489
  if ( bp_activity_update_meta( $activity_id, 'favorite_count', (int) $fav_count - 1 ) ) {
490
 
491
+ // Update users favorites
492
  if ( bp_update_user_meta( $user_id, 'bp_favorite_activities', $my_favs ) ) {
493
 
494
+ // Execute additional code
 
 
 
 
 
 
 
495
  do_action( 'bp_activity_remove_user_favorite', $activity_id, $user_id );
496
 
497
+ // Success
498
  return true;
499
 
500
+ // Error updating
501
  } else {
502
  return false;
503
  }
504
 
505
+ // Error updating favorite count
506
  } else {
507
  return false;
508
  }
509
 
510
+ // Error getting favorite count
511
  } else {
512
  return false;
513
  }
516
  /**
517
  * Check whether an activity item exists with a given content string.
518
  *
519
+ * @since BuddyPress (1.1)
520
  *
521
  * @uses BP_Activity_Activity::check_exists_by_content() {@link BP_Activity_Activity}
522
  * @uses apply_filters() To call the 'bp_activity_check_exists_by_content' hook.
525
  * @return int|null The ID of the located activity item. Null if none is found.
526
  */
527
  function bp_activity_check_exists_by_content( $content ) {
 
 
 
 
 
 
 
 
528
  return apply_filters( 'bp_activity_check_exists_by_content', BP_Activity_Activity::check_exists_by_content( $content ) );
529
  }
530
 
531
  /**
532
  * Retrieve the last time activity was updated.
533
  *
534
+ * @since BuddyPress (1.0)
535
  *
536
  * @uses BP_Activity_Activity::get_last_updated() {@link BP_Activity_Activity}
537
  * @uses apply_filters() To call the 'bp_activity_get_last_updated' hook.
539
  * @return string Date last updated.
540
  */
541
  function bp_activity_get_last_updated() {
 
 
 
 
 
 
 
 
542
  return apply_filters( 'bp_activity_get_last_updated', BP_Activity_Activity::get_last_updated() );
543
  }
544
 
545
  /**
546
  * Retrieve the number of favorite activity stream items a user has.
547
  *
548
+ * @since BuddyPress (1.2)
549
  *
550
  * @uses BP_Activity_Activity::total_favorite_count() {@link BP_Activity_Activity}
551
  *
554
  */
555
  function bp_activity_total_favorites_for_user( $user_id = 0 ) {
556
 
557
+ // Fallback on displayed user, and then logged in user
558
+ if ( empty( $user_id ) )
559
  $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
 
560
 
561
  return BP_Activity_Activity::total_favorite_count( $user_id );
562
  }
566
  /**
567
  * Delete a meta entry from the DB for an activity stream item.
568
  *
569
+ * @since BuddyPress (1.2.0)
570
  *
571
  * @global object $wpdb WordPress database access object.
572
+ * @global object $bp BuddyPress global settings.
573
+ *
574
+ * @param int $activity_id ID of the activity item whose metadata is being deleted.
575
+ * @param string $meta_key Optional. The key of the metadata being deleted. If
576
+ * omitted, all metadata associated with the activity
577
+ * item will be deleted.
578
+ * @param string $meta_value Optional. If present, the metadata will only be
579
+ * deleted if the meta_value matches this parameter.
580
+ * @param bool $delete_all Optional. If true, delete matching metadata entries
581
+ * for all objects, ignoring the specified object_id. Otherwise,
582
+ * only delete matching metadata entries for the specified
583
+ * activity item. Default: false.
584
  * @return bool True on success, false on failure.
585
  */
586
  function bp_activity_delete_meta( $activity_id, $meta_key = '', $meta_value = '', $delete_all = false ) {
587
+ global $wpdb, $bp;
588
 
589
+ // Legacy - if no meta_key is passed, delete all for the item
590
  if ( empty( $meta_key ) ) {
591
  $all_meta = bp_activity_get_meta( $activity_id );
592
  $keys = ! empty( $all_meta ) ? array_keys( $all_meta ) : array();
593
 
594
+ // With no meta_key, ignore $delete_all
595
  $delete_all = false;
596
  } else {
597
  $keys = array( $meta_key );
611
  /**
612
  * Get metadata for a given activity item.
613
  *
614
+ * @since BuddyPress (1.2)
615
  *
616
  * @uses apply_filters() To call the 'bp_activity_get_meta' hook.
617
  *
618
+ * @param int $activity_id ID of the activity item whose metadata is being requested.
619
+ * @param string $meta_key Optional. If present, only the metadata matching
620
+ * that meta key will be returned. Otherwise, all metadata for the
621
+ * activity item will be fetched.
622
+ * @param bool $single Optional. If true, return only the first value of the
623
+ * specified meta_key. This parameter has no effect if meta_key is not
624
+ * specified. Default: true.
625
  * @return mixed The meta value(s) being requested.
626
  */
627
  function bp_activity_get_meta( $activity_id = 0, $meta_key = '', $single = true ) {
629
  $retval = get_metadata( 'activity', $activity_id, $meta_key, $single );
630
  remove_filter( 'query', 'bp_filter_metaid_column_name' );
631
 
632
+ // Filter result before returning
 
 
 
 
 
 
 
 
 
633
  return apply_filters( 'bp_activity_get_meta', $retval, $activity_id, $meta_key, $single );
634
  }
635
 
636
  /**
637
  * Update a piece of activity meta.
638
  *
639
+ * @since BuddyPress (1.2)
640
  *
641
+ * @param int $activity_id ID of the activity item whose metadata is being
642
+ * updated.
643
+ * @param string $meta_key Key of the metadata being updated.
644
+ * @param mixed $meta_value Value to be set.
645
+ * @param mixed $prev_value Optional. If specified, only update existing
646
+ * metadata entries with the specified value. Otherwise, update all
647
+ * entries.
648
  * @return bool|int Returns false on failure. On successful update of existing
649
+ * metadata, returns true. On successful creation of new metadata,
650
+ * returns the integer ID of the new metadata row.
651
  */
652
  function bp_activity_update_meta( $activity_id, $meta_key, $meta_value, $prev_value = '' ) {
653
  add_filter( 'query', 'bp_filter_metaid_column_name' );
660
  /**
661
  * Add a piece of activity metadata.
662
  *
663
+ * @since BuddyPress (2.0.0)
664
  *
665
+ * @param int $activity_id ID of the activity item.
666
+ * @param string $meta_key Metadata key.
667
+ * @param mixed $meta_value Metadata value.
668
+ * @param bool $unique. Optional. Whether to enforce a single metadata value
669
+ * for the given key. If true, and the object already has a value for
670
+ * the key, no change will be made. Default: false.
671
  * @return int|bool The meta ID on successful update, false on failure.
672
  */
673
  function bp_activity_add_meta( $activity_id, $meta_key, $meta_value, $unique = false ) {
683
  /**
684
  * Completely remove a user's activity data.
685
  *
686
+ * @since BuddyPress (1.5)
687
  *
688
  * @uses is_user_logged_in()
689
  * @uses bp_activity_delete()
692
  * @uses do_action() To call the 'bp_activity_remove_all_user_data' hook.
693
  *
694
  * @param int $user_id ID of the user whose activity is being deleted.
 
695
  */
696
  function bp_activity_remove_all_user_data( $user_id = 0 ) {
697
 
698
+ // Do not delete user data unless a logged in user says so
699
+ if ( empty( $user_id ) || !is_user_logged_in() )
700
  return false;
 
701
 
702
+ // Clear the user's activity from the sitewide stream and clear their activity tables
703
  bp_activity_delete( array( 'user_id' => $user_id ) );
704
 
705
+ // Remove any usermeta
706
+ bp_delete_user_meta( $user_id, 'bp_latest_update' );
707
  bp_delete_user_meta( $user_id, 'bp_favorite_activities' );
708
 
709
  // Execute additional code
710
  do_action( 'bp_activity_remove_data', $user_id ); // Deprecated! Do not use!
711
 
712
+ // Use this going forward
 
 
 
 
 
 
713
  do_action( 'bp_activity_remove_all_user_data', $user_id );
714
  }
715
  add_action( 'wpmu_delete_user', 'bp_activity_remove_all_user_data' );
718
  /**
719
  * Mark all of the user's activity as spam.
720
  *
721
+ * @since BuddyPress (1.6)
722
  *
723
  * @global object $wpdb WordPress database access object.
724
+ * @global object $bp BuddyPress global settings.
725
  *
726
  * @param int $user_id ID of the user whose activity is being spammed.
 
727
  */
728
  function bp_activity_spam_all_user_data( $user_id = 0 ) {
729
+ global $bp, $wpdb;
730
 
731
+ // Do not delete user data unless a logged in user says so
732
+ if ( empty( $user_id ) || ! is_user_logged_in() )
733
  return false;
 
734
 
735
  // Get all the user's activities.
736
+ $activities = bp_activity_get( array( 'display_comments' => 'stream', 'filter' => array( 'user_id' => $user_id ), 'show_hidden' => true, ) );
 
 
 
 
 
 
737
 
738
+ // Mark each as spam
739
  foreach ( (array) $activities['activities'] as $activity ) {
740
 
741
+ // Create an activity object
742
  $activity_obj = new BP_Activity_Activity;
743
+ foreach ( $activity as $k => $v )
744
  $activity_obj->$k = $v;
 
745
 
746
+ // Mark as spam
747
  bp_activity_mark_as_spam( $activity_obj );
748
 
749
  /*
750
  * If Akismet is present, update the activity history meta.
751
  *
752
  * This is usually taken care of when BP_Activity_Activity::save() happens, but
753
+ * as we're going to be updating all the activity statuses directly, for efficency,
754
  * we need to update manually.
755
  */
756
+ if ( ! empty( $bp->activity->akismet ) )
757
  $bp->activity->akismet->update_activity_spam_meta( $activity_obj );
 
758
 
759
+ // Tidy up
760
  unset( $activity_obj );
761
  }
762
 
763
+ // Mark all of this user's activities as spam
764
  $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_spam = 1 WHERE user_id = %d", $user_id ) );
765
 
766
+ // Call an action for plugins to use
 
 
 
 
 
 
 
767
  do_action( 'bp_activity_spam_all_user_data', $user_id, $activities['activities'] );
768
  }
769
  add_action( 'bp_make_spam_user', 'bp_activity_spam_all_user_data' );
771
  /**
772
  * Mark all of the user's activity as ham (not spam).
773
  *
774
+ * @since BuddyPress (1.6)
775
  *
776
  * @global object $wpdb WordPress database access object.
777
+ * @global object $bp BuddyPress global settings.
778
  *
779
  * @param int $user_id ID of the user whose activity is being hammed.
 
780
  */
781
  function bp_activity_ham_all_user_data( $user_id = 0 ) {
782
+ global $bp, $wpdb;
783
 
784
+ // Do not delete user data unless a logged in user says so
785
+ if ( empty( $user_id ) || ! is_user_logged_in() )
786
  return false;
 
787
 
788
  // Get all the user's activities.
789
+ $activities = bp_activity_get( array( 'display_comments' => 'stream', 'filter' => array( 'user_id' => $user_id ), 'show_hidden' => true, 'spam' => 'all', ) );
 
 
 
 
 
790
 
791
+ // Mark each as not spam
 
 
792
  foreach ( (array) $activities['activities'] as $activity ) {
793
 
794
+ // Create an activity object
795
  $activity_obj = new BP_Activity_Activity;
796
+ foreach ( $activity as $k => $v )
797
  $activity_obj->$k = $v;
 
798
 
799
+ // Mark as not spam
800
  bp_activity_mark_as_ham( $activity_obj );
801
 
802
  /*
803
  * If Akismet is present, update the activity history meta.
804
  *
805
  * This is usually taken care of when BP_Activity_Activity::save() happens, but
806
+ * as we're going to be updating all the activity statuses directly, for efficency,
807
  * we need to update manually.
808
  */
809
+ if ( ! empty( $bp->activity->akismet ) )
810
  $bp->activity->akismet->update_activity_ham_meta( $activity_obj );
 
811
 
812
+ // Tidy up
813
  unset( $activity_obj );
814
  }
815
 
816
+ // Mark all of this user's activities as spam
817
  $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_spam = 0 WHERE user_id = %d", $user_id ) );
818
 
819
+ // Call an action for plugins to use
 
 
 
 
 
 
 
820
  do_action( 'bp_activity_ham_all_user_data', $user_id, $activities['activities'] );
821
  }
822
  add_action( 'bp_make_ham_user', 'bp_activity_ham_all_user_data' );
823
 
824
  /**
825
+ * Register the activity stream actions for updates
826
  *
827
+ * @since BuddyPress (1.6)
828
+ *
829
+ * @global object $bp BuddyPress global settings.
830
  */
831
  function bp_activity_register_activity_actions() {
832
+ global $bp;
833
 
834
  bp_activity_set_action(
835
  $bp->activity->id,
836
  'activity_update',
837
  __( 'Posted a status update', 'buddypress' ),
838
+ 'bp_activity_format_activity_action_activity_update'
 
 
839
  );
840
 
841
  bp_activity_set_action(
842
  $bp->activity->id,
843
  'activity_comment',
844
  __( 'Replied to a status update', 'buddypress' ),
845
+ 'bp_activity_format_activity_action_activity_comment'
 
846
  );
847
 
 
 
 
 
 
 
 
848
  do_action( 'bp_activity_register_activity_actions' );
849
 
850
  // Backpat. Don't use this.
857
  *
858
  * @param object $activity Activity data object.
859
  * @return string|bool Returns false if no callback is found, otherwise returns
860
+ * the formatted action string.
861
  */
862
  function bp_activity_generate_action_string( $activity ) {
863
+ // Check for valid input
 
864
  if ( empty( $activity->component ) || empty( $activity->type ) ) {
865
  return false;
866
  }
867
 
868
+ // Check for registered format callback
869
+ if ( empty( buddypress()->activity->actions->{$activity->component}->{$activity->type}['format_callback'] ) ) {
 
870
  return false;
871
  }
872
 
873
+ // We apply the format_callback as a filter
874
+ add_filter( 'bp_activity_generate_action_string', buddypress()->activity->actions->{$activity->component}->{$activity->type}['format_callback'], 10, 2 );
875
 
876
+ // Generate the action string (run through the filter defined above)
 
 
 
 
 
 
 
877
  $action = apply_filters( 'bp_activity_generate_action_string', $activity->action, $activity );
878
 
879
+ // Remove the filter for future activity items
880
+ remove_filter( 'bp_activity_generate_action_string', buddypress()->activity->actions->{$activity->component}->{$activity->type}['format_callback'], 10, 2 );
881
 
882
  return $action;
883
  }
885
  /**
886
  * Format 'activity_update' activity actions.
887
  *
888
+ * @since BuddyPress (2.0.0)
889
  *
890
+ * @param string $action Static activity action.
891
  * @param object $activity Activity data object.
892
+ * @return string
893
  */
894
  function bp_activity_format_activity_action_activity_update( $action, $activity ) {
895
  $action = sprintf( __( '%s posted an update', 'buddypress' ), bp_core_get_userlink( $activity->user_id ) );
 
 
 
 
 
 
 
 
 
896
  return apply_filters( 'bp_activity_new_update_action', $action, $activity );
897
  }
898
 
899
  /**
900
  * Format 'activity_comment' activity actions.
901
  *
902
+ * @since BuddyPress (2.0.0)
903
  *
904
+ * @param string $action Static activity action.
905
  * @param object $activity Activity data object.
906
+ * @return string
907
  */
908
  function bp_activity_format_activity_action_activity_comment( $action, $activity ) {
909
  $action = sprintf( __( '%s posted a new activity comment', 'buddypress' ), bp_core_get_userlink( $activity->user_id ) );
 
 
 
 
 
 
 
 
 
910
  return apply_filters( 'bp_activity_comment_action', $action, $activity );
911
  }
912
 
913
+ /******************************************************************************
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
914
  * Business functions are where all the magic happens in BuddyPress. They will
915
  * handle the actual saving or manipulation of information. Usually they will
916
  * hand off to a database class for data access, then return
920
  /**
921
  * Retrieve an activity or activities.
922
  *
923
+ * bp_activity_get() shares all arguments with BP_Activity_Activity::get(). The
924
+ * following is a list of bp_activity_get() parameters that have different
925
  * default values from BP_Activity_Activity::get() (value in parentheses is
926
  * the default for the bp_activity_get()).
927
  * - 'per_page' (false)
928
  *
929
+ * @since BuddyPress (1.2)
 
930
  *
931
  * @see BP_Activity_Activity::get() For more information on accepted arguments
932
  * and the format of the returned value.
936
  * @uses BP_Activity_Activity::get() {@link BP_Activity_Activity}
937
  * @uses apply_filters_ref_array() To call the 'bp_activity_get' hook.
938
  *
939
+ * @param array $args See BP_Activity_Activity::get() for description.
940
  * @return array $activity See BP_Activity_Activity::get() for description.
941
  */
942
  function bp_activity_get( $args = '' ) {
943
+ $defaults = array(
 
944
  'max' => false, // Maximum number of results to return
 
945
  'page' => 1, // page 1 without a per_page will result in no pagination.
946
  'per_page' => false, // results per page
947
  'sort' => 'DESC', // sort ASC or DESC
949
 
950
  'search_terms' => false, // Pass search terms as a string
951
  'meta_query' => false, // Filter by activity meta. See WP_Meta_Query for format
 
 
952
  'show_hidden' => false, // Show activity items that are hidden site-wide?
953
+ 'exclude' => false, // Comma-separated list of activity IDs to exclude
954
+ 'in' => false, // Comma-separated list or array of activity IDs to which you want to limit the query
 
955
  'spam' => 'ham_only', // 'ham_only' (default), 'spam_only' or 'all'.
956
  'update_meta_cache' => true,
 
 
957
 
958
  /**
959
  * Pass filters as an array -- all filter items can be multiple values comma separated:
960
  * array(
961
+ * 'user_id' => false, // user_id to filter on
962
+ * 'object' => false, // object to filter on e.g. groups, profile, status, friends
963
+ * 'action' => false, // action to filter on e.g. activity_update, profile_updated
964
+ * 'primary_id' => false, // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
965
+ * 'secondary_id' => false, // secondary object ID to filter on e.g. a post_id
966
  * );
967
  */
968
  'filter' => array()
969
+ );
970
+ $r = wp_parse_args( $args, $defaults );
971
+ extract( $r, EXTR_SKIP );
972
 
973
  // Attempt to return a cached copy of the first page of sitewide activity.
974
+ if ( 1 == (int) $page && empty( $max ) && empty( $search_terms ) && empty( $meta_query ) && empty( $filter ) && empty( $exclude ) && empty( $in ) && 'DESC' == $sort && empty( $exclude ) && 'ham_only' == $spam ) {
975
+ if ( !$activity = wp_cache_get( 'bp_activity_sitewide_front', 'bp' ) ) {
976
+ $args = array(
977
+ 'page' => $page,
978
+ 'per_page' => $per_page,
979
+ 'max' => $max,
980
+ 'sort' => $sort,
981
+ 'search_terms' => $search_terms,
982
+ 'meta_query' => $meta_query,
983
+ 'filter' => $filter,
984
+ 'display_comments' => $display_comments,
985
+ 'show_hidden' => $show_hidden,
986
+ 'spam' => $spam,
987
+ 'update_meta_cache' => $update_meta_cache,
988
+ );
989
+ $activity = BP_Activity_Activity::get( $args );
 
 
 
 
 
 
 
 
990
  wp_cache_set( 'bp_activity_sitewide_front', $activity, 'bp' );
991
  }
992
 
993
  } else {
994
+ $args = array(
995
+ 'page' => $page,
996
+ 'per_page' => $per_page,
997
+ 'max' => $max,
998
+ 'sort' => $sort,
999
+ 'search_terms' => $search_terms,
1000
+ 'meta_query' => $meta_query,
1001
+ 'filter' => $filter,
1002
+ 'display_comments' => $display_comments,
1003
+ 'show_hidden' => $show_hidden,
1004
+ 'exclude' => $exclude,
1005
+ 'in' => $in,
1006
+ 'spam' => $spam
1007
+ );
1008
+ $activity = BP_Activity_Activity::get( $args );
 
 
 
1009
  }
1010
 
 
 
 
 
 
 
 
 
1011
  return apply_filters_ref_array( 'bp_activity_get', array( &$activity, &$r ) );
1012
  }
1013
 
1014
  /**
1015
  * Fetch specific activity items.
1016
  *
1017
+ * @since BuddyPress (1.2)
1018
  *
1019
+ * @see BP_Activity_Activity::get() For more information on accepted arguments
1020
  * @uses wp_parse_args()
1021
+ * @uses apply_filters() To call the 'bp_activity_get_specific' hook
1022
  * @uses BP_Activity_Activity::get() {@link BP_Activity_Activity}
1023
  *
1024
+ * @param array $args {
1025
  * All arguments and defaults are shared with BP_Activity_Activity::get(),
1026
  * except for the following:
1027
  * @type string|int|array Single activity ID, comma-separated list of IDs,
1028
+ * or array of IDs.
1029
  * }
1030
  * @return array $activity See BP_Activity_Activity::get() for description.
1031
  */
1032
  function bp_activity_get_specific( $args = '' ) {
1033
+ $defaults = array(
1034
+ 'activity_ids' => false, // A single activity_id or array of IDs.
1035
+ 'display_comments' => false, // true or false to display threaded comments for these specific activity items
1036
+ 'max' => false, // Maximum number of results to return
1037
+ 'page' => 1, // page 1 without a per_page will result in no pagination.
1038
+ 'per_page' => false, // results per page
1039
+ 'show_hidden' => true, // When fetching specific items, show all
1040
+ 'sort' => 'DESC', // sort ASC or DESC
1041
+ 'spam' => 'ham_only', // Retrieve items marked as spam
 
1042
  'update_meta_cache' => true,
1043
+ );
1044
+ $r = wp_parse_args( $args, $defaults );
1045
+ extract( $r, EXTR_SKIP );
1046
 
1047
  $get_args = array(
1048
+ 'page' => $page,
1049
+ 'per_page' => $per_page,
1050
+ 'max' => $max,
1051
+ 'sort' => $sort,
1052
+ 'display_comments' => $display_comments,
1053
+ 'show_hidden' => $show_hidden,
1054
+ 'in' => $activity_ids,
1055
+ 'spam' => $spam,
1056
+ 'update_meta_cache' => $update_meta_cache,
1057
  );
 
 
 
 
 
 
 
 
 
 
1058
  return apply_filters( 'bp_activity_get_specific', BP_Activity_Activity::get( $get_args ), $args, $get_args );
1059
  }
1060
 
1061
  /**
1062
  * Add an activity item.
1063
  *
1064
+ * @since BuddyPress (1.1)
1065
  *
1066
  * @uses wp_parse_args()
1067
  * @uses BP_Activity_Activity::save() {@link BP_Activity_Activity}
1068
  * @uses BP_Activity_Activity::rebuild_activity_comment_tree() {@link BP_Activity_Activity}
1069
  * @uses wp_cache_delete()
1070
+ * @uses do_action() To call the 'bp_activity_add' hook
1071
  *
1072
+ * @param array $args {
1073
  * An array of arguments.
1074
+ * @type int|bool $id Pass an activity ID to update an existing item, or
1075
+ * false to create a new item. Default: false.
1076
+ * @type string $action Optional. The activity action/description, typically
1077
+ * something like "Joe posted an update". Values passed to this param
1078
+ * will be stored in the database and used as a fallback for when the
1079
+ * activity item's format_callback cannot be found (eg, when the
1080
+ * component is disabled). As long as you have registered a
1081
+ * format_callback for your $type, it is unnecessary to include this
1082
+ * argument - BP will generate it automatically.
1083
+ * See {@link bp_activity_set_action()}.
1084
+ * @type string $content Optional. The content of the activity item.
1085
+ * @type string $component The unique name of the component associated with
1086
+ * the activity item - 'groups', 'profile', etc.
1087
+ * @type string $type The specific activity type, used for directory
1088
+ * filtering. 'new_blog_post', 'activity_update', etc.
1089
+ * @type string $primary_link Optional. The URL for this item, as used in
1090
+ * RSS feeds. Defaults to the URL for this activity item's permalink page.
1091
+ * @type int|bool $user_id Optional. The ID of the user associated with the
1092
+ * activity item. May be set to false or 0 if the item is not related
1093
+ * to any user. Default: the ID of the currently logged-in user.
1094
+ * @type int $item_id Optional. The ID of the associated item.
1095
+ * @type int $secondary_item_id Optional. The ID of a secondary associated
1096
+ * item.
1097
+ * @type string $date_recorded Optional. The GMT time, in Y-m-d h:i:s format,
1098
+ * when the item was recorded. Defaults to the current time.
1099
+ * @type bool $hide_sitewide Should the item be hidden on sitewide streams?
1100
+ * Default: false.
1101
+ * @type bool $is_spam Should the item be marked as spam? Default: false.
1102
  * }
1103
  * @return int|bool The ID of the activity on success. False on error.
1104
  */
1105
  function bp_activity_add( $args = '' ) {
1106
 
1107
+ $defaults = array(
1108
+ 'id' => false, // Pass an existing activity ID to update an existing entry.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1109
 
1110
+ 'action' => '', // The activity action - e.g. "Jon Doe posted an update"
1111
+ 'content' => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!"
 
1112
 
1113
+ 'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent
1114
+ 'type' => false, // The activity type e.g. activity_update, profile_updated
1115
+ 'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1116
 
1117
+ 'user_id' => bp_loggedin_user_id(), // Optional: The user to record the activity for, can be false if this activity is not for a user.
1118
+ 'item_id' => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id
1119
+ 'secondary_item_id' => false, // Optional: A second ID used to further filter e.g. a comment_id
1120
+ 'recorded_time' => bp_core_current_time(), // The GMT time that this activity was recorded
1121
+ 'hide_sitewide' => false, // Should this be hidden on the sitewide activity stream?
1122
+ 'is_spam' => false, // Is this activity item to be marked as spam?
1123
+ );
1124
+ $params = wp_parse_args( $args, $defaults );
1125
+ extract( $params, EXTR_SKIP );
1126
+
1127
+ // Make sure we are backwards compatible
1128
+ if ( empty( $component ) && !empty( $component_name ) )
1129
+ $component = $component_name;
1130
+
1131
+ if ( empty( $type ) && !empty( $component_action ) )
1132
+ $type = $component_action;
1133
+
1134
+ // Setup activity to be added
1135
+ $activity = new BP_Activity_Activity( $id );
1136
+ $activity->user_id = $user_id;
1137
+ $activity->component = $component;
1138
+ $activity->type = $type;
1139
+ $activity->content = $content;
1140
+ $activity->primary_link = $primary_link;
1141
+ $activity->item_id = $item_id;
1142
+ $activity->secondary_item_id = $secondary_item_id;
1143
+ $activity->date_recorded = $recorded_time;
1144
+ $activity->hide_sitewide = $hide_sitewide;
1145
+ $activity->is_spam = $is_spam;
1146
+ $activity->action = ! empty( $action ) ? $action : bp_activity_generate_action_string( $activity );
1147
+
1148
+ if ( !$activity->save() )
1149
+ return false;
1150
 
1151
+ // If this is an activity comment, rebuild the tree
1152
+ if ( 'activity_comment' == $activity->type )
1153
  BP_Activity_Activity::rebuild_activity_comment_tree( $activity->item_id );
 
1154
 
1155
  wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
1156
+ do_action( 'bp_activity_add', $params );
 
 
 
 
 
 
 
 
1157
 
1158
  return $activity->id;
1159
  }
1161
  /**
1162
  * Post an activity update.
1163
  *
1164
+ * @since BuddyPress (1.2)
1165
  *
1166
+ * @global object $bp BuddyPress global settings.
1167
  * @uses wp_parse_args()
1168
  * @uses bp_is_user_inactive()
1169
  * @uses bp_core_get_userlink()
1175
  * @uses wp_filter_kses()
1176
  * @uses do_action() To call the 'bp_activity_posted_update' hook.
1177
  *
1178
+ * @param array $args {
1179
  * @type string $content The content of the activity update.
1180
+ * @type int $user_id Optional. Defaults to the logged-in user.
1181
  * }
1182
+ * @return int $activity_id The activity id
1183
  */
1184
  function bp_activity_post_update( $args = '' ) {
1185
+ global $bp;
1186
 
1187
+ $defaults = array(
1188
  'content' => false,
1189
  'user_id' => bp_loggedin_user_id()
1190
+ );
1191
+ $r = wp_parse_args( $args, $defaults );
1192
+ extract( $r, EXTR_SKIP );
1193
 
1194
+ if ( empty( $content ) || !strlen( trim( $content ) ) )
1195
  return false;
 
1196
 
1197
+ if ( bp_is_user_inactive( $user_id ) )
1198
  return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1199
 
1200
+ // Record this on the user's profile
1201
+ $from_user_link = bp_core_get_userlink( $user_id );
1202
+ $activity_content = $content;
1203
+ $primary_link = bp_core_get_userlink( $user_id, false, true );
 
 
 
 
1204
 
1205
+ // Now write the values
1206
  $activity_id = bp_activity_add( array(
1207
+ 'user_id' => $user_id,
1208
+ 'content' => apply_filters( 'bp_activity_new_update_content', $activity_content ),
1209
+ 'primary_link' => apply_filters( 'bp_activity_new_update_primary_link', $primary_link ),
1210
+ 'component' => $bp->activity->id,
1211
  'type' => 'activity_update',
1212
  ) );
1213
 
1214
+ $activity_content = apply_filters( 'bp_activity_latest_update_content', $content, $activity_content );
 
 
 
 
 
 
 
 
1215
 
1216
  // Add this update to the "latest update" usermeta so it can be fetched anywhere.
1217
+ bp_update_user_meta( bp_loggedin_user_id(), 'bp_latest_update', array( 'id' => $activity_id, 'content' => $activity_content ) );
 
 
 
1218
 
1219
+ do_action( 'bp_activity_posted_update', $content, $user_id, $activity_id );
 
 
 
 
 
 
 
 
 
1220
 
1221
  return $activity_id;
1222
  }
1223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1224
  /**
1225
  * Add an activity comment.
1226
  *
1227
+ * @since BuddyPress (1.2)
1228
  *
1229
+ * @global object $bp BuddyPress global settings.
1230
  * @uses wp_parse_args()
1231
  * @uses bp_activity_add()
1232
  * @uses apply_filters() To call the 'bp_activity_comment_action' hook.
1233
  * @uses apply_filters() To call the 'bp_activity_comment_content' hook.
1234
+ * @uses bp_activity_new_comment_notification()
1235
  * @uses wp_cache_delete()
1236
  * @uses do_action() To call the 'bp_activity_comment_posted' hook.
1237
  *
1238
+ * @param array $args {
1239
+ * @type int $id Optional. Pass an ID to update an existing comment.
1240
+ * @type string $content The content of the comment.
1241
+ * @type int $user_id Optional. The ID of the user making the comment.
1242
+ * Defaults to the ID of the logged-in user.
1243
+ * @type int $activity_id The ID of the "root" activity item, ie the oldest
1244
+ * ancestor of the comment.
1245
+ * @type int $parent_id Optional. The ID of the parent activity item, ie the
1246
+ * item to which the comment is an immediate reply. If
1247
+ * not provided, this value defaults to the $activity_id.
1248
  * }
1249
  * @return int|bool The ID of the comment on success, otherwise false.
1250
  */
1251
  function bp_activity_new_comment( $args = '' ) {
 
 
 
1252
 
1253
+ $params = wp_parse_args( $args, array(
 
 
 
 
1254
  'id' => false,
1255
  'content' => false,
1256
  'user_id' => bp_loggedin_user_id(),
1257
+ 'activity_id' => false, // ID of the root activity item
1258
+ 'parent_id' => false // ID of a parent comment (optional)
1259
  ) );
1260
 
1261
+ extract( $params, EXTR_SKIP );
 
 
 
1262
 
1263
+ // Bail if missing necessary data
1264
+ if ( empty( $content ) || empty( $user_id ) || empty( $activity_id ) ) {
1265
  return false;
1266
  }
1267
 
1268
+ // Maybe set current activity ID as the parent
1269
+ if ( empty( $parent_id ) ) {
1270
+ $parent_id = $activity_id;
1271
  }
1272
 
1273
+ // Check to see if the parent activity is hidden, and if so, hide this comment publically.
 
 
1274
  $activity = new BP_Activity_Activity( $activity_id );
 
 
 
 
 
 
 
 
 
 
1275
  $is_hidden = ( (int) $activity->hide_sitewide ) ? 1 : 0;
1276
 
1277
+ // Insert the activity comment
 
 
 
 
 
 
 
 
 
1278
  $comment_id = bp_activity_add( array(
1279
+ 'id' => $id,
1280
+ 'content' => apply_filters( 'bp_activity_comment_content', $content ),
1281
  'component' => buddypress()->activity->id,
1282
  'type' => 'activity_comment',
1283
+ 'user_id' => $user_id,
1284
  'item_id' => $activity_id,
1285
+ 'secondary_item_id' => $parent_id,
1286
  'hide_sitewide' => $is_hidden
1287
  ) );
1288
 
1289
+ // Comment caches are stored only with the top-level item
1290
  wp_cache_delete( $activity_id, 'bp_activity_comments' );
1291
 
1292
+ // Walk the tree to clear caches for all parent items
1293
+ $clear_id = $parent_id;
1294
  while ( $clear_id != $activity_id ) {
1295
  $clear_object = new BP_Activity_Activity( $clear_id );
1296
  wp_cache_delete( $clear_id, 'bp_activity' );
1298
  }
1299
  wp_cache_delete( $activity_id, 'bp_activity' );
1300
 
1301
+ do_action( 'bp_activity_comment_posted', $comment_id, $params, $activity );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1302
 
1303
  return $comment_id;
1304
  }
1306
  /**
1307
  * Fetch the activity_id for an existing activity entry in the DB.
1308
  *
1309
+ * @since BuddyPress (1.2)
1310
  *
1311
  * @see BP_Activity_Activity::get() For more information on accepted arguments.
1312
  * @uses wp_parse_args()
1313
  * @uses apply_filters() To call the 'bp_activity_get_activity_id' hook.
1314
  * @uses BP_Activity_Activity::save() {@link BP_Activity_Activity}
1315
  *
1316
+ * @param array $args See BP_Activity_Activity::get() for description.
1317
  * @return int $activity_id The ID of the activity item found.
1318
  */
1319
  function bp_activity_get_activity_id( $args = '' ) {
1320
+ $defaults = array(
 
1321
  'user_id' => false,
1322
  'component' => false,
1323
  'type' => false,
1326
  'action' => false,
1327
  'content' => false,
1328
  'date_recorded' => false,
1329
+ );
1330
 
1331
+ $r = wp_parse_args( $args, $defaults );
1332
+ extract( $r, EXTR_SKIP );
1333
+
1334
+ return apply_filters( 'bp_activity_get_activity_id', BP_Activity_Activity::get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content, $date_recorded ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
1335
  }
1336
 
1337
  /**
1347
  *
1348
  * If you are deleting an activity comment please use bp_activity_delete_comment();
1349
  *
1350
+ * @since BuddyPress (1.0)
1351
  *
1352
  * @see BP_Activity_Activity::get() For more information on accepted arguments.
1353
  * @uses wp_parse_args()
1360
  * @uses do_action() To call the 'bp_activity_deleted_activities' hook.
1361
  * @uses wp_cache_delete()
1362
  *
1363
+ * @param array $args To delete specific activity items, use
1364
+ * $args = array( 'id' => $ids );
1365
+ * Otherwise, to use filters for item deletion, the argument format is
1366
+ * the same as BP_Activity_Activity::get(). See that method for a description.
 
1367
  * @return bool True on success, false on failure.
1368
  */
1369
  function bp_activity_delete( $args = '' ) {
1370
 
1371
+ // Pass one or more the of following variables to delete by those variables
1372
+ $defaults = array(
1373
  'id' => false,
1374
  'action' => false,
1375
  'content' => false,
1381
  'secondary_item_id' => false,
1382
  'date_recorded' => false,
1383
  'hide_sitewide' => false
1384
+ );
1385
+
1386
+ $args = wp_parse_args( $args, $defaults );
1387
 
 
 
 
 
 
 
 
1388
  do_action( 'bp_before_activity_delete', $args );
1389
 
1390
+ // Adjust the new mention count of any mentioned member
1391
  bp_activity_adjust_mention_count( $args['id'], 'delete' );
1392
 
1393
+ if ( !$activity_ids_deleted = BP_Activity_Activity::delete( $args ) )
 
1394
  return false;
 
1395
 
1396
+ // Check if the user's latest update has been deleted
1397
+ if ( empty( $args['user_id'] ) )
1398
+ $user_id = bp_loggedin_user_id();
1399
+ else
1400
+ $user_id = $args['user_id'];
1401
 
1402
  $latest_update = bp_get_user_meta( $user_id, 'bp_latest_update', true );
1403
  if ( !empty( $latest_update ) ) {
1406
  }
1407
  }
1408
 
 
 
 
 
 
 
 
1409
  do_action( 'bp_activity_delete', $args );
 
 
 
 
 
 
 
 
1410
  do_action( 'bp_activity_deleted_activities', $activity_ids_deleted );
1411
 
1412
  wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
1419
  *
1420
  * You should use bp_activity_delete() instead.
1421
  *
1422
+ * @since BuddyPress (1.1)
1423
+ * @deprecated BuddyPress (1.2)
1424
  *
1425
  * @uses wp_parse_args()
1426
  * @uses bp_activity_delete()
1427
  *
1428
+ * @param array $args See BP_Activity_Activity::get for a description
1429
+ * of accepted arguments.
1430
+ *
1431
  * @return bool True on success, false on failure.
1432
  */
1433
  function bp_activity_delete_by_item_id( $args = '' ) {
1434
 
1435
+ $defaults = array(
1436
  'item_id' => false,
1437
  'component' => false,
1438
  'type' => false,
1439
  'user_id' => false,
1440
  'secondary_item_id' => false
1441
+ );
1442
+ $r = wp_parse_args( $args, $defaults );
1443
+ extract( $r, EXTR_SKIP );
1444
 
1445
+ return bp_activity_delete( array( 'item_id' => $item_id, 'component' => $component, 'type' => $type, 'user_id' => $user_id, 'secondary_item_id' => $secondary_item_id ) );
1446
  }
1447
 
1448
  /**
1449
  * Delete an activity item by activity id.
1450
  *
1451
+ * @since BuddyPress (1.1)
1452
  *
1453
  * @uses bp_activity_delete()
1454
  *
1455
+ * @param int ID of the activity item to be deleted.
1456
  * @return bool True on success, false on failure.
1457
  */
1458
  function bp_activity_delete_by_activity_id( $activity_id ) {
1464
  *
1465
  * You should use bp_activity_delete() instead.
1466
  *
1467
+ * @since BuddyPress (1.1)
1468
+ * @deprecated BuddyPress (1.2)
1469
  *
1470
  * @uses bp_activity_delete()
1471
  *
1472
+ * @param int $user_id The user id.
1473
+ * @param string $content The activity id.
1474
  * @param string $component The activity component.
1475
+ * @param string $type The activity type.
1476
  * @return bool True on success, false on failure.
1477
  */
1478
  function bp_activity_delete_by_content( $user_id, $content, $component, $type ) {
1479
+ return bp_activity_delete( array( 'user_id' => $user_id, 'content' => $content, 'component' => $component, 'type' => $type ) );
 
 
 
 
 
1480
  }
1481
 
1482
  /**
1484
  *
1485
  * You should use bp_activity_delete() instead.
1486
  *
1487
+ * @since BuddyPress (1.1)
1488
+ * @deprecated BuddyPress (1.2)
1489
  *
1490
  * @uses bp_activity_delete()
1491
  *
1492
+ * @param int $user_id The user id.
1493
  * @param string $component The activity component.
1494
  * @return bool True on success, false on failure.
1495
  */
1496
  function bp_activity_delete_for_user_by_component( $user_id, $component ) {
1497
+ return bp_activity_delete( array( 'user_id' => $user_id, 'component' => $component ) );
 
 
 
1498
  }
1499
 
1500
  /**
1501
  * Delete an activity comment.
1502
  *
1503
+ * @since BuddyPress (1.2)
1504
  *
1505
  * @uses apply_filters() To call the 'bp_activity_delete_comment_pre' hook.
1506
  * @uses bp_activity_delete_children()
1514
  *
1515
  * @param int $activity_id The ID of the "root" activity, ie the comment's
1516
  * oldest ancestor.
1517
+ * @param int $comment_id The ID of the comment to be deleted.
1518
+ * @return bool True on success, false on failure
1519
  */
1520
  function bp_activity_delete_comment( $activity_id, $comment_id ) {
1521
+ /***
 
 
 
1522
  * You may want to hook into this filter if you want to override this function and
1523
  * handle the deletion of child comments differently. Make sure you return false.
 
 
 
 
 
 
1524
  */
1525
+ if ( !apply_filters( 'bp_activity_delete_comment_pre', true, $activity_id, $comment_id ) )
1526
  return false;
 
1527
 
1528
  // Delete any children of this comment.
1529
  bp_activity_delete_children( $activity_id, $comment_id );
1530
 
1531
+ // Delete the actual comment
1532
+ if ( !bp_activity_delete( array( 'id' => $comment_id, 'type' => 'activity_comment' ) ) )
1533
  return false;
 
1534
 
1535
+ // Recalculate the comment tree
 
 
 
1536
  BP_Activity_Activity::rebuild_activity_comment_tree( $activity_id );
1537
 
 
 
 
 
 
 
 
 
1538
  do_action( 'bp_activity_delete_comment', $activity_id, $comment_id );
1539
 
1540
  return true;
1543
  /**
1544
  * Delete an activity comment's children.
1545
  *
1546
+ * @since BuddyPress (1.2)
1547
  *
1548
  * @uses BP_Activity_Activity::get_child_comments() {@link BP_Activity_Activity}
1549
  * @uses bp_activity_delete_children()
1551
  *
1552
  * @param int $activity_id The ID of the "root" activity, ie the
1553
  * comment's oldest ancestor.
1554
+ * @param int $comment_id The ID of the comment to be deleted.
1555
  */
1556
+ function bp_activity_delete_children( $activity_id, $comment_id) {
 
 
 
 
1557
  // Recursively delete all children of this comment.
1558
+ if ( $children = BP_Activity_Activity::get_child_comments( $comment_id ) ) {
1559
  foreach( (array) $children as $child ) {
1560
  bp_activity_delete_children( $activity_id, $child->id );
1561
  }
1562
  }
1563
+ bp_activity_delete( array( 'secondary_item_id' => $comment_id, 'type' => 'activity_comment', 'item_id' => $activity_id ) );
 
 
 
 
 
 
1564
  }
1565
 
1566
  /**
1571
  * be sure to pass the full $activity_obj parameter as well, if you already
1572
  * have it available.
1573
  *
1574
+ * @since BuddyPress (1.2)
1575
  *
1576
  * @uses bp_get_root_domain()
1577
  * @uses bp_get_activity_root_slug()
1578
  * @uses apply_filters_ref_array() To call the 'bp_activity_get_permalink' hook.
1579
  *
1580
+ * @param int $activity_id The unique id of the activity object.
1581
+ * @param object $activity_obj Optional. The activity object.
1582
  * @return string $link Permalink for the activity item.
1583
  */
1584
  function bp_activity_get_permalink( $activity_id, $activity_obj = false ) {
 
1585
 
1586
+ if ( empty( $activity_obj ) )
1587
  $activity_obj = new BP_Activity_Activity( $activity_id );
 
1588
 
1589
  if ( isset( $activity_obj->current_comment ) ) {
1590
  $activity_obj = $activity_obj->current_comment;
1591
  }
1592
 
1593
+ if ( 'new_blog_post' == $activity_obj->type || 'new_blog_comment' == $activity_obj->type || 'new_forum_topic' == $activity_obj->type || 'new_forum_post' == $activity_obj->type ) {
 
 
 
 
 
 
 
 
 
 
 
1594
  $link = $activity_obj->primary_link;
1595
  } else {
1596
  if ( 'activity_comment' == $activity_obj->type ) {
1600
  }
1601
  }
1602
 
 
 
 
 
 
 
 
1603
  return apply_filters_ref_array( 'bp_activity_get_permalink', array( $link, &$activity_obj ) );
1604
  }
1605
 
1606
  /**
1607
  * Hide a user's activity.
1608
  *
1609
+ * @since BuddyPress (1.2)
1610
  *
1611
  * @uses BP_Activity_Activity::hide_all_for_user() {@link BP_Activity_Activity}
1612
  *
1627
  * through the content, grabs the first image and converts it to a thumbnail,
1628
  * and removes the rest of the images from the string.
1629
  *
1630
+ * @since BuddyPress (1.2)
 
 
1631
  *
1632
  * @uses esc_attr()
1633
+ * @uses apply_filters() To call the 'bp_activity_thumbnail_content_images' hook
1634
  *
1635
+ * @param string $content The content of the activity item.
1636
+ * @param string $link Optional. The unescaped URL that the image should link
1637
+ * to. If absent, the image will not be a link.
1638
+ * @param array $activity_args Optional. The args passed to the activity
1639
  * creation function (eg bp_blogs_record_activity()).
1640
  * @return string $content The content with images stripped and replaced with a
1641
  * single thumb.
1644
 
1645
  preg_match_all( '/<img[^>]*>/Ui', $content, $matches );
1646
 
1647
+ // Remove <img> tags. Also remove caption shortcodes and caption text if present
1648
  $content = preg_replace('|(\[caption(.*?)\])?<img[^>]*>([^\[\[]*\[\/caption\])?|', '', $content );
1649
 
1650
  if ( !empty( $matches ) && !empty( $matches[0] ) ) {
1651
+ // Get the SRC value
1652
+ preg_match( '/<img.*?(src\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $src );
1653
 
1654
+ // Get the width and height
 
 
 
1655
  preg_match( '/<img.*?(height\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $height );
1656
  preg_match( '/<img.*?(width\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $width );
1657
 
1658
+ if ( !empty( $src ) ) {
1659
+ $src = substr( substr( str_replace( 'src=', '', $src[1] ), 0, -1 ), 1 );
1660
+ $height = substr( substr( str_replace( 'height=', '', $height[1] ), 0, -1 ), 1 );
1661
+ $width = substr( substr( str_replace( 'width=', '', $width[1] ), 0, -1 ), 1 );
 
 
 
 
 
 
1662
 
1663
  if ( empty( $width ) || empty( $height ) ) {
1664
  $width = 100;
1678
  }
1679
  }
1680
 
 
 
 
 
 
 
 
 
 
1681
  return apply_filters( 'bp_activity_thumbnail_content_images', $content, $matches, $args );
1682
  }
1683
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1684
  /**
1685
  * Fetch whether the current user is allowed to mark items as spam.
1686
  *
1687
+ * @since BuddyPress (1.6)
1688
  *
1689
  * @return bool True if user is allowed to mark activity items as spam.
1690
  */
1691
  function bp_activity_user_can_mark_spam() {
 
 
 
 
 
 
 
 
1692
  return apply_filters( 'bp_activity_user_can_mark_spam', bp_current_user_can( 'bp_moderate' ) );
1693
  }
1694
 
1695
  /**
1696
  * Mark an activity item as spam.
1697
  *
1698
+ * @since BuddyPress (1.6)
1699
+ *
1700
+ * @global object $bp BuddyPress global settings.
1701
  *
1702
  * @param BP_Activity_Activity $activity The activity item to be spammed.
1703
+ * @param string $source Optional. Default is "by_a_person" (ie, a person has
1704
+ * manually marked the activity as spam). BP core also
1705
+ * accepts 'by_akismet'.
1706
  */
1707
  function bp_activity_mark_as_spam( &$activity, $source = 'by_a_person' ) {
1708
+ global $bp;
1709
 
1710
  $activity->is_spam = 1;
1711
 
1712
+ // Clear the activity stream first page cache
1713
  wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
1714
 
1715
+ // Clear the activity comment cache for this activity item
1716
  wp_cache_delete( $activity->id, 'bp_activity_comments' );
1717
 
1718
+ // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity
1719
  if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) {
1720
  remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4, 1 );
1721
 
1722
+ // Build data package for Akismet
1723
  $activity_data = BP_Akismet::build_akismet_data_package( $activity );
1724
 
1725
+ // Tell Akismet this is spam
1726
  $activity_data = $bp->activity->akismet->send_akismet_request( $activity_data, 'submit', 'spam' );
1727
 
1728
+ // Update meta
1729
  add_action( 'bp_activity_after_save', array( $bp->activity->akismet, 'update_activity_spam_meta' ), 1, 1 );
1730
  }
1731
 
 
 
 
 
 
 
 
 
 
1732
  do_action( 'bp_activity_mark_as_spam', $activity, $source );
1733
  }
1734
 
1735
  /**
1736
  * Mark an activity item as ham.
1737
  *
1738
+ * @since BuddyPress (1.6)
1739
  *
1740
+ * @global object $bp BuddyPress global settings.
1741
+ *
1742
+ * @param BP_Activity_Activity $activity The activity item to be hammed.
1743
+ * @param string $source Optional. Default is "by_a_person" (ie, a person has
1744
+ * manually marked the activity as spam). BP core also
1745
+ * accepts 'by_akismet'.
1746
  */
1747
  function bp_activity_mark_as_ham( &$activity, $source = 'by_a_person' ) {
1748
+ global $bp;
1749
 
1750
  $activity->is_spam = 0;
1751
 
1752
+ // Clear the activity stream first page cache
1753
  wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
1754
 
1755
+ // Clear the activity comment cache for this activity item
1756
  wp_cache_delete( $activity->id, 'bp_activity_comments' );
1757
 
1758
+ // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity
1759
  if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) {
1760
  remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4, 1 );
1761
 
1762
+ // Build data package for Akismet
1763
  $activity_data = BP_Akismet::build_akismet_data_package( $activity );
1764
 
1765
+ // Tell Akismet this is spam
1766
  $activity_data = $bp->activity->akismet->send_akismet_request( $activity_data, 'submit', 'ham' );
1767
 
1768
+ // Update meta
1769
  add_action( 'bp_activity_after_save', array( $bp->activity->akismet, 'update_activity_ham_meta' ), 1, 1 );
1770
  }
1771
 
 
 
 
 
 
 
 
 
 
1772
  do_action( 'bp_activity_mark_as_ham', $activity, $source );
1773
  }
1774
 
1785
  * This does not cover recursive activity comments, as they do not use a real loop.
1786
  * For that, see {@link bp_activity_comment_embed()}.
1787
  *
1788
+ * @since BuddyPress (1.5)
1789
  *
1790
  * @see BP_Embed
1791
  * @see bp_embed_activity_cache()
1792
  * @see bp_embed_activity_save_cache()
 
1793
  * @uses add_filter() To attach 'bp_get_activity_id' to 'embed_post_id'.
1794
  * @uses add_filter() To attach 'bp_embed_activity_cache' to 'bp_embed_get_cache'.
1795
  * @uses add_action() To attach 'bp_embed_activity_save_cache' to 'bp_embed_update_cache'.
1809
  * necessary to grab each comment's embeds from the cache, or put them in
1810
  * the cache if they are not there yet.
1811
  *
1812
+ * @since BuddyPress (1.5)
1813
  *
1814
  * @see BP_Embed
1815
  * @see bp_embed_activity_cache()
1816
  * @see bp_embed_activity_save_cache()
 
1817
  * @uses add_filter() To attach 'bp_get_activity_comment_id' to 'embed_post_id'.
1818
  * @uses add_filter() To attach 'bp_embed_activity_cache' to 'bp_embed_get_cache'.
1819
  * @uses add_action() To attach 'bp_embed_activity_save_cache' to 'bp_embed_update_cache'.
1828
  /**
1829
  * When a user clicks on a "Read More" item, make sure embeds are correctly parsed and shown for the expanded content.
1830
  *
1831
+ * @since BuddyPress (1.5)
1832
  *
1833
  * @see BP_Embed
1834
+ * @global object $bp BuddyPress global settings
1835
  * @uses add_filter() To attach create_function() to 'embed_post_id'.
1836
  * @uses add_filter() To attach 'bp_embed_activity_cache' to 'bp_embed_get_cache'.
1837
  * @uses add_action() To attach 'bp_embed_activity_save_cache' to 'bp_embed_update_cache'.
1839
  * @param object $activity The activity that is being expanded.
1840
  */
1841
  function bp_dtheme_embed_read_more( $activity ) {
1842
+ global $bp;
1843
 
1844
+ $bp->activity->read_more_id = $activity->id;
1845
+
1846
+ add_filter( 'embed_post_id', create_function( '', 'global $bp; return $bp->activity->read_more_id;' ) );
1847
+ add_filter( 'bp_embed_get_cache', 'bp_embed_activity_cache', 10, 3 );
1848
+ add_action( 'bp_embed_update_cache', 'bp_embed_activity_save_cache', 10, 3 );
1849
  }
1850
+ add_action( 'bp_dtheme_get_single_activity_content', 'bp_dtheme_embed_read_more' );
 
1851
 
1852
  /**
1853
  * Clean up 'embed_post_id' filter after comment recursion.
1855
  * This filter must be removed so that the non-comment filters take over again
1856
  * once the comments are done being processed.
1857
  *
1858
+ * @since BuddyPress (1.5)
1859
  *
1860
  * @see bp_activity_comment_embed()
1861
  * @uses remove_filter() To remove 'bp_get_activity_comment_id' from 'embed_post_id'.
1870
  *
1871
  * Used during {@link BP_Embed::parse_oembed()} via {@link bp_activity_embed()}.
1872
  *
1873
+ * @since BuddyPress (1.5)
1874
  *
1875
  * @see BP_Embed::parse_oembed()
1876
  * @uses bp_activity_get_meta()
1877
  *
1878
+ * @param string $cache An empty string passed by BP_Embed::parse_oembed() for
1879
+ * functions like this one to filter.
1880
+ * @param int $id The ID of the activity item.
1881
  * @param string $cachekey The cache key generated in BP_Embed::parse_oembed().
1882
  * @return mixed The cached embeds for this activity item.
1883
  */
1890
  *
1891
  * Used during {@link BP_Embed::parse_oembed()} via {@link bp_activity_embed()}.
1892
  *
1893
+ * @since BuddyPress (1.5)
1894
  *
1895
  * @see BP_Embed::parse_oembed()
1896
  * @uses bp_activity_update_meta()
1897
  *
1898
+ * @param string $cache An empty string passed by BP_Embed::parse_oembed() for
1899
+ * functions like this one to filter.
1900
+ * @param int $id The ID of the activity item.
1901
  * @param string $cachekey The cache key generated in BP_Embed::parse_oembed().
1902
+ * @return bool True on success, false on failure.
1903
  */
1904
  function bp_embed_activity_save_cache( $cache, $cachekey, $id ) {
1905
  bp_activity_update_meta( $id, $cachekey, $cache );
1908
  /**
1909
  * Should we use Heartbeat to refresh activities?
1910
  *
1911
+ * @since BuddyPress (2.0.0)
1912
  *
1913
+ * @uses bp_is_activity_heartbeat_active() to check if heatbeat setting is on.
1914
  * @uses bp_is_activity_directory() to check if the current page is the activity
1915
  * directory.
1916
+ * @uses bp_is_active() to check if the group component is active.
1917
  * @uses bp_is_group_activity() to check if on a single group, the current page
1918
  * is the group activities.
1919
+ * @uses bp_is_group_home() to check if the current page is a single group home
1920
+ * page.
1921
  *
1922
  * @return bool True if activity heartbeat is enabled, otherwise false.
1923
  */
1928
  return $retval;
1929
  }
1930
 
1931
+ if ( bp_is_activity_directory() ) {
1932
  $retval = true;
1933
  }
1934
 
1935
+ if ( bp_is_active( 'groups') ) {
1936
+ // If no custom front, then activities are loaded in group's home
1937
+ $has_custom_front = bp_locate_template( array( 'groups/single/front.php' ), false, true );
1938
+
1939
+ if ( bp_is_group_activity() || ( ! $has_custom_front && bp_is_group_home() ) ) {
1940
+ $retval = true;
1941
+ }
1942
+ }
1943
+
1944
  return $retval;
1945
  }
bp-activity/bp-activity-loader.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  /**
3
  * BuddyPress Activity Streams Loader.
4
  *
@@ -8,20 +9,20 @@
8
  * @subpackage ActivityCore
9
  */
10
 
11
- // Exit if accessed directly.
12
- defined( 'ABSPATH' ) || exit;
13
 
14
  /**
15
  * Main Activity Class.
16
  *
17
- * @since 1.5.0
18
  */
19
  class BP_Activity_Component extends BP_Component {
20
 
21
  /**
22
  * Start the activity component setup process.
23
  *
24
- * @since 1.5.0
25
  */
26
  public function __construct() {
27
  parent::start(
@@ -29,8 +30,7 @@ class BP_Activity_Component extends BP_Component {
29
  __( 'Activity Streams', 'buddypress' ),
30
  buddypress()->plugin_dir,
31
  array(
32
- 'adminbar_myaccount_order' => 10,
33
- 'search_query_arg' => 'activity_search',
34
  )
35
  );
36
  }
@@ -38,17 +38,15 @@ class BP_Activity_Component extends BP_Component {
38
  /**
39
  * Include component files.
40
  *
41
- * @since 1.5.0
42
  *
43
  * @see BP_Component::includes() for a description of arguments.
44
  *
45
  * @param array $includes See BP_Component::includes() for a description.
46
  */
47
  public function includes( $includes = array() ) {
48
-
49
- // Files to include.
50
  $includes = array(
51
- 'cssjs',
52
  'actions',
53
  'screens',
54
  'filters',
@@ -59,11 +57,9 @@ class BP_Activity_Component extends BP_Component {
59
  'cache'
60
  );
61
 
62
- // Load Akismet support if Akismet is configured.
63
  $akismet_key = bp_get_option( 'wordpress_api_key' );
64
-
65
- /** This filter is documented in bp-activity/bp-activity-actions.php */
66
- if ( defined( 'AKISMET_VERSION' ) && class_exists( 'Akismet' ) && ( ! empty( $akismet_key ) || defined( 'WPCOM_API_KEY' ) ) && apply_filters( 'bp_activity_use_akismet', bp_is_akismet_active() ) ) {
67
  $includes[] = 'akismet';
68
  }
69
 
@@ -80,7 +76,7 @@ class BP_Activity_Component extends BP_Component {
80
  * The BP_ACTIVITY_SLUG constant is deprecated, and only used here for
81
  * backwards compatibility.
82
  *
83
- * @since 1.5.0
84
  *
85
  * @see BP_Component::setup_globals() for a description of arguments.
86
  *
@@ -89,18 +85,17 @@ class BP_Activity_Component extends BP_Component {
89
  public function setup_globals( $args = array() ) {
90
  $bp = buddypress();
91
 
92
- // Define a slug, if necessary.
93
- if ( ! defined( 'BP_ACTIVITY_SLUG' ) ) {
94
  define( 'BP_ACTIVITY_SLUG', $this->id );
95
- }
96
 
97
- // Global tables for activity component.
98
  $global_tables = array(
99
  'table_name' => $bp->table_prefix . 'bp_activity',
100
  'table_name_meta' => $bp->table_prefix . 'bp_activity_meta',
101
  );
102
 
103
- // Metadata tables for groups component.
104
  $meta_tables = array(
105
  'activity' => $bp->table_prefix . 'bp_activity_meta',
106
  );
@@ -111,7 +106,7 @@ class BP_Activity_Component extends BP_Component {
111
  'slug' => BP_ACTIVITY_SLUG,
112
  'root_slug' => isset( $bp->pages->activity->slug ) ? $bp->pages->activity->slug : BP_ACTIVITY_SLUG,
113
  'has_directory' => true,
114
- 'directory_title' => _x( 'Site-Wide Activity', 'component directory title', 'buddypress' ),
115
  'notification_callback' => 'bp_activity_format_notifications',
116
  'search_string' => __( 'Search Activity...', 'buddypress' ),
117
  'global_tables' => $global_tables,
@@ -124,7 +119,7 @@ class BP_Activity_Component extends BP_Component {
124
  /**
125
  * Set up component navigation.
126
  *
127
- * @since 1.5.0
128
  *
129
  * @see BP_Component::setup_nav() for a description of arguments.
130
  * @uses bp_is_active()
@@ -132,17 +127,28 @@ class BP_Activity_Component extends BP_Component {
132
  * @uses bp_get_friends_slug()
133
  * @uses bp_get_groups_slug()
134
  *
135
- * @param array $main_nav Optional. See BP_Component::setup_nav() for description.
136
- * @param array $sub_nav Optional. See BP_Component::setup_nav() for description.
 
 
137
  */
138
  public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
139
 
140
- // Stop if there is no user displayed or logged in.
141
- if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) {
 
 
 
 
 
 
 
 
 
 
142
  return;
143
- }
144
 
145
- // Determine user to use.
146
  if ( bp_displayed_user_domain() ) {
147
  $user_domain = bp_displayed_user_domain();
148
  } elseif ( bp_loggedin_user_domain() ) {
@@ -151,75 +157,63 @@ class BP_Activity_Component extends BP_Component {
151
  return;
152
  }
153
 
154
- $slug = bp_get_activity_slug();
155
- $activity_link = trailingslashit( $user_domain . $slug );
156
 
157
- // Add 'Activity' to the main navigation.
158
- $main_nav = array(
159
- 'name' => _x( 'Activity', 'Profile activity screen nav', 'buddypress' ),
160
- 'slug' => $slug,
161
- 'position' => 10,
162
- 'screen_function' => 'bp_activity_screen_my_activity',
163
- 'default_subnav_slug' => 'just-me',
164
- 'item_css_id' => $this->id
165
- );
166
-
167
- // Add the subnav items to the activity nav item if we are using a theme that supports this.
168
  $sub_nav[] = array(
169
- 'name' => _x( 'Personal', 'Profile activity screen sub nav', 'buddypress' ),
170
  'slug' => 'just-me',
171
  'parent_url' => $activity_link,
172
- 'parent_slug' => $slug,
173
  'screen_function' => 'bp_activity_screen_my_activity',
174
  'position' => 10
175
  );
176
 
177
- // Check @mentions.
178
  if ( bp_activity_do_mentions() ) {
179
  $sub_nav[] = array(
180
- 'name' => _x( 'Mentions', 'Profile activity screen sub nav', 'buddypress' ),
181
  'slug' => 'mentions',
182
  'parent_url' => $activity_link,
183
- 'parent_slug' => $slug,
184
  'screen_function' => 'bp_activity_screen_mentions',
185
  'position' => 20,
186
  'item_css_id' => 'activity-mentions'
187
  );
188
  }
189
 
190
- // Favorite activity items.
191
- if ( bp_activity_can_favorite() ) {
192
- $sub_nav[] = array(
193
- 'name' => _x( 'Favorites', 'Profile activity screen sub nav', 'buddypress' ),
194
- 'slug' => 'favorites',
195
- 'parent_url' => $activity_link,
196
- 'parent_slug' => $slug,
197
- 'screen_function' => 'bp_activity_screen_favorites',
198
- 'position' => 30,
199
- 'item_css_id' => 'activity-favs'
200
- );
201
- }
202
 
203
- // Additional menu if friends is active.
204
  if ( bp_is_active( 'friends' ) ) {
205
  $sub_nav[] = array(
206
- 'name' => _x( 'Friends', 'Profile activity screen sub nav', 'buddypress' ),
207
  'slug' => bp_get_friends_slug(),
208
  'parent_url' => $activity_link,
209
- 'parent_slug' => $slug,
210
  'screen_function' => 'bp_activity_screen_friends',
211
  'position' => 40,
212
  'item_css_id' => 'activity-friends'
213
  ) ;
214
  }
215
 
216
- // Additional menu if groups is active.
217
  if ( bp_is_active( 'groups' ) ) {
218
  $sub_nav[] = array(
219
- 'name' => _x( 'Groups', 'Profile activity screen sub nav', 'buddypress' ),
220
  'slug' => bp_get_groups_slug(),
221
  'parent_url' => $activity_link,
222
- 'parent_slug' => $slug,
223
  'screen_function' => 'bp_activity_screen_groups',
224
  'position' => 50,
225
  'item_css_id' => 'activity-groups'
@@ -232,7 +226,7 @@ class BP_Activity_Component extends BP_Component {
232
  /**
233
  * Set up the component entries in the WordPress Admin Bar.
234
  *
235
- * @since 1.5.0
236
  *
237
  * @see BP_Component::setup_nav() for a description of the $wp_admin_nav
238
  * parameter array.
@@ -248,40 +242,42 @@ class BP_Activity_Component extends BP_Component {
248
  * description.
249
  */
250
  public function setup_admin_bar( $wp_admin_nav = array() ) {
 
251
 
252
- // Menus for logged in user.
253
  if ( is_user_logged_in() ) {
254
 
255
- // Setup the logged in user variables.
256
- $activity_link = trailingslashit( bp_loggedin_user_domain() . bp_get_activity_slug() );
 
257
 
258
- // Unread message count.
259
  if ( bp_activity_do_mentions() ) {
260
  $count = bp_get_total_mention_count_for_user( bp_loggedin_user_id() );
261
  if ( !empty( $count ) ) {
262
- $title = sprintf( _x( 'Mentions <span class="count">%s</span>', 'Toolbar Mention logged in user', 'buddypress' ), bp_core_number_format( $count ) );
263
  } else {
264
- $title = _x( 'Mentions', 'Toolbar Mention logged in user', 'buddypress' );
265
  }
266
  }
267
 
268
- // Add the "Activity" sub menu.
269
  $wp_admin_nav[] = array(
270
- 'parent' => buddypress()->my_account_menu_id,
271
  'id' => 'my-account-' . $this->id,
272
- 'title' => _x( 'Activity', 'My Account Activity sub nav', 'buddypress' ),
273
- 'href' => $activity_link
274
  );
275
 
276
- // Personal.
277
  $wp_admin_nav[] = array(
278
  'parent' => 'my-account-' . $this->id,
279
  'id' => 'my-account-' . $this->id . '-personal',
280
- 'title' => _x( 'Personal', 'My Account Activity sub nav', 'buddypress' ),
281
- 'href' => $activity_link
282
  );
283
 
284
- // Mentions.
285
  if ( bp_activity_do_mentions() ) {
286
  $wp_admin_nav[] = array(
287
  'parent' => 'my-account-' . $this->id,
@@ -291,22 +287,20 @@ class BP_Activity_Component extends BP_Component {
291
  );
292
  }
293
 
294
- // Favorite activity items.
295
- if ( bp_activity_can_favorite() ) {
296
- $wp_admin_nav[] = array(
297
- 'parent' => 'my-account-' . $this->id,
298
- 'id' => 'my-account-' . $this->id . '-favorites',
299
- 'title' => _x( 'Favorites', 'My Account Activity sub nav', 'buddypress' ),
300
- 'href' => trailingslashit( $activity_link . 'favorites' )
301
- );
302
- }
303
 
304
  // Friends?
305
  if ( bp_is_active( 'friends' ) ) {
306
  $wp_admin_nav[] = array(
307
  'parent' => 'my-account-' . $this->id,
308
  'id' => 'my-account-' . $this->id . '-friends',
309
- 'title' => _x( 'Friends', 'My Account Activity sub nav', 'buddypress' ),
310
  'href' => trailingslashit( $activity_link . bp_get_friends_slug() )
311
  );
312
  }
@@ -316,7 +310,7 @@ class BP_Activity_Component extends BP_Component {
316
  $wp_admin_nav[] = array(
317
  'parent' => 'my-account-' . $this->id,
318
  'id' => 'my-account-' . $this->id . '-groups',
319
- 'title' => _x( 'Groups', 'My Account Activity sub nav', 'buddypress' ),
320
  'href' => trailingslashit( $activity_link . bp_get_groups_slug() )
321
  );
322
  }
@@ -328,20 +322,19 @@ class BP_Activity_Component extends BP_Component {
328
  /**
329
  * Set up the title for pages and <title>.
330
  *
331
- * @since 1.5.0
332
  *
333
  * @uses bp_is_activity_component()
334
  * @uses bp_is_my_profile()
335
  * @uses bp_core_fetch_avatar()
336
  */
337
  public function setup_title() {
 
338
 
339
- // Adjust title based on view.
340
  if ( bp_is_activity_component() ) {
341
- $bp = buddypress();
342
-
343
  if ( bp_is_my_profile() ) {
344
- $bp->bp_options_title = _x( 'My Activity', 'Page and <title>', 'buddypress' );
345
  } else {
346
  $bp->bp_options_avatar = bp_core_fetch_avatar( array(
347
  'item_id' => bp_displayed_user_id(),
@@ -358,32 +351,14 @@ class BP_Activity_Component extends BP_Component {
358
  /**
359
  * Set up actions necessary for the component.
360
  *
361
- * @since 1.6.0
362
  */
363
  public function setup_actions() {
364
-
365
- // Spam prevention.
366
  add_action( 'bp_include', 'bp_activity_setup_akismet' );
367
 
368
  parent::setup_actions();
369
  }
370
-
371
- /**
372
- * Setup cache groups.
373
- *
374
- * @since 2.2.0
375
- */
376
- public function setup_cache_groups() {
377
-
378
- // Global groups.
379
- wp_cache_add_global_groups( array(
380
- 'bp_activity',
381
- 'bp_activity_comments',
382
- 'activity_meta'
383
- ) );
384
-
385
- parent::setup_cache_groups();
386
- }
387
  }
388
 
389
  /**
1
  <?php
2
+
3
  /**
4
  * BuddyPress Activity Streams Loader.
5
  *
9
  * @subpackage ActivityCore
10
  */
11
 
12
+ // Exit if accessed directly
13
+ if ( !defined( 'ABSPATH' ) ) exit;
14
 
15
  /**
16
  * Main Activity Class.
17
  *
18
+ * @since BuddyPress (1.5)
19
  */
20
  class BP_Activity_Component extends BP_Component {
21
 
22
  /**
23
  * Start the activity component setup process.
24
  *
25
+ * @since BuddyPress (1.5)
26
  */
27
  public function __construct() {
28
  parent::start(
30
  __( 'Activity Streams', 'buddypress' ),
31
  buddypress()->plugin_dir,
32
  array(
33
+ 'adminbar_myaccount_order' => 10
 
34
  )
35
  );
36
  }
38
  /**
39
  * Include component files.
40
  *
41
+ * @since BuddyPress (1.5)
42
  *
43
  * @see BP_Component::includes() for a description of arguments.
44
  *
45
  * @param array $includes See BP_Component::includes() for a description.
46
  */
47
  public function includes( $includes = array() ) {
48
+ // Files to include
 
49
  $includes = array(
 
50
  'actions',
51
  'screens',
52
  'filters',
57
  'cache'
58
  );
59
 
60
+ // Load Akismet support if Akismet is configured
61
  $akismet_key = bp_get_option( 'wordpress_api_key' );
62
+ if ( defined( 'AKISMET_VERSION' ) && ( !empty( $akismet_key ) || defined( 'WPCOM_API_KEY' ) ) && apply_filters( 'bp_activity_use_akismet', bp_is_akismet_active() ) ) {
 
 
63
  $includes[] = 'akismet';
64
  }
65
 
76
  * The BP_ACTIVITY_SLUG constant is deprecated, and only used here for
77
  * backwards compatibility.
78
  *
79
+ * @since BuddyPress (1.5)
80
  *
81
  * @see BP_Component::setup_globals() for a description of arguments.
82
  *
85
  public function setup_globals( $args = array() ) {
86
  $bp = buddypress();
87
 
88
+ // Define a slug, if necessary
89
+ if ( !defined( 'BP_ACTIVITY_SLUG' ) )
90
  define( 'BP_ACTIVITY_SLUG', $this->id );
 
91
 
92
+ // Global tables for activity component
93
  $global_tables = array(
94
  'table_name' => $bp->table_prefix . 'bp_activity',
95
  'table_name_meta' => $bp->table_prefix . 'bp_activity_meta',
96
  );
97
 
98
+ // Metadata tables for groups component
99
  $meta_tables = array(
100
  'activity' => $bp->table_prefix . 'bp_activity_meta',
101
  );
106
  'slug' => BP_ACTIVITY_SLUG,
107
  'root_slug' => isset( $bp->pages->activity->slug ) ? $bp->pages->activity->slug : BP_ACTIVITY_SLUG,
108
  'has_directory' => true,
109
+ 'directory_title' => _x( 'Sitewide Activity', 'component directory title', 'buddypress' ),
110
  'notification_callback' => 'bp_activity_format_notifications',
111
  'search_string' => __( 'Search Activity...', 'buddypress' ),
112
  'global_tables' => $global_tables,
119
  /**
120
  * Set up component navigation.
121
  *
122
+ * @since BuddyPress (1.5)
123
  *
124
  * @see BP_Component::setup_nav() for a description of arguments.
125
  * @uses bp_is_active()
127
  * @uses bp_get_friends_slug()
128
  * @uses bp_get_groups_slug()
129
  *
130
+ * @param array $main_nav Optional. See BP_Component::setup_nav() for
131
+ * description.
132
+ * @param array $sub_nav Optional. See BP_Component::setup_nav() for
133
+ * description.
134
  */
135
  public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
136
 
137
+ // Add 'Activity' to the main navigation
138
+ $main_nav = array(
139
+ 'name' => __( 'Activity', 'buddypress' ),
140
+ 'slug' => $this->slug,
141
+ 'position' => 10,
142
+ 'screen_function' => 'bp_activity_screen_my_activity',
143
+ 'default_subnav_slug' => 'just-me',
144
+ 'item_css_id' => $this->id
145
+ );
146
+
147
+ // Stop if there is no user displayed or logged in
148
+ if ( !is_user_logged_in() && !bp_displayed_user_id() )
149
  return;
 
150
 
151
+ // Determine user to use
152
  if ( bp_displayed_user_domain() ) {
153
  $user_domain = bp_displayed_user_domain();
154
  } elseif ( bp_loggedin_user_domain() ) {
157
  return;
158
  }
159
 
160
+ // User link
161
+ $activity_link = trailingslashit( $user_domain . $this->slug );
162
 
163
+ // Add the subnav items to the activity nav item if we are using a theme that supports this
 
 
 
 
 
 
 
 
 
 
164
  $sub_nav[] = array(
165
+ 'name' => __( 'Personal', 'buddypress' ),
166
  'slug' => 'just-me',
167
  'parent_url' => $activity_link,
168
+ 'parent_slug' => $this->slug,
169
  'screen_function' => 'bp_activity_screen_my_activity',
170
  'position' => 10
171
  );
172
 
173
+ // @ mentions
174
  if ( bp_activity_do_mentions() ) {
175
  $sub_nav[] = array(
176
+ 'name' => __( 'Mentions', 'buddypress' ),
177
  'slug' => 'mentions',
178
  'parent_url' => $activity_link,
179
+ 'parent_slug' => $this->slug,
180
  'screen_function' => 'bp_activity_screen_mentions',
181
  'position' => 20,
182
  'item_css_id' => 'activity-mentions'
183
  );
184
  }
185
 
186
+ // Favorite activity items
187
+ $sub_nav[] = array(
188
+ 'name' => __( 'Favorites', 'buddypress' ),
189
+ 'slug' => 'favorites',
190
+ 'parent_url' => $activity_link,
191
+ 'parent_slug' => $this->slug,
192
+ 'screen_function' => 'bp_activity_screen_favorites',
193
+ 'position' => 30,
194
+ 'item_css_id' => 'activity-favs'
195
+ );
 
 
196
 
197
+ // Additional menu if friends is active
198
  if ( bp_is_active( 'friends' ) ) {
199
  $sub_nav[] = array(
200
+ 'name' => __( 'Friends', 'buddypress' ),
201
  'slug' => bp_get_friends_slug(),
202
  'parent_url' => $activity_link,
203
+ 'parent_slug' => $this->slug,
204
  'screen_function' => 'bp_activity_screen_friends',
205
  'position' => 40,
206
  'item_css_id' => 'activity-friends'
207
  ) ;
208
  }
209
 
210
+ // Additional menu if groups is active
211
  if ( bp_is_active( 'groups' ) ) {
212
  $sub_nav[] = array(
213
+ 'name' => __( 'Groups', 'buddypress' ),
214
  'slug' => bp_get_groups_slug(),
215
  'parent_url' => $activity_link,
216
+ 'parent_slug' => $this->slug,
217
  'screen_function' => 'bp_activity_screen_groups',
218
  'position' => 50,
219
  'item_css_id' => 'activity-groups'
226
  /**
227
  * Set up the component entries in the WordPress Admin Bar.
228
  *
229
+ * @since BuddyPress (1.5)
230
  *
231
  * @see BP_Component::setup_nav() for a description of the $wp_admin_nav
232
  * parameter array.
242
  * description.
243
  */
244
  public function setup_admin_bar( $wp_admin_nav = array() ) {
245
+ $bp = buddypress();
246
 
247
+ // Menus for logged in user
248
  if ( is_user_logged_in() ) {
249
 
250
+ // Setup the logged in user variables
251
+ $user_domain = bp_loggedin_user_domain();
252
+ $activity_link = trailingslashit( $user_domain . $this->slug );
253
 
254
+ // Unread message count
255
  if ( bp_activity_do_mentions() ) {
256
  $count = bp_get_total_mention_count_for_user( bp_loggedin_user_id() );
257
  if ( !empty( $count ) ) {
258
+ $title = sprintf( __( 'Mentions <span class="count">%s</span>', 'buddypress' ), number_format_i18n( $count ) );
259
  } else {
260
+ $title = __( 'Mentions', 'buddypress' );
261
  }
262
  }
263
 
264
+ // Add the "Activity" sub menu
265
  $wp_admin_nav[] = array(
266
+ 'parent' => $bp->my_account_menu_id,
267
  'id' => 'my-account-' . $this->id,
268
+ 'title' => __( 'Activity', 'buddypress' ),
269
+ 'href' => trailingslashit( $activity_link )
270
  );
271
 
272
+ // Personal
273
  $wp_admin_nav[] = array(
274
  'parent' => 'my-account-' . $this->id,
275
  'id' => 'my-account-' . $this->id . '-personal',
276
+ 'title' => __( 'Personal', 'buddypress' ),
277
+ 'href' => trailingslashit( $activity_link )
278
  );
279
 
280
+ // Mentions
281
  if ( bp_activity_do_mentions() ) {
282
  $wp_admin_nav[] = array(
283
  'parent' => 'my-account-' . $this->id,
287
  );
288
  }
289
 
290
+ // Favorites
291
+ $wp_admin_nav[] = array(
292
+ 'parent' => 'my-account-' . $this->id,
293
+ 'id' => 'my-account-' . $this->id . '-favorites',
294
+ 'title' => __( 'Favorites', 'buddypress' ),
295
+ 'href' => trailingslashit( $activity_link . 'favorites' )
296
+ );
 
 
297
 
298
  // Friends?
299
  if ( bp_is_active( 'friends' ) ) {
300
  $wp_admin_nav[] = array(
301
  'parent' => 'my-account-' . $this->id,
302
  'id' => 'my-account-' . $this->id . '-friends',
303
+ 'title' => __( 'Friends', 'buddypress' ),
304
  'href' => trailingslashit( $activity_link . bp_get_friends_slug() )
305
  );
306
  }
310
  $wp_admin_nav[] = array(
311
  'parent' => 'my-account-' . $this->id,
312
  'id' => 'my-account-' . $this->id . '-groups',
313
+ 'title' => __( 'Groups', 'buddypress' ),
314
  'href' => trailingslashit( $activity_link . bp_get_groups_slug() )
315
  );
316
  }
322
  /**
323
  * Set up the title for pages and <title>.
324
  *
325
+ * @since BuddyPress (1.5)
326
  *
327
  * @uses bp_is_activity_component()
328
  * @uses bp_is_my_profile()
329
  * @uses bp_core_fetch_avatar()
330
  */
331
  public function setup_title() {
332
+ $bp = buddypress();
333
 
334
+ // Adjust title based on view
335
  if ( bp_is_activity_component() ) {
 
 
336
  if ( bp_is_my_profile() ) {
337
+ $bp->bp_options_title = __( 'My Activity', 'buddypress' );
338
  } else {
339
  $bp->bp_options_avatar = bp_core_fetch_avatar( array(
340
  'item_id' => bp_displayed_user_id(),
351
  /**
352
  * Set up actions necessary for the component.
353
  *
354
+ * @since BuddyPress (1.6)
355
  */
356
  public function setup_actions() {
357
+ // Spam prevention
 
358
  add_action( 'bp_include', 'bp_activity_setup_akismet' );
359
 
360
  parent::setup_actions();
361
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
362
  }
363
 
364
  /**
bp-activity/bp-activity-notifications.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  /**
3
  * BuddyPress Activity Notifications.
4
  *
@@ -6,15 +7,15 @@
6
  * @subpackage ActivityNotifications
7
  */
8
 
9
- // Exit if accessed directly.
10
- defined( 'ABSPATH' ) || exit;
11
 
12
  /* Emails *********************************************************************/
13
 
14
  /**
15
  * Send email and BP notifications when a user is mentioned in an update.
16
  *
17
- * @since 1.2.0
18
  *
19
  * @uses bp_notifications_add_notification()
20
  * @uses bp_get_user_meta()
@@ -33,14 +34,14 @@ defined( 'ABSPATH' ) || exit;
33
  * @uses apply_filters() To call the 'bp_activity_at_message_notification_subject' hook.
34
  * @uses apply_filters() To call the 'bp_activity_at_message_notification_message' hook.
35
  * @uses wp_mail()
36
- * @uses do_action() To call the 'bp_activity_sent_mention_email' hook.
37
  *
38
- * @param int $activity_id The ID of the activity update.
39
  * @param int $receiver_user_id The ID of the user who is receiving the update.
40
  */
41
  function bp_activity_at_message_notification( $activity_id, $receiver_user_id ) {
42
 
43
- // Don't leave multiple notifications for the same activity item.
44
  $notifications = BP_Core_Notification::get_all_for_user( $receiver_user_id, 'all' );
45
 
46
  foreach( $notifications as $notification ) {
@@ -55,7 +56,7 @@ function bp_activity_at_message_notification( $activity_id, $receiver_user_id )
55
  $message = '';
56
  $content = '';
57
 
58
- // Now email the user with the contents of the message (if they have enabled email notifications).
59
  if ( 'no' != bp_get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) {
60
  $poster_name = bp_core_get_user_displayname( $activity->user_id );
61
 
@@ -66,7 +67,7 @@ function bp_activity_at_message_notification( $activity_id, $receiver_user_id )
66
  $poster_name = stripslashes( $poster_name );
67
  $content = bp_activity_filter_kses( strip_tags( stripslashes( $activity->content ) ) );
68
 
69
- // Set up and send the message.
70
  $ud = bp_core_get_core_userdata( $receiver_user_id );
71
  $to = $ud->user_email;
72
  $subject = bp_get_email_subject( array( 'text' => sprintf( __( '%s mentioned you in an update', 'buddypress' ), $poster_name ) ) );
@@ -93,64 +94,26 @@ To view and respond to the message, log in and visit: %3$s
93
  ', 'buddypress' ), $poster_name, $content, $message_link );
94
  }
95
 
96
- // Only show the disable notifications line if the settings component is enabled.
97
  if ( bp_is_active( 'settings' ) ) {
98
  $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
99
  }
100
 
101
- /**
102
- * Filters the user email that the @mention notification will be sent to.
103
- *
104
- * @since 1.2.0
105
- *
106
- * @param string $to User email the notification is being sent to.
107
- */
108
  $to = apply_filters( 'bp_activity_at_message_notification_to', $to );
109
-
110
- /**
111
- * Filters the @mention notification subject that will be sent to user.
112
- *
113
- * @since 1.2.0
114
- *
115
- * @param string $subject Email notification subject text.
116
- * @param string $poster_name Name of the person who made the @mention.
117
- */
118
  $subject = apply_filters( 'bp_activity_at_message_notification_subject', $subject, $poster_name );
119
-
120
- /**
121
- * Filters the @mention notification message that will be sent to user.
122
- *
123
- * @since 1.2.0
124
- *
125
- * @param string $message Email notification message text.
126
- * @param string $poster_name Name of the person who made the @mention.
127
- * @param string $content Content of the @mention.
128
- * @param string $message_link URL permalink for the activity message.
129
- * @param string $settings_link URL permalink for the user's notification settings area.
130
- */
131
  $message = apply_filters( 'bp_activity_at_message_notification_message', $message, $poster_name, $content, $message_link, $settings_link );
132
 
133
  wp_mail( $to, $subject, $message );
134
  }
135
 
136
- /**
137
- * Fires after the sending of an @mention email notification.
138
- *
139
- * @since 1.5.0
140
- *
141
- * @param BP_Activity_Activity $activity Activity Item object.
142
- * @param string $subject Email notification subject text.
143
- * @param string $message Email notification message text.
144
- * @param string $content Content of the @mention.
145
- * @param int $receiver_user_id The ID of the user who is receiving the update.
146
- */
147
  do_action( 'bp_activity_sent_mention_email', $activity, $subject, $message, $content, $receiver_user_id );
148
  }
149
 
150
  /**
151
  * Send email and BP notifications when an activity item receives a comment.
152
  *
153
- * @since 1.2.0
154
  *
155
  * @uses bp_get_user_meta()
156
  * @uses bp_core_get_user_displayname()
@@ -162,24 +125,23 @@ To view and respond to the message, log in and visit: %3$s
162
  * @uses wp_specialchars_decode()
163
  * @uses get_blog_option()
164
  * @uses bp_get_root_blog_id()
165
- * @uses apply_filters() To call the 'bp_activity_new_comment_notification_to' hook.
166
- * @uses apply_filters() To call the 'bp_activity_new_comment_notification_subject' hook.
167
- * @uses apply_filters() To call the 'bp_activity_new_comment_notification_message' hook.
168
  * @uses wp_mail()
169
- * @uses do_action() To call the 'bp_activity_sent_reply_to_update_email' hook.
170
- * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_to' hook.
171
- * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_subject' hook.
172
- * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_message' hook.
173
- * @uses do_action() To call the 'bp_activity_sent_reply_to_reply_email' hook.
174
  *
175
- * @param int $comment_id The comment id.
176
- * @param int $commenter_id The ID of the user who posted the comment.
177
- * @param array $params {@link bp_activity_new_comment()}.
178
- * @return bool
179
  */
180
  function bp_activity_new_comment_notification( $comment_id = 0, $commenter_id = 0, $params = array() ) {
181
 
182
- // Set some default parameters.
183
  $activity_id = 0;
184
  $parent_id = 0;
185
 
@@ -196,7 +158,7 @@ function bp_activity_new_comment_notification( $comment_id = 0, $commenter_id =
196
  $poster_name = stripslashes( $poster_name );
197
  $content = bp_activity_filter_kses( stripslashes($content) );
198
 
199
- // Set up and send the message.
200
  $ud = bp_core_get_core_userdata( $original_activity->user_id );
201
  $to = $ud->user_email;
202
  $subject = bp_get_email_subject( array( 'text' => sprintf( __( '%s replied to one of your updates', 'buddypress' ), $poster_name ) ) );
@@ -210,61 +172,22 @@ To view your original update and all comments, log in and visit: %3$s
210
  ---------------------
211
  ', 'buddypress' ), $poster_name, $content, $thread_link );
212
 
213
- // Only show the disable notifications line if the settings component is enabled.
214
  if ( bp_is_active( 'settings' ) ) {
215
  $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
216
  }
217
 
218
- /**
219
- * Filters the user email that the new comment notification will be sent to.
220
- *
221
- * @since 1.2.0
222
- *
223
- * @param string $to User email the notification is being sent to.
224
- */
225
  $to = apply_filters( 'bp_activity_new_comment_notification_to', $to );
226
-
227
- /**
228
- * Filters the new comment notification subject that will be sent to user.
229
- *
230
- * @since 1.2.0
231
- *
232
- * @param string $subject Email notification subject text.
233
- * @param string $poster_name Name of the person who made the comment.
234
- */
235
  $subject = apply_filters( 'bp_activity_new_comment_notification_subject', $subject, $poster_name );
236
-
237
- /**
238
- * Filters the new comment notification message that will be sent to user.
239
- *
240
- * @since 1.2.0
241
- *
242
- * @param string $message Email notification message text.
243
- * @param string $poster_name Name of the person who made the comment.
244
- * @param string $content Content of the comment.
245
- * @param string $thread_link URL permalink for the activity thread.
246
- * @param string $settings_link URL permalink for the user's notification settings area.
247
- */
248
  $message = apply_filters( 'bp_activity_new_comment_notification_message', $message, $poster_name, $content, $thread_link, $settings_link );
249
 
250
  wp_mail( $to, $subject, $message );
251
 
252
- /**
253
- * Fires after the sending of a reply to an update email notification.
254
- *
255
- * @since 1.5.0
256
- *
257
- * @param int $user_id ID of the original activity item author.
258
- * @param string $subject Email notification subject text.
259
- * @param string $message Email notification message text.
260
- * @param int $comment_id ID for the newly received comment.
261
- * @param int $commenter_id ID of the user who made the comment.
262
- * @param array $params Arguments used with the original activity comment.
263
- */
264
  do_action( 'bp_activity_sent_reply_to_update_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params );
265
  }
266
 
267
- /*
268
  * If this is a reply to another comment, send an email notification to the
269
  * author of the immediate parent comment.
270
  */
@@ -280,7 +203,7 @@ To view your original update and all comments, log in and visit: %3$s
280
  $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
281
  $settings_link = bp_core_get_user_domain( $parent_comment->user_id ) . $settings_slug . '/notifications/';
282
 
283
- // Set up and send the message.
284
  $ud = bp_core_get_core_userdata( $parent_comment->user_id );
285
  $to = $ud->user_email;
286
  $subject = bp_get_email_subject( array( 'text' => sprintf( __( '%s replied to one of your comments', 'buddypress' ), $poster_name ) ) );
@@ -298,68 +221,28 @@ To view the original activity, your comment and all replies, log in and visit: %
298
  ---------------------
299
  ', 'buddypress' ), $poster_name, $content, $thread_link );
300
 
301
- // Only show the disable notifications line if the settings component is enabled.
302
  if ( bp_is_active( 'settings' ) ) {
303
  $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
304
  }
305
 
306
- /**
307
- * Filters the user email that the new comment reply notification will be sent to.
308
- *
309
- * @since 1.2.0
310
- *
311
- * @param string $to User email the notification is being sent to.
312
- */
313
  $to = apply_filters( 'bp_activity_new_comment_notification_comment_author_to', $to );
314
-
315
- /**
316
- * Filters the new comment reply notification subject that will be sent to user.
317
- *
318
- * @since 1.2.0
319
- *
320
- * @param string $subject Email notification subject text.
321
- * @param string $poster_name Name of the person who made the comment reply.
322
- */
323
  $subject = apply_filters( 'bp_activity_new_comment_notification_comment_author_subject', $subject, $poster_name );
324
-
325
- /**
326
- * Filters the new comment reply notification message that will be sent to user.
327
- *
328
- * @since 1.2.0
329
- *
330
- * @param string $message Email notification message text.
331
- * @param string $poster_name Name of the person who made the comment reply.
332
- * @param string $content Content of the comment reply.
333
- * @param string $settings_link URL permalink for the user's notification settings area.
334
- * @param string $thread_link URL permalink for the activity thread.
335
- */
336
  $message = apply_filters( 'bp_activity_new_comment_notification_comment_author_message', $message, $poster_name, $content, $settings_link, $thread_link );
337
 
338
  wp_mail( $to, $subject, $message );
339
 
340
- /**
341
- * Fires after the sending of a reply to a reply email notification.
342
- *
343
- * @since 1.5.0
344
- *
345
- * @param int $user_id ID of the parent activity item author.
346
- * @param string $subject Email notification subject text.
347
- * @param string $message Email notification message text.
348
- * @param int $comment_id ID for the newly received comment.
349
- * @param int $commenter_id ID of the user who made the comment.
350
- * @param array $params Arguments used with the original activity comment.
351
- */
352
- do_action( 'bp_activity_sent_reply_to_reply_email', $parent_comment->user_id, $subject, $message, $comment_id, $commenter_id, $params );
353
  }
354
  }
355
 
356
  /**
357
- * Helper method to map action arguments to function parameters.
358
- *
359
- * @since 1.9.0
360
  *
361
- * @param int $comment_id ID of the comment being notified about.
362
- * @param array $params Parameters to use with notification.
 
363
  */
364
  function bp_activity_new_comment_notification_helper( $comment_id, $params ) {
365
  bp_activity_new_comment_notification( $comment_id, $params['user_id'], $params );
@@ -371,7 +254,7 @@ add_action( 'bp_activity_comment_posted', 'bp_activity_new_comment_notification_
371
  /**
372
  * Format notifications related to activity.
373
  *
374
- * @since 1.5.0
375
  *
376
  * @uses bp_loggedin_user_domain()
377
  * @uses bp_get_activity_slug()
@@ -380,11 +263,11 @@ add_action( 'bp_activity_comment_posted', 'bp_activity_new_comment_notification_
380
  * @uses apply_filters() To call the 'bp_activity_single_at_mentions_notification' hook.
381
  * @uses do_action() To call 'activity_format_notifications' hook.
382
  *
383
- * @param string $action The type of activity item. Just 'new_at_mention' for now.
384
- * @param int $item_id The activity ID.
385
- * @param int $secondary_item_id In the case of at-mentions, this is the mentioner's ID.
386
- * @param int $total_items The total number of notifications to format.
387
- * @param string $format 'string' to get a BuddyBar-compatible notification, 'array' otherwise.
388
  * @return string $return Formatted @mention notification.
389
  */
390
  function bp_activity_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
@@ -395,69 +278,27 @@ function bp_activity_format_notifications( $action, $item_id, $secondary_item_id
395
  $poster_user_id = $secondary_item_id;
396
  $at_mention_link = bp_loggedin_user_domain() . bp_get_activity_slug() . '/mentions/';
397
  $at_mention_title = sprintf( __( '@%s Mentions', 'buddypress' ), bp_get_loggedin_user_username() );
398
- $amount = 'single';
399
 
400
  if ( (int) $total_items > 1 ) {
401
  $text = sprintf( __( 'You have %1$d new mentions', 'buddypress' ), (int) $total_items );
402
- $amount = 'multiple';
403
  } else {
404
  $user_fullname = bp_core_get_user_displayname( $poster_user_id );
405
  $text = sprintf( __( '%1$s mentioned you', 'buddypress' ), $user_fullname );
 
406
  }
407
  break;
408
  }
409
 
410
  if ( 'string' == $format ) {
411
-
412
- /**
413
- * Filters the @mention notification for the string format.
414
- *
415
- * This is a variable filter that is dependent on how many items
416
- * need notified about. The two possible hooks are bp_activity_single_at_mentions_notification
417
- * or bp_activity_multiple_at_mentions_notification.
418
- *
419
- * @since 1.5.0
420
- *
421
- * @param string $string HTML anchor tag for the mention.
422
- * @param string $at_mention_link The permalink for the mention.
423
- * @param int $total_items How many items being notified about.
424
- * @param int $activity_id ID of the activity item being formatted.
425
- * @param int $poster_user_id ID of the user posting the mention.
426
- */
427
- $return = apply_filters( 'bp_activity_' . $amount . '_at_mentions_notification', '<a href="' . esc_url( $at_mention_link ) . '" title="' . esc_attr( $at_mention_title ) . '">' . esc_html( $text ) . '</a>', $at_mention_link, (int) $total_items, $activity_id, $poster_user_id );
428
  } else {
429
-
430
- /**
431
- * Filters the @mention notification for any non-string format.
432
- *
433
- * This is a variable filter that is dependent on how many items need notified about.
434
- * The two possible hooks are bp_activity_single_at_mentions_notification
435
- * or bp_activity_multiple_at_mentions_notification.
436
- *
437
- * @since 1.5.0
438
- *
439
- * @param array $array Array holding the content and permalink for the mention notification.
440
- * @param string $at_mention_link The permalink for the mention.
441
- * @param int $total_items How many items being notified about.
442
- * @param int $activity_id ID of the activity item being formatted.
443
- * @param int $poster_user_id ID of the user posting the mention.
444
- */
445
- $return = apply_filters( 'bp_activity_' . $amount . '_at_mentions_notification', array(
446
  'text' => $text,
447
  'link' => $at_mention_link
448
  ), $at_mention_link, (int) $total_items, $activity_id, $poster_user_id );
449
  }
450
 
451
- /**
452
- * Fires right before returning the formatted activity notifications.
453
- *
454
- * @since 1.2.0
455
- *
456
- * @param string $action The type of activity item.
457
- * @param int $item_id The activity ID.
458
- * @param int $secondary_item_id @mention mentioner ID.
459
- * @param int $total_items Total amount of items to format.
460
- */
461
  do_action( 'activity_format_notifications', $action, $item_id, $secondary_item_id, $total_items );
462
 
463
  return $return;
@@ -471,13 +312,13 @@ function bp_activity_format_notifications( $action, $item_id, $secondary_item_id
471
  * future when we separate emails from Notifications, this will need its own
472
  * 'bp_activity_at_name_send_emails' equivalent helper function.
473
  *
474
- * @since 1.9.0
475
  *
476
- * @param object $activity Activity object.
477
- * @param string $subject (not used) Notification subject.
478
- * @param string $message (not used) Notification message.
479
- * @param string $content (not used) Notification content.
480
- * @param int $receiver_user_id ID of user receiving notification.
481
  */
482
  function bp_activity_at_mention_add_notification( $activity, $subject, $message, $content, $receiver_user_id ) {
483
  if ( bp_is_active( 'notifications' ) ) {
@@ -497,7 +338,7 @@ add_action( 'bp_activity_sent_mention_email', 'bp_activity_at_mention_add_notifi
497
  /**
498
  * Mark at-mention notifications as read when users visit their Mentions page.
499
  *
500
- * @since 1.5.0
501
  *
502
  * @uses bp_notifications_mark_all_notifications_by_type()
503
  */
@@ -506,7 +347,7 @@ function bp_activity_remove_screen_notifications() {
506
  return;
507
  }
508
 
509
- // Only mark read if you're looking at your own mentions.
510
  if ( ! bp_is_my_profile() ) {
511
  return;
512
  }
@@ -518,9 +359,7 @@ add_action( 'bp_activity_screen_mentions', 'bp_activity_remove_screen_notificati
518
  /**
519
  * Mark at-mention notification as read when user visits the activity with the mention.
520
  *
521
- * @since 2.0.0
522
- *
523
- * @param BP_Activity_Activity $activity Activity object.
524
  */
525
  function bp_activity_remove_screen_notifications_single_activity_permalink( $activity ) {
526
  if ( ! bp_is_active( 'notifications' ) ) {
@@ -531,7 +370,8 @@ function bp_activity_remove_screen_notifications_single_activity_permalink( $act
531
  return;
532
  }
533
 
534
- // Mark as read any notifications for the current user related to this activity item.
 
535
  bp_notifications_mark_notifications_by_item_id( bp_loggedin_user_id(), $activity->id, buddypress()->activity->id, 'new_at_mention' );
536
  }
537
  add_action( 'bp_activity_screen_single_activity_permalink', 'bp_activity_remove_screen_notifications_single_activity_permalink' );
@@ -539,13 +379,13 @@ add_action( 'bp_activity_screen_single_activity_permalink', 'bp_activity_remove_
539
  /**
540
  * Delete at-mention notifications when the corresponding activity item is deleted.
541
  *
542
- * @since 2.0.0
543
  *
544
  * @param array $activity_ids_deleted IDs of deleted activity items.
545
  */
546
  function bp_activity_at_mention_delete_notification( $activity_ids_deleted = array() ) {
547
  // Let's delete all without checking if content contains any mentions
548
- // to avoid a query to get the activity.
549
  if ( bp_is_active( 'notifications' ) && ! empty( $activity_ids_deleted ) ) {
550
  foreach ( $activity_ids_deleted as $activity_id ) {
551
  bp_notifications_delete_all_notifications_by_type( $activity_id, buddypress()->activity->id );
1
  <?php
2
+
3
  /**
4
  * BuddyPress Activity Notifications.
5
  *
7
  * @subpackage ActivityNotifications
8
  */
9
 
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
 
13
  /* Emails *********************************************************************/
14
 
15
  /**
16
  * Send email and BP notifications when a user is mentioned in an update.
17
  *
18
+ * @since BuddyPress (1.2)
19
  *
20
  * @uses bp_notifications_add_notification()
21
  * @uses bp_get_user_meta()
34
  * @uses apply_filters() To call the 'bp_activity_at_message_notification_subject' hook.
35
  * @uses apply_filters() To call the 'bp_activity_at_message_notification_message' hook.
36
  * @uses wp_mail()
37
+ * @uses do_action() To call the 'bp_activity_sent_mention_email' hook
38
  *
39
+ * @param int $activity_id The ID of the activity update.
40
  * @param int $receiver_user_id The ID of the user who is receiving the update.
41
  */
42
  function bp_activity_at_message_notification( $activity_id, $receiver_user_id ) {
43
 
44
+ // Don't leave multiple notifications for the same activity item
45
  $notifications = BP_Core_Notification::get_all_for_user( $receiver_user_id, 'all' );
46
 
47
  foreach( $notifications as $notification ) {
56
  $message = '';
57
  $content = '';
58
 
59
+ // Now email the user with the contents of the message (if they have enabled email notifications)
60
  if ( 'no' != bp_get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) {
61
  $poster_name = bp_core_get_user_displayname( $activity->user_id );
62
 
67
  $poster_name = stripslashes( $poster_name );
68
  $content = bp_activity_filter_kses( strip_tags( stripslashes( $activity->content ) ) );
69
 
70
+ // Set up and send the message
71
  $ud = bp_core_get_core_userdata( $receiver_user_id );
72
  $to = $ud->user_email;
73
  $subject = bp_get_email_subject( array( 'text' => sprintf( __( '%s mentioned you in an update', 'buddypress' ), $poster_name ) ) );
94
  ', 'buddypress' ), $poster_name, $content, $message_link );
95
  }
96
 
97
+ // Only show the disable notifications line if the settings component is enabled
98
  if ( bp_is_active( 'settings' ) ) {
99
  $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
100
  }
101
 
102
+ // Send the message
 
 
 
 
 
 
103
  $to = apply_filters( 'bp_activity_at_message_notification_to', $to );
 
 
 
 
 
 
 
 
 
104
  $subject = apply_filters( 'bp_activity_at_message_notification_subject', $subject, $poster_name );
 
 
 
 
 
 
 
 
 
 
 
 
105
  $message = apply_filters( 'bp_activity_at_message_notification_message', $message, $poster_name, $content, $message_link, $settings_link );
106
 
107
  wp_mail( $to, $subject, $message );
108
  }
109
 
 
 
 
 
 
 
 
 
 
 
 
110
  do_action( 'bp_activity_sent_mention_email', $activity, $subject, $message, $content, $receiver_user_id );
111
  }
112
 
113
  /**
114
  * Send email and BP notifications when an activity item receives a comment.
115
  *
116
+ * @since BuddyPress (1.2)
117
  *
118
  * @uses bp_get_user_meta()
119
  * @uses bp_core_get_user_displayname()
125
  * @uses wp_specialchars_decode()
126
  * @uses get_blog_option()
127
  * @uses bp_get_root_blog_id()
128
+ * @uses apply_filters() To call the 'bp_activity_new_comment_notification_to' hook
129
+ * @uses apply_filters() To call the 'bp_activity_new_comment_notification_subject' hook
130
+ * @uses apply_filters() To call the 'bp_activity_new_comment_notification_message' hook
131
  * @uses wp_mail()
132
+ * @uses do_action() To call the 'bp_activity_sent_reply_to_update_email' hook
133
+ * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_to' hook
134
+ * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_subject' hook
135
+ * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_message' hook
136
+ * @uses do_action() To call the 'bp_activity_sent_reply_to_reply_email' hook
137
  *
138
+ * @param int $comment_id The comment id.
139
+ * @param int $commenter_id The ID of the user who posted the comment.
140
+ * @param array $params {@link bp_activity_new_comment()}
 
141
  */
142
  function bp_activity_new_comment_notification( $comment_id = 0, $commenter_id = 0, $params = array() ) {
143
 
144
+ // Set some default parameters
145
  $activity_id = 0;
146
  $parent_id = 0;
147
 
158
  $poster_name = stripslashes( $poster_name );
159
  $content = bp_activity_filter_kses( stripslashes($content) );
160
 
161
+ // Set up and send the message
162
  $ud = bp_core_get_core_userdata( $original_activity->user_id );
163
  $to = $ud->user_email;
164
  $subject = bp_get_email_subject( array( 'text' => sprintf( __( '%s replied to one of your updates', 'buddypress' ), $poster_name ) ) );
172
  ---------------------
173
  ', 'buddypress' ), $poster_name, $content, $thread_link );
174
 
175
+ // Only show the disable notifications line if the settings component is enabled
176
  if ( bp_is_active( 'settings' ) ) {
177
  $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
178
  }
179
 
180
+ /* Send the message */
 
 
 
 
 
 
181
  $to = apply_filters( 'bp_activity_new_comment_notification_to', $to );
 
 
 
 
 
 
 
 
 
182
  $subject = apply_filters( 'bp_activity_new_comment_notification_subject', $subject, $poster_name );
 
 
 
 
 
 
 
 
 
 
 
 
183
  $message = apply_filters( 'bp_activity_new_comment_notification_message', $message, $poster_name, $content, $thread_link, $settings_link );
184
 
185
  wp_mail( $to, $subject, $message );
186
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  do_action( 'bp_activity_sent_reply_to_update_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params );
188
  }
189
 
190
+ /***
191
  * If this is a reply to another comment, send an email notification to the
192
  * author of the immediate parent comment.
193
  */
203
  $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
204
  $settings_link = bp_core_get_user_domain( $parent_comment->user_id ) . $settings_slug . '/notifications/';
205
 
206
+ // Set up and send the message
207
  $ud = bp_core_get_core_userdata( $parent_comment->user_id );
208
  $to = $ud->user_email;
209
  $subject = bp_get_email_subject( array( 'text' => sprintf( __( '%s replied to one of your comments', 'buddypress' ), $poster_name ) ) );
221
  ---------------------
222
  ', 'buddypress' ), $poster_name, $content, $thread_link );
223
 
224
+ // Only show the disable notifications line if the settings component is enabled
225
  if ( bp_is_active( 'settings' ) ) {
226
  $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
227
  }
228
 
229
+ /* Send the message */
 
 
 
 
 
 
230
  $to = apply_filters( 'bp_activity_new_comment_notification_comment_author_to', $to );
 
 
 
 
 
 
 
 
 
231
  $subject = apply_filters( 'bp_activity_new_comment_notification_comment_author_subject', $subject, $poster_name );
 
 
 
 
 
 
 
 
 
 
 
 
232
  $message = apply_filters( 'bp_activity_new_comment_notification_comment_author_message', $message, $poster_name, $content, $settings_link, $thread_link );
233
 
234
  wp_mail( $to, $subject, $message );
235
 
236
+ do_action( 'bp_activity_sent_reply_to_reply_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params );
 
 
 
 
 
 
 
 
 
 
 
 
237
  }
238
  }
239
 
240
  /**
241
+ * Helper method to map action arguments to function parameters
 
 
242
  *
243
+ * @since BuddyPress (1.9.0)
244
+ * @param int $comment_id
245
+ * @param array $params
246
  */
247
  function bp_activity_new_comment_notification_helper( $comment_id, $params ) {
248
  bp_activity_new_comment_notification( $comment_id, $params['user_id'], $params );
254
  /**
255
  * Format notifications related to activity.
256
  *
257
+ * @since BuddyPress (1.5)
258
  *
259
  * @uses bp_loggedin_user_domain()
260
  * @uses bp_get_activity_slug()
263
  * @uses apply_filters() To call the 'bp_activity_single_at_mentions_notification' hook.
264
  * @uses do_action() To call 'activity_format_notifications' hook.
265
  *
266
+ * @param string $action The type of activity item. Just 'new_at_mention' for now.
267
+ * @param int $item_id The activity ID.
268
+ * @param int $secondary_item_id In the case of at-mentions, this is the mentioner's ID.
269
+ * @param int $total_items The total number of notifications to format.
270
+ * @param string $format 'string' to get a BuddyBar-compatible notification, 'array' otherwise.
271
  * @return string $return Formatted @mention notification.
272
  */
273
  function bp_activity_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
278
  $poster_user_id = $secondary_item_id;
279
  $at_mention_link = bp_loggedin_user_domain() . bp_get_activity_slug() . '/mentions/';
280
  $at_mention_title = sprintf( __( '@%s Mentions', 'buddypress' ), bp_get_loggedin_user_username() );
 
281
 
282
  if ( (int) $total_items > 1 ) {
283
  $text = sprintf( __( 'You have %1$d new mentions', 'buddypress' ), (int) $total_items );
284
+ $filter = 'bp_activity_multiple_at_mentions_notification';
285
  } else {
286
  $user_fullname = bp_core_get_user_displayname( $poster_user_id );
287
  $text = sprintf( __( '%1$s mentioned you', 'buddypress' ), $user_fullname );
288
+ $filter = 'bp_activity_single_at_mentions_notification';
289
  }
290
  break;
291
  }
292
 
293
  if ( 'string' == $format ) {
294
+ $return = apply_filters( $filter, '<a href="' . esc_url( $at_mention_link ) . '" title="' . esc_attr( $at_mention_title ) . '">' . esc_html( $text ) . '</a>', $at_mention_link, (int) $total_items, $activity_id, $poster_user_id );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
295
  } else {
296
+ $return = apply_filters( $filter, array(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
  'text' => $text,
298
  'link' => $at_mention_link
299
  ), $at_mention_link, (int) $total_items, $activity_id, $poster_user_id );
300
  }
301
 
 
 
 
 
 
 
 
 
 
 
302
  do_action( 'activity_format_notifications', $action, $item_id, $secondary_item_id, $total_items );
303
 
304
  return $return;
312
  * future when we separate emails from Notifications, this will need its own
313
  * 'bp_activity_at_name_send_emails' equivalent helper function.
314
  *
315
+ * @since BuddyPress (1.9.0)
316
  *
317
+ * @param obj $activity
318
+ * @param string $subject (not used)
319
+ * @param string $message (not used)
320
+ * @param string $content (not used)
321
+ * @param int $receiver_user_id
322
  */
323
  function bp_activity_at_mention_add_notification( $activity, $subject, $message, $content, $receiver_user_id ) {
324
  if ( bp_is_active( 'notifications' ) ) {
338
  /**
339
  * Mark at-mention notifications as read when users visit their Mentions page.
340
  *
341
+ * @since BuddyPress (1.5)
342
  *
343
  * @uses bp_notifications_mark_all_notifications_by_type()
344
  */
347
  return;
348
  }
349
 
350
+ // Only mark read if you're looking at your own mentions
351
  if ( ! bp_is_my_profile() ) {
352
  return;
353
  }
359
  /**
360
  * Mark at-mention notification as read when user visits the activity with the mention.
361
  *
362
+ * @since BuddyPress (2.0.0)
 
 
363
  */
364
  function bp_activity_remove_screen_notifications_single_activity_permalink( $activity ) {
365
  if ( ! bp_is_active( 'notifications' ) ) {
370
  return;
371
  }
372
 
373
+ // Mark as read any notifications for the current user related to this
374
+ // activity item
375
  bp_notifications_mark_notifications_by_item_id( bp_loggedin_user_id(), $activity->id, buddypress()->activity->id, 'new_at_mention' );
376
  }
377
  add_action( 'bp_activity_screen_single_activity_permalink', 'bp_activity_remove_screen_notifications_single_activity_permalink' );
379
  /**
380
  * Delete at-mention notifications when the corresponding activity item is deleted.
381
  *
382
+ * @since BuddyPress (2.0.0)
383
  *
384
  * @param array $activity_ids_deleted IDs of deleted activity items.
385
  */
386
  function bp_activity_at_mention_delete_notification( $activity_ids_deleted = array() ) {
387
  // Let's delete all without checking if content contains any mentions
388
+ // to avoid a query to get the activity
389
  if ( bp_is_active( 'notifications' ) && ! empty( $activity_ids_deleted ) ) {
390
  foreach ( $activity_ids_deleted as $activity_id ) {
391
  bp_notifications_delete_all_notifications_by_type( $activity_id, buddypress()->activity->id );
bp-activity/bp-activity-screens.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  /**
3
  * BuddyPress Activity Screens.
4
  *
@@ -10,13 +11,13 @@
10
  * @subpackage ActivityScreens
11
  */
12
 
13
- // Exit if accessed directly.
14
- defined( 'ABSPATH' ) || exit;
15
 
16
  /**
17
  * Load the Activity directory.
18
  *
19
- * @since 1.5.0
20
  *
21
  * @uses bp_displayed_user_id()
22
  * @uses bp_is_activity_component()
@@ -30,20 +31,8 @@ function bp_activity_screen_index() {
30
  if ( bp_is_activity_directory() ) {
31
  bp_update_is_directory( true, 'activity' );
32
 
33
- /**
34
- * Fires right before the loading of the Activity directory screen template file.
35
- *
36
- * @since 1.5.0
37
- */
38
  do_action( 'bp_activity_screen_index' );
39
 
40
- /**
41
- * Filters the template to load for the Activity directory screen.
42
- *
43
- * @since 1.5.0
44
- *
45
- * @param string $template Path to the activity template to load.
46
- */
47
  bp_core_load_template( apply_filters( 'bp_activity_screen_index', 'activity/index' ) );
48
  }
49
  }
@@ -52,35 +41,21 @@ add_action( 'bp_screens', 'bp_activity_screen_index' );
52
  /**
53
  * Load the 'My Activity' page.
54
  *
55
- * @since 1.0.0
56
  *
57
  * @uses do_action() To call the 'bp_activity_screen_my_activity' hook.
58
  * @uses bp_core_load_template()
59
  * @uses apply_filters() To call the 'bp_activity_template_my_activity' hook.
60
  */
61
  function bp_activity_screen_my_activity() {
62
-
63
- /**
64
- * Fires right before the loading of the "My Activity" screen template file.
65
- *
66
- * @since 1.0.0
67
- */
68
  do_action( 'bp_activity_screen_my_activity' );
69
-
70
- /**
71
- * Filters the template to load for the "My Activity" screen.
72
- *
73
- * @since 1.0.0
74
- *
75
- * @param string $template Path to the activity template to load.
76
- */
77
  bp_core_load_template( apply_filters( 'bp_activity_template_my_activity', 'members/single/home' ) );
78
  }
79
 
80
  /**
81
  * Load the 'My Friends' activity page.
82
  *
83
- * @since 1.0.0
84
  *
85
  * @uses bp_is_active()
86
  * @uses bp_update_is_item_admin()
@@ -94,125 +69,69 @@ function bp_activity_screen_friends() {
94
  return false;
95
 
96
  bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' );
97
-
98
- /**
99
- * Fires right before the loading of the "My Friends" screen template file.
100
- *
101
- * @since 1.2.0
102
- */
103
  do_action( 'bp_activity_screen_friends' );
104
-
105
- /**
106
- * Filters the template to load for the "My Friends" screen.
107
- *
108
- * @since 1.0.0
109
- *
110
- * @param string $template Path to the activity template to load.
111
- */
112
  bp_core_load_template( apply_filters( 'bp_activity_template_friends_activity', 'members/single/home' ) );
113
  }
114
 
115
  /**
116
  * Load the 'My Groups' activity page.
117
  *
118
- * @since 1.2.0
119
  *
120
  * @uses bp_is_active()
121
  * @uses bp_update_is_item_admin()
122
  * @uses bp_current_user_can()
123
- * @uses do_action() To call the 'bp_activity_screen_groups' hook.
124
  * @uses bp_core_load_template()
125
- * @uses apply_filters() To call the 'bp_activity_template_groups_activity' hook.
126
  */
127
  function bp_activity_screen_groups() {
128
  if ( !bp_is_active( 'groups' ) )
129
  return false;
130
 
131
  bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' );
132
-
133
- /**
134
- * Fires right before the loading of the "My Groups" screen template file.
135
- *
136
- * @since 1.2.0
137
- */
138
  do_action( 'bp_activity_screen_groups' );
139
-
140
- /**
141
- * Filters the template to load for the "My Groups" screen.
142
- *
143
- * @since 1.2.0
144
- *
145
- * @param string $template Path to the activity template to load.
146
- */
147
  bp_core_load_template( apply_filters( 'bp_activity_template_groups_activity', 'members/single/home' ) );
148
  }
149
 
150
  /**
151
  * Load the 'Favorites' activity page.
152
  *
153
- * @since 1.2.0
154
  *
155
  * @uses bp_update_is_item_admin()
156
  * @uses bp_current_user_can()
157
- * @uses do_action() To call the 'bp_activity_screen_favorites' hook.
158
  * @uses bp_core_load_template()
159
- * @uses apply_filters() To call the 'bp_activity_template_favorite_activity' hook.
160
  */
161
  function bp_activity_screen_favorites() {
162
  bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' );
163
-
164
- /**
165
- * Fires right before the loading of the "Favorites" screen template file.
166
- *
167
- * @since 1.2.0
168
- */
169
  do_action( 'bp_activity_screen_favorites' );
170
-
171
- /**
172
- * Filters the template to load for the "Favorites" screen.
173
- *
174
- * @since 1.2.0
175
- *
176
- * @param string $template Path to the activity template to load.
177
- */
178
  bp_core_load_template( apply_filters( 'bp_activity_template_favorite_activity', 'members/single/home' ) );
179
  }
180
 
181
  /**
182
  * Load the 'Mentions' activity page.
183
  *
184
- * @since 1.2.0
185
  *
186
  * @uses bp_update_is_item_admin()
187
  * @uses bp_current_user_can()
188
- * @uses do_action() To call the 'bp_activity_screen_mentions' hook.
189
  * @uses bp_core_load_template()
190
- * @uses apply_filters() To call the 'bp_activity_template_mention_activity' hook.
191
  */
192
  function bp_activity_screen_mentions() {
193
  bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' );
194
-
195
- /**
196
- * Fires right before the loading of the "Mentions" screen template file.
197
- *
198
- * @since 1.2.0
199
- */
200
  do_action( 'bp_activity_screen_mentions' );
201
-
202
- /**
203
- * Filters the template to load for the "Mentions" screen.
204
- *
205
- * @since 1.2.0
206
- *
207
- * @param string $template Path to the activity template to load.
208
- */
209
  bp_core_load_template( apply_filters( 'bp_activity_template_mention_activity', 'members/single/home' ) );
210
  }
211
 
212
  /**
213
  * Reset the logged-in user's new mentions data when he visits his mentions screen.
214
  *
215
- * @since 1.5.0
216
  *
217
  * @uses bp_is_my_profile()
218
  * @uses bp_activity_clear_new_mentions()
@@ -227,8 +146,9 @@ add_action( 'bp_activity_screen_mentions', 'bp_activity_reset_my_new_mentions' )
227
  /**
228
  * Load the page for a single activity item.
229
  *
230
- * @since 1.2.0
231
  *
 
232
  * @uses bp_is_activity_component()
233
  * @uses bp_activity_get_specific()
234
  * @uses bp_current_action()
@@ -237,8 +157,8 @@ add_action( 'bp_activity_screen_mentions', 'bp_activity_reset_my_new_mentions' )
237
  * @uses bp_is_active()
238
  * @uses groups_get_group()
239
  * @uses groups_is_user_member()
240
- * @uses apply_filters_ref_array() To call the 'bp_activity_permalink_access' hook.
241
- * @uses do_action() To call the 'bp_activity_screen_single_activity_permalink' hook.
242
  * @uses bp_core_add_message()
243
  * @uses is_user_logged_in()
244
  * @uses bp_core_redirect()
@@ -247,19 +167,19 @@ add_action( 'bp_activity_screen_mentions', 'bp_activity_reset_my_new_mentions' )
247
  * @uses bp_get_root_domain()
248
  * @uses bp_get_activity_root_slug()
249
  * @uses bp_core_load_template()
250
- * @uses apply_filters() To call the 'bp_activity_template_profile_activity_permalink' hook.
251
  */
252
  function bp_activity_screen_single_activity_permalink() {
253
- $bp = buddypress();
254
 
255
- // No displayed user or not viewing activity component.
256
  if ( !bp_is_activity_component() )
257
  return false;
258
 
259
  if ( ! bp_current_action() || !is_numeric( bp_current_action() ) )
260
  return false;
261
 
262
- // Get the activity details.
263
  $activity = bp_activity_get_specific( array( 'activity_ids' => bp_current_action(), 'show_hidden' => true, 'spam' => 'ham_only', ) );
264
 
265
  // 404 if activity does not exist
@@ -271,26 +191,26 @@ function bp_activity_screen_single_activity_permalink() {
271
  $activity = $activity['activities'][0];
272
  }
273
 
274
- // Default access is true.
275
  $has_access = true;
276
 
277
- // If activity is from a group, do an extra cap check.
278
  if ( isset( $bp->groups->id ) && $activity->component == $bp->groups->id ) {
279
 
280
- // Activity is from a group, but groups is currently disabled.
281
  if ( !bp_is_active( 'groups') ) {
282
  bp_do_404();
283
  return;
284
  }
285
 
286
  // Check to see if the group is not public, if so, check the
287
- // user has access to see this activity.
288
  if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) ) {
289
 
290
- // Group is not public.
291
  if ( 'public' != $group->status ) {
292
 
293
- // User is not a member of group.
294
  if ( !groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) {
295
  $has_access = false;
296
  }
@@ -298,52 +218,24 @@ function bp_activity_screen_single_activity_permalink() {
298
  }
299
  }
300
 
301
- /**
302
- * Filters the access permission for a single activity view.
303
- *
304
- * @since 1.2.0
305
- *
306
- * @param array $access Array holding the current $has_access value and current activity item instance.
307
- */
308
  $has_access = apply_filters_ref_array( 'bp_activity_permalink_access', array( $has_access, &$activity ) );
309
 
310
- /**
311
- * Fires before the loading of a single activity template file.
312
- *
313
- * @since 1.2.0
314
- *
315
- * @param BP_Activity_Activity $activity Object representing the current activity item being displayed.
316
- * @param bool $has_access Whether or not the current user has access to view activity.
317
- */
318
  do_action( 'bp_activity_screen_single_activity_permalink', $activity, $has_access );
319
 
320
- // Access is specifically disallowed.
321
  if ( false === $has_access ) {
322
 
323
- // User feedback.
324
  bp_core_add_message( __( 'You do not have access to this activity.', 'buddypress' ), 'error' );
325
 
326
- // Redirect based on logged in status.
327
- if ( is_user_logged_in() ) {
328
- $url = bp_loggedin_user_domain();
329
-
330
- } else {
331
- $url = sprintf(
332
- site_url( 'wp-login.php?redirect_to=%s' ),
333
- urlencode( esc_url_raw( bp_activity_get_permalink( (int) bp_current_action() ) ) )
334
- );
335
- }
336
-
337
- bp_core_redirect( $url );
338
  }
339
 
340
- /**
341
- * Filters the template to load for a single activity screen.
342
- *
343
- * @since 1.0.0
344
- *
345
- * @param string $template Path to the activity template to load.
346
- */
347
  bp_core_load_template( apply_filters( 'bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink' ) );
348
  }
349
  add_action( 'bp_screens', 'bp_activity_screen_single_activity_permalink' );
@@ -351,7 +243,7 @@ add_action( 'bp_screens', 'bp_activity_screen_single_activity_permalink' );
351
  /**
352
  * Add activity notifications settings to the notifications settings page.
353
  *
354
- * @since 1.2.0
355
  *
356
  * @uses bp_get_user_meta()
357
  * @uses bp_core_get_username()
@@ -386,26 +278,19 @@ function bp_activity_screen_notification_settings() {
386
  <tr id="activity-notification-settings-mentions">
387
  <td>&nbsp;</td>
388
  <td><?php printf( __( 'A member mentions you in an update using "@%s"', 'buddypress' ), bp_core_get_username( bp_displayed_user_id() ) ) ?></td>
389
- <td class="yes"><input type="radio" name="notifications[notification_activity_new_mention]" id="notification-activity-new-mention-yes" value="yes" <?php checked( $mention, 'yes', true ) ?>/><label for="notification-activity-new-mention-yes" class="bp-screen-reader-text"><?php _e( 'Yes, send email', 'buddypress' ); ?></label></td>
390
- <td class="no"><input type="radio" name="notifications[notification_activity_new_mention]" id="notification-activity-new-mention-no" value="no" <?php checked( $mention, 'no', true ) ?>/><label for="notification-activity-new-mention-no" class="bp-screen-reader-text"><?php _e( 'No, do not send email', 'buddypress' ); ?></label></td>
391
  </tr>
392
  <?php endif; ?>
393
 
394
  <tr id="activity-notification-settings-replies">
395
  <td>&nbsp;</td>
396
  <td><?php _e( "A member replies to an update or comment you've posted", 'buddypress' ) ?></td>
397
- <td class="yes"><input type="radio" name="notifications[notification_activity_new_reply]" id="notification-activity-new-reply-yes" value="yes" <?php checked( $reply, 'yes', true ) ?>/><label for="notification-activity-new-reply-yes" class="bp-screen-reader-text"><?php _e( 'Yes, send email', 'buddypress' ); ?></label></td>
398
- <td class="no"><input type="radio" name="notifications[notification_activity_new_reply]" id="notification-activity-new-reply-no" value="no" <?php checked( $reply, 'no', true ) ?>/><label for="notification-activity-new-reply-no" class="bp-screen-reader-text"><?php _e( 'No, do not send email', 'buddypress' ); ?></label></td>
399
  </tr>
400
 
401
- <?php
402
-
403
- /**
404
- * Fires inside the closing </tbody> tag for activity screen notification settings.
405
- *
406
- * @since 1.2.0
407
- */
408
- do_action( 'bp_activity_screen_notification_settings' ) ?>
409
  </tbody>
410
  </table>
411
 
@@ -413,22 +298,22 @@ function bp_activity_screen_notification_settings() {
413
  }
414
  add_action( 'bp_notification_settings', 'bp_activity_screen_notification_settings', 1 );
415
 
416
- /** Theme Compatibility *******************************************************/
417
 
418
  /**
419
  * The main theme compat class for BuddyPress Activity.
420
  *
421
- * This class sets up the necessary theme compatibility actions to safely output
422
  * activity template parts to the_title and the_content areas of a theme.
423
  *
424
- * @since 1.7.0
425
  */
426
  class BP_Activity_Theme_Compat {
427
 
428
  /**
429
  * Set up the activity component theme compatibility.
430
  *
431
- * @since 1.7.0
432
  */
433
  public function __construct() {
434
  add_action( 'bp_setup_theme_compat', array( $this, 'is_activity' ) );
@@ -437,26 +322,25 @@ class BP_Activity_Theme_Compat {
437
  /**
438
  * Set up the theme compatibility hooks, if we're looking at an activity page.
439
  *
440
- * @since 1.7.0
441
  */
442
  public function is_activity() {
443
 
444
- // Bail if not looking at a group.
445
  if ( ! bp_is_activity_component() )
446
  return;
447
 
448
- // Activity Directory.
449
  if ( ! bp_displayed_user_id() && ! bp_current_action() ) {
450
  bp_update_is_directory( true, 'activity' );
451
 
452
- /** This action is documented in bp-activity/bp-activity-screens.php */
453
  do_action( 'bp_activity_screen_index' );
454
 
455
  add_filter( 'bp_get_buddypress_template', array( $this, 'directory_template_hierarchy' ) );
456
  add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'directory_dummy_post' ) );
457
  add_filter( 'bp_replace_the_content', array( $this, 'directory_content' ) );
458
 
459
- // Single activity.
460
  } elseif ( bp_is_single_activity() ) {
461
  add_filter( 'bp_get_buddypress_template', array( $this, 'single_template_hierarchy' ) );
462
  add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'single_dummy_post' ) );
@@ -471,26 +355,19 @@ class BP_Activity_Theme_Compat {
471
  *
472
  * This is to mirror how WordPress has {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
473
  *
474
- * @since 1.8.0
475
  *
476
  * @param string $templates The templates from bp_get_theme_compat_templates().
477
  * @return array $templates Array of custom templates to look for.
478
  */
479
  public function directory_template_hierarchy( $templates ) {
480
-
481
- /**
482
- * Filters the template hierarchy for the activity directory page.
483
- *
484
- * @since 1.8.0
485
- *
486
- * @param array $index-directory Array holding template names to be merged into template list.
487
- */
488
  $new_templates = apply_filters( 'bp_template_hierarchy_activity_directory', array(
489
  'activity/index-directory.php'
490
  ) );
491
 
492
  // Merge new templates with existing stack
493
- // @see bp_get_theme_compat_templates().
494
  $templates = array_merge( (array) $new_templates, $templates );
495
 
496
  return $templates;
@@ -499,7 +376,7 @@ class BP_Activity_Theme_Compat {
499
  /**
500
  * Update the global $post with directory data.
501
  *
502
- * @since 1.7.0
503
  */
504
  public function directory_dummy_post() {
505
  bp_theme_compat_reset_post( array(
@@ -508,7 +385,7 @@ class BP_Activity_Theme_Compat {
508
  'post_author' => 0,
509
  'post_date' => 0,
510
  'post_content' => '',
511
- 'post_type' => 'page',
512
  'post_status' => 'publish',
513
  'is_page' => true,
514
  'comment_status' => 'closed'
@@ -518,7 +395,7 @@ class BP_Activity_Theme_Compat {
518
  /**
519
  * Filter the_content with the groups index template part.
520
  *
521
- * @since 1.7.0
522
  */
523
  public function directory_content() {
524
  return bp_buffer_template_part( 'activity/index', null, false );
@@ -531,26 +408,19 @@ class BP_Activity_Theme_Compat {
531
  *
532
  * This is to mirror how WordPress has {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
533
  *
534
- * @since 1.8.0
535
  *
536
  * @param string $templates The templates from bp_get_theme_compat_templates().
537
  * @return array $templates Array of custom templates to look for.
538
  */
539
  public function single_template_hierarchy( $templates ) {
540
-
541
- /**
542
- * Filters the template hierarchy for the activity permalink pages.
543
- *
544
- * @since 1.8.0
545
- *
546
- * @param array $index Array holding template names to be merged into template list.
547
- */
548
  $new_templates = apply_filters( 'bp_template_hierarchy_activity_single_item', array(
549
  'activity/single/index.php'
550
  ) );
551
 
552
  // Merge new templates with existing stack
553
- // @see bp_get_theme_compat_templates().
554
  $templates = array_merge( (array) $new_templates, $templates );
555
 
556
  return $templates;
@@ -559,7 +429,7 @@ class BP_Activity_Theme_Compat {
559
  /**
560
  * Update the global $post with the displayed user's data.
561
  *
562
- * @since 1.7.0
563
  */
564
  public function single_dummy_post() {
565
  bp_theme_compat_reset_post( array(
@@ -568,7 +438,7 @@ class BP_Activity_Theme_Compat {
568
  'post_author' => 0,
569
  'post_date' => 0,
570
  'post_content' => '',
571
- 'post_type' => 'page',
572
  'post_status' => 'publish',
573
  'is_page' => true,
574
  'comment_status' => 'closed'
@@ -578,7 +448,7 @@ class BP_Activity_Theme_Compat {
578
  /**
579
  * Filter the_content with the members' activity permalink template part.
580
  *
581
- * @since 1.7.0
582
  */
583
  public function single_dummy_content() {
584
  return bp_buffer_template_part( 'activity/single/home', null, false );
1
  <?php
2
+
3
  /**
4
  * BuddyPress Activity Screens.
5
  *
11
  * @subpackage ActivityScreens
12
  */
13
 
14
+ // Exit if accessed directly
15
+ if ( !defined( 'ABSPATH' ) ) exit;
16
 
17
  /**
18
  * Load the Activity directory.
19
  *
20
+ * @since BuddyPress (1.5)
21
  *
22
  * @uses bp_displayed_user_id()
23
  * @uses bp_is_activity_component()
31
  if ( bp_is_activity_directory() ) {
32
  bp_update_is_directory( true, 'activity' );
33
 
 
 
 
 
 
34
  do_action( 'bp_activity_screen_index' );
35
 
 
 
 
 
 
 
 
36
  bp_core_load_template( apply_filters( 'bp_activity_screen_index', 'activity/index' ) );
37
  }
38
  }
41
  /**
42
  * Load the 'My Activity' page.
43
  *
44
+ * @since BuddyPress (1.0)
45
  *
46
  * @uses do_action() To call the 'bp_activity_screen_my_activity' hook.
47
  * @uses bp_core_load_template()
48
  * @uses apply_filters() To call the 'bp_activity_template_my_activity' hook.
49
  */
50
  function bp_activity_screen_my_activity() {
 
 
 
 
 
 
51
  do_action( 'bp_activity_screen_my_activity' );
 
 
 
 
 
 
 
 
52
  bp_core_load_template( apply_filters( 'bp_activity_template_my_activity', 'members/single/home' ) );
53
  }
54
 
55
  /**
56
  * Load the 'My Friends' activity page.
57
  *
58
+ * @since BuddyPress (1.0)
59
  *
60
  * @uses bp_is_active()
61
  * @uses bp_update_is_item_admin()
69
  return false;
70
 
71
  bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' );
 
 
 
 
 
 
72
  do_action( 'bp_activity_screen_friends' );
 
 
 
 
 
 
 
 
73
  bp_core_load_template( apply_filters( 'bp_activity_template_friends_activity', 'members/single/home' ) );
74
  }
75
 
76
  /**
77
  * Load the 'My Groups' activity page.
78
  *
79
+ * @since BuddyPress (1.2)
80
  *
81
  * @uses bp_is_active()
82
  * @uses bp_update_is_item_admin()
83
  * @uses bp_current_user_can()
84
+ * @uses do_action() To call the 'bp_activity_screen_groups' hook
85
  * @uses bp_core_load_template()
86
+ * @uses apply_filters() To call the 'bp_activity_template_groups_activity' hook
87
  */
88
  function bp_activity_screen_groups() {
89
  if ( !bp_is_active( 'groups' ) )
90
  return false;
91
 
92
  bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' );
 
 
 
 
 
 
93
  do_action( 'bp_activity_screen_groups' );
 
 
 
 
 
 
 
 
94
  bp_core_load_template( apply_filters( 'bp_activity_template_groups_activity', 'members/single/home' ) );
95
  }
96
 
97
  /**
98
  * Load the 'Favorites' activity page.
99
  *
100
+ * @since BuddyPress (1.2)
101
  *
102
  * @uses bp_update_is_item_admin()
103
  * @uses bp_current_user_can()
104
+ * @uses do_action() To call the 'bp_activity_screen_favorites' hook
105
  * @uses bp_core_load_template()
106
+ * @uses apply_filters() To call the 'bp_activity_template_favorite_activity' hook
107
  */
108
  function bp_activity_screen_favorites() {
109
  bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' );
 
 
 
 
 
 
110
  do_action( 'bp_activity_screen_favorites' );
 
 
 
 
 
 
 
 
111
  bp_core_load_template( apply_filters( 'bp_activity_template_favorite_activity', 'members/single/home' ) );
112
  }
113
 
114
  /**
115
  * Load the 'Mentions' activity page.
116
  *
117
+ * @since BuddyPress (1.2)
118
  *
119
  * @uses bp_update_is_item_admin()
120
  * @uses bp_current_user_can()
121
+ * @uses do_action() To call the 'bp_activity_screen_mentions' hook
122
  * @uses bp_core_load_template()
123
+ * @uses apply_filters() To call the 'bp_activity_template_mention_activity' hook
124
  */
125
  function bp_activity_screen_mentions() {
126
  bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' );
 
 
 
 
 
 
127
  do_action( 'bp_activity_screen_mentions' );
 
 
 
 
 
 
 
 
128
  bp_core_load_template( apply_filters( 'bp_activity_template_mention_activity', 'members/single/home' ) );
129
  }
130
 
131
  /**
132
  * Reset the logged-in user's new mentions data when he visits his mentions screen.
133
  *
134
+ * @since BuddyPress (1.5)
135
  *
136
  * @uses bp_is_my_profile()
137
  * @uses bp_activity_clear_new_mentions()
146
  /**
147
  * Load the page for a single activity item.
148
  *
149
+ * @since BuddyPress (1.2)
150
  *
151
+ * @global object $bp BuddyPress global settings
152
  * @uses bp_is_activity_component()
153
  * @uses bp_activity_get_specific()
154
  * @uses bp_current_action()
157
  * @uses bp_is_active()
158
  * @uses groups_get_group()
159
  * @uses groups_is_user_member()
160
+ * @uses apply_filters_ref_array() To call the 'bp_activity_permalink_access' hook
161
+ * @uses do_action() To call the 'bp_activity_screen_single_activity_permalink' hook
162
  * @uses bp_core_add_message()
163
  * @uses is_user_logged_in()
164
  * @uses bp_core_redirect()
167
  * @uses bp_get_root_domain()
168
  * @uses bp_get_activity_root_slug()
169
  * @uses bp_core_load_template()
170
+ * @uses apply_filters() To call the 'bp_activity_template_profile_activity_permalink' hook
171
  */
172
  function bp_activity_screen_single_activity_permalink() {
173
+ global $bp;
174
 
175
+ // No displayed user or not viewing activity component
176
  if ( !bp_is_activity_component() )
177
  return false;
178
 
179
  if ( ! bp_current_action() || !is_numeric( bp_current_action() ) )
180
  return false;
181
 
182
+ // Get the activity details
183
  $activity = bp_activity_get_specific( array( 'activity_ids' => bp_current_action(), 'show_hidden' => true, 'spam' => 'ham_only', ) );
184
 
185
  // 404 if activity does not exist
191
  $activity = $activity['activities'][0];
192
  }
193
 
194
+ // Default access is true
195
  $has_access = true;
196
 
197
+ // If activity is from a group, do an extra cap check
198
  if ( isset( $bp->groups->id ) && $activity->component == $bp->groups->id ) {
199
 
200
+ // Activity is from a group, but groups is currently disabled
201
  if ( !bp_is_active( 'groups') ) {
202
  bp_do_404();
203
  return;
204
  }
205
 
206
  // Check to see if the group is not public, if so, check the
207
+ // user has access to see this activity
208
  if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) ) {
209
 
210
+ // Group is not public
211
  if ( 'public' != $group->status ) {
212
 
213
+ // User is not a member of group
214
  if ( !groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) {
215
  $has_access = false;
216
  }
218
  }
219
  }
220
 
221
+ // Allow access to be filtered
 
 
 
 
 
 
222
  $has_access = apply_filters_ref_array( 'bp_activity_permalink_access', array( $has_access, &$activity ) );
223
 
224
+ // Allow additional code execution
 
 
 
 
 
 
 
225
  do_action( 'bp_activity_screen_single_activity_permalink', $activity, $has_access );
226
 
227
+ // Access is specifically disallowed
228
  if ( false === $has_access ) {
229
 
230
+ // User feedback
231
  bp_core_add_message( __( 'You do not have access to this activity.', 'buddypress' ), 'error' );
232
 
233
+ // Redirect based on logged in status
234
+ is_user_logged_in() ?
235
+ bp_core_redirect( bp_loggedin_user_domain() ) :
236
+ bp_core_redirect( site_url( 'wp-login.php?redirect_to=' . esc_url( bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . bp_current_action() . '/' ) ) );
 
 
 
 
 
 
 
 
237
  }
238
 
 
 
 
 
 
 
 
239
  bp_core_load_template( apply_filters( 'bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink' ) );
240
  }
241
  add_action( 'bp_screens', 'bp_activity_screen_single_activity_permalink' );
243
  /**
244
  * Add activity notifications settings to the notifications settings page.
245
  *
246
+ * @since BuddyPress (1.2)
247
  *
248
  * @uses bp_get_user_meta()
249
  * @uses bp_core_get_username()
278
  <tr id="activity-notification-settings-mentions">
279
  <td>&nbsp;</td>
280
  <td><?php printf( __( 'A member mentions you in an update using "@%s"', 'buddypress' ), bp_core_get_username( bp_displayed_user_id() ) ) ?></td>
281
+ <td class="yes"><input type="radio" name="notifications[notification_activity_new_mention]" value="yes" <?php checked( $mention, 'yes', true ) ?>/></td>
282
+ <td class="no"><input type="radio" name="notifications[notification_activity_new_mention]" value="no" <?php checked( $mention, 'no', true ) ?>/></td>
283
  </tr>
284
  <?php endif; ?>
285
 
286
  <tr id="activity-notification-settings-replies">
287
  <td>&nbsp;</td>
288
  <td><?php _e( "A member replies to an update or comment you've posted", 'buddypress' ) ?></td>
289
+ <td class="yes"><input type="radio" name="notifications[notification_activity_new_reply]" value="yes" <?php checked( $reply, 'yes', true ) ?>/></td>
290
+ <td class="no"><input type="radio" name="notifications[notification_activity_new_reply]" value="no" <?php checked( $reply, 'no', true ) ?>/></td>
291
  </tr>
292
 
293
+ <?php do_action( 'bp_activity_screen_notification_settings' ) ?>
 
 
 
 
 
 
 
294
  </tbody>
295
  </table>
296
 
298
  }
299
  add_action( 'bp_notification_settings', 'bp_activity_screen_notification_settings', 1 );
300
 
301
+ /** Theme Compatability *******************************************************/
302
 
303
  /**
304
  * The main theme compat class for BuddyPress Activity.
305
  *
306
+ * This class sets up the necessary theme compatability actions to safely output
307
  * activity template parts to the_title and the_content areas of a theme.
308
  *
309
+ * @since BuddyPress (1.7)
310
  */
311
  class BP_Activity_Theme_Compat {
312
 
313
  /**
314
  * Set up the activity component theme compatibility.
315
  *
316
+ * @since BuddyPress (1.7)
317
  */
318
  public function __construct() {
319
  add_action( 'bp_setup_theme_compat', array( $this, 'is_activity' ) );
322
  /**
323
  * Set up the theme compatibility hooks, if we're looking at an activity page.
324
  *
325
+ * @since BuddyPress (1.7)
326
  */
327
  public function is_activity() {
328
 
329
+ // Bail if not looking at a group
330
  if ( ! bp_is_activity_component() )
331
  return;
332
 
333
+ // Activity Directory
334
  if ( ! bp_displayed_user_id() && ! bp_current_action() ) {
335
  bp_update_is_directory( true, 'activity' );
336
 
 
337
  do_action( 'bp_activity_screen_index' );
338
 
339
  add_filter( 'bp_get_buddypress_template', array( $this, 'directory_template_hierarchy' ) );
340
  add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'directory_dummy_post' ) );
341
  add_filter( 'bp_replace_the_content', array( $this, 'directory_content' ) );
342
 
343
+ // Single activity
344
  } elseif ( bp_is_single_activity() ) {
345
  add_filter( 'bp_get_buddypress_template', array( $this, 'single_template_hierarchy' ) );
346
  add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'single_dummy_post' ) );
355
  *
356
  * This is to mirror how WordPress has {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
357
  *
358
+ * @since BuddyPress (1.8)
359
  *
360
  * @param string $templates The templates from bp_get_theme_compat_templates().
361
  * @return array $templates Array of custom templates to look for.
362
  */
363
  public function directory_template_hierarchy( $templates ) {
364
+ // Setup our templates based on priority
 
 
 
 
 
 
 
365
  $new_templates = apply_filters( 'bp_template_hierarchy_activity_directory', array(
366
  'activity/index-directory.php'
367
  ) );
368
 
369
  // Merge new templates with existing stack
370
+ // @see bp_get_theme_compat_templates()
371
  $templates = array_merge( (array) $new_templates, $templates );
372
 
373
  return $templates;
376
  /**
377
  * Update the global $post with directory data.
378
  *
379
+ * @since BuddyPress (1.7)
380
  */
381
  public function directory_dummy_post() {
382
  bp_theme_compat_reset_post( array(
385
  'post_author' => 0,
386
  'post_date' => 0,
387
  'post_content' => '',
388
+ 'post_type' => 'bp_activity',
389
  'post_status' => 'publish',
390
  'is_page' => true,
391
  'comment_status' => 'closed'
395
  /**
396
  * Filter the_content with the groups index template part.
397
  *
398
+ * @since BuddyPress (1.7)
399
  */
400
  public function directory_content() {
401
  return bp_buffer_template_part( 'activity/index', null, false );
408
  *
409
  * This is to mirror how WordPress has {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
410
  *
411
+ * @since BuddyPress (1.8)
412
  *
413
  * @param string $templates The templates from bp_get_theme_compat_templates().
414
  * @return array $templates Array of custom templates to look for.
415
  */
416
  public function single_template_hierarchy( $templates ) {
417
+ // Setup our templates based on priority
 
 
 
 
 
 
 
418
  $new_templates = apply_filters( 'bp_template_hierarchy_activity_single_item', array(
419
  'activity/single/index.php'
420
  ) );
421
 
422
  // Merge new templates with existing stack
423
+ // @see bp_get_theme_compat_templates()
424
  $templates = array_merge( (array) $new_templates, $templates );
425
 
426
  return $templates;
429
  /**
430
  * Update the global $post with the displayed user's data.
431
  *
432
+ * @since BuddyPress (1.7)
433
  */
434
  public function single_dummy_post() {
435
  bp_theme_compat_reset_post( array(
438
  'post_author' => 0,
439
  'post_date' => 0,
440
  'post_content' => '',
441
+ 'post_type' => 'bp_activity',
442
  'post_status' => 'publish',
443
  'is_page' => true,
444
  'comment_status' => 'closed'
448
  /**
449
  * Filter the_content with the members' activity permalink template part.
450
  *
451
+ * @since BuddyPress (1.7)
452
  */
453
  public function single_dummy_content() {
454
  return bp_buffer_template_part( 'activity/single/home', null, false );
bp-activity/bp-activity-template.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  /**
3
  * BuddyPress Activity Template Functions.
4
  *
@@ -6,13 +7,13 @@
6
  * @subpackage ActivityTemplate
7
  */
8
 
9
- // Exit if accessed directly.
10
- defined( 'ABSPATH' ) || exit;
11
 
12
  /**
13
  * Output the activity component slug.
14
  *
15
- * @since 1.5.0
16
  *
17
  * @uses bp_get_activity_slug()
18
  */
@@ -22,28 +23,20 @@ function bp_activity_slug() {
22
  /**
23
  * Return the activity component slug.
24
  *
25
- * @since 1.5.0
26
  *
27
  * @uses apply_filters() To call the 'bp_get_activity_slug' hook.
28
  *
29
  * @return string The activity component slug.
30
  */
31
  function bp_get_activity_slug() {
32
-
33
- /**
34
- * Filters the activity component slug.
35
- *
36
- * @since 1.5.0
37
- *
38
- * @param string $slug Activity component slug.
39
- */
40
  return apply_filters( 'bp_get_activity_slug', buddypress()->activity->slug );
41
  }
42
 
43
  /**
44
  * Output the activity component root slug.
45
  *
46
- * @since 1.5.0
47
  *
48
  * @uses bp_get_activity_root_slug()
49
  */
@@ -53,40 +46,32 @@ function bp_activity_root_slug() {
53
  /**
54
  * Return the activity component root slug.
55
  *
56
- * @since 1.5.0
57
  *
58
  * @uses apply_filters() To call the 'bp_get_activity_root_slug' hook.
59
  *
60
  * @return string The activity component root slug.
61
  */
62
  function bp_get_activity_root_slug() {
63
-
64
- /**
65
- * Filters the activity component root slug.
66
- *
67
- * @since 1.5.0
68
- *
69
- * @param string $root_slug Activity component root slug.
70
- */
71
  return apply_filters( 'bp_get_activity_root_slug', buddypress()->activity->root_slug );
72
  }
73
 
74
  /**
75
  * Output activity directory permalink.
76
  *
77
- * @since 1.5.0
78
  *
79
  * @uses bp_get_activity_directory_permalink()
80
  */
81
  function bp_activity_directory_permalink() {
82
- echo esc_url( bp_get_activity_directory_permalink() );
83
  }
84
  /**
85
- * Return activity directory permalink.
86
  *
87
- * @since 1.5.0
88
  *
89
- * @uses trailingslashit()
90
  * @uses bp_get_root_domain()
91
  * @uses bp_get_activity_root_slug()
92
  * @uses apply_filters() To call the 'bp_get_activity_directory_permalink' hook.
@@ -94,14 +79,6 @@ function bp_activity_directory_permalink() {
94
  * @return string Activity directory permalink.
95
  */
96
  function bp_get_activity_directory_permalink() {
97
-
98
- /**
99
- * Filters the activity directory permalink.
100
- *
101
- * @since 1.5.0
102
- *
103
- * @param string $url Permalink url for the activity directory.
104
- */
105
  return apply_filters( 'bp_get_activity_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_activity_root_slug() ) );
106
  }
107
 
@@ -110,97 +87,22 @@ function bp_activity_directory_permalink() {
110
  *
111
  * This is responsible for loading a group of activity items and displaying them.
112
  *
113
- * @since 1.0.0
114
  */
115
  class BP_Activity_Template {
 
 
 
 
 
116
 
117
- /**
118
- * The loop iterator.
119
- *
120
- * @since 1.5.0
121
- * @var int
122
- */
123
- public $current_activity = -1;
124
-
125
- /**
126
- * The activity count.
127
- *
128
- * @since 1.5.0
129
- * @var int
130
- */
131
- public $activity_count;
132
-
133
- /**
134
- * The total activity count.
135
- *
136
- * @since 1.5.0
137
- * @var int
138
- */
139
- public $total_activity_count;
140
-
141
- /**
142
- * Array of activities located by the query.
143
- *
144
- * @since 1.5.0
145
- * @var array
146
- */
147
- public $activities;
148
-
149
- /**
150
- * The activity object currently being iterated on.
151
- *
152
- * @since 1.5.0
153
- * @var object
154
- */
155
- public $activity;
156
-
157
- /**
158
- * A flag for whether the loop is currently being iterated.
159
- *
160
- * @since 1.5.0
161
- * @var bool
162
- */
163
- public $in_the_loop;
164
-
165
- /**
166
- * URL parameter key for activity pagination. Default: 'acpage'.
167
- *
168
- * @since 2.1.0
169
- * @var string
170
- */
171
- public $pag_arg;
172
-
173
- /**
174
- * The page number being requested.
175
- *
176
- * @since 1.5.0
177
- * @var int
178
- */
179
- public $pag_page;
180
-
181
- /**
182
- * The number of items being requested per page.
183
- *
184
- * @since 1.5.0
185
- * @var int
186
- */
187
- public $pag_num;
188
 
189
- /**
190
- * An HTML string containing pagination links.
191
- *
192
- * @since 1.5.0
193
- * @var string
194
- */
195
- public $pag_links;
196
 
197
- /**
198
- * The displayed user's full name.
199
- *
200
- * @since 1.5.0
201
- * @var string
202
- */
203
- public $full_name;
204
 
205
  /**
206
  * Constructor method.
@@ -216,23 +118,23 @@ class BP_Activity_Template {
216
  * BP_Activity_Activity::get(), as well as 'page_arg' and
217
  * 'include'. Default values for 'per_page' and 'display_comments'
218
  * differ from the originating function, and are described below.
219
- * @type string $page_arg The string used as a query parameter in
220
- * pagination links. Default: 'acpage'.
221
- * @type array|bool $include Pass an array of activity IDs to
222
- * retrieve only those items, or false to noop the 'include'
223
- * parameter. 'include' differs from 'in' in that 'in' forms
224
- * an IN clause that works in conjunction with other filters
225
- * passed to the function, while 'include' is interpreted as
226
- * an exact list of items to retrieve, which skips all other
227
- * filter-related parameters. Default: false.
228
- * @type int|bool $per_page Default: 20.
229
  * @type string|bool $display_comments Default: 'threaded'.
230
  * }
231
  */
232
- public function __construct( $args ) {
233
- $bp = buddypress();
234
 
235
- // Backward compatibility with old method of passing arguments.
236
  if ( !is_array( $args ) || func_num_args() > 1 ) {
237
  _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__ ) );
238
 
@@ -261,18 +163,13 @@ class BP_Activity_Template {
261
  'per_page' => 20,
262
  'page_arg' => 'acpage',
263
  'max' => false,
264
- 'fields' => 'all',
265
- 'count_total' => false,
266
  'sort' => false,
267
  'include' => false,
268
  'exclude' => false,
269
  'in' => false,
270
  'filter' => false,
271
- 'scope' => false,
272
  'search_terms' => false,
273
  'meta_query' => false,
274
- 'date_query' => false,
275
- 'filter_query' => false,
276
  'display_comments' => 'threaded',
277
  'show_hidden' => false,
278
  'spam' => 'ham_only',
@@ -281,22 +178,20 @@ class BP_Activity_Template {
281
  $r = wp_parse_args( $args, $defaults );
282
  extract( $r );
283
 
284
- $this->pag_arg = sanitize_key( $r['page_arg'] );
285
- $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $r['page'] );
286
- $this->pag_num = bp_sanitize_pagination_arg( 'num', $r['per_page'] );
287
 
288
- // Check if blog/forum replies are disabled.
289
- $this->disable_blogforum_replies = (bool) bp_core_get_root_option( 'bp-disable-blogforum-comments' );
290
 
291
- // Get an array of the logged in user's favorite activities.
292
  $this->my_favs = maybe_unserialize( bp_get_user_meta( bp_loggedin_user_id(), 'bp_favorite_activities', true ) );
293
 
294
- // Fetch specific activity items based on ID's.
295
  if ( !empty( $include ) ) {
296
  $this->activities = bp_activity_get_specific( array(
297
  'activity_ids' => explode( ',', $include ),
298
  'max' => $max,
299
- 'count_total' => $count_total,
300
  'page' => $this->pag_page,
301
  'per_page' => $this->pag_num,
302
  'sort' => $sort,
@@ -306,21 +201,17 @@ class BP_Activity_Template {
306
  'update_meta_cache' => $update_meta_cache,
307
  ) );
308
 
309
- // Fetch all activity items.
310
  } else {
311
  $this->activities = bp_activity_get( array(
312
  'display_comments' => $display_comments,
313
  'max' => $max,
314
- 'count_total' => $count_total,
315
  'per_page' => $this->pag_num,
316
  'page' => $this->pag_page,
317
  'sort' => $sort,
318
  'search_terms' => $search_terms,
319
  'meta_query' => $meta_query,
320
- 'date_query' => $date_query,
321
- 'filter_query' => $filter_query,
322
  'filter' => $filter,
323
- 'scope' => $scope,
324
  'show_hidden' => $show_hidden,
325
  'exclude' => $exclude,
326
  'in' => $in,
@@ -329,17 +220,10 @@ class BP_Activity_Template {
329
  ) );
330
  }
331
 
332
- // The total_activity_count property will be set only if a
333
- // 'count_total' query has taken place.
334
- if ( ! is_null( $this->activities['total'] ) ) {
335
- if ( ! $max || $max >= (int) $this->activities['total'] ) {
336
- $this->total_activity_count = (int) $this->activities['total'];
337
- } else {
338
- $this->total_activity_count = (int) $max;
339
- }
340
- }
341
-
342
- $this->has_more_items = $this->activities['has_more_items'];
343
 
344
  $this->activities = $this->activities['activities'];
345
 
@@ -355,37 +239,33 @@ class BP_Activity_Template {
355
 
356
  $this->full_name = bp_get_displayed_user_fullname();
357
 
358
- // Fetch parent content for activity comments so we do not have to query in the loop.
359
  foreach ( (array) $this->activities as $activity ) {
360
- if ( 'activity_comment' != $activity->type ) {
361
  continue;
362
- }
363
 
364
  $parent_ids[] = $activity->item_id;
365
  }
366
 
367
- if ( !empty( $parent_ids ) ) {
368
  $activity_parents = bp_activity_get_specific( array( 'activity_ids' => $parent_ids ) );
369
- }
370
 
371
  if ( !empty( $activity_parents['activities'] ) ) {
372
- foreach( $activity_parents['activities'] as $parent ) {
373
  $this->activity_parents[$parent->id] = $parent;
374
- }
375
 
376
  unset( $activity_parents );
377
  }
378
 
379
  if ( (int) $this->total_activity_count && (int) $this->pag_num ) {
380
  $this->pag_links = paginate_links( array(
381
- 'base' => add_query_arg( $this->pag_arg, '%#%' ),
382
  'format' => '',
383
  'total' => ceil( (int) $this->total_activity_count / (int) $this->pag_num ),
384
  'current' => (int) $this->pag_page,
385
  'prev_text' => _x( '&larr;', 'Activity pagination previous text', 'buddypress' ),
386
  'next_text' => _x( '&rarr;', 'Activity pagination next text', 'buddypress' ),
387
- 'mid_size' => 1,
388
- 'add_args' => array(),
389
  ) );
390
  }
391
  }
@@ -398,9 +278,8 @@ class BP_Activity_Template {
398
  * @return bool True if there are items in the loop, otherwise false.
399
  */
400
  function has_activities() {
401
- if ( $this->activity_count ) {
402
  return true;
403
- }
404
 
405
  return false;
406
  }
@@ -410,9 +289,9 @@ class BP_Activity_Template {
410
  *
411
  * @return object The next activity item to iterate over.
412
  */
413
- public function next_activity() {
414
  $this->current_activity++;
415
- $this->activity = $this->activities[ $this->current_activity ];
416
 
417
  return $this->activity;
418
  }
@@ -420,7 +299,7 @@ class BP_Activity_Template {
420
  /**
421
  * Rewind the posts and reset post index.
422
  */
423
- public function rewind_activities() {
424
  $this->current_activity = -1;
425
  if ( $this->activity_count > 0 ) {
426
  $this->activity = $this->activities[0];
@@ -439,24 +318,16 @@ class BP_Activity_Template {
439
  * @return bool True if there are more activity items to show,
440
  * otherwise false.
441
  */
442
- public function user_activities() {
443
- if ( ( $this->current_activity + 1 ) < $this->activity_count ) {
444
  return true;
445
- } elseif ( ( $this->current_activity + 1 ) == $this->activity_count ) {
446
-
447
- /**
448
- * Fires right before the rewinding of activity posts.
449
- *
450
- * @since 1.1.0
451
- */
452
- do_action( 'activity_loop_end' );
453
-
454
- // Do some cleaning up after the loop.
455
  $this->rewind_activities();
456
  }
457
 
458
  $this->in_the_loop = false;
459
-
460
  return false;
461
  }
462
 
@@ -469,25 +340,16 @@ class BP_Activity_Template {
469
  *
470
  * @see bp_the_activity()
471
  */
472
- public function the_activity() {
473
 
474
  $this->in_the_loop = true;
475
  $this->activity = $this->next_activity();
476
 
477
- if ( is_array( $this->activity ) ) {
478
  $this->activity = (object) $this->activity;
479
- }
480
 
481
- // Loop has just started.
482
- if ( $this->current_activity == 0 ) {
483
-
484
- /**
485
- * Fires if the current activity item is the first in the activity loop.
486
- *
487
- * @since 1.1.0
488
- */
489
  do_action('activity_loop_start');
490
- }
491
  }
492
  }
493
 
@@ -498,10 +360,10 @@ class BP_Activity_Template {
498
  * $activities_template global, enabling the use of BuddyPress templates and
499
  * template functions to display a list of activity items.
500
  *
501
- * @since 1.0.0
502
- * @since 2.4.0 Introduced the `$fields` parameter.
503
  *
504
  * @global object $activities_template {@link BP_Activity_Template}
 
505
  * @uses groups_is_user_member()
506
  * @uses bp_current_action()
507
  * @uses bp_is_current_action()
@@ -514,261 +376,308 @@ class BP_Activity_Template {
514
  * @uses bp_activity_get_user_favorites()
515
  * @uses apply_filters() To call the 'bp_has_activities' hook.
516
  *
517
- * @param array|string $args {
518
- * Arguments for limiting the contents of the activity loop. Most arguments
519
- * are in the same format as {@link BP_Activity_Activity::get()}. However,
520
- * because the format of the arguments accepted here differs in a number of
521
- * ways, and because bp_has_activities() determines some default arguments in
522
- * a dynamic fashion, we list all accepted arguments here as well.
523
- *
524
- * Arguments can be passed as an associative array, or as a URL querystring
525
- * (eg, 'user_id=4&display_comments=threaded').
526
- *
527
- * @type int $page Which page of results to fetch. Using page=1 without per_page will result
528
- * in no pagination. Default: 1.
529
- * @type int|bool $per_page Number of results per page. Default: 20.
530
- * @type string $page_arg String used as a query parameter in pagination links. Default: 'acpage'.
531
- * @type int|bool $max Maximum number of results to return. Default: false (unlimited).
532
- * @type string $fields Activity fields to retrieve. 'all' to fetch entire activity objects,
533
- * 'ids' to get only the activity IDs. Default 'all'.
534
- * @type string|bool $count_total If true, an additional DB query is run to count the total activity items
535
- * for the query. Default: false.
536
- * @type string $sort 'ASC' or 'DESC'. Default: 'DESC'.
537
- * @type array|bool $exclude Array of activity IDs to exclude. Default: false.
538
- * @type array|bool $in Array of IDs to limit query by (IN). 'in' is intended to be used in
539
- * conjunction with other filter parameters. Default: false.
540
- * @type array|bool $include Array of exact activity IDs to query. Providing an 'include' array will
541
- * override all other filters passed in the argument array. When viewing the
542
- * permalink page for a single activity item, this value defaults to the ID of
543
- * that item. Otherwise the default is false.
544
- * @type array $meta_query Limit by activitymeta by passing an array of meta_query conditions. See
545
- * {@link WP_Meta_Query::queries} for a description of the syntax.
546
- * @type array $date_query Limit by date by passing an array of date_query conditions. See first
547
- * parameter of {@link WP_Date_Query::__construct()} for syntax.
548
- * @type array $filter_query Advanced activity filtering. See {@link BP_Activity_Query::__construct()}.
549
- * @type string $search_terms Limit results by a search term. Default: false.
550
- * @type string $scope Use a BuddyPress pre-built filter.
551
- * - 'just-me' retrieves items belonging only to a user; this is equivalent
552
- * to passing a 'user_id' argument.
553
- * - 'friends' retrieves items belonging to the friends of a user.
554
- * - 'groups' retrieves items belonging to groups to which a user belongs to.
555
- * - 'favorites' retrieves a user's favorited activity items.
556
- * - 'mentions' retrieves items where a user has received an @-mention.
557
- * The default value of 'scope' is set to one of the above if that value
558
- * appears in the appropriate place in the URL; eg, 'scope' will be 'groups'
559
- * when visiting http://example.com/members/joe/activity/groups/. Otherwise
560
- * defaults to false.
561
- * @type int|array|bool $user_id The ID(s) of user(s) whose activity should be fetched. Pass a single ID or
562
- * an array of IDs. When viewing a user profile page (but not that user's
563
- * activity subpages, ie My Friends, My Groups, etc), 'user_id' defaults to
564
- * the ID of the displayed user. Otherwise the default is false.
565
- * @type string|array|bool $object Filters by the `component` column in the database, which is generally the
566
- * component ID in the case of BuddyPress components, or the plugin slug in
567
- * the case of plugins. For example, 'groups' will limit results to those that
568
- * are associated with the BP Groups component. Accepts a single component
569
- * string, or an array of multiple components. Defaults to 'groups' when
570
- * viewing the page of a single group, the My Groups activity filter, or the
571
- * Activity > Groups filter of a user profile. Otherwise defaults to false.
572
- * @type string|array|bool $action Filters by the `type` column in the database, which is a string
573
- * categorizing the activity item (eg, 'new_blog_post', 'created_group').
574
- * Accepts a comma-delimited string or an array of types. Default: false.
575
- * @type int|array|bool $primary_id Filters by the `item_id` column in the database. The meaning of
576
- * 'primary_id' differs between components/types; for example, in the case of
577
- * 'created_group', 'primary_id' is the ID of the group. Accepts a single ID,
578
- * or an array of multiple IDs. When viewing a single group, defaults to the
579
- * current group ID. When viewing a user's Groups stream page, defaults to the
580
- * IDs of the user's groups. Otherwise defaults to false.
581
- * @type int|array|bool $secondary_id Filters by the `secondary_item_id` column in the database. The meaning of
582
- * 'secondary_id' differs between components/types. Accepts a single ID, or an
583
- * array of multiple IDs. Defaults to false.
584
- * @type int $offset Return only activity items with an ID greater than or equal to this one.
585
- * Note that providing an offset will disable pagination. Default: false.
586
- * @type string|bool $display_comments How to handle activity comments. Possible values:
587
- * - 'threaded' - comments appear in a threaded tree, under their parent
588
- * items.
589
- * - 'stream' - the activity stream is presented in a flat manner, with
590
- * comments sorted in chronological order alongside other activity items.
591
- * - false - don't fetch activity comments at all.
592
- * Default: 'threaded'.
593
- * @type bool $show_hidden Whether to show items marked hide_sitewide. Defaults to false, except in
594
- * the following cases:
595
- * - User is viewing his own activity stream.
596
- * - User is viewing the activity stream of a non-public group of which he
597
- * is a member.
598
- * @type string|bool $spam Spam status. 'ham_only', 'spam_only', or false to show all activity
599
- * regardless of spam status. Default: 'ham_only'.
600
- * @type bool $populate_extras Whether to pre-fetch the activity metadata for the queried items.
601
- * Default: true.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
602
  * }
603
  * @return bool Returns true when activities are found, otherwise false.
604
  */
605
  function bp_has_activities( $args = '' ) {
606
- global $activities_template;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
607
 
608
- // Get BuddyPress.
609
- $bp = buddypress();
610
 
611
- /*
612
- * Smart Defaults.
613
- */
614
 
615
- // User filtering.
616
- $user_id = bp_displayed_user_id()
617
- ? bp_displayed_user_id()
618
- : false;
619
-
620
- // Group filtering.
621
- if ( bp_is_group() ) {
622
- $object = $bp->groups->id;
623
- $primary_id = bp_get_current_group_id();
624
- $show_hidden = (bool) ( groups_is_user_member( bp_loggedin_user_id(), $primary_id ) || bp_current_user_can( 'bp_moderate' ) );
625
- } else {
626
- $object = false;
627
- $primary_id = false;
628
- $show_hidden = false;
629
- }
630
 
631
- // The default scope should recognize custom slugs.
632
- $scope = array_key_exists( bp_current_action(), (array) $bp->loaded_components )
633
- ? $bp->loaded_components[ bp_current_action() ]
634
- : bp_current_action();
635
 
636
- // Support for permalinks on single item pages: /groups/my-group/activity/124/.
637
- $include = bp_is_current_action( bp_get_activity_slug() )
638
- ? bp_action_variable( 0 )
639
- : false;
 
 
640
 
641
- $search_terms_default = false;
642
- $search_query_arg = bp_core_get_component_search_query_arg( 'activity' );
643
- if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) {
644
- $search_terms_default = stripslashes( $_REQUEST[ $search_query_arg ] );
645
  }
646
 
647
- /*
648
- * Parse Args.
649
- */
650
 
651
- // Note: any params used for filtering can be a single value, or multiple
652
- // values comma separated.
653
- $r = bp_parse_args( $args, array(
654
- 'display_comments' => 'threaded', // False for none, stream/threaded - show comments in the stream or threaded under items.
655
- 'include' => $include, // Pass an activity_id or string of IDs comma-separated.
656
- 'exclude' => false, // Pass an activity_id or string of IDs comma-separated.
657
- 'in' => false, // Comma-separated list or array of activity IDs among which to search.
658
- 'sort' => 'DESC', // Sort DESC or ASC.
659
- 'page' => 1, // Which page to load.
660
- 'per_page' => 20, // Number of items per page.
661
- 'page_arg' => 'acpage', // See https://buddypress.trac.wordpress.org/ticket/3679.
662
- 'max' => false, // Max number to return.
663
- 'fields' => 'all',
664
- 'count_total' => false,
665
- 'show_hidden' => $show_hidden, // Show activity items that are hidden site-wide?
666
- 'spam' => 'ham_only', // Hide spammed items.
667
 
668
- // Scope - pre-built activity filters for a user (friends/groups/favorites/mentions).
669
- 'scope' => $scope,
 
670
 
671
- // Filtering
672
- 'user_id' => $user_id, // user_id to filter on.
673
- 'object' => $object, // Object to filter on e.g. groups, profile, status, friends.
674
- 'action' => false, // Action to filter on e.g. activity_update, new_forum_post, profile_updated.
675
- 'primary_id' => $primary_id, // Object ID to filter on e.g. a group_id or forum_id or blog_id etc.
676
- 'secondary_id' => false, // Secondary object ID to filter on e.g. a post_id.
677
- 'offset' => false, // Return only items >= this ID.
678
- 'since' => false, // Return only items recorded since this Y-m-d H:i:s date.
679
-
680
- 'meta_query' => false, // Filter on activity meta. See WP_Meta_Query for format.
681
- 'date_query' => false, // Filter by date. See first parameter of WP_Date_Query for format.
682
- 'filter_query' => false, // Advanced filtering. See BP_Activity_Query for format.
683
-
684
- // Searching.
685
- 'search_terms' => $search_terms_default,
686
- 'update_meta_cache' => true,
687
- ), 'has_activities' );
688
 
689
- /*
690
- * Smart Overrides.
691
- */
 
 
 
692
 
693
- // Translate various values for 'display_comments'
694
- // This allows disabling comments via ?display_comments=0
695
- // or =none or =false. Final true is a strict type check. See #5029.
696
- if ( in_array( $r['display_comments'], array( 0, '0', 'none', 'false' ), true ) ) {
697
- $r['display_comments'] = false;
698
- }
 
699
 
700
- // Ignore pagination if an offset is passed.
701
- if ( ! empty( $r['offset'] ) ) {
702
- $r['page'] = 0;
703
- }
704
 
705
- // Search terms.
706
- if ( ! empty( $_REQUEST['s'] ) && empty( $r['search_terms'] ) ) {
707
- $r['search_terms'] = $_REQUEST['s'];
708
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
709
 
710
- // Do not exceed the maximum per page.
711
- if ( ! empty( $r['max'] ) && ( (int) $r['per_page'] > (int) $r['max'] ) ) {
712
- $r['per_page'] = $r['max'];
 
 
 
 
713
  }
714
 
715
- /**
716
- * Filters whether BuddyPress should enable afilter support.
717
- *
718
- * Support for basic filters in earlier BP versions is disabled by default.
719
- * To enable, put add_filter( 'bp_activity_enable_afilter_support', '__return_true' );
720
- * into bp-custom.php or your theme's functions.php.
721
- *
722
- * @since 1.6.0
723
- *
724
- * @param bool $value True if BuddyPress should enable afilter support.
725
- */
726
- if ( isset( $_GET['afilter'] ) && apply_filters( 'bp_activity_enable_afilter_support', false ) ) {
727
- $r['filter'] = array(
728
- 'object' => $_GET['afilter']
729
- );
730
- } elseif ( ! empty( $r['user_id'] ) || ! empty( $r['object'] ) || ! empty( $r['action'] ) || ! empty( $r['primary_id'] ) || ! empty( $r['secondary_id'] ) || ! empty( $r['offset'] ) || ! empty( $r['since'] ) ) {
731
- $r['filter'] = array(
732
- 'user_id' => $r['user_id'],
733
- 'object' => $r['object'],
734
- 'action' => $r['action'],
735
- 'primary_id' => $r['primary_id'],
736
- 'secondary_id' => $r['secondary_id'],
737
- 'offset' => $r['offset'],
738
- 'since' => $r['since']
739
- );
740
- } else {
741
- $r['filter'] = false;
742
- }
743
 
744
- // If specific activity items have been requested, override the $hide_spam
745
- // argument. This prevents backpat errors with AJAX.
746
- if ( ! empty( $r['include'] ) && ( 'ham_only' === $r['spam'] ) ) {
747
- $r['spam'] = 'all';
748
- }
 
 
 
 
749
 
750
- /*
751
- * Query
752
- */
753
 
754
- $activities_template = new BP_Activity_Template( $r );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
755
 
756
- /**
757
- * Filters whether or not there are activity items to display.
758
- *
759
- * @since 1.1.0
760
- *
761
- * @param bool $value Whether or not there are activity items to display.
762
- * @param string $activities_template Current activities template being used.
763
- * @param array $r Array of arguments passed into the BP_Activity_Template class.
764
- */
765
- return apply_filters( 'bp_has_activities', $activities_template->has_activities(), $activities_template, $r );
766
  }
767
 
768
  /**
769
  * Determine if there are still activities left in the loop.
770
  *
771
- * @since 1.0.0
772
  *
773
  * @global object $activities_template {@link BP_Activity_Template}
774
  * @uses BP_Activity_Template::user_activities() {@link BP_Activity_Template::user_activities()}
@@ -783,7 +692,7 @@ function bp_activities() {
783
  /**
784
  * Get the current activity object in the loop.
785
  *
786
- * @since 1.0.0
787
  *
788
  * @global object $activities_template {@link BP_Activity_Template}
789
  * @uses BP_Activity_Template::the_activity() {@link BP_Activity_Template::the_activity()}
@@ -795,43 +704,10 @@ function bp_the_activity() {
795
  return $activities_template->the_activity();
796
  }
797
 
798
- /**
799
- * Output the URL for the Load More link.
800
- *
801
- * @since 2.1.0
802
- */
803
- function bp_activity_load_more_link() {
804
- echo esc_url( bp_get_activity_load_more_link() );
805
- }
806
- /**
807
- * Get the URL for the Load More link.
808
- *
809
- * @since 2.1.0
810
- *
811
- * @return string $link
812
- */
813
- function bp_get_activity_load_more_link() {
814
- global $activities_template;
815
-
816
- $url = bp_get_requested_url();
817
- $link = add_query_arg( $activities_template->pag_arg, $activities_template->pag_page + 1, $url );
818
-
819
- /**
820
- * Filters the Load More link URL.
821
- *
822
- * @since 2.1.0
823
- *
824
- * @param string $link The "Load More" link URL with appropriate query args.
825
- * @param string $url The original URL.
826
- * @param object $activities_template The activity template loop global.
827
- */
828
- return apply_filters( 'bp_get_activity_load_more_link', $link, $url, $activities_template );
829
- }
830
-
831
  /**
832
  * Output the activity pagination count.
833
  *
834
- * @since 1.0.0
835
  *
836
  * @global object $activities_template {@link BP_Activity_Template}
837
  * @uses BP_Activity_Template::the_activity() {@link BP_Activity_Template::the_activity()}
@@ -843,7 +719,7 @@ function bp_activity_pagination_count() {
843
  /**
844
  * Return the activity pagination count.
845
  *
846
- * @since 1.2.0
847
  *
848
  * @global object $activities_template {@link BP_Activity_Template}
849
  * @uses bp_core_number_format()
@@ -858,19 +734,13 @@ function bp_activity_pagination_count() {
858
  $to_num = bp_core_number_format( ( $start_num + ( $activities_template->pag_num - 1 ) > $activities_template->total_activity_count ) ? $activities_template->total_activity_count : $start_num + ( $activities_template->pag_num - 1 ) );
859
  $total = bp_core_number_format( $activities_template->total_activity_count );
860
 
861
- if ( 1 == $activities_template->total_activity_count ) {
862
- $message = __( 'Viewing 1 item', 'buddypress' );
863
- } else {
864
- $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s item', 'Viewing %1$s - %2$s of %3$s items', $activities_template->total_activity_count, 'buddypress' ), $from_num, $to_num, $total );
865
- }
866
-
867
- return $message;
868
  }
869
 
870
  /**
871
  * Output the activity pagination links.
872
  *
873
- * @since 1.0.0
874
  *
875
  * @uses bp_get_activity_pagination_links()
876
  */
@@ -881,7 +751,7 @@ function bp_activity_pagination_links() {
881
  /**
882
  * Return the activity pagination links.
883
  *
884
- * @since 1.0.0
885
  *
886
  * @global object $activities_template {@link BP_Activity_Template}
887
  * @uses apply_filters() To call the 'bp_get_activity_pagination_links' hook.
@@ -891,20 +761,13 @@ function bp_activity_pagination_links() {
891
  function bp_get_activity_pagination_links() {
892
  global $activities_template;
893
 
894
- /**
895
- * Filters the activity pagination link output.
896
- *
897
- * @since 1.0.0
898
- *
899
- * @param string $pag_links Output for the activity pagination links.
900
- */
901
  return apply_filters( 'bp_get_activity_pagination_links', $activities_template->pag_links );
902
  }
903
 
904
  /**
905
  * Return true when there are more activity items to be shown than currently appear.
906
  *
907
- * @since 1.5.0
908
  *
909
  * @global object $activities_template {@link BP_Activity_Template}
910
  * @uses apply_filters() To call the 'bp_activity_has_more_items' hook.
@@ -914,32 +777,21 @@ function bp_activity_pagination_links() {
914
  function bp_activity_has_more_items() {
915
  global $activities_template;
916
 
917
- if ( ! empty( $activities_template->has_more_items ) ) {
918
- $has_more_items = true;
919
- } else {
920
- $remaining_pages = 0;
921
 
922
- if ( ! empty( $activities_template->pag_page ) ) {
923
- $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->pag_num * $activities_template->pag_page ) );
924
- }
925
-
926
- $has_more_items = (int) $remaining_pages > 0;
927
  }
928
 
929
- /**
930
- * Filters whether there are more activity items to display.
931
- *
932
- * @since 1.5.0
933
- *
934
- * @param bool $has_more_items Whether or not there are more activity items to display.
935
- */
936
  return apply_filters( 'bp_activity_has_more_items', $has_more_items );
937
  }
938
 
939
  /**
940
  * Output the activity count.
941
  *
942
- * @since 1.2.0
943
  *
944
  * @uses bp_get_activity_count()
945
  */
@@ -950,7 +802,7 @@ function bp_activity_count() {
950
  /**
951
  * Return the activity count.
952
  *
953
- * @since 1.2.0
954
  *
955
  * @global object $activities_template {@link BP_Activity_Template}
956
  * @uses apply_filters() To call the 'bp_get_activity_count' hook.
@@ -960,20 +812,13 @@ function bp_activity_count() {
960
  function bp_get_activity_count() {
961
  global $activities_template;
962
 
963
- /**
964
- * Filters the activity count for the activity template.
965
- *
966
- * @since 1.2.0
967
- *
968
- * @param int $activity_count The count for total activity.
969
- */
970
  return apply_filters( 'bp_get_activity_count', (int) $activities_template->activity_count );
971
  }
972
 
973
  /**
974
  * Output the number of activities per page.
975
  *
976
- * @since 1.2.0
977
  *
978
  * @uses bp_get_activity_per_page()
979
  */
@@ -984,7 +829,7 @@ function bp_activity_per_page() {
984
  /**
985
  * Return the number of activities per page.
986
  *
987
- * @since 1.2.0
988
  *
989
  * @global object $activities_template {@link BP_Activity_Template}
990
  * @uses apply_filters() To call the 'bp_get_activity_per_page' hook.
@@ -994,20 +839,13 @@ function bp_activity_per_page() {
994
  function bp_get_activity_per_page() {
995
  global $activities_template;
996
 
997
- /**
998
- * Filters the activity posts per page value.
999
- *
1000
- * @since 1.2.0
1001
- *
1002
- * @param int $pag_num How many post should be displayed for pagination.
1003
- */
1004
  return apply_filters( 'bp_get_activity_per_page', (int) $activities_template->pag_num );
1005
  }
1006
 
1007
  /**
1008
  * Output the activities title.
1009
  *
1010
- * @since 1.0.0
1011
  *
1012
  * @uses bp_get_activities_title()
1013
  * @todo Deprecate.
@@ -1019,31 +857,24 @@ function bp_activities_title() {
1019
  /**
1020
  * Return the activities title.
1021
  *
1022
- * @since 1.0.0
1023
  *
1024
  * @global string $bp_activity_title
1025
  * @uses apply_filters() To call the 'bp_get_activities_title' hook.
1026
  * @todo Deprecate.
1027
  *
1028
- * @return string The activities title.
1029
  */
1030
  function bp_get_activities_title() {
1031
  global $bp_activity_title;
1032
 
1033
- /**
1034
- * Filters the activities title for the activity template.
1035
- *
1036
- * @since 1.0.0
1037
- *
1038
- * @param string $bp_activity_title The title to be displayed.
1039
- */
1040
  return apply_filters( 'bp_get_activities_title', $bp_activity_title );
1041
  }
1042
 
1043
  /**
1044
  * {@internal Missing Description}
1045
  *
1046
- * @since 1.0.0
1047
  *
1048
  * @uses bp_get_activities_no_activity()
1049
  * @todo Deprecate.
@@ -1055,10 +886,10 @@ function bp_activities_no_activity() {
1055
  /**
1056
  * {@internal Missing Description}
1057
  *
1058
- * @since 1.0.0
1059
  *
1060
  * @global string $bp_activity_no_activity
1061
- * @uses apply_filters() To call the 'bp_get_activities_no_activity' hook.
1062
  * @todo Deprecate.
1063
  *
1064
  * @return string
@@ -1066,20 +897,13 @@ function bp_activities_no_activity() {
1066
  function bp_get_activities_no_activity() {
1067
  global $bp_activity_no_activity;
1068
 
1069
- /**
1070
- * Filters the text used when there is no activity to display.
1071
- *
1072
- * @since 1.0.0
1073
- *
1074
- * @param string $bp_activity_no_activity Text to display for no activity.
1075
- */
1076
  return apply_filters( 'bp_get_activities_no_activity', $bp_activity_no_activity );
1077
  }
1078
 
1079
  /**
1080
  * Output the activity ID.
1081
  *
1082
- * @since 1.2.0
1083
  *
1084
  * @uses bp_get_activity_id()
1085
  */
@@ -1090,7 +914,7 @@ function bp_activity_id() {
1090
  /**
1091
  * Return the activity ID.
1092
  *
1093
- * @since 1.2.0
1094
  *
1095
  * @global object $activities_template {@link BP_Activity_Template}
1096
  * @uses apply_filters() To call the 'bp_get_activity_id' hook.
@@ -1099,21 +923,13 @@ function bp_activity_id() {
1099
  */
1100
  function bp_get_activity_id() {
1101
  global $activities_template;
1102
-
1103
- /**
1104
- * Filters the activity ID being displayed.
1105
- *
1106
- * @since 1.2.0
1107
- *
1108
- * @param int $id The activity ID.
1109
- */
1110
  return apply_filters( 'bp_get_activity_id', $activities_template->activity->id );
1111
  }
1112
 
1113
  /**
1114
  * Output the activity item ID.
1115
  *
1116
- * @since 1.2.0
1117
  *
1118
  * @uses bp_get_activity_item_id()
1119
  */
@@ -1124,7 +940,7 @@ function bp_activity_item_id() {
1124
  /**
1125
  * Return the activity item ID.
1126
  *
1127
- * @since 1.2.0
1128
  *
1129
  * @global object $activities_template {@link BP_Activity_Template}
1130
  * @uses apply_filters() To call the 'bp_get_activity_item_id' hook.
@@ -1133,21 +949,13 @@ function bp_activity_item_id() {
1133
  */
1134
  function bp_get_activity_item_id() {
1135
  global $activities_template;
1136
-
1137
- /**
1138
- * Filters the activity item ID being displayed.
1139
- *
1140
- * @since 1.2.0
1141
- *
1142
- * @param int $item_id The activity item ID.
1143
- */
1144
  return apply_filters( 'bp_get_activity_item_id', $activities_template->activity->item_id );
1145
  }
1146
 
1147
  /**
1148
  * Output the activity secondary item ID.
1149
  *
1150
- * @since 1.2.0
1151
  *
1152
  * @uses bp_get_activity_secondary_item_id()
1153
  */
@@ -1158,7 +966,7 @@ function bp_activity_secondary_item_id() {
1158
  /**
1159
  * Return the activity secondary item ID.
1160
  *
1161
- * @since 1.2.0
1162
  *
1163
  * @global object $activities_template {@link BP_Activity_Template}
1164
  * @uses apply_filters() To call the 'bp_get_activity_secondary_item_id' hook.
@@ -1167,21 +975,13 @@ function bp_activity_secondary_item_id() {
1167
  */
1168
  function bp_get_activity_secondary_item_id() {
1169
  global $activities_template;
1170
-
1171
- /**
1172
- * Filters the activity secondary item ID being displayed.
1173
- *
1174
- * @since 1.2.0
1175
- *
1176
- * @param int $secondary_item_id The activity secondary item ID.
1177
- */
1178
  return apply_filters( 'bp_get_activity_secondary_item_id', $activities_template->activity->secondary_item_id );
1179
  }
1180
 
1181
  /**
1182
  * Output the date the activity was recorded.
1183
  *
1184
- * @since 1.2.0
1185
  *
1186
  * @uses bp_get_activity_date_recorded()
1187
  */
@@ -1192,7 +992,7 @@ function bp_activity_date_recorded() {
1192
  /**
1193
  * Return the date the activity was recorded.
1194
  *
1195
- * @since 1.2.0
1196
  *
1197
  * @global object $activities_template {@link BP_Activity_Template}
1198
  * @uses apply_filters() To call the 'bp_get_activity_date_recorded' hook.
@@ -1201,59 +1001,13 @@ function bp_activity_date_recorded() {
1201
  */
1202
  function bp_get_activity_date_recorded() {
1203
  global $activities_template;
1204
-
1205
- /**
1206
- * Filters the date the activity was recorded.
1207
- *
1208
- * @since 1.2.0
1209
- *
1210
- * @param int $date_recorded The activity's date.
1211
- */
1212
  return apply_filters( 'bp_get_activity_date_recorded', $activities_template->activity->date_recorded );
1213
  }
1214
 
1215
- /**
1216
- * Output the display name of the member who posted the activity.
1217
- *
1218
- * @since 2.1.0
1219
- *
1220
- * @uses bp_get_activity_member_display_name()
1221
- */
1222
- function bp_activity_member_display_name() {
1223
- echo bp_get_activity_member_display_name();
1224
- }
1225
-
1226
- /**
1227
- * Return the display name of the member who posted the activity.
1228
- *
1229
- * @since 2.1.0
1230
- *
1231
- * @global object $activities_template {@link BP_Activity_Template}
1232
- * @uses apply_filters() To call the 'bp_get_activity_member_display_name' hook.
1233
- *
1234
- * @return string The date the activity was recorded.
1235
- */
1236
- function bp_get_activity_member_display_name() {
1237
- global $activities_template;
1238
-
1239
- $retval = isset( $activities_template->activity->display_name )
1240
- ? $activities_template->activity->display_name
1241
- : '';
1242
-
1243
- /**
1244
- * Filters the display name of the member who posted the activity.
1245
- *
1246
- * @since 2.1.0
1247
- *
1248
- * @param int $retval Display name for the member who posted.
1249
- */
1250
- return apply_filters( 'bp_get_activity_member_display_name', $retval );
1251
- }
1252
-
1253
  /**
1254
  * Output the activity object name.
1255
  *
1256
- * @since 1.2.0
1257
  *
1258
  * @uses bp_get_activity_object_name()
1259
  */
@@ -1264,7 +1018,7 @@ function bp_activity_object_name() {
1264
  /**
1265
  * Return the activity object name.
1266
  *
1267
- * @since 1.2.0
1268
  *
1269
  * @global object $activities_template {@link BP_Activity_Template}
1270
  * @uses apply_filters() To call the 'bp_get_activity_object_name' hook.
@@ -1273,21 +1027,13 @@ function bp_activity_object_name() {
1273
  */
1274
  function bp_get_activity_object_name() {
1275
  global $activities_template;
1276
-
1277
- /**
1278
- * Filters the activity object name.
1279
- *
1280
- * @since 1.2.0
1281
- *
1282
- * @param string $activity_component The activity object name.
1283
- */
1284
  return apply_filters( 'bp_get_activity_object_name', $activities_template->activity->component );
1285
  }
1286
 
1287
  /**
1288
  * Output the activity type.
1289
  *
1290
- * @since 1.2.0
1291
  *
1292
  * @uses bp_get_activity_type()
1293
  */
@@ -1298,7 +1044,7 @@ function bp_activity_type() {
1298
  /**
1299
  * Return the activity type.
1300
  *
1301
- * @since 1.2.0
1302
  *
1303
  * @global object $activities_template {@link BP_Activity_Template}
1304
  * @uses apply_filters() To call the 'bp_get_activity_type' hook.
@@ -1307,14 +1053,6 @@ function bp_activity_type() {
1307
  */
1308
  function bp_get_activity_type() {
1309
  global $activities_template;
1310
-
1311
- /**
1312
- * Filters the activity type.
1313
- *
1314
- * @since 1.2.0
1315
- *
1316
- * @param string $activity_type The activity type.
1317
- */
1318
  return apply_filters( 'bp_get_activity_type', $activities_template->activity->type );
1319
  }
1320
 
@@ -1323,11 +1061,11 @@ function bp_activity_type() {
1323
  *
1324
  * Just a wrapper for bp_activity_type().
1325
  *
1326
- * @since 1.2.0
1327
- * @deprecated 1.5.0
1328
  *
1329
  * @todo Properly deprecate in favor of bp_activity_type() and
1330
- * remove redundant echo
1331
  *
1332
  * @uses bp_activity_type()
1333
  */
@@ -1338,8 +1076,8 @@ function bp_activity_type() {
1338
  *
1339
  * Just a wrapper for bp_get_activity_type().
1340
  *
1341
- * @since 1.2.0
1342
- * @deprecated 1.5.0
1343
  *
1344
  * @todo Properly deprecate in favor of bp_get_activity_type().
1345
  *
@@ -1352,7 +1090,7 @@ function bp_activity_type() {
1352
  /**
1353
  * Output the activity user ID.
1354
  *
1355
- * @since 1.1.0
1356
  *
1357
  * @uses bp_get_activity_user_id()
1358
  */
@@ -1363,7 +1101,7 @@ function bp_activity_user_id() {
1363
  /**
1364
  * Return the activity user ID.
1365
  *
1366
- * @since 1.1.0
1367
  *
1368
  * @global object $activities_template {@link BP_Activity_Template}
1369
  * @uses apply_filters() To call the 'bp_get_activity_user_id' hook.
@@ -1372,21 +1110,13 @@ function bp_activity_user_id() {
1372
  */
1373
  function bp_get_activity_user_id() {
1374
  global $activities_template;
1375
-
1376
- /**
1377
- * Filters the activity user ID.
1378
- *
1379
- * @since 1.1.0
1380
- *
1381
- * @param int $user_id The activity user ID.
1382
- */
1383
  return apply_filters( 'bp_get_activity_user_id', $activities_template->activity->user_id );
1384
  }
1385
 
1386
  /**
1387
  * Output the activity user link.
1388
  *
1389
- * @since 1.2.0
1390
  *
1391
  * @uses bp_get_activity_user_link()
1392
  */
@@ -1397,7 +1127,7 @@ function bp_activity_user_link() {
1397
  /**
1398
  * Return the activity user link.
1399
  *
1400
- * @since 1.2.0
1401
  *
1402
  * @global object $activities_template {@link BP_Activity_Template}
1403
  * @uses bp_core_get_user_domain()
@@ -1408,31 +1138,23 @@ function bp_activity_user_link() {
1408
  function bp_get_activity_user_link() {
1409
  global $activities_template;
1410
 
1411
- if ( empty( $activities_template->activity->user_id ) || empty( $activities_template->activity->user_nicename ) || empty( $activities_template->activity->user_login ) ) {
1412
  $link = $activities_template->activity->primary_link;
1413
- } else {
1414
  $link = bp_core_get_user_domain( $activities_template->activity->user_id, $activities_template->activity->user_nicename, $activities_template->activity->user_login );
1415
- }
1416
 
1417
- /**
1418
- * Filters the activity user link.
1419
- *
1420
- * @since 1.2.0
1421
- *
1422
- * @param string $link The activity user link.
1423
- */
1424
  return apply_filters( 'bp_get_activity_user_link', $link );
1425
  }
1426
 
1427
  /**
1428
  * Output the avatar of the user that performed the action.
1429
  *
1430
- * @since 1.1.0
1431
  *
1432
  * @see bp_get_activity_avatar() for description of arguments.
1433
  * @uses bp_get_activity_avatar()
1434
  *
1435
- * @param array|string $args See {@link bp_get_activity_avatar()} for description.
1436
  */
1437
  function bp_activity_avatar( $args = '' ) {
1438
  echo bp_get_activity_avatar( $args );
@@ -1440,29 +1162,30 @@ function bp_activity_avatar( $args = '' ) {
1440
  /**
1441
  * Return the avatar of the user that performed the action.
1442
  *
1443
- * @since 1.1.0
1444
  *
1445
  * @see bp_core_fetch_avatar() For a description of the arguments.
1446
  * @global object $activities_template {@link BP_Activity_Template}
 
1447
  * @uses bp_is_single_activity()
1448
  * @uses wp_parse_args()
1449
- * @uses apply_filters() To call the 'bp_get_activity_avatar_object_' . $current_activity_item->component hook.
1450
- * @uses apply_filters() To call the 'bp_get_activity_avatar_item_id' hook.
1451
  * @uses bp_core_fetch_avatar()
1452
- * @uses apply_filters() To call the 'bp_get_activity_avatar' hook.
1453
  *
1454
- * @param array|string $args {
1455
  * Arguments are listed here with an explanation of their defaults.
1456
  * For more information about the arguments, see
1457
  * {@link bp_core_fetch_avatar()}.
1458
- * @type string $alt Default: 'Profile picture of [user name]' if
1459
- * activity user name is available, otherwise 'Profile picture'.
1460
- * @type string $class Default: 'avatar'.
1461
- * @type string|bool $email Default: Email of the activity's
1462
- * associated user, if available. Otherwise false.
1463
- * @type string $type Default: 'full' when viewing a single activity
1464
- * permalink page, otherwise 'thumb'.
1465
- * @type int|bool $user_id Default: ID of the activity's user.
1466
  * }
1467
  * @return string User avatar string.
1468
  */
@@ -1471,17 +1194,17 @@ function bp_activity_avatar( $args = '' ) {
1471
 
1472
  $bp = buddypress();
1473
 
1474
- // On activity permalink pages, default to the full-size avatar.
1475
  $type_default = bp_is_single_activity() ? 'full' : 'thumb';
1476
 
1477
  // Within the activity comment loop, the current activity should be set
1478
  // to current_comment. Otherwise, just use activity.
1479
  $current_activity_item = isset( $activities_template->activity->current_comment ) ? $activities_template->activity->current_comment : $activities_template->activity;
1480
 
1481
- // Activity user display name.
1482
  $dn_default = isset( $current_activity_item->display_name ) ? $current_activity_item->display_name : '';
1483
 
1484
- // Prepend some descriptive text to alt.
1485
  $alt_default = !empty( $dn_default ) ? sprintf( __( 'Profile picture of %s', 'buddypress' ), $dn_default ) : __( 'Profile picture', 'buddypress' );
1486
 
1487
  $defaults = array(
@@ -1497,14 +1220,14 @@ function bp_activity_avatar( $args = '' ) {
1497
 
1498
  if ( !isset( $height ) && !isset( $width ) ) {
1499
 
1500
- // Backpat.
1501
  if ( isset( $bp->avatar->full->height ) || isset( $bp->avatar->thumb->height ) ) {
1502
  $height = ( 'full' == $type ) ? $bp->avatar->full->height : $bp->avatar->thumb->height;
1503
  } else {
1504
  $height = 20;
1505
  }
1506
 
1507
- // Backpat.
1508
  if ( isset( $bp->avatar->full->width ) || isset( $bp->avatar->thumb->width ) ) {
1509
  $width = ( 'full' == $type ) ? $bp->avatar->full->width : $bp->avatar->thumb->width;
1510
  } else {
@@ -1512,41 +1235,15 @@ function bp_activity_avatar( $args = '' ) {
1512
  }
1513
  }
1514
 
1515
- /**
1516
- * Filters the activity avatar object based on current activity item component.
1517
- *
1518
- * This is a variable filter dependent on the component used.
1519
- * Possible hooks are bp_get_activity_avatar_object_blog,
1520
- * bp_get_activity_avatar_object_group, and bp_get_activity_avatar_object_user.
1521
- *
1522
- * @since 1.1.0
1523
- *
1524
- * @param string $component Component being displayed.
1525
- */
1526
  $object = apply_filters( 'bp_get_activity_avatar_object_' . $current_activity_item->component, 'user' );
1527
  $item_id = !empty( $user_id ) ? $user_id : $current_activity_item->user_id;
1528
-
1529
- /**
1530
- * Filters the activity avatar item ID.
1531
- *
1532
- * @since 1.2.10
1533
- *
1534
- * @param int $item_id Item ID for the activity avatar.
1535
- */
1536
  $item_id = apply_filters( 'bp_get_activity_avatar_item_id', $item_id );
1537
 
1538
- // If this is a user object pass the users' email address for Gravatar so we don't have to prefetch it.
1539
- if ( 'user' == $object && empty( $user_id ) && empty( $email ) && isset( $current_activity_item->user_email ) ) {
1540
  $email = $current_activity_item->user_email;
1541
- }
1542
 
1543
- /**
1544
- * Filters the value returned by bp_core_fetch_avatar.
1545
- *
1546
- * @since 1.1.3
1547
- *
1548
- * @param array $value Array of arguments calculated for use with bp_core_fetch_avatar.
1549
- */
1550
  return apply_filters( 'bp_get_activity_avatar', bp_core_fetch_avatar( array(
1551
  'item_id' => $item_id,
1552
  'object' => $object,
@@ -1562,21 +1259,21 @@ function bp_activity_avatar( $args = '' ) {
1562
  /**
1563
  * Output the avatar of the object that action was performed on.
1564
  *
1565
- * @since 1.2.0
1566
  *
1567
  * @see bp_get_activity_secondary_avatar() for description of arguments.
1568
  * @uses bp_get_activity_secondary_avatar()
1569
  *
1570
- * @param array|string $args See {@link bp_get_activity_secondary_avatar} for description.
1571
  */
1572
  function bp_activity_secondary_avatar( $args = '' ) {
1573
  echo bp_get_activity_secondary_avatar( $args );
1574
  }
1575
 
1576
  /**
1577
- * Return the avatar of the object that action was performed on.
1578
  *
1579
- * @since 1.2.0
1580
  *
1581
  * @see bp_core_fetch_avatar() for description of arguments.
1582
  * @global object $activities_template {@link BP_Activity_Template}
@@ -1587,17 +1284,17 @@ function bp_activity_secondary_avatar( $args = '' ) {
1587
  * @uses bp_core_fetch_avatar()
1588
  * @uses apply_filters() To call the 'bp_get_activity_secondary_avatar' hook.
1589
  *
1590
- * @param array|string $args {
1591
  * For a complete description of arguments, see {@link bp_core_fetch_avatar()}.
1592
- * @type string $alt Default value varies based on current activity
1593
- * item component.
1594
- * @type string $type Default: 'full' when viewing a single activity
1595
- * permalink page, otherwise 'thumb'.
1596
- * @type string $class Default: 'avatar'.
1597
- * @type string|bool $email Default: email of the activity's user.
1598
- * @type int|bool $user_id Default: ID of the activity's user.
1599
  * }
1600
- * @return string The secondary avatar.
1601
  */
1602
  function bp_get_activity_secondary_avatar( $args = '' ) {
1603
  global $activities_template;
@@ -1614,19 +1311,15 @@ function bp_activity_secondary_avatar( $args = '' ) {
1614
  ) );
1615
  extract( $r, EXTR_SKIP );
1616
 
1617
- // Set item_id and object (default to user).
1618
  switch ( $activities_template->activity->component ) {
1619
  case 'groups' :
1620
- if ( bp_disable_group_avatar_uploads() ) {
1621
- return false;
1622
- }
1623
-
1624
  $object = 'group';
1625
  $item_id = $activities_template->activity->item_id;
1626
  $link = '';
1627
  $name = '';
1628
 
1629
- // Only if groups is active.
1630
  if ( bp_is_active( 'groups' ) ) {
1631
  $group = groups_get_group( array(
1632
  'group_id' => $item_id,
@@ -1679,34 +1372,16 @@ function bp_activity_secondary_avatar( $args = '' ) {
1679
  break;
1680
  }
1681
 
1682
- /**
1683
- * Filters the activity secondary avatar object based on current activity item component.
1684
- *
1685
- * This is a variable filter dependent on the component used. Possible hooks are
1686
- * bp_get_activity_secondary_avatar_object_blog, bp_get_activity_secondary_avatar_object_group,
1687
- * and bp_get_activity_secondary_avatar_object_user.
1688
- *
1689
- * @since 1.2.10
1690
- *
1691
- * @param string $object Component being displayed.
1692
- */
1693
  $object = apply_filters( 'bp_get_activity_secondary_avatar_object_' . $activities_template->activity->component, $object );
1694
-
1695
- /**
1696
- * Filters the activity secondary avatar item ID.
1697
- *
1698
- * @since 1.2.10
1699
- *
1700
- * @param int $item_id ID for the secondary avatar item.
1701
- */
1702
  $item_id = apply_filters( 'bp_get_activity_secondary_avatar_item_id', $item_id );
1703
 
1704
- // If we have no item_id or object, there is no avatar to display.
1705
  if ( empty( $item_id ) || empty( $object ) ) {
1706
  return false;
1707
  }
1708
 
1709
- // Get the avatar.
1710
  $avatar = bp_core_fetch_avatar( array(
1711
  'item_id' => $item_id,
1712
  'object' => $object,
@@ -1719,43 +1394,25 @@ function bp_activity_secondary_avatar( $args = '' ) {
1719
  ) );
1720
 
1721
  if ( !empty( $linked ) ) {
1722
-
1723
- /**
1724
- * Filters the secondary avatar link for current activity.
1725
- *
1726
- * @since 1.7.0
1727
- *
1728
- * @param string $link Link to wrap the avatar image in.
1729
- * @param string $component Activity component being acted on.
1730
- */
1731
  $link = apply_filters( 'bp_get_activity_secondary_avatar_link', $link, $activities_template->activity->component );
1732
 
1733
- /**
1734
- * Filters the determined avatar for the secondary activity item.
1735
- *
1736
- * @since 1.2.10
1737
- *
1738
- * @param string $avatar Formatted HTML <img> element, or raw avatar URL.
1739
- */
1740
- $avatar = apply_filters( 'bp_get_activity_secondary_avatar', $avatar );
1741
-
1742
  return sprintf( '<a href="%s" class="%s">%s</a>',
1743
  $link,
1744
  $link_class,
1745
- $avatar
1746
  );
1747
  }
1748
 
1749
- /** This filter is documented in bp-activity/bp-activity-template.php */
1750
  return apply_filters( 'bp_get_activity_secondary_avatar', $avatar );
1751
  }
1752
 
1753
  /**
1754
- * Output the activity action.
1755
  *
1756
- * @since 1.2.0
1757
  *
1758
- * @param array $args See bp_get_activity_action().
1759
  * @uses bp_get_activity_action()
1760
  */
1761
  function bp_activity_action( $args = array() ) {
@@ -1763,64 +1420,44 @@ function bp_activity_action( $args = array() ) {
1763
  }
1764
 
1765
  /**
1766
- * Return the activity action.
1767
  *
1768
- * @since 1.2.0
1769
  *
1770
  * @global object $activities_template {@link BP_Activity_Template}
1771
- * @uses apply_filters_ref_array() To call the 'bp_get_activity_action_pre_meta' hook.
 
1772
  * @uses bp_insert_activity_meta()
1773
  * @uses apply_filters_ref_array() To call the 'bp_get_activity_action' hook.
1774
  *
1775
  * @param array $args {
1776
  * @type bool $no_timestamp Whether to exclude the timestamp.
1777
  * }
1778
- *
1779
  * @return string The activity action.
1780
  */
1781
  function bp_get_activity_action( $args = array() ) {
1782
  global $activities_template;
1783
 
1784
- $r = wp_parse_args( $args, array(
1785
  'no_timestamp' => false,
1786
- ) );
1787
 
1788
- /**
1789
- * Filters the activity action before the action is inserted as meta.
1790
- *
1791
- * @since 1.2.10
1792
- *
1793
- * @param array $value Array containing the current action, the current activity, and the $args array passed into the function.
1794
- */
1795
- $action = apply_filters_ref_array( 'bp_get_activity_action_pre_meta', array(
1796
- $activities_template->activity->action,
1797
- &$activities_template->activity,
1798
- $r
1799
- ) );
1800
 
1801
- // Prepend the activity action meta (link, time since, etc...).
1802
- if ( ! empty( $action ) && empty( $r['no_timestamp'] ) ) {
1803
  $action = bp_insert_activity_meta( $action );
1804
- }
1805
 
1806
- /**
1807
- * Filters the activity action after the action has been inserted as meta.
1808
- *
1809
- * @since 1.2.0
1810
- *
1811
- * @param array $value Array containing the current action, the current activity, and the $args array passed into the function.
1812
- */
1813
- return apply_filters_ref_array( 'bp_get_activity_action', array(
1814
- $action,
1815
- &$activities_template->activity,
1816
- $r
1817
- ) );
1818
  }
1819
 
1820
  /**
1821
- * Output the activity content body.
1822
  *
1823
- * @since 1.2.0
1824
  *
1825
  * @uses bp_get_activity_content_body()
1826
  */
@@ -1829,9 +1466,9 @@ function bp_activity_content_body() {
1829
  }
1830
 
1831
  /**
1832
- * Return the activity content body.
1833
  *
1834
- * @since 1.2.0
1835
  *
1836
  * @global object $activities_template {@link BP_Activity_Template}
1837
  * @uses bp_insert_activity_meta()
@@ -1842,25 +1479,17 @@ function bp_activity_content_body() {
1842
  function bp_get_activity_content_body() {
1843
  global $activities_template;
1844
 
1845
- // Backwards compatibility if action is not being used.
1846
- if ( empty( $activities_template->activity->action ) && ! empty( $activities_template->activity->content ) ) {
1847
  $activities_template->activity->content = bp_insert_activity_meta( $activities_template->activity->content );
1848
- }
1849
 
1850
- /**
1851
- * Filters the activity content body.
1852
- *
1853
- * @since 1.2.0
1854
- *
1855
- * @param array $value Array containing the current activity content body and the current activity.
1856
- */
1857
  return apply_filters_ref_array( 'bp_get_activity_content_body', array( $activities_template->activity->content, &$activities_template->activity ) );
1858
  }
1859
 
1860
  /**
1861
  * Does the activity have content?
1862
  *
1863
- * @since 1.2.0
1864
  *
1865
  * @global object $activities_template {@link BP_Activity_Template}
1866
  *
@@ -1869,9 +1498,8 @@ function bp_activity_content_body() {
1869
  function bp_activity_has_content() {
1870
  global $activities_template;
1871
 
1872
- if ( ! empty( $activities_template->activity->content ) ) {
1873
  return true;
1874
- }
1875
 
1876
  return false;
1877
  }
@@ -1879,8 +1507,8 @@ function bp_activity_has_content() {
1879
  /**
1880
  * Output the activity content.
1881
  *
1882
- * @since 1.0.0
1883
- * @deprecated 1.5.0
1884
  *
1885
  * @todo properly deprecate this function.
1886
  *
@@ -1893,8 +1521,8 @@ function bp_activity_content() {
1893
  /**
1894
  * Return the activity content.
1895
  *
1896
- * @since 1.0.0
1897
- * @deprecated 1.5.0
1898
  *
1899
  * @todo properly deprecate this function.
1900
  *
@@ -1905,13 +1533,13 @@ function bp_activity_content() {
1905
  * @return string The activity content.
1906
  */
1907
  function bp_get_activity_content() {
1908
-
1909
  /**
1910
  * If you want to filter activity update content, please use
1911
- * the filter 'bp_get_activity_content_body'.
1912
  *
1913
- * This function is mainly for backwards compatibility.
1914
  */
 
1915
  $content = bp_get_activity_action() . ' ' . bp_get_activity_content_body();
1916
  return apply_filters( 'bp_get_activity_content', $content );
1917
  }
@@ -1922,7 +1550,7 @@ function bp_activity_content() {
1922
  * This metadata includes the time since the item was posted (which will appear
1923
  * as a link to the item's permalink).
1924
  *
1925
- * @since 1.2.0
1926
  *
1927
  * @global object $activities_template {@link BP_Activity_Template}
1928
  * @uses bp_core_time_since()
@@ -1936,133 +1564,67 @@ function bp_activity_content() {
1936
  * @param string $content The activity content.
1937
  * @return string The activity content with the metadata string attached.
1938
  */
1939
- function bp_insert_activity_meta( $content = '' ) {
1940
  global $activities_template;
1941
 
1942
- // Strip any legacy time since placeholders from BP 1.0-1.1.
1943
- $new_content = str_replace( '<span class="time-since">%s</span>', '', $content );
1944
 
1945
- // Get the time since this activity was recorded.
1946
- $date_recorded = bp_core_time_since( $activities_template->activity->date_recorded );
1947
-
1948
- /**
1949
- * Filters the activity item time since markup.
1950
- *
1951
- * @since 1.2.0
1952
- *
1953
- * @param array $value Array containing the time since markup and the current activity component.
1954
- */
1955
- $time_since = apply_filters_ref_array( 'bp_activity_time_since', array(
1956
- '<span class="time-since">' . $date_recorded . '</span>',
1957
- &$activities_template->activity
1958
- ) );
1959
-
1960
- // Insert the permalink.
1961
- if ( ! bp_is_single_activity() ) {
1962
-
1963
- // Setup variables for activity meta.
1964
- $activity_permalink = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity );
1965
- $activity_meta = sprintf( '%1$s <a href="%2$s" class="view activity-time-since" title="%3$s">%4$s</a>',
1966
- $new_content,
1967
- $activity_permalink,
1968
- esc_attr__( 'View Discussion', 'buddypress' ),
1969
- $time_since
1970
- );
1971
 
1972
- /**
1973
- * Filters the activity permalink to be added to the activity content.
1974
- *
1975
- * @since 1.2.0
1976
- *
1977
- * @param array $value Array containing the html markup for the activity permalink, after being parsed by
1978
- * sprintf and current activity component.
1979
- */
1980
- $new_content = apply_filters_ref_array( 'bp_activity_permalink', array(
1981
- $activity_meta,
1982
- &$activities_template->activity
1983
- ) );
1984
- } else {
1985
- $new_content .= str_pad( $time_since, strlen( $time_since ) + 2, ' ', STR_PAD_BOTH );
1986
- }
1987
 
1988
- /**
1989
- * Filters the activity content after activity metadata has been attached.
1990
- *
1991
- * @since 1.2.0
1992
- *
1993
- * @param string $content Activity content with the activity metadata added.
1994
- */
1995
- return apply_filters( 'bp_insert_activity_meta', $new_content, $content );
1996
  }
1997
 
1998
  /**
1999
  * Determine if the current user can delete an activity item.
2000
  *
2001
- * @since 1.2.0
2002
  *
2003
  * @global object $activities_template {@link BP_Activity_Template}
2004
- * @uses apply_filters() To call the 'bp_activity_user_can_delete' hook.
2005
  *
2006
- * @param object|bool $activity Optional. Falls back on the current item in the loop.
2007
  * @return bool True if can delete, false otherwise.
2008
  */
2009
  function bp_activity_user_can_delete( $activity = false ) {
2010
  global $activities_template;
2011
 
2012
- // Try to use current activity if none was passed.
2013
- if ( empty( $activity ) && ! empty( $activities_template->activity ) ) {
2014
  $activity = $activities_template->activity;
2015
- }
2016
 
2017
- // If current_comment is set, we'll use that in place of the main activity.
2018
- if ( isset( $activity->current_comment ) ) {
2019
  $activity = $activity->current_comment;
2020
- }
2021
 
2022
- // Assume the user cannot delete the activity item.
2023
  $can_delete = false;
2024
 
2025
- // Only logged in users can delete activity.
2026
- if ( is_user_logged_in() ) {
2027
-
2028
- // Community moderators can always delete activity (at least for now).
2029
- if ( bp_current_user_can( 'bp_moderate' ) ) {
2030
- $can_delete = true;
2031
- }
2032
 
2033
- // Users are allowed to delete their own activity. This is actually
2034
- // quite powerful, because doing so also deletes all comments to that
2035
- // activity item. We should revisit this eventually.
2036
- if ( isset( $activity->user_id ) && ( (int) $activity->user_id === bp_loggedin_user_id() ) ) {
2037
- $can_delete = true;
2038
- }
2039
 
2040
- // Viewing a single item, and this user is an admin of that item.
2041
- if ( bp_is_single_item() && bp_is_item_admin() ) {
2042
- $can_delete = true;
2043
- }
2044
- }
2045
 
2046
- /**
2047
- * Filters whether the current user can delete an activity item.
2048
- *
2049
- * @since 1.5.0
2050
- *
2051
- * @param bool $can_delete Whether the user can delete the item.
2052
- * @param object $activity Current activity item object.
2053
- */
2054
- return (bool) apply_filters( 'bp_activity_user_can_delete', $can_delete, $activity );
2055
  }
2056
 
2057
  /**
2058
  * Output the activity parent content.
2059
  *
2060
- * @since 1.2.0
2061
  *
2062
  * @see bp_get_activity_parent_content() for a description of arguments.
2063
  * @uses bp_get_activity_parent_content()
2064
  *
2065
- * @param array|string $args See {@link bp_get_activity_parent_content} for description.
2066
  */
2067
  function bp_activity_parent_content( $args = '' ) {
2068
  echo bp_get_activity_parent_content($args);
@@ -2071,63 +1633,60 @@ function bp_activity_parent_content( $args = '' ) {
2071
  /**
2072
  * Return the activity content.
2073
  *
2074
- * @since 1.2.0
2075
  *
2076
  * @global object $activities_template {@link BP_Activity_Template}
 
2077
  * @uses apply_filters() To call the 'bp_get_activity_parent_content' hook.
2078
  *
2079
- * @param string $args Unused. Left over from an earlier implementation.
2080
- * @return mixed False on failure, otherwise the activity parent content.
 
 
 
2081
  */
2082
  function bp_get_activity_parent_content( $args = '' ) {
2083
  global $activities_template;
2084
 
2085
- // Bail if no activity on no item ID.
2086
- if ( empty( $activities_template->activity ) || empty( $activities_template->activity->item_id ) ) {
2087
- return false;
2088
- }
2089
 
2090
- // Get the ID of the parent activity content.
2091
- $parent_id = (int) $activities_template->activity->item_id;
2092
 
2093
- // Bail if no parent content.
2094
- if ( empty( $activities_template->activity_parents[ $parent_id ] ) ) {
2095
  return false;
2096
- }
2097
 
2098
- // Bail if no action.
2099
- if ( empty( $activities_template->activity_parents[ $parent_id ]->action ) ) {
2100
  return false;
2101
- }
2102
 
2103
- // Content always includes action.
2104
- $content = $activities_template->activity_parents[ $parent_id ]->action;
 
2105
 
2106
- // Maybe append activity content, if it exists.
2107
- if ( ! empty( $activities_template->activity_parents[ $parent_id ]->content ) ) {
2108
- $content .= ' ' . $activities_template->activity_parents[ $parent_id ]->content;
2109
- }
2110
 
2111
- // Remove the time since content for backwards compatibility.
 
 
 
 
2112
  $content = str_replace( '<span class="time-since">%s</span>', '', $content );
2113
 
2114
- // Remove images.
2115
  $content = preg_replace( '/<img[^>]*>/Ui', '', $content );
2116
 
2117
- /**
2118
- * Filters the activity parent content.
2119
- *
2120
- * @since 1.2.0
2121
- *
2122
- * @param string $content Content set to be displayed as parent content.
2123
- */
2124
  return apply_filters( 'bp_get_activity_parent_content', $content );
2125
  }
2126
 
2127
  /**
2128
  * Output the parent activity's user ID.
2129
  *
2130
- * @since 1.7.0
2131
  */
2132
  function bp_activity_parent_user_id() {
2133
  echo bp_get_activity_parent_user_id();
@@ -2136,50 +1695,41 @@ function bp_activity_parent_user_id() {
2136
  /**
2137
  * Return the parent activity's user ID.
2138
  *
2139
- * @since 1.7.0
2140
  *
2141
  * @global BP_Activity_Template $activities_template
2142
  *
2143
  * @return bool|int False if parent activity can't be found, otherwise
2144
- * the parent activity's user ID.
2145
  */
2146
  function bp_get_activity_parent_user_id() {
2147
  global $activities_template;
2148
 
2149
- // Bail if no activity on no item ID.
2150
- if ( empty( $activities_template->activity ) || empty( $activities_template->activity->item_id ) ) {
2151
  return false;
2152
- }
2153
 
2154
- // Get the ID of the parent activity content.
2155
- $parent_id = (int) $activities_template->activity->item_id;
 
2156
 
2157
- // Bail if no parent item.
2158
- if ( empty( $activities_template->activity_parents[ $parent_id ] ) ) {
2159
  return false;
2160
- }
2161
 
2162
- // Bail if no parent user ID.
2163
- if ( empty( $activities_template->activity_parents[ $parent_id ]->user_id ) ) {
2164
  return false;
2165
- }
2166
 
2167
- $retval = $activities_template->activity_parents[ $parent_id ]->user_id;
2168
 
2169
- /**
2170
- * Filters the activity parent item's user ID.
2171
- *
2172
- * @since 1.7.0
2173
- *
2174
- * @param int $retval ID for the activity parent's user.
2175
- */
2176
  return (int) apply_filters( 'bp_get_activity_parent_user_id', $retval );
2177
  }
2178
 
2179
  /**
2180
  * Output whether or not the current activity is in a current user's favorites.
2181
  *
2182
- * @since 1.2.0
2183
  *
2184
  * @uses bp_get_activity_is_favorite()
2185
  */
@@ -2190,7 +1740,7 @@ function bp_activity_is_favorite() {
2190
  /**
2191
  * Return whether the current activity is in a current user's favorites.
2192
  *
2193
- * @since 1.2.0
2194
  *
2195
  * @global object $activities_template {@link BP_Activity_Template}
2196
  * @uses apply_filters() To call the 'bp_get_activity_is_favorite' hook.
@@ -2200,24 +1750,17 @@ function bp_activity_is_favorite() {
2200
  function bp_get_activity_is_favorite() {
2201
  global $activities_template;
2202
 
2203
- /**
2204
- * Filters whether the current activity item is in the current user's favorites.
2205
- *
2206
- * @since 1.2.0
2207
- *
2208
- * @param bool $value Whether or not the current activity item is in the current user's favorites.
2209
- */
2210
- return (bool) apply_filters( 'bp_get_activity_is_favorite', in_array( $activities_template->activity->id, (array) $activities_template->my_favs ) );
2211
  }
2212
 
2213
  /**
2214
  * Output the comment markup for an activity item.
2215
  *
2216
- * @since 1.2.0
2217
  *
2218
  * @todo deprecate $args param
2219
  *
2220
- * @param array|string $args See {@link bp_activity_get_comments} for description.
2221
  */
2222
  function bp_activity_comments( $args = '' ) {
2223
  echo bp_activity_get_comments( $args );
@@ -2226,64 +1769,52 @@ function bp_activity_comments( $args = '' ) {
2226
  /**
2227
  * Get the comment markup for an activity item.
2228
  *
2229
- * @since 1.2.0
2230
  *
2231
  * @todo deprecate $args param
 
2232
  * @todo Given that checks for children already happen in bp_activity_recurse_comments(),
2233
- * this function can probably be streamlined or removed.
 
 
2234
  *
2235
  * @global object $activities_template {@link BP_Activity_Template}
2236
  * @uses bp_activity_recurse_comments()
2237
- *
2238
- * @param string $args Unused. Left over from an earlier implementation.
2239
- * @return bool
2240
  */
2241
  function bp_activity_get_comments( $args = '' ) {
2242
  global $activities_template;
2243
 
2244
- if ( empty( $activities_template->activity->children ) ) {
2245
  return false;
2246
- }
2247
 
2248
  bp_activity_recurse_comments( $activities_template->activity );
2249
  }
2250
 
2251
  /**
2252
- * Loops through a level of activity comments and loads the template for each.
2253
  *
2254
  * Note: The recursion itself used to happen entirely in this function. Now it is
2255
  * split between here and the comment.php template.
2256
  *
2257
- * @since 1.2.0
 
 
2258
  *
2259
  * @global object $activities_template {@link BP_Activity_Template}
2260
  * @uses locate_template()
2261
- *
2262
- * @param object $comment The activity object currently being recursed.
2263
- * @return bool|string
2264
  */
2265
  function bp_activity_recurse_comments( $comment ) {
2266
  global $activities_template;
2267
 
2268
- if ( empty( $comment ) ) {
2269
  return false;
2270
- }
2271
 
2272
- if ( empty( $comment->children ) ) {
2273
  return false;
2274
- }
2275
 
2276
- /**
2277
- * Filters the opening tag for the template that lists activity comments.
2278
- *
2279
- * @since 1.6.0
2280
- *
2281
- * @param string $value Opening tag for the HTML markup to use.
2282
- */
2283
- echo apply_filters( 'bp_activity_recurse_comments_start_ul', '<ul>' );
2284
  foreach ( (array) $comment->children as $comment_child ) {
2285
-
2286
- // Put the comment into the global so it's available to filters.
2287
  $activities_template->activity->current_comment = $comment_child;
2288
 
2289
  $template = bp_locate_template( 'activity/comment.php', false, false );
@@ -2300,42 +1831,25 @@ function bp_activity_comments( $args = '' ) {
2300
 
2301
  unset( $activities_template->activity->current_comment );
2302
  }
2303
-
2304
- /**
2305
- * Filters the closing tag for the template that list activity comments.
2306
- *
2307
- * @since 1.6.0
2308
- *
2309
- * @param string $value Closing tag for the HTML markup to use.
2310
- */
2311
- echo apply_filters( 'bp_activity_recurse_comments_end_ul', '</ul>' );
2312
  }
2313
 
2314
  /**
2315
  * Utility function that returns the comment currently being recursed.
2316
  *
2317
- * @since 1.5.0
2318
  *
2319
  * @global object $activities_template {@link BP_Activity_Template}
2320
  * @uses apply_filters() To call the 'bp_activity_current_comment' hook.
2321
  *
2322
  * @return object|bool $current_comment The activity comment currently being
2323
- * displayed. False on failure.
2324
  */
2325
  function bp_activity_current_comment() {
2326
  global $activities_template;
2327
 
2328
- $current_comment = !empty( $activities_template->activity->current_comment )
2329
- ? $activities_template->activity->current_comment
2330
- : false;
2331
 
2332
- /**
2333
- * Filters the current comment being recursed.
2334
- *
2335
- * @since 1.5.0
2336
- *
2337
- * @param object|bool $current_comment The activity comment currently being displayed. False on failure.
2338
- */
2339
  return apply_filters( 'bp_activity_current_comment', $current_comment );
2340
  }
2341
 
@@ -2343,7 +1857,7 @@ function bp_activity_current_comment() {
2343
  /**
2344
  * Output the ID of the activity comment currently being displayed.
2345
  *
2346
- * @since 1.5.0
2347
  *
2348
  * @uses bp_get_activity_comment_id()
2349
  */
@@ -2354,33 +1868,26 @@ function bp_activity_comment_id() {
2354
  /**
2355
  * Return the ID of the activity comment currently being displayed.
2356
  *
2357
- * @since 1.5.0
2358
  *
2359
  * @global object $activities_template {@link BP_Activity_Template}
2360
  * @uses apply_filters() To call the 'bp_activity_comment_id' hook.
2361
  *
2362
- * @return int|bool $comment_id The ID of the activity comment currently
2363
- * being displayed, false if none is found.
2364
  */
2365
  function bp_get_activity_comment_id() {
2366
  global $activities_template;
2367
 
2368
  $comment_id = isset( $activities_template->activity->current_comment->id ) ? $activities_template->activity->current_comment->id : false;
2369
 
2370
- /**
2371
- * Filters the ID of the activity comment currently being displayed.
2372
- *
2373
- * @since 1.5.0
2374
- *
2375
- * @param int|bool $comment_id ID for the comment currently being displayed.
2376
- */
2377
  return apply_filters( 'bp_activity_comment_id', $comment_id );
2378
  }
2379
 
2380
  /**
2381
  * Output the ID of the author of the activity comment currently being displayed.
2382
  *
2383
- * @since 1.5.0
2384
  *
2385
  * @uses bp_get_activity_comment_user_id()
2386
  */
@@ -2391,33 +1898,26 @@ function bp_activity_comment_user_id() {
2391
  /**
2392
  * Return the ID of the author of the activity comment currently being displayed.
2393
  *
2394
- * @since 1.5.0
2395
  *
2396
  * @global object $activities_template {@link BP_Activity_Template}
2397
  * @uses apply_filters() To call the 'bp_activity_comment_user_id' hook.
2398
  *
2399
  * @return int|bool $user_id The user_id of the author of the displayed
2400
- * activity comment. False on failure.
2401
  */
2402
  function bp_get_activity_comment_user_id() {
2403
  global $activities_template;
2404
 
2405
  $user_id = isset( $activities_template->activity->current_comment->user_id ) ? $activities_template->activity->current_comment->user_id : false;
2406
 
2407
- /**
2408
- * Filters the ID of the author of the activity comment currently being displayed.
2409
- *
2410
- * @since 1.5.0
2411
- *
2412
- * @param int|bool $user_id ID for the author of the comment currently being displayed.
2413
- */
2414
  return apply_filters( 'bp_activity_comment_user_id', $user_id );
2415
  }
2416
 
2417
  /**
2418
  * Output the author link for the activity comment currently being displayed.
2419
  *
2420
- * @since 1.5.0
2421
  *
2422
  * @uses bp_get_activity_comment_user_link()
2423
  */
@@ -2428,31 +1928,24 @@ function bp_activity_comment_user_link() {
2428
  /**
2429
  * Return the author link for the activity comment currently being displayed.
2430
  *
2431
- * @since 1.5.0
2432
  *
2433
  * @uses bp_core_get_user_domain()
2434
  * @uses bp_get_activity_comment_user_id()
2435
- * @uses apply_filters() To call the 'bp_activity_comment_user_link' hook.
2436
  *
2437
  * @return string $user_link The URL of the activity comment author's profile.
2438
  */
2439
  function bp_get_activity_comment_user_link() {
2440
  $user_link = bp_core_get_user_domain( bp_get_activity_comment_user_id() );
2441
 
2442
- /**
2443
- * Filters the author link for the activity comment currently being displayed.
2444
- *
2445
- * @since 1.5.0
2446
- *
2447
- * @param string $user_link Link for the author of the activity comment currently being displayed.
2448
- */
2449
  return apply_filters( 'bp_activity_comment_user_link', $user_link );
2450
  }
2451
 
2452
  /**
2453
  * Output the author name for the activity comment currently being displayed.
2454
  *
2455
- * @since 1.5.0
2456
  *
2457
  * @uses bp_get_activity_comment_name()
2458
  */
@@ -2466,7 +1959,7 @@ function bp_activity_comment_name() {
2466
  * The use of the 'bp_acomment_name' filter is deprecated. Please use
2467
  * 'bp_activity_comment_name'.
2468
  *
2469
- * @since 1.5.0
2470
  *
2471
  * @global object $activities_template {@link BP_Activity_Template}
2472
  * @uses apply_filters() To call the 'bp_acomment_name' hook.
@@ -2477,27 +1970,18 @@ function bp_activity_comment_name() {
2477
  function bp_get_activity_comment_name() {
2478
  global $activities_template;
2479
 
2480
- if ( isset( $activities_template->activity->current_comment->user_fullname ) ) {
2481
-
2482
- $name = apply_filters( 'bp_acomment_name', $activities_template->activity->current_comment->user_fullname, $activities_template->activity->current_comment ); // Backward compatibility.
2483
- } else {
2484
  $name = $activities_template->activity->current_comment->display_name;
2485
- }
2486
 
2487
- /**
2488
- * Filters the name of the author for the activity comment.
2489
- *
2490
- * @since 1.5.0
2491
- *
2492
- * @param string $name Name to be displayed with the activity comment.
2493
- */
2494
  return apply_filters( 'bp_activity_comment_name', $name );
2495
  }
2496
 
2497
  /**
2498
- * Output the formatted date_recorded of the activity comment currently being displayed.
2499
  *
2500
- * @since 1.5.0
2501
  *
2502
  * @uses bp_get_activity_comment_date_recorded()
2503
  */
@@ -2505,69 +1989,33 @@ function bp_activity_comment_date_recorded() {
2505
  echo bp_get_activity_comment_date_recorded();
2506
  }
2507
 
2508
- /**
2509
- * Return the formatted date_recorded for the activity comment currently being displayed.
2510
- *
2511
- * @since 1.5.0
2512
- *
2513
- * @uses bp_core_time_since()
2514
- * @uses apply_filters() To call the 'bp_activity_comment_date_recorded' hook.
2515
- *
2516
- * @return string|bool $date_recorded Time since the activity was recorded,
2517
- * in the form "%s ago". False on failure.
2518
- */
2519
- function bp_get_activity_comment_date_recorded() {
2520
-
2521
- /**
2522
- * Filters the recorded date of the activity comment currently being displayed.
2523
- *
2524
- * @since 1.5.0
2525
- *
2526
- * @param string|bool Date for the activity comment currently being displayed.
2527
- */
2528
- return apply_filters( 'bp_activity_comment_date_recorded', bp_core_time_since( bp_get_activity_comment_date_recorded_raw() ) );
2529
- }
2530
-
2531
- /**
2532
- * Output the date_recorded of the activity comment currently being displayed.
2533
- *
2534
- * @since 2.3.0
2535
- *
2536
- * @uses bp_get_activity_comment_date_recorded()
2537
- */
2538
- function bp_activity_comment_date_recorded_raw() {
2539
- echo bp_get_activity_comment_date_recorded_raw();
2540
- }
2541
-
2542
  /**
2543
  * Return the date_recorded for the activity comment currently being displayed.
2544
  *
2545
- * @since 2.3.0
2546
  *
2547
  * @global object $activities_template {@link BP_Activity_Template}
2548
  * @uses bp_core_time_since()
2549
- * @uses apply_filters() To call the 'bp_activity_comment_date_recorded' hook.
2550
  *
2551
  * @return string|bool $date_recorded Time since the activity was recorded,
2552
- * in the form "%s ago". False on failure.
2553
  */
2554
- function bp_get_activity_comment_date_recorded_raw() {
2555
  global $activities_template;
2556
 
2557
- /**
2558
- * Filters the raw recorded date of the activity comment currently being displayed.
2559
- *
2560
- * @since 2.3.0
2561
- *
2562
- * @param string|bool Raw date for the activity comment currently being displayed.
2563
- */
2564
- return apply_filters( 'bp_activity_comment_date_recorded', $activities_template->activity->current_comment->date_recorded );
2565
  }
2566
 
2567
  /**
2568
  * Output the 'delete' URL for the activity comment currently being displayed.
2569
  *
2570
- * @since 1.5.0
2571
  *
2572
  * @uses bp_get_activity_comment_delete_link()
2573
  */
@@ -2576,9 +2024,9 @@ function bp_activity_comment_delete_link() {
2576
  }
2577
 
2578
  /**
2579
- * Gets the 'delete' URL for the activity comment currently being displayed.
2580
  *
2581
- * @since 1.5.0
2582
  *
2583
  * @uses wp_nonce_url()
2584
  * @uses bp_get_root_domain()
@@ -2587,25 +2035,18 @@ function bp_activity_comment_delete_link() {
2587
  * @uses apply_filters() To call the 'bp_activity_comment_delete_link' hook.
2588
  *
2589
  * @return string $link The nonced URL for deleting the current
2590
- * activity comment.
2591
  */
2592
  function bp_get_activity_comment_delete_link() {
2593
  $link = wp_nonce_url( bp_get_root_domain() . '/' . bp_get_activity_slug() . '/delete/' . bp_get_activity_comment_id() . '?cid=' . bp_get_activity_comment_id(), 'bp_activity_delete_link' );
2594
 
2595
- /**
2596
- * Filters the link used for deleting the activity comment currently being displayed.
2597
- *
2598
- * @since 1.5.0
2599
- *
2600
- * @param string $link Link to use for deleting the currently displayed activity comment.
2601
- */
2602
  return apply_filters( 'bp_activity_comment_delete_link', $link );
2603
  }
2604
 
2605
  /**
2606
  * Output the content of the activity comment currently being displayed.
2607
  *
2608
- * @since 1.5.0
2609
  *
2610
  * @uses bp_get_activity_comment_content()
2611
  */
@@ -2621,7 +2062,7 @@ function bp_activity_comment_content() {
2621
  * 'bp_activity_comment_content' to modify the content of activity
2622
  * comments only.
2623
  *
2624
- * @since 1.5.0
2625
  *
2626
  * @global object $activities_template {@link BP_Activity_Template}
2627
  * @uses apply_filters() To call the 'bp_get_activity_content' hook.
@@ -2632,23 +2073,15 @@ function bp_activity_comment_content() {
2632
  function bp_get_activity_comment_content() {
2633
  global $activities_template;
2634
 
2635
- /** This filter is documented in bp-activity/bp-activity-template.php */
2636
  $content = apply_filters( 'bp_get_activity_content', $activities_template->activity->current_comment->content );
2637
 
2638
- /**
2639
- * Filters the content of the current activity comment.
2640
- *
2641
- * @since 1.2.0
2642
- *
2643
- * @param string $content The content of the current activity comment.
2644
- */
2645
  return apply_filters( 'bp_activity_comment_content', $content );
2646
  }
2647
 
2648
  /**
2649
  * Output the activity comment count.
2650
  *
2651
- * @since 1.2.0
2652
  *
2653
  * @uses bp_activity_get_comment_count()
2654
  */
@@ -2657,84 +2090,69 @@ function bp_activity_comment_count() {
2657
  }
2658
 
2659
  /**
2660
- * Return the comment count of an activity item.
 
 
 
 
 
2661
  *
2662
- * @since 1.2.0
2663
  *
2664
  * @global object $activities_template {@link BP_Activity_Template}
2665
  * @uses bp_activity_recurse_comment_count()
2666
  * @uses apply_filters() To call the 'bp_activity_get_comment_count' hook.
 
2667
  *
2668
- * @param array|null $deprecated Deprecated.
2669
  * @return int $count The activity comment count.
2670
  */
2671
- function bp_activity_get_comment_count( $deprecated = null ) {
2672
  global $activities_template;
2673
 
2674
- // Deprecated notice about $args.
2675
- if ( ! empty( $deprecated ) ) {
2676
- _deprecated_argument( __FUNCTION__, '1.2', sprintf( __( '%1$s no longer accepts arguments. See the inline documentation at %2$s for more details.', 'buddypress' ), __FUNCTION__, __FILE__ ) );
2677
- }
2678
 
2679
- // Get the count using the purpose-built recursive function.
2680
- $count = ! empty( $activities_template->activity->children )
2681
- ? bp_activity_recurse_comment_count( $activities_template->activity )
2682
- : 0;
2683
 
2684
- /**
2685
- * Filters the activity comment count.
2686
- *
2687
- * @since 1.2.0
2688
- *
2689
- * @param int $count The activity comment count.
2690
- */
2691
  return apply_filters( 'bp_activity_get_comment_count', (int) $count );
2692
  }
2693
 
2694
  /**
2695
- * Return the total number of comments to the current comment.
2696
  *
2697
- * This function recursively adds the total number of comments each
2698
- * activity child has, and returns them.
 
 
2699
  *
2700
- * @since 1.2.0
2701
  *
2702
  * @uses bp_activity_recurse_comment_count()
2703
- * @uses apply_filters() To call the 'bp_activity_recurse_comment_count' hook.
 
2704
  *
2705
  * @param object $comment Activity comment object.
2706
- * @param int $count The current iteration count.
2707
  * @return int $count The activity comment count.
2708
  */
2709
  function bp_activity_recurse_comment_count( $comment, $count = 0 ) {
2710
 
2711
- // Copy the count.
2712
- $new_count = $count;
2713
 
2714
- // Loop through children and recursively count comments.
2715
- if ( ! empty( $comment->children ) ) {
2716
- foreach ( (array) $comment->children as $comment ) {
2717
- $new_count++;
2718
- $new_count = bp_activity_recurse_comment_count( $comment, $new_count );
2719
- }
2720
  }
2721
 
2722
- /**
2723
- * Filters the total number of comments for the current comment.
2724
- *
2725
- * @since 2.1.0
2726
- *
2727
- * @param int $new_count New total count for the current comment.
2728
- * @param object $comment Activity comment object.
2729
- * @param int $count Current iteration count for the current comment.
2730
- */
2731
- return apply_filters( 'bp_activity_recurse_comment_count', $new_count, $comment, $count );
2732
  }
2733
 
2734
  /**
2735
  * Output the depth of the current activity comment.
2736
  *
2737
- * @since 2.0.0
2738
  */
2739
  function bp_activity_comment_depth() {
2740
  echo bp_activity_get_comment_depth();
@@ -2742,27 +2160,19 @@ function bp_activity_comment_depth() {
2742
  /**
2743
  * Return the current activity comment depth.
2744
  *
2745
- * @since 2.0.0
2746
  *
2747
- * @return int $depth Depth for the current activity comment.
2748
  */
2749
  function bp_activity_get_comment_depth() {
2750
  global $activities_template;
2751
-
2752
- /**
2753
- * Filters the comment depth of the current activity comment.
2754
- *
2755
- * @since 2.0.0
2756
- *
2757
- * @param int $depth Depth for the current activity comment.
2758
- */
2759
  return apply_filters( 'bp_activity_get_comment_depth', $activities_template->activity->current_comment->depth );
2760
  }
2761
 
2762
  /**
2763
  * Output the activity comment link.
2764
  *
2765
- * @since 1.2.0
2766
  *
2767
  * @uses bp_get_activity_comment_link()
2768
  */
@@ -2773,7 +2183,7 @@ function bp_activity_comment_link() {
2773
  /**
2774
  * Return the activity comment link.
2775
  *
2776
- * @since 1.2.0
2777
  *
2778
  * @global object $activities_template {@link BP_Activity_Template}
2779
  * @uses apply_filters() To call the 'bp_get_activity_comment_link' hook.
@@ -2782,21 +2192,13 @@ function bp_activity_comment_link() {
2782
  */
2783
  function bp_get_activity_comment_link() {
2784
  global $activities_template;
2785
-
2786
- /**
2787
- * Filters the comment link for the current activity comment.
2788
- *
2789
- * @since 1.2.0
2790
- *
2791
- * @param string $value Constructed URL parameters with activity IDs.
2792
- */
2793
  return apply_filters( 'bp_get_activity_comment_link', '?ac=' . $activities_template->activity->id . '/#ac-form-' . $activities_template->activity->id );
2794
  }
2795
 
2796
  /**
2797
- * Output the activity comment form no JavaScript display CSS.
2798
  *
2799
- * @since 1.2.0
2800
  *
2801
  * @uses bp_get_activity_comment_form_nojs_display()
2802
  */
@@ -2805,21 +2207,19 @@ function bp_activity_comment_form_nojs_display() {
2805
  }
2806
 
2807
  /**
2808
- * Return the activity comment form no JavaScript display CSS.
2809
  *
2810
- * @since 1.2.0
2811
  *
2812
  * @global object $activities_template {@link BP_Activity_Template}
2813
  *
2814
- * @return string|bool The activity comment form no JavaScript
2815
- * display CSS. False on failure.
2816
  */
2817
  function bp_get_activity_comment_form_nojs_display() {
2818
  global $activities_template;
2819
-
2820
- if ( isset( $_GET['ac'] ) && ( $_GET['ac'] === ( $activities_template->activity->id . '/' ) ) ) {
2821
  return 'style="display: block"';
2822
- }
2823
 
2824
  return false;
2825
  }
@@ -2827,7 +2227,7 @@ function bp_activity_comment_form_nojs_display() {
2827
  /**
2828
  * Output the activity comment form action.
2829
  *
2830
- * @since 1.2.0
2831
  *
2832
  * @uses bp_get_activity_comment_form_action()
2833
  */
@@ -2838,7 +2238,7 @@ function bp_activity_comment_form_action() {
2838
  /**
2839
  * Return the activity comment form action.
2840
  *
2841
- * @since 1.2.0
2842
  *
2843
  * @uses home_url()
2844
  * @uses bp_get_activity_root_slug()
@@ -2847,21 +2247,13 @@ function bp_activity_comment_form_action() {
2847
  * @return string The activity comment form action.
2848
  */
2849
  function bp_get_activity_comment_form_action() {
2850
-
2851
- /**
2852
- * Filters the activity comment form action URL.
2853
- *
2854
- * @since 1.2.0
2855
- *
2856
- * @param string $value URL to use in the comment form's action attribute.
2857
- */
2858
  return apply_filters( 'bp_get_activity_comment_form_action', home_url( bp_get_activity_root_slug() . '/reply/' ) );
2859
  }
2860
 
2861
  /**
2862
  * Output the activity permalink ID.
2863
  *
2864
- * @since 1.2.0
2865
  *
2866
  * @uses bp_get_activity_permalink_id()
2867
  */
@@ -2872,28 +2264,20 @@ function bp_activity_permalink_id() {
2872
  /**
2873
  * Return the activity permalink ID.
2874
  *
2875
- * @since 1.2.0
2876
  *
2877
  * @uses apply_filters() To call the 'bp_get_activity_permalink_id' hook.
2878
  *
2879
  * @return string The activity permalink ID.
2880
  */
2881
  function bp_get_activity_permalink_id() {
2882
-
2883
- /**
2884
- * Filters the activity action permalink ID.
2885
- *
2886
- * @since 1.2.0
2887
- *
2888
- * @param string $value Current action for the activity item.
2889
- */
2890
  return apply_filters( 'bp_get_activity_permalink_id', bp_current_action() );
2891
  }
2892
 
2893
  /**
2894
  * Output the activity thread permalink.
2895
  *
2896
- * @since 1.2.0
2897
  *
2898
  * @uses bp_get_activity_permalink_id()
2899
  */
@@ -2904,7 +2288,7 @@ function bp_activity_thread_permalink() {
2904
  /**
2905
  * Return the activity thread permalink.
2906
  *
2907
- * @since 1.2.0
2908
  *
2909
  * @uses bp_activity_get_permalink()
2910
  * @uses apply_filters() To call the 'bp_get_activity_thread_permalink' hook.
@@ -2916,20 +2300,13 @@ function bp_activity_thread_permalink() {
2916
 
2917
  $link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity );
2918
 
2919
- /**
2920
- * Filters the activity thread permalink.
2921
- *
2922
- * @since 1.2.0
2923
- *
2924
- * @param string $link The activity thread permalink.
2925
- */
2926
- return apply_filters( 'bp_get_activity_thread_permalink', $link );
2927
  }
2928
 
2929
  /**
2930
  * Output the activity comment permalink.
2931
  *
2932
- * @since 1.8.0
2933
  *
2934
  * @uses bp_get_activity_permalink_id()
2935
  */
@@ -2939,7 +2316,7 @@ function bp_activity_comment_permalink() {
2939
  /**
2940
  * Return the activity comment permalink.
2941
  *
2942
- * @since 1.8.0
2943
  *
2944
  * @uses bp_activity_get_permalink()
2945
  * @uses apply_filters() To call the 'bp_get_activity_comment_permalink' hook.
@@ -2949,34 +2326,15 @@ function bp_activity_comment_permalink() {
2949
  function bp_get_activity_comment_permalink() {
2950
  global $activities_template;
2951
 
2952
- // Check that comment exists.
2953
- $comment_id = isset( $activities_template->activity->current_comment->id )
2954
- ? $activities_template->activity->current_comment->id
2955
- : 0;
2956
 
2957
- // Setup the comment link.
2958
- $comment_link = ! empty( $comment_id )
2959
- ? '#acomment-' .$comment_id
2960
- : false;
2961
-
2962
- // Append comment ID to end of activity permalink.
2963
- $link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ) . $comment_link;
2964
-
2965
- /**
2966
- * Filters the activity comment permalink.
2967
- *
2968
- * @since 1.8.0
2969
- *
2970
- * @param string $link Activity comment permalink.
2971
- * @param int $comment_id ID for the current activity comment.
2972
- */
2973
- return apply_filters( 'bp_get_activity_comment_permalink', $link, $comment_id );
2974
  }
2975
 
2976
  /**
2977
  * Output the activity favorite link.
2978
  *
2979
- * @since 1.2.0
2980
  *
2981
  * @uses bp_get_activity_favorite_link()
2982
  */
@@ -2987,33 +2345,25 @@ function bp_activity_favorite_link() {
2987
  /**
2988
  * Return the activity favorite link.
2989
  *
2990
- * @since 1.2.0
2991
  *
2992
  * @global object $activities_template {@link BP_Activity_Template}
2993
  * @uses wp_nonce_url()
2994
  * @uses home_url()
2995
  * @uses bp_get_activity_root_slug()
2996
- * @uses apply_filters() To call the 'bp_get_activity_favorite_link' hook.
2997
  *
2998
  * @return string The activity favorite link.
2999
  */
3000
  function bp_get_activity_favorite_link() {
3001
  global $activities_template;
3002
-
3003
- /**
3004
- * Filters the activity favorite link.
3005
- *
3006
- * @since 1.2.0
3007
- *
3008
- * @param string $value Constructed link for favoriting the activity comment.
3009
- */
3010
  return apply_filters( 'bp_get_activity_favorite_link', wp_nonce_url( home_url( bp_get_activity_root_slug() . '/favorite/' . $activities_template->activity->id . '/' ), 'mark_favorite' ) );
3011
  }
3012
 
3013
  /**
3014
  * Output the activity unfavorite link.
3015
  *
3016
- * @since 1.2.0
3017
  *
3018
  * @uses bp_get_activity_unfavorite_link()
3019
  */
@@ -3024,7 +2374,7 @@ function bp_activity_unfavorite_link() {
3024
  /**
3025
  * Return the activity unfavorite link.
3026
  *
3027
- * @since 1.2.0
3028
  *
3029
  * @global object $activities_template {@link BP_Activity_Template}
3030
  * @uses wp_nonce_url()
@@ -3036,21 +2386,13 @@ function bp_activity_unfavorite_link() {
3036
  */
3037
  function bp_get_activity_unfavorite_link() {
3038
  global $activities_template;
3039
-
3040
- /**
3041
- * Filters the activity unfavorite link.
3042
- *
3043
- * @since 1.2.0
3044
- *
3045
- * @param string $value Constructed link for unfavoriting the activity comment.
3046
- */
3047
  return apply_filters( 'bp_get_activity_unfavorite_link', wp_nonce_url( home_url( bp_get_activity_root_slug() . '/unfavorite/' . $activities_template->activity->id . '/' ), 'unmark_favorite' ) );
3048
  }
3049
 
3050
  /**
3051
  * Output the activity CSS class.
3052
  *
3053
- * @since 1.0.0
3054
  *
3055
  * @uses bp_get_activity_css_class()
3056
  */
@@ -3061,7 +2403,7 @@ function bp_activity_css_class() {
3061
  /**
3062
  * Return the current activity item's CSS class.
3063
  *
3064
- * @since 1.0.0
3065
  *
3066
  * @global object $activities_template {@link BP_Activity_Template}
3067
  * @uses apply_filters() To call the 'bp_activity_mini_activity_types' hook.
@@ -3074,13 +2416,6 @@ function bp_activity_css_class() {
3074
  function bp_get_activity_css_class() {
3075
  global $activities_template;
3076
 
3077
- /**
3078
- * Filters the available mini activity actions available as CSS classes.
3079
- *
3080
- * @since 1.2.0
3081
- *
3082
- * @param array $value Array of classes used to determine classes applied to HTML element.
3083
- */
3084
  $mini_activity_actions = apply_filters( 'bp_activity_mini_activity_types', array(
3085
  'friendship_accepted',
3086
  'friendship_created',
@@ -3092,28 +2427,19 @@ function bp_activity_css_class() {
3092
 
3093
  $class = ' activity-item';
3094
 
3095
- if ( in_array( $activities_template->activity->type, (array) $mini_activity_actions ) || empty( $activities_template->activity->content ) ) {
3096
  $class .= ' mini';
3097
- }
3098
 
3099
- if ( bp_activity_get_comment_count() && bp_activity_can_comment() ) {
3100
  $class .= ' has-comments';
3101
- }
3102
 
3103
- /**
3104
- * Filters the determined classes to add to the HTML element.
3105
- *
3106
- * @since 1.0.0
3107
- *
3108
- * @param string $value Classes to be added to the HTML element.
3109
- */
3110
  return apply_filters( 'bp_get_activity_css_class', $activities_template->activity->component . ' ' . $activities_template->activity->type . $class );
3111
  }
3112
 
3113
  /**
3114
  * Output the activity delete link.
3115
  *
3116
- * @since 1.1.0
3117
  *
3118
  * @uses bp_get_activity_delete_link()
3119
  */
@@ -3124,96 +2450,41 @@ function bp_activity_delete_link() {
3124
  /**
3125
  * Return the activity delete link.
3126
  *
3127
- * @since 1.1.0
3128
  *
3129
  * @global object $activities_template {@link BP_Activity_Template}
3130
  * @uses bp_get_root_domain()
3131
  * @uses bp_get_activity_root_slug()
3132
  * @uses bp_is_activity_component()
3133
  * @uses bp_current_action()
 
3134
  * @uses wp_get_referer()
3135
  * @uses wp_nonce_url()
3136
  * @uses apply_filters() To call the 'bp_get_activity_delete_link' hook.
3137
  *
3138
  * @return string $link Activity delete link. Contains $redirect_to arg
3139
- * if on single activity page.
3140
  */
3141
  function bp_get_activity_delete_link() {
 
3142
 
3143
- $url = bp_get_activity_delete_url();
3144
  $class = 'delete-activity';
3145
 
3146
- // Determine if we're on a single activity page, and customize accordingly.
3147
  if ( bp_is_activity_component() && is_numeric( bp_current_action() ) ) {
 
3148
  $class = 'delete-activity-single';
3149
  }
3150
 
3151
- $link = '<a href="' . esc_url( $url ) . '" class="button item-button bp-secondary-action ' . $class . ' confirm" rel="nofollow">' . __( 'Delete', 'buddypress' ) . '</a>';
3152
-
3153
- /**
3154
- * Filters the activity delete link.
3155
- *
3156
- * @since 1.1.0
3157
- *
3158
- * @param string $link Activity delete HTML link.
3159
- */
3160
  return apply_filters( 'bp_get_activity_delete_link', $link );
3161
  }
3162
 
3163
- /**
3164
- * Output the URL to delete a single activity stream item.
3165
- *
3166
- * @since 2.1.0
3167
- *
3168
- * @uses bp_get_activity_delete_link()
3169
- */
3170
- function bp_activity_delete_url() {
3171
- echo esc_url( bp_get_activity_delete_url() );
3172
- }
3173
- /**
3174
- * Return the URL to delete a single activity item.
3175
- *
3176
- * @since 2.1.0
3177
- *
3178
- * @global object $activities_template {@link BP_Activity_Template}
3179
- * @uses bp_get_root_domain()
3180
- * @uses bp_get_activity_root_slug()
3181
- * @uses bp_is_activity_component()
3182
- * @uses bp_current_action()
3183
- * @uses add_query_arg()
3184
- * @uses wp_get_referer()
3185
- * @uses wp_nonce_url()
3186
- * @uses apply_filters() To call the 'bp_get_activity_delete_link' hook.
3187
- *
3188
- * @return string $link Activity delete link. Contains $redirect_to arg
3189
- * if on single activity page.
3190
- */
3191
- function bp_get_activity_delete_url() {
3192
- global $activities_template;
3193
-
3194
- $url = trailingslashit( bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/delete/' . $activities_template->activity->id );
3195
-
3196
- // Determine if we're on a single activity page, and customize accordingly.
3197
- if ( bp_is_activity_component() && is_numeric( bp_current_action() ) ) {
3198
- $url = add_query_arg( array( 'redirect_to' => wp_get_referer() ), $url );
3199
- }
3200
-
3201
- $url = wp_nonce_url( $url, 'bp_activity_delete_link' );
3202
-
3203
- /**
3204
- * Filters the activity delete URL.
3205
- *
3206
- * @since 2.1.0
3207
- *
3208
- * @param string $url Activity delete URL.
3209
- */
3210
- return apply_filters( 'bp_get_activity_delete_url', $url );
3211
- }
3212
-
3213
  /**
3214
  * Output the activity latest update link.
3215
  *
3216
- * @since 1.2.0
3217
  *
3218
  * @see bp_get_activity_latest_update() for description of parameters.
3219
  * @uses bp_get_activity_latest_update()
@@ -3227,70 +2498,47 @@ function bp_activity_latest_update( $user_id = 0 ) {
3227
  /**
3228
  * Return the activity latest update link.
3229
  *
3230
- * @since 1.2.0
3231
  *
3232
  * @uses bp_is_user_inactive()
3233
  * @uses bp_core_is_user_deleted()
3234
  * @uses bp_get_user_meta()
3235
- * @uses apply_filters() To call the 'bp_get_activity_latest_update_excerpt' hook.
3236
  * @uses bp_create_excerpt()
3237
  * @uses bp_get_root_domain()
3238
  * @uses bp_get_activity_root_slug()
3239
- * @uses apply_filters() To call the 'bp_get_activity_latest_update' hook.
3240
  *
3241
  * @param int $user_id If empty, will fall back on displayed user.
3242
  * @return string|bool $latest_update The activity latest update link.
3243
- * False on failure.
3244
  */
3245
  function bp_get_activity_latest_update( $user_id = 0 ) {
3246
 
3247
- if ( empty( $user_id ) ) {
3248
  $user_id = bp_displayed_user_id();
3249
- }
3250
 
3251
- if ( bp_is_user_inactive( $user_id ) ) {
3252
  return false;
3253
- }
3254
 
3255
- if ( !$update = bp_get_user_meta( $user_id, 'bp_latest_update', true ) ) {
3256
  return false;
3257
- }
3258
 
3259
- /**
3260
- * Filters the latest update excerpt.
3261
- *
3262
- * @since 1.2.10
3263
- *
3264
- * @param string $value The excerpt for the latest update.
3265
- */
3266
  $latest_update = apply_filters( 'bp_get_activity_latest_update_excerpt', trim( strip_tags( bp_create_excerpt( $update['content'], 358 ) ) ) );
 
3267
 
3268
- $latest_update = sprintf(
3269
- '%s <a href="%s">%s</a>',
3270
- $latest_update,
3271
- esc_url_raw( bp_activity_get_permalink( $update['id'] ) ),
3272
- esc_attr__( 'View', 'buddypress' )
3273
- );
3274
-
3275
- /**
3276
- * Filters the latest update excerpt with view link appended to the end.
3277
- *
3278
- * @since 1.2.0
3279
- *
3280
- * @param string $latest_update The latest update with "view" link appended to it.
3281
- */
3282
- return apply_filters( 'bp_get_activity_latest_update', $latest_update );
3283
  }
3284
 
3285
  /**
3286
  * Output the activity filter links.
3287
  *
3288
- * @since 1.1.0
3289
  *
3290
  * @see bp_get_activity_filter_links() for description of parameters.
3291
  * @uses bp_get_activity_filter_links()
3292
  *
3293
- * @param array|bool $args See {@link bp_get_activity_filter_links()} for description.
3294
  */
3295
  function bp_activity_filter_links( $args = false ) {
3296
  echo bp_get_activity_filter_links( $args );
@@ -3299,7 +2547,7 @@ function bp_activity_filter_links( $args = false ) {
3299
  /**
3300
  * Return the activity filter links.
3301
  *
3302
- * @since 1.1.0
3303
  *
3304
  * @uses wp_parse_args()
3305
  * @uses BP_Activity_Activity::get_recorded_components() {@link BP_Activity_Activity}
@@ -3309,45 +2557,45 @@ function bp_activity_filter_links( $args = false ) {
3309
  * @uses apply_filters() To call the 'bp_get_activity_filter_link_href' hook.
3310
  * @uses apply_filters() To call the 'bp_get_activity_filter_links' hook.
3311
  *
3312
- * @param array|bool $args {
3313
  * @type string $style The type of markup to use for the links.
3314
- * 'list', 'paragraph', or 'span'. Default: 'list'.
3315
  * }
3316
  * @return string|bool $component_links The activity filter links.
3317
  * False on failure.
3318
  */
3319
  function bp_get_activity_filter_links( $args = false ) {
3320
 
3321
- $r = wp_parse_args( $args, array(
3322
  'style' => 'list'
3323
- ) );
 
 
 
3324
 
3325
- // Define local variable.
3326
  $component_links = array();
3327
 
3328
- // Fetch the names of components that have activity recorded in the DB.
3329
  $components = BP_Activity_Activity::get_recorded_components();
3330
 
3331
- if ( empty( $components ) ) {
3332
  return false;
3333
- }
3334
 
3335
  foreach ( (array) $components as $component ) {
3336
 
3337
- // Skip the activity comment filter.
3338
- if ( 'activity' == $component ) {
3339
  continue;
3340
- }
3341
 
3342
- if ( isset( $_GET['afilter'] ) && $component == $_GET['afilter'] ) {
3343
  $selected = ' class="selected"';
3344
- } else {
3345
- $selected = '';
3346
- }
3347
 
3348
  $component = esc_attr( $component );
3349
 
3350
- switch ( $r['style'] ) {
3351
  case 'list':
3352
  $tag = 'li';
3353
  $before = '<li id="afilter-' . $component . '"' . $selected . '>';
@@ -3367,40 +2615,23 @@ function bp_activity_filter_links( $args = false ) {
3367
 
3368
  $link = add_query_arg( 'afilter', $component );
3369
  $link = remove_query_arg( 'acpage' , $link );
3370
-
3371
- /**
3372
- * Filters the activity filter link URL for the current activity component.
3373
- *
3374
- * @since 1.1.0
3375
- *
3376
- * @param string $link The URL for the current component.
3377
- * @param string $component The current component getting links constructed for.
3378
- */
3379
  $link = apply_filters( 'bp_get_activity_filter_link_href', $link, $component );
3380
 
3381
- $component_links[] = $before . '<a href="' . esc_url( $link ) . '">' . ucwords( $component ) . '</a>' . $after;
3382
  }
3383
 
3384
  $link = remove_query_arg( 'afilter' , $link );
3385
 
3386
- if ( isset( $_GET['afilter'] ) ) {
3387
- $component_links[] = '<' . $tag . ' id="afilter-clear"><a href="' . esc_url( $link ) . '">' . __( 'Clear Filter', 'buddypress' ) . '</a></' . $tag . '>';
3388
- }
3389
 
3390
- /**
3391
- * Filters all of the constructed filter links.
3392
- *
3393
- * @since 1.1.0
3394
- *
3395
- * @param string $value All of the links to be displayed to the user.
3396
- */
3397
  return apply_filters( 'bp_get_activity_filter_links', implode( "\n", $component_links ) );
3398
  }
3399
 
3400
  /**
3401
  * Determine if a comment can be made on an activity item.
3402
  *
3403
- * @since 1.2.0
3404
  *
3405
  * @global object $activities_template {@link BP_Activity_Template}
3406
  * @uses bp_get_activity_action_name()
@@ -3410,126 +2641,63 @@ function bp_activity_filter_links( $args = false ) {
3410
  */
3411
  function bp_activity_can_comment() {
3412
  global $activities_template;
3413
- $bp = buddypress();
3414
 
3415
- // Assume activity can be commented on.
3416
  $can_comment = true;
3417
 
3418
- // Determine ability to comment based on activity action name.
3419
- $activity_action = bp_get_activity_action_name();
3420
-
3421
- $turn_off = 0;
3422
- if ( ! empty( $activities_template->disable_blogforum_replies ) ) {
3423
- $turn_off = 1;
3424
- }
3425
-
3426
- $maybe_turn_off = array_fill_keys( array(
3427
- 'new_blog_post',
3428
- 'new_blog_comment',
3429
- 'new_forum_topic',
3430
- 'new_forum_post',
3431
- ), $turn_off );
3432
-
3433
- $maybe_turn_off['activity_comment'] = 1;
3434
-
3435
- // Fetch all the tracked post types once.
3436
- if ( empty( $bp->activity->track ) ) {
3437
- $bp->activity->track = bp_activity_get_post_types_tracking_args();
3438
- }
3439
-
3440
- foreach ( $bp->activity->track as $action => $tracking_args ) {
3441
- if ( empty( $tracking_args->activity_comment ) ) {
3442
- $maybe_turn_off[ $action ] = $turn_off;
3443
- }
3444
  }
3445
 
3446
- $can_comment = empty( $maybe_turn_off[ $activity_action ] );
 
3447
 
3448
- /**
3449
- * Filters whether a comment can be made on an activity item.
3450
- *
3451
- * @since 1.5.0
3452
- *
3453
- * @param bool $can_comment Status on if activity can be commented on.
3454
- * @param string $activity_action Current activity action being checked on.
3455
- */
3456
- return apply_filters( 'bp_activity_can_comment', $can_comment, $activity_action );
3457
  }
3458
 
3459
  /**
3460
- * Determine whether a comment can be made on an activity reply item.
 
 
 
 
3461
  *
3462
- * @since 1.5.0
3463
  *
3464
- * @param bool|object $comment Activity comment.
3465
- * @return bool $can_comment True if comment can receive comments,
3466
- * otherwise false.
3467
  */
3468
- function bp_activity_can_comment_reply( $comment = false ) {
3469
-
3470
- // Assume activity can be commented on.
3471
  $can_comment = true;
3472
 
3473
- // Check that comment exists.
3474
- if ( empty( $comment ) ) {
3475
- $comment = bp_activity_current_comment();
3476
  }
3477
 
3478
- if ( ! empty( $comment ) ) {
3479
-
3480
- // Fall back on current comment in activity loop.
3481
- $comment_depth = isset( $comment->depth )
3482
- ? intval( $comment->depth )
3483
- : bp_activity_get_comment_depth();
3484
-
3485
- // Threading is turned on, so check the depth.
3486
- if ( get_option( 'thread_comments' ) ) {
3487
- $can_comment = (bool) ( $comment_depth < get_option( 'thread_comments_depth' ) );
3488
-
3489
- // No threading for comment replies if no threading for comments.
3490
- } else {
3491
- $can_comment = false;
3492
- }
3493
- }
3494
-
3495
- /**
3496
- * Filters whether a comment can be made on an activity reply item.
3497
- *
3498
- * @since 1.5.0
3499
- *
3500
- * @param bool $can_comment Status on if activity reply can be commented on.
3501
- * @param string $comment Current comment being checked on.
3502
- */
3503
- return (bool) apply_filters( 'bp_activity_can_comment_reply', $can_comment, $comment );
3504
  }
3505
 
3506
  /**
3507
- * Determine whether favorites are allowed.
3508
  *
3509
  * Defaults to true, but can be modified by plugins.
3510
  *
3511
- * @since 1.5.0
3512
  *
3513
  * @uses apply_filters() To call the 'bp_activity_can_favorite' hook.
3514
  *
3515
- * @return bool True if comment can receive comments.
3516
  */
3517
  function bp_activity_can_favorite() {
 
3518
 
3519
- /**
3520
- * Filters whether or not users can favorite activity items.
3521
- *
3522
- * @since 1.5.0
3523
- *
3524
- * @param bool $value Whether or not favoriting is enabled.
3525
- */
3526
- return apply_filters( 'bp_activity_can_favorite', true );
3527
  }
3528
 
3529
  /**
3530
  * Output the total favorite count for a specified user.
3531
  *
3532
- * @since 1.2.0
3533
  *
3534
  * @see bp_get_total_favorite_count_for_user() for description of parameters.
3535
  * @uses bp_get_total_favorite_count_for_user()
@@ -3543,44 +2711,27 @@ function bp_total_favorite_count_for_user( $user_id = 0 ) {
3543
  /**
3544
  * Return the total favorite count for a specified user.
3545
  *
3546
- * @since 1.2.0
3547
  *
3548
  * @uses bp_activity_total_favorites_for_user()
3549
- * @uses apply_filters() To call the 'bp_get_total_favorite_count_for_user' hook.
3550
  *
3551
  * @param int $user_id ID of user being queried. Default: displayed user ID.
3552
  * @return int The total favorite count for the specified user.
3553
  */
3554
  function bp_get_total_favorite_count_for_user( $user_id = 0 ) {
3555
- $retval = false;
3556
-
3557
- if ( bp_activity_can_favorite() ) {
3558
- // Default to displayed user if none is passed.
3559
- $user_id = empty( $user_id )
3560
- ? bp_displayed_user_id()
3561
- : $user_id;
3562
-
3563
- // Get user meta if user ID exists.
3564
- if ( ! empty( $user_id ) ) {
3565
- $retval = bp_activity_total_favorites_for_user( $user_id );
3566
- }
3567
  }
3568
 
3569
- /**
3570
- * Filters the total favorite count for a user.
3571
- *
3572
- * @since 1.2.0
3573
- *
3574
- * @param int|bool $retval Total favorite count for a user. False on no favorites.
3575
- */
3576
- return apply_filters( 'bp_get_total_favorite_count_for_user', $retval );
3577
  }
3578
-
3579
 
3580
  /**
3581
  * Output the total mention count for a specified user.
3582
  *
3583
- * @since 1.2.0
3584
  *
3585
  * @see bp_get_total_mention_count_for_user() for description of parameters.
3586
  * @uses bp_get_total_favorite_count_for_user()
@@ -3594,7 +2745,7 @@ function bp_total_mention_count_for_user( $user_id = 0 ) {
3594
  /**
3595
  * Return the total mention count for a specified user.
3596
  *
3597
- * @since 1.2.0
3598
  *
3599
  * @uses bp_get_user_meta()
3600
  * @uses apply_filters() To call the 'bp_get_total_mention_count_for_user' hook.
@@ -3603,77 +2754,51 @@ function bp_total_mention_count_for_user( $user_id = 0 ) {
3603
  * @return int The total mention count for the specified user.
3604
  */
3605
  function bp_get_total_mention_count_for_user( $user_id = 0 ) {
 
 
 
3606
 
3607
- // Default to displayed user if none is passed.
3608
- $user_id = empty( $user_id )
3609
- ? bp_displayed_user_id()
3610
- : $user_id;
3611
-
3612
- // Get user meta if user ID exists.
3613
- $retval = ! empty( $user_id )
3614
- ? bp_get_user_meta( $user_id, 'bp_new_mention_count', true )
3615
- : false;
3616
-
3617
- /**
3618
- * Filters the total mention count for a user.
3619
- *
3620
- * @since 1.2.0
3621
- *
3622
- * @param int|bool $retval Total mention count for a user. False on no mentions.
3623
- */
3624
- return apply_filters( 'bp_get_total_mention_count_for_user', $retval );
3625
  }
 
3626
 
3627
  /**
3628
  * Output the public message link for displayed user.
3629
  *
3630
- * @since 1.2.0
3631
  *
3632
  * @uses bp_get_send_public_message_link()
3633
  */
3634
  function bp_send_public_message_link() {
3635
- echo esc_url( bp_get_send_public_message_link() );
3636
  }
3637
 
3638
  /**
3639
  * Return the public message link for the displayed user.
3640
  *
3641
- * @since 1.2.0
3642
  *
3643
  * @uses is_user_logged_in()
3644
  * @uses bp_is_my_profile()
3645
  * @uses bp_is_user()
3646
  * @uses wp_nonce_url()
3647
  * @uses bp_get_activity_directory_permalink()
3648
- * @uses apply_filters() To call the 'bp_get_send_public_message_link' hook.
3649
  *
3650
  * @return string The public message link for the displayed user.
3651
  */
3652
  function bp_get_send_public_message_link() {
3653
 
3654
- // No link if not logged in, not looking at someone else's profile.
3655
- if ( ! is_user_logged_in() || ! bp_is_user() || bp_is_my_profile() ) {
3656
- $retval = '';
3657
- } else {
3658
- $args = array( 'r' => bp_get_displayed_user_mentionname() );
3659
- $url = add_query_arg( $args, bp_get_activity_directory_permalink() );
3660
- $retval = wp_nonce_url( $url );
3661
- }
3662
 
3663
- /**
3664
- * Filters the public message link for the displayed user.
3665
- *
3666
- * @since 1.2.0
3667
- *
3668
- * @param string $retval The URL for the public message link.
3669
- */
3670
- return apply_filters( 'bp_get_send_public_message_link', $retval );
3671
  }
3672
 
3673
  /**
3674
  * Recurse through all activity comments and return the activity comment IDs.
3675
  *
3676
- * @since 2.0.0
3677
  *
3678
  * @param array $activity Array of activities generated from {@link bp_activity_get()}.
3679
  * @param array $activity_ids Used for recursion purposes in this function.
@@ -3700,58 +2825,44 @@ function bp_activity_recurse_comments_activity_ids( $activity = array(), $activi
3700
  /**
3701
  * Output the mentioned user display name.
3702
  *
3703
- * @since 1.2.0
3704
  *
3705
  * @see bp_get_mentioned_user_display_name() for description of parameters.
3706
  * @uses bp_get_mentioned_user_display_name()
3707
  *
3708
- * @param int|string|bool $user_id_or_username See {@link bp_get_mentioned_user_display_name()}.
3709
  */
3710
- function bp_mentioned_user_display_name( $user_id_or_username = false ) {
3711
  echo bp_get_mentioned_user_display_name( $user_id_or_username );
3712
  }
3713
 
3714
  /**
3715
- * Returns the mentioned user display name.
3716
  *
3717
- * @since 1.2.0
3718
  *
3719
  * @uses bp_core_get_user_displayname()
3720
  * @uses apply_filters() To call the 'bp_get_mentioned_user_display_name' hook.
3721
  *
3722
- * @param int|string|bool $user_id_or_username User ID or username.
3723
  * @return string The mentioned user's display name.
3724
  */
3725
- function bp_get_mentioned_user_display_name( $user_id_or_username = false ) {
3726
-
3727
- // Get user display name.
3728
- $name = bp_core_get_user_displayname( $user_id_or_username );
3729
-
3730
- // If user somehow has no name, return this really lame string.
3731
- if ( empty( $name ) ) {
3732
  $name = __( 'a user', 'buddypress' );
3733
- }
3734
 
3735
- /**
3736
- * Filters the mentioned user display name.
3737
- *
3738
- * @since 1.2.0
3739
- *
3740
- * @param string $name Display name for the mentioned user.
3741
- * @param int|string $user_id_or_username User ID or username use for query.
3742
- */
3743
  return apply_filters( 'bp_get_mentioned_user_display_name', $name, $user_id_or_username );
3744
  }
3745
 
3746
  /**
3747
  * Output button for sending a public message (an @-mention).
3748
  *
3749
- * @since 1.2.0
3750
  *
3751
  * @see bp_get_send_public_message_button() for description of parameters.
3752
  * @uses bp_get_send_public_message_button()
3753
  *
3754
- * @param array|string $args See {@link bp_get_send_public_message_button()}.
3755
  */
3756
  function bp_send_public_message_button( $args = '' ) {
3757
  echo bp_get_send_public_message_button( $args );
@@ -3760,33 +2871,32 @@ function bp_send_public_message_button( $args = '' ) {
3760
  /**
3761
  * Return button for sending a public message (an @-mention).
3762
  *
3763
- * @since 1.2.0
3764
  *
3765
  * @uses bp_get_send_public_message_link()
3766
  * @uses wp_parse_args()
3767
  * @uses bp_get_button()
3768
  * @uses apply_filters() To call the 'bp_get_send_public_message_button' hook.
3769
  *
3770
- * @param array|string $args {
3771
  * All arguments are optional. See {@link BP_Button} for complete
3772
  * descriptions.
3773
- * @type string $id Default: 'public_message'.
3774
- * @type string $component Default: 'activity'.
3775
- * @type bool $must_be_logged_in Default: true.
3776
- * @type bool $block_self Default: true.
3777
- * @type string $wrapper_id Default: 'post-mention'.
3778
- * @type string $link_href Default: the public message link for
3779
- * the current member in the loop.
3780
- * @type string $link_title Default: 'Send a public message on your
3781
- * activity stream.'.
3782
- * @type string $link_text Default: 'Public Message'.
3783
- * @type string $link_class Default: 'activity-button mention'.
3784
  * }
3785
  * @return string The button for sending a public message.
3786
  */
3787
  function bp_get_send_public_message_button( $args = '' ) {
3788
-
3789
- $r = bp_parse_args( $args, array(
3790
  'id' => 'public_message',
3791
  'component' => 'activity',
3792
  'must_be_logged_in' => true,
@@ -3796,22 +2906,18 @@ function bp_send_public_message_button( $args = '' ) {
3796
  'link_title' => __( 'Send a public message on your activity stream.', 'buddypress' ),
3797
  'link_text' => __( 'Public Message', 'buddypress' ),
3798
  'link_class' => 'activity-button mention'
3799
- ) );
3800
 
3801
- /**
3802
- * Filters the public message button HTML.
3803
- *
3804
- * @since 1.2.10
3805
- *
3806
- * @param array $r Array of arguments for the public message button HTML.
3807
- */
3808
- return bp_get_button( apply_filters( 'bp_get_send_public_message_button', $r ) );
3809
  }
3810
 
3811
  /**
3812
  * Output the activity post form action.
3813
  *
3814
- * @since 1.2.0
3815
  *
3816
  * @uses bp_get_activity_post_form_action()
3817
  */
@@ -3822,7 +2928,7 @@ function bp_activity_post_form_action() {
3822
  /**
3823
  * Return the activity post form action.
3824
  *
3825
- * @since 1.2.0
3826
  *
3827
  * @uses home_url()
3828
  * @uses bp_get_activity_root_slug()
@@ -3831,14 +2937,6 @@ function bp_activity_post_form_action() {
3831
  * @return string The activity post form action.
3832
  */
3833
  function bp_get_activity_post_form_action() {
3834
-
3835
- /**
3836
- * Filters the action url used for the activity post form.
3837
- *
3838
- * @since 1.2.0
3839
- *
3840
- * @param string $value URL to be used for the activity post form.
3841
- */
3842
  return apply_filters( 'bp_get_activity_post_form_action', home_url( bp_get_activity_root_slug() . '/post/' ) );
3843
  }
3844
 
@@ -3850,142 +2948,82 @@ function bp_activity_post_form_action() {
3850
  * Avatars are wrapped in <li> elements, but you've got to provide your own
3851
  * <ul> or <ol> wrapper markup.
3852
  *
3853
- * @since 1.7.0
3854
  *
3855
  * @see bp_core_fetch_avatar() for a description of arguments.
3856
  *
3857
  * @param array $args See {@link bp_core_fetch_avatar()}.
3858
  */
3859
  function bp_activity_comments_user_avatars( $args = array() ) {
3860
-
3861
- $r = bp_parse_args( $args, array(
3862
  'height' => false,
3863
  'html' => true,
3864
  'type' => 'thumb',
3865
  'width' => false,
3866
- ) );
3867
-
3868
- // Get the user IDs of everyone who has left a comment to the current activity item.
3869
- $user_ids = bp_activity_get_comments_user_ids();
3870
- $output = array();
3871
- $retval = '';
3872
 
3873
- if ( ! empty( $user_ids ) ) {
3874
- foreach ( (array) $user_ids as $user_id ) {
3875
 
3876
- // Skip an empty user ID.
3877
- if ( empty( $user_id ) ) {
3878
- continue;
3879
- }
3880
 
3881
- // Get profile link for this user.
3882
- $profile_link = bp_core_get_user_domain( $user_id );
 
 
3883
 
3884
- // Get avatar for this user.
3885
- $image_html = bp_core_fetch_avatar( array(
3886
- 'item_id' => $user_id,
3887
- 'height' => $r['height'],
3888
- 'html' => $r['html'],
3889
- 'type' => $r['type'],
3890
- 'width' => $r['width']
3891
- ) );
3892
-
3893
- // If user has link & avatar, add them to the output array.
3894
- if ( ! empty( $profile_link ) && ! empty( $image_html ) ) {
3895
- $output[] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $profile_link ), $image_html );
3896
- }
3897
- }
3898
-
3899
- // If output array is not empty, wrap everything in some list items.
3900
- if ( ! empty( $output ) ) {
3901
- $retval = '<li>' . implode( '</li><li>', $output ) . '</li>';
3902
- }
3903
  }
3904
 
3905
- /**
3906
- * Filters the list of linked avatars for users who have commented on the current activity item.
3907
- *
3908
- * @since 1.7.0
3909
- *
3910
- * @param string $retval HTML markup for the list of avatars.
3911
- * @param array $r Array of arguments used for each avatar.
3912
- * @param array $output Array of each avatar found, before imploded into single string.
3913
- */
3914
- echo apply_filters( 'bp_activity_comments_user_avatars', $retval, $r, $output );
3915
  }
3916
 
3917
  /**
3918
  * Return the IDs of every user who's left a comment on the current activity item.
3919
  *
3920
- * @since 1.7.0
3921
  *
3922
  * @return bool|array An array of IDs, or false if none are found.
3923
  */
3924
  function bp_activity_get_comments_user_ids() {
3925
- global $activities_template;
3926
-
3927
- $user_ids = ! empty( $activities_template->activity->children )
3928
- ? (array) bp_activity_recurse_comments_user_ids( $activities_template->activity->children )
3929
- : array();
3930
 
3931
- /**
3932
- * Filters the list of user IDs for the current activity item.
3933
- *
3934
- * @since 1.7.0
3935
- *
3936
- * @param array $value Array of unique user IDs for the current activity item.
3937
- */
3938
  return apply_filters( 'bp_activity_get_comments_user_ids', array_unique( $user_ids ) );
3939
  }
3940
 
3941
  /**
3942
  * Recurse through all activity comments and collect the IDs of the users who wrote them.
3943
  *
3944
- * @since 1.7.0
3945
  *
3946
  * @param array $comments Array of {@link BP_Activity_Activity} items.
3947
  * @return array Array of user IDs.
3948
  */
3949
- function bp_activity_recurse_comments_user_ids( array $comments = array() ) {
3950
-
3951
- // Default user ID's array.
3952
  $user_ids = array();
3953
 
3954
- // Loop through comments and try to get user ID's.
3955
- if ( ! empty( $comments ) ) {
3956
- foreach ( $comments as $comment ) {
3957
-
3958
- // If a user is a spammer, their activity items will have been
3959
- // automatically marked as spam. Skip these.
3960
- if ( ! empty( $comment->is_spam ) ) {
3961
- continue;
3962
- }
3963
 
3964
- // Add user ID to array.
3965
- $user_ids[] = $comment->user_id;
3966
 
3967
- // Check for commentception.
3968
- if ( ! empty( $comment->children ) ) {
3969
- $user_ids = array_merge( $user_ids, bp_activity_recurse_comments_user_ids( $comment->children ) );
3970
- }
3971
- }
3972
  }
3973
 
3974
- /**
3975
- * Filters the list of user IDs for the current activity comment item.
3976
- *
3977
- * @since 2.1.0
3978
- *
3979
- * @param array $user_ids Array of user IDs for the current activity comment item.
3980
- * @param array $comments Array of comments being checked for user IDs.
3981
- */
3982
- return apply_filters( 'bp_activity_recurse_comments_user_ids', $user_ids, $comments );
3983
  }
3984
 
3985
  /**
3986
  * Output the mentionname for the displayed user.
3987
  *
3988
- * @since 1.9.0
3989
  */
3990
  function bp_displayed_user_mentionname() {
3991
  echo bp_get_displayed_user_mentionname();
@@ -3993,82 +3031,58 @@ function bp_displayed_user_mentionname() {
3993
  /**
3994
  * Get the mentionname for the displayed user.
3995
  *
3996
- * @since 1.9.0
3997
  *
3998
  * @return string Mentionname for the displayed user, if available.
3999
  */
4000
  function bp_get_displayed_user_mentionname() {
4001
-
4002
- /**
4003
- * Filters the mentionname for the displayed user.
4004
- *
4005
- * @since 1.9.0
4006
- *
4007
- * @param string $value The mentionanme for the displayed user.
4008
- */
4009
  return apply_filters( 'bp_get_displayed_user_mentionname', bp_activity_get_user_mentionname( bp_displayed_user_id() ) );
4010
  }
4011
 
4012
  /**
4013
  * Echo a list of all registered activity types for use in dropdowns or checkbox lists.
4014
  *
4015
- * @since 1.7.0
4016
  *
4017
- * @param string $output Optional. Either 'select' or 'checkbox'. Default: 'select'.
4018
- * @param array|string $args {
4019
  * Optional extra arguments.
4020
- * @type string $checkbox_name When returning checkboxes, sets the 'name'
4021
- * attribute.
4022
- * @type array|string $selected A list of types that should be checked/
4023
- * selected.
4024
  * }
4025
  */
4026
  function bp_activity_types_list( $output = 'select', $args = '' ) {
4027
-
4028
- $args = bp_parse_args( $args, array(
4029
  'checkbox_name' => 'bp_activity_types',
4030
  'selected' => array(),
4031
- ) );
 
4032
 
4033
  $activities = bp_activity_get_types();
4034
  natsort( $activities );
4035
 
4036
- // Loop through the activity types and output markup.
4037
  foreach ( $activities as $type => $description ) {
4038
 
4039
- // See if we need to preselect the current type.
4040
  $checked = checked( true, in_array( $type, (array) $args['selected'] ), false );
4041
  $selected = selected( true, in_array( $type, (array) $args['selected'] ), false );
4042
 
4043
- // Switch output based on the element.
4044
- switch ( $output ) {
4045
- case 'select' :
4046
- printf( '<option value="%1$s" %2$s>%3$s</option>', esc_attr( $type ), $selected, esc_html( $description ) );
4047
- break;
4048
- case 'checkbox' :
4049
- printf( '<label style="" for="%1$s[]">%2$s<input type="checkbox" id="%1$s[]" name="%1$s[]" value="%3$s" %4$s/></label>', esc_attr( $args['checkbox_name'] ), esc_html( $description ), esc_attr( $args['checkbox_name'] ), esc_attr( $args['checkbox_name'] ), esc_attr( $type ), $checked );
4050
- break;
4051
- }
4052
 
4053
- /**
4054
- * Fires at the end of the listing of activity types.
4055
- *
4056
- * This is a variable action hook. The actual hook to use will depend on the output type specified.
4057
- * Two default hooks are bp_activity_types_list_select and bp_activity_types_list_checkbox.
4058
- *
4059
- * @since 1.7.0
4060
- *
4061
- * @param array $args Array of arguments passed into function.
4062
- * @param string $type Activity type being rendered in the output.
4063
- * @param string $description Description of the activity type being rendered.
4064
- */
4065
  do_action( 'bp_activity_types_list_' . $output, $args, $type, $description );
4066
  }
4067
 
4068
- // Backpat with BP-Default for dropdown boxes only.
4069
- if ( 'select' === $output ) {
4070
  do_action( 'bp_activity_filter_options' );
4071
- }
4072
  }
4073
 
4074
 
@@ -4077,7 +3091,7 @@ function bp_activity_types_list( $output = 'select', $args = '' ) {
4077
  /**
4078
  * Output the sitewide activity feed link.
4079
  *
4080
- * @since 1.0.0
4081
  *
4082
  * @uses bp_get_sitewide_activity_feed_link()
4083
  */
@@ -4088,7 +3102,7 @@ function bp_sitewide_activity_feed_link() {
4088
  /**
4089
  * Returns the sitewide activity feed link.
4090
  *
4091
- * @since 1.0.0
4092
  *
4093
  * @uses home_url()
4094
  * @uses bp_get_activity_root_slug()
@@ -4097,21 +3111,13 @@ function bp_sitewide_activity_feed_link() {
4097
  * @return string The sitewide activity feed link.
4098
  */
4099
  function bp_get_sitewide_activity_feed_link() {
4100
-
4101
- /**
4102
- * Filters the sidewide activity feed link.
4103
- *
4104
- * @since 1.0.0
4105
- *
4106
- * @param string $value The feed link for sitewide activity.
4107
- */
4108
  return apply_filters( 'bp_get_sitewide_activity_feed_link', bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/feed/' );
4109
  }
4110
 
4111
  /**
4112
  * Output the member activity feed link.
4113
  *
4114
- * @since 1.2.0
4115
  *
4116
  * @uses bp_get_member_activity_feed_link()
4117
  */
@@ -4122,8 +3128,8 @@ function bp_member_activity_feed_link() {
4122
  /**
4123
  * Output the member activity feed link.
4124
  *
4125
- * @since 1.0.0
4126
- * @deprecated 1.2.0
4127
  *
4128
  * @todo properly deprecate in favor of bp_member_activity_feed_link().
4129
  *
@@ -4134,7 +3140,7 @@ function bp_activities_member_rss_link() { echo bp_get_member_activity_feed_link
4134
  /**
4135
  * Return the member activity feed link.
4136
  *
4137
- * @since 1.2.0
4138
  *
4139
  * @uses bp_is_profile_component()
4140
  * @uses bp_is_current_action()
@@ -4149,46 +3155,27 @@ function bp_activities_member_rss_link() { echo bp_get_member_activity_feed_link
4149
  */
4150
  function bp_get_member_activity_feed_link() {
4151
 
4152
- // Single member activity feed link.
4153
- if ( bp_is_profile_component() || bp_is_current_action( 'just-me' ) ) {
4154
  $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/feed/';
4155
-
4156
- // Friend feed link.
4157
- } elseif ( bp_is_active( 'friends' ) && bp_is_current_action( bp_get_friends_slug() ) ) {
4158
  $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_friends_slug() . '/feed/';
4159
-
4160
- // Group feed link.
4161
- } elseif ( bp_is_active( 'groups' ) && bp_is_current_action( bp_get_groups_slug() ) ) {
4162
  $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_groups_slug() . '/feed/';
4163
-
4164
- // Favorites activity feed link.
4165
- } elseif ( 'favorites' === bp_current_action() ) {
4166
  $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/favorites/feed/';
4167
-
4168
- // Mentions activity feed link.
4169
- } elseif ( ( 'mentions' === bp_current_action() ) && bp_activity_do_mentions() ) {
4170
  $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/mentions/feed/';
4171
-
4172
- // No feed link.
4173
- } else {
4174
  $link = '';
4175
- }
4176
 
4177
- /**
4178
- * Filters the member activity feed link.
4179
- *
4180
- * @since 1.0.0
4181
- *
4182
- * @param string $link URL for the member activity feed.
4183
- */
4184
  return apply_filters( 'bp_get_activities_member_rss_link', $link );
4185
  }
4186
 
4187
  /**
4188
  * Return the member activity feed link.
4189
  *
4190
- * @since 1.0.0
4191
- * @deprecated 1.2.0
4192
  *
4193
  * @todo properly deprecate in favor of bp_get_member_activity_feed_link().
4194
  *
@@ -4204,7 +3191,7 @@ function bp_activities_member_rss_link() { echo bp_get_member_activity_feed_link
4204
  /**
4205
  * Outputs the activity feed item guid.
4206
  *
4207
- * @since 1.0.0
4208
  *
4209
  * @uses bp_activity_feed_item_guid()
4210
  */
@@ -4215,7 +3202,7 @@ function bp_activity_feed_item_guid() {
4215
  /**
4216
  * Returns the activity feed item guid.
4217
  *
4218
- * @since 1.2.0
4219
  *
4220
  * @global object $activities_template {@link BP_Activity_Template}
4221
  * @uses apply_filters() To call the 'bp_get_activity_feed_item_guid' hook.
@@ -4225,20 +3212,13 @@ function bp_activity_feed_item_guid() {
4225
  function bp_get_activity_feed_item_guid() {
4226
  global $activities_template;
4227
 
4228
- /**
4229
- * Filters the activity feed item guid.
4230
- *
4231
- * @since 1.1.3
4232
- *
4233
- * @param string $value Calculated md5 value for the activity feed item.
4234
- */
4235
  return apply_filters( 'bp_get_activity_feed_item_guid', md5( $activities_template->activity->date_recorded . '-' . $activities_template->activity->content ) );
4236
  }
4237
 
4238
  /**
4239
  * Output the activity feed item title.
4240
  *
4241
- * @since 1.0.0
4242
  *
4243
  * @uses bp_get_activity_feed_item_title()
4244
  */
@@ -4249,7 +3229,7 @@ function bp_activity_feed_item_title() {
4249
  /**
4250
  * Return the activity feed item title.
4251
  *
4252
- * @since 1.0.0
4253
  *
4254
  * @global object $activities_template {@link BP_Activity_Template}
4255
  * @uses ent2ncr()
@@ -4262,37 +3242,27 @@ function bp_activity_feed_item_title() {
4262
  function bp_get_activity_feed_item_title() {
4263
  global $activities_template;
4264
 
4265
- if ( !empty( $activities_template->activity->action ) ) {
4266
  $content = $activities_template->activity->action;
4267
- } else {
4268
  $content = $activities_template->activity->content;
4269
- }
4270
 
4271
  $content = explode( '<span', $content );
4272
- $title = strip_tags( ent2ncr( trim( convert_chars( $content[0] ) ) ) );
4273
 
4274
- if ( ':' === substr( $title, -1 ) ) {
4275
  $title = substr( $title, 0, -1 );
4276
- }
4277
 
4278
- if ( 'activity_update' === $activities_template->activity->type ) {
4279
  $title .= ': ' . strip_tags( ent2ncr( trim( convert_chars( bp_create_excerpt( $activities_template->activity->content, 70, array( 'ending' => " [&#133;]" ) ) ) ) ) );
4280
- }
4281
 
4282
- /**
4283
- * Filters the activity feed item title.
4284
- *
4285
- * @since 1.0.0
4286
- *
4287
- * @param string $title The title for the activity feed item.
4288
- */
4289
  return apply_filters( 'bp_get_activity_feed_item_title', $title );
4290
  }
4291
 
4292
  /**
4293
- * Output the activity feed item link.
4294
  *
4295
- * @since 1.0.0
4296
  *
4297
  * @uses bp_get_activity_feed_item_link()
4298
  */
@@ -4301,9 +3271,9 @@ function bp_activity_feed_item_link() {
4301
  }
4302
 
4303
  /**
4304
- * Return the activity feed item link.
4305
  *
4306
- * @since 1.0.0
4307
  *
4308
  * @global object $activities_template {@link BP_Activity_Template}
4309
  * @uses apply_filters() To call the 'bp_get_activity_feed_item_link' hook.
@@ -4313,24 +3283,13 @@ function bp_activity_feed_item_link() {
4313
  function bp_get_activity_feed_item_link() {
4314
  global $activities_template;
4315
 
4316
- $retval = ! empty( $activities_template->activity->primary_link )
4317
- ? $activities_template->activity->primary_link
4318
- : '';
4319
-
4320
- /**
4321
- * Filters the activity feed item link.
4322
- *
4323
- * @since 1.0.0
4324
- *
4325
- * @param string $retval The URL for the activity feed item.
4326
- */
4327
- return apply_filters( 'bp_get_activity_feed_item_link', $retval );
4328
  }
4329
 
4330
  /**
4331
  * Output the activity feed item date.
4332
  *
4333
- * @since 1.0.0
4334
  *
4335
  * @uses bp_get_activity_feed_item_date()
4336
  */
@@ -4341,7 +3300,7 @@ function bp_activity_feed_item_date() {
4341
  /**
4342
  * Return the activity feed item date.
4343
  *
4344
- * @since 1.0.0
4345
  *
4346
  * @global object $activities_template {@link BP_Activity_Template}
4347
  * @uses apply_filters() To call the 'bp_get_activity_feed_item_date' hook.
@@ -4351,24 +3310,13 @@ function bp_activity_feed_item_date() {
4351
  function bp_get_activity_feed_item_date() {
4352
  global $activities_template;
4353
 
4354
- $retval = ! empty( $activities_template->activity->date_recorded )
4355
- ? $activities_template->activity->date_recorded
4356
- : '';
4357
-
4358
- /**
4359
- * Filters the activity feed item date.
4360
- *
4361
- * @since 1.0.0
4362
- *
4363
- * @param string $retval The date for the activity feed item.
4364
- */
4365
- return apply_filters( 'bp_get_activity_feed_item_date', $retval );
4366
  }
4367
 
4368
  /**
4369
  * Output the activity feed item description.
4370
  *
4371
- * @since 1.0.0
4372
  *
4373
  * @uses bp_get_activity_feed_item_description()
4374
  */
@@ -4379,7 +3327,7 @@ function bp_activity_feed_item_description() {
4379
  /**
4380
  * Return the activity feed item description.
4381
  *
4382
- * @since 1.0.0
4383
  *
4384
  * @global object $activities_template {@link BP_Activity_Template}
4385
  * @uses ent2ncr()
@@ -4391,30 +3339,17 @@ function bp_activity_feed_item_description() {
4391
  function bp_get_activity_feed_item_description() {
4392
  global $activities_template;
4393
 
4394
- // Get the content, if exists.
4395
- $content = ! empty( $activities_template->activity->content )
4396
- ? $activities_template->activity->content
4397
- : '';
4398
-
4399
- // Perform a few string conversions on the content, if it's not empty.
4400
- if ( ! empty( $content ) ) {
4401
- $content = ent2ncr( convert_chars( str_replace( '%s', '', $content ) ) );
4402
- }
4403
 
4404
- /**
4405
- * Filters the activity feed item description.
4406
- *
4407
- * @since 1.0.0
4408
- *
4409
- * @param string $content The description for the activity feed item.
4410
- */
4411
- return apply_filters( 'bp_get_activity_feed_item_description', $content );
4412
  }
4413
 
4414
  /**
4415
  * Template tag so we can hook activity feed to <head>.
4416
  *
4417
- * @since 1.5.0
4418
  *
4419
  * @uses bloginfo()
4420
  * @uses bp_sitewide_activity_feed_link()
@@ -4427,98 +3362,3 @@ function bp_activity_sitewide_feed() {
4427
  <?php
4428
  }
4429
  add_action( 'bp_head', 'bp_activity_sitewide_feed' );
4430
-
4431
- /**
4432
- * Display available filters depending on the scope.
4433
- *
4434
- * @since 2.1.0
4435
- *
4436
- * @param string $context The current context. 'activity', 'member',
4437
- * 'member_groups', 'group'.
4438
- * @uses bp_get_activity_show_filters()
4439
- */
4440
- function bp_activity_show_filters( $context = '' ) {
4441
- echo bp_get_activity_show_filters( $context );
4442
- }
4443
- /**
4444
- * Get available filters depending on the scope.
4445
- *
4446
- * @since 2.1.0
4447
- *
4448
- * @param string $context The current context. 'activity', 'member',
4449
- * 'member_groups', 'group'.
4450
- *
4451
- * @return string HTML for <option> values.
4452
- */
4453
- function bp_get_activity_show_filters( $context = '' ) {
4454
- // Set default context based on current page.
4455
- if ( empty( $context ) ) {
4456
-
4457
- // On member pages, default to 'member', unless this
4458
- // is a user's Groups activity.
4459
- if ( bp_is_user() ) {
4460
- if ( bp_is_active( 'groups' ) && bp_is_current_action( bp_get_groups_slug() ) ) {
4461
- $context = 'member_groups';
4462
- } else {
4463
- $context = 'member';
4464
- }
4465
-
4466
- // On individual group pages, default to 'group'.
4467
- } elseif ( bp_is_active( 'groups' ) && bp_is_group() ) {
4468
- $context = 'group';
4469
-
4470
- // 'activity' everywhere else.
4471
- } else {
4472
- $context = 'activity';
4473
- }
4474
- }
4475
-
4476
- $filters = array();
4477
-
4478
- // Walk through the registered actions, and prepare an the
4479
- // select box options.
4480
- foreach ( bp_activity_get_actions() as $actions ) {
4481
- foreach ( $actions as $action ) {
4482
- if ( ! in_array( $context, (array) $action['context'] ) ) {
4483
- continue;
4484
- }
4485
-
4486
- // Friends activity collapses two filters into one.
4487
- if ( in_array( $action['key'], array( 'friendship_accepted', 'friendship_created' ) ) ) {
4488
- $action['key'] = 'friendship_accepted,friendship_created';
4489
- }
4490
-
4491
- $filters[ $action['key'] ] = $action['label'];
4492
- }
4493
- }
4494
-
4495
- /**
4496
- * Filters the options available in the activity filter dropdown.
4497
- *
4498
- * @since 2.2.0
4499
- *
4500
- * @param array $filters Array of filter options for the given context, in the following format: $option_value => $option_name.
4501
- * @param string $context Context for the filter. 'activity', 'member', 'member_groups', 'group'.
4502
- */
4503
- $filters = apply_filters( 'bp_get_activity_show_filters_options', $filters, $context );
4504
-
4505
- // Build the options output.
4506
- $output = '';
4507
-
4508
- if ( ! empty( $filters ) ) {
4509
- foreach ( $filters as $value => $filter ) {
4510
- $output .= '<option value="' . esc_attr( $value ) . '">' . esc_html( $filter ) . '</option>' . "\n";
4511
- }
4512
- }
4513
-
4514
- /**
4515
- * Filters the HTML markup result for the activity filter dropdown.
4516
- *
4517
- * @since 2.1.0
4518
- *
4519
- * @param string $output HTML output for the activity filter dropdown.
4520
- * @param array $filters Array of filter options for the given context, in the following format: $option_value => $option_name.
4521
- * @param string $context Context for the filter. 'activity', 'member', 'member_groups', 'group'.
4522
- */
4523
- return apply_filters( 'bp_get_activity_show_filters', $output, $filters, $context );
4524
- }
1
  <?php
2
+
3
  /**
4
  * BuddyPress Activity Template Functions.
5
  *
7
  * @subpackage ActivityTemplate
8
  */
9
 
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
 
13
  /**
14
  * Output the activity component slug.
15
  *
16
+ * @since BuddyPress (1.5)
17
  *
18
  * @uses bp_get_activity_slug()
19
  */
23
  /**
24
  * Return the activity component slug.
25
  *
26
+ * @since BuddyPress (1.5)
27
  *
28
  * @uses apply_filters() To call the 'bp_get_activity_slug' hook.
29
  *
30
  * @return string The activity component slug.
31
  */
32
  function bp_get_activity_slug() {
 
 
 
 
 
 
 
 
33
  return apply_filters( 'bp_get_activity_slug', buddypress()->activity->slug );
34
  }
35
 
36
  /**
37
  * Output the activity component root slug.
38
  *
39
+ * @since BuddyPress (1.5)
40
  *
41
  * @uses bp_get_activity_root_slug()
42
  */
46
  /**
47
  * Return the activity component root slug.
48
  *
49
+ * @since BuddyPress (1.5)
50
  *
51
  * @uses apply_filters() To call the 'bp_get_activity_root_slug' hook.
52
  *
53
  * @return string The activity component root slug.
54
  */
55
  function bp_get_activity_root_slug() {
 
 
 
 
 
 
 
 
56
  return apply_filters( 'bp_get_activity_root_slug', buddypress()->activity->root_slug );
57
  }
58
 
59
  /**
60
  * Output activity directory permalink.
61
  *
62
+ * @since BuddyPress (1.5)
63
  *
64
  * @uses bp_get_activity_directory_permalink()
65
  */
66
  function bp_activity_directory_permalink() {
67
+ echo bp_get_activity_directory_permalink();
68
  }
69
  /**
70
+ * Return activity directory permalink
71
  *
72
+ * @since BuddyPress (1.5)
73
  *
74
+ * @uses traisingslashit()
75
  * @uses bp_get_root_domain()
76
  * @uses bp_get_activity_root_slug()
77
  * @uses apply_filters() To call the 'bp_get_activity_directory_permalink' hook.
79
  * @return string Activity directory permalink.
80
  */
81
  function bp_get_activity_directory_permalink() {
 
 
 
 
 
 
 
 
82
  return apply_filters( 'bp_get_activity_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_activity_root_slug() ) );
83
  }
84
 
87
  *
88
  * This is responsible for loading a group of activity items and displaying them.
89
  *
90
+ * @since BuddyPress (1.0)
91
  */
92
  class BP_Activity_Template {
93
+ var $current_activity = -1;
94
+ var $activity_count;
95
+ var $total_activity_count;
96
+ var $activities;
97
+ var $activity;
98
 
99
+ var $in_the_loop;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
 
101
+ var $pag_page;
102
+ var $pag_num;
103
+ var $pag_links;
 
 
 
 
104
 
105
+ var $full_name;
 
 
 
 
 
 
106
 
107
  /**
108
  * Constructor method.
118
  * BP_Activity_Activity::get(), as well as 'page_arg' and
119
  * 'include'. Default values for 'per_page' and 'display_comments'
120
  * differ from the originating function, and are described below.
121
+ * @type string $page_arg The string used as a query parameter in
122
+ * pagination links. Default: 'acpage'.
123
+ * @type array|bool $include Pass an array of activity IDs to
124
+ * retrieve only those items, or false to noop the 'include'
125
+ * parameter. 'include' differs from 'in' in that 'in' forms
126
+ * an IN clause that works in conjunction with other filters
127
+ * passed to the function, while 'include' is interpreted as
128
+ * an exact list of items to retrieve, which skips all other
129
+ * filter-related parameters. Default: false.
130
+ * @type int|bool $per_page Default: 20.
131
  * @type string|bool $display_comments Default: 'threaded'.
132
  * }
133
  */
134
+ function __construct( $args ) {
135
+ global $bp;
136
 
137
+ // Backward compatibility with old method of passing arguments
138
  if ( !is_array( $args ) || func_num_args() > 1 ) {
139
  _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__ ) );
140
 
163
  'per_page' => 20,
164
  'page_arg' => 'acpage',
165
  'max' => false,
 
 
166
  'sort' => false,
167
  'include' => false,
168
  'exclude' => false,
169
  'in' => false,
170
  'filter' => false,
 
171
  'search_terms' => false,
172
  'meta_query' => false,
 
 
173
  'display_comments' => 'threaded',
174
  'show_hidden' => false,
175
  'spam' => 'ham_only',
178
  $r = wp_parse_args( $args, $defaults );
179
  extract( $r );
180
 
181
+ $this->pag_page = isset( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[$page_arg] ) : $page;
182
+ $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
 
183
 
184
+ // Check if blog/forum replies are disabled
185
+ $this->disable_blogforum_replies = isset( $bp->site_options['bp-disable-blogforum-comments'] ) ? $bp->site_options['bp-disable-blogforum-comments'] : false;
186
 
187
+ // Get an array of the logged in user's favorite activities
188
  $this->my_favs = maybe_unserialize( bp_get_user_meta( bp_loggedin_user_id(), 'bp_favorite_activities', true ) );
189
 
190
+ // Fetch specific activity items based on ID's
191
  if ( !empty( $include ) ) {
192
  $this->activities = bp_activity_get_specific( array(
193
  'activity_ids' => explode( ',', $include ),
194
  'max' => $max,
 
195
  'page' => $this->pag_page,
196
  'per_page' => $this->pag_num,
197
  'sort' => $sort,
201
  'update_meta_cache' => $update_meta_cache,
202
  ) );
203
 
204
+ // Fetch all activity items
205
  } else {
206
  $this->activities = bp_activity_get( array(
207
  'display_comments' => $display_comments,
208
  'max' => $max,
 
209
  'per_page' => $this->pag_num,
210
  'page' => $this->pag_page,
211
  'sort' => $sort,
212
  'search_terms' => $search_terms,
213
  'meta_query' => $meta_query,
 
 
214
  'filter' => $filter,
 
215
  'show_hidden' => $show_hidden,
216
  'exclude' => $exclude,
217
  'in' => $in,
220
  ) );
221
  }
222
 
223
+ if ( !$max || $max >= (int) $this->activities['total'] )
224
+ $this->total_activity_count = (int) $this->activities['total'];
225
+ else
226
+ $this->total_activity_count = (int) $max;
 
 
 
 
 
 
 
227
 
228
  $this->activities = $this->activities['activities'];
229
 
239
 
240
  $this->full_name = bp_get_displayed_user_fullname();
241
 
242
+ // Fetch parent content for activity comments so we do not have to query in the loop
243
  foreach ( (array) $this->activities as $activity ) {
244
+ if ( 'activity_comment' != $activity->type )
245
  continue;
 
246
 
247
  $parent_ids[] = $activity->item_id;
248
  }
249
 
250
+ if ( !empty( $parent_ids ) )
251
  $activity_parents = bp_activity_get_specific( array( 'activity_ids' => $parent_ids ) );
 
252
 
253
  if ( !empty( $activity_parents['activities'] ) ) {
254
+ foreach( $activity_parents['activities'] as $parent )
255
  $this->activity_parents[$parent->id] = $parent;
 
256
 
257
  unset( $activity_parents );
258
  }
259
 
260
  if ( (int) $this->total_activity_count && (int) $this->pag_num ) {
261
  $this->pag_links = paginate_links( array(
262
+ 'base' => add_query_arg( $page_arg, '%#%' ),
263
  'format' => '',
264
  'total' => ceil( (int) $this->total_activity_count / (int) $this->pag_num ),
265
  'current' => (int) $this->pag_page,
266
  'prev_text' => _x( '&larr;', 'Activity pagination previous text', 'buddypress' ),
267
  'next_text' => _x( '&rarr;', 'Activity pagination next text', 'buddypress' ),
268
+ 'mid_size' => 1
 
269
  ) );
270
  }
271
  }
278
  * @return bool True if there are items in the loop, otherwise false.
279
  */
280
  function has_activities() {
281
+ if ( $this->activity_count )
282
  return true;
 
283
 
284
  return false;
285
  }
289
  *
290
  * @return object The next activity item to iterate over.
291
  */
292
+ function next_activity() {
293
  $this->current_activity++;
294
+ $this->activity = $this->activities[$this->current_activity];
295
 
296
  return $this->activity;
297
  }
299
  /**
300
  * Rewind the posts and reset post index.
301
  */
302
+ function rewind_activities() {
303
  $this->current_activity = -1;
304
  if ( $this->activity_count > 0 ) {
305
  $this->activity = $this->activities[0];
318
  * @return bool True if there are more activity items to show,
319
  * otherwise false.
320
  */
321
+ function user_activities() {
322
+ if ( $this->current_activity + 1 < $this->activity_count ) {
323
  return true;
324
+ } elseif ( $this->current_activity + 1 == $this->activity_count ) {
325
+ do_action('activity_loop_end');
326
+ // Do some cleaning up after the loop
 
 
 
 
 
 
 
327
  $this->rewind_activities();
328
  }
329
 
330
  $this->in_the_loop = false;
 
331
  return false;
332
  }
333
 
340
  *
341
  * @see bp_the_activity()
342
  */
343
+ function the_activity() {
344
 
345
  $this->in_the_loop = true;
346
  $this->activity = $this->next_activity();
347
 
348
+ if ( is_array( $this->activity ) )
349
  $this->activity = (object) $this->activity;
 
350
 
351
+ if ( $this->current_activity == 0 ) // loop has just started
 
 
 
 
 
 
 
352
  do_action('activity_loop_start');
 
353
  }
354
  }
355
 
360
  * $activities_template global, enabling the use of BuddyPress templates and
361
  * template functions to display a list of activity items.
362
  *
363
+ * @since BuddyPress (1.0)
 
364
  *
365
  * @global object $activities_template {@link BP_Activity_Template}
366
+ * @global object $bp BuddyPress global settings.
367
  * @uses groups_is_user_member()
368
  * @uses bp_current_action()
369
  * @uses bp_is_current_action()
376
  * @uses bp_activity_get_user_favorites()
377
  * @uses apply_filters() To call the 'bp_has_activities' hook.
378
  *
379
+ * @param array $args {
380
+ * Arguments for limiting the contents of the activity loop. Most
381
+ * arguments are in the same format as {@link BP_Activity_Activity::get()}.
382
+ * However, because the format of the arguments accepted here differs in
383
+ * a number of ways, and because bp_has_activities() determines some
384
+ * default arguments in a dynamic fashion, we list all accepted arguments
385
+ * here as well.
386
+ *
387
+ * Arguments can be passed as an associative array, or as a URL query
388
+ * string (eg, 'user_id=4&display_comments=threaded').
389
+ *
390
+ * @type int $page Which page of results to fetch. Using page=1 without
391
+ * per_page will result in no pagination. Default: 1.
392
+ * @type int|bool $per_page Number of results per page. Default: 20.
393
+ * @type string $page_arg The string used as a query parameter in
394
+ * pagination links. Default: 'acpage'.
395
+ * @type int|bool $max Maximum number of results to return.
396
+ * Default: false (unlimited).
397
+ * @type string $sort 'ASC' or 'DESC'. Default: 'DESC'.
398
+ * @type array|bool $exclude Array of activity IDs to exclude. Default: false.
399
+ * @type array|bool $in Array of IDs to limit query by (IN). 'in' is
400
+ * intended to be used in conjunction with other filter parameters.
401
+ * Default: false.
402
+ * @type array|bool $include Array of exact activity IDs to query.
403
+ * Providing an 'include' array will override all other filters
404
+ * passed in the argument array. When viewing a the permalink page
405
+ * for a single activity item, this value defaults to the ID of that
406
+ * item. Otherwise the default is false.
407
+ * @type array $meta_query Limit by activitymeta by passing an array of
408
+ * meta_query conditions. See {@link WP_Meta_Query::queries} for a
409
+ * description of the syntax.
410
+ * @type string $search_terms Limit results by a search term. Default: false.
411
+ * @type string|bool $scope Use one of BuddyPress's pre-built filters. In
412
+ * each case, the term 'current user' refers to the displayed user
413
+ * when looking at a user profile, and otherwise to the logged-in user.
414
+ * - 'just-me' retrieves items belonging only to the logged-in user;
415
+ * this is equivalent to passing a 'user_id' argument
416
+ * - 'friends' retrieves items belonging to the friends of the
417
+ * current user
418
+ * - 'groups' retrieves items associated with the groups to which
419
+ * the current user belongs
420
+ * - 'favorites' retrieves the current user's favorited activity
421
+ * items
422
+ * - 'mentions' retrieves activity items where the current user has
423
+ * received an @-mention
424
+ * The default value of 'scope' is set to one of the above if that
425
+ * value appears in the appropriate place in the URL; eg, 'scope' will
426
+ * be 'groups' when visiting http://example.com/members/joe/activity/groups/.
427
+ * Otherwise defaults to false.
428
+ * @type int|array|bool $user_id The ID(s) of user(s) whose activity should
429
+ * be fetched. Pass a single ID or an array of IDs. When viewing a
430
+ * user profile page (but not that user's activity subpages, ie My
431
+ * Friends, My Groups, etc), 'user_id' defaults to the ID of the
432
+ * displayed user. Otherwise the default is false.
433
+ * @type string|array|bool $object Filters by the `component` column in the
434
+ * database, which is generally the component ID in the case of
435
+ * BuddyPress components, or the plugin slug in the case of plugins.
436
+ * For example, 'groups' will limit results to those that are
437
+ * associated with the BP Groups component. Accepts a single
438
+ * component string, or an array of multiple components. Defaults to
439
+ * 'groups' when viewing the page of a single group, the My Groups
440
+ * activity filter, or the Activity > Groups filter of a user profile.
441
+ * Otherwise defaults to false.
442
+ * @type string|array|bool $action Filters by the `type` column in the
443
+ * database, which is a string categorizing the activity item (eg,
444
+ * 'new_blog_post', 'created_group'). Accepts a single type string,
445
+ * or an array of multiple types. Defaults to false.
446
+ * @type int|array|bool $primary_id Filters by the `item_id` column in the
447
+ * database. The meaning of 'primary_id' differs between components/
448
+ * types; for example, in the case of 'created_group', 'primary_id'
449
+ * is the ID of the group. Accepts a single ID, or an array of
450
+ * multiple IDs. When viewing a single group, defaults to the current
451
+ * group ID. When viewing a user's Groups stream page, defaults to
452
+ * the IDs of the user's groups. Otherwise defaults to false.
453
+ * @type int|array|bool $secondary_id Filters by the `secondary_item_id`
454
+ * column in the database. The meaning of 'secondary_id' differs
455
+ * between components/types. Accepts a single ID, or an array of
456
+ * multiple IDs. Defaults to false.
457
+ * @type int $offset Return only activity items with an ID greater than or
458
+ * equal to this one. Note that providing an offset will disable
459
+ * pagination. Default: false.
460
+ * @type string|bool $display_comments How to handle activity comments.
461
+ * Possible values:
462
+ * - 'threaded' - comments appear in a threaded tree, under their
463
+ * parent items
464
+ * - 'stream' - the activity stream is presented in a flat manner,
465
+ * with comments sorted in chronological order alongside other
466
+ * activity items
467
+ * - false - don't fetch activity comments at all
468
+ * Default: 'threaded'.
469
+ * @type bool $show_hidden Whether to show items marked hide_sitewide.
470
+ * Defaults to false, except in the following cases:
471
+ * - User is viewing his own activity stream
472
+ * - User is viewing the activity stream of a non-public group of
473
+ * which he is a member
474
+ * @type bool $show_hidden Normally defaults to false, except when:
475
+ * - a user is viewing his own activity stream
476
+ * - a user is viewing the activity stream of a non-public group of
477
+ * which he is a member
478
+ * @type string|bool $spam Spam status. 'ham_only', 'spam_only', or false
479
+ * to show all activity regardless of spam status. Default: 'ham_only'.
480
+ * @type bool $populate_extras Whether to pre-fetch the activity metadata
481
+ * for the queried items. Default: true.
482
  * }
483
  * @return bool Returns true when activities are found, otherwise false.
484
  */
485
  function bp_has_activities( $args = '' ) {
486
+ global $activities_template, $bp;
487
+
488
+ /***
489
+ * Set the defaults based on the current page. Any of these will be overridden
490
+ * if arguments are directly passed into the loop. Custom plugins should always
491
+ * pass their parameters directly to the loop.
492
+ */
493
+ $user_id = false;
494
+ $include = false;
495
+ $exclude = false;
496
+ $in = false;
497
+ $show_hidden = false;
498
+ $object = false;
499
+ $primary_id = false;
500
+
501
+ // User filtering
502
+ if ( bp_displayed_user_id() )
503
+ $user_id = bp_displayed_user_id();
504
+
505
+ // Group filtering
506
+ if ( !empty( $bp->groups->current_group ) ) {
507
+ $object = $bp->groups->id;
508
+ $primary_id = $bp->groups->current_group->id;
509
+
510
+ if ( ( 'public' != $bp->groups->current_group->status ) && ( groups_is_user_member( bp_loggedin_user_id(), $bp->groups->current_group->id ) || bp_current_user_can( 'bp_moderate' ) ) )
511
+ $show_hidden = true;
512
+ }
513
+
514
+ // The default scope should recognize custom slugs
515
+ if ( array_key_exists( bp_current_action(), (array) $bp->loaded_components ) ) {
516
+ $scope = $bp->loaded_components[bp_current_action()];
517
+ }
518
+ else
519
+ $scope = bp_current_action();
520
+
521
+ // Support for permalinks on single item pages: /groups/my-group/activity/124/
522
+ if ( bp_is_current_action( bp_get_activity_slug() ) )
523
+ $include = bp_action_variable( 0 );
524
+
525
+ // Note: any params used for filtering can be a single value, or multiple values comma separated.
526
+ $defaults = array(
527
+ 'display_comments' => 'threaded', // false for none, stream/threaded - show comments in the stream or threaded under items
528
+ 'include' => $include, // pass an activity_id or string of IDs comma-separated
529
+ 'exclude' => $exclude, // pass an activity_id or string of IDs comma-separated
530
+ 'in' => $in, // comma-separated list or array of activity IDs among which to search
531
+ 'sort' => 'DESC', // sort DESC or ASC
532
+ 'page' => 1, // which page to load
533
+ 'per_page' => 20, // number of items per page
534
+ 'max' => false, // max number to return
535
+ 'show_hidden' => $show_hidden, // Show activity items that are hidden site-wide?
536
+ 'spam' => 'ham_only', // Hide spammed items
537
 
538
+ 'page_arg' => 'acpage', // See https://buddypress.trac.wordpress.org/ticket/3679
 
539
 
540
+ // Scope - pre-built activity filters for a user (friends/groups/favorites/mentions)
541
+ 'scope' => $scope,
 
542
 
543
+ // Filtering
544
+ 'user_id' => $user_id, // user_id to filter on
545
+ 'object' => $object, // object to filter on e.g. groups, profile, status, friends
546
+ 'action' => false, // action to filter on e.g. activity_update, new_forum_post, profile_updated
547
+ 'primary_id' => $primary_id, // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
548
+ 'secondary_id' => false, // secondary object ID to filter on e.g. a post_id
549
+ 'offset' => false, // return only items >= this ID
550
+ 'since' => false, // return only items recorded since this Y-m-d H:i:s date
551
+
552
+ 'meta_query' => false, // filter on activity meta. See WP_Meta_Query for format
553
+
554
+ // Searching
555
+ 'search_terms' => false, // specify terms to search on
556
+ 'update_meta_cache' => true,
557
+ );
558
 
559
+ $r = bp_parse_args( $args, $defaults, 'has_activities' );
560
+ extract( $r );
 
 
561
 
562
+ // Translate various values for 'display_comments'
563
+ // This allows disabling comments via ?display_comments=0
564
+ // or =none or =false. Final true is a strict type check. See #5029
565
+ if ( in_array( $display_comments, array( 0, '0', 'none', 'false' ), true ) ) {
566
+ $display_comments = false;
567
+ }
568
 
569
+ // Ignore pagination if an offset is passed
570
+ if ( ! empty( $offset ) ) {
571
+ $page = 0;
 
572
  }
573
 
574
+ if ( empty( $search_terms ) && ! empty( $_REQUEST['s'] ) )
575
+ $search_terms = $_REQUEST['s'];
 
576
 
577
+ // If you have passed a "scope" then this will override any filters you have passed.
578
+ if ( 'just-me' == $scope || 'friends' == $scope || 'groups' == $scope || 'favorites' == $scope || 'mentions' == $scope ) {
579
+ if ( 'just-me' == $scope )
580
+ $display_comments = 'stream';
 
 
 
 
 
 
 
 
 
 
 
 
581
 
582
+ // determine which user_id applies
583
+ if ( empty( $user_id ) )
584
+ $user_id = bp_displayed_user_id() ? bp_displayed_user_id() : bp_loggedin_user_id();
585
 
586
+ // are we displaying user specific activity?
587
+ if ( is_numeric( $user_id ) ) {
588
+ $show_hidden = ( $user_id == bp_loggedin_user_id() && $scope != 'friends' ) ? 1 : 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
589
 
590
+ switch ( $scope ) {
591
+ case 'friends':
592
+ if ( bp_is_active( 'friends' ) )
593
+ $friends = friends_get_friend_user_ids( $user_id );
594
+ if ( empty( $friends ) )
595
+ return false;
596
 
597
+ $user_id = implode( ',', (array) $friends );
598
+ break;
599
+ case 'groups':
600
+ if ( bp_is_active( 'groups' ) ) {
601
+ $groups = groups_get_user_groups( $user_id );
602
+ if ( empty( $groups['groups'] ) )
603
+ return false;
604
 
605
+ $object = $bp->groups->id;
606
+ $primary_id = implode( ',', (array) $groups['groups'] );
 
 
607
 
608
+ $user_id = 0;
609
+ }
610
+ break;
611
+ case 'favorites':
612
+ $favs = bp_activity_get_user_favorites( $user_id );
613
+ if ( empty( $favs ) )
614
+ return false;
615
+
616
+ $in = implode( ',', (array) $favs );
617
+ $display_comments = true;
618
+ $user_id = 0;
619
+ break;
620
+ case 'mentions':
621
+
622
+ // Are mentions disabled?
623
+ if ( ! bp_activity_do_mentions() ) {
624
+ return false;
625
+ }
626
 
627
+ // Start search at @ symbol and stop search at closing tag delimiter.
628
+ $search_terms = '@' . bp_activity_get_user_mentionname( $user_id ) . '<';
629
+ $display_comments = 'stream';
630
+ $user_id = 0;
631
+ break;
632
+ }
633
+ }
634
  }
635
 
636
+ // Do not exceed the maximum per page
637
+ if ( !empty( $max ) && ( (int) $per_page > (int) $max ) )
638
+ $per_page = $max;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
639
 
640
+ // Support for basic filters in earlier BP versions is disabled by default. To enable, put
641
+ // add_filter( 'bp_activity_enable_afilter_support', '__return_true' );
642
+ // into bp-custom.php or your theme's functions.php
643
+ if ( isset( $_GET['afilter'] ) && apply_filters( 'bp_activity_enable_afilter_support', false ) )
644
+ $filter = array( 'object' => $_GET['afilter'] );
645
+ else if ( ! empty( $user_id ) || ! empty( $object ) || ! empty( $action ) || ! empty( $primary_id ) || ! empty( $secondary_id ) || ! empty( $offset ) || ! empty( $since ) )
646
+ $filter = array( 'user_id' => $user_id, 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id, 'offset' => $offset, 'since' => $since );
647
+ else
648
+ $filter = false;
649
 
650
+ // If specific activity items have been requested, override the $hide_spam argument. This prevents backpat errors with AJAX.
651
+ if ( !empty( $include ) && ( 'ham_only' == $spam ) )
652
+ $spam = 'all';
653
 
654
+ $template_args = array(
655
+ 'page' => $page,
656
+ 'per_page' => $per_page,
657
+ 'page_arg' => $page_arg,
658
+ 'max' => $max,
659
+ 'sort' => $sort,
660
+ 'include' => $include,
661
+ 'exclude' => $exclude,
662
+ 'in' => $in,
663
+ 'filter' => $filter,
664
+ 'search_terms' => $search_terms,
665
+ 'meta_query' => $meta_query,
666
+ 'display_comments' => $display_comments,
667
+ 'show_hidden' => $show_hidden,
668
+ 'spam' => $spam,
669
+ 'update_meta_cache' => $update_meta_cache,
670
+ );
671
 
672
+ $activities_template = new BP_Activity_Template( $template_args );
673
+
674
+ return apply_filters( 'bp_has_activities', $activities_template->has_activities(), $activities_template, $template_args );
 
 
 
 
 
 
 
675
  }
676
 
677
  /**
678
  * Determine if there are still activities left in the loop.
679
  *
680
+ * @since BuddyPress (1.0)
681
  *
682
  * @global object $activities_template {@link BP_Activity_Template}
683
  * @uses BP_Activity_Template::user_activities() {@link BP_Activity_Template::user_activities()}
692
  /**
693
  * Get the current activity object in the loop.
694
  *
695
+ * @since BuddyPress (1.0)
696
  *
697
  * @global object $activities_template {@link BP_Activity_Template}
698
  * @uses BP_Activity_Template::the_activity() {@link BP_Activity_Template::the_activity()}
704
  return $activities_template->the_activity();
705
  }
706
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
707
  /**
708
  * Output the activity pagination count.
709
  *
710
+ * @since BuddyPress (1.0)
711
  *
712
  * @global object $activities_template {@link BP_Activity_Template}
713
  * @uses BP_Activity_Template::the_activity() {@link BP_Activity_Template::the_activity()}
719
  /**
720
  * Return the activity pagination count.
721
  *
722
+ * @since BuddyPress (1.2)
723
  *
724
  * @global object $activities_template {@link BP_Activity_Template}
725
  * @uses bp_core_number_format()
734
  $to_num = bp_core_number_format( ( $start_num + ( $activities_template->pag_num - 1 ) > $activities_template->total_activity_count ) ? $activities_template->total_activity_count : $start_num + ( $activities_template->pag_num - 1 ) );
735
  $total = bp_core_number_format( $activities_template->total_activity_count );
736
 
737
+ return sprintf( _n( 'Viewing item %1$s to %2$s (of %3$s item)', 'Viewing item %1$s to %2$s (of %3$s items)', $total, 'buddypress' ), $from_num, $to_num, $total );
 
 
 
 
 
 
738
  }
739
 
740
  /**
741
  * Output the activity pagination links.
742
  *
743
+ * @since BuddyPress (1.0)
744
  *
745
  * @uses bp_get_activity_pagination_links()
746
  */
751
  /**
752
  * Return the activity pagination links.
753
  *
754
+ * @since BuddyPress (1.0)
755
  *
756
  * @global object $activities_template {@link BP_Activity_Template}
757
  * @uses apply_filters() To call the 'bp_get_activity_pagination_links' hook.
761
  function bp_get_activity_pagination_links() {
762
  global $activities_template;
763
 
 
 
 
 
 
 
 
764
  return apply_filters( 'bp_get_activity_pagination_links', $activities_template->pag_links );
765
  }
766
 
767
  /**
768
  * Return true when there are more activity items to be shown than currently appear.
769
  *
770
+ * @since BuddyPress (1.5)
771
  *
772
  * @global object $activities_template {@link BP_Activity_Template}
773
  * @uses apply_filters() To call the 'bp_activity_has_more_items' hook.
777
  function bp_activity_has_more_items() {
778
  global $activities_template;
779
 
780
+ $remaining_pages = 0;
 
 
 
781
 
782
+ if ( ! empty( $activities_template->pag_page ) ) {
783
+ $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->pag_num * $activities_template->pag_page ) );
 
 
 
784
  }
785
 
786
+ $has_more_items = (int) $remaining_pages ? true : false;
787
+
 
 
 
 
 
788
  return apply_filters( 'bp_activity_has_more_items', $has_more_items );
789
  }
790
 
791
  /**
792
  * Output the activity count.
793
  *
794
+ * @since BuddyPress (1.2)
795
  *
796
  * @uses bp_get_activity_count()
797
  */
802
  /**
803
  * Return the activity count.
804
  *
805
+ * @since BuddyPress (1.2)
806
  *
807
  * @global object $activities_template {@link BP_Activity_Template}
808
  * @uses apply_filters() To call the 'bp_get_activity_count' hook.
812
  function bp_get_activity_count() {
813
  global $activities_template;
814
 
 
 
 
 
 
 
 
815
  return apply_filters( 'bp_get_activity_count', (int) $activities_template->activity_count );
816
  }
817
 
818
  /**
819
  * Output the number of activities per page.
820
  *
821
+ * @since BuddyPress (1.2)
822
  *
823
  * @uses bp_get_activity_per_page()
824
  */
829
  /**
830
  * Return the number of activities per page.
831
  *
832
+ * @since BuddyPress (1.2)
833
  *
834
  * @global object $activities_template {@link BP_Activity_Template}
835
  * @uses apply_filters() To call the 'bp_get_activity_per_page' hook.
839
  function bp_get_activity_per_page() {
840
  global $activities_template;
841
 
 
 
 
 
 
 
 
842
  return apply_filters( 'bp_get_activity_per_page', (int) $activities_template->pag_num );
843
  }
844
 
845
  /**
846
  * Output the activities title.
847
  *
848
+ * @since BuddyPress (1.0)
849
  *
850
  * @uses bp_get_activities_title()
851
  * @todo Deprecate.
857
  /**
858
  * Return the activities title.
859
  *
860
+ * @since BuddyPress (1.0)
861
  *
862
  * @global string $bp_activity_title
863
  * @uses apply_filters() To call the 'bp_get_activities_title' hook.
864
  * @todo Deprecate.
865
  *
866
+ * @return int The activities title.
867
  */
868
  function bp_get_activities_title() {
869
  global $bp_activity_title;
870
 
 
 
 
 
 
 
 
871
  return apply_filters( 'bp_get_activities_title', $bp_activity_title );
872
  }
873
 
874
  /**
875
  * {@internal Missing Description}
876
  *
877
+ * @since BuddyPress (1.0)
878
  *
879
  * @uses bp_get_activities_no_activity()
880
  * @todo Deprecate.
886
  /**
887
  * {@internal Missing Description}
888
  *
889
+ * @since BuddyPress (1.0)
890
  *
891
  * @global string $bp_activity_no_activity
892
+ * @uses apply_filters() To call the 'bp_get_activities_no_activity' hook
893
  * @todo Deprecate.
894
  *
895
  * @return string
897
  function bp_get_activities_no_activity() {
898
  global $bp_activity_no_activity;
899
 
 
 
 
 
 
 
 
900
  return apply_filters( 'bp_get_activities_no_activity', $bp_activity_no_activity );
901
  }
902
 
903
  /**
904
  * Output the activity ID.
905
  *
906
+ * @since BuddyPress (1.2)
907
  *
908
  * @uses bp_get_activity_id()
909
  */
914
  /**
915
  * Return the activity ID.
916
  *
917
+ * @since BuddyPress (1.2)
918
  *
919
  * @global object $activities_template {@link BP_Activity_Template}
920
  * @uses apply_filters() To call the 'bp_get_activity_id' hook.
923
  */
924
  function bp_get_activity_id() {
925
  global $activities_template;
 
 
 
 
 
 
 
 
926
  return apply_filters( 'bp_get_activity_id', $activities_template->activity->id );
927
  }
928
 
929
  /**
930
  * Output the activity item ID.
931
  *
932
+ * @since BuddyPress (1.2)
933
  *
934
  * @uses bp_get_activity_item_id()
935
  */
940
  /**
941
  * Return the activity item ID.
942
  *
943
+ * @since BuddyPress (1.2)
944
  *
945
  * @global object $activities_template {@link BP_Activity_Template}
946
  * @uses apply_filters() To call the 'bp_get_activity_item_id' hook.
949
  */
950
  function bp_get_activity_item_id() {
951
  global $activities_template;
 
 
 
 
 
 
 
 
952
  return apply_filters( 'bp_get_activity_item_id', $activities_template->activity->item_id );
953
  }
954
 
955
  /**
956
  * Output the activity secondary item ID.
957
  *
958
+ * @since BuddyPress (1.2)
959
  *
960
  * @uses bp_get_activity_secondary_item_id()
961
  */
966
  /**
967
  * Return the activity secondary item ID.
968
  *
969
+ * @since BuddyPress (1.2)
970
  *
971
  * @global object $activities_template {@link BP_Activity_Template}
972
  * @uses apply_filters() To call the 'bp_get_activity_secondary_item_id' hook.
975
  */
976
  function bp_get_activity_secondary_item_id() {
977
  global $activities_template;
 
 
 
 
 
 
 
 
978
  return apply_filters( 'bp_get_activity_secondary_item_id', $activities_template->activity->secondary_item_id );
979
  }
980
 
981
  /**
982
  * Output the date the activity was recorded.
983
  *
984
+ * @since BuddyPress (1.2)
985
  *
986
  * @uses bp_get_activity_date_recorded()
987
  */
992
  /**
993
  * Return the date the activity was recorded.
994
  *
995
+ * @since BuddyPress (1.2)
996
  *
997
  * @global object $activities_template {@link BP_Activity_Template}
998
  * @uses apply_filters() To call the 'bp_get_activity_date_recorded' hook.
1001
  */
1002
  function bp_get_activity_date_recorded() {
1003
  global $activities_template;
 
 
 
 
 
 
 
 
1004
  return apply_filters( 'bp_get_activity_date_recorded', $activities_template->activity->date_recorded );
1005
  }
1006
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1007
  /**
1008
  * Output the activity object name.
1009
  *
1010
+ * @since BuddyPress (1.2)
1011
  *
1012
  * @uses bp_get_activity_object_name()
1013
  */
1018
  /**
1019
  * Return the activity object name.
1020
  *
1021
+ * @since BuddyPress (1.2)
1022
  *
1023
  * @global object $activities_template {@link BP_Activity_Template}
1024
  * @uses apply_filters() To call the 'bp_get_activity_object_name' hook.
1027
  */
1028
  function bp_get_activity_object_name() {
1029
  global $activities_template;
 
 
 
 
 
 
 
 
1030
  return apply_filters( 'bp_get_activity_object_name', $activities_template->activity->component );
1031
  }
1032
 
1033
  /**
1034
  * Output the activity type.
1035
  *
1036
+ * @since BuddyPress (1.2)
1037
  *
1038
  * @uses bp_get_activity_type()
1039
  */
1044
  /**
1045
  * Return the activity type.
1046
  *
1047
+ * @since BuddyPress (1.2)
1048
  *
1049
  * @global object $activities_template {@link BP_Activity_Template}
1050
  * @uses apply_filters() To call the 'bp_get_activity_type' hook.
1053
  */
1054
  function bp_get_activity_type() {
1055
  global $activities_template;
 
 
 
 
 
 
 
 
1056
  return apply_filters( 'bp_get_activity_type', $activities_template->activity->type );
1057
  }
1058
 
1061
  *
1062
  * Just a wrapper for bp_activity_type().
1063
  *
1064
+ * @since BuddyPress (1.2)
1065
+ * @deprecated BuddyPress (1.5)
1066
  *
1067
  * @todo Properly deprecate in favor of bp_activity_type() and
1068
+ * remove redundant echo
1069
  *
1070
  * @uses bp_activity_type()
1071
  */
1076
  *
1077
  * Just a wrapper for bp_get_activity_type().
1078
  *
1079
+ * @since BuddyPress (1.2)
1080
+ * @deprecated BuddyPress (1.5)
1081
  *
1082
  * @todo Properly deprecate in favor of bp_get_activity_type().
1083
  *
1090
  /**
1091
  * Output the activity user ID.
1092
  *
1093
+ * @since BuddyPress (1.1)
1094
  *
1095
  * @uses bp_get_activity_user_id()
1096
  */
1101
  /**
1102
  * Return the activity user ID.
1103
  *
1104
+ * @since BuddyPress (1.1)
1105
  *
1106
  * @global object $activities_template {@link BP_Activity_Template}
1107
  * @uses apply_filters() To call the 'bp_get_activity_user_id' hook.
1110
  */
1111
  function bp_get_activity_user_id() {
1112
  global $activities_template;
 
 
 
 
 
 
 
 
1113
  return apply_filters( 'bp_get_activity_user_id', $activities_template->activity->user_id );
1114
  }
1115
 
1116
  /**
1117
  * Output the activity user link.
1118
  *
1119
+ * @since BuddyPress (1.2)
1120
  *
1121
  * @uses bp_get_activity_user_link()
1122
  */
1127
  /**
1128
  * Return the activity user link.
1129
  *
1130
+ * @since BuddyPress (1.2)
1131
  *
1132
  * @global object $activities_template {@link BP_Activity_Template}
1133
  * @uses bp_core_get_user_domain()
1138
  function bp_get_activity_user_link() {
1139
  global $activities_template;
1140
 
1141
+ if ( empty( $activities_template->activity->user_id ) )
1142
  $link = $activities_template->activity->primary_link;
1143
+ else
1144
  $link = bp_core_get_user_domain( $activities_template->activity->user_id, $activities_template->activity->user_nicename, $activities_template->activity->user_login );
 
1145
 
 
 
 
 
 
 
 
1146
  return apply_filters( 'bp_get_activity_user_link', $link );
1147
  }
1148
 
1149
  /**
1150
  * Output the avatar of the user that performed the action.
1151
  *
1152
+ * @since BuddyPress (1.1)
1153
  *
1154
  * @see bp_get_activity_avatar() for description of arguments.
1155
  * @uses bp_get_activity_avatar()
1156
  *
1157
+ * @param array $args See {@link bp_get_activity_avatar()} for description.
1158
  */
1159
  function bp_activity_avatar( $args = '' ) {
1160
  echo bp_get_activity_avatar( $args );
1162
  /**
1163
  * Return the avatar of the user that performed the action.
1164
  *
1165
+ * @since BuddyPress (1.1)
1166
  *
1167
  * @see bp_core_fetch_avatar() For a description of the arguments.
1168
  * @global object $activities_template {@link BP_Activity_Template}
1169
+ * @global object $bp BuddyPress global settings
1170
  * @uses bp_is_single_activity()
1171
  * @uses wp_parse_args()
1172
+ * @uses apply_filters() To call the 'bp_get_activity_avatar_object_' . $current_activity_item->component hook
1173
+ * @uses apply_filters() To call the 'bp_get_activity_avatar_item_id' hook
1174
  * @uses bp_core_fetch_avatar()
1175
+ * @uses apply_filters() To call the 'bp_get_activity_avatar' hook
1176
  *
1177
+ * @param array $args {
1178
  * Arguments are listed here with an explanation of their defaults.
1179
  * For more information about the arguments, see
1180
  * {@link bp_core_fetch_avatar()}.
1181
+ * @type string $alt Default: 'Profile picture of [user name]' if
1182
+ * activity user name is available, otherwise 'Profile picture'.
1183
+ * @type string $class Default: 'avatar'.
1184
+ * @type string|bool $email Default: Email of the activity's
1185
+ * associated user, if available. Otherwise false.
1186
+ * @type string $type Default: 'full' when viewing a single activity
1187
+ * permalink page, otherwise 'thumb'.
1188
+ * @type int|bool $user_id Default: ID of the activity's user.
1189
  * }
1190
  * @return string User avatar string.
1191
  */
1194
 
1195
  $bp = buddypress();
1196
 
1197
+ // On activity permalink pages, default to the full-size avatar
1198
  $type_default = bp_is_single_activity() ? 'full' : 'thumb';
1199
 
1200
  // Within the activity comment loop, the current activity should be set
1201
  // to current_comment. Otherwise, just use activity.
1202
  $current_activity_item = isset( $activities_template->activity->current_comment ) ? $activities_template->activity->current_comment : $activities_template->activity;
1203
 
1204
+ // Activity user display name
1205
  $dn_default = isset( $current_activity_item->display_name ) ? $current_activity_item->display_name : '';
1206
 
1207
+ // Prepend some descriptive text to alt
1208
  $alt_default = !empty( $dn_default ) ? sprintf( __( 'Profile picture of %s', 'buddypress' ), $dn_default ) : __( 'Profile picture', 'buddypress' );
1209
 
1210
  $defaults = array(
1220
 
1221
  if ( !isset( $height ) && !isset( $width ) ) {
1222
 
1223
+ // Backpat
1224
  if ( isset( $bp->avatar->full->height ) || isset( $bp->avatar->thumb->height ) ) {
1225
  $height = ( 'full' == $type ) ? $bp->avatar->full->height : $bp->avatar->thumb->height;
1226
  } else {
1227
  $height = 20;
1228
  }
1229
 
1230
+ // Backpat
1231
  if ( isset( $bp->avatar->full->width ) || isset( $bp->avatar->thumb->width ) ) {
1232
  $width = ( 'full' == $type ) ? $bp->avatar->full->width : $bp->avatar->thumb->width;
1233
  } else {
1235
  }
1236
  }
1237
 
1238
+ // Primary activity avatar is always a user, but can be modified via a filter
 
 
 
 
 
 
 
 
 
 
1239
  $object = apply_filters( 'bp_get_activity_avatar_object_' . $current_activity_item->component, 'user' );
1240
  $item_id = !empty( $user_id ) ? $user_id : $current_activity_item->user_id;
 
 
 
 
 
 
 
 
1241
  $item_id = apply_filters( 'bp_get_activity_avatar_item_id', $item_id );
1242
 
1243
+ // If this is a user object pass the users' email address for Gravatar so we don't have to refetch it.
1244
+ if ( 'user' == $object && empty( $user_id ) && empty( $email ) && isset( $current_activity_item->user_email ) )
1245
  $email = $current_activity_item->user_email;
 
1246
 
 
 
 
 
 
 
 
1247
  return apply_filters( 'bp_get_activity_avatar', bp_core_fetch_avatar( array(
1248
  'item_id' => $item_id,
1249
  'object' => $object,
1259
  /**
1260
  * Output the avatar of the object that action was performed on.
1261
  *
1262
+ * @since BuddyPress (1.2)
1263
  *
1264
  * @see bp_get_activity_secondary_avatar() for description of arguments.
1265
  * @uses bp_get_activity_secondary_avatar()
1266
  *
1267
+ * @param array $args See {@link bp_get_activity_secondary_avatar} for description.
1268
  */
1269
  function bp_activity_secondary_avatar( $args = '' ) {
1270
  echo bp_get_activity_secondary_avatar( $args );
1271
  }
1272
 
1273
  /**
1274
+ * Return the avatar of the object that action was performed on
1275
  *
1276
+ * @since BuddyPress (1.2)
1277
  *
1278
  * @see bp_core_fetch_avatar() for description of arguments.
1279
  * @global object $activities_template {@link BP_Activity_Template}
1284
  * @uses bp_core_fetch_avatar()
1285
  * @uses apply_filters() To call the 'bp_get_activity_secondary_avatar' hook.
1286
  *
1287
+ * @param array $args {
1288
  * For a complete description of arguments, see {@link bp_core_fetch_avatar()}.
1289
+ * @type string $alt Default value varies based on current activity
1290
+ * item component.
1291
+ * @type string $type Default: 'full' when viewing a single activity
1292
+ * permalink page, otherwise 'thumb'.
1293
+ * @type string $class Default: 'avatar'.
1294
+ * @type string|bool $email Default: email of the activity's user.
1295
+ * @type int|bool $user_id Default: ID of the activity's user.
1296
  * }
1297
+ * @return string The secondary avatar
1298
  */
1299
  function bp_get_activity_secondary_avatar( $args = '' ) {
1300
  global $activities_template;
1311
  ) );
1312
  extract( $r, EXTR_SKIP );
1313
 
1314
+ // Set item_id and object (default to user)
1315
  switch ( $activities_template->activity->component ) {
1316
  case 'groups' :
 
 
 
 
1317
  $object = 'group';
1318
  $item_id = $activities_template->activity->item_id;
1319
  $link = '';
1320
  $name = '';
1321
 
1322
+ // Only if groups is active
1323
  if ( bp_is_active( 'groups' ) ) {
1324
  $group = groups_get_group( array(
1325
  'group_id' => $item_id,
1372
  break;
1373
  }
1374
 
1375
+ // Allow object, item_id, and link to be filtered
 
 
 
 
 
 
 
 
 
 
1376
  $object = apply_filters( 'bp_get_activity_secondary_avatar_object_' . $activities_template->activity->component, $object );
 
 
 
 
 
 
 
 
1377
  $item_id = apply_filters( 'bp_get_activity_secondary_avatar_item_id', $item_id );
1378
 
1379
+ // If we have no item_id or object, there is no avatar to display
1380
  if ( empty( $item_id ) || empty( $object ) ) {
1381
  return false;
1382
  }
1383
 
1384
+ // Get the avatar
1385
  $avatar = bp_core_fetch_avatar( array(
1386
  'item_id' => $item_id,
1387
  'object' => $object,
1394
  ) );
1395
 
1396
  if ( !empty( $linked ) ) {
 
 
 
 
 
 
 
 
 
1397
  $link = apply_filters( 'bp_get_activity_secondary_avatar_link', $link, $activities_template->activity->component );
1398
 
 
 
 
 
 
 
 
 
 
1399
  return sprintf( '<a href="%s" class="%s">%s</a>',
1400
  $link,
1401
  $link_class,
1402
+ apply_filters( 'bp_get_activity_secondary_avatar', $avatar )
1403
  );
1404
  }
1405
 
1406
+ // else
1407
  return apply_filters( 'bp_get_activity_secondary_avatar', $avatar );
1408
  }
1409
 
1410
  /**
1411
+ * Output the activity action
1412
  *
1413
+ * @since BuddyPress (1.2)
1414
  *
1415
+ * @param array $args See bp_get_activity_action()
1416
  * @uses bp_get_activity_action()
1417
  */
1418
  function bp_activity_action( $args = array() ) {
1420
  }
1421
 
1422
  /**
1423
+ * Return the activity action
1424
  *
1425
+ * @since BuddyPress (1.2)
1426
  *
1427
  * @global object $activities_template {@link BP_Activity_Template}
1428
+ * @param array $args Only parameter is "no_timestamp". If true, timestamp is shown in output.
1429
+ * @uses apply_filters_ref_array() To call the 'bp_get_activity_action_pre_meta' hook
1430
  * @uses bp_insert_activity_meta()
1431
  * @uses apply_filters_ref_array() To call the 'bp_get_activity_action' hook.
1432
  *
1433
  * @param array $args {
1434
  * @type bool $no_timestamp Whether to exclude the timestamp.
1435
  * }
 
1436
  * @return string The activity action.
1437
  */
1438
  function bp_get_activity_action( $args = array() ) {
1439
  global $activities_template;
1440
 
1441
+ $defaults = array(
1442
  'no_timestamp' => false,
1443
+ );
1444
 
1445
+ $args = wp_parse_args( $args, $defaults );
1446
+ extract( $args, EXTR_SKIP );
1447
+
1448
+ $action = $activities_template->activity->action;
1449
+ $action = apply_filters_ref_array( 'bp_get_activity_action_pre_meta', array( $action, &$activities_template->activity, $args ) );
 
 
 
 
 
 
 
1450
 
1451
+ if ( ! empty( $action ) && ! $no_timestamp )
 
1452
  $action = bp_insert_activity_meta( $action );
 
1453
 
1454
+ return apply_filters_ref_array( 'bp_get_activity_action', array( $action, &$activities_template->activity, $args ) );
 
 
 
 
 
 
 
 
 
 
 
1455
  }
1456
 
1457
  /**
1458
+ * Output the activity content body
1459
  *
1460
+ * @since BuddyPress (1.2)
1461
  *
1462
  * @uses bp_get_activity_content_body()
1463
  */
1466
  }
1467
 
1468
  /**
1469
+ * Return the activity content body
1470
  *
1471
+ * @since BuddyPress (1.2)
1472
  *
1473
  * @global object $activities_template {@link BP_Activity_Template}
1474
  * @uses bp_insert_activity_meta()
1479
  function bp_get_activity_content_body() {
1480
  global $activities_template;
1481
 
1482
+ // Backwards compatibility if action is not being used
1483
+ if ( empty( $activities_template->activity->action ) && !empty( $activities_template->activity->content ) )
1484
  $activities_template->activity->content = bp_insert_activity_meta( $activities_template->activity->content );
 
1485
 
 
 
 
 
 
 
 
1486
  return apply_filters_ref_array( 'bp_get_activity_content_body', array( $activities_template->activity->content, &$activities_template->activity ) );
1487
  }
1488
 
1489
  /**
1490
  * Does the activity have content?
1491
  *
1492
+ * @since BuddyPress (1.2)
1493
  *
1494
  * @global object $activities_template {@link BP_Activity_Template}
1495
  *
1498
  function bp_activity_has_content() {
1499
  global $activities_template;
1500
 
1501
+ if ( !empty( $activities_template->activity->content ) )
1502
  return true;
 
1503
 
1504
  return false;
1505
  }
1507
  /**
1508
  * Output the activity content.
1509
  *
1510
+ * @since BuddyPress (1.0)
1511
+ * @deprecated BuddyPress (1.5)
1512
  *
1513
  * @todo properly deprecate this function.
1514
  *
1521
  /**
1522
  * Return the activity content.
1523
  *
1524
+ * @since BuddyPress (1.0)
1525
+ * @deprecated BuddyPress (1.5)
1526
  *
1527
  * @todo properly deprecate this function.
1528
  *
1533
  * @return string The activity content.
1534
  */
1535
  function bp_get_activity_content() {
 
1536
  /**
1537
  * If you want to filter activity update content, please use
1538
+ * the filter 'bp_get_activity_content_body'
1539
  *
1540
+ * This function is mainly for backwards comptibility.
1541
  */
1542
+
1543
  $content = bp_get_activity_action() . ' ' . bp_get_activity_content_body();
1544
  return apply_filters( 'bp_get_activity_content', $content );
1545
  }
1550
  * This metadata includes the time since the item was posted (which will appear
1551
  * as a link to the item's permalink).
1552
  *
1553
+ * @since BuddyPress (1.2)
1554
  *
1555
  * @global object $activities_template {@link BP_Activity_Template}
1556
  * @uses bp_core_time_since()
1564
  * @param string $content The activity content.
1565
  * @return string The activity content with the metadata string attached.
1566
  */
1567
+ function bp_insert_activity_meta( $content ) {
1568
  global $activities_template;
1569
 
1570
+ // Strip any legacy time since placeholders from BP 1.0-1.1
1571
+ $content = str_replace( '<span class="time-since">%s</span>', '', $content );
1572
 
1573
+ // Insert the time since.
1574
+ $time_since = apply_filters_ref_array( 'bp_activity_time_since', array( '<span class="time-since">' . bp_core_time_since( $activities_template->activity->date_recorded ) . '</span>', &$activities_template->activity ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1575
 
1576
+ // Insert the permalink
1577
+ if ( !bp_is_single_activity() )
1578
+ $content = apply_filters_ref_array( 'bp_activity_permalink', array( sprintf( '%1$s <a href="%2$s" class="view activity-time-since" title="%3$s">%4$s</a>', $content, bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ), esc_attr__( 'View Discussion', 'buddypress' ), $time_since ), &$activities_template->activity ) );
1579
+ else
1580
+ $content .= str_pad( $time_since, strlen( $time_since ) + 2, ' ', STR_PAD_BOTH );
 
 
 
 
 
 
 
 
 
 
1581
 
1582
+ return apply_filters( 'bp_insert_activity_meta', $content );
 
 
 
 
 
 
 
1583
  }
1584
 
1585
  /**
1586
  * Determine if the current user can delete an activity item.
1587
  *
1588
+ * @since BuddyPress (1.2)
1589
  *
1590
  * @global object $activities_template {@link BP_Activity_Template}
1591
+ * @uses apply_filters() To call the 'bp_activity_user_can_delete' hook
1592
  *
1593
+ * @param object $activity Optional. Falls back on the current item in the loop.
1594
  * @return bool True if can delete, false otherwise.
1595
  */
1596
  function bp_activity_user_can_delete( $activity = false ) {
1597
  global $activities_template;
1598
 
1599
+ if ( !$activity )
 
1600
  $activity = $activities_template->activity;
 
1601
 
1602
+ if ( isset( $activity->current_comment ) )
 
1603
  $activity = $activity->current_comment;
 
1604
 
 
1605
  $can_delete = false;
1606
 
1607
+ if ( bp_current_user_can( 'bp_moderate' ) )
1608
+ $can_delete = true;
 
 
 
 
 
1609
 
1610
+ if ( is_user_logged_in() && $activity->user_id == bp_loggedin_user_id() )
1611
+ $can_delete = true;
 
 
 
 
1612
 
1613
+ if ( bp_is_item_admin() && bp_is_single_item() )
1614
+ $can_delete = true;
 
 
 
1615
 
1616
+ return apply_filters( 'bp_activity_user_can_delete', $can_delete, $activity );
 
 
 
 
 
 
 
 
1617
  }
1618
 
1619
  /**
1620
  * Output the activity parent content.
1621
  *
1622
+ * @since BuddyPress (1.2)
1623
  *
1624
  * @see bp_get_activity_parent_content() for a description of arguments.
1625
  * @uses bp_get_activity_parent_content()
1626
  *
1627
+ * @param array $args See {@link bp_get_activity_parent_content} for description.
1628
  */
1629
  function bp_activity_parent_content( $args = '' ) {
1630
  echo bp_get_activity_parent_content($args);
1633
  /**
1634
  * Return the activity content.
1635
  *
1636
+ * @since BuddyPress (1.2)
1637
  *
1638
  * @global object $activities_template {@link BP_Activity_Template}
1639
+ * @uses wp_parse_args()
1640
  * @uses apply_filters() To call the 'bp_get_activity_parent_content' hook.
1641
  *
1642
+ * @param array $args {
1643
+ * Array of optional arguments.
1644
+ * @deprecated bool $hide_user No longer used.
1645
+ * }
1646
+ * @return mixed False on failure, otherwise the activity parent content
1647
  */
1648
  function bp_get_activity_parent_content( $args = '' ) {
1649
  global $activities_template;
1650
 
1651
+ $defaults = array(
1652
+ 'hide_user' => false
1653
+ );
 
1654
 
1655
+ $r = wp_parse_args( $args, $defaults );
1656
+ extract( $r, EXTR_SKIP );
1657
 
1658
+ // Get the ID of the parent activity content
1659
+ if ( !$parent_id = $activities_template->activity->item_id )
1660
  return false;
 
1661
 
1662
+ // Bail if no parent content
1663
+ if ( empty( $activities_template->activity_parents[$parent_id] ) )
1664
  return false;
 
1665
 
1666
+ // Bail if no action
1667
+ if ( empty( $activities_template->activity_parents[$parent_id]->action ) )
1668
+ return false;
1669
 
1670
+ // Content always includes action
1671
+ $content = $activities_template->activity_parents[$parent_id]->action;
 
 
1672
 
1673
+ // Maybe append activity content, if it exists
1674
+ if ( ! empty( $activities_template->activity_parents[$parent_id]->content ) )
1675
+ $content .= ' ' . $activities_template->activity_parents[$parent_id]->content;
1676
+
1677
+ // Remove the time since content for backwards compatibility
1678
  $content = str_replace( '<span class="time-since">%s</span>', '', $content );
1679
 
1680
+ // Remove images
1681
  $content = preg_replace( '/<img[^>]*>/Ui', '', $content );
1682
 
 
 
 
 
 
 
 
1683
  return apply_filters( 'bp_get_activity_parent_content', $content );
1684
  }
1685
 
1686
  /**
1687
  * Output the parent activity's user ID.
1688
  *
1689
+ * @since BuddyPress (1.7)
1690
  */
1691
  function bp_activity_parent_user_id() {
1692
  echo bp_get_activity_parent_user_id();
1695
  /**
1696
  * Return the parent activity's user ID.
1697
  *
1698
+ * @since BuddyPress (1.7)
1699
  *
1700
  * @global BP_Activity_Template $activities_template
1701
  *
1702
  * @return bool|int False if parent activity can't be found, otherwise
1703
+ * the parent activity's user ID.
1704
  */
1705
  function bp_get_activity_parent_user_id() {
1706
  global $activities_template;
1707
 
1708
+ // Bail if no activity on no item ID
1709
+ if ( empty( $activities_template->activity ) || empty( $activities_template->activity->item_id ) )
1710
  return false;
 
1711
 
1712
+ // Get the ID of the parent activity content
1713
+ if ( !$parent_id = $activities_template->activity->item_id )
1714
+ return false;
1715
 
1716
+ // Bail if no parent item
1717
+ if ( empty( $activities_template->activity_parents[$parent_id] ) )
1718
  return false;
 
1719
 
1720
+ // Bail if no parent user ID
1721
+ if ( empty( $activities_template->activity_parents[$parent_id]->user_id ) )
1722
  return false;
 
1723
 
1724
+ $retval = $activities_template->activity_parents[$parent_id]->user_id;
1725
 
 
 
 
 
 
 
 
1726
  return (int) apply_filters( 'bp_get_activity_parent_user_id', $retval );
1727
  }
1728
 
1729
  /**
1730
  * Output whether or not the current activity is in a current user's favorites.
1731
  *
1732
+ * @since BuddyPress (1.2)
1733
  *
1734
  * @uses bp_get_activity_is_favorite()
1735
  */
1740
  /**
1741
  * Return whether the current activity is in a current user's favorites.
1742
  *
1743
+ * @since BuddyPress (1.2)
1744
  *
1745
  * @global object $activities_template {@link BP_Activity_Template}
1746
  * @uses apply_filters() To call the 'bp_get_activity_is_favorite' hook.
1750
  function bp_get_activity_is_favorite() {
1751
  global $activities_template;
1752
 
1753
+ return apply_filters( 'bp_get_activity_is_favorite', in_array( $activities_template->activity->id, (array) $activities_template->my_favs ) );
 
 
 
 
 
 
 
1754
  }
1755
 
1756
  /**
1757
  * Output the comment markup for an activity item.
1758
  *
1759
+ * @since BuddyPress (1.2)
1760
  *
1761
  * @todo deprecate $args param
1762
  *
1763
+ * @param string $args Unused. Appears to be left over from an earlier implementation.
1764
  */
1765
  function bp_activity_comments( $args = '' ) {
1766
  echo bp_activity_get_comments( $args );
1769
  /**
1770
  * Get the comment markup for an activity item.
1771
  *
1772
+ * @since BuddyPress (1.2)
1773
  *
1774
  * @todo deprecate $args param
1775
+ *
1776
  * @todo Given that checks for children already happen in bp_activity_recurse_comments(),
1777
+ * this function can probably be streamlined or removed.
1778
+ *
1779
+ * @param string $args Unused. Appears to be left over from an earlier implementation.
1780
  *
1781
  * @global object $activities_template {@link BP_Activity_Template}
1782
  * @uses bp_activity_recurse_comments()
 
 
 
1783
  */
1784
  function bp_activity_get_comments( $args = '' ) {
1785
  global $activities_template;
1786
 
1787
+ if ( !isset( $activities_template->activity->children ) || !$activities_template->activity->children )
1788
  return false;
 
1789
 
1790
  bp_activity_recurse_comments( $activities_template->activity );
1791
  }
1792
 
1793
  /**
1794
+ * Loops through a level of activity comments and loads the template for each
1795
  *
1796
  * Note: The recursion itself used to happen entirely in this function. Now it is
1797
  * split between here and the comment.php template.
1798
  *
1799
+ * @since BuddyPress (1.2)
1800
+ *
1801
+ * @param object $comment The activity object currently being recursed
1802
  *
1803
  * @global object $activities_template {@link BP_Activity_Template}
1804
  * @uses locate_template()
 
 
 
1805
  */
1806
  function bp_activity_recurse_comments( $comment ) {
1807
  global $activities_template;
1808
 
1809
+ if ( empty( $comment ) )
1810
  return false;
 
1811
 
1812
+ if ( empty( $comment->children ) )
1813
  return false;
 
1814
 
1815
+ echo apply_filters( 'bp_activity_recurse_comments_start_ul', '<ul>');
 
 
 
 
 
 
 
1816
  foreach ( (array) $comment->children as $comment_child ) {
1817
+ // Put the comment into the global so it's available to filters
 
1818
  $activities_template->activity->current_comment = $comment_child;
1819
 
1820
  $template = bp_locate_template( 'activity/comment.php', false, false );
1831
 
1832
  unset( $activities_template->activity->current_comment );
1833
  }
1834
+ echo apply_filters( 'bp_activity_recurse_comments_end_ul', '</ul>');
 
 
 
 
 
 
 
 
1835
  }
1836
 
1837
  /**
1838
  * Utility function that returns the comment currently being recursed.
1839
  *
1840
+ * @since BuddyPress (1.5)
1841
  *
1842
  * @global object $activities_template {@link BP_Activity_Template}
1843
  * @uses apply_filters() To call the 'bp_activity_current_comment' hook.
1844
  *
1845
  * @return object|bool $current_comment The activity comment currently being
1846
+ * displayed. False on failure.
1847
  */
1848
  function bp_activity_current_comment() {
1849
  global $activities_template;
1850
 
1851
+ $current_comment = !empty( $activities_template->activity->current_comment ) ? $activities_template->activity->current_comment : false;
 
 
1852
 
 
 
 
 
 
 
 
1853
  return apply_filters( 'bp_activity_current_comment', $current_comment );
1854
  }
1855
 
1857
  /**
1858
  * Output the ID of the activity comment currently being displayed.
1859
  *
1860
+ * @since BuddyPress (1.5)
1861
  *
1862
  * @uses bp_get_activity_comment_id()
1863
  */
1868
  /**
1869
  * Return the ID of the activity comment currently being displayed.
1870
  *
1871
+ * @since BuddyPress (1.5)
1872
  *
1873
  * @global object $activities_template {@link BP_Activity_Template}
1874
  * @uses apply_filters() To call the 'bp_activity_comment_id' hook.
1875
  *
1876
+ * @return int|bool $comment_id The ID of the activity comment
1877
+ * currently being displayed, false if none is found.
1878
  */
1879
  function bp_get_activity_comment_id() {
1880
  global $activities_template;
1881
 
1882
  $comment_id = isset( $activities_template->activity->current_comment->id ) ? $activities_template->activity->current_comment->id : false;
1883
 
 
 
 
 
 
 
 
1884
  return apply_filters( 'bp_activity_comment_id', $comment_id );
1885
  }
1886
 
1887
  /**
1888
  * Output the ID of the author of the activity comment currently being displayed.
1889
  *
1890
+ * @since BuddyPress (1.5)
1891
  *
1892
  * @uses bp_get_activity_comment_user_id()
1893
  */
1898
  /**
1899
  * Return the ID of the author of the activity comment currently being displayed.
1900
  *
1901
+ * @since BuddyPress (1.5)
1902
  *
1903
  * @global object $activities_template {@link BP_Activity_Template}
1904
  * @uses apply_filters() To call the 'bp_activity_comment_user_id' hook.
1905
  *
1906
  * @return int|bool $user_id The user_id of the author of the displayed
1907
+ * activity comment. False on failure.
1908
  */
1909
  function bp_get_activity_comment_user_id() {
1910
  global $activities_template;
1911
 
1912
  $user_id = isset( $activities_template->activity->current_comment->user_id ) ? $activities_template->activity->current_comment->user_id : false;
1913
 
 
 
 
 
 
 
 
1914
  return apply_filters( 'bp_activity_comment_user_id', $user_id );
1915
  }
1916
 
1917
  /**
1918
  * Output the author link for the activity comment currently being displayed.
1919
  *
1920
+ * @since BuddyPress (1.5)
1921
  *
1922
  * @uses bp_get_activity_comment_user_link()
1923
  */
1928
  /**
1929
  * Return the author link for the activity comment currently being displayed.
1930
  *
1931
+ * @since BuddyPress (1.5)
1932
  *
1933
  * @uses bp_core_get_user_domain()
1934
  * @uses bp_get_activity_comment_user_id()
1935
+ * @uses apply_filters() To call the 'bp_activity_comment_user_link' hook
1936
  *
1937
  * @return string $user_link The URL of the activity comment author's profile.
1938
  */
1939
  function bp_get_activity_comment_user_link() {
1940
  $user_link = bp_core_get_user_domain( bp_get_activity_comment_user_id() );
1941
 
 
 
 
 
 
 
 
1942
  return apply_filters( 'bp_activity_comment_user_link', $user_link );
1943
  }
1944
 
1945
  /**
1946
  * Output the author name for the activity comment currently being displayed.
1947
  *
1948
+ * @since BuddyPress (1.5)
1949
  *
1950
  * @uses bp_get_activity_comment_name()
1951
  */
1959
  * The use of the 'bp_acomment_name' filter is deprecated. Please use
1960
  * 'bp_activity_comment_name'.
1961
  *
1962
+ * @since BuddyPress (1.5)
1963
  *
1964
  * @global object $activities_template {@link BP_Activity_Template}
1965
  * @uses apply_filters() To call the 'bp_acomment_name' hook.
1970
  function bp_get_activity_comment_name() {
1971
  global $activities_template;
1972
 
1973
+ if ( isset( $activities_template->activity->current_comment->user_fullname ) )
1974
+ $name = apply_filters( 'bp_acomment_name', $activities_template->activity->current_comment->user_fullname, $activities_template->activity->current_comment ); // backward compatibility
1975
+ else
 
1976
  $name = $activities_template->activity->current_comment->display_name;
 
1977
 
 
 
 
 
 
 
 
1978
  return apply_filters( 'bp_activity_comment_name', $name );
1979
  }
1980
 
1981
  /**
1982
+ * Output the date_recorded of the activity comment currently being displayed.
1983
  *
1984
+ * @since BuddyPress (1.5)
1985
  *
1986
  * @uses bp_get_activity_comment_date_recorded()
1987
  */
1989
  echo bp_get_activity_comment_date_recorded();
1990
  }
1991
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1992
  /**
1993
  * Return the date_recorded for the activity comment currently being displayed.
1994
  *
1995
+ * @since BuddyPress (1.5)
1996
  *
1997
  * @global object $activities_template {@link BP_Activity_Template}
1998
  * @uses bp_core_time_since()
1999
+ * @uses apply_filters() To call the 'bp_activity_comment_date_recorded' hook
2000
  *
2001
  * @return string|bool $date_recorded Time since the activity was recorded,
2002
+ * in the form "%s ago". False on failure.
2003
  */
2004
+ function bp_get_activity_comment_date_recorded() {
2005
  global $activities_template;
2006
 
2007
+ if ( empty( $activities_template->activity->current_comment->date_recorded ) )
2008
+ return false;
2009
+
2010
+ $date_recorded = bp_core_time_since( $activities_template->activity->current_comment->date_recorded );
2011
+
2012
+ return apply_filters( 'bp_activity_comment_date_recorded', $date_recorded );
 
 
2013
  }
2014
 
2015
  /**
2016
  * Output the 'delete' URL for the activity comment currently being displayed.
2017
  *
2018
+ * @since BuddyPress (1.5)
2019
  *
2020
  * @uses bp_get_activity_comment_delete_link()
2021
  */
2024
  }
2025
 
2026
  /**
2027
+ * Gets the 'delete' URL for the activity comment currently being displayed
2028
  *
2029
+ * @since BuddyPress (1.5)
2030
  *
2031
  * @uses wp_nonce_url()
2032
  * @uses bp_get_root_domain()
2035
  * @uses apply_filters() To call the 'bp_activity_comment_delete_link' hook.
2036
  *
2037
  * @return string $link The nonced URL for deleting the current
2038
+ * activity comment.
2039
  */
2040
  function bp_get_activity_comment_delete_link() {
2041
  $link = wp_nonce_url( bp_get_root_domain() . '/' . bp_get_activity_slug() . '/delete/' . bp_get_activity_comment_id() . '?cid=' . bp_get_activity_comment_id(), 'bp_activity_delete_link' );
2042
 
 
 
 
 
 
 
 
2043
  return apply_filters( 'bp_activity_comment_delete_link', $link );
2044
  }
2045
 
2046
  /**
2047
  * Output the content of the activity comment currently being displayed.
2048
  *
2049
+ * @since BuddyPress (1.5)
2050
  *
2051
  * @uses bp_get_activity_comment_content()
2052
  */
2062
  * 'bp_activity_comment_content' to modify the content of activity
2063
  * comments only.
2064
  *
2065
+ * @since BuddyPress (1.5)
2066
  *
2067
  * @global object $activities_template {@link BP_Activity_Template}
2068
  * @uses apply_filters() To call the 'bp_get_activity_content' hook.
2073
  function bp_get_activity_comment_content() {
2074
  global $activities_template;
2075
 
 
2076
  $content = apply_filters( 'bp_get_activity_content', $activities_template->activity->current_comment->content );
2077
 
 
 
 
 
 
 
 
2078
  return apply_filters( 'bp_activity_comment_content', $content );
2079
  }
2080
 
2081
  /**
2082
  * Output the activity comment count.
2083
  *
2084
+ * @since BuddyPress (1.2)
2085
  *
2086
  * @uses bp_activity_get_comment_count()
2087
  */
2090
  }
2091
 
2092
  /**
2093
+ * Return the content of the activity comment currently being displayed.
2094
+ *
2095
+ * The content is run through two filters. 'bp_get_activity_content'
2096
+ * will apply all filters applied to activity items in general. Use
2097
+ * 'bp_activity_comment_content' to modify the content of activity
2098
+ * comments only.
2099
  *
2100
+ * @since BuddyPress (1.2)
2101
  *
2102
  * @global object $activities_template {@link BP_Activity_Template}
2103
  * @uses bp_activity_recurse_comment_count()
2104
  * @uses apply_filters() To call the 'bp_activity_get_comment_count' hook.
2105
+ * @todo deprecate $args
2106
  *
2107
+ * @param array $args Deprecated.
2108
  * @return int $count The activity comment count.
2109
  */
2110
+ function bp_activity_get_comment_count( $args = '' ) {
2111
  global $activities_template;
2112
 
2113
+ if ( !isset( $activities_template->activity->children ) || !$activities_template->activity->children )
2114
+ return 0;
 
 
2115
 
2116
+ $count = bp_activity_recurse_comment_count( $activities_template->activity );
 
 
 
2117
 
 
 
 
 
 
 
 
2118
  return apply_filters( 'bp_activity_get_comment_count', (int) $count );
2119
  }
2120
 
2121
  /**
2122
+ * Return the content of the activity comment currently being displayed.
2123
  *
2124
+ * The content is run through two filters. 'bp_get_activity_content'
2125
+ * will apply all filters applied to activity items in general.
2126
+ * Use bp_activity_comment_content to modify the content of
2127
+ * activity comments only.
2128
  *
2129
+ * @since BuddyPress (1.2)
2130
  *
2131
  * @uses bp_activity_recurse_comment_count()
2132
+ * @uses apply_filters() To call the 'bp_activity_get_comment_count' hook
2133
+ * @todo investigate why bp_activity_recurse_comment_count() is used while being declared
2134
  *
2135
  * @param object $comment Activity comment object.
2136
+ * @param int $count The current iteration count.
2137
  * @return int $count The activity comment count.
2138
  */
2139
  function bp_activity_recurse_comment_count( $comment, $count = 0 ) {
2140
 
2141
+ if ( empty( $comment->children ) )
2142
+ return $count;
2143
 
2144
+ foreach ( (array) $comment->children as $comment ) {
2145
+ $count++;
2146
+ $count = bp_activity_recurse_comment_count( $comment, $count );
 
 
 
2147
  }
2148
 
2149
+ return $count;
 
 
 
 
 
 
 
 
 
2150
  }
2151
 
2152
  /**
2153
  * Output the depth of the current activity comment.
2154
  *
2155
+ * @since BuddyPress (2.0.0)
2156
  */
2157
  function bp_activity_comment_depth() {
2158
  echo bp_activity_get_comment_depth();
2160
  /**
2161
  * Return the current activity comment depth.
2162
  *
2163
+ * @since BuddyPress (2.0.0)
2164
  *
2165
+ * @return int
2166
  */
2167
  function bp_activity_get_comment_depth() {
2168
  global $activities_template;
 
 
 
 
 
 
 
 
2169
  return apply_filters( 'bp_activity_get_comment_depth', $activities_template->activity->current_comment->depth );
2170
  }
2171
 
2172
  /**
2173
  * Output the activity comment link.
2174
  *
2175
+ * @since BuddyPress (1.2)
2176
  *
2177
  * @uses bp_get_activity_comment_link()
2178
  */
2183
  /**
2184
  * Return the activity comment link.
2185
  *
2186
+ * @since BuddyPress (1.2)
2187
  *
2188
  * @global object $activities_template {@link BP_Activity_Template}
2189
  * @uses apply_filters() To call the 'bp_get_activity_comment_link' hook.
2192
  */
2193
  function bp_get_activity_comment_link() {
2194
  global $activities_template;
 
 
 
 
 
 
 
 
2195
  return apply_filters( 'bp_get_activity_comment_link', '?ac=' . $activities_template->activity->id . '/#ac-form-' . $activities_template->activity->id );
2196
  }
2197
 
2198
  /**
2199
+ * Output the activity comment form no javascript display CSS.
2200
  *
2201
+ * @since BuddyPress (1.2)
2202
  *
2203
  * @uses bp_get_activity_comment_form_nojs_display()
2204
  */
2207
  }
2208
 
2209
  /**
2210
+ * Return the activity comment form no javascript display CSS.
2211
  *
2212
+ * @since BuddyPress (1.2)
2213
  *
2214
  * @global object $activities_template {@link BP_Activity_Template}
2215
  *
2216
+ * @return string|bool The activity comment form no javascript
2217
+ * display CSS. False on failure
2218
  */
2219
  function bp_get_activity_comment_form_nojs_display() {
2220
  global $activities_template;
2221
+ if ( isset( $_GET['ac'] ) && $_GET['ac'] == $activities_template->activity->id . '/' )
 
2222
  return 'style="display: block"';
 
2223
 
2224
  return false;
2225
  }
2227
  /**
2228
  * Output the activity comment form action.
2229
  *
2230
+ * @since BuddyPress (1.2)
2231
  *
2232
  * @uses bp_get_activity_comment_form_action()
2233
  */
2238
  /**
2239
  * Return the activity comment form action.
2240
  *
2241
+ * @since BuddyPress (1.2)
2242
  *
2243
  * @uses home_url()
2244
  * @uses bp_get_activity_root_slug()
2247
  * @return string The activity comment form action.
2248
  */
2249
  function bp_get_activity_comment_form_action() {
 
 
 
 
 
 
 
 
2250
  return apply_filters( 'bp_get_activity_comment_form_action', home_url( bp_get_activity_root_slug() . '/reply/' ) );
2251
  }
2252
 
2253
  /**
2254
  * Output the activity permalink ID.
2255
  *
2256
+ * @since BuddyPress (1.2)
2257
  *
2258
  * @uses bp_get_activity_permalink_id()
2259
  */
2264
  /**
2265
  * Return the activity permalink ID.
2266
  *
2267
+ * @since BuddyPress (1.2)
2268
  *
2269
  * @uses apply_filters() To call the 'bp_get_activity_permalink_id' hook.
2270
  *
2271
  * @return string The activity permalink ID.
2272
  */
2273
  function bp_get_activity_permalink_id() {
 
 
 
 
 
 
 
 
2274
  return apply_filters( 'bp_get_activity_permalink_id', bp_current_action() );
2275
  }
2276
 
2277
  /**
2278
  * Output the activity thread permalink.
2279
  *
2280
+ * @since BuddyPress (1.2)
2281
  *
2282
  * @uses bp_get_activity_permalink_id()
2283
  */
2288
  /**
2289
  * Return the activity thread permalink.
2290
  *
2291
+ * @since BuddyPress (1.2)
2292
  *
2293
  * @uses bp_activity_get_permalink()
2294
  * @uses apply_filters() To call the 'bp_get_activity_thread_permalink' hook.
2300
 
2301
  $link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity );
2302
 
2303
+ return apply_filters( 'bp_get_activity_thread_permalink', $link );
 
 
 
 
 
 
 
2304
  }
2305
 
2306
  /**
2307
  * Output the activity comment permalink.
2308
  *
2309
+ * @since BuddyPress (1.8)
2310
  *
2311
  * @uses bp_get_activity_permalink_id()
2312
  */
2316
  /**
2317
  * Return the activity comment permalink.
2318
  *
2319
+ * @since BuddyPress (1.8)
2320
  *
2321
  * @uses bp_activity_get_permalink()
2322
  * @uses apply_filters() To call the 'bp_get_activity_comment_permalink' hook.
2326
  function bp_get_activity_comment_permalink() {
2327
  global $activities_template;
2328
 
2329
+ $link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ) . '#acomment-' . $activities_template->activity->current_comment->id;
 
 
 
2330
 
2331
+ return apply_filters( 'bp_get_activity_comment_permalink', $link );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2332
  }
2333
 
2334
  /**
2335
  * Output the activity favorite link.
2336
  *
2337
+ * @since BuddyPress (1.2)
2338
  *
2339
  * @uses bp_get_activity_favorite_link()
2340
  */
2345
  /**
2346
  * Return the activity favorite link.
2347
  *
2348
+ * @since BuddyPress (1.2)
2349
  *
2350
  * @global object $activities_template {@link BP_Activity_Template}
2351
  * @uses wp_nonce_url()
2352
  * @uses home_url()
2353
  * @uses bp_get_activity_root_slug()
2354
+ * @uses apply_filters() To call the 'bp_get_activity_favorite_link' hook
2355
  *
2356
  * @return string The activity favorite link.
2357
  */
2358
  function bp_get_activity_favorite_link() {
2359
  global $activities_template;
 
 
 
 
 
 
 
 
2360
  return apply_filters( 'bp_get_activity_favorite_link', wp_nonce_url( home_url( bp_get_activity_root_slug() . '/favorite/' . $activities_template->activity->id . '/' ), 'mark_favorite' ) );
2361
  }
2362
 
2363
  /**
2364
  * Output the activity unfavorite link.
2365
  *
2366
+ * @since BuddyPress (1.2)
2367
  *
2368
  * @uses bp_get_activity_unfavorite_link()
2369
  */
2374
  /**
2375
  * Return the activity unfavorite link.
2376
  *
2377
+ * @since BuddyPress (1.2)
2378
  *
2379
  * @global object $activities_template {@link BP_Activity_Template}
2380
  * @uses wp_nonce_url()
2386
  */
2387
  function bp_get_activity_unfavorite_link() {
2388
  global $activities_template;
 
 
 
 
 
 
 
 
2389
  return apply_filters( 'bp_get_activity_unfavorite_link', wp_nonce_url( home_url( bp_get_activity_root_slug() . '/unfavorite/' . $activities_template->activity->id . '/' ), 'unmark_favorite' ) );
2390
  }
2391
 
2392
  /**
2393
  * Output the activity CSS class.
2394
  *
2395
+ * @since BuddyPress (1.0)
2396
  *
2397
  * @uses bp_get_activity_css_class()
2398
  */
2403
  /**
2404
  * Return the current activity item's CSS class.
2405
  *
2406
+ * @since BuddyPress (1.0)
2407
  *
2408
  * @global object $activities_template {@link BP_Activity_Template}
2409
  * @uses apply_filters() To call the 'bp_activity_mini_activity_types' hook.
2416
  function bp_get_activity_css_class() {
2417
  global $activities_template;
2418
 
 
 
 
 
 
 
 
2419
  $mini_activity_actions = apply_filters( 'bp_activity_mini_activity_types', array(
2420
  'friendship_accepted',
2421
  'friendship_created',
2427
 
2428
  $class = ' activity-item';
2429
 
2430
+ if ( in_array( $activities_template->activity->type, (array) $mini_activity_actions ) || empty( $activities_template->activity->content ) )
2431
  $class .= ' mini';
 
2432
 
2433
+ if ( bp_activity_get_comment_count() && bp_activity_can_comment() )
2434
  $class .= ' has-comments';
 
2435
 
 
 
 
 
 
 
 
2436
  return apply_filters( 'bp_get_activity_css_class', $activities_template->activity->component . ' ' . $activities_template->activity->type . $class );
2437
  }
2438
 
2439
  /**
2440
  * Output the activity delete link.
2441
  *
2442
+ * @since BuddyPress (1.1)
2443
  *
2444
  * @uses bp_get_activity_delete_link()
2445
  */
2450
  /**
2451
  * Return the activity delete link.
2452
  *
2453
+ * @since BuddyPress (1.1)
2454
  *
2455
  * @global object $activities_template {@link BP_Activity_Template}
2456
  * @uses bp_get_root_domain()
2457
  * @uses bp_get_activity_root_slug()
2458
  * @uses bp_is_activity_component()
2459
  * @uses bp_current_action()
2460
+ * @uses add_query_arg()
2461
  * @uses wp_get_referer()
2462
  * @uses wp_nonce_url()
2463
  * @uses apply_filters() To call the 'bp_get_activity_delete_link' hook.
2464
  *
2465
  * @return string $link Activity delete link. Contains $redirect_to arg
2466
+ * if on single activity page.
2467
  */
2468
  function bp_get_activity_delete_link() {
2469
+ global $activities_template;
2470
 
2471
+ $url = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/delete/' . $activities_template->activity->id;
2472
  $class = 'delete-activity';
2473
 
2474
+ // Determine if we're on a single activity page, and customize accordingly
2475
  if ( bp_is_activity_component() && is_numeric( bp_current_action() ) ) {
2476
+ $url = add_query_arg( array( 'redirect_to' => wp_get_referer() ), $url );
2477
  $class = 'delete-activity-single';
2478
  }
2479
 
2480
+ $link = '<a href="' . wp_nonce_url( $url, 'bp_activity_delete_link' ) . '" class="button item-button bp-secondary-action ' . $class . ' confirm" rel="nofollow">' . __( 'Delete', 'buddypress' ) . '</a>';
 
 
 
 
 
 
 
 
2481
  return apply_filters( 'bp_get_activity_delete_link', $link );
2482
  }
2483
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2484
  /**
2485
  * Output the activity latest update link.
2486
  *
2487
+ * @since BuddyPress (1.2)
2488
  *
2489
  * @see bp_get_activity_latest_update() for description of parameters.
2490
  * @uses bp_get_activity_latest_update()
2498
  /**
2499
  * Return the activity latest update link.
2500
  *
2501
+ * @since BuddyPress (1.2)
2502
  *
2503
  * @uses bp_is_user_inactive()
2504
  * @uses bp_core_is_user_deleted()
2505
  * @uses bp_get_user_meta()
2506
+ * @uses apply_filters() To call the 'bp_get_activity_latest_update_excerpt' hook
2507
  * @uses bp_create_excerpt()
2508
  * @uses bp_get_root_domain()
2509
  * @uses bp_get_activity_root_slug()
2510
+ * @uses apply_filters() To call the 'bp_get_activity_latest_update' hook
2511
  *
2512
  * @param int $user_id If empty, will fall back on displayed user.
2513
  * @return string|bool $latest_update The activity latest update link.
2514
+ * False on failure
2515
  */
2516
  function bp_get_activity_latest_update( $user_id = 0 ) {
2517
 
2518
+ if ( empty( $user_id ) )
2519
  $user_id = bp_displayed_user_id();
 
2520
 
2521
+ if ( bp_is_user_inactive( $user_id ) )
2522
  return false;
 
2523
 
2524
+ if ( !$update = bp_get_user_meta( $user_id, 'bp_latest_update', true ) )
2525
  return false;
 
2526
 
 
 
 
 
 
 
 
2527
  $latest_update = apply_filters( 'bp_get_activity_latest_update_excerpt', trim( strip_tags( bp_create_excerpt( $update['content'], 358 ) ) ) );
2528
+ $latest_update .= ' <a href="' . bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $update['id'] . '/"> ' . __( 'View', 'buddypress' ) . '</a>';
2529
 
2530
+ return apply_filters( 'bp_get_activity_latest_update', $latest_update );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2531
  }
2532
 
2533
  /**
2534
  * Output the activity filter links.
2535
  *
2536
+ * @since BuddyPress (1.1)
2537
  *
2538
  * @see bp_get_activity_filter_links() for description of parameters.
2539
  * @uses bp_get_activity_filter_links()
2540
  *
2541
+ * @param array $args See {@link bp_get_activity_filter_links()} for description.
2542
  */
2543
  function bp_activity_filter_links( $args = false ) {
2544
  echo bp_get_activity_filter_links( $args );
2547
  /**
2548
  * Return the activity filter links.
2549
  *
2550
+ * @since BuddyPress (1.1)
2551
  *
2552
  * @uses wp_parse_args()
2553
  * @uses BP_Activity_Activity::get_recorded_components() {@link BP_Activity_Activity}
2557
  * @uses apply_filters() To call the 'bp_get_activity_filter_link_href' hook.
2558
  * @uses apply_filters() To call the 'bp_get_activity_filter_links' hook.
2559
  *
2560
+ * @param array $args {
2561
  * @type string $style The type of markup to use for the links.
2562
+ * 'list', 'paragraph', or 'span'. Default: 'list'.
2563
  * }
2564
  * @return string|bool $component_links The activity filter links.
2565
  * False on failure.
2566
  */
2567
  function bp_get_activity_filter_links( $args = false ) {
2568
 
2569
+ $defaults = array(
2570
  'style' => 'list'
2571
+ );
2572
+
2573
+ $r = wp_parse_args( $args, $defaults );
2574
+ extract( $r, EXTR_SKIP );
2575
 
2576
+ // Define local variable
2577
  $component_links = array();
2578
 
2579
+ // Fetch the names of components that have activity recorded in the DB
2580
  $components = BP_Activity_Activity::get_recorded_components();
2581
 
2582
+ if ( empty( $components ) )
2583
  return false;
 
2584
 
2585
  foreach ( (array) $components as $component ) {
2586
 
2587
+ // Skip the activity comment filter
2588
+ if ( 'activity' == $component )
2589
  continue;
 
2590
 
2591
+ if ( isset( $_GET['afilter'] ) && $component == $_GET['afilter'] )
2592
  $selected = ' class="selected"';
2593
+ else
2594
+ unset($selected);
 
2595
 
2596
  $component = esc_attr( $component );
2597
 
2598
+ switch ( $style ) {
2599
  case 'list':
2600
  $tag = 'li';
2601
  $before = '<li id="afilter-' . $component . '"' . $selected . '>';
2615
 
2616
  $link = add_query_arg( 'afilter', $component );
2617
  $link = remove_query_arg( 'acpage' , $link );
 
 
 
 
 
 
 
 
 
2618
  $link = apply_filters( 'bp_get_activity_filter_link_href', $link, $component );
2619
 
2620
+ $component_links[] = $before . '<a href="' . esc_attr( $link ) . '">' . ucwords( $component ) . '</a>' . $after;
2621
  }
2622
 
2623
  $link = remove_query_arg( 'afilter' , $link );
2624
 
2625
+ if ( isset( $_GET['afilter'] ) )
2626
+ $component_links[] = '<' . $tag . ' id="afilter-clear"><a href="' . esc_attr( $link ) . '">' . __( 'Clear Filter', 'buddypress' ) . '</a></' . $tag . '>';
 
2627
 
 
 
 
 
 
 
 
2628
  return apply_filters( 'bp_get_activity_filter_links', implode( "\n", $component_links ) );
2629
  }
2630
 
2631
  /**
2632
  * Determine if a comment can be made on an activity item.
2633
  *
2634
+ * @since BuddyPress (1.2)
2635
  *
2636
  * @global object $activities_template {@link BP_Activity_Template}
2637
  * @uses bp_get_activity_action_name()
2641
  */
2642
  function bp_activity_can_comment() {
2643
  global $activities_template;
 
2644
 
 
2645
  $can_comment = true;
2646
 
2647
+ if ( false === $activities_template->disable_blogforum_replies || (int) $activities_template->disable_blogforum_replies ) {
2648
+ if ( 'new_blog_post' == bp_get_activity_action_name() || 'new_blog_comment' == bp_get_activity_action_name() || 'new_forum_topic' == bp_get_activity_action_name() || 'new_forum_post' == bp_get_activity_action_name() )
2649
+ $can_comment = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2650
  }
2651
 
2652
+ if ( 'activity_comment' == bp_get_activity_action_name() )
2653
+ $can_comment = false;
2654
 
2655
+ return apply_filters( 'bp_activity_can_comment', $can_comment );
 
 
 
 
 
 
 
 
2656
  }
2657
 
2658
  /**
2659
+ * Determine if a comment can be made on an activity reply item.
2660
+ *
2661
+ * Defaults to true, but can be modified by plugins.
2662
+ *
2663
+ * @since BuddyPress (1.5)
2664
  *
2665
+ * @uses apply_filters() To call the 'bp_activity_can_comment_reply' hook
2666
  *
2667
+ * @param object $comment Activity comment.
2668
+ * @return bool $can_comment True if comment can receive comments.
 
2669
  */
2670
+ function bp_activity_can_comment_reply( $comment ) {
 
 
2671
  $can_comment = true;
2672
 
2673
+ if ( get_option( 'thread_comments' ) && bp_activity_get_comment_depth() >= get_option( 'thread_comments_depth' ) ) {
2674
+ $can_comment = false;
 
2675
  }
2676
 
2677
+ return apply_filters( 'bp_activity_can_comment_reply', $can_comment, $comment );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2678
  }
2679
 
2680
  /**
2681
+ * Determine if an favorites are allowed.
2682
  *
2683
  * Defaults to true, but can be modified by plugins.
2684
  *
2685
+ * @since BuddyPress (1.5)
2686
  *
2687
  * @uses apply_filters() To call the 'bp_activity_can_favorite' hook.
2688
  *
2689
+ * @return bool $can_favorite True if comment can receive comments.
2690
  */
2691
  function bp_activity_can_favorite() {
2692
+ $can_favorite = true;
2693
 
2694
+ return apply_filters( 'bp_activity_can_favorite', $can_favorite );
 
 
 
 
 
 
 
2695
  }
2696
 
2697
  /**
2698
  * Output the total favorite count for a specified user.
2699
  *
2700
+ * @since BuddyPress (1.2)
2701
  *
2702
  * @see bp_get_total_favorite_count_for_user() for description of parameters.
2703
  * @uses bp_get_total_favorite_count_for_user()
2711
  /**
2712
  * Return the total favorite count for a specified user.
2713
  *
2714
+ * @since BuddyPress (1.2)
2715
  *
2716
  * @uses bp_activity_total_favorites_for_user()
2717
+ * @uses apply_filters() To call the 'bp_get_total_favorite_count_for_user' hook
2718
  *
2719
  * @param int $user_id ID of user being queried. Default: displayed user ID.
2720
  * @return int The total favorite count for the specified user.
2721
  */
2722
  function bp_get_total_favorite_count_for_user( $user_id = 0 ) {
2723
+ if ( ! $user_id ) {
2724
+ $user_id = bp_displayed_user_id();
 
 
 
 
 
 
 
 
 
 
2725
  }
2726
 
2727
+ return apply_filters( 'bp_get_total_favorite_count_for_user', bp_activity_total_favorites_for_user( $user_id ) );
 
 
 
 
 
 
 
2728
  }
2729
+ add_filter( 'bp_get_total_favorite_count_for_user', 'bp_core_number_format' );
2730
 
2731
  /**
2732
  * Output the total mention count for a specified user.
2733
  *
2734
+ * @since BuddyPress (1.2)
2735
  *
2736
  * @see bp_get_total_mention_count_for_user() for description of parameters.
2737
  * @uses bp_get_total_favorite_count_for_user()
2745
  /**
2746
  * Return the total mention count for a specified user.
2747
  *
2748
+ * @since BuddyPress (1.2)
2749
  *
2750
  * @uses bp_get_user_meta()
2751
  * @uses apply_filters() To call the 'bp_get_total_mention_count_for_user' hook.
2754
  * @return int The total mention count for the specified user.
2755
  */
2756
  function bp_get_total_mention_count_for_user( $user_id = 0 ) {
2757
+ if ( ! $user_id ) {
2758
+ $user_id = bp_displayed_user_id();
2759
+ }
2760
 
2761
+ return apply_filters( 'bp_get_total_mention_count_for_user', bp_get_user_meta( $user_id, 'bp_new_mention_count', true ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2762
  }
2763
+ add_filter( 'bp_get_total_mention_count_for_user', 'bp_core_number_format' );
2764
 
2765
  /**
2766
  * Output the public message link for displayed user.
2767
  *
2768
+ * @since BuddyPress (1.2)
2769
  *
2770
  * @uses bp_get_send_public_message_link()
2771
  */
2772
  function bp_send_public_message_link() {
2773
+ echo bp_get_send_public_message_link();
2774
  }
2775
 
2776
  /**
2777
  * Return the public message link for the displayed user.
2778
  *
2779
+ * @since BuddyPress (1.2)
2780
  *
2781
  * @uses is_user_logged_in()
2782
  * @uses bp_is_my_profile()
2783
  * @uses bp_is_user()
2784
  * @uses wp_nonce_url()
2785
  * @uses bp_get_activity_directory_permalink()
2786
+ * @uses apply_filters() To call the 'bp_get_send_public_message_link' hook
2787
  *
2788
  * @return string The public message link for the displayed user.
2789
  */
2790
  function bp_get_send_public_message_link() {
2791
 
2792
+ if ( ! is_user_logged_in() || ! bp_is_user() || bp_is_my_profile() )
2793
+ return false;
 
 
 
 
 
 
2794
 
2795
+ return apply_filters( 'bp_get_send_public_message_link', wp_nonce_url( bp_get_activity_directory_permalink() . '?r=' . bp_get_displayed_user_mentionname() ) );
 
 
 
 
 
 
 
2796
  }
2797
 
2798
  /**
2799
  * Recurse through all activity comments and return the activity comment IDs.
2800
  *
2801
+ * @since BuddyPress (2.0.0)
2802
  *
2803
  * @param array $activity Array of activities generated from {@link bp_activity_get()}.
2804
  * @param array $activity_ids Used for recursion purposes in this function.
2825
  /**
2826
  * Output the mentioned user display name.
2827
  *
2828
+ * @since BuddyPress (1.2)
2829
  *
2830
  * @see bp_get_mentioned_user_display_name() for description of parameters.
2831
  * @uses bp_get_mentioned_user_display_name()
2832
  *
2833
+ * @param int|string $user_id_or_username See {@link bp_get_mentioned_user_display_name()}.
2834
  */
2835
+ function bp_mentioned_user_display_name( $user_id_or_username ) {
2836
  echo bp_get_mentioned_user_display_name( $user_id_or_username );
2837
  }
2838
 
2839
  /**
2840
+ * Returns the mentioned user display name
2841
  *
2842
+ * @since BuddyPress (1.2)
2843
  *
2844
  * @uses bp_core_get_user_displayname()
2845
  * @uses apply_filters() To call the 'bp_get_mentioned_user_display_name' hook.
2846
  *
2847
+ * @param int|string User ID or username.
2848
  * @return string The mentioned user's display name.
2849
  */
2850
+ function bp_get_mentioned_user_display_name( $user_id_or_username ) {
2851
+ if ( !$name = bp_core_get_user_displayname( $user_id_or_username ) )
 
 
 
 
 
2852
  $name = __( 'a user', 'buddypress' );
 
2853
 
 
 
 
 
 
 
 
 
2854
  return apply_filters( 'bp_get_mentioned_user_display_name', $name, $user_id_or_username );
2855
  }
2856
 
2857
  /**
2858
  * Output button for sending a public message (an @-mention).
2859
  *
2860
+ * @since BuddyPress (1.2)
2861
  *
2862
  * @see bp_get_send_public_message_button() for description of parameters.
2863
  * @uses bp_get_send_public_message_button()
2864
  *
2865
+ * @param array $args See {@link bp_get_send_public_message_button()}.
2866
  */
2867
  function bp_send_public_message_button( $args = '' ) {
2868
  echo bp_get_send_public_message_button( $args );
2871
  /**
2872
  * Return button for sending a public message (an @-mention).
2873
  *
2874
+ * @since BuddyPress (1.2)
2875
  *
2876
  * @uses bp_get_send_public_message_link()
2877
  * @uses wp_parse_args()
2878
  * @uses bp_get_button()
2879
  * @uses apply_filters() To call the 'bp_get_send_public_message_button' hook.
2880
  *
2881
+ * @param array $args {
2882
  * All arguments are optional. See {@link BP_Button} for complete
2883
  * descriptions.
2884
+ * @type string $id Default: 'public_message'.
2885
+ * @type string $component Default: 'activity'.
2886
+ * @type bool $must_be_logged_in Default: true.
2887
+ * @type bool $block_self Default: true.
2888
+ * @type string $wrapper_id Default: 'post-mention'.
2889
+ * @type string $link_href Default: the public message link for
2890
+ * the current member in the loop.
2891
+ * @type string $link_title Default: 'Send a public message on your
2892
+ * activity stream.'.
2893
+ * @type string $link_text Default: 'Public Message'.
2894
+ * @type string $link_class Default: 'activity-button mention'.
2895
  * }
2896
  * @return string The button for sending a public message.
2897
  */
2898
  function bp_get_send_public_message_button( $args = '' ) {
2899
+ $defaults = array(
 
2900
  'id' => 'public_message',
2901
  'component' => 'activity',
2902
  'must_be_logged_in' => true,
2906
  'link_title' => __( 'Send a public message on your activity stream.', 'buddypress' ),
2907
  'link_text' => __( 'Public Message', 'buddypress' ),
2908
  'link_class' => 'activity-button mention'
2909
+ );
2910
 
2911
+ $button = wp_parse_args( $args, $defaults );
2912
+
2913
+ // Filter and return the HTML button
2914
+ return bp_get_button( apply_filters( 'bp_get_send_public_message_button', $button ) );
 
 
 
 
2915
  }
2916
 
2917
  /**
2918
  * Output the activity post form action.
2919
  *
2920
+ * @since BuddyPress (1.2)
2921
  *
2922
  * @uses bp_get_activity_post_form_action()
2923
  */
2928
  /**
2929
  * Return the activity post form action.
2930
  *
2931
+ * @since BuddyPress (1.2)
2932
  *
2933
  * @uses home_url()
2934
  * @uses bp_get_activity_root_slug()
2937
  * @return string The activity post form action.
2938
  */
2939
  function bp_get_activity_post_form_action() {
 
 
 
 
 
 
 
 
2940
  return apply_filters( 'bp_get_activity_post_form_action', home_url( bp_get_activity_root_slug() . '/post/' ) );
2941
  }
2942
 
2948
  * Avatars are wrapped in <li> elements, but you've got to provide your own
2949
  * <ul> or <ol> wrapper markup.
2950
  *
2951
+ * @since BuddyPress (1.7)
2952
  *
2953
  * @see bp_core_fetch_avatar() for a description of arguments.
2954
  *
2955
  * @param array $args See {@link bp_core_fetch_avatar()}.
2956
  */
2957
  function bp_activity_comments_user_avatars( $args = array() ) {
2958
+ $defaults = array(
 
2959
  'height' => false,
2960
  'html' => true,
2961
  'type' => 'thumb',
2962
  'width' => false,
2963
+ );
 
 
 
 
 
2964
 
2965
+ $args = wp_parse_args( $args, $defaults );
2966
+ extract( $args, EXTR_SKIP );
2967
 
2968
+ // Get the user IDs of everyone who has left a comment to the current activity item
2969
+ $user_ids = bp_activity_get_comments_user_ids();
 
 
2970
 
2971
+ $output = array();
2972
+ foreach ( (array) $user_ids as $user_id ) {
2973
+ $profile_link = bp_core_get_user_domain( $user_id );
2974
+ $image_html = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'height' => $height, 'html' => $html, 'type' => $type, 'width' => $width, ) );
2975
 
2976
+ $output[] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $profile_link ), $image_html );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2977
  }
2978
 
2979
+ echo apply_filters( 'bp_activity_comments_user_avatars', '<li>' . implode( '</li><li>', $output ) . '</li>', $args, $output );
 
 
 
 
 
 
 
 
 
2980
  }
2981
 
2982
  /**
2983
  * Return the IDs of every user who's left a comment on the current activity item.
2984
  *
2985
+ * @since BuddyPress (1.7)
2986
  *
2987
  * @return bool|array An array of IDs, or false if none are found.
2988
  */
2989
  function bp_activity_get_comments_user_ids() {
2990
+ if ( empty( $GLOBALS['activities_template']->activity ) || empty( $GLOBALS['activities_template']->activity->children ) )
2991
+ return false;
 
 
 
2992
 
2993
+ $user_ids = (array) bp_activity_recurse_comments_user_ids( $GLOBALS['activities_template']->activity->children );
 
 
 
 
 
 
2994
  return apply_filters( 'bp_activity_get_comments_user_ids', array_unique( $user_ids ) );
2995
  }
2996
 
2997
  /**
2998
  * Recurse through all activity comments and collect the IDs of the users who wrote them.
2999
  *
3000
+ * @since BuddyPress (1.7)
3001
  *
3002
  * @param array $comments Array of {@link BP_Activity_Activity} items.
3003
  * @return array Array of user IDs.
3004
  */
3005
+ function bp_activity_recurse_comments_user_ids( array $comments ) {
 
 
3006
  $user_ids = array();
3007
 
3008
+ foreach ( $comments as $comment ) {
3009
+ // If a user is a spammer, their activity items will have been automatically marked as spam. Skip these.
3010
+ if ( $comment->is_spam )
3011
+ continue;
 
 
 
 
 
3012
 
3013
+ $user_ids[] = $comment->user_id;
 
3014
 
3015
+ // Check for commentception
3016
+ if ( ! empty( $comment->children ) )
3017
+ $user_ids = array_merge( $user_ids, bp_activity_recurse_comments_user_ids( $comment->children ) );
 
 
3018
  }
3019
 
3020
+ return $user_ids;
 
 
 
 
 
 
 
 
3021
  }
3022
 
3023
  /**
3024
  * Output the mentionname for the displayed user.
3025
  *
3026
+ * @since BuddyPress (1.9.0)
3027
  */
3028
  function bp_displayed_user_mentionname() {
3029
  echo bp_get_displayed_user_mentionname();
3031
  /**
3032
  * Get the mentionname for the displayed user.
3033
  *
3034
+ * @since BuddyPress (1.9.0)
3035
  *
3036
  * @return string Mentionname for the displayed user, if available.
3037
  */
3038
  function bp_get_displayed_user_mentionname() {
 
 
 
 
 
 
 
 
3039
  return apply_filters( 'bp_get_displayed_user_mentionname', bp_activity_get_user_mentionname( bp_displayed_user_id() ) );
3040
  }
3041
 
3042
  /**
3043
  * Echo a list of all registered activity types for use in dropdowns or checkbox lists.
3044
  *
3045
+ * @since BuddyPress (1.7)
3046
  *
3047
+ * @param string $output Optional. Either 'select' or 'checkbox'. Default: 'select'.
3048
+ * @param array $args {
3049
  * Optional extra arguments.
3050
+ * @type string $checkbox_name When returning checkboxes, sets the 'name'
3051
+ * attribute.
3052
+ * @type array|string $selected A list of types that should be checked/
3053
+ * selected.
3054
  * }
3055
  */
3056
  function bp_activity_types_list( $output = 'select', $args = '' ) {
3057
+ $defaults = array(
 
3058
  'checkbox_name' => 'bp_activity_types',
3059
  'selected' => array(),
3060
+ );
3061
+ $args = wp_parse_args( $args, $defaults );
3062
 
3063
  $activities = bp_activity_get_types();
3064
  natsort( $activities );
3065
 
3066
+ // Loop through the activity types and output markup
3067
  foreach ( $activities as $type => $description ) {
3068
 
3069
+ // See if we need to preselect the current type
3070
  $checked = checked( true, in_array( $type, (array) $args['selected'] ), false );
3071
  $selected = selected( true, in_array( $type, (array) $args['selected'] ), false );
3072
 
3073
+ if ( 'select' == $output )
3074
+ printf( '<option value="%1$s" %2$s>%3$s</option>', esc_attr( $type ), $selected, esc_html( $description ) );
 
 
 
 
 
 
 
3075
 
3076
+ elseif ( 'checkbox' == $output )
3077
+ printf( '<label style="">%1$s<input type="checkbox" name="%2$s[]" value="%3$s" %4$s/></label>', esc_html( $description ), esc_attr( $args['checkbox_name'] ), esc_attr( $type ), $checked );
3078
+
3079
+ // Allow custom markup
 
 
 
 
 
 
 
 
3080
  do_action( 'bp_activity_types_list_' . $output, $args, $type, $description );
3081
  }
3082
 
3083
+ // Backpat with BP-Default for dropdown boxes only
3084
+ if ( 'select' == $output )
3085
  do_action( 'bp_activity_filter_options' );
 
3086
  }
3087
 
3088
 
3091
  /**
3092
  * Output the sitewide activity feed link.
3093
  *
3094
+ * @since BuddyPress (1.0)
3095
  *
3096
  * @uses bp_get_sitewide_activity_feed_link()
3097
  */
3102
  /**
3103
  * Returns the sitewide activity feed link.
3104
  *
3105
+ * @since BuddyPress (1.0)
3106
  *
3107
  * @uses home_url()
3108
  * @uses bp_get_activity_root_slug()
3111
  * @return string The sitewide activity feed link.
3112
  */
3113
  function bp_get_sitewide_activity_feed_link() {
 
 
 
 
 
 
 
 
3114
  return apply_filters( 'bp_get_sitewide_activity_feed_link', bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/feed/' );
3115
  }
3116
 
3117
  /**
3118
  * Output the member activity feed link.
3119
  *
3120
+ * @since BuddyPress (1.2)
3121
  *
3122
  * @uses bp_get_member_activity_feed_link()
3123
  */
3128
  /**
3129
  * Output the member activity feed link.
3130
  *
3131
+ * @since BuddyPress (1.0)
3132
+ * @deprecated BuddyPress (1.2)
3133
  *
3134
  * @todo properly deprecate in favor of bp_member_activity_feed_link().
3135
  *
3140
  /**
3141
  * Return the member activity feed link.
3142
  *
3143
+ * @since BuddyPress (1.2)
3144
  *
3145
  * @uses bp_is_profile_component()
3146
  * @uses bp_is_current_action()
3155
  */
3156
  function bp_get_member_activity_feed_link() {
3157
 
3158
+ if ( bp_is_profile_component() || bp_is_current_action( 'just-me' ) )
 
3159
  $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/feed/';
3160
+ elseif ( bp_is_active( 'friends' ) && bp_is_current_action( bp_get_friends_slug() ) )
 
 
3161
  $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_friends_slug() . '/feed/';
3162
+ elseif ( bp_is_active( 'groups' ) && bp_is_current_action( bp_get_groups_slug() ) )
 
 
3163
  $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_groups_slug() . '/feed/';
3164
+ elseif ( 'favorites' == bp_current_action() )
 
 
3165
  $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/favorites/feed/';
3166
+ elseif ( 'mentions' == bp_current_action() && bp_activity_do_mentions() )
 
 
3167
  $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/mentions/feed/';
3168
+ else
 
 
3169
  $link = '';
 
3170
 
 
 
 
 
 
 
 
3171
  return apply_filters( 'bp_get_activities_member_rss_link', $link );
3172
  }
3173
 
3174
  /**
3175
  * Return the member activity feed link.
3176
  *
3177
+ * @since BuddyPress (1.0)
3178
+ * @deprecated BuddyPress (1.2)
3179
  *
3180
  * @todo properly deprecate in favor of bp_get_member_activity_feed_link().
3181
  *
3191
  /**
3192
  * Outputs the activity feed item guid.
3193
  *
3194
+ * @since BuddyPress (1.0)
3195
  *
3196
  * @uses bp_activity_feed_item_guid()
3197
  */
3202
  /**
3203
  * Returns the activity feed item guid.
3204
  *
3205
+ * @since BuddyPress (1.2)
3206
  *
3207
  * @global object $activities_template {@link BP_Activity_Template}
3208
  * @uses apply_filters() To call the 'bp_get_activity_feed_item_guid' hook.
3212
  function bp_get_activity_feed_item_guid() {
3213
  global $activities_template;
3214
 
 
 
 
 
 
 
 
3215
  return apply_filters( 'bp_get_activity_feed_item_guid', md5( $activities_template->activity->date_recorded . '-' . $activities_template->activity->content ) );
3216
  }
3217
 
3218
  /**
3219
  * Output the activity feed item title.
3220
  *
3221
+ * @since BuddyPress (1.0)
3222
  *
3223
  * @uses bp_get_activity_feed_item_title()
3224
  */
3229
  /**
3230
  * Return the activity feed item title.
3231
  *
3232
+ * @since BuddyPress (1.0)
3233
  *
3234
  * @global object $activities_template {@link BP_Activity_Template}
3235
  * @uses ent2ncr()
3242
  function bp_get_activity_feed_item_title() {
3243
  global $activities_template;
3244
 
3245
+ if ( !empty( $activities_template->activity->action ) )
3246
  $content = $activities_template->activity->action;
3247
+ else
3248
  $content = $activities_template->activity->content;
 
3249
 
3250
  $content = explode( '<span', $content );
3251
+ $title = strip_tags( ent2ncr( trim( convert_chars( $content[0] ) ) ) );
3252
 
3253
+ if ( ':' == substr( $title, -1 ) )
3254
  $title = substr( $title, 0, -1 );
 
3255
 
3256
+ if ( 'activity_update' == $activities_template->activity->type )
3257
  $title .= ': ' . strip_tags( ent2ncr( trim( convert_chars( bp_create_excerpt( $activities_template->activity->content, 70, array( 'ending' => " [&#133;]" ) ) ) ) ) );
 
3258
 
 
 
 
 
 
 
 
3259
  return apply_filters( 'bp_get_activity_feed_item_title', $title );
3260
  }
3261
 
3262
  /**
3263
+ * Output the activity feed item link
3264
  *
3265
+ * @since BuddyPress (1.0)
3266
  *
3267
  * @uses bp_get_activity_feed_item_link()
3268
  */
3271
  }
3272
 
3273
  /**
3274
+ * Return the activity feed item link
3275
  *
3276
+ * @since BuddyPress (1.0)
3277
  *
3278
  * @global object $activities_template {@link BP_Activity_Template}
3279
  * @uses apply_filters() To call the 'bp_get_activity_feed_item_link' hook.
3283
  function bp_get_activity_feed_item_link() {
3284
  global $activities_template;
3285
 
3286
+ return apply_filters( 'bp_get_activity_feed_item_link', $activities_template->activity->primary_link );
 
 
 
 
 
 
 
 
 
 
 
3287
  }
3288
 
3289
  /**
3290
  * Output the activity feed item date.
3291
  *
3292
+ * @since BuddyPress (1.0)
3293
  *
3294
  * @uses bp_get_activity_feed_item_date()
3295
  */
3300
  /**
3301
  * Return the activity feed item date.
3302
  *
3303
+ * @since BuddyPress (1.0)
3304
  *
3305
  * @global object $activities_template {@link BP_Activity_Template}
3306
  * @uses apply_filters() To call the 'bp_get_activity_feed_item_date' hook.
3310
  function bp_get_activity_feed_item_date() {
3311
  global $activities_template;
3312
 
3313
+ return apply_filters( 'bp_get_activity_feed_item_date', $activities_template->activity->date_recorded );
 
 
 
 
 
 
 
 
 
 
 
3314
  }
3315
 
3316
  /**
3317
  * Output the activity feed item description.
3318
  *
3319
+ * @since BuddyPress (1.0)
3320
  *
3321
  * @uses bp_get_activity_feed_item_description()
3322
  */
3327
  /**
3328
  * Return the activity feed item description.
3329
  *
3330
+ * @since BuddyPress (1.0)
3331
  *
3332
  * @global object $activities_template {@link BP_Activity_Template}
3333
  * @uses ent2ncr()
3339
  function bp_get_activity_feed_item_description() {
3340
  global $activities_template;
3341
 
3342
+ $content = '';
3343
+ if ( ! empty( $activities_template->activity->content ) )
3344
+ $content = $activities_template->activity->content;
 
 
 
 
 
 
3345
 
3346
+ return apply_filters( 'bp_get_activity_feed_item_description', ent2ncr( convert_chars( str_replace( '%s', '', $content ) ) ) );
 
 
 
 
 
 
 
3347
  }
3348
 
3349
  /**
3350
  * Template tag so we can hook activity feed to <head>.
3351
  *
3352
+ * @since BuddyPress (1.5)
3353
  *
3354
  * @uses bloginfo()
3355
  * @uses bp_sitewide_activity_feed_link()
3362
  <?php
3363
  }
3364
  add_action( 'bp_head', 'bp_activity_sitewide_feed' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-activity/classes/class-bp-activity-activity.php DELETED
@@ -1,1793 +0,0 @@
1
- <?php
2
- /**
3
- * BuddyPress Activity Classes
4
- *
5
- * @package BuddyPress
6
- * @subpackage Activity
7
- */
8
-
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 1.0.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|bool $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 1.0.0
213
- *
214
- * @param BP_Activity_Activity $this Current instance of the activity item being saved. Passed by reference.
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 1.0.0
250
- *
251
- * @param BP_Activity_Activity $this Current instance of activity item being saved. Passed by reference.
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
- * @since 1.0.0
264
- * @since 2.4.0 Introduced the `$fields` parameter.
265
- *
266
- * @see BP_Activity_Activity::get_filter_sql() for a description of the
267
- * 'filter' parameter.
268
- * @see WP_Meta_Query::queries for a description of the 'meta_query'
269
- * parameter format.
270
- *
271
- * @param array $args {
272
- * An array of arguments. All items are optional.
273
- * @type int $page Which page of results to fetch. Using page=1 without per_page will result
274
- * in no pagination. Default: 1.
275
- * @type int|bool $per_page Number of results per page. Default: 25.
276
- * @type int|bool $max Maximum number of results to return. Default: false (unlimited).
277
- * @type string $fields Activity fields to return. Pass 'ids' to get only the activity IDs.
278
- * 'all' returns full activity objects.
279
- * @type string $sort ASC or DESC. Default: 'DESC'.
280
- * @type array $exclude Array of activity IDs to exclude. Default: false.
281
- * @type array $in Array of ids to limit query by (IN). Default: false.
282
- * @type array $meta_query Array of meta_query conditions. See WP_Meta_Query::queries.
283
- * @type array $date_query Array of date_query conditions. See first parameter of
284
- * WP_Date_Query::__construct().
285
- * @type array $filter_query Array of advanced query conditions. See BP_Activity_Query::__construct().
286
- * @type string|array $scope Pre-determined set of activity arguments.
287
- * @type array $filter See BP_Activity_Activity::get_filter_sql().
288
- * @type string $search_terms Limit results by a search term. Default: false.
289
- * @type bool $display_comments Whether to include activity comments. Default: false.
290
- * @type bool $show_hidden Whether to show items marked hide_sitewide. Default: false.
291
- * @type string $spam Spam status. Default: 'ham_only'.
292
- * @type bool $update_meta_cache Whether to pre-fetch metadata for queried activity items. Default: true.
293
- * @type string|bool $count_total If true, an additional DB query is run to count the total activity items
294
- * for the query. Default: false.
295
- * }
296
- * @return array The array returned has two keys:
297
- * - 'total' is the count of located activities
298
- * - 'activities' is an array of the located activities
299
- */
300
- public static function get( $args = array() ) {
301
- global $wpdb;
302
-
303
- // Backward compatibility with old method of passing arguments.
304
- if ( !is_array( $args ) || func_num_args() > 1 ) {
305
- _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__ ) );
306
-
307
- $old_args_keys = array(
308
- 0 => 'max',
309
- 1 => 'page',
310
- 2 => 'per_page',
311
- 3 => 'sort',
312
- 4 => 'search_terms',
313
- 5 => 'filter',
314
- 6 => 'display_comments',
315
- 7 => 'show_hidden',
316
- 8 => 'exclude',
317
- 9 => 'in',
318
- 10 => 'spam'
319
- );
320
-
321
- $func_args = func_get_args();
322
- $args = bp_core_parse_args_array( $old_args_keys, $func_args );
323
- }
324
-
325
- $bp = buddypress();
326
- $r = wp_parse_args( $args, array(
327
- 'page' => 1, // The current page.
328
- 'per_page' => 25, // Activity items per page.
329
- 'max' => false, // Max number of items to return.
330
- 'fields' => 'all', // Fields to include.
331
- 'sort' => 'DESC', // ASC or DESC.
332
- 'exclude' => false, // Array of ids to exclude.
333
- 'in' => false, // Array of ids to limit query by (IN).
334
- 'meta_query' => false, // Filter by activitymeta.
335
- 'date_query' => false, // Filter by date.
336
- 'filter_query' => false, // Advanced filtering - see BP_Activity_Query.
337
- 'filter' => false, // See self::get_filter_sql().
338
- 'scope' => false, // Preset activity arguments.
339
- 'search_terms' => false, // Terms to search by.
340
- 'display_comments' => false, // Whether to include activity comments.
341
- 'show_hidden' => false, // Show items marked hide_sitewide.
342
- 'spam' => 'ham_only', // Spam status.
343
- 'update_meta_cache' => true, // Whether or not to update meta cache.
344
- 'count_total' => false, // Whether or not to use count_total.
345
- ) );
346
-
347
- // Select conditions.
348
- $select_sql = "SELECT DISTINCT a.id";
349
-
350
- $from_sql = " FROM {$bp->activity->table_name} a";
351
-
352
- $join_sql = '';
353
-
354
- // Where conditions.
355
- $where_conditions = array();
356
-
357
- // Excluded types.
358
- $excluded_types = array();
359
-
360
- // Scope takes precedence.
361
- if ( ! empty( $r['scope'] ) ) {
362
- $scope_query = self::get_scope_query_sql( $r['scope'], $r );
363
-
364
- // Add our SQL conditions if matches were found.
365
- if ( ! empty( $scope_query['sql'] ) ) {
366
- $where_conditions['scope_query_sql'] = $scope_query['sql'];
367
- }
368
-
369
- // Override some arguments if needed.
370
- if ( ! empty( $scope_query['override'] ) ) {
371
- $r = self::array_replace_recursive( $r, $scope_query['override'] );
372
- }
373
-
374
- // Advanced filtering.
375
- } elseif ( ! empty( $r['filter_query'] ) ) {
376
- $filter_query = new BP_Activity_Query( $r['filter_query'] );
377
- $sql = $filter_query->get_sql();
378
- if ( ! empty( $sql ) ) {
379
- $where_conditions['filter_query_sql'] = $sql;
380
- }
381
- }
382
-
383
- // Regular filtering.
384
- if ( $r['filter'] && $filter_sql = BP_Activity_Activity::get_filter_sql( $r['filter'] ) ) {
385
- $where_conditions['filter_sql'] = $filter_sql;
386
- }
387
-
388
- // Spam.
389
- if ( 'ham_only' == $r['spam'] ) {
390
- $where_conditions['spam_sql'] = 'a.is_spam = 0';
391
- } elseif ( 'spam_only' == $r['spam'] ) {
392
- $where_conditions['spam_sql'] = 'a.is_spam = 1';
393
- }
394
-
395
- // Searching.
396
- if ( $r['search_terms'] ) {
397
- $search_terms_like = '%' . bp_esc_like( $r['search_terms'] ) . '%';
398
- $where_conditions['search_sql'] = $wpdb->prepare( 'a.content LIKE %s', $search_terms_like );
399
- }
400
-
401
- // Sorting.
402
- $sort = $r['sort'];
403
- if ( $sort != 'ASC' && $sort != 'DESC' ) {
404
- $sort = 'DESC';
405
- }
406
-
407
- // Hide Hidden Items?
408
- if ( ! $r['show_hidden'] ) {
409
- $where_conditions['hidden_sql'] = "a.hide_sitewide = 0";
410
- }
411
-
412
- // Exclude specified items.
413
- if ( ! empty( $r['exclude'] ) ) {
414
- $exclude = implode( ',', wp_parse_id_list( $r['exclude'] ) );
415
- $where_conditions['exclude'] = "a.id NOT IN ({$exclude})";
416
- }
417
-
418
- // The specific ids to which you want to limit the query.
419
- if ( ! empty( $r['in'] ) ) {
420
- $in = implode( ',', wp_parse_id_list( $r['in'] ) );
421
- $where_conditions['in'] = "a.id IN ({$in})";
422
- }
423
-
424
- // Process meta_query into SQL.
425
- $meta_query_sql = self::get_meta_query_sql( $r['meta_query'] );
426
-
427
- if ( ! empty( $meta_query_sql['join'] ) ) {
428
- $join_sql .= $meta_query_sql['join'];
429
- }
430
-
431
- if ( ! empty( $meta_query_sql['where'] ) ) {
432
- $where_conditions[] = $meta_query_sql['where'];
433
- }
434
-
435
- // Process date_query into SQL.
436
- $date_query_sql = self::get_date_query_sql( $r['date_query'] );
437
-
438
- if ( ! empty( $date_query_sql ) ) {
439
- $where_conditions['date'] = $date_query_sql;
440
- }
441
-
442
- // Alter the query based on whether we want to show activity item
443
- // comments in the stream like normal comments or threaded below
444
- // the activity.
445
- if ( false === $r['display_comments'] || 'threaded' === $r['display_comments'] ) {
446
- $excluded_types[] = 'activity_comment';
447
- }
448
-
449
- // Exclude 'last_activity' items unless the 'action' filter has
450
- // been explicitly set.
451
- if ( empty( $r['filter']['object'] ) ) {
452
- $excluded_types[] = 'last_activity';
453
- }
454
-
455
- // Build the excluded type sql part.
456
- if ( ! empty( $excluded_types ) ) {
457
- $not_in = "'" . implode( "', '", esc_sql( $excluded_types ) ) . "'";
458
- $where_conditions['excluded_types'] = "a.type NOT IN ({$not_in})";
459
- }
460
-
461
- /**
462
- * Filters the MySQL WHERE conditions for the Activity items get method.
463
- *
464
- * @since 1.9.0
465
- *
466
- * @param array $where_conditions Current conditions for MySQL WHERE statement.
467
- * @param array $r Parsed arguments passed into method.
468
- * @param string $select_sql Current SELECT MySQL statement at point of execution.
469
- * @param string $from_sql Current FROM MySQL statement at point of execution.
470
- * @param string $join_sql Current INNER JOIN MySQL statement at point of execution.
471
- */
472
- $where_conditions = apply_filters( 'bp_activity_get_where_conditions', $where_conditions, $r, $select_sql, $from_sql, $join_sql );
473
-
474
- // Join the where conditions together.
475
- $where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
476
-
477
- /**
478
- * Filters the preferred order of indexes for activity item.
479
- *
480
- * @since 1.6.0
481
- *
482
- * @param array Array of indexes in preferred order.
483
- */
484
- $indexes = apply_filters( 'bp_activity_preferred_index_order', array( 'user_id', 'item_id', 'secondary_item_id', 'date_recorded', 'component', 'type', 'hide_sitewide', 'is_spam' ) );
485
-
486
- foreach( $indexes as $key => $index ) {
487
- if ( false !== strpos( $where_sql, $index ) ) {
488
- $the_index = $index;
489
- break; // Take the first one we find.
490
- }
491
- }
492
-
493
- if ( !empty( $the_index ) ) {
494
- $index_hint_sql = "USE INDEX ({$the_index})";
495
- } else {
496
- $index_hint_sql = '';
497
- }
498
-
499
- // Sanitize page and per_page parameters.
500
- $page = absint( $r['page'] );
501
- $per_page = absint( $r['per_page'] );
502
-
503
- $retval = array(
504
- 'activities' => null,
505
- 'total' => null,
506
- 'has_more_items' => null,
507
- );
508
-
509
- /**
510
- * Filters if BuddyPress should use legacy query structure over current structure for version 2.0+.
511
- *
512
- * It is not recommended to use the legacy structure, but allowed to if needed.
513
- *
514
- * @since 2.0.0
515
- *
516
- * @param bool $value Whether to use legacy structure or not.
517
- * @param BP_Activity_Activity $value Current method being called.
518
- * @param array $r Parsed arguments passed into method.
519
- */
520
- if ( apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, $r ) ) {
521
-
522
- // Legacy queries joined against the user table.
523
- $select_sql = "SELECT DISTINCT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name";
524
- $from_sql = " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID";
525
-
526
- if ( ! empty( $page ) && ! empty( $per_page ) ) {
527
- $pag_sql = $wpdb->prepare( "LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page );
528
-
529
- /** This filter is documented in bp-activity/bp-activity-classes.php */
530
- $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 ) );
531
- } else {
532
- $pag_sql = '';
533
-
534
- /**
535
- * Filters the legacy MySQL query statement so plugins can alter before results are fetched.
536
- *
537
- * @since 1.5.0
538
- *
539
- * @param string $value Concatenated MySQL statement pieces to be query results with for legacy query.
540
- * @param string $select_sql Final SELECT MySQL statement portion for legacy query.
541
- * @param string $from_sql Final FROM MySQL statement portion for legacy query.
542
- * @param string $where_sql Final WHERE MySQL statement portion for legacy query.
543
- * @param string $sort Final sort direction for legacy query.
544
- */
545
- $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 ) );
546
- }
547
-
548
- } else {
549
- // Query first for activity IDs.
550
- $activity_ids_sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort}";
551
-
552
- if ( ! empty( $per_page ) && ! empty( $page ) ) {
553
- // We query for $per_page + 1 items in order to
554
- // populate the has_more_items flag.
555
- $activity_ids_sql .= $wpdb->prepare( " LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page + 1 );
556
- }
557
-
558
- /**
559
- * Filters the paged activities MySQL statement.
560
- *
561
- * @since 2.0.0
562
- *
563
- * @param string $activity_ids_sql MySQL statement used to query for Activity IDs.
564
- * @param array $r Array of arguments passed into method.
565
- */
566
- $activity_ids_sql = apply_filters( 'bp_activity_paged_activities_sql', $activity_ids_sql, $r );
567
-
568
- $activity_ids = $wpdb->get_col( $activity_ids_sql );
569
-
570
- $retval['has_more_items'] = ! empty( $per_page ) && count( $activity_ids ) > $per_page;
571
-
572
- // If we've fetched more than the $per_page value, we
573
- // can discard the extra now.
574
- if ( ! empty( $per_page ) && count( $activity_ids ) === $per_page + 1 ) {
575
- array_pop( $activity_ids );
576
- }
577
-
578
- if ( 'ids' === $r['fields'] ) {
579
- $activities = array_map( 'intval', $activity_ids );
580
- } else {
581
- $activities = self::get_activity_data( $activity_ids );
582
- }
583
- }
584
-
585
- if ( 'ids' !== $r['fields'] ) {
586
- // Get the fullnames of users so we don't have to query in the loop.
587
- $activities = self::append_user_fullnames( $activities );
588
-
589
- // Get activity meta.
590
- $activity_ids = array();
591
- foreach ( (array) $activities as $activity ) {
592
- $activity_ids[] = $activity->id;
593
- }
594
-
595
- if ( ! empty( $activity_ids ) && $r['update_meta_cache'] ) {
596
- bp_activity_update_meta_cache( $activity_ids );
597
- }
598
-
599
- if ( $activities && $r['display_comments'] ) {
600
- $activities = BP_Activity_Activity::append_comments( $activities, $r['spam'] );
601
- }
602
-
603
- // Pre-fetch data associated with activity users and other objects.
604
- BP_Activity_Activity::prefetch_object_data( $activities );
605
-
606
- // Generate action strings.
607
- $activities = BP_Activity_Activity::generate_action_strings( $activities );
608
- }
609
-
610
- $retval['activities'] = $activities;
611
-
612
- // If $max is set, only return up to the max results.
613
- if ( ! empty( $r['count_total'] ) ) {
614
-
615
- /**
616
- * Filters the total activities MySQL statement.
617
- *
618
- * @since 1.5.0
619
- *
620
- * @param string $value MySQL statement used to query for total activities.
621
- * @param string $where_sql MySQL WHERE statement portion.
622
- * @param string $sort Sort direction for query.
623
- */
624
- $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 );
625
- $total_activities = $wpdb->get_var( $total_activities_sql );
626
-
627
- if ( !empty( $r['max'] ) ) {
628
- if ( (int) $total_activities > (int) $r['max'] ) {
629
- $total_activities = $r['max'];
630
- }
631
- }
632
-
633
- $retval['total'] = $total_activities;
634
- }
635
-
636
- return $retval;
637
- }
638
-
639
- /**
640
- * Convert activity IDs to activity objects, as expected in template loop.
641
- *
642
- * @since 2.0.0
643
- *
644
- * @param array $activity_ids Array of activity IDs.
645
- * @return array
646
- */
647
- protected static function get_activity_data( $activity_ids = array() ) {
648
- global $wpdb;
649
-
650
- // Bail if no activity ID's passed.
651
- if ( empty( $activity_ids ) ) {
652
- return array();
653
- }
654
-
655
- // Get BuddyPress.
656
- $bp = buddypress();
657
-
658
- $activities = array();
659
- $uncached_ids = bp_get_non_cached_ids( $activity_ids, 'bp_activity' );
660
-
661
- // Prime caches as necessary.
662
- if ( ! empty( $uncached_ids ) ) {
663
- // Format the activity ID's for use in the query below.
664
- $uncached_ids_sql = implode( ',', wp_parse_id_list( $uncached_ids ) );
665
-
666
- // Fetch data from activity table, preserving order.
667
- $queried_adata = $wpdb->get_results( "SELECT * FROM {$bp->activity->table_name} WHERE id IN ({$uncached_ids_sql})");
668
-
669
- // Put that data into the placeholders created earlier,
670
- // and add it to the cache.
671
- foreach ( (array) $queried_adata as $adata ) {
672
- wp_cache_set( $adata->id, $adata, 'bp_activity' );
673
- }
674
- }
675
-
676
- // Now fetch data from the cache.
677
- foreach ( $activity_ids as $activity_id ) {
678
- $activities[] = wp_cache_get( $activity_id, 'bp_activity' );
679
- }
680
-
681
- // Then fetch user data.
682
- $user_query = new BP_User_Query( array(
683
- 'user_ids' => wp_list_pluck( $activities, 'user_id' ),
684
- 'populate_extras' => false,
685
- ) );
686
-
687
- // Associated located user data with activity items.
688
- foreach ( $activities as $a_index => $a_item ) {
689
- $a_user_id = intval( $a_item->user_id );
690
- $a_user = isset( $user_query->results[ $a_user_id ] ) ? $user_query->results[ $a_user_id ] : '';
691
-
692
- if ( !empty( $a_user ) ) {
693
- $activities[ $a_index ]->user_email = $a_user->user_email;
694
- $activities[ $a_index ]->user_nicename = $a_user->user_nicename;
695
- $activities[ $a_index ]->user_login = $a_user->user_login;
696
- $activities[ $a_index ]->display_name = $a_user->display_name;
697
- }
698
- }
699
-
700
- return $activities;
701
- }
702
-
703
- /**
704
- * Append xProfile fullnames to an activity array.
705
- *
706
- * @since 2.0.0
707
- *
708
- * @param array $activities Activities array.
709
- * @return array
710
- */
711
- protected static function append_user_fullnames( $activities ) {
712
-
713
- if ( bp_is_active( 'xprofile' ) && ! empty( $activities ) ) {
714
- $activity_user_ids = wp_list_pluck( $activities, 'user_id' );
715
-
716
- if ( ! empty( $activity_user_ids ) ) {
717
- $fullnames = bp_core_get_user_displaynames( $activity_user_ids );
718
- if ( ! empty( $fullnames ) ) {
719
- foreach ( (array) $activities as $i => $activity ) {
720
- if ( ! empty( $fullnames[ $activity->user_id ] ) ) {
721
- $activities[ $i ]->user_fullname = $fullnames[ $activity->user_id ];
722
- }
723
- }
724
- }
725
- }
726
- }
727
-
728
- return $activities;
729
- }
730
-
731
- /**
732
- * Pre-fetch data for objects associated with activity items.
733
- *
734
- * Activity items are associated with users, and often with other
735
- * BuddyPress data objects. Here, we pre-fetch data about these
736
- * associated objects, so that inline lookups - done primarily when
737
- * building action strings - do not result in excess database queries.
738
- *
739
- * The only object data required for activity component activity types
740
- * (activity_update and activity_comment) is related to users, and that
741
- * info is fetched separately in BP_Activity_Activity::get_activity_data().
742
- * So this method contains nothing but a filter that allows other
743
- * components, such as bp-friends and bp-groups, to hook in and prime
744
- * their own caches at the beginning of an activity loop.
745
- *
746
- * @since 2.0.0
747
- *
748
- * @param array $activities Array of activities.
749
- * @return array $activities Array of activities.
750
- */
751
- protected static function prefetch_object_data( $activities ) {
752
-
753
- /**
754
- * Filters inside prefetch_object_data method to aid in pre-fetching object data associated with activity item.
755
- *
756
- * @since 2.0.0
757
- *
758
- * @param array $activities Array of activities.
759
- */
760
- return apply_filters( 'bp_activity_prefetch_object_data', $activities );
761
- }
762
-
763
- /**
764
- * Generate action strings for the activities located in BP_Activity_Activity::get().
765
- *
766
- * If no string can be dynamically generated for a given item
767
- * (typically because the activity type has not been properly
768
- * registered), the static 'action' value pulled from the database will
769
- * be left in place.
770
- *
771
- * @since 2.0.0
772
- *
773
- * @param array $activities Array of activities.
774
- * @return array
775
- */
776
- protected static function generate_action_strings( $activities ) {
777
- foreach ( $activities as $key => $activity ) {
778
- $generated_action = bp_activity_generate_action_string( $activity );
779
- if ( false !== $generated_action ) {
780
- $activity->action = $generated_action;
781
- }
782
-
783
- $activities[ $key ] = $activity;
784
- }
785
-
786
- return $activities;
787
- }
788
-
789
- /**
790
- * Get the SQL for the 'meta_query' param in BP_Activity_Activity::get().
791
- *
792
- * We use WP_Meta_Query to do the heavy lifting of parsing the
793
- * meta_query array and creating the necessary SQL clauses. However,
794
- * since BP_Activity_Activity::get() builds its SQL differently than
795
- * WP_Query, we have to alter the return value (stripping the leading
796
- * AND keyword from the 'where' clause).
797
- *
798
- * @since 1.8.0
799
- *
800
- * @param array $meta_query An array of meta_query filters. See the
801
- * documentation for WP_Meta_Query for details.
802
- * @return array $sql_array 'join' and 'where' clauses.
803
- */
804
- public static function get_meta_query_sql( $meta_query = array() ) {
805
- global $wpdb;
806
-
807
- $sql_array = array(
808
- 'join' => '',
809
- 'where' => '',
810
- );
811
-
812
- if ( ! empty( $meta_query ) ) {
813
- $activity_meta_query = new WP_Meta_Query( $meta_query );
814
-
815
- // WP_Meta_Query expects the table name at
816
- // $wpdb->activitymeta.
817
- $wpdb->activitymeta = buddypress()->activity->table_name_meta;
818
-
819
- $meta_sql = $activity_meta_query->get_sql( 'activity', 'a', 'id' );
820
-
821
- // Strip the leading AND - BP handles it in get().
822
- $sql_array['where'] = preg_replace( '/^\sAND/', '', $meta_sql['where'] );
823
- $sql_array['join'] = $meta_sql['join'];
824
- }
825
-
826
- return $sql_array;
827
- }
828
-
829
- /**
830
- * Get the SQL for the 'date_query' param in BP_Activity_Activity::get().
831
- *
832
- * We use BP_Date_Query, which extends WP_Date_Query, to do the heavy lifting
833
- * of parsing the date_query array and creating the necessary SQL clauses.
834
- * However, since BP_Activity_Activity::get() builds its SQL differently than
835
- * WP_Query, we have to alter the return value (stripping the leading AND
836
- * keyword from the query).
837
- *
838
- * @since 2.1.0
839
- *
840
- * @param array $date_query An array of date_query parameters. See the
841
- * documentation for the first parameter of WP_Date_Query.
842
- * @return string
843
- */
844
- public static function get_date_query_sql( $date_query = array() ) {
845
- $sql = '';
846
-
847
- // Date query.
848
- if ( ! empty( $date_query ) && is_array( $date_query ) ) {
849
- $date_query = new BP_Date_Query( $date_query, 'date_recorded' );
850
- $sql = preg_replace( '/^\sAND/', '', $date_query->get_sql() );
851
- }
852
-
853
- return $sql;
854
- }
855
-
856
- /**
857
- * Get the SQL for the 'scope' param in BP_Activity_Activity::get().
858
- *
859
- * A scope is a predetermined set of activity arguments. This method is used
860
- * to grab these activity arguments and override any existing args if needed.
861
- *
862
- * Can handle multiple scopes.
863
- *
864
- * @since 2.2.0
865
- *
866
- * @param mixed $scope The activity scope. Accepts string or array of scopes.
867
- * @param array $r Current activity arguments. Same as those of BP_Activity_Activity::get(),
868
- * but merged with defaults.
869
- * @return array 'sql' WHERE SQL string and 'override' activity args.
870
- */
871
- public static function get_scope_query_sql( $scope = false, $r = array() ) {
872
-
873
- // Define arrays for future use.
874
- $query_args = array();
875
- $override = array();
876
- $retval = array();
877
-
878
- // Check for array of scopes.
879
- if ( is_array( $scope ) ) {
880
- $scopes = $scope;
881
-
882
- // Explode a comma separated string of scopes.
883
- } elseif ( is_string( $scope ) ) {
884
- $scopes = explode( ',', $scope );
885
- }
886
-
887
- // Bail if no scope passed.
888
- if ( empty( $scopes ) ) {
889
- return false;
890
- }
891
-
892
- // Helper to easily grab the 'user_id'.
893
- if ( ! empty( $r['filter']['user_id'] ) ) {
894
- $r['user_id'] = $r['filter']['user_id'];
895
- }
896
-
897
- // Parse each scope; yes! we handle multiples!
898
- foreach ( $scopes as $scope ) {
899
- $scope_args = array();
900
-
901
- /**
902
- * Plugins can hook here to set their activity arguments for custom scopes.
903
- *
904
- * This is a dynamic filter based on the activity scope. eg:
905
- * - 'bp_activity_set_groups_scope_args'
906
- * - 'bp_activity_set_friends_scope_args'
907
- *
908
- * To see how this filter is used, plugin devs should check out:
909
- * - bp_groups_filter_activity_scope() - used for 'groups' scope
910
- * - bp_friends_filter_activity_scope() - used for 'friends' scope
911
- *
912
- * @since 2.2.0
913
- *
914
- * @param array {
915
- * Activity query clauses.
916
- * @type array {
917
- * Activity arguments for your custom scope.
918
- * See {@link BP_Activity_Query::_construct()} for more details.
919
- * }
920
- * @type array $override Optional. Override existing activity arguments passed by $r.
921
- * }
922
- * @param array $r Current activity arguments passed in BP_Activity_Activity::get().
923
- */
924
- $scope_args = apply_filters( "bp_activity_set_{$scope}_scope_args", array(), $r );
925
-
926
- if ( ! empty( $scope_args ) ) {
927
- // Merge override properties from other scopes
928
- // this might be a problem...
929
- if ( ! empty( $scope_args['override'] ) ) {
930
- $override = array_merge( $override, $scope_args['override'] );
931
- unset( $scope_args['override'] );
932
- }
933
-
934
- // Save scope args.
935
- if ( ! empty( $scope_args ) ) {
936
- $query_args[] = $scope_args;
937
- }
938
- }
939
- }
940
-
941
- if ( ! empty( $query_args ) ) {
942
- // Set relation to OR.
943
- $query_args['relation'] = 'OR';
944
-
945
- $query = new BP_Activity_Query( $query_args );
946
- $sql = $query->get_sql();
947
- if ( ! empty( $sql ) ) {
948
- $retval['sql'] = $sql;
949
- }
950
- }
951
-
952
- if ( ! empty( $override ) ) {
953
- $retval['override'] = $override;
954
- }
955
-
956
- return $retval;
957
- }
958
-
959
- /**
960
- * In BuddyPress 1.2.x, this was used to retrieve specific activity stream items (for example, on an activity's permalink page).
961
- *
962
- * As of 1.5.x, use BP_Activity_Activity::get() with an 'in' parameter instead.
963
- *
964
- * @since 1.2.0
965
- *
966
- * @deprecated 1.5
967
- * @deprecated Use BP_Activity_Activity::get() with an 'in' parameter instead.
968
- *
969
- * @param mixed $activity_ids Array or comma-separated string of activity IDs to retrieve.
970
- * @param int|bool $max Maximum number of results to return. (Optional; default is no maximum).
971
- * @param int $page The set of results that the user is viewing. Used in pagination. (Optional; default is 1).
972
- * @param int $per_page Specifies how many results per page. Used in pagination. (Optional; default is 25).
973
- * @param string $sort MySQL column sort; ASC or DESC. (Optional; default is DESC).
974
- * @param bool $display_comments Retrieve an activity item's associated comments or not. (Optional; default is false).
975
- * @return array
976
- */
977
- public static function get_specific( $activity_ids, $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $display_comments = false ) {
978
- _deprecated_function( __FUNCTION__, '1.5', 'Use BP_Activity_Activity::get() with the "in" parameter instead.' );
979
- return BP_Activity_Activity::get( $max, $page, $per_page, $sort, false, false, $display_comments, false, false, $activity_ids );
980
- }
981
-
982
- /**
983
- * Get the first activity ID that matches a set of criteria.
984
- *
985
- * @todo Should parameters be optional?
986
- *
987
- * @param int $user_id User ID to filter by.
988
- * @param string $component Component to filter by.
989
- * @param string $type Activity type to filter by.
990
- * @param int $item_id Associated item to filter by.
991
- * @param int $secondary_item_id Secondary associated item to filter by.
992
- * @param string $action Action to filter by.
993
- * @param string $content Content to filter by.
994
- * @param string $date_recorded Date to filter by.
995
- * @return int|bool Activity ID on success, false if none is found.
996
- */
997
- public static function get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content, $date_recorded ) {
998
- global $wpdb;
999
-
1000
- $bp = buddypress();
1001
-
1002
- $where_args = false;
1003
-
1004
- if ( ! empty( $user_id ) ) {
1005
- $where_args[] = $wpdb->prepare( "user_id = %d", $user_id );
1006
- }
1007
-
1008
- if ( ! empty( $component ) ) {
1009
- $where_args[] = $wpdb->prepare( "component = %s", $component );
1010
- }
1011
-
1012
- if ( ! empty( $type ) ) {
1013
- $where_args[] = $wpdb->prepare( "type = %s", $type );
1014
- }
1015
-
1016
- if ( ! empty( $item_id ) ) {
1017
- $where_args[] = $wpdb->prepare( "item_id = %d", $item_id );
1018
- }
1019
-
1020
- if ( ! empty( $secondary_item_id ) ) {
1021
- $where_args[] = $wpdb->prepare( "secondary_item_id = %d", $secondary_item_id );
1022
- }
1023
-
1024
- if ( ! empty( $action ) ) {
1025
- $where_args[] = $wpdb->prepare( "action = %s", $action );
1026
- }
1027
-
1028
- if ( ! empty( $content ) ) {
1029
- $where_args[] = $wpdb->prepare( "content = %s", $content );
1030
- }
1031
-
1032
- if ( ! empty( $date_recorded ) ) {
1033
- $where_args[] = $wpdb->prepare( "date_recorded = %s", $date_recorded );
1034
- }
1035
-
1036
- if ( ! empty( $where_args ) ) {
1037
- $where_sql = 'WHERE ' . join( ' AND ', $where_args );
1038
- return $wpdb->get_var( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" );
1039
- }
1040
-
1041
- return false;
1042
- }
1043
-
1044
- /**
1045
- * Delete activity items from the database.
1046
- *
1047
- * To delete a specific activity item, pass an 'id' parameter.
1048
- * Otherwise use the filters.
1049
- *
1050
- * @since 1.2.0
1051
- *
1052
- * @param array $args {
1053
- * @int $id Optional. The ID of a specific item to delete.
1054
- * @string $action Optional. The action to filter by.
1055
- * @string $content Optional. The content to filter by.
1056
- * @string $component Optional. The component name to filter by.
1057
- * @string $type Optional. The activity type to filter by.
1058
- * @string $primary_link Optional. The primary URL to filter by.
1059
- * @int $user_id Optional. The user ID to filter by.
1060
- * @int $item_id Optional. The associated item ID to filter by.
1061
- * @int $secondary_item_id Optional. The secondary associated item ID to filter by.
1062
- * @string $date_recorded Optional. The date to filter by.
1063
- * @int $hide_sitewide Optional. Default: false.
1064
- * }
1065
- * @return array|bool An array of deleted activity IDs on success, false on failure.
1066
- */
1067
- public static function delete( $args = array() ) {
1068
- global $wpdb;
1069
-
1070
- $bp = buddypress();
1071
- $r = wp_parse_args( $args, array(
1072
- 'id' => false,
1073
- 'action' => false,
1074
- 'content' => false,
1075
- 'component' => false,
1076
- 'type' => false,
1077
- 'primary_link' => false,
1078
- 'user_id' => false,
1079
- 'item_id' => false,
1080
- 'secondary_item_id' => false,
1081
- 'date_recorded' => false,
1082
- 'hide_sitewide' => false
1083
- ) );
1084
-
1085
- // Setup empty array from where query arguments.
1086
- $where_args = array();
1087
-
1088
- // ID.
1089
- if ( ! empty( $r['id'] ) ) {
1090
- $where_args[] = $wpdb->prepare( "id = %d", $r['id'] );
1091
- }
1092
-
1093
- // User ID.
1094
- if ( ! empty( $r['user_id'] ) ) {
1095
- $where_args[] = $wpdb->prepare( "user_id = %d", $r['user_id'] );
1096
- }
1097
-
1098
- // Action.
1099
- if ( ! empty( $r['action'] ) ) {
1100
- $where_args[] = $wpdb->prepare( "action = %s", $r['action'] );
1101
- }
1102
-
1103
- // Content.
1104
- if ( ! empty( $r['content'] ) ) {
1105
- $where_args[] = $wpdb->prepare( "content = %s", $r['content'] );
1106
- }
1107
-
1108
- // Component.
1109
- if ( ! empty( $r['component'] ) ) {
1110
- $where_args[] = $wpdb->prepare( "component = %s", $r['component'] );
1111
- }
1112
-
1113
- // Type.
1114
- if ( ! empty( $r['type'] ) ) {
1115
- $where_args[] = $wpdb->prepare( "type = %s", $r['type'] );
1116
- }
1117
-
1118
- // Primary Link.
1119
- if ( ! empty( $r['primary_link'] ) ) {
1120
- $where_args[] = $wpdb->prepare( "primary_link = %s", $r['primary_link'] );
1121
- }
1122
-
1123
- // Item ID.
1124
- if ( ! empty( $r['item_id'] ) ) {
1125
- $where_args[] = $wpdb->prepare( "item_id = %d", $r['item_id'] );
1126
- }
1127
-
1128
- // Secondary item ID.
1129
- if ( ! empty( $r['secondary_item_id'] ) ) {
1130
- $where_args[] = $wpdb->prepare( "secondary_item_id = %d", $r['secondary_item_id'] );
1131
- }
1132
-
1133
- // Date Recorded.
1134
- if ( ! empty( $r['date_recorded'] ) ) {
1135
- $where_args[] = $wpdb->prepare( "date_recorded = %s", $r['date_recorded'] );
1136
- }
1137
-
1138
- // Hidden sitewide.
1139
- if ( ! empty( $r['hide_sitewide'] ) ) {
1140
- $where_args[] = $wpdb->prepare( "hide_sitewide = %d", $r['hide_sitewide'] );
1141
- }
1142
-
1143
- // Bail if no where arguments.
1144
- if ( empty( $where_args ) ) {
1145
- return false;
1146
- }
1147
-
1148
- // Join the where arguments for querying.
1149
- $where_sql = 'WHERE ' . join( ' AND ', $where_args );
1150
-
1151
- // Fetch all activities being deleted so we can perform more actions.
1152
- $activities = $wpdb->get_results( "SELECT * FROM {$bp->activity->table_name} {$where_sql}" );
1153
-
1154
- /**
1155
- * Action to allow intercepting activity items to be deleted.
1156
- *
1157
- * @since 2.3.0
1158
- *
1159
- * @param array $activities Array of activities.
1160
- * @param array $r Array of parsed arguments.
1161
- */
1162
- do_action_ref_array( 'bp_activity_before_delete', array( $activities, $r ) );
1163
-
1164
- // Attempt to delete activities from the database.
1165
- $deleted = $wpdb->query( "DELETE FROM {$bp->activity->table_name} {$where_sql}" );
1166
-
1167
- // Bail if nothing was deleted.
1168
- if ( empty( $deleted ) ) {
1169
- return false;
1170
- }
1171
-
1172
- /**
1173
- * Action to allow intercepting activity items just deleted.
1174
- *
1175
- * @since 2.3.0
1176
- *
1177
- * @param array $activities Array of activities.
1178
- * @param array $r Array of parsed arguments.
1179
- */
1180
- do_action_ref_array( 'bp_activity_after_delete', array( $activities, $r ) );
1181
-
1182
- // Pluck the activity IDs out of the $activities array.
1183
- $activity_ids = wp_parse_id_list( wp_list_pluck( $activities, 'id' ) );
1184
-
1185
- // Handle accompanying activity comments and meta deletion.
1186
- if ( ! empty( $activity_ids ) ) {
1187
-
1188
- // Delete all activity meta entries for activity items.
1189
- BP_Activity_Activity::delete_activity_meta_entries( $activity_ids );
1190
-
1191
- // Setup empty array for comments.
1192
- $comment_ids = array();
1193
-
1194
- // Loop through activity ids and attempt to delete comments.
1195
- foreach ( $activity_ids as $activity_id ) {
1196
-
1197
- // Attempt to delete comments.
1198
- $comments = BP_Activity_Activity::delete( array(
1199
- 'type' => 'activity_comment',
1200
- 'item_id' => $activity_id
1201
- ) );
1202
-
1203
- // Merge IDs together.
1204
- if ( ! empty( $comments ) ) {
1205
- $comment_ids = array_merge( $comment_ids, $comments );
1206
- }
1207
- }
1208
-
1209
- // Merge activity IDs with any deleted comment IDs.
1210
- if ( ! empty( $comment_ids ) ) {
1211
- $activity_ids = array_unique( array_merge( $activity_ids, $comment_ids ) );
1212
- }
1213
- }
1214
-
1215
- return $activity_ids;
1216
- }
1217
-
1218
- /**
1219
- * Delete the comments associated with a set of activity items.
1220
- *
1221
- * This method is no longer used by BuddyPress, and it is recommended not to
1222
- * use it going forward, and use BP_Activity_Activity::delete() instead.
1223
- *
1224
- * @since 1.2.0
1225
- * @deprecated 2.3.0
1226
- *
1227
- * @param array $activity_ids Activity IDs whose comments should be deleted.
1228
- * @param bool $delete_meta Should we delete the activity meta items for these comments.
1229
- *
1230
- * @return bool True on success.
1231
- */
1232
- public static function delete_activity_item_comments( $activity_ids = array(), $delete_meta = true ) {
1233
- global $wpdb;
1234
-
1235
- $bp = buddypress();
1236
-
1237
- $delete_meta = (bool) $delete_meta;
1238
- $activity_ids = implode( ',', wp_parse_id_list( $activity_ids ) );
1239
-
1240
- if ( $delete_meta ) {
1241
- // Fetch the activity comment IDs for our deleted activity items.
1242
- $activity_comment_ids = $wpdb->get_col( "SELECT id FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND item_id IN ({$activity_ids})" );
1243
-
1244
- if ( ! empty( $activity_comment_ids ) ) {
1245
- self::delete_activity_meta_entries( $activity_comment_ids );
1246
- }
1247
- }
1248
-
1249
- return $wpdb->query( "DELETE FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND item_id IN ({$activity_ids})" );
1250
- }
1251
-
1252
- /**
1253
- * Delete the meta entries associated with a set of activity items.
1254
- *
1255
- * @since 1.2.0
1256
- *
1257
- * @param array $activity_ids Activity IDs whose meta should be deleted.
1258
- * @return bool True on success.
1259
- */
1260
- public static function delete_activity_meta_entries( $activity_ids = array() ) {
1261
- $activity_ids = wp_parse_id_list( $activity_ids );
1262
-
1263
- foreach ( $activity_ids as $activity_id ) {
1264
- bp_activity_delete_meta( $activity_id );
1265
- }
1266
-
1267
- return true;
1268
- }
1269
-
1270
- /**
1271
- * Append activity comments to their associated activity items.
1272
- *
1273
- * @since 1.2.0
1274
- *
1275
- * @global wpdb $wpdb WordPress database object.
1276
- *
1277
- * @param array $activities Activities to fetch comments for.
1278
- * @param string $spam Optional. 'ham_only' (default), 'spam_only' or 'all'.
1279
- * @return array The updated activities with nested comments.
1280
- */
1281
- public static function append_comments( $activities, $spam = 'ham_only' ) {
1282
- $activity_comments = array();
1283
-
1284
- // Now fetch the activity comments and parse them into the correct position in the activities array.
1285
- foreach ( (array) $activities as $activity ) {
1286
- $top_level_parent_id = 'activity_comment' == $activity->type ? $activity->item_id : 0;
1287
- $activity_comments[$activity->id] = BP_Activity_Activity::get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right, $spam, $top_level_parent_id );
1288
- }
1289
-
1290
- // Merge the comments with the activity items.
1291
- foreach ( (array) $activities as $key => $activity ) {
1292
- if ( isset( $activity_comments[$activity->id] ) ) {
1293
- $activities[$key]->children = $activity_comments[$activity->id];
1294
- }
1295
- }
1296
-
1297
- return $activities;
1298
- }
1299
-
1300
- /**
1301
- * Get activity comments that are associated with a specific activity ID.
1302
- *
1303
- * @since 1.2.0
1304
- *
1305
- * @global wpdb $wpdb WordPress database object.
1306
- *
1307
- * @param int $activity_id Activity ID to fetch comments for.
1308
- * @param int $left Left-most node boundary.
1309
- * @param int $right Right-most node boundary.
1310
- * @param string $spam Optional. 'ham_only' (default), 'spam_only' or 'all'.
1311
- * @param int $top_level_parent_id Optional. The id of the root-level parent activity item.
1312
- * @return array The updated activities with nested comments.
1313
- */
1314
- public static function get_activity_comments( $activity_id, $left, $right, $spam = 'ham_only', $top_level_parent_id = 0 ) {
1315
- global $wpdb;
1316
-
1317
- if ( empty( $top_level_parent_id ) ) {
1318
- $top_level_parent_id = $activity_id;
1319
- }
1320
-
1321
- $comments = wp_cache_get( $activity_id, 'bp_activity_comments' );
1322
-
1323
- // We store the string 'none' to cache the fact that the
1324
- // activity item has no comments.
1325
- if ( 'none' === $comments ) {
1326
- $comments = false;
1327
-
1328
- // A true cache miss.
1329
- } elseif ( empty( $comments ) ) {
1330
-
1331
- $bp = buddypress();
1332
-
1333
- // Select the user's fullname with the query.
1334
- if ( bp_is_active( 'xprofile' ) ) {
1335
- $fullname_select = ", pd.value as user_fullname";
1336
- $fullname_from = ", {$bp->profile->table_name_data} pd ";
1337
- $fullname_where = "AND pd.user_id = a.user_id AND pd.field_id = 1";
1338
-
1339
- // Prevent debug errors.
1340
- } else {
1341
- $fullname_select = $fullname_from = $fullname_where = '';
1342
- }
1343
-
1344
- // Don't retrieve activity comments marked as spam.
1345
- if ( 'ham_only' == $spam ) {
1346
- $spam_sql = 'AND a.is_spam = 0';
1347
- } elseif ( 'spam_only' == $spam ) {
1348
- $spam_sql = 'AND a.is_spam = 1';
1349
- } else {
1350
- $spam_sql = '';
1351
- }
1352
-
1353
- // Legacy query - not recommended.
1354
- $func_args = func_get_args();
1355
-
1356
- /**
1357
- * Filters if BuddyPress should use the legacy activity query.
1358
- *
1359
- * @since 2.0.0
1360
- *
1361
- * @param bool $value Whether or not to use the legacy query.
1362
- * @param BP_Activity_Activity $value Magic method referring to currently called method.
1363
- * @param array $func_args Array of the method's argument list.
1364
- */
1365
- if ( apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, $func_args ) ) {
1366
-
1367
- /**
1368
- * Filters the MySQL prepared statement for the legacy activity query.
1369
- *
1370
- * @since 1.5.0
1371
- *
1372
- * @param string $value Prepared statement for the activity query.
1373
- * @param int $activity_id Activity ID to fetch comments for.
1374
- * @param int $left Left-most node boundary.
1375
- * @param int $right Right-most node boundary.
1376
- * @param string $spam_sql SQL Statement portion to differentiate between ham or spam.
1377
- */
1378
- $sql = apply_filters( 'bp_activity_comments_user_join_filter', $wpdb->prepare( "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp->activity->table_name} a, {$wpdb->users} u{$fullname_from} WHERE u.ID = a.user_id {$fullname_where} AND a.type = 'activity_comment' {$spam_sql} AND a.item_id = %d AND a.mptt_left > %d AND a.mptt_left < %d ORDER BY a.date_recorded ASC", $top_level_parent_id, $left, $right ), $activity_id, $left, $right, $spam_sql );
1379
-
1380
- $descendants = $wpdb->get_results( $sql );
1381
-
1382
- // We use the mptt BETWEEN clause to limit returned
1383
- // descendants to the correct part of the tree.
1384
- } else {
1385
- $sql = $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} a WHERE a.type = 'activity_comment' {$spam_sql} AND a.item_id = %d and a.mptt_left > %d AND a.mptt_left < %d ORDER BY a.date_recorded ASC", $top_level_parent_id, $left, $right );
1386
-
1387
- $descendant_ids = $wpdb->get_col( $sql );
1388
- $descendants = self::get_activity_data( $descendant_ids );
1389
- $descendants = self::append_user_fullnames( $descendants );
1390
- }
1391
-
1392
- $ref = array();
1393
-
1394
- // Loop descendants and build an assoc array.
1395
- foreach ( (array) $descendants as $d ) {
1396
- $d->children = array();
1397
-
1398
- // If we have a reference on the parent.
1399
- if ( isset( $ref[ $d->secondary_item_id ] ) ) {
1400
- $ref[ $d->secondary_item_id ]->children[ $d->id ] = $d;
1401
- $ref[ $d->id ] =& $ref[ $d->secondary_item_id ]->children[ $d->id ];
1402
-
1403
- // If we don't have a reference on the parent, put in the root level.
1404
- } else {
1405
- $comments[ $d->id ] = $d;
1406
- $ref[ $d->id ] =& $comments[ $d->id ];
1407
- }
1408
- }
1409
-
1410
- // Calculate depth for each item.
1411
- foreach ( $ref as &$r ) {
1412
- $depth = 1;
1413
- $parent_id = $r->secondary_item_id;
1414
-
1415
- while ( $parent_id !== $r->item_id ) {
1416
- $depth++;
1417
-
1418
- // When display_comments=stream, the parent comment may not be part of the
1419
- // returned results, so we manually fetch it.
1420
- if ( empty( $ref[ $parent_id ] ) ) {
1421
- $direct_parent = new BP_Activity_Activity( $parent_id );
1422
- if ( isset( $direct_parent->secondary_item_id ) ) {
1423
- // If the direct parent is not an activity update, that means we've reached
1424
- // the parent activity item (eg. new_blog_post).
1425
- if ( 'activity_update' !== $direct_parent->type ) {
1426
- $parent_id = $r->item_id;
1427
-
1428
- } else {
1429
- $parent_id = $direct_parent->secondary_item_id;
1430
- }
1431
-
1432
- } else {
1433
- // Something went wrong. Short-circuit the depth calculation.
1434
- $parent_id = $r->item_id;
1435
- }
1436
- } else {
1437
- $parent_id = $ref[ $parent_id ]->secondary_item_id;
1438
- }
1439
- }
1440
- $r->depth = $depth;
1441
- }
1442
-
1443
- // If we cache a value of false, it'll count as a cache
1444
- // miss the next time the activity comments are fetched.
1445
- // Storing the string 'none' is a hack workaround to
1446
- // avoid unnecessary queries.
1447
- if ( false === $comments ) {
1448
- $cache_value = 'none';
1449
- } else {
1450
- $cache_value = $comments;
1451
- }
1452
-
1453
- wp_cache_set( $activity_id, $cache_value, 'bp_activity_comments' );
1454
- }
1455
-
1456
- return $comments;
1457
- }
1458
-
1459
- /**
1460
- * Rebuild nested comment tree under an activity or activity comment.
1461
- *
1462
- * @since 1.2.0
1463
- *
1464
- * @global wpdb $wpdb WordPress database object.
1465
- *
1466
- * @param int $parent_id ID of an activity or activity comment.
1467
- * @param int $left Node boundary start for activity or activity comment.
1468
- * @return int Right Node boundary of activity or activity comment.
1469
- */
1470
- public static function rebuild_activity_comment_tree( $parent_id, $left = 1 ) {
1471
- global $wpdb;
1472
-
1473
- $bp = buddypress();
1474
-
1475
- // The right value of this node is the left value + 1.
1476
- $right = intval( $left + 1 );
1477
-
1478
- // Get all descendants of this node.
1479
- $comments = BP_Activity_Activity::get_child_comments( $parent_id );
1480
- $descendants = wp_list_pluck( $comments, 'id' );
1481
-
1482
- // Loop the descendants and recalculate the left and right values.
1483
- foreach ( (array) $descendants as $descendant_id ) {
1484
- $right = BP_Activity_Activity::rebuild_activity_comment_tree( $descendant_id, $right );
1485
- }
1486
-
1487
- // We've got the left value, and now that we've processed the children
1488
- // of this node we also know the right value.
1489
- if ( 1 === $left ) {
1490
- $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE id = %d", $left, $right, $parent_id ) );
1491
- } else {
1492
- $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE type = 'activity_comment' AND id = %d", $left, $right, $parent_id ) );
1493
- }
1494
-
1495
- // Return the right value of this node + 1.
1496
- return intval( $right + 1 );
1497
- }
1498
-
1499
- /**
1500
- * Get child comments of an activity or activity comment.
1501
- *
1502
- * @since 1.2.0
1503
- *
1504
- * @global wpdb $wpdb WordPress database object.
1505
- *
1506
- * @param int $parent_id ID of an activity or activity comment.
1507
- * @return object Numerically indexed array of child comments.
1508
- */
1509
- public static function get_child_comments( $parent_id ) {
1510
- global $wpdb;
1511
-
1512
- $bp = buddypress();
1513
-
1514
- return $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND secondary_item_id = %d", $parent_id ) );
1515
- }
1516
-
1517
- /**
1518
- * Get a list of components that have recorded activity associated with them.
1519
- *
1520
- * @param bool $skip_last_activity If true, components will not be
1521
- * included if the only activity type associated with them is
1522
- * 'last_activity'. (Since 2.0.0, 'last_activity' is stored in
1523
- * the activity table, but these items are not full-fledged
1524
- * activity items.) Default: true.
1525
- * @return array List of component names.
1526
- */
1527
- public static function get_recorded_components( $skip_last_activity = true ) {
1528
- global $wpdb;
1529
-
1530
- $bp = buddypress();
1531
-
1532
- if ( true === $skip_last_activity ) {
1533
- $components = $wpdb->get_col( "SELECT DISTINCT component FROM {$bp->activity->table_name} WHERE action != '' AND action != 'last_activity' ORDER BY component ASC" );
1534
- } else {
1535
- $components = $wpdb->get_col( "SELECT DISTINCT component FROM {$bp->activity->table_name} ORDER BY component ASC" );
1536
- }
1537
-
1538
- return $components;
1539
- }
1540
-
1541
- /**
1542
- * Get sitewide activity items for use in an RSS feed.
1543
- *
1544
- * @param int $limit Optional. Number of items to fetch. Default: 35.
1545
- * @return array $activity_feed List of activity items, with RSS data added.
1546
- */
1547
- public static function get_sitewide_items_for_feed( $limit = 35 ) {
1548
- $activities = bp_activity_get_sitewide( array( 'max' => $limit ) );
1549
- $activity_feed = array();
1550
-
1551
- for ( $i = 0, $count = count( $activities ); $i < $count; ++$i ) {
1552
- $title = explode( '<span', $activities[$i]['content'] );
1553
- $activity_feed[$i]['title'] = trim( strip_tags( $title[0] ) );
1554
- $activity_feed[$i]['link'] = $activities[$i]['primary_link'];
1555
- $activity_feed[$i]['description'] = @sprintf( $activities[$i]['content'], '' );
1556
- $activity_feed[$i]['pubdate'] = $activities[$i]['date_recorded'];
1557
- }
1558
-
1559
- return $activity_feed;
1560
- }
1561
-
1562
- /**
1563
- * Create SQL IN clause for filter queries.
1564
- *
1565
- * @since 1.5.0
1566
- *
1567
- * @see BP_Activity_Activity::get_filter_sql()
1568
- *
1569
- * @param string $field The database field.
1570
- * @param array|bool $items The values for the IN clause, or false when none are found.
1571
- * @return string|bool
1572
- */
1573
- public static function get_in_operator_sql( $field, $items ) {
1574
- global $wpdb;
1575
-
1576
- // Split items at the comma.
1577
- if ( ! is_array( $items ) ) {
1578
- $items = explode( ',', $items );
1579
- }
1580
-
1581
- // Array of prepared integers or quoted strings.
1582
- $items_prepared = array();
1583
-
1584
- // Clean up and format each item.
1585
- foreach ( $items as $item ) {
1586
- // Clean up the string.
1587
- $item = trim( $item );
1588
- // Pass everything through prepare for security and to safely quote strings.
1589
- $items_prepared[] = ( is_numeric( $item ) ) ? $wpdb->prepare( '%d', $item ) : $wpdb->prepare( '%s', $item );
1590
- }
1591
-
1592
- // Build IN operator sql syntax.
1593
- if ( count( $items_prepared ) )
1594
- return sprintf( '%s IN ( %s )', trim( $field ), implode( ',', $items_prepared ) );
1595
- else
1596
- return false;
1597
- }
1598
-
1599
- /**
1600
- * Create filter SQL clauses.
1601
- *
1602
- * @since 1.5.0
1603
- *
1604
- * @param array $filter_array {
1605
- * Fields and values to filter by.
1606
- *
1607
- * @type array|string|int $user_id User ID(s).
1608
- * @type array|string $object Corresponds to the 'component'
1609
- * column in the database.
1610
- * @type array|string $action Corresponds to the 'type' column
1611
- * in the database.
1612
- * @type array|string|int $primary_id Corresponds to the 'item_id'
1613
- * column in the database.
1614
- * @type array|string|int $secondary_id Corresponds to the
1615
- * 'secondary_item_id' column in the database.
1616
- * @type int $offset Return only those items with an ID greater
1617
- * than the offset value.
1618
- * @type string $since Return only those items that have a
1619
- * date_recorded value greater than a
1620
- * given MySQL-formatted date.
1621
- * }
1622
- * @return string The filter clause, for use in a SQL query.
1623
- */
1624
- public static function get_filter_sql( $filter_array ) {
1625
-
1626
- $filter_sql = array();
1627
-
1628
- if ( !empty( $filter_array['user_id'] ) ) {
1629
- $user_sql = BP_Activity_Activity::get_in_operator_sql( 'a.user_id', $filter_array['user_id'] );
1630
- if ( !empty( $user_sql ) )
1631
- $filter_sql[] = $user_sql;
1632
- }
1633
-
1634
- if ( !empty( $filter_array['object'] ) ) {
1635
- $object_sql = BP_Activity_Activity::get_in_operator_sql( 'a.component', $filter_array['object'] );
1636
- if ( !empty( $object_sql ) )
1637
- $filter_sql[] = $object_sql;
1638
- }
1639
-
1640
- if ( !empty( $filter_array['action'] ) ) {
1641
- $action_sql = BP_Activity_Activity::get_in_operator_sql( 'a.type', $filter_array['action'] );
1642
- if ( ! empty( $action_sql ) )
1643
- $filter_sql[] = $action_sql;
1644
- }
1645
-
1646
- if ( !empty( $filter_array['primary_id'] ) ) {
1647
- $pid_sql = BP_Activity_Activity::get_in_operator_sql( 'a.item_id', $filter_array['primary_id'] );
1648
- if ( !empty( $pid_sql ) )
1649
- $filter_sql[] = $pid_sql;
1650
- }
1651
-
1652
- if ( !empty( $filter_array['secondary_id'] ) ) {
1653
- $sid_sql = BP_Activity_Activity::get_in_operator_sql( 'a.secondary_item_id', $filter_array['secondary_id'] );
1654
- if ( !empty( $sid_sql ) )
1655
- $filter_sql[] = $sid_sql;
1656
- }
1657
-
1658
- if ( ! empty( $filter_array['offset'] ) ) {
1659
- $sid_sql = absint( $filter_array['offset'] );
1660
- $filter_sql[] = "a.id >= {$sid_sql}";
1661
- }
1662
-
1663
- if ( ! empty( $filter_array['since'] ) ) {
1664
- // Validate that this is a proper Y-m-d H:i:s date.
1665
- // Trick: parse to UNIX date then translate back.
1666
- $translated_date = date( 'Y-m-d H:i:s', strtotime( $filter_array['since'] ) );
1667
- if ( $translated_date === $filter_array['since'] ) {
1668
- $filter_sql[] = "a.date_recorded > '{$translated_date}'";
1669
- }
1670
- }
1671
-
1672
- if ( empty( $filter_sql ) )
1673
- return false;
1674
-
1675
- return join( ' AND ', $filter_sql );
1676
- }
1677
-
1678
- /**
1679
- * Get the date/time of last recorded activity.
1680
- *
1681
- * @since 1.2.0
1682
- *
1683
- * @return string ISO timestamp.
1684
- */
1685
- public static function get_last_updated() {
1686
- global $wpdb;
1687
-
1688
- $bp = buddypress();
1689
-
1690
- return $wpdb->get_var( "SELECT date_recorded FROM {$bp->activity->table_name} ORDER BY date_recorded DESC LIMIT 1" );
1691
- }
1692
-
1693
- /**
1694
- * Get favorite count for a given user.
1695
- *
1696
- * @since 1.2.0
1697
- *
1698
- * @param int $user_id The ID of the user whose favorites you're counting.
1699
- * @return int $value A count of the user's favorites.
1700
- */
1701
- public static function total_favorite_count( $user_id ) {
1702
-
1703
- // Get activities from user meta.
1704
- $favorite_activity_entries = bp_get_user_meta( $user_id, 'bp_favorite_activities', true );
1705
- if ( ! empty( $favorite_activity_entries ) ) {
1706
- return count( maybe_unserialize( $favorite_activity_entries ) );
1707
- }
1708
-
1709
- // No favorites.
1710
- return 0;
1711
- }
1712
-
1713
- /**
1714
- * Check whether an activity item exists with a given string content.
1715
- *
1716
- * @param string $content The content to filter by.
1717
- * @return int|bool The ID of the first matching item if found, otherwise false.
1718
- */
1719
- public static function check_exists_by_content( $content ) {
1720
- global $wpdb;
1721
-
1722
- $bp = buddypress();
1723
-
1724
- return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE content = %s", $content ) );
1725
- }
1726
-
1727
- /**
1728
- * Hide all activity for a given user.
1729
- *
1730
- * @param int $user_id The ID of the user whose activity you want to mark hidden.
1731
- * @return mixed
1732
- */
1733
- public static function hide_all_for_user( $user_id ) {
1734
- global $wpdb;
1735
-
1736
- $bp = buddypress();
1737
-
1738
- return $wpdb->get_var( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET hide_sitewide = 1 WHERE user_id = %d", $user_id ) );
1739
- }
1740
-
1741
- /**
1742
- * PHP-agnostic version of {@link array_replace_recursive()}.
1743
- *
1744
- * The array_replace_recursive() function is a PHP 5.3 function. BuddyPress (and
1745
- * WordPress) currently supports down to PHP 5.2, so this method is a workaround
1746
- * for PHP 5.2.
1747
- *
1748
- * Note: array_replace_recursive() supports infinite arguments, but for our use-
1749
- * case, we only need to support two arguments.
1750
- *
1751
- * Subject to removal once WordPress makes PHP 5.3.0 the minimum requirement.
1752
- *
1753
- * @since 2.2.0
1754
- *
1755
- * @see http://php.net/manual/en/function.array-replace-recursive.php#109390
1756
- *
1757
- * @param array $base Array with keys needing to be replaced.
1758
- * @param array $replacements Array with the replaced keys.
1759
- * @return array
1760
- */
1761
- protected static function array_replace_recursive( $base = array(), $replacements = array() ) {
1762
- if ( function_exists( 'array_replace_recursive' ) ) {
1763
- return array_replace_recursive( $base, $replacements );
1764
- }
1765
-
1766
- // PHP 5.2-compatible version
1767
- // http://php.net/manual/en/function.array-replace-recursive.php#109390.
1768
- foreach ( array_slice( func_get_args(), 1 ) as $replacements ) {
1769
- $bref_stack = array( &$base );
1770
- $head_stack = array( $replacements );
1771
-
1772
- do {
1773
- end( $bref_stack );
1774
-
1775
- $bref = &$bref_stack[ key( $bref_stack ) ];
1776
- $head = array_pop( $head_stack );
1777
-
1778
- unset( $bref_stack[ key($bref_stack) ] );
1779
-
1780
- foreach ( array_keys( $head ) as $key ) {
1781
- if ( isset( $key, $bref ) && is_array( $bref[$key] ) && is_array( $head[$key] ) ) {
1782
- $bref_stack[] = &$bref[ $key ];
1783
- $head_stack[] = $head[ $key ];
1784
- } else {
1785
- $bref[ $key ] = $head[ $key ];
1786
- }
1787
- }
1788
- } while( count( $head_stack ) );
1789
- }
1790
-
1791
- return $base;
1792
- }
1793
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-activity/classes/class-bp-activity-feed.php DELETED
@@ -1,447 +0,0 @@
1
- <?php
2
- /**
3
- * BuddyPress Activity Classes.
4
- *
5
- * @package BuddyPress
6
- * @subpackage ActivityFeeds
7
- */
8
-
9
- // Exit if accessed directly.
10
- defined( 'ABSPATH' ) || exit;
11
-
12
- /**
13
- * Create a RSS feed using the activity component.
14
- *
15
- * You should only construct a new feed when you've validated that you're on
16
- * the appropriate screen.
17
- *
18
- * @since 1.8.0
19
- *
20
- * See {@link bp_activity_action_sitewide_feed()} as an example.
21
- *
22
- * @param array $args {
23
- * @type string $id Required. Internal id for the feed; should be alphanumeric only.
24
- * @type string $title Optional. RSS feed title.
25
- * @type string $link Optional. Relevant link for the RSS feed.
26
- * @type string $description Optional. RSS feed description.
27
- * @type string $ttl Optional. Time-to-live. (see inline doc in constructor)
28
- * @type string $update_period Optional. Part of the syndication module.
29
- * (see inline doc in constructor for more info)
30
- * @type string $update_frequency Optional. Part of the syndication module.
31
- * (see inline doc in constructor for more info)
32
- * @type string $max Optional. Number of feed items to display.
33
- * @type array $activity_args Optional. Arguments passed to {@link bp_has_activities()}
34
- * }
35
- */
36
- class BP_Activity_Feed {
37
-
38
- /**
39
- * Holds our custom class properties.
40
- *
41
- * These variables are stored in a protected array that is magically
42
- * updated using PHP 5.2+ methods.
43
- *
44
- * @see BP_Feed::__construct() This is where $data is added.
45
- * @var array
46
- */
47
- protected $data;
48
-
49
- /**
50
- * Magic method for checking the existence of a certain data variable.
51
- *
52
- * @param string $key Property to check.
53
- *
54
- * @return bool Whether or not data variable exists.
55
- */
56
- public function __isset( $key ) { return isset( $this->data[$key] ); }
57
-
58
- /**
59
- * Magic method for getting a certain data variable.
60
- *
61
- * @param string $key Property to get.
62
- *
63
- * @return mixed Data in variable if available or null.
64
- */
65
- public function __get( $key ) { return isset( $this->data[$key] ) ? $this->data[$key] : null; }
66
-
67
- /**
68
- * Magic method for setting a certain data variable.
69
- *
70
- * @since 2.4.0
71
- *
72
- * @param string $key The property to set.
73
- * @param mixed $value The value to set.
74
- */
75
- public function __set( $key, $value ) { $this->data[$key] = $value; }
76
-
77
- /**
78
- * Constructor.
79
- *
80
- * @param array $args Optional.
81
- */
82
- public function __construct( $args = array() ) {
83
-
84
- /**
85
- * Filters if BuddyPress should consider feeds enabled. If disabled, it will return early.
86
- *
87
- * @since 1.8.0
88
- *
89
- * @param bool true Default true aka feeds are enabled.
90
- */
91
- if ( false === (bool) apply_filters( 'bp_activity_enable_feeds', true ) ) {
92
- global $wp_query;
93
-
94
- // Set feed flag to false.
95
- $wp_query->is_feed = false;
96
-
97
- return false;
98
- }
99
-
100
- // Setup data.
101
- $this->data = wp_parse_args( $args, array(
102
- // Internal identifier for the RSS feed - should be alphanumeric only.
103
- 'id' => '',
104
-
105
- // RSS title - should be plain-text.
106
- 'title' => '',
107
-
108
- // Relevant link for the RSS feed.
109
- 'link' => '',
110
-
111
- // RSS description - should be plain-text.
112
- 'description' => '',
113
-
114
- // Time-to-live - number of minutes to cache the data before an aggregator
115
- // requests it again. This is only acknowledged if the RSS client supports it
116
- //
117
- // See: http://www.rssboard.org/rss-profile#element-channel-ttl.
118
- // See: http://www.kbcafe.com/rss/rssfeedstate.html#ttl.
119
- 'ttl' => '30',
120
-
121
- // Syndication module - similar to ttl, but not really supported by RSS
122
- // clients
123
- //
124
- // See: http://web.resource.org/rss/1.0/modules/syndication/#description.
125
- // See: http://www.kbcafe.com/rss/rssfeedstate.html#syndicationmodule.
126
- 'update_period' => 'hourly',
127
- 'update_frequency' => 2,
128
-
129
- // Number of items to display.
130
- 'max' => 50,
131
-
132
- // Activity arguments passed to bp_has_activities().
133
- 'activity_args' => array()
134
- ) );
135
-
136
- /**
137
- * Fires before the feed is setup so plugins can modify.
138
- *
139
- * @since 1.8.0
140
- *
141
- * @param BP_Activity_Feed $this Current instance of activity feed. Passed by reference.
142
- */
143
- do_action_ref_array( 'bp_activity_feed_prefetch', array( &$this ) );
144
-
145
- // Setup class properties.
146
- $this->setup_properties();
147
-
148
- // Check if id is valid.
149
- if ( empty( $this->id ) ) {
150
- _doing_it_wrong( 'BP_Activity_Feed', __( "RSS feed 'id' must be defined", 'buddypress' ), 'BP 1.8' );
151
- return false;
152
- }
153
-
154
- /**
155
- * Fires after the feed is setup so plugins can modify.
156
- *
157
- * @since 1.8.0
158
- *
159
- * @param BP_Activity_Feed $this Current instance of activity feed. Passed by reference.
160
- */
161
- do_action_ref_array( 'bp_activity_feed_postfetch', array( &$this ) );
162
-
163
- // Setup feed hooks.
164
- $this->setup_hooks();
165
-
166
- // Output the feed.
167
- $this->output();
168
-
169
- // Kill the rest of the output.
170
- die();
171
- }
172
-
173
- /** SETUP ****************************************************************/
174
-
175
- /**
176
- * Setup and validate the class properties.
177
- */
178
- protected function setup_properties() {
179
- $this->id = sanitize_title( $this->id );
180
- $this->title = strip_tags( $this->title );
181
- $this->link = esc_url_raw( $this->link );
182
- $this->description = strip_tags( $this->description );
183
- $this->ttl = (int) $this->ttl;
184
- $this->update_period = strip_tags( $this->update_period );
185
- $this->update_frequency = (int) $this->update_frequency;
186
-
187
- $this->activity_args = wp_parse_args( $this->activity_args, array(
188
- 'max' => $this->max,
189
- 'per_page' => $this->max,
190
- 'display_comments' => 'stream'
191
- ) );
192
-
193
- }
194
-
195
- /**
196
- * Setup some hooks that are used in the feed.
197
- *
198
- * Currently, these hooks are used to maintain backwards compatibility with
199
- * the RSS feeds previous to BP 1.8.
200
- */
201
- protected function setup_hooks() {
202
- add_action( 'bp_activity_feed_rss_attributes', array( $this, 'backpat_rss_attributes' ) );
203
- add_action( 'bp_activity_feed_channel_elements', array( $this, 'backpat_channel_elements' ) );
204
- add_action( 'bp_activity_feed_item_elements', array( $this, 'backpat_item_elements' ) );
205
- }
206
-
207
- /** BACKPAT HOOKS ********************************************************/
208
-
209
- /**
210
- * Fire a hook to ensure backward compatibility for RSS attributes.
211
- */
212
- public function backpat_rss_attributes() {
213
-
214
- /**
215
- * Fires inside backpat_rss_attributes method for backwards compatibility related to RSS attributes.
216
- *
217
- * This hook was originally separated out for individual components but has since been abstracted into the BP_Activity_Feed class.
218
- *
219
- * @since 1.0.0
220
- */
221
- do_action( 'bp_activity_' . $this->id . '_feed' );
222
- }
223
-
224
- /**
225
- * Fire a hook to ensure backward compatibility for channel elements.
226
- */
227
- public function backpat_channel_elements() {
228
-
229
- /**
230
- * Fires inside backpat_channel_elements method for backwards compatibility related to RSS channel elements.
231
- *
232
- * This hook was originally separated out for individual components but has since been abstracted into the BP_Activity_Feed class.
233
- *
234
- * @since 1.0.0
235
- */
236
- do_action( 'bp_activity_' . $this->id . '_feed_head' );
237
- }
238
-
239
- /**
240
- * Fire a hook to ensure backward compatibility for item elements.
241
- */
242
- public function backpat_item_elements() {
243
- switch ( $this->id ) {
244
-
245
- // Sitewide and friends feeds use the 'personal' hook.
246
- case 'sitewide' :
247
- case 'friends' :
248
- $id = 'personal';
249
-
250
- break;
251
-
252
- default :
253
- $id = $this->id;
254
-
255
- break;
256
- }
257
-
258
- /**
259
- * Fires inside backpat_item_elements method for backwards compatibility related to RSS item elements.
260
- *
261
- * This hook was originally separated out for individual components but has since been abstracted into the BP_Activity_Feed class.
262
- *
263
- * @since 1.0.0
264
- */
265
- do_action( 'bp_activity_' . $id . '_feed_item' );
266
- }
267
-
268
- /** HELPERS **************************************************************/
269
-
270
- /**
271
- * Output the feed's item content.
272
- */
273
- protected function feed_content() {
274
- bp_activity_content_body();
275
-
276
- switch ( $this->id ) {
277
-
278
- // Also output parent activity item if we're on a specific feed.
279
- case 'favorites' :
280
- case 'friends' :
281
- case 'mentions' :
282
- case 'personal' :
283
-
284
- if ( 'activity_comment' == bp_get_activity_action_name() ) :
285
- ?>
286
- <strong><?php _e( 'In reply to', 'buddypress' ) ?></strong> -
287
- <?php bp_activity_parent_content() ?>
288
- <?php
289
- endif;
290
-
291
- break;
292
- }
293
- }
294
-
295
- /**
296
- * Sets various HTTP headers related to Content-Type and browser caching.
297
- *
298
- * Most of this class method is derived from {@link WP::send_headers()}.
299
- *
300
- * @since 1.9.0
301
- */
302
- protected function http_headers() {
303
- // Set up some additional headers if not on a directory page
304
- // this is done b/c BP uses pseudo-pages.
305
- if ( ! bp_is_directory() ) {
306
- global $wp_query;
307
-
308
- $wp_query->is_404 = false;
309
- status_header( 200 );
310
- }
311
-
312
- // Set content-type.
313
- @header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
314
- send_nosniff_header();
315
-
316
- // Cache-related variables.
317
- $last_modified = mysql2date( 'D, d M Y H:i:s O', bp_activity_get_last_updated(), false );
318
- $modified_timestamp = strtotime( $last_modified );
319
- $etag = md5( $last_modified );
320
-
321
- // Set cache-related headers.
322
- @header( 'Last-Modified: ' . $last_modified );
323
- @header( 'Pragma: no-cache' );
324
- @header( 'ETag: ' . '"' . $etag . '"' );
325
-
326
- // First commit of BuddyPress! (Easter egg).
327
- @header( 'Expires: Tue, 25 Mar 2008 17:13:55 GMT');
328
-
329
- // Get ETag from supported user agents.
330
- if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) ) {
331
- $client_etag = wp_unslash( $_SERVER['HTTP_IF_NONE_MATCH'] );
332
-
333
- // Remove quotes from ETag.
334
- $client_etag = trim( $client_etag, '"' );
335
-
336
- // Strip suffixes from ETag if they exist (eg. "-gzip").
337
- $etag_suffix_pos = strpos( $client_etag, '-' );
338
- if ( ! empty( $etag_suffix_pos ) ) {
339
- $client_etag = substr( $client_etag, 0, $etag_suffix_pos );
340
- }
341
-
342
- // No ETag found.
343
- } else {
344
- $client_etag = false;
345
- }
346
-
347
- // Get client last modified timestamp from supported user agents.
348
- $client_last_modified = empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ? '' : trim( $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
349
- $client_modified_timestamp = $client_last_modified ? strtotime( $client_last_modified ) : 0;
350
-
351
- // Set 304 status if feed hasn't been updated since last fetch.
352
- if ( ( $client_last_modified && $client_etag ) ?
353
- ( ( $client_modified_timestamp >= $modified_timestamp ) && ( $client_etag == $etag ) ) :
354
- ( ( $client_modified_timestamp >= $modified_timestamp ) || ( $client_etag == $etag ) ) ) {
355
- $status = 304;
356
- } else {
357
- $status = false;
358
- }
359
-
360
- // If feed hasn't changed as reported by the user agent, set 304 status header.
361
- if ( ! empty( $status ) ) {
362
- status_header( $status );
363
-
364
- // Cached response, so stop now!
365
- if ( $status == 304 ) {
366
- exit();
367
- }
368
- }
369
- }
370
-
371
- /** OUTPUT ***************************************************************/
372
-
373
- /**
374
- * Output the RSS feed.
375
- */
376
- protected function output() {
377
- $this->http_headers();
378
- echo '<?xml version="1.0" encoding="' . get_option( 'blog_charset' ) . '"?'.'>';
379
- ?>
380
-
381
- <rss version="2.0"
382
- xmlns:content="http://purl.org/rss/1.0/modules/content/"
383
- xmlns:atom="http://www.w3.org/2005/Atom"
384
- xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
385
- xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
386
- <?php
387
-
388
- /**
389
- * Fires at the end of the opening RSS tag for feed output so plugins can add extra attributes.
390
- *
391
- * @since 1.8.0
392
- */
393
- do_action( 'bp_activity_feed_rss_attributes' ); ?>
394
- >
395
-
396
- <channel>
397
- <title><?php echo $this->title; ?></title>
398
- <link><?php echo $this->link; ?></link>
399
- <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
400
- <description><?php echo $this->description ?></description>
401
- <lastBuildDate><?php echo mysql2date( 'D, d M Y H:i:s O', bp_activity_get_last_updated(), false ); ?></lastBuildDate>
402
- <generator>https://buddypress.org/?v=<?php bp_version(); ?></generator>
403
- <language><?php bloginfo_rss( 'language' ); ?></language>
404
- <ttl><?php echo $this->ttl; ?></ttl>
405
- <sy:updatePeriod><?php echo $this->update_period; ?></sy:updatePeriod>
406
- <sy:updateFrequency><?php echo $this->update_frequency; ?></sy:updateFrequency>
407
- <?php
408
-
409
- /**
410
- * Fires at the end of channel elements list in RSS feed so plugins can add extra channel elements.
411
- *
412
- * @since 1.8.0
413
- */
414
- do_action( 'bp_activity_feed_channel_elements' ); ?>
415
-
416
- <?php if ( bp_has_activities( $this->activity_args ) ) : ?>
417
- <?php while ( bp_activities() ) : bp_the_activity(); ?>
418
- <item>
419
- <guid isPermaLink="false"><?php bp_activity_feed_item_guid(); ?></guid>
420
- <title><?php echo stripslashes( bp_get_activity_feed_item_title() ); ?></title>
421
- <link><?php bp_activity_thread_permalink() ?></link>
422
- <pubDate><?php echo mysql2date( 'D, d M Y H:i:s O', bp_get_activity_feed_item_date(), false ); ?></pubDate>
423
-
424
- <?php if ( bp_get_activity_feed_item_description() ) : ?>
425
- <content:encoded><![CDATA[<?php $this->feed_content(); ?>]]></content:encoded>
426
- <?php endif; ?>
427
-
428
- <?php if ( bp_activity_can_comment() ) : ?>
429
- <slash:comments><?php bp_activity_comment_count(); ?></slash:comments>
430
- <?php endif; ?>
431
-
432
- <?php
433
-
434
- /**
435
- * Fires at the end of the individual RSS Item list in RSS feed so plugins can add extra item elements.
436
- *
437
- * @since 1.8.0
438
- */
439
- do_action( 'bp_activity_feed_item_elements' ); ?>
440
- </item>
441
- <?php endwhile; ?>
442
-
443
- <?php endif; ?>
444
- </channel>
445
- </rss><?php
446
- }
447
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-activity/classes/class-bp-activity-query.php DELETED
@@ -1,246 +0,0 @@
1
- <?php
2
- /**
3
- * BuddyPress Activity Classes
4
- *
5
- * @package BuddyPress
6
- * @subpackage ActivityQuery
7
- */
8
-
9
- // Exit if accessed directly.
10
- defined( 'ABSPATH' ) || exit;
11
-
12
- /**
13
- * Class for generating the WHERE SQL clause for advanced activity fetching.
14
- *
15
- * This is notably used in {@link BP_Activity_Activity::get()} with the
16
- * 'filter_query' parameter.
17
- *
18
- * @since 2.2.0
19
- */
20
- class BP_Activity_Query extends BP_Recursive_Query {
21
- /**
22
- * Array of activity queries.
23
- *
24
- * See {@see BP_Activity_Query::__construct()} for information on query arguments.
25
- *
26
- * @since 2.2.0
27
- * @var array
28
- */
29
- public $queries = array();
30
-
31
- /**
32
- * Table alias.
33
- *
34
- * @since 2.2.0
35
- * @var string
36
- */
37
- public $table_alias = '';
38
-
39
- /**
40
- * Supported DB columns.
41
- *
42
- * See the 'wp_bp_activity' DB table schema.
43
- *
44
- * @since 2.2.0
45
- * @var array
46
- */
47
- public $db_columns = array(
48
- 'id', 'user_id', 'component', 'type', 'action', 'content',
49
- 'item_id', 'secondary_item_id', 'hide_sitewide', 'is_spam',
50
- );
51
-
52
- /**
53
- * Constructor.
54
- *
55
- * @since 2.2.0
56
- *
57
- * @param array $query {
58
- * Array of query clauses.
59
- * @type array {
60
- * @type string $column Required. The column to query against. Basically, any DB column in the main
61
- * 'wp_bp_activity' table.
62
- * @type string $value Required. Value to filter by.
63
- * @type string $compare Optional. The comparison operator. Default '='.
64
- * Accepts '=', '!=', '>', '>=', '<', '<=', 'IN', 'NOT IN', 'LIKE',
65
- * 'NOT LIKE', BETWEEN', 'NOT BETWEEN', 'REGEXP', 'NOT REGEXP', 'RLIKE'.
66
- * @type string $relation Optional. The boolean relationship between the activity queries.
67
- * Accepts 'OR', 'AND'. Default 'AND'.
68
- * @type array {
69
- * Optional. Another fully-formed activity query. See parameters above.
70
- * }
71
- * }
72
- * }
73
- */
74
- public function __construct( $query = array() ) {
75
- if ( ! is_array( $query ) ) {
76
- return;
77
- }
78
-
79
- $this->queries = $this->sanitize_query( $query );
80
- }
81
-
82
- /**
83
- * Generates WHERE SQL clause to be appended to a main query.
84
- *
85
- * @since 2.2.0
86
- *
87
- * @param string $alias An existing table alias that is compatible with the current query clause.
88
- * Default: 'a'. BP_Activity_Activity::get() uses 'a', so we default to that.
89
- * @return string SQL fragment to append to the main WHERE clause.
90
- */
91
- public function get_sql( $alias = 'a' ) {
92
- if ( ! empty( $alias ) ) {
93
- $this->table_alias = sanitize_title( $alias );
94
- }
95
-
96
- $sql = $this->get_sql_clauses();
97
-
98
- // We only need the 'where' clause.
99
- //
100
- // Also trim trailing "AND" clause from parent BP_Recursive_Query class
101
- // since it's not necessary for our needs.
102
- return preg_replace( '/^\sAND/', '', $sql['where'] );
103
- }
104
-
105
- /**
106
- * Generate WHERE clauses for a first-order clause.
107
- *
108
- * @since 2.2.0
109
- *
110
- * @param array $clause Array of arguments belonging to the clause.
111
- * @param array $parent_query Parent query to which the clause belongs.
112
- * @return array {
113
- * @type array $where Array of subclauses for the WHERE statement.
114
- * @type array $join Empty array. Not used.
115
- * }
116
- */
117
- protected function get_sql_for_clause( $clause, $parent_query ) {
118
- global $wpdb;
119
-
120
- $sql_chunks = array(
121
- 'where' => array(),
122
- 'join' => array(),
123
- );
124
-
125
- $column = isset( $clause['column'] ) ? $this->validate_column( $clause['column'] ) : '';
126
- $value = isset( $clause['value'] ) ? $clause['value'] : '';
127
- if ( empty( $column ) || ! isset( $clause['value'] ) ) {
128
- return $sql_chunks;
129
- }
130
-
131
- if ( isset( $clause['compare'] ) ) {
132
- $clause['compare'] = strtoupper( $clause['compare'] );
133
- } else {
134
- $clause['compare'] = isset( $clause['value'] ) && is_array( $clause['value'] ) ? 'IN' : '=';
135
- }
136
-
137
- // Default 'compare' to '=' if no valid operator is found.
138
- if ( ! in_array( $clause['compare'], array(
139
- '=', '!=', '>', '>=', '<', '<=',
140
- 'LIKE', 'NOT LIKE',
141
- 'IN', 'NOT IN',
142
- 'BETWEEN', 'NOT BETWEEN',
143
- 'REGEXP', 'NOT REGEXP', 'RLIKE'
144
- ) ) ) {
145
- $clause['compare'] = '=';
146
- }
147
-
148
- $compare = $clause['compare'];
149
-
150
- $alias = ! empty( $this->table_alias ) ? "{$this->table_alias}." : '';
151
-
152
- // Next, Build the WHERE clause.
153
- $where = '';
154
-
155
- // Value.
156
- if ( isset( $clause['value'] ) ) {
157
- if ( in_array( $compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) {
158
- if ( ! is_array( $value ) ) {
159
- $value = preg_split( '/[,\s]+/', $value );
160
- }
161
- }
162
-
163
- // Tinyint.
164
- if ( ! empty( $column ) && true === in_array( $column, array( 'hide_sitewide', 'is_spam' ) ) ) {
165
- $sql_chunks['where'][] = $wpdb->prepare( "{$alias}{$column} = %d", $value );
166
-
167
- } else {
168
- switch ( $compare ) {
169
- // IN uses different syntax.
170
- case 'IN' :
171
- case 'NOT IN' :
172
- $in_sql = BP_Activity_Activity::get_in_operator_sql( "{$alias}{$column}", $value );
173
-
174
- // 'NOT IN' operator is as easy as a string replace!
175
- if ( 'NOT IN' === $compare ) {
176
- $in_sql = str_replace( 'IN', 'NOT IN', $in_sql );
177
- }
178
-
179
- $sql_chunks['where'][] = $in_sql;
180
- break;
181
-
182
- case 'BETWEEN' :
183
- case 'NOT BETWEEN' :
184
- $value = array_slice( $value, 0, 2 );
185
- $where = $wpdb->prepare( '%s AND %s', $value );
186
- break;
187
-
188
- case 'LIKE' :
189
- case 'NOT LIKE' :
190
- $value = '%' . bp_esc_like( $value ) . '%';
191
- $where = $wpdb->prepare( '%s', $value );
192
- break;
193
-
194
- default :
195
- $where = $wpdb->prepare( '%s', $value );
196
- break;
197
-
198
- }
199
- }
200
-
201
- if ( $where ) {
202
- $sql_chunks['where'][] = "{$alias}{$column} {$compare} {$where}";
203
- }
204
- }
205
-
206
- /*
207
- * Multiple WHERE clauses should be joined in parentheses.
208
- */
209
- if ( 1 < count( $sql_chunks['where'] ) ) {
210
- $sql_chunks['where'] = array( '( ' . implode( ' AND ', $sql_chunks['where'] ) . ' )' );
211
- }
212
-
213
- return $sql_chunks;
214
- }
215
-
216
- /**
217
- * Determine whether a clause is first-order.
218
- *
219
- * @since 2.2.0
220
- *
221
- * @param array $query Clause to check.
222
- * @return bool
223
- */
224
- protected function is_first_order_clause( $query ) {
225
- return isset( $query['column'] ) || isset( $query['value'] );
226
- }
227
-
228
- /**
229
- * Validates a column name parameter.
230
- *
231
- * Column names are checked against a whitelist of known tables.
232
- * See {@link BP_Activity_Query::db_tables}.
233
- *
234
- * @since 2.2.0
235
- *
236
- * @param string $column The user-supplied column name.
237
- * @return string A validated column name value.
238
- */
239
- public function validate_column( $column = '' ) {
240
- if ( in_array( $column, $this->db_columns ) ) {
241
- return $column;
242
- } else {
243
- return '';
244
- }
245
- }
246
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-activity/css/mentions-rtl.css DELETED
@@ -1,93 +0,0 @@
1
- .atwho-view {
2
- background: rgba(204, 204, 204, 0.8);
3
- border-radius: 2px;
4
- border: 1px solid rgb(204, 204, 204);
5
- box-shadow: 0 0 5px rgba(204, 204, 204, 0.25), 0 0 1px #FFF;
6
- color: #D84800;
7
- display: none;
8
- font-family: sans-serif;
9
- margin-top: 18px;
10
- position: absolute;
11
- top: 0;
12
- z-index: 1000; /* >999 for wp-admin */
13
- }
14
- /* @noflip */
15
- .atwho-view {
16
- left: 0;
17
- }
18
- .atwho-view ul {
19
- background: #FFF;
20
- list-style: none;
21
- margin: auto;
22
- padding: 0;
23
- }
24
- .atwho-view ul li {
25
- border-bottom: 1px solid #EFEFEF;
26
- box-sizing: content-box;
27
- cursor: pointer;
28
- display: block;
29
- font-size: 14px;
30
- height: 20px;
31
- line-height: 20px;
32
- margin: 0;
33
- overflow: hidden;
34
- padding: 5px 10px;
35
- }
36
- .atwho-view img {
37
- border-radius: 2px;
38
- float: left;
39
- height: 20px;
40
- margin-top:0;
41
- width: 20px;
42
- }
43
- .atwho-view strong {
44
- background: #EFEFEF;
45
- font: bold;
46
- }
47
- .atwho-view .username strong {
48
- color: #D54E21;
49
- }
50
- .atwho-view small {
51
- color: #AAA;
52
- float: left;
53
- font-size: smaller;
54
- font-weight: normal;
55
- margin: 0 40px 0 10px;
56
- }
57
- .atwho-view .cur {
58
- background: rgba(239, 239, 239, 0.5);
59
- }
60
-
61
- @media (max-width: 900px) {
62
- .atwho-view img {
63
- float: right;
64
- margin: 0 0 0 10px;
65
- }
66
- }
67
- @media (max-width: 400px) {
68
- .atwho-view ul li {
69
- font-size: 16px;
70
- line-height: 23px;
71
- padding: 13px;
72
- }
73
- .atwho-view ul li img {
74
- height: 30px;
75
- margin-top: -5px;
76
- width: 30px;
77
- }
78
- .atwho-view {
79
- border-radius: 0;
80
- height: 100%;
81
- right: 0 !important;
82
- width: 100%;
83
- }
84
- .atwho-view ul li .username {
85
- display: inline-block;
86
- margin: -10px 0 0 0;
87
- padding: 10px 0;
88
- }
89
- .atwho-view ul li small {
90
- display: inline-block;
91
- margin-right: 20px;
92
- }
93
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-activity/css/mentions-rtl.min.css DELETED
@@ -1 +0,0 @@
1
- .atwho-view{background:rgba(204,204,204,.8);border-radius:2px;border:1px solid #ccc;box-shadow:0 0 5px rgba(204,204,204,.25),0 0 1px #FFF;color:#D84800;display:none;font-family:sans-serif;margin-top:18px;position:absolute;top:0;z-index:1000;left:0}.atwho-view ul{background:#FFF;list-style:none;margin:auto;padding:0}.atwho-view ul li{border-bottom:1px solid #EFEFEF;box-sizing:content-box;cursor:pointer;display:block;font-size:14px;height:20px;line-height:20px;margin:0;overflow:hidden;padding:5px 10px}.atwho-view img{border-radius:2px;float:left;height:20px;margin-top:0;width:20px}.atwho-view strong{background:#EFEFEF;font:700}.atwho-view .username strong{color:#D54E21}.atwho-view small{color:#AAA;float:left;font-size:smaller;font-weight:400;margin:0 40px 0 10px}.atwho-view .cur{background:rgba(239,239,239,.5)}@media (max-width:900px){.atwho-view img{float:right;margin:0 0 0 10px}}@media (max-width:400px){.atwho-view ul li{font-size:16px;line-height:23px;padding:13px}.atwho-view ul li img{height:30px;margin-top:-5px;width:30px}.atwho-view{border-radius:0;height:100%;right:0!important;width:100%}.atwho-view ul li .username{display:inline-block;margin:-10px 0 0;padding:10px 0}.atwho-view ul li small{display:inline-block;margin-right:20px}}
 
bp-activity/css/mentions.css DELETED
@@ -1,93 +0,0 @@
1
- .atwho-view {
2
- background: rgba(204, 204, 204, 0.8);
3
- border-radius: 2px;
4
- border: 1px solid rgb(204, 204, 204);
5
- box-shadow: 0 0 5px rgba(204, 204, 204, 0.25), 0 0 1px #FFF;
6
- color: #D84800;
7
- display: none;
8
- font-family: sans-serif;
9
- margin-top: 18px;
10
- position: absolute;
11
- top: 0;
12
- z-index: 1000; /* >999 for wp-admin */
13
- }
14
- /* @noflip */
15
- .atwho-view {
16
- left: 0;
17
- }
18
- .atwho-view ul {
19
- background: #FFF;
20
- list-style: none;
21
- margin: auto;
22
- padding: 0;
23
- }
24
- .atwho-view ul li {
25
- border-bottom: 1px solid #EFEFEF;
26
- box-sizing: content-box;
27
- cursor: pointer;
28
- display: block;
29
- font-size: 14px;
30
- height: 20px;
31
- line-height: 20px;
32
- margin: 0;
33
- overflow: hidden;
34
- padding: 5px 10px;
35
- }
36
- .atwho-view img {
37
- border-radius: 2px;
38
- float: right;
39
- height: 20px;
40
- margin-top:0;
41
- width: 20px;
42
- }
43
- .atwho-view strong {
44
- background: #EFEFEF;
45
- font: bold;
46
- }
47
- .atwho-view .username strong {
48
- color: #D54E21;
49
- }
50
- .atwho-view small {
51
- color: #AAA;
52
- float: right;
53
- font-size: smaller;
54
- font-weight: normal;
55
- margin: 0 10px 0 40px;
56
- }
57
- .atwho-view .cur {
58
- background: rgba(239, 239, 239, 0.5);
59
- }
60
-
61
- @media (max-width: 900px) {
62
- .atwho-view img {
63
- float: left;
64
- margin: 0 10px 0 0;
65
- }
66
- }
67
- @media (max-width: 400px) {
68
- .atwho-view ul li {
69
- font-size: 16px;
70
- line-height: 23px;
71
- padding: 13px;
72
- }
73
- .atwho-view ul li img {
74
- height: 30px;
75
- margin-top: -5px;
76
- width: 30px;
77
- }
78
- .atwho-view {
79
- border-radius: 0;
80
- height: 100%;
81
- left: 0 !important;
82
- width: 100%;
83
- }
84
- .atwho-view ul li .username {
85
- display: inline-block;
86
- margin: -10px 0 0 0;
87
- padding: 10px 0;
88
- }
89
- .atwho-view ul li small {
90
- display: inline-block;
91
- margin-left: 20px;
92
- }
93
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-activity/css/mentions.min.css DELETED
@@ -1 +0,0 @@
1
- .atwho-view{background:rgba(204,204,204,.8);border-radius:2px;border:1px solid #ccc;box-shadow:0 0 5px rgba(204,204,204,.25),0 0 1px #FFF;color:#D84800;display:none;font-family:sans-serif;margin-top:18px;position:absolute;top:0;z-index:1000;left:0}.atwho-view ul{background:#FFF;list-style:none;margin:auto;padding:0}.atwho-view ul li{border-bottom:1px solid #EFEFEF;box-sizing:content-box;cursor:pointer;display:block;font-size:14px;height:20px;line-height:20px;margin:0;overflow:hidden;padding:5px 10px}.atwho-view img{border-radius:2px;float:right;height:20px;margin-top:0;width:20px}.atwho-view strong{background:#EFEFEF;font:700}.atwho-view .username strong{color:#D54E21}.atwho-view small{color:#AAA;float:right;font-size:smaller;font-weight:400;margin:0 10px 0 40px}.atwho-view .cur{background:rgba(239,239,239,.5)}@media (max-width:900px){.atwho-view img{float:left;margin:0 10px 0 0}}@media (max-width:400px){.atwho-view ul li{font-size:16px;line-height:23px;padding:13px}.atwho-view ul li img{height:30px;margin-top:-5px;width:30px}.atwho-view{border-radius:0;height:100%;left:0!important;width:100%}.atwho-view ul li .username{display:inline-block;margin:-10px 0 0;padding:10px 0}.atwho-view ul li small{display:inline-block;margin-left:20px}}
 
bp-activity/js/mentions.js DELETED
@@ -1,255 +0,0 @@
1
- /* global bp */
2
-
3
- window.bp = window.bp || {};
4
-
5
- ( function( bp, $, undefined ) {
6
- var mentionsQueryCache = [],
7
- mentionsItem;
8
-
9
- bp.mentions = bp.mentions || {};
10
- bp.mentions.users = window.bp.mentions.users || [];
11
-
12
- if ( typeof window.BP_Suggestions === 'object' ) {
13
- bp.mentions.users = window.BP_Suggestions.friends || bp.mentions.users;
14
- }
15
-
16
- /**
17
- * Adds BuddyPress @mentions to form inputs.
18
- *
19
- * @param {array|object} options If array, becomes the suggestions' data source. If object, passed as config to $.atwho().
20
- * @since 2.1.0
21
- */
22
- $.fn.bp_mentions = function( options ) {
23
- if ( $.isArray( options ) ) {
24
- options = { data: options };
25
- }
26
-
27
- /**
28
- * Default options for at.js; see https://github.com/ichord/At.js/.
29
- */
30
- var suggestionsDefaults = {
31
- delay: 200,
32
- hide_without_suffix: true,
33
- insert_tpl: '</>${atwho-data-value}</>', // For contentEditable, the fake tags make jQuery insert a textNode.
34
- limit: 10,
35
- start_with_space: false,
36
- suffix: '',
37
-
38
- callbacks: {
39
- /**
40
- * Custom filter to only match the start of spaced words.
41
- * Based on the core/default one.
42
- *
43
- * @param {string} query
44
- * @param {array} data
45
- * @param {string} search_key
46
- * @return {array}
47
- * @since 2.1.0
48
- */
49
- filter: function( query, data, search_key ) {
50
- var item, _i, _len, _results = [],
51
- regxp = new RegExp( '^' + query + '| ' + query, 'ig' ); // start of string, or preceded by a space.
52
-
53
- for ( _i = 0, _len = data.length; _i < _len; _i++ ) {
54
- item = data[ _i ];
55
- if ( item[ search_key ].toLowerCase().match( regxp ) ) {
56
- _results.push( item );
57
- }
58
- }
59
-
60
- return _results;
61
- },
62
-
63
- /**
64
- * Removes some spaces around highlighted string and tweaks regex to allow spaces
65
- * (to match display_name). Based on the core default.
66
- *
67
- * @param {unknown} li
68
- * @param {string} query
69
- * @return {string}
70
- * @since 2.1.0
71
- */
72
- highlighter: function( li, query ) {
73
- if ( ! query ) {
74
- return li;
75
- }
76
-
77
- var regexp = new RegExp( '>(\\s*|[\\w\\s]*)(' + this.at.replace( '+', '\\+') + '?' + query.replace( '+', '\\+' ) + ')([\\w ]*)\\s*<', 'ig' );
78
- return li.replace( regexp, function( str, $1, $2, $3 ) {
79
- return '>' + $1 + '<strong>' + $2 + '</strong>' + $3 + '<';
80
- });
81
- },
82
-
83
- /**
84
- * Reposition the suggestion list dynamically.
85
- *
86
- * @param {unknown} offset
87
- * @since 2.1.0
88
- */
89
- before_reposition: function( offset ) {
90
- // get the iframe, if any, already applied with atwho
91
- var caret,
92
- line,
93
- iframeOffset,
94
- move,
95
- $view = $( '#atwho-ground-' + this.id + ' .atwho-view' ),
96
- $body = $( 'body' ),
97
- atwhoDataValue = this.$inputor.data( 'atwho' );
98
-
99
- if ( 'undefined' !== atwhoDataValue && 'undefined' !== atwhoDataValue.iframe && null !== atwhoDataValue.iframe ) {
100
- caret = this.$inputor.caret( 'offset', { iframe: atwhoDataValue.iframe } );
101
- // Caret.js no longer calculates iframe caret position from the window (it's now just within the iframe).
102
- // We need to get the iframe offset from the window and merge that into our object.
103
- iframeOffset = $( atwhoDataValue.iframe ).offset();
104
- if ( 'undefined' !== iframeOffset ) {
105
- caret.left += iframeOffset.left;
106
- caret.top += iframeOffset.top;
107
- }
108
- } else {
109
- caret = this.$inputor.caret( 'offset' );
110
- }
111
-
112
- // If the caret is past horizontal half, then flip it, yo
113
- if ( caret.left > ( $body.width() / 2 ) ) {
114
- $view.addClass( 'right' );
115
- move = caret.left - offset.left - this.view.$el.width();
116
- } else {
117
- $view.removeClass( 'right' );
118
- move = caret.left - offset.left + 1;
119
- }
120
-
121
- // If we're on a small screen, scroll to caret
122
- if ( $body.width() <= 400 ) {
123
- $( document ).scrollTop( caret.top - 6 );
124
- }
125
-
126
- // New position is under the caret (never above) and positioned to follow
127
- // Dynamic sizing based on the input area (remove 'px' from end)
128
- line = parseInt( this.$inputor.css( 'line-height' ).substr( 0, this.$inputor.css( 'line-height' ).length - 2 ), 10 );
129
- if ( !line || line < 5 ) { // sanity check, and catch no line-height
130
- line = 19;
131
- }
132
-
133
- offset.top = caret.top + line;
134
- offset.left += move;
135
- },
136
-
137
- /**
138
- * Override default behaviour which inserts junk tags in the WordPress Visual editor.
139
- *
140
- * @param {unknown} $inputor Element which we're inserting content into.
141
- * @param {string) content The content that will be inserted.
142
- * @param {string) suffix Applied to the end of the content string.
143
- * @return {string}
144
- * @since 2.1.0
145
- */
146
- inserting_wrapper: function( $inputor, content, suffix ) {
147
- return '' + content + suffix;
148
- }
149
- }
150
- },
151
-
152
- /**
153
- * Default options for our @mentions; see https://github.com/ichord/At.js/.
154
- */
155
- mentionsDefaults = {
156
- callbacks: {
157
- /**
158
- * If there are no matches for the query in this.data, then query BuddyPress.
159
- *
160
- * @param {string} query Partial @mention to search for.
161
- * @param {function} render_view Render page callback function.
162
- * @since 2.1.0
163
- */
164
- remote_filter: function( query, render_view ) {
165
- var self = $( this ),
166
- params = {};
167
-
168
- mentionsItem = mentionsQueryCache[ query ];
169
- if ( typeof mentionsItem === 'object' ) {
170
- render_view( mentionsItem );
171
- return;
172
- }
173
-
174
- if ( self.xhr ) {
175
- self.xhr.abort();
176
- }
177
-
178
- params = { 'action': 'bp_get_suggestions', 'term': query, 'type': 'members' };
179
-
180
- if ( $.isNumeric( this.$inputor.data( 'suggestions-group-id' ) ) ) {
181
- params['group-id'] = parseInt( this.$inputor.data( 'suggestions-group-id' ), 10 );
182
- }
183
-
184
- self.xhr = $.getJSON( ajaxurl, params )
185
- /**
186
- * Success callback for the @suggestions lookup.
187
- *
188
- * @param {object} response Details of users matching the query.
189
- * @since 2.1.0
190
- */
191
- .done(function( response ) {
192
- if ( ! response.success ) {
193
- return;
194
- }
195
-
196
- var data = $.map( response.data,
197
- /**
198
- * Create a composite index to determine ordering of results;
199
- * nicename matches will appear on top.
200
- *
201
- * @param {array} suggestion A suggestion's original data.
202
- * @return {array} A suggestion's new data.
203
- * @since 2.1.0
204
- */
205
- function( suggestion ) {
206
- suggestion.search = suggestion.search || suggestion.ID + ' ' + suggestion.name;
207
- return suggestion;
208
- }
209
- );
210
-
211
- mentionsQueryCache[ query ] = data;
212
- render_view( data );
213
- });
214
- }
215
- },
216
-
217
- data: $.map( options.data,
218
- /**
219
- * Create a composite index to search against of nicename + display name.
220
- * This will also determine ordering of results, so nicename matches will appear on top.
221
- *
222
- * @param {array} suggestion A suggestion's original data.
223
- * @return {array} A suggestion's new data.
224
- * @since 2.1.0
225
- */
226
- function( suggestion ) {
227
- suggestion.search = suggestion.search || suggestion.ID + ' ' + suggestion.name;
228
- return suggestion;
229
- }
230
- ),
231
-
232
- at: '@',
233
- search_key: 'search',
234
- tpl: '<li data-value="@${ID}"><img src="${image}" /><span class="username">@${ID}</span><small>${name}</small></li>'
235
- },
236
-
237
- opts = $.extend( true, {}, suggestionsDefaults, mentionsDefaults, options );
238
- return $.fn.atwho.call( this, opts );
239
- };
240
-
241
- $( document ).ready(function() {
242
- // Activity/reply, post comments, dashboard post 'text' editor.
243
- $( '.bp-suggestions, #comments form textarea, .wp-editor-area' ).bp_mentions( bp.mentions.users );
244
- });
245
-
246
- bp.mentions.tinyMCEinit = function() {
247
- if ( typeof window.tinyMCE === 'undefined' || window.tinyMCE.activeEditor === null || typeof window.tinyMCE.activeEditor === 'undefined' ) {
248
- return;
249
- } else {
250
- $( window.tinyMCE.activeEditor.contentDocument.activeElement )
251
- .atwho( 'setIframe', $( '#content_ifr' )[0] )
252
- .bp_mentions( bp.mentions.users );
253
- }
254
- };
255
- })( bp, jQuery );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-activity/js/mentions.min.js DELETED
@@ -1,2 +0,0 @@
1
- /*! buddypress - v2.4.0 - 2015-10-29 4:00:53 PM UTC - https://wordpress.org/plugins/buddypress/ */
2
- window.bp=window.bp||{},function(a,b,c){var d,e=[];a.mentions=a.mentions||{},a.mentions.users=window.bp.mentions.users||[],"object"==typeof window.BP_Suggestions&&(a.mentions.users=window.BP_Suggestions.friends||a.mentions.users),b.fn.bp_mentions=function(a){b.isArray(a)&&(a={data:a});var c={delay:200,hide_without_suffix:!0,insert_tpl:"</>${atwho-data-value}</>",limit:10,start_with_space:!1,suffix:"",callbacks:{filter:function(a,b,c){var d,e,f,g=[],h=new RegExp("^"+a+"| "+a,"ig");for(e=0,f=b.length;f>e;e++)d=b[e],d[c].toLowerCase().match(h)&&g.push(d);return g},highlighter:function(a,b){if(!b)return a;var c=new RegExp(">(\\s*|[\\w\\s]*)("+this.at.replace("+","\\+")+"?"+b.replace("+","\\+")+")([\\w ]*)\\s*<","ig");return a.replace(c,function(a,b,c,d){return">"+b+"<strong>"+c+"</strong>"+d+"<"})},before_reposition:function(a){var c,d,e,f,g=b("#atwho-ground-"+this.id+" .atwho-view"),h=b("body"),i=this.$inputor.data("atwho");"undefined"!==i&&"undefined"!==i.iframe&&null!==i.iframe?(c=this.$inputor.caret("offset",{iframe:i.iframe}),e=b(i.iframe).offset(),"undefined"!==e&&(c.left+=e.left,c.top+=e.top)):c=this.$inputor.caret("offset"),c.left>h.width()/2?(g.addClass("right"),f=c.left-a.left-this.view.$el.width()):(g.removeClass("right"),f=c.left-a.left+1),h.width()<=400&&b(document).scrollTop(c.top-6),d=parseInt(this.$inputor.css("line-height").substr(0,this.$inputor.css("line-height").length-2),10),(!d||5>d)&&(d=19),a.top=c.top+d,a.left+=f},inserting_wrapper:function(a,b,c){return""+b+c}}},f={callbacks:{remote_filter:function(a,c){var f=b(this),g={};return d=e[a],"object"==typeof d?void c(d):(f.xhr&&f.xhr.abort(),g={action:"bp_get_suggestions",term:a,type:"members"},b.isNumeric(this.$inputor.data("suggestions-group-id"))&&(g["group-id"]=parseInt(this.$inputor.data("suggestions-group-id"),10)),void(f.xhr=b.getJSON(ajaxurl,g).done(function(d){if(d.success){var f=b.map(d.data,function(a){return a.search=a.search||a.ID+" "+a.name,a});e[a]=f,c(f)}})))}},data:b.map(a.data,function(a){return a.search=a.search||a.ID+" "+a.name,a}),at:"@",search_key:"search",tpl:'<li data-value="@${ID}"><img src="${image}" /><span class="username">@${ID}</span><small>${name}</small></li>'},g=b.extend(!0,{},c,f,a);return b.fn.atwho.call(this,g)},b(document).ready(function(){b(".bp-suggestions, #comments form textarea, .wp-editor-area").bp_mentions(a.mentions.users)}),a.mentions.tinyMCEinit=function(){"undefined"!=typeof window.tinyMCE&&null!==window.tinyMCE.activeEditor&&"undefined"!=typeof window.tinyMCE.activeEditor&&b(window.tinyMCE.activeEditor.contentDocument.activeElement).atwho("setIframe",b("#content_ifr")[0]).bp_mentions(a.mentions.users)}}(bp,jQuery);
 
 
bp-blogs/bp-blogs-actions.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  /**
3
  * BuddyPress Blogs Actions.
4
  *
@@ -7,12 +8,12 @@
7
  */
8
 
9
  // Exit if accessed directly
10
- defined( 'ABSPATH' ) || exit;
11
 
12
  /**
13
  * Redirect to a random blog in the multisite network.
14
  *
15
- * @since 1.0.0
16
  */
17
  function bp_blogs_redirect_to_random_blog() {
18
 
1
  <?php
2
+
3
  /**
4
  * BuddyPress Blogs Actions.
5
  *
8
  */
9
 
10
  // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
 
13
  /**
14
  * Redirect to a random blog in the multisite network.
15
  *
16
+ * @since BuddyPress (1.0.0)
17
  */
18
  function bp_blogs_redirect_to_random_blog() {
19
 
bp-blogs/bp-blogs-activity.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  /**
3
  * BuddyPress Blogs Activity.
4
  *
@@ -6,18 +7,20 @@
6
  * @subpackage BlogsActivity
7
  */
8
 
9
- // Exit if accessed directly.
10
- defined( 'ABSPATH' ) || exit;
11
 
12
  /**
13
  * Register activity actions for the blogs component.
14
  *
15
- * @since 1.0.0
 
 
16
  *
17
  * @return bool|null Returns false if activity component is not active.
18
  */
19
  function bp_blogs_register_activity_actions() {
20
- $bp = buddypress();
21
 
22
  // Bail if activity is not active
23
  if ( ! bp_is_active( 'activity' ) ) {
@@ -29,31 +32,24 @@ function bp_blogs_register_activity_actions() {
29
  $bp->blogs->id,
30
  'new_blog',
31
  __( 'New site created', 'buddypress' ),
32
- 'bp_blogs_format_activity_action_new_blog',
33
- __( 'New Sites', 'buddypress' ),
34
- array( 'activity', 'member' ),
35
- 0
36
  );
37
  }
38
 
39
- // Only add the comment type if the 'post' post type is trackable
40
- if ( post_type_supports( 'post', 'buddypress-activity' ) ) {
41
- bp_activity_set_action(
42
- $bp->blogs->id,
43
- 'new_blog_comment',
44
- __( 'New post comment posted', 'buddypress' ),
45
- 'bp_blogs_format_activity_action_new_blog_comment',
46
- __( 'Comments', 'buddypress' ),
47
- array( 'activity', 'member' ),
48
- 10
49
- );
50
- }
 
51
 
52
- /**
53
- * Fires after the registry of the default blog component activity actions.
54
- *
55
- * @since 1.1.0
56
- */
57
  do_action( 'bp_blogs_register_activity_actions' );
58
  }
59
  add_action( 'bp_register_activity_actions', 'bp_blogs_register_activity_actions' );
@@ -61,12 +57,10 @@ add_action( 'bp_register_activity_actions', 'bp_blogs_register_activity_actions'
61
  /**
62
  * Format 'new_blog' activity actions.
63
  *
64
- * @since 2.0.0
65
- *
66
- * @param string $action Static activity action.
67
- * @param object $activity Activity data object.
68
  *
69
- * @return string
 
70
  */
71
  function bp_blogs_format_activity_action_new_blog( $action, $activity ) {
72
  $blog_url = bp_blogs_get_blogmeta( $activity->item_id, 'url' );
@@ -86,26 +80,16 @@ function bp_blogs_format_activity_action_new_blog( $action, $activity ) {
86
  }
87
  }
88
 
89
- /**
90
- * Filters the new blog activity action for the new blog.
91
- *
92
- * @since 2.0.0
93
- *
94
- * @param string $action Constructed activity action.
95
- * @param object $activity Activity data object.
96
- */
97
  return apply_filters( 'bp_blogs_format_activity_action_new_blog', $action, $activity );
98
  }
99
 
100
  /**
101
  * Format 'new_blog_post' activity actions.
102
  *
103
- * @since 2.0.0
104
- *
105
- * @param string $action Static activity action.
106
- * @param object $activity Activity data object.
107
  *
108
- * @return string Constructed activity action.
 
109
  */
110
  function bp_blogs_format_activity_action_new_blog_post( $action, $activity ) {
111
  $blog_url = bp_blogs_get_blogmeta( $activity->item_id, 'url' );
@@ -119,68 +103,27 @@ function bp_blogs_format_activity_action_new_blog_post( $action, $activity ) {
119
  bp_blogs_update_blogmeta( $activity->item_id, 'name', $blog_name );
120
  }
121
 
122
- /**
123
- * When the post is published we are faking an activity object
124
- * to which we add 2 properties :
125
- * - the post url
126
- * - the post title
127
- * This is done to build the 'post link' part of the activity
128
- * action string.
129
- * NB: in this case the activity has not yet been created.
130
- */
131
- if ( isset( $activity->post_url ) ) {
132
- $post_url = $activity->post_url;
133
-
134
- /**
135
- * The post_url property is not set, we need to build the url
136
- * thanks to the post id which is also saved as the secondary
137
- * item id property of the activity object.
138
- */
139
- } else {
140
- $post_url = add_query_arg( 'p', $activity->secondary_item_id, trailingslashit( $blog_url ) );
141
- }
142
-
143
- // Should be the case when the post has just been published
144
- if ( isset( $activity->post_title ) ) {
145
- $post_title = $activity->post_title;
146
 
147
- // If activity already exists try to get the post title from activity meta
148
- } else if ( ! empty( $activity->id ) ) {
149
- $post_title = bp_activity_get_meta( $activity->id, 'post_title' );
150
- }
151
 
152
- /**
153
- * In case the post was published without a title
154
- * or the activity meta was not found
155
- */
156
  if ( empty( $post_title ) ) {
157
- // Defaults to no title
158
- $post_title = esc_html__( '(no title)', 'buddypress' );
159
-
160
  switch_to_blog( $activity->item_id );
161
 
162
  $post = get_post( $activity->secondary_item_id );
163
  if ( is_a( $post, 'WP_Post' ) ) {
164
- // Does the post have a title ?
165
- if ( ! empty( $post->post_title ) ) {
166
- $post_title = $post->post_title;
167
- }
168
-
169
- // Make sure the activity exists before saving the post title in activity meta
170
- if ( ! empty( $activity->id ) ) {
171
- bp_activity_update_meta( $activity->id, 'post_title', $post_title );
172
- }
173
  }
174
 
175
  restore_current_blog();
176
  }
177
 
178
- // Build the 'post link' part of the activity action string
179
- $post_link = '<a href="' . esc_url( $post_url ) . '">' . $post_title . '</a>';
180
 
181
  $user_link = bp_core_get_userlink( $activity->user_id );
182
 
183
- // Build the complete activity action string
184
  if ( is_multisite() ) {
185
  $action = sprintf( __( '%1$s wrote a new post, %2$s, on the site %3$s', 'buddypress' ), $user_link, $post_link, '<a href="' . esc_url( $blog_url ) . '">' . esc_html( $blog_name ) . '</a>' );
186
  } else {
@@ -198,26 +141,16 @@ function bp_blogs_format_activity_action_new_blog_post( $action, $activity ) {
198
  }
199
  }
200
 
201
- /**
202
- * Filters the new blog post action for the new blog.
203
- *
204
- * @since 2.0.0
205
- *
206
- * @param string $action Constructed activity action.
207
- * @param object $activity Activity data object.
208
- */
209
  return apply_filters( 'bp_blogs_format_activity_action_new_blog_post', $action, $activity );
210
  }
211
 
212
  /**
213
  * Format 'new_blog_comment' activity actions.
214
  *
215
- * @since 2.0.0
216
- *
217
- * @param string $action Static activity action.
218
- * @param object $activity Activity data object.
219
  *
220
- * @return string Constructed activity action.
 
221
  */
222
  function bp_blogs_format_activity_action_new_blog_comment( $action, $activity ) {
223
  $blog_url = bp_blogs_get_blogmeta( $activity->item_id, 'url' );
@@ -255,7 +188,7 @@ function bp_blogs_format_activity_action_new_blog_comment( $action, $activity )
255
  restore_current_blog();
256
  }
257
 
258
- $post_link = '<a href="' . esc_url( $post_url ) . '">' . $post_title . '</a>';
259
  $user_link = bp_core_get_userlink( $activity->user_id );
260
 
261
  if ( is_multisite() ) {
@@ -275,14 +208,6 @@ function bp_blogs_format_activity_action_new_blog_comment( $action, $activity )
275
  }
276
  }
277
 
278
- /**
279
- * Filters the new blog comment action for the new blog.
280
- *
281
- * @since 2.0.0
282
- *
283
- * @param string $action Constructed activity action.
284
- * @param object $activity Activity data object.
285
- */
286
  return apply_filters( 'bp_blogs_format_activity_action_new_blog_comment', $action, $activity );
287
  }
288
 
@@ -291,10 +216,9 @@ function bp_blogs_format_activity_action_new_blog_comment( $action, $activity )
291
  *
292
  * This reduces database overhead during the activity loop.
293
  *
294
- * @since 2.0.0
295
  *
296
  * @param array $activities Array of activity items.
297
- *
298
  * @return array
299
  */
300
  function bp_blogs_prefetch_activity_object_data( $activities ) {
@@ -323,11 +247,12 @@ add_filter( 'bp_activity_prefetch_object_data', 'bp_blogs_prefetch_activity_obje
323
  /**
324
  * Record blog-related activity to the activity stream.
325
  *
326
- * @since 1.0.0
327
  *
328
  * @see bp_activity_add() for description of parameters.
 
329
  *
330
- * @param array|string $args {
331
  * See {@link bp_activity_add()} for complete description of arguments.
332
  * The arguments listed here have different default values from
333
  * bp_activity_add().
@@ -336,13 +261,11 @@ add_filter( 'bp_activity_prefetch_object_data', 'bp_blogs_prefetch_activity_obje
336
  * @return int|bool On success, returns the activity ID. False on failure.
337
  */
338
  function bp_blogs_record_activity( $args = '' ) {
 
339
 
340
  // Bail if activity is not active
341
- if ( ! bp_is_active( 'activity' ) ) {
342
  return false;
343
- }
344
-
345
- $bp = buddypress();
346
 
347
  $defaults = array(
348
  'user_id' => bp_loggedin_user_id(),
@@ -358,53 +281,39 @@ function bp_blogs_record_activity( $args = '' ) {
358
  );
359
 
360
  $r = wp_parse_args( $args, $defaults );
 
361
 
362
- if ( ! empty( $r['action'] ) ) {
 
 
363
 
364
- /**
365
- * Filters the action associated with activity for activity stream.
366
- *
367
- * @since 1.2.0
368
- *
369
- * @param string $value Action for the activity stream.
370
- */
371
- $r['action'] = apply_filters( 'bp_blogs_record_activity_action', $r['action'] );
372
- }
373
 
374
- if ( ! empty( $r['content'] ) ) {
375
-
376
- /**
377
- * Filters the content associated with activity for activity stream.
378
- *
379
- * @since 1.2.0
380
- *
381
- * @param string $value Generated summary from content for the activity stream.
382
- * @param string $value Content for the activity stream.
383
- * @param array $r Array of arguments used for the activity stream item.
384
- */
385
- $r['content'] = apply_filters( 'bp_blogs_record_activity_content', bp_activity_create_summary( $r['content'], $r ), $r['content'], $r );
386
- }
387
 
388
  // Check for an existing entry and update if one exists.
389
  $id = bp_activity_get_activity_id( array(
390
- 'user_id' => $r['user_id'],
391
- 'component' => $r['component'],
392
- 'type' => $r['type'],
393
- 'item_id' => $r['item_id'],
394
- 'secondary_item_id' => $r['secondary_item_id'],
395
  ) );
396
 
397
- return bp_activity_add( array( 'id' => $id, 'user_id' => $r['user_id'], 'action' => $r['action'], 'content' => $r['content'], 'primary_link' => $r['primary_link'], 'component' => $r['component'], 'type' => $r['type'], 'item_id' => $r['item_id'], 'secondary_item_id' => $r['secondary_item_id'], 'recorded_time' => $r['recorded_time'], 'hide_sitewide' => $r['hide_sitewide'] ) );
398
  }
399
 
400
  /**
401
  * Delete a blog-related activity stream item.
402
  *
403
- * @since 1.0.0
404
  *
405
  * @see bp_activity_delete() for description of parameters.
 
406
  *
407
- * @param array|string $args {
408
  * See {@link bp_activity_delete()} for complete description of arguments.
409
  * The arguments listed here have different default values from
410
  * bp_activity_add().
@@ -412,22 +321,31 @@ function bp_blogs_record_activity( $args = '' ) {
412
  * }
413
  * @return bool True on success, false on failure.
414
  */
415
- function bp_blogs_delete_activity( $args = '' ) {
 
416
 
417
  // Bail if activity is not active
418
- if ( ! bp_is_active( 'activity' ) ) {
419
  return false;
420
- }
421
 
422
- $r = bp_parse_args( $args, array(
423
  'item_id' => false,
424
- 'component' => buddypress()->blogs->id,
425
  'type' => false,
426
  'user_id' => false,
427
  'secondary_item_id' => false
428
- ) );
429
 
430
- bp_activity_delete_by_item_id( $r );
 
 
 
 
 
 
 
 
 
431
  }
432
 
433
  /**
@@ -441,10 +359,9 @@ function bp_blogs_delete_activity( $args = '' ) {
441
  * to blogmeta and checks the values in blogmeta instead. This is to prevent
442
  * multiple {@link switch_to_blog()} calls in the activity stream.
443
  *
444
- * @since 2.0.0
445
  *
446
  * @param object $activity The BP_Activity_Activity object
447
- *
448
  * @return bool
449
  */
450
  function bp_blogs_comments_open( $activity ) {
@@ -527,11 +444,11 @@ function bp_blogs_comments_open( $activity ) {
527
  *
528
  * For blog post -> activity comment, see {@link bp_blogs_record_comment()}.
529
  *
530
- * @since 2.0.0
531
  *
532
- * @param int $comment_id The activity ID for the posted activity comment.
533
- * @param array $params Parameters for the activity comment.
534
- * @param object $parent_activity Parameters of the parent activity item (in this case, the blog post).
535
  */
536
  function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_activity ) {
537
  // if parent activity isn't a blog post, stop now!
@@ -604,34 +521,14 @@ function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_
604
  // doesn't change on the frontend until the next page refresh.
605
  $resave_activity = new BP_Activity_Activity( $comment_id );
606
  $resave_activity->primary_link = get_comment_link( $post_comment_id );
607
-
608
- /**
609
- * Now that the activity id exists and the post comment was created, we don't need to update
610
- * the content of the comment as there are no chances it has evolved.
611
- */
612
- remove_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 );
613
-
614
  $resave_activity->save();
615
 
616
- // add the edit activity comment hook back
617
- add_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comment', 20 );
618
-
619
  // multisite again!
620
  restore_current_blog();
621
 
622
  // add the comment hook back
623
  add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
624
 
625
- /**
626
- * Fires after activity comments have been synced and posted as blog comments.
627
- *
628
- * @since 2.0.0
629
- *
630
- * @param int $comment_id The activity ID for the posted activity comment.
631
- * @param array $args Array of args used for the comment syncing.
632
- * @param object $parent_activity Parameters of the blog post parent activity item.
633
- * @param object $user User data object for the blog comment.
634
- */
635
  do_action( 'bp_blogs_sync_add_from_activity_comment', $comment_id, $args, $parent_activity, $user );
636
  }
637
  add_action( 'bp_activity_comment_posted', 'bp_blogs_sync_add_from_activity_comment', 10, 3 );
@@ -643,13 +540,11 @@ add_action( 'bp_activity_comment_posted', 'bp_blogs_sync_add_from_activity_comme
643
  * of the 'bp_activity_delete_comment' action because we need to fetch the
644
  * activity comment children before they are deleted.
645
  *
646
- * @since 2.0.0
647
  *
648
  * @param bool $retval
649
- * @param int $parent_activity_id The parent activity ID for the activity comment.
650
- * @param int $activity_id The activity ID for the pending deleted activity comment.
651
- *
652
- * @return bool
653
  */
654
  function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_id, $activity_id ) {
655
  // check if parent activity is a blog post
@@ -691,7 +586,7 @@ add_filter( 'bp_activity_delete_comment_pre', 'bp_blogs_sync_delete_from_activit
691
  /**
692
  * Updates the blog comment when the associated activity comment is edited.
693
  *
694
- * @since 2.0.0
695
  *
696
  * @param BP_Activity_Activity $activity The activity object.
697
  */
@@ -748,101 +643,19 @@ add_action( 'bp_activity_before_save', 'bp_blogs_sync_activity_edit_to_post_comm
748
  * Since these activity entries are deleted, we need to remove the deleted
749
  * activity comment IDs from each comment's meta when a post is trashed.
750
  *
751
- * @since 2.0.0
752
  *
753
- * @param int $post_id The post ID.
754
- * @param array $comments Array of comment statuses. The key is comment ID, the
755
- * value is the $comment->comment_approved value.
756
  */
757
- function bp_blogs_remove_activity_meta_for_trashed_comments( $post_id = 0, $comments = array() ) {
758
- if ( ! empty( $comments ) ) {
759
- foreach ( array_keys( $comments ) as $comment_id ) {
760
- delete_comment_meta( $comment_id, 'bp_activity_comment_id' );
761
- }
762
  }
763
  }
764
  add_action( 'trashed_post_comments', 'bp_blogs_remove_activity_meta_for_trashed_comments', 10, 2 );
765
 
766
- /**
767
- * Filter 'new_blog_comment' bp_has_activities() loop to include new- and old-style blog activity comment items.
768
- *
769
- * In BuddyPress 2.0, the schema for storing activity items related to blog
770
- * posts changed. Instead creating new top-level 'new_blog_comment' activity
771
- * items, blog comments are recorded in the activity stream as comments on the
772
- * 'new_blog_post' activity items corresponding to the parent post. This filter
773
- * ensures that the 'new_blog_comment' filter in bp_has_activities() (which
774
- * powers the 'Comments' filter in the activity directory dropdown) includes
775
- * both old-style and new-style activity comments.
776
- *
777
- * This implementation involves filtering the activity queries directly, and
778
- * should be considered a stopgap. The proper solution would involve enabling
779
- * multiple query condition clauses, connected by an OR, in the bp_has_activities()
780
- * API.
781
- *
782
- * @since 2.1.0
783
- *
784
- * @param array $args Arguments passed from bp_parse_args() in bp_has_activities().
785
- *
786
- * @return array $args
787
- */
788
- function bp_blogs_new_blog_comment_query_backpat( $args ) {
789
- global $wpdb;
790
- $bp = buddypress();
791
-
792
- // Bail if this is not a 'new_blog_comment' query
793
- if ( 'new_blog_comment' !== $args['action'] ) {
794
- return $args;
795
- }
796
-
797
- // Comment synced ?
798
- $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT activity_id FROM {$bp->activity->table_name_meta} WHERE meta_key = %s", 'bp_blogs_post_comment_id' ) );
799
-
800
- if ( empty( $activity_ids ) ) {
801
- return $args;
802
- }
803
-
804
- // Init the filter query
805
- $filter_query = array();
806
-
807
- if ( 'null' === $args['scope'] ) {
808
- $args['scope'] = '';
809
- } elseif ( 'just-me' === $args['scope'] ) {
810
- $filter_query = array(
811
- 'relation' => 'AND',
812
- array(
813
- 'column' => 'user_id',
814
- 'value' => bp_displayed_user_id(),
815
- ),
816
- );
817
- $args['scope'] = '';
818
- }
819
-
820
- $filter_query[] = array(
821
- 'relation' => 'OR',
822
- array(
823
- 'column' => 'type',
824
- 'value' => $args['action'],
825
- ),
826
- array(
827
- 'column' => 'id',
828
- 'value' => $activity_ids,
829
- 'compare' => 'IN'
830
- ),
831
- );
832
-
833
- $args['filter_query'] = $filter_query;
834
-
835
- // Make sure to have comment in stream mode && avoid duplicate content
836
- $args['display_comments'] = 'stream';
837
-
838
- // Finally reset the action
839
- $args['action'] = '';
840
-
841
- // Return the original arguments
842
- return $args;
843
- }
844
- add_filter( 'bp_after_has_activities_parse_args', 'bp_blogs_new_blog_comment_query_backpat' );
845
-
846
  /**
847
  * Utility function to set up some variables for use in the activity loop.
848
  *
@@ -851,12 +664,12 @@ add_filter( 'bp_after_has_activities_parse_args', 'bp_blogs_new_blog_comment_que
851
  *
852
  * This is to prevent having to requery these items later on.
853
  *
854
- * @since 2.0.0
855
  *
856
  * @see bp_blogs_disable_activity_commenting()
857
  * @see bp_blogs_setup_comment_loop_globals_on_ajax()
858
  *
859
- * @param object $activity The BP_Activity_Activity object.
860
  */
861
  function bp_blogs_setup_activity_loop_globals( $activity ) {
862
  if ( ! is_object( $activity ) ) {
@@ -903,7 +716,7 @@ function bp_blogs_setup_activity_loop_globals( $activity ) {
903
  /**
904
  * Set up some globals used in the activity comment loop when AJAX is used.
905
  *
906
- * @since 2.0.0
907
  *
908
  * @see bp_blogs_setup_activity_loop_globals()
909
  */
@@ -935,10 +748,9 @@ add_action( 'bp_before_activity_comment', 'bp_blogs_setup_comment_loop_globals_o
935
  * based on a certain age
936
  * - the activity entry is a 'new_blog_comment' type
937
  *
938
- * @since 2.0.0
939
  *
940
  * @param bool $retval Is activity commenting enabled for this activity entry?
941
- *
942
  * @return bool
943
  */
944
  function bp_blogs_disable_activity_commenting( $retval ) {
@@ -987,11 +799,10 @@ add_filter( 'bp_activity_can_comment', 'bp_blogs_disable_activity_commenting' );
987
  * This check uses a locally-cached value set in {@link bp_blogs_disable_activity_commenting()}
988
  * via {@link bp_blogs_setup_activity_loop_globals()}.
989
  *
990
- * @since 2.0.0
991
- *
992
- * @param bool $retval Are replies allowed for this activity reply?
993
- * @param object|array $comment The activity comment object.
994
  *
 
 
995
  * @return bool
996
  */
997
  function bp_blogs_can_comment_reply( $retval, $comment ) {
@@ -1026,22 +837,15 @@ add_filter( 'bp_activity_can_comment_reply', 'bp_blogs_can_comment_reply', 10, 2
1026
  * This is only done if activity commenting is allowed and whether the parent
1027
  * activity item is a 'new_blog_post' entry.
1028
  *
1029
- * @since 2.0.0
1030
- *
1031
- * @param string $retval The activity comment permalink.
1032
  *
 
1033
  * @return string
1034
  */
1035
- function bp_blogs_activity_comment_permalink( $retval = '' ) {
1036
  global $activities_template;
1037
 
1038
- // Get the current comment ID
1039
- $item_id = isset( $activities_template->activity->current_comment->item_id )
1040
- ? $activities_template->activity->current_comment->item_id
1041
- : false;
1042
-
1043
- // Maybe adjust the link if item ID exists
1044
- if ( ( false !== $item_id ) && isset( buddypress()->blogs->allow_comments[ $item_id ] ) ) {
1045
  $retval = $activities_template->activity->current_comment->primary_link;
1046
  }
1047
 
@@ -1054,11 +858,10 @@ add_filter( 'bp_get_activity_comment_permalink', 'bp_blogs_activity_comment_perm
1054
  *
1055
  * This is only done if the activity comment is associated with a blog comment.
1056
  *
1057
- * @since 2.0.1
1058
  *
1059
- * @param string $retval The activity permalink.
1060
  * @param BP_Activity_Activity $activity
1061
- *
1062
  * @return string
1063
  */
1064
  function bp_blogs_activity_comment_single_permalink( $retval, $activity ) {
@@ -1081,11 +884,10 @@ add_filter( 'bp_activity_get_permalink', 'bp_blogs_activity_comment_single_perma
1081
  *
1082
  * This is only done if the activity comment is associated with a blog comment.
1083
  *
1084
- * @since 2.0.1
1085
  *
1086
- * @param string $retval The activity action.
1087
  * @param BP_Activity_Activity $activity
1088
- *
1089
  * @return string
1090
  */
1091
  function bp_blogs_activity_comment_single_action( $retval, $activity ) {
1
  <?php
2
+
3
  /**
4
  * BuddyPress Blogs Activity.
5
  *
7
  * @subpackage BlogsActivity
8
  */
9
 
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
 
13
  /**
14
  * Register activity actions for the blogs component.
15
  *
16
+ * @since BuddyPress (1.0.0)
17
+ *
18
+ * @global object $bp The BuddyPress global settings object.
19
  *
20
  * @return bool|null Returns false if activity component is not active.
21
  */
22
  function bp_blogs_register_activity_actions() {
23
+ global $bp;
24
 
25
  // Bail if activity is not active
26
  if ( ! bp_is_active( 'activity' ) ) {
32
  $bp->blogs->id,
33
  'new_blog',
34
  __( 'New site created', 'buddypress' ),
35
+ 'bp_blogs_format_activity_action_new_blog'
 
 
 
36
  );
37
  }
38
 
39
+ bp_activity_set_action(
40
+ $bp->blogs->id,
41
+ 'new_blog_post',
42
+ __( 'New post published', 'buddypress' ),
43
+ 'bp_blogs_format_activity_action_new_blog_post'
44
+ );
45
+
46
+ bp_activity_set_action(
47
+ $bp->blogs->id,
48
+ 'new_blog_comment',
49
+ __( 'New post comment posted', 'buddypress' ),
50
+ 'bp_blogs_format_activity_action_new_blog_comment'
51
+ );
52
 
 
 
 
 
 
53
  do_action( 'bp_blogs_register_activity_actions' );
54
  }
55
  add_action( 'bp_register_activity_actions', 'bp_blogs_register_activity_actions' );
57
  /**
58
  * Format 'new_blog' activity actions.
59
  *
60
+ * @since BuddyPress (2.0.0)
 
 
 
61
  *
62
+ * @param string $action Static activity action.
63
+ * @param obj $activity Activity data object.
64
  */
65
  function bp_blogs_format_activity_action_new_blog( $action, $activity ) {
66
  $blog_url = bp_blogs_get_blogmeta( $activity->item_id, 'url' );
80
  }
81
  }
82
 
 
 
 
 
 
 
 
 
83
  return apply_filters( 'bp_blogs_format_activity_action_new_blog', $action, $activity );
84
  }
85
 
86
  /**
87
  * Format 'new_blog_post' activity actions.
88
  *
89
+ * @since BuddyPress (2.0.0)
 
 
 
90
  *
91
+ * @param string $action Static activity action.
92
+ * @param obj $activity Activity data object.
93
  */
94
  function bp_blogs_format_activity_action_new_blog_post( $action, $activity ) {
95
  $blog_url = bp_blogs_get_blogmeta( $activity->item_id, 'url' );
103
  bp_blogs_update_blogmeta( $activity->item_id, 'name', $blog_name );
104
  }
105
 
106
+ $post_url = add_query_arg( 'p', $activity->secondary_item_id, trailingslashit( $blog_url ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
 
108
+ $post_title = bp_activity_get_meta( $activity->id, 'post_title' );
 
 
 
109
 
110
+ // Should only be empty at the time of post creation
 
 
 
111
  if ( empty( $post_title ) ) {
 
 
 
112
  switch_to_blog( $activity->item_id );
113
 
114
  $post = get_post( $activity->secondary_item_id );
115
  if ( is_a( $post, 'WP_Post' ) ) {
116
+ $post_title = $post->post_title;
117
+ bp_activity_update_meta( $activity->id, 'post_title', $post_title );
 
 
 
 
 
 
 
118
  }
119
 
120
  restore_current_blog();
121
  }
122
 
123
+ $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>';
 
124
 
125
  $user_link = bp_core_get_userlink( $activity->user_id );
126
 
 
127
  if ( is_multisite() ) {
128
  $action = sprintf( __( '%1$s wrote a new post, %2$s, on the site %3$s', 'buddypress' ), $user_link, $post_link, '<a href="' . esc_url( $blog_url ) . '">' . esc_html( $blog_name ) . '</a>' );
129
  } else {
141
  }
142
  }
143
 
 
 
 
 
 
 
 
 
144
  return apply_filters( 'bp_blogs_format_activity_action_new_blog_post', $action, $activity );
145
  }
146
 
147
  /**
148
  * Format 'new_blog_comment' activity actions.
149
  *
150
+ * @since BuddyPress (2.0.0)
 
 
 
151
  *
152
+ * @param string $action Static activity action.
153
+ * @param obj $activity Activity data object.
154
  */
155
  function bp_blogs_format_activity_action_new_blog_comment( $action, $activity ) {
156
  $blog_url = bp_blogs_get_blogmeta( $activity->item_id, 'url' );
188
  restore_current_blog();
189
  }
190
 
191
+ $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>';
192
  $user_link = bp_core_get_userlink( $activity->user_id );
193
 
194
  if ( is_multisite() ) {
208
  }
209
  }
210
 
 
 
 
 
 
 
 
 
211
  return apply_filters( 'bp_blogs_format_activity_action_new_blog_comment', $action, $activity );
212
  }
213
 
216
  *
217
  * This reduces database overhead during the activity loop.
218
  *
219
+ * @since BuddyPress (2.0.0)
220
  *
221
  * @param array $activities Array of activity items.
 
222
  * @return array
223
  */
224
  function bp_blogs_prefetch_activity_object_data( $activities ) {
247
  /**
248
  * Record blog-related activity to the activity stream.
249
  *
250
+ * @since BuddyPress (1.0.0)
251
  *
252
  * @see bp_activity_add() for description of parameters.
253
+ * @global object $bp The BuddyPress global settings object.
254
  *
255
+ * @param array $args {
256
  * See {@link bp_activity_add()} for complete description of arguments.
257
  * The arguments listed here have different default values from
258
  * bp_activity_add().
261
  * @return int|bool On success, returns the activity ID. False on failure.
262
  */
263
  function bp_blogs_record_activity( $args = '' ) {
264
+ global $bp;
265
 
266
  // Bail if activity is not active
267
+ if ( ! bp_is_active( 'activity' ) )
268
  return false;
 
 
 
269
 
270
  $defaults = array(
271
  'user_id' => bp_loggedin_user_id(),
281
  );
282
 
283
  $r = wp_parse_args( $args, $defaults );
284
+ extract( $r, EXTR_SKIP );
285
 
286
+ // Remove large images and replace them with just one image thumbnail
287
+ if ( !empty( $content ) )
288
+ $content = bp_activity_thumbnail_content_images( $content, $primary_link, $r );
289
 
290
+ if ( !empty( $action ) )
291
+ $action = apply_filters( 'bp_blogs_record_activity_action', $action );
 
 
 
 
 
 
 
292
 
293
+ if ( !empty( $content ) )
294
+ $content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $content ), $content );
 
 
 
 
 
 
 
 
 
 
 
295
 
296
  // Check for an existing entry and update if one exists.
297
  $id = bp_activity_get_activity_id( array(
298
+ 'user_id' => $user_id,
299
+ 'component' => $component,
300
+ 'type' => $type,
301
+ 'item_id' => $item_id,
302
+ 'secondary_item_id' => $secondary_item_id
303
  ) );
304
 
305
+ return bp_activity_add( array( 'id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
306
  }
307
 
308
  /**
309
  * Delete a blog-related activity stream item.
310
  *
311
+ * @since BuddyPress (1.0.0)
312
  *
313
  * @see bp_activity_delete() for description of parameters.
314
+ * @global object $bp The BuddyPress global settings object.
315
  *
316
+ * @param array $args {
317
  * See {@link bp_activity_delete()} for complete description of arguments.
318
  * The arguments listed here have different default values from
319
  * bp_activity_add().
321
  * }
322
  * @return bool True on success, false on failure.
323
  */
324
+ function bp_blogs_delete_activity( $args = true ) {
325
+ global $bp;
326
 
327
  // Bail if activity is not active
328
+ if ( ! bp_is_active( 'activity' ) )
329
  return false;
 
330
 
331
+ $defaults = array(
332
  'item_id' => false,
333
+ 'component' => $bp->blogs->id,
334
  'type' => false,
335
  'user_id' => false,
336
  'secondary_item_id' => false
337
+ );
338
 
339
+ $params = wp_parse_args( $args, $defaults );
340
+ extract( $params, EXTR_SKIP );
341
+
342
+ bp_activity_delete_by_item_id( array(
343
+ 'item_id' => $item_id,
344
+ 'component' => $component,
345
+ 'type' => $type,
346
+ 'user_id' => $user_id,
347
+ 'secondary_item_id' => $secondary_item_id
348
+ ) );
349
  }
350
 
351
  /**
359
  * to blogmeta and checks the values in blogmeta instead. This is to prevent
360
  * multiple {@link switch_to_blog()} calls in the activity stream.
361
  *
362
+ * @since BuddyPress (2.0.0)
363
  *
364
  * @param object $activity The BP_Activity_Activity object
 
365
  * @return bool
366
  */
367
  function bp_blogs_comments_open( $activity ) {
444
  *
445
  * For blog post -> activity comment, see {@link bp_blogs_record_comment()}.
446
  *
447
+ * @since BuddyPress (2.0.0)
448
  *
449
+ * @param int $comment_id The activity ID for the posted activity comment.
450
+ * @param array $params Parameters for the activity comment.
451
+ * @param object Parameters of the parent activity item (in this case, the blog post).
452
  */
453
  function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_activity ) {
454
  // if parent activity isn't a blog post, stop now!
521
  // doesn't change on the frontend until the next page refresh.
522
  $resave_activity = new BP_Activity_Activity( $comment_id );
523
  $resave_activity->primary_link = get_comment_link( $post_comment_id );
 
 
 
 
 
 
 
524
  $resave_activity->save();
525
 
 
 
 
526
  // multisite again!
527
  restore_current_blog();
528
 
529
  // add the comment hook back
530
  add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
531
 
 
 
 
 
 
 
 
 
 
 
532
  do_action( 'bp_blogs_sync_add_from_activity_comment', $comment_id, $args, $parent_activity, $user );
533
  }
534
  add_action( 'bp_activity_comment_posted', 'bp_blogs_sync_add_from_activity_comment', 10, 3 );
540
  * of the 'bp_activity_delete_comment' action because we need to fetch the
541
  * activity comment children before they are deleted.
542
  *
543
+ * @since BuddyPress (2.0.0)
544
  *
545
  * @param bool $retval
546
+ * @param int $parent_activity_id The parent activity ID for the activity comment.
547
+ * @param int $activity_id The activity ID for the pending deleted activity comment.
 
 
548
  */
549
  function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_id, $activity_id ) {
550
  // check if parent activity is a blog post
586
  /**
587
  * Updates the blog comment when the associated activity comment is edited.
588
  *
589
+ * @since BuddyPress (2.0.0)
590
  *
591
  * @param BP_Activity_Activity $activity The activity object.
592
  */
643
  * Since these activity entries are deleted, we need to remove the deleted
644
  * activity comment IDs from each comment's meta when a post is trashed.
645
  *
646
+ * @since BuddyPress (2.0.0)
647
  *
648
+ * @param int $post_id The post ID
649
+ * @param array $statuses Array of comment statuses. The key is comment ID, the
650
+ * value is the $comment->comment_approved value.
651
  */
652
+ function bp_blogs_remove_activity_meta_for_trashed_comments( $post_id, $statuses ) {
653
+ foreach ( $statuses as $comment_id => $comment_approved ) {
654
+ delete_comment_meta( $comment_id, 'bp_activity_comment_id' );
 
 
655
  }
656
  }
657
  add_action( 'trashed_post_comments', 'bp_blogs_remove_activity_meta_for_trashed_comments', 10, 2 );
658
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
659
  /**
660
  * Utility function to set up some variables for use in the activity loop.
661
  *
664
  *
665
  * This is to prevent having to requery these items later on.
666
  *
667
+ * @since BuddyPress (2.0.0)
668
  *
669
  * @see bp_blogs_disable_activity_commenting()
670
  * @see bp_blogs_setup_comment_loop_globals_on_ajax()
671
  *
672
+ * @param object $activity The BP_Activity_Activity object
673
  */
674
  function bp_blogs_setup_activity_loop_globals( $activity ) {
675
  if ( ! is_object( $activity ) ) {
716
  /**
717
  * Set up some globals used in the activity comment loop when AJAX is used.
718
  *
719
+ * @since BuddyPress (2.0.0)
720
  *
721
  * @see bp_blogs_setup_activity_loop_globals()
722
  */
748
  * based on a certain age
749
  * - the activity entry is a 'new_blog_comment' type
750
  *
751
+ * @since BuddyPress (2.0.0)
752
  *
753
  * @param bool $retval Is activity commenting enabled for this activity entry?
 
754
  * @return bool
755
  */
756
  function bp_blogs_disable_activity_commenting( $retval ) {
799
  * This check uses a locally-cached value set in {@link bp_blogs_disable_activity_commenting()}
800
  * via {@link bp_blogs_setup_activity_loop_globals()}.
801
  *
802
+ * @since BuddyPress (2.0.0)
 
 
 
803
  *
804
+ * @param bool $retval Are replies allowed for this activity reply?
805
+ * @param object $comment The activity comment object
806
  * @return bool
807
  */
808
  function bp_blogs_can_comment_reply( $retval, $comment ) {
837
  * This is only done if activity commenting is allowed and whether the parent
838
  * activity item is a 'new_blog_post' entry.
839
  *
840
+ * @since BuddyPress (2.0.0)
 
 
841
  *
842
+ * @param string $retval The activity comment permalink
843
  * @return string
844
  */
845
+ function bp_blogs_activity_comment_permalink( $retval ) {
846
  global $activities_template;
847
 
848
+ if ( isset( buddypress()->blogs->allow_comments[$activities_template->activity->current_comment->item_id] ) ){
 
 
 
 
 
 
849
  $retval = $activities_template->activity->current_comment->primary_link;
850
  }
851
 
858
  *
859
  * This is only done if the activity comment is associated with a blog comment.
860
  *
861
+ * @since BuddyPress (2.0.1)
862
  *
863
+ * @param string $retval The activity permalink
864
  * @param BP_Activity_Activity $activity
 
865
  * @return string
866
  */
867
  function bp_blogs_activity_comment_single_permalink( $retval, $activity ) {
884
  *
885
  * This is only done if the activity comment is associated with a blog comment.
886
  *
887
+ * @since BuddyPress (2.0.1)
888
  *
889
+ * @param string $retval The activity action
890
  * @param BP_Activity_Activity $activity
 
891
  * @return string
892
  */
893
  function bp_blogs_activity_comment_single_action( $retval, $activity ) {
bp-blogs/bp-blogs-buddybar.php ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * BuddyPress Blogs BuddyBar functions.
5
+ *
6
+ * @package BuddyPress
7
+ * @subpackage BlogsBuddyBar
8
+ */
9
+
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
+
13
+ /**
14
+ * Add a Sites menu to the BuddyBar.
15
+ *
16
+ * @since BuddyPress (1.0.0)
17
+ *
18
+ * @global object $bp The BuddyPress global settings object.
19
+ *
20
+ * @return bool|null Returns false on failure. Otherwise echoes the menu item.
21
+ */
22
+ function bp_adminbar_blogs_menu() {
23
+ global $bp;
24
+
25
+ if ( !is_user_logged_in() || !bp_is_active( 'blogs' ) )
26
+ return false;
27
+
28
+ if ( !is_multisite() )
29
+ return false;
30
+
31
+ $blogs = wp_cache_get( 'bp_blogs_of_user_' . bp_loggedin_user_id() . '_inc_hidden', 'bp' );
32
+ if ( empty( $blogs ) ) {
33
+ $blogs = bp_blogs_get_blogs_for_user( bp_loggedin_user_id(), true );
34
+ wp_cache_set( 'bp_blogs_of_user_' . bp_loggedin_user_id() . '_inc_hidden', $blogs, 'bp' );
35
+ }
36
+
37
+ $counter = 0;
38
+ if ( is_array( $blogs['blogs'] ) && (int) $blogs['count'] ) {
39
+
40
+ echo '<li id="bp-adminbar-blogs-menu"><a href="' . trailingslashit( bp_loggedin_user_domain() . bp_get_blogs_slug() ) . '">';
41
+
42
+ _e( 'My Sites', 'buddypress' );
43
+
44
+ echo '</a>';
45
+ echo '<ul>';
46
+
47
+ foreach ( (array) $blogs['blogs'] as $blog ) {
48
+ $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
49
+ $site_url = esc_attr( $blog->siteurl );
50
+
51
+ echo '<li' . $alt . '>';
52
+ echo '<a href="' . $site_url . '">' . esc_html( $blog->name ) . '</a>';
53
+ echo '<ul>';
54
+ echo '<li class="alt"><a href="' . $site_url . 'wp-admin/">' . __( 'Dashboard', 'buddypress' ) . '</a></li>';
55
+ echo '<li><a href="' . $site_url . 'wp-admin/post-new.php">' . __( 'New Post', 'buddypress' ) . '</a></li>';
56
+ echo '<li class="alt"><a href="' . $site_url . 'wp-admin/edit.php">' . __( 'Manage Posts', 'buddypress' ) . '</a></li>';
57
+ echo '<li><a href="' . $site_url . 'wp-admin/edit-comments.php">' . __( 'Manage Comments', 'buddypress' ) . '</a></li>';
58
+ echo '</ul>';
59
+
60
+ do_action( 'bp_adminbar_blog_items', $blog );
61
+
62
+ echo '</li>';
63
+ $counter++;
64
+ }
65
+
66
+ $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
67
+
68
+ if ( bp_blog_signup_enabled() ) {
69
+ echo '<li' . $alt . '>';
70
+ echo '<a href="' . bp_get_root_domain() . '/' . bp_get_blogs_root_slug() . '/create/">' . __( 'Create a Site!', 'buddypress' ) . '</a>';
71
+ echo '</li>';
72
+ }
73
+
74
+ echo '</ul>';
75
+ echo '</li>';
76
+ }
77
+ }
78
+ add_action( 'bp_adminbar_menus', 'bp_adminbar_blogs_menu', 6 );
bp-blogs/bp-blogs-cache.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  /**
3
  * BuddyPress Blogs Caching.
4
  *
@@ -9,8 +10,8 @@
9
  * @subpackage BlogsCache
10
  */
11
 
12
- // Exit if accessed directly.
13
- defined( 'ABSPATH' ) || exit;
14
 
15
  /**
16
  * Slurp up blogmeta for a specified set of blogs.
@@ -19,8 +20,8 @@ defined( 'ABSPATH' ) || exit;
19
  * in $blog_ids and adds it to the WP cache. This improves efficiency when
20
  * using querying blogmeta inline.
21
  *
22
- * @param int|string|array|bool $blog_ids Accepts a single blog ID, or a comma-
23
- * separated list or array of blog IDs.
24
  */
25
  function bp_blogs_update_meta_cache( $blog_ids = false ) {
26
  $cache_args = array(
@@ -36,26 +37,34 @@ function bp_blogs_update_meta_cache( $blog_ids = false ) {
36
  /**
37
  * Clear the blog object cache.
38
  *
39
- * @since 1.0.0
40
  *
41
  * @param int $blog_id ID of the current blog.
42
  * @param int $user_id ID of the user whose blog cache should be cleared.
43
  */
44
- function bp_blogs_clear_blog_object_cache( $blog_id = 0, $user_id = 0 ) {
45
- if ( ! empty( $user_id ) ) {
46
- wp_cache_delete( 'bp_blogs_of_user_' . $user_id, 'bp' );
47
- wp_cache_delete( 'bp_total_blogs_for_user_' . $user_id, 'bp' );
48
- }
49
 
 
 
 
 
 
 
 
 
 
 
50
  wp_cache_delete( 'bp_total_blogs', 'bp' );
51
  }
52
 
53
- // List actions to clear object caches on.
54
  add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 );
55
- add_action( 'wpmu_new_blog', 'bp_blogs_clear_blog_object_cache', 10, 2 );
56
- add_action( 'bp_blogs_remove_blog', 'bp_blogs_clear_blog_object_cache' );
57
 
58
- // List actions to clear super cached pages on, if super cache is installed.
59
  add_action( 'bp_blogs_remove_data_for_blog', 'bp_core_clear_cache' );
60
  add_action( 'bp_blogs_remove_comment', 'bp_core_clear_cache' );
61
  add_action( 'bp_blogs_remove_post', 'bp_core_clear_cache' );
1
  <?php
2
+
3
  /**
4
  * BuddyPress Blogs Caching.
5
  *
10
  * @subpackage BlogsCache
11
  */
12
 
13
+ // Exit if accessed directly
14
+ if ( !defined( 'ABSPATH' ) ) exit;
15
 
16
  /**
17
  * Slurp up blogmeta for a specified set of blogs.
20
  * in $blog_ids and adds it to the WP cache. This improves efficiency when
21
  * using querying blogmeta inline.
22
  *
23
+ * @param int|str|array $blog_ids Accepts a single blog ID, or a comma-
24
+ * separated list or array of blog IDs.
25
  */
26
  function bp_blogs_update_meta_cache( $blog_ids = false ) {
27
  $cache_args = array(
37
  /**
38
  * Clear the blog object cache.
39
  *
40
+ * @since BuddyPress (1.0.0)
41
  *
42
  * @param int $blog_id ID of the current blog.
43
  * @param int $user_id ID of the user whose blog cache should be cleared.
44
  */
45
+ function bp_blogs_clear_blog_object_cache( $blog_id, $user_id ) {
46
+ wp_cache_delete( 'bp_blogs_of_user_' . $user_id, 'bp' );
47
+ wp_cache_delete( 'bp_total_blogs_for_user_' . $user_id, 'bp' );
48
+ }
 
49
 
50
+ /**
51
+ * Clear cache when a new blog is created.
52
+ *
53
+ * @since BuddyPress (1.0.0)
54
+ *
55
+ * @param BP_Blogs_Blog $recorded_blog_obj The recorded blog, passed by
56
+ * 'bp_blogs_new_blog'.
57
+ */
58
+ function bp_blogs_format_clear_blog_cache( $recorded_blog_obj ) {
59
+ bp_blogs_clear_blog_object_cache( false, $recorded_blog_obj->user_id );
60
  wp_cache_delete( 'bp_total_blogs', 'bp' );
61
  }
62
 
63
+ // List actions to clear object caches on
64
  add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 );
65
+ add_action( 'bp_blogs_new_blog', 'bp_blogs_format_clear_blog_cache', 10, 2 );
 
66
 
67
+ // List actions to clear super cached pages on, if super cache is installed
68
  add_action( 'bp_blogs_remove_data_for_blog', 'bp_core_clear_cache' );
69
  add_action( 'bp_blogs_remove_comment', 'bp_core_clear_cache' );
70
  add_action( 'bp_blogs_remove_post', 'bp_core_clear_cache' );
bp-blogs/bp-blogs-classes.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  /**
3
  * BuddyPress Blogs Classes.
4
  *
@@ -6,7 +7,521 @@
6
  * @subpackage BlogsClasses
7
  */
8
 
9
- // Exit if accessed directly.
10
- defined( 'ABSPATH' ) || exit;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- require dirname( __FILE__ ) . '/classes/class-bp-blogs-blog.php';
 
 
1
  <?php
2
+
3
  /**
4
  * BuddyPress Blogs Classes.
5
  *
7
  * @subpackage BlogsClasses
8
  */
9
 
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
+
13
+ /**
14
+ * The main BuddyPress blog class.
15
+ *
16
+ * A BP_Blogs_Object represents a link between a specific WordPress blog on a
17
+ * network and a specific user on that blog.
18
+ *
19
+ * @since BuddyPress (1.0.0)
20
+ */
21
+ class BP_Blogs_Blog {
22
+ public $id;
23
+ public $user_id;
24
+ public $blog_id;
25
+
26
+ /**
27
+ * Constructor method.
28
+ *
29
+ * @param int $id Optional. The ID of the blog.
30
+ */
31
+ public function __construct( $id = null ) {
32
+ if ( !empty( $id ) ) {
33
+ $this->id = $id;
34
+ $this->populate();
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Populate the object with data about the specific activity item.
40
+ */
41
+ public function populate() {
42
+ global $wpdb, $bp;
43
+
44
+ $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name} WHERE id = %d", $this->id ) );
45
+
46
+ $this->user_id = $blog->user_id;
47
+ $this->blog_id = $blog->blog_id;
48
+ }
49
+
50
+ /**
51
+ * Save the BP blog data to the database.
52
+ *
53
+ * @return bool True on success, false on failure.
54
+ */
55
+ public function save() {
56
+ global $wpdb, $bp;
57
+
58
+ $this->user_id = apply_filters( 'bp_blogs_blog_user_id_before_save', $this->user_id, $this->id );
59
+ $this->blog_id = apply_filters( 'bp_blogs_blog_id_before_save', $this->blog_id, $this->id );
60
+
61
+ do_action_ref_array( 'bp_blogs_blog_before_save', array( &$this ) );
62
+
63
+ // Don't try and save if there is no user ID or blog ID set.
64
+ if ( !$this->user_id || !$this->blog_id )
65
+ return false;
66
+
67
+ // Don't save if this blog has already been recorded for the user.
68
+ if ( !$this->id && $this->exists() )
69
+ return false;
70
+
71
+ if ( $this->id ) {
72
+ // Update
73
+ $sql = $wpdb->prepare( "UPDATE {$bp->blogs->table_name} SET user_id = %d, blog_id = %d WHERE id = %d", $this->user_id, $this->blog_id, $this->id );
74
+ } else {
75
+ // Save
76
+ $sql = $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name} ( user_id, blog_id ) VALUES ( %d, %d )", $this->user_id, $this->blog_id );
77
+ }
78
+
79
+ if ( !$wpdb->query($sql) )
80
+ return false;
81
+
82
+ do_action_ref_array( 'bp_blogs_blog_after_save', array( &$this ) );
83
+
84
+ if ( $this->id )
85
+ return $this->id;
86
+ else
87
+ return $wpdb->insert_id;
88
+ }
89
+
90
+ /**
91
+ * Check whether an association between this user and this blog exists.
92
+ *
93
+ * @return int The number of associations between the user and blog
94
+ * saved in the blog component tables.
95
+ */
96
+ public function exists() {
97
+ global $bp, $wpdb;
98
+
99
+ return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $this->user_id, $this->blog_id ) );
100
+ }
101
+
102
+ /** Static Methods ***************************************************/
103
+
104
+ /**
105
+ * Retrieve a set of blog-user associations.
106
+ *
107
+ * @param string $type The order in which results should be returned.
108
+ * 'active', 'alphabetical', 'newest', or 'random'.
109
+ * @param int|bool $limit Optional. The maximum records to return.
110
+ * Default: false.
111
+ * @param int|bool $page Optional. The page of records to return.
112
+ * Default: false (unlimited results).
113
+ * @param int $user_id Optional. ID of the user whose blogs are being
114
+ * retrieved. Default: 0.
115
+ * @param string|bool $search_terms Optional. Search by text stored in
116
+ * blogmeta (such as the blog name). Default: false.
117
+ * @param bool $update_meta_cache Whether to pre-fetch metadata for
118
+ * blogs. Default: true.
119
+ * @param array $include_blog_ids Array of blog IDs to include.
120
+ * @return array Multidimensional results array, structured as follows:
121
+ * 'blogs' - Array of located blog objects
122
+ * 'total' - A count of the total blogs matching the filter params
123
+ */
124
+ public static function get( $type, $limit = false, $page = false, $user_id = 0, $search_terms = false, $update_meta_cache = true, $include_blog_ids = false ) {
125
+ global $bp, $wpdb;
126
+
127
+ if ( !is_user_logged_in() || ( !bp_current_user_can( 'bp_moderate' ) && ( $user_id != bp_loggedin_user_id() ) ) )
128
+ $hidden_sql = "AND wb.public = 1";
129
+ else
130
+ $hidden_sql = '';
131
+
132
+ $pag_sql = ( $limit && $page ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ) : '';
133
+
134
+ $user_sql = !empty( $user_id ) ? $wpdb->prepare( " AND b.user_id = %d", $user_id ) : '';
135
+
136
+ switch ( $type ) {
137
+ case 'active': default:
138
+ $order_sql = "ORDER BY bm.meta_value DESC";
139
+ break;
140
+ case 'alphabetical':
141
+ $order_sql = "ORDER BY bm2.meta_value ASC";
142
+ break;
143
+ case 'newest':
144
+ $order_sql = "ORDER BY wb.registered DESC";
145
+ break;
146
+ case 'random':
147
+ $order_sql = "ORDER BY RAND()";
148
+ break;
149
+ }
150
+
151
+ $include_sql = '';
152
+ $include_blog_ids = array_filter( wp_parse_id_list( $include_blog_ids ) );
153
+ if ( ! empty( $include_blog_ids ) ) {
154
+ $blog_ids_sql = implode( ',', $include_blog_ids );
155
+ $include_sql = " AND b.blog_id IN ({$blog_ids_sql})";
156
+ }
157
+
158
+ if ( !empty( $search_terms ) ) {
159
+ $filter = esc_sql( like_escape( $search_terms ) );
160
+ $paged_blogs = $wpdb->get_results( "SELECT b.blog_id, b.user_id as admin_user_id, u.user_email as admin_user_email, wb.domain, wb.path, bm.meta_value as last_activity, bm2.meta_value as name FROM {$bp->blogs->table_name} b, {$bp->blogs->table_name_blogmeta} bm, {$bp->blogs->table_name_blogmeta} bm2, {$wpdb->base_prefix}blogs wb, {$wpdb->users} u WHERE b.blog_id = wb.blog_id AND b.user_id = u.ID AND b.blog_id = bm.blog_id AND b.blog_id = bm2.blog_id AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$hidden_sql} AND bm.meta_key = 'last_activity' AND bm2.meta_key = 'name' AND bm2.meta_value LIKE '%%$filter%%' {$user_sql} {$include_sql} GROUP BY b.blog_id {$order_sql} {$pag_sql}" );
161
+ $total_blogs = $wpdb->get_var( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm, {$bp->blogs->table_name_blogmeta} bm2 WHERE b.blog_id = wb.blog_id AND bm.blog_id = b.blog_id AND bm2.blog_id = b.blog_id AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$hidden_sql} AND bm.meta_key = 'name' AND bm2.meta_key = 'description' AND ( bm.meta_value LIKE '%%$filter%%' || bm2.meta_value LIKE '%%$filter%%' ) {$user_sql} {$include_sql}" );
162
+ } else {
163
+ $paged_blogs = $wpdb->get_results( "SELECT b.blog_id, b.user_id as admin_user_id, u.user_email as admin_user_email, wb.domain, wb.path, bm.meta_value as last_activity, bm2.meta_value as name FROM {$bp->blogs->table_name} b, {$bp->blogs->table_name_blogmeta} bm, {$bp->blogs->table_name_blogmeta} bm2, {$wpdb->base_prefix}blogs wb, {$wpdb->users} u WHERE b.blog_id = wb.blog_id AND b.user_id = u.ID AND b.blog_id = bm.blog_id AND b.blog_id = bm2.blog_id {$user_sql} AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$hidden_sql} AND bm.meta_key = 'last_activity' AND bm2.meta_key = 'name' {$include_sql} GROUP BY b.blog_id {$order_sql} {$pag_sql}" );
164
+ $total_blogs = $wpdb->get_var( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb WHERE b.blog_id = wb.blog_id {$user_sql} AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$include_sql} {$hidden_sql}" );
165
+ }
166
+
167
+ $blog_ids = array();
168
+ foreach ( (array) $paged_blogs as $blog ) {
169
+ $blog_ids[] = (int) $blog->blog_id;
170
+ }
171
+
172
+ $paged_blogs = BP_Blogs_Blog::get_blog_extras( $paged_blogs, $blog_ids, $type );
173
+
174
+ if ( $update_meta_cache ) {
175
+ bp_blogs_update_meta_cache( $blog_ids );
176
+ }
177
+
178
+ return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
179
+ }
180
+
181
+ /**
182
+ * Delete the record of a given blog for all users.
183
+ *
184
+ * @param int $blog_id The blog being removed from all users.
185
+ * @return int|bool Number of rows deleted on success, false on failure.
186
+ */
187
+ public static function delete_blog_for_all( $blog_id ) {
188
+ global $wpdb, $bp;
189
+
190
+ bp_blogs_delete_blogmeta( $blog_id );
191
+ return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
192
+ }
193
+
194
+ /**
195
+ * Delete the record of a given blog for a specific user.
196
+ *
197
+ * @param int $blog_id The blog being removed.
198
+ * @param int $user_id Optional. The ID of the user from whom the blog
199
+ * is being removed. If absent, defaults to the logged-in user ID.
200
+ * @return int|bool Number of rows deleted on success, false on failure.
201
+ */
202
+ public static function delete_blog_for_user( $blog_id, $user_id = null ) {
203
+ global $wpdb, $bp;
204
+
205
+ if ( !$user_id )
206
+ $user_id = bp_loggedin_user_id();
207
+
208
+ return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $user_id, $blog_id ) );
209
+ }
210
+
211
+ /**
212
+ * Delete all of a user's blog associations in the BP tables.
213
+ *
214
+ * @param int $user_id Optional. The ID of the user whose blog
215
+ * associations are being deleted. If absent, defaults to
216
+ * logged-in user ID.
217
+ * @return int|bool Number of rows deleted on success, false on failure.
218
+ */
219
+ public static function delete_blogs_for_user( $user_id = null ) {
220
+ global $wpdb, $bp;
221
+
222
+ if ( !$user_id )
223
+ $user_id = bp_loggedin_user_id();
224
+
225
+ return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) );
226
+ }
227
+
228
+ /**
229
+ * Get all of a user's blogs, as tracked by BuddyPress.
230
+ *
231
+ * Note that this is different from the WordPress function
232
+ * {@link get_blogs_of_user()}; the current method returns only those
233
+ * blogs that have been recorded by BuddyPress, while the WP function
234
+ * does a true query of a user's blog capabilities.
235
+ *
236
+ * @param int $user_id Optional. ID of the user whose blogs are being
237
+ * queried. Defaults to logged-in user.
238
+ * @param bool $show_hidden Optional. Whether to include blogs that are
239
+ * not marked public. Defaults to true when viewing one's own
240
+ * profile.
241
+ * @return array Multidimensional results array, structured as follows:
242
+ * 'blogs' - Array of located blog objects
243
+ * 'total' - A count of the total blogs for the user.
244
+ */
245
+ public static function get_blogs_for_user( $user_id = 0, $show_hidden = false ) {
246
+ global $bp, $wpdb;
247
+
248
+ if ( !$user_id )
249
+ $user_id = bp_displayed_user_id();
250
+
251
+ // Show logged in users their hidden blogs.
252
+ if ( !bp_is_my_profile() && !$show_hidden )
253
+ $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id, b.id, bm1.meta_value as name, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND bm1.meta_key = 'name' AND wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ORDER BY b.blog_id", $user_id ) );
254
+ else
255
+ $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id, b.id, bm1.meta_value as name, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND bm1.meta_key = 'name' AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ORDER BY b.blog_id", $user_id ) );
256
+
257
+ $total_blog_count = BP_Blogs_Blog::total_blog_count_for_user( $user_id );
258
+
259
+ $user_blogs = array();
260
+ foreach ( (array) $blogs as $blog ) {
261
+ $user_blogs[$blog->blog_id] = new stdClass;
262
+ $user_blogs[$blog->blog_id]->id = $blog->id;
263
+ $user_blogs[$blog->blog_id]->blog_id = $blog->blog_id;
264
+ $user_blogs[$blog->blog_id]->siteurl = ( is_ssl() ) ? 'https://' . $blog->domain . $blog->path : 'http://' . $blog->domain . $blog->path;
265
+ $user_blogs[$blog->blog_id]->name = $blog->name;
266
+ }
267
+
268
+ return array( 'blogs' => $user_blogs, 'count' => $total_blog_count );
269
+ }
270
+
271
+ /**
272
+ * Get IDs of all of a user's blogs, as tracked by BuddyPress.
273
+ *
274
+ * This method always includes hidden blogs.
275
+ *
276
+ * @param int $user_id Optional. ID of the user whose blogs are being
277
+ * queried. Defaults to logged-in user.
278
+ * @return int The number of blogs associated with the user.
279
+ */
280
+ public static function get_blog_ids_for_user( $user_id = 0 ) {
281
+ global $bp, $wpdb;
282
+
283
+ if ( !$user_id )
284
+ $user_id = bp_displayed_user_id();
285
+
286
+ return $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) );
287
+ }
288
+
289
+ /**
290
+ * Check whether a blog has been recorded by BuddyPress.
291
+ *
292
+ * @param int $blog_id ID of the blog being queried.
293
+ * @return int|null The ID of the first located entry in the BP table
294
+ * on success, otherwise null.
295
+ */
296
+ public static function is_recorded( $blog_id ) {
297
+ global $bp, $wpdb;
298
+
299
+ return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
300
+ }
301
+
302
+ /**
303
+ * Return a count of associated blogs for a given user.
304
+ *
305
+ * Includes hidden blogs when the logged-in user is the same as the
306
+ * $user_id parameter, or when the logged-in user has the bp_moderate
307
+ * cap.
308
+ *
309
+ * @param int $user_id Optional. ID of the user whose blogs are being
310
+ * queried. Defaults to logged-in user.
311
+ * @return int Blog count for the user.
312
+ */
313
+ public static function total_blog_count_for_user( $user_id = null ) {
314
+ global $bp, $wpdb;
315
+
316
+ if ( !$user_id )
317
+ $user_id = bp_displayed_user_id();
318
+
319
+ // If the user is logged in return the blog count including their hidden blogs.
320
+ if ( ( is_user_logged_in() && $user_id == bp_loggedin_user_id() ) || bp_current_user_can( 'bp_moderate' ) ) {
321
+ return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id ) );
322
+ } else {
323
+ return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id ) );
324
+ }
325
+ }
326
+
327
+ /**
328
+ * Return a list of blogs matching a search term.
329
+ *
330
+ * Matches against blog names and descriptions, as stored in the BP
331
+ * blogmeta table.
332
+ *
333
+ * @param string $filter The search term.
334
+ * @param int $limit Optional. The maximum number of items to return.
335
+ * Default: null (no limit).
336
+ * @param int $page Optional. The page of results to return. Default:
337
+ * null (no limit).
338
+ * @return array Multidimensional results array, structured as follows:
339
+ * 'blogs' - Array of located blog objects
340
+ * 'total' - A count of the total blogs matching the query.
341
+ */
342
+ public static function search_blogs( $filter, $limit = null, $page = null ) {
343
+ global $wpdb, $bp;
344
+
345
+ $filter = esc_sql( like_escape( $filter ) );
346
+
347
+ $hidden_sql = '';
348
+ if ( !bp_current_user_can( 'bp_moderate' ) )
349
+ $hidden_sql = "AND wb.public = 1";
350
+
351
+ $pag_sql = '';
352
+ if ( $limit && $page ) {
353
+ $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
354
+ }
355
+
356
+ $paged_blogs = $wpdb->get_results( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND bm.meta_value LIKE '%%$filter%%' ) {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY meta_value ASC{$pag_sql}" );
357
+ $total_blogs = $wpdb->get_var( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND bm.meta_value LIKE '%%$filter%%' ) {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY meta_value ASC" );
358
+
359
+ return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
360
+ }
361
+
362
+ /**
363
+ * Retrieve a list of all blogs.
364
+ *
365
+ * Query will include hidden blogs if the logged-in user has the
366
+ * 'bp_moderate' cap.
367
+ *
368
+ * @param int $limit Optional. The maximum number of items to return.
369
+ * Default: null (no limit).
370
+ * @param int $page Optional. The page of results to return. Default:
371
+ * null (no limit).
372
+ * @return array Multidimensional results array, structured as follows:
373
+ * 'blogs' - Array of located blog objects
374
+ * 'total' - A count of the total blogs.
375
+ */
376
+ public static function get_all( $limit = null, $page = null ) {
377
+ global $bp, $wpdb;
378
+
379
+ $hidden_sql = !bp_current_user_can( 'bp_moderate' ) ? "AND wb.public = 1" : '';
380
+ $pag_sql = ( $limit && $page ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ) : '';
381
+
382
+ $paged_blogs = $wpdb->get_results( "SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 {$hidden_sql} {$pag_sql}" );
383
+ $total_blogs = $wpdb->get_var( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 {$hidden_sql}" );
384
+
385
+ return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
386
+ }
387
+
388
+ /**
389
+ * Retrieve a list of blogs whose names start with a given letter.
390
+ *
391
+ * Query will include hidden blogs if the logged-in user has the
392
+ * 'bp_moderate' cap.
393
+ *
394
+ * @param string $letter. The letter you're looking for.
395
+ * @param int $limit Optional. The maximum number of items to return.
396
+ * Default: null (no limit).
397
+ * @param int $page Optional. The page of results to return. Default:
398
+ * null (no limit).
399
+ * @return array Multidimensional results array, structured as follows:
400
+ * 'blogs' - Array of located blog objects.
401
+ * 'total' - A count of the total blogs matching the query.
402
+ */
403
+ public static function get_by_letter( $letter, $limit = null, $page = null ) {
404
+ global $bp, $wpdb;
405
+
406
+ $letter = esc_sql( like_escape( $letter ) );
407
+
408
+ $hidden_sql = '';
409
+ if ( !bp_current_user_can( 'bp_moderate' ) )
410
+ $hidden_sql = "AND wb.public = 1";
411
+
412
+ if ( $limit && $page )
413
+ $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
414
+
415
+ $paged_blogs = $wpdb->get_results( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE bm.meta_key = 'name' AND bm.meta_value LIKE '$letter%%' {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY bm.meta_value ASC{$pag_sql}" );
416
+ $total_blogs = $wpdb->get_var( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE bm.meta_key = 'name' AND bm.meta_value LIKE '$letter%%' {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY bm.meta_value ASC" );
417
+
418
+ return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
419
+ }
420
+
421
+ /**
422
+ * Fetch blog data not caught in the main query and append it to results array.
423
+ *
424
+ * Gets the following information, which is either unavailable at the
425
+ * time of the original query, or is more efficient to look up in one
426
+ * fell swoop:
427
+ * - The latest post for each blog, include Featured Image data
428
+ * - The blog description
429
+ *
430
+ * @param array $paged_blogs Array of results from the original query.
431
+ * @param array $blog_ids Array of IDs returned from the original query.
432
+ * @param string|bool $type Not currently used. Default: false.
433
+ * @return array $paged_blogs The located blogs array, with the extras added.
434
+ */
435
+ public static function get_blog_extras( &$paged_blogs, &$blog_ids, $type = false ) {
436
+ global $bp, $wpdb;
437
+
438
+ if ( empty( $blog_ids ) )
439
+ return $paged_blogs;
440
+
441
+ $blog_ids = implode( ',', wp_parse_id_list( $blog_ids ) );
442
+
443
+ for ( $i = 0, $count = count( $paged_blogs ); $i < $count; ++$i ) {
444
+ $blog_prefix = $wpdb->get_blog_prefix( $paged_blogs[$i]->blog_id );
445
+ $paged_blogs[$i]->latest_post = $wpdb->get_row( "SELECT ID, post_content, post_title, post_excerpt, guid FROM {$blog_prefix}posts WHERE post_status = 'publish' AND post_type = 'post' AND id != 1 ORDER BY id DESC LIMIT 1" );
446
+ $images = array();
447
+
448
+ // Add URLs to any Featured Image this post might have
449
+ if ( ! empty( $paged_blogs[$i]->latest_post ) && has_post_thumbnail( $paged_blogs[$i]->latest_post->ID ) ) {
450
+
451
+ // Grab 4 sizes of the image. Thumbnail.
452
+ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'thumbnail', false );
453
+ if ( ! empty( $image ) )
454
+ $images['thumbnail'] = $image[0];
455
+
456
+ // Medium
457
+ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'medium', false );
458
+ if ( ! empty( $image ) )
459
+ $images['medium'] = $image[0];
460
+
461
+ // Large
462
+ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'large', false );
463
+ if ( ! empty( $image ) )
464
+ $images['large'] = $image[0];
465
+
466
+ // Post thumbnail
467
+ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'post-thumbnail', false );
468
+ if ( ! empty( $image ) )
469
+ $images['post-thumbnail'] = $image[0];
470
+
471
+ // Add the images to the latest_post object
472
+ $paged_blogs[$i]->latest_post->images = $images;
473
+ }
474
+ }
475
+
476
+ /* Fetch the blog description for each blog (as it may be empty we can't fetch it in the main query). */
477
+ $blog_descs = $wpdb->get_results( "SELECT blog_id, meta_value as description FROM {$bp->blogs->table_name_blogmeta} WHERE meta_key = 'description' AND blog_id IN ( {$blog_ids} )" );
478
+
479
+ for ( $i = 0, $count = count( $paged_blogs ); $i < $count; ++$i ) {
480
+ foreach ( (array) $blog_descs as $desc ) {
481
+ if ( $desc->blog_id == $paged_blogs[$i]->blog_id )
482
+ $paged_blogs[$i]->description = $desc->description;
483
+ }
484
+ }
485
+
486
+ return $paged_blogs;
487
+ }
488
+
489
+ /**
490
+ * Check whether a given blog is hidden.
491
+ *
492
+ * Checks the 'public' column in the wp_blogs table.
493
+ *
494
+ * @param int $blog_id The ID of the blog being checked.
495
+ * @return bool True if hidden (public = 0), false otherwise.
496
+ */
497
+ public static function is_hidden( $blog_id ) {
498
+ global $wpdb;
499
+
500
+ if ( !(int) $wpdb->get_var( $wpdb->prepare( "SELECT public FROM {$wpdb->base_prefix}blogs WHERE blog_id = %d", $blog_id ) ) ) {
501
+ return true;
502
+ }
503
+
504
+ return false;
505
+ }
506
+
507
+ /**
508
+ * Get ID of user-blog link.
509
+ *
510
+ * @param int $user_id ID of user.
511
+ * @param int $blog_id ID of blog.
512
+ * @return int|bool ID of user-blog link, or false if not found.
513
+ */
514
+ public static function get_user_blog( $user_id, $blog_id ) {
515
+ global $bp, $wpdb;
516
+
517
+ $user_blog = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $user_id, $blog_id ) );
518
+
519
+ if ( empty( $user_blog ) ) {
520
+ $user_blog = false;
521
+ } else {
522
+ $user_blog = intval( $user_blog );
523
+ }
524
 
525
+ return $user_blog;
526
+ }
527
+ }
bp-blogs/bp-blogs-filters.php CHANGED
@@ -1,10 +1,11 @@
1
  <?php
 
2
  /**
3
  * Filters related to the Blogs component.
4
  *
5
  * @package BuddyPress
6
- * @subpackage BlogFilters
7
- * @since 1.6.0
8
  */
9
 
10
  /** Display Filters **********************************************************/
@@ -23,104 +24,15 @@ add_filter( 'bp_blog_latest_post_content', 'prepend_attachment' );
23
  /**
24
  * Ensure that the 'Create a new site' link at wp-admin/my-sites.php points to the BP blog signup.
25
  *
26
- * @since 1.6.0
27
  *
28
  * @uses apply_filters() Filter 'bp_blogs_creation_location' to alter the
29
  * returned value.
30
  *
31
  * @param string $url The original URL (points to wp-signup.php by default).
32
- *
33
  * @return string The new URL.
34
  */
35
  function bp_blogs_creation_location( $url ) {
36
-
37
- /**
38
- * Filters the 'Create a new site' link URL.
39
- *
40
- * @since 1.6.0
41
- *
42
- * @param string $value URL for the 'Create a new site' signup page.
43
- */
44
- return apply_filters( 'bp_blogs_creation_location', trailingslashit( bp_get_blogs_directory_permalink() . 'create' ), $url );
45
  }
46
  add_filter( 'wp_signup_location', 'bp_blogs_creation_location' );
47
-
48
- /**
49
- * Only select comments by ID instead of all fields when using get_comments().
50
- *
51
- * @since 2.1.0
52
- *
53
- * @see bp_blogs_update_post_activity_meta()
54
- *
55
- * @param array $retval Current SQL clauses in array format.
56
- *
57
- * @return array
58
- */
59
- function bp_blogs_comments_clauses_select_by_id( $retval ) {
60
- $retval['fields'] = 'comment_ID';
61
-
62
- return $retval;
63
- }
64
-
65
- /**
66
- * Check whether the current post can be published.
67
- *
68
- * Abstracted from the deprecated `bp_blogs_record_post()`.
69
- *
70
- * @since 2.2.0
71
- *
72
- * @param bool $return Whether the post should be published.
73
- * @param int $blog_id ID of the blog.
74
- * @param int $post_id ID of the post.
75
- * @param int $user_id ID of the post author.
76
- *
77
- * @return bool True to authorize the post to be published, otherwise false.
78
- */
79
- function bp_blogs_post_pre_publish( $return = true, $blog_id = 0, $post_id = 0, $user_id = 0 ) {
80
- $bp = buddypress();
81
-
82
- // If blog is not trackable, do not record the activity.
83
- if ( ! bp_blogs_is_blog_trackable( $blog_id, $user_id ) ) {
84
- return false;
85
- }
86
-
87
- /*
88
- * Stop infinite loops with WordPress MU Sitewide Tags.
89
- * That plugin changed the way its settings were stored at some point. Thus the dual check.
90
- */
91
- $sitewide_tags_blog_settings = bp_core_get_root_option( 'sitewide_tags_blog' );
92
- if ( ! empty( $sitewide_tags_blog_settings ) ) {
93
- $st_options = maybe_unserialize( $sitewide_tags_blog_settings );
94
- $tags_blog_id = isset( $st_options['tags_blog_id'] ) ? $st_options['tags_blog_id'] : 0;
95
- } else {
96
- $tags_blog_id = bp_core_get_root_option( 'sitewide_tags_blog' );
97
- $tags_blog_id = intval( $tags_blog_id );
98
- }
99
-
100
- /**
101
- * Filters whether or not BuddyPress should block sitewide tags activity.
102
- *
103
- * @since 2.2.0
104
- *
105
- * @param bool $value Current status of the sitewide tags activity.
106
- */
107
- if ( (int) $blog_id == $tags_blog_id && apply_filters( 'bp_blogs_block_sitewide_tags_activity', true ) ) {
108
- return false;
109
- }
110
-
111
- /**
112
- * Filters whether or not the current blog is public.
113
- *
114
- * @since 2.2.0
115
- *
116
- * @param int $value Value from the blog_public option for the current blog.
117
- */
118
- $is_blog_public = apply_filters( 'bp_is_blog_public', (int) get_blog_option( $blog_id, 'blog_public' ) );
119
-
120
- if ( 0 === $is_blog_public && is_multisite() ) {
121
- return false;
122
- }
123
-
124
- return $return;
125
- }
126
- add_filter( 'bp_activity_post_pre_publish', 'bp_blogs_post_pre_publish', 10, 4 );
1
  <?php
2
+
3
  /**
4
  * Filters related to the Blogs component.
5
  *
6
  * @package BuddyPress
7
+ * @subpackage Blogs
8
+ * @since BuddyPress (1.6.0)
9
  */
10
 
11
  /** Display Filters **********************************************************/
24
  /**
25
  * Ensure that the 'Create a new site' link at wp-admin/my-sites.php points to the BP blog signup.
26
  *
27
+ * @since BuddyPress (1.6.0)
28
  *
29
  * @uses apply_filters() Filter 'bp_blogs_creation_location' to alter the
30
  * returned value.
31
  *
32
  * @param string $url The original URL (points to wp-signup.php by default).
 
33
  * @return string The new URL.
34
  */
35
  function bp_blogs_creation_location( $url ) {
36
+ return apply_filters( 'bp_blogs_creation_location', trailingslashit( bp_get_root_domain() . '/' . bp_get_blogs_root_slug() . '/create', $url ) );
 
 
 
 
 
 
 
 
37
  }
38
  add_filter( 'wp_signup_location', 'bp_blogs_creation_location' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-blogs/bp-blogs-functions.php CHANGED
@@ -7,154 +7,94 @@
7
  */
8
 
9
  // Exit if accessed directly
10
- defined( 'ABSPATH' ) || exit;
11
 
12
  /**
13
  * Check whether the $bp global lists an activity directory page.
14
  *
15
- * @since 1.5.0
 
 
16
  *
17
  * @return bool True if set, false if empty.
18
  */
19
  function bp_blogs_has_directory() {
20
- $bp = buddypress();
21
 
22
  return (bool) !empty( $bp->pages->blogs->id );
23
  }
24
 
25
  /**
26
- * Retrieve a set of blogs.
27
  *
28
  * @see BP_Blogs_Blog::get() for a description of arguments and return value.
29
  *
30
- * @param array|string $args {
31
  * Arguments are listed here with their default values. For more
32
  * information about the arguments, see {@link BP_Blogs_Blog::get()}.
33
- * @type string $type Default: 'active'.
34
- * @type int|bool $user_id Default: false.
35
- * @type array $include_blog_ids Default: false.
36
- * @type string|bool $search_terms Default: false.
37
- * @type int $per_page Default: 20.
38
- * @type int $page Default: 1.
39
- * @type bool $update_meta_cache Whether to pre-fetch blogmeta. Default: true.
40
  * }
41
  * @return array See {@link BP_Blogs_Blog::get()}.
42
  */
43
  function bp_blogs_get_blogs( $args = '' ) {
44
 
45
- // Parse query arguments
46
- $r = bp_parse_args( $args, array(
47
- 'type' => 'active', // 'active', 'alphabetical', 'newest', or 'random'
48
- 'include_blog_ids' => false, // Array of blog IDs to include
49
- 'user_id' => false, // Limit to blogs this user can post to
50
- 'search_terms' => false, // Limit to blogs matching these search terms
51
  'per_page' => 20, // The number of results to return per page
52
  'page' => 1, // The page to return if limiting per page
53
- 'update_meta_cache' => true // Whether to pre-fetch blogmeta
54
- ), 'blogs_get_blogs' );
55
-
56
- // Get the blogs
57
- $blogs = BP_Blogs_Blog::get(
58
- $r['type'],
59
- $r['per_page'],
60
- $r['page'],
61
- $r['user_id'],
62
- $r['search_terms'],
63
- $r['update_meta_cache'],
64
- $r['include_blog_ids']
65
  );
66
 
67
- // Filter and return
68
- return apply_filters( 'bp_blogs_get_blogs', $blogs, $r );
 
 
69
  }
70
 
71
  /**
72
  * Populate the BP blogs table with existing blogs.
73
  *
74
- * @since 1.0.0
75
- *
76
- * @global object $wpdb WordPress database object.
77
  * @uses get_users()
78
  * @uses bp_blogs_record_blog()
79
- *
80
- * @return bool
81
  */
82
  function bp_blogs_record_existing_blogs() {
83
- global $wpdb;
84
-
85
- // Query for all sites in network
86
- if ( is_multisite() ) {
87
 
88
- // Get blog ID's if not a large network
89
- if ( ! wp_is_large_network() ) {
90
- $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$wpdb->base_prefix}blogs WHERE mature = 0 AND spam = 0 AND deleted = 0 AND site_id = %d", $wpdb->siteid ) );
91
 
92
- // If error running this query, set blog ID's to false
93
- if ( is_wp_error( $blog_ids ) ) {
94
- $blog_ids = false;
95
- }
96
-
97
- // Large networks are not currently supported
98
- } else {
99
- $blog_ids = false;
100
- }
101
-
102
- // Record a single site
103
  } else {
104
- $blog_ids = $wpdb->blogid;
105
  }
106
 
107
- // Bail if there are no blogs in the network
108
- if ( empty( $blog_ids ) ) {
109
- return false;
110
- }
111
-
112
- // Get BuddyPress
113
- $bp = buddypress();
114
-
115
- // Truncate user blogs table
116
- $truncate = $wpdb->query( "TRUNCATE {$bp->blogs->table_name}" );
117
- if ( is_wp_error( $truncate ) ) {
118
- return false;
119
- }
120
-
121
- // Truncate user blogsmeta table
122
- $truncate = $wpdb->query( "TRUNCATE {$bp->blogs->table_name_blogmeta}" );
123
- if ( is_wp_error( $truncate ) ) {
124
- return false;
125
- }
126
-
127
- // Loop through users of blogs and record the relationship
128
- foreach ( (array) $blog_ids as $blog_id ) {
129
-
130
- // Ensure that the cache is clear after the table TRUNCATE above
131
- wp_cache_delete( $blog_id, 'blog_meta' );
132
-
133
- // Get all users
134
- $users = get_users( array(
135
- 'blog_id' => $blog_id
136
- ) );
137
-
138
- // Continue on if no users exist for this site (how did this happen?)
139
- if ( empty( $users ) ) {
140
- continue;
141
- }
142
-
143
- // Loop through users and record their relationship to this blog
144
- foreach ( (array) $users as $user ) {
145
- bp_blogs_add_user_to_blog( $user->ID, false, $blog_id );
146
  }
147
  }
148
-
149
- /**
150
- * Fires after the BP blogs tables have been populated with existing blogs.
151
- *
152
- * @since 2.4.0
153
- */
154
- do_action( 'bp_blogs_recorded_existing_blogs' );
155
-
156
- // No errors
157
- return true;
158
  }
159
 
160
  /**
@@ -163,13 +103,12 @@ function bp_blogs_record_existing_blogs() {
163
  * If $user_id is provided, you can restrict site from being recordable
164
  * only to particular users.
165
  *
166
- * @since 1.7.0
167
  *
168
  * @uses apply_filters()
169
  *
170
  * @param int $blog_id ID of the blog being checked.
171
  * @param int $user_id Optional. ID of the user for whom access is being checked.
172
- *
173
  * @return bool True if blog is recordable, otherwise false.
174
  */
175
  function bp_blogs_is_blog_recordable( $blog_id, $user_id = 0 ) {
@@ -195,14 +134,13 @@ function bp_blogs_is_blog_recordable( $blog_id, $user_id = 0 ) {
195
  * If $user_id is provided, the developer can restrict site from
196
  * being trackable only to particular users.
197
  *
198
- * @since 1.7.0
199
  *
200
  * @uses bp_blogs_is_blog_recordable
201
  * @uses apply_filters()
202
  *
203
  * @param int $blog_id ID of the blog being checked.
204
  * @param int $user_id Optional. ID of the user for whom access is being checked.
205
- *
206
  * @return bool True if blog is trackable, otherwise false.
207
  */
208
  function bp_blogs_is_blog_trackable( $blog_id, $user_id = 0 ) {
@@ -225,15 +163,14 @@ function bp_blogs_is_blog_trackable( $blog_id, $user_id = 0 ) {
225
  /**
226
  * Make BuddyPress aware of a new site so that it can track its activity.
227
  *
228
- * @since 1.0.0
229
  *
230
  * @uses BP_Blogs_Blog
231
  *
232
- * @param int $blog_id ID of the blog being recorded.
233
- * @param int $user_id ID of the user for whom the blog is being recorded.
234
  * @param bool $no_activity Optional. Whether to skip recording an activity
235
- * item about this blog creation. Default: false.
236
- *
237
  * @return bool|null Returns false on failure.
238
  */
239
  function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) {
@@ -246,12 +183,12 @@ function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) {
246
  return false;
247
 
248
  $name = get_blog_option( $blog_id, 'blogname' );
249
- $url = get_home_url( $blog_id );
250
 
251
  if ( empty( $name ) ) {
252
- $name = $url;
253
  }
254
 
 
255
  $description = get_blog_option( $blog_id, 'blogdescription' );
256
  $close_old_posts = get_blog_option( $blog_id, 'close_comments_for_old_posts' );
257
  $close_days_old = get_blog_option( $blog_id, 'close_comments_days_old' );
@@ -293,15 +230,6 @@ function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) {
293
  ) );
294
  }
295
 
296
- /**
297
- * Fires after BuddyPress has been made aware of a new site for activity tracking.
298
- *
299
- * @since 1.0.0
300
- *
301
- * @param BP_Blogs_Blog $recorded_blog Current blog being recorded. Passed by reference.
302
- * @param bool $is_private Whether or not the current blog being recorded is private.
303
- * @param bool $is_recorded Whether or not the current blog was recorded.
304
- */
305
  do_action_ref_array( 'bp_blogs_new_blog', array( &$recorded_blog, $is_private, $is_recorded ) );
306
  }
307
  add_action( 'wpmu_new_blog', 'bp_blogs_record_blog', 10, 2 );
@@ -312,7 +240,7 @@ add_action( 'wpmu_new_blog', 'bp_blogs_record_blog', 10, 2 );
312
  * @global object $wpdb DB Layer.
313
  *
314
  * @param string $oldvalue Value before save. Passed by do_action() but
315
- * unused here.
316
  * @param string $newvalue Value to change meta to.
317
  */
318
  function bp_blogs_update_option_blogname( $oldvalue, $newvalue ) {
@@ -323,12 +251,12 @@ function bp_blogs_update_option_blogname( $oldvalue, $newvalue ) {
323
  add_action( 'update_option_blogname', 'bp_blogs_update_option_blogname', 10, 2 );
324
 
325
  /**
326
- * Update blog description in BuddyPress blogmeta table.
327
  *
328
  * @global object $wpdb DB Layer.
329
  *
330
  * @param string $oldvalue Value before save. Passed by do_action() but
331
- * unused here.
332
  * @param string $newvalue Value to change meta to.
333
  */
334
  function bp_blogs_update_option_blogdescription( $oldvalue, $newvalue ) {
@@ -341,12 +269,12 @@ add_action( 'update_option_blogdescription', 'bp_blogs_update_option_blogdescrip
341
  /**
342
  * Update "Close comments for old posts" option in BuddyPress blogmeta table.
343
  *
344
- * @since 2.0.0
345
  *
346
  * @global object $wpdb DB Layer.
347
  *
348
  * @param string $oldvalue Value before save. Passed by do_action() but
349
- * unused here.
350
  * @param string $newvalue Value to change meta to.
351
  */
352
  function bp_blogs_update_option_close_comments_for_old_posts( $oldvalue, $newvalue ) {
@@ -359,15 +287,15 @@ add_action( 'update_option_close_comments_for_old_posts', 'bp_blogs_update_optio
359
  /**
360
  * Update "Close comments after days old" option in BuddyPress blogmeta table.
361
  *
362
- * @since 2.0.0
363
  *
364
  * @global object $wpdb DB Layer.
365
  *
366
  * @param string $oldvalue Value before save. Passed by do_action() but
367
- * unused here.
368
  * @param string $newvalue Value to change meta to.
369
  */
370
- function bp_blogs_update_option_close_comments_days_old( $oldvalue, $newvalue ) {
371
  global $wpdb;
372
 
373
  bp_blogs_update_blogmeta( $wpdb->blogid, 'close_comments_days_old', $newvalue );
@@ -377,12 +305,12 @@ add_action( 'update_option_close_comments_days_old', 'bp_blogs_update_option_clo
377
  /**
378
  * When toggling threaded comments, update thread depth in blogmeta table.
379
  *
380
- * @since 2.0.0
381
  *
382
  * @global object $wpdb DB Layer.
383
  *
384
  * @param string $oldvalue Value before save. Passed by do_action() but
385
- * unused here.
386
  * @param string $newvalue Value to change meta to.
387
  */
388
  function bp_blogs_update_option_thread_comments( $oldvalue, $newvalue ) {
@@ -401,12 +329,12 @@ add_action( 'update_option_thread_comments', 'bp_blogs_update_option_thread_comm
401
  /**
402
  * When updating comment depth, update thread depth in blogmeta table.
403
  *
404
- * @since 2.0.0
405
  *
406
  * @global object $wpdb DB Layer.
407
  *
408
  * @param string $oldvalue Value before save. Passed by do_action() but
409
- * unused here.
410
  * @param string $newvalue Value to change meta to.
411
  */
412
  function bp_blogs_update_option_thread_comments_depth( $oldvalue, $newvalue ) {
@@ -421,150 +349,194 @@ function bp_blogs_update_option_thread_comments_depth( $oldvalue, $newvalue ) {
421
  add_action( 'update_option_thread_comments_depth', 'bp_blogs_update_option_thread_comments_depth', 10, 2 );
422
 
423
  /**
424
- * Deletes the 'url' blogmeta for a site.
425
  *
426
- * Hooked to 'refresh_blog_details', which is notably used when editing a site
427
- * under "Network Admin > Sites".
 
428
  *
429
- * @since 2.3.0
430
  *
431
- * @param int $site_id The site ID.
432
- */
433
- function bp_blogs_delete_url_blogmeta( $site_id = 0 ) {
434
- bp_blogs_delete_blogmeta( (int) $site_id, 'url' );
435
- }
436
- add_action( 'refresh_blog_details', 'bp_blogs_delete_url_blogmeta' );
437
-
438
- /**
439
- * Record activity metadata about a published blog post.
440
  *
441
- * @since 2.2.0
442
  *
443
- * @param int $activity_id ID of the activity item.
444
- * @param WP_Post $post Post object.
445
- * @param array $args Array of arguments.
446
  */
447
- function bp_blogs_publish_post_activity_meta( $activity_id, $post, $args ) {
448
- if ( empty( $activity_id ) || 'post' != $post->post_type ) {
449
- return;
450
- }
451
-
452
- bp_activity_update_meta( $activity_id, 'post_title', $post->post_title );
453
 
454
- if ( ! empty( $args['post_url'] ) ) {
455
- $post_permalink = $args['post_url'];
456
- } else {
457
- $post_permalink = $post->guid;
 
 
458
  }
459
 
460
- bp_activity_update_meta( $activity_id, 'post_url', $post_permalink );
 
 
 
 
461
 
462
- // Update the blog's last activity.
463
- bp_blogs_update_blogmeta( $args['item_id'], 'last_activity', bp_core_current_time() );
464
 
465
- /**
466
- * Fires after BuddyPress has recorded metadata about a published blog post.
467
- *
468
- * @since 1.0.0
469
- *
470
- * @param int $ID ID of the blog post being recorded.
471
- * @param WP_Post $post WP_Post object for the current blog post.
472
- * @param string $value ID of the user associated with the current blog post.
473
- */
474
- do_action( 'bp_blogs_new_blog_post', $post->ID, $post, $args['user_id'] );
 
475
  }
476
- add_action( 'bp_activity_post_type_published', 'bp_blogs_publish_post_activity_meta', 10, 3 );
477
 
478
  /**
479
- * Updates a blog post's activity meta entry during a post edit.
480
  *
481
- * @since 2.2.0
482
- *
483
- * @param WP_Post $post Post object.
484
- * @param BP_Activity_Activity $activity Activity object.
 
485
  */
486
- function bp_blogs_update_post_activity_meta( $post, $activity ) {
487
- if ( empty( $activity->id ) || 'post' != $post->post_type ) {
488
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
489
  }
490
 
491
- // Update post title in activity meta.
492
- $existing_title = bp_activity_get_meta( $activity->id, 'post_title' );
493
- if ( $post->post_title !== $existing_title ) {
494
- bp_activity_update_meta( $activity->id, 'post_title', $post->post_title );
495
-
496
- // Now update activity meta for post comments... sigh.
497
- add_filter( 'comments_clauses', 'bp_blogs_comments_clauses_select_by_id' );
498
- $comments = get_comments( array( 'post_id' => $post->ID ) );
499
- remove_filter( 'comments_clauses', 'bp_blogs_comments_clauses_select_by_id' );
500
-
501
- if ( ! empty( $comments ) ) {
502
- $activity_ids = array();
503
- $comment_ids = wp_list_pluck( $comments, 'comment_ID' );
504
-
505
- // Set up activity args.
506
- $args = array(
507
- 'update_meta_cache' => false,
508
- 'show_hidden' => true,
509
- 'per_page' => 99999,
510
- );
511
 
512
- // Query for old-style "new_blog_comment" activity items.
513
- $args['filter'] = array(
514
- 'object' => buddypress()->blogs->id,
515
- 'action' => 'new_blog_comment',
516
- 'secondary_id' => implode( ',', $comment_ids ),
517
- );
518
 
519
- $activities = bp_activity_get( $args );
520
- if ( ! empty( $activities['activities'] ) ) {
521
- $activity_ids = (array) wp_list_pluck( $activities['activities'], 'id' );
522
- }
523
 
524
- // Query for activity comments connected to a blog post.
525
- unset( $args['filter'] );
526
- $args['meta_query'] = array( array(
527
- 'key' => 'bp_blogs_post_comment_id',
528
- 'value' => $comment_ids,
529
- 'compare' => 'IN',
530
- ) );
531
- $args['type'] = 'activity_comment';
532
- $args['display_comments'] = 'stream';
533
 
534
- $activities = bp_activity_get( $args );
535
- if ( ! empty( $activities['activities'] ) ) {
536
- $activity_ids = array_merge( $activity_ids, (array) wp_list_pluck( $activities['activities'], 'id' ) );
537
- }
 
 
538
 
539
- // Update activity meta for all found activity items.
540
- if ( ! empty( $activity_ids ) ) {
541
- foreach ( $activity_ids as $aid ) {
542
- bp_activity_update_meta( $aid, 'post_title', $post->post_title );
 
 
 
 
 
 
 
 
 
 
 
 
 
543
  }
544
  }
545
 
546
- unset( $activities, $activity_ids, $comment_ids, $comments );
 
 
 
 
 
 
 
 
 
 
547
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
548
  }
549
 
550
- // Add post comment status to activity meta if closed.
 
 
 
 
 
551
  if( 'closed' == $post->comment_status ) {
552
- bp_activity_update_meta( $activity->id, 'post_comment_status', $post->comment_status );
553
  } else {
554
- bp_activity_delete_meta( $activity->id, 'post_comment_status' );
555
  }
556
  }
557
- add_action( 'bp_activity_post_type_updated', 'bp_blogs_update_post_activity_meta', 10, 2 );
558
 
559
  /**
560
  * Record a new blog comment in the BuddyPress activity stream.
561
  *
562
  * Only posts the item if blog is public and post is not password-protected.
563
  *
564
- * @param int $comment_id ID of the comment being recorded.
565
  * @param bool|string $is_approved Optional. The $is_approved value passed to
566
- * the 'comment_post' action. Default: true.
567
- *
568
  * @return bool|object Returns false on failure, the comment object on success.
569
  */
570
  function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
@@ -646,11 +618,7 @@ function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
646
  $args['secondary_item_id'] = $comment_id;
647
 
648
  // record the activity entry
649
- $activity_id = bp_blogs_record_activity( $args );
650
-
651
- // add some post info in activity meta
652
- bp_activity_update_meta( $activity_id, 'post_title', $recorded_comment->post->post_title );
653
- bp_activity_update_meta( $activity_id, 'post_url', add_query_arg( 'p', $recorded_comment->post->ID, home_url( '/' ) ) );
654
 
655
  // record comment as BP activity comment under the parent 'new_blog_post'
656
  // activity item
@@ -673,11 +641,6 @@ function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
673
  'secondary_item_id' => $recorded_comment->comment_post_ID
674
  ) );
675
 
676
- // Try to create a new activity item for the parent blog post
677
- if ( empty( $parent_activity_id ) ) {
678
- $parent_activity_id = bp_activity_post_type_publish( $recorded_comment->comment_post_ID, $recorded_comment->post );
679
- }
680
-
681
  // we found the parent activity entry
682
  // so let's go ahead and reconfigure some activity args
683
  if ( ! empty( $parent_activity_id ) ) {
@@ -719,8 +682,6 @@ function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
719
  if ( empty( $args['id'] ) ) {
720
  // add meta to activity comment
721
  bp_activity_update_meta( $comment_activity_id, 'bp_blogs_post_comment_id', $comment_id );
722
- bp_activity_update_meta( $comment_activity_id, 'post_title', $recorded_comment->post->post_title );
723
- bp_activity_update_meta( $comment_activity_id, 'post_url', add_query_arg( 'p', $recorded_comment->post->ID, home_url( '/' ) ) );
724
 
725
  // add meta to comment
726
  add_comment_meta( $comment_id, 'bp_activity_comment_id', $comment_activity_id );
@@ -744,77 +705,40 @@ add_action( 'edit_comment', 'bp_blogs_record_comment', 10 );
744
  * set/changed ('add_user_to_blog', 'profile_update', 'user_register'). It
745
  * parses the changes, and records them as necessary in the BP blog tracker.
746
  *
747
- * BuddyPress does not track blogs for users with the 'subscriber' role by
748
- * default, though as of 2.1.0 you can filter 'bp_blogs_get_allowed_roles' to
749
- * modify this behavior.
750
- *
751
- * @param int $user_id The ID of the user.
752
- * @param string|bool $role User's WordPress role for this blog ID.
753
- * @param int $blog_id Blog ID user is being added to.
754
  *
 
 
 
 
 
755
  * @return bool|null False on failure.
756
  */
757
  function bp_blogs_add_user_to_blog( $user_id, $role = false, $blog_id = 0 ) {
758
  global $wpdb;
759
 
760
- // If no blog ID was passed, use the root blog ID
761
  if ( empty( $blog_id ) ) {
762
  $blog_id = isset( $wpdb->blogid ) ? $wpdb->blogid : bp_get_root_blog_id();
763
  }
764
 
765
- // If no role was passed, try to find the blog role
766
  if ( empty( $role ) ) {
 
767
 
768
- // Get user capabilities
769
- $key = $wpdb->get_blog_prefix( $blog_id ). 'capabilities';
770
- $user_roles = array_keys( (array) bp_get_user_meta( $user_id, $key, true ) );
771
-
772
- // User has roles so lets
773
- if ( ! empty( $user_roles ) ) {
774
-
775
- // Get blog roles
776
- $blog_roles = array_keys( bp_get_current_blog_roles() );
777
-
778
- // Look for blog only roles of the user
779
- $intersect_roles = array_intersect( $user_roles, $blog_roles );
780
 
781
- // If there's a role in the array, use the first one. This isn't
782
- // very smart, but since roles aren't exactly hierarchical, and
783
- // WordPress does not yet have a UI for multiple user roles, it's
784
- // fine for now.
785
- if ( ! empty( $intersect_roles ) ) {
786
- $role = array_shift( $intersect_roles );
787
- }
788
- }
789
  }
790
 
791
- // Bail if no role was found or role is not in the allowed roles array
792
- if ( empty( $role ) || ! in_array( $role, bp_blogs_get_allowed_roles() ) ) {
793
- return false;
794
- }
795
-
796
- // Record the blog activity for this user being added to this blog
797
- bp_blogs_record_blog( $blog_id, $user_id, true );
798
  }
799
  add_action( 'add_user_to_blog', 'bp_blogs_add_user_to_blog', 10, 3 );
800
  add_action( 'profile_update', 'bp_blogs_add_user_to_blog' );
801
  add_action( 'user_register', 'bp_blogs_add_user_to_blog' );
802
 
803
- /**
804
- * The allowed blog roles a member must have to be recorded into the
805
- * `bp_user_blogs` pointer table.
806
- *
807
- * This added and was made filterable in BuddyPress 2.1.0 to make it easier
808
- * to extend the functionality of the Blogs component.
809
- *
810
- * @since 2.1.0
811
- *
812
- * @return string
813
- */
814
- function bp_blogs_get_allowed_roles() {
815
- return apply_filters( 'bp_blogs_get_allowed_roles', array( 'contributor', 'author', 'editor', 'administrator' ) );
816
- }
817
-
818
  /**
819
  * Remove a blog-user pair from BP's blog tracker.
820
  *
@@ -824,23 +748,23 @@ function bp_blogs_get_allowed_roles() {
824
  function bp_blogs_remove_user_from_blog( $user_id, $blog_id = 0 ) {
825
  global $wpdb;
826
 
827
- if ( empty( $blog_id ) ) {
828
  $blog_id = $wpdb->blogid;
829
- }
830
 
831
  bp_blogs_remove_blog_for_user( $user_id, $blog_id );
832
  }
833
  add_action( 'remove_user_from_blog', 'bp_blogs_remove_user_from_blog', 10, 2 );
834
 
835
  /**
836
- * Rehook WP's maybe_add_existing_user_to_blog with a later priority.
837
  *
838
  * WordPress catches add-user-to-blog requests at init:10. In some cases, this
839
  * can precede BP's Blogs component. This function bumps the priority of the
840
  * core function, so that we can be sure that the Blogs component is loaded
841
- * first. See https://buddypress.trac.wordpress.org/ticket/3916.
842
  *
843
- * @since 1.6.0
 
844
  */
845
  function bp_blogs_maybe_add_user_to_blog() {
846
  if ( ! is_multisite() )
@@ -857,36 +781,16 @@ add_action( 'init', 'bp_blogs_maybe_add_user_to_blog', 1 );
857
  * @param int $blog_id ID of the blog being removed.
858
  */
859
  function bp_blogs_remove_blog( $blog_id ) {
 
860
 
861
  $blog_id = (int) $blog_id;
862
-
863
- /**
864
- * Fires before a "blog created" item is removed from blogs
865
- * tracker and activity stream.
866
- *
867
- * @since 1.5.0
868
- *
869
- * @param int $blog_id ID of the blog having its item removed.
870
- */
871
  do_action( 'bp_blogs_before_remove_blog', $blog_id );
872
 
873
  BP_Blogs_Blog::delete_blog_for_all( $blog_id );
874
 
875
  // Delete activity stream item
876
- bp_blogs_delete_activity( array(
877
- 'item_id' => $blog_id,
878
- 'component' => buddypress()->blogs->id,
879
- 'type' => 'new_blog'
880
- ) );
881
 
882
- /**
883
- * Fires after a "blog created" item has been removed from blogs
884
- * tracker and activity stream.
885
- *
886
- * @since 1.0.0
887
- *
888
- * @param int $blog_id ID of the blog who had its item removed.
889
- */
890
  do_action( 'bp_blogs_remove_blog', $blog_id );
891
  }
892
  add_action( 'delete_blog', 'bp_blogs_remove_blog' );
@@ -898,18 +802,11 @@ add_action( 'delete_blog', 'bp_blogs_remove_blog' );
898
  * @param int $blog_id ID of the blog being removed.
899
  */
900
  function bp_blogs_remove_blog_for_user( $user_id, $blog_id ) {
 
901
 
902
  $blog_id = (int) $blog_id;
903
  $user_id = (int) $user_id;
904
 
905
- /**
906
- * Fires before a blog is removed from the tracker for a specific user.
907
- *
908
- * @since 1.5.0
909
- *
910
- * @param int $blog_id ID of the blog being removed.
911
- * @param int $user_id ID of the user having the blog removed for.
912
- */
913
  do_action( 'bp_blogs_before_remove_blog_for_user', $blog_id, $user_id );
914
 
915
  BP_Blogs_Blog::delete_blog_for_user( $blog_id, $user_id );
@@ -917,18 +814,10 @@ function bp_blogs_remove_blog_for_user( $user_id, $blog_id ) {
917
  // Delete activity stream item
918
  bp_blogs_delete_activity( array(
919
  'item_id' => $blog_id,
920
- 'component' => buddypress()->blogs->id,
921
  'type' => 'new_blog'
922
  ) );
923
 
924
- /**
925
- * Fires after a blog has been removed from the tracker for a specific user.
926
- *
927
- * @since 1.0.0
928
- *
929
- * @param int $blog_id ID of the blog that was removed.
930
- * @param int $user_id ID of the user having the blog removed for.
931
- */
932
  do_action( 'bp_blogs_remove_blog_for_user', $blog_id, $user_id );
933
  }
934
  add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 );
@@ -939,12 +828,10 @@ add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 );
939
  * @param int $post_id ID of the post to be removed.
940
  * @param int $blog_id Optional. Defaults to current blog ID.
941
  * @param int $user_id Optional. Defaults to the logged-in user ID. This param
942
- * is currently unused in the function (but is passed to hooks).
943
- *
944
- * @return bool
945
  */
946
  function bp_blogs_remove_post( $post_id, $blog_id = 0, $user_id = 0 ) {
947
- global $wpdb;
948
 
949
  if ( empty( $wpdb->blogid ) )
950
  return false;
@@ -957,34 +844,11 @@ function bp_blogs_remove_post( $post_id, $blog_id = 0, $user_id = 0 ) {
957
  if ( !$user_id )
958
  $user_id = bp_loggedin_user_id();
959
 
960
- /**
961
- * Fires before removal of a blog post activity item from the activity stream.
962
- *
963
- * @since 1.5.0
964
- *
965
- * @param int $blog_id ID of the blog associated with the post that was removed.
966
- * @param int $post_id ID of the post that was removed.
967
- * @param int $user_id ID of the user having the blog removed for.
968
- */
969
  do_action( 'bp_blogs_before_remove_post', $blog_id, $post_id, $user_id );
970
 
971
  // Delete activity stream item
972
- bp_blogs_delete_activity( array(
973
- 'item_id' => $blog_id,
974
- 'secondary_item_id' => $post_id,
975
- 'component' => buddypress()->blogs->id,
976
- 'type' => 'new_blog_post'
977
- ) );
978
 
979
- /**
980
- * Fires after removal of a blog post activity item from the activity stream.
981
- *
982
- * @since 1.0.0
983
- *
984
- * @param int $blog_id ID of the blog associated with the post that was removed.
985
- * @param int $post_id ID of the post that was removed.
986
- * @param int $user_id ID of the user having the blog removed for.
987
- */
988
  do_action( 'bp_blogs_remove_post', $blog_id, $post_id, $user_id );
989
  }
990
  add_action( 'delete_post', 'bp_blogs_remove_post' );
@@ -1021,7 +885,6 @@ function bp_blogs_remove_comment( $comment_id ) {
1021
  $activity = bp_activity_get( array(
1022
  'in' => $activity_id,
1023
  'display_comments' => 'stream',
1024
- 'spam' => 'all',
1025
  ) );
1026
 
1027
  // get all activity comment IDs for the pending deleted item
@@ -1045,15 +908,6 @@ function bp_blogs_remove_comment( $comment_id ) {
1045
  }
1046
  }
1047
 
1048
- /**
1049
- * Fires after a blog comment activity item was removed from activity stream.
1050
- *
1051
- * @since 1.0.0
1052
- *
1053
- * @param int $blogid Item ID for the blog associated with the removed comment.
1054
- * @param int $comment_id ID of the comment being removed.
1055
- * @param int $value ID of the current logged in user.
1056
- */
1057
  do_action( 'bp_blogs_remove_comment', $wpdb->blogid, $comment_id, bp_loggedin_user_id() );
1058
  }
1059
  add_action( 'delete_comment', 'bp_blogs_remove_comment' );
@@ -1061,15 +915,15 @@ add_action( 'delete_comment', 'bp_blogs_remove_comment' );
1061
  /**
1062
  * Removes blog comments that are associated with activity comments.
1063
  *
1064
- * @since 2.0.0
1065
  *
1066
  * @see bp_blogs_remove_comment()
1067
  * @see bp_blogs_sync_delete_from_activity_comment()
1068
  *
1069
  * @param array $activity_ids The activity IDs to check association with blog
1070
- * comments.
1071
- * @param bool $force_delete Whether to force delete the comments. If false,
1072
- * comments are trashed instead.
1073
  */
1074
  function bp_blogs_remove_associated_blog_comments( $activity_ids = array(), $force_delete = true ) {
1075
  // query args
@@ -1102,13 +956,16 @@ function bp_blogs_remove_associated_blog_comments( $activity_ids = array(), $for
1102
  /**
1103
  * When a blog comment status transition occurs, update the relevant activity's status.
1104
  *
1105
- * @since 1.6.0
 
 
1106
  *
1107
  * @param string $new_status New comment status.
1108
  * @param string $old_status Previous comment status.
1109
- * @param object $comment Comment data.
1110
  */
1111
  function bp_blogs_transition_activity_status( $new_status, $old_status, $comment ) {
 
1112
 
1113
  // Check the Activity component is active
1114
  if ( ! bp_is_active( 'activity' ) )
@@ -1137,12 +994,7 @@ function bp_blogs_transition_activity_status( $new_status, $old_status, $comment
1137
 
1138
  // Get the activity
1139
  if ( bp_disable_blogforum_comments() ) {
1140
- $activity_id = bp_activity_get_activity_id( array(
1141
- 'component' => buddypress()->blogs->id,
1142
- 'item_id' => get_current_blog_id(),
1143
- 'secondary_item_id' => $comment->comment_ID,
1144
- 'type' => 'new_blog_comment'
1145
- ) );
1146
  } else {
1147
  $activity_id = get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true );
1148
  }
@@ -1187,9 +1039,7 @@ add_action( 'transition_comment_status', 'bp_blogs_transition_activity_status',
1187
  * @return int $count Total blog count.
1188
  */
1189
  function bp_blogs_total_blogs() {
1190
- $count = wp_cache_get( 'bp_total_blogs', 'bp' );
1191
-
1192
- if ( false === $count ) {
1193
  $blogs = BP_Blogs_Blog::get_all();
1194
  $count = $blogs['total'];
1195
  wp_cache_set( 'bp_total_blogs', $count, 'bp' );
@@ -1200,25 +1050,16 @@ function bp_blogs_total_blogs() {
1200
  /**
1201
  * Get the total number of blogs being tracked by BP for a specific user.
1202
  *
1203
- * @since 1.2.0
1204
- *
1205
  * @param int $user_id ID of the user being queried. Default: on a user page,
1206
- * the displayed user. Otherwise, the logged-in user.
1207
- *
1208
  * @return int $count Total blog count for the user.
1209
  */
1210
  function bp_blogs_total_blogs_for_user( $user_id = 0 ) {
1211
- if ( empty( $user_id ) ) {
1212
- $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
1213
- }
1214
 
1215
- // no user ID? do not attempt to look at cache
1216
- if ( empty( $user_id ) ) {
1217
- return 0;
1218
- }
1219
 
1220
- $count = wp_cache_get( 'bp_total_blogs_for_user_' . $user_id, 'bp' );
1221
- if ( false === $count ) {
1222
  $count = BP_Blogs_Blog::total_blog_count_for_user( $user_id );
1223
  wp_cache_set( 'bp_total_blogs_for_user_' . $user_id, $count, 'bp' );
1224
  }
@@ -1232,35 +1073,16 @@ function bp_blogs_total_blogs_for_user( $user_id = 0 ) {
1232
  * @param int $blog_id The ID of the blog to expunge.
1233
  */
1234
  function bp_blogs_remove_data_for_blog( $blog_id ) {
 
1235
 
1236
- /**
1237
- * Fires before all data related to a given blog is removed from blogs tracker
1238
- * and activity stream.
1239
- *
1240
- * @since 1.5.0
1241
- *
1242
- * @param int $blog_id ID of the blog whose data is being removed.
1243
- */
1244
  do_action( 'bp_blogs_before_remove_data_for_blog', $blog_id );
1245
 
1246
  // If this is regular blog, delete all data for that blog.
1247
  BP_Blogs_Blog::delete_blog_for_all( $blog_id );
1248
 
1249
  // Delete activity stream item
1250
- bp_blogs_delete_activity( array(
1251
- 'item_id' => $blog_id,
1252
- 'component' => buddypress()->blogs->id,
1253
- 'type' => false
1254
- ) );
1255
 
1256
- /**
1257
- * Fires after all data related to a given blog has been removed from blogs tracker
1258
- * and activity stream.
1259
- *
1260
- * @since 1.0.0
1261
- *
1262
- * @param int $blog_id ID of the blog whose data is being removed.
1263
- */
1264
  do_action( 'bp_blogs_remove_data_for_blog', $blog_id );
1265
  }
1266
  add_action( 'delete_blog', 'bp_blogs_remove_data_for_blog', 1 );
@@ -1271,9 +1093,8 @@ add_action( 'delete_blog', 'bp_blogs_remove_data_for_blog', 1 );
1271
  * @see BP_Blogs_Blog::get_blogs_for_user() for a description of parameters
1272
  * and return values.
1273
  *
1274
- * @param int $user_id See {@BP_Blogs_Blog::get_blogs_for_user()}.
1275
  * @param bool $show_hidden See {@BP_Blogs_Blog::get_blogs_for_user()}.
1276
- *
1277
  * @return array See {@BP_Blogs_Blog::get_blogs_for_user()}.
1278
  */
1279
  function bp_blogs_get_blogs_for_user( $user_id, $show_hidden = false ) {
@@ -1286,8 +1107,7 @@ function bp_blogs_get_blogs_for_user( $user_id, $show_hidden = false ) {
1286
  * @see BP_Blogs_Blog::get_all() for a description of parameters and return values.
1287
  *
1288
  * @param int $limit See {@BP_Blogs_Blog::get_all()}.
1289
- * @param int $page See {@BP_Blogs_Blog::get_all()}.
1290
- *
1291
  * @return array See {@BP_Blogs_Blog::get_all()}.
1292
  */
1293
  function bp_blogs_get_all_blogs( $limit = null, $page = null ) {
@@ -1300,8 +1120,7 @@ function bp_blogs_get_all_blogs( $limit = null, $page = null ) {
1300
  * @see BP_Blogs_Blog::get() for a description of parameters and return values.
1301
  *
1302
  * @param int $limit See {@BP_Blogs_Blog::get()}.
1303
- * @param int $page See {@BP_Blogs_Blog::get()}.
1304
- *
1305
  * @return array See {@BP_Blogs_Blog::get()}.
1306
  */
1307
  function bp_blogs_get_random_blogs( $limit = null, $page = null ) {
@@ -1314,7 +1133,6 @@ function bp_blogs_get_random_blogs( $limit = null, $page = null ) {
1314
  * @see BP_Blogs_Blog::is_hidden() for a description of parameters and return values.
1315
  *
1316
  * @param int $blog_id See {@BP_Blogs_Blog::is_hidden()}.
1317
- *
1318
  * @return bool See {@BP_Blogs_Blog::is_hidden()}.
1319
  */
1320
  function bp_blogs_is_blog_hidden( $blog_id ) {
@@ -1331,25 +1149,24 @@ function bp_blogs_is_blog_hidden( $blog_id ) {
1331
  */
1332
 
1333
  /**
1334
- * Delete a metadata from the DB for a blog.
1335
  *
1336
  * @global object $wpdb WordPress database access object.
1337
- *
1338
- * @param int $blog_id ID of the blog whose metadata is being deleted.
1339
- * @param string|bool $meta_key Optional. The key of the metadata being deleted. If
1340
- * omitted, all BP metadata associated with the blog will
1341
- * be deleted.
1342
- * @param string|bool $meta_value Optional. If present, the metadata will only be
1343
- * deleted if the meta_value matches this parameter.
1344
- * @param bool $delete_all Optional. If true, delete matching metadata entries for
1345
- * all objects, ignoring the specified blog_id. Otherwise, only
1346
- * delete matching metadata entries for the specified blog.
1347
- * Default: false.
1348
- *
1349
  * @return bool True on success, false on failure.
1350
  */
1351
  function bp_blogs_delete_blogmeta( $blog_id, $meta_key = false, $meta_value = false, $delete_all = false ) {
1352
- global $wpdb;
1353
 
1354
  // Legacy - if no meta_key is passed, delete all for the blog_id
1355
  if ( empty( $meta_key ) ) {
@@ -1374,18 +1191,18 @@ function bp_blogs_delete_blogmeta( $blog_id, $meta_key = false, $meta_value = fa
1374
  /**
1375
  * Get metadata for a given blog.
1376
  *
1377
- * @since 1.2.0
1378
  *
1379
  * @global object $wpdb WordPress database access object.
 
1380
  *
1381
- * @param int $blog_id ID of the blog whose metadata is being requested.
1382
  * @param string $meta_key Optional. If present, only the metadata matching
1383
- * that meta key will be returned. Otherwise, all
1384
- * metadata for the blog will be fetched.
1385
- * @param bool $single Optional. If true, return only the first value of the
1386
- * specified meta_key. This parameter has no effect if
1387
- * meta_key is not specified. Default: true.
1388
- *
1389
  * @return mixed The meta value(s) being requested.
1390
  */
1391
  function bp_blogs_get_blogmeta( $blog_id, $meta_key = '', $single = true ) {
@@ -1400,17 +1217,17 @@ function bp_blogs_get_blogmeta( $blog_id, $meta_key = '', $single = true ) {
1400
  * Update a piece of blog meta.
1401
  *
1402
  * @global object $wpdb WordPress database access object.
1403
- *
1404
- * @param int $blog_id ID of the blog whose metadata is being updated.
1405
- * @param string $meta_key Key of the metadata being updated.
1406
- * @param mixed $meta_value Value to be set.
1407
- * @param mixed $prev_value Optional. If specified, only update existing
1408
- * metadata entries with the specified value.
1409
- * Otherwise, update all entries.
1410
- *
1411
  * @return bool|int Returns false on failure. On successful update of existing
1412
- * metadata, returns true. On successful creation of new metadata,
1413
- * returns the integer ID of the new metadata row.
1414
  */
1415
  function bp_blogs_update_blogmeta( $blog_id, $meta_key, $meta_value, $prev_value = '' ) {
1416
  add_filter( 'query', 'bp_filter_metaid_column_name' );
@@ -1423,15 +1240,14 @@ function bp_blogs_update_blogmeta( $blog_id, $meta_key, $meta_value, $prev_value
1423
  /**
1424
  * Add a piece of blog metadata.
1425
  *
1426
- * @since 2.0.0
1427
- *
1428
- * @param int $blog_id ID of the blog.
1429
- * @param string $meta_key Metadata key.
1430
- * @param mixed $meta_value Metadata value.
1431
- * @param bool $unique Optional. Whether to enforce a single metadata value
1432
- * for the given key. If true, and the object already has a value for
1433
- * the key, no change will be made. Default: false.
1434
  *
 
 
 
 
 
 
1435
  * @return int|bool The meta ID on successful update, false on failure.
1436
  */
1437
  function bp_blogs_add_blogmeta( $blog_id, $meta_key, $meta_value, $unique = false ) {
@@ -1445,60 +1261,19 @@ function bp_blogs_add_blogmeta( $blog_id, $meta_key, $meta_value, $unique = fals
1445
  * Remove all blog associations for a given user.
1446
  *
1447
  * @param int $user_id ID whose blog data should be removed.
1448
- *
1449
  * @return bool|null Returns false on failure.
1450
  */
1451
  function bp_blogs_remove_data( $user_id ) {
1452
  if ( !is_multisite() )
1453
  return false;
1454
 
1455
- /**
1456
- * Fires before all blog associations are removed for a given user.
1457
- *
1458
- * @since 1.5.0
1459
- *
1460
- * @param int $user_id ID of the user whose blog associations are being removed.
1461
- */
1462
  do_action( 'bp_blogs_before_remove_data', $user_id );
1463
 
1464
  // If this is regular blog, delete all data for that blog.
1465
  BP_Blogs_Blog::delete_blogs_for_user( $user_id );
1466
 
1467
- /**
1468
- * Fires after all blog associations are removed for a given user.
1469
- *
1470
- * @since 1.0.0
1471
- *
1472
- * @param int $user_id ID of the user whose blog associations were removed.
1473
- */
1474
  do_action( 'bp_blogs_remove_data', $user_id );
1475
  }
1476
  add_action( 'wpmu_delete_user', 'bp_blogs_remove_data' );
1477
  add_action( 'delete_user', 'bp_blogs_remove_data' );
1478
  add_action( 'bp_make_spam_user', 'bp_blogs_remove_data' );
1479
-
1480
- /**
1481
- * Restore all blog associations for a given user.
1482
- *
1483
- * @since 2.2.0
1484
- *
1485
- * @param int $user_id ID whose blog data should be restored.
1486
- */
1487
- function bp_blogs_restore_data( $user_id = 0 ) {
1488
- if ( ! is_multisite() ) {
1489
- return;
1490
- }
1491
-
1492
- // Get the user's blogs
1493
- $user_blogs = get_blogs_of_user( $user_id );
1494
- if ( empty( $user_blogs ) ) {
1495
- return;
1496
- }
1497
-
1498
- $blogs = array_keys( $user_blogs );
1499
-
1500
- foreach ( $blogs as $blog_id ) {
1501
- bp_blogs_add_user_to_blog( $user_id, false, $blog_id );
1502
- }
1503
- }
1504
- add_action( 'bp_make_ham_user', 'bp_blogs_restore_data', 10, 1 );
7
  */
8
 
9
  // Exit if accessed directly
10
+ if ( !defined( 'ABSPATH' ) ) exit;
11
 
12
  /**
13
  * Check whether the $bp global lists an activity directory page.
14
  *
15
+ * @since BuddyPress (1.5.0)
16
+ *
17
+ * @global BuddyPress $bp The one true BuddyPress instance.
18
  *
19
  * @return bool True if set, false if empty.
20
  */
21
  function bp_blogs_has_directory() {
22
+ global $bp;
23
 
24
  return (bool) !empty( $bp->pages->blogs->id );
25
  }
26
 
27
  /**
28
+ * Retrieve a set of blogs
29
  *
30
  * @see BP_Blogs_Blog::get() for a description of arguments and return value.
31
  *
32
+ * @param array $args {
33
  * Arguments are listed here with their default values. For more
34
  * information about the arguments, see {@link BP_Blogs_Blog::get()}.
35
+ * @type string $type Default: 'active'.
36
+ * @type int|bool $user_id Default: false.
37
+ * @type array $include_blog_ids Default: false.
38
+ * @type string|bool $search_terms Default: false.
39
+ * @type int $per_page Default: 20.
40
+ * @type int $page Default: 1.
41
+ * @type bool $update_meta_cache Whether to pre-fetch blogmeta. Default: true.
42
  * }
43
  * @return array See {@link BP_Blogs_Blog::get()}.
44
  */
45
  function bp_blogs_get_blogs( $args = '' ) {
46
 
47
+ $defaults = array(
48
+ 'type' => 'active', // active, alphabetical, newest, or random
49
+ 'user_id' => false, // Pass a user_id to limit to only blogs that this user has privilages higher than subscriber on
50
+ 'include_blog_ids' => false,
51
+ 'search_terms' => false, // Limit to blogs that match these search terms
 
52
  'per_page' => 20, // The number of results to return per page
53
  'page' => 1, // The page to return if limiting per page
54
+ 'update_meta_cache' => true,
 
 
 
 
 
 
 
 
 
 
 
55
  );
56
 
57
+ $params = wp_parse_args( $args, $defaults );
58
+ extract( $params, EXTR_SKIP );
59
+
60
+ return apply_filters( 'bp_blogs_get_blogs', BP_Blogs_Blog::get( $type, $per_page, $page, $user_id, $search_terms, $update_meta_cache, $include_blog_ids ), $params );
61
  }
62
 
63
  /**
64
  * Populate the BP blogs table with existing blogs.
65
  *
66
+ * @global object $bp BuddyPress global settings
67
+ * @global object $wpdb WordPress database object
 
68
  * @uses get_users()
69
  * @uses bp_blogs_record_blog()
 
 
70
  */
71
  function bp_blogs_record_existing_blogs() {
72
+ global $bp, $wpdb;
 
 
 
73
 
74
+ // Truncate user blogs table and re-record.
75
+ $wpdb->query( "DELETE FROM {$bp->blogs->table_name} WHERE 1=1" );
 
76
 
77
+ if ( is_multisite() ) {
78
+ $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$wpdb->base_prefix}blogs WHERE mature = 0 AND spam = 0 AND deleted = 0 AND site_id = %d", $wpdb->siteid ) );
 
 
 
 
 
 
 
 
 
79
  } else {
80
+ $blog_ids = 1;
81
  }
82
 
83
+ if ( !empty( $blog_ids ) ) {
84
+ foreach( (array) $blog_ids as $blog_id ) {
85
+ $users = get_users( array( 'blog_id' => $blog_id, 'fields' => 'ID' ) );
86
+ $subscribers = get_users( array( 'blog_id' => $blog_id, 'fields' => 'ID', 'role' => 'subscriber' ) );
87
+
88
+ if ( !empty( $users ) ) {
89
+ foreach ( (array) $users as $user ) {
90
+ // Don't record blogs for subscribers
91
+ if ( !in_array( $user, $subscribers ) ) {
92
+ bp_blogs_record_blog( $blog_id, $user, true );
93
+ }
94
+ }
95
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  }
97
  }
 
 
 
 
 
 
 
 
 
 
98
  }
99
 
100
  /**
103
  * If $user_id is provided, you can restrict site from being recordable
104
  * only to particular users.
105
  *
106
+ * @since BuddyPress (1.7.0)
107
  *
108
  * @uses apply_filters()
109
  *
110
  * @param int $blog_id ID of the blog being checked.
111
  * @param int $user_id Optional. ID of the user for whom access is being checked.
 
112
  * @return bool True if blog is recordable, otherwise false.
113
  */
114
  function bp_blogs_is_blog_recordable( $blog_id, $user_id = 0 ) {
134
  * If $user_id is provided, the developer can restrict site from
135
  * being trackable only to particular users.
136
  *
137
+ * @since BuddyPress (1.7.0)
138
  *
139
  * @uses bp_blogs_is_blog_recordable
140
  * @uses apply_filters()
141
  *
142
  * @param int $blog_id ID of the blog being checked.
143
  * @param int $user_id Optional. ID of the user for whom access is being checked.
 
144
  * @return bool True if blog is trackable, otherwise false.
145
  */
146
  function bp_blogs_is_blog_trackable( $blog_id, $user_id = 0 ) {
163
  /**
164
  * Make BuddyPress aware of a new site so that it can track its activity.
165
  *
166
+ * @since BuddyPress (1.0.0)
167
  *
168
  * @uses BP_Blogs_Blog
169
  *
170
+ * @param int $blog_id ID of the blog being recorded.
171
+ * @param int $user_id ID of the user for whom the blog is being recorded.
172
  * @param bool $no_activity Optional. Whether to skip recording an activity
173
+ * item about this blog creation. Default: false.
 
174
  * @return bool|null Returns false on failure.
175
  */
176
  function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) {
183
  return false;
184
 
185
  $name = get_blog_option( $blog_id, 'blogname' );
 
186
 
187
  if ( empty( $name ) ) {
188
+ return false;
189
  }
190
 
191
+ $url = get_home_url( $blog_id );
192
  $description = get_blog_option( $blog_id, 'blogdescription' );
193
  $close_old_posts = get_blog_option( $blog_id, 'close_comments_for_old_posts' );
194
  $close_days_old = get_blog_option( $blog_id, 'close_comments_days_old' );
230
  ) );
231
  }
232
 
 
 
 
 
 
 
 
 
 
233
  do_action_ref_array( 'bp_blogs_new_blog', array( &$recorded_blog, $is_private, $is_recorded ) );
234
  }
235
  add_action( 'wpmu_new_blog', 'bp_blogs_record_blog', 10, 2 );
240
  * @global object $wpdb DB Layer.
241
  *
242
  * @param string $oldvalue Value before save. Passed by do_action() but
243
+ * unused here.
244
  * @param string $newvalue Value to change meta to.
245
  */
246
  function bp_blogs_update_option_blogname( $oldvalue, $newvalue ) {
251
  add_action( 'update_option_blogname', 'bp_blogs_update_option_blogname', 10, 2 );
252
 
253
  /**
254
+ * Update blog description in BuddyPress blogmeta table
255
  *
256
  * @global object $wpdb DB Layer.
257
  *
258
  * @param string $oldvalue Value before save. Passed by do_action() but
259
+ * unused here.
260
  * @param string $newvalue Value to change meta to.
261
  */
262
  function bp_blogs_update_option_blogdescription( $oldvalue, $newvalue ) {
269
  /**
270
  * Update "Close comments for old posts" option in BuddyPress blogmeta table.
271
  *
272
+ * @since BuddyPress (2.0.0)
273
  *
274
  * @global object $wpdb DB Layer.
275
  *
276
  * @param string $oldvalue Value before save. Passed by do_action() but
277
+ * unused here.
278
  * @param string $newvalue Value to change meta to.
279
  */
280
  function bp_blogs_update_option_close_comments_for_old_posts( $oldvalue, $newvalue ) {
287
  /**
288
  * Update "Close comments after days old" option in BuddyPress blogmeta table.
289
  *
290
+ * @since BuddyPress (2.0.0)
291
  *
292
  * @global object $wpdb DB Layer.
293
  *
294
  * @param string $oldvalue Value before save. Passed by do_action() but
295
+ * unused here.
296
  * @param string $newvalue Value to change meta to.
297
  */
298
+ function bp_blogs_update_option_close_close_comments_days_old( $oldvalue, $newvalue ) {
299
  global $wpdb;
300
 
301
  bp_blogs_update_blogmeta( $wpdb->blogid, 'close_comments_days_old', $newvalue );
305
  /**
306
  * When toggling threaded comments, update thread depth in blogmeta table.
307
  *
308
+ * @since BuddyPress (2.0.0)
309
  *
310
  * @global object $wpdb DB Layer.
311
  *
312
  * @param string $oldvalue Value before save. Passed by do_action() but
313
+ * unused here.
314
  * @param string $newvalue Value to change meta to.
315
  */
316
  function bp_blogs_update_option_thread_comments( $oldvalue, $newvalue ) {
329
  /**
330
  * When updating comment depth, update thread depth in blogmeta table.
331
  *
332
+ * @since BuddyPress (2.0.0)
333
  *
334
  * @global object $wpdb DB Layer.
335
  *
336
  * @param string $oldvalue Value before save. Passed by do_action() but
337
+ * unused here.
338
  * @param string $newvalue Value to change meta to.
339
  */
340
  function bp_blogs_update_option_thread_comments_depth( $oldvalue, $newvalue ) {
349
  add_action( 'update_option_thread_comments_depth', 'bp_blogs_update_option_thread_comments_depth', 10, 2 );
350
 
351
  /**
352
+ * Detect a change in post status, and initiate an activity update if necessary.
353
  *
354
+ * Posts get new activity updates when (a) they are being published, and (b)
355
+ * they have not already been published. This enables proper posting for
356
+ * regular posts as well as scheduled posts, while preventing post bumping.
357
  *
358
+ * See #4090, #3746, #2546 for background.
359
  *
360
+ * @since BuddyPress (2.0.0)
 
 
 
 
 
 
 
 
361
  *
362
+ * @todo Support untrashing better
363
  *
364
+ * @param string $new_status New status for the post.
365
+ * @param string $old_status Old status for the post.
366
+ * @param object $post Post data.
367
  */
368
+ function bp_blogs_catch_transition_post_status( $new_status, $old_status, $post ) {
 
 
 
 
 
369
 
370
+ // This is an edit
371
+ if ( $new_status === $old_status ) {
372
+ if ( $new_status == 'publish' ) {
373
+ bp_blogs_update_post( $post );
374
+ return;
375
+ }
376
  }
377
 
378
+ // Publishing a previously unpublished post
379
+ if ( 'publish' === $new_status ) {
380
+ // Untrashing the post
381
+ // Nothing here yet
382
+ if ( 'trash' == $old_status ) {}
383
 
384
+ // Record the post
385
+ bp_blogs_record_post( $post->ID, $post );
386
 
387
+ // Unpublishing a previously published post
388
+ } else if ( 'publish' === $old_status ) {
389
+ // Some form of pending status
390
+ // Only remove the activity entry
391
+ bp_blogs_delete_activity( array(
392
+ 'item_id' => get_current_blog_id(),
393
+ 'secondary_item_id' => $post->ID,
394
+ 'component' => buddypress()->blogs->id,
395
+ 'type' => 'new_blog_post'
396
+ ) );
397
+ }
398
  }
399
+ add_action( 'transition_post_status', 'bp_blogs_catch_transition_post_status', 10, 3 );
400
 
401
  /**
402
+ * Record a new blog post in the BuddyPress activity stream.
403
  *
404
+ * @param int $post_id ID of the post being recorded.
405
+ * @param object $post The WP post object passed to the 'save_post' action.
406
+ * @param int $user_id Optional. The user to whom the activity item will be
407
+ * associated. Defaults to the post_author.
408
+ * @return bool|null Returns false on failure.
409
  */
410
+ function bp_blogs_record_post( $post_id, $post, $user_id = 0 ) {
411
+ global $bp, $wpdb;
412
+
413
+ $post_id = (int) $post_id;
414
+ $blog_id = (int) $wpdb->blogid;
415
+
416
+ // If blog is not trackable, do not record the activity.
417
+ if ( ! bp_blogs_is_blog_trackable( $blog_id, $user_id ) )
418
+ return false;
419
+
420
+ if ( !$user_id )
421
+ $user_id = (int) $post->post_author;
422
+
423
+ // Stop infinite loops with WordPress MU Sitewide Tags.
424
+ // That plugin changed the way its settings were stored at some point. Thus the dual check.
425
+ if ( !empty( $bp->site_options['sitewide_tags_blog'] ) ) {
426
+ $st_options = maybe_unserialize( $bp->site_options['sitewide_tags_blog'] );
427
+ $tags_blog_id = isset( $st_options['tags_blog_id'] ) ? $st_options['tags_blog_id'] : 0;
428
+ } else {
429
+ $tags_blog_id = isset( $bp->site_options['tags_blog_id'] ) ? $bp->site_options['tags_blog_id'] : 0;
430
  }
431
 
432
+ if ( (int) $blog_id == $tags_blog_id && apply_filters( 'bp_blogs_block_sitewide_tags_activity', true ) )
433
+ return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
434
 
435
+ // Don't record this if it's not a post
436
+ if ( !in_array( $post->post_type, apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) ) ) )
437
+ return false;
 
 
 
438
 
439
+ $is_blog_public = apply_filters( 'bp_is_blog_public', (int)get_blog_option( $blog_id, 'blog_public' ) );
 
 
 
440
 
441
+ if ( 'publish' == $post->post_status && empty( $post->post_password ) ) {
442
+ if ( $is_blog_public || !is_multisite() ) {
 
 
 
 
 
 
 
443
 
444
+ // Record this in activity streams
445
+ $post_permalink = add_query_arg(
446
+ 'p',
447
+ $post_id,
448
+ trailingslashit( get_home_url( $blog_id ) )
449
+ );
450
 
451
+ if ( is_multisite() )
452
+ $activity_action = sprintf( __( '%1$s wrote a new post, %2$s, on the site %3$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' );
453
+ else
454
+ $activity_action = sprintf( __( '%1$s wrote a new post, %2$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
455
+
456
+ // Make sure there's not an existing entry for this post (prevent bumping)
457
+ if ( bp_is_active( 'activity' ) ) {
458
+ $existing = bp_activity_get( array(
459
+ 'filter' => array(
460
+ 'action' => 'new_blog_post',
461
+ 'primary_id' => $blog_id,
462
+ 'secondary_id' => $post_id,
463
+ )
464
+ ) );
465
+
466
+ if ( !empty( $existing['activities'] ) ) {
467
+ return;
468
  }
469
  }
470
 
471
+ $activity_content = $post->post_content;
472
+
473
+ bp_blogs_record_activity( array(
474
+ 'user_id' => (int) $post->post_author,
475
+ 'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, $post, $post_permalink ),
476
+ 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
477
+ 'type' => 'new_blog_post',
478
+ 'item_id' => $blog_id,
479
+ 'secondary_item_id' => $post_id,
480
+ 'recorded_time' => $post->post_date_gmt,
481
+ ));
482
  }
483
+
484
+ // Update the blogs last activity
485
+ bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
486
+ } else {
487
+ bp_blogs_remove_post( $post_id, $blog_id, $user_id );
488
+ }
489
+
490
+ do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
491
+ }
492
+
493
+ /**
494
+ * Updates a blog post's corresponding activity entry during a post edit.
495
+ *
496
+ * @since BuddyPress (2.0.0)
497
+ *
498
+ * @see bp_blogs_catch_transition_post_status()
499
+ *
500
+ * @param WP_Post $post
501
+ */
502
+ function bp_blogs_update_post( $post ) {
503
+ if ( ! bp_is_active( 'activity' ) ) {
504
+ return;
505
+ }
506
+
507
+ $activity_id = bp_activity_get_activity_id( array(
508
+ 'component' => buddypress()->blogs->id,
509
+ 'item_id' => get_current_blog_id(),
510
+ 'secondary_item_id' => $post->ID,
511
+ 'type' => 'new_blog_post',
512
+ ) );
513
+
514
+ // activity ID doesn't exist, so stop!
515
+ if ( empty( $activity_id ) ) {
516
+ return;
517
  }
518
 
519
+ // update the activity entry
520
+ $activity = new BP_Activity_Activity( $activity_id );
521
+ $activity->content = $post->post_content;
522
+ $activity->save();
523
+
524
+ // add post comment status to activity meta if closed
525
  if( 'closed' == $post->comment_status ) {
526
+ bp_activity_update_meta( $activity_id, 'post_comment_status', $post->comment_status );
527
  } else {
528
+ bp_activity_delete_meta( $activity_id, 'post_comment_status' );
529
  }
530
  }
 
531
 
532
  /**
533
  * Record a new blog comment in the BuddyPress activity stream.
534
  *
535
  * Only posts the item if blog is public and post is not password-protected.
536
  *
537
+ * @param int $comment_id ID of the comment being recorded.
538
  * @param bool|string $is_approved Optional. The $is_approved value passed to
539
+ * the 'comment_post' action. Default: true.
 
540
  * @return bool|object Returns false on failure, the comment object on success.
541
  */
542
  function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
618
  $args['secondary_item_id'] = $comment_id;
619
 
620
  // record the activity entry
621
+ bp_blogs_record_activity( $args );
 
 
 
 
622
 
623
  // record comment as BP activity comment under the parent 'new_blog_post'
624
  // activity item
641
  'secondary_item_id' => $recorded_comment->comment_post_ID
642
  ) );
643
 
 
 
 
 
 
644
  // we found the parent activity entry
645
  // so let's go ahead and reconfigure some activity args
646
  if ( ! empty( $parent_activity_id ) ) {
682
  if ( empty( $args['id'] ) ) {
683
  // add meta to activity comment
684
  bp_activity_update_meta( $comment_activity_id, 'bp_blogs_post_comment_id', $comment_id );
 
 
685
 
686
  // add meta to comment
687
  add_comment_meta( $comment_id, 'bp_activity_comment_id', $comment_activity_id );
705
  * set/changed ('add_user_to_blog', 'profile_update', 'user_register'). It
706
  * parses the changes, and records them as necessary in the BP blog tracker.
707
  *
708
+ * BuddyPress does not track blogs for Subscribers.
 
 
 
 
 
 
709
  *
710
+ * @param int $user_id The ID of the user.
711
+ * @param string|bool $role The WP role being assigned to the user
712
+ * ('subscriber', 'contributor', 'author', 'editor', 'administrator', or
713
+ * a custom role). Defaults to false.
714
+ * @param int $blog_id Default: the current blog ID.
715
  * @return bool|null False on failure.
716
  */
717
  function bp_blogs_add_user_to_blog( $user_id, $role = false, $blog_id = 0 ) {
718
  global $wpdb;
719
 
 
720
  if ( empty( $blog_id ) ) {
721
  $blog_id = isset( $wpdb->blogid ) ? $wpdb->blogid : bp_get_root_blog_id();
722
  }
723
 
 
724
  if ( empty( $role ) ) {
725
+ $key = $wpdb->get_blog_prefix( $blog_id ). 'capabilities';
726
 
727
+ $roles = bp_get_user_meta( $user_id, $key, true );
 
 
 
 
 
 
 
 
 
 
 
728
 
729
+ if ( is_array( $roles ) )
730
+ $role = array_search( 1, $roles );
731
+ else
732
+ return false;
 
 
 
 
733
  }
734
 
735
+ if ( $role != 'subscriber' )
736
+ bp_blogs_record_blog( $blog_id, $user_id, true );
 
 
 
 
 
737
  }
738
  add_action( 'add_user_to_blog', 'bp_blogs_add_user_to_blog', 10, 3 );
739
  add_action( 'profile_update', 'bp_blogs_add_user_to_blog' );
740
  add_action( 'user_register', 'bp_blogs_add_user_to_blog' );
741
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
742
  /**
743
  * Remove a blog-user pair from BP's blog tracker.
744
  *
748
  function bp_blogs_remove_user_from_blog( $user_id, $blog_id = 0 ) {
749
  global $wpdb;
750
 
751
+ if ( empty( $blog_id ) )
752
  $blog_id = $wpdb->blogid;
 
753
 
754
  bp_blogs_remove_blog_for_user( $user_id, $blog_id );
755
  }
756
  add_action( 'remove_user_from_blog', 'bp_blogs_remove_user_from_blog', 10, 2 );
757
 
758
  /**
759
+ * Rehook WP's maybe_add_existing_user_to_blog with a later priority
760
  *
761
  * WordPress catches add-user-to-blog requests at init:10. In some cases, this
762
  * can precede BP's Blogs component. This function bumps the priority of the
763
  * core function, so that we can be sure that the Blogs component is loaded
764
+ * first. See http://buddypress.trac.wordpress.org/ticket/3916.
765
  *
766
+ * @since BuddyPress (1.6)
767
+ * @access private
768
  */
769
  function bp_blogs_maybe_add_user_to_blog() {
770
  if ( ! is_multisite() )
781
  * @param int $blog_id ID of the blog being removed.
782
  */
783
  function bp_blogs_remove_blog( $blog_id ) {
784
+ global $bp;
785
 
786
  $blog_id = (int) $blog_id;
 
 
 
 
 
 
 
 
 
787
  do_action( 'bp_blogs_before_remove_blog', $blog_id );
788
 
789
  BP_Blogs_Blog::delete_blog_for_all( $blog_id );
790
 
791
  // Delete activity stream item
792
+ bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->id, 'type' => 'new_blog' ) );
 
 
 
 
793
 
 
 
 
 
 
 
 
 
794
  do_action( 'bp_blogs_remove_blog', $blog_id );
795
  }
796
  add_action( 'delete_blog', 'bp_blogs_remove_blog' );
802
  * @param int $blog_id ID of the blog being removed.
803
  */
804
  function bp_blogs_remove_blog_for_user( $user_id, $blog_id ) {
805
+ global $bp;
806
 
807
  $blog_id = (int) $blog_id;
808
  $user_id = (int) $user_id;
809
 
 
 
 
 
 
 
 
 
810
  do_action( 'bp_blogs_before_remove_blog_for_user', $blog_id, $user_id );
811
 
812
  BP_Blogs_Blog::delete_blog_for_user( $blog_id, $user_id );
814
  // Delete activity stream item
815
  bp_blogs_delete_activity( array(
816
  'item_id' => $blog_id,
817
+ 'component' => $bp->blogs->id,
818
  'type' => 'new_blog'
819
  ) );
820
 
 
 
 
 
 
 
 
 
821
  do_action( 'bp_blogs_remove_blog_for_user', $blog_id, $user_id );
822
  }
823
  add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 );
828
  * @param int $post_id ID of the post to be removed.
829
  * @param int $blog_id Optional. Defaults to current blog ID.
830
  * @param int $user_id Optional. Defaults to the logged-in user ID. This param
831
+ * is currently unused in the function (but is passed to hooks).
 
 
832
  */
833
  function bp_blogs_remove_post( $post_id, $blog_id = 0, $user_id = 0 ) {
834
+ global $wpdb, $bp;
835
 
836
  if ( empty( $wpdb->blogid ) )
837
  return false;
844
  if ( !$user_id )
845
  $user_id = bp_loggedin_user_id();
846
 
 
 
 
 
 
 
 
 
 
847
  do_action( 'bp_blogs_before_remove_post', $blog_id, $post_id, $user_id );
848
 
849
  // Delete activity stream item
850
+ bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->id, 'type' => 'new_blog_post' ) );
 
 
 
 
 
851
 
 
 
 
 
 
 
 
 
 
852
  do_action( 'bp_blogs_remove_post', $blog_id, $post_id, $user_id );
853
  }
854
  add_action( 'delete_post', 'bp_blogs_remove_post' );
885
  $activity = bp_activity_get( array(
886
  'in' => $activity_id,
887
  'display_comments' => 'stream',
 
888
  ) );
889
 
890
  // get all activity comment IDs for the pending deleted item
908
  }
909
  }
910
 
 
 
 
 
 
 
 
 
 
911
  do_action( 'bp_blogs_remove_comment', $wpdb->blogid, $comment_id, bp_loggedin_user_id() );
912
  }
913
  add_action( 'delete_comment', 'bp_blogs_remove_comment' );
915
  /**
916
  * Removes blog comments that are associated with activity comments.
917
  *
918
+ * @since BuddyPress (2.0.0)
919
  *
920
  * @see bp_blogs_remove_comment()
921
  * @see bp_blogs_sync_delete_from_activity_comment()
922
  *
923
  * @param array $activity_ids The activity IDs to check association with blog
924
+ * comments.
925
+ * @param bool $force_delete Whether to force delete the comments. If false,
926
+ * comments are trashed instead.
927
  */
928
  function bp_blogs_remove_associated_blog_comments( $activity_ids = array(), $force_delete = true ) {
929
  // query args
956
  /**
957
  * When a blog comment status transition occurs, update the relevant activity's status.
958
  *
959
+ * @since BuddyPress (1.6.0)
960
+ *
961
+ * @global object $bp BuddyPress global settings.
962
  *
963
  * @param string $new_status New comment status.
964
  * @param string $old_status Previous comment status.
965
+ * @param object $comment Comment data.
966
  */
967
  function bp_blogs_transition_activity_status( $new_status, $old_status, $comment ) {
968
+ global $bp;
969
 
970
  // Check the Activity component is active
971
  if ( ! bp_is_active( 'activity' ) )
994
 
995
  // Get the activity
996
  if ( bp_disable_blogforum_comments() ) {
997
+ $activity_id = bp_activity_get_activity_id( array( 'component' => $bp->blogs->id, 'item_id' => get_current_blog_id(), 'secondary_item_id' => $comment->comment_ID, 'type' => 'new_blog_comment', ) );
 
 
 
 
 
998
  } else {
999
  $activity_id = get_comment_meta( $comment->comment_ID, 'bp_activity_comment_id', true );
1000
  }
1039
  * @return int $count Total blog count.
1040
  */
1041
  function bp_blogs_total_blogs() {
1042
+ if ( !$count = wp_cache_get( 'bp_total_blogs', 'bp' ) ) {
 
 
1043
  $blogs = BP_Blogs_Blog::get_all();
1044
  $count = $blogs['total'];
1045
  wp_cache_set( 'bp_total_blogs', $count, 'bp' );
1050
  /**
1051
  * Get the total number of blogs being tracked by BP for a specific user.
1052
  *
 
 
1053
  * @param int $user_id ID of the user being queried. Default: on a user page,
1054
+ * the displayed user. Otherwise, the logged-in user.
 
1055
  * @return int $count Total blog count for the user.
1056
  */
1057
  function bp_blogs_total_blogs_for_user( $user_id = 0 ) {
 
 
 
1058
 
1059
+ if ( empty( $user_id ) )
1060
+ $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
 
 
1061
 
1062
+ if ( !$count = wp_cache_get( 'bp_total_blogs_for_user_' . $user_id, 'bp' ) ) {
 
1063
  $count = BP_Blogs_Blog::total_blog_count_for_user( $user_id );
1064
  wp_cache_set( 'bp_total_blogs_for_user_' . $user_id, $count, 'bp' );
1065
  }
1073
  * @param int $blog_id The ID of the blog to expunge.
1074
  */
1075
  function bp_blogs_remove_data_for_blog( $blog_id ) {
1076
+ global $bp;
1077
 
 
 
 
 
 
 
 
 
1078
  do_action( 'bp_blogs_before_remove_data_for_blog', $blog_id );
1079
 
1080
  // If this is regular blog, delete all data for that blog.
1081
  BP_Blogs_Blog::delete_blog_for_all( $blog_id );
1082
 
1083
  // Delete activity stream item
1084
+ bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->id, 'type' => false ) );
 
 
 
 
1085
 
 
 
 
 
 
 
 
 
1086
  do_action( 'bp_blogs_remove_data_for_blog', $blog_id );
1087
  }
1088
  add_action( 'delete_blog', 'bp_blogs_remove_data_for_blog', 1 );
1093
  * @see BP_Blogs_Blog::get_blogs_for_user() for a description of parameters
1094
  * and return values.
1095
  *
1096
+ * @param int $user_id See {@BP_Blogs_Blog::get_blogs_for_user()}.
1097
  * @param bool $show_hidden See {@BP_Blogs_Blog::get_blogs_for_user()}.
 
1098
  * @return array See {@BP_Blogs_Blog::get_blogs_for_user()}.
1099
  */
1100
  function bp_blogs_get_blogs_for_user( $user_id, $show_hidden = false ) {
1107
  * @see BP_Blogs_Blog::get_all() for a description of parameters and return values.
1108
  *
1109
  * @param int $limit See {@BP_Blogs_Blog::get_all()}.
1110
+ * @param int $page See {@BP_Blogs_Blog::get_all()}.
 
1111
  * @return array See {@BP_Blogs_Blog::get_all()}.
1112
  */
1113
  function bp_blogs_get_all_blogs( $limit = null, $page = null ) {
1120
  * @see BP_Blogs_Blog::get() for a description of parameters and return values.
1121
  *
1122
  * @param int $limit See {@BP_Blogs_Blog::get()}.
1123
+ * @param int $page See {@BP_Blogs_Blog::get()}.
 
1124
  * @return array See {@BP_Blogs_Blog::get()}.
1125
  */
1126
  function bp_blogs_get_random_blogs( $limit = null, $page = null ) {
1133
  * @see BP_Blogs_Blog::is_hidden() for a description of parameters and return values.
1134
  *
1135
  * @param int $blog_id See {@BP_Blogs_Blog::is_hidden()}.
 
1136
  * @return bool See {@BP_Blogs_Blog::is_hidden()}.
1137
  */
1138
  function bp_blogs_is_blog_hidden( $blog_id ) {
1149
  */
1150
 
1151
  /**
1152
+ * Delete a metadta from the DB for a blog.
1153
  *
1154
  * @global object $wpdb WordPress database access object.
1155
+ * @global object $bp BuddyPress global settings.
1156
+ *
1157
+ * @param int $blog_id ID of the blog whose metadata is being deleted.
1158
+ * @param string $meta_key Optional. The key of the metadata being deleted. If
1159
+ * omitted, all BP metadata associated with the blog will be deleted.
1160
+ * @param string $meta_value Optional. If present, the metadata will only be
1161
+ * deleted if the meta_value matches this parameter.
1162
+ * @param bool $delete_all Optional. If true, delete matching metadata entries
1163
+ * for all objects, ignoring the specified blog_id. Otherwise, only
1164
+ * delete matching metadata entries for the specified blog.
1165
+ * Default: false.
 
1166
  * @return bool True on success, false on failure.
1167
  */
1168
  function bp_blogs_delete_blogmeta( $blog_id, $meta_key = false, $meta_value = false, $delete_all = false ) {
1169
+ global $wpdb, $bp;
1170
 
1171
  // Legacy - if no meta_key is passed, delete all for the blog_id
1172
  if ( empty( $meta_key ) ) {
1191
  /**
1192
  * Get metadata for a given blog.
1193
  *
1194
+ * @since BuddyPress (1.2.0)
1195
  *
1196
  * @global object $wpdb WordPress database access object.
1197
+ * @global object $bp BuddyPress global settings.
1198
  *
1199
+ * @param int $blog_id ID of the blog whose metadata is being requested.
1200
  * @param string $meta_key Optional. If present, only the metadata matching
1201
+ * that meta key will be returned. Otherwise, all metadata for the
1202
+ * blog will be fetched.
1203
+ * @param bool $single Optional. If true, return only the first value of the
1204
+ * specified meta_key. This parameter has no effect if meta_key is not
1205
+ * specified. Default: true.
 
1206
  * @return mixed The meta value(s) being requested.
1207
  */
1208
  function bp_blogs_get_blogmeta( $blog_id, $meta_key = '', $single = true ) {
1217
  * Update a piece of blog meta.
1218
  *
1219
  * @global object $wpdb WordPress database access object.
1220
+ * @global object $bp BuddyPress global settings.
1221
+ *
1222
+ * @param int $blog_id ID of the blog whose metadata is being updated.
1223
+ * @param string $meta_key Key of the metadata being updated.
1224
+ * @param mixed $meta_value Value to be set.
1225
+ * @param mixed $prev_value Optional. If specified, only update existing
1226
+ * metadata entries with the specified value. Otherwise, update all
1227
+ * entries.
1228
  * @return bool|int Returns false on failure. On successful update of existing
1229
+ * metadata, returns true. On successful creation of new metadata,
1230
+ * returns the integer ID of the new metadata row.
1231
  */
1232
  function bp_blogs_update_blogmeta( $blog_id, $meta_key, $meta_value, $prev_value = '' ) {
1233
  add_filter( 'query', 'bp_filter_metaid_column_name' );
1240
  /**
1241
  * Add a piece of blog metadata.
1242
  *
1243
+ * @since BuddyPress (2.0.0)
 
 
 
 
 
 
 
1244
  *
1245
+ * @param int $blog_id ID of the blog.
1246
+ * @param string $meta_key Metadata key.
1247
+ * @param mixed $meta_value Metadata value.
1248
+ * @param bool $unique. Optional. Whether to enforce a single metadata value
1249
+ * for the given key. If true, and the object already has a value for
1250
+ * the key, no change will be made. Default: false.
1251
  * @return int|bool The meta ID on successful update, false on failure.
1252
  */
1253
  function bp_blogs_add_blogmeta( $blog_id, $meta_key, $meta_value, $unique = false ) {
1261
  * Remove all blog associations for a given user.
1262
  *
1263
  * @param int $user_id ID whose blog data should be removed.
 
1264
  * @return bool|null Returns false on failure.
1265
  */
1266
  function bp_blogs_remove_data( $user_id ) {
1267
  if ( !is_multisite() )
1268
  return false;
1269
 
 
 
 
 
 
 
 
1270
  do_action( 'bp_blogs_before_remove_data', $user_id );
1271
 
1272
  // If this is regular blog, delete all data for that blog.
1273
  BP_Blogs_Blog::delete_blogs_for_user( $user_id );
1274
 
 
 
 
 
 
 
 
1275
  do_action( 'bp_blogs_remove_data', $user_id );
1276
  }
1277
  add_action( 'wpmu_delete_user', 'bp_blogs_remove_data' );
1278
  add_action( 'delete_user', 'bp_blogs_remove_data' );
1279
  add_action( 'bp_make_spam_user', 'bp_blogs_remove_data' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-blogs/bp-blogs-loader.php CHANGED
@@ -1,33 +1,31 @@
1
  <?php
 
2
  /**
3
- * BuddyPress Blogs Loader
4
  *
5
- * The blogs component tracks posts and comments to member activity streams,
6
- * shows blogs the member can post to in their profiles, and caches useful
7
- * information from those blogs to make querying blogs in bulk more performant.
8
  *
9
  * @package BuddyPress
10
- * @subpackage BlogsCore
11
  */
12
 
13
  // Exit if accessed directly
14
- defined( 'ABSPATH' ) || exit;
15
 
16
  class BP_Blogs_Component extends BP_Component {
17
 
18
  /**
19
  * Start the blogs component creation process.
20
  *
21
- * @since 1.5.0
22
  */
23
  public function __construct() {
24
  parent::start(
25
  'blogs',
26
- __( 'Site Directory', 'buddypress' ),
27
  buddypress()->plugin_dir,
28
  array(
29
- 'adminbar_myaccount_order' => 30,
30
- 'search_query_arg' => 'sites_search',
31
  )
32
  );
33
  }
@@ -38,7 +36,7 @@ class BP_Blogs_Component extends BP_Component {
38
  * The BP_BLOGS_SLUG constant is deprecated, and only used here for
39
  * backwards compatibility.
40
  *
41
- * @since 1.5.0
42
  *
43
  * @see BP_Component::setup_globals() for description of parameters.
44
  *
@@ -47,9 +45,8 @@ class BP_Blogs_Component extends BP_Component {
47
  public function setup_globals( $args = array() ) {
48
  $bp = buddypress();
49
 
50
- if ( ! defined( 'BP_BLOGS_SLUG' ) ) {
51
  define ( 'BP_BLOGS_SLUG', $this->id );
52
- }
53
 
54
  // Global tables for messaging component
55
  $global_tables = array(
@@ -61,12 +58,12 @@ class BP_Blogs_Component extends BP_Component {
61
  'blog' => $bp->table_prefix . 'bp_user_blogs_blogmeta',
62
  );
63
 
64
- // All globals for blogs component.
 
65
  $args = array(
66
  'slug' => BP_BLOGS_SLUG,
67
  'root_slug' => isset( $bp->pages->blogs->slug ) ? $bp->pages->blogs->slug : BP_BLOGS_SLUG,
68
  'has_directory' => is_multisite(), // Non-multisite installs don't need a top-level Sites directory, since there's only one site
69
- 'directory_title' => _x( 'Sites', 'component directory title', 'buddypress' ),
70
  'notification_callback' => 'bp_blogs_format_notifications',
71
  'search_string' => __( 'Search sites...', 'buddypress' ),
72
  'autocomplete_all' => defined( 'BP_MESSAGES_AUTOCOMPLETE_ALL' ),
@@ -76,35 +73,6 @@ class BP_Blogs_Component extends BP_Component {
76
 
77
  // Setup the globals
78
  parent::setup_globals( $args );
79
-
80
- /*
81
- * Filters if a blog is public.
82
- *
83
- * In case the config is not multisite, the blog_public option is ignored.
84
- *
85
- * @since 2.3.0
86
- *
87
- * @oaram int $value Whether or not the blog is public.
88
- */
89
- if ( 0 !== apply_filters( 'bp_is_blog_public', (int) get_option( 'blog_public' ) ) || ! is_multisite() ) {
90
-
91
- /**
92
- * Filters the post types to track for the Blogs component.
93
- *
94
- * @since 1.5.0
95
- * @deprecated 2.3.0
96
- *
97
- * @param array $value Array of post types to track.
98
- */
99
- $post_types = apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) );
100
-
101
- foreach ( $post_types as $post_type ) {
102
- add_post_type_support( $post_type, 'buddypress-activity' );
103
- }
104
- }
105
-
106
- // Filter the generic track parameters for the 'post' post type.
107
- add_filter( 'bp_activity_get_post_type_tracking_args', array( $this, 'post_tracking_args' ), 10, 2 );
108
  }
109
 
110
  /**
@@ -115,7 +83,6 @@ class BP_Blogs_Component extends BP_Component {
115
  * @param array $includes See {@link BP_Component::includes()}.
116
  */
117
  public function includes( $includes = array() ) {
118
-
119
  // Files to include
120
  $includes = array(
121
  'cache',
@@ -126,11 +93,11 @@ class BP_Blogs_Component extends BP_Component {
126
  'filters',
127
  'activity',
128
  'functions',
 
129
  );
130
 
131
- if ( is_multisite() ) {
132
  $includes[] = 'widgets';
133
- }
134
 
135
  // Include the files
136
  parent::includes( $includes );
@@ -142,20 +109,30 @@ class BP_Blogs_Component extends BP_Component {
142
  * @see BP_Component::setup_nav() for a description of arguments.
143
  *
144
  * @param array $main_nav Optional. See BP_Component::setup_nav() for
145
- * description.
146
- * @param array $sub_nav Optional. See BP_Component::setup_nav() for
147
- * description.
148
  */
149
  public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
 
150
 
151
  /**
152
  * Blog/post/comment menus should not appear on single WordPress setups.
153
  * Although comments and posts made by users will still show on their
154
  * activity stream.
155
  */
156
- if ( ! is_multisite() ) {
157
  return false;
158
- }
 
 
 
 
 
 
 
 
 
159
 
160
  // Determine user to use
161
  if ( bp_displayed_user_domain() ) {
@@ -166,27 +143,13 @@ class BP_Blogs_Component extends BP_Component {
166
  return;
167
  }
168
 
169
- $slug = bp_get_blogs_slug();
170
- $parent_url = trailingslashit( $user_domain . $slug );
171
-
172
- // Add 'Sites' to the main navigation
173
- $count = (int) bp_get_total_blog_count_for_user();
174
- $class = ( 0 === $count ) ? 'no-count' : 'count';
175
- $nav_text = sprintf( __( 'Sites <span class="%s">%s</span>', 'buddypress' ), esc_attr( $class ), bp_core_number_format( $count ) );
176
- $main_nav = array(
177
- 'name' => $nav_text,
178
- 'slug' => $slug,
179
- 'position' => 30,
180
- 'screen_function' => 'bp_blogs_screen_my_blogs',
181
- 'default_subnav_slug' => 'my-sites',
182
- 'item_css_id' => $this->id
183
- );
184
 
185
  $sub_nav[] = array(
186
  'name' => __( 'My Sites', 'buddypress' ),
187
  'slug' => 'my-sites',
188
  'parent_url' => $parent_url,
189
- 'parent_slug' => $slug,
190
  'screen_function' => 'bp_blogs_screen_my_blogs',
191
  'position' => 10
192
  );
@@ -198,38 +161,35 @@ class BP_Blogs_Component extends BP_Component {
198
  /**
199
  * Set up bp-blogs integration with the WordPress admin bar.
200
  *
201
- * @since 1.5.0
202
  *
203
  * @see BP_Component::setup_admin_bar() for a description of arguments.
204
  *
205
  * @param array $wp_admin_nav See BP_Component::setup_admin_bar()
206
- * for description.
207
- *
208
- * @return bool
209
  */
210
  public function setup_admin_bar( $wp_admin_nav = array() ) {
 
211
 
212
  /**
213
  * Site/post/comment menus should not appear on single WordPress setups.
214
- *
215
- * Comments and posts made by users will still show in their activity.
216
  */
217
- if ( ! is_multisite() ) {
218
  return false;
219
- }
220
 
221
  // Menus for logged in user
222
  if ( is_user_logged_in() ) {
223
 
224
- // Setup the logged in user variables
225
- $blogs_link = trailingslashit( bp_loggedin_user_domain() . bp_get_blogs_slug() );
226
 
227
  // Add the "Sites" sub menu
228
  $wp_admin_nav[] = array(
229
- 'parent' => buddypress()->my_account_menu_id,
230
  'id' => 'my-account-' . $this->id,
231
  'title' => __( 'Sites', 'buddypress' ),
232
- 'href' => $blogs_link
233
  );
234
 
235
  // My Sites
@@ -237,7 +197,7 @@ class BP_Blogs_Component extends BP_Component {
237
  'parent' => 'my-account-' . $this->id,
238
  'id' => 'my-account-' . $this->id . '-my-sites',
239
  'title' => __( 'My Sites', 'buddypress' ),
240
- 'href' => $blogs_link
241
  );
242
 
243
  // Create a Site
@@ -258,11 +218,10 @@ class BP_Blogs_Component extends BP_Component {
258
  * Set up the title for pages and <title>
259
  */
260
  public function setup_title() {
 
261
 
262
  // Set up the component options navigation for Site
263
  if ( bp_is_blogs_component() ) {
264
- $bp = buddypress();
265
-
266
  if ( bp_is_my_profile() ) {
267
  if ( bp_is_active( 'xprofile' ) ) {
268
  $bp->bp_options_title = __( 'My Sites', 'buddypress' );
@@ -282,66 +241,6 @@ class BP_Blogs_Component extends BP_Component {
282
 
283
  parent::setup_title();
284
  }
285
-
286
- /**
287
- * Setup cache groups
288
- *
289
- * @since 2.2.0
290
- */
291
- public function setup_cache_groups() {
292
-
293
- // Global groups
294
- wp_cache_add_global_groups( array(
295
- 'blog_meta'
296
- ) );
297
-
298
- parent::setup_cache_groups();
299
- }
300
-
301
- /**
302
- * Set up the tracking arguments for the 'post' post type.
303
- *
304
- * @since 2.2.0
305
- *
306
- * @see bp_activity_get_post_type_tracking_args() for information on parameters.
307
- *
308
- * @param object|null $params
309
- * @param string|int $post_type
310
- *
311
- * @return object
312
- */
313
- public function post_tracking_args( $params = null, $post_type = 0 ) {
314
-
315
- /**
316
- * Filters the post types to track for the Blogs component.
317
- *
318
- * @since 1.5.0
319
- * @deprecated 2.3.0
320
- *
321
- * Make sure plugins still using 'bp_blogs_record_post_post_types'
322
- * to track their post types will generate new_blog_post activities
323
- * See https://buddypress.trac.wordpress.org/ticket/6306
324
- *
325
- * @param array $value Array of post types to track.
326
- */
327
- $post_types = apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) );
328
- $post_types_array = array_flip( $post_types );
329
-
330
- if ( ! isset( $post_types_array[ $post_type ] ) ) {
331
- return $params;
332
- }
333
-
334
- // Set specific params for the 'post' post type.
335
- $params->component_id = $this->id;
336
- $params->action_id = 'new_blog_post';
337
- $params->admin_filter = __( 'New post published', 'buddypress' );
338
- $params->format_callback = 'bp_blogs_format_activity_action_new_blog_post';
339
- $params->front_filter = __( 'Posts', 'buddypress' );
340
- $params->contexts = array( 'activity', 'member' );
341
- $params->position = 5;
342
-
343
- return $params;
344
- }
345
  }
346
 
347
  /**
1
  <?php
2
+
3
  /**
4
+ * BuddyPress Blogs Streams Loader
5
  *
6
+ * An blogs stream component, for users, groups, and blog tracking.
 
 
7
  *
8
  * @package BuddyPress
9
+ * @subpackage Blogs Core
10
  */
11
 
12
  // Exit if accessed directly
13
+ if ( !defined( 'ABSPATH' ) ) exit;
14
 
15
  class BP_Blogs_Component extends BP_Component {
16
 
17
  /**
18
  * Start the blogs component creation process.
19
  *
20
+ * @since BuddyPress (1.5.0)
21
  */
22
  public function __construct() {
23
  parent::start(
24
  'blogs',
25
+ __( 'Site Tracking', 'buddypress' ),
26
  buddypress()->plugin_dir,
27
  array(
28
+ 'adminbar_myaccount_order' => 30
 
29
  )
30
  );
31
  }
36
  * The BP_BLOGS_SLUG constant is deprecated, and only used here for
37
  * backwards compatibility.
38
  *
39
+ * @since BuddyPress (1.5.0)
40
  *
41
  * @see BP_Component::setup_globals() for description of parameters.
42
  *
45
  public function setup_globals( $args = array() ) {
46
  $bp = buddypress();
47
 
48
+ if ( !defined( 'BP_BLOGS_SLUG' ) )
49
  define ( 'BP_BLOGS_SLUG', $this->id );
 
50
 
51
  // Global tables for messaging component
52
  $global_tables = array(
58
  'blog' => $bp->table_prefix . 'bp_user_blogs_blogmeta',
59
  );
60
 
61
+ // All globals for messaging component.
62
+ // Note that global_tables is included in this array.
63
  $args = array(
64
  'slug' => BP_BLOGS_SLUG,
65
  'root_slug' => isset( $bp->pages->blogs->slug ) ? $bp->pages->blogs->slug : BP_BLOGS_SLUG,
66
  'has_directory' => is_multisite(), // Non-multisite installs don't need a top-level Sites directory, since there's only one site
 
67
  'notification_callback' => 'bp_blogs_format_notifications',
68
  'search_string' => __( 'Search sites...', 'buddypress' ),
69
  'autocomplete_all' => defined( 'BP_MESSAGES_AUTOCOMPLETE_ALL' ),
73
 
74
  // Setup the globals
75
  parent::setup_globals( $args );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  }
77
 
78
  /**
83
  * @param array $includes See {@link BP_Component::includes()}.
84
  */
85
  public function includes( $includes = array() ) {
 
86
  // Files to include
87
  $includes = array(
88
  'cache',
93
  'filters',
94
  'activity',
95
  'functions',
96
+ 'buddybar'
97
  );
98
 
99
+ if ( is_multisite() )
100
  $includes[] = 'widgets';
 
101
 
102
  // Include the files
103
  parent::includes( $includes );
109
  * @see BP_Component::setup_nav() for a description of arguments.
110
  *
111
  * @param array $main_nav Optional. See BP_Component::setup_nav() for
112
+ * description.
113
+ * @param array $sub_nav Optional. See BP_Component::setup_nav() for
114
+ * description.
115
  */
116
  public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
117
+ $bp = buddypress();
118
 
119
  /**
120
  * Blog/post/comment menus should not appear on single WordPress setups.
121
  * Although comments and posts made by users will still show on their
122
  * activity stream.
123
  */
124
+ if ( !is_multisite() )
125
  return false;
126
+
127
+ // Add 'Sites' to the main navigation
128
+ $main_nav = array(
129
+ 'name' => sprintf( __( 'Sites <span>%d</span>', 'buddypress' ), bp_blogs_total_blogs_for_user() ),
130
+ 'slug' => $this->slug,
131
+ 'position' => 30,
132
+ 'screen_function' => 'bp_blogs_screen_my_blogs',
133
+ 'default_subnav_slug' => 'my-sites',
134
+ 'item_css_id' => $this->id
135
+ );
136
 
137
  // Determine user to use
138
  if ( bp_displayed_user_domain() ) {
143
  return;
144
  }
145
 
146
+ $parent_url = trailingslashit( $user_domain . bp_get_blogs_slug() );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
 
148
  $sub_nav[] = array(
149
  'name' => __( 'My Sites', 'buddypress' ),
150
  'slug' => 'my-sites',
151
  'parent_url' => $parent_url,
152
+ 'parent_slug' => $bp->blogs->slug,
153
  'screen_function' => 'bp_blogs_screen_my_blogs',
154
  'position' => 10
155
  );
161
  /**
162
  * Set up bp-blogs integration with the WordPress admin bar.
163
  *
164
+ * @since BuddyPress (1.5.0)
165
  *
166
  * @see BP_Component::setup_admin_bar() for a description of arguments.
167
  *
168
  * @param array $wp_admin_nav See BP_Component::setup_admin_bar()
169
+ * for description.
 
 
170
  */
171
  public function setup_admin_bar( $wp_admin_nav = array() ) {
172
+ $bp = buddypress();
173
 
174
  /**
175
  * Site/post/comment menus should not appear on single WordPress setups.
176
+ * Although comments and posts made by users will still show on their
177
+ * activity stream.
178
  */
179
+ if ( !is_multisite() )
180
  return false;
 
181
 
182
  // Menus for logged in user
183
  if ( is_user_logged_in() ) {
184
 
185
+ $blogs_link = trailingslashit( bp_loggedin_user_domain() . $this->slug );
 
186
 
187
  // Add the "Sites" sub menu
188
  $wp_admin_nav[] = array(
189
+ 'parent' => $bp->my_account_menu_id,
190
  'id' => 'my-account-' . $this->id,
191
  'title' => __( 'Sites', 'buddypress' ),
192
+ 'href' => trailingslashit( $blogs_link )
193
  );
194
 
195
  // My Sites
197
  'parent' => 'my-account-' . $this->id,
198
  'id' => 'my-account-' . $this->id . '-my-sites',
199
  'title' => __( 'My Sites', 'buddypress' ),
200
+ 'href' => trailingslashit( $blogs_link )
201
  );
202
 
203
  // Create a Site
218
  * Set up the title for pages and <title>
219
  */
220
  public function setup_title() {
221
+ $bp = buddypress();
222
 
223
  // Set up the component options navigation for Site
224
  if ( bp_is_blogs_component() ) {
 
 
225
  if ( bp_is_my_profile() ) {
226
  if ( bp_is_active( 'xprofile' ) ) {
227
  $bp->bp_options_title = __( 'My Sites', 'buddypress' );
241
 
242
  parent::setup_title();
243
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
  }
245
 
246
  /**
bp-blogs/bp-blogs-screens.php CHANGED
@@ -1,13 +1,14 @@
1
  <?php
 
2
  /**
3
- * BuddyPress Blogs Screens.
4
  *
5
  * @package BuddyPress
6
  * @subpackage BlogsScreens
7
  */
8
 
9
  // Exit if accessed directly
10
- defined( 'ABSPATH' ) || exit;
11
 
12
  /**
13
  * Load the "My Blogs" screen.
@@ -16,11 +17,6 @@ function bp_blogs_screen_my_blogs() {
16
  if ( !is_multisite() )
17
  return false;
18
 
19
- /**
20
- * Fires right before the loading of the My Blogs screen template file.
21
- *
22
- * @since 1.0.0
23
- */
24
  do_action( 'bp_blogs_screen_my_blogs' );
25
 
26
  bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'members/single/home' ) );
@@ -37,11 +33,6 @@ function bp_blogs_screen_create_a_blog() {
37
  if ( !is_user_logged_in() || !bp_blog_signup_enabled() )
38
  return false;
39
 
40
- /**
41
- * Fires right before the loading of the Create A Blog screen template file.
42
- *
43
- * @since 1.0.0
44
- */
45
  do_action( 'bp_blogs_screen_create_a_blog' );
46
 
47
  bp_core_load_template( apply_filters( 'bp_blogs_template_create_a_blog', 'blogs/create' ) );
@@ -55,11 +46,6 @@ function bp_blogs_screen_index() {
55
  if ( bp_is_blogs_directory() ) {
56
  bp_update_is_directory( true, 'blogs' );
57
 
58
- /**
59
- * Fires right before the loading of the top-level Blogs screen template file.
60
- *
61
- * @since 1.0.0
62
- */
63
  do_action( 'bp_blogs_screen_index' );
64
 
65
  bp_core_load_template( apply_filters( 'bp_blogs_screen_index', 'blogs/index' ) );
@@ -67,31 +53,31 @@ function bp_blogs_screen_index() {
67
  }
68
  add_action( 'bp_screens', 'bp_blogs_screen_index', 2 );
69
 
70
- /** Theme Compatibility *******************************************************/
71
 
72
  /**
73
- * The main theme compat class for BuddyPress Blogs.
74
  *
75
- * This class sets up the necessary theme compatibility actions to safely output
76
  * group template parts to the_title and the_content areas of a theme.
77
  *
78
- * @since 1.7.0
79
  */
80
  class BP_Blogs_Theme_Compat {
81
 
82
  /**
83
  * Set up theme compatibility for the Blogs component.
84
  *
85
- * @since 1.7.0
86
  */
87
  public function __construct() {
88
  add_action( 'bp_setup_theme_compat', array( $this, 'is_blogs' ) );
89
  }
90
 
91
  /**
92
- * Are we looking at something that needs Blogs theme compatibility?
93
  *
94
- * @since 1.7.0
95
  */
96
  public function is_blogs() {
97
 
@@ -107,12 +93,6 @@ class BP_Blogs_Theme_Compat {
107
  if ( is_multisite() && ! bp_current_action() ) {
108
  bp_update_is_directory( true, 'blogs' );
109
 
110
- /**
111
- * Fires if in the blog directory and BuddyPress needs Blog theme compatibility,
112
- * before the actions and filters are added.
113
- *
114
- * @since 1.5.0
115
- */
116
  do_action( 'bp_blogs_screen_index' );
117
 
118
  add_filter( 'bp_get_buddypress_template', array( $this, 'directory_template_hierarchy' ) );
@@ -135,21 +115,14 @@ class BP_Blogs_Theme_Compat {
135
  * This is to mirror how WordPress has
136
  * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
137
  *
138
- * @since 1.8.0
139
- *
140
- * @param string $templates The templates from bp_get_theme_compat_templates().
141
  *
 
 
142
  * @return array $templates Array of custom templates to look for.
143
  */
144
  public function directory_template_hierarchy( $templates ) {
145
-
146
- /**
147
- * Filters the custom templates used for theme compat with the blog directory page.
148
- *
149
- * @since 1.8.0
150
- *
151
- * @param array $value Array of template paths to add to template list to look for.
152
- */
153
  $new_templates = apply_filters( 'bp_template_hierarchy_blogs_create', array(
154
  'blogs/index-directory.php'
155
  ) );
@@ -164,17 +137,19 @@ class BP_Blogs_Theme_Compat {
164
  /**
165
  * Update the global $post with directory data.
166
  *
167
- * @since 1.7.0
168
  */
169
  public function directory_dummy_post() {
170
 
 
 
171
  bp_theme_compat_reset_post( array(
172
  'ID' => 0,
173
- 'post_title' => __( 'Sites', 'buddypress' ),
174
  'post_author' => 0,
175
  'post_date' => 0,
176
  'post_content' => '',
177
- 'post_type' => 'page',
178
  'post_status' => 'publish',
179
  'is_page' => true,
180
  'comment_status' => 'closed'
@@ -184,7 +159,7 @@ class BP_Blogs_Theme_Compat {
184
  /**
185
  * Filter the_content with the groups index template part.
186
  *
187
- * @since 1.7.0
188
  */
189
  public function directory_content() {
190
  return bp_buffer_template_part( 'blogs/index', null, false );
@@ -198,21 +173,14 @@ class BP_Blogs_Theme_Compat {
198
  * This is to mirror how WordPress has
199
  * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
200
  *
201
- * @since 1.8.0
202
- *
203
- * @param string $templates The templates from bp_get_theme_compat_templates().
204
  *
 
 
205
  * @return array $templates Array of custom templates to look for.
206
  */
207
  public function create_template_hierarchy( $templates ) {
208
-
209
- /**
210
- * Filters the custom templates used for theme compat with the blog create page.
211
- *
212
- * @since 1.8.0
213
- *
214
- * @param array $value Array of template paths to add to template list to look for.
215
- */
216
  $new_templates = apply_filters( 'bp_template_hierarchy_blogs_create', array(
217
  'blogs/index-create.php'
218
  ) );
@@ -227,13 +195,13 @@ class BP_Blogs_Theme_Compat {
227
  /**
228
  * Update the global $post with create screen data.
229
  *
230
- * @since 1.7.0
231
  */
232
  public function create_dummy_post() {
233
 
234
  // Title based on ability to create blogs
235
  if ( is_user_logged_in() && bp_blog_signup_enabled() ) {
236
- $title = __( 'Create a Site', 'buddypress' );
237
  } else {
238
  $title = __( 'Sites', 'buddypress' );
239
  }
@@ -244,7 +212,7 @@ class BP_Blogs_Theme_Compat {
244
  'post_author' => 0,
245
  'post_date' => 0,
246
  'post_content' => '',
247
- 'post_type' => 'page',
248
  'post_status' => 'publish',
249
  'is_page' => true,
250
  'comment_status' => 'closed'
@@ -254,7 +222,7 @@ class BP_Blogs_Theme_Compat {
254
  /**
255
  * Filter the_content with the create screen template part.
256
  *
257
- * @since 1.7.0
258
  */
259
  public function create_content() {
260
  return bp_buffer_template_part( 'blogs/create', null, false );
1
  <?php
2
+
3
  /**
4
+ * BuddyPress Blogs Screens
5
  *
6
  * @package BuddyPress
7
  * @subpackage BlogsScreens
8
  */
9
 
10
  // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
 
13
  /**
14
  * Load the "My Blogs" screen.
17
  if ( !is_multisite() )
18
  return false;
19
 
 
 
 
 
 
20
  do_action( 'bp_blogs_screen_my_blogs' );
21
 
22
  bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'members/single/home' ) );
33
  if ( !is_user_logged_in() || !bp_blog_signup_enabled() )
34
  return false;
35
 
 
 
 
 
 
36
  do_action( 'bp_blogs_screen_create_a_blog' );
37
 
38
  bp_core_load_template( apply_filters( 'bp_blogs_template_create_a_blog', 'blogs/create' ) );
46
  if ( bp_is_blogs_directory() ) {
47
  bp_update_is_directory( true, 'blogs' );
48
 
 
 
 
 
 
49
  do_action( 'bp_blogs_screen_index' );
50
 
51
  bp_core_load_template( apply_filters( 'bp_blogs_screen_index', 'blogs/index' ) );
53
  }
54
  add_action( 'bp_screens', 'bp_blogs_screen_index', 2 );
55
 
56
+ /** Theme Compatability *******************************************************/
57
 
58
  /**
59
+ * The main theme compat class for BuddyPress Blogs
60
  *
61
+ * This class sets up the necessary theme compatability actions to safely output
62
  * group template parts to the_title and the_content areas of a theme.
63
  *
64
+ * @since BuddyPress (1.7.0)
65
  */
66
  class BP_Blogs_Theme_Compat {
67
 
68
  /**
69
  * Set up theme compatibility for the Blogs component.
70
  *
71
+ * @since BuddyPress (1.7.0)
72
  */
73
  public function __construct() {
74
  add_action( 'bp_setup_theme_compat', array( $this, 'is_blogs' ) );
75
  }
76
 
77
  /**
78
+ * Are we looking at something that needs Blogs theme compatability?
79
  *
80
+ * @since BuddyPress (1.7.0)
81
  */
82
  public function is_blogs() {
83
 
93
  if ( is_multisite() && ! bp_current_action() ) {
94
  bp_update_is_directory( true, 'blogs' );
95
 
 
 
 
 
 
 
96
  do_action( 'bp_blogs_screen_index' );
97
 
98
  add_filter( 'bp_get_buddypress_template', array( $this, 'directory_template_hierarchy' ) );
115
  * This is to mirror how WordPress has
116
  * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
117
  *
118
+ * @since BuddyPress (1.8.0)
 
 
119
  *
120
+ * @param string $templates The templates from
121
+ * bp_get_theme_compat_templates().
122
  * @return array $templates Array of custom templates to look for.
123
  */
124
  public function directory_template_hierarchy( $templates ) {
125
+ // Setup our templates based on priority
 
 
 
 
 
 
 
126
  $new_templates = apply_filters( 'bp_template_hierarchy_blogs_create', array(
127
  'blogs/index-directory.php'
128
  ) );
137
  /**
138
  * Update the global $post with directory data.
139
  *
140
+ * @since BuddyPress (1.7.0)
141
  */
142
  public function directory_dummy_post() {
143
 
144
+ $title = apply_filters( 'bp_blogs_directory_header', __( 'Sites', 'buddypress' ) );
145
+
146
  bp_theme_compat_reset_post( array(
147
  'ID' => 0,
148
+ 'post_title' => $title,
149
  'post_author' => 0,
150
  'post_date' => 0,
151
  'post_content' => '',
152
+ 'post_type' => 'bp_blogs',
153
  'post_status' => 'publish',
154
  'is_page' => true,
155
  'comment_status' => 'closed'
159
  /**
160
  * Filter the_content with the groups index template part.
161
  *
162
+ * @since BuddyPress (1.7.0)
163
  */
164
  public function directory_content() {
165
  return bp_buffer_template_part( 'blogs/index', null, false );
173
  * This is to mirror how WordPress has
174
  * {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
175
  *
176
+ * @since BuddyPress (1.8.0)
 
 
177
  *
178
+ * @param string $templates The templates from
179
+ * bp_get_theme_compat_templates().
180
  * @return array $templates Array of custom templates to look for.
181
  */
182
  public function create_template_hierarchy( $templates ) {
183
+ // Setup our templates based on priority
 
 
 
 
 
 
 
184
  $new_templates = apply_filters( 'bp_template_hierarchy_blogs_create', array(
185
  'blogs/index-create.php'
186
  ) );
195
  /**
196
  * Update the global $post with create screen data.
197
  *
198
+ * @since BuddyPress (1.7.0)
199
  */
200
  public function create_dummy_post() {
201
 
202
  // Title based on ability to create blogs
203
  if ( is_user_logged_in() && bp_blog_signup_enabled() ) {
204
+ $title = '<a class="button bp-title-button" href="' . trailingslashit( bp_get_root_domain() . '/' . bp_get_blogs_root_slug() ) . '">' . __( 'Sites', 'buddypress' ) . '</a>&nbsp;' . __( 'Create a Site', 'buddypress' );
205
  } else {
206
  $title = __( 'Sites', 'buddypress' );
207
  }
212
  'post_author' => 0,
213
  'post_date' => 0,
214
  'post_content' => '',
215
+ 'post_type' => 'bp_group',
216
  'post_status' => 'publish',
217
  'is_page' => true,
218
  'comment_status' => 'closed'
222
  /**
223
  * Filter the_content with the create screen template part.
224
  *
225
+ * @since BuddyPress (1.7.0)
226
  */
227
  public function create_content() {
228
  return bp_buffer_template_part( 'blogs/create', null, false );
bp-blogs/bp-blogs-template.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  /**
3
  * BuddyPress Blogs Template Tags.
4
  *
@@ -6,13 +7,13 @@
6
  * @subpackage BlogsTemplate
7
  */
8
 
9
- // Exit if accessed directly.
10
- defined( 'ABSPATH' ) || exit;
11
 
12
  /**
13
  * Output the blogs component slug.
14
  *
15
- * @since 1.5.0
16
  *
17
  * @uses bp_get_blogs_slug()
18
  */
@@ -22,26 +23,18 @@ function bp_blogs_slug() {
22
  /**
23
  * Return the blogs component slug.
24
  *
25
- * @since 1.5.0
26
  *
27
  * @return string The 'blogs' slug.
28
  */
29
  function bp_get_blogs_slug() {
30
-
31
- /**
32
- * Filters the blogs component slug.
33
- *
34
- * @since 1.5.0
35
- *
36
- * @param string $slug Slug for the blogs component.
37
- */
38
  return apply_filters( 'bp_get_blogs_slug', buddypress()->blogs->slug );
39
  }
40
 
41
  /**
42
  * Output the blogs component root slug.
43
  *
44
- * @since 1.5.0
45
  *
46
  * @uses bp_get_blogs_root_slug()
47
  */
@@ -51,53 +44,36 @@ function bp_blogs_root_slug() {
51
  /**
52
  * Return the blogs component root slug.
53
  *
54
- * @since 1.5.0
55
  *
56
  * @return string The 'blogs' root slug.
57
  */
58
  function bp_get_blogs_root_slug() {
59
-
60
- /**
61
- * Filters the blogs component root slug.
62
- *
63
- * @since 1.5.0
64
- *
65
- * @param string $root_slug Root slug for the blogs component.
66
- */
67
  return apply_filters( 'bp_get_blogs_root_slug', buddypress()->blogs->root_slug );
68
  }
69
 
70
  /**
71
  * Output blog directory permalink.
72
  *
73
- * @since 1.5.0
74
  *
75
  * @uses bp_get_blogs_directory_permalink()
76
  */
77
  function bp_blogs_directory_permalink() {
78
- echo esc_url( bp_get_blogs_directory_permalink() );
79
  }
80
  /**
81
  * Return blog directory permalink.
82
  *
83
- * @since 1.5.0
84
  *
85
  * @uses apply_filters()
86
  * @uses trailingslashit()
87
  * @uses bp_get_root_domain()
88
  * @uses bp_get_blogs_root_slug()
89
- *
90
  * @return string The URL of the Blogs directory.
91
  */
92
  function bp_get_blogs_directory_permalink() {
93
-
94
- /**
95
- * Filters the blog directory permalink.
96
- *
97
- * @since 1.5.0
98
- *
99
- * @param string $value Permalink URL for the blog directory.
100
- */
101
  return apply_filters( 'bp_get_blogs_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_blogs_root_slug() ) );
102
  }
103
 
@@ -111,94 +87,99 @@ class BP_Blogs_Template {
111
  /**
112
  * The loop iterator.
113
  *
 
114
  * @var int
115
  */
116
- public $current_blog = -1;
117
 
118
  /**
119
  * The number of blogs returned by the paged query.
120
  *
 
121
  * @var int
122
  */
123
- public $blog_count = 0;
124
 
125
  /**
126
  * Array of blogs located by the query..
127
  *
 
128
  * @var array
129
  */
130
- public $blogs = array();
131
 
132
  /**
133
  * The blog object currently being iterated on.
134
  *
 
135
  * @var object
136
  */
137
- public $blog;
138
 
139
  /**
140
  * A flag for whether the loop is currently being iterated.
141
  *
 
142
  * @var bool
143
  */
144
- public $in_the_loop = false;
145
 
146
  /**
147
  * The page number being requested.
148
  *
149
- * @var int
 
150
  */
151
- public $pag_page = 1;
152
 
153
  /**
154
  * The number of items being requested per page.
155
  *
156
- * @var int
 
157
  */
158
- public $pag_num = 20;
159
 
160
  /**
161
  * An HTML string containing pagination links.
162
  *
 
163
  * @var string
164
  */
165
- public $pag_links = '';
166
 
167
  /**
168
  * The total number of blogs matching the query parameters.
169
  *
 
170
  * @var int
171
  */
172
- public $total_blog_count = 0;
173
 
174
  /**
175
  * Constructor method.
176
  *
177
  * @see BP_Blogs_Blog::get() for a description of parameters.
178
  *
179
- * @param string $type See {@link BP_Blogs_Blog::get()}.
180
- * @param string $page See {@link BP_Blogs_Blog::get()}.
181
- * @param string $per_page See {@link BP_Blogs_Blog::get()}.
182
- * @param string $max See {@link BP_Blogs_Blog::get()}.
183
- * @param string $user_id See {@link BP_Blogs_Blog::get()}.
184
- * @param string $search_terms See {@link BP_Blogs_Blog::get()}.
185
- * @param string $page_arg The string used as a query parameter in
186
- * pagination links. Default: 'bpage'.
187
- * @param bool $update_meta_cache Whether to pre-fetch metadata for
188
- * queried blogs.
189
- * @param array|bool $include_blog_ids Array of blog IDs to include.
190
  */
191
- public function __construct( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg = 'bpage', $update_meta_cache = true, $include_blog_ids = false ) {
192
 
193
- $this->pag_arg = sanitize_key( $page_arg );
194
- $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $page );
195
- $this->pag_num = bp_sanitize_pagination_arg( 'num', $per_page );
196
 
197
- // Backwards compatibility support for blogs by first letter
198
- if ( ! empty( $_REQUEST['letter'] ) ) {
199
  $this->blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page );
200
-
201
- // Typical blogs query
202
  } else {
203
  $this->blogs = bp_blogs_get_blogs( array(
204
  'type' => $type,
@@ -211,37 +192,32 @@ class BP_Blogs_Template {
211
  ) );
212
  }
213
 
214
- // Set the total blog count
215
- if ( empty( $max ) || ( $max >= (int) $this->blogs['total'] ) ) {
216
  $this->total_blog_count = (int) $this->blogs['total'];
217
- } else {
218
  $this->total_blog_count = (int) $max;
219
- }
220
 
221
- // Set the blogs array (to loop through later
222
  $this->blogs = $this->blogs['blogs'];
223
 
224
- // Get the current blog count to compare maximum against
225
- $blog_count = count( $this->blogs );
226
-
227
- // Set the current blog count
228
- if ( empty( $max ) || ( $max >= (int) $blog_count ) ) {
229
- $this->blog_count = (int) $blog_count;
230
  } else {
231
- $this->blog_count = (int) $max;
232
  }
233
 
234
- // Build pagination links based on total blogs and current page number
235
- if ( ! empty( $this->total_blog_count ) && ! empty( $this->pag_num ) ) {
236
  $this->pag_links = paginate_links( array(
237
- 'base' => add_query_arg( $this->pag_arg, '%#%' ),
238
  'format' => '',
239
  'total' => ceil( (int) $this->total_blog_count / (int) $this->pag_num ),
240
  'current' => (int) $this->pag_page,
241
  'prev_text' => _x( '&larr;', 'Blog pagination previous text', 'buddypress' ),
242
- 'next_text' => _x( '&rarr;', 'Blog pagination next text', 'buddypress' ),
243
- 'mid_size' => 1,
244
- 'add_args' => array(),
245
  ) );
246
  }
247
  }
@@ -253,8 +229,11 @@ class BP_Blogs_Template {
253
  *
254
  * @return bool True if there are items in the loop, otherwise false.
255
  */
256
- public function has_blogs() {
257
- return (bool) ! empty( $this->blog_count );
 
 
 
258
  }
259
 
260
  /**
@@ -262,9 +241,9 @@ class BP_Blogs_Template {
262
  *
263
  * @return object The next blog to iterate over.
264
  */
265
- public function next_blog() {
266
  $this->current_blog++;
267
- $this->blog = $this->blogs[ $this->current_blog ];
268
 
269
  return $this->blog;
270
  }
@@ -272,7 +251,7 @@ class BP_Blogs_Template {
272
  /**
273
  * Rewind the blogs and reset blog index.
274
  */
275
- public function rewind_blogs() {
276
  $this->current_blog = -1;
277
  if ( $this->blog_count > 0 ) {
278
  $this->blog = $this->blogs[0];
@@ -290,17 +269,11 @@ class BP_Blogs_Template {
290
  *
291
  * @return bool True if there are more blogs to show, otherwise false.
292
  */
293
- public function blogs() {
294
- if ( ( $this->current_blog + 1 ) < $this->blog_count ) {
295
  return true;
296
- } elseif ( ( $this->current_blog + 1 ) === $this->blog_count ) {
297
-
298
- /**
299
- * Fires right before the rewinding of blogs listing after all are shown.
300
- *
301
- * @since 1.5.0
302
- */
303
- do_action( 'blog_loop_end' );
304
  // Do some cleaning up after the loop
305
  $this->rewind_blogs();
306
  }
@@ -318,21 +291,13 @@ class BP_Blogs_Template {
318
  *
319
  * @see bp_the_blog()
320
  */
321
- public function the_blog() {
322
 
323
  $this->in_the_loop = true;
324
  $this->blog = $this->next_blog();
325
 
326
- // loop has just started
327
- if ( 0 === $this->current_blog ) {
328
-
329
- /**
330
- * Fires if on the first blog in the loop.
331
- *
332
- * @since 1.5.0
333
- */
334
- do_action( 'blog_loop_start' );
335
- }
336
  }
337
  }
338
 
@@ -354,7 +319,7 @@ function bp_rewind_blogs() {
354
  *
355
  * @global object $blogs_template {@link BP_Blogs_Template}
356
  *
357
- * @param array|string $args {
358
  * Arguments for limiting the contents of the blogs loop. Most arguments
359
  * are in the same format as {@link BP_Blogs_Blog::get()}. However, because
360
  * the format of the arguments accepted here differs in a number of ways,
@@ -364,68 +329,72 @@ function bp_rewind_blogs() {
364
  * Arguments can be passed as an associative array, or as a URL query
365
  * string (eg, 'user_id=4&per_page=3').
366
  *
367
- * @type int $page Which page of results to fetch. Using page=1 without
368
- * per_page will result in no pagination. Default: 1.
369
- * @type int|bool $per_page Number of results per page. Default: 20.
370
- * @type string $page_arg The string used as a query parameter in
371
- * pagination links. Default: 'bpage'.
372
- * @type int|bool $max Maximum number of results to return.
373
- * Default: false (unlimited).
374
- * @type string $type The order in which results should be fetched.
375
- * 'active', 'alphabetical', 'newest', or 'random'.
376
- * @type array $include_blog_ids Array of blog IDs to limit results to.
377
- * @type string $sort 'ASC' or 'DESC'. Default: 'DESC'.
378
- * @type string $search_terms Limit results by a search term. Default: the value of `$_REQUEST['s']` or
379
- * `$_REQUEST['sites_search']`, if present.
380
- * @type int $user_id The ID of the user whose blogs should be retrieved.
381
- * When viewing a user profile page, 'user_id' defaults to the
382
- * ID of the displayed user. Otherwise the default is false.
383
  * }
384
  * @return bool Returns true when blogs are found, otherwise false.
385
  */
386
  function bp_has_blogs( $args = '' ) {
387
  global $blogs_template;
388
 
389
- // Check for and use search terms.
390
- $search_terms_default = false;
391
- $search_query_arg = bp_core_get_component_search_query_arg( 'blogs' );
392
- if ( ! empty( $_REQUEST[ $search_query_arg ] ) ) {
393
- $search_terms_default = stripslashes( $_REQUEST[ $search_query_arg ] );
394
- } elseif ( ! empty( $_REQUEST['s'] ) ) {
395
- $search_terms_default = stripslashes( $_REQUEST['s'] );
396
- }
397
 
398
- // Parse arguments
399
- $r = bp_parse_args( $args, array(
400
- 'type' => 'active',
401
- 'page_arg' => 'bpage', // See https://buddypress.trac.wordpress.org/ticket/3679
 
 
402
  'page' => 1,
403
  'per_page' => 20,
404
  'max' => false,
405
- 'user_id' => bp_displayed_user_id(), // Pass a user_id to limit to only blogs this user is a member of
406
- 'include_blog_ids' => false,
407
- 'search_terms' => $search_terms_default,
408
- 'update_meta_cache' => true
409
- ), 'has_blogs' );
410
 
411
- // Set per_page to maximum if max is enforced
412
- if ( ! empty( $r['max'] ) && ( (int) $r['per_page'] > (int) $r['max'] ) ) {
413
- $r['per_page'] = (int) $r['max'];
 
 
 
 
 
 
 
 
 
 
 
 
 
414
  }
415
 
416
- // Get the blogs
417
- $blogs_template = new BP_Blogs_Template( $r['type'], $r['page'], $r['per_page'], $r['max'], $r['user_id'], $r['search_terms'], $r['page_arg'], $r['update_meta_cache'], $r['include_blog_ids'] );
 
 
 
418
 
419
- /**
420
- * Filters whether or not there are blogs to list.
421
- *
422
- * @since 1.1.0
423
- *
424
- * @param bool $value Whether or not there are blogs to list.
425
- * @param BP_Blogs_Template $blogs_template Current blogs template object.
426
- * @param array $r Parsed arguments used in blogs template query.
427
- */
428
- return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), $blogs_template, $r );
429
  }
430
 
431
  /**
@@ -467,13 +436,7 @@ function bp_blogs_pagination_count() {
467
  $to_num = bp_core_number_format( ( $start_num + ( $blogs_template->pag_num - 1 ) > $blogs_template->total_blog_count ) ? $blogs_template->total_blog_count : $start_num + ( $blogs_template->pag_num - 1 ) );
468
  $total = bp_core_number_format( $blogs_template->total_blog_count );
469
 
470
- if ( 1 == $blogs_template->total_blog_count ) {
471
- $message = __( 'Viewing 1 site', 'buddypress' );
472
- } else {
473
- $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s site', 'Viewing %1$s - %2$s of %3$s sites', $blogs_template->total_blog_count, 'buddypress' ), $from_num, $to_num, $total );
474
- }
475
-
476
- echo $message;
477
  }
478
 
479
  /**
@@ -492,13 +455,6 @@ function bp_blogs_pagination_links() {
492
  function bp_get_blogs_pagination_links() {
493
  global $blogs_template;
494
 
495
- /**
496
- * Filters the blogs pagination links.
497
- *
498
- * @since 1.0.0
499
- *
500
- * @param string $pag_links HTML pagination links.
501
- */
502
  return apply_filters( 'bp_get_blogs_pagination_links', $blogs_template->pag_links );
503
  }
504
 
@@ -507,7 +463,7 @@ function bp_blogs_pagination_links() {
507
  *
508
  * @see bp_get_blog_avatar() for description of arguments.
509
  *
510
- * @param array|string $args See {@link bp_get_blog_avatar()}.
511
  */
512
  function bp_blog_avatar( $args = '' ) {
513
  echo bp_get_blog_avatar( $args );
@@ -518,62 +474,39 @@ function bp_blog_avatar( $args = '' ) {
518
  * At the moment, blog avatars are simply the user avatars of the blog
519
  * admin. Filter 'bp_get_blog_avatar_' . $blog_id to customize.
520
  *
521
- * @since 2.4.0 Introduced `$title` argument.
522
- *
523
  * @see bp_core_fetch_avatar() For a description of arguments and
524
  * return values.
525
  *
526
- * @param array|string $args {
527
  * Arguments are listed here with an explanation of their defaults.
528
  * For more information about the arguments, see
529
  * {@link bp_core_fetch_avatar()}.
530
- * @type string $alt Default: 'Profile picture of site author [user name]'.
531
- * @type string $class Default: 'avatar'.
532
- * @type string $title Default: 'Profile picture of site author [user name]'.
533
- * @type string $type Default: 'full'.
534
- * @type int|bool $width Default: false.
535
- * @type int|bool $height Default: false.
536
- * @type bool $id Currently unused.
537
- * @type bool $no_grav Default: true.
538
  * }
539
  * @return string User avatar string.
540
  */
541
  function bp_get_blog_avatar( $args = '' ) {
542
  global $blogs_template;
543
 
544
- // Bail if avatars are turned off
545
- // @todo Should we maybe still filter this?
546
- if ( ! buddypress()->avatar->show_avatars ) {
547
- return false;
548
- }
549
-
550
- $author_displayname = bp_core_get_user_displayname( $blogs_template->blog->admin_user_id );
551
-
552
- // Parse the arguments
553
- $r = bp_parse_args( $args, array(
554
  'type' => 'full',
555
  'width' => false,
556
  'height' => false,
557
  'class' => 'avatar',
558
- 'title' => sprintf( __( 'Profile picture of site author %s', 'buddypress' ), esc_attr( $author_displayname ) ),
559
  'id' => false,
560
- 'alt' => sprintf( __( 'Profile picture of site author %s', 'buddypress' ), esc_attr( $author_displayname ) ),
561
- 'no_grav' => true,
562
- ) );
563
-
564
- // Fetch the avatar
565
- $avatar = bp_core_fetch_avatar( array(
566
- 'item_id' => $blogs_template->blog->admin_user_id,
567
- 'title' => $r['title'],
568
- //'avatar_dir' => 'blog-avatars',
569
- //'object' => 'blog',
570
- 'type' => $r['type'],
571
- 'alt' => $r['alt'],
572
- 'css_id' => $r['id'],
573
- 'class' => $r['class'],
574
- 'width' => $r['width'],
575
- 'height' => $r['height']
576
- ) );
577
 
578
  /***
579
  * In future BuddyPress versions you will be able to set the avatar for a blog.
@@ -583,19 +516,9 @@ function bp_blog_avatar( $args = '' ) {
583
  * This filter is deprecated as of BuddyPress 1.5 and may be removed in a future version.
584
  * Use the 'bp_get_blog_avatar' filter instead.
585
  */
586
- $avatar = apply_filters( 'bp_get_blog_avatar_' . $blogs_template->blog->blog_id, $avatar );
587
 
588
- /**
589
- * Filters a blog's avatar.
590
- *
591
- * @since 1.5.0
592
- *
593
- * @param string $avatar Formatted HTML <img> element, or raw avatar
594
- * URL based on $html arg.
595
- * @param int $blog_id ID of the blog whose avatar is being displayed.
596
- * @param array $r Array of arguments used when fetching avatar.
597
- */
598
- return apply_filters( 'bp_get_blog_avatar', $avatar, $blogs_template->blog->blog_id, $r );
599
  }
600
 
601
  function bp_blog_permalink() {
@@ -614,13 +537,6 @@ function bp_blog_permalink() {
614
  $permalink = $protocol . $blogs_template->blog->domain . $blogs_template->blog->path;
615
  }
616
 
617
- /**
618
- * Filters the blog permalink.
619
- *
620
- * @since 1.0.0
621
- *
622
- * @param string $permalink Permalink URL for the blog.
623
- */
624
  return apply_filters( 'bp_get_blog_permalink', $permalink );
625
  }
626
 
@@ -638,20 +554,13 @@ function bp_blog_name() {
638
  function bp_get_blog_name() {
639
  global $blogs_template;
640
 
641
- /**
642
- * Filters the name of the current blog in the loop.
643
- *
644
- * @since 1.2.0
645
- *
646
- * @param string $name Name of the current blog in the loop.
647
- */
648
  return apply_filters( 'bp_get_blog_name', $blogs_template->blog->name );
649
  }
650
 
651
  /**
652
  * Output the ID of the current blog in the loop.
653
  *
654
- * @since 1.7.0
655
  */
656
  function bp_blog_id() {
657
  echo bp_get_blog_id();
@@ -659,20 +568,13 @@ function bp_blog_id() {
659
  /**
660
  * Return the ID of the current blog in the loop.
661
  *
662
- * @since 1.7.0
663
  *
664
  * @return int ID of the current blog in the loop.
665
  */
666
  function bp_get_blog_id() {
667
  global $blogs_template;
668
 
669
- /**
670
- * Filters the ID of the current blog in the loop.
671
- *
672
- * @since 1.7.0
673
- *
674
- * @param int $blog_id ID of the current blog in the loop.
675
- */
676
  return apply_filters( 'bp_get_blog_id', $blogs_template->blog->blog_id );
677
  }
678
 
@@ -680,14 +582,6 @@ function bp_blog_id() {
680
  * Output the description of the current blog in the loop.
681
  */
682
  function bp_blog_description() {
683
-
684
- /**
685
- * Filters the description of the current blog in the loop.
686
- *
687
- * @since 1.2.0
688
- *
689
- * @param string $value Description of the current blog in the loop.
690
- */
691
  echo apply_filters( 'bp_blog_description', bp_get_blog_description() );
692
  }
693
  /**
@@ -698,179 +592,88 @@ function bp_blog_description() {
698
  function bp_get_blog_description() {
699
  global $blogs_template;
700
 
701
- /**
702
- * Filters the description of the current blog in the loop.
703
- *
704
- * @since 1.0.0
705
- *
706
- * @param string $value Description of the current blog in the loop.
707
- */
708
  return apply_filters( 'bp_get_blog_description', $blogs_template->blog->description );
709
  }
710
 
711
  /**
712
  * Output the row class of the current blog in the loop.
713
  *
714
- * @since 1.7.0
715
- *
716
- * @param array $classes Array of custom classes
717
  */
718
- function bp_blog_class( $classes = array() ) {
719
- echo bp_get_blog_class( $classes );
720
  }
721
  /**
722
  * Return the row class of the current blog in the loop.
723
  *
724
- * @since 1.7.0
725
  *
726
  * @global BP_Blogs_Template $blogs_template
727
- * @param array $classes Array of custom classes
728
  *
729
  * @return string Row class of the site.
730
  */
731
- function bp_get_blog_class( $classes = array() ) {
732
  global $blogs_template;
733
 
734
- // Add even/odd classes, but only if there's more than 1 group
735
- if ( $blogs_template->blog_count > 1 ) {
736
- $pos_in_loop = (int) $blogs_template->current_blog;
737
- $classes[] = ( $pos_in_loop % 2 ) ? 'even' : 'odd';
738
 
739
- // If we've only one site in the loop, don't bother with odd and even
740
- } else {
 
 
741
  $classes[] = 'bp-single-blog';
742
- }
743
 
744
- /**
745
- * Filters the row class of the current blog in the loop.
746
- *
747
- * @since 1.7.0
748
- *
749
- * @param array $classes Array of classes to be applied to row.
750
- */
751
  $classes = apply_filters( 'bp_get_blog_class', $classes );
752
  $classes = array_merge( $classes, array() );
753
- $retval = 'class="' . join( ' ', $classes ) . '"';
754
 
 
755
  return $retval;
756
  }
757
 
758
  /**
759
  * Output the last active date of the current blog in the loop.
760
- *
761
- * @param array $args See {@link bp_get_blog_last_active()}.
762
  */
763
- function bp_blog_last_active( $args = array() ) {
764
- echo bp_get_blog_last_active( $args );
765
  }
766
  /**
767
  * Return the last active date of the current blog in the loop.
768
  *
769
- * @param array $args {
770
- * Array of optional arguments.
771
- * @type bool $active_format If true, formatted "Active 5 minutes ago".
772
- * If false, formatted "5 minutes ago".
773
- * Default: true.
774
- * }
775
  * @return string Last active date.
776
  */
777
- function bp_get_blog_last_active( $args = array() ) {
778
  global $blogs_template;
779
 
780
- // Parse the activity format
781
- $r = bp_parse_args( $args, array(
782
- 'active_format' => true
783
- ) );
784
-
785
- // Backwards compatibility for anyone forcing a 'true' active_format
786
- if ( true === $r['active_format'] ) {
787
- $r['active_format'] = __( 'active %s', 'buddypress' );
788
- }
789
-
790
- // Blog has been posted to at least once
791
- if ( isset( $blogs_template->blog->last_activity ) ) {
792
-
793
- // Backwards compatibility for pre 1.5 'ago' strings
794
- $last_activity = ! empty( $r['active_format'] )
795
- ? bp_core_get_last_activity( $blogs_template->blog->last_activity, $r['active_format'] )
796
- : bp_core_time_since( $blogs_template->blog->last_activity );
797
-
798
- // Blog has never been posted to
799
- } else {
800
- $last_activity = __( 'Never active', 'buddypress' );
801
- }
802
-
803
- /**
804
- * Filters the last active date of the current blog in the loop.
805
- *
806
- * @since
807
- *
808
- * @param string $last_activity Last active date.
809
- * @param array $r Array of parsed args used to determine formatting.
810
- */
811
- return apply_filters( 'bp_blog_last_active', $last_activity, $r );
812
  }
813
 
814
  /**
815
  * Output the latest post from the current blog in the loop.
816
- *
817
- * @param array $args See {@link bp_get_blog_latest_post()}.
818
  */
819
- function bp_blog_latest_post( $args = array() ) {
820
- echo bp_get_blog_latest_post( $args );
821
  }
822
  /**
823
  * Return the latest post from the current blog in the loop.
824
  *
825
- * @param array $args {
826
- * Array of optional arguments.
827
- * @type bool $latest_format If true, formatted "Latest post: [link to post]".
828
- * If false, formatted "[link to post]".
829
- * Default: true.
830
- * }
831
  * @return string $retval String of the form 'Latest Post: [link to post]'.
832
  */
833
- function bp_get_blog_latest_post( $args = array() ) {
834
  global $blogs_template;
835
 
836
- $r = wp_parse_args( $args, array(
837
- 'latest_format' => true,
838
- ) );
839
-
840
  $retval = bp_get_blog_latest_post_title();
841
 
842
- if ( ! empty( $retval ) ) {
843
- if ( ! empty( $r['latest_format'] ) ) {
844
-
845
- /**
846
- * Filters the title text of the latest post for the current blog in loop.
847
- *
848
- * @since 1.0.0
849
- *
850
- * @param string $retval Title of the latest post.
851
- */
852
- $retval = sprintf( __( 'Latest Post: %s', 'buddypress' ), '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval ) . '</a>' );
853
- } else {
854
-
855
- /** This filter is documented in bp-blogs/bp-blogs-template.php */
856
- $retval = '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval ) . '</a>';
857
- }
858
- }
859
 
860
- /**
861
- * Filters the HTML markup result for the latest blog post in loop.
862
- *
863
- * @since 1.2.0
864
- *
865
- * @param string $retval HTML markup for the latest post.
866
- */
867
  return apply_filters( 'bp_get_blog_latest_post', $retval );
868
  }
869
 
870
  /**
871
  * Output the title of the latest post on the current blog in the loop.
872
  *
873
- * @since 1.7.0
874
  *
875
  * @see bp_get_blog_latest_post_title()
876
  */
@@ -880,7 +683,7 @@ function bp_blog_latest_post_title() {
880
  /**
881
  * Return the title of the latest post on the current blog in the loop.
882
  *
883
- * @since 1.7.0
884
  *
885
  * @global BP_Blogs_Template
886
  *
@@ -894,30 +697,23 @@ function bp_blog_latest_post_title() {
894
  if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->post_title ) )
895
  $retval = $blogs_template->blog->latest_post->post_title;
896
 
897
- /**
898
- * Filters the title text of the latest post on the current blog in the loop.
899
- *
900
- * @since 1.7.0
901
- *
902
- * @param string $retval Title text for the latest post.
903
- */
904
  return apply_filters( 'bp_get_blog_latest_post_title', $retval );
905
  }
906
 
907
  /**
908
  * Output the permalink of the latest post on the current blog in the loop.
909
  *
910
- * @since 1.7.0
911
  *
912
  * @see bp_get_blog_latest_post_title()
913
  */
914
  function bp_blog_latest_post_permalink() {
915
- echo esc_url( bp_get_blog_latest_post_permalink() );
916
  }
917
  /**
918
  * Return the permalink of the latest post on the current blog in the loop.
919
  *
920
- * @since 1.7.0
921
  *
922
  * @global BP_Blogs_Template
923
  *
@@ -931,20 +727,13 @@ function bp_blog_latest_post_permalink() {
931
  if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->ID ) )
932
  $retval = add_query_arg( 'p', $blogs_template->blog->latest_post->ID, bp_get_blog_permalink() );
933
 
934
- /**
935
- * Filters the permalink of the latest post on the current blog in the loop.
936
- *
937
- * @since 1.7.0
938
- *
939
- * @param string $retval Permalink URL of the latest post.
940
- */
941
  return apply_filters( 'bp_get_blog_latest_post_permalink', $retval );
942
  }
943
 
944
  /**
945
  * Output the content of the latest post on the current blog in the loop.
946
  *
947
- * @since 1.7.0
948
  *
949
  * @uses bp_get_blog_latest_post_content()
950
  */
@@ -954,7 +743,7 @@ function bp_blog_latest_post_content() {
954
  /**
955
  * Return the content of the latest post on the current blog in the loop.
956
  *
957
- * @since 1.7.0
958
  *
959
  * @global BP_Blogs_Template
960
  *
@@ -968,20 +757,13 @@ function bp_blog_latest_post_content() {
968
  if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->post_content ) )
969
  $retval = $blogs_template->blog->latest_post->post_content;
970
 
971
- /**
972
- * Filters the content of the latest post on the current blog in the loop.
973
- *
974
- * @since 1.7.0
975
- *
976
- * @param string $retval Content of the latest post on the current blog in the loop.
977
- */
978
  return apply_filters( 'bp_get_blog_latest_post_content', $retval );
979
  }
980
 
981
  /**
982
  * Output the featured image of the latest post on the current blog in the loop.
983
  *
984
- * @since 1.7.0
985
  *
986
  * @see bp_get_blog_latest_post_content() For description of parameters.
987
  *
@@ -993,13 +775,12 @@ function bp_blog_latest_post_featured_image( $size = 'thumbnail' ) {
993
  /**
994
  * Return the featured image of the latest post on the current blog in the loop.
995
  *
996
- * @since 1.7.0
997
  *
998
  * @global BP_Blogs_Template
999
  *
1000
  * @param string $size Image version to return. 'thumbnail', 'medium',
1001
- * 'large', or 'post-thumbnail'. Default: 'thumbnail'.
1002
- *
1003
  * @return string URL of the image.
1004
  */
1005
  function bp_get_blog_latest_post_featured_image( $size = 'thumbnail' ) {
@@ -1010,39 +791,22 @@ function bp_blog_latest_post_featured_image( $size = 'thumbnail' ) {
1010
  if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->images[$size] ) )
1011
  $retval = $blogs_template->blog->latest_post->images[$size];
1012
 
1013
- /**
1014
- * Filters the featured image of the latest post on the current blog in the loop.
1015
- *
1016
- * @since 1.7.0
1017
- *
1018
- * @param string $retval The featured image of the latest post on the current blog in the loop.
1019
- */
1020
  return apply_filters( 'bp_get_blog_latest_post_featured_image', $retval );
1021
  }
1022
 
1023
  /**
1024
  * Does the latest blog post have a featured image?
1025
  *
1026
- * @since 1.7.0
1027
- *
1028
- * @param string $thumbnail Image version to return. 'thumbnail', 'medium', 'large',
1029
- * or 'post-thumbnail'. Default: 'thumbnail'.
1030
  *
 
 
1031
  * @return bool True if the latest blog post from the current blog has a
1032
- * featured image of the given size.
1033
  */
1034
  function bp_blog_latest_post_has_featured_image( $thumbnail = 'thumbnail' ) {
1035
  $image = bp_get_blog_latest_post_featured_image( $thumbnail );
1036
 
1037
- /**
1038
- * Filters whether or not the latest blog post has a featured image.
1039
- *
1040
- * @since 1.7.0
1041
- *
1042
- * @param bool $value Whether or not the latest blog post has a featured image.
1043
- * @param string $thumbnail Image version to return.
1044
- * @param string $image Returned value from bp_get_blog_latest_post_featured_image.
1045
- */
1046
  return apply_filters( 'bp_blog_latest_post_has_featured_image', ! empty( $image ), $thumbnail, $image );
1047
  }
1048
 
@@ -1076,14 +840,6 @@ function bp_total_blog_count() {
1076
  * @return int Total number of blogs.
1077
  */
1078
  function bp_get_total_blog_count() {
1079
-
1080
- /**
1081
- * Filters the total number of blogs on the site.
1082
- *
1083
- * @since 1.2.0
1084
- *
1085
- * @param int $value Total number of blogs on the site.
1086
- */
1087
  return apply_filters( 'bp_get_total_blog_count', bp_blogs_total_blogs() );
1088
  }
1089
  add_filter( 'bp_get_total_blog_count', 'bp_core_number_format' );
@@ -1100,18 +856,9 @@ function bp_total_blog_count_for_user( $user_id = 0 ) {
1100
  * Return the total number of blogs for a given user.
1101
  *
1102
  * @param int $user_id ID of the user.
1103
- *
1104
  * @return int Total number of blogs for the user.
1105
  */
1106
  function bp_get_total_blog_count_for_user( $user_id = 0 ) {
1107
-
1108
- /**
1109
- * Filters the total number of blogs for a given user.
1110
- *
1111
- * @since 1.2.0
1112
- *
1113
- * @param int $value Total number of blogs for a given user.
1114
- */
1115
  return apply_filters( 'bp_get_total_blog_count_for_user', bp_blogs_total_blogs_for_user( $user_id ) );
1116
  }
1117
  add_filter( 'bp_get_total_blog_count_for_user', 'bp_core_number_format' );
@@ -1128,19 +875,10 @@ function bp_total_blog_count_for_user( $user_id = 0 ) {
1128
  * @return bool True if blog registration is enabled.
1129
  */
1130
  function bp_blog_signup_enabled() {
1131
- $bp = buddypress();
1132
 
1133
- $active_signup = isset( $bp->site_options['registration'] )
1134
- ? $bp->site_options['registration']
1135
- : 'all';
1136
 
1137
- /**
1138
- * Filters whether or not blog creation is enabled.
1139
- *
1140
- * @since 1.0.0
1141
- *
1142
- * @param string $active_signup Value of the registration site option creation status.
1143
- */
1144
  $active_signup = apply_filters( 'wpmu_active_signup', $active_signup ); // return "all", "none", "blog" or "user"
1145
 
1146
  if ( 'none' == $active_signup || 'user' == $active_signup )
@@ -1152,10 +890,10 @@ function bp_blog_signup_enabled() {
1152
  /**
1153
  * Output the wrapper markup for the blog signup form.
1154
  *
1155
- * @param string $blogname Optional. The default blog name (path or domain).
1156
- * @param string $blog_title Optional. The default blog title.
1157
- * @param string|WP_Error $errors Optional. The WP_Error object returned by a previous
1158
- * submission attempt.
1159
  */
1160
  function bp_show_blog_signup_form($blogname = '', $blog_title = '', $errors = '') {
1161
  global $current_user;
@@ -1167,24 +905,14 @@ function bp_show_blog_signup_form($blogname = '', $blog_title = '', $errors = ''
1167
  $errors = new WP_Error();
1168
  }
1169
 
1170
- /**
1171
- * Filters the default values for Blog name, title, and any current errors.
1172
- *
1173
- * @since 1.0.0
1174
- *
1175
- * @param array $value {
1176
- * string $blogname Default blog name provided.
1177
- * string $blog_title Default blog title provided.
1178
- * WP_Error $errors WP_Error object.
1179
- * }
1180
- */
1181
  $filtered_results = apply_filters('signup_another_blog_init', array('blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors ));
1182
  $blogname = $filtered_results['blogname'];
1183
  $blog_title = $filtered_results['blog_title'];
1184
  $errors = $filtered_results['errors'];
1185
 
1186
  if ( $errors->get_error_code() ) {
1187
- echo "<p>" . __('There was a problem; please correct the form below and try again.', 'buddypress') . "</p>";
1188
  }
1189
  ?>
1190
  <p><?php printf(__("By filling out the form below, you can <strong>add a site to your account</strong>. There is no limit to the number of sites that you can have, so create to your heart's content, but blog responsibly!", 'buddypress'), $current_user->display_name) ?></p>
@@ -1194,14 +922,7 @@ function bp_show_blog_signup_form($blogname = '', $blog_title = '', $errors = ''
1194
  <form class="standard-form" id="setupform" method="post" action="">
1195
 
1196
  <input type="hidden" name="stage" value="gimmeanotherblog" />
1197
- <?php
1198
-
1199
- /**
1200
- * Fires after the default hidden fields in blog signup form markup.
1201
- *
1202
- * @since 1.0.0
1203
- */
1204
- do_action( 'signup_hidden_fields' ); ?>
1205
 
1206
  <?php bp_blogs_signup_blog($blogname, $blog_title, $errors); ?>
1207
  <p>
@@ -1217,10 +938,10 @@ function bp_show_blog_signup_form($blogname = '', $blog_title = '', $errors = ''
1217
  /**
1218
  * Output the input fields for the blog creation form.
1219
  *
1220
- * @param string $blogname Optional. The default blog name (path or domain).
1221
- * @param string $blog_title Optional. The default blog title.
1222
- * @param string|WP_Error $errors Optional. The WP_Error object returned by a previous
1223
- * submission attempt.
1224
  */
1225
  function bp_blogs_signup_blog( $blogname = '', $blog_title = '', $errors = '' ) {
1226
  global $current_site;
@@ -1240,7 +961,7 @@ function bp_blogs_signup_blog( $blogname = '', $blog_title = '', $errors = '' )
1240
  if ( !is_subdomain_install() )
1241
  echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span> <input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="63" /><br />';
1242
  else
1243
- echo '<input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="63" ' . bp_get_form_field_attributes( 'blogname' ) . '/> <span class="suffix_address">.' . bp_blogs_get_subdomain_base() . '</span><br />';
1244
 
1245
  if ( !is_user_logged_in() ) {
1246
  print '(<strong>' . __( 'Your address will be ' , 'buddypress');
@@ -1282,16 +1003,29 @@ function bp_blogs_signup_blog( $blogname = '', $blog_title = '', $errors = '' )
1282
  </p>
1283
 
1284
  <?php
 
 
1285
 
 
 
 
 
 
 
 
 
1286
  /**
1287
- * Fires at the end of all of the default input fields for blog creation form.
1288
  *
1289
- * @since 1.0.0
1290
  *
1291
- * @param WP_Error $errors WP_Error object if any present.
1292
  */
1293
- do_action('signup_blogform', $errors);
1294
- }
 
 
 
1295
 
1296
  /**
1297
  * Process a blog registration submission.
@@ -1323,17 +1057,6 @@ function bp_blogs_validate_blog_signup() {
1323
  $public = (int) $_POST['blog_public'];
1324
 
1325
  $meta = apply_filters( 'signup_create_blog_meta', array( 'lang_id' => 1, 'public' => $public ) ); // depreciated
1326
-
1327
- /**
1328
- * Filters the default values for Blog meta.
1329
- *
1330
- * @since 1.0.0
1331
- *
1332
- * @param array $meta {
1333
- * string $value Default blog language ID.
1334
- * string $public Default public status.
1335
- * }
1336
- */
1337
  $meta = apply_filters( 'add_signup_meta', $meta );
1338
 
1339
  // If this is a subdomain install, set up the site inside the root domain.
@@ -1363,12 +1086,12 @@ function bp_blogs_validate_blog_form() {
1363
  /**
1364
  * Display a message after successful blog registration.
1365
  *
1366
- * @param string $domain The new blog's domain.
1367
- * @param string $path The new blog's path.
1368
- * @param string $blog_title The new blog's title.
1369
- * @param string $user_name The user name of the user who created the blog. Unused.
1370
- * @param string $user_email The email of the user who created the blog. Unused.
1371
- * @param string|array $meta Meta values associated with the new blog. Unused.
1372
  */
1373
  function bp_blogs_confirm_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = '' ) {
1374
  $protocol = is_ssl() ? 'https://' : 'http://';
@@ -1380,36 +1103,15 @@ function bp_blogs_confirm_blog_signup( $domain, $path, $blog_title, $user_name,
1380
  </p>
1381
 
1382
  <?php
1383
-
1384
- /**
1385
- * Fires after the default successful blog registration message markup.
1386
- *
1387
- * @since 1.0.0
1388
- */
1389
  do_action('signup_finished');
1390
  }
1391
 
1392
  /**
1393
  * Output a "Create a Site" link for users viewing their own profiles.
1394
- *
1395
- * This function is not used by BuddyPress as of 1.2, but is kept here for older
1396
- * themes that may still be using it.
1397
  */
1398
  function bp_create_blog_link() {
1399
-
1400
- // Don't show this link when not on your own profile
1401
- if ( ! bp_is_my_profile() ) {
1402
- return;
1403
- }
1404
-
1405
- /**
1406
- * Filters "Create a Site" links for users viewing their own profiles.
1407
- *
1408
- * @since 1.0.0
1409
- *
1410
- * @param string $value HTML link for creating a site.
1411
- */
1412
- echo apply_filters( 'bp_create_blog_link', '<a href="' . trailingslashit( bp_get_blogs_directory_permalink() . 'create' ) . '">' . __( 'Create a Site', 'buddypress' ) . '</a>' );
1413
  }
1414
 
1415
  /**
@@ -1420,9 +1122,10 @@ function bp_create_blog_link() {
1420
  function bp_blogs_blog_tabs() {
1421
 
1422
  // Don't show these tabs on a user's own profile
1423
- if ( bp_is_my_profile() ) {
1424
  return false;
1425
- } ?>
 
1426
 
1427
  <ul class="content-header-nav">
1428
  <li<?php if ( bp_is_current_action( 'my-blogs' ) || !bp_current_action() ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_blogs_slug() . '/my-blogs' ); ?>"><?php printf( __( "%s's Sites", 'buddypress' ), bp_get_displayed_user_fullname() ); ?></a></li>
@@ -1431,12 +1134,6 @@ function bp_blogs_blog_tabs() {
1431
  </ul>
1432
 
1433
  <?php
1434
-
1435
- /**
1436
- * Fires after the markup for the navigation tabs for a user Blogs page.
1437
- *
1438
- * @since 1.0.0
1439
- */
1440
  do_action( 'bp_blogs_blog_tabs' );
1441
  }
1442
 
@@ -1444,34 +1141,21 @@ function bp_blogs_blog_tabs() {
1444
  * Output the blog directory search form.
1445
  */
1446
  function bp_directory_blogs_search_form() {
1447
-
1448
- $query_arg = bp_core_get_component_search_query_arg( 'blogs' );
1449
-
1450
- if ( ! empty( $_REQUEST[ $query_arg ] ) ) {
1451
- $search_value = stripslashes( $_REQUEST[ $query_arg ] );
1452
- } else {
1453
- $search_value = bp_get_search_default_text( 'blogs' );
1454
- }
1455
 
1456
  $search_form_html = '<form action="" method="get" id="search-blogs-form">
1457
- <label for="blogs_search"><input type="text" name="' . esc_attr( $query_arg ) . '" id="blogs_search" placeholder="'. esc_attr( $search_value ) .'" /></label>
1458
  <input type="submit" id="blogs_search_submit" name="blogs_search_submit" value="' . __( 'Search', 'buddypress' ) . '" />
1459
  </form>';
1460
 
1461
- /**
1462
- * Filters the output for the blog directory search form.
1463
- *
1464
- * @since 1.9.0
1465
- *
1466
- * @param string $search_form_html HTML markup for blog directory search form.
1467
- */
1468
  echo apply_filters( 'bp_directory_blogs_search_form', $search_form_html );
1469
  }
1470
 
1471
  /**
1472
  * Output the Create a Site button.
1473
  *
1474
- * @since 2.0.0
1475
  */
1476
  function bp_blog_create_button() {
1477
  echo bp_get_blog_create_button();
@@ -1479,7 +1163,7 @@ function bp_blog_create_button() {
1479
  /**
1480
  * Get the Create a Site button.
1481
  *
1482
- * @since 2.0.0
1483
  *
1484
  * @return string
1485
  */
@@ -1497,83 +1181,20 @@ function bp_blog_create_button() {
1497
  'component' => 'blogs',
1498
  'link_text' => __( 'Create a Site', 'buddypress' ),
1499
  'link_title' => __( 'Create a Site', 'buddypress' ),
1500
- 'link_class' => 'blog-create no-ajax',
1501
- 'link_href' => trailingslashit( bp_get_blogs_directory_permalink() . 'create' ),
1502
  'wrapper' => false,
1503
- 'block_self' => false,
1504
  );
1505
 
1506
- /**
1507
- * Filters the Create a Site button.
1508
- *
1509
- * @since 2.0.0
1510
- *
1511
- * @param array $button_args Array of arguments to be used for the Create a Site button.
1512
- */
1513
  return bp_get_button( apply_filters( 'bp_get_blog_create_button', $button_args ) );
1514
  }
1515
 
1516
- /**
1517
- * Output the Create a Site nav item.
1518
- *
1519
- * @since 2.2.0
1520
- */
1521
- function bp_blog_create_nav_item() {
1522
- echo bp_get_blog_create_nav_item();
1523
- }
1524
-
1525
- /**
1526
- * Get the Create a Site nav item.
1527
- *
1528
- * @since 2.2.0
1529
- *
1530
- * @return string
1531
- */
1532
- function bp_get_blog_create_nav_item() {
1533
- // Get the create a site button
1534
- $create_blog_button = bp_get_blog_create_button();
1535
-
1536
- // Make sure the button is available
1537
- if ( empty( $create_blog_button ) ) {
1538
- return;
1539
- }
1540
-
1541
- $output = '<li id="blog-create-nav">' . $create_blog_button . '</li>';
1542
-
1543
- return apply_filters( 'bp_get_blog_create_nav_item', $output );
1544
- }
1545
-
1546
- /**
1547
- * Checks if a specific theme is still filtering the Blogs directory title
1548
- * if so, transform the title button into a Blogs directory nav item.
1549
- *
1550
- * @since 2.2.0
1551
- *
1552
- * @uses bp_blog_create_nav_item() to output the Create a Site nav item.
1553
- *
1554
- * @return string HTML Output
1555
- */
1556
- function bp_blog_backcompat_create_nav_item() {
1557
- // Bail if Blogs nav item is already used by bp-legacy
1558
- if ( has_action( 'bp_blogs_directory_blog_types', 'bp_legacy_theme_blog_create_nav', 999 ) ) {
1559
- return;
1560
- }
1561
-
1562
- // Bail if the theme is not filtering the Blogs directory title
1563
- if ( ! has_filter( 'bp_blogs_directory_header' ) ) {
1564
- return;
1565
- }
1566
-
1567
- bp_blog_create_nav_item();
1568
- }
1569
- add_action( 'bp_blogs_directory_blog_types', 'bp_blog_backcompat_create_nav_item', 1000 );
1570
-
1571
  /**
1572
  * Output button for visiting a blog in a loop.
1573
  *
1574
  * @see bp_get_blogs_visit_blog_button() for description of arguments.
1575
  *
1576
- * @param array|string $args See {@link bp_get_blogs_visit_blog_button()}.
1577
  */
1578
  function bp_blogs_visit_blog_button( $args = '' ) {
1579
  echo bp_get_blogs_visit_blog_button( $args );
@@ -1584,18 +1205,18 @@ function bp_blogs_visit_blog_button( $args = '' ) {
1584
  * @see BP_Button for a complete description of arguments and return
1585
  * value.
1586
  *
1587
- * @param array|string $args {
1588
  * Arguments are listed below, with their default values. For a
1589
  * complete description of arguments, see {@link BP_Button}.
1590
- * @type string $id Default: 'visit_blog'.
1591
- * @type string $component Default: 'blogs'.
1592
- * @type bool $must_be_logged_in Default: false.
1593
- * @type bool $block_self Default: false.
1594
- * @type string $wrapper_class Default: 'blog-button visit'.
1595
- * @type string $link_href Permalink of the current blog in the loop.
1596
- * @type string $link_class Default: 'blog-button visit'.
1597
- * @type string $link_text Default: 'Visit Site'.
1598
- * @type string $link_title Default: 'Visit Site'.
1599
  * }
1600
  * @return string The HTML for the Visit button.
1601
  */
@@ -1614,13 +1235,7 @@ function bp_blogs_visit_blog_button( $args = '' ) {
1614
 
1615
  $button = wp_parse_args( $args, $defaults );
1616
 
1617
- /**
1618
- * Filters the button for visiting a blog in a loop.
1619
- *
1620
- * @since 1.2.10
1621
- *
1622
- * @param array $button Array of arguments to be used for the button to visit a blog.
1623
- */
1624
  return bp_get_button( apply_filters( 'bp_get_blogs_visit_blog_button', $button ) );
1625
  }
1626
 
@@ -1629,11 +1244,10 @@ function bp_blogs_visit_blog_button( $args = '' ) {
1629
  /**
1630
  * Display the number of blogs in user's profile.
1631
  *
1632
- * @since 2.0.0
1633
  *
1634
- * @uses bp_blogs_admin_get_profile_stats() to get the stats.
1635
- *
1636
- * @param array|string $args before|after|user_id
1637
  */
1638
  function bp_blogs_profile_stats( $args = '' ) {
1639
  echo bp_blogs_get_profile_stats( $args );
@@ -1643,10 +1257,9 @@ add_action( 'bp_members_admin_user_stats', 'bp_blogs_profile_stats', 9, 1 );
1643
  /**
1644
  * Return the number of blogs in user's profile.
1645
  *
1646
- * @since 2.0.0
1647
- *
1648
- * @param array|string $args before|after|user_id
1649
  *
 
1650
  * @return string HTML for stats output.
1651
  */
1652
  function bp_blogs_get_profile_stats( $args = '' ) {
@@ -1676,13 +1289,6 @@ function bp_blogs_get_profile_stats( $args = '' ) {
1676
  }
1677
  }
1678
 
1679
- /**
1680
- * Filters the number of blogs in user's profile.
1681
- *
1682
- * @since 2.0.0
1683
- *
1684
- * @param string $value Output determined for the profile stats.
1685
- * @param array $r Array of arguments used for default output if none provided.
1686
- */
1687
  return apply_filters( 'bp_blogs_get_profile_stats', $r['output'], $r );
1688
  }
1
  <?php
2
+
3
  /**
4
  * BuddyPress Blogs Template Tags.
5
  *
7
  * @subpackage BlogsTemplate
8
  */
9
 
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
 
13
  /**
14
  * Output the blogs component slug.
15
  *
16
+ * @since BuddyPress (1.5.0)
17
  *
18
  * @uses bp_get_blogs_slug()
19
  */
23
  /**
24
  * Return the blogs component slug.
25
  *
26
+ * @since BuddyPress (1.5.0)
27
  *
28
  * @return string The 'blogs' slug.
29
  */
30
  function bp_get_blogs_slug() {
 
 
 
 
 
 
 
 
31
  return apply_filters( 'bp_get_blogs_slug', buddypress()->blogs->slug );
32
  }
33
 
34
  /**
35
  * Output the blogs component root slug.
36
  *
37
+ * @since BuddyPress (1.5.0)
38
  *
39
  * @uses bp_get_blogs_root_slug()
40
  */
44
  /**
45
  * Return the blogs component root slug.
46
  *
47
+ * @since BuddyPress (1.5.0)
48
  *
49
  * @return string The 'blogs' root slug.
50
  */
51
  function bp_get_blogs_root_slug() {
 
 
 
 
 
 
 
 
52
  return apply_filters( 'bp_get_blogs_root_slug', buddypress()->blogs->root_slug );
53
  }
54
 
55
  /**
56
  * Output blog directory permalink.
57
  *
58
+ * @since BuddyPress (1.5.0)
59
  *
60
  * @uses bp_get_blogs_directory_permalink()
61
  */
62
  function bp_blogs_directory_permalink() {
63
+ echo bp_get_blogs_directory_permalink();
64
  }
65
  /**
66
  * Return blog directory permalink.
67
  *
68
+ * @since BuddyPress (1.5.0)
69
  *
70
  * @uses apply_filters()
71
  * @uses trailingslashit()
72
  * @uses bp_get_root_domain()
73
  * @uses bp_get_blogs_root_slug()
 
74
  * @return string The URL of the Blogs directory.
75
  */
76
  function bp_get_blogs_directory_permalink() {
 
 
 
 
 
 
 
 
77
  return apply_filters( 'bp_get_blogs_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_blogs_root_slug() ) );
78
  }
79
 
87
  /**
88
  * The loop iterator.
89
  *
90
+ * @access public
91
  * @var int
92
  */
93
+ var $current_blog = -1;
94
 
95
  /**
96
  * The number of blogs returned by the paged query.
97
  *
98
+ * @access public
99
  * @var int
100
  */
101
+ var $blog_count;
102
 
103
  /**
104
  * Array of blogs located by the query..
105
  *
106
+ * @access public
107
  * @var array
108
  */
109
+ var $blogs;
110
 
111
  /**
112
  * The blog object currently being iterated on.
113
  *
114
+ * @access public
115
  * @var object
116
  */
117
+ var $blog;
118
 
119
  /**
120
  * A flag for whether the loop is currently being iterated.
121
  *
122
+ * @access public
123
  * @var bool
124
  */
125
+ var $in_the_loop;
126
 
127
  /**
128
  * The page number being requested.
129
  *
130
+ * @access public
131
+ * @var public
132
  */
133
+ var $pag_page;
134
 
135
  /**
136
  * The number of items being requested per page.
137
  *
138
+ * @access public
139
+ * @var public
140
  */
141
+ var $pag_num;
142
 
143
  /**
144
  * An HTML string containing pagination links.
145
  *
146
+ * @access public
147
  * @var string
148
  */
149
+ var $pag_links;
150
 
151
  /**
152
  * The total number of blogs matching the query parameters.
153
  *
154
+ * @access public
155
  * @var int
156
  */
157
+ var $total_blog_count;
158
 
159
  /**
160
  * Constructor method.
161
  *
162
  * @see BP_Blogs_Blog::get() for a description of parameters.
163
  *
164
+ * @param string $type See {@link BP_Blogs_Blog::get()}.
165
+ * @param string $page See {@link BP_Blogs_Blog::get()}.
166
+ * @param string $per_page See {@link BP_Blogs_Blog::get()}.
167
+ * @param string $max See {@link BP_Blogs_Blog::get()}.
168
+ * @param string $user_id See {@link BP_Blogs_Blog::get()}.
169
+ * @param string $search_terms See {@link BP_Blogs_Blog::get()}.
170
+ * @param string $page_arg The string used as a query parameter in
171
+ * pagination links. Default: 'bpage'.
172
+ * @param bool $update_meta_cache Whether to pre-fetch metadata for
173
+ * queried blogs.
174
+ * @param array $include_blog_ids Array of blog IDs to include.
175
  */
176
+ function __construct( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg = 'bpage', $update_meta_cache = true, $include_blog_ids = false ) {
177
 
178
+ $this->pag_page = isset( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[$page_arg] ) : $page;
179
+ $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
 
180
 
181
+ if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] ) {
 
182
  $this->blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page );
 
 
183
  } else {
184
  $this->blogs = bp_blogs_get_blogs( array(
185
  'type' => $type,
192
  ) );
193
  }
194
 
195
+ if ( !$max || $max >= (int) $this->blogs['total'] )
 
196
  $this->total_blog_count = (int) $this->blogs['total'];
197
+ else
198
  $this->total_blog_count = (int) $max;
 
199
 
 
200
  $this->blogs = $this->blogs['blogs'];
201
 
202
+ if ( $max ) {
203
+ if ( $max >= count($this->blogs) ) {
204
+ $this->blog_count = count( $this->blogs );
205
+ } else {
206
+ $this->blog_count = (int) $max;
207
+ }
208
  } else {
209
+ $this->blog_count = count( $this->blogs );
210
  }
211
 
212
+ if ( (int) $this->total_blog_count && (int) $this->pag_num ) {
 
213
  $this->pag_links = paginate_links( array(
214
+ 'base' => add_query_arg( $page_arg, '%#%' ),
215
  'format' => '',
216
  'total' => ceil( (int) $this->total_blog_count / (int) $this->pag_num ),
217
  'current' => (int) $this->pag_page,
218
  'prev_text' => _x( '&larr;', 'Blog pagination previous text', 'buddypress' ),
219
+ 'next_text' => _x( '&rarr;', 'Blog pagination next text', 'buddypress' ),
220
+ 'mid_size' => 1
 
221
  ) );
222
  }
223
  }
229
  *
230
  * @return bool True if there are items in the loop, otherwise false.
231
  */
232
+ function has_blogs() {
233
+ if ( $this->blog_count )
234
+ return true;
235
+
236
+ return false;
237
  }
238
 
239
  /**
241
  *
242
  * @return object The next blog to iterate over.
243
  */
244
+ function next_blog() {
245
  $this->current_blog++;
246
+ $this->blog = $this->blogs[$this->current_blog];
247
 
248
  return $this->blog;
249
  }
251
  /**
252
  * Rewind the blogs and reset blog index.
253
  */
254
+ function rewind_blogs() {
255
  $this->current_blog = -1;
256
  if ( $this->blog_count > 0 ) {
257
  $this->blog = $this->blogs[0];
269
  *
270
  * @return bool True if there are more blogs to show, otherwise false.
271
  */
272
+ function blogs() {
273
+ if ( $this->current_blog + 1 < $this->blog_count ) {
274
  return true;
275
+ } elseif ( $this->current_blog + 1 == $this->blog_count ) {
276
+ do_action('blog_loop_end');
 
 
 
 
 
 
277
  // Do some cleaning up after the loop
278
  $this->rewind_blogs();
279
  }
291
  *
292
  * @see bp_the_blog()
293
  */
294
+ function the_blog() {
295
 
296
  $this->in_the_loop = true;
297
  $this->blog = $this->next_blog();
298
 
299
+ if ( 0 == $this->current_blog ) // loop has just started
300
+ do_action('blog_loop_start');
 
 
 
 
 
 
 
 
301
  }
302
  }
303
 
319
  *
320
  * @global object $blogs_template {@link BP_Blogs_Template}
321
  *
322
+ * @param array $args {
323
  * Arguments for limiting the contents of the blogs loop. Most arguments
324
  * are in the same format as {@link BP_Blogs_Blog::get()}. However, because
325
  * the format of the arguments accepted here differs in a number of ways,
329
  * Arguments can be passed as an associative array, or as a URL query
330
  * string (eg, 'user_id=4&per_page=3').
331
  *
332
+ * @type int $page Which page of results to fetch. Using page=1 without
333
+ * per_page will result in no pagination. Default: 1.
334
+ * @type int|bool $per_page Number of results per page. Default: 20.
335
+ * @type string $page_arg The string used as a query parameter in
336
+ * pagination links. Default: 'bpage'.
337
+ * @type int|bool $max Maximum number of results to return.
338
+ * Default: false (unlimited).
339
+ * @type string $type The order in which results should be fetched.
340
+ * 'active', 'alphabetical', 'newest', or 'random'.
341
+ * @type array $include_blog_ids Array of blog IDs to limit results to.
342
+ * @type string $sort 'ASC' or 'DESC'. Default: 'DESC'.
343
+ * @type string $search_terms Limit results by a search term. Default: null.
344
+ * @type int $user_id The ID of the user whose blogs should be retrieved.
345
+ * When viewing a user profile page, 'user_id' defaults to the ID of
346
+ * the displayed user. Otherwise the default is false.
 
347
  * }
348
  * @return bool Returns true when blogs are found, otherwise false.
349
  */
350
  function bp_has_blogs( $args = '' ) {
351
  global $blogs_template;
352
 
353
+ /***
354
+ * Set the defaults based on the current page. Any of these will be overridden
355
+ * if arguments are directly passed into the loop. Custom plugins should always
356
+ * pass their parameters directly to the loop.
357
+ */
358
+ $type = 'active';
359
+ $user_id = 0;
360
+ $search_terms = null;
361
 
362
+ // User filtering
363
+ if ( bp_displayed_user_id() )
364
+ $user_id = bp_displayed_user_id();
365
+
366
+ $defaults = array(
367
+ 'type' => $type,
368
  'page' => 1,
369
  'per_page' => 20,
370
  'max' => false,
 
 
 
 
 
371
 
372
+ 'page_arg' => 'bpage', // See https://buddypress.trac.wordpress.org/ticket/3679
373
+
374
+ 'user_id' => $user_id, // Pass a user_id to limit to only blogs this user has higher than subscriber access to
375
+ 'include_blog_ids' => false,
376
+ 'search_terms' => $search_terms, // Pass search terms to filter on the blog title or description.
377
+ 'update_meta_cache' => true,
378
+ );
379
+
380
+ $r = bp_parse_args( $args, $defaults, 'has_blogs' );
381
+ extract( $r );
382
+
383
+ if ( is_null( $search_terms ) ) {
384
+ if ( isset( $_REQUEST['s'] ) && !empty( $_REQUEST['s'] ) )
385
+ $search_terms = $_REQUEST['s'];
386
+ else
387
+ $search_terms = false;
388
  }
389
 
390
+ if ( $max ) {
391
+ if ( $per_page > $max ) {
392
+ $per_page = $max;
393
+ }
394
+ }
395
 
396
+ $blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg, $update_meta_cache, $include_blog_ids );
397
+ return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), $blogs_template );
 
 
 
 
 
 
 
 
398
  }
399
 
400
  /**
436
  $to_num = bp_core_number_format( ( $start_num + ( $blogs_template->pag_num - 1 ) > $blogs_template->total_blog_count ) ? $blogs_template->total_blog_count : $start_num + ( $blogs_template->pag_num - 1 ) );
437
  $total = bp_core_number_format( $blogs_template->total_blog_count );
438
 
439
+ echo sprintf( _n( 'Viewing site %1$s to %2$s (of %3$s site)', 'Viewing site %1$s to %2$s (of %3$s sites)', $total, 'buddypress' ), $from_num, $to_num, $total );
 
 
 
 
 
 
440
  }
441
 
442
  /**
455
  function bp_get_blogs_pagination_links() {
456
  global $blogs_template;
457
 
 
 
 
 
 
 
 
458
  return apply_filters( 'bp_get_blogs_pagination_links', $blogs_template->pag_links );
459
  }
460
 
463
  *
464
  * @see bp_get_blog_avatar() for description of arguments.
465
  *
466
+ * @param array $args See {@link bp_get_blog_avatar()}.
467
  */
468
  function bp_blog_avatar( $args = '' ) {
469
  echo bp_get_blog_avatar( $args );
474
  * At the moment, blog avatars are simply the user avatars of the blog
475
  * admin. Filter 'bp_get_blog_avatar_' . $blog_id to customize.
476
  *
 
 
477
  * @see bp_core_fetch_avatar() For a description of arguments and
478
  * return values.
479
  *
480
+ * @param array $args {
481
  * Arguments are listed here with an explanation of their defaults.
482
  * For more information about the arguments, see
483
  * {@link bp_core_fetch_avatar()}.
484
+ * @type string $alt Default: 'Profile picture of site author
485
+ * [user name]'.
486
+ * @type string $class Default: 'avatar'.
487
+ * @type string $type Default: 'full'.
488
+ * @type int|bool $width Default: false.
489
+ * @type int|bool $height Default: false.
490
+ * @type bool $id Currently unused.
491
+ * @type bool $no_grav Default: false.
492
  * }
493
  * @return string User avatar string.
494
  */
495
  function bp_get_blog_avatar( $args = '' ) {
496
  global $blogs_template;
497
 
498
+ $defaults = array(
 
 
 
 
 
 
 
 
 
499
  'type' => 'full',
500
  'width' => false,
501
  'height' => false,
502
  'class' => 'avatar',
 
503
  'id' => false,
504
+ 'alt' => sprintf( __( 'Profile picture of site author %s', 'buddypress' ), bp_core_get_user_displayname( $blogs_template->blog->admin_user_id ) ),
505
+ 'no_grav' => true
506
+ );
507
+
508
+ $r = wp_parse_args( $args, $defaults );
509
+ extract( $r, EXTR_SKIP );
 
 
 
 
 
 
 
 
 
 
 
510
 
511
  /***
512
  * In future BuddyPress versions you will be able to set the avatar for a blog.
516
  * This filter is deprecated as of BuddyPress 1.5 and may be removed in a future version.
517
  * Use the 'bp_get_blog_avatar' filter instead.
518
  */
519
+ $avatar = apply_filters( 'bp_get_blog_avatar_' . $blogs_template->blog->blog_id, bp_core_fetch_avatar( array( 'item_id' => $blogs_template->blog->admin_user_id, 'type' => $type, 'alt' => $alt, 'width' => $width, 'height' => $height, 'class' => $class, 'email' => $blogs_template->blog->admin_user_email ) ) );
520
 
521
+ return apply_filters( 'bp_get_blog_avatar', $avatar, $blogs_template->blog->blog_id, array( 'item_id' => $blogs_template->blog->admin_user_id, 'type' => $type, 'alt' => $alt, 'width' => $width, 'height' => $height, 'class' => $class, 'email' => $blogs_template->blog->admin_user_email ) );
 
 
 
 
 
 
 
 
 
 
522
  }
523
 
524
  function bp_blog_permalink() {
537
  $permalink = $protocol . $blogs_template->blog->domain . $blogs_template->blog->path;
538
  }
539
 
 
 
 
 
 
 
 
540
  return apply_filters( 'bp_get_blog_permalink', $permalink );
541
  }
542
 
554
  function bp_get_blog_name() {
555
  global $blogs_template;
556
 
 
 
 
 
 
 
 
557
  return apply_filters( 'bp_get_blog_name', $blogs_template->blog->name );
558
  }
559
 
560
  /**
561
  * Output the ID of the current blog in the loop.
562
  *
563
+ * @since BuddyPress (1.7.0)
564
  */
565
  function bp_blog_id() {
566
  echo bp_get_blog_id();
568
  /**
569
  * Return the ID of the current blog in the loop.
570
  *
571
+ * @since BuddyPress (1.7.0)
572
  *
573
  * @return int ID of the current blog in the loop.
574
  */
575
  function bp_get_blog_id() {
576
  global $blogs_template;
577
 
 
 
 
 
 
 
 
578
  return apply_filters( 'bp_get_blog_id', $blogs_template->blog->blog_id );
579
  }
580
 
582
  * Output the description of the current blog in the loop.
583
  */
584
  function bp_blog_description() {
 
 
 
 
 
 
 
 
585
  echo apply_filters( 'bp_blog_description', bp_get_blog_description() );
586
  }
587
  /**
592
  function bp_get_blog_description() {
593
  global $blogs_template;
594
 
 
 
 
 
 
 
 
595
  return apply_filters( 'bp_get_blog_description', $blogs_template->blog->description );
596
  }
597
 
598
  /**
599
  * Output the row class of the current blog in the loop.
600
  *
601
+ * @since BuddyPress (1.7.0)
 
 
602
  */
603
+ function bp_blog_class() {
604
+ echo bp_get_blog_class();
605
  }
606
  /**
607
  * Return the row class of the current blog in the loop.
608
  *
609
+ * @since BuddyPress (1.7.0)
610
  *
611
  * @global BP_Blogs_Template $blogs_template
 
612
  *
613
  * @return string Row class of the site.
614
  */
615
+ function bp_get_blog_class() {
616
  global $blogs_template;
617
 
618
+ $classes = array();
619
+ $pos_in_loop = (int) $blogs_template->current_blog;
 
 
620
 
621
+ // If we've only one site in the loop, don't bother with odd and even.
622
+ if ( $blogs_template->blog_count > 1 )
623
+ $classes[] = ( $pos_in_loop % 2 ) ? 'even' : 'odd';
624
+ else
625
  $classes[] = 'bp-single-blog';
 
626
 
 
 
 
 
 
 
 
627
  $classes = apply_filters( 'bp_get_blog_class', $classes );
628
  $classes = array_merge( $classes, array() );
 
629
 
630
+ $retval = 'class="' . join( ' ', $classes ) . '"';
631
  return $retval;
632
  }
633
 
634
  /**
635
  * Output the last active date of the current blog in the loop.
 
 
636
  */
637
+ function bp_blog_last_active() {
638
+ echo bp_get_blog_last_active();
639
  }
640
  /**
641
  * Return the last active date of the current blog in the loop.
642
  *
 
 
 
 
 
 
643
  * @return string Last active date.
644
  */
645
+ function bp_get_blog_last_active() {
646
  global $blogs_template;
647
 
648
+ return apply_filters( 'bp_blog_last_active', bp_core_get_last_activity( $blogs_template->blog->last_activity, __( 'active %s', 'buddypress' ) ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
649
  }
650
 
651
  /**
652
  * Output the latest post from the current blog in the loop.
 
 
653
  */
654
+ function bp_blog_latest_post() {
655
+ echo bp_get_blog_latest_post();
656
  }
657
  /**
658
  * Return the latest post from the current blog in the loop.
659
  *
 
 
 
 
 
 
660
  * @return string $retval String of the form 'Latest Post: [link to post]'.
661
  */
662
+ function bp_get_blog_latest_post() {
663
  global $blogs_template;
664
 
 
 
 
 
665
  $retval = bp_get_blog_latest_post_title();
666
 
667
+ if ( ! empty( $retval ) )
668
+ $retval = sprintf( __( 'Latest Post: %s', 'buddypress' ), '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $retval ) . '</a>' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
669
 
 
 
 
 
 
 
 
670
  return apply_filters( 'bp_get_blog_latest_post', $retval );
671
  }
672
 
673
  /**
674
  * Output the title of the latest post on the current blog in the loop.
675
  *
676
+ * @since BuddyPress (1.7.0)
677
  *
678
  * @see bp_get_blog_latest_post_title()
679
  */
683
  /**
684
  * Return the title of the latest post on the current blog in the loop.
685
  *
686
+ * @since BuddyPress (1.7.0)
687
  *
688
  * @global BP_Blogs_Template
689
  *
697
  if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->post_title ) )
698
  $retval = $blogs_template->blog->latest_post->post_title;
699
 
 
 
 
 
 
 
 
700
  return apply_filters( 'bp_get_blog_latest_post_title', $retval );
701
  }
702
 
703
  /**
704
  * Output the permalink of the latest post on the current blog in the loop.
705
  *
706
+ * @since BuddyPress (1.7.0)
707
  *
708
  * @see bp_get_blog_latest_post_title()
709
  */
710
  function bp_blog_latest_post_permalink() {
711
+ echo bp_get_blog_latest_post_permalink();
712
  }
713
  /**
714
  * Return the permalink of the latest post on the current blog in the loop.
715
  *
716
+ * @since BuddyPress (1.7.0)
717
  *
718
  * @global BP_Blogs_Template
719
  *
727
  if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->ID ) )
728
  $retval = add_query_arg( 'p', $blogs_template->blog->latest_post->ID, bp_get_blog_permalink() );
729
 
 
 
 
 
 
 
 
730
  return apply_filters( 'bp_get_blog_latest_post_permalink', $retval );
731
  }
732
 
733
  /**
734
  * Output the content of the latest post on the current blog in the loop.
735
  *
736
+ * @since BuddyPress (1.7.0)
737
  *
738
  * @uses bp_get_blog_latest_post_content()
739
  */
743
  /**
744
  * Return the content of the latest post on the current blog in the loop.
745
  *
746
+ * @since BuddyPress (1.7.0)
747
  *
748
  * @global BP_Blogs_Template
749
  *
757
  if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->post_content ) )
758
  $retval = $blogs_template->blog->latest_post->post_content;
759
 
 
 
 
 
 
 
 
760
  return apply_filters( 'bp_get_blog_latest_post_content', $retval );
761
  }
762
 
763
  /**
764
  * Output the featured image of the latest post on the current blog in the loop.
765
  *
766
+ * @since BuddyPress (1.7.0)
767
  *
768
  * @see bp_get_blog_latest_post_content() For description of parameters.
769
  *
775
  /**
776
  * Return the featured image of the latest post on the current blog in the loop.
777
  *
778
+ * @since BuddyPress (1.7.0)
779
  *
780
  * @global BP_Blogs_Template
781
  *
782
  * @param string $size Image version to return. 'thumbnail', 'medium',
783
+ * 'large', or 'post-thumbnail'. Default: 'thumbnail'.
 
784
  * @return string URL of the image.
785
  */
786
  function bp_get_blog_latest_post_featured_image( $size = 'thumbnail' ) {
791
  if ( ! empty( $blogs_template->blog->latest_post ) && ! empty( $blogs_template->blog->latest_post->images[$size] ) )
792
  $retval = $blogs_template->blog->latest_post->images[$size];
793
 
 
 
 
 
 
 
 
794
  return apply_filters( 'bp_get_blog_latest_post_featured_image', $retval );
795
  }
796
 
797
  /**
798
  * Does the latest blog post have a featured image?
799
  *
800
+ * @since BuddyPress (1.7.0)
 
 
 
801
  *
802
+ * @param string $size Image version to return. 'thumbnail', 'medium', 'large',
803
+ * or 'post-thumbnail'. Default: 'thumbnail'.
804
  * @return bool True if the latest blog post from the current blog has a
805
+ * featured image of the given size.
806
  */
807
  function bp_blog_latest_post_has_featured_image( $thumbnail = 'thumbnail' ) {
808
  $image = bp_get_blog_latest_post_featured_image( $thumbnail );
809
 
 
 
 
 
 
 
 
 
 
810
  return apply_filters( 'bp_blog_latest_post_has_featured_image', ! empty( $image ), $thumbnail, $image );
811
  }
812
 
840
  * @return int Total number of blogs.
841
  */
842
  function bp_get_total_blog_count() {
 
 
 
 
 
 
 
 
843
  return apply_filters( 'bp_get_total_blog_count', bp_blogs_total_blogs() );
844
  }
845
  add_filter( 'bp_get_total_blog_count', 'bp_core_number_format' );
856
  * Return the total number of blogs for a given user.
857
  *
858
  * @param int $user_id ID of the user.
 
859
  * @return int Total number of blogs for the user.
860
  */
861
  function bp_get_total_blog_count_for_user( $user_id = 0 ) {
 
 
 
 
 
 
 
 
862
  return apply_filters( 'bp_get_total_blog_count_for_user', bp_blogs_total_blogs_for_user( $user_id ) );
863
  }
864
  add_filter( 'bp_get_total_blog_count_for_user', 'bp_core_number_format' );
875
  * @return bool True if blog registration is enabled.
876
  */
877
  function bp_blog_signup_enabled() {
878
+ global $bp;
879
 
880
+ $active_signup = isset( $bp->site_options['registration'] ) ? $bp->site_options['registration'] : 'all';
 
 
881
 
 
 
 
 
 
 
 
882
  $active_signup = apply_filters( 'wpmu_active_signup', $active_signup ); // return "all", "none", "blog" or "user"
883
 
884
  if ( 'none' == $active_signup || 'user' == $active_signup )
890
  /**
891
  * Output the wrapper markup for the blog signup form.
892
  *
893
+ * @param string $blogname Optional. The default blog name (path or domain).
894
+ * @param string $blog_title Optional. The default blog title.
895
+ * @param string|WP_Error Optional. The WP_Error object returned by a previous
896
+ * submission attempt.
897
  */
898
  function bp_show_blog_signup_form($blogname = '', $blog_title = '', $errors = '') {
899
  global $current_user;
905
  $errors = new WP_Error();
906
  }
907
 
908
+ // allow definition of default variables
 
 
 
 
 
 
 
 
 
 
909
  $filtered_results = apply_filters('signup_another_blog_init', array('blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors ));
910
  $blogname = $filtered_results['blogname'];
911
  $blog_title = $filtered_results['blog_title'];
912
  $errors = $filtered_results['errors'];
913
 
914
  if ( $errors->get_error_code() ) {
915
+ echo "<p>" . __('There was a problem, please correct the form below and try again.', 'buddypress') . "</p>";
916
  }
917
  ?>
918
  <p><?php printf(__("By filling out the form below, you can <strong>add a site to your account</strong>. There is no limit to the number of sites that you can have, so create to your heart's content, but blog responsibly!", 'buddypress'), $current_user->display_name) ?></p>
922
  <form class="standard-form" id="setupform" method="post" action="">
923
 
924
  <input type="hidden" name="stage" value="gimmeanotherblog" />
925
+ <?php do_action( 'signup_hidden_fields' ); ?>
 
 
 
 
 
 
 
926
 
927
  <?php bp_blogs_signup_blog($blogname, $blog_title, $errors); ?>
928
  <p>
938
  /**
939
  * Output the input fields for the blog creation form.
940
  *
941
+ * @param string $blogname Optional. The default blog name (path or domain).
942
+ * @param string $blog_title Optional. The default blog title.
943
+ * @param string|WP_Error Optional. The WP_Error object returned by a previous
944
+ * submission attempt.
945
  */
946
  function bp_blogs_signup_blog( $blogname = '', $blog_title = '', $errors = '' ) {
947
  global $current_site;
961
  if ( !is_subdomain_install() )
962
  echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span> <input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="63" /><br />';
963
  else
964
+ echo '<input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="63" /> <span class="suffix_address">.' . bp_blogs_get_subdomain_base() . '</span><br />';
965
 
966
  if ( !is_user_logged_in() ) {
967
  print '(<strong>' . __( 'Your address will be ' , 'buddypress');
1003
  </p>
1004
 
1005
  <?php
1006
+ do_action('signup_blogform', $errors);
1007
+ }
1008
 
1009
+ /**
1010
+ * Output the base URL for subdomain installations of WordPress Multisite.
1011
+ *
1012
+ * @since BuddyPress (1.6.0)
1013
+ */
1014
+ function bp_blogs_subdomain_base() {
1015
+ echo bp_blogs_get_subdomain_base();
1016
+ }
1017
  /**
1018
+ * Return the base URL for subdomain installations of WordPress Multisite.
1019
  *
1020
+ * @since BuddyPress (1.6.0)
1021
  *
1022
+ * @return string The base URL - eg, 'example.com' for site_url() example.com or www.example.com.
1023
  */
1024
+ function bp_blogs_get_subdomain_base() {
1025
+ global $current_site;
1026
+
1027
+ return apply_filters( 'bp_blogs_subdomain_base', preg_replace( '|^www\.|', '', $current_site->domain ) . $current_site->path );
1028
+ }
1029
 
1030
  /**
1031
  * Process a blog registration submission.
1057
  $public = (int) $_POST['blog_public'];
1058
 
1059
  $meta = apply_filters( 'signup_create_blog_meta', array( 'lang_id' => 1, 'public' => $public ) ); // depreciated
 
 
 
 
 
 
 
 
 
 
 
1060
  $meta = apply_filters( 'add_signup_meta', $meta );
1061
 
1062
  // If this is a subdomain install, set up the site inside the root domain.
1086
  /**
1087
  * Display a message after successful blog registration.
1088
  *
1089
+ * @param string $domain The new blog's domain.
1090
+ * @param string $path The new blog's path.
1091
+ * @param string $blog_title The new blog's title.
1092
+ * @param string $user_name The user name of the user who created the blog. Unused.
1093
+ * @param string $user_email The email of the user who created the blog. Unused.
1094
+ * @param string|array $meta Meta values associated with the new blog. Unused.
1095
  */
1096
  function bp_blogs_confirm_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = '' ) {
1097
  $protocol = is_ssl() ? 'https://' : 'http://';
1103
  </p>
1104
 
1105
  <?php
 
 
 
 
 
 
1106
  do_action('signup_finished');
1107
  }
1108
 
1109
  /**
1110
  * Output a "Create a Site" link for users viewing their own profiles.
 
 
 
1111
  */
1112
  function bp_create_blog_link() {
1113
+ if ( bp_is_my_profile() )
1114
+ echo apply_filters( 'bp_create_blog_link', '<a href="' . bp_get_root_domain() . '/' . bp_get_blogs_root_slug() . '/create/">' . __( 'Create a Site', 'buddypress' ) . '</a>' );
 
 
 
 
 
 
 
 
 
 
 
 
1115
  }
1116
 
1117
  /**
1122
  function bp_blogs_blog_tabs() {
1123
 
1124
  // Don't show these tabs on a user's own profile
1125
+ if ( bp_is_my_profile() )
1126
  return false;
1127
+
1128
+ ?>
1129
 
1130
  <ul class="content-header-nav">
1131
  <li<?php if ( bp_is_current_action( 'my-blogs' ) || !bp_current_action() ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_blogs_slug() . '/my-blogs' ); ?>"><?php printf( __( "%s's Sites", 'buddypress' ), bp_get_displayed_user_fullname() ); ?></a></li>
1134
  </ul>
1135
 
1136
  <?php
 
 
 
 
 
 
1137
  do_action( 'bp_blogs_blog_tabs' );
1138
  }
1139
 
1141
  * Output the blog directory search form.
1142
  */
1143
  function bp_directory_blogs_search_form() {
1144
+ $default_search_value = bp_get_search_default_text();
1145
+ $search_value = !empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value;
 
 
 
 
 
 
1146
 
1147
  $search_form_html = '<form action="" method="get" id="search-blogs-form">
1148
+ <label><input type="text" name="s" id="blogs_search" placeholder="'. esc_attr( $search_value ) .'" /></label>
1149
  <input type="submit" id="blogs_search_submit" name="blogs_search_submit" value="' . __( 'Search', 'buddypress' ) . '" />
1150
  </form>';
1151
 
 
 
 
 
 
 
 
1152
  echo apply_filters( 'bp_directory_blogs_search_form', $search_form_html );
1153
  }
1154
 
1155
  /**
1156
  * Output the Create a Site button.
1157
  *
1158
+ * @since BuddyPress (2.0.0)
1159
  */
1160
  function bp_blog_create_button() {
1161
  echo bp_get_blog_create_button();
1163
  /**
1164
  * Get the Create a Site button.
1165
  *
1166
+ * @since BuddyPress (2.0.0)
1167
  *
1168
  * @return string
1169
  */
1181
  'component' => 'blogs',
1182
  'link_text' => __( 'Create a Site', 'buddypress' ),
1183
  'link_title' => __( 'Create a Site', 'buddypress' ),
1184
+ 'link_class' => 'button blog-create bp-title-button',
1185
+ 'link_href' => trailingslashit( bp_get_root_domain() ) . trailingslashit( bp_get_blogs_root_slug() ) . trailingslashit( 'create' ),
1186
  'wrapper' => false,
 
1187
  );
1188
 
 
 
 
 
 
 
 
1189
  return bp_get_button( apply_filters( 'bp_get_blog_create_button', $button_args ) );
1190
  }
1191
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1192
  /**
1193
  * Output button for visiting a blog in a loop.
1194
  *
1195
  * @see bp_get_blogs_visit_blog_button() for description of arguments.
1196
  *
1197
+ * @param array $args See {@link bp_get_blogs_visit_blog_button()}.
1198
  */
1199
  function bp_blogs_visit_blog_button( $args = '' ) {
1200
  echo bp_get_blogs_visit_blog_button( $args );
1205
  * @see BP_Button for a complete description of arguments and return
1206
  * value.
1207
  *
1208
+ * @param array $args {
1209
  * Arguments are listed below, with their default values. For a
1210
  * complete description of arguments, see {@link BP_Button}.
1211
+ * @type string $id Default: 'visit_blog'.
1212
+ * @type string $component Default: 'blogs'.
1213
+ * @type bool $must_be_logged_in Default: false.
1214
+ * @type bool $block_self Default: false.
1215
+ * @type string $wrapper_class Default: 'blog-button visit'.
1216
+ * @type string $link_href Permalink of the current blog in the loop.
1217
+ * @type string $link_class Default: 'blog-button visit'.
1218
+ * @type string $link_text Default: 'Visit Site'.
1219
+ * @type string $link_title Default: 'Visit Site'.
1220
  * }
1221
  * @return string The HTML for the Visit button.
1222
  */
1235
 
1236
  $button = wp_parse_args( $args, $defaults );
1237
 
1238
+ // Filter and return the HTML button
 
 
 
 
 
 
1239
  return bp_get_button( apply_filters( 'bp_get_blogs_visit_blog_button', $button ) );
1240
  }
1241
 
1244
  /**
1245
  * Display the number of blogs in user's profile.
1246
  *
1247
+ * @since BuddyPress (2.0.0)
1248
  *
1249
+ * @param array $args before|after|user_id
1250
+ * @uses bp_blogs_admin_get_profile_stats() to get the stats
 
1251
  */
1252
  function bp_blogs_profile_stats( $args = '' ) {
1253
  echo bp_blogs_get_profile_stats( $args );
1257
  /**
1258
  * Return the number of blogs in user's profile.
1259
  *
1260
+ * @since BuddyPress (2.0.0)
 
 
1261
  *
1262
+ * @param array $args before|after|user_id
1263
  * @return string HTML for stats output.
1264
  */
1265
  function bp_blogs_get_profile_stats( $args = '' ) {
1289
  }
1290
  }
1291
 
1292
+ // Filter and return
 
 
 
 
 
 
 
1293
  return apply_filters( 'bp_blogs_get_profile_stats', $r['output'], $r );
1294
  }
bp-blogs/bp-blogs-widgets.php CHANGED
@@ -1,13 +1,14 @@
1
  <?php
 
2
  /**
3
- * BuddyPress Blogs Widgets.
4
  *
5
  * @package BuddyPress
6
  * @subpackage BlogsWidgets
7
  */
8
 
9
  // Exit if accessed directly
10
- defined( 'ABSPATH' ) || exit;
11
 
12
  /**
13
  * Register the widgets for the Blogs component.
@@ -15,21 +16,20 @@ defined( 'ABSPATH' ) || exit;
15
  function bp_blogs_register_widgets() {
16
  global $wpdb;
17
 
18
- if ( bp_is_active( 'activity' ) && bp_is_root_blog( $wpdb->blogid ) ) {
19
  add_action( 'widgets_init', create_function( '', 'return register_widget("BP_Blogs_Recent_Posts_Widget");' ) );
20
- }
21
  }
22
  add_action( 'bp_register_widgets', 'bp_blogs_register_widgets' );
23
 
24
  /**
25
- * The Recent Networkwide Posts widget.
26
  */
27
  class BP_Blogs_Recent_Posts_Widget extends WP_Widget {
28
 
29
  /**
30
  * Constructor method.
31
  */
32
- public function __construct() {
33
  $widget_ops = array(
34
  'description' => __( 'A list of recently published posts from across your network.', 'buddypress' ),
35
  'classname' => 'widget_bp_blogs_widget buddypress widget',
@@ -42,52 +42,25 @@ class BP_Blogs_Recent_Posts_Widget extends WP_Widget {
42
  *
43
  * @see WP_Widget::widget() for description of parameters.
44
  *
45
- * @param array $args Widget arguments.
46
  * @param array $instance Widget settings, as saved by the user.
47
  */
48
- public function widget( $args, $instance ) {
49
 
50
- $title = ! empty( $instance['title'] )
51
- ? esc_html( $instance['title'] )
52
- : __( 'Recent Networkwide Posts', 'buddypress' );
53
 
54
  if ( ! empty( $instance['link_title'] ) ) {
55
- $title = '<a href="' . bp_get_blogs_directory_permalink() . '">' . esc_html( $title ) . '</a>';
56
  }
57
 
58
- /**
59
- * Filters the Blogs Recent Posts widget title.
60
- *
61
- * @since 2.2.0
62
- * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter.
63
- *
64
- * @param string $title The widget title.
65
- * @param array $instance The settings for the particular instance of the widget.
66
- * @param string $id_base Root ID for all widgets of this type.
67
- */
68
- $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
69
-
70
  echo $args['before_widget'];
71
  echo $args['before_title'] . $title . $args['after_title'];
72
 
73
- if ( empty( $instance['max_posts'] ) || empty( $instance['max_posts'] ) ) {
74
- $instance['max_posts'] = 10;
75
- }
76
 
77
- $after_widget = $args['after_widget'];
78
-
79
- // Override some of the contextually set parameters for bp_has_activities()
80
- $args = array(
81
- 'action' => 'new_blog_post',
82
- 'max' => $instance['max_posts'],
83
- 'per_page' => $instance['max_posts'],
84
- 'user_id' => 0,
85
- 'scope' => false,
86
- 'object' => false,
87
- 'primary_id' => false
88
- ); ?>
89
-
90
- <?php if ( bp_has_activities( $args ) ) : ?>
91
 
92
  <ul id="blog-post-list" class="activity-list item-list">
93
 
@@ -95,12 +68,15 @@ class BP_Blogs_Recent_Posts_Widget extends WP_Widget {
95
 
96
  <li>
97
  <div class="activity-content" style="margin: 0">
98
- <div class="activity-header"><?php bp_activity_action(); ?></div>
99
 
100
- <?php if ( bp_get_activity_content_body() ) : ?>
101
-
102
- <div class="activity-inner"><?php bp_activity_content_body(); ?></div>
103
 
 
 
 
 
104
  <?php endif; ?>
105
 
106
  </div>
@@ -111,14 +87,12 @@ class BP_Blogs_Recent_Posts_Widget extends WP_Widget {
111
  </ul>
112
 
113
  <?php else : ?>
114
-
115
  <div id="message" class="info">
116
- <p><?php _e( 'Sorry, there were no posts found. Why not write one?', 'buddypress' ); ?></p>
117
  </div>
118
-
119
  <?php endif; ?>
120
 
121
- <?php echo $after_widget; ?>
122
  <?php
123
  }
124
 
@@ -127,13 +101,12 @@ class BP_Blogs_Recent_Posts_Widget extends WP_Widget {
127
  *
128
  * @param array $new_instance The new instance options.
129
  * @param array $old_instance The old instance options.
130
- *
131
  * @return array $instance The parsed options to be saved.
132
  */
133
- public function update( $new_instance, $old_instance ) {
134
- $instance = $old_instance;
135
- $instance['title'] = strip_tags( $new_instance['title'] );
136
- $instance['max_posts'] = strip_tags( $new_instance['max_posts'] );
137
  $instance['link_title'] = (bool) $new_instance['link_title'];
138
 
139
  return $instance;
@@ -142,26 +115,24 @@ class BP_Blogs_Recent_Posts_Widget extends WP_Widget {
142
  /**
143
  * Output the networkwide posts widget options form.
144
  *
145
- * @param array $instance Settings for this widget.
146
- *
147
- * @return string
148
  */
149
- public function form( $instance ) {
150
  $instance = wp_parse_args( (array) $instance, array(
151
  'title' => __( 'Recent Networkwide Posts', 'buddypress' ),
152
  'max_posts' => 10,
153
  'link_title' => false,
154
  ) );
155
 
156
- $title = strip_tags( $instance['title'] );
157
- $max_posts = strip_tags( $instance['max_posts'] );
158
  $link_title = (bool) $instance['link_title'];
159
 
160
  ?>
161
 
162
- <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _ex( 'Title:', 'Label for the Title field of the Recent Networkwide Posts widget', 'buddypress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" style="width: 100%;" /></label></p>
163
- <p><label for="<?php echo $this->get_field_id( 'link_title' ); ?>"><input type="checkbox" name="<?php echo $this->get_field_name( 'link_title' ); ?>" value="1" <?php checked( $link_title ); ?> /> <?php _e( 'Link widget title to Blogs directory', 'buddypress' ); ?></label></p>
164
- <p><label for="<?php echo $this->get_field_id( 'max_posts' ); ?>"><?php _e( 'Max posts to show:', 'buddypress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_posts' ); ?>" name="<?php echo $this->get_field_name( 'max_posts' ); ?>" type="text" value="<?php echo esc_attr( $max_posts ); ?>" style="width: 30%" /></label></p>
165
  <?php
166
  }
167
  }
1
  <?php
2
+
3
  /**
4
+ * BuddyPress Blogs Widgets
5
  *
6
  * @package BuddyPress
7
  * @subpackage BlogsWidgets
8
  */
9
 
10
  // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
 
13
  /**
14
  * Register the widgets for the Blogs component.
16
  function bp_blogs_register_widgets() {
17
  global $wpdb;
18
 
19
+ if ( bp_is_active( 'activity' ) && (int) $wpdb->blogid == bp_get_root_blog_id() )
20
  add_action( 'widgets_init', create_function( '', 'return register_widget("BP_Blogs_Recent_Posts_Widget");' ) );
 
21
  }
22
  add_action( 'bp_register_widgets', 'bp_blogs_register_widgets' );
23
 
24
  /**
25
+ * The Recent Networkwide Posts widget
26
  */
27
  class BP_Blogs_Recent_Posts_Widget extends WP_Widget {
28
 
29
  /**
30
  * Constructor method.
31
  */
32
+ function __construct() {
33
  $widget_ops = array(
34
  'description' => __( 'A list of recently published posts from across your network.', 'buddypress' ),
35
  'classname' => 'widget_bp_blogs_widget buddypress widget',
42
  *
43
  * @see WP_Widget::widget() for description of parameters.
44
  *
45
+ * @param array $args Widget arguments.
46
  * @param array $instance Widget settings, as saved by the user.
47
  */
48
+ function widget( $args, $instance ) {
49
 
50
+ $title = ! empty( $instance['title'] ) ? esc_html( $instance['title'] ) : __( 'Recent Networkwide Posts', 'buddypress' );
 
 
51
 
52
  if ( ! empty( $instance['link_title'] ) ) {
53
+ $title = '<a href="' . trailingslashit( bp_get_root_domain() ) . trailingslashit( bp_get_blogs_root_slug() ) . '">' . esc_html( $title ) . '</a>';
54
  }
55
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  echo $args['before_widget'];
57
  echo $args['before_title'] . $title . $args['after_title'];
58
 
59
+ if ( empty( $instance['max_posts'] ) || !$instance['max_posts'] )
60
+ $instance['max_posts'] = 10; ?>
 
61
 
62
+ <?php // Override some of the contextually set parameters for bp_has_activities() ?>
63
+ <?php if ( bp_has_activities( array( 'action' => 'new_blog_post', 'max' => $instance['max_posts'], 'per_page' => $instance['max_posts'], 'user_id' => 0, 'scope' => false, 'object' => false, 'primary_id' => false ) ) ) : ?>
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
  <ul id="blog-post-list" class="activity-list item-list">
66
 
68
 
69
  <li>
70
  <div class="activity-content" style="margin: 0">
 
71
 
72
+ <div class="activity-header">
73
+ <?php bp_activity_action() ?>
74
+ </div>
75
 
76
+ <?php if ( bp_get_activity_content_body() ) : ?>
77
+ <div class="activity-inner">
78
+ <?php bp_activity_content_body() ?>
79
+ </div>
80
  <?php endif; ?>
81
 
82
  </div>
87
  </ul>
88
 
89
  <?php else : ?>
 
90
  <div id="message" class="info">
91
+ <p><?php _e( 'Sorry, there were no posts found. Why not write one?', 'buddypress' ) ?></p>
92
  </div>
 
93
  <?php endif; ?>
94
 
95
+ <?php echo $args['after_widget']; ?>
96
  <?php
97
  }
98
 
101
  *
102
  * @param array $new_instance The new instance options.
103
  * @param array $old_instance The old instance options.
 
104
  * @return array $instance The parsed options to be saved.
105
  */
106
+ function update( $new_instance, $old_instance ) {
107
+ $instance = $old_instance;
108
+ $instance['title'] = strip_tags( $new_instance['title'] );
109
+ $instance['max_posts'] = strip_tags( $new_instance['max_posts'] );
110
  $instance['link_title'] = (bool) $new_instance['link_title'];
111
 
112
  return $instance;
115
  /**
116
  * Output the networkwide posts widget options form.
117
  *
118
+ * @param $instance Settings for this widget.
 
 
119
  */
120
+ function form( $instance ) {
121
  $instance = wp_parse_args( (array) $instance, array(
122
  'title' => __( 'Recent Networkwide Posts', 'buddypress' ),
123
  'max_posts' => 10,
124
  'link_title' => false,
125
  ) );
126
 
127
+ $title = strip_tags( $instance['title'] );
128
+ $max_posts = strip_tags( $instance['max_posts'] );
129
  $link_title = (bool) $instance['link_title'];
130
 
131
  ?>
132
 
133
+ <p><label for="<?php echo $this->get_field_id( 'title' ) ?>"><?php _ex( 'Title:', 'Label for the Title field of the Recent Networkwide Posts widget', 'buddypress' ) ?> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ) ?>" name="<?php echo $this->get_field_name( 'title' ) ?>" type="text" value="<?php echo esc_attr( $title ) ?>" style="width: 100%;" /></label></p>
134
+ <p><label for="<?php echo $this->get_field_id( 'link_title' ) ?>"><input type="checkbox" name="<?php echo $this->get_field_name( 'link_title' ) ?>" value="1" <?php checked( $link_title ) ?> /> <?php _e( 'Link widget title to Blogs directory', 'buddypress' ) ?></label></p>
135
+ <p><label for="<?php echo $this->get_field_id( 'max_posts' ) ?>"><?php _e( 'Max posts to show:', 'buddypress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_posts' ); ?>" name="<?php echo $this->get_field_name( 'max_posts' ); ?>" type="text" value="<?php echo esc_attr( $max_posts ); ?>" style="width: 30%" /></label></p>
136
  <?php
137
  }
138
  }
bp-blogs/classes/class-bp-blogs-blog.php DELETED
@@ -1,619 +0,0 @@
1
- <?php
2
- /**
3
- * BuddyPress Blogs Classes.
4
- *
5
- * @package BuddyPress
6
- * @subpackage BlogsClasses
7
- */
8
-
9
- // Exit if accessed directly
10
- defined( 'ABSPATH' ) || exit;
11
-
12
- /**
13
- * The main BuddyPress blog class.
14
- *
15
- * A BP_Blogs_Object represents a link between a specific WordPress blog on a
16
- * network and a specific user on that blog.
17
- *
18
- * @since 1.0.0
19
- */
20
- class BP_Blogs_Blog {
21
- public $id;
22
- public $user_id;
23
- public $blog_id;
24
-
25
- /**
26
- * Constructor method.
27
- *
28
- * @param int $id Optional. The ID of the blog.
29
- */
30
- public function __construct( $id = null ) {
31
- if ( !empty( $id ) ) {
32
- $this->id = $id;
33
- $this->populate();
34
- }
35
- }
36
-
37
- /**
38
- * Populate the object with data about the specific activity item.
39
- */
40
- public function populate() {
41
- global $wpdb;
42
-
43
- $bp = buddypress();
44
-
45
- $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name} WHERE id = %d", $this->id ) );
46
-
47
- $this->user_id = $blog->user_id;
48
- $this->blog_id = $blog->blog_id;
49
- }
50
-
51
- /**
52
- * Save the BP blog data to the database.
53
- *
54
- * @return bool True on success, false on failure.
55
- */
56
- public function save() {
57
- global $wpdb;
58
-
59
- $this->user_id = apply_filters( 'bp_blogs_blog_user_id_before_save', $this->user_id, $this->id );
60
- $this->blog_id = apply_filters( 'bp_blogs_blog_id_before_save', $this->blog_id, $this->id );
61
-
62
- /**
63
- * Fires before the current blog item gets saved.
64
- *
65
- * Please use this hook to filter the properties above. Each part will be passed in.
66
- *
67
- * @since 1.0.0
68
- *
69
- * @param BP_Blogs_Blog $this Current instance of the blog item being saved. Passed by reference.
70
- */
71
- do_action_ref_array( 'bp_blogs_blog_before_save', array( &$this ) );
72
-
73
- // Don't try and save if there is no user ID or blog ID set.
74
- if ( !$this->user_id || !$this->blog_id )
75
- return false;
76
-
77
- // Don't save if this blog has already been recorded for the user.
78
- if ( !$this->id && $this->exists() )
79
- return false;
80
-
81
- $bp = buddypress();
82
-
83
- if ( $this->id ) {
84
- // Update
85
- $sql = $wpdb->prepare( "UPDATE {$bp->blogs->table_name} SET user_id = %d, blog_id = %d WHERE id = %d", $this->user_id, $this->blog_id, $this->id );
86
- } else {
87
- // Save
88
- $sql = $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name} ( user_id, blog_id ) VALUES ( %d, %d )", $this->user_id, $this->blog_id );
89
- }
90
-
91
- if ( !$wpdb->query($sql) )
92
- return false;
93
-
94
- /**
95
- * Fires after the current blog item gets saved.
96
- *
97
- * Please use this hook to filter the properties above. Each part will be passed in.
98
- *
99
- * @since 1.0.0
100
- *
101
- * @param BP_Blogs_Blog $this Current instance of the blog item being saved. Passed by reference.
102
- */
103
- do_action_ref_array( 'bp_blogs_blog_after_save', array( &$this ) );
104
-
105
- if ( $this->id )
106
- return $this->id;
107
- else
108
- return $wpdb->insert_id;
109
- }
110
-
111
- /**
112
- * Check whether an association between this user and this blog exists.
113
- *
114
- * @return int $value The number of associations between the user and blog
115
- * saved in the blog component tables.
116
- */
117
- public function exists() {
118
- global $wpdb;
119
-
120
- $bp = buddypress();
121
-
122
- return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $this->user_id, $this->blog_id ) );
123
- }
124
-
125
- /** Static Methods ***************************************************/
126
-
127
- /**
128
- * Retrieve a set of blog-user associations.
129
- *
130
- * @param string $type The order in which results should be returned.
131
- * 'active', 'alphabetical', 'newest', or 'random'.
132
- * @param int|bool $limit Optional. The maximum records to return.
133
- * Default: false.
134
- * @param int|bool $page Optional. The page of records to return.
135
- * Default: false (unlimited results).
136
- * @param int $user_id Optional. ID of the user whose blogs are being
137
- * retrieved. Default: 0.
138
- * @param string|bool $search_terms Optional. Search by text stored in
139
- * blogmeta (such as the blog name). Default: false.
140
- * @param bool $update_meta_cache Whether to pre-fetch metadata for
141
- * blogs. Default: true.
142
- * @param array|bool $include_blog_ids Array of blog IDs to include.
143
- *
144
- * @return array Multidimensional results array, structured as follows:
145
- * 'blogs' - Array of located blog objects
146
- * 'total' - A count of the total blogs matching the filter params
147
- */
148
- public static function get( $type, $limit = false, $page = false, $user_id = 0, $search_terms = false, $update_meta_cache = true, $include_blog_ids = false ) {
149
- global $wpdb;
150
-
151
- $bp = buddypress();
152
-
153
- if ( !is_user_logged_in() || ( !bp_current_user_can( 'bp_moderate' ) && ( $user_id != bp_loggedin_user_id() ) ) )
154
- $hidden_sql = "AND wb.public = 1";
155
- else
156
- $hidden_sql = '';
157
-
158
- $pag_sql = ( $limit && $page ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ) : '';
159
-
160
- $user_sql = !empty( $user_id ) ? $wpdb->prepare( " AND b.user_id = %d", $user_id ) : '';
161
-
162
- switch ( $type ) {
163
- case 'active': default:
164
- $order_sql = "ORDER BY bm.meta_value DESC";
165
- break;
166
- case 'alphabetical':
167
- $order_sql = "ORDER BY bm_name.meta_value ASC";
168
- break;
169
- case 'newest':
170
- $order_sql = "ORDER BY wb.registered DESC";
171
- break;
172
- case 'random':
173
- $order_sql = "ORDER BY RAND()";
174
- break;
175
- }
176
-
177
- $include_sql = '';
178
- $include_blog_ids = array_filter( wp_parse_id_list( $include_blog_ids ) );
179
- if ( ! empty( $include_blog_ids ) ) {
180
- $blog_ids_sql = implode( ',', $include_blog_ids );
181
- $include_sql = " AND b.blog_id IN ({$blog_ids_sql})";
182
- }
183
-
184
- if ( ! empty( $search_terms ) ) {
185
- $search_terms_like = '%' . bp_esc_like( $search_terms ) . '%';
186
- $search_terms_sql = $wpdb->prepare( 'AND (bm_name.meta_value LIKE %s OR bm_description.meta_value LIKE %s)', $search_terms_like, $search_terms_like );
187
- } else {
188
- $search_terms_sql = '';
189
- }
190
-
191
- $paged_blogs = $wpdb->get_results( "
192
- SELECT b.blog_id, b.user_id as admin_user_id, u.user_email as admin_user_email, wb.domain, wb.path, bm.meta_value as last_activity, bm_name.meta_value as name
193
- FROM
194
- {$bp->blogs->table_name} b
195
- LEFT JOIN {$bp->blogs->table_name_blogmeta} bm ON (b.blog_id = bm.blog_id)
196
- LEFT JOIN {$bp->blogs->table_name_blogmeta} bm_name ON (b.blog_id = bm_name.blog_id)
197
- LEFT JOIN {$bp->blogs->table_name_blogmeta} bm_description ON (b.blog_id = bm_description.blog_id)
198
- LEFT JOIN {$wpdb->base_prefix}blogs wb ON (b.blog_id = wb.blog_id)
199
- LEFT JOIN {$wpdb->users} u ON (b.user_id = u.ID)
200
- WHERE
201
- wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$hidden_sql}
202
- AND bm.meta_key = 'last_activity' AND bm_name.meta_key = 'name' AND bm_description.meta_key = 'description'
203
- {$search_terms_sql} {$user_sql} {$include_sql}
204
- GROUP BY b.blog_id {$order_sql} {$pag_sql}
205
- " );
206
-
207
- $total_blogs = $wpdb->get_var( "
208
- SELECT COUNT(DISTINCT b.blog_id)
209
- FROM
210
- {$bp->blogs->table_name} b
211
- LEFT JOIN {$wpdb->base_prefix}blogs wb ON (b.blog_id = wb.blog_id)
212
- LEFT JOIN {$bp->blogs->table_name_blogmeta} bm_name ON (b.blog_id = bm_name.blog_id)
213
- LEFT JOIN {$bp->blogs->table_name_blogmeta} bm_description ON (b.blog_id = bm_description.blog_id)
214
- WHERE
215
- wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$hidden_sql}
216
- AND
217
- bm_name.meta_key = 'name' AND bm_description.meta_key = 'description'
218
- {$search_terms_sql} {$user_sql} {$include_sql}
219
- " );
220
-
221
- $blog_ids = array();
222
- foreach ( (array) $paged_blogs as $blog ) {
223
- $blog_ids[] = (int) $blog->blog_id;
224
- }
225
-
226
- $paged_blogs = BP_Blogs_Blog::get_blog_extras( $paged_blogs, $blog_ids, $type );
227
-
228
- if ( $update_meta_cache ) {
229
- bp_blogs_update_meta_cache( $blog_ids );
230
- }
231
-
232
- return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
233
- }
234
-
235
- /**
236
- * Delete the record of a given blog for all users.
237
- *
238
- * @param int $blog_id The blog being removed from all users.
239
- * @return int|bool Number of rows deleted on success, false on failure.
240
- */
241
- public static function delete_blog_for_all( $blog_id ) {
242
- global $wpdb;
243
-
244
- bp_blogs_delete_blogmeta( $blog_id );
245
-
246
- $bp = buddypress();
247
-
248
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
249
- }
250
-
251
- /**
252
- * Delete the record of a given blog for a specific user.
253
- *
254
- * @param int $blog_id The blog being removed.
255
- * @param int $user_id Optional. The ID of the user from whom the blog is
256
- * being removed. If absent, defaults to the logged-in user ID.
257
- *
258
- * @return int|bool Number of rows deleted on success, false on failure.
259
- */
260
- public static function delete_blog_for_user( $blog_id, $user_id = null ) {
261
- global $wpdb;
262
-
263
- if ( !$user_id )
264
- $user_id = bp_loggedin_user_id();
265
-
266
- $bp = buddypress();
267
-
268
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $user_id, $blog_id ) );
269
- }
270
-
271
- /**
272
- * Delete all of a user's blog associations in the BP tables.
273
- *
274
- * @param int $user_id Optional. The ID of the user whose blog associations
275
- * are being deleted. If absent, defaults to logged-in user ID.
276
- *
277
- * @return int|bool Number of rows deleted on success, false on failure.
278
- */
279
- public static function delete_blogs_for_user( $user_id = null ) {
280
- global $wpdb;
281
-
282
- if ( !$user_id )
283
- $user_id = bp_loggedin_user_id();
284
-
285
- $bp = buddypress();
286
-
287
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) );
288
- }
289
-
290
- /**
291
- * Get all of a user's blogs, as tracked by BuddyPress.
292
- *
293
- * Note that this is different from the WordPress function
294
- * {@link get_blogs_of_user()}; the current method returns only those
295
- * blogs that have been recorded by BuddyPress, while the WP function
296
- * does a true query of a user's blog capabilities.
297
- *
298
- * @param int $user_id Optional. ID of the user whose blogs are being
299
- * queried. Defaults to logged-in user.
300
- * @param bool $show_hidden Optional. Whether to include blogs that are not marked
301
- * public. Defaults to true when viewing one's own profile.
302
- *
303
- * @return array Multidimensional results array, structured as follows:
304
- * 'blogs' - Array of located blog objects.
305
- * 'total' - A count of the total blogs for the user.
306
- */
307
- public static function get_blogs_for_user( $user_id = 0, $show_hidden = false ) {
308
- global $wpdb;
309
-
310
- $bp = buddypress();
311
-
312
- if ( !$user_id )
313
- $user_id = bp_displayed_user_id();
314
-
315
- // Show logged in users their hidden blogs.
316
- if ( !bp_is_my_profile() && !$show_hidden )
317
- $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id, b.id, bm1.meta_value as name, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND bm1.meta_key = 'name' AND wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ORDER BY b.blog_id", $user_id ) );
318
- else
319
- $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id, b.id, bm1.meta_value as name, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND bm1.meta_key = 'name' AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ORDER BY b.blog_id", $user_id ) );
320
-
321
- $total_blog_count = BP_Blogs_Blog::total_blog_count_for_user( $user_id );
322
-
323
- $user_blogs = array();
324
- foreach ( (array) $blogs as $blog ) {
325
- $user_blogs[$blog->blog_id] = new stdClass;
326
- $user_blogs[$blog->blog_id]->id = $blog->id;
327
- $user_blogs[$blog->blog_id]->blog_id = $blog->blog_id;
328
- $user_blogs[$blog->blog_id]->siteurl = ( is_ssl() ) ? 'https://' . $blog->domain . $blog->path : 'http://' . $blog->domain . $blog->path;
329
- $user_blogs[$blog->blog_id]->name = $blog->name;
330
- }
331
-
332
- return array( 'blogs' => $user_blogs, 'count' => $total_blog_count );
333
- }
334
-
335
- /**
336
- * Get IDs of all of a user's blogs, as tracked by BuddyPress.
337
- *
338
- * This method always includes hidden blogs.
339
- *
340
- * @param int $user_id Optional. ID of the user whose blogs are being
341
- * queried. Defaults to logged-in user.
342
- *
343
- * @return int The number of blogs associated with the user.
344
- */
345
- public static function get_blog_ids_for_user( $user_id = 0 ) {
346
- global $wpdb;
347
-
348
- $bp = buddypress();
349
-
350
- if ( !$user_id )
351
- $user_id = bp_displayed_user_id();
352
-
353
- return $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) );
354
- }
355
-
356
- /**
357
- * Check whether a blog has been recorded by BuddyPress.
358
- *
359
- * @param int $blog_id ID of the blog being queried.
360
- *
361
- * @return int|null The ID of the first located entry in the BP table
362
- * on success, otherwise null.
363
- */
364
- public static function is_recorded( $blog_id ) {
365
- global $wpdb;
366
-
367
- $bp = buddypress();
368
-
369
- return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
370
- }
371
-
372
- /**
373
- * Return a count of associated blogs for a given user.
374
- *
375
- * Includes hidden blogs when the logged-in user is the same as the
376
- * $user_id parameter, or when the logged-in user has the bp_moderate
377
- * cap.
378
- *
379
- * @param int $user_id Optional. ID of the user whose blogs are being
380
- * queried. Defaults to logged-in user.
381
- *
382
- * @return int Blog count for the user.
383
- */
384
- public static function total_blog_count_for_user( $user_id = null ) {
385
- global $wpdb;
386
-
387
- $bp = buddypress();
388
-
389
- if ( !$user_id )
390
- $user_id = bp_displayed_user_id();
391
-
392
- // If the user is logged in return the blog count including their hidden blogs.
393
- if ( ( is_user_logged_in() && $user_id == bp_loggedin_user_id() ) || bp_current_user_can( 'bp_moderate' ) ) {
394
- return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id ) );
395
- } else {
396
- return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id ) );
397
- }
398
- }
399
-
400
- /**
401
- * Return a list of blogs matching a search term.
402
- *
403
- * Matches against blog names and descriptions, as stored in the BP
404
- * blogmeta table.
405
- *
406
- * @param string $filter The search term.
407
- * @param int $limit Optional. The maximum number of items to return.
408
- * Default: null (no limit).
409
- * @param int $page Optional. The page of results to return. Default:
410
- * null (no limit).
411
- *
412
- * @return array Multidimensional results array, structured as follows:
413
- * 'blogs' - Array of located blog objects.
414
- * 'total' - A count of the total blogs matching the query.
415
- */
416
- public static function search_blogs( $filter, $limit = null, $page = null ) {
417
- global $wpdb;
418
-
419
- $search_terms_like = '%' . bp_esc_like( $filter ) . '%';
420
- $search_terms_sql = $wpdb->prepare( 'bm.meta_value LIKE %s', $search_terms_like );
421
-
422
- $hidden_sql = '';
423
- if ( !bp_current_user_can( 'bp_moderate' ) )
424
- $hidden_sql = "AND wb.public = 1";
425
-
426
- $pag_sql = '';
427
- if ( $limit && $page ) {
428
- $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
429
- }
430
-
431
- $bp = buddypress();
432
-
433
- $paged_blogs = $wpdb->get_results( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND {$search_terms_sql} ) {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY meta_value ASC{$pag_sql}" );
434
- $total_blogs = $wpdb->get_var( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND {$search_terms_sql} ) {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY meta_value ASC" );
435
-
436
- return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
437
- }
438
-
439
- /**
440
- * Retrieve a list of all blogs.
441
- *
442
- * Query will include hidden blogs if the logged-in user has the
443
- * 'bp_moderate' cap.
444
- *
445
- * @param int $limit Optional. The maximum number of items to return.
446
- * Default: null (no limit).
447
- * @param int $page Optional. The page of results to return. Default:
448
- * null (no limit).
449
- *
450
- * @return array Multidimensional results array, structured as follows:
451
- * 'blogs' - Array of located blog objects.
452
- * 'total' - A count of the total blogs.
453
- */
454
- public static function get_all( $limit = null, $page = null ) {
455
- global $wpdb;
456
-
457
- $bp = buddypress();
458
-
459
- $hidden_sql = !bp_current_user_can( 'bp_moderate' ) ? "AND wb.public = 1" : '';
460
- $pag_sql = ( $limit && $page ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ) : '';
461
-
462
- $paged_blogs = $wpdb->get_results( "SELECT DISTINCT b.blog_id FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 {$hidden_sql} {$pag_sql}" );
463
- $total_blogs = $wpdb->get_var( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 {$hidden_sql}" );
464
-
465
- return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
466
- }
467
-
468
- /**
469
- * Retrieve a list of blogs whose names start with a given letter.
470
- *
471
- * Query will include hidden blogs if the logged-in user has the
472
- * 'bp_moderate' cap.
473
- *
474
- * @param string $letter. The letter you're looking for.
475
- * @param int $limit Optional. The maximum number of items to return.
476
- * Default: null (no limit).
477
- * @param int $page Optional. The page of results to return. Default:
478
- * null (no limit).
479
- *
480
- * @return array Multidimensional results array, structured as follows:
481
- * 'blogs' - Array of located blog objects.
482
- * 'total' - A count of the total blogs matching the query.
483
- */
484
- public static function get_by_letter( $letter, $limit = null, $page = null ) {
485
- global $wpdb;
486
-
487
- $bp = buddypress();
488
-
489
- $letter_like = '%' . bp_esc_like( $letter ) . '%';
490
- $letter_sql = $wpdb->prepare( 'bm.meta_value LIKE %s', $letter_like );
491
-
492
- $hidden_sql = '';
493
- if ( !bp_current_user_can( 'bp_moderate' ) )
494
- $hidden_sql = "AND wb.public = 1";
495
-
496
- $pag_sql = '';
497
- if ( $limit && $page )
498
- $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
499
-
500
- $paged_blogs = $wpdb->get_results( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE bm.meta_key = 'name' AND {$letter_sql} {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY bm.meta_value ASC{$pag_sql}" );
501
- $total_blogs = $wpdb->get_var( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE bm.meta_key = 'name' AND {$letter_sql} {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY bm.meta_value ASC" );
502
-
503
- return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
504
- }
505
-
506
- /**
507
- * Fetch blog data not caught in the main query and append it to results array.
508
- *
509
- * Gets the following information, which is either unavailable at the
510
- * time of the original query, or is more efficient to look up in one
511
- * fell swoop:
512
- * - The latest post for each blog, include Featured Image data
513
- * - The blog description
514
- *
515
- * @param array $paged_blogs Array of results from the original query.
516
- * @param array $blog_ids Array of IDs returned from the original query.
517
- * @param string|bool $type Not currently used. Default: false.
518
- *
519
- * @return array $paged_blogs The located blogs array, with the extras added.
520
- */
521
- public static function get_blog_extras( &$paged_blogs, &$blog_ids, $type = false ) {
522
- global $wpdb;
523
-
524
- $bp = buddypress();
525
-
526
- if ( empty( $blog_ids ) )
527
- return $paged_blogs;
528
-
529
- $blog_ids = implode( ',', wp_parse_id_list( $blog_ids ) );
530
-
531
- for ( $i = 0, $count = count( $paged_blogs ); $i < $count; ++$i ) {
532
- $blog_prefix = $wpdb->get_blog_prefix( $paged_blogs[$i]->blog_id );
533
- $paged_blogs[$i]->latest_post = $wpdb->get_row( "SELECT ID, post_content, post_title, post_excerpt, guid FROM {$blog_prefix}posts WHERE post_status = 'publish' AND post_type = 'post' AND id != 1 ORDER BY id DESC LIMIT 1" );
534
- $images = array();
535
-
536
- // Add URLs to any Featured Image this post might have
537
- if ( ! empty( $paged_blogs[$i]->latest_post ) && has_post_thumbnail( $paged_blogs[$i]->latest_post->ID ) ) {
538
-
539
- // Grab 4 sizes of the image. Thumbnail.
540
- $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'thumbnail', false );
541
- if ( ! empty( $image ) )
542
- $images['thumbnail'] = $image[0];
543
-
544
- // Medium
545
- $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'medium', false );
546
- if ( ! empty( $image ) )
547
- $images['medium'] = $image[0];
548
-
549
- // Large
550
- $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'large', false );
551
- if ( ! empty( $image ) )
552
- $images['large'] = $image[0];
553
-
554
- // Post thumbnail
555
- $image = wp_get_attachment_image_src( get_post_thumbnail_id( $paged_blogs[$i]->latest_post->ID ), 'post-thumbnail', false );
556
- if ( ! empty( $image ) )
557
- $images['post-thumbnail'] = $image[0];
558
-
559
- // Add the images to the latest_post object
560
- $paged_blogs[$i]->latest_post->images = $images;
561
- }
562
- }
563
-
564
- /* Fetch the blog description for each blog (as it may be empty we can't fetch it in the main query). */
565
- $blog_descs = $wpdb->get_results( "SELECT blog_id, meta_value as description FROM {$bp->blogs->table_name_blogmeta} WHERE meta_key = 'description' AND blog_id IN ( {$blog_ids} )" );
566
-
567
- for ( $i = 0, $count = count( $paged_blogs ); $i < $count; ++$i ) {
568
- foreach ( (array) $blog_descs as $desc ) {
569
- if ( $desc->blog_id == $paged_blogs[$i]->blog_id )
570
- $paged_blogs[$i]->description = $desc->description;
571
- }
572
- }
573
-
574
- return $paged_blogs;
575
- }
576
-
577
- /**
578
- * Check whether a given blog is hidden.
579
- *
580
- * Checks the 'public' column in the wp_blogs table.
581
- *
582
- * @param int $blog_id The ID of the blog being checked.
583
- *
584
- * @return bool True if hidden (public = 0), false otherwise.
585
- */
586
- public static function is_hidden( $blog_id ) {
587
- global $wpdb;
588
-
589
- if ( !(int) $wpdb->get_var( $wpdb->prepare( "SELECT public FROM {$wpdb->base_prefix}blogs WHERE blog_id = %d", $blog_id ) ) ) {
590
- return true;
591
- }
592
-
593
- return false;
594
- }
595
-
596
- /**
597
- * Get ID of user-blog link.
598
- *
599
- * @param int $user_id ID of user.
600
- * @param int $blog_id ID of blog.
601
- *
602
- * @return int|bool ID of user-blog link, or false if not found.
603
- */
604
- public static function get_user_blog( $user_id, $blog_id ) {
605
- global $wpdb;
606
-
607
- $bp = buddypress();
608
-
609
- $user_blog = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $user_id, $blog_id ) );
610
-
611
- if ( empty( $user_blog ) ) {
612
- $user_blog = false;
613
- } else {
614
- $user_blog = intval( $user_blog );
615
- }
616
-
617
- return $user_blog;
618
- }
619
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-core/admin/{bp-core-admin-actions.php → bp-core-actions.php} RENAMED
@@ -1,12 +1,13 @@
1
  <?php
 
2
  /**
3
- * BuddyPress Admin Actions.
4
  *
5
  * This file contains the actions that are used through-out BuddyPress Admin. They
6
  * are consolidated here to make searching for them easier, and to help developers
7
  * understand at a glance the order in which things occur.
8
  *
9
- * There are a few common places that additional actions can currently be found.
10
  *
11
  * - BuddyPress: In {@link BuddyPress::setup_actions()} in BuddyPress.php
12
  * - Admin: More in {@link bp_Admin::setup_actions()} in admin.php
@@ -17,11 +18,11 @@
17
  * @see bp-core-filters.php
18
  */
19
 
20
- // Exit if accessed directly.
21
- defined( 'ABSPATH' ) || exit;
22
 
23
  /**
24
- * Attach BuddyPress to WordPress.
25
  *
26
  * BuddyPress uses its own internal actions to help aid in third-party plugin
27
  * development, and to limit the amount of potential future code changes when
@@ -59,16 +60,16 @@ add_action( 'bp_admin_menu', 'bp_admin_separator' );
59
 
60
  /**
61
  * When a new site is created in a multisite installation, run the activation
62
- * routine on that site.
63
  *
64
- * @since 1.7.0
65
  *
66
- * @param int $blog_id
67
- * @param int $user_id
68
  * @param string $domain
69
  * @param string $path
70
- * @param int $site_id
71
- * @param array $meta
72
  */
73
  function bp_new_site( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
74
 
@@ -79,18 +80,7 @@ function bp_new_site( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
79
  // Switch to the new blog
80
  switch_to_blog( $blog_id );
81
 
82
- /**
83
- * Fires the activation routine for a new site created in a multisite installation.
84
- *
85
- * @since 1.7.0
86
- *
87
- * @param int $blog_id ID of the blog being installed to.
88
- * @param int $user_id ID of the user the install is for.
89
- * @param string $domain Domain to use with the install.
90
- * @param string $path Path to use with the install.
91
- * @param int $site_id ID of the site being installed to.
92
- * @param array $meta Metadata to use with the site creation.
93
- */
94
  do_action( 'bp_new_site', $blog_id, $user_id, $domain, $path, $site_id, $meta );
95
 
96
  // restore original blog
@@ -100,137 +90,85 @@ function bp_new_site( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
100
  /** Sub-Actions ***************************************************************/
101
 
102
  /**
103
- * Piggy back admin_init action.
104
  *
105
- * @since 1.7.0
106
- * @uses do_action() Calls 'bp_admin_init'.
107
  */
108
  function bp_admin_init() {
109
-
110
- /**
111
- * Fires inside the bp_admin_init function.
112
- *
113
- * @since 1.6.0
114
- */
115
  do_action( 'bp_admin_init' );
116
  }
117
 
118
  /**
119
- * Piggy back admin_menu action.
120
  *
121
- * @since 1.7.0
122
- * @uses do_action() Calls 'bp_admin_menu'.
123
  */
124
  function bp_admin_menu() {
125
-
126
- /**
127
- * Fires inside the bp_admin_menu function.
128
- *
129
- * @since 1.7.0
130
- */
131
  do_action( 'bp_admin_menu' );
132
  }
133
 
134
  /**
135
- * Piggy back admin_head action.
136
  *
137
- * @since 1.7.0
138
- * @uses do_action() Calls 'bp_admin_head'.
139
  */
140
  function bp_admin_head() {
141
-
142
- /**
143
- * Fires inside the bp_admin_head function.
144
- *
145
- * @since 1.6.0
146
- */
147
  do_action( 'bp_admin_head' );
148
  }
149
 
150
  /**
151
- * Piggy back admin_notices action.
152
  *
153
- * @since 1.7.0
154
- * @uses do_action() Calls 'bp_admin_notices'.
155
  */
156
  function bp_admin_notices() {
157
-
158
- /**
159
- * Fires inside the bp_admin_notices function.
160
- *
161
- * @since 1.5.0
162
- */
163
  do_action( 'bp_admin_notices' );
164
  }
165
 
166
  /**
167
  * Piggy back admin_enqueue_scripts action.
168
  *
169
- * @since 1.7.0
170
  *
171
  * @uses do_action() Calls 'bp_admin_enqueue_scripts''.
172
  *
173
  * @param string $hook_suffix The current admin page, passed to
174
- * 'admin_enqueue_scripts'.
175
  */
176
  function bp_admin_enqueue_scripts( $hook_suffix = '' ) {
177
-
178
- /**
179
- * Fires inside the bp_admin_enqueue_scripts function.
180
- *
181
- * @since 1.7.0
182
- *
183
- * @param string $hook_suffix The current admin page, passed to admin_enqueue_scripts.
184
- */
185
  do_action( 'bp_admin_enqueue_scripts', $hook_suffix );
186
  }
187
 
188
  /**
189
- * Dedicated action to register BuddyPress importers.
190
  *
191
- * @since 1.7.0
192
- * @uses do_action() Calls 'bp_admin_notices'.
193
  */
194
  function bp_register_importers() {
195
-
196
- /**
197
- * Fires inside the bp_register_importers function.
198
- *
199
- * Used to register a BuddyPress importer.
200
- *
201
- * @since 1.7.0
202
- */
203
  do_action( 'bp_register_importers' );
204
  }
205
 
206
  /**
207
- * Dedicated action to register admin styles.
208
  *
209
- * @since 1.7.0
210
- * @uses do_action() Calls 'bp_admin_notices'.
211
  */
212
  function bp_register_admin_style() {
213
-
214
- /**
215
- * Fires inside the bp_register_admin_style function.
216
- *
217
- * @since 1.7.0
218
- */
219
  do_action( 'bp_register_admin_style' );
220
  }
221
 
222
  /**
223
- * Dedicated action to register admin settings.
224
  *
225
- * @since 1.7.0
226
- * @uses do_action() Calls 'bp_register_admin_settings'.
227
  */
228
  function bp_register_admin_settings() {
229
-
230
- /**
231
- * Fires inside the bp_register_admin_settings function.
232
- *
233
- * @since 1.6.0
234
- */
235
  do_action( 'bp_register_admin_settings' );
236
  }
1
  <?php
2
+
3
  /**
4
+ * BuddyPress Admin Actions
5
  *
6
  * This file contains the actions that are used through-out BuddyPress Admin. They
7
  * are consolidated here to make searching for them easier, and to help developers
8
  * understand at a glance the order in which things occur.
9
  *
10
+ * There are a few common places that additional actions can currently be found
11
  *
12
  * - BuddyPress: In {@link BuddyPress::setup_actions()} in BuddyPress.php
13
  * - Admin: More in {@link bp_Admin::setup_actions()} in admin.php
18
  * @see bp-core-filters.php
19
  */
20
 
21
+ // Exit if accessed directly
22
+ if ( !defined( 'ABSPATH' ) ) exit;
23
 
24
  /**
25
+ * Attach BuddyPress to WordPress
26
  *
27
  * BuddyPress uses its own internal actions to help aid in third-party plugin
28
  * development, and to limit the amount of potential future code changes when
60
 
61
  /**
62
  * When a new site is created in a multisite installation, run the activation
63
+ * routine on that site
64
  *
65
+ * @since BuddyPress (1.7)
66
  *
67
+ * @param int $blog_id
68
+ * @param int $user_id
69
  * @param string $domain
70
  * @param string $path
71
+ * @param int $site_id
72
+ * @param array() $meta
73
  */
74
  function bp_new_site( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
75
 
80
  // Switch to the new blog
81
  switch_to_blog( $blog_id );
82
 
83
+ // Do the BuddyPress activation routine
 
 
 
 
 
 
 
 
 
 
 
84
  do_action( 'bp_new_site', $blog_id, $user_id, $domain, $path, $site_id, $meta );
85
 
86
  // restore original blog
90
  /** Sub-Actions ***************************************************************/
91
 
92
  /**
93
+ * Piggy back admin_init action
94
  *
95
+ * @since BuddyPress (1.7)
96
+ * @uses do_action() Calls 'bp_admin_init'
97
  */
98
  function bp_admin_init() {
 
 
 
 
 
 
99
  do_action( 'bp_admin_init' );
100
  }
101
 
102
  /**
103
+ * Piggy back admin_menu action
104
  *
105
+ * @since BuddyPress (1.7)
106
+ * @uses do_action() Calls 'bp_admin_menu'
107
  */
108
  function bp_admin_menu() {
 
 
 
 
 
 
109
  do_action( 'bp_admin_menu' );
110
  }
111
 
112
  /**
113
+ * Piggy back admin_head action
114
  *
115
+ * @since BuddyPress (1.7)
116
+ * @uses do_action() Calls 'bp_admin_head'
117
  */
118
  function bp_admin_head() {
 
 
 
 
 
 
119
  do_action( 'bp_admin_head' );
120
  }
121
 
122
  /**
123
+ * Piggy back admin_notices action
124
  *
125
+ * @since BuddyPress (1.7)
126
+ * @uses do_action() Calls 'bp_admin_notices'
127
  */
128
  function bp_admin_notices() {
 
 
 
 
 
 
129
  do_action( 'bp_admin_notices' );
130
  }
131
 
132
  /**
133
  * Piggy back admin_enqueue_scripts action.
134
  *
135
+ * @since BuddyPress (1.7.0)
136
  *
137
  * @uses do_action() Calls 'bp_admin_enqueue_scripts''.
138
  *
139
  * @param string $hook_suffix The current admin page, passed to
140
+ * 'admin_enqueue_scripts'.
141
  */
142
  function bp_admin_enqueue_scripts( $hook_suffix = '' ) {
 
 
 
 
 
 
 
 
143
  do_action( 'bp_admin_enqueue_scripts', $hook_suffix );
144
  }
145
 
146
  /**
147
+ * Dedicated action to register BuddyPress importers
148
  *
149
+ * @since BuddyPress (1.7)
150
+ * @uses do_action() Calls 'bp_admin_notices'
151
  */
152
  function bp_register_importers() {
 
 
 
 
 
 
 
 
153
  do_action( 'bp_register_importers' );
154
  }
155
 
156
  /**
157
+ * Dedicated action to register admin styles
158
  *
159
+ * @since BuddyPress (1.7)
160
+ * @uses do_action() Calls 'bp_admin_notices'
161
  */
162
  function bp_register_admin_style() {
 
 
 
 
 
 
163
  do_action( 'bp_register_admin_style' );
164
  }
165
 
166
  /**
167
+ * Dedicated action to register admin settings
168
  *
169
+ * @since BuddyPress (1.7)
170
+ * @uses do_action() Calls 'bp_register_admin_settings'
171
  */
172
  function bp_register_admin_settings() {
 
 
 
 
 
 
173
  do_action( 'bp_register_admin_settings' );
174
  }
bp-core/admin/{bp-core-admin-components.php → bp-core-components.php} RENAMED
@@ -1,25 +1,27 @@
1
  <?php
 
2
  /**
3
- * BuddyPress Admin Component Functions.
4
  *
5
  * @package BuddyPress
6
  * @subpackage CoreAdministration
7
  */
8
 
9
- // Exit if accessed directly.
10
- defined( 'ABSPATH' ) || exit;
11
 
12
  /**
13
  * Renders the Component Setup admin panel.
14
  *
15
  * @package BuddyPress
16
- * @since 1.6.0
17
  * @uses bp_core_admin_component_options()
18
  */
19
  function bp_core_admin_components_settings() {
20
  ?>
21
 
22
  <div class="wrap">
 
23
 
24
  <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( __( 'Components', 'buddypress' ) ); ?></h2>
25
  <form action="" method="post" id="bp-admin-component-form">
@@ -42,21 +44,13 @@ function bp_core_admin_components_settings() {
42
  * Creates reusable markup for component setup on the Components and Pages dashboard panel.
43
  *
44
  * @package BuddyPress
45
- * @since 1.6.0
46
  * @todo Use settings API
47
  */
48
  function bp_core_admin_components_options() {
49
 
50
  // Declare local variables
51
  $deactivated_components = array();
52
-
53
- /**
54
- * Filters the array of available components.
55
- *
56
- * @since 1.5.0
57
- *
58
- * @param mixed $value Active components.
59
- */
60
  $active_components = apply_filters( 'bp_active_components', bp_get_option( 'bp-active-components' ) );
61
 
62
  // The default components (if none are previously selected)
@@ -147,11 +141,11 @@ function bp_core_admin_components_options() {
147
  } ?>
148
 
149
  <ul class="subsubsub">
150
- <li><a href="<?php echo esc_url( add_query_arg( array( 'page' => 'bp-components', 'action' => 'all' ), bp_get_admin_url( $page ) ) ); ?>" <?php if ( $action === 'all' ) : ?>class="current"<?php endif; ?>><?php printf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $all_count, 'plugins', 'buddypress' ), number_format_i18n( $all_count ) ); ?></a> | </li>
151
- <li><a href="<?php echo esc_url( add_query_arg( array( 'page' => 'bp-components', 'action' => 'active' ), bp_get_admin_url( $page ) ) ); ?>" <?php if ( $action === 'active' ) : ?>class="current"<?php endif; ?>><?php printf( _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', count( $active_components ), 'buddypress' ), number_format_i18n( count( $active_components ) ) ); ?></a> | </li>
152
- <li><a href="<?php echo esc_url( add_query_arg( array( 'page' => 'bp-components', 'action' => 'inactive' ), bp_get_admin_url( $page ) ) ); ?>" <?php if ( $action === 'inactive' ) : ?>class="current"<?php endif; ?>><?php printf( _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', count( $inactive_components ), 'buddypress' ), number_format_i18n( count( $inactive_components ) ) ); ?></a> | </li>
153
- <li><a href="<?php echo esc_url( add_query_arg( array( 'page' => 'bp-components', 'action' => 'mustuse' ), bp_get_admin_url( $page ) ) ); ?>" <?php if ( $action === 'mustuse' ) : ?>class="current"<?php endif; ?>><?php printf( _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', count( $required_components ), 'buddypress' ), number_format_i18n( count( $required_components ) ) ); ?></a> | </li>
154
- <li><a href="<?php echo esc_url( add_query_arg( array( 'page' => 'bp-components', 'action' => 'retired' ), bp_get_admin_url( $page ) ) ); ?>" <?php if ( $action === 'retired' ) : ?>class="current"<?php endif; ?>><?php printf( _n( 'Retired <span class="count">(%s)</span>', 'Retired <span class="count">(%s)</span>', count( $retired_components ), 'buddypress' ), number_format_i18n( count( $retired_components ) ) ); ?></a></li>
155
  </ul>
156
 
157
  <table class="widefat fixed plugins" cellspacing="0">
@@ -192,13 +186,11 @@ function bp_core_admin_components_options() {
192
 
193
  <?php endif; ?>
194
 
 
195
  </th>
196
  <td class="plugin-title" style="width: 190px;">
197
  <span></span>
198
- <label for="bp_components[<?php echo esc_attr( $name ); ?>]">
199
- <strong><?php echo esc_html( $labels['title'] ); ?></strong>
200
- </label>
201
-
202
  <div class="row-actions-visible">
203
 
204
  </div>
@@ -233,9 +225,9 @@ function bp_core_admin_components_options() {
233
  }
234
 
235
  /**
236
- * Handle saving the Component settings.
237
  *
238
- * @since 1.6.0
239
  * @todo Use settings API when it supports saving network settings
240
  */
241
  function bp_core_admin_components_settings_handler() {
@@ -255,7 +247,7 @@ function bp_core_admin_components_settings_handler() {
255
  $bp = buddypress();
256
 
257
  // Save settings and upgrade schema
258
- require_once( $bp->plugin_dir . '/bp-core/admin/bp-core-admin-schema.php' );
259
 
260
  $submitted = stripslashes_deep( $_POST['bp_components'] );
261
  $bp->active_components = bp_core_admin_get_active_components_from_submitted_settings( $submitted );
@@ -275,7 +267,7 @@ function bp_core_admin_components_settings_handler() {
275
  add_action( 'bp_admin_init', 'bp_core_admin_components_settings_handler' );
276
 
277
  /**
278
- * Calculates the components that should be active after save, based on submitted settings.
279
  *
280
  * The way that active components must be set after saving your settings must
281
  * be calculated differently depending on which of the Components subtabs you
@@ -294,11 +286,10 @@ add_action( 'bp_admin_init', 'bp_core_admin_components_settings_handler' );
294
  * is not present, before merging the submitted components with the active
295
  * ones.
296
  *
297
- * @since 1.7.0
298
- *
299
- * @param array $submitted This is the array of component settings coming from the POST
300
- * global. You should stripslashes_deep() before passing to this function.
301
  *
 
 
302
  * @return array The calculated list of component settings
303
  */
304
  function bp_core_admin_get_active_components_from_submitted_settings( $submitted ) {
@@ -335,15 +326,14 @@ function bp_core_admin_get_active_components_from_submitted_settings( $submitted
335
  }
336
 
337
  /**
338
- * Return a list of component information, optionally filtered by type.
339
  *
340
  * We use this information both to build the markup for the admin screens, as
341
  * well as to do some processing on settings data submitted from those screens.
342
  *
343
- * @since 1.7.0
344
- *
345
- * @param string $type 'all', 'optional', 'retired', 'required'.
346
  *
 
347
  * @return array An array of requested component data
348
  */
349
  function bp_core_admin_get_components( $type = 'all' ) {
@@ -364,7 +354,7 @@ function bp_core_admin_get_components( $type = 'all' ) {
364
  $retired_components = array(
365
  'forums' => array(
366
  'title' => __( 'Group Forums', 'buddypress' ),
367
- 'description' => sprintf( __( 'BuddyPress Forums are retired. Use %s.', 'buddypress' ), '<a href="https://bbpress.org/">bbPress</a>' )
368
  ),
369
  );
370
 
@@ -431,15 +421,5 @@ function bp_core_admin_get_components( $type = 'all' ) {
431
 
432
  }
433
 
434
- /**
435
- * Filters the list of component information.
436
- *
437
- * @since 2.0.0
438
- *
439
- * @param array $components Array of component information.
440
- * @param string $type Type of component list requested.
441
- * Possible values include 'all', 'optional',
442
- * 'retired', 'required'.
443
- */
444
  return apply_filters( 'bp_core_admin_get_components', $components, $type );
445
  }
1
  <?php
2
+
3
  /**
4
+ * BuddyPress Admin Component Functions
5
  *
6
  * @package BuddyPress
7
  * @subpackage CoreAdministration
8
  */
9
 
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
 
13
  /**
14
  * Renders the Component Setup admin panel.
15
  *
16
  * @package BuddyPress
17
+ * @since BuddyPress (1.6)
18
  * @uses bp_core_admin_component_options()
19
  */
20
  function bp_core_admin_components_settings() {
21
  ?>
22
 
23
  <div class="wrap">
24
+ <?php screen_icon( 'buddypress'); ?>
25
 
26
  <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( __( 'Components', 'buddypress' ) ); ?></h2>
27
  <form action="" method="post" id="bp-admin-component-form">
44
  * Creates reusable markup for component setup on the Components and Pages dashboard panel.
45
  *
46
  * @package BuddyPress
47
+ * @since BuddyPress (1.6)
48
  * @todo Use settings API
49
  */
50
  function bp_core_admin_components_options() {
51
 
52
  // Declare local variables
53
  $deactivated_components = array();
 
 
 
 
 
 
 
 
54
  $active_components = apply_filters( 'bp_active_components', bp_get_option( 'bp-active-components' ) );
55
 
56
  // The default components (if none are previously selected)
141
  } ?>
142
 
143
  <ul class="subsubsub">
144
+ <li><a href="<?php echo add_query_arg( array( 'page' => 'bp-components', 'action' => 'all' ), bp_get_admin_url( $page ) ); ?>" <?php if ( $action === 'all' ) : ?>class="current"<?php endif; ?>><?php printf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $all_count, 'plugins', 'buddypress' ), number_format_i18n( $all_count ) ); ?></a> | </li>
145
+ <li><a href="<?php echo add_query_arg( array( 'page' => 'bp-components', 'action' => 'active' ), bp_get_admin_url( $page ) ); ?>" <?php if ( $action === 'active' ) : ?>class="current"<?php endif; ?>><?php printf( _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', count( $active_components ), 'buddypress' ), number_format_i18n( count( $active_components ) ) ); ?></a> | </li>
146
+ <li><a href="<?php echo add_query_arg( array( 'page' => 'bp-components', 'action' => 'inactive' ), bp_get_admin_url( $page ) ); ?>" <?php if ( $action === 'inactive' ) : ?>class="current"<?php endif; ?>><?php printf( _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', count( $inactive_components ), 'buddypress' ), number_format_i18n( count( $inactive_components ) ) ); ?></a> | </li>
147
+ <li><a href="<?php echo add_query_arg( array( 'page' => 'bp-components', 'action' => 'mustuse' ), bp_get_admin_url( $page ) ); ?>" <?php if ( $action === 'mustuse' ) : ?>class="current"<?php endif; ?>><?php printf( _n( 'Must-Use <span class="count">(%s)</span>', 'Must-Use <span class="count">(%s)</span>', count( $required_components ), 'buddypress' ), number_format_i18n( count( $required_components ) ) ); ?></a> | </li>
148
+ <li><a href="<?php echo add_query_arg( array( 'page' => 'bp-components', 'action' => 'retired' ), bp_get_admin_url( $page ) ); ?>" <?php if ( $action === 'retired' ) : ?>class="current"<?php endif; ?>><?php printf( _n( 'Retired <span class="count">(%s)</span>', 'Retired <span class="count">(%s)</span>', count( $retired_components ), 'buddypress' ), number_format_i18n( count( $retired_components ) ) ); ?></a></li>
149
  </ul>
150
 
151
  <table class="widefat fixed plugins" cellspacing="0">
186
 
187
  <?php endif; ?>
188
 
189
+ <label class="screen-reader-text" for="bp_components[<?php echo esc_attr( $name ); ?>]"><?php sprintf( __( 'Select %s', 'buddypress' ), esc_html( $labels['title'] ) ); ?></label>
190
  </th>
191
  <td class="plugin-title" style="width: 190px;">
192
  <span></span>
193
+ <strong><?php echo esc_html( $labels['title'] ); ?></strong>
 
 
 
194
  <div class="row-actions-visible">
195
 
196
  </div>
225
  }
226
 
227
  /**
228
+ * Handle saving the Component settings
229
  *
230
+ * @since BuddyPress (1.6)
231
  * @todo Use settings API when it supports saving network settings
232
  */
233
  function bp_core_admin_components_settings_handler() {
247
  $bp = buddypress();
248
 
249
  // Save settings and upgrade schema
250
+ require_once( $bp->plugin_dir . '/bp-core/admin/bp-core-schema.php' );
251
 
252
  $submitted = stripslashes_deep( $_POST['bp_components'] );
253
  $bp->active_components = bp_core_admin_get_active_components_from_submitted_settings( $submitted );
267
  add_action( 'bp_admin_init', 'bp_core_admin_components_settings_handler' );
268
 
269
  /**
270
+ * Calculates the components that should be active after save, based on submitted settings
271
  *
272
  * The way that active components must be set after saving your settings must
273
  * be calculated differently depending on which of the Components subtabs you
286
  * is not present, before merging the submitted components with the active
287
  * ones.
288
  *
289
+ * @since (BuddyPress) 1.7
 
 
 
290
  *
291
+ * @param array This is the array of component settings coming from the POST
292
+ * global. You should stripslashes_deep() before passing to this function
293
  * @return array The calculated list of component settings
294
  */
295
  function bp_core_admin_get_active_components_from_submitted_settings( $submitted ) {
326
  }
327
 
328
  /**
329
+ * Return a list of component information, optionally filtered by type
330
  *
331
  * We use this information both to build the markup for the admin screens, as
332
  * well as to do some processing on settings data submitted from those screens.
333
  *
334
+ * @since (BuddyPress) 1.7
 
 
335
  *
336
+ * @param string $type 'all', 'optional', 'retired', 'required'
337
  * @return array An array of requested component data
338
  */
339
  function bp_core_admin_get_components( $type = 'all' ) {
354
  $retired_components = array(
355
  'forums' => array(
356
  'title' => __( 'Group Forums', 'buddypress' ),
357
+ 'description' => sprintf( __( 'BuddyPress Forums are retired. Use %s.', 'buddypress' ), '<a href="http://bbpress.org">bbPress</a>' )
358
  ),
359
  );
360
 
421
 
422
  }
423
 
 
 
 
 
 
 
 
 
 
 
424
  return apply_filters( 'bp_core_admin_get_components', $components, $type );
425
  }
bp-core/admin/{bp-core-admin-functions.php → bp-core-functions.php} RENAMED
@@ -1,13 +1,14 @@
1
  <?php
 
2
  /**
3
- * BuddyPress Common Admin Functions.
4
  *
5
  * @package BuddyPress
6
  * @subpackage CoreAdministration
7
  */
8
 
9
- // Exit if accessed directly.
10
- defined( 'ABSPATH' ) || exit;
11
 
12
  /** Menu **********************************************************************/
13
 
@@ -31,7 +32,7 @@ function bp_core_admin_menu_init() {
31
  * @global array $_parent_pages
32
  * @global array $_registered_pages
33
  * @global array $submenu
34
- * @since 1.6.0
35
  */
36
  function bp_core_admin_backpat_menu() {
37
  global $_parent_pages, $_registered_pages, $submenu;
@@ -70,15 +71,14 @@ add_action( bp_core_admin_hook(), 'bp_core_admin_backpat_menu', 999 );
70
  *
71
  * @global string $plugin_page
72
  * @global array $submenu
73
- * @since 1.6.0
74
  */
75
  function bp_core_modify_admin_menu_highlight() {
76
- global $plugin_page, $submenu_file;
77
 
78
  // This tweaks the Settings subnav menu to show only one BuddyPress menu item
79
- if ( ! in_array( $plugin_page, array( 'bp-activity', 'bp-general-settings', ) ) ) {
80
  $submenu_file = 'bp-components';
81
- }
82
 
83
  // Network Admin > Tools
84
  if ( in_array( $plugin_page, array( 'bp-tools', 'available-tools' ) ) ) {
@@ -92,7 +92,7 @@ function bp_core_modify_admin_menu_highlight() {
92
  * will never appear.
93
  *
94
  * @see bp_core_admin_backpat_menu()
95
- * @since 1.6.0
96
  * @todo Add convenience links into the markup once new positions are finalised.
97
  */
98
  function bp_core_admin_backpat_page() {
@@ -100,6 +100,7 @@ function bp_core_admin_backpat_page() {
100
  $settings_url = add_query_arg( 'page', 'bp-components', $url ); ?>
101
 
102
  <div class="wrap">
 
103
  <h2><?php _e( 'Why have all my BuddyPress menus disappeared?', 'buddypress' ); ?></h2>
104
 
105
  <p><?php _e( "Don't worry! We've moved the BuddyPress options into more convenient and easier to find locations. You're seeing this page because you are running a legacy BuddyPress plugin which has not been updated.", 'buddypress' ); ?></p>
@@ -112,14 +113,15 @@ function bp_core_admin_backpat_page() {
112
  /** Notices *******************************************************************/
113
 
114
  /**
115
- * Print admin messages to admin_notices or network_admin_notices.
116
  *
117
  * BuddyPress combines all its messages into a single notice, to avoid a preponderance of yellow
118
  * boxes.
119
  *
120
- * @since 1.5.0
 
121
  *
122
- * @uses bp_current_user_can() to check current user permissions before showing the notices.
123
  * @uses bp_is_root_blog()
124
  */
125
  function bp_core_print_admin_notices() {
@@ -135,39 +137,40 @@ function bp_core_print_admin_notices() {
135
  return;
136
  }
137
 
138
- $notice_types = array();
139
- foreach ( buddypress()->admin->notices as $notice ) {
140
- $notice_types[] = $notice['type'];
141
- }
142
- $notice_types = array_unique( $notice_types );
143
 
144
- foreach ( $notice_types as $type ) {
145
- $notices = wp_list_filter( buddypress()->admin->notices, array( 'type' => $type ) );
146
- printf( '<div id="message" class="fade %s">', sanitize_html_class( $type ) );
147
 
148
- foreach ( $notices as $notice ) {
149
- printf( '<p>%s</p>', $notice['message'] );
150
- }
151
 
152
- printf( '</div>' );
153
- }
 
 
 
 
 
 
 
154
  }
155
  add_action( 'admin_notices', 'bp_core_print_admin_notices' );
156
  add_action( 'network_admin_notices', 'bp_core_print_admin_notices' );
157
 
158
  /**
159
- * Add an admin notice to the BP queue.
160
  *
161
  * Messages added with this function are displayed in BuddyPress's general purpose admin notices
162
  * box. It is recommended that you hook this function to admin_init, so that your messages are
163
  * loaded in time.
164
  *
165
- * @since 1.5.0
 
166
  *
167
- * @param string $notice The notice you are adding to the queue.
168
- * @param string $type The notice type; optional. Usually either "updated" or "error".
169
  */
170
- function bp_core_add_admin_notice( $notice = '', $type = 'updated' ) {
171
 
172
  // Do not add if the notice is empty
173
  if ( empty( $notice ) ) {
@@ -180,40 +183,34 @@ function bp_core_add_admin_notice( $notice = '', $type = 'updated' ) {
180
  }
181
 
182
  // Add the notice
183
- buddypress()->admin->notices[] = array(
184
- 'message' => $notice,
185
- 'type' => $type,
186
- );
187
  }
188
 
189
  /**
190
- * Verify that some BP prerequisites are set up properly, and notify the admin if not.
191
  *
192
  * On every Dashboard page, this function checks the following:
193
- * - that pretty permalinks are enabled.
194
- * - that every BP component that needs a WP page for a directory has one.
195
- * - that no WP page has multiple BP components associated with it.
196
  * The administrator will be shown a notice for each check that fails.
197
  *
198
  * @global WPDB $wpdb WordPress DB object
199
  * @global WP_Rewrite $wp_rewrite
200
- * @since 1.2.0
201
  */
202
  function bp_core_activation_notice() {
203
- global $wp_rewrite, $wpdb;
 
 
204
 
205
  // Only the super admin gets warnings
206
  if ( ! bp_current_user_can( 'bp_moderate' ) ) {
207
  return;
208
  }
209
 
210
- // Bail in user admin
211
- if ( is_user_admin() ) {
212
- return;
213
- }
214
-
215
  // On multisite installs, don't load on a non-root blog, unless do_network_admin is overridden
216
- if ( is_multisite() && bp_core_do_network_admin() && ! bp_is_root_blog() ) {
217
  return;
218
  }
219
 
@@ -222,13 +219,17 @@ function bp_core_activation_notice() {
222
  return;
223
  }
224
 
 
 
 
 
 
225
  /**
226
- * Check to make sure that the blog setup routine has run. This can't
227
- * happen during the wizard because of the order which the components
228
- * are loaded.
229
  */
230
  if ( bp_is_active( 'blogs' ) ) {
231
- $bp = buddypress();
232
  $count = $wpdb->get_var( "SELECT COUNT(*) FROM {$bp->blogs->table_name}" );
233
 
234
  if ( empty( $count ) ) {
@@ -236,13 +237,16 @@ function bp_core_activation_notice() {
236
  }
237
  }
238
 
239
- // Add notice if no rewrite rules are enabled
240
- if ( empty( $wp_rewrite->permalink_structure ) ) {
241
- bp_core_add_admin_notice( sprintf( __( '<strong>BuddyPress is almost ready</strong>. You must <a href="%s">update your permalink structure</a> to something other than the default for it to work.', 'buddypress' ), admin_url( 'options-permalink.php' ) ), 'error' );
 
 
242
  }
243
 
244
- // Get BuddyPress instance
245
- $bp = buddypress();
 
246
 
247
  /**
248
  * Check for orphaned BP components (BP component is enabled, no WP page exists)
@@ -274,7 +278,7 @@ function bp_core_activation_notice() {
274
  );
275
  }
276
 
277
- // On the first admin screen after a new installation, this isn't set, so grab it to suppress a misleading error message.
278
  if ( empty( $bp->pages->members ) ) {
279
  $bp->pages = bp_core_get_directory_pages();
280
  }
@@ -296,7 +300,7 @@ function bp_core_activation_notice() {
296
 
297
  if ( !empty( $orphaned_components ) ) {
298
  $admin_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) );
299
- $notice = sprintf( __( 'The following active BuddyPress Components do not have associated WordPress Pages: %2$s. <a href="%1$s">Repair</a>', 'buddypress' ), esc_url( $admin_url ), '<strong>' . implode( '</strong>, <strong>', $orphaned_components ) . '</strong>' );
300
 
301
  bp_core_add_admin_notice( $notice );
302
  }
@@ -318,40 +322,38 @@ function bp_core_activation_notice() {
318
  // If there are duplicates, post a message about them
319
  if ( !empty( $dupe_names ) ) {
320
  $admin_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) );
321
- $notice = sprintf( __( 'Each BuddyPress Component needs its own WordPress page. The following WordPress Pages have more than one component associated with them: %2$s. <a href="%1$s">Repair</a>', 'buddypress' ), esc_url( $admin_url ), '<strong>' . implode( '</strong>, <strong>', $dupe_names ) . '</strong>' );
322
 
323
  bp_core_add_admin_notice( $notice );
324
  }
325
  }
326
 
327
  /**
328
- * Redirect user to BuddyPress's What's New page on activation.
329
  *
330
- * @since 1.7.0
331
  *
332
- * @internal Used internally to redirect BuddyPress to the about page on activation.
333
  *
334
- * @uses get_transient() To see if transient to redirect exists.
335
- * @uses delete_transient() To delete the transient if it exists.
336
- * @uses is_network_admin() To bail if being network activated.
337
- * @uses wp_safe_redirect() To redirect.
338
- * @uses add_query_arg() To help build the URL to redirect to.
339
- * @uses admin_url() To get the admin URL to index.php.
340
  */
341
  function bp_do_activation_redirect() {
342
 
343
  // Bail if no activation redirect
344
- if ( ! get_transient( '_bp_activation_redirect' ) ) {
345
  return;
346
- }
347
 
348
  // Delete the redirect transient
349
  delete_transient( '_bp_activation_redirect' );
350
 
351
  // Bail if activating from network, or bulk
352
- if ( isset( $_GET['activate-multi'] ) ) {
353
  return;
354
- }
355
 
356
  $query_args = array( 'page' => 'bp-about' );
357
  if ( get_transient( '_bp_is_new_install' ) ) {
@@ -366,53 +368,19 @@ function bp_do_activation_redirect() {
366
  /** UI/Styling ****************************************************************/
367
 
368
  /**
369
- * Output the tabs in the admin area.
370
  *
371
- * @since 1.5.0
372
- *
373
- * @param string $active_tab Name of the tab that is active. Optional.
374
  */
375
  function bp_core_admin_tabs( $active_tab = '' ) {
 
 
376
  $tabs_html = '';
377
  $idle_class = 'nav-tab';
378
  $active_class = 'nav-tab nav-tab-active';
379
 
380
- /**
381
- * Filters the admin tabs to be displayed.
382
- *
383
- * @since 1.9.0
384
- *
385
- * @param array $value Array of tabs to output to the admin area.
386
- */
387
- $tabs = apply_filters( 'bp_core_admin_tabs', bp_core_get_admin_tabs( $active_tab ) );
388
-
389
- // Loop through tabs and build navigation
390
- foreach ( array_values( $tabs ) as $tab_data ) {
391
- $is_current = (bool) ( $tab_data['name'] == $active_tab );
392
- $tab_class = $is_current ? $active_class : $idle_class;
393
- $tabs_html .= '<a href="' . esc_url( $tab_data['href'] ) . '" class="' . esc_attr( $tab_class ) . '">' . esc_html( $tab_data['name'] ) . '</a>';
394
- }
395
-
396
- echo $tabs_html;
397
-
398
- /**
399
- * Fires after the output of tabs for the admin area.
400
- *
401
- * @since 1.5.0
402
- */
403
- do_action( 'bp_admin_tabs' );
404
- }
405
-
406
- /**
407
- * Get the data for the tabs in the admin area.
408
- *
409
- * @since 2.2.0
410
- *
411
- * @param string $active_tab Name of the tab that is active. Optional.
412
- *
413
- * @return string
414
- */
415
- function bp_core_get_admin_tabs( $active_tab = '' ) {
416
  $tabs = array(
417
  '0' => array(
418
  'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bp-components' ), 'admin.php' ) ),
@@ -441,25 +409,30 @@ function bp_core_get_admin_tabs( $active_tab = '' ) {
441
  );
442
  }
443
 
444
- /**
445
- * Filters the tab data used in our wp-admin screens.
446
- *
447
- * @since 2.2.0
448
- *
449
- * @param array $tabs Tab data.
450
- */
451
- return apply_filters( 'bp_core_get_admin_tabs', $tabs );
 
 
 
 
 
 
 
452
  }
453
 
454
  /** Help **********************************************************************/
455
 
456
  /**
457
- * adds contextual help to BuddyPress admin pages.
458
  *
459
- * @since 1.7.0
460
  * @todo Make this part of the BP_Component class and split into each component
461
- *
462
- * @param string $screen
463
  */
464
  function bp_core_add_contextual_help( $screen = '' ) {
465
 
@@ -467,7 +440,7 @@ function bp_core_add_contextual_help( $screen = '' ) {
467
 
468
  switch ( $screen->id ) {
469
 
470
- // Component page
471
  case 'settings_page_bp-components' :
472
 
473
  // help tabs
@@ -480,8 +453,8 @@ function bp_core_add_contextual_help( $screen = '' ) {
480
  // help panel - sidebar links
481
  $screen->set_help_sidebar(
482
  '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
483
- '<p>' . __( '<a href="https://codex.buddypress.org/getting-started/configure-components/">Managing Components</a>', 'buddypress' ) . '</p>' .
484
- '<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
485
  );
486
  break;
487
 
@@ -498,8 +471,8 @@ function bp_core_add_contextual_help( $screen = '' ) {
498
  // Help panel - sidebar links
499
  $screen->set_help_sidebar(
500
  '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
501
- '<p>' . __( '<a href="https://codex.buddypress.org/getting-started/configure-components/#settings-buddypress-pages">Managing Pages</a>', 'buddypress' ) . '</p>' .
502
- '<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
503
  );
504
 
505
  break;
@@ -517,8 +490,8 @@ function bp_core_add_contextual_help( $screen = '' ) {
517
  // Help panel - sidebar links
518
  $screen->set_help_sidebar(
519
  '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
520
- '<p>' . __( '<a href="https://codex.buddypress.org/getting-started/configure-components/#settings-buddypress-settings">Managing Settings</a>', 'buddypress' ) . '</p>' .
521
- '<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
522
  );
523
 
524
  break;
@@ -536,8 +509,8 @@ function bp_core_add_contextual_help( $screen = '' ) {
536
  // Help panel - sidebar links
537
  $screen->set_help_sidebar(
538
  '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
539
- '<p>' . __( '<a href="https://codex.buddypress.org/administrator-guide/extended-profiles/">Managing Profile Fields</a>', 'buddypress' ) . '</p>' .
540
- '<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
541
  );
542
 
543
  break;
@@ -546,31 +519,27 @@ function bp_core_add_contextual_help( $screen = '' ) {
546
  add_action( 'contextual_help', 'bp_core_add_contextual_help' );
547
 
548
  /**
549
- * renders contextual help content to contextual help tabs.
550
  *
551
- * @since 1.7.0
552
- *
553
- * @param string $tab
554
- *
555
- * @return string
556
  */
557
  function bp_core_add_contextual_help_content( $tab = '' ) {
558
 
559
  switch ( $tab ) {
560
  case 'bp-comp-overview' :
561
- $retval = __( 'By default, all but four of the BuddyPress components are enabled. You can selectively enable or disable any of the components by using the form below. Your BuddyPress installation will continue to function. However, the features of the disabled components will no longer be accessible to anyone using the site.', 'buddypress' );
562
  break;
563
 
564
  case 'bp-page-overview' :
565
- $retval = __( 'BuddyPress Components use WordPress Pages for their root directory/archive pages. You can change the page associations for each active component by using the form below.', 'buddypress' );
566
  break;
567
 
568
  case 'bp-settings-overview' :
569
- $retval = __( 'Extra configuration settings are provided and activated. You can selectively enable or disable any setting by using the form on this screen.', 'buddypress' );
570
  break;
571
 
572
  case 'bp-profile-overview' :
573
- $retval = __( 'Your users will distinguish themselves through their profile page. Create relevant profile fields that will show on each users profile.', 'buddypress' ) . '<br /><br />' . __( 'Note: Any fields in the first group will appear on the signup page.', 'buddypress' );
574
  break;
575
 
576
  default:
@@ -589,34 +558,30 @@ function bp_core_add_contextual_help_content( $tab = '' ) {
589
  /** Separator *****************************************************************/
590
 
591
  /**
592
- * Add a separator to the WordPress admin menus.
593
  *
594
- * @since 1.7.0
595
  *
596
- * @uses bp_current_user_can() To check users capability on root blog.
597
  */
598
  function bp_admin_separator() {
599
 
600
  // Bail if BuddyPress is not network activated and viewing network admin
601
- if ( is_network_admin() && ! bp_is_network_activated() ) {
602
  return;
603
- }
604
 
605
  // Bail if BuddyPress is network activated and viewing site admin
606
- if ( ! is_network_admin() && bp_is_network_activated() ) {
607
  return;
608
- }
609
 
610
  // Prevent duplicate separators when no core menu items exist
611
- if ( ! bp_current_user_can( 'bp_moderate' ) ) {
612
  return;
613
- }
614
 
615
  // Bail if there are no components with admin UI's. Hardcoded for now, until
616
  // there's a real API for determining this later.
617
- if ( ! bp_is_active( 'activity' ) && ! bp_is_active( 'groups' ) ) {
618
  return;
619
- }
620
 
621
  global $menu;
622
 
@@ -624,41 +589,37 @@ function bp_admin_separator() {
624
  }
625
 
626
  /**
627
- * Tell WordPress we have a custom menu order.
628
  *
629
- * @since 1.7.0
630
- * @uses bp_current_user_can() To check users capability on root blog.
631
- *
632
- * @param bool $menu_order Menu order.
633
  *
 
 
634
  * @return bool Always true
635
  */
636
  function bp_admin_custom_menu_order( $menu_order = false ) {
637
 
638
  // Bail if user cannot see admin pages
639
- if ( ! bp_current_user_can( 'bp_moderate' ) ) {
640
  return $menu_order;
641
- }
642
 
643
  return true;
644
  }
645
 
646
  /**
647
- * Move our custom separator above our custom post types.
648
  *
649
- * @since 1.7.0
650
- * @uses bp_current_user_can() To check users capability on root blog.
651
- *
652
- * @param array $menu_order Menu Order.
653
  *
 
 
654
  * @return array Modified menu order
655
  */
656
  function bp_admin_menu_order( $menu_order = array() ) {
657
 
658
  // Bail if user cannot see admin pages
659
- if ( empty( $menu_order ) || ! bp_current_user_can( 'bp_moderate' ) ) {
660
  return $menu_order;
661
- }
662
 
663
  // Initialize our custom order array
664
  $bp_menu_order = array();
@@ -666,19 +627,12 @@ function bp_admin_menu_order( $menu_order = array() ) {
666
  // Menu values
667
  $last_sep = is_network_admin() ? 'separator1' : 'separator2';
668
 
669
- /**
670
- * Filters the custom admin menus.
671
- *
672
- * @since 1.7.0
673
- *
674
- * @param array $value Empty array.
675
- */
676
  $custom_menus = (array) apply_filters( 'bp_admin_menu_order', array() );
677
 
678
  // Bail if no components have top level admin pages
679
- if ( empty( $custom_menus ) ) {
680
  return $menu_order;
681
- }
682
 
683
  // Add our separator to beginning of array
684
  array_unshift( $custom_menus, 'separator-buddypress' );
@@ -712,14 +666,13 @@ function bp_admin_menu_order( $menu_order = array() ) {
712
  /** Utility *****************************************************************/
713
 
714
  /**
715
- * When using a WP_List_Table, get the currently selected bulk action.
716
  *
717
  * WP_List_Tables have bulk actions at the top and at the bottom of the tables,
718
  * and the inputs have different keys in the $_REQUEST array. This function
719
  * reconciles the two values and returns a single action being performed.
720
  *
721
- * @since 1.7.0
722
- *
723
  * @return string
724
  */
725
  function bp_admin_list_table_current_bulk_action() {
@@ -737,9 +690,9 @@ function bp_admin_list_table_current_bulk_action() {
737
  /** Menus *********************************************************************/
738
 
739
  /**
740
- * Register meta box and associated JS for BuddyPress WP Nav Menu.
741
  *
742
- * @since 1.9.0
743
  */
744
  function bp_admin_wp_nav_menu_meta_box() {
745
  if ( ! bp_is_root_blog() ) {
@@ -754,7 +707,7 @@ function bp_admin_wp_nav_menu_meta_box() {
754
  /**
755
  * Build and populate the BuddyPress accordion on Appearance > Menus.
756
  *
757
- * @since 1.9.0
758
  *
759
  * @global $nav_menu_selected_id
760
  */
@@ -818,9 +771,9 @@ function bp_admin_do_wp_nav_menu_meta_box() {
818
  * - URL - This field is automatically generated by BP on output, so this
819
  * field is useless and can cause confusion.
820
  *
821
- * Note: These restrictions are only enforced if JavaScript is enabled.
822
  *
823
- * @since 1.9.0
824
  */
825
  function bp_admin_wp_nav_menu_restrict_items() {
826
  ?>
@@ -841,53 +794,32 @@ function bp_admin_wp_nav_menu_restrict_items() {
841
  /**
842
  * Add "Mark as Spam/Ham" button to user row actions.
843
  *
844
- * @since 2.0.0
845
  *
846
- * @param array $actions User row action links.
847
  * @param object $user_object Current user information.
848
- *
849
  * @return array $actions User row action links.
850
  */
851
  function bp_core_admin_user_row_actions( $actions, $user_object ) {
852
 
853
- // Setup the $user_id variable from the current user object
854
- $user_id = 0;
855
- if ( !empty( $user_object->ID ) ) {
856
- $user_id = absint( $user_object->ID );
857
- }
858
-
859
- // Bail early if user cannot perform this action, or is looking at themselves
860
- if ( current_user_can( 'edit_user', $user_id ) && ( bp_loggedin_user_id() !== $user_id ) ) {
861
 
862
- // Admin URL could be single site or network
863
  $url = bp_get_admin_url( 'users.php' );
864
 
865
- // If spammed, create unspam link
866
- if ( bp_is_user_spammer( $user_id ) ) {
867
- $url = add_query_arg( array( 'action' => 'ham', 'user' => $user_id ), $url );
868
- $unspam_link = wp_nonce_url( $url, 'bp-spam-user' );
869
- $actions['ham'] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $unspam_link ), esc_html__( 'Not Spam', 'buddypress' ) );
870
-
871
- // If not already spammed, create spam link
872
  } else {
873
- $url = add_query_arg( array( 'action' => 'spam', 'user' => $user_id ), $url );
874
- $spam_link = wp_nonce_url( $url, 'bp-spam-user' );
875
- $actions['spam'] = sprintf( '<a class="submitdelete" href="%1$s">%2$s</a>', esc_url( $spam_link ), esc_html__( 'Spam', 'buddypress' ) );
876
  }
877
  }
878
 
879
- // Create a "View" link
880
- $url = bp_core_get_user_domain( $user_id );
881
- $actions['view'] = sprintf( '<a href="%1$s">%2$s</a>', esc_url( $url ), esc_html__( 'View', 'buddypress' ) );
882
-
883
- // Return new actions
884
  return $actions;
885
  }
886
 
887
  /**
888
  * Catch requests to mark individual users as spam/ham from users.php.
889
  *
890
- * @since 2.0.0
891
  */
892
  function bp_core_admin_user_manage_spammers() {
893
 
@@ -921,7 +853,7 @@ function bp_core_admin_user_manage_spammers() {
921
  // Process the user
922
  bp_core_process_spammer_status( $user_id, $status );
923
 
924
- $redirect = add_query_arg( array( 'updated' => 'marked-' . $status ), $redirect );
925
 
926
  wp_redirect( $redirect );
927
  }
@@ -942,7 +874,7 @@ function bp_core_admin_user_manage_spammers() {
942
  /**
943
  * Inline script that adds the 'site-spammed' class to spammed users.
944
  *
945
- * @since 2.0.0
946
  */
947
  function bp_core_admin_user_spammed_js() {
948
  ?>
1
  <?php
2
+
3
  /**
4
+ * BuddyPress Common Admin Functions
5
  *
6
  * @package BuddyPress
7
  * @subpackage CoreAdministration
8
  */
9
 
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
 
13
  /** Menu **********************************************************************/
14
 
32
  * @global array $_parent_pages
33
  * @global array $_registered_pages
34
  * @global array $submenu
35
+ * @since BuddyPress (1.6)
36
  */
37
  function bp_core_admin_backpat_menu() {
38
  global $_parent_pages, $_registered_pages, $submenu;
71
  *
72
  * @global string $plugin_page
73
  * @global array $submenu
74
+ * @since BuddyPress (1.6)
75
  */
76
  function bp_core_modify_admin_menu_highlight() {
77
+ global $pagenow, $plugin_page, $submenu_file;
78
 
79
  // This tweaks the Settings subnav menu to show only one BuddyPress menu item
80
+ if ( ! in_array( $plugin_page, array( 'bp-activity', 'bp-general-settings', ) ) )
81
  $submenu_file = 'bp-components';
 
82
 
83
  // Network Admin > Tools
84
  if ( in_array( $plugin_page, array( 'bp-tools', 'available-tools' ) ) ) {
92
  * will never appear.
93
  *
94
  * @see bp_core_admin_backpat_menu()
95
+ * @since BuddyPress (1.6)
96
  * @todo Add convenience links into the markup once new positions are finalised.
97
  */
98
  function bp_core_admin_backpat_page() {
100
  $settings_url = add_query_arg( 'page', 'bp-components', $url ); ?>
101
 
102
  <div class="wrap">
103
+ <?php screen_icon( 'buddypress' ); ?>
104
  <h2><?php _e( 'Why have all my BuddyPress menus disappeared?', 'buddypress' ); ?></h2>
105
 
106
  <p><?php _e( "Don't worry! We've moved the BuddyPress options into more convenient and easier to find locations. You're seeing this page because you are running a legacy BuddyPress plugin which has not been updated.", 'buddypress' ); ?></p>
113
  /** Notices *******************************************************************/
114
 
115
  /**
116
+ * Print admin messages to admin_notices or network_admin_notices
117
  *
118
  * BuddyPress combines all its messages into a single notice, to avoid a preponderance of yellow
119
  * boxes.
120
  *
121
+ * @package BuddyPress Core
122
+ * @since BuddyPress (1.5)
123
  *
124
+ * @uses bp_current_user_can() to check current user permissions before showing the notices
125
  * @uses bp_is_root_blog()
126
  */
127
  function bp_core_print_admin_notices() {
137
  return;
138
  }
139
 
140
+ // Get the admin notices
141
+ $admin_notices = buddypress()->admin->notices;
 
 
 
142
 
143
+ // Show the messages
144
+ if ( !empty( $admin_notices ) ) : ?>
 
145
 
146
+ <div id="message" class="updated fade">
 
 
147
 
148
+ <?php foreach ( $admin_notices as $notice ) : ?>
149
+
150
+ <p><?php echo $notice; ?></p>
151
+
152
+ <?php endforeach; ?>
153
+
154
+ </div>
155
+
156
+ <?php endif;
157
  }
158
  add_action( 'admin_notices', 'bp_core_print_admin_notices' );
159
  add_action( 'network_admin_notices', 'bp_core_print_admin_notices' );
160
 
161
  /**
162
+ * Add an admin notice to the BP queue
163
  *
164
  * Messages added with this function are displayed in BuddyPress's general purpose admin notices
165
  * box. It is recommended that you hook this function to admin_init, so that your messages are
166
  * loaded in time.
167
  *
168
+ * @package BuddyPress Core
169
+ * @since BuddyPress (1.5)
170
  *
171
+ * @param string $notice The notice you are adding to the queue
 
172
  */
173
+ function bp_core_add_admin_notice( $notice = '' ) {
174
 
175
  // Do not add if the notice is empty
176
  if ( empty( $notice ) ) {
183
  }
184
 
185
  // Add the notice
186
+ buddypress()->admin->notices[] = $notice;
 
 
 
187
  }
188
 
189
  /**
190
+ * Verify that some BP prerequisites are set up properly, and notify the admin if not
191
  *
192
  * On every Dashboard page, this function checks the following:
193
+ * - that pretty permalinks are enabled
194
+ * - that every BP component that needs a WP page for a directory has one
195
+ * - that no WP page has multiple BP components associated with it
196
  * The administrator will be shown a notice for each check that fails.
197
  *
198
  * @global WPDB $wpdb WordPress DB object
199
  * @global WP_Rewrite $wp_rewrite
200
+ * @since BuddyPress (1.2)
201
  */
202
  function bp_core_activation_notice() {
203
+ global $wpdb, $wp_rewrite;
204
+
205
+ $bp = buddypress();
206
 
207
  // Only the super admin gets warnings
208
  if ( ! bp_current_user_can( 'bp_moderate' ) ) {
209
  return;
210
  }
211
 
 
 
 
 
 
212
  // On multisite installs, don't load on a non-root blog, unless do_network_admin is overridden
213
+ if ( is_multisite() && bp_core_do_network_admin() && !bp_is_root_blog() ) {
214
  return;
215
  }
216
 
219
  return;
220
  }
221
 
222
+ // Bail in network admin
223
+ if ( is_user_admin() ) {
224
+ return;
225
+ }
226
+
227
  /**
228
+ * Check to make sure that the blog setup routine has run. This can't happen during the
229
+ * wizard because of the order which the components are loaded. We check for multisite here
230
+ * on the off chance that someone has activated the blogs component and then disabled MS
231
  */
232
  if ( bp_is_active( 'blogs' ) ) {
 
233
  $count = $wpdb->get_var( "SELECT COUNT(*) FROM {$bp->blogs->table_name}" );
234
 
235
  if ( empty( $count ) ) {
237
  }
238
  }
239
 
240
+ /**
241
+ * Are pretty permalinks enabled?
242
+ */
243
+ if ( isset( $_POST['permalink_structure'] ) ) {
244
+ return;
245
  }
246
 
247
+ if ( empty( $wp_rewrite->permalink_structure ) ) {
248
+ bp_core_add_admin_notice( sprintf( __( '<strong>BuddyPress is almost ready</strong>. You must <a href="%s">update your permalink structure</a> to something other than the default for it to work.', 'buddypress' ), admin_url( 'options-permalink.php' ) ) );
249
+ }
250
 
251
  /**
252
  * Check for orphaned BP components (BP component is enabled, no WP page exists)
278
  );
279
  }
280
 
281
+ // On the first admin screen after a new installation, this isn't set, so grab it to supress a misleading error message.
282
  if ( empty( $bp->pages->members ) ) {
283
  $bp->pages = bp_core_get_directory_pages();
284
  }
300
 
301
  if ( !empty( $orphaned_components ) ) {
302
  $admin_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) );
303
+ $notice = sprintf( __( 'The following active BuddyPress Components do not have associated WordPress Pages: %2$s. <a href="%1$s">Repair</a>', 'buddypress' ), $admin_url, '<strong>' . implode( '</strong>, <strong>', $orphaned_components ) . '</strong>' );
304
 
305
  bp_core_add_admin_notice( $notice );
306
  }
322
  // If there are duplicates, post a message about them
323
  if ( !empty( $dupe_names ) ) {
324
  $admin_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) );
325
+ $notice = sprintf( __( 'Each BuddyPress Component needs its own WordPress page. The following WordPress Pages have more than one component associated with them: %2$s. <a href="%1$s">Repair</a>', 'buddypress' ), $admin_url, '<strong>' . implode( '</strong>, <strong>', $dupe_names ) . '</strong>' );
326
 
327
  bp_core_add_admin_notice( $notice );
328
  }
329
  }
330
 
331
  /**
332
+ * Redirect user to BuddyPress's What's New page on activation
333
  *
334
+ * @since BuddyPress (1.7)
335
  *
336
+ * @internal Used internally to redirect BuddyPress to the about page on activation
337
  *
338
+ * @uses get_transient() To see if transient to redirect exists
339
+ * @uses delete_transient() To delete the transient if it exists
340
+ * @uses is_network_admin() To bail if being network activated
341
+ * @uses wp_safe_redirect() To redirect
342
+ * @uses add_query_arg() To help build the URL to redirect to
343
+ * @uses admin_url() To get the admin URL to index.php
344
  */
345
  function bp_do_activation_redirect() {
346
 
347
  // Bail if no activation redirect
348
+ if ( ! get_transient( '_bp_activation_redirect' ) )
349
  return;
 
350
 
351
  // Delete the redirect transient
352
  delete_transient( '_bp_activation_redirect' );
353
 
354
  // Bail if activating from network, or bulk
355
+ if ( isset( $_GET['activate-multi'] ) )
356
  return;
 
357
 
358
  $query_args = array( 'page' => 'bp-about' );
359
  if ( get_transient( '_bp_is_new_install' ) ) {
368
  /** UI/Styling ****************************************************************/
369
 
370
  /**
371
+ * Output the tabs in the admin area
372
  *
373
+ * @since BuddyPress (1.5)
374
+ * @param string $active_tab Name of the tab that is active
 
375
  */
376
  function bp_core_admin_tabs( $active_tab = '' ) {
377
+
378
+ // Declare local variables
379
  $tabs_html = '';
380
  $idle_class = 'nav-tab';
381
  $active_class = 'nav-tab nav-tab-active';
382
 
383
+ // Setup core admin tabs
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
384
  $tabs = array(
385
  '0' => array(
386
  'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bp-components' ), 'admin.php' ) ),
409
  );
410
  }
411
 
412
+ // Allow the tabs to be filtered
413
+ $tabs = apply_filters( 'bp_core_admin_tabs', $tabs );
414
+
415
+ // Loop through tabs and build navigation
416
+ foreach ( array_values( $tabs ) as $tab_data ) {
417
+ $is_current = (bool) ( $tab_data['name'] == $active_tab );
418
+ $tab_class = $is_current ? $active_class : $idle_class;
419
+ $tabs_html .= '<a href="' . esc_url( $tab_data['href'] ) . '" class="' . esc_attr( $tab_class ) . '">' . esc_html( $tab_data['name'] ) . '</a>';
420
+ }
421
+
422
+ // Output the tabs
423
+ echo $tabs_html;
424
+
425
+ // Do other fun things
426
+ do_action( 'bp_admin_tabs' );
427
  }
428
 
429
  /** Help **********************************************************************/
430
 
431
  /**
432
+ * adds contextual help to BuddyPress admin pages
433
  *
434
+ * @since BuddyPress (1.7)
435
  * @todo Make this part of the BP_Component class and split into each component
 
 
436
  */
437
  function bp_core_add_contextual_help( $screen = '' ) {
438
 
440
 
441
  switch ( $screen->id ) {
442
 
443
+ // Compontent page
444
  case 'settings_page_bp-components' :
445
 
446
  // help tabs
453
  // help panel - sidebar links
454
  $screen->set_help_sidebar(
455
  '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
456
+ '<p>' . __( '<a href="http://codex.buddypress.org/getting-started/configure-buddypress-components/#settings-buddypress-components">Managing Components</a>', 'buddypress' ) . '</p>' .
457
+ '<p>' . __( '<a href="http://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
458
  );
459
  break;
460
 
471
  // Help panel - sidebar links
472
  $screen->set_help_sidebar(
473
  '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
474
+ '<p>' . __( '<a href="http://codex.buddypress.org/getting-started/configure-buddypress-components/#settings-buddypress-pages">Managing Pages</a>', 'buddypress' ) . '</p>' .
475
+ '<p>' . __( '<a href="http://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
476
  );
477
 
478
  break;
490
  // Help panel - sidebar links
491
  $screen->set_help_sidebar(
492
  '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
493
+ '<p>' . __( '<a href="http://codex.buddypress.org/getting-started/configure-buddypress-components/#settings-buddypress-settings">Managing Settings</a>', 'buddypress' ) . '</p>' .
494
+ '<p>' . __( '<a href="http://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
495
  );
496
 
497
  break;
509
  // Help panel - sidebar links
510
  $screen->set_help_sidebar(
511
  '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
512
+ '<p>' . __( '<a href="http://codex.buddypress.org/getting-started/configure-buddypress-components/#users-profile-fields">Managing Profile Fields</a>', 'buddypress' ) . '</p>' .
513
+ '<p>' . __( '<a href="http://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
514
  );
515
 
516
  break;
519
  add_action( 'contextual_help', 'bp_core_add_contextual_help' );
520
 
521
  /**
522
+ * renders contextual help content to contextual help tabs
523
  *
524
+ * @since BuddyPress (1.7)
 
 
 
 
525
  */
526
  function bp_core_add_contextual_help_content( $tab = '' ) {
527
 
528
  switch ( $tab ) {
529
  case 'bp-comp-overview' :
530
+ $retval = __( 'By default, all BuddyPress components are enabled. You can selectively disable any of the components by using the form. Your BuddyPress installation will continue to function. However, the features of the disabled components will no longer be accessible to anyone using the site.', 'buddypress' );
531
  break;
532
 
533
  case 'bp-page-overview' :
534
+ $retval = __( 'BuddyPress Components use WordPress Pages for their root directory/archive pages. Here you can change the page associations for each active component.', 'buddypress' );
535
  break;
536
 
537
  case 'bp-settings-overview' :
538
+ $retval = __( 'Extra configuration settings.', 'buddypress' );
539
  break;
540
 
541
  case 'bp-profile-overview' :
542
+ $retval = __( 'Your users will distinguish themselves through their profile page. Create relevant profile fields that will show on each users profile.</br></br>Note: Any fields in the first group will appear on the signup page.', 'buddypress' );
543
  break;
544
 
545
  default:
558
  /** Separator *****************************************************************/
559
 
560
  /**
561
+ * Add a separator to the WordPress admin menus
562
  *
563
+ * @since BuddyPress (1.7)
564
  *
565
+ * @uses bp_current_user_can() To check users capability on root blog
566
  */
567
  function bp_admin_separator() {
568
 
569
  // Bail if BuddyPress is not network activated and viewing network admin
570
+ if ( is_network_admin() && ! bp_is_network_activated() )
571
  return;
 
572
 
573
  // Bail if BuddyPress is network activated and viewing site admin
574
+ if ( ! is_network_admin() && bp_is_network_activated() )
575
  return;
 
576
 
577
  // Prevent duplicate separators when no core menu items exist
578
+ if ( ! bp_current_user_can( 'bp_moderate' ) )
579
  return;
 
580
 
581
  // Bail if there are no components with admin UI's. Hardcoded for now, until
582
  // there's a real API for determining this later.
583
+ if ( ! bp_is_active( 'activity' ) && ! bp_is_active( 'groups' ) )
584
  return;
 
585
 
586
  global $menu;
587
 
589
  }
590
 
591
  /**
592
+ * Tell WordPress we have a custom menu order
593
  *
594
+ * @since BuddyPress (1.7)
 
 
 
595
  *
596
+ * @param bool $menu_order Menu order
597
+ * @uses bp_current_user_can() To check users capability on root blog
598
  * @return bool Always true
599
  */
600
  function bp_admin_custom_menu_order( $menu_order = false ) {
601
 
602
  // Bail if user cannot see admin pages
603
+ if ( ! bp_current_user_can( 'bp_moderate' ) )
604
  return $menu_order;
 
605
 
606
  return true;
607
  }
608
 
609
  /**
610
+ * Move our custom separator above our custom post types
611
  *
612
+ * @since BuddyPress (1.7)
 
 
 
613
  *
614
+ * @param array $menu_order Menu Order
615
+ * @uses bp_current_user_can() To check users capability on root blog
616
  * @return array Modified menu order
617
  */
618
  function bp_admin_menu_order( $menu_order = array() ) {
619
 
620
  // Bail if user cannot see admin pages
621
+ if ( empty( $menu_order ) || ! bp_current_user_can( 'bp_moderate' ) )
622
  return $menu_order;
 
623
 
624
  // Initialize our custom order array
625
  $bp_menu_order = array();
627
  // Menu values
628
  $last_sep = is_network_admin() ? 'separator1' : 'separator2';
629
 
630
+ // Filter the custom admin menus
 
 
 
 
 
 
631
  $custom_menus = (array) apply_filters( 'bp_admin_menu_order', array() );
632
 
633
  // Bail if no components have top level admin pages
634
+ if ( empty( $custom_menus ) )
635
  return $menu_order;
 
636
 
637
  // Add our separator to beginning of array
638
  array_unshift( $custom_menus, 'separator-buddypress' );
666
  /** Utility *****************************************************************/
667
 
668
  /**
669
+ * When using a WP_List_Table, get the currently selected bulk action
670
  *
671
  * WP_List_Tables have bulk actions at the top and at the bottom of the tables,
672
  * and the inputs have different keys in the $_REQUEST array. This function
673
  * reconciles the two values and returns a single action being performed.
674
  *
675
+ * @since BuddyPress (1.7)
 
676
  * @return string
677
  */
678
  function bp_admin_list_table_current_bulk_action() {
690
  /** Menus *********************************************************************/
691
 
692
  /**
693
+ * Register meta box and associated JS for BuddyPress WP Nav Menu .
694
  *
695
+ * @since BuddyPress (1.9.0)
696
  */
697
  function bp_admin_wp_nav_menu_meta_box() {
698
  if ( ! bp_is_root_blog() ) {
707
  /**
708
  * Build and populate the BuddyPress accordion on Appearance > Menus.
709
  *
710
+ * @since BuddyPress (1.9.0)
711
  *
712
  * @global $nav_menu_selected_id
713
  */
771
  * - URL - This field is automatically generated by BP on output, so this
772
  * field is useless and can cause confusion.
773
  *
774
+ * Note: These restrictions are only enforced if javascript is enabled.
775
  *
776
+ * @since BuddyPress (1.9.0)
777
  */
778
  function bp_admin_wp_nav_menu_restrict_items() {
779
  ?>
794
  /**
795
  * Add "Mark as Spam/Ham" button to user row actions.
796
  *
797
+ * @since BuddyPress (2.0.0)
798
  *
799
+ * @param array $actions User row action links.
800
  * @param object $user_object Current user information.
 
801
  * @return array $actions User row action links.
802
  */
803
  function bp_core_admin_user_row_actions( $actions, $user_object ) {
804
 
805
+ if ( current_user_can( 'edit_user', $user_object->ID ) && bp_loggedin_user_id() != $user_object->ID ) {
 
 
 
 
 
 
 
806
 
 
807
  $url = bp_get_admin_url( 'users.php' );
808
 
809
+ if ( bp_is_user_spammer( $user_object->ID ) ) {
810
+ $actions['ham'] = "<a href='" . wp_nonce_url( $url . "?action=ham&amp;user=$user_object->ID", 'bp-spam-user' ) . "'>" . __( 'Not Spam', 'buddypress' ) . "</a>";
 
 
 
 
 
811
  } else {
812
+ $actions['spam'] = "<a class='submitdelete' href='" . wp_nonce_url( $url . "?action=spam&amp;user=$user_object->ID", 'bp-spam-user' ) . "'>" . __( 'Mark as Spam', 'buddypress' ) . "</a>";
 
 
813
  }
814
  }
815
 
 
 
 
 
 
816
  return $actions;
817
  }
818
 
819
  /**
820
  * Catch requests to mark individual users as spam/ham from users.php.
821
  *
822
+ * @since BuddyPress (2.0.0)
823
  */
824
  function bp_core_admin_user_manage_spammers() {
825
 
853
  // Process the user
854
  bp_core_process_spammer_status( $user_id, $status );
855
 
856
+ $redirect = add_query_arg( array( 'updated' => 'marked-' . $status ), $redirect);
857
 
858
  wp_redirect( $redirect );
859
  }
874
  /**
875
  * Inline script that adds the 'site-spammed' class to spammed users.
876
  *
877
+ * @since BuddyPress (2.0.0)
878
  */
879
  function bp_core_admin_user_spammed_js() {
880
  ?>
bp-core/admin/{bp-core-admin-schema.php → bp-core-schema.php} RENAMED
@@ -1,142 +1,89 @@
1
  <?php
2
  /**
3
- * BuddyPress DB schema.
4
  *
5
  * @package BuddyPress
6
  * @subpackage CoreAdministration
7
  */
8
 
9
- // Exit if accessed directly.
10
- defined( 'ABSPATH' ) || exit;
11
 
12
- /**
13
- * Get the DB schema to use for BuddyPress components.
14
- *
15
- * @since 1.1.0
16
- *
17
- * @global $wpdb $wpdb
18
- * @return string The default database character-set, if set.
19
- */
20
  function bp_core_set_charset() {
21
  global $wpdb;
22
 
23
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
24
 
 
25
  return !empty( $wpdb->charset ) ? "DEFAULT CHARACTER SET {$wpdb->charset}" : '';
26
  }
27
 
28
- /**
29
- * Main installer.
30
- *
31
- * Can be passed an optional array of components to explicitly run installation
32
- * routines on, typically the first time a component is activated in Settings.
33
- *
34
- * @since 1.0.0
35
- *
36
- * @param array|bool $active_components Components to install.
37
- */
38
  function bp_core_install( $active_components = false ) {
39
 
40
- bp_pre_schema_upgrade();
41
-
42
- // If no components passed, get all the active components from the main site
43
- if ( empty( $active_components ) ) {
44
-
45
- /** This filter is documented in bp-core/admin/bp-core-admin-components.php */
46
  $active_components = apply_filters( 'bp_active_components', bp_get_option( 'bp-active-components' ) );
47
- }
48
 
49
- // Install Activity Streams even when inactive (to store last_activity data)
 
50
  bp_core_install_activity_streams();
51
 
52
- // Install the signups table
53
- bp_core_maybe_install_signups();
54
-
55
  // Notifications
56
- if ( !empty( $active_components['notifications'] ) ) {
57
  bp_core_install_notifications();
58
- }
59
 
60
  // Friend Connections
61
- if ( !empty( $active_components['friends'] ) ) {
62
  bp_core_install_friends();
63
- }
64
 
65
  // Extensible Groups
66
- if ( !empty( $active_components['groups'] ) ) {
67
  bp_core_install_groups();
68
- }
69
 
70
  // Private Messaging
71
- if ( !empty( $active_components['messages'] ) ) {
72
  bp_core_install_private_messaging();
73
- }
74
 
75
  // Extended Profiles
76
- if ( !empty( $active_components['xprofile'] ) ) {
77
  bp_core_install_extended_profiles();
78
- }
79
 
80
  // Blog tracking
81
- if ( !empty( $active_components['blogs'] ) ) {
82
  bp_core_install_blog_tracking();
83
- }
 
 
84
  }
85
 
86
- /**
87
- * Install database tables for the Notifications component.
88
- *
89
- * @since 1.0.0
90
- *
91
- * @uses bp_core_set_charset()
92
- * @uses bp_core_get_table_prefix()
93
- * @uses dbDelta()
94
- */
95
  function bp_core_install_notifications() {
 
96
  $sql = array();
97
  $charset_collate = bp_core_set_charset();
98
  $bp_prefix = bp_core_get_table_prefix();
99
 
100
  $sql[] = "CREATE TABLE {$bp_prefix}bp_notifications (
101
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
102
- user_id bigint(20) NOT NULL,
103
- item_id bigint(20) NOT NULL,
104
- secondary_item_id bigint(20),
105
- component_name varchar(75) NOT NULL,
106
- component_action varchar(75) NOT NULL,
107
- date_notified datetime NOT NULL,
108
- is_new bool NOT NULL DEFAULT 0,
109
- KEY item_id (item_id),
110
- KEY secondary_item_id (secondary_item_id),
111
- KEY user_id (user_id),
112
- KEY is_new (is_new),
113
- KEY component_name (component_name),
114
- KEY component_action (component_action),
115
- KEY useritem (user_id,is_new)
116
- ) {$charset_collate};";
117
-
118
- $sql[] = "CREATE TABLE {$bp_prefix}bp_notifications_meta (
119
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
120
- notification_id bigint(20) NOT NULL,
121
- meta_key varchar(255) DEFAULT NULL,
122
- meta_value longtext DEFAULT NULL,
123
- KEY notification_id (notification_id),
124
- KEY meta_key (meta_key(191))
125
- ) {$charset_collate};";
126
 
127
  dbDelta( $sql );
128
  }
129
 
130
- /**
131
- * Install database tables for the Activity component.
132
- *
133
- * @since 1.0.0
134
- *
135
- * @uses bp_core_set_charset()
136
- * @uses bp_core_get_table_prefix()
137
- * @uses dbDelta()
138
- */
139
  function bp_core_install_activity_streams() {
 
140
  $sql = array();
141
  $charset_collate = bp_core_set_charset();
142
  $bp_prefix = bp_core_get_table_prefix();
@@ -148,7 +95,7 @@ function bp_core_install_activity_streams() {
148
  type varchar(75) NOT NULL,
149
  action text NOT NULL,
150
  content longtext NOT NULL,
151
- primary_link text NOT NULL,
152
  item_id bigint(20) NOT NULL,
153
  secondary_item_id bigint(20) DEFAULT NULL,
154
  date_recorded datetime NOT NULL,
@@ -174,69 +121,53 @@ function bp_core_install_activity_streams() {
174
  meta_key varchar(255) DEFAULT NULL,
175
  meta_value longtext DEFAULT NULL,
176
  KEY activity_id (activity_id),
177
- KEY meta_key (meta_key(191))
178
- ) {$charset_collate};";
179
 
180
  dbDelta( $sql );
181
  }
182
 
183
- /**
184
- * Install database tables for the Notifications component.
185
- *
186
- * @since 1.0.0
187
- *
188
- * @uses bp_core_set_charset()
189
- * @uses bp_core_get_table_prefix()
190
- * @uses dbDelta()
191
- */
192
  function bp_core_install_friends() {
 
193
  $sql = array();
194
  $charset_collate = bp_core_set_charset();
195
  $bp_prefix = bp_core_get_table_prefix();
196
 
197
  $sql[] = "CREATE TABLE {$bp_prefix}bp_friends (
198
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
199
- initiator_user_id bigint(20) NOT NULL,
200
- friend_user_id bigint(20) NOT NULL,
201
- is_confirmed bool DEFAULT 0,
202
- is_limited bool DEFAULT 0,
203
- date_created datetime NOT NULL,
204
- KEY initiator_user_id (initiator_user_id),
205
- KEY friend_user_id (friend_user_id)
206
- ) {$charset_collate};";
207
 
208
  dbDelta( $sql );
209
  }
210
 
211
- /**
212
- * Install database tables for the Groups component.
213
- *
214
- * @since 1.0.0
215
- *
216
- * @uses bp_core_set_charset()
217
- * @uses bp_core_get_table_prefix()
218
- * @uses dbDelta()
219
- */
220
  function bp_core_install_groups() {
 
221
  $sql = array();
222
  $charset_collate = bp_core_set_charset();
223
  $bp_prefix = bp_core_get_table_prefix();
224
 
225
  $sql[] = "CREATE TABLE {$bp_prefix}bp_groups (
226
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
227
  creator_id bigint(20) NOT NULL,
228
- name varchar(100) NOT NULL,
229
- slug varchar(200) NOT NULL,
230
- description longtext NOT NULL,
231
  status varchar(10) NOT NULL DEFAULT 'public',
232
  enable_forum tinyint(1) NOT NULL DEFAULT '1',
233
  date_created datetime NOT NULL,
234
- KEY creator_id (creator_id),
235
- KEY status (status)
236
- ) {$charset_collate};";
237
 
238
  $sql[] = "CREATE TABLE {$bp_prefix}bp_groups_members (
239
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
240
  group_id bigint(20) NOT NULL,
241
  user_id bigint(20) NOT NULL,
242
  inviter_id bigint(20) NOT NULL,
@@ -251,10 +182,10 @@ function bp_core_install_groups() {
251
  KEY group_id (group_id),
252
  KEY is_admin (is_admin),
253
  KEY is_mod (is_mod),
254
- KEY user_id (user_id),
255
  KEY inviter_id (inviter_id),
256
  KEY is_confirmed (is_confirmed)
257
- ) {$charset_collate};";
258
 
259
  $sql[] = "CREATE TABLE {$bp_prefix}bp_groups_groupmeta (
260
  id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
@@ -262,81 +193,55 @@ function bp_core_install_groups() {
262
  meta_key varchar(255) DEFAULT NULL,
263
  meta_value longtext DEFAULT NULL,
264
  KEY group_id (group_id),
265
- KEY meta_key (meta_key(191))
266
- ) {$charset_collate};";
267
 
268
  dbDelta( $sql );
269
  }
270
 
271
- /**
272
- * Install database tables for the Messages component.
273
- *
274
- * @since 1.0.0
275
- *
276
- * @uses bp_core_set_charset()
277
- * @uses bp_core_get_table_prefix()
278
- * @uses dbDelta()
279
- */
280
  function bp_core_install_private_messaging() {
 
281
  $sql = array();
282
  $charset_collate = bp_core_set_charset();
283
  $bp_prefix = bp_core_get_table_prefix();
284
 
285
  $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_messages (
286
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
287
- thread_id bigint(20) NOT NULL,
288
- sender_id bigint(20) NOT NULL,
289
- subject varchar(200) NOT NULL,
290
- message longtext NOT NULL,
291
- date_sent datetime NOT NULL,
292
- KEY sender_id (sender_id),
293
- KEY thread_id (thread_id)
294
- ) {$charset_collate};";
295
 
296
  $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_recipients (
297
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
298
- user_id bigint(20) NOT NULL,
299
- thread_id bigint(20) NOT NULL,
300
- unread_count int(10) NOT NULL DEFAULT '0',
301
  sender_only tinyint(1) NOT NULL DEFAULT '0',
302
  is_deleted tinyint(1) NOT NULL DEFAULT '0',
303
- KEY user_id (user_id),
304
- KEY thread_id (thread_id),
305
  KEY is_deleted (is_deleted),
306
  KEY sender_only (sender_only),
307
- KEY unread_count (unread_count)
308
- ) {$charset_collate};";
309
 
310
  $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_notices (
311
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
312
- subject varchar(200) NOT NULL,
313
- message longtext NOT NULL,
314
- date_sent datetime NOT NULL,
315
  is_active tinyint(1) NOT NULL DEFAULT '0',
316
- KEY is_active (is_active)
317
- ) {$charset_collate};";
318
-
319
- $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_meta (
320
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
321
- message_id bigint(20) NOT NULL,
322
- meta_key varchar(255) DEFAULT NULL,
323
- meta_value longtext DEFAULT NULL,
324
- KEY message_id (message_id),
325
- KEY meta_key (meta_key(191))
326
- ) {$charset_collate};";
327
 
328
  dbDelta( $sql );
329
  }
330
 
331
- /**
332
- * Install database tables for the Profiles component.
333
- *
334
- * @since 1.0.0
335
- *
336
- * @uses bp_core_set_charset()
337
- * @uses bp_core_get_table_prefix()
338
- * @uses dbDelta()
339
- */
340
  function bp_core_install_extended_profiles() {
341
  global $wpdb;
342
 
@@ -354,43 +259,43 @@ function bp_core_install_extended_profiles() {
354
  }
355
 
356
  $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_groups (
357
- id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
358
- name varchar(150) NOT NULL,
359
- description mediumtext NOT NULL,
360
- group_order bigint(20) NOT NULL DEFAULT '0',
361
- can_delete tinyint(1) NOT NULL,
362
- KEY can_delete (can_delete)
363
- ) {$charset_collate};";
364
 
365
  $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_fields (
366
- id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
367
- group_id bigint(20) unsigned NOT NULL,
368
- parent_id bigint(20) unsigned NOT NULL,
369
- type varchar(150) NOT NULL,
370
- name varchar(150) NOT NULL,
371
- description longtext NOT NULL,
372
- is_required tinyint(1) NOT NULL DEFAULT '0',
373
- is_default_option tinyint(1) NOT NULL DEFAULT '0',
374
- field_order bigint(20) NOT NULL DEFAULT '0',
375
- option_order bigint(20) NOT NULL DEFAULT '0',
376
- order_by varchar(15) NOT NULL DEFAULT '',
377
- can_delete tinyint(1) NOT NULL DEFAULT '1',
378
- KEY group_id (group_id),
379
- KEY parent_id (parent_id),
380
- KEY field_order (field_order),
381
- KEY can_delete (can_delete),
382
- KEY is_required (is_required)
383
- ) {$charset_collate};";
384
 
385
  $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_data (
386
- id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
387
- field_id bigint(20) unsigned NOT NULL,
388
- user_id bigint(20) unsigned NOT NULL,
389
- value longtext NOT NULL,
390
- last_updated datetime NOT NULL,
391
- KEY field_id (field_id),
392
- KEY user_id (user_id)
393
- ) {$charset_collate};";
394
 
395
  $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_meta (
396
  id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
@@ -399,46 +304,36 @@ function bp_core_install_extended_profiles() {
399
  meta_key varchar(255) DEFAULT NULL,
400
  meta_value longtext DEFAULT NULL,
401
  KEY object_id (object_id),
402
- KEY meta_key (meta_key(191))
403
- ) {$charset_collate};";
404
 
405
  dbDelta( $sql );
406
 
407
  // Insert the default group and fields
408
  $insert_sql = array();
409
 
410
- if ( ! $wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_groups WHERE id = 1" ) ) {
411
  $insert_sql[] = "INSERT INTO {$bp_prefix}bp_xprofile_groups ( name, description, can_delete ) VALUES ( " . $wpdb->prepare( '%s', stripslashes( bp_get_option( 'bp-xprofile-base-group-name' ) ) ) . ", '', 0 );";
412
- }
413
 
414
- if ( ! $wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE id = 1" ) ) {
415
  $insert_sql[] = "INSERT INTO {$bp_prefix}bp_xprofile_fields ( group_id, parent_id, type, name, description, is_required, can_delete ) VALUES ( 1, 0, 'textbox', " . $wpdb->prepare( '%s', stripslashes( bp_get_option( 'bp-xprofile-fullname-field-name' ) ) ) . ", '', 1, 0 );";
416
- }
417
 
418
  dbDelta( $insert_sql );
419
  }
420
 
421
- /**
422
- * Install database tables for the Sites component.
423
- *
424
- * @since 1.0.0
425
- *
426
- * @uses bp_core_set_charset()
427
- * @uses bp_core_get_table_prefix()
428
- * @uses dbDelta()
429
- */
430
  function bp_core_install_blog_tracking() {
 
431
  $sql = array();
432
  $charset_collate = bp_core_set_charset();
433
  $bp_prefix = bp_core_get_table_prefix();
434
 
435
  $sql[] = "CREATE TABLE {$bp_prefix}bp_user_blogs (
436
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
437
- user_id bigint(20) NOT NULL,
438
- blog_id bigint(20) NOT NULL,
439
- KEY user_id (user_id),
440
- KEY blog_id (blog_id)
441
- ) {$charset_collate};";
442
 
443
  $sql[] = "CREATE TABLE {$bp_prefix}bp_user_blogs_blogmeta (
444
  id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
@@ -446,8 +341,8 @@ function bp_core_install_blog_tracking() {
446
  meta_key varchar(255) DEFAULT NULL,
447
  meta_value longtext DEFAULT NULL,
448
  KEY blog_id (blog_id),
449
- KEY meta_key (meta_key(191))
450
- ) {$charset_collate};";
451
 
452
  dbDelta( $sql );
453
  }
@@ -457,7 +352,7 @@ function bp_core_install_blog_tracking() {
457
  /**
458
  * Install the signups table.
459
  *
460
- * @since 2.0.0
461
  *
462
  * @global $wpdb
463
  * @uses wp_get_db_schema() to get WordPress ms_global schema
@@ -466,7 +361,7 @@ function bp_core_install_signups() {
466
  global $wpdb;
467
 
468
  // Signups is not there and we need it so let's create it
469
- require_once( buddypress()->plugin_dir . '/bp-core/admin/bp-core-admin-schema.php' );
470
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
471
 
472
  // Never use bp_core_get_table_prefix() for any global users tables
@@ -499,9 +394,9 @@ function bp_core_install_signups() {
499
  *
500
  * This is necessary because WordPress's `pre_schema_upgrade()` function wraps
501
  * table ALTER's in multisite checks, and other plugins may have installed their
502
- * own sign-ups table; Eg: Gravity Forms User Registration Add On.
503
  *
504
- * @since 2.0.1
505
  *
506
  * @see pre_schema_upgrade()
507
  * @link https://core.trac.wordpress.org/ticket/27855 WordPress Trac Ticket
@@ -512,11 +407,6 @@ function bp_core_install_signups() {
512
  function bp_core_upgrade_signups() {
513
  global $wpdb;
514
 
515
- // Bail if global tables should not be upgraded
516
- if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) {
517
- return;
518
- }
519
-
520
  // Never use bp_core_get_table_prefix() for any global users tables
521
  $wpdb->signups = $wpdb->base_prefix . 'signups';
522
 
1
  <?php
2
  /**
3
+ * BuddyPress DB schema
4
  *
5
  * @package BuddyPress
6
  * @subpackage CoreAdministration
7
  */
8
 
9
+ // Exit if accessed directly
10
+ if ( !defined( 'ABSPATH' ) ) exit;
11
 
 
 
 
 
 
 
 
 
12
  function bp_core_set_charset() {
13
  global $wpdb;
14
 
15
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
16
 
17
+ // BuddyPress component DB schema
18
  return !empty( $wpdb->charset ) ? "DEFAULT CHARACTER SET {$wpdb->charset}" : '';
19
  }
20
 
 
 
 
 
 
 
 
 
 
 
21
  function bp_core_install( $active_components = false ) {
22
 
23
+ if ( empty( $active_components ) )
 
 
 
 
 
24
  $active_components = apply_filters( 'bp_active_components', bp_get_option( 'bp-active-components' ) );
 
25
 
26
+ // Activity Streams
27
+ // Install tables even when inactive, to store last_activity data
28
  bp_core_install_activity_streams();
29
 
 
 
 
30
  // Notifications
31
+ if ( !empty( $active_components['notifications'] ) )
32
  bp_core_install_notifications();
 
33
 
34
  // Friend Connections
35
+ if ( !empty( $active_components['friends'] ) )
36
  bp_core_install_friends();
 
37
 
38
  // Extensible Groups
39
+ if ( !empty( $active_components['groups'] ) )
40
  bp_core_install_groups();
 
41
 
42
  // Private Messaging
43
+ if ( !empty( $active_components['messages'] ) )
44
  bp_core_install_private_messaging();
 
45
 
46
  // Extended Profiles
47
+ if ( !empty( $active_components['xprofile'] ) )
48
  bp_core_install_extended_profiles();
 
49
 
50
  // Blog tracking
51
+ if ( !empty( $active_components['blogs'] ) )
52
  bp_core_install_blog_tracking();
53
+
54
+ // Maybe install (or upgrade) the signups table
55
+ bp_core_maybe_install_signups();
56
  }
57
 
 
 
 
 
 
 
 
 
 
58
  function bp_core_install_notifications() {
59
+
60
  $sql = array();
61
  $charset_collate = bp_core_set_charset();
62
  $bp_prefix = bp_core_get_table_prefix();
63
 
64
  $sql[] = "CREATE TABLE {$bp_prefix}bp_notifications (
65
+ id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
66
+ user_id bigint(20) NOT NULL,
67
+ item_id bigint(20) NOT NULL,
68
+ secondary_item_id bigint(20),
69
+ component_name varchar(75) NOT NULL,
70
+ component_action varchar(75) NOT NULL,
71
+ date_notified datetime NOT NULL,
72
+ is_new bool NOT NULL DEFAULT 0,
73
+ KEY item_id (item_id),
74
+ KEY secondary_item_id (secondary_item_id),
75
+ KEY user_id (user_id),
76
+ KEY is_new (is_new),
77
+ KEY component_name (component_name),
78
+ KEY component_action (component_action),
79
+ KEY useritem (user_id,is_new)
80
+ ) {$charset_collate};";
 
 
 
 
 
 
 
 
 
81
 
82
  dbDelta( $sql );
83
  }
84
 
 
 
 
 
 
 
 
 
 
85
  function bp_core_install_activity_streams() {
86
+
87
  $sql = array();
88
  $charset_collate = bp_core_set_charset();
89
  $bp_prefix = bp_core_get_table_prefix();
95
  type varchar(75) NOT NULL,
96
  action text NOT NULL,
97
  content longtext NOT NULL,
98
+ primary_link varchar(255) NOT NULL,
99
  item_id bigint(20) NOT NULL,
100
  secondary_item_id bigint(20) DEFAULT NULL,
101
  date_recorded datetime NOT NULL,
121
  meta_key varchar(255) DEFAULT NULL,
122
  meta_value longtext DEFAULT NULL,
123
  KEY activity_id (activity_id),
124
+ KEY meta_key (meta_key)
125
+ ) {$charset_collate};";
126
 
127
  dbDelta( $sql );
128
  }
129
 
 
 
 
 
 
 
 
 
 
130
  function bp_core_install_friends() {
131
+
132
  $sql = array();
133
  $charset_collate = bp_core_set_charset();
134
  $bp_prefix = bp_core_get_table_prefix();
135
 
136
  $sql[] = "CREATE TABLE {$bp_prefix}bp_friends (
137
+ id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
138
+ initiator_user_id bigint(20) NOT NULL,
139
+ friend_user_id bigint(20) NOT NULL,
140
+ is_confirmed bool DEFAULT 0,
141
+ is_limited bool DEFAULT 0,
142
+ date_created datetime NOT NULL,
143
+ KEY initiator_user_id (initiator_user_id),
144
+ KEY friend_user_id (friend_user_id)
145
+ ) {$charset_collate};";
146
 
147
  dbDelta( $sql );
148
  }
149
 
 
 
 
 
 
 
 
 
 
150
  function bp_core_install_groups() {
151
+
152
  $sql = array();
153
  $charset_collate = bp_core_set_charset();
154
  $bp_prefix = bp_core_get_table_prefix();
155
 
156
  $sql[] = "CREATE TABLE {$bp_prefix}bp_groups (
157
+ id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
158
  creator_id bigint(20) NOT NULL,
159
+ name varchar(100) NOT NULL,
160
+ slug varchar(200) NOT NULL,
161
+ description longtext NOT NULL,
162
  status varchar(10) NOT NULL DEFAULT 'public',
163
  enable_forum tinyint(1) NOT NULL DEFAULT '1',
164
  date_created datetime NOT NULL,
165
+ KEY creator_id (creator_id),
166
+ KEY status (status)
167
+ ) {$charset_collate};";
168
 
169
  $sql[] = "CREATE TABLE {$bp_prefix}bp_groups_members (
170
+ id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
171
  group_id bigint(20) NOT NULL,
172
  user_id bigint(20) NOT NULL,
173
  inviter_id bigint(20) NOT NULL,
182
  KEY group_id (group_id),
183
  KEY is_admin (is_admin),
184
  KEY is_mod (is_mod),
185
+ KEY user_id (user_id),
186
  KEY inviter_id (inviter_id),
187
  KEY is_confirmed (is_confirmed)
188
+ ) {$charset_collate};";
189
 
190
  $sql[] = "CREATE TABLE {$bp_prefix}bp_groups_groupmeta (
191
  id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
193
  meta_key varchar(255) DEFAULT NULL,
194
  meta_value longtext DEFAULT NULL,
195
  KEY group_id (group_id),
196
+ KEY meta_key (meta_key)
197
+ ) {$charset_collate};";
198
 
199
  dbDelta( $sql );
200
  }
201
 
 
 
 
 
 
 
 
 
 
202
  function bp_core_install_private_messaging() {
203
+
204
  $sql = array();
205
  $charset_collate = bp_core_set_charset();
206
  $bp_prefix = bp_core_get_table_prefix();
207
 
208
  $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_messages (
209
+ id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
210
+ thread_id bigint(20) NOT NULL,
211
+ sender_id bigint(20) NOT NULL,
212
+ subject varchar(200) NOT NULL,
213
+ message longtext NOT NULL,
214
+ date_sent datetime NOT NULL,
215
+ KEY sender_id (sender_id),
216
+ KEY thread_id (thread_id)
217
+ ) {$charset_collate};";
218
 
219
  $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_recipients (
220
+ id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
221
+ user_id bigint(20) NOT NULL,
222
+ thread_id bigint(20) NOT NULL,
223
+ unread_count int(10) NOT NULL DEFAULT '0',
224
  sender_only tinyint(1) NOT NULL DEFAULT '0',
225
  is_deleted tinyint(1) NOT NULL DEFAULT '0',
226
+ KEY user_id (user_id),
227
+ KEY thread_id (thread_id),
228
  KEY is_deleted (is_deleted),
229
  KEY sender_only (sender_only),
230
+ KEY unread_count (unread_count)
231
+ ) {$charset_collate};";
232
 
233
  $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_notices (
234
+ id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
235
+ subject varchar(200) NOT NULL,
236
+ message longtext NOT NULL,
237
+ date_sent datetime NOT NULL,
238
  is_active tinyint(1) NOT NULL DEFAULT '0',
239
+ KEY is_active (is_active)
240
+ ) {$charset_collate};";
 
 
 
 
 
 
 
 
 
241
 
242
  dbDelta( $sql );
243
  }
244
 
 
 
 
 
 
 
 
 
 
245
  function bp_core_install_extended_profiles() {
246
  global $wpdb;
247
 
259
  }
260
 
261
  $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_groups (
262
+ id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
263
+ name varchar(150) NOT NULL,
264
+ description mediumtext NOT NULL,
265
+ group_order bigint(20) NOT NULL DEFAULT '0',
266
+ can_delete tinyint(1) NOT NULL,
267
+ KEY can_delete (can_delete)
268
+ ) {$charset_collate};";
269
 
270
  $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_fields (
271
+ id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
272
+ group_id bigint(20) unsigned NOT NULL,
273
+ parent_id bigint(20) unsigned NOT NULL,
274
+ type varchar(150) NOT NULL,
275
+ name varchar(150) NOT NULL,
276
+ description longtext NOT NULL,
277
+ is_required tinyint(1) NOT NULL DEFAULT '0',
278
+ is_default_option tinyint(1) NOT NULL DEFAULT '0',
279
+ field_order bigint(20) NOT NULL DEFAULT '0',
280
+ option_order bigint(20) NOT NULL DEFAULT '0',
281
+ order_by varchar(15) NOT NULL DEFAULT '',
282
+ can_delete tinyint(1) NOT NULL DEFAULT '1',
283
+ KEY group_id (group_id),
284
+ KEY parent_id (parent_id),
285
+ KEY field_order (field_order),
286
+ KEY can_delete (can_delete),
287
+ KEY is_required (is_required)
288
+ ) {$charset_collate};";
289
 
290
  $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_data (
291
+ id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
292
+ field_id bigint(20) unsigned NOT NULL,
293
+ user_id bigint(20) unsigned NOT NULL,
294
+ value longtext NOT NULL,
295
+ last_updated datetime NOT NULL,
296
+ KEY field_id (field_id),
297
+ KEY user_id (user_id)
298
+ ) {$charset_collate};";
299
 
300
  $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_meta (
301
  id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
304
  meta_key varchar(255) DEFAULT NULL,
305
  meta_value longtext DEFAULT NULL,
306
  KEY object_id (object_id),
307
+ KEY meta_key (meta_key)
308
+ ) {$charset_collate};";
309
 
310
  dbDelta( $sql );
311
 
312
  // Insert the default group and fields
313
  $insert_sql = array();
314
 
315
+ if ( !$wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_groups WHERE id = 1" ) )
316
  $insert_sql[] = "INSERT INTO {$bp_prefix}bp_xprofile_groups ( name, description, can_delete ) VALUES ( " . $wpdb->prepare( '%s', stripslashes( bp_get_option( 'bp-xprofile-base-group-name' ) ) ) . ", '', 0 );";
 
317
 
318
+ if ( !$wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE id = 1" ) )
319
  $insert_sql[] = "INSERT INTO {$bp_prefix}bp_xprofile_fields ( group_id, parent_id, type, name, description, is_required, can_delete ) VALUES ( 1, 0, 'textbox', " . $wpdb->prepare( '%s', stripslashes( bp_get_option( 'bp-xprofile-fullname-field-name' ) ) ) . ", '', 1, 0 );";
 
320
 
321
  dbDelta( $insert_sql );
322
  }
323
 
 
 
 
 
 
 
 
 
 
324
  function bp_core_install_blog_tracking() {
325
+
326
  $sql = array();
327
  $charset_collate = bp_core_set_charset();
328
  $bp_prefix = bp_core_get_table_prefix();
329
 
330
  $sql[] = "CREATE TABLE {$bp_prefix}bp_user_blogs (
331
+ id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
332
+ user_id bigint(20) NOT NULL,
333
+ blog_id bigint(20) NOT NULL,
334
+ KEY user_id (user_id),
335
+ KEY blog_id (blog_id)
336
+ ) {$charset_collate};";
337
 
338
  $sql[] = "CREATE TABLE {$bp_prefix}bp_user_blogs_blogmeta (
339
  id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
341
  meta_key varchar(255) DEFAULT NULL,
342
  meta_value longtext DEFAULT NULL,
343
  KEY blog_id (blog_id),
344
+ KEY meta_key (meta_key)
345
+ ) {$charset_collate};";
346
 
347
  dbDelta( $sql );
348
  }
352
  /**
353
  * Install the signups table.
354
  *
355
+ * @since BuddyPress (2.0.0)
356
  *
357
  * @global $wpdb
358
  * @uses wp_get_db_schema() to get WordPress ms_global schema
361
  global $wpdb;
362
 
363
  // Signups is not there and we need it so let's create it
364
+ require_once( buddypress()->plugin_dir . '/bp-core/admin/bp-core-schema.php' );
365
  require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
366
 
367
  // Never use bp_core_get_table_prefix() for any global users tables
394
  *
395
  * This is necessary because WordPress's `pre_schema_upgrade()` function wraps
396
  * table ALTER's in multisite checks, and other plugins may have installed their
397
+ * own sign-ups table; Eg: Gravity Forms User Registration Add On
398
  *
399
+ * @since BuddyPress (2.0.1)
400
  *
401
  * @see pre_schema_upgrade()
402
  * @link https://core.trac.wordpress.org/ticket/27855 WordPress Trac Ticket
407
  function bp_core_upgrade_signups() {
408
  global $wpdb;
409
 
 
 
 
 
 
410
  // Never use bp_core_get_table_prefix() for any global users tables
411
  $wpdb->signups = $wpdb->base_prefix . 'signups';
412
 
bp-core/admin/{bp-core-admin-settings.php → bp-core-settings.php} RENAMED
@@ -1,27 +1,28 @@
1
  <?php
 
2
  /**
3
- * BuddyPress Admin Settings.
4
  *
5
  * @package BuddyPress
6
  * @subpackage CoreAdministration
7
  */
8
 
9
- // Exit if accessed directly.
10
- defined( 'ABSPATH' ) || exit;
11
 
12
  /**
13
- * Main settings section description for the settings page.
14
  *
15
- * @since 1.6.0
16
  */
17
  function bp_admin_setting_callback_main_section() { }
18
 
19
  /**
20
- * Admin bar for logged out users setting field.
21
  *
22
- * @since 1.6.0
23
  *
24
- * @uses bp_form_option() To output the option value.
25
  */
26
  function bp_admin_setting_callback_admin_bar() {
27
  ?>
@@ -33,11 +34,11 @@ function bp_admin_setting_callback_admin_bar() {
33
  }
34
 
35
  /**
36
- * Allow members to delete their accounts setting field.
37
  *
38
- * @since 1.6.0
39
  *
40
- * @uses checked() To display the checked attribute.
41
  */
42
  function bp_admin_setting_callback_account_deletion() {
43
  ?>
@@ -48,21 +49,36 @@ function bp_admin_setting_callback_account_deletion() {
48
  <?php
49
  }
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  /** Activity *******************************************************************/
52
 
53
  /**
54
- * Groups settings section description for the settings page.
55
  *
56
- * @since 1.6.0
57
  */
58
  function bp_admin_setting_callback_activity_section() { }
59
 
60
  /**
61
- * Allow Akismet setting field.
62
  *
63
- * @since 1.6.0
64
  *
65
- * @uses checked() To display the checked attribute.
66
  */
67
  function bp_admin_setting_callback_activity_akismet() {
68
  ?>
@@ -74,9 +90,9 @@ function bp_admin_setting_callback_activity_akismet() {
74
  }
75
 
76
  /**
77
- * Allow activity comments on blog posts and forum posts.
78
  *
79
- * @since 1.6.0
80
  */
81
  function bp_admin_setting_callback_blogforum_comments() {
82
  ?>
@@ -90,7 +106,7 @@ function bp_admin_setting_callback_blogforum_comments() {
90
  /**
91
  * Allow Heartbeat to refresh activity stream.
92
  *
93
- * @since 2.0.0
94
  */
95
  function bp_admin_setting_callback_heartbeat() {
96
  ?>
@@ -102,17 +118,27 @@ function bp_admin_setting_callback_heartbeat() {
102
  }
103
 
104
  /**
105
- * Sanitization for bp-disable-blogforum-comments setting.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  *
107
  * In the UI, a checkbox asks whether you'd like to *enable* blog/forum activity comments. For
108
  * legacy reasons, the option that we store is 1 if these comments are *disabled*. So we use this
109
  * function to flip the boolean before saving the intval.
110
  *
111
- * @since 1.6.0
112
- *
113
- * @param bool $value
114
- *
115
- * @return bool
116
  */
117
  function bp_admin_sanitize_callback_blogforum_comments( $value = false ) {
118
  return $value ? 0 : 1;
@@ -121,18 +147,18 @@ function bp_admin_sanitize_callback_blogforum_comments( $value = false ) {
121
  /** XProfile ******************************************************************/
122
 
123
  /**
124
- * Profile settings section description for the settings page.
125
  *
126
- * @since 1.6.0
127
  */
128
  function bp_admin_setting_callback_xprofile_section() { }
129
 
130
  /**
131
- * Enable BP->WP profile syncing field.
132
  *
133
- * @since 1.6.0
134
  *
135
- * @uses bp_form_option() To output the option value.
136
  */
137
  function bp_admin_setting_callback_profile_sync() {
138
  ?>
@@ -144,11 +170,11 @@ function bp_admin_setting_callback_profile_sync() {
144
  }
145
 
146
  /**
147
- * Allow members to upload avatars field.
148
  *
149
- * @since 1.6.0
150
  *
151
- * @uses checked() To display the checked attribute.
152
  */
153
  function bp_admin_setting_callback_avatar_uploads() {
154
  ?>
@@ -159,33 +185,21 @@ function bp_admin_setting_callback_avatar_uploads() {
159
  <?php
160
  }
161
 
162
- /**
163
- * Allow members to upload cover images field.
164
- *
165
- * @since 2.4.0
166
- */
167
- function bp_admin_setting_callback_cover_image_uploads() {
168
- ?>
169
- <input id="bp-disable-cover-image-uploads" name="bp-disable-cover-image-uploads" type="checkbox" value="1" <?php checked( ! bp_disable_cover_image_uploads() ); ?> />
170
- <label for="bp-disable-cover-image-uploads"><?php _e( 'Allow registered members to upload cover images', 'buddypress' ); ?></label>
171
- <?php
172
- }
173
-
174
  /** Groups Section ************************************************************/
175
 
176
  /**
177
- * Groups settings section description for the settings page.
178
  *
179
- * @since 1.6.0
180
  */
181
  function bp_admin_setting_callback_groups_section() { }
182
 
183
  /**
184
- * Allow all users to create groups field.
185
  *
186
- * @since 1.6.0
187
  *
188
- * @uses checked() To display the checked attribute.
189
  */
190
  function bp_admin_setting_callback_group_creation() {
191
  ?>
@@ -197,46 +211,22 @@ function bp_admin_setting_callback_group_creation() {
197
  <?php
198
  }
199
 
200
- /**
201
- * 'Enable group avatars' field markup.
202
- *
203
- * @since 2.3.0
204
- */
205
- function bp_admin_setting_callback_group_avatar_uploads() {
206
- ?>
207
- <input id="bp-disable-group-avatar-uploads" name="bp-disable-group-avatar-uploads" type="checkbox" value="1" <?php checked( ! bp_disable_group_avatar_uploads() ); ?> />
208
- <label for="bp-disable-group-avatar-uploads"><?php _e( 'Allow customizable avatars for groups', 'buddypress' ); ?></label>
209
- <?php
210
- }
211
-
212
- /**
213
- * 'Enable group cover images' field markup.
214
- *
215
- * @since 2.4.0
216
- */
217
- function bp_admin_setting_callback_group_cover_image_uploads() {
218
- ?>
219
- <input id="bp-disable-group-cover-image-uploads" name="bp-disable-group-cover-image-uploads" type="checkbox" value="1" <?php checked( ! bp_disable_group_cover_image_uploads() ); ?> />
220
- <label for="bp-disable-group-cover-image-uploads"><?php _e( 'Allow customizable cover images for groups', 'buddypress' ); ?></label>
221
- <?php
222
- }
223
-
224
  /** Forums Section ************************************************************/
225
 
226
  /**
227
- * Forums settings section description for the settings page.
228
  *
229
- * @since 1.6.0
230
  */
231
  function bp_admin_setting_callback_bbpress_section() { }
232
 
233
  /**
234
- * bb-config.php location field.
235
  *
236
- * @since 1.6.0
237
- * @uses checked() To display the checked attribute.
238
- * @uses bp_get_option() To get the config location.
239
- * @uses bp_form_option() To get the sanitized form option.
240
  */
241
  function bp_admin_setting_callback_bbpress_configuration() {
242
 
@@ -262,10 +252,11 @@ function bp_admin_setting_callback_bbpress_configuration() {
262
  /**
263
  * The main settings page
264
  *
265
- * @since 1.6.0
266
  *
267
- * @uses settings_fields() To output the hidden fields for the form.
268
- * @uses do_settings_sections() To output the settings sections.
 
269
  */
270
  function bp_core_admin_settings() {
271
 
@@ -276,9 +267,11 @@ function bp_core_admin_settings() {
276
 
277
  <div class="wrap">
278
 
 
 
279
  <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( __( 'Settings', 'buddypress' ) ); ?></h2>
280
 
281
- <form action="<?php echo esc_url( $form_action ) ?>" method="post">
282
 
283
  <?php settings_fields( 'buddypress' ); ?>
284
 
@@ -294,9 +287,9 @@ function bp_core_admin_settings() {
294
  }
295
 
296
  /**
297
- * Save our settings.
298
  *
299
- * @since 1.6.0
300
  */
301
  function bp_core_admin_settings_save() {
302
  global $wp_settings_fields;
@@ -316,13 +309,10 @@ function bp_core_admin_settings_save() {
316
  }
317
  }
318
 
319
- // Some legacy options are not registered with the Settings API, or are reversed in the UI.
320
  $legacy_options = array(
321
  'bp-disable-account-deletion',
322
  'bp-disable-avatar-uploads',
323
- 'bp-disable-cover-image-uploads',
324
- 'bp-disable-group-avatar-uploads',
325
- 'bp-disable-group-cover-image-uploads',
326
  'bp_disable_blogforum_comments',
327
  'bp-disable-profile-sync',
328
  'bp_restrict_group_creation',
@@ -343,15 +333,15 @@ function bp_core_admin_settings_save() {
343
  add_action( 'bp_admin_init', 'bp_core_admin_settings_save', 100 );
344
 
345
  /**
346
- * Output settings API option.
347
  *
348
- * @since 1.6.0
349
  *
350
  * @uses bp_get_bp_form_option()
351
  *
352
  * @param string $option
353
  * @param string $default
354
- * @param bool $slug
355
  */
356
  function bp_form_option( $option, $default = '' , $slug = false ) {
357
  echo bp_get_form_option( $option, $default, $slug );
@@ -359,7 +349,7 @@ function bp_form_option( $option, $default = '' , $slug = false ) {
359
  /**
360
  * Return settings API option
361
  *
362
- * @since 1.6.0
363
  *
364
  * @uses bp_get_option()
365
  * @uses esc_attr()
@@ -367,9 +357,7 @@ function bp_form_option( $option, $default = '' , $slug = false ) {
367
  *
368
  * @param string $option
369
  * @param string $default
370
- * @param bool $slug
371
- *
372
- * @return string
373
  */
374
  function bp_get_form_option( $option, $default = '', $slug = false ) {
375
 
@@ -377,31 +365,17 @@ function bp_form_option( $option, $default = '' , $slug = false ) {
377
  $value = bp_get_option( $option, $default );
378
 
379
  // Slug?
380
- if ( true === $slug ) {
381
-
382
- /**
383
- * Filters the slug value in the form field.
384
- *
385
- * @since 1.6.0
386
- *
387
- * @param string $value Value being returned for the requested option.
388
- */
389
  $value = esc_attr( apply_filters( 'editable_slug', $value ) );
390
- } else { // Not a slug
 
 
391
  $value = esc_attr( $value );
392
- }
393
 
394
  // Fallback to default
395
  if ( empty( $value ) )
396
  $value = $default;
397
 
398
- /**
399
- * Filters the settings API option.
400
- *
401
- * @since 1.6.0
402
- *
403
- * @param string $value Value being returned for the requested option.
404
- * @param string $option Option whose value is being requested.
405
- */
406
  return apply_filters( 'bp_get_form_option', $value, $option );
407
  }
1
  <?php
2
+
3
  /**
4
+ * BuddyPress Admin Settings
5
  *
6
  * @package BuddyPress
7
  * @subpackage CoreAdministration
8
  */
9
 
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
 
13
  /**
14
+ * Main settings section description for the settings page
15
  *
16
+ * @since BuddyPress (1.6)
17
  */
18
  function bp_admin_setting_callback_main_section() { }
19
 
20
  /**
21
+ * Admin bar for logged out users setting field
22
  *
23
+ * @since BuddyPress (1.6)
24
  *
25
+ * @uses bp_form_option() To output the option value
26
  */
27
  function bp_admin_setting_callback_admin_bar() {
28
  ?>
34
  }
35
 
36
  /**
37
+ * Allow members to delete their accounts setting field
38
  *
39
+ * @since BuddyPress (1.6)
40
  *
41
+ * @uses checked() To display the checked attribute
42
  */
43
  function bp_admin_setting_callback_account_deletion() {
44
  ?>
49
  <?php
50
  }
51
 
52
+ /**
53
+ * If user has upgraded to 1.6 and chose to retain their BuddyBar, offer then a switch to change over
54
+ * to the WP Toolbar.
55
+ *
56
+ * @since BuddyPress (1.6)
57
+ */
58
+ function bp_admin_setting_callback_force_buddybar() {
59
+ ?>
60
+
61
+ <input id="_bp_force_buddybar" name="_bp_force_buddybar" type="checkbox" value="1" <?php checked( ! bp_force_buddybar( true ) ); ?> />
62
+ <label for="_bp_force_buddybar"><?php _e( 'Switch to WordPress Toolbar', 'buddypress' ); ?></label>
63
+
64
+ <?php
65
+ }
66
+
67
  /** Activity *******************************************************************/
68
 
69
  /**
70
+ * Groups settings section description for the settings page
71
  *
72
+ * @since BuddyPress (1.6)
73
  */
74
  function bp_admin_setting_callback_activity_section() { }
75
 
76
  /**
77
+ * Allow Akismet setting field
78
  *
79
+ * @since BuddyPress (1.6)
80
  *
81
+ * @uses checked() To display the checked attribute
82
  */
83
  function bp_admin_setting_callback_activity_akismet() {
84
  ?>
90
  }
91
 
92
  /**
93
+ * Allow activity comments on blog posts and forum posts
94
  *
95
+ * @since BuddyPress (1.6)
96
  */
97
  function bp_admin_setting_callback_blogforum_comments() {
98
  ?>
106
  /**
107
  * Allow Heartbeat to refresh activity stream.
108
  *
109
+ * @since BuddyPress (2.0.0)
110
  */
111
  function bp_admin_setting_callback_heartbeat() {
112
  ?>
118
  }
119
 
120
  /**
121
+ * Sanitization for _bp_force_buddyvar
122
+ *
123
+ * If upgraded to 1.6 and you chose to keep the BuddyBar, a checkbox asks if you want to switch to
124
+ * the WP Toolbar. The option we store is 1 if the BuddyBar is forced on, so we use this function
125
+ * to flip the boolean before saving the intval.
126
+ *
127
+ * @since BuddyPress (1.6)
128
+ * @access Private
129
+ */
130
+ function bp_admin_sanitize_callback_force_buddybar( $value = false ) {
131
+ return $value ? 0 : 1;
132
+ }
133
+
134
+ /**
135
+ * Sanitization for bp-disable-blogforum-comments setting
136
  *
137
  * In the UI, a checkbox asks whether you'd like to *enable* blog/forum activity comments. For
138
  * legacy reasons, the option that we store is 1 if these comments are *disabled*. So we use this
139
  * function to flip the boolean before saving the intval.
140
  *
141
+ * @since BuddyPress (1.6)
 
 
 
 
142
  */
143
  function bp_admin_sanitize_callback_blogforum_comments( $value = false ) {
144
  return $value ? 0 : 1;
147
  /** XProfile ******************************************************************/
148
 
149
  /**
150
+ * Profile settings section description for the settings page
151
  *
152
+ * @since BuddyPress (1.6)
153
  */
154
  function bp_admin_setting_callback_xprofile_section() { }
155
 
156
  /**
157
+ * Enable BP->WP profile syncing field
158
  *
159
+ * @since BuddyPress (1.6)
160
  *
161
+ * @uses bp_form_option() To output the option value
162
  */
163
  function bp_admin_setting_callback_profile_sync() {
164
  ?>
170
  }
171
 
172
  /**
173
+ * Allow members to upload avatars field
174
  *
175
+ * @since BuddyPress (1.6)
176
  *
177
+ * @uses checked() To display the checked attribute
178
  */
179
  function bp_admin_setting_callback_avatar_uploads() {
180
  ?>
185
  <?php
186
  }
187
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  /** Groups Section ************************************************************/
189
 
190
  /**
191
+ * Groups settings section description for the settings page
192
  *
193
+ * @since BuddyPress (1.6)
194
  */
195
  function bp_admin_setting_callback_groups_section() { }
196
 
197
  /**
198
+ * Allow all users to create groups field
199
  *
200
+ * @since BuddyPress (1.6)
201
  *
202
+ * @uses checked() To display the checked attribute
203
  */
204
  function bp_admin_setting_callback_group_creation() {
205
  ?>
211
  <?php
212
  }
213
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  /** Forums Section ************************************************************/
215
 
216
  /**
217
+ * Forums settings section description for the settings page
218
  *
219
+ * @since BuddyPress (1.6)
220
  */
221
  function bp_admin_setting_callback_bbpress_section() { }
222
 
223
  /**
224
+ * bb-config.php location field
225
  *
226
+ * @since BuddyPress (1.6)
227
+ * @uses checked() To display the checked attribute
228
+ * @uses bp_get_option() To get the config location
229
+ * @uses bp_form_option() To get the sanitized form option
230
  */
231
  function bp_admin_setting_callback_bbpress_configuration() {
232
 
252
  /**
253
  * The main settings page
254
  *
255
+ * @since BuddyPress (1.6)
256
  *
257
+ * @uses screen_icon() To display the screen icon
258
+ * @uses settings_fields() To output the hidden fields for the form
259
+ * @uses do_settings_sections() To output the settings sections
260
  */
261
  function bp_core_admin_settings() {
262
 
267
 
268
  <div class="wrap">
269
 
270
+ <?php screen_icon( 'buddypress' ); ?>
271
+
272
  <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( __( 'Settings', 'buddypress' ) ); ?></h2>
273
 
274
+ <form action="<?php echo $form_action ?>" method="post">
275
 
276
  <?php settings_fields( 'buddypress' ); ?>
277
 
287
  }
288
 
289
  /**
290
+ * Save our settings
291
  *
292
+ * @since BuddyPress (1.6)
293
  */
294
  function bp_core_admin_settings_save() {
295
  global $wp_settings_fields;
309
  }
310
  }
311
 
312
+ // Some legacy options are not registered with the Settings API
313
  $legacy_options = array(
314
  'bp-disable-account-deletion',
315
  'bp-disable-avatar-uploads',
 
 
 
316
  'bp_disable_blogforum_comments',
317
  'bp-disable-profile-sync',
318
  'bp_restrict_group_creation',
333
  add_action( 'bp_admin_init', 'bp_core_admin_settings_save', 100 );
334
 
335
  /**
336
+ * Output settings API option
337
  *
338
+ * @since BuddyPress (1.6)
339
  *
340
  * @uses bp_get_bp_form_option()
341
  *
342
  * @param string $option
343
  * @param string $default
344
+ * @param bool $slug
345
  */
346
  function bp_form_option( $option, $default = '' , $slug = false ) {
347
  echo bp_get_form_option( $option, $default, $slug );
349
  /**
350
  * Return settings API option
351
  *
352
+ * @since BuddyPress (1.6)
353
  *
354
  * @uses bp_get_option()
355
  * @uses esc_attr()
357
  *
358
  * @param string $option
359
  * @param string $default
360
+ * @param bool $slug
 
 
361
  */
362
  function bp_get_form_option( $option, $default = '', $slug = false ) {
363
 
365
  $value = bp_get_option( $option, $default );
366
 
367
  // Slug?
368
+ if ( true === $slug )
 
 
 
 
 
 
 
 
369
  $value = esc_attr( apply_filters( 'editable_slug', $value ) );
370
+
371
+ // Not a slug
372
+ else
373
  $value = esc_attr( $value );
 
374
 
375
  // Fallback to default
376
  if ( empty( $value ) )
377
  $value = $default;
378
 
379
+ // Allow plugins to further filter the output
 
 
 
 
 
 
 
380
  return apply_filters( 'bp_get_form_option', $value, $option );
381
  }
bp-core/admin/{bp-core-admin-slugs.php → bp-core-slugs.php} RENAMED
@@ -1,18 +1,19 @@
1
  <?php
 
2
  /**
3
- * BuddyPress Admin Slug Functions.
4
  *
5
  * @package BuddyPress
6
  * @subpackage CoreAdministration
7
  */
8
 
9
- // Exit if accessed directly.
10
- defined( 'ABSPATH' ) || exit;
11
 
12
  /**
13
  * Renders the page mapping admin panel.
14
  *
15
- * @since 1.6.0
16
  * @todo Use settings API
17
  * @uses bp_core_admin_component_options()
18
  */
@@ -20,6 +21,7 @@ function bp_core_admin_slugs_settings() {
20
  ?>
21
 
22
  <div class="wrap">
 
23
 
24
  <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( __( 'Pages', 'buddypress' ) ); ?></h2>
25
  <form action="" method="post" id="bp-admin-page-form">
@@ -42,11 +44,11 @@ function bp_core_admin_slugs_settings() {
42
  * Creates reusable markup for page setup on the Components and Pages dashboard panel.
43
  *
44
  * @package BuddyPress
45
- * @since 1.6.0
46
  * @todo Use settings API
47
  */
48
  function bp_core_admin_slugs_options() {
49
- $bp = buddypress();
50
 
51
  // Get the existing WP pages
52
  $existing_pages = bp_core_get_directory_page_ids();
@@ -70,13 +72,6 @@ function bp_core_admin_slugs_options() {
70
 
71
  /** Directory Display *****************************************************/
72
 
73
- /**
74
- * Filters the loaded components needing directory page association to a WordPress page.
75
- *
76
- * @since 1.5.0
77
- *
78
- * @param array $directory_pages Array of available components to set associations for.
79
- */
80
  $directory_pages = apply_filters( 'bp_directory_pages', $directory_pages );
81
 
82
  if ( !empty( $directory_pages ) ) : ?>
@@ -106,6 +101,9 @@ function bp_core_admin_slugs_options() {
106
  'selected' => !empty( $existing_pages[$name] ) ? $existing_pages[$name] : false
107
  ) ); ?>
108
 
 
 
 
109
  <?php if ( !empty( $existing_pages[$name] ) ) : ?>
110
 
111
  <a href="<?php echo get_permalink( $existing_pages[$name] ); ?>" class="button-secondary" target="_bp"><?php _e( 'View', 'buddypress' ); ?></a>
@@ -120,16 +118,7 @@ function bp_core_admin_slugs_options() {
120
 
121
  <?php endforeach ?>
122
 
123
- <?php
124
-
125
- /**
126
- * Fires after the display of default directories.
127
- *
128
- * Allows plugins to add their own directory associations.
129
- *
130
- * @since 1.5.0
131
- */
132
- do_action( 'bp_active_external_directories' ); ?>
133
 
134
  </tbody>
135
  </table>
@@ -146,13 +135,6 @@ function bp_core_admin_slugs_options() {
146
  'activate' => __( 'Activate', 'buddypress' ),
147
  );
148
 
149
- /**
150
- * Filters the default static pages for BuddyPress setup.
151
- *
152
- * @since 1.6.0
153
- *
154
- * @param array $static_pages Array of static default static pages.
155
- */
156
  $static_pages = apply_filters( 'bp_static_pages', $static_pages );
157
 
158
  if ( !empty( $static_pages ) ) : ?>
@@ -182,6 +164,9 @@ function bp_core_admin_slugs_options() {
182
  'selected' => !empty( $existing_pages[$name] ) ? $existing_pages[$name] : false
183
  ) ) ?>
184
 
 
 
 
185
  <?php if ( !empty( $existing_pages[$name] ) ) : ?>
186
 
187
  <a href="<?php echo get_permalink( $existing_pages[$name] ); ?>" class="button-secondary" target="_bp"><?php _e( 'View', 'buddypress' ); ?></a>
@@ -195,14 +180,7 @@ function bp_core_admin_slugs_options() {
195
 
196
  <?php endforeach ?>
197
 
198
- <?php
199
-
200
- /**
201
- * Fires after the display of default static pages for BuddyPress setup.
202
- *
203
- * @since 1.5.0
204
- */
205
- do_action( 'bp_active_external_pages' ); ?>
206
 
207
  </tbody>
208
  </table>
@@ -212,14 +190,14 @@ function bp_core_admin_slugs_options() {
212
  }
213
 
214
  /**
215
- * Handle saving of the BuddyPress slugs.
216
  *
217
- * @since 1.6.0
218
  * @todo Use settings API
219
  */
220
  function bp_core_admin_slugs_setup_handler() {
221
 
222
- if ( isset( $_POST['bp-admin-pages-submit'] ) ) {
223
  if ( !check_admin_referer( 'bp-admin-pages-setup' ) )
224
  return false;
225
 
1
  <?php
2
+
3
  /**
4
+ * BuddyPress Admin Slug Functions
5
  *
6
  * @package BuddyPress
7
  * @subpackage CoreAdministration
8
  */
9
 
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
 
13
  /**
14
  * Renders the page mapping admin panel.
15
  *
16
+ * @since BuddyPress (1.6)
17
  * @todo Use settings API
18
  * @uses bp_core_admin_component_options()
19
  */
21
  ?>
22
 
23
  <div class="wrap">
24
+ <?php screen_icon( 'buddypress'); ?>
25
 
26
  <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( __( 'Pages', 'buddypress' ) ); ?></h2>
27
  <form action="" method="post" id="bp-admin-page-form">
44
  * Creates reusable markup for page setup on the Components and Pages dashboard panel.
45
  *
46
  * @package BuddyPress
47
+ * @since BuddyPress (1.6)
48
  * @todo Use settings API
49
  */
50
  function bp_core_admin_slugs_options() {
51
+ global $bp;
52
 
53
  // Get the existing WP pages
54
  $existing_pages = bp_core_get_directory_page_ids();
72
 
73
  /** Directory Display *****************************************************/
74
 
 
 
 
 
 
 
 
75
  $directory_pages = apply_filters( 'bp_directory_pages', $directory_pages );
76
 
77
  if ( !empty( $directory_pages ) ) : ?>
101
  'selected' => !empty( $existing_pages[$name] ) ? $existing_pages[$name] : false
102
  ) ); ?>
103
 
104
+ <a href="<?php echo admin_url( add_query_arg( array( 'post_type' => 'page' ), 'post-new.php' ) ); ?>" class="button-secondary"><?php _e( 'New Page', 'buddypress' ); ?></a>
105
+ <input class="button-primary" type="submit" name="bp-admin-pages-single" value="<?php esc_attr_e( 'Save', 'buddypress' ) ?>" />
106
+
107
  <?php if ( !empty( $existing_pages[$name] ) ) : ?>
108
 
109
  <a href="<?php echo get_permalink( $existing_pages[$name] ); ?>" class="button-secondary" target="_bp"><?php _e( 'View', 'buddypress' ); ?></a>
118
 
119
  <?php endforeach ?>
120
 
121
+ <?php do_action( 'bp_active_external_directories' ); ?>
 
 
 
 
 
 
 
 
 
122
 
123
  </tbody>
124
  </table>
135
  'activate' => __( 'Activate', 'buddypress' ),
136
  );
137
 
 
 
 
 
 
 
 
138
  $static_pages = apply_filters( 'bp_static_pages', $static_pages );
139
 
140
  if ( !empty( $static_pages ) ) : ?>
164
  'selected' => !empty( $existing_pages[$name] ) ? $existing_pages[$name] : false
165
  ) ) ?>
166
 
167
+ <a href="<?php echo admin_url( add_query_arg( array( 'post_type' => 'page' ), 'post-new.php' ) ); ?>" class="button-secondary"><?php _e( 'New Page', 'buddypress' ); ?></a>
168
+ <input class="button-primary" type="submit" name="bp-admin-pages-single" value="<?php esc_attr_e( 'Save', 'buddypress' ) ?>" />
169
+
170
  <?php if ( !empty( $existing_pages[$name] ) ) : ?>
171
 
172
  <a href="<?php echo get_permalink( $existing_pages[$name] ); ?>" class="button-secondary" target="_bp"><?php _e( 'View', 'buddypress' ); ?></a>
180
 
181
  <?php endforeach ?>
182
 
183
+ <?php do_action( 'bp_active_external_pages' ); ?>
 
 
 
 
 
 
 
184
 
185
  </tbody>
186
  </table>
190
  }
191
 
192
  /**
193
+ * Handle saving of the BuddyPress slugs
194
  *
195
+ * @since BuddyPress (1.6)
196
  * @todo Use settings API
197
  */
198
  function bp_core_admin_slugs_setup_handler() {
199
 
200
+ if ( isset( $_POST['bp-admin-pages-submit'] ) || isset( $_POST['bp-admin-pages-single'] ) ) {
201
  if ( !check_admin_referer( 'bp-admin-pages-setup' ) )
202
  return false;
203
 
bp-core/admin/{bp-core-admin-tools.php → bp-core-tools.php} RENAMED
@@ -1,24 +1,20 @@
1
  <?php
 
2
  /**
3
- * BuddyPress Tools panel.
4
- *
5
- * @since 2.0.0
6
  *
7
- * @package BuddyPress
8
- * @subpackage Core
9
  */
10
 
11
- // Exit if accessed directly.
12
- defined( 'ABSPATH' ) || exit;
13
-
14
  /**
15
  * Render the BuddyPress Tools page.
16
  *
17
- * @since 2.0.0
18
  */
19
  function bp_core_admin_tools() {
20
  ?>
21
  <div class="wrap">
 
22
 
23
  <h2><?php esc_html_e( 'BuddyPress Tools', 'buddypress' ) ?></h2>
24
 
@@ -39,7 +35,7 @@ function bp_core_admin_tools() {
39
 
40
  <?php foreach ( bp_admin_repair_list() as $item ) : ?>
41
 
42
- <label for="<?php echo esc_attr( str_replace( '_', '-', $item[0] ) ); ?>"><input type="checkbox" class="checkbox" name="<?php echo esc_attr( $item[0] ) . '" id="' . esc_attr( str_replace( '_', '-', $item[0] ) ); ?>" value="1" /> <?php echo esc_html( $item[1] ); ?></label><br />
43
 
44
  <?php endforeach; ?>
45
 
@@ -61,7 +57,7 @@ function bp_core_admin_tools() {
61
  /**
62
  * Handle the processing and feedback of the admin tools page.
63
  *
64
- * @since 2.0.0
65
  */
66
  function bp_admin_repair_handler() {
67
  if ( ! bp_is_post_request() ) {
@@ -136,37 +132,20 @@ function bp_admin_repair_list() {
136
  );
137
  }
138
 
139
- // Blogs:
140
- // - user blog count
141
- if ( bp_is_active( 'blogs' ) ) {
142
- $repair_list[90] = array(
143
- 'bp-blog-records',
144
- __( 'Repopulate blogs records', 'buddypress' ),
145
- 'bp_admin_repair_blog_records',
146
- );
147
- }
148
-
149
  ksort( $repair_list );
150
 
151
- /**
152
- * Filters the array of the repair list.
153
- *
154
- * @since 2.0.0
155
- *
156
- * @param array $repair_list Array of values for the Repair list options.
157
- */
158
  return (array) apply_filters( 'bp_repair_list', $repair_list );
159
  }
160
 
161
  /**
162
  * Recalculate friend counts for each user.
163
  *
164
- * @since 2.0.0
165
  *
166
  * @return array
167
  */
168
  function bp_admin_repair_friend_count() {
169
- global $wpdb;
170
 
171
  if ( ! bp_is_active( 'friends' ) ) {
172
  return;
@@ -180,8 +159,6 @@ function bp_admin_repair_friend_count() {
180
  return array( 1, sprintf( $statement, $result ) );
181
  }
182
 
183
- $bp = buddypress();
184
-
185
  // Walk through all users on the site
186
  $total_users = $wpdb->get_row( "SELECT count(ID) as c FROM {$wpdb->users}" )->c;
187
 
@@ -219,12 +196,12 @@ function bp_admin_repair_friend_count() {
219
  /**
220
  * Recalculate group counts for each user.
221
  *
222
- * @since 2.0.0
223
  *
224
  * @return array
225
  */
226
  function bp_admin_repair_group_count() {
227
- global $wpdb;
228
 
229
  if ( ! bp_is_active( 'groups' ) ) {
230
  return;
@@ -238,8 +215,6 @@ function bp_admin_repair_group_count() {
238
  return array( 1, sprintf( $statement, $result ) );
239
  }
240
 
241
- $bp = buddypress();
242
-
243
  // Walk through all users on the site
244
  $total_users = $wpdb->get_row( "SELECT count(ID) as c FROM {$wpdb->users}" )->c;
245
 
@@ -263,42 +238,10 @@ function bp_admin_repair_group_count() {
263
  return array( 0, sprintf( $statement, __( 'Complete!', 'buddypress' ) ) );
264
  }
265
 
266
- /**
267
- * Recalculate user-to-blog relationships and useful blog meta data.
268
- *
269
- * @since 2.1.0
270
- *
271
- * @return array
272
- */
273
- function bp_admin_repair_blog_records() {
274
-
275
- // Description of this tool, displayed to the user
276
- $statement = __( 'Repopulating Blogs records&hellip; %s', 'buddypress' );
277
-
278
- // Default to failure text
279
- $result = __( 'Failed!', 'buddypress' );
280
-
281
- // Default to unrepaired
282
- $repair = false;
283
-
284
- // Run function if blogs component is active
285
- if ( bp_is_active( 'blogs' ) ) {
286
- $repair = bp_blogs_record_existing_blogs();
287
- }
288
-
289
- // Setup success/fail messaging
290
- if ( true === $repair ) {
291
- $result = __( 'Complete!', 'buddypress' );
292
- }
293
-
294
- // All done!
295
- return array( 0, sprintf( $statement, $result ) );
296
- }
297
-
298
  /**
299
  * Recalculate the total number of active site members.
300
  *
301
- * @since 2.0.0
302
  */
303
  function bp_admin_repair_count_members() {
304
  $statement = __( 'Counting the number of active members on the site&hellip; %s', 'buddypress' );
@@ -312,7 +255,7 @@ function bp_admin_repair_count_members() {
312
  *
313
  * Re-runs the migration from usermeta introduced in BP 2.0.
314
  *
315
- * @since 2.0.0
316
  */
317
  function bp_admin_repair_last_activity() {
318
  $statement = __( 'Determining last activity dates for each user&hellip; %s', 'buddypress' );
@@ -323,12 +266,10 @@ function bp_admin_repair_last_activity() {
323
  /**
324
  * Assemble admin notices relating success/failure of repair processes.
325
  *
326
- * @since 2.0.0
327
  *
328
- * @param string $message Feedback message.
329
- * @param string|bool $class Unused.
330
- *
331
- * @return bool
332
  */
333
  function bp_admin_tools_feedback( $message, $class = false ) {
334
  if ( is_string( $message ) ) {
@@ -340,6 +281,7 @@ function bp_admin_tools_feedback( $message, $class = false ) {
340
  switch ( count( $errors ) ) {
341
  case 0:
342
  return false;
 
343
 
344
  case 1:
345
  $message = '<p>' . $errors[0] . '</p>';
@@ -370,21 +312,14 @@ function bp_admin_tools_feedback( $message, $class = false ) {
370
  * We register this page on Network Admin as a top-level home for our
371
  * BuddyPress tools. This displays the default content.
372
  *
373
- * @since 2.0.0
374
  */
375
  function bp_core_admin_available_tools_page() {
376
  ?>
377
  <div class="wrap">
378
  <h2><?php esc_attr_e( 'Tools', 'buddypress' ) ?></h2>
379
 
380
- <?php
381
-
382
- /**
383
- * Fires inside the markup used to display the Available Tools page.
384
- *
385
- * @since 2.0.0
386
- */
387
- do_action( 'bp_network_tool_box' ); ?>
388
 
389
  </div>
390
  <?php
@@ -393,7 +328,7 @@ function bp_core_admin_available_tools_page() {
393
  /**
394
  * Render an introduction of BuddyPress tools on Available Tools page.
395
  *
396
- * @since 2.0.0
397
  */
398
  function bp_core_admin_available_tools_intro() {
399
  $query_arg = array(
@@ -403,8 +338,8 @@ function bp_core_admin_available_tools_intro() {
403
  $page = bp_core_do_network_admin() ? 'admin.php' : 'tools.php' ;
404
  $url = add_query_arg( $query_arg, bp_get_admin_url( $page ) );
405
  ?>
406
- <div class="card tool-box">
407
- <h3><?php esc_html_e( 'BuddyPress Tools', 'buddypress' ) ?></h3>
408
  <p>
409
  <?php esc_html_e( 'BuddyPress keeps track of various relationships between users, groups, and activity items. Occasionally these relationships become out of sync, most often after an import, update, or migration.', 'buddypress' ); ?>
410
  <?php printf( esc_html_x( 'Use the %s to repair these relationships.', 'buddypress tools intro', 'buddypress' ), '<a href="' . esc_url( $url ) . '">' . esc_html__( 'BuddyPress Tools', 'buddypress' ) . '</a>' ); ?>
1
  <?php
2
+
3
  /**
4
+ * BuddyPress Tools panel
 
 
5
  *
6
+ * @since BuddyPress (2.0.0)
 
7
  */
8
 
 
 
 
9
  /**
10
  * Render the BuddyPress Tools page.
11
  *
12
+ * @since BuddyPress (2.0.0)
13
  */
14
  function bp_core_admin_tools() {
15
  ?>
16
  <div class="wrap">
17
+ <?php screen_icon( 'buddypress'); ?>
18
 
19
  <h2><?php esc_html_e( 'BuddyPress Tools', 'buddypress' ) ?></h2>
20
 
35
 
36
  <?php foreach ( bp_admin_repair_list() as $item ) : ?>
37
 
38
+ <label><input type="checkbox" class="checkbox" name="<?php echo esc_attr( $item[0] ) . '" id="' . esc_attr( str_replace( '_', '-', $item[0] ) ); ?>" value="1" /> <?php echo esc_html( $item[1] ); ?></label><br />
39
 
40
  <?php endforeach; ?>
41
 
57
  /**
58
  * Handle the processing and feedback of the admin tools page.
59
  *
60
+ * @since BuddyPress (2.0.0)
61
  */
62
  function bp_admin_repair_handler() {
63
  if ( ! bp_is_post_request() ) {
132
  );
133
  }
134
 
 
 
 
 
 
 
 
 
 
 
135
  ksort( $repair_list );
136
 
 
 
 
 
 
 
 
137
  return (array) apply_filters( 'bp_repair_list', $repair_list );
138
  }
139
 
140
  /**
141
  * Recalculate friend counts for each user.
142
  *
143
+ * @since BuddyPress (2.0.0)
144
  *
145
  * @return array
146
  */
147
  function bp_admin_repair_friend_count() {
148
+ global $wpdb, $bp;
149
 
150
  if ( ! bp_is_active( 'friends' ) ) {
151
  return;
159
  return array( 1, sprintf( $statement, $result ) );
160
  }
161
 
 
 
162
  // Walk through all users on the site
163
  $total_users = $wpdb->get_row( "SELECT count(ID) as c FROM {$wpdb->users}" )->c;
164
 
196
  /**
197
  * Recalculate group counts for each user.
198
  *
199
+ * @since BuddyPress (2.0.0)
200
  *
201
  * @return array
202
  */
203
  function bp_admin_repair_group_count() {
204
+ global $wpdb, $bp;
205
 
206
  if ( ! bp_is_active( 'groups' ) ) {
207
  return;
215
  return array( 1, sprintf( $statement, $result ) );
216
  }
217
 
 
 
218
  // Walk through all users on the site
219
  $total_users = $wpdb->get_row( "SELECT count(ID) as c FROM {$wpdb->users}" )->c;
220
 
238
  return array( 0, sprintf( $statement, __( 'Complete!', 'buddypress' ) ) );
239
  }
240
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
  /**
242
  * Recalculate the total number of active site members.
243
  *
244
+ * @since BuddyPress (2.0.0)
245
  */
246
  function bp_admin_repair_count_members() {
247
  $statement = __( 'Counting the number of active members on the site&hellip; %s', 'buddypress' );
255
  *
256
  * Re-runs the migration from usermeta introduced in BP 2.0.
257
  *
258
+ * @since BuddyPress (2.0.0)
259
  */
260
  function bp_admin_repair_last_activity() {
261
  $statement = __( 'Determining last activity dates for each user&hellip; %s', 'buddypress' );
266
  /**
267
  * Assemble admin notices relating success/failure of repair processes.
268
  *
269
+ * @since BuddyPress (2.0.0)
270
  *
271
+ * @param string $message Feedback message.
272
+ * @param unknown $class Unused.
 
 
273
  */
274
  function bp_admin_tools_feedback( $message, $class = false ) {
275
  if ( is_string( $message ) ) {
281
  switch ( count( $errors ) ) {
282
  case 0:
283
  return false;
284
+ break;
285
 
286
  case 1:
287
  $message = '<p>' . $errors[0] . '</p>';
312
  * We register this page on Network Admin as a top-level home for our
313
  * BuddyPress tools. This displays the default content.
314
  *
315
+ * @since BuddyPress (2.0.0)
316
  */
317
  function bp_core_admin_available_tools_page() {
318
  ?>
319
  <div class="wrap">
320
  <h2><?php esc_attr_e( 'Tools', 'buddypress' ) ?></h2>
321
 
322
+ <?php do_action( 'bp_network_tool_box' ); ?>
 
 
 
 
 
 
 
323
 
324
  </div>
325
  <?php
328
  /**
329
  * Render an introduction of BuddyPress tools on Available Tools page.
330
  *
331
+ * @since BuddyPress (2.0.0)
332
  */
333
  function bp_core_admin_available_tools_intro() {
334
  $query_arg = array(
338
  $page = bp_core_do_network_admin() ? 'admin.php' : 'tools.php' ;
339
  $url = add_query_arg( $query_arg, bp_get_admin_url( $page ) );
340
  ?>
341
+ <div class="tool-box">
342
+ <h3 class="title"><?php esc_html_e( 'BuddyPress Tools', 'buddypress' ) ?></h3>
343
  <p>
344
  <?php esc_html_e( 'BuddyPress keeps track of various relationships between users, groups, and activity items. Occasionally these relationships become out of sync, most often after an import, update, or migration.', 'buddypress' ); ?>
345
  <?php printf( esc_html_x( 'Use the %s to repair these relationships.', 'buddypress tools intro', 'buddypress' ), '<a href="' . esc_url( $url ) . '">' . esc_html__( 'BuddyPress Tools', 'buddypress' ) . '</a>' ); ?>
bp-core/admin/css/common-rtl.css DELETED
@@ -1,258 +0,0 @@
1
- /**
2
- * CSS that is always loaded when in wp-admin
3
- *
4
- * @since 1.6.0
5
- */
6
-
7
- /* Welcome Screen
8
- ------------------------------------------------------------------------------*/
9
-
10
- body.dashboard_page_bp-about span.dashicons,
11
- body.index_page_bp-about span.dashicons {
12
- float: right;
13
- clear: right;
14
- margin: 15px 0 0 15px ;
15
- height: 90px;
16
- width: 90px;
17
- background-color: #cccccc;
18
- -webkit-border-radius: 50%;
19
- border-radius: 50%;
20
- border: 1px solid #c1c1c1;
21
- font-size: 65px;
22
- line-height: 90px;
23
- color: #999;
24
- text-align: center;
25
- }
26
-
27
- /* About Page - since 2.3.3 (WP 4.3) */
28
-
29
- .about-wrap .two-col > div {
30
- position: relative;
31
- width: 47.6%;
32
- margin-left: 4.799999999%;
33
- float: right;
34
- }
35
-
36
- .about-wrap [class$=col] .last-feature {
37
- margin-left: 0;
38
- }
39
-
40
- .about-wrap .feature-list.finer-points h4,
41
- .about-wrap .feature-list.finer-points p {
42
- margin-right: 115px;
43
- }
44
-
45
- @media screen and ( max-width: 782px ) {
46
- .about-wrap .two-col > div {
47
- width: 100%;
48
- margin: 30px 0 0;
49
- padding: 0 0 30px;
50
- border-bottom: 1px solid rgba(0, 0, 0, 0.1);
51
- }
52
- body.dashboard_page_bp-about span.dashicons,
53
- body.index_page_bp-about span.dashicons {
54
- font-size: 55px;
55
- line-height: 70px;
56
- height: 70px;
57
- width: 70px;
58
- }
59
- .about-wrap .feature-list h2 {
60
- margin: 30px 0 0;
61
- text-align: center;
62
- }
63
- .about-wrap .feature-list.finer-points h4,
64
- .about-wrap .feature-list.finer-points p {
65
- margin-right: 90px;
66
- }
67
- }
68
-
69
- /* About Page - since 2.4.0 (WP 4.4-trunk) */
70
-
71
- .about-wrap .headline-feature {
72
- margin-bottom: 1px solid rgba(0, 0, 0, 0.1);
73
- }
74
-
75
- .about-wrap .headline-feature p {
76
- font-size: 1.15em;
77
- margin: 1.25em;
78
- text-align: center;
79
- }
80
-
81
- .about-wrap .headline-feature h3 {
82
- font-size: 1.75em;
83
- font-weight: normal;
84
- margin: 1.25em 0 0.6em;
85
- text-align: center;
86
- }
87
-
88
- .about-wrap .feature-section {
89
- margin-top: 40px;
90
- }
91
-
92
- .about-wrap .changelog .feature-section {
93
- margin-top: 0;
94
- }
95
-
96
- /* User's Lists
97
- ------------------------------------------------------------------------------*/
98
-
99
- body.site-users-php th#role,
100
- body.users-php th#role,
101
- body.users_page_bp-signups th#count_sent {
102
- width: 10%;
103
- }
104
-
105
- body.site-users-php th#name,
106
- body.site-users-php th#email,
107
- body.users-php th#name,
108
- body.users-php th#registered,
109
- body.users-php th#email,
110
- body.users_page_bp-signups th#name,
111
- body.users_page_bp-signups th#registered,
112
- body.users_page_bp-signups th#email,
113
- body.users_page_bp-signups th#date_sent {
114
- width: 15%;
115
- }
116
-
117
- body.users-php th#blogs,
118
- body.users_page_bp-signups th#blogs {
119
- width: 20%;
120
- }
121
-
122
- body.users_page_bp-signups th.column-count_sent,
123
- body.users_page_bp-signups td.count_sent {
124
- text-align: center;
125
- }
126
-
127
- /* Tools */
128
- #adminmenu .toplevel_page_network-tools div.wp-menu-image:before {
129
- content: "";
130
- }
131
-
132
- /* Components
133
- ------------------------------------------------------------------------------*/
134
-
135
- /* Dashicons */
136
- #adminmenu #toplevel_page_bp-activity .wp-menu-image:before,
137
- #adminmenu #toplevel_page_bp-activity_user .wp-menu-image:before,
138
- #adminmenu #toplevel_page_bp-activity_network .wp-menu-image:before {
139
- content: "\f452";
140
- }
141
-
142
- #adminmenu #toplevel_page_bp-groups .wp-menu-image:before,
143
- #adminmenu #toplevel_page_bp-groups_user .wp-menu-image:before,
144
- #adminmenu #toplevel_page_bp-groups_network .wp-menu-image:before {
145
- content: "\f456";
146
- }
147
-
148
- #adminmenu #toplevel_page_bp-notifications .wp-menu-image:before,
149
- #adminmenu #toplevel_page_bp-notifications_user .wp-menu-image:before,
150
- #adminmenu #toplevel_page_bp-notifications_network .wp-menu-image:before {
151
- content: "\f439";
152
- }
153
-
154
- #adminmenu #toplevel_page_bp-messages .wp-menu-image:before,
155
- #adminmenu #toplevel_page_bp-messages_user .wp-menu-image:before,
156
- #adminmenu #toplevel_page_bp-messages_network .wp-menu-image:before {
157
- content: "\f457";
158
- }
159
-
160
- #adminmenu #toplevel_page_bp-friends .wp-menu-image:before,
161
- #adminmenu #toplevel_page_bp-friends_user .wp-menu-image:before,
162
- #adminmenu #toplevel_page_bp-friends_network .wp-menu-image:before{
163
- content: "\f454";
164
- }
165
-
166
- #adminmenu #toplevel_page_bp-settings .wp-menu-image:before,
167
- #adminmenu #toplevel_page_bp-settings_user .wp-menu-image:before,
168
- #adminmenu #toplevel_page_bp-settings_network .wp-menu-image:before {
169
- content: "\f108";
170
- }
171
-
172
- #adminmenu li.toplevel_page_bp-components .wp-menu-image,
173
- #adminmenu li.toplevel_page_bp-general-settings .wp-menu-image {
174
- content: "\f448";
175
- }
176
-
177
- /* Settings - Dashicons (WP 3.8+) */
178
- .settings_page_bp-components td.plugin-title span {
179
- float: right;
180
- width: 18px;
181
- height: 18px;
182
- margin-left: 5px;
183
- }
184
-
185
- .settings_page_bp-components td.plugin-title span:before {
186
- font-family: 'dashicons';
187
- font-size: 18px;
188
- }
189
-
190
- .settings_page_bp-components tr.activity td.plugin-title span:before {
191
- content: "\f452";
192
- }
193
-
194
- .settings_page_bp-components tr.notifications td.plugin-title span:before {
195
- content: "\f339";
196
- }
197
-
198
- .settings_page_bp-components tr.xprofile td.plugin-title span:before {
199
- content: "\f336";
200
- }
201
-
202
- .settings_page_bp-components tr.settings td.plugin-title span:before {
203
- content: "\f108";
204
- }
205
-
206
- .settings_page_bp-components tr.groups td.plugin-title span:before {
207
- content: "\f456";
208
- }
209
-
210
- .settings_page_bp-components tr.messages td.plugin-title span:before {
211
- content: "\f457";
212
- }
213
-
214
- .settings_page_bp-components tr.forums td.plugin-title span:before {
215
- content: "\f452";
216
- }
217
-
218
- .settings_page_bp-components tr.blogs td.plugin-title span:before {
219
- content: "\f120";
220
- }
221
-
222
- .settings_page_bp-components tr.friends td.plugin-title span:before {
223
- content: "\f454";
224
- }
225
-
226
- #bp-admin-component-form .widefat th {
227
- display: table-cell;
228
- vertical-align: top;
229
- }
230
-
231
- /* Version Badge */
232
-
233
- .bp-badge {
234
- font: normal 150px/1 'dashicons' !important;
235
- color: #D84800;
236
- display: inline-block;
237
- }
238
-
239
- .bp-badge:before {
240
- content: "\f448";
241
- }
242
-
243
- .about-wrap .bp-badge {
244
- position: absolute;
245
- top: 0;
246
- left: 0;
247
- }
248
-
249
- /* About Page - since 2.3.3 (WP 4.3) */
250
-
251
- @media only screen and (max-width: 500px) {
252
- .about-wrap .bp-badge {
253
- position: relative;
254
- margin: 10px auto;
255
- top: auto;
256
- left: auto;
257
- }
258
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-core/admin/css/common-rtl.min.css DELETED
@@ -1 +0,0 @@
1
- body.dashboard_page_bp-about span.dashicons,body.index_page_bp-about span.dashicons{float:right;clear:right;margin:15px 0 0 15px;height:90px;width:90px;background-color:#ccc;-webkit-border-radius:50%;border-radius:50%;border:1px solid #c1c1c1;font-size:65px;line-height:90px;color:#999;text-align:center}.about-wrap .two-col>div{position:relative;width:47.6%;margin-left:4.799999999%;float:right}.about-wrap [class$=col] .last-feature{margin-left:0}.about-wrap .feature-list.finer-points h4,.about-wrap .feature-list.finer-points p{margin-right:115px}@media screen and (max-width:782px){.about-wrap .two-col>div{width:100%;margin:30px 0 0;padding:0 0 30px;border-bottom:1px solid rgba(0,0,0,.1)}body.dashboard_page_bp-about span.dashicons,body.index_page_bp-about span.dashicons{font-size:55px;line-height:70px;height:70px;width:70px}.about-wrap .feature-list h2{margin:30px 0 0;text-align:center}.about-wrap .feature-list.finer-points h4,.about-wrap .feature-list.finer-points p{margin-right:90px}}.about-wrap .headline-feature{margin-bottom:1px solid rgba(0,0,0,.1)}.about-wrap .headline-feature p{font-size:1.15em;margin:1.25em;text-align:center}.about-wrap .headline-feature h3{font-size:1.75em;font-weight:400;margin:1.25em 0 .6em;text-align:center}.about-wrap .feature-section{margin-top:40px}.about-wrap .changelog .feature-section{margin-top:0}body.site-users-php th#role,body.users-php th#role,body.users_page_bp-signups th#count_sent{width:10%}body.site-users-php th#email,body.site-users-php th#name,body.users-php th#email,body.users-php th#name,body.users-php th#registered,body.users_page_bp-signups th#date_sent,body.users_page_bp-signups th#email,body.users_page_bp-signups th#name,body.users_page_bp-signups th#registered{width:15%}body.users-php th#blogs,body.users_page_bp-signups th#blogs{width:20%}body.users_page_bp-signups td.count_sent,body.users_page_bp-signups th.column-count_sent{text-align:center}#adminmenu .toplevel_page_network-tools div.wp-menu-image:before{content:""}#adminmenu #toplevel_page_bp-activity .wp-menu-image:before,#adminmenu #toplevel_page_bp-activity_network .wp-menu-image:before,#adminmenu #toplevel_page_bp-activity_user .wp-menu-image:before{content:"\f452"}#adminmenu #toplevel_page_bp-groups .wp-menu-image:before,#adminmenu #toplevel_page_bp-groups_network .wp-menu-image:before,#adminmenu #toplevel_page_bp-groups_user .wp-menu-image:before{content:"\f456"}#adminmenu #toplevel_page_bp-notifications .wp-menu-image:before,#adminmenu #toplevel_page_bp-notifications_network .wp-menu-image:before,#adminmenu #toplevel_page_bp-notifications_user .wp-menu-image:before{content:"\f439"}#adminmenu #toplevel_page_bp-messages .wp-menu-image:before,#adminmenu #toplevel_page_bp-messages_network .wp-menu-image:before,#adminmenu #toplevel_page_bp-messages_user .wp-menu-image:before{content:"\f457"}#adminmenu #toplevel_page_bp-friends .wp-menu-image:before,#adminmenu #toplevel_page_bp-friends_network .wp-menu-image:before,#adminmenu #toplevel_page_bp-friends_user .wp-menu-image:before{content:"\f454"}#adminmenu #toplevel_page_bp-settings .wp-menu-image:before,#adminmenu #toplevel_page_bp-settings_network .wp-menu-image:before,#adminmenu #toplevel_page_bp-settings_user .wp-menu-image:before{content:"\f108"}#adminmenu li.toplevel_page_bp-components .wp-menu-image,#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image{content:"\f448"}.settings_page_bp-components td.plugin-title span{float:right;width:18px;height:18px;margin-left:5px}.settings_page_bp-components td.plugin-title span:before{font-family:dashicons;font-size:18px}.settings_page_bp-components tr.activity td.plugin-title span:before{content:"\f452"}.settings_page_bp-components tr.notifications td.plugin-title span:before{content:"\f339"}.settings_page_bp-components tr.xprofile td.plugin-title span:before{content:"\f336"}.settings_page_bp-components tr.settings td.plugin-title span:before{content:"\f108"}.settings_page_bp-components tr.groups td.plugin-title span:before{content:"\f456"}.settings_page_bp-components tr.messages td.plugin-title span:before{content:"\f457"}.settings_page_bp-components tr.forums td.plugin-title span:before{content:"\f452"}.settings_page_bp-components tr.blogs td.plugin-title span:before{content:"\f120"}.settings_page_bp-components tr.friends td.plugin-title span:before{content:"\f454"}#bp-admin-component-form .widefat th{display:table-cell;vertical-align:top}.bp-badge{font:400 150px/1 dashicons!important;color:#D84800;display:inline-block}.bp-badge:before{content:"\f448"}.about-wrap .bp-badge{position:absolute;top:0;left:0}@media only screen and (max-width:500px){.about-wrap .bp-badge{position:relative;margin:10px auto;top:auto;left:auto}}
 
bp-core/admin/css/common.css CHANGED
@@ -1,132 +1,121 @@
1
  /**
2
  * CSS that is always loaded when in wp-admin
3
  *
4
- * @since 1.6.0
5
  */
6
 
7
- /* Welcome Screen
8
  ------------------------------------------------------------------------------*/
9
 
10
- body.dashboard_page_bp-about span.dashicons,
11
- body.index_page_bp-about span.dashicons {
12
- float: left;
13
- clear: left;
14
- margin: 15px 15px 0 0 ;
15
- height: 90px;
16
- width: 90px;
17
- background-color: #cccccc;
18
- -webkit-border-radius: 50%;
19
- border-radius: 50%;
20
- border: 1px solid #c1c1c1;
21
- font-size: 65px;
22
- line-height: 90px;
23
- color: #999;
24
- text-align: center;
25
- }
26
-
27
- /* About Page - since 2.3.3 (WP 4.3) */
28
-
29
- .about-wrap .two-col > div {
30
- position: relative;
31
- width: 47.6%;
32
- margin-right: 4.799999999%;
33
- float: left;
34
- }
35
-
36
- .about-wrap [class$=col] .last-feature {
37
- margin-right: 0;
38
  }
39
 
40
- .about-wrap .feature-list.finer-points h4,
41
- .about-wrap .feature-list.finer-points p {
42
- margin-left: 115px;
43
  }
44
 
45
- @media screen and ( max-width: 782px ) {
46
- .about-wrap .two-col > div {
47
- width: 100%;
48
- margin: 30px 0 0;
49
- padding: 0 0 30px;
50
- border-bottom: 1px solid rgba(0, 0, 0, 0.1);
51
- }
52
- body.dashboard_page_bp-about span.dashicons,
53
- body.index_page_bp-about span.dashicons {
54
- font-size: 55px;
55
- line-height: 70px;
56
- height: 70px;
57
- width: 70px;
58
- }
59
- .about-wrap .feature-list h2 {
60
- margin: 30px 0 0;
61
- text-align: center;
62
- }
63
- .about-wrap .feature-list.finer-points h4,
64
- .about-wrap .feature-list.finer-points p {
65
- margin-left: 90px;
66
- }
67
- }
68
-
69
- /* About Page - since 2.4.0 (WP 4.4-trunk) */
70
-
71
- .about-wrap .headline-feature {
72
- margin-bottom: 1px solid rgba(0, 0, 0, 0.1);
73
  }
74
 
75
- .about-wrap .headline-feature p {
76
- font-size: 1.15em;
77
- margin: 1.25em;
78
- text-align: center;
79
- }
80
 
81
- .about-wrap .headline-feature h3 {
82
- font-size: 1.75em;
83
- font-weight: normal;
84
- margin: 1.25em 0 0.6em;
85
- text-align: center;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  }
87
 
88
- .about-wrap .feature-section {
89
- margin-top: 40px;
 
90
  }
91
 
92
- .about-wrap .changelog .feature-section {
93
- margin-top: 0;
94
  }
95
-
96
- /* User's Lists
97
- ------------------------------------------------------------------------------*/
98
-
99
- body.site-users-php th#role,
100
- body.users-php th#role,
101
- body.users_page_bp-signups th#count_sent {
102
- width: 10%;
103
  }
104
-
105
- body.site-users-php th#name,
106
- body.site-users-php th#email,
107
- body.users-php th#name,
108
- body.users-php th#registered,
109
- body.users-php th#email,
110
- body.users_page_bp-signups th#name,
111
- body.users_page_bp-signups th#registered,
112
- body.users_page_bp-signups th#email,
113
- body.users_page_bp-signups th#date_sent {
114
- width: 15%;
115
  }
116
-
117
- body.users-php th#blogs,
118
- body.users_page_bp-signups th#blogs {
119
- width: 20%;
120
  }
121
-
122
- body.users_page_bp-signups th.column-count_sent,
123
- body.users_page_bp-signups td.count_sent {
124
- text-align: center;
125
  }
126
-
127
- /* Tools */
128
- #adminmenu .toplevel_page_network-tools div.wp-menu-image:before {
129
- content: "";
130
  }
131
 
132
  /* Components
@@ -174,6 +163,22 @@ body.users_page_bp-signups td.count_sent {
174
  content: "\f448";
175
  }
176
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
  /* Settings - Dashicons (WP 3.8+) */
178
  .settings_page_bp-components td.plugin-title span {
179
  float: left;
@@ -223,6 +228,143 @@ body.users_page_bp-signups td.count_sent {
223
  content: "\f454";
224
  }
225
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  #bp-admin-component-form .widefat th {
227
  display: table-cell;
228
  vertical-align: top;
@@ -232,7 +374,7 @@ body.users_page_bp-signups td.count_sent {
232
 
233
  .bp-badge {
234
  font: normal 150px/1 'dashicons' !important;
235
- color: #D84800;
236
  display: inline-block;
237
  }
238
 
@@ -245,14 +387,47 @@ body.users_page_bp-signups td.count_sent {
245
  top: 0;
246
  right: 0;
247
  }
 
 
 
 
248
 
249
- /* About Page - since 2.3.3 (WP 4.3) */
 
250
 
251
- @media only screen and (max-width: 500px) {
252
- .about-wrap .bp-badge {
253
- position: relative;
254
- margin: 10px auto;
255
- top: auto;
256
- right: auto;
 
 
 
 
 
257
  }
258
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  /**
2
  * CSS that is always loaded when in wp-admin
3
  *
4
+ * @since BuddyPress (1.6)
5
  */
6
 
7
+ /* Icon 32's
8
  ------------------------------------------------------------------------------*/
9
 
10
+ body.branch-3-6 div#icon-buddypress,
11
+ body.branch-3-7 div#icon-buddypress {
12
+ background: url('../images/icons32.png') no-repeat -370px -6px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  }
14
 
15
+ body.branch-3-6 div#icon-buddypress-activity,
16
+ body.branch-3-7 div#icon-buddypress-activity {
17
+ background: url('../images/icons32.png') no-repeat -10px -6px;
18
  }
19
 
20
+ body.branch-3-6 div#icon-buddypress-groups,
21
+ body.branch-3-7 div#icon-buddypress-groups {
22
+ background: url('../images/icons32.png') no-repeat -250px -6px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  }
24
 
25
+ /* Menu Icons
26
+ ------------------------------------------------------------------------------*/
 
 
 
27
 
28
+ /* Backpat */
29
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-components .wp-menu-image,
30
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image,
31
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-components .wp-menu-image,
32
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image {
33
+ background-image: url('../images/menu.png') !important;
34
+ background-position: -178px -34px;
35
+ }
36
+
37
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-components:hover .wp-menu-image,
38
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-general-settings:hover .wp-menu-image,
39
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-components.wp-has-current-submenu .wp-menu-image,
40
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-general-settings.wp-has-current-submenu .wp-menu-image,
41
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-components:hover .wp-menu-image,
42
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-general-settings:hover .wp-menu-image,
43
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-components.wp-has-current-submenu .wp-menu-image,
44
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-general-settings.wp-has-current-submenu .wp-menu-image {
45
+ background-position: -178px -2px;
46
+ }
47
+
48
+ /* Activity */
49
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-activity .wp-menu-image,
50
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-activity_network .wp-menu-image,
51
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-activity .wp-menu-image,
52
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-activity_network .wp-menu-image {
53
+ background-image: url('../images/menu.png');
54
+ background-position: 0 -34px;
55
+ }
56
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-activity:hover .wp-menu-image,
57
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-activity.current .wp-menu-image,
58
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-activity.wp-has-current-submenu .wp-menu-image,
59
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-activity_network:hover .wp-menu-image,
60
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-activity_network.current .wp-menu-image,
61
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-activity_network.wp-has-current-submenu .wp-menu-image,
62
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-activity:hover .wp-menu-image,
63
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-activity.current .wp-menu-image,
64
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-activity.wp-has-current-submenu .wp-menu-image,
65
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-activity_network:hover .wp-menu-image,
66
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-activity_network.current .wp-menu-image,
67
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-activity_network.wp-has-current-submenu .wp-menu-image {
68
+ background-position: 0 -2px;
69
+ }
70
+
71
+ /* Groups */
72
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-groups .wp-menu-image,
73
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-groups_network .wp-menu-image,
74
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-groups .wp-menu-image,
75
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-groups_network .wp-menu-image {
76
+ background-image: url('../images/menu.png');
77
+ background-position: -61px -34px;
78
+ }
79
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-groups:hover .wp-menu-image,
80
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-groups.current .wp-menu-image,
81
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-groups.wp-has-current-submenu .wp-menu-image,
82
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-groups_network:hover .wp-menu-image,
83
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-groups_network.current .wp-menu-image,
84
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-groups_network.wp-has-current-submenu .wp-menu-image,
85
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-groups:hover .wp-menu-image,
86
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-groups.current .wp-menu-image,
87
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-groups.wp-has-current-submenu .wp-menu-image,
88
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-groups_network:hover .wp-menu-image,
89
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-groups_network.current .wp-menu-image,
90
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-groups_network.wp-has-current-submenu .wp-menu-image {
91
+ background-position: -61px -2px;
92
  }
93
 
94
+ /* Tools */
95
+ #adminmenu .toplevel_page_network-tools div.wp-menu-image:before {
96
+ content: "";
97
  }
98
 
99
+ th.column-gid {
100
+ width: 60px;
101
  }
102
+ td.column-gid {
103
+ vertical-align: middle;
 
 
 
 
 
 
104
  }
105
+ table.bp-group-members th,
106
+ table.bp-group-members td {
107
+ padding: 5px 0;
 
 
 
 
 
 
 
 
108
  }
109
+ table.bp-group-members .uid-column {
110
+ padding-left: 20px;
111
+ padding-right: 20px;
 
112
  }
113
+ table.bp-group-members .uname-column {
114
+ width: 70%;
 
 
115
  }
116
+ table.bp-group-members .urole-column {
117
+ padding-left: 20px;
118
+ padding-right: 20px;
 
119
  }
120
 
121
  /* Components
163
  content: "\f448";
164
  }
165
 
166
+ /* Dashicons overrides for backward compatibility */
167
+ body.branch-3-6 #adminmenu #toplevel_page_bp-activity .wp-menu-image:before,
168
+ body.branch-3-6 #adminmenu #toplevel_page_bp-activity_network .wp-menu-image:before,
169
+ body.branch-3-6 #adminmenu #toplevel_page_bp-groups .wp-menu-image:before,
170
+ body.branch-3-6 #adminmenu #toplevel_page_bp-groups_network .wp-menu-image:before,
171
+ body.branch-3-6 #adminmenu li.toplevel_page_bp-components .wp-menu-image,
172
+ body.branch-3-6 #adminmenu li.toplevel_page_bp-general-settings .wp-menu-image,
173
+ body.branch-3-7 #adminmenu #toplevel_page_bp-activity .wp-menu-image:before,
174
+ body.branch-3-7 #adminmenu #toplevel_page_bp-activity_network .wp-menu-image:before,
175
+ body.branch-3-7 #adminmenu #toplevel_page_bp-groups .wp-menu-image:before,
176
+ body.branch-3-7 #adminmenu #toplevel_page_bp-groups_network .wp-menu-image:before,
177
+ body.branch-3-7 #adminmenu li.toplevel_page_bp-components .wp-menu-image,
178
+ body.branch-3-7 #adminmenu li.toplevel_page_bp-general-settings .wp-menu-image {
179
+ content: "";
180
+ }
181
+
182
  /* Settings - Dashicons (WP 3.8+) */
183
  .settings_page_bp-components td.plugin-title span {
184
  float: left;
228
  content: "\f454";
229
  }
230
 
231
+ /* Settings - Legacy (< WP 3.8) */
232
+ body.branch-3-6.settings_page_bp-components tr.activity td.plugin-title span:before,
233
+ body.branch-3-6.settings_page_bp-components tr.notifications td.plugin-title span:before,
234
+ body.branch-3-6.settings_page_bp-components tr.xprofile td.plugin-title span:before,
235
+ body.branch-3-6.settings_page_bp-components tr.settings td.plugin-title span:before,
236
+ body.branch-3-6.settings_page_bp-components tr.groups td.plugin-title span:before,
237
+ body.branch-3-6.settings_page_bp-components tr.messages td.plugin-title span:before,
238
+ body.branch-3-6.settings_page_bp-components tr.forums td.plugin-title span:before,
239
+ body.branch-3-6.settings_page_bp-components tr.blogs td.plugin-title span:before,
240
+ body.branch-3-6.settings_page_bp-components tr.friends td.plugin-title span:before,
241
+ body.branch-3-7.settings_page_bp-components tr.activity td.plugin-title span:before,
242
+ body.branch-3-7.settings_page_bp-components tr.notifications td.plugin-title span:before,
243
+ body.branch-3-7.settings_page_bp-components tr.xprofile td.plugin-title span:before,
244
+ body.branch-3-7.settings_page_bp-components tr.settings td.plugin-title span:before,
245
+ body.branch-3-7.settings_page_bp-components tr.groups td.plugin-title span:before,
246
+ body.branch-3-7.settings_page_bp-components tr.messages td.plugin-title span:before,
247
+ body.branch-3-7.settings_page_bp-components tr.forums td.plugin-title span:before,
248
+ body.branch-3-7.settings_page_bp-components tr.blogs td.plugin-title span:before,
249
+ body.branch-3-7.settings_page_bp-components tr.friends td.plugin-title span:before {
250
+ content: "";
251
+ }
252
+
253
+ body.branch-3-6.settings_page_bp-components td.plugin-title span,
254
+ body.branch-3-7.settings_page_bp-components td.plugin-title span {
255
+ background-image: url('../images/menu.png');
256
+ background-position: -4px -40px;
257
+ background-repeat: no-repeat;
258
+ }
259
+
260
+ body.branch-3-6.settings_page_bp-components tr.active td.plugin-title span,
261
+ body.branch-3-7.settings_page_bp-components tr.active td.plugin-title span {
262
+ background-position-y: -7px;
263
+ }
264
+
265
+ body.branch-3-6.settings_page_bp-components tr.activity td.plugin-title span,
266
+ body.branch-3-7.settings_page_bp-components tr.activity td.plugin-title span {
267
+ background-position: -4px -40px;
268
+ }
269
+
270
+ body.branch-3-6.settings_page_bp-components tr.activity.active td.plugin-title span,
271
+ body.branch-3-7.settings_page_bp-components tr.activity.active td.plugin-title span {
272
+ background-position: -4px -7px;
273
+ }
274
+
275
+ body.branch-3-6.settings_page_bp-components tr.xprofile td.plugin-title span,
276
+ body.branch-3-7.settings_page_bp-components tr.xprofile td.plugin-title span {
277
+ background-image: url('../images/menu-wp.png');
278
+ background-position: -305px -40px;
279
+ }
280
+
281
+ body.branch-3-6.settings_page_bp-components tr.xprofile.active td.plugin-title span,
282
+ body.branch-3-7.settings_page_bp-components tr.xprofile.active td.plugin-title span {
283
+ background-position: -305px -7px;
284
+ }
285
+
286
+ body.branch-3-6.settings_page_bp-components tr.settings td.plugin-title span,
287
+ body.branch-3-7.settings_page_bp-components tr.settings td.plugin-title span {
288
+ background-image: url('../images/menu-wp.png');
289
+ background-position: -334px -40px;
290
+ }
291
+
292
+ body.branch-3-6.settings_page_bp-components tr.settings.active td.plugin-title span,
293
+ body.branch-3-7.settings_page_bp-components tr.settings.active td.plugin-title span {
294
+ background-position: -334px -7px;
295
+ }
296
+
297
+ body.branch-3-6.settings_page_bp-components tr.groups td.plugin-title span,
298
+ body.branch-3-7.settings_page_bp-components tr.groups td.plugin-title span {
299
+ background-position: -66px -40px;
300
+ }
301
+
302
+ body.branch-3-6.settings_page_bp-components tr.groups.active td.plugin-title span,
303
+ body.branch-3-7.settings_page_bp-components tr.groups.active td.plugin-title span {
304
+ background-position: -66px -7px;
305
+ }
306
+
307
+ body.branch-3-6.settings_page_bp-components tr.messages td.plugin-title span,
308
+ body.branch-3-7.settings_page_bp-components tr.messages td.plugin-title span {
309
+ background-position: -154px -40px;
310
+ }
311
+
312
+ body.branch-3-6.settings_page_bp-components tr.messages.active td.plugin-title span,
313
+ body.branch-3-7.settings_page_bp-components tr.messages.active td.plugin-title span {
314
+ background-position: -154px -7px;
315
+ }
316
+
317
+ body.branch-3-6.settings_page_bp-components tr.forums td.plugin-title span,
318
+ body.branch-3-7.settings_page_bp-components tr.forums td.plugin-title span {
319
+ background-image: url('../images/menu-wp.png');
320
+ background-position: -36px -40px;
321
+ }
322
+
323
+ body.branch-3-6.settings_page_bp-components tr.forums.active td.plugin-title span,
324
+ body.branch-3-7.settings_page_bp-components tr.forums.active td.plugin-title span {
325
+ background-position: -36px -7px;
326
+ }
327
+
328
+ body.branch-3-6.settings_page_bp-components tr.blogs td.plugin-title span,
329
+ body.branch-3-7.settings_page_bp-components tr.blogs td.plugin-title span {
330
+ background-position: -125px -40px;
331
+ }
332
+
333
+ body.branch-3-6.settings_page_bp-components tr.blogs.active td.plugin-title span,
334
+ body.branch-3-7.settings_page_bp-components tr.blogs.active td.plugin-title span {
335
+ background-position: -125px -7px;
336
+ }
337
+
338
+ body.branch-3-6.settings_page_bp-components tr.friends td.plugin-title span,
339
+ body.branch-3-7.settings_page_bp-components tr.friends td.plugin-title span {
340
+ background-position: -95px -40px;
341
+ }
342
+
343
+ body.branch-3-6.settings_page_bp-components tr.friends.active td.plugin-title span,
344
+ body.branch-3-7.settings_page_bp-components tr.friends.active td.plugin-title span {
345
+ background-position: -95px -7px;
346
+ }
347
+
348
+ body.branch-3-6.settings_page_bp-components tr.core td.plugin-title span,
349
+ body.branch-3-7.settings_page_bp-components tr.core td.plugin-title span {
350
+ background-position: -184px -40px;
351
+ }
352
+
353
+ body.branch-3-6.settings_page_bp-components tr.core.active td.plugin-title span,
354
+ body.branch-3-7.settings_page_bp-components tr.core.active td.plugin-title span {
355
+ background-position: -184px -7px;
356
+ }
357
+
358
+ body.branch-3-6.settings_page_bp-components tr.members td.plugin-title span,
359
+ body.branch-3-7.settings_page_bp-components tr.members td.plugin-title span {
360
+ background-position: -36px -40px;
361
+ }
362
+
363
+ body.branch-3-6.settings_page_bp-components tr.members.active td.plugin-title span,
364
+ body.branch-3-7.settings_page_bp-components tr.members.active td.plugin-title span {
365
+ background-position: -36px -7px;
366
+ }
367
+
368
  #bp-admin-component-form .widefat th {
369
  display: table-cell;
370
  vertical-align: top;
374
 
375
  .bp-badge {
376
  font: normal 150px/1 'dashicons' !important;
377
+ color: #000;
378
  display: inline-block;
379
  }
380
 
387
  top: 0;
388
  right: 0;
389
  }
390
+ body.rtl .about-wrap .bp-badge {
391
+ right: auto;
392
+ left: 0;
393
+ }
394
 
395
+ /* HiDPI
396
+ ------------------------------------------------------------------------------*/
397
 
398
+ @media only screen and (-webkit-min-device-pixel-ratio: 1.5) {
399
+
400
+ /* Icon 32 */
401
+ body.branch-3-6 div#icon-buddypress,
402
+ body.branch-3-6 div#icon-buddypress-activity,
403
+ body.branch-3-6 div#icon-buddypress-groups,
404
+ body.branch-3-7 div#icon-buddypress,
405
+ body.branch-3-7 div#icon-buddypress-activity,
406
+ body.branch-3-7 div#icon-buddypress-groups {
407
+ background-image: url('../images/icons64.png');
408
+ background-size: 419px 45px;
409
  }
410
+
411
+ /* Backpat */
412
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-components .wp-menu-image,
413
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image,
414
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-activity .wp-menu-image,
415
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-activity_network .wp-menu-image,
416
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-groups .wp-menu-image,
417
+ body.branch-3-6 ul#adminmenu li.toplevel_page_bp-groups_network .wp-menu-image,
418
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-components .wp-menu-image,
419
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image,
420
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-activity .wp-menu-image,
421
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-activity_network .wp-menu-image,
422
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-groups .wp-menu-image,
423
+ body.branch-3-7 ul#adminmenu li.toplevel_page_bp-groups_network .wp-menu-image {
424
+ background-image: url('../images/menu-2x.png') !important;
425
+ background-size: 209px 64px;
426
+ }
427
+
428
+ /* Badge */
429
+ .bp-badge {
430
+ background-image: url('../images/badge-2x.png');
431
+ background-size: 173px 194px;
432
+ }
433
+ }
bp-core/admin/css/common.min.css CHANGED
@@ -1 +1 @@
1
- body.dashboard_page_bp-about span.dashicons,body.index_page_bp-about span.dashicons{float:left;clear:left;margin:15px 15px 0 0;height:90px;width:90px;background-color:#ccc;-webkit-border-radius:50%;border-radius:50%;border:1px solid #c1c1c1;font-size:65px;line-height:90px;color:#999;text-align:center}.about-wrap .two-col>div{position:relative;width:47.6%;margin-right:4.799999999%;float:left}.about-wrap [class$=col] .last-feature{margin-right:0}.about-wrap .feature-list.finer-points h4,.about-wrap .feature-list.finer-points p{margin-left:115px}@media screen and (max-width:782px){.about-wrap .two-col>div{width:100%;margin:30px 0 0;padding:0 0 30px;border-bottom:1px solid rgba(0,0,0,.1)}body.dashboard_page_bp-about span.dashicons,body.index_page_bp-about span.dashicons{font-size:55px;line-height:70px;height:70px;width:70px}.about-wrap .feature-list h2{margin:30px 0 0;text-align:center}.about-wrap .feature-list.finer-points h4,.about-wrap .feature-list.finer-points p{margin-left:90px}}.about-wrap .headline-feature{margin-bottom:1px solid rgba(0,0,0,.1)}.about-wrap .headline-feature p{font-size:1.15em;margin:1.25em;text-align:center}.about-wrap .headline-feature h3{font-size:1.75em;font-weight:400;margin:1.25em 0 .6em;text-align:center}.about-wrap .feature-section{margin-top:40px}.about-wrap .changelog .feature-section{margin-top:0}body.site-users-php th#role,body.users-php th#role,body.users_page_bp-signups th#count_sent{width:10%}body.site-users-php th#email,body.site-users-php th#name,body.users-php th#email,body.users-php th#name,body.users-php th#registered,body.users_page_bp-signups th#date_sent,body.users_page_bp-signups th#email,body.users_page_bp-signups th#name,body.users_page_bp-signups th#registered{width:15%}body.users-php th#blogs,body.users_page_bp-signups th#blogs{width:20%}body.users_page_bp-signups td.count_sent,body.users_page_bp-signups th.column-count_sent{text-align:center}#adminmenu .toplevel_page_network-tools div.wp-menu-image:before{content:""}#adminmenu #toplevel_page_bp-activity .wp-menu-image:before,#adminmenu #toplevel_page_bp-activity_network .wp-menu-image:before,#adminmenu #toplevel_page_bp-activity_user .wp-menu-image:before{content:"\f452"}#adminmenu #toplevel_page_bp-groups .wp-menu-image:before,#adminmenu #toplevel_page_bp-groups_network .wp-menu-image:before,#adminmenu #toplevel_page_bp-groups_user .wp-menu-image:before{content:"\f456"}#adminmenu #toplevel_page_bp-notifications .wp-menu-image:before,#adminmenu #toplevel_page_bp-notifications_network .wp-menu-image:before,#adminmenu #toplevel_page_bp-notifications_user .wp-menu-image:before{content:"\f439"}#adminmenu #toplevel_page_bp-messages .wp-menu-image:before,#adminmenu #toplevel_page_bp-messages_network .wp-menu-image:before,#adminmenu #toplevel_page_bp-messages_user .wp-menu-image:before{content:"\f457"}#adminmenu #toplevel_page_bp-friends .wp-menu-image:before,#adminmenu #toplevel_page_bp-friends_network .wp-menu-image:before,#adminmenu #toplevel_page_bp-friends_user .wp-menu-image:before{content:"\f454"}#adminmenu #toplevel_page_bp-settings .wp-menu-image:before,#adminmenu #toplevel_page_bp-settings_network .wp-menu-image:before,#adminmenu #toplevel_page_bp-settings_user .wp-menu-image:before{content:"\f108"}#adminmenu li.toplevel_page_bp-components .wp-menu-image,#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image{content:"\f448"}.settings_page_bp-components td.plugin-title span{float:left;width:18px;height:18px;margin-right:5px}.settings_page_bp-components td.plugin-title span:before{font-family:dashicons;font-size:18px}.settings_page_bp-components tr.activity td.plugin-title span:before{content:"\f452"}.settings_page_bp-components tr.notifications td.plugin-title span:before{content:"\f339"}.settings_page_bp-components tr.xprofile td.plugin-title span:before{content:"\f336"}.settings_page_bp-components tr.settings td.plugin-title span:before{content:"\f108"}.settings_page_bp-components tr.groups td.plugin-title span:before{content:"\f456"}.settings_page_bp-components tr.messages td.plugin-title span:before{content:"\f457"}.settings_page_bp-components tr.forums td.plugin-title span:before{content:"\f452"}.settings_page_bp-components tr.blogs td.plugin-title span:before{content:"\f120"}.settings_page_bp-components tr.friends td.plugin-title span:before{content:"\f454"}#bp-admin-component-form .widefat th{display:table-cell;vertical-align:top}.bp-badge{font:400 150px/1 dashicons!important;color:#D84800;display:inline-block}.bp-badge:before{content:"\f448"}.about-wrap .bp-badge{position:absolute;top:0;right:0}@media only screen and (max-width:500px){.about-wrap .bp-badge{position:relative;margin:10px auto;top:auto;right:auto}}
1
+ body.branch-3-6 div#icon-buddypress,body.branch-3-7 div#icon-buddypress{background:url('../images/icons32.png') no-repeat -370px -6px}body.branch-3-6 div#icon-buddypress-activity,body.branch-3-7 div#icon-buddypress-activity{background:url('../images/icons32.png') no-repeat -10px -6px}body.branch-3-6 div#icon-buddypress-groups,body.branch-3-7 div#icon-buddypress-groups{background:url('../images/icons32.png') no-repeat -250px -6px}body.branch-3-6 ul#adminmenu li.toplevel_page_bp-components .wp-menu-image,body.branch-3-6 ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image,body.branch-3-7 ul#adminmenu li.toplevel_page_bp-components .wp-menu-image,body.branch-3-7 ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image{background-image:url('../images/menu.png') !important;background-position:-178px -34px}body.branch-3-6 ul#adminmenu li.toplevel_page_bp-components:hover .wp-menu-image,body.branch-3-6 ul#adminmenu li.toplevel_page_bp-general-settings:hover .wp-menu-image,body.branch-3-6 ul#adminmenu li.toplevel_page_bp-components.wp-has-current-submenu .wp-menu-image,body.branch-3-6 ul#adminmenu li.toplevel_page_bp-general-settings.wp-has-current-submenu .wp-menu-image,body.branch-3-7 ul#adminmenu li.toplevel_page_bp-components:hover .wp-menu-image,body.branch-3-7 ul#adminmenu li.toplevel_page_bp-general-settings:hover .wp-menu-image,body.branch-3-7 ul#adminmenu li.toplevel_page_bp-components.wp-has-current-submenu .wp-menu-image,body.branch-3-7 ul#adminmenu li.toplevel_page_bp-general-settings.wp-has-current-submenu .wp-menu-image{background-position:-178px -2px}body.branch-3-6 ul#adminmenu li.toplevel_page_bp-activity .wp-menu-image,body.branch-3-6 ul#adminmenu li.toplevel_page_bp-activity_network .wp-menu-image,body.branch-3-7 ul#adminmenu li.toplevel_page_bp-activity .wp-menu-image,body.branch-3-7 ul#adminmenu li.toplevel_page_bp-activity_network .wp-menu-image{background-image:url('../images/menu.png');background-position:0 -34px}body.branch-3-6 ul#adminmenu li.toplevel_page_bp-activity:hover .wp-menu-image,body.branch-3-6 ul#adminmenu li.toplevel_page_bp-activity.current .wp-menu-image,body.branch-3-6 ul#adminmenu li.toplevel_page_bp-activity.wp-has-current-submenu .wp-menu-image,body.branch-3-6 ul#adminmenu li.toplevel_page_bp-activity_network:hover .wp-menu-image,body.branch-3-6 ul#adminmenu li.toplevel_page_bp-activity_network.current .wp-menu-image,body.branch-3-6 ul#adminmenu li.toplevel_page_bp-activity_network.wp-has-current-submenu .wp-menu-image,body.branch-3-7 ul#adminmenu li.toplevel_page_bp-activity:hover .wp-menu-image,body.branch-3-7 ul#adminmenu li.toplevel_page_bp-activity.current .wp-menu-image,body.branch-3-7 ul#adminmenu li.toplevel_page_bp-activity.wp-has-current-submenu .wp-menu-image,body.branch-3-7 ul#adminmenu li.toplevel_page_bp-activity_network:hover .wp-menu-image,body.branch-3-7 ul#adminmenu li.toplevel_page_bp-activity_network.current .wp-menu-image,body.branch-3-7 ul#adminmenu li.toplevel_page_bp-activity_network.wp-has-current-submenu .wp-menu-image{background-position:0 -2px}body.branch-3-6 ul#adminmenu li.toplevel_page_bp-groups .wp-menu-image,body.branch-3-6 ul#adminmenu li.toplevel_page_bp-groups_network .wp-menu-image,body.branch-3-7 ul#adminmenu li.toplevel_page_bp-groups .wp-menu-image,body.branch-3-7 ul#adminmenu li.toplevel_page_bp-groups_network .wp-menu-image{background-image:url('../images/menu.png');background-position:-61px -34px}body.branch-3-6 ul#adminmenu li.toplevel_page_bp-groups:hover .wp-menu-image,body.branch-3-6 ul#adminmenu li.toplevel_page_bp-groups.current .wp-menu-image,body.branch-3-6 ul#adminmenu li.toplevel_page_bp-groups.wp-has-current-submenu .wp-menu-image,body.branch-3-6 ul#adminmenu li.toplevel_page_bp-groups_network:hover .wp-menu-image,body.branch-3-6 ul#adminmenu li.toplevel_page_bp-groups_network.current .wp-menu-image,body.branch-3-6 ul#adminmenu li.toplevel_page_bp-groups_network.wp-has-current-submenu .wp-menu-image,body.branch-3-7 ul#adminmenu li.toplevel_page_bp-groups:hover .wp-menu-image,body.branch-3-7 ul#adminmenu li.toplevel_page_bp-groups.current .wp-menu-image,body.branch-3-7 ul#adminmenu li.toplevel_page_bp-groups.wp-has-current-submenu .wp-menu-image,body.branch-3-7 ul#adminmenu li.toplevel_page_bp-groups_network:hover .wp-menu-image,body.branch-3-7 ul#adminmenu li.toplevel_page_bp-groups_network.current .wp-menu-image,body.branch-3-7 ul#adminmenu li.toplevel_page_bp-groups_network.wp-has-current-submenu .wp-menu-image{background-position:-61px -2px}#adminmenu .toplevel_page_network-tools div.wp-menu-image:before{content:""}th.column-gid{width:60px}td.column-gid{vertical-align:middle}table.bp-group-members th,table.bp-group-members td{padding:5px 0}table.bp-group-members .uid-column{padding-left:20px;padding-right:20px}table.bp-group-members .uname-column{width:70%}table.bp-group-members .urole-column{padding-left:20px;padding-right:20px}#adminmenu #toplevel_page_bp-activity .wp-menu-image:before,#adminmenu #toplevel_page_bp-activity_user .wp-menu-image:before,#adminmenu #toplevel_page_bp-activity_network .wp-menu-image:before{content:"\f452"}#adminmenu #toplevel_page_bp-groups .wp-menu-image:before,#adminmenu #toplevel_page_bp-groups_user .wp-menu-image:before,#adminmenu #toplevel_page_bp-groups_network .wp-menu-image:before{content:"\f456"}#adminmenu #toplevel_page_bp-notifications .wp-menu-image:before,#adminmenu #toplevel_page_bp-notifications_user .wp-menu-image:before,#adminmenu #toplevel_page_bp-notifications_network .wp-menu-image:before{content:"\f439"}#adminmenu #toplevel_page_bp-messages .wp-menu-image:before,#adminmenu #toplevel_page_bp-messages_user .wp-menu-image:before,#adminmenu #toplevel_page_bp-messages_network .wp-menu-image:before{content:"\f457"}#adminmenu #toplevel_page_bp-friends .wp-menu-image:before,#adminmenu #toplevel_page_bp-friends_user .wp-menu-image:before,#adminmenu #toplevel_page_bp-friends_network .wp-menu-image:before{content:"\f454"}#adminmenu #toplevel_page_bp-settings .wp-menu-image:before,#adminmenu #toplevel_page_bp-settings_user .wp-menu-image:before,#adminmenu #toplevel_page_bp-settings_network .wp-menu-image:before{content:"\f108"}#adminmenu li.toplevel_page_bp-components .wp-menu-image,#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image{content:"\f448"}body.branch-3-6 #adminmenu #toplevel_page_bp-activity .wp-menu-image:before,body.branch-3-6 #adminmenu #toplevel_page_bp-activity_network .wp-menu-image:before,body.branch-3-6 #adminmenu #toplevel_page_bp-groups .wp-menu-image:before,body.branch-3-6 #adminmenu #toplevel_page_bp-groups_network .wp-menu-image:before,body.branch-3-6 #adminmenu li.toplevel_page_bp-components .wp-menu-image,body.branch-3-6 #adminmenu li.toplevel_page_bp-general-settings .wp-menu-image,body.branch-3-7 #adminmenu #toplevel_page_bp-activity .wp-menu-image:before,body.branch-3-7 #adminmenu #toplevel_page_bp-activity_network .wp-menu-image:before,body.branch-3-7 #adminmenu #toplevel_page_bp-groups .wp-menu-image:before,body.branch-3-7 #adminmenu #toplevel_page_bp-groups_network .wp-menu-image:before,body.branch-3-7 #adminmenu li.toplevel_page_bp-components .wp-menu-image,body.branch-3-7 #adminmenu li.toplevel_page_bp-general-settings .wp-menu-image{content:""}.settings_page_bp-components td.plugin-title span{float:left;width:18px;height:18px;margin-right:5px}.settings_page_bp-components td.plugin-title span:before{font-family:'dashicons';font-size:18px}.settings_page_bp-components tr.activity td.plugin-title span:before{content:"\f452"}.settings_page_bp-components tr.notifications td.plugin-title span:before{content:"\f339"}.settings_page_bp-components tr.xprofile td.plugin-title span:before{content:"\f336"}.settings_page_bp-components tr.settings td.plugin-title span:before{content:"\f108"}.settings_page_bp-components tr.groups td.plugin-title span:before{content:"\f456"}.settings_page_bp-components tr.messages td.plugin-title span:before{content:"\f457"}.settings_page_bp-components tr.forums td.plugin-title span:before{content:"\f452"}.settings_page_bp-components tr.blogs td.plugin-title span:before{content:"\f120"}.settings_page_bp-components tr.friends td.plugin-title span:before{content:"\f454"}body.branch-3-6.settings_page_bp-components tr.activity td.plugin-title span:before,body.branch-3-6.settings_page_bp-components tr.notifications td.plugin-title span:before,body.branch-3-6.settings_page_bp-components tr.xprofile td.plugin-title span:before,body.branch-3-6.settings_page_bp-components tr.settings td.plugin-title span:before,body.branch-3-6.settings_page_bp-components tr.groups td.plugin-title span:before,body.branch-3-6.settings_page_bp-components tr.messages td.plugin-title span:before,body.branch-3-6.settings_page_bp-components tr.forums td.plugin-title span:before,body.branch-3-6.settings_page_bp-components tr.blogs td.plugin-title span:before,body.branch-3-6.settings_page_bp-components tr.friends td.plugin-title span:before,body.branch-3-7.settings_page_bp-components tr.activity td.plugin-title span:before,body.branch-3-7.settings_page_bp-components tr.notifications td.plugin-title span:before,body.branch-3-7.settings_page_bp-components tr.xprofile td.plugin-title span:before,body.branch-3-7.settings_page_bp-components tr.settings td.plugin-title span:before,body.branch-3-7.settings_page_bp-components tr.groups td.plugin-title span:before,body.branch-3-7.settings_page_bp-components tr.messages td.plugin-title span:before,body.branch-3-7.settings_page_bp-components tr.forums td.plugin-title span:before,body.branch-3-7.settings_page_bp-components tr.blogs td.plugin-title span:before,body.branch-3-7.settings_page_bp-components tr.friends td.plugin-title span:before{content:""}body.branch-3-6.settings_page_bp-components td.plugin-title span,body.branch-3-7.settings_page_bp-components td.plugin-title span{background-image:url('../images/menu.png');background-position:-4px -40px;background-repeat:no-repeat}body.branch-3-6.settings_page_bp-components tr.active td.plugin-title span,body.branch-3-7.settings_page_bp-components tr.active td.plugin-title span{background-position-y:-7px}body.branch-3-6.settings_page_bp-components tr.activity td.plugin-title span,body.branch-3-7.settings_page_bp-components tr.activity td.plugin-title span{background-position:-4px -40px}body.branch-3-6.settings_page_bp-components tr.activity.active td.plugin-title span,body.branch-3-7.settings_page_bp-components tr.activity.active td.plugin-title span{background-position:-4px -7px}body.branch-3-6.settings_page_bp-components tr.xprofile td.plugin-title span,body.branch-3-7.settings_page_bp-components tr.xprofile td.plugin-title span{background-image:url('../images/menu-wp.png');background-position:-305px -40px}body.branch-3-6.settings_page_bp-components tr.xprofile.active td.plugin-title span,body.branch-3-7.settings_page_bp-components tr.xprofile.active td.plugin-title span{background-position:-305px -7px}body.branch-3-6.settings_page_bp-components tr.settings td.plugin-title span,body.branch-3-7.settings_page_bp-components tr.settings td.plugin-title span{background-image:url('../images/menu-wp.png');background-position:-334px -40px}body.branch-3-6.settings_page_bp-components tr.settings.active td.plugin-title span,body.branch-3-7.settings_page_bp-components tr.settings.active td.plugin-title span{background-position:-334px -7px}body.branch-3-6.settings_page_bp-components tr.groups td.plugin-title span,body.branch-3-7.settings_page_bp-components tr.groups td.plugin-title span{background-position:-66px -40px}body.branch-3-6.settings_page_bp-components tr.groups.active td.plugin-title span,body.branch-3-7.settings_page_bp-components tr.groups.active td.plugin-title span{background-position:-66px -7px}body.branch-3-6.settings_page_bp-components tr.messages td.plugin-title span,body.branch-3-7.settings_page_bp-components tr.messages td.plugin-title span{background-position:-154px -40px}body.branch-3-6.settings_page_bp-components tr.messages.active td.plugin-title span,body.branch-3-7.settings_page_bp-components tr.messages.active td.plugin-title span{background-position:-154px -7px}body.branch-3-6.settings_page_bp-components tr.forums td.plugin-title span,body.branch-3-7.settings_page_bp-components tr.forums td.plugin-title span{background-image:url('../images/menu-wp.png');background-position:-36px -40px}body.branch-3-6.settings_page_bp-components tr.forums.active td.plugin-title span,body.branch-3-7.settings_page_bp-components tr.forums.active td.plugin-title span{background-position:-36px -7px}body.branch-3-6.settings_page_bp-components tr.blogs td.plugin-title span,body.branch-3-7.settings_page_bp-components tr.b