BuddyPress - Version 1.5.7

Version Description

  • Security upgrade
Download this release

Release Info

Developer DJPaul
Plugin Icon 128x128 BuddyPress
Version 1.5.7
Comparing to
See all releases

Code changes from version 1.6-RC1 to 1.5.7

Files changed (116) hide show
  1. bp-activity/admin/css/admin.css +0 -1
  2. bp-activity/admin/css/admin.dev.css +0 -77
  3. bp-activity/admin/js/admin.dev.js +0 -167
  4. bp-activity/admin/js/admin.js +0 -1
  5. bp-activity/bp-activity-actions.php +38 -109
  6. bp-activity/bp-activity-admin.php +0 -1393
  7. bp-activity/bp-activity-akismet.php +0 -587
  8. bp-activity/bp-activity-cache.php +0 -39
  9. bp-activity/bp-activity-classes.php +45 -157
  10. bp-activity/bp-activity-filters.php +17 -89
  11. bp-activity/bp-activity-functions.php +155 -388
  12. bp-activity/bp-activity-loader.php +28 -51
  13. bp-activity/bp-activity-notifications.php +6 -15
  14. bp-activity/bp-activity-screens.php +30 -28
  15. bp-activity/bp-activity-template.php +288 -335
  16. bp-activity/feeds/bp-activity-favorites-feed.php +4 -5
  17. bp-activity/feeds/bp-activity-friends-feed.php +0 -1
  18. bp-activity/feeds/bp-activity-group-feed.php +1 -2
  19. bp-activity/feeds/bp-activity-mentions-feed.php +4 -6
  20. bp-activity/feeds/bp-activity-mygroups-feed.php +3 -5
  21. bp-activity/feeds/bp-activity-personal-feed.php +3 -4
  22. bp-activity/feeds/bp-activity-sitewide-feed.php +1 -2
  23. bp-blogs/bp-blogs-actions.php +4 -26
  24. bp-blogs/bp-blogs-activity.php +29 -64
  25. bp-blogs/bp-blogs-buddybar.php +8 -26
  26. bp-blogs/bp-blogs-cache.php +4 -25
  27. bp-blogs/bp-blogs-classes.php +26 -34
  28. bp-blogs/bp-blogs-filters.php +0 -26
  29. bp-blogs/bp-blogs-functions.php +55 -156
  30. bp-blogs/bp-blogs-loader.php +17 -36
  31. bp-blogs/bp-blogs-screens.php +1 -9
  32. bp-blogs/bp-blogs-template.php +48 -48
  33. bp-blogs/bp-blogs-widgets.php +12 -11
  34. bp-core/admin/bp-core-admin.php +637 -0
  35. bp-core/admin/bp-core-components.php +0 -300
  36. bp-core/admin/bp-core-functions.php +0 -399
  37. bp-core/admin/bp-core-schema.php +32 -116
  38. bp-core/admin/bp-core-settings.php +0 -368
  39. bp-core/admin/bp-core-slugs.php +0 -224
  40. bp-core/admin/bp-core-update.php +590 -287
  41. bp-core/admin/css/common.css +0 -1
  42. bp-core/admin/css/common.dev.css +0 -143
  43. bp-core/admin/css/wizard.css +0 -1
  44. bp-core/admin/images/icons32.png +0 -0
  45. bp-core/admin/images/menu-wp.png +0 -0
  46. bp-core/admin/images/menu.png +0 -0
  47. bp-core/bp-core-actions.php +0 -267
  48. bp-core/bp-core-admin.php +0 -511
  49. bp-core/bp-core-adminbar.php +225 -35
  50. bp-core/bp-core-avatars.php +121 -230
  51. bp-core/bp-core-buddybar.php +104 -169
  52. bp-core/bp-core-cache.php +3 -88
  53. bp-core/bp-core-caps.php +0 -426
  54. bp-core/bp-core-catchuri.php +90 -326
  55. bp-core/bp-core-classes.php +138 -172
  56. bp-core/bp-core-component.php +26 -57
  57. bp-core/bp-core-cssjs.php +36 -3
  58. bp-core/bp-core-filters.php +51 -72
  59. bp-core/bp-core-functions.php +555 -253
  60. bp-core/bp-core-hooks.php +114 -0
  61. bp-core/bp-core-loader.php +68 -81
  62. bp-core/bp-core-moderation.php +0 -268
  63. bp-core/bp-core-options.php +0 -524
  64. bp-core/bp-core-template.php +72 -106
  65. bp-core/bp-core-update.php +0 -197
  66. bp-core/bp-core-widgets.php +29 -23
  67. bp-core/bp-core-wpabstraction.php +6 -5
  68. bp-core/css/admin-bar-rtl.css +1 -1
  69. bp-core/css/admin-bar.css +1 -1
  70. bp-core/css/admin-bar.dev.css +29 -25
  71. bp-core/css/admin.css +1 -0
  72. bp-core/{admin/css/wizard.dev.css → css/admin.dev.css} +41 -56
  73. bp-core/css/buddybar-rtl.css +1 -1
  74. bp-core/css/buddybar.css +1 -1
  75. bp-core/css/buddybar.dev.css +4 -2
  76. bp-core/deprecated/1.5.php +5 -134
  77. bp-core/deprecated/1.6.php +0 -264
  78. bp-core/images/admin-bar-sprite-rtl.png +0 -0
  79. bp-core/images/admin-bar-sprite.png +0 -0
  80. bp-core/images/admin_menu_icon.png +0 -0
  81. bp-core/{admin/images → images}/completed.gif +0 -0
  82. bp-core/{admin/images → images}/find.png +0 -0
  83. bp-core/images/icons32.png +0 -0
  84. bp-core/{admin/images → images}/installed.gif +0 -0
  85. bp-core/images/logo-column-header.png +0 -0
  86. bp-core/images/logo.png +0 -0
  87. bp-core/{admin/js/wizard.dev.js → js/update.dev.js} +0 -0
  88. bp-core/{admin/js/wizard.js → js/update.js} +0 -0
  89. bp-forums/bp-forums-admin.php +25 -80
  90. bp-forums/bp-forums-bbpress-sa.php +9 -5
  91. bp-forums/bp-forums-filters.php +3 -3
  92. bp-forums/bp-forums-functions.php +29 -102
  93. bp-forums/bp-forums-loader.php +23 -25
  94. bp-forums/bp-forums-screens.php +2 -2
  95. bp-forums/bp-forums-template.php +59 -63
  96. bp-forums/deprecated/1.6.php +0 -203
  97. bp-friends/bp-friends-actions.php +1 -7
  98. bp-friends/bp-friends-activity.php +16 -26
  99. bp-friends/bp-friends-cache.php +4 -9
  100. bp-friends/bp-friends-classes.php +50 -53
  101. bp-friends/bp-friends-functions.php +23 -40
  102. bp-friends/bp-friends-loader.php +18 -25
  103. bp-friends/bp-friends-notifications.php +16 -20
  104. bp-friends/bp-friends-screens.php +9 -24
  105. bp-friends/bp-friends-template.php +95 -80
  106. bp-groups/bp-groups-actions.php +34 -41
  107. bp-groups/bp-groups-activity.php +39 -48
  108. bp-groups/bp-groups-adminbar.php +57 -27
  109. bp-groups/bp-groups-buddybar.php +4 -19
  110. bp-groups/bp-groups-cache.php +3 -58
  111. bp-groups/bp-groups-classes.php +154 -259
  112. bp-groups/bp-groups-filters.php +14 -27
  113. bp-groups/bp-groups-forums.php +42 -159
  114. bp-groups/bp-groups-functions.php +84 -125
  115. bp-groups/bp-groups-loader.php +55 -174
  116. bp-groups/bp-groups-notifications.php +13 -19
bp-activity/admin/css/admin.css DELETED
@@ -1 +0,0 @@
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}
 
bp-activity/admin/css/admin.dev.css DELETED
@@ -1,77 +0,0 @@
1
- .akismet-status {
2
- float: right;
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: right;
42
- padding: 4px 10px 0;
43
- vertical-align: top;
44
- }
45
- #bp-activities-form .column-response img {
46
- float: left;
47
- margin-right: 10px;
48
- margin-top: 1px;
49
- }
50
- .activity-errors {
51
- list-style-type: disc;
52
- margin-left: 2em;
53
- }
54
-
55
- #bp_activity_action div.inside,
56
- #bp_activity_content div.inside {
57
- line-height: 0;
58
- }
59
- #bp_activity_action h3,
60
- #bp_activity_content h3 {
61
- cursor: auto;
62
- }
63
- #bp_activity_action td.mceIframeContainer,
64
- #bp_activity_content td.mceIframeContainer {
65
- background-color: white;
66
- }
67
- #post-body #bp-activities-action_resize,
68
- #post-body #bp-activities-content_resize {
69
- position: inherit;
70
- margin-top: -2px;
71
- }
72
- #bp_activity_link input {
73
- width: 99%;
74
- }
75
- #bp-activities-primaryid {
76
- margin-bottom: 1em;
77
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-activity/admin/js/admin.dev.js DELETED
@@ -1,167 +0,0 @@
1
- (function( $ ) {
2
-
3
- /**
4
- * Activity reply object for the activity index screen
5
- *
6
- * @since 1.6
7
- */
8
- var activityReply = {
9
-
10
- /**
11
- * Attach event handler functions to the relevant elements.
12
- *
13
- * @since 1.6
14
- */
15
- init : function() {
16
- $(document).on( 'click', '.row-actions a.reply', activityReply.open );
17
- $(document).on( 'click', '#bp-activities-container a.cancel', activityReply.close );
18
- $(document).on( 'click', '#bp-activities-container a.save', activityReply.send );
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
- });
26
- },
27
-
28
- /**
29
- * Reveals the entire row when "reply" is pressed.
30
- *
31
- * @since 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 );
37
-
38
- // Fade the whole row in, and set focus on the text area.
39
- box.fadeIn( '300' );
40
- $( '#bp-activities' ).focus();
41
-
42
- return false;
43
- },
44
-
45
- /**
46
- * Hide and reset the entire row when "cancel", or escape, are pressed.
47
- *
48
- * @since 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();
56
-
57
- // Remove any error message and disable the spinner
58
- $( '#bp-replysubmit .error' ).html( '' ).hide();
59
- $( '#bp-replysubmit .waiting' ).hide();
60
- });
61
-
62
- return false;
63
- },
64
-
65
- /**
66
- * Submits "form" via AJAX back to WordPress.
67
- *
68
- * @since 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();
74
-
75
- // Grab the nonce
76
- var reply = {};
77
- reply['_ajax_nonce-bp-activity-admin-reply'] = $( '#bp-activities-container input[name="_ajax_nonce-bp-activity-admin-reply"]' ).val();
78
-
79
- // Get the rest of the data
80
- reply.action = 'bp-activity-admin-reply';
81
- reply.content = $( '#bp-activities' ).val();
82
- reply.parent_id = $( '#bp-activities-container' ).prev().data( 'parent_id' );
83
- reply.root_id = $( '#bp-activities-container' ).prev().data( 'root_id' );
84
-
85
- // Make the AJAX call
86
- $.ajax({
87
- data : reply,
88
- type : 'POST',
89
- url : ajaxurl,
90
-
91
- // Callbacks
92
- error : function( r ) { activityReply.error( r ); },
93
- success : function( r ) { activityReply.show( r ); }
94
- });
95
-
96
- return false;
97
- },
98
-
99
- /**
100
- * send() error message handler
101
- *
102
- * @since 1.6
103
- */
104
- error : function( r ) {
105
- var er = r.statusText;
106
- $('#bp-replysubmit .waiting').hide();
107
-
108
- if ( r.responseText ) {
109
- er = r.responseText.replace( /<.[^<>]*?>/g, '' );
110
- }
111
-
112
- if ( er ) {
113
- $('#bp-replysubmit .error').html( er ).show();
114
- }
115
- },
116
-
117
- /**
118
- * send() success handler
119
- *
120
- * @since 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
- }
130
-
131
- response = wpAjax.parseAjaxResponse( xml );
132
- if ( response.errors ) {
133
- activityReply.error( { 'responseText': wpAjax.broken } );
134
- return false;
135
- }
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();
143
-
144
- // Remove any error message and disable the spinner
145
- $( '#bp-replysubmit .error' ).html( '' ).hide();
146
- $( '#bp-replysubmit .waiting' ).hide();
147
-
148
- // Insert new activity item
149
- $( '#bp-activities-container' ).before( response.data );
150
-
151
- // Get background colour and animate the flash
152
- id = $( '#activity-' + response.id );
153
- bg = id.closest( '.widefat' ).css( 'backgroundColor' );
154
- id.animate( { 'backgroundColor': '#CEB' }, 300 ).animate( { 'backgroundColor': bg }, 300 );
155
- });
156
- }
157
- };
158
-
159
- $(document).ready( function () {
160
- // Create the Activity reply object after domready event
161
- activityReply.init();
162
-
163
- // On the edit screen, unload the close/open toggle js for the action & content metaboxes
164
- $( '#bp_activity_action h3, #bp_activity_content h3' ).unbind( 'click' );
165
- });
166
-
167
- })(jQuery);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-activity/admin/js/admin.js DELETED
@@ -1 +0,0 @@
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")})})(jQuery);
 
bp-activity/bp-activity-actions.php CHANGED
@@ -15,7 +15,7 @@ if ( !defined( 'ABSPATH' ) ) exit;
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
  */
@@ -27,7 +27,7 @@ add_action( 'bp_init', 'bp_register_activity_actions', 8 );
27
  /**
28
  * Allow core components and dependent plugins to register activity actions
29
  *
30
- * @since BuddyPress (1.2)
31
  *
32
  * @global object $bp BuddyPress global settings
33
  * @uses bp_is_activity_component()
@@ -88,14 +88,7 @@ function bp_activity_action_permalink_router() {
88
 
89
  // Set redirect to users' activity stream
90
  } else {
91
- $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/';
92
- }
93
-
94
- // If set, add the original query string back onto the redirect URL
95
- if ( !empty( $_SERVER['QUERY_STRING'] ) ) {
96
- $query_frags = array();
97
- wp_parse_str( $_SERVER['QUERY_STRING'], $query_frags );
98
- $redirect = add_query_arg( urlencode_deep( $query_frags ), $redirect );
99
  }
100
 
101
  // Allow redirect to be filtered
@@ -110,10 +103,11 @@ add_action( 'bp_actions', 'bp_activity_action_permalink_router' );
110
  /**
111
  * Delete specific activity item and redirect to previous page.
112
  *
113
- * @since BuddyPress (1.1)
114
  *
115
  * @param int $activity_id Activity id to be deleted. Defaults to 0.
116
  *
 
117
  * @uses bp_is_activity_component()
118
  * @uses bp_is_current_action()
119
  * @uses bp_action_variable()
@@ -128,6 +122,7 @@ add_action( 'bp_actions', 'bp_activity_action_permalink_router' );
128
  * @return bool False on failure
129
  */
130
  function bp_activity_action_delete_activity( $activity_id = 0 ) {
 
131
 
132
  // Not viewing activity or action is not delete
133
  if ( !bp_is_activity_component() || !bp_is_current_action( 'delete' ) )
@@ -169,65 +164,12 @@ function bp_activity_action_delete_activity( $activity_id = 0 ) {
169
  }
170
  add_action( 'bp_actions', 'bp_activity_action_delete_activity' );
171
 
172
- /**
173
- * Mark specific activity item as spam and redirect to previous page
174
- *
175
- * @global object $bp BuddyPress global settings
176
- * @param int $activity_id Activity id to be deleted. Defaults to 0.
177
- * @return bool False on failure
178
- * @since 1.6
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
-
194
- // Is the current user allowed to spam items?
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
222
- bp_core_redirect( wp_get_referer() );
223
- }
224
- add_action( 'bp_actions', 'bp_activity_action_spam_activity' );
225
-
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()
233
  * @uses bp_is_current_action()
@@ -245,6 +187,7 @@ add_action( 'bp_actions', 'bp_activity_action_spam_activity' );
245
  * @return bool False on failure
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' ) )
@@ -270,7 +213,7 @@ function bp_activity_action_post_update() {
270
 
271
  // Post to groups object
272
  } else if ( 'groups' == $object && bp_is_active( 'groups' ) ) {
273
- if ( (int) $item_id ) {
274
  $activity_id = groups_post_update( array( 'content' => $content, 'group_id' => $item_id ) );
275
  }
276
 
@@ -293,8 +236,9 @@ add_action( 'bp_actions', 'bp_activity_action_post_update' );
293
  /**
294
  * Post new activity comment.
295
  *
296
- * @since BuddyPress (1.2)
297
  *
 
298
  * @uses is_user_logged_in()
299
  * @uses bp_is_activity_component()
300
  * @uses bp_is_current_action()
@@ -309,8 +253,9 @@ add_action( 'bp_actions', 'bp_activity_action_post_update' );
309
  * @return bool False on failure
310
  */
311
  function bp_activity_action_post_comment() {
 
312
 
313
- if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'reply' ) )
314
  return false;
315
 
316
  // Check the nonce
@@ -342,8 +287,9 @@ add_action( 'bp_actions', 'bp_activity_action_post_comment' );
342
  /**
343
  * Mark activity as favorite.
344
  *
345
- * @since BuddyPress (1.2)
346
  *
 
347
  * @uses is_user_logged_in()
348
  * @uses bp_is_activity_component()
349
  * @uses bp_is_current_action()
@@ -357,8 +303,9 @@ add_action( 'bp_actions', 'bp_activity_action_post_comment' );
357
  * @return bool False on failure
358
  */
359
  function bp_activity_action_mark_favorite() {
 
360
 
361
- if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'favorite' ) )
362
  return false;
363
 
364
  // Check the nonce
@@ -376,8 +323,9 @@ add_action( 'bp_actions', 'bp_activity_action_mark_favorite' );
376
  /**
377
  * Remove activity from favorites.
378
  *
379
- * @since BuddyPress (1.2)
380
  *
 
381
  * @uses is_user_logged_in()
382
  * @uses bp_is_activity_component()
383
  * @uses bp_is_current_action()
@@ -391,8 +339,9 @@ add_action( 'bp_actions', 'bp_activity_action_mark_favorite' );
391
  * @return bool False on failure
392
  */
393
  function bp_activity_action_remove_favorite() {
 
394
 
395
- if ( ! is_user_logged_in() || ! bp_is_activity_component() || ! bp_is_current_action( 'unfavorite' ) )
396
  return false;
397
 
398
  // Check the nonce
@@ -410,7 +359,7 @@ add_action( 'bp_actions', 'bp_activity_action_remove_favorite' );
410
  /**
411
  * Load the sitewide feed.
412
  *
413
- * @since BuddyPress (1.0)
414
  *
415
  * @global object $bp BuddyPress global settings
416
  * @global object $wp_query
@@ -438,8 +387,9 @@ add_action( 'bp_actions', 'bp_activity_action_sitewide_feed' );
438
  /**
439
  * Load a user's personal feed.
440
  *
441
- * @since BuddyPress (1.0)
442
  *
 
443
  * @global object $wp_query
444
  * @uses bp_is_user_activity()
445
  * @uses bp_is_current_action()
@@ -448,7 +398,7 @@ add_action( 'bp_actions', 'bp_activity_action_sitewide_feed' );
448
  * @return bool False on failure
449
  */
450
  function bp_activity_action_personal_feed() {
451
- global $wp_query;
452
 
453
  if ( !bp_is_user_activity() || !bp_is_current_action( 'feed' ) )
454
  return false;
@@ -464,8 +414,9 @@ add_action( 'bp_actions', 'bp_activity_action_personal_feed' );
464
  /**
465
  * Load a user's friends feed.
466
  *
467
- * @since BuddyPress (1.0)
468
  *
 
469
  * @global object $wp_query
470
  * @uses bp_is_active()
471
  * @uses bp_is_user_activity()
@@ -477,7 +428,7 @@ add_action( 'bp_actions', 'bp_activity_action_personal_feed' );
477
  * @return bool False on failure
478
  */
479
  function bp_activity_action_friends_feed() {
480
- global $wp_query;
481
 
482
  if ( !bp_is_active( 'friends' ) || !bp_is_user_activity() || !bp_is_current_action( bp_get_friends_slug() ) || !bp_is_action_variable( 'feed', 0 ) )
483
  return false;
@@ -493,8 +444,9 @@ add_action( 'bp_actions', 'bp_activity_action_friends_feed' );
493
  /**
494
  * Load a user's my groups feed.
495
  *
496
- * @since BuddyPress (1.2)
497
  *
 
498
  * @global object $wp_query
499
  * @uses bp_is_active()
500
  * @uses bp_is_user_activity()
@@ -506,7 +458,7 @@ add_action( 'bp_actions', 'bp_activity_action_friends_feed' );
506
  * @return bool False on failure
507
  */
508
  function bp_activity_action_my_groups_feed() {
509
- global $wp_query;
510
 
511
  if ( !bp_is_active( 'groups' ) || !bp_is_user_activity() || !bp_is_current_action( bp_get_groups_slug() ) || !bp_is_action_variable( 'feed', 0 ) )
512
  return false;
@@ -522,8 +474,9 @@ add_action( 'bp_actions', 'bp_activity_action_my_groups_feed' );
522
  /**
523
  * Load a user's @mentions feed.
524
  *
525
- * @since BuddyPress (1.2)
526
  *
 
527
  * @global object $wp_query
528
  * @uses bp_is_user_activity()
529
  * @uses bp_is_current_action()
@@ -533,7 +486,7 @@ add_action( 'bp_actions', 'bp_activity_action_my_groups_feed' );
533
  * @return bool False on failure
534
  */
535
  function bp_activity_action_mentions_feed() {
536
- global $wp_query;
537
 
538
  if ( !bp_is_user_activity() || !bp_is_current_action( 'mentions' ) || !bp_is_action_variable( 'feed', 0 ) )
539
  return false;
@@ -549,8 +502,9 @@ add_action( 'bp_actions', 'bp_activity_action_mentions_feed' );
549
  /**
550
  * Load a user's favorites feed.
551
  *
552
- * @since BuddyPress (1.2)
553
  *
 
554
  * @global object $wp_query
555
  * @uses bp_is_user_activity()
556
  * @uses bp_is_current_action()
@@ -560,7 +514,7 @@ add_action( 'bp_actions', 'bp_activity_action_mentions_feed' );
560
  * @return bool False on failure
561
  */
562
  function bp_activity_action_favorites_feed() {
563
- global $wp_query;
564
 
565
  if ( !bp_is_user_activity() || !bp_is_current_action( 'favorites' ) || !bp_is_action_variable( 'feed', 0 ) )
566
  return false;
@@ -573,29 +527,4 @@ function bp_activity_action_favorites_feed() {
573
  }
574
  add_action( 'bp_actions', 'bp_activity_action_favorites_feed' );
575
 
576
- /**
577
- * Loads Akismet
578
- *
579
- * @global object $bp BuddyPress global settings
580
- * @since 1.6
581
- */
582
- function bp_activity_setup_akismet() {
583
- global $bp;
584
-
585
- // Bail if Akismet is not active
586
- if ( ! defined( 'AKISMET_VERSION' ) )
587
- return;
588
-
589
- // Bail if no Akismet key is set
590
- if ( ! bp_get_option( 'wordpress_api_key' ) && ! defined( 'WPCOM_API_KEY' ) )
591
- return;
592
-
593
- // Bail if BuddyPress Activity Akismet support has been disabled by another plugin
594
- if ( ! apply_filters( 'bp_activity_use_akismet', true ) )
595
- return;
596
-
597
- // Instantiate Akismet for BuddyPress
598
- $bp->activity->akismet = new BP_Akismet();
599
- }
600
-
601
  ?>
15
  /**
16
  * Allow core components and dependent plugins to register activity actions
17
  *
18
+ * @since 1.2.0
19
  *
20
  * @uses do_action() To call 'bp_register_activity_actions' hook.
21
  */
27
  /**
28
  * Allow core components and dependent plugins to register activity actions
29
  *
30
+ * @since 1.2.0
31
  *
32
  * @global object $bp BuddyPress global settings
33
  * @uses bp_is_activity_component()
88
 
89
  // Set redirect to users' activity stream
90
  } else {
91
+ $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id;
 
 
 
 
 
 
 
92
  }
93
 
94
  // Allow redirect to be filtered
103
  /**
104
  * Delete specific activity item and redirect to previous page.
105
  *
106
+ * @since 1.1.0
107
  *
108
  * @param int $activity_id Activity id to be deleted. Defaults to 0.
109
  *
110
+ * @global object $bp BuddyPress global settings
111
  * @uses bp_is_activity_component()
112
  * @uses bp_is_current_action()
113
  * @uses bp_action_variable()
122
  * @return bool False on failure
123
  */
124
  function bp_activity_action_delete_activity( $activity_id = 0 ) {
125
+ global $bp;
126
 
127
  // Not viewing activity or action is not delete
128
  if ( !bp_is_activity_component() || !bp_is_current_action( 'delete' ) )
164
  }
165
  add_action( 'bp_actions', 'bp_activity_action_delete_activity' );
166
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  /**
168
  * Post user/group activity update.
169
  *
170
+ * @since 1.2.0
171
  *
172
+ * @global object $bp BuddyPress global settings
173
  * @uses is_user_logged_in()
174
  * @uses bp_is_activity_component()
175
  * @uses bp_is_current_action()
187
  * @return bool False on failure
188
  */
189
  function bp_activity_action_post_update() {
190
+ global $bp;
191
 
192
  // Do not proceed if user is not logged in, not viewing activity, or not posting
193
  if ( !is_user_logged_in() || !bp_is_activity_component() || !bp_is_current_action( 'post' ) )
213
 
214
  // Post to groups object
215
  } else if ( 'groups' == $object && bp_is_active( 'groups' ) ) {
216
+ if ( (int)$item_id ) {
217
  $activity_id = groups_post_update( array( 'content' => $content, 'group_id' => $item_id ) );
218
  }
219
 
236
  /**
237
  * Post new activity comment.
238
  *
239
+ * @since 1.2.0
240
  *
241
+ * @global object $bp BuddyPress global settings
242
  * @uses is_user_logged_in()
243
  * @uses bp_is_activity_component()
244
  * @uses bp_is_current_action()
253
  * @return bool False on failure
254
  */
255
  function bp_activity_action_post_comment() {
256
+ global $bp;
257
 
258
+ if ( !is_user_logged_in() || ( bp_is_activity_component() ) || !bp_is_current_action( 'reply' ) )
259
  return false;
260
 
261
  // Check the nonce
287
  /**
288
  * Mark activity as favorite.
289
  *
290
+ * @since 1.2.0
291
  *
292
+ * @global object $bp BuddyPress global settings
293
  * @uses is_user_logged_in()
294
  * @uses bp_is_activity_component()
295
  * @uses bp_is_current_action()
303
  * @return bool False on failure
304
  */
305
  function bp_activity_action_mark_favorite() {
306
+ global $bp;
307
 
308
+ if ( !is_user_logged_in() || ( bp_is_activity_component() ) || !bp_is_current_action( 'favorite' ) )
309
  return false;
310
 
311
  // Check the nonce
323
  /**
324
  * Remove activity from favorites.
325
  *
326
+ * @since 1.2.0
327
  *
328
+ * @global object $bp BuddyPress global settings
329
  * @uses is_user_logged_in()
330
  * @uses bp_is_activity_component()
331
  * @uses bp_is_current_action()
339
  * @return bool False on failure
340
  */
341
  function bp_activity_action_remove_favorite() {
342
+ global $bp;
343
 
344
+ if ( !is_user_logged_in() || ( bp_is_activity_component() ) || !bp_is_current_action( 'unfavorite' ) )
345
  return false;
346
 
347
  // Check the nonce
359
  /**
360
  * Load the sitewide feed.
361
  *
362
+ * @since 1.0.0
363
  *
364
  * @global object $bp BuddyPress global settings
365
  * @global object $wp_query
387
  /**
388
  * Load a user's personal feed.
389
  *
390
+ * @since 1.0.0
391
  *
392
+ * @global object $bp BuddyPress global settings
393
  * @global object $wp_query
394
  * @uses bp_is_user_activity()
395
  * @uses bp_is_current_action()
398
  * @return bool False on failure
399
  */
400
  function bp_activity_action_personal_feed() {
401
+ global $bp, $wp_query;
402
 
403
  if ( !bp_is_user_activity() || !bp_is_current_action( 'feed' ) )
404
  return false;
414
  /**
415
  * Load a user's friends feed.
416
  *
417
+ * @since 1.0.0
418
  *
419
+ * @global object $bp BuddyPress global settings
420
  * @global object $wp_query
421
  * @uses bp_is_active()
422
  * @uses bp_is_user_activity()
428
  * @return bool False on failure
429
  */
430
  function bp_activity_action_friends_feed() {
431
+ global $bp, $wp_query;
432
 
433
  if ( !bp_is_active( 'friends' ) || !bp_is_user_activity() || !bp_is_current_action( bp_get_friends_slug() ) || !bp_is_action_variable( 'feed', 0 ) )
434
  return false;
444
  /**
445
  * Load a user's my groups feed.
446
  *
447
+ * @since 1.2.0
448
  *
449
+ * @global object $bp BuddyPress global settings
450
  * @global object $wp_query
451
  * @uses bp_is_active()
452
  * @uses bp_is_user_activity()
458
  * @return bool False on failure
459
  */
460
  function bp_activity_action_my_groups_feed() {
461
+ global $bp, $wp_query;
462
 
463
  if ( !bp_is_active( 'groups' ) || !bp_is_user_activity() || !bp_is_current_action( bp_get_groups_slug() ) || !bp_is_action_variable( 'feed', 0 ) )
464
  return false;
474
  /**
475
  * Load a user's @mentions feed.
476
  *
477
+ * @since 1.2.0
478
  *
479
+ * @global object $bp BuddyPress global settings
480
  * @global object $wp_query
481
  * @uses bp_is_user_activity()
482
  * @uses bp_is_current_action()
486
  * @return bool False on failure
487
  */
488
  function bp_activity_action_mentions_feed() {
489
+ global $bp, $wp_query;
490
 
491
  if ( !bp_is_user_activity() || !bp_is_current_action( 'mentions' ) || !bp_is_action_variable( 'feed', 0 ) )
492
  return false;
502
  /**
503
  * Load a user's favorites feed.
504
  *
505
+ * @since 1.2.0
506
  *
507
+ * @global object $bp BuddyPress global settings
508
  * @global object $wp_query
509
  * @uses bp_is_user_activity()
510
  * @uses bp_is_current_action()
514
  * @return bool False on failure
515
  */
516
  function bp_activity_action_favorites_feed() {
517
+ global $bp, $wp_query;
518
 
519
  if ( !bp_is_user_activity() || !bp_is_current_action( 'favorites' ) || !bp_is_action_variable( 'feed', 0 ) )
520
  return false;
527
  }
528
  add_action( 'bp_actions', 'bp_activity_action_favorites_feed' );
529
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
530
  ?>
bp-activity/bp-activity-admin.php DELETED
@@ -1,1393 +0,0 @@
1
- <?php
2
- /**
3
- * BuddyPress Activity component admin screen
4
- *
5
- * Props to WordPress core for the Comments admin screen, and its contextual help text,
6
- * on which this implementation is heavily based.
7
- *
8
- * @package BuddyPress
9
- * @since 1.6
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
- * Registers the Activity component admin screen
25
- *
26
- * @since 1.6
27
- */
28
- function bp_activity_add_admin_menu() {
29
-
30
- if ( ! bp_current_user_can( 'bp_moderate' ) )
31
- return;
32
-
33
- // Add our screen
34
- $hook = add_menu_page( __( 'Activity', 'buddypress' ), __( 'Activity', 'buddypress' ), 'manage_options', 'bp-activity', 'bp_activity_admin' );
35
-
36
- // Hook into early actions to load custom CSS and our init handler.
37
- add_action( "load-$hook", 'bp_activity_admin_load' );
38
- }
39
- add_action( bp_core_admin_hook(), 'bp_activity_add_admin_menu' );
40
-
41
- /**
42
- * AJAX receiver for Activity replies via the admin screen. Adds a new activity
43
- * comment, and returns HTML for a new table row.
44
- *
45
- * @since 1.6
46
- */
47
- function bp_activity_admin_reply() {
48
- // Check nonce
49
- check_ajax_referer( 'bp-activity-admin-reply', '_ajax_nonce-bp-activity-admin-reply' );
50
-
51
- $parent_id = ! empty( $_REQUEST['parent_id'] ) ? (int) $_REQUEST['parent_id'] : 0;
52
- $root_id = ! empty( $_REQUEST['root_id'] ) ? (int) $_REQUEST['root_id'] : 0;
53
-
54
- // $parent_id is required
55
- if ( empty( $parent_id ) )
56
- die( '-1' );
57
-
58
- // If $root_id not set (e.g. for root items), use $parent_id
59
- if ( empty( $root_id ) )
60
- $root_id = $parent_id;
61
-
62
- // Check that a reply has been entered
63
- if ( empty( $_REQUEST['content'] ) )
64
- die( __( 'ERROR: Please type a reply.', 'buddypress' ) );
65
-
66
- // Check parent activity exists
67
- $parent_activity = new BP_Activity_Activity( $parent_id );
68
- if ( empty( $parent_activity->component ) )
69
- die( __( 'ERROR: The item you are trying to reply to cannot be found, or it has been deleted.', 'buddypress' ) );
70
-
71
- // @todo: Check if user is allowed to create new activity items
72
- // if ( ! current_user_can( 'bp_new_activity' ) )
73
- if ( ! is_super_admin() )
74
- die( '-1' );
75
-
76
- // Add new activity comment
77
- $new_activity_id = bp_activity_new_comment( array(
78
- 'activity_id' => $root_id, // ID of the root activity item
79
- 'content' => $_REQUEST['content'],
80
- 'parent_id' => $parent_id, // ID of a parent comment
81
- ) );
82
-
83
- // Fetch the new activity item, as we need it to create table markup to return
84
- $new_activity = new BP_Activity_Activity( $new_activity_id );
85
-
86
- // This needs to be set for the BP_Activity_List_Table constructor to work
87
- set_current_screen( 'toplevel_page_bp-activity' );
88
-
89
- // Set up an output buffer
90
- ob_start();
91
- $list_table = new BP_Activity_List_Table();
92
- $list_table->single_row( (array) $new_activity );
93
-
94
- // Get table markup
95
- $response = array(
96
- 'data' => ob_get_contents(),
97
- 'id' => $new_activity_id,
98
- 'position' => -1,
99
- 'what' => 'bp_activity',
100
- );
101
- ob_end_clean();
102
-
103
- // Send response
104
- $r = new WP_Ajax_Response();
105
- $r->add( $response );
106
- $r->send();
107
-
108
- exit();
109
- }
110
- add_action( 'wp_ajax_bp-activity-admin-reply', 'bp_activity_admin_reply' );
111
-
112
- /**
113
- * Handle save/update of screen options for the Activity component admin screen
114
- *
115
- * @param string $value Will always be false unless another plugin filters it first.
116
- * @param string $option Screen option name
117
- * @param string $new_value Screen option form value
118
- * @return string Option value. False to abandon update.
119
- * @since 1.6
120
- */
121
- function bp_activity_admin_screen_options( $value, $option, $new_value ) {
122
- if ( 'toplevel_page_bp_activity_per_page' != $option && 'toplevel_page_bp_activity_network_per_page' != $option )
123
- return $value;
124
-
125
- // Per page
126
- $new_value = (int) $new_value;
127
- if ( $new_value < 1 || $new_value > 999 )
128
- return $value;
129
-
130
- return $new_value;
131
- }
132
-
133
- /**
134
- * Hide the advanced edit meta boxes by default, so we don't clutter the scren.
135
- *
136
- * @param WP_Screen $screen Screen identifier
137
- * @return array Hidden Meta Boxes
138
- * @since 1.0
139
- */
140
- function bp_activity_admin_edit_hidden_metaboxes( $hidden, $screen ) {
141
- if ( empty( $screen->id ) || 'toplevel_page_bp-activity' != $screen->id && 'toplevel_page_bp-activity_network' != $screen->id )
142
- return $hidden;
143
-
144
- // Hide the primary link meta box by default
145
- $hidden = array_merge( (array) $hidden, array( 'bp_activity_itemids', 'bp_activity_link', 'bp_activity_type', 'bp_activity_userid', ) );
146
-
147
- return apply_filters( 'bp_hide_meta_boxes', array_unique( $hidden ), $screen );
148
- }
149
- add_filter( 'default_hidden_meta_boxes', 'bp_activity_admin_edit_hidden_metaboxes', 10, 2 );
150
-
151
- /**
152
- * Set up the admin page before any output is sent. Register contextual help and screen options for this admin page.
153
- *
154
- * @global object $bp BuddyPress global settings
155
- * @global BP_Activity_List_Table $bp_activity_list_table Activity screen list table
156
- * @since 1.6
157
- */
158
- function bp_activity_admin_load() {
159
- global $bp, $bp_activity_list_table;
160
-
161
- // Decide whether to load the dev version of the CSS and JavaScript
162
- $dev = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? 'dev.' : '';
163
-
164
- // Decide whether to load the index or edit screen
165
- $doaction = ! empty( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
166
-
167
- // Call an action for plugins to hook in early
168
- do_action( 'bp_activity_admin_load', $doaction );
169
-
170
- // Edit screen
171
- if ( 'edit' == $doaction && ! empty( $_GET['aid'] ) ) {
172
- // columns screen option
173
- add_screen_option( 'layout_columns', array( 'default' => 2, 'max' => 2, ) );
174
-
175
- get_current_screen()->add_help_tab( array(
176
- 'id' => 'bp-activity-edit-overview',
177
- 'title' => __( 'Overview', 'buddypress' ),
178
- 'content' =>
179
- '<p>' . __( 'You edit activities made on your site similar to the way you edit a comment. This is useful if you need to change which page the activity links to, or when you notice that the author has made a typographical error.', 'buddypress' ) . '</p>' .
180
- '<p>' . __( 'The two big editing areas for the activity title and content are fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to unhide more boxes (Primary Item/Secondary Item, Link, Type, Author ID) or to choose a 1- or 2-column layout for this screen.', 'buddypress' ) . '</p>' .
181
- '<p>' . __( 'You can also moderate the activity from this screen using the Status box, where you can also change the timestamp of the activity.', 'buddypress' ) . '</p>'
182
- ) );
183
-
184
- get_current_screen()->add_help_tab( array(
185
- 'id' => 'bp-activity-edit-advanced',
186
- 'title' => __( 'Item, Link, Type', 'buddypress' ),
187
- 'content' =>
188
- '<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>' .
189
- '<p>' . __( '<strong>Link</strong> - Activity generated by blog 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>' .
190
- '<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>' .
191
- '<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>'
192
- ) );
193
-
194
- // Help panel - sidebar links
195
- get_current_screen()->set_help_sidebar(
196
- '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
197
- '<p>' . __( '<a href="http://codex.buddypress.org/buddypress-site-administration/managing-activity/">Managing Activity</a>', 'buddypress' ) . '</p>' .
198
- '<p>' . __( '<a href="http://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
199
- );
200
-
201
- // Register metaboxes for the edit screen.
202
- add_meta_box( 'submitdiv', _x( 'Status', 'activity admin edit screen', 'buddypress' ), 'bp_activity_admin_edit_metabox_status', get_current_screen()->id, 'side', 'core' );
203
- add_meta_box( 'bp_activity_itemids', _x( 'Primary Item/Secondary Item', 'activity admin edit screen', 'buddypress' ), 'bp_activity_admin_edit_metabox_itemids', get_current_screen()->id, 'normal', 'core' );
204
- add_meta_box( 'bp_activity_link', _x( 'Link', 'activity admin edit screen', 'buddypress' ), 'bp_activity_admin_edit_metabox_link', get_current_screen()->id, 'normal', 'core' );
205
- 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' );
206
- 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' );
207
-
208
- // Enqueue javascripts
209
- wp_enqueue_script( 'postbox' );
210
- wp_enqueue_script( 'dashboard' );
211
- wp_enqueue_script( 'comment' );
212
-
213
- // Index screen
214
- } else {
215
- // Create the Activity screen list table
216
- $bp_activity_list_table = new BP_Activity_List_Table();
217
-
218
- // per_page screen option
219
- add_screen_option( 'per_page', array( 'label' => _x( 'Activity', 'Activity items per page (screen options)', 'buddypress' )) );
220
-
221
- // Help panel - overview text
222
- get_current_screen()->add_help_tab( array(
223
- 'id' => 'bp-activity-overview',
224
- 'title' => __( 'Overview', 'buddypress' ),
225
- 'content' =>
226
- '<p>' . __( 'You can manage activities made on your site similar to the way you manage comments and other content. This screen is customizable in the same ways as other management screens, and you can act on activities using the on-hover action links or the Bulk Actions.', 'buddypress' ) . '</p>' .
227
- '<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>'
228
- ) );
229
-
230
- // Help panel - moderation text
231
- get_current_screen()->add_help_tab( array(
232
- 'id' => 'bp-activity-moderating',
233
- 'title' => __( 'Moderating Activity', 'buddypress' ),
234
- 'content' =>
235
- '<p>' . __( 'In the <strong>Activity</strong> column, above each activity it says &#8220;Submitted on,&#8221; followed by the date and time the activity item was generated on your site. Clicking on the date/time link will take you to that activity on your live site. Hovering over any activity gives you options to reply, edit, spam mark, or delete that activity.', 'buddypress' ) . '</p>' .
236
- '<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>'
237
- ) );
238
-
239
- // Help panel - sidebar links
240
- get_current_screen()->set_help_sidebar(
241
- '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
242
- '<p>' . __( '<a href="http://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
243
- );
244
- }
245
-
246
- // Enqueue CSS and JavaScript
247
- wp_enqueue_script( 'bp_activity_admin_js', BP_PLUGIN_URL . "bp-activity/admin/js/admin.{$dev}js", array( 'jquery', 'wp-ajax-response' ), bp_get_version(), true );
248
- wp_enqueue_style( 'bp_activity_admin_css', BP_PLUGIN_URL . "bp-activity/admin/css/admin.{$dev}css", array(), bp_get_version() );
249
-
250
- // Handle spam/un-spam/delete of activities
251
- if ( !empty( $doaction ) && ! in_array( $doaction, array( '-1', 'edit', 'save', ) ) ) {
252
-
253
- // Build redirection URL
254
- $redirect_to = remove_query_arg( array( 'aid', 'deleted', 'error', 'spammed', 'unspammed', ), wp_get_referer() );
255
- $redirect_to = add_query_arg( 'paged', $bp_activity_list_table->get_pagenum(), $redirect_to );
256
-
257
- // Get activity IDs
258
- $activity_ids = array_map( 'absint', (array) $_REQUEST['aid'] );
259
-
260
- // Call a filter for plugins to modify the requested activities to load
261
- $activity_ids = apply_filters( 'bp_activity_admin_action_activity_ids', $activity_ids );
262
-
263
- // Is this a bulk request?
264
- if ( 'bulk_' == substr( $doaction, 0, 5 ) && ! empty( $_REQUEST['aid'] ) ) {
265
- // Check this is a valid form submission
266
- check_admin_referer( 'bulk-activities' );
267
-
268
- // Trim 'bulk_' off the action name to avoid duplicating a ton of code
269
- $doaction = substr( $doaction, 5 );
270
-
271
- // This is a request to delete, spam, or un-spam, a single item.
272
- } elseif ( !empty( $_REQUEST['aid'] ) ) {
273
-
274
- // Check this is a valid form submission
275
- check_admin_referer( 'spam-activity_' . $activity_ids[0] );
276
- }
277
-
278
- // Initialise counters for how many of each type of item we perform an action on
279
- $deleted = $spammed = $unspammed = 0;
280
-
281
- // Store any errors that occurs when updating the database items
282
- $errors = array();
283
-
284
- // "We'd like to shoot the monster, could you move, please?"
285
- foreach ( $activity_ids as $activity_id ) {
286
- // @todo: Check the permissions on each
287
- //if ( ! current_user_can( 'bp_edit_activity', $activity_id ) )
288
- // continue;
289
-
290
- // Get the activity from the database
291
- $activity = new BP_Activity_Activity( $activity_id );
292
- if ( empty( $activity->component ) ) {
293
- $errors[] = $activity_id;
294
- continue;
295
- }
296
-
297
- switch ( $doaction ) {
298
- case 'delete' :
299
- if ( 'activity_comment' == $activity->type )
300
- bp_activity_delete_comment( $activity->item_id, $activity->id );
301
- else
302
- bp_activity_delete( array( 'id' => $activity->id ) );
303
-
304
- $deleted++;
305
- break;
306
-
307
- case 'ham' :
308
- /**
309
- * Remove moderation and blacklist checks in case we want to ham an activity
310
- * which contains one of these listed keys.
311
- */
312
- remove_action( 'bp_activity_before_save', 'bp_activity_check_moderation_keys', 2, 1 );
313
- remove_action( 'bp_activity_before_save', 'bp_activity_check_blacklist_keys', 2, 1 );
314
-
315
- bp_activity_mark_as_ham( $activity );
316
- $result = $activity->save();
317
-
318
- // Check for any error during activity save
319
- if ( ! $result )
320
- $errors[] = $activity->id;
321
- else
322
- $unspammed++;
323
- break;
324
-
325
- case 'spam' :
326
- bp_activity_mark_as_spam( $activity );
327
- $result = $activity->save();
328
-
329
- // Check for any error during activity save
330
- if ( ! $result )
331
- $errors[] = $activity->id;
332
- else
333
- $spammed++;
334
- break;
335
-
336
- default:
337
- break;
338
- }
339
-
340
- // Release memory
341
- unset( $activity );
342
- }
343
-
344
- // Call actions for plugins to do something before we redirect
345
- do_action( 'bp_activity_admin_action_after', array( $spammed, $unspammed, $deleted, $errors ), $redirect_to, $activity_ids );
346
-
347
- // Add arguments to the redirect URL so that on page reload, we can easily display what we've just done.
348
- if ( $spammed )
349
- $redirect_to = add_query_arg( 'spammed', $spammed, $redirect_to );
350
-
351
- if ( $unspammed )
352
- $redirect_to = add_query_arg( 'unspammed', $unspammed, $redirect_to );
353
-
354
- if ( $deleted )
355
- $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to );
356
-
357
- // If an error occurred, pass back the activity ID that failed
358
- if ( ! empty( $errors ) )
359
- $redirect_to = add_query_arg( 'error', implode ( ',', array_map( 'absint', $errors ) ), $redirect_to );
360
-
361
- // Redirect
362
- wp_redirect( apply_filters( 'bp_activity_admin_action_redirect', $redirect_to ) );
363
- exit;
364
-
365
-
366
- // Save the edit
367
- } elseif ( $doaction && 'save' == $doaction ) {
368
- // Build redirection URL
369
- $redirect_to = remove_query_arg( array( 'action', 'aid', 'deleted', 'error', 'spammed', 'unspammed', ), $_SERVER['REQUEST_URI'] );
370
-
371
- // Get activity ID
372
- $activity_id = (int) $_REQUEST['aid'];
373
-
374
- // Check this is a valid form submission
375
- check_admin_referer( 'edit-activity_' . $activity_id );
376
-
377
- // Get the activity from the database
378
- $activity = new BP_Activity_Activity( $activity_id );
379
-
380
- // If the activity doesn't exist, just redirect back to the index
381
- if ( empty( $activity->component ) ) {
382
- wp_redirect( $redirect_to );
383
- exit;
384
- }
385
-
386
- // Check the form for the updated properties
387
-
388
- // Store any error that occurs when updating the database item
389
- $error = 0;
390
-
391
- // Activity spam status
392
- $prev_spam_status = $new_spam_status = false;
393
- if ( ! empty( $_POST['activity_status'] ) ) {
394
- $prev_spam_status = $activity->is_spam;
395
- $new_spam_status = ( 'spam' == $_POST['activity_status'] ) ? true : false;
396
- }
397
-
398
- // Activity action
399
- if ( isset( $_POST['bp-activities-action'] ) )
400
- $activity->action = $_POST['bp-activities-action'];
401
-
402
- // Activity content
403
- if ( isset( $_POST['bp-activities-content'] ) )
404
- $activity->content = $_POST['bp-activities-content'];
405
-
406
- // Activity primary link
407
- if ( ! empty( $_POST['bp-activities-link'] ) )
408
- $activity->primary_link = $_POST['bp-activities-link'];
409
-
410
- // Activity user ID
411
- if ( ! empty( $_POST['bp-activities-userid'] ) )
412
- $activity->user_id = (int) $_POST['bp-activities-userid'];
413
-
414
- // Activity item primary ID
415
- if ( isset( $_POST['bp-activities-primaryid'] ) )
416
- $activity->item_id = (int) $_POST['bp-activities-primaryid'];
417
-
418
- // Activity item secondary ID
419
- if ( isset( $_POST['bp-activities-secondaryid'] ) )
420
- $activity->secondary_item_id = (int) $_POST['bp-activities-secondaryid'];
421
-
422
- // Activity type
423
- if ( ! empty( $_POST['bp-activities-type'] ) ) {
424
- $actions = array();
425
-
426
- // Walk through the registered actions, and build an array of actions/values.
427
- foreach ( $bp->activity->actions as $action ) {
428
- $action = array_values( (array) $action );
429
-
430
- for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ )
431
- $actions[] = $action[$i]['key'];
432
- }
433
-
434
- // This was a mis-named activity type from before BP 1.6
435
- unset( $actions['friends_register_activity_action'] );
436
-
437
- // Check that the new type is a registered activity type
438
- if ( in_array( $_POST['bp-activities-type'], $actions ) )
439
- $activity->type = $_POST['bp-activities-type'];
440
- }
441
-
442
- // Activity timestamp
443
- if ( ! empty( $_POST['aa'] ) && ! empty( $_POST['mm'] ) && ! empty( $_POST['jj'] ) && ! empty( $_POST['hh'] ) && ! empty( $_POST['mn'] ) && ! empty( $_POST['ss'] ) ) {
444
- $aa = $_POST['aa'];
445
- $mm = $_POST['mm'];
446
- $jj = $_POST['jj'];
447
- $hh = $_POST['hh'];
448
- $mn = $_POST['mn'];
449
- $ss = $_POST['ss'];
450
- $aa = ( $aa <= 0 ) ? date( 'Y' ) : $aa;
451
- $mm = ( $mm <= 0 ) ? date( 'n' ) : $mm;
452
- $jj = ( $jj > 31 ) ? 31 : $jj;
453
- $jj = ( $jj <= 0 ) ? date( 'j' ) : $jj;
454
- $hh = ( $hh > 23 ) ? $hh -24 : $hh;
455
- $mn = ( $mn > 59 ) ? $mn -60 : $mn;
456
- $ss = ( $ss > 59 ) ? $ss -60 : $ss;
457
-
458
- // Reconstruct the date into a timestamp
459
- $gmt_date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
460
-
461
- $activity->date_recorded = $gmt_date;
462
- }
463
-
464
- // Has the spam status has changed?
465
- if ( $new_spam_status != $prev_spam_status ) {
466
- if ( $new_spam_status )
467
- bp_activity_mark_as_spam( $activity );
468
- else
469
- bp_activity_mark_as_ham( $activity );
470
- }
471
-
472
- // Save
473
- $result = $activity->save();
474
-
475
- // Clear the activity stream first page cache, in case this activity's timestamp was changed
476
- wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
477
-
478
- // Check for any error during activity save
479
- if ( false === $result )
480
- $error = $activity->id;
481
-
482
- // Call actions for plugins to do something before we redirect
483
- do_action_ref_array( 'bp_activity_admin_edit_after', array( &$activity, $error ) );
484
-
485
- // If an error occurred, pass back the activity ID that failed
486
- if ( $error )
487
- $redirect_to = add_query_arg( 'error', (int) $error, $redirect_to );
488
- else
489
- $redirect_to = add_query_arg( 'updated', (int) $activity->id, $redirect_to );
490
-
491
- // Redirect
492
- wp_redirect( apply_filters( 'bp_activity_admin_edit_redirect', $redirect_to ) );
493
- exit;
494
-
495
-
496
- // If a referrer and a nonce is supplied, but no action, redirect back.
497
- } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
498
- wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), stripslashes( $_SERVER['REQUEST_URI'] ) ) );
499
- exit;
500
- }
501
- }
502
-
503
- /**
504
- * Outputs the Activity component admin screens
505
- *
506
- * @since 1.6
507
- */
508
- function bp_activity_admin() {
509
- // Decide whether to load the index or edit screen
510
- $doaction = ! empty( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
511
-
512
- // Display the single activity edit screen
513
- if ( 'edit' == $doaction && ! empty( $_GET['aid'] ) )
514
- bp_activity_admin_edit();
515
-
516
- // Otherwise, display the Activity index screen
517
- else
518
- bp_activity_admin_index();
519
- }
520
-
521
- /**
522
- * Display the single activity edit screen
523
- *
524
- * @global int $screen_layout_columns Number of columns shown on this admin page
525
- * @since 1.6
526
- */
527
- function bp_activity_admin_edit() {
528
- global $screen_layout_columns;
529
-
530
- // @todo: Check if user is allowed to edit activity items
531
- // if ( ! current_user_can( 'bp_edit_activity' ) )
532
- if ( ! is_super_admin() )
533
- die( '-1' );
534
-
535
- // Get the activity from the database
536
- $activity = bp_activity_get( array(
537
- 'in' => ! empty( $_REQUEST['aid'] ) ? (int) $_REQUEST['aid'] : 0,
538
- 'max' => 1,
539
- 'show_hidden' => true,
540
- 'spam' => 'all',
541
- 'display_comments' => 0
542
- ) );
543
-
544
- if ( ! empty( $activity['activities'][0] ) ) {
545
- $activity = $activity['activities'][0];
546
-
547
- // Workaround to use WP's touch_time() without duplicating that function
548
- $GLOBALS['comment'] = new stdClass;
549
- $GLOBALS['comment']->comment_date = $activity->date_recorded;
550
- } else {
551
- $activity = '';
552
- }
553
-
554
- // Construct URL for form
555
- $form_url = remove_query_arg( array( 'action', 'deleted', 'error', 'spammed', 'unspammed', ), $_SERVER['REQUEST_URI'] );
556
- $form_url = add_query_arg( 'action', 'save', $form_url );
557
-
558
- // Call an action for plugins to modify the activity before we display the edit form
559
- do_action_ref_array( 'bp_activity_admin_edit', array( &$activity ) );
560
- ?>
561
-
562
- <div class="wrap">
563
- <?php screen_icon( 'buddypress-activity' ); ?>
564
- <h2><?php printf( __( 'Editing Activity (ID #%s)', 'buddypress' ), number_format_i18n( (int) $_REQUEST['aid'] ) ); ?></h2>
565
-
566
- <?php if ( ! empty( $activity ) ) : ?>
567
-
568
- <form action="<?php echo esc_attr( $form_url ); ?>" id="bp-activities-edit-form" method="post">
569
- <div id="poststuff">
570
-
571
- <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
572
- <div id="post-body-content">
573
- <div id="postdiv" class="postarea">
574
- <div id="bp_activity_action" class="postbox">
575
- <h3><?php _e( 'Action', 'buddypress' ); ?></h3>
576
- <div class="inside">
577
- <?php wp_editor( stripslashes( $activity->action ), 'bp-activities-action', array( 'media_buttons' => false, 'textarea_rows' => 7, 'teeny' => true, 'quicktags' => array( 'buttons' => 'strong,em,link,block,del,ins,img,code,spell,close' ) ) ); ?>
578
- </div>
579
- </div>
580
-
581
- <div id="bp_activity_content" class="postbox">
582
- <h3><?php _e( 'Content', 'buddypress' ); ?></h3>
583
- <div class="inside">
584
- <?php wp_editor( stripslashes( $activity->content ), 'bp-activities-content', array( 'media_buttons' => false, 'teeny' => true, 'quicktags' => array( 'buttons' => 'strong,em,link,block,del,ins,img,code,spell,close' ) ) ); ?>
585
- </div>
586
- </div>
587
- </div>
588
- </div><!-- #post-body-content -->
589
-
590
- <div id="postbox-container-1" class="postbox-container">
591
- <?php do_meta_boxes( get_current_screen()->id, 'side', $activity ); ?>
592
- </div>
593
-
594
- <div id="postbox-container-2" class="postbox-container">
595
- <?php do_meta_boxes( get_current_screen()->id, 'normal', $activity ); ?>
596
- <?php do_meta_boxes( get_current_screen()->id, 'advanced', $activity ); ?>
597
- </div>
598
- </div><!-- #post-body -->
599
-
600
- </div><!-- #poststuff -->
601
- <?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
602
- <?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?>
603
- <?php wp_nonce_field( 'edit-activity_' . $activity->id ); ?>
604
- </form>
605
-
606
- <?php else : ?>
607
- <p><?php printf( __( 'No activity found with this ID. <a href="%s">Go back and try again</a>.', 'buddypress' ), network_admin_url( 'admin.php?page=bp-activity' ) ); ?></p>
608
- <?php endif; ?>
609
-
610
- </div><!-- .wrap -->
611
-
612
- <?php
613
- }
614
-
615
- /**
616
- * Status metabox for the Activity admin edit screen
617
- *
618
- * @param object $item Activity item
619
- * @since 1.6
620
- */
621
- function bp_activity_admin_edit_metabox_status( $item ) {
622
- ?>
623
-
624
- <div class="submitbox" id="submitcomment">
625
-
626
- <div id="minor-publishing">
627
- <div id="minor-publishing-actions">
628
- <div id="preview-action">
629
- <a class="button preview" href="<?php echo esc_attr( bp_activity_get_permalink( $item->id, $item ) ); ?>" target="_blank"><?php _e( 'View Activity', 'buddypress' ); ?></a>
630
- </div>
631
-
632
- <div class="clear"></div>
633
- </div><!-- #minor-publishing-actions -->
634
-
635
- <div id="misc-publishing-actions">
636
- <div class="misc-pub-section" id="comment-status-radio">
637
- <label class="approved"><input type="radio" name="activity_status" value="ham" <?php checked( $item->is_spam, 0 ); ?>><?php _e( 'Approved', 'buddypress' ); ?></label><br />
638
- <label class="spam"><input type="radio" name="activity_status" value="spam" <?php checked( $item->is_spam, 1 ); ?>><?php _e( 'Spam', 'buddypress' ); ?></label>
639
- </div>
640
-
641
- <div class="misc-pub-section curtime misc-pub-section-last">
642
- <?php
643
- // translators: Publish box date format, see http://php.net/date
644
- $datef = __( 'M j, Y @ G:i', 'buddypress' );
645
- $date = date_i18n( $datef, strtotime( $item->date_recorded ) );
646
- ?>
647
- <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>
648
-
649
- <div id='timestampdiv' class='hide-if-js'>
650
- <?php touch_time( 1, 0, 5 ); ?>
651
- </div><!-- #timestampdiv -->
652
- </div>
653
- </div> <!-- #misc-publishing-actions -->
654
-
655
- <div class="clear"></div>
656
- </div><!-- #minor-publishing -->
657
-
658
- <div id="major-publishing-actions">
659
- <div id="publishing-action">
660
- <?php submit_button( __( 'Update', 'buddypress' ), 'primary', 'save', false, array( 'tabindex' => '4' ) ); ?>
661
- </div>
662
- <div class="clear"></div>
663
- </div><!-- #major-publishing-actions -->
664
-
665
- </div><!-- #submitcomment -->
666
-
667
- <?php
668
- }
669
-
670
- /**
671
- * Primary link metabox for the Activity admin edit screen
672
- *
673
- * @param object $item Activity item
674
- * @since 1.6
675
- */
676
- function bp_activity_admin_edit_metabox_link( $item ) {
677
- ?>
678
-
679
- <label class="screen-reader-text" for="bp-activities-link"><?php _e( 'Link', 'buddypress' ); ?></label>
680
- <input type="url" name="bp-activities-link" value="<?php echo esc_url( $item->primary_link ); ?>" />
681
- <p><?php _e( 'Activity generated by blog posts and comments, forum topics and replies, and some plugins, uses the link field for a permalink back to the content item.', 'buddypress' ); ?></p>
682
-
683
- <?php
684
- }
685
-
686
- /**
687
- * User ID metabox for the Activity admin edit screen
688
- *
689
- * @param object $item Activity item
690
- * @since 1.6
691
- */
692
- function bp_activity_admin_edit_metabox_userid( $item ) {
693
- ?>
694
-
695
- <label class="screen-reader-text" for="bp-activities-userid"><?php _e( 'Author ID', 'buddypress' ); ?></label>
696
- <input type="number" name="bp-activities-userid" value="<?php echo esc_attr( $item->user_id ); ?>" min="1" />
697
-
698
- <?php
699
- }
700
-
701
- /**
702
- * Activity type metabox for the Activity admin edit screen
703
- *
704
- * @global object $bp BuddyPress global settings
705
- * @param object $item Activity item
706
- * @since 1.6
707
- */
708
- function bp_activity_admin_edit_metabox_type( $item ) {
709
- global $bp;
710
-
711
- $actions = array();
712
- $selected = $item->type;
713
-
714
- // Walk through the registered actions, and build an array of actions/values.
715
- foreach ( $bp->activity->actions as $action ) {
716
- $action = array_values( (array) $action );
717
-
718
- for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ )
719
- $actions[ $action[$i]['key'] ] = $action[$i]['value'];
720
- }
721
-
722
- // This was a mis-named activity type from before BP 1.6
723
- unset( $actions['friends_register_activity_action'] );
724
-
725
- // Sort array by the human-readable value
726
- natsort( $actions );
727
- ?>
728
-
729
- <select name="bp-activities-type">
730
- <?php foreach ( $actions as $k => $v ) : ?>
731
- <option value="<?php echo esc_attr( $k ); ?>" <?php selected( $k, $selected ); ?>><?php echo esc_html( $v ); ?></option>
732
- <?php endforeach; ?>
733
- </select>
734
-
735
- <?php
736
- }
737
-
738
- /**
739
- * Primary item ID/Secondary item ID metabox for the Activity admin edit screen
740
- *
741
- * @param object $item Activity item
742
- * @since 1.6
743
- */
744
- function bp_activity_admin_edit_metabox_itemids( $item ) {
745
- ?>
746
-
747
- <label for="bp-activities-primaryid"><?php _e( 'Primary Item ID', 'buddypress' ); ?></label>
748
- <input type="number" name="bp-activities-primaryid" id="bp-activities-primaryid" value="<?php echo esc_attr( $item->item_id ); ?>" min="0" />
749
- <br />
750
-
751
- <label for="bp-activities-secondaryid"><?php _e( 'Secondary Item ID', 'buddypress' ); ?></label>
752
- <input type="number" name="bp-activities-secondaryid" id="bp-activities-secondaryid" value="<?php echo esc_attr( $item->secondary_item_id ); ?>" min="0" />
753
-
754
- <p><?php _e( 'These identify the object that created this activity. For example, the fields could reference a pair of site and comment IDs.', 'buddypress' ); ?></p>
755
-
756
- <?php
757
- }
758
-
759
- /**
760
- * Display the Activity admin index screen, which contains a list of all the activities.
761
- *
762
- * @global BP_Activity_List_Table $bp_activity_list_table Activity screen list table
763
- * @global string $plugin_page
764
- * @since 1.6
765
- */
766
- function bp_activity_admin_index() {
767
- global $bp_activity_list_table, $plugin_page;
768
-
769
- $messages = array();
770
-
771
- // If the user has just made a change to an activity item, build status messages
772
- if ( ! empty( $_REQUEST['deleted'] ) || ! empty( $_REQUEST['spammed'] ) || ! empty( $_REQUEST['unspammed'] ) || ! empty( $_REQUEST['error'] ) || ! empty( $_REQUEST['updated'] ) ) {
773
- $deleted = ! empty( $_REQUEST['deleted'] ) ? (int) $_REQUEST['deleted'] : 0;
774
- $errors = ! empty( $_REQUEST['error'] ) ? $_REQUEST['error'] : '';
775
- $spammed = ! empty( $_REQUEST['spammed'] ) ? (int) $_REQUEST['spammed'] : 0;
776
- $unspammed = ! empty( $_REQUEST['unspammed'] ) ? (int) $_REQUEST['unspammed'] : 0;
777
- $updated = ! empty( $_REQUEST['updated'] ) ? (int) $_REQUEST['updated'] : 0;
778
-
779
- $errors = array_map( 'absint', explode( ',', $errors ) );
780
-
781
- // Make sure we don't get any empty values in $errors
782
- for ( $i = 0, $errors_count = count( $errors ); $i < $errors_count; $i++ ) {
783
- if ( 0 === $errors[$i] )
784
- unset( $errors[$i] );
785
- }
786
-
787
- // Reindex array
788
- $errors = array_values( $errors );
789
-
790
- if ( $deleted > 0 )
791
- $messages[] = sprintf( _n( '%s activity has been permanently deleted.', '%s activity items have been permanently deleted.', $deleted, 'buddypress' ), number_format_i18n( $deleted ) );
792
-
793
- if ( ! empty( $errors ) ) {
794
- if ( 1 == count( $errors ) ) {
795
- $messages[] = sprintf( __( 'An error occurred when trying to update activity ID #%s.', 'buddypress' ), number_format_i18n( $errors[0] ) );
796
-
797
- } else {
798
- $error_msg = __( 'Errors occurred when trying to update these activity items:', 'buddypress' );
799
- $error_msg .= '<ul class="activity-errors">';
800
-
801
- // Display each error as a list item
802
- foreach ( $errors as $error ) {
803
- // Translators: This is a bulleted list of item IDs
804
- $error_msg .= '<li>' . sprintf( __( '#%s', 'buddypress' ), number_format_i18n( $error ) ) . '</li>';
805
- }
806
-
807
- $error_msg .= '</ul>';
808
- $messages[] = $error_msg;
809
- }
810
- }
811
-
812
- if ( $spammed > 0 )
813
- $messages[] = sprintf( _n( '%s activity has been successfully spammed.', '%s activity items have been successfully spammed.', $spammed, 'buddypress' ), number_format_i18n( $spammed ) );
814
-
815
- if ( $unspammed > 0 )
816
- $messages[] = sprintf( _n( '%s activity has been successfully unspammed.', '%s activity items have been successfully unspammed.', $unspammed, 'buddypress' ), number_format_i18n( $unspammed ) );
817
-
818
- if ( $updated > 0 )
819
- $messages[] = __( 'The activity has been updated succesfully.', 'buddypress' );
820
- }
821
-
822
- // Prepare the activity items for display
823
- $bp_activity_list_table->prepare_items();
824
-
825
- // Call an action for plugins to modify the activity before we display the edit form
826
- do_action( 'bp_activity_admin_index', $messages );
827
- ?>
828
-
829
- <div class="wrap">
830
- <?php screen_icon( 'buddypress-activity' ); ?>
831
- <h2>
832
- <?php if ( !empty( $_REQUEST['aid'] ) ) : ?>
833
- <?php printf( __( 'Activity related to ID #%s', 'buddypress' ), number_format_i18n( (int) $_REQUEST['aid'] ) ); ?>
834
- <?php else : ?>
835
- <?php _e( 'Activity', 'buddypress' ); ?>
836
- <?php endif; ?>
837
-
838
- <?php if ( !empty( $_REQUEST['s'] ) ) : ?>
839
- <span class="subtitle"><?php printf( __( 'Search results for &#8220;%s&#8221;', 'buddypress' ), wp_html_excerpt( esc_html( stripslashes( $_REQUEST['s'] ) ), 50 ) ); ?></span>
840
- <?php endif; ?>
841
- </h2>
842
-
843
- <?php // If the user has just made a change to an activity item, display the status messages ?>
844
- <?php if ( !empty( $messages ) ) : ?>
845
- <div id="moderated" class="<?php echo ( ! empty( $_REQUEST['error'] ) ) ? 'error' : 'updated'; ?>"><p><?php echo implode( "<br/>\n", $messages ); ?></p></div>
846
- <?php endif; ?>
847
-
848
- <?php // Display each activity on its own row ?>
849
- <?php $bp_activity_list_table->views(); ?>
850
-
851
- <form id="bp-activities-form" action="" method="get">
852
- <?php $bp_activity_list_table->search_box( __( 'Search all Activity', 'buddypress' ), 'bp-activity' ); ?>
853
- <input type="hidden" name="page" value="<?php echo esc_attr( $plugin_page ); ?>" />
854
- <?php $bp_activity_list_table->display(); ?>
855
- </form>
856
-
857
- <?php // This markup is used for the reply form ?>
858
- <table style="display: none;">
859
- <tr id="bp-activities-container" style="display: none;">
860
- <td colspan="4">
861
- <form method="get" action="">
862
-
863
- <h5 id="bp-replyhead"><?php _e( 'Reply to Activity', 'buddypress' ); ?></h5>
864
- <?php wp_editor( '', 'bp-activities', array( 'dfw' => false, 'media_buttons' => false, 'quicktags' => array( 'buttons' => 'strong,em,link,block,del,ins,img,code,spell,close' ), 'tinymce' => false, ) ); ?>
865
-
866
- <p id="bp-replysubmit" class="submit">
867
- <a href="#" class="cancel button-secondary alignleft"><?php _e( 'Cancel', 'buddypress' ); ?></a>
868
- <a href="#" class="save button-primary alignright"><?php _e( 'Reply', 'buddypress' ); ?></a>
869
-
870
- <img class="waiting" style="display:none;" src="<?php echo esc_url( network_admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
871
- <span class="error" style="display:none;"></span>
872
- <br class="clear" />
873
- </p>
874
-
875
- <?php wp_nonce_field( 'bp-activity-admin-reply', '_ajax_nonce-bp-activity-admin-reply', false ); ?>
876
-
877
- </form>
878
- </td>
879
- </tr>
880
- </table>
881
- </div>
882
-
883
- <?php
884
- }
885
-
886
- /**
887
- * List table class for the Activity component admin page.
888
- *
889
- * @since 1.6
890
- */
891
- class BP_Activity_List_Table extends WP_List_Table {
892
- /**
893
- * What type of view is being displayed? e.g. "All", "Pending", "Approved", "Spam"...
894
- *
895
- * @since 1.6
896
- */
897
- public $view = 'all';
898
-
899
- /**
900
- * How many activity items have been marked as spam.
901
- *
902
- * @since 1.6
903
- */
904
- public $spam_count = 0;
905
-
906
- /**
907
- * Store activity-to-user-ID mappings for use in the In Response To column.
908
- *
909
- * @since 1.6
910
- */
911
- protected $activity_user_id = array();
912
-
913
- /**
914
- * Constructor
915
- *
916
- * @since 1.6
917
- */
918
- public function __construct() {
919
-
920
- // Define singular and plural labels, as well as whether we support AJAX.
921
- parent::__construct( array(
922
- 'ajax' => false,
923
- 'plural' => 'activities',
924
- 'singular' => 'activity',
925
- ) );
926
- }
927
-
928
- /**
929
- * Handle filtering of data, sorting, pagination, and any other data-manipulation required prior to rendering.
930
- *
931
- * @since 1.6
932
- */
933
- function prepare_items() {
934
- $screen = get_current_screen();
935
-
936
- // Option defaults
937
- $filter = array();
938
- $include_id = false;
939
- $search_terms = false;
940
- $sort = 'DESC';
941
- $spam = 'ham_only';
942
-
943
- // Set current page
944
- $page = $this->get_pagenum();
945
-
946
- // Set per page from the screen options
947
- $per_page = $this->get_items_per_page( str_replace( '-', '_', "{$screen->id}_per_page" ) );
948
-
949
- // Check if we're on the "Spam" view
950
- if ( !empty( $_REQUEST['activity_status'] ) && 'spam' == $_REQUEST['activity_status'] ) {
951
- $spam = 'spam_only';
952
- $this->view = 'spam';
953
- }
954
-
955
- // Sort order
956
- if ( !empty( $_REQUEST['order'] ) && 'desc' != $_REQUEST['order'] )
957
- $sort = 'ASC';
958
-
959
- // Order by
960
- /*if ( !empty( $_REQUEST['orderby'] ) ) {
961
- }*/
962
-
963
- // Filter
964
- if ( !empty( $_REQUEST['activity_type'] ) )
965
- $filter = array( 'action' => $_REQUEST['activity_type'] );
966
-
967
- // Are we doing a search?
968
- if ( !empty( $_REQUEST['s'] ) )
969
- $search_terms = $_REQUEST['s'];
970
-
971
- // Check if user has clicked on a specific activity (if so, fetch only that, and any related, activity).
972
- if ( !empty( $_REQUEST['aid'] ) )
973
- $include_id = (int) $_REQUEST['aid'];
974
-
975
- // Get the spam total (ignoring any search query or filter)
976
- $spams = bp_activity_get( array(
977
- 'display_comments' => 'stream',
978
- 'show_hidden' => true,
979
- 'spam' => 'spam_only',
980
- ) );
981
- $this->spam_count = $spams['total'];
982
- unset( $spams );
983
-
984
- // Get the activities from the database
985
- $activities = bp_activity_get( array(
986
- 'display_comments' => 'stream',
987
- 'filter' => $filter,
988
- 'in' => $include_id,
989
- 'page' => $page,
990
- 'per_page' => $per_page,
991
- 'search_terms' => $search_terms,
992
- 'show_hidden' => true,
993
- //'sort' => $sort,
994
- 'spam' => $spam,
995
- ) );
996
-
997
- // If we're viewing a specific activity, flatten all activites into a single array.
998
- if ( $include_id ) {
999
- $activities['activities'] = BP_Activity_List_Table::flatten_activity_array( $activities['activities'] );
1000
- $activities['total'] = count( $activities['activities'] );
1001
-
1002
- // Sort the array by the activity object's date_recorded value
1003
- usort( $activities['activities'], create_function( '$a, $b', 'return $a->date_recorded > $b->date_recorded;' ) );
1004
- }
1005
-
1006
- // bp_activity_get returns an array of objects; cast these to arrays for WP_List_Table.
1007
- $new_activities = array();
1008
- foreach ( $activities['activities'] as $activity_item ) {
1009
- $new_activities[] = (array) $activity_item;
1010
-
1011
- // Build an array of activity-to-user ID mappings for better efficency in the In Response To column
1012
- $this->activity_user_id[$activity_item->id] = $activity_item->user_id;
1013
- }
1014
-
1015
- // Set raw data to display
1016
- $this->items = $new_activities;
1017
-
1018
- // Store information needed for handling table pagination
1019
- $this->set_pagination_args( array(
1020
- 'per_page' => $per_page,
1021
- 'total_items' => $activities['total'],
1022
- 'total_pages' => ceil( $activities['total'] / $per_page )
1023
- ) );
1024
-
1025
- // Don't truncate activity items; bp_activity_truncate_entry() needs to be used inside a BP_Activity_Template loop.
1026
- remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
1027
- }
1028
-
1029
- /**
1030
- * Get an array of all the columns on the page
1031
- *
1032
- * @return array
1033
- * @since 1.6
1034
- */
1035
- function get_column_info() {
1036
- $this->_column_headers = array(
1037
- $this->get_columns(),
1038
- array(),
1039
- $this->get_sortable_columns(),
1040
- );
1041
-
1042
- return $this->_column_headers;
1043
- }
1044
-
1045
- /**
1046
- * Displays a message on screen when no items are found (e.g. no search matches)
1047
- *
1048
- * @since 1.6
1049
- */
1050
- function no_items() {
1051
- _e( 'No activities found.', 'buddypress' );
1052
- }
1053
-
1054
- /**
1055
- * Outputs the Activity data table
1056
- *
1057
- * @since 1.6
1058
- */
1059
- function display() {
1060
- extract( $this->_args );
1061
-
1062
- $this->display_tablenav( 'top' );
1063
- ?>
1064
-
1065
- <table class="<?php echo implode( ' ', $this->get_table_classes() ); ?>" cellspacing="0">
1066
- <thead>
1067
- <tr>
1068
- <?php $this->print_column_headers(); ?>
1069
- </tr>
1070
- </thead>
1071
-
1072
- <tfoot>
1073
- <tr>
1074
- <?php $this->print_column_headers( false ); ?>
1075
- </tr>
1076
- </tfoot>
1077
-
1078
- <tbody id="the-comment-list">
1079
- <?php $this->display_rows_or_placeholder(); ?>
1080
- </tbody>
1081
- </table>
1082
- <?php
1083
-
1084
- $this->display_tablenav( 'bottom' );
1085
- }
1086
-
1087
- /**
1088
- * Generates content for a single row of the table
1089
- *
1090
- * @param object $item The current item
1091
- * @since 1.6
1092
- */
1093
- function single_row( $item ) {
1094
- static $row_class = '';
1095
- $row_class = ( $row_class == '' ? ' class="alternate"' : '' );
1096
-
1097
- echo '<tr' . $row_class . ' id="activity-' . esc_attr( $item['id'] ) . '" data-parent_id="' . esc_attr( $item['id'] ) . '" data-root_id="' . esc_attr( $item['item_id'] ) . '">';
1098
- echo $this->single_row_columns( $item );
1099
- echo '</tr>';
1100
- }
1101
-
1102
- /**
1103
- * Get the list of views available on this table (e.g. "all", "spam").
1104
- *
1105
- * @since 1.6
1106
- */
1107
- function get_views() {
1108
- $redirect_to = remove_query_arg( array( 'activity_status', 'aid', 'deleted', 'error', 'spammed', 'unspammed', 'updated', ), $_SERVER['REQUEST_URI'] );
1109
- ?>
1110
- <ul class="subsubsub">
1111
- <li class="all"><a href="<?php echo esc_attr( esc_url( $redirect_to ) ); ?>" class="<?php if ( 'spam' != $this->view ) echo 'current'; ?>"><?php _e( 'All', 'buddypress' ); ?></a> |</li>
1112
- <li class="spam"><a href="<?php echo esc_attr( esc_url( add_query_arg( 'activity_status', 'spam', $redirect_to ) ) ); ?>" 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>
1113
-
1114
- <?php do_action( 'bp_activity_list_table_get_views', $redirect_to, $this->view ); ?>
1115
- </ul>
1116
- <?php
1117
- }
1118
-
1119
- /**
1120
- * Get bulk actions
1121
- *
1122
- * @return array Key/value pairs for the bulk actions dropdown
1123
- * @since 1.6
1124
- */
1125
- function get_bulk_actions() {
1126
- $actions = array();
1127
- $actions['bulk_spam'] = __( 'Mark as Spam', 'buddypress' );
1128
- $actions['bulk_ham'] = __( 'Not Spam', 'buddypress' );
1129
- $actions['bulk_delete'] = __( 'Delete Permanently', 'buddypress' );
1130
-
1131
- return apply_filters( 'bp_activity_list_table_get_bulk_actions', $actions );
1132
- }
1133
-
1134
- /**
1135
- * Get the table column titles.
1136
- *
1137
- * @see WP_List_Table::single_row_columns()
1138
- * @return array
1139
- * @since 1.6
1140
- */
1141
- function get_columns() {
1142
- return array(
1143
- 'cb' => '<input name type="checkbox" />',
1144
- 'author' => __( 'Author', 'buddypress' ),
1145
- 'comment' => __( 'Activity', 'buddypress' ),
1146
- 'response' => __( 'In Response To', 'buddypress' ),
1147
- );
1148
- }
1149
-
1150
- /**
1151
- * Get the column names for sortable columns
1152
- *
1153
- * @return array
1154
- * @since 1.6
1155
- * @todo For this to work, BP_Activity_Activity::get() needs updating to supporting ordering by specific fields
1156
- */
1157
- function get_sortable_columns() {
1158
- return array();
1159
-
1160
- /*return array(
1161
- 'author' => array( 'activity_author', false ), // Intentionally not using "=>"
1162
- );*/
1163
- }
1164
-
1165
- /**
1166
- * Markup for the "filter" part of the form (i.e. which activity type to display)
1167
- *
1168
- * @global object $bp BuddyPress global settings
1169
- * @param string $which 'top' or 'bottom'
1170
- * @since 1.6
1171
- */
1172
- function extra_tablenav( $which ) {
1173
- global $bp;
1174
-
1175
- if ( 'bottom' == $which )
1176
- return;
1177
-
1178
- $actions = array();
1179
- $selected = !empty( $_REQUEST['activity_type'] ) ? $_REQUEST['activity_type'] : '';
1180
-
1181
- // Walk through the registered actions, and build an array of actions/values.
1182
- foreach ( $bp->activity->actions as $action ) {
1183
- $action = array_values( (array) $action );
1184
-
1185
- for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ )
1186
- $actions[ $action[$i]['key'] ] = $action[$i]['value'];
1187
- }
1188
-
1189
- // This was a mis-named activity type from before BP 1.6
1190
- unset( $actions['friends_register_activity_action'] );
1191
-
1192
- // This type has not been used since BP 1.0.3. It will be re-instated in a future version.
1193
- unset( $actions['updated_profile'] );
1194
-
1195
- // Sort array by the human-readable value
1196
- natsort( $actions );
1197
- ?>
1198
-
1199
- <div class="alignleft actions">
1200
- <select name="activity_type">
1201
- <option value="" <?php selected( !$selected ); ?>><?php _e( 'Show all activity types', 'buddypress' ); ?></option>
1202
-
1203
- <?php foreach ( $actions as $k => $v ) : ?>
1204
- <option value="<?php echo esc_attr( $k ); ?>" <?php selected( $k, $selected ); ?>><?php echo esc_html( $v ); ?></option>
1205
- <?php endforeach; ?>
1206
- </select>
1207
-
1208
- <?php submit_button( __( 'Filter', 'buddypress' ), 'secondary', false, false, array( 'id' => 'post-query-submit' ) ); ?>
1209
- </div>
1210
-
1211
- <?php
1212
- }
1213
-
1214
- /**
1215
- * Checkbox column
1216
- *
1217
- * @param array $item A singular item (one full row)
1218
- * @see WP_List_Table::single_row_columns()
1219
- * @since 1.6
1220
- */
1221
- function column_cb( $item ) {
1222
- printf( '<input type="checkbox" name="aid[]" value="%d" />', (int) $item['id'] );
1223
- }
1224
-
1225
- /**
1226
- * Author column
1227
- *
1228
- * @param array $item A singular item (one full row)
1229
- * @see WP_List_Table::single_row_columns()
1230
- * @since 1.6
1231
- */
1232
- function column_author( $item ) {
1233
- echo '<strong>' . get_avatar( $item['user_id'], '32' ) . ' ' . bp_core_get_userlink( $item['user_id'] ) . '</strong>';
1234
- }
1235
-
1236
- /**
1237
- * Content column, and "quick admin" rollover actions.
1238
- *
1239
- * Called "comment" in the CSS so we can re-use some WP core CSS.
1240
- *
1241
- * @param array $item A singular item (one full row)
1242
- * @see WP_List_Table::single_row_columns()
1243
- * @since 1.6
1244
- */
1245
- function column_comment( $item ) {
1246
- // Determine what type of item (row) we're dealing with
1247
- if ( $item['is_spam'] )
1248
- $item_status = 'spam';
1249
- else
1250
- $item_status = 'all';
1251
-
1252
- // Preorder items: Reply | Edit | Spam | Delete Permanently
1253
- $actions = array(
1254
- 'reply' => '',
1255
- 'edit' => '',
1256
- 'spam' => '', 'unspam' => '',
1257
- 'delete' => '',
1258
- );
1259
-
1260
- // Build actions URLs
1261
- $base_url = network_admin_url( 'admin.php?page=bp-activity&amp;aid=' . $item['id'] );
1262
- $spam_nonce = esc_html( '_wpnonce=' . wp_create_nonce( 'spam-activity_' . $item['id'] ) );
1263
-
1264
- $delete_url = $base_url . "&amp;action=delete&amp;$spam_nonce";
1265
- $edit_url = $base_url . '&amp;action=edit';
1266
- $ham_url = $base_url . "&amp;action=ham&amp;$spam_nonce";
1267
- $spam_url = $base_url . "&amp;action=spam&amp;$spam_nonce";
1268
-
1269
- // Rollover actions
1270
-
1271
- // Reply - javascript only; implemented by AJAX.
1272
- if ( 'spam' != $item_status ) {
1273
- $actions['reply'] = sprintf( '<a href="#" class="reply hide-if-no-js">%s</a>', __( 'Reply', 'buddypress' ) );
1274
-
1275
- // Edit
1276
- $actions['edit'] = sprintf( '<a href="%s">%s</a>', $edit_url, __( 'Edit', 'buddypress' ) );
1277
- }
1278
-
1279
- // Spam/unspam
1280
- if ( 'spam' == $item_status )
1281
- $actions['unspam'] = sprintf( '<a href="%s">%s</a>', $ham_url, __( 'Not Spam', 'buddypress' ) );
1282
- else
1283
- $actions['spam'] = sprintf( '<a href="%s">%s</a>', $spam_url, __( 'Spam', 'buddypress' ) );
1284
-
1285
- // Delete
1286
- $actions['delete'] = sprintf( '<a href="%s" onclick="%s">%s</a>', $delete_url, "javascript:return confirm('" . esc_js( __( 'Are you sure?', 'buddypress' ) ) . "'); ", __( 'Delete Permanently', 'buddypress' ) );
1287
-
1288
- // Start timestamp
1289
- echo '<div class="submitted-on">';
1290
-
1291
- // Other plugins can filter which actions are shown
1292
- $actions = apply_filters( 'bp_activity_admin_comment_row_actions', array_filter( $actions ), $item );
1293
-
1294
- /* translators: 2: activity admin ui date/time */
1295
- printf( __( 'Submitted on <a href="%1$s">%2$s at %3$s</a>', 'buddypress' ), bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $item['id'] . '/', date_i18n( get_option( 'date_format' ), strtotime( $item['date_recorded'] ) ), date_i18n( get_option( 'time_format' ), strtotime( $item['date_recorded'] ) ) );
1296
-
1297
- // End timestamp
1298
- echo '</div>';
1299
-
1300
- // Get activity content - if not set, use the action
1301
- if ( ! empty( $item['content'] ) )
1302
- $content = apply_filters_ref_array( 'bp_get_activity_content_body', array( $item['content'] ) );
1303
- else
1304
- $content = apply_filters_ref_array( 'bp_get_activity_action', array( $item['action'] ) );
1305
-
1306
- echo $content . ' ' . $this->row_actions( $actions );
1307
- }
1308
-
1309
- /**
1310
- * "In response to" column
1311
- *
1312
- * @param array $item A singular item (one full row)
1313
- * @see WP_List_Table::single_row_columns()
1314
- * @since 1.6
1315
- */
1316
- function column_response( $item ) {
1317
- // Is $item is a root activity?
1318
- if ( empty( $item['item_id'] ) || ! in_array( $item['type'], apply_filters( 'bp_activity_admin_root_activity_types', array( 'activity_comment' ), $item ) ) ) {
1319
- $comment_count = !empty( $item['children'] ) ? bp_activity_recurse_comment_count( (object) $item ) : 0;
1320
- $root_activity_url = network_admin_url( 'admin.php?page=bp-activity&amp;aid=' . $item['id'] );
1321
-
1322
- // If the activity has comments, display a link to the activity's permalink, with its comment count in a speech bubble
1323
- if ( $comment_count ) {
1324
- $title_attr = sprintf( _n( '%s related activity', '%s related activities', $comment_count, 'buddypress' ), number_format_i18n( $comment_count ) );
1325
- printf( '<a href="%1$s" title="%2$s" class="post-com-count"><span class="comment-count">%3$s</span></a>', esc_attr( $root_activity_url ), esc_attr( $title_attr ), number_format_i18n( $comment_count ) );
1326
- }
1327
-
1328
- // For non-root activities, display a link to the replied-to activity's author's profile
1329
- } else {
1330
- 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 />';
1331
- }
1332
-
1333
- // Activity permalink
1334
- if ( ! $item['is_spam'] )
1335
- printf( __( '<a href="%1$s">View Activity</a>', 'buddypress' ), bp_activity_get_permalink( $item['id'], (object) $item ) );
1336
- }
1337
-
1338
- /**
1339
- * A wrapper function for the BP_Activity_List_Table to get the specified activity's user ID.
1340
- *
1341
- * @param int $activity_id Activity ID to retrieve User ID for
1342
- * @since 1.6
1343
- */
1344
- protected function get_activity_user_id( $activity_id ) {
1345
- // If there is an existing activity/user ID mapping, just return the user ID.
1346
- if ( ! empty( $this->activity_user_id[$activity_id] ) ) {
1347
- return $this->activity_user_id[$activity_id];
1348
-
1349
- /**
1350
- * We don't have a mapping. This means the $activity_id is not on the current
1351
- * page of results, so fetch its details from the database.
1352
- */
1353
- } else {
1354
- $activity = bp_activity_get_specific( array( 'activity_ids' => $activity_id, 'show_hidden' => true, 'spam' => 'all', ) );
1355
-
1356
- /**
1357
- * If, somehow, the referenced activity has been deleted, leaving its associated
1358
- * activites as orphans, use the logged in user's ID to avoid errors.
1359
- */
1360
- if ( empty( $activity['activities'] ) )
1361
- return bp_loggedin_user_id();
1362
-
1363
- // Store the new activity/user ID mapping for any later re-use
1364
- $this->activity_user_id[ $activity['activities'][0]->id ] = $activity['activities'][0]->user_id;
1365
-
1366
- // Return the user ID
1367
- return $activity['activities'][0]->user_id;
1368
- }
1369
- }
1370
-
1371
- /**
1372
- * Helper function to flatten all activites returned from bp_activity_get() into a single array.
1373
- *
1374
- * @param array $tree Source array
1375
- * @return array Flattened array
1376
- * @since 1.6
1377
- */
1378
- public static function flatten_activity_array( $tree ){
1379
- foreach ( (array) $tree as $node ) {
1380
- if ( isset( $node->children ) ) {
1381
-
1382
- foreach ( BP_Activity_List_Table::flatten_activity_array( $node->children ) as $child ) {
1383
- $tree[] = $child;
1384
- }
1385
-
1386
- unset( $node->children );
1387
- }
1388
- }
1389
-
1390
- return $tree;
1391
- }
1392
- }
1393
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-activity/bp-activity-akismet.php DELETED
@@ -1,587 +0,0 @@
1
- <?php
2
- /**
3
- * Akismet support for BuddyPress' Activity Stream
4
- *
5
- * @package BuddyPress
6
- * @since 1.6
7
- * @subpackage Activity
8
- */
9
-
10
- // Exit if accessed directly
11
- if ( !defined( 'ABSPATH' ) ) exit;
12
-
13
- class BP_Akismet {
14
- /**
15
- * The activity last marked as spam
16
- *
17
- * @access protected
18
- * @var BP_Activity_Activity
19
- * @since 1.6
20
- */
21
- protected $last_activity = null;
22
-
23
- /**
24
- * Constructor
25
- *
26
- * @since 1.6
27
- */
28
- public function __construct() {
29
- $this->setup_actions();
30
- }
31
-
32
- /**
33
- * Hook Akismet into the activity stream
34
- *
35
- * @since 1.6
36
- */
37
- protected function setup_actions() {
38
- // Add nonces to activity stream lists
39
- add_action( 'bp_after_activity_post_form', array( $this, 'add_activity_stream_nonce' ) );
40
- add_action( 'bp_activity_entry_comments', array( $this, 'add_activity_stream_nonce' ) );
41
-
42
- // Add a "mark as spam" button to individual activity items
43
- add_action( 'bp_activity_entry_meta', array( $this, 'add_activity_spam_button' ) );
44
- add_action( 'bp_activity_comment_options', array( $this, 'add_activity_comment_spam_button' ) );
45
-
46
- // Check activity for spam
47
- add_action( 'bp_activity_before_save', array( $this, 'check_activity' ), 4, 1 );
48
-
49
- // Tidy up member's latest (activity) update
50
- add_action( 'bp_activity_posted_update', array( $this, 'check_member_activity_update' ), 1, 3 );
51
-
52
- // Hooks to extend Activity core spam/ham functions for Akismet
53
- add_action( 'bp_activity_mark_as_spam', array( $this, 'mark_as_spam' ), 10, 2 );
54
- add_action( 'bp_activity_mark_as_ham', array( $this, 'mark_as_ham' ), 10, 2 );
55
-
56
- // Hook into the Activity wp-admin screen
57
- add_action( 'bp_activity_admin_comment_row_actions', array( $this, 'comment_row_action' ), 10, 2 );
58
- add_action( 'bp_activity_admin_load', array( $this, 'add_history_metabox' ) );
59
- }
60
-
61
- /**
62
- * Add a history item to the hover links in an activity's row.
63
- *
64
- * This function lifted with love from the Akismet WordPress plugin's
65
- * akismet_comment_row_action() function. Thanks!
66
- *
67
- * @param array $actions The hover links
68
- * @param array $activity The activity for the current row being processed
69
- * @return array The hover links
70
- * @since 1.6
71
- */
72
- function comment_row_action( $actions, $activity ) {
73
- $akismet_result = bp_activity_get_meta( $activity['id'], '_bp_akismet_result' );
74
- $user_result = bp_activity_get_meta( $activity['id'], '_bp_akismet_user_result' );
75
- $desc = '';
76
-
77
- if ( !$user_result || $user_result == $akismet_result ) {
78
- // Show the original Akismet result if the user hasn't overridden it, or if their decision was the same
79
- if ( 'true' == $akismet_result && $activity['is_spam'] )
80
- $desc = __( 'Flagged as spam by Akismet', 'buddypress' );
81
-
82
- elseif ( 'false' == $akismet_result && !$activity['is_spam'] )
83
- $desc = __( 'Cleared by Akismet', 'buddypress' );
84
-
85
- } else {
86
- $who = bp_activity_get_meta( $activity['id'], '_bp_akismet_user' );
87
-
88
- if ( 'true' == $user_result )
89
- $desc = sprintf( __( 'Flagged as spam by %s', 'buddypress' ), $who );
90
- else
91
- $desc = sprintf( __( 'Un-spammed by %s', 'buddypress' ), $who );
92
- }
93
-
94
- // add a History item to the hover links, just after Edit
95
- if ( $akismet_result ) {
96
- $b = array();
97
- foreach ( $actions as $k => $item ) {
98
- $b[ $k ] = $item;
99
- if ( $k == 'edit' )
100
- $b['history'] = '<a href="' . network_admin_url( 'admin.php?page=bp-activity&amp;action=edit&aid=' . $activity['id'] ) . '#bp_activity_history"> '. __( 'History', 'buddypress' ) . '</a>';
101
- }
102
-
103
- $actions = $b;
104
- }
105
-
106
- if ( $desc )
107
- echo '<span class="akismet-status"><a href="' . network_admin_url( 'admin.php?page=bp-activity&amp;action=edit&aid=' . $activity['id'] ) . '#bp_activity_history">' . htmlspecialchars( $desc ) . '</a></span>';
108
-
109
- return apply_filters( 'bp_akismet_comment_row_action', $actions );
110
- }
111
-
112
- /**
113
- * Adds a nonce to the member profile status form, and to the reply form of each activity stream item.
114
- * This is used by Akismet to help detect spam activity.
115
- *
116
- * @see http://plugins.trac.wordpress.org/ticket/1232
117
- * @since 1.6
118
- */
119
- public function add_activity_stream_nonce() {
120
- $form_id = '_bp_as_nonce';
121
- $value = '_bp_as_nonce_' . bp_loggedin_user_id();
122
-
123
- // If we're in the activity stream loop, we can use the current item's ID to make the nonce unique
124
- if ( 'bp_activity_entry_comments' == current_filter() ) {
125
- $form_id .= '_' . bp_get_activity_id();
126
- $value .= '_' . bp_get_activity_id();
127
- }
128
-
129
- wp_nonce_field( $value, $form_id, false );
130
- }
131
-
132
- /**
133
- * Check the member's latest (activity) update to see if it's the item that was (just) marked as spam.
134
- *
135
- * This can't be done in BP_Akismet::check_activity() due to BP-Default's AJAX implementation; see bp_dtheme_post_update().
136
- *
137
- * @param string $content Activity update text
138
- * @param int $user_id User ID
139
- * @param int $activity_id Activity ID
140
- * @see bp_dtheme_post_update()
141
- * @since 1.6
142
- */
143
- public function check_member_activity_update( $content, $user_id, $activity_id ) {
144
- // By default, only handle activity updates and activity comments.
145
- if ( empty( $this->last_activity ) || !in_array( $this->last_activity->type, BP_Akismet::get_activity_types() ) )
146
- return;
147
-
148
- // Was this $activity_id just marked as spam? If not, bail out.
149
- if ( !$this->last_activity->id || $activity_id != $this->last_activity->id || 'false' == $this->last_activity->akismet_submission['bp_as_result'] )
150
- return;
151
-
152
- // It was, so delete the member's latest activity update.
153
- bp_delete_user_meta( $user_id, 'bp_latest_update' );
154
- }
155
-
156
- /**
157
- * Adds a "mark as spam" button to each activity item for site admins.
158
- *
159
- * This function is intended to be used inside the activity stream loop.
160
- *
161
- * @since 1.6
162
- */
163
- public function add_activity_spam_button() {
164
- if ( !bp_activity_user_can_mark_spam() )
165
- return;
166
-
167
- // By default, only handle activity updates and activity comments.
168
- if ( !in_array( bp_get_activity_type(), BP_Akismet::get_activity_types() ) )
169
- return;
170
-
171
- bp_button(
172
- array(
173
- 'block_self' => false,
174
- 'component' => 'activity',
175
- 'id' => 'activity_make_spam_' . bp_get_activity_id(),
176
- 'link_class' => 'bp-secondary-action spam-activity confirm button item-button',
177
- 'link_href' => wp_nonce_url( bp_get_root_domain() . '/' . bp_get_activity_slug() . '/spam/' . bp_get_activity_id() . '/', 'bp_activity_akismet_spam_' . bp_get_activity_id() ),
178
- 'link_text' => __( 'Spam', 'buddypress' ),
179
- 'wrapper' => false,
180
- )
181
- );
182
- }
183
-
184
- /**
185
- * Adds a "mark as spam" button to each activity COMMENT item for site admins.
186
- *
187
- * This function is intended to be used inside the activity stream loop.
188
- *
189
- * @since 1.6
190
- */
191
- public function add_activity_comment_spam_button() {
192
- if ( !bp_activity_user_can_mark_spam() )
193
- return;
194
-
195
- // By default, only handle activity updates and activity comments.
196
- $current_comment = bp_activity_current_comment();
197
- if ( empty( $current_comment ) || !in_array( $current_comment->type, BP_Akismet::get_activity_types() ) )
198
- return;
199
-
200
- bp_button(
201
- array(
202
- 'block_self' => false,
203
- 'component' => 'activity',
204
- 'id' => 'activity_make_spam_' . bp_get_activity_comment_id(),
205
- 'link_class' => 'bp-secondary-action spam-activity-comment confirm',
206
- 'link_href' => wp_nonce_url( bp_get_root_domain() . '/' . bp_get_activity_slug() . '/spam/' . bp_get_activity_comment_id() . '/?cid=' . bp_get_activity_comment_id(), 'bp_activity_akismet_spam_' . bp_get_activity_comment_id() ),
207
- 'link_text' => __( 'Spam', 'buddypress' ),
208
- 'wrapper' => false,
209
- )
210
- );
211
- }
212
-
213
- /**
214
- * Get a list of filterable types of activity item that we want Akismet to automatically check for spam.
215
- *
216
- * @return array List of activity types
217
- * @since 1.6
218
- * @static
219
- */
220
- public static function get_activity_types() {
221
- return apply_filters( 'bp_akismet_get_activity_types', array( 'activity_comment', 'activity_update' ) );
222
- }
223
-
224
- /**
225
- * Mark activity item as spam
226
- *
227
- * @param BP_Activity_Activity $activity
228
- * @param string $source Either "by_a_person" (e.g. a person has manually marked the activity as spam) or "by_akismet" (automatically spammed).
229
- * @since 1.6
230
- */
231
- public function mark_as_spam( $activity, $source ) {
232
- // Record this item so we can do some tidyup in BP_Akismet::check_member_activity_update()
233
- $this->last_activity = $activity;
234
-
235
- do_action( 'bp_activity_akismet_mark_as_spam', $activity, $source );
236
- }
237
-
238
- /**
239
- * Mark activity item as ham
240
- *
241
- * @param BP_Activity_Activity $activity
242
- * @param string $source Either "by_a_person" (e.g. a person has manually marked the activity as ham) or "by_akismet" (automatically hammed).
243
- * @since 1.6
244
- */
245
- public function mark_as_ham( $activity, $source ) {
246
- // If the activity was, originally, automatically marked as spam by Akismet, run the @mentions filter as it would have been skipped.
247
- if ( 'true' == bp_activity_get_meta( $activity->id, '_bp_akismet_result' ) && !bp_activity_get_meta( $activity->id, '_bp_akismet_user_result' ) )
248
- $activity->content = bp_activity_at_name_filter( $activity->content, $activity->id );
249
-
250
- do_action( 'bp_activity_akismet_mark_as_ham', $activity, $source );
251
- }
252
-
253
- /**
254
- * Build a data package for the Akismet service to inspect
255
- *
256
- * @param BP_Activity_Activity $activity
257
- * @see http://akismet.com/development/api/#comment-check
258
- * @since 1.6
259
- * @static
260
- */
261
- public static function build_akismet_data_package( $activity ) {
262
- $userdata = get_userdata( $activity->user_id );
263
-
264
- $activity_data = array();
265
- $activity_data['akismet_comment_nonce'] = 'inactive';
266
- $activity_data['comment_author'] = $userdata->display_name;
267
- $activity_data['comment_author_email'] = $userdata->user_email;
268
- $activity_data['comment_author_url'] = bp_core_get_userlink( $userdata->ID, false, true);
269
- $activity_data['comment_content'] = $activity->content;
270
- $activity_data['comment_type'] = $activity->type;
271
- $activity_data['permalink'] = bp_activity_get_permalink( $activity->id, $activity );
272
- $activity_data['user_ID'] = $userdata->ID;
273
- $activity_data['user_role'] = akismet_get_user_roles( $userdata->ID );
274
-
275
- /**
276
- * Get the nonce if the new activity was submitted through the "what's up, Paul?" form.
277
- * This helps Akismet ensure that the update was a valid form submission.
278
- */
279
- if ( !empty( $_POST['_bp_as_nonce'] ) )
280
- $activity_data['akismet_comment_nonce'] = wp_verify_nonce( $_POST['_bp_as_nonce'], "_bp_as_nonce_{$userdata->ID}" ) ? 'passed' : 'failed';
281
-
282
- /**
283
- * If the new activity was a reply to an existing item, check the nonce with the activity parent ID.
284
- * This helps Akismet ensure that the update was a valid form submission.
285
- */
286
- elseif ( !empty( $activity->secondary_item_id ) && !empty( $_POST['_bp_as_nonce_' . $activity->secondary_item_id] ) )
287
- $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';
288
-
289
- return apply_filters( 'bp_akismet_build_akismet_data_package', $activity_data, $activity );
290
- }
291
-
292
- /**
293
- * Check if the activity item is spam or ham
294
- *
295
- * @param BP_Activity_Activity $activity The activity item to check
296
- * @see http://akismet.com/development/api/
297
- * @since 1.6
298
- * @todo Spam counter?
299
- * @todo Auto-delete old spam?
300
- */
301
- public function check_activity( $activity ) {
302
- // By default, only handle activity updates and activity comments.
303
- if ( !in_array( $activity->type, BP_Akismet::get_activity_types() ) )
304
- return;
305
-
306
- // Make sure last_activity is clear to avoid any confusion
307
- $this->last_activity = null;
308
-
309
- // Build data package for Akismet
310
- $activity_data = BP_Akismet::build_akismet_data_package( $activity );
311
-
312
- // Check with Akismet to see if this is spam
313
- $activity_data = $this->send_akismet_request( $activity_data, 'check', 'spam' );
314
-
315
- // Record this item
316
- $this->last_activity = $activity;
317
-
318
- // Store a copy of the data that was submitted to Akismet
319
- $this->last_activity->akismet_submission = $activity_data;
320
-
321
- // Spam
322
- if ( 'true' == $activity_data['bp_as_result'] ) {
323
- // Action for plugin authors
324
- do_action_ref_array( 'bp_activity_akismet_spam_caught', array( &$activity, $activity_data ) );
325
-
326
- // Mark as spam
327
- bp_activity_mark_as_spam( $activity, 'by_akismet' );
328
- }
329
-
330
- // Update activity meta after a spam check
331
- add_action( 'bp_activity_after_save', array( $this, 'update_activity_akismet_meta' ), 1, 1 );
332
- }
333
-
334
- /**
335
- * Update activity meta after a manual spam change (user initiated)
336
- *
337
- * @param BP_Activity_Activity $activity The activity to check
338
- * @since 1.6
339
- */
340
- public function update_activity_spam_meta( $activity ) {
341
- // By default, only handle activity updates and activity comments.
342
- if ( !in_array( $activity->type, BP_Akismet::get_activity_types() ) )
343
- return;
344
-
345
- $this->update_activity_history( $activity->id, sprintf( __( '%s reported this activity as spam', 'buddypress' ), bp_get_loggedin_user_username() ), 'report-spam' );
346
- bp_activity_update_meta( $activity->id, '_bp_akismet_user_result', 'true' );
347
- bp_activity_update_meta( $activity->id, '_bp_akismet_user', bp_get_loggedin_user_username() );
348
- }
349
-
350
- /**
351
- * Update activity meta after a manual ham change (user initiated)
352
- *
353
- * @param BP_Activity_Activity $activity The activity to check
354
- * @since 1.6
355
- */
356
- public function update_activity_ham_meta( $activity ) {
357
- // By default, only handle activity updates and activity comments.
358
- if ( !in_array( $activity->type, BP_Akismet::get_activity_types() ) )
359
- return;
360
-
361
- $this->update_activity_history( $activity->id, sprintf( __( '%s reported this activity as not spam', 'buddypress' ), bp_get_loggedin_user_username() ), 'report-ham' );
362
- bp_activity_update_meta( $activity->id, '_bp_akismet_user_result', 'false' );
363
- bp_activity_update_meta( $activity->id, '_bp_akismet_user', bp_get_loggedin_user_username() );
364
- }
365
-
366
- /**
367
- * Update activity meta after an automatic spam check (not user initiated)
368
- *
369
- * @param BP_Activity_Activity $activity The activity to check
370
- * @since 1.6
371
- */
372
- public function update_activity_akismet_meta( $activity ) {
373
- // Check we're dealing with what was last updated by Akismet
374
- if ( empty( $this->last_activity ) || !empty( $this->last_activity ) && $activity->id != $this->last_activity->id )
375
- return;
376
-
377
- // By default, only handle activity updates and activity comments.
378
- if ( !in_array( $this->last_activity->type, BP_Akismet::get_activity_types() ) )
379
- return;
380
-
381
- // Spam
382
- if ( 'true' == $this->last_activity->akismet_submission['bp_as_result'] ) {
383
- bp_activity_update_meta( $activity->id, '_bp_akismet_result', 'true' );
384
- $this->update_activity_history( $activity->id, __( 'Akismet caught this item as spam', 'buddypress' ), 'check-spam' );
385
-
386
- // Not spam
387
- } elseif ( 'false' == $this->last_activity->akismet_submission['bp_as_result'] ) {
388
- bp_activity_update_meta( $activity->id, '_bp_akismet_result', 'false' );
389
- $this->update_activity_history( $activity->id, __( 'Akismet cleared this item', 'buddypress' ), 'check-ham' );
390
-
391
- // Uh oh, something's gone horribly wrong. Unexpected result.
392
- } else {
393
- bp_activity_update_meta( $activity->id, '_bp_akismet_error', bp_core_current_time() );
394
- $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' );
395
- }
396
-
397
- // Record the original data which was submitted to Akismet for checking
398
- bp_activity_update_meta( $activity->id, '_bp_akismet_submission', $this->last_activity->akismet_submission );
399
- }
400
-
401
- /**
402
- * Contact Akismet to check if this is spam or ham
403
- *
404
- * Props to WordPress core Akismet plugin for alot of this
405
- *
406
- * @global string $akismet_api_host
407
- * @global string $akismet_api_port
408
- * @param array $activity_data Packet of information to submit to Akismet
409
- * @param string $check "check" or "submit"
410
- * @param string $spam "spam" or "ham"
411
- * @since 1.6
412
- */
413
- public function send_akismet_request( $activity_data, $check = 'check', $spam = 'spam' ) {
414
- global $akismet_api_host, $akismet_api_port;
415
-
416
- // Check that host and port are set, if not, set them
417
- if ( function_exists( 'akismet_init' ) && ( empty( $akismet_api_host ) || empty( $akismet_api_port ) ) )
418
- akismet_init();
419
-
420
- $query_string = $path = $response = '';
421
-
422
- $activity_data['blog'] = bp_get_option( 'home' );
423
- $activity_data['blog_charset'] = bp_get_option( 'blog_charset' );
424
- $activity_data['blog_lang'] = get_locale();
425
- $activity_data['referrer'] = $_SERVER['HTTP_REFERER'];
426
- $activity_data['user_agent'] = bp_core_current_user_ua();
427
- $activity_data['user_ip'] = bp_core_current_user_ip();
428
-
429
- if ( akismet_test_mode() )
430
- $activity_data['is_test'] = 'true';
431
-
432
- // Loop through _POST args and rekey strings
433
- foreach ( $_POST as $key => $value )
434
- if ( is_string( $value ) && 'cookie' != $key )
435
- $activity_data['POST_' . $key] = $value;
436
-
437
- // Keys to ignore
438
- $ignore = array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' );
439
-
440
- // Loop through _SERVER args and remove whitelisted keys
441
- foreach ( $_SERVER as $key => $value ) {
442
-
443
- // Key should not be ignored
444
- if ( !in_array( $key, $ignore ) && is_string( $value ) ) {
445
- $activity_data[$key] = $value;
446
-
447
- // Key should be ignored
448
- } else {
449
- $activity_data[$key] = '';
450
- }
451
- }
452
-
453
- foreach ( $activity_data as $key => $data )
454
- $query_string .= $key . '=' . urlencode( stripslashes( $data ) ) . '&';
455
-
456
- if ( 'check' == $check )
457
- $path = '/1.1/comment-check';
458
- elseif ( 'submit' == $check )
459
- $path = '/1.1/submit-' . $spam;
460
-
461
- // Send to Akismet
462
- add_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) );
463
- $response = akismet_http_post( $query_string, $akismet_api_host, $path, $akismet_api_port );
464
- remove_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) );
465
-
466
- // Get the response
467
- if ( ! empty( $response[1] ) && ! is_wp_error( $response[1] ) )
468
- $activity_data['bp_as_result'] = $response[1];
469
- else
470
- $activity_data['bp_as_result'] = false;
471
-
472
- // Perform a daily tidy up
473
- if ( ! wp_next_scheduled( 'bp_activity_akismet_delete_old_metadata' ) )
474
- wp_schedule_event( time(), 'daily', 'bp_activity_akismet_delete_old_metadata' );
475
-
476
- return $activity_data;
477
- }
478
-
479
- /**
480
- * Filters user agent when sending to Akismet.
481
- *
482
- * @param string $user_agent
483
- * @since 1.6
484
- */
485
- public function buddypress_ua( $user_agent ) {
486
- $user_agent = 'BuddyPress/' . bp_get_version() . ' | Akismet/'. constant( 'AKISMET_VERSION' );
487
- return $user_agent;
488
- }
489
-
490
- /**
491
- * Adds a "History" meta box to the activity edit screen.
492
- *
493
- * @param string $screen_action The type of screen that has been requested
494
- * @since 1.6
495
- */
496
- function add_history_metabox( $screen_action ) {
497
- // Only proceed if we're on the edit screen
498
- if ( 'edit' != $screen_action )
499
- return;
500
-
501
- // Display meta box with a low priority (low position on screen by default)
502
- add_meta_box( 'bp_activity_history', __( 'Activity History', 'buddypress' ), array( $this, 'history_metabox' ), get_current_screen()->id, 'normal', 'low' );
503
- }
504
-
505
- /**
506
- * History meta box for the Activity admin edit screen
507
- *
508
- * @param object $item Activity item
509
- * @since 1.6
510
- * @todo Update activity meta to allow >1 record with the same key (iterate through $history).
511
- * @see http://buddypress.trac.wordpress.org/ticket/3907
512
- */
513
- function history_metabox( $item ) {
514
- $history = BP_Akismet::get_activity_history( $item->id );
515
-
516
- if ( empty( $history ) )
517
- return;
518
-
519
- echo '<div class="akismet-history"><div>';
520
- 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] ) );
521
- echo '</div></div>';
522
- }
523
-
524
- /**
525
- * Update an activity item's Akismet history
526
- *
527
- * @param int $activity_id Activity item ID
528
- * @param string $message Human-readable description of what's changed
529
- * @param string $event The type of check we were carrying out
530
- * @since 1.6
531
- */
532
- public function update_activity_history( $activity_id = 0, $message = '', $event = '' ) {
533
- $event = array(
534
- 'event' => $event,
535
- 'message' => $message,
536
- 'time' => akismet_microtime(),
537
- 'user' => bp_loggedin_user_id(),
538
- );
539
-
540
- // Save the history data
541
- bp_activity_update_meta( $activity_id, '_bp_akismet_history', $event );
542
- }
543
-
544
- /**
545
- * Get an activity item's Akismet history
546
- *
547
- * @param int $activity_id Activity item ID
548
- * @return array The activity item's Akismet history
549
- * @since 1.6
550
- */
551
- public function get_activity_history( $activity_id = 0 ) {
552
- $history = bp_activity_get_meta( $activity_id, '_bp_akismet_history' );
553
- if ( $history === false )
554
- $history = array();
555
-
556
- // Sort it by the time recorded
557
- usort( $history, 'akismet_cmp_time' );
558
-
559
- return $history;
560
- }
561
- }
562
-
563
- /**
564
- * Deletes old spam activity meta data, as _bp_akismet_submission meta can be large.
565
- *
566
- * @global object $bp BuddyPress global settings
567
- * @global wpdb $wpdb WordPress database object
568
- * @since 1.6
569
- */
570
- function bp_activity_akismet_delete_old_metadata() {
571
- global $bp, $wpdb;
572
-
573
- $interval = apply_filters( 'bp_activity_akismet_delete_meta_interval', 15 );
574
-
575
- // Enforce a minimum of 1 day
576
- $interval = max( 1, absint( $interval ) );
577
-
578
- // _bp_akismet_submission meta values are large, so expire them after $interval days regardless of the activity status
579
- $sql = $wpdb->prepare( "SELECT a.id FROM {$bp->activity->table_name} a LEFT JOIN {$bp->activity->table_name_meta} m ON a.id = m.activity_id WHERE m.meta_key = %s AND DATE_SUB(%s, INTERVAL {$interval} DAY) > a.date_recorded LIMIT 10000", '_bp_akismet_submission', current_time( 'mysql', 1 ) );
580
- $activity_ids = $wpdb->get_col( $sql );
581
-
582
- if ( ! empty( $activity_ids ) ) {
583
- foreach ( $activity_ids as $activity_id )
584
- bp_activity_delete_meta( $activity_id, '_bp_akismet_submission' );
585
- }
586
- }
587
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-activity/bp-activity-cache.php DELETED
@@ -1,39 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Functions related to the BuddyPress Activity component and the WP Cache
5
- *
6
- * @since 1.6
7
- */
8
-
9
- // Exit if accessed directly
10
- if ( !defined( 'ABSPATH' ) ) exit;
11
-
12
- /**
13
- * Slurps up activitymeta
14
- *
15
- * This function is called in two places in the BP_Groups_Group class:
16
- * - in the populate() method, when single group objects are populated
17
- * - in the get() method, when multiple groups are queried
18
- *
19
- * It grabs all groupmeta associated with all of the groups passed in $group_ids and adds it to
20
- * the WP cache. This improves efficiency when using groupmeta inline
21
- *
22
- * @param int|str|array $group_ids Accepts a single group_id, or a comma-separated list or array of
23
- * group ids
24
- */
25
- function bp_activity_update_meta_cache( $activity_ids = false ) {
26
- global $bp;
27
-
28
- $cache_args = array(
29
- 'object_ids' => $activity_ids,
30
- 'object_type' => $bp->activity->id,
31
- 'object_column' => 'activity_id',
32
- 'meta_table' => $bp->activity->table_name_meta,
33
- 'cache_key_prefix' => 'bp_activity_meta'
34
- );
35
-
36
- bp_update_meta_cache( $cache_args );
37
- }
38
-
39
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-activity/bp-activity-classes.php CHANGED
@@ -1,15 +1,16 @@
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
- class BP_Activity_Activity {
13
  var $id;
14
  var $item_id;
15
  var $secondary_item_id;
@@ -23,9 +24,14 @@ class BP_Activity_Activity {
23
  var $hide_sitewide = false;
24
  var $mptt_left;
25
  var $mptt_right;
26
- var $is_spam;
 
 
 
27
 
28
  function __construct( $id = false ) {
 
 
29
  if ( !empty( $id ) ) {
30
  $this->id = $id;
31
  $this->populate();
@@ -49,9 +55,6 @@ class BP_Activity_Activity {
49
  $this->hide_sitewide = $row->hide_sitewide;
50
  $this->mptt_left = $row->mptt_left;
51
  $this->mptt_right = $row->mptt_right;
52
- $this->is_spam = $row->is_spam;
53
-
54
- bp_activity_update_meta_cache( $this->id );
55
  }
56
  }
57
 
@@ -71,7 +74,6 @@ class BP_Activity_Activity {
71
  $this->hide_sitewide = apply_filters_ref_array( 'bp_activity_hide_sitewide_before_save', array( $this->hide_sitewide, &$this ) );
72
  $this->mptt_left = apply_filters_ref_array( 'bp_activity_mptt_left_before_save', array( $this->mptt_left, &$this ) );
73
  $this->mptt_right = apply_filters_ref_array( 'bp_activity_mptt_right_before_save', array( $this->mptt_right, &$this ) );
74
- $this->is_spam = apply_filters_ref_array( 'bp_activity_is_spam_before_save', array( $this->is_spam, &$this ) );
75
 
76
  // Use this, not the filters above
77
  do_action_ref_array( 'bp_activity_before_save', array( &$this ) );
@@ -80,25 +82,20 @@ class BP_Activity_Activity {
80
  return false;
81
 
82
  if ( !$this->primary_link )
83
- $this->primary_link = bp_loggedin_user_domain();
84
 
85
  // If we have an existing ID, update the activity item, otherwise insert it.
86
  if ( $this->id )
87
- $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 = %s, secondary_item_id = %s, 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 );
88
  else
89
- $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, %s, %s, %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 );
90
 
91
- if ( false === $wpdb->query( $q ) )
92
  return false;
93
 
94
- // If this is a new activity item, set the $id property
95
  if ( empty( $this->id ) )
96
  $this->id = $wpdb->insert_id;
97
 
98
- // If an existing activity item, prevent any changes to the content generating new @mention notifications.
99
- else
100
- add_filter( 'bp_activity_at_name_do_notifications', '__return_false' );
101
-
102
  do_action_ref_array( 'bp_activity_after_save', array( &$this ) );
103
 
104
  return true;
@@ -106,53 +103,9 @@ class BP_Activity_Activity {
106
 
107
  // Static Functions
108
 
109
- /**
110
- * Get activity items, as specified by parameters
111
- *
112
- * @param array $args See $defaults for explanation of arguments
113
- * @return array
114
- */
115
- function get( $args = array() ) {
116
  global $wpdb, $bp;
117
 
118
- // Backward compatibility with old method of passing arguments
119
- if ( !is_array( $args ) || func_num_args() > 1 ) {
120
- _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__ ) );
121
-
122
- $old_args_keys = array(
123
- 0 => 'max',
124
- 1 => 'page',
125
- 2 => 'per_page',
126
- 3 => 'sort',
127
- 4 => 'search_terms',
128
- 5 => 'filter',
129
- 6 => 'display_comments',
130
- 7 => 'show_hidden',
131
- 8 => 'exclude',
132
- 9 => 'in',
133
- 10 => 'spam'
134
- );
135
-
136
- $func_args = func_get_args();
137
- $args = bp_core_parse_args_array( $old_args_keys, $func_args );
138
- }
139
-
140
- $defaults = array(
141
- 'page' => 1, // The current page
142
- 'per_page' => 25, // Activity items per page
143
- 'max' => false, // Max number of items to return
144
- 'sort' => 'DESC', // ASC or DESC
145
- 'exclude' => false, // Array of ids to exclude
146
- 'in' => false, // Array of ids to limit query by (IN)
147
- 'filter' => false, // See self::get_filter_sql()
148
- 'search_terms' => false, // Terms to search by
149
- 'display_comments' => false, // Whether to include activity comments
150
- 'show_hidden' => false, // Show items marked hide_sitewide
151
- 'spam' => 'ham_only', // Spam status
152
- );
153
- $r = wp_parse_args( $args, $defaults );
154
- extract( $r );
155
-
156
  // Select conditions
157
  $select_sql = "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name";
158
 
@@ -161,12 +114,6 @@ class BP_Activity_Activity {
161
  // Where conditions
162
  $where_conditions = array();
163
 
164
- // Spam
165
- if ( 'ham_only' == $spam )
166
- $where_conditions['spam_sql'] = 'a.is_spam = 0';
167
- elseif ( 'spam_only' == $spam )
168
- $where_conditions['spam_sql'] = 'a.is_spam = 1';
169
-
170
  // Searching
171
  if ( $search_terms ) {
172
  $search_terms = $wpdb->escape( $search_terms );
@@ -205,53 +152,36 @@ class BP_Activity_Activity {
205
 
206
  $where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
207
 
208
- // Define the preferred order for indexes
209
- $indexes = apply_filters( 'bp_activity_preferred_index_order', array( 'user_id', 'item_id', 'secondary_item_id', 'date_recorded', 'component', 'type', 'hide_sitewide', 'is_spam' ) );
210
-
211
- foreach( $indexes as $key => $index ) {
212
- if ( false !== strpos( $where_sql, $index ) ) {
213
- $the_index = $index;
214
- break; // Take the first one we find
215
- }
216
- }
217
-
218
- if ( !empty( $the_index ) ) {
219
- $index_hint_sql = $wpdb->prepare( "USE INDEX ({$the_index})" );
220
- } else {
221
- $index_hint_sql = '';
222
- }
223
-
224
  if ( !empty( $per_page ) && !empty( $page ) ) {
225
 
226
  // Make sure page values are absolute integers
227
  $page = absint( $page );
228
  $per_page = absint( $per_page );
229
 
230
- $pag_sql = $wpdb->prepare( "LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page );
231
  $activities = $wpdb->get_results( apply_filters( 'bp_activity_get_user_join_filter', $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}" ), $select_sql, $from_sql, $where_sql, $sort, $pag_sql ) );
232
  } else {
233
  $activities = $wpdb->get_results( apply_filters( 'bp_activity_get_user_join_filter', $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort}" ), $select_sql, $from_sql, $where_sql, $sort ) );
234
  }
235
 
236
- $total_activities_sql = apply_filters( 'bp_activity_total_activities_sql', $wpdb->prepare( "SELECT count(a.id) FROM {$bp->activity->table_name} a {$index_hint_sql} {$where_sql} ORDER BY a.date_recorded {$sort}" ), $where_sql, $sort );
237
 
238
  $total_activities = $wpdb->get_var( $total_activities_sql );
239
 
240
  // Get the fullnames of users so we don't have to query in the loop
241
- $activity_user_ids = array();
242
  if ( bp_is_active( 'xprofile' ) && $activities ) {
243
- foreach ( (array) $activities as $activity ) {
244
- if ( (int) $activity->user_id )
245
  $activity_user_ids[] = $activity->user_id;
246
  }
247
 
248
- $activity_user_ids = implode( ',', array_unique( (array) $activity_user_ids ) );
249
  if ( !empty( $activity_user_ids ) ) {
250
  if ( $names = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, value AS user_fullname FROM {$bp->profile->table_name_data} WHERE field_id = 1 AND user_id IN ({$activity_user_ids})" ) ) ) {
251
- foreach ( (array) $names as $name )
252
  $tmp_names[$name->user_id] = $name->user_fullname;
253
 
254
- foreach ( (array) $activities as $i => $activity ) {
255
  if ( !empty( $tmp_names[$activity->user_id] ) )
256
  $activities[$i]->user_fullname = $tmp_names[$activity->user_id];
257
  }
@@ -261,35 +191,25 @@ class BP_Activity_Activity {
261
  }
262
  }
263
  }
264
-
265
- // Get activity meta
266
- $activity_ids = array();
267
- foreach ( (array) $activities as $activity ) {
268
- $activity_ids[] = $activity->id;
269
- }
270
-
271
- if ( !empty( $activity_ids ) ) {
272
- bp_activity_update_meta_cache( $activity_ids );
273
- }
274
 
275
  if ( $activities && $display_comments )
276
- $activities = BP_Activity_Activity::append_comments( $activities, $spam );
277
 
278
  // If $max is set, only return up to the max results
279
  if ( !empty( $max ) ) {
280
- if ( (int) $total_activities > (int) $max )
281
  $total_activities = $max;
282
  }
283
 
284
- return array( 'activities' => $activities, 'total' => (int) $total_activities );
285
  }
286
 
287
  /**
288
  * In BuddyPress 1.2.x, this was used to retrieve specific activity stream items (for example, on an activity's permalink page).
289
- * As of 1.5.x, use BP_Activity_Activity::get() with an 'in' parameter instead.
290
  *
291
  * @deprecated 1.5
292
- * @deprecated Use BP_Activity_Activity::get() with an 'in' parameter instead.
293
  * @param mixed $activity_ids Array or comma-separated string of activity IDs to retrieve
294
  * @param int $max Maximum number of results to return. (Optional; default is no maximum)
295
  * @param int $page The set of results that the user is viewing. Used in pagination. (Optional; default is 1)
@@ -300,7 +220,7 @@ class BP_Activity_Activity {
300
  * @since 1.2
301
  */
302
  function get_specific( $activity_ids, $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $display_comments = false ) {
303
- _deprecated_function( __FUNCTION__, '1.5', 'Use BP_Activity_Activity::get() with the "in" parameter instead.' );
304
  return BP_Activity_Activity::get( $max, $page, $per_page, $sort, false, false, $display_comments, false, false, $activity_ids );
305
  }
306
 
@@ -438,47 +358,26 @@ class BP_Activity_Activity {
438
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id IN ({$activity_ids})" ) );
439
  }
440
 
441
- /**
442
- * Append activity comments to their associated activity items
443
- *
444
- * @global wpdb $wpdb WordPress database object
445
- * @param array $activities
446
- * @param bool $spam Optional; 'ham_only' (default), 'spam_only' or 'all'.
447
- * @return array The updated activities with nested comments
448
- * @since 1.2
449
- */
450
- function append_comments( $activities, $spam = 'ham_only' ) {
451
- global $wpdb;
452
 
453
  $activity_comments = array();
454
 
455
  /* Now fetch the activity comments and parse them into the correct position in the activities array. */
456
- foreach( (array) $activities as $activity ) {
457
  if ( 'activity_comment' != $activity->type && $activity->mptt_left && $activity->mptt_right )
458
- $activity_comments[$activity->id] = BP_Activity_Activity::get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right, $spam );
459
  }
460
 
461
  /* Merge the comments with the activity items */
462
- foreach( (array) $activities as $key => $activity )
463
  if ( isset( $activity_comments[$activity->id] ) )
464
  $activities[$key]->children = $activity_comments[$activity->id];
465
 
466
  return $activities;
467
  }
468
 
469
- /**
470
- * Get activity comments that are associated with a specific activity ID
471
- *
472
- * @global BuddyPress $bp The one true BuddyPress instance
473
- * @global wpdb $wpdb WordPress database object
474
- * @param int $activity_id Activity ID to fetch comments for
475
- * @param int $left Left-most node boundary
476
- * @param into $right Right-most node boundary
477
- * @param bool $spam Optional; 'ham_only' (default), 'spam_only' or 'all'.
478
- * @return array The updated activities with nested comments
479
- * @since 1.2
480
- */
481
- function get_activity_comments( $activity_id, $left, $right, $spam = 'ham_only' ) {
482
  global $wpdb, $bp;
483
 
484
  if ( !$comments = wp_cache_get( 'bp_activity_comments_' . $activity_id ) ) {
@@ -493,21 +392,11 @@ class BP_Activity_Activity {
493
  $fullname_select = $fullname_from = $fullname_where = '';
494
  }
495
 
496
- // Don't retrieve activity comments marked as spam
497
- if ( 'ham_only' == $spam )
498
- $spam_sql = 'AND a.is_spam = 0';
499
- elseif ( 'spam_only' == $spam )
500
- $spam_sql = 'AND a.is_spam = 1';
501
- else
502
- $spam_sql = '';
503
-
504
- $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 BETWEEN %d AND %d ORDER BY a.date_recorded ASC", $activity_id, $left, $right ), $activity_id, $left, $right, $spam_sql );
505
-
506
  // Retrieve all descendants of the $root node
507
- $descendants = $wpdb->get_results( $sql );
508
 
509
  // Loop descendants and build an assoc array
510
- foreach ( (array) $descendants as $d ) {
511
  $d->children = array();
512
 
513
  // If we have a reference on the parent
@@ -537,7 +426,7 @@ class BP_Activity_Activity {
537
  $descendants = BP_Activity_Activity::get_child_comments( $parent_id );
538
 
539
  // Loop the descendants and recalculate the left and right values
540
- foreach ( (array) $descendants as $descendant )
541
  $right = BP_Activity_Activity::rebuild_activity_comment_tree( $descendant->id, $right );
542
 
543
  // We've got the left value, and now that we've processed the children
@@ -564,17 +453,17 @@ class BP_Activity_Activity {
564
  }
565
 
566
  function get_sitewide_items_for_feed( $limit = 35 ) {
567
- global $bp;
568
 
569
- $activities = bp_activity_get_sitewide( array( 'max' => $limit ) );
570
- $activity_feed = array();
571
 
572
  for ( $i = 0, $count = count( $activities ); $i < $count; ++$i ) {
573
- $title = explode( '<span', $activities[$i]['content'] );
574
- $activity_feed[$i]['title'] = trim( strip_tags( $title[0] ) );
575
- $activity_feed[$i]['link'] = $activities[$i]['primary_link'];
 
576
  $activity_feed[$i]['description'] = @sprintf( $activities[$i]['content'], '' );
577
- $activity_feed[$i]['pubdate'] = $activities[$i]['date_recorded'];
578
  }
579
 
580
  return $activity_feed;
@@ -605,8 +494,7 @@ class BP_Activity_Activity {
605
  }
606
 
607
  function get_filter_sql( $filter_array ) {
608
-
609
- $filter_sql = array();
610
 
611
  if ( !empty( $filter_array['user_id'] ) ) {
612
  $user_sql = BP_Activity_Activity::get_in_operator_sql( 'a.user_id', $filter_array['user_id'] );
@@ -638,7 +526,7 @@ class BP_Activity_Activity {
638
  $filter_sql[] = $sid_sql;
639
  }
640
 
641
- if ( empty( $filter_sql ) )
642
  return false;
643
 
644
  return join( ' AND ', $filter_sql );
1
  <?php
2
+
3
  /**
4
  * BuddyPress Activity Classes
5
  *
6
  * @package BuddyPress
7
+ * @subpackage ActivityClasses
8
  */
9
 
10
  // Exit if accessed directly
11
  if ( !defined( 'ABSPATH' ) ) exit;
12
 
13
+ Class BP_Activity_Activity {
14
  var $id;
15
  var $item_id;
16
  var $secondary_item_id;
24
  var $hide_sitewide = false;
25
  var $mptt_left;
26
  var $mptt_right;
27
+
28
+ function bp_activity_activity( $id = false ) {
29
+ $this->__construct( $id );
30
+ }
31
 
32
  function __construct( $id = false ) {
33
+ global $bp;
34
+
35
  if ( !empty( $id ) ) {
36
  $this->id = $id;
37
  $this->populate();
55
  $this->hide_sitewide = $row->hide_sitewide;
56
  $this->mptt_left = $row->mptt_left;
57
  $this->mptt_right = $row->mptt_right;
 
 
 
58
  }
59
  }
60
 
74
  $this->hide_sitewide = apply_filters_ref_array( 'bp_activity_hide_sitewide_before_save', array( $this->hide_sitewide, &$this ) );
75
  $this->mptt_left = apply_filters_ref_array( 'bp_activity_mptt_left_before_save', array( $this->mptt_left, &$this ) );
76
  $this->mptt_right = apply_filters_ref_array( 'bp_activity_mptt_right_before_save', array( $this->mptt_right, &$this ) );
 
77
 
78
  // Use this, not the filters above
79
  do_action_ref_array( 'bp_activity_before_save', array( &$this ) );
82
  return false;
83
 
84
  if ( !$this->primary_link )
85
+ $this->primary_link = $bp->loggedin_user->domain;
86
 
87
  // If we have an existing ID, update the activity item, otherwise insert it.
88
  if ( $this->id )
89
+ $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 = %s, secondary_item_id = %s, hide_sitewide = %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->id );
90
  else
91
+ $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 ) VALUES ( %d, %s, %s, %s, %s, %s, %s, %s, %s, %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 );
92
 
93
+ if ( !$wpdb->query( $q ) )
94
  return false;
95
 
 
96
  if ( empty( $this->id ) )
97
  $this->id = $wpdb->insert_id;
98
 
 
 
 
 
99
  do_action_ref_array( 'bp_activity_after_save', array( &$this ) );
100
 
101
  return true;
103
 
104
  // Static Functions
105
 
106
+ function get( $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false, $exclude = false, $in = false ) {
 
 
 
 
 
 
107
  global $wpdb, $bp;
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  // Select conditions
110
  $select_sql = "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name";
111
 
114
  // Where conditions
115
  $where_conditions = array();
116
 
 
 
 
 
 
 
117
  // Searching
118
  if ( $search_terms ) {
119
  $search_terms = $wpdb->escape( $search_terms );
152
 
153
  $where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
154
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  if ( !empty( $per_page ) && !empty( $page ) ) {
156
 
157
  // Make sure page values are absolute integers
158
  $page = absint( $page );
159
  $per_page = absint( $per_page );
160
 
161
+ $pag_sql = $wpdb->prepare( "LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page );
162
  $activities = $wpdb->get_results( apply_filters( 'bp_activity_get_user_join_filter', $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}" ), $select_sql, $from_sql, $where_sql, $sort, $pag_sql ) );
163
  } else {
164
  $activities = $wpdb->get_results( apply_filters( 'bp_activity_get_user_join_filter', $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort}" ), $select_sql, $from_sql, $where_sql, $sort ) );
165
  }
166
 
167
+ $total_activities_sql = apply_filters( 'bp_activity_total_activities_sql', $wpdb->prepare( "SELECT count(a.id) FROM {$bp->activity->table_name} a {$where_sql} ORDER BY a.date_recorded {$sort}" ), $where_sql, $sort );
168
 
169
  $total_activities = $wpdb->get_var( $total_activities_sql );
170
 
171
  // Get the fullnames of users so we don't have to query in the loop
 
172
  if ( bp_is_active( 'xprofile' ) && $activities ) {
173
+ foreach ( (array)$activities as $activity ) {
174
+ if ( (int)$activity->user_id )
175
  $activity_user_ids[] = $activity->user_id;
176
  }
177
 
178
+ $activity_user_ids = implode( ',', array_unique( (array)$activity_user_ids ) );
179
  if ( !empty( $activity_user_ids ) ) {
180
  if ( $names = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, value AS user_fullname FROM {$bp->profile->table_name_data} WHERE field_id = 1 AND user_id IN ({$activity_user_ids})" ) ) ) {
181
+ foreach ( (array)$names as $name )
182
  $tmp_names[$name->user_id] = $name->user_fullname;
183
 
184
+ foreach ( (array)$activities as $i => $activity ) {
185
  if ( !empty( $tmp_names[$activity->user_id] ) )
186
  $activities[$i]->user_fullname = $tmp_names[$activity->user_id];
187
  }
191
  }
192
  }
193
  }
 
 
 
 
 
 
 
 
 
 
194
 
195
  if ( $activities && $display_comments )
196
+ $activities = BP_Activity_Activity::append_comments( $activities );
197
 
198
  // If $max is set, only return up to the max results
199
  if ( !empty( $max ) ) {
200
+ if ( (int)$total_activities > (int)$max )
201
  $total_activities = $max;
202
  }
203
 
204
+ return array( 'activities' => $activities, 'total' => (int)$total_activities );
205
  }
206
 
207
  /**
208
  * In BuddyPress 1.2.x, this was used to retrieve specific activity stream items (for example, on an activity's permalink page).
209
+ * As of 1.5.x, use BP_Activity_Activity::get( ..., $in ) instead.
210
  *
211
  * @deprecated 1.5
212
+ * @deprecated Use BP_Activity_Activity::get( ..., $in ) instead.
213
  * @param mixed $activity_ids Array or comma-separated string of activity IDs to retrieve
214
  * @param int $max Maximum number of results to return. (Optional; default is no maximum)
215
  * @param int $page The set of results that the user is viewing. Used in pagination. (Optional; default is 1)
220
  * @since 1.2
221
  */
222
  function get_specific( $activity_ids, $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $display_comments = false ) {
223
+ _deprecated_function( __FUNCTION__, '1.5', 'Use BP_Activity_Activity::get( ..., $in ) instead.' );
224
  return BP_Activity_Activity::get( $max, $page, $per_page, $sort, false, false, $display_comments, false, false, $activity_ids );
225
  }
226
 
358
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id IN ({$activity_ids})" ) );
359
  }
360
 
361
+ function append_comments( $activities ) {
362
+ global $bp, $wpdb;
 
 
 
 
 
 
 
 
 
363
 
364
  $activity_comments = array();
365
 
366
  /* Now fetch the activity comments and parse them into the correct position in the activities array. */
367
+ foreach( (array)$activities as $activity ) {
368
  if ( 'activity_comment' != $activity->type && $activity->mptt_left && $activity->mptt_right )
369
+ $activity_comments[$activity->id] = BP_Activity_Activity::get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right );
370
  }
371
 
372
  /* Merge the comments with the activity items */
373
+ foreach( (array)$activities as $key => $activity )
374
  if ( isset( $activity_comments[$activity->id] ) )
375
  $activities[$key]->children = $activity_comments[$activity->id];
376
 
377
  return $activities;
378
  }
379
 
380
+ function get_activity_comments( $activity_id, $left, $right ) {
 
 
 
 
 
 
 
 
 
 
 
 
381
  global $wpdb, $bp;
382
 
383
  if ( !$comments = wp_cache_get( 'bp_activity_comments_' . $activity_id ) ) {
392
  $fullname_select = $fullname_from = $fullname_where = '';
393
  }
394
 
 
 
 
 
 
 
 
 
 
 
395
  // Retrieve all descendants of the $root node
396
+ $descendants = $wpdb->get_results( 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' AND a.item_id = %d AND a.mptt_left BETWEEN %d AND %d ORDER BY a.date_recorded ASC", $activity_id, $left, $right ), $activity_id, $left, $right ) );
397
 
398
  // Loop descendants and build an assoc array
399
+ foreach ( (array)$descendants as $d ) {
400
  $d->children = array();
401
 
402
  // If we have a reference on the parent
426
  $descendants = BP_Activity_Activity::get_child_comments( $parent_id );
427
 
428
  // Loop the descendants and recalculate the left and right values
429
+ foreach ( (array)$descendants as $descendant )
430
  $right = BP_Activity_Activity::rebuild_activity_comment_tree( $descendant->id, $right );
431
 
432
  // We've got the left value, and now that we've processed the children
453
  }
454
 
455
  function get_sitewide_items_for_feed( $limit = 35 ) {
456
+ global $wpdb, $bp;
457
 
458
+ $activities = bp_activity_get_sitewide( array( 'max' => $limit ) );
 
459
 
460
  for ( $i = 0, $count = count( $activities ); $i < $count; ++$i ) {
461
+ $title = explode( '<span', $activities[$i]['content'] );
462
+
463
+ $activity_feed[$i]['title'] = trim( strip_tags( $title[0] ) );
464
+ $activity_feed[$i]['link'] = $activities[$i]['primary_link'];
465
  $activity_feed[$i]['description'] = @sprintf( $activities[$i]['content'], '' );
466
+ $activity_feed[$i]['pubdate'] = $activities[$i]['date_recorded'];
467
  }
468
 
469
  return $activity_feed;
494
  }
495
 
496
  function get_filter_sql( $filter_array ) {
497
+ global $wpdb;
 
498
 
499
  if ( !empty( $filter_array['user_id'] ) ) {
500
  $user_sql = BP_Activity_Activity::get_in_operator_sql( 'a.user_id', $filter_array['user_id'] );
526
  $filter_sql[] = $sid_sql;
527
  }
528
 
529
+ if ( empty($filter_sql) )
530
  return false;
531
 
532
  return join( ' AND ', $filter_sql );
bp-activity/bp-activity-filters.php CHANGED
@@ -10,8 +10,6 @@
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 );
@@ -22,7 +20,6 @@ add_filter( 'bp_get_activity_latest_update_excerpt', 'bp_activity_filter_kses',
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' );
@@ -76,8 +73,6 @@ add_filter( 'bp_get_activity_latest_update', 'stripslashes_deep' );
76
  add_filter( 'bp_get_activity_latest_update_excerpt', 'stripslashes_deep' );
77
  add_filter( 'bp_get_activity_feed_item_description', 'stripslashes_deep' );
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' );
@@ -89,78 +84,13 @@ add_filter( 'bp_get_activity_feed_item_description', 'bp_activity_make_nofollow_
89
  add_filter( 'pre_comment_content', 'bp_activity_at_name_filter' );
90
  add_filter( 'group_forum_topic_text_before_save', 'bp_activity_at_name_filter' );
91
  add_filter( 'group_forum_post_text_before_save', 'bp_activity_at_name_filter' );
92
- add_filter( 'the_content', 'bp_activity_at_name_filter' );
93
 
94
  add_filter( 'bp_get_activity_parent_content', 'bp_create_excerpt' );
95
 
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_after_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
-
108
- /** Functions *****************************************************************/
109
-
110
- /**
111
- * Types of activity stream items to check against
112
- *
113
- * @since BuddyPress (1.6)
114
- */
115
- function bp_activity_get_moderated_activity_types() {
116
- $types = array(
117
- 'activity_comment',
118
- 'activity_update'
119
- );
120
- return apply_filters( 'bp_activity_check_activity_types', $types );
121
- }
122
-
123
- /**
124
- * Check activity stream for moderation keys
125
- *
126
- * @since BuddyPress (1.6)
127
- * @param BP_Activity_Activity $activity
128
- * @return If activity type is not an update or comment
129
- */
130
- function bp_activity_check_moderation_keys( $activity ) {
131
-
132
- // Only check specific types of activity updates
133
- if ( !in_array( $activity->type, bp_activity_get_moderated_activity_types() ) )
134
- return;
135
-
136
- // Unset the activity component so activity stream update fails
137
- // @todo This is temporary until some kind of moderation is built
138
- if ( !bp_core_check_for_moderation( $activity->user_id, '', $activity->content ) )
139
- $activity->component = false;
140
- }
141
-
142
- /**
143
- * Check activity stream for blacklisted keys
144
- *
145
- * @since BuddyPress (1.6)
146
- * @param BP_Activity_Activity $activity
147
- * @return If activity type is not an update or comment
148
- */
149
- function bp_activity_check_blacklist_keys( $activity ) {
150
-
151
- // Only check specific types of activity updates
152
- if ( ! in_array( $activity->type, bp_activity_get_moderated_activity_types() ) )
153
- return;
154
-
155
- // Mark as spam
156
- if ( ! bp_core_check_for_blacklist( $activity->user_id, '', $activity->content ) )
157
- bp_activity_mark_as_spam( $activity, 'by_blacklist' );
158
- }
159
-
160
  /**
161
  * Custom kses filtering for activity content
162
  *
163
- * @since BuddyPress (1.1)
164
  *
165
  * @param string $content The activity content
166
  *
@@ -175,6 +105,9 @@ function bp_activity_filter_kses( $content ) {
175
  $activity_allowedtags = $allowedtags;
176
  $activity_allowedtags['span'] = array();
177
  $activity_allowedtags['span']['class'] = array();
 
 
 
178
  $activity_allowedtags['a']['class'] = array();
179
  $activity_allowedtags['a']['id'] = array();
180
  $activity_allowedtags['a']['rel'] = array();
@@ -196,7 +129,7 @@ function bp_activity_filter_kses( $content ) {
196
  /**
197
  * Finds and links @-mentioned users in the contents of activity items
198
  *
199
- * @since BuddyPress (1.2)
200
  *
201
  * @param string $content The activity content
202
  * @param int $activity_id The activity id
@@ -211,16 +144,9 @@ function bp_activity_filter_kses( $content ) {
211
  * @return string $content Content filtered for mentions
212
  */
213
  function bp_activity_at_name_filter( $content, $activity_id = 0 ) {
214
- if ( $activity_id & bp_is_active( 'activity' ) ) {
215
- $activity = new BP_Activity_Activity( $activity_id );
216
-
217
- // If this activity has been marked as spam, don't do anything. This prevents @notifications being sent.
218
- if ( !empty( $activity ) && $activity->is_spam )
219
- return $content;
220
- }
221
-
222
  $usernames = bp_activity_find_mentions( $content );
223
- foreach( (array) $usernames as $username ) {
 
224
  if ( bp_is_username_compatibility_mode() )
225
  $user_id = username_exists( $username );
226
  else
@@ -230,7 +156,7 @@ function bp_activity_at_name_filter( $content, $activity_id = 0 ) {
230
  continue;
231
 
232
  // If an activity_id is provided, we can send email and BP notifications
233
- if ( $activity_id && apply_filters( 'bp_activity_at_name_do_notifications', true ) ) {
234
  bp_activity_at_message_notification( $activity_id, $user_id );
235
  }
236
 
@@ -247,7 +173,7 @@ function bp_activity_at_name_filter( $content, $activity_id = 0 ) {
247
  /**
248
  * Catch mentions in saved activity items
249
  *
250
- * @since BuddyPress (1.5)
251
  *
252
  * @param obj $activity
253
  *
@@ -265,11 +191,12 @@ function bp_activity_at_name_filter_updates( $activity ) {
265
  // Resave the activity with the new content
266
  $activity->save();
267
  }
 
268
 
269
  /**
270
  * Catches links in activity text so rel=nofollow can be added
271
  *
272
- * @since BuddyPress (1.2)
273
  *
274
  * @param string $text Activity text
275
  *
@@ -282,7 +209,7 @@ function bp_activity_make_nofollow_filter( $text ) {
282
  /**
283
  * Adds rel=nofollow to a link
284
  *
285
- * @since BuddyPress (1.2)
286
  *
287
  * @param array $matches
288
  *
@@ -297,7 +224,7 @@ function bp_activity_make_nofollow_filter( $text ) {
297
  /**
298
  * Truncates long activity entries when viewed in activity streams
299
  *
300
- * @since BuddyPress (1.5)
301
  *
302
  * @param $text The original activity entry text
303
  *
@@ -326,9 +253,8 @@ function bp_activity_truncate_entry( $text ) {
326
  $excerpt = bp_create_excerpt( $text, $excerpt_length, array( 'ending' => __( '&hellip;', 'buddypress' ) ) );
327
 
328
  // If the text returned by bp_create_excerpt() is different from the original text (ie it's
329
- // been truncated), add the "Read More" link. Note that bp_create_excerpt() is stripping
330
- // shortcodes, so we have strip them from the $text before the comparison
331
- if ( $excerpt != strip_shortcodes( $text ) ) {
332
  $id = !empty( $activities_template->activity->current_comment->id ) ? 'acomment-read-more-' . $activities_template->activity->current_comment->id : 'activity-read-more-' . bp_get_activity_id();
333
 
334
  $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 );
@@ -336,5 +262,7 @@ function bp_activity_truncate_entry( $text ) {
336
 
337
  return apply_filters( 'bp_activity_truncate_entry', $excerpt, $text, $append_text );
338
  }
 
 
339
 
340
  ?>
10
  // Exit if accessed directly
11
  if ( !defined( 'ABSPATH' ) ) exit;
12
 
 
 
13
  // Apply WordPress defined filters
14
  add_filter( 'bp_get_activity_action', 'bp_activity_filter_kses', 1 );
15
  add_filter( 'bp_get_activity_content_body', 'bp_activity_filter_kses', 1 );
20
  add_filter( 'bp_get_activity_feed_item_description', 'bp_activity_filter_kses', 1 );
21
  add_filter( 'bp_activity_content_before_save', 'bp_activity_filter_kses', 1 );
22
  add_filter( 'bp_activity_action_before_save', 'bp_activity_filter_kses', 1 );
 
23
 
24
  add_filter( 'bp_get_activity_action', 'force_balance_tags' );
25
  add_filter( 'bp_get_activity_content_body', 'force_balance_tags' );
73
  add_filter( 'bp_get_activity_latest_update_excerpt', 'stripslashes_deep' );
74
  add_filter( 'bp_get_activity_feed_item_description', 'stripslashes_deep' );
75
 
 
 
76
  // Apply BuddyPress defined filters
77
  add_filter( 'bp_get_activity_content', 'bp_activity_make_nofollow_filter' );
78
  add_filter( 'bp_get_activity_content_body', 'bp_activity_make_nofollow_filter' );
84
  add_filter( 'pre_comment_content', 'bp_activity_at_name_filter' );
85
  add_filter( 'group_forum_topic_text_before_save', 'bp_activity_at_name_filter' );
86
  add_filter( 'group_forum_post_text_before_save', 'bp_activity_at_name_filter' );
 
87
 
88
  add_filter( 'bp_get_activity_parent_content', 'bp_create_excerpt' );
89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  /**
91
  * Custom kses filtering for activity content
92
  *
93
+ * @since 1.1.0
94
  *
95
  * @param string $content The activity content
96
  *
105
  $activity_allowedtags = $allowedtags;
106
  $activity_allowedtags['span'] = array();
107
  $activity_allowedtags['span']['class'] = array();
108
+ $activity_allowedtags['div'] = array();
109
+ $activity_allowedtags['div']['class'] = array();
110
+ $activity_allowedtags['div']['id'] = array();
111
  $activity_allowedtags['a']['class'] = array();
112
  $activity_allowedtags['a']['id'] = array();
113
  $activity_allowedtags['a']['rel'] = array();
129
  /**
130
  * Finds and links @-mentioned users in the contents of activity items
131
  *
132
+ * @since 1.2.0
133
  *
134
  * @param string $content The activity content
135
  * @param int $activity_id The activity id
144
  * @return string $content Content filtered for mentions
145
  */
146
  function bp_activity_at_name_filter( $content, $activity_id = 0 ) {
 
 
 
 
 
 
 
 
147
  $usernames = bp_activity_find_mentions( $content );
148
+
149
+ foreach( (array)$usernames as $username ) {
150
  if ( bp_is_username_compatibility_mode() )
151
  $user_id = username_exists( $username );
152
  else
156
  continue;
157
 
158
  // If an activity_id is provided, we can send email and BP notifications
159
+ if ( $activity_id ) {
160
  bp_activity_at_message_notification( $activity_id, $user_id );
161
  }
162
 
173
  /**
174
  * Catch mentions in saved activity items
175
  *
176
+ * @since 1.5.0
177
  *
178
  * @param obj $activity
179
  *
191
  // Resave the activity with the new content
192
  $activity->save();
193
  }
194
+ add_filter( 'bp_activity_after_save', 'bp_activity_at_name_filter_updates' );
195
 
196
  /**
197
  * Catches links in activity text so rel=nofollow can be added
198
  *
199
+ * @since 1.2.0
200
  *
201
  * @param string $text Activity text
202
  *
209
  /**
210
  * Adds rel=nofollow to a link
211
  *
212
+ * @since 1.2.0
213
  *
214
  * @param array $matches
215
  *
224
  /**
225
  * Truncates long activity entries when viewed in activity streams
226
  *
227
+ * @since 1.5.0
228
  *
229
  * @param $text The original activity entry text
230
  *
253
  $excerpt = bp_create_excerpt( $text, $excerpt_length, array( 'ending' => __( '&hellip;', 'buddypress' ) ) );
254
 
255
  // If the text returned by bp_create_excerpt() is different from the original text (ie it's
256
+ // been truncated), add the "Read More" link.
257
+ if ( $excerpt != $text ) {
 
258
  $id = !empty( $activities_template->activity->current_comment->id ) ? 'acomment-read-more-' . $activities_template->activity->current_comment->id : 'activity-read-more-' . bp_get_activity_id();
259
 
260
  $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 );
262
 
263
  return apply_filters( 'bp_activity_truncate_entry', $excerpt, $text, $append_text );
264
  }
265
+ add_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
266
+ add_filter( 'bp_get_activity_content', 'bp_activity_truncate_entry', 5 );
267
 
268
  ?>
bp-activity/bp-activity-functions.php CHANGED
@@ -15,7 +15,7 @@ if ( !defined( 'ABSPATH' ) ) exit;
15
  /**
16
  * Checks $bp pages global and looks for directory page
17
  *
18
- * @since BuddyPress (1.5)
19
  *
20
  * @global object $bp BuddyPress global settings
21
  *
@@ -30,14 +30,14 @@ function bp_activity_has_directory() {
30
  /**
31
  * Searches through the content of an activity item to locate usernames, designated by an @ sign
32
  *
33
- * @since BuddyPress (1.5)
34
  *
35
  * @param string $content The content of the activity, usually found in $activity->content
36
  *
37
  * @return bool|array $usernames Array of the found usernames that match existing users. False if no matches
38
  */
39
  function bp_activity_find_mentions( $content ) {
40
- $pattern = '/[@]+([A-Za-z0-9-_\.@]+)\b/';
41
  preg_match_all( $pattern, $content, $usernames );
42
 
43
  // Make sure there's only one instance of each username
@@ -50,7 +50,7 @@ function bp_activity_find_mentions( $content ) {
50
  /**
51
  * Resets a user's unread mentions list and count
52
  *
53
- * @since BuddyPress (1.5)
54
  *
55
  * @param int $user_id The id of the user whose unread mentions are being reset
56
  * @uses bp_delete_user_meta()
@@ -63,7 +63,7 @@ function bp_activity_clear_new_mentions( $user_id ) {
63
  /**
64
  * Adjusts new mention count for mentioned users when activity items are deleted or created
65
  *
66
- * @since BuddyPress (1.5)
67
  *
68
  * @param int $activity_id The unique id for the activity item
69
  * @param string $action Can be 'delete' or 'add'. Defaults to 'add'
@@ -79,7 +79,7 @@ function bp_activity_adjust_mention_count( $activity_id, $action = 'add' ) {
79
  $activity = new BP_Activity_Activity( $activity_id );
80
 
81
  if ( $usernames = bp_activity_find_mentions( strip_tags( $activity->content ) ) ) {
82
- foreach( (array) $usernames as $username ) {
83
  if ( bp_is_username_compatibility_mode() )
84
  $user_id = username_exists( $username );
85
  else
@@ -104,7 +104,7 @@ function bp_activity_adjust_mention_count( $activity_id, $action = 'add' ) {
104
  case 'add' :
105
  default :
106
  if ( !in_array( $activity_id, $new_mentions ) ) {
107
- $new_mentions[] = (int) $activity_id;
108
  }
109
  break;
110
  }
@@ -122,7 +122,7 @@ function bp_activity_adjust_mention_count( $activity_id, $action = 'add' ) {
122
  /**
123
  * Formats notifications related to activity
124
  *
125
- * @since BuddyPress (1.5)
126
  *
127
  * @param string $action The type of activity item. Just 'new_at_mention' for now
128
  * @param int $item_id The activity id
@@ -130,6 +130,7 @@ function bp_activity_adjust_mention_count( $activity_id, $action = 'add' ) {
130
  * @param int $total_items The total number of notifications to format
131
  * @param string $format 'string' to get a BuddyBar-compatible notification, 'array' otherwise
132
  *
 
133
  * @uses bp_loggedin_user_domain()
134
  * @uses bp_get_activity_slug()
135
  * @uses bp_core_get_user_displayname()
@@ -140,32 +141,33 @@ function bp_activity_adjust_mention_count( $activity_id, $action = 'add' ) {
140
  * @return string $return Formatted @mention notification
141
  */
142
  function bp_activity_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
 
143
 
144
  switch ( $action ) {
145
  case 'new_at_mention':
146
  $activity_id = $item_id;
147
  $poster_user_id = $secondary_item_id;
148
  $at_mention_link = bp_loggedin_user_domain() . bp_get_activity_slug() . '/mentions/';
149
- $at_mention_title = sprintf( __( '@%s Mentions', 'buddypress' ), bp_get_loggedin_user_username() );
150
 
151
- if ( (int) $total_items > 1 ) {
152
- $text = sprintf( __( 'You have %1$d new mentions', 'buddypress' ), (int) $total_items );
153
  $filter = 'bp_activity_multiple_at_mentions_notification';
154
  } else {
155
  $user_fullname = bp_core_get_user_displayname( $poster_user_id );
156
- $text = sprintf( __( '%1$s mentioned you', 'buddypress' ), $user_fullname );
157
  $filter = 'bp_activity_single_at_mentions_notification';
158
  }
159
  break;
160
  }
161
 
162
  if ( 'string' == $format ) {
163
- $return = apply_filters( $filter, '<a href="' . $at_mention_link . '" title="' . $at_mention_title . '">' . $text . '</a>', $at_mention_link, (int) $total_items, $activity_id, $poster_user_id );
164
  } else {
165
  $return = apply_filters( $filter, array(
166
  'text' => $text,
167
  'link' => $at_mention_link
168
- ), $at_mention_link, (int) $total_items, $activity_id, $poster_user_id );
169
  }
170
 
171
  do_action( 'activity_format_notifications', $action, $item_id, $secondary_item_id, $total_items );
@@ -178,7 +180,7 @@ function bp_activity_format_notifications( $action, $item_id, $secondary_item_id
178
  /**
179
  * Sets the current action for a given activity stream location
180
  *
181
- * @since BuddyPress (1.1)
182
  *
183
  * @param string $component_id
184
  * @param string $key
@@ -197,14 +199,6 @@ function bp_activity_set_action( $component_id, $key, $value ) {
197
  return false;
198
 
199
  // Set activity action
200
- if ( !isset( $bp->activity->actions ) || !is_object( $bp->activity->actions ) ) {
201
- $bp->activity->actions = new stdClass;
202
- }
203
-
204
- if ( !isset( $bp->activity->actions->{$component_id} ) || !is_object( $bp->activity->actions->{$component_id} ) ) {
205
- $bp->activity->actions->{$component_id} = new stdClass;
206
- }
207
-
208
  $bp->activity->actions->{$component_id}->{$key} = apply_filters( 'bp_activity_set_action', array(
209
  'key' => $key,
210
  'value' => $value
@@ -216,7 +210,7 @@ function bp_activity_set_action( $component_id, $key, $value ) {
216
  /**
217
  * Retreives the current action from a component and key
218
  *
219
- * @since BuddyPress (1.1)
220
  *
221
  * @param string $component_id
222
  * @param string $key
@@ -241,20 +235,22 @@ function bp_activity_get_action( $component_id, $key ) {
241
  /**
242
  * Get a users favorite activity stream items
243
  *
244
- * @since BuddyPress (1.2)
245
  *
246
  * @param int $user_id
247
  *
 
248
  * @uses bp_get_user_meta()
249
  * @uses apply_filters() To call the 'bp_activity_get_user_favorites' hook
250
  *
251
  * @return array Array of users favorite activity stream ID's
252
  */
253
  function bp_activity_get_user_favorites( $user_id = 0 ) {
 
254
 
255
  // Fallback to logged in user if no user_id is passed
256
  if ( empty( $user_id ) )
257
- $user_id = bp_displayed_user_id();
258
 
259
  // Get favorites for user
260
  $favs = bp_get_user_meta( $user_id, 'bp_favorite_activities', true );
@@ -265,11 +261,12 @@ function bp_activity_get_user_favorites( $user_id = 0 ) {
265
  /**
266
  * Add an activity stream item as a favorite for a user
267
  *
268
- * @since BuddyPress (1.2)
269
  *
270
  * @param int $activity_id
271
  * @param int $user_id
272
  *
 
273
  * @uses is_user_logged_in()
274
  * @uses bp_get_user_meta()
275
  * @uses bp_activity_get_meta()
@@ -281,6 +278,7 @@ function bp_activity_get_user_favorites( $user_id = 0 ) {
281
  * @return bool True on success, false on failure
282
  */
283
  function bp_activity_add_user_favorite( $activity_id, $user_id = 0 ) {
 
284
 
285
  // Favorite activity stream items are for logged in users only
286
  if ( !is_user_logged_in() )
@@ -288,18 +286,18 @@ function bp_activity_add_user_favorite( $activity_id, $user_id = 0 ) {
288
 
289
  // Fallback to logged in user if no user_id is passed
290
  if ( empty( $user_id ) )
291
- $user_id = bp_loggedin_user_id();
292
 
293
  // Update the user's personal favorites
294
- $my_favs = bp_get_user_meta( bp_loggedin_user_id(), 'bp_favorite_activities', true );
295
  $my_favs[] = $activity_id;
296
 
297
  // Update the total number of users who have favorited this activity
298
  $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' );
299
- $fav_count = !empty( $fav_count ) ? (int) $fav_count + 1 : 1;
300
 
301
  // Update user meta
302
- bp_update_user_meta( bp_loggedin_user_id(), 'bp_favorite_activities', $my_favs );
303
 
304
  // Update activity meta counts
305
  if ( true === bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count ) ) {
@@ -322,11 +320,12 @@ function bp_activity_add_user_favorite( $activity_id, $user_id = 0 ) {
322
  /**
323
  * Remove an activity stream item as a favorite for a user
324
  *
325
- * @since BuddyPress (1.2)
326
  *
327
  * @param int $activity_id
328
  * @param int $user_id
329
  *
 
330
  * @uses is_user_logged_in()
331
  * @uses bp_get_user_meta()
332
  * @uses bp_activity_get_meta()
@@ -337,6 +336,7 @@ function bp_activity_add_user_favorite( $activity_id, $user_id = 0 ) {
337
  * @return bool True on success, false on failure
338
  */
339
  function bp_activity_remove_user_favorite( $activity_id, $user_id = 0 ) {
 
340
 
341
  // Favorite activity stream items are for logged in users only
342
  if ( !is_user_logged_in() )
@@ -344,7 +344,7 @@ function bp_activity_remove_user_favorite( $activity_id, $user_id = 0 ) {
344
 
345
  // Fallback to logged in user if no user_id is passed
346
  if ( empty( $user_id ) )
347
- $user_id = bp_loggedin_user_id();
348
 
349
  // Remove the fav from the user's favs
350
  $my_favs = bp_get_user_meta( $user_id, 'bp_favorite_activities', true );
@@ -356,7 +356,7 @@ function bp_activity_remove_user_favorite( $activity_id, $user_id = 0 ) {
356
  if ( $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' ) ) {
357
 
358
  // Deduct from total favorites
359
- if ( bp_activity_update_meta( $activity_id, 'favorite_count', (int) $fav_count - 1 ) ) {
360
 
361
  // Update users favorites
362
  if ( bp_update_user_meta( $user_id, 'bp_favorite_activities', $my_favs ) ) {
@@ -386,7 +386,7 @@ function bp_activity_remove_user_favorite( $activity_id, $user_id = 0 ) {
386
  /**
387
  * Check if activity exists by scanning content
388
  *
389
- * @since BuddyPress (1.1)
390
  *
391
  * @param string $content
392
  *
@@ -402,7 +402,7 @@ function bp_activity_check_exists_by_content( $content ) {
402
  /**
403
  * Retrieve the last time activity was updated
404
  *
405
- * @since BuddyPress (1.0)
406
  *
407
  * @uses BP_Activity_Activity::get_last_updated() {@link BP_Activity_Activity}
408
  * @uses apply_filters() To call the 'bp_activity_get_last_updated' hook
@@ -416,19 +416,21 @@ function bp_activity_get_last_updated() {
416
  /**
417
  * Retrieve the number of favorite activity stream items a user has
418
  *
419
- * @since BuddyPress (1.2)
420
  *
421
  * @param int $user_id
422
  *
 
423
  * @uses BP_Activity_Activity::total_favorite_count() {@link BP_Activity_Activity}
424
  *
425
  * @return int Total favorite count
426
  */
427
  function bp_activity_total_favorites_for_user( $user_id = 0 ) {
 
428
 
429
  // Fallback on displayed user, and then logged in user
430
  if ( empty( $user_id ) )
431
- $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
432
 
433
  return BP_Activity_Activity::total_favorite_count( $user_id );
434
  }
@@ -438,7 +440,7 @@ function bp_activity_total_favorites_for_user( $user_id = 0 ) {
438
  /**
439
  * Delete a meta entry from the DB for an activity stream item
440
  *
441
- * @since BuddyPress (1.2)
442
  *
443
  * @param int $activity_id
444
  * @param string $meta_key
@@ -480,7 +482,7 @@ function bp_activity_delete_meta( $activity_id, $meta_key = '', $meta_value = ''
480
  $retval = $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s", $activity_id, $meta_key ) );
481
 
482
  // Delete cache entry
483
- wp_cache_delete( 'bp_activity_meta_' . $activity_id . '_' . $meta_key, 'bp' );
484
 
485
  // Success
486
  if ( !is_wp_error( $retval ) )
@@ -494,7 +496,7 @@ function bp_activity_delete_meta( $activity_id, $meta_key = '', $meta_value = ''
494
  /**
495
  * Get activity meta
496
  *
497
- * @since BuddyPress (1.2)
498
  *
499
  * @param int $activity_id
500
  * @param string $meta_key
@@ -521,33 +523,26 @@ function bp_activity_get_meta( $activity_id = 0, $meta_key = '' ) {
521
  $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
522
 
523
  // Check cache
524
- if ( !$metas = wp_cache_get( 'bp_activity_meta_' . $activity_id . '_' . $meta_key, 'bp' ) ) {
 
525
  // No cache so hit the DB
526
  $metas = $wpdb->get_col( $wpdb->prepare("SELECT meta_value FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s", $activity_id, $meta_key ) );
527
 
528
  // Set cache
529
- wp_cache_set( 'bp_activity_meta_' . $activity_id . '_' . $meta_key, $metas, 'bp' );
530
  }
531
 
532
  // No key so get all for activity_id
533
  } else {
534
- $metas = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM {$bp->activity->table_name_meta} WHERE activity_id = %d", $activity_id ) );
535
-
536
- if ( !empty( $metas ) ) {
537
- $metas = array_map( 'maybe_unserialize', (array) $metas );
538
-
539
- foreach( $metas as $mkey => $mvalue ) {
540
- wp_cache_set( 'bp_activity_meta_' . $activity_id . '_' . $mkey, $mvalue, 'bp' );
541
- }
542
- }
543
  }
544
-
545
  // No result so return false
546
  if ( empty( $metas ) )
547
  return false;
548
 
549
  // Maybe, just maybe... unserialize
550
- $metas = array_map( 'maybe_unserialize', (array) $metas );
551
 
552
  // Return first item in array if only 1, else return all metas found
553
  $retval = ( 1 == count( $metas ) ? $metas[0] : $metas );
@@ -559,7 +554,7 @@ function bp_activity_get_meta( $activity_id = 0, $meta_key = '' ) {
559
  /**
560
  * Update activity meta
561
  *
562
- * @since BuddyPress (1.2)
563
  *
564
  * @param int $activity_id
565
  * @param string $meta_key
@@ -610,7 +605,7 @@ function bp_activity_update_meta( $activity_id, $meta_key, $meta_value ) {
610
  return false;
611
 
612
  // Set cache
613
- wp_cache_set( 'bp_activity_meta_' . $activity_id . '_' . $meta_key, $meta_value, 'bp' );
614
 
615
  // Victory is ours!
616
  return true;
@@ -621,7 +616,7 @@ function bp_activity_update_meta( $activity_id, $meta_key, $meta_value ) {
621
  /**
622
  * Completely remove a user's activity data
623
  *
624
- * @since BuddyPress (1.5)
625
  *
626
  * @param int $user_id
627
  *
@@ -652,127 +647,25 @@ function bp_activity_remove_all_user_data( $user_id = 0 ) {
652
  }
653
  add_action( 'wpmu_delete_user', 'bp_activity_remove_all_user_data' );
654
  add_action( 'delete_user', 'bp_activity_remove_all_user_data' );
655
-
656
- /**
657
- * Mark all of the user's activity as spam
658
- *
659
- * @global object $wpdb
660
- * @global object $bp BuddyPress global settings
661
- * @param int $user_id
662
- * @since 1.6
663
- */
664
- function bp_activity_spam_all_user_data( $user_id = 0 ) {
665
- global $bp, $wpdb;
666
-
667
- // Do not delete user data unless a logged in user says so
668
- if ( empty( $user_id ) || ! is_user_logged_in() )
669
- return false;
670
-
671
- // Get all the user's activities.
672
- $activities = bp_activity_get( array( 'display_comments' => 'stream', 'filter' => array( 'user_id' => $user_id ), 'show_hidden' => true, ) );
673
-
674
- // Mark each as spam
675
- foreach ( (array) $activities['activities'] as $activity ) {
676
-
677
- // Create an activity object
678
- $activity_obj = new BP_Activity_Activity;
679
- foreach ( $activity as $k => $v )
680
- $activity_obj->$k = $v;
681
-
682
- // Mark as spam
683
- bp_activity_mark_as_spam( $activity_obj );
684
-
685
- /*
686
- * If Akismet is present, update the activity history meta.
687
- *
688
- * This is usually taken care of when BP_Activity_Activity::save() happens, but
689
- * as we're going to be updating all the activity statuses directly, for efficency,
690
- * we need to update manually.
691
- */
692
- if ( ! empty( $bp->activity->akismet ) )
693
- $bp->activity->akismet->update_activity_spam_meta( $activity_obj );
694
-
695
- // Tidy up
696
- unset( $activity_obj );
697
- }
698
-
699
- // Mark all of this user's activities as spam
700
- $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_spam = 1 WHERE user_id = %d", $user_id ) );
701
-
702
- // Call an action for plugins to use
703
- do_action( 'bp_activity_spam_all_user_data', $user_id, $activities['activities'] );
704
- }
705
- add_action( 'bp_make_spam_user', 'bp_activity_spam_all_user_data' );
706
-
707
- /**
708
- * Mark all of the user's activity as ham (not spam)
709
- *
710
- * @global object $wpdb
711
- * @global object $bp BuddyPress global settings
712
- * @param int $user_id
713
- * @since 1.6
714
- */
715
- function bp_activity_ham_all_user_data( $user_id = 0 ) {
716
- global $bp, $wpdb;
717
-
718
- // Do not delete user data unless a logged in user says so
719
- if ( empty( $user_id ) || ! is_user_logged_in() )
720
- return false;
721
-
722
- // Get all the user's activities.
723
- $activities = bp_activity_get( array( 'display_comments' => 'stream', 'filter' => array( 'user_id' => $user_id ), 'show_hidden' => true, 'spam' => 'all', ) );
724
-
725
- // Mark each as not spam
726
- foreach ( (array) $activities['activities'] as $activity ) {
727
-
728
- // Create an activity object
729
- $activity_obj = new BP_Activity_Activity;
730
- foreach ( $activity as $k => $v )
731
- $activity_obj->$k = $v;
732
-
733
- // Mark as not spam
734
- bp_activity_mark_as_ham( $activity_obj );
735
-
736
- /*
737
- * If Akismet is present, update the activity history meta.
738
- *
739
- * This is usually taken care of when BP_Activity_Activity::save() happens, but
740
- * as we're going to be updating all the activity statuses directly, for efficency,
741
- * we need to update manually.
742
- */
743
- if ( ! empty( $bp->activity->akismet ) )
744
- $bp->activity->akismet->update_activity_ham_meta( $activity_obj );
745
-
746
- // Tidy up
747
- unset( $activity_obj );
748
- }
749
-
750
- // Mark all of this user's activities as spam
751
- $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_spam = 0 WHERE user_id = %d", $user_id ) );
752
-
753
- // Call an action for plugins to use
754
- do_action( 'bp_activity_ham_all_user_data', $user_id, $activities['activities'] );
755
- }
756
- add_action( 'bp_make_ham_user', 'bp_activity_ham_all_user_data' );
757
 
758
  /**
759
  * Register the activity stream actions for updates
760
  *
 
 
761
  * @global object $bp BuddyPress global settings
762
- * @since 1.6
 
763
  */
764
- function bp_activity_register_activity_actions() {
765
  global $bp;
766
 
767
- bp_activity_set_action( $bp->activity->id, 'activity_update', __( 'Posted a status update', 'buddypress' ) );
768
- bp_activity_set_action( $bp->activity->id, 'activity_comment', __( 'Replied to a status update', 'buddypress' ) );
769
-
770
- do_action( 'bp_activity_register_activity_actions' );
771
 
772
- // Backpat. Don't use this.
773
  do_action( 'updates_register_activity_actions' );
774
  }
775
- add_action( 'bp_register_activity_actions', 'bp_activity_register_activity_actions' );
776
 
777
  /******************************************************************************
778
  * Business functions are where all the magic happens in BuddyPress. They will
@@ -784,7 +677,7 @@ add_action( 'bp_register_activity_actions', 'bp_activity_register_activity_actio
784
  /**
785
  * Retrieve an activity or activities
786
  *
787
- * @since BuddyPress (1.2)
788
  *
789
  * @param array $args
790
  *
@@ -798,17 +691,16 @@ add_action( 'bp_register_activity_actions', 'bp_activity_register_activity_actio
798
  */
799
  function bp_activity_get( $args = '' ) {
800
  $defaults = array(
801
- 'max' => false, // Maximum number of results to return
802
- 'page' => 1, // page 1 without a per_page will result in no pagination.
803
- 'per_page' => false, // results per page
804
- 'sort' => 'DESC', // sort ASC or DESC
805
- 'display_comments' => false, // false for no comments. 'stream' for within stream display, 'threaded' for below each activity item
806
-
807
- 'search_terms' => false, // Pass search terms as a string
808
- 'show_hidden' => false, // Show activity items that are hidden site-wide?
809
- 'exclude' => false, // Comma-separated list of activity IDs to exclude
810
- 'in' => false, // Comma-separated list or array of activity IDs to which you want to limit the query
811
- 'spam' => 'ham_only', // 'ham_only' (default), 'spam_only' or 'all'.
812
 
813
  /**
814
  * Pass filters as an array -- all filter items can be multiple values comma separated:
@@ -826,39 +718,13 @@ function bp_activity_get( $args = '' ) {
826
  extract( $r, EXTR_SKIP );
827
 
828
  // Attempt to return a cached copy of the first page of sitewide activity.
829
- if ( 1 == (int) $page && empty( $max ) && empty( $search_terms ) && empty( $filter ) && empty( $exclude ) && empty( $in ) && 'DESC' == $sort && empty( $exclude ) && 'ham_only' == $spam ) {
830
  if ( !$activity = wp_cache_get( 'bp_activity_sitewide_front', 'bp' ) ) {
831
- $args = array(
832
- 'page' => $page,
833
- 'per_page' => $per_page,
834
- 'max' => $max,
835
- 'sort' => $sort,
836
- 'search_terms' => $search_terms,
837
- 'filter' => $filter,
838
- 'display_comments' => $display_comments,
839
- 'show_hidden' => $show_hidden,
840
- 'spam' => $spam
841
- );
842
- $activity = BP_Activity_Activity::get( $args );
843
  wp_cache_set( 'bp_activity_sitewide_front', $activity, 'bp' );
844
  }
845
-
846
- } else {
847
- $args = array(
848
- 'page' => $page,
849
- 'per_page' => $per_page,
850
- 'max' => $max,
851
- 'sort' => $sort,
852
- 'search_terms' => $search_terms,
853
- 'filter' => $filter,
854
- 'display_comments' => $display_comments,
855
- 'show_hidden' => $show_hidden,
856
- 'exclude' => $exclude,
857
- 'in' => $in,
858
- 'spam' => $spam
859
- );
860
- $activity = BP_Activity_Activity::get( $args );
861
- }
862
 
863
  return apply_filters_ref_array( 'bp_activity_get', array( &$activity, &$r ) );
864
  }
@@ -866,7 +732,7 @@ function bp_activity_get( $args = '' ) {
866
  /**
867
  * Fetch specific activity items
868
  *
869
- * @since BuddyPress (1.2)
870
  *
871
  * @param array $args See docs for $defaults for details
872
  *
@@ -878,38 +744,28 @@ function bp_activity_get( $args = '' ) {
878
  */
879
  function bp_activity_get_specific( $args = '' ) {
880
  $defaults = array(
881
- 'activity_ids' => false, // A single activity_id or array of IDs.
882
- 'display_comments' => false, // true or false to display threaded comments for these specific activity items
883
- 'max' => false, // Maximum number of results to return
884
- 'page' => 1, // page 1 without a per_page will result in no pagination.
885
- 'per_page' => false, // results per page
886
- 'show_hidden' => true, // When fetching specific items, show all
887
- 'sort' => 'DESC', // sort ASC or DESC
888
- 'spam' => 'ham_only', // Retrieve items marked as spam
889
  );
890
  $r = wp_parse_args( $args, $defaults );
891
  extract( $r, EXTR_SKIP );
892
 
893
- $get_args = array(
894
- 'page' => $page,
895
- 'per_page' => $per_page,
896
- 'max' => $max,
897
- 'sort' => $sort,
898
- 'display_comments' => $display_comments,
899
- 'show_hidden' => $show_hidden,
900
- 'in' => $activity_ids,
901
- 'spam' => $spam
902
- );
903
- return apply_filters( 'bp_activity_get_specific', BP_Activity_Activity::get( $get_args ), $args, $get_args );
904
  }
905
 
906
  /**
907
  * Add an activity item
908
  *
909
- * @since BuddyPress (1.1)
910
  *
911
  * @param array $args See docs for $defaults for details
912
  *
 
913
  * @uses wp_parse_args()
914
  * @uses BP_Activity_Activity::save() {@link BP_Activity_Activity}
915
  * @uses BP_Activity_Activity::rebuild_activity_comment_tree() {@link BP_Activity_Activity}
@@ -919,6 +775,7 @@ function bp_activity_get_specific( $args = '' ) {
919
  * @return int The activity id
920
  */
921
  function bp_activity_add( $args = '' ) {
 
922
 
923
  $defaults = array(
924
  'id' => false, // Pass an existing activity ID to update an existing entry.
@@ -930,12 +787,11 @@ function bp_activity_add( $args = '' ) {
930
  'type' => false, // The activity type e.g. activity_update, profile_updated
931
  'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink)
932
 
933
- '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.
934
  'item_id' => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id
935
  'secondary_item_id' => false, // Optional: A second ID used to further filter e.g. a comment_id
936
  'recorded_time' => bp_core_current_time(), // The GMT time that this activity was recorded
937
- 'hide_sitewide' => false, // Should this be hidden on the sitewide activity stream?
938
- 'is_spam' => false, // Is this activity item to be marked as spam?
939
  );
940
  $params = wp_parse_args( $args, $defaults );
941
  extract( $params, EXTR_SKIP );
@@ -959,7 +815,6 @@ function bp_activity_add( $args = '' ) {
959
  $activity->secondary_item_id = $secondary_item_id;
960
  $activity->date_recorded = $recorded_time;
961
  $activity->hide_sitewide = $hide_sitewide;
962
- $activity->is_spam = $is_spam;
963
 
964
  if ( !$activity->save() )
965
  return false;
@@ -977,13 +832,14 @@ function bp_activity_add( $args = '' ) {
977
  /**
978
  * Post an activity update
979
  *
980
- * @since BuddyPress (1.2)
981
  *
982
  * @param array $args See docs for $defaults for details
983
  *
984
  * @global object $bp BuddyPress global settings
985
  * @uses wp_parse_args()
986
- * @uses bp_is_user_inactive()
 
987
  * @uses bp_core_get_userlink()
988
  * @uses bp_activity_add()
989
  * @uses apply_filters() To call the 'bp_activity_new_update_action' hook
@@ -1000,7 +856,7 @@ function bp_activity_post_update( $args = '' ) {
1000
 
1001
  $defaults = array(
1002
  'content' => false,
1003
- 'user_id' => bp_loggedin_user_id()
1004
  );
1005
  $r = wp_parse_args( $args, $defaults );
1006
  extract( $r, EXTR_SKIP );
@@ -1008,7 +864,7 @@ function bp_activity_post_update( $args = '' ) {
1008
  if ( empty( $content ) || !strlen( trim( $content ) ) )
1009
  return false;
1010
 
1011
- if ( bp_is_user_inactive( $user_id ) )
1012
  return false;
1013
 
1014
  // Record this on the user's profile
@@ -1027,10 +883,8 @@ function bp_activity_post_update( $args = '' ) {
1027
  'type' => 'activity_update'
1028
  ) );
1029
 
1030
- $activity_content = apply_filters( 'bp_activity_latest_update_content', $content );
1031
-
1032
  // Add this update to the "latest update" usermeta so it can be fetched anywhere.
1033
- bp_update_user_meta( bp_loggedin_user_id(), 'bp_latest_update', array( 'id' => $activity_id, 'content' => $content ) );
1034
 
1035
  do_action( 'bp_activity_posted_update', $content, $user_id, $activity_id );
1036
 
@@ -1040,7 +894,7 @@ function bp_activity_post_update( $args = '' ) {
1040
  /**
1041
  * Add an activity comment
1042
  *
1043
- * @since BuddyPress (1.2)
1044
  *
1045
  * @param array $args See docs for $defaults for details
1046
  *
@@ -1061,7 +915,7 @@ function bp_activity_new_comment( $args = '' ) {
1061
  $defaults = array(
1062
  'id' => false,
1063
  'content' => false,
1064
- 'user_id' => bp_loggedin_user_id(),
1065
  'activity_id' => false, // ID of the root activity item
1066
  'parent_id' => false // ID of a parent comment (optional)
1067
  );
@@ -1069,27 +923,27 @@ function bp_activity_new_comment( $args = '' ) {
1069
  $params = wp_parse_args( $args, $defaults );
1070
  extract( $params, EXTR_SKIP );
1071
 
1072
- if ( empty( $content ) || empty( $user_id ) || empty( $activity_id ) )
1073
  return false;
1074
 
1075
- if ( empty( $parent_id ) )
1076
  $parent_id = $activity_id;
1077
 
1078
  // Check to see if the parent activity is hidden, and if so, hide this comment publically.
1079
  $activity = new BP_Activity_Activity( $activity_id );
1080
- $is_hidden = ( (int) $activity->hide_sitewide ) ? 1 : 0;
1081
 
1082
  // Insert the activity comment
1083
  $comment_id = bp_activity_add( array(
1084
- 'id' => $id,
1085
- 'action' => apply_filters( 'bp_activity_comment_action', sprintf( __( '%s posted a new activity comment', 'buddypress' ), bp_core_get_userlink( $user_id ) ) ),
1086
- 'content' => apply_filters( 'bp_activity_comment_content', $content ),
1087
- 'component' => $bp->activity->id,
1088
- 'type' => 'activity_comment',
1089
- 'user_id' => $user_id,
1090
- 'item_id' => $activity_id,
1091
  'secondary_item_id' => $parent_id,
1092
- 'hide_sitewide' => $is_hidden
1093
  ) );
1094
 
1095
  // Send an email notification if settings allow
@@ -1106,7 +960,7 @@ function bp_activity_new_comment( $args = '' ) {
1106
  /**
1107
  * Fetch the activity_id for an existing activity entry in the DB.
1108
  *
1109
- * @since BuddyPress (1.2)
1110
  *
1111
  * @param array $args See docs for $defaults for details
1112
  *
@@ -1147,10 +1001,11 @@ function bp_activity_get_activity_id( $args = '' ) {
1147
  *
1148
  * If you are deleting an activity comment please use bp_activity_delete_comment();
1149
  *
1150
- * @since BuddyPress (1.0)
1151
  *
1152
  * @param array $args See docs for $defaults for details
1153
  *
 
1154
  * @uses wp_parse_args()
1155
  * @uses bp_activity_adjust_mention_count()
1156
  * @uses BP_Activity_Activity::delete() {@link BP_Activity_Activity}
@@ -1164,6 +1019,7 @@ function bp_activity_get_activity_id( $args = '' ) {
1164
  * @return bool True on success, false on failure
1165
  */
1166
  function bp_activity_delete( $args = '' ) {
 
1167
 
1168
  // Pass one or more the of following variables to delete by those variables
1169
  $defaults = array(
@@ -1190,7 +1046,7 @@ function bp_activity_delete( $args = '' ) {
1190
 
1191
  // Check if the user's latest update has been deleted
1192
  if ( empty( $args['user_id'] ) )
1193
- $user_id = bp_loggedin_user_id();
1194
  else
1195
  $user_id = $args['user_id'];
1196
 
@@ -1198,9 +1054,8 @@ function bp_activity_delete( $args = '' ) {
1198
 
1199
  $latest_update = bp_get_user_meta( $user_id, 'bp_latest_update', true );
1200
  if ( !empty( $latest_update ) ) {
1201
- if ( in_array( (int) $latest_update['id'], (array) $activity_ids_deleted ) ) {
1202
  bp_delete_user_meta( $user_id, 'bp_latest_update' );
1203
- }
1204
  }
1205
 
1206
  do_action( 'bp_activity_delete', $args );
@@ -1216,25 +1071,21 @@ function bp_activity_delete( $args = '' ) {
1216
  *
1217
  * You should use bp_activity_delete() instead
1218
  *
1219
- * @since BuddyPress (1.1)
1220
- * @deprecated BuddyPress (1.2)
1221
  *
1222
  * @param array $args See docs for $defaults for details
1223
  *
 
1224
  * @uses wp_parse_args()
1225
  * @uses bp_activity_delete()
1226
  *
1227
  * @return bool True on success, false on failure
1228
  */
1229
  function bp_activity_delete_by_item_id( $args = '' ) {
 
1230
 
1231
- $defaults = array(
1232
- 'item_id' => false,
1233
- 'component' => false,
1234
- 'type' => false,
1235
- 'user_id' => false,
1236
- 'secondary_item_id' => false
1237
- );
1238
  $r = wp_parse_args( $args, $defaults );
1239
  extract( $r, EXTR_SKIP );
1240
 
@@ -1246,8 +1097,8 @@ function bp_activity_delete( $args = '' ) {
1246
  *
1247
  * You should use bp_activity_delete() instead
1248
  *
1249
- * @since BuddyPress (1.1)
1250
- * @deprecated BuddyPress (1.2)
1251
  *
1252
  * @param int $activity_id The activity id
1253
  *
@@ -1264,8 +1115,8 @@ function bp_activity_delete( $args = '' ) {
1264
  *
1265
  * You should use bp_activity_delete() instead
1266
  *
1267
- * @since BuddyPress (1.1)
1268
- * @deprecated BuddyPress (1.2)
1269
  *
1270
  * @param int $user_id The user id
1271
  * @param string $content The activity id
@@ -1285,8 +1136,8 @@ function bp_activity_delete( $args = '' ) {
1285
  *
1286
  * You should use bp_activity_delete() instead
1287
  *
1288
- * @since BuddyPress (1.1)
1289
- * @deprecated BuddyPress (1.2)
1290
  *
1291
  * @param int $user_id The user id
1292
  * @param string $component The activity component
@@ -1302,7 +1153,7 @@ function bp_activity_delete( $args = '' ) {
1302
  /**
1303
  * Delete an activity comment
1304
  *
1305
- * @since BuddyPress (1.2)
1306
  *
1307
  * @param int $activity_id The activity id
1308
  * @param int $comment_id The activity comment id
@@ -1341,7 +1192,7 @@ function bp_activity_delete_comment( $activity_id, $comment_id ) {
1341
  /**
1342
  * Delete an activity comment's children
1343
  *
1344
- * @since BuddyPress (1.2)
1345
  *
1346
  * @param int $activity_id The activity id
1347
  * @param int $comment_id The activity comment id
@@ -1353,9 +1204,8 @@ function bp_activity_delete_comment( $activity_id, $comment_id ) {
1353
  function bp_activity_delete_children( $activity_id, $comment_id) {
1354
  // Recursively delete all children of this comment.
1355
  if ( $children = BP_Activity_Activity::get_child_comments( $comment_id ) ) {
1356
- foreach( (array) $children as $child ) {
1357
  bp_activity_delete_children( $activity_id, $child->id );
1358
- }
1359
  }
1360
  bp_activity_delete( array( 'secondary_item_id' => $comment_id, 'type' => 'activity_comment', 'item_id' => $activity_id ) );
1361
  }
@@ -1367,11 +1217,12 @@ function bp_activity_delete_comment( $activity_id, $comment_id ) {
1367
  * object. To save yourself some processing overhead, be sure to pass the full $activity_obj param
1368
  * as well, if you already have it available.
1369
  *
1370
- * @since BuddyPress (1.2)
1371
  *
1372
  * @param int $activity_id The unique id of the activity object
1373
  * @param object $activity_obj (optional) The activity object
1374
  *
 
1375
  * @uses bp_get_root_domain()
1376
  * @uses bp_get_activity_root_slug()
1377
  * @uses apply_filters_ref_array() To call the 'bp_activity_get_permalink' hook
@@ -1379,22 +1230,22 @@ function bp_activity_delete_comment( $activity_id, $comment_id ) {
1379
  * @return string $link Permalink for the activity item
1380
  */
1381
  function bp_activity_get_permalink( $activity_id, $activity_obj = false ) {
 
1382
 
1383
- if ( empty( $activity_obj ) )
1384
  $activity_obj = new BP_Activity_Activity( $activity_id );
1385
 
1386
  if ( isset( $activity_obj->current_comment ) ) {
1387
  $activity_obj = $activity_obj->current_comment;
1388
  }
1389
 
1390
- 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 ) {
1391
  $link = $activity_obj->primary_link;
1392
- } else {
1393
- if ( 'activity_comment' == $activity_obj->type ) {
1394
  $link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $activity_obj->item_id . '/';
1395
- } else {
1396
  $link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $activity_obj->id . '/';
1397
- }
1398
  }
1399
 
1400
  return apply_filters_ref_array( 'bp_activity_get_permalink', array( $link, &$activity_obj ) );
@@ -1403,7 +1254,7 @@ function bp_activity_get_permalink( $activity_id, $activity_obj = false ) {
1403
  /**
1404
  * Hide a user's activity
1405
  *
1406
- * @since BuddyPress (1.2)
1407
  *
1408
  * @param int $user_id The user id
1409
  *
@@ -1418,7 +1269,7 @@ function bp_activity_hide_user_activity( $user_id ) {
1418
  /**
1419
  * Take content, remove all images and replace them with one thumbnail image.
1420
  *
1421
- * @since BuddyPress (1.2)
1422
  *
1423
  * @param string $content The content to work with
1424
  * @param string $link Optional. The URL that the image should link to
@@ -1429,31 +1280,32 @@ function bp_activity_hide_user_activity( $user_id ) {
1429
  * @return string $content The content with images stripped and replaced with a single thumb.
1430
  */
1431
  function bp_activity_thumbnail_content_images( $content, $link = false ) {
 
1432
 
1433
  preg_match_all( '/<img[^>]*>/Ui', $content, $matches );
1434
- $content = preg_replace('|(\[caption(.*?)\])?<img[^>]*>(\[/caption\])?|', '', $content );
1435
-
1436
  if ( !empty( $matches ) && !empty( $matches[0] ) ) {
1437
  // Get the SRC value
1438
  preg_match( '/<img.*?(src\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $src );
1439
 
1440
  // Get the width and height
1441
  preg_match( '/<img.*?(height\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $height );
1442
- preg_match( '/<img.*?(width\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $width );
1443
 
1444
  if ( !empty( $src ) ) {
1445
- $src = substr( substr( str_replace( 'src=', '', $src[1] ), 0, -1 ), 1 );
1446
  $height = substr( substr( str_replace( 'height=', '', $height[1] ), 0, -1 ), 1 );
1447
- $width = substr( substr( str_replace( 'width=', '', $width[1] ), 0, -1 ), 1 );
1448
 
1449
  if ( empty( $width ) || empty( $height ) ) {
1450
- $width = 100;
1451
  $height = 100;
1452
  }
1453
 
1454
- $ratio = (int) $width / (int) $height;
1455
- $new_height = (int) $height >= 100 ? 100 : $height;
1456
- $new_width = $new_height * $ratio;
1457
 
1458
  $image = '<img src="' . esc_attr( $src ) . '" width="' . $new_width . '" height="' . $new_height . '" alt="' . __( 'Thumbnail', 'buddypress' ) . '" class="align-left thumbnail" />';
1459
 
@@ -1468,90 +1320,6 @@ function bp_activity_thumbnail_content_images( $content, $link = false ) {
1468
  return apply_filters( 'bp_activity_thumbnail_content_images', $content, $matches );
1469
  }
1470
 
1471
- /**
1472
- * Convenience function to control whether the current user is allowed to mark activity items as spam
1473
- *
1474
- * @return bool True if user is allowed to mark activity items as spam
1475
- * @since 1.6
1476
- * @static
1477
- */
1478
- function bp_activity_user_can_mark_spam() {
1479
- return apply_filters( 'bp_activity_user_can_mark_spam', bp_current_user_can( 'bp_moderate' ) );
1480
- }
1481
-
1482
- /**
1483
- * Mark activity item as spam
1484
- *
1485
- * @global object $bp BuddyPress global settings
1486
- * @param BP_Activity_Activity $activity
1487
- * @param string $source Optional; default is "by_a_person" (e.g. a person has manually marked the activity as spam).
1488
- * @since 1.6
1489
- */
1490
- function bp_activity_mark_as_spam( &$activity, $source = 'by_a_person' ) {
1491
- global $bp;
1492
-
1493
- $activity->is_spam = 1;
1494
-
1495
- // Clear the activity stream first page cache
1496
- wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
1497
-
1498
- // Clear the activity comment cache for this activity item
1499
- wp_cache_delete( 'bp_activity_comments_' . $activity->id, 'bp' );
1500
-
1501
- // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity
1502
- if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) {
1503
- remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4, 1 );
1504
-
1505
- // Build data package for Akismet
1506
- $activity_data = BP_Akismet::build_akismet_data_package( $activity );
1507
-
1508
- // Tell Akismet this is spam
1509
- $activity_data = $bp->activity->akismet->send_akismet_request( $activity_data, 'submit', 'spam' );
1510
-
1511
- // Update meta
1512
- add_action( 'bp_activity_after_save', array( $bp->activity->akismet, 'update_activity_spam_meta' ), 1, 1 );
1513
- }
1514
-
1515
- do_action( 'bp_activity_mark_as_spam', $activity, $source );
1516
- }
1517
-
1518
- /**
1519
- * Mark activity item as ham
1520
- *
1521
- * @global object $bp BuddyPress global settings
1522
- * @param BP_Activity_Activity $activity
1523
- * @param string $source Optional; default is "by_a_person" (e.g. a person has manually marked the activity as spam).
1524
- * @since 1.6
1525
- */
1526
- function bp_activity_mark_as_ham( &$activity, $source = 'by_a_person' ) {
1527
- global $bp;
1528
-
1529
- $activity->is_spam = 0;
1530
-
1531
- // Clear the activity stream first page cache
1532
- wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
1533
-
1534
- // Clear the activity comment cache for this activity item
1535
- wp_cache_delete( 'bp_activity_comments_' . $activity->id, 'bp' );
1536
-
1537
- // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity
1538
- if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) {
1539
- remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4, 1 );
1540
-
1541
- // Build data package for Akismet
1542
- $activity_data = BP_Akismet::build_akismet_data_package( $activity );
1543
-
1544
- // Tell Akismet this is spam
1545
- $activity_data = $bp->activity->akismet->send_akismet_request( $activity_data, 'submit', 'ham' );
1546
-
1547
- // Update meta
1548
- add_action( 'bp_activity_after_save', array( $bp->activity->akismet, 'update_activity_ham_meta' ), 1, 1 );
1549
- }
1550
-
1551
- do_action( 'bp_activity_mark_as_ham', $activity, $source );
1552
- }
1553
-
1554
-
1555
  /** Embeds *******************************************************************/
1556
 
1557
  /**
@@ -1561,7 +1329,7 @@ function bp_activity_mark_as_ham( &$activity, $source = 'by_a_person' ) {
1561
  * This does not cover recursive activity comments, as they do not use a real loop.
1562
  * For that, see {@link bp_activity_comment_embed()}.
1563
  *
1564
- * @since BuddyPress (1.5)
1565
  *
1566
  * @see BP_Embed
1567
  * @see bp_embed_activity_cache()
@@ -1583,7 +1351,7 @@ add_action( 'activity_loop_start', 'bp_activity_embed' );
1583
  * when BP is recursing through activity comments {@link bp_activity_recurse_comments()}.
1584
  * If no cache and link is embeddable, cache it.
1585
  *
1586
- * @since BuddyPress (1.5)
1587
  *
1588
  * @see BP_Embed
1589
  * @see bp_embed_activity_cache()
@@ -1603,7 +1371,7 @@ add_action( 'bp_before_activity_comment', 'bp_activity_comment_embed' );
1603
  /**
1604
  * When a user clicks on a "Read More" item, make sure embeds are correctly parsed and shown for the expanded content.
1605
  *
1606
- * @since BuddyPress (1.5)
1607
  *
1608
  * @see BP_Embed
1609
  *
@@ -1630,7 +1398,7 @@ add_action( 'bp_dtheme_get_single_activity_content', 'bp_dtheme_embed_read_more'
1630
  * is rendered to avoid conflict with the 'embed_post_id' filter in
1631
  * {@link bp_activity_embed()} or any other component embeds.
1632
  *
1633
- * @since BuddyPress (1.5)
1634
  *
1635
  * @see bp_activity_comment_embed()
1636
  *
@@ -1645,7 +1413,7 @@ add_action( 'bp_after_activity_comment', 'bp_activity_comment_embed_after_recurs
1645
  * Wrapper function for {@link bp_activity_get_meta()}.
1646
  * Used during {@link BP_Embed::parse_oembed()} via {@link bp_activity_embed()}.
1647
  *
1648
- * @since BuddyPress (1.5)
1649
  *
1650
  * @uses bp_activity_get_meta()
1651
  *
@@ -1659,12 +1427,11 @@ function bp_embed_activity_cache( $cache, $id, $cachekey ) {
1659
  * Wrapper function for {@link bp_activity_update_meta()}.
1660
  * Used during {@link BP_Embed::parse_oembed()} via {@link bp_activity_embed()}.
1661
  *
1662
- * @since BuddyPress (1.5)
1663
  *
1664
  * @uses bp_activity_update_meta()
1665
  */
1666
  function bp_embed_activity_save_cache( $cache, $cachekey, $id ) {
1667
  bp_activity_update_meta( $id, $cachekey, $cache );
1668
  }
1669
-
1670
- ?>
15
  /**
16
  * Checks $bp pages global and looks for directory page
17
  *
18
+ * @since 1.5.0
19
  *
20
  * @global object $bp BuddyPress global settings
21
  *
30
  /**
31
  * Searches through the content of an activity item to locate usernames, designated by an @ sign
32
  *
33
+ * @since 1.5.0
34
  *
35
  * @param string $content The content of the activity, usually found in $activity->content
36
  *
37
  * @return bool|array $usernames Array of the found usernames that match existing users. False if no matches
38
  */
39
  function bp_activity_find_mentions( $content ) {
40
+ $pattern = '/[@]+([A-Za-z0-9-_\.@]+)/';
41
  preg_match_all( $pattern, $content, $usernames );
42
 
43
  // Make sure there's only one instance of each username
50
  /**
51
  * Resets a user's unread mentions list and count
52
  *
53
+ * @since 1.5.0
54
  *
55
  * @param int $user_id The id of the user whose unread mentions are being reset
56
  * @uses bp_delete_user_meta()
63
  /**
64
  * Adjusts new mention count for mentioned users when activity items are deleted or created
65
  *
66
+ * @since 1.5.0
67
  *
68
  * @param int $activity_id The unique id for the activity item
69
  * @param string $action Can be 'delete' or 'add'. Defaults to 'add'
79
  $activity = new BP_Activity_Activity( $activity_id );
80
 
81
  if ( $usernames = bp_activity_find_mentions( strip_tags( $activity->content ) ) ) {
82
+ foreach( (array)$usernames as $username ) {
83
  if ( bp_is_username_compatibility_mode() )
84
  $user_id = username_exists( $username );
85
  else
104
  case 'add' :
105
  default :
106
  if ( !in_array( $activity_id, $new_mentions ) ) {
107
+ $new_mentions[] = (int)$activity_id;
108
  }
109
  break;
110
  }
122
  /**
123
  * Formats notifications related to activity
124
  *
125
+ * @since 1.5.0
126
  *
127
  * @param string $action The type of activity item. Just 'new_at_mention' for now
128
  * @param int $item_id The activity id
130
  * @param int $total_items The total number of notifications to format
131
  * @param string $format 'string' to get a BuddyBar-compatible notification, 'array' otherwise
132
  *
133
+ * @global object $bp BuddyPress global settings
134
  * @uses bp_loggedin_user_domain()
135
  * @uses bp_get_activity_slug()
136
  * @uses bp_core_get_user_displayname()
141
  * @return string $return Formatted @mention notification
142
  */
143
  function bp_activity_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
144
+ global $bp;
145
 
146
  switch ( $action ) {
147
  case 'new_at_mention':
148
  $activity_id = $item_id;
149
  $poster_user_id = $secondary_item_id;
150
  $at_mention_link = bp_loggedin_user_domain() . bp_get_activity_slug() . '/mentions/';
151
+ $at_mention_title = sprintf( __( '@%s Mentions', 'buddypress' ), $bp->loggedin_user->userdata->user_nicename );
152
 
153
+ if ( (int)$total_items > 1 ) {
154
+ $text = sprintf( __( 'You have %1$d new activity mentions', 'buddypress' ), (int)$total_items );
155
  $filter = 'bp_activity_multiple_at_mentions_notification';
156
  } else {
157
  $user_fullname = bp_core_get_user_displayname( $poster_user_id );
158
+ $text = sprintf( __( '%1$s mentioned you in an activity update', 'buddypress' ), $user_fullname );
159
  $filter = 'bp_activity_single_at_mentions_notification';
160
  }
161
  break;
162
  }
163
 
164
  if ( 'string' == $format ) {
165
+ $return = apply_filters( $filter, '<a href="' . $at_mention_link . '" title="' . $at_mention_title . '">' . $text . '</a>', $at_mention_link, (int)$total_items, $activity_id, $poster_user_id );
166
  } else {
167
  $return = apply_filters( $filter, array(
168
  'text' => $text,
169
  'link' => $at_mention_link
170
+ ), $at_mention_link, (int)$total_items, $activity_id, $poster_user_id );
171
  }
172
 
173
  do_action( 'activity_format_notifications', $action, $item_id, $secondary_item_id, $total_items );
180
  /**
181
  * Sets the current action for a given activity stream location
182
  *
183
+ * @since 1.1.0
184
  *
185
  * @param string $component_id
186
  * @param string $key
199
  return false;
200
 
201
  // Set activity action
 
 
 
 
 
 
 
 
202
  $bp->activity->actions->{$component_id}->{$key} = apply_filters( 'bp_activity_set_action', array(
203
  'key' => $key,
204
  'value' => $value
210
  /**
211
  * Retreives the current action from a component and key
212
  *
213
+ * @since 1.1.0
214
  *
215
  * @param string $component_id
216
  * @param string $key
235
  /**
236
  * Get a users favorite activity stream items
237
  *
238
+ * @since 1.2.0
239
  *
240
  * @param int $user_id
241
  *
242
+ * @global object $bp BuddyPress global settings
243
  * @uses bp_get_user_meta()
244
  * @uses apply_filters() To call the 'bp_activity_get_user_favorites' hook
245
  *
246
  * @return array Array of users favorite activity stream ID's
247
  */
248
  function bp_activity_get_user_favorites( $user_id = 0 ) {
249
+ global $bp;
250
 
251
  // Fallback to logged in user if no user_id is passed
252
  if ( empty( $user_id ) )
253
+ $user_id = $bp->displayed_user->id;
254
 
255
  // Get favorites for user
256
  $favs = bp_get_user_meta( $user_id, 'bp_favorite_activities', true );
261
  /**
262
  * Add an activity stream item as a favorite for a user
263
  *
264
+ * @since 1.2.0
265
  *
266
  * @param int $activity_id
267
  * @param int $user_id
268
  *
269
+ * @global object $bp BuddyPress global settings
270
  * @uses is_user_logged_in()
271
  * @uses bp_get_user_meta()
272
  * @uses bp_activity_get_meta()
278
  * @return bool True on success, false on failure
279
  */
280
  function bp_activity_add_user_favorite( $activity_id, $user_id = 0 ) {
281
+ global $bp;
282
 
283
  // Favorite activity stream items are for logged in users only
284
  if ( !is_user_logged_in() )
286
 
287
  // Fallback to logged in user if no user_id is passed
288
  if ( empty( $user_id ) )
289
+ $user_id = $bp->loggedin_user->id;
290
 
291
  // Update the user's personal favorites
292
+ $my_favs = bp_get_user_meta( $bp->loggedin_user->id, 'bp_favorite_activities', true );
293
  $my_favs[] = $activity_id;
294
 
295
  // Update the total number of users who have favorited this activity
296
  $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' );
297
+ $fav_count = !empty( $fav_count ) ? (int)$fav_count + 1 : 1;
298
 
299
  // Update user meta
300
+ bp_update_user_meta( $bp->loggedin_user->id, 'bp_favorite_activities', $my_favs );
301
 
302
  // Update activity meta counts
303
  if ( true === bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count ) ) {
320
  /**
321
  * Remove an activity stream item as a favorite for a user
322
  *
323
+ * @since 1.2.0
324
  *
325
  * @param int $activity_id
326
  * @param int $user_id
327
  *
328
+ * @global object $bp BuddyPress global settings
329
  * @uses is_user_logged_in()
330
  * @uses bp_get_user_meta()
331
  * @uses bp_activity_get_meta()
336
  * @return bool True on success, false on failure
337
  */
338
  function bp_activity_remove_user_favorite( $activity_id, $user_id = 0 ) {
339
+ global $bp;
340
 
341
  // Favorite activity stream items are for logged in users only
342
  if ( !is_user_logged_in() )
344
 
345
  // Fallback to logged in user if no user_id is passed
346
  if ( empty( $user_id ) )
347
+ $user_id = $bp->loggedin_user->id;
348
 
349
  // Remove the fav from the user's favs
350
  $my_favs = bp_get_user_meta( $user_id, 'bp_favorite_activities', true );
356
  if ( $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' ) ) {
357
 
358
  // Deduct from total favorites
359
+ if ( bp_activity_update_meta( $activity_id, 'favorite_count', (int)$fav_count - 1 ) ) {
360
 
361
  // Update users favorites
362
  if ( bp_update_user_meta( $user_id, 'bp_favorite_activities', $my_favs ) ) {
386
  /**
387
  * Check if activity exists by scanning content
388
  *
389
+ * @since 1.1.0
390
  *
391
  * @param string $content
392
  *
402
  /**
403
  * Retrieve the last time activity was updated
404
  *
405
+ * @since 1.0.0
406
  *
407
  * @uses BP_Activity_Activity::get_last_updated() {@link BP_Activity_Activity}
408
  * @uses apply_filters() To call the 'bp_activity_get_last_updated' hook
416
  /**
417
  * Retrieve the number of favorite activity stream items a user has
418
  *
419
+ * @since 1.2.0
420
  *
421
  * @param int $user_id
422
  *
423
+ * @global object $bp BuddyPress global settings
424
  * @uses BP_Activity_Activity::total_favorite_count() {@link BP_Activity_Activity}
425
  *
426
  * @return int Total favorite count
427
  */
428
  function bp_activity_total_favorites_for_user( $user_id = 0 ) {
429
+ global $bp;
430
 
431
  // Fallback on displayed user, and then logged in user
432
  if ( empty( $user_id ) )
433
+ $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
434
 
435
  return BP_Activity_Activity::total_favorite_count( $user_id );
436
  }
440
  /**
441
  * Delete a meta entry from the DB for an activity stream item
442
  *
443
+ * @since 1.2.0
444
  *
445
  * @param int $activity_id
446
  * @param string $meta_key
482
  $retval = $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s", $activity_id, $meta_key ) );
483
 
484
  // Delete cache entry
485
+ wp_cache_delete( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, 'bp' );
486
 
487
  // Success
488
  if ( !is_wp_error( $retval ) )
496
  /**
497
  * Get activity meta
498
  *
499
+ * @since 1.2.0
500
  *
501
  * @param int $activity_id
502
  * @param string $meta_key
523
  $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
524
 
525
  // Check cache
526
+ if ( !$metas = wp_cache_get( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, 'bp' ) ) {
527
+
528
  // No cache so hit the DB
529
  $metas = $wpdb->get_col( $wpdb->prepare("SELECT meta_value FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s", $activity_id, $meta_key ) );
530
 
531
  // Set cache
532
+ wp_cache_set( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, $metas, 'bp' );
533
  }
534
 
535
  // No key so get all for activity_id
536
  } else {
537
+ $metas = $wpdb->get_col( $wpdb->prepare( "SELECT meta_value FROM {$bp->activity->table_name_meta} WHERE activity_id = %d", $activity_id ) );
 
 
 
 
 
 
 
 
538
  }
539
+
540
  // No result so return false
541
  if ( empty( $metas ) )
542
  return false;
543
 
544
  // Maybe, just maybe... unserialize
545
+ $metas = array_map( 'maybe_unserialize', (array)$metas );
546
 
547
  // Return first item in array if only 1, else return all metas found
548
  $retval = ( 1 == count( $metas ) ? $metas[0] : $metas );
554
  /**
555
  * Update activity meta
556
  *
557
+ * @since 1.2.0
558
  *
559
  * @param int $activity_id
560
  * @param string $meta_key
605
  return false;
606
 
607
  // Set cache
608
+ wp_cache_set( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, $meta_value, 'bp' );
609
 
610
  // Victory is ours!
611
  return true;
616
  /**
617
  * Completely remove a user's activity data
618
  *
619
+ * @since 1.5.0
620
  *
621
  * @param int $user_id
622
  *
647
  }
648
  add_action( 'wpmu_delete_user', 'bp_activity_remove_all_user_data' );
649
  add_action( 'delete_user', 'bp_activity_remove_all_user_data' );
650
+ add_action( 'bp_make_spam_user', 'bp_activity_remove_all_user_data' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
651
 
652
  /**
653
  * Register the activity stream actions for updates
654
  *
655
+ * @since 1.2.0
656
+ *
657
  * @global object $bp BuddyPress global settings
658
+ * @uses bp_activity_set_action()
659
+ * @uses do_action() To call the 'updates_register_activity_actions' hook
660
  */
661
+ function updates_register_activity_actions() {
662
  global $bp;
663
 
664
+ bp_activity_set_action( $bp->activity->id, 'activity_update', __( 'Posted an update', 'buddypress' ) );
 
 
 
665
 
 
666
  do_action( 'updates_register_activity_actions' );
667
  }
668
+ add_action( 'bp_register_activity_actions', 'updates_register_activity_actions' );
669
 
670
  /******************************************************************************
671
  * Business functions are where all the magic happens in BuddyPress. They will
677
  /**
678
  * Retrieve an activity or activities
679
  *
680
+ * @since 1.2.0
681
  *
682
  * @param array $args
683
  *
691
  */
692
  function bp_activity_get( $args = '' ) {
693
  $defaults = array(
694
+ 'max' => false, // Maximum number of results to return
695
+ 'page' => 1, // page 1 without a per_page will result in no pagination.
696
+ 'per_page' => false, // results per page
697
+ 'sort' => 'DESC', // sort ASC or DESC
698
+ 'display_comments' => false, // false for no comments. 'stream' for within stream display, 'threaded' for below each activity item
699
+
700
+ 'search_terms' => false, // Pass search terms as a string
701
+ 'show_hidden' => false, // Show activity items that are hidden site-wide?
702
+ 'exclude' => false, // Comma-separated list of activity IDs to exclude
703
+ 'in' => false, // Comma-separated list or array of activity IDs to which you want to limit the query
 
704
 
705
  /**
706
  * Pass filters as an array -- all filter items can be multiple values comma separated:
718
  extract( $r, EXTR_SKIP );
719
 
720
  // Attempt to return a cached copy of the first page of sitewide activity.
721
+ if ( 1 == (int)$page && empty( $max ) && empty( $search_terms ) && empty( $filter ) && 'DESC' == $sort && empty( $exclude ) ) {
722
  if ( !$activity = wp_cache_get( 'bp_activity_sitewide_front', 'bp' ) ) {
723
+ $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden );
 
 
 
 
 
 
 
 
 
 
 
724
  wp_cache_set( 'bp_activity_sitewide_front', $activity, 'bp' );
725
  }
726
+ } else
727
+ $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden, $exclude, $in );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
728
 
729
  return apply_filters_ref_array( 'bp_activity_get', array( &$activity, &$r ) );
730
  }
732
  /**
733
  * Fetch specific activity items
734
  *
735
+ * @since 1.2.0
736
  *
737
  * @param array $args See docs for $defaults for details
738
  *
744
  */
745
  function bp_activity_get_specific( $args = '' ) {
746
  $defaults = array(
747
+ 'activity_ids' => false, // A single activity_id or array of IDs.
748
+ 'page' => 1, // page 1 without a per_page will result in no pagination.
749
+ 'per_page' => false, // results per page
750
+ 'max' => false, // Maximum number of results to return
751
+ 'sort' => 'DESC', // sort ASC or DESC
752
+ 'display_comments' => false, // true or false to display threaded comments for these specific activity items
753
+ 'show_hidden' => true // When fetching specific items, show all
 
754
  );
755
  $r = wp_parse_args( $args, $defaults );
756
  extract( $r, EXTR_SKIP );
757
 
758
+ return apply_filters( 'bp_activity_get_specific', BP_Activity_Activity::get( $max, $page, $per_page, $sort, false, false, $display_comments, $show_hidden, false, $activity_ids ) );
 
 
 
 
 
 
 
 
 
 
759
  }
760
 
761
  /**
762
  * Add an activity item
763
  *
764
+ * @since 1.1.0
765
  *
766
  * @param array $args See docs for $defaults for details
767
  *
768
+ * @global object $bp BuddyPress global settings
769
  * @uses wp_parse_args()
770
  * @uses BP_Activity_Activity::save() {@link BP_Activity_Activity}
771
  * @uses BP_Activity_Activity::rebuild_activity_comment_tree() {@link BP_Activity_Activity}
775
  * @return int The activity id
776
  */
777
  function bp_activity_add( $args = '' ) {
778
+ global $bp;
779
 
780
  $defaults = array(
781
  'id' => false, // Pass an existing activity ID to update an existing entry.
787
  'type' => false, // The activity type e.g. activity_update, profile_updated
788
  'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink)
789
 
790
+ '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.
791
  'item_id' => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id
792
  'secondary_item_id' => false, // Optional: A second ID used to further filter e.g. a comment_id
793
  'recorded_time' => bp_core_current_time(), // The GMT time that this activity was recorded
794
+ 'hide_sitewide' => false // Should this be hidden on the sitewide activity stream?
 
795
  );
796
  $params = wp_parse_args( $args, $defaults );
797
  extract( $params, EXTR_SKIP );
815
  $activity->secondary_item_id = $secondary_item_id;
816
  $activity->date_recorded = $recorded_time;
817
  $activity->hide_sitewide = $hide_sitewide;
 
818
 
819
  if ( !$activity->save() )
820
  return false;
832
  /**
833
  * Post an activity update
834
  *
835
+ * @since 1.2.0
836
  *
837
  * @param array $args See docs for $defaults for details
838
  *
839
  * @global object $bp BuddyPress global settings
840
  * @uses wp_parse_args()
841
+ * @uses bp_core_is_user_spammer()
842
+ * @uses bp_core_is_user_deleted()
843
  * @uses bp_core_get_userlink()
844
  * @uses bp_activity_add()
845
  * @uses apply_filters() To call the 'bp_activity_new_update_action' hook
856
 
857
  $defaults = array(
858
  'content' => false,
859
+ 'user_id' => $bp->loggedin_user->id
860
  );
861
  $r = wp_parse_args( $args, $defaults );
862
  extract( $r, EXTR_SKIP );
864
  if ( empty( $content ) || !strlen( trim( $content ) ) )
865
  return false;
866
 
867
+ if ( bp_core_is_user_spammer( $user_id ) || bp_core_is_user_deleted( $user_id ) )
868
  return false;
869
 
870
  // Record this on the user's profile
883
  'type' => 'activity_update'
884
  ) );
885
 
 
 
886
  // Add this update to the "latest update" usermeta so it can be fetched anywhere.
887
+ bp_update_user_meta( $bp->loggedin_user->id, 'bp_latest_update', array( 'id' => $activity_id, 'content' => wp_filter_kses( $content ) ) );
888
 
889
  do_action( 'bp_activity_posted_update', $content, $user_id, $activity_id );
890
 
894
  /**
895
  * Add an activity comment
896
  *
897
+ * @since 1.2.0
898
  *
899
  * @param array $args See docs for $defaults for details
900
  *
915
  $defaults = array(
916
  'id' => false,
917
  'content' => false,
918
+ 'user_id' => $bp->loggedin_user->id,
919
  'activity_id' => false, // ID of the root activity item
920
  'parent_id' => false // ID of a parent comment (optional)
921
  );
923
  $params = wp_parse_args( $args, $defaults );
924
  extract( $params, EXTR_SKIP );
925
 
926
+ if ( empty($content) || empty($user_id) || empty($activity_id) )
927
  return false;
928
 
929
+ if ( empty($parent_id) )
930
  $parent_id = $activity_id;
931
 
932
  // Check to see if the parent activity is hidden, and if so, hide this comment publically.
933
  $activity = new BP_Activity_Activity( $activity_id );
934
+ $is_hidden = ( (int)$activity->hide_sitewide ) ? 1 : 0;
935
 
936
  // Insert the activity comment
937
  $comment_id = bp_activity_add( array(
938
+ 'id' => $id,
939
+ 'action' => apply_filters( 'bp_activity_comment_action', sprintf( __( '%s posted a new activity comment', 'buddypress' ), bp_core_get_userlink( $user_id ) ) ),
940
+ 'content' => apply_filters( 'bp_activity_comment_content', $content ),
941
+ 'component' => $bp->activity->id,
942
+ 'type' => 'activity_comment',
943
+ 'user_id' => $user_id,
944
+ 'item_id' => $activity_id,
945
  'secondary_item_id' => $parent_id,
946
+ 'hide_sitewide' => $is_hidden
947
  ) );
948
 
949
  // Send an email notification if settings allow
960
  /**
961
  * Fetch the activity_id for an existing activity entry in the DB.
962
  *
963
+ * @since 1.2.0
964
  *
965
  * @param array $args See docs for $defaults for details
966
  *
1001
  *
1002
  * If you are deleting an activity comment please use bp_activity_delete_comment();
1003
  *
1004
+ * @since 1.0.0
1005
  *
1006
  * @param array $args See docs for $defaults for details
1007
  *
1008
+ * @global object $bp BuddyPress global settings
1009
  * @uses wp_parse_args()
1010
  * @uses bp_activity_adjust_mention_count()
1011
  * @uses BP_Activity_Activity::delete() {@link BP_Activity_Activity}
1019
  * @return bool True on success, false on failure
1020
  */
1021
  function bp_activity_delete( $args = '' ) {
1022
+ global $bp;
1023
 
1024
  // Pass one or more the of following variables to delete by those variables
1025
  $defaults = array(
1046
 
1047
  // Check if the user's latest update has been deleted
1048
  if ( empty( $args['user_id'] ) )
1049
+ $user_id = $bp->loggedin_user->id;
1050
  else
1051
  $user_id = $args['user_id'];
1052
 
1054
 
1055
  $latest_update = bp_get_user_meta( $user_id, 'bp_latest_update', true );
1056
  if ( !empty( $latest_update ) ) {
1057
+ if ( in_array( (int)$latest_update['id'], (array)$activity_ids_deleted ) )
1058
  bp_delete_user_meta( $user_id, 'bp_latest_update' );
 
1059
  }
1060
 
1061
  do_action( 'bp_activity_delete', $args );
1071
  *
1072
  * You should use bp_activity_delete() instead
1073
  *
1074
+ * @since 1.1.0
1075
+ * @deprecated 1.2.0
1076
  *
1077
  * @param array $args See docs for $defaults for details
1078
  *
1079
+ * @global object $bp BuddyPress global settings
1080
  * @uses wp_parse_args()
1081
  * @uses bp_activity_delete()
1082
  *
1083
  * @return bool True on success, false on failure
1084
  */
1085
  function bp_activity_delete_by_item_id( $args = '' ) {
1086
+ global $bp;
1087
 
1088
+ $defaults = array( 'item_id' => false, 'component' => false, 'type' => false, 'user_id' => false, 'secondary_item_id' => false );
 
 
 
 
 
 
1089
  $r = wp_parse_args( $args, $defaults );
1090
  extract( $r, EXTR_SKIP );
1091
 
1097
  *
1098
  * You should use bp_activity_delete() instead
1099
  *
1100
+ * @since 1.1.0
1101
+ * @deprecated 1.2.0
1102
  *
1103
  * @param int $activity_id The activity id
1104
  *
1115
  *
1116
  * You should use bp_activity_delete() instead
1117
  *
1118
+ * @since 1.1.0
1119
+ * @deprecated 1.2.0
1120
  *
1121
  * @param int $user_id The user id
1122
  * @param string $content The activity id
1136
  *
1137
  * You should use bp_activity_delete() instead
1138
  *
1139
+ * @since 1.1.0
1140
+ * @deprecated 1.2.0
1141
  *
1142
  * @param int $user_id The user id
1143
  * @param string $component The activity component
1153
  /**
1154
  * Delete an activity comment
1155
  *
1156
+ * @since 1.2.0
1157
  *
1158
  * @param int $activity_id The activity id
1159
  * @param int $comment_id The activity comment id
1192
  /**
1193
  * Delete an activity comment's children
1194
  *
1195
+ * @since 1.2.0
1196
  *
1197
  * @param int $activity_id The activity id
1198
  * @param int $comment_id The activity comment id
1204
  function bp_activity_delete_children( $activity_id, $comment_id) {
1205
  // Recursively delete all children of this comment.
1206
  if ( $children = BP_Activity_Activity::get_child_comments( $comment_id ) ) {
1207
+ foreach( (array)$children as $child )
1208
  bp_activity_delete_children( $activity_id, $child->id );
 
1209
  }
1210
  bp_activity_delete( array( 'secondary_item_id' => $comment_id, 'type' => 'activity_comment', 'item_id' => $activity_id ) );
1211
  }
1217
  * object. To save yourself some processing overhead, be sure to pass the full $activity_obj param
1218
  * as well, if you already have it available.
1219
  *
1220
+ * @since 1.2.0
1221
  *
1222
  * @param int $activity_id The unique id of the activity object
1223
  * @param object $activity_obj (optional) The activity object
1224
  *
1225
+ * @global object $bp BuddyPress global settings
1226
  * @uses bp_get_root_domain()
1227
  * @uses bp_get_activity_root_slug()
1228
  * @uses apply_filters_ref_array() To call the 'bp_activity_get_permalink' hook
1230
  * @return string $link Permalink for the activity item
1231
  */
1232
  function bp_activity_get_permalink( $activity_id, $activity_obj = false ) {
1233
+ global $bp;
1234
 
1235
+ if ( !$activity_obj )
1236
  $activity_obj = new BP_Activity_Activity( $activity_id );
1237
 
1238
  if ( isset( $activity_obj->current_comment ) ) {
1239
  $activity_obj = $activity_obj->current_comment;
1240
  }
1241
 
1242
+ 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 )
1243
  $link = $activity_obj->primary_link;
1244
+ else {
1245
+ if ( 'activity_comment' == $activity_obj->type )
1246
  $link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $activity_obj->item_id . '/';
1247
+ else
1248
  $link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $activity_obj->id . '/';
 
1249
  }
1250
 
1251
  return apply_filters_ref_array( 'bp_activity_get_permalink', array( $link, &$activity_obj ) );
1254
  /**
1255
  * Hide a user's activity
1256
  *
1257
+ * @since 1.2.0
1258
  *
1259
  * @param int $user_id The user id
1260
  *
1269
  /**
1270
  * Take content, remove all images and replace them with one thumbnail image.
1271
  *
1272
+ * @since 1.2.0
1273
  *
1274
  * @param string $content The content to work with
1275
  * @param string $link Optional. The URL that the image should link to
1280
  * @return string $content The content with images stripped and replaced with a single thumb.
1281
  */
1282
  function bp_activity_thumbnail_content_images( $content, $link = false ) {
1283
+ global $post;
1284
 
1285
  preg_match_all( '/<img[^>]*>/Ui', $content, $matches );
1286
+ $content = preg_replace('/<img[^>]*>/Ui', '', $content );
1287
+
1288
  if ( !empty( $matches ) && !empty( $matches[0] ) ) {
1289
  // Get the SRC value
1290
  preg_match( '/<img.*?(src\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $src );
1291
 
1292
  // Get the width and height
1293
  preg_match( '/<img.*?(height\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $height );
1294
+ preg_match( '/<img.*?(width\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $width );
1295
 
1296
  if ( !empty( $src ) ) {
1297
+ $src = substr( substr( str_replace( 'src=', '', $src[1] ), 0, -1 ), 1 );
1298
  $height = substr( substr( str_replace( 'height=', '', $height[1] ), 0, -1 ), 1 );
1299
+ $width = substr( substr( str_replace( 'width=', '', $width[1] ), 0, -1 ), 1 );
1300
 
1301
  if ( empty( $width ) || empty( $height ) ) {
1302
+ $width = 100;
1303
  $height = 100;
1304
  }
1305
 
1306
+ $ratio = (int)$width / (int)$height;
1307
+ $new_height = (int)$height >= 100 ? 100 : $height;
1308
+ $new_width = $new_height * $ratio;
1309
 
1310
  $image = '<img src="' . esc_attr( $src ) . '" width="' . $new_width . '" height="' . $new_height . '" alt="' . __( 'Thumbnail', 'buddypress' ) . '" class="align-left thumbnail" />';
1311
 
1320
  return apply_filters( 'bp_activity_thumbnail_content_images', $content, $matches );
1321
  }
1322
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1323
  /** Embeds *******************************************************************/
1324
 
1325
  /**
1329
  * This does not cover recursive activity comments, as they do not use a real loop.
1330
  * For that, see {@link bp_activity_comment_embed()}.
1331
  *
1332
+ * @since 1.5
1333
  *
1334
  * @see BP_Embed
1335
  * @see bp_embed_activity_cache()
1351
  * when BP is recursing through activity comments {@link bp_activity_recurse_comments()}.
1352
  * If no cache and link is embeddable, cache it.
1353
  *
1354
+ * @since 1.5
1355
  *
1356
  * @see BP_Embed
1357
  * @see bp_embed_activity_cache()
1371
  /**
1372
  * When a user clicks on a "Read More" item, make sure embeds are correctly parsed and shown for the expanded content.
1373
  *
1374
+ * @since 1.5
1375
  *
1376
  * @see BP_Embed
1377
  *
1398
  * is rendered to avoid conflict with the 'embed_post_id' filter in
1399
  * {@link bp_activity_embed()} or any other component embeds.
1400
  *
1401
+ * @since 1.5
1402
  *
1403
  * @see bp_activity_comment_embed()
1404
  *
1413
  * Wrapper function for {@link bp_activity_get_meta()}.
1414
  * Used during {@link BP_Embed::parse_oembed()} via {@link bp_activity_embed()}.
1415
  *
1416
+ * @since 1.5
1417
  *
1418
  * @uses bp_activity_get_meta()
1419
  *
1427
  * Wrapper function for {@link bp_activity_update_meta()}.
1428
  * Used during {@link BP_Embed::parse_oembed()} via {@link bp_activity_embed()}.
1429
  *
1430
+ * @since 1.5
1431
  *
1432
  * @uses bp_activity_update_meta()
1433
  */
1434
  function bp_embed_activity_save_cache( $cache, $cachekey, $id ) {
1435
  bp_activity_update_meta( $id, $cachekey, $cache );
1436
  }
1437
+ ?>
 
bp-activity/bp-activity-loader.php CHANGED
@@ -15,15 +15,19 @@ if ( !defined( 'ABSPATH' ) ) exit;
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 creation process
24
  *
25
- * @since BuddyPress (1.5)
26
  */
 
 
 
 
27
  function __construct() {
28
  parent::start(
29
  'activity',
@@ -35,7 +39,7 @@ class BP_Activity_Component extends BP_Component {
35
  /**
36
  * Include files
37
  *
38
- * @since BuddyPress (1.5)
39
  */
40
  function includes() {
41
  // Files to include
@@ -47,17 +51,8 @@ class BP_Activity_Component extends BP_Component {
47
  'template',
48
  'functions',
49
  'notifications',
50
- 'cache'
51
  );
52
 
53
- // Load Akismet support if Akismet is configured
54
- $akismet_key = bp_get_option( 'wordpress_api_key' );
55
- if ( defined( 'AKISMET_VERSION' ) && ( !empty( $akismet_key ) || defined( 'WPCOM_API_KEY' ) ) && apply_filters( 'bp_activity_use_akismet', true ) )
56
- $includes[] = 'akismet';
57
-
58
- if ( is_admin() )
59
- $includes[] = 'admin';
60
-
61
  parent::includes( $includes );
62
  }
63
 
@@ -67,7 +62,7 @@ class BP_Activity_Component extends BP_Component {
67
  * The BP_ACTIVITY_SLUG constant is deprecated, and only used here for
68
  * backwards compatibility.
69
  *
70
- * @since BuddyPress (1.5)
71
  *
72
  * @global object $bp BuddyPress global settings
73
  */
@@ -87,6 +82,7 @@ class BP_Activity_Component extends BP_Component {
87
  // All globals for activity component.
88
  // Note that global_tables is included in this array.
89
  $globals = array(
 
90
  'slug' => BP_ACTIVITY_SLUG,
91
  'root_slug' => isset( $bp->pages->activity->slug ) ? $bp->pages->activity->slug : BP_ACTIVITY_SLUG,
92
  'has_directory' => true,
@@ -101,7 +97,7 @@ class BP_Activity_Component extends BP_Component {
101
  /**
102
  * Setup BuddyBar navigation
103
  *
104
- * @since BuddyPress (1.5)
105
  *
106
  * @global object $bp BuddyPress global settings
107
  * @uses bp_is_active()
@@ -110,8 +106,7 @@ class BP_Activity_Component extends BP_Component {
110
  * @uses bp_get_groups_slug()
111
  */
112
  function setup_nav() {
113
-
114
- $sub_nav = array();
115
 
116
  // Add 'Activity' to the main navigation
117
  $main_nav = array(
@@ -124,14 +119,14 @@ class BP_Activity_Component extends BP_Component {
124
  );
125
 
126
  // Stop if there is no user displayed or logged in
127
- if ( !is_user_logged_in() && !bp_displayed_user_id() )
128
  return;
129
 
130
  // Determine user to use
131
- if ( bp_displayed_user_domain() )
132
- $user_domain = bp_displayed_user_domain();
133
- elseif ( bp_loggedin_user_domain() )
134
- $user_domain = bp_loggedin_user_domain();
135
  else
136
  return;
137
 
@@ -200,9 +195,9 @@ class BP_Activity_Component extends BP_Component {
200
  }
201
 
202
  /**
203
- * Set up the Toolbar
204
  *
205
- * @since BuddyPress (1.5)
206
  *
207
  * @global object $bp BuddyPress global settings
208
  * @uses is_user_logged_in()
@@ -223,13 +218,12 @@ class BP_Activity_Component extends BP_Component {
223
  if ( is_user_logged_in() ) {
224
 
225
  // Setup the logged in user variables
226
- $user_domain = bp_loggedin_user_domain();
227
  $activity_link = trailingslashit( $user_domain . $this->slug );
228
 
229
  // Unread message count
230
- $count = bp_get_total_mention_count_for_user( bp_loggedin_user_id() );
231
- if ( !empty( $count ) ) {
232
- $title = sprintf( __( 'Mentions <span class="count">%s</span>', 'buddypress' ), number_format_i18n( $count ) );
233
  } else {
234
  $title = __( 'Mentions', 'buddypress' );
235
  }
@@ -293,7 +287,7 @@ class BP_Activity_Component extends BP_Component {
293
  /**
294
  * Sets up the title for pages and <title>
295
  *
296
- * @since BuddyPress (1.5)
297
  *
298
  * @global object $bp BuddyPress global settings
299
  * @uses bp_is_activity_component()
@@ -309,35 +303,18 @@ class BP_Activity_Component extends BP_Component {
309
  $bp->bp_options_title = __( 'My Activity', 'buddypress' );
310
  } else {
311
  $bp->bp_options_avatar = bp_core_fetch_avatar( array(
312
- 'item_id' => bp_displayed_user_id(),
313
- 'type' => 'thumb',
314
- 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() )
315
  ) );
316
- $bp->bp_options_title = bp_get_displayed_user_fullname();
317
  }
318
  }
319
 
320
  parent::setup_title();
321
  }
322
-
323
- /**
324
- * Setup the actions
325
- *
326
- * @since 1.6
327
- */
328
- function setup_actions() {
329
- // Spam prevention
330
- add_action( 'bp_include', 'bp_activity_setup_akismet' );
331
-
332
- parent::setup_actions();
333
- }
334
  }
335
 
336
- function bp_setup_activity() {
337
- global $bp;
338
-
339
- $bp->activity = new BP_Activity_Component();
340
- }
341
- add_action( 'bp_setup_components', 'bp_setup_activity', 6 );
342
 
343
- ?>
15
  /**
16
  * Main Activity Class
17
  *
18
+ * @since 1.5.0
19
  */
20
  class BP_Activity_Component extends BP_Component {
21
 
22
  /**
23
  * Start the activity component creation process
24
  *
25
+ * @since 1.5.0
26
  */
27
+ function BP_Activity_Component() {
28
+ $this->__construct();
29
+ }
30
+
31
  function __construct() {
32
  parent::start(
33
  'activity',
39
  /**
40
  * Include files
41
  *
42
+ * @since 1.5.0
43
  */
44
  function includes() {
45
  // Files to include
51
  'template',
52
  'functions',
53
  'notifications',
 
54
  );
55
 
 
 
 
 
 
 
 
 
56
  parent::includes( $includes );
57
  }
58
 
62
  * The BP_ACTIVITY_SLUG constant is deprecated, and only used here for
63
  * backwards compatibility.
64
  *
65
+ * @since 1.5.0
66
  *
67
  * @global object $bp BuddyPress global settings
68
  */
82
  // All globals for activity component.
83
  // Note that global_tables is included in this array.
84
  $globals = array(
85
+ 'path' => BP_PLUGIN_DIR,
86
  'slug' => BP_ACTIVITY_SLUG,
87
  'root_slug' => isset( $bp->pages->activity->slug ) ? $bp->pages->activity->slug : BP_ACTIVITY_SLUG,
88
  'has_directory' => true,
97
  /**
98
  * Setup BuddyBar navigation
99
  *
100
+ * @since 1.5.0
101
  *
102
  * @global object $bp BuddyPress global settings
103
  * @uses bp_is_active()
106
  * @uses bp_get_groups_slug()
107
  */
108
  function setup_nav() {
109
+ global $bp;
 
110
 
111
  // Add 'Activity' to the main navigation
112
  $main_nav = array(
119
  );
120
 
121
  // Stop if there is no user displayed or logged in
122
+ if ( !is_user_logged_in() && !isset( $bp->displayed_user->id ) )
123
  return;
124
 
125
  // Determine user to use
126
+ if ( isset( $bp->displayed_user->domain ) )
127
+ $user_domain = $bp->displayed_user->domain;
128
+ elseif ( isset( $bp->loggedin_user->domain ) )
129
+ $user_domain = $bp->loggedin_user->domain;
130
  else
131
  return;
132
 
195
  }
196
 
197
  /**
198
+ * Set up the admin bar
199
  *
200
+ * @since 1.5.0
201
  *
202
  * @global object $bp BuddyPress global settings
203
  * @uses is_user_logged_in()
218
  if ( is_user_logged_in() ) {
219
 
220
  // Setup the logged in user variables
221
+ $user_domain = $bp->loggedin_user->domain;
222
  $activity_link = trailingslashit( $user_domain . $this->slug );
223
 
224
  // Unread message count
225
+ if ( $count = bp_get_total_mention_count_for_user( bp_loggedin_user_id() ) ) {
226
+ $title = sprintf( __( 'Mentions <span class="count">%s</span>', 'buddypress' ), $count );
 
227
  } else {
228
  $title = __( 'Mentions', 'buddypress' );
229
  }
287
  /**
288
  * Sets up the title for pages and <title>
289
  *
290
+ * @since 1.5.0
291
  *
292
  * @global object $bp BuddyPress global settings
293
  * @uses bp_is_activity_component()
303
  $bp->bp_options_title = __( 'My Activity', 'buddypress' );
304
  } else {
305
  $bp->bp_options_avatar = bp_core_fetch_avatar( array(
306
+ 'item_id' => $bp->displayed_user->id,
307
+ 'type' => 'thumb'
 
308
  ) );
309
+ $bp->bp_options_title = $bp->displayed_user->fullname;
310
  }
311
  }
312
 
313
  parent::setup_title();
314
  }
 
 
 
 
 
 
 
 
 
 
 
 
315
  }
316
 
317
+ // Create the activity component
318
+ $bp->activity = new BP_Activity_Component();
 
 
 
 
319
 
320
+ ?>
bp-activity/bp-activity-notifications.php CHANGED
@@ -13,11 +13,12 @@ if ( !defined( 'ABSPATH' ) ) exit;
13
  /**
14
  * Sends an email notification and a BP notification when someone mentions you in an update
15
  *
16
- * @since BuddyPress (1.2)
17
  *
18
  * @param int $activity_id The id of the activity update
19
  * @param int $receiver_user_id The unique user_id of the user who is receiving the update
20
  *
 
21
  * @uses bp_core_add_notification()
22
  * @uses bp_get_user_meta()
23
  * @uses bp_core_get_user_displayname()
@@ -38,15 +39,7 @@ if ( !defined( 'ABSPATH' ) ) exit;
38
  * @uses do_action() To call the 'bp_activity_sent_mention_email' hook
39
  */
40
  function bp_activity_at_message_notification( $activity_id, $receiver_user_id ) {
41
-
42
- // Don't leave multiple notifications for the same activity item
43
- $notifications = BP_Core_Notification::get_all_for_user( $receiver_user_id, 'all' );
44
-
45
- foreach( $notifications as $notification ) {
46
- if ( $activity_id == $notification->item_id ) {
47
- return;
48
- }
49
- }
50
 
51
  $activity = new BP_Activity_Activity( $activity_id );
52
 
@@ -111,12 +104,13 @@ To view and respond to the message, log in and visit: %3$s
111
  /**
112
  * Sends an email notification and a BP notification when someone mentions you in an update
113
  *
114
- * @since BuddyPress (1.2)
115
  *
116
  * @param int $comment_id The comment id
117
  * @param int $commenter_id The unique user_id of the user who posted the comment
118
  * @param array $params {@link bp_activity_new_comment()}
119
  *
 
120
  * @uses bp_get_user_meta()
121
  * @uses bp_core_get_user_displayname()
122
  * @uses bp_activity_get_permalink()
@@ -138,10 +132,7 @@ To view and respond to the message, log in and visit: %3$s
138
  * @uses do_action() To call the 'bp_activity_sent_reply_to_reply_email' hook
139
  */
140
  function bp_activity_new_comment_notification( $comment_id, $commenter_id, $params ) {
141
-
142
- // Set some default parameters
143
- $activity_id = 0;
144
- $parent_id = 0;
145
 
146
  extract( $params );
147
 
13
  /**
14
  * Sends an email notification and a BP notification when someone mentions you in an update
15
  *
16
+ * @since 1.2.0
17
  *
18
  * @param int $activity_id The id of the activity update
19
  * @param int $receiver_user_id The unique user_id of the user who is receiving the update
20
  *
21
+ * @global object $bp BuddyPress global settings
22
  * @uses bp_core_add_notification()
23
  * @uses bp_get_user_meta()
24
  * @uses bp_core_get_user_displayname()
39
  * @uses do_action() To call the 'bp_activity_sent_mention_email' hook
40
  */
41
  function bp_activity_at_message_notification( $activity_id, $receiver_user_id ) {
42
+ global $bp;
 
 
 
 
 
 
 
 
43
 
44
  $activity = new BP_Activity_Activity( $activity_id );
45
 
104
  /**
105
  * Sends an email notification and a BP notification when someone mentions you in an update
106
  *
107
+ * @since 1.2.0
108
  *
109
  * @param int $comment_id The comment id
110
  * @param int $commenter_id The unique user_id of the user who posted the comment
111
  * @param array $params {@link bp_activity_new_comment()}
112
  *
113
+ * @global object $bp BuddyPress global settings
114
  * @uses bp_get_user_meta()
115
  * @uses bp_core_get_user_displayname()
116
  * @uses bp_activity_get_permalink()
132
  * @uses do_action() To call the 'bp_activity_sent_reply_to_reply_email' hook
133
  */
134
  function bp_activity_new_comment_notification( $comment_id, $commenter_id, $params ) {
135
+ global $bp;
 
 
 
136
 
137
  extract( $params );
138
 
bp-activity/bp-activity-screens.php CHANGED
@@ -13,7 +13,7 @@ if ( !defined( 'ABSPATH' ) ) exit;
13
  /**
14
  * Activity screen index
15
  *
16
- * @since BuddyPress (1.5)
17
  *
18
  * @uses bp_displayed_user_id()
19
  * @uses bp_is_activity_component()
@@ -37,7 +37,7 @@ add_action( 'bp_screens', 'bp_activity_screen_index' );
37
  /**
38
  * Activity screen 'my activity' index
39
  *
40
- * @since BuddyPress (1.0)
41
  *
42
  * @uses do_action() To call the 'bp_activity_screen_my_activity' hook
43
  * @uses bp_core_load_template()
@@ -51,11 +51,11 @@ function bp_activity_screen_my_activity() {
51
  /**
52
  * Activity screen 'friends' index
53
  *
54
- * @since BuddyPress (1.0)
55
  *
56
  * @uses bp_is_active()
57
  * @uses bp_update_is_item_admin()
58
- * @uses bp_current_user_can()
59
  * @uses do_action() To call the 'bp_activity_screen_friends' hook
60
  * @uses bp_core_load_template()
61
  * @uses apply_filters() To call the 'bp_activity_template_friends_activity' hook
@@ -64,7 +64,7 @@ function bp_activity_screen_friends() {
64
  if ( !bp_is_active( 'friends' ) )
65
  return false;
66
 
67
- bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' );
68
  do_action( 'bp_activity_screen_friends' );
69
  bp_core_load_template( apply_filters( 'bp_activity_template_friends_activity', 'members/single/home' ) );
70
  }
@@ -72,11 +72,11 @@ function bp_activity_screen_friends() {
72
  /**
73
  * Activity screen 'groups' index
74
  *
75
- * @since BuddyPress (1.2)
76
  *
77
  * @uses bp_is_active()
78
  * @uses bp_update_is_item_admin()
79
- * @uses bp_current_user_can()
80
  * @uses do_action() To call the 'bp_activity_screen_groups' hook
81
  * @uses bp_core_load_template()
82
  * @uses apply_filters() To call the 'bp_activity_template_groups_activity' hook
@@ -85,7 +85,7 @@ function bp_activity_screen_groups() {
85
  if ( !bp_is_active( 'groups' ) )
86
  return false;
87
 
88
- bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' );
89
  do_action( 'bp_activity_screen_groups' );
90
  bp_core_load_template( apply_filters( 'bp_activity_template_groups_activity', 'members/single/home' ) );
91
  }
@@ -93,16 +93,16 @@ function bp_activity_screen_groups() {
93
  /**
94
  * Activity screen 'favorites' index
95
  *
96
- * @since BuddyPress (1.2)
97
  *
98
  * @uses bp_update_is_item_admin()
99
- * @uses bp_current_user_can()
100
  * @uses do_action() To call the 'bp_activity_screen_favorites' hook
101
  * @uses bp_core_load_template()
102
  * @uses apply_filters() To call the 'bp_activity_template_favorite_activity' hook
103
  */
104
  function bp_activity_screen_favorites() {
105
- bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' );
106
  do_action( 'bp_activity_screen_favorites' );
107
  bp_core_load_template( apply_filters( 'bp_activity_template_favorite_activity', 'members/single/home' ) );
108
  }
@@ -110,16 +110,16 @@ function bp_activity_screen_favorites() {
110
  /**
111
  * Activity screen 'mentions' index
112
  *
113
- * @since BuddyPress (1.2)
114
  *
115
  * @uses bp_update_is_item_admin()
116
- * @uses bp_current_user_can()
117
  * @uses do_action() To call the 'bp_activity_screen_mentions' hook
118
  * @uses bp_core_load_template()
119
  * @uses apply_filters() To call the 'bp_activity_template_mention_activity' hook
120
  */
121
  function bp_activity_screen_mentions() {
122
- bp_update_is_item_admin( bp_current_user_can( 'bp_moderate' ), 'activity' );
123
  do_action( 'bp_activity_screen_mentions' );
124
  bp_core_load_template( apply_filters( 'bp_activity_template_mention_activity', 'members/single/home' ) );
125
  }
@@ -128,7 +128,7 @@ function bp_activity_screen_mentions() {
128
  * Removes activity notifications from the notification menu when a user clicks on them and
129
  * is taken to a specific screen.
130
  *
131
- * @since BuddyPress (1.5)
132
  *
133
  * @global object $bp BuddyPress global settings
134
  * @uses bp_core_delete_notifications_by_type()
@@ -136,7 +136,7 @@ function bp_activity_screen_mentions() {
136
  function bp_activity_remove_screen_notifications() {
137
  global $bp;
138
 
139
- bp_core_delete_notifications_by_type( bp_loggedin_user_id(), $bp->activity->id, 'new_at_mention' );
140
  }
141
  add_action( 'bp_activity_screen_my_activity', 'bp_activity_remove_screen_notifications' );
142
  add_action( 'bp_activity_screen_single_activity_permalink', 'bp_activity_remove_screen_notifications' );
@@ -145,7 +145,7 @@ add_action( 'bp_activity_screen_mentions', 'bp_activity_remove_
145
  /**
146
  * Reset the logged-in user's new mentions data when he visits his mentions screen
147
  *
148
- * @since BuddyPress (1.5)
149
  *
150
  * @uses bp_is_my_profile()
151
  * @uses bp_activity_clear_new_mentions()
@@ -160,7 +160,7 @@ add_action( 'bp_activity_screen_mentions', 'bp_activity_reset_my_new_mentions' )
160
  /**
161
  * Reset the logged-in user's new mentions data when he visits his mentions screen
162
  *
163
- * @since BuddyPress (1.2)
164
  *
165
  * @global object $bp BuddyPress global settings
166
  * @uses bp_is_activity_component()
@@ -190,11 +190,11 @@ function bp_activity_screen_single_activity_permalink() {
190
  if ( !bp_is_activity_component() )
191
  return false;
192
 
193
- if ( ! bp_current_action() || !is_numeric( bp_current_action() ) )
194
  return false;
195
 
196
  // Get the activity details
197
- $activity = bp_activity_get_specific( array( 'activity_ids' => bp_current_action(), 'show_hidden' => true, 'spam' => 'ham_only', ) );
198
 
199
  // 404 if activity does not exist
200
  if ( empty( $activity['activities'][0] ) || bp_action_variables() ) {
@@ -225,7 +225,7 @@ function bp_activity_screen_single_activity_permalink() {
225
  if ( 'public' != $group->status ) {
226
 
227
  // User is not a member of group
228
- if ( !groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) {
229
  $has_access = false;
230
  }
231
  }
@@ -246,8 +246,8 @@ function bp_activity_screen_single_activity_permalink() {
246
 
247
  // Redirect based on logged in status
248
  is_user_logged_in() ?
249
- bp_core_redirect( bp_loggedin_user_domain() ) :
250
- 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() . '/' ) ) );
251
  }
252
 
253
  bp_core_load_template( apply_filters( 'bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink' ) );
@@ -257,18 +257,20 @@ add_action( 'bp_screens', 'bp_activity_screen_single_activity_permalink' );
257
  /**
258
  * Add activity notifications settings to the notifications settings page
259
  *
260
- * @since BuddyPress (1.2)
261
  *
 
262
  * @uses bp_get_user_meta()
263
  * @uses bp_core_get_username()
264
  * @uses do_action() To call the 'bp_activity_screen_notification_settings' hook
265
  */
266
  function bp_activity_screen_notification_settings() {
 
267
 
268
- if ( !$mention = bp_get_user_meta( bp_displayed_user_id(), 'notification_activity_new_mention', true ) )
269
  $mention = 'yes';
270
 
271
- if ( !$reply = bp_get_user_meta( bp_displayed_user_id(), 'notification_activity_new_reply', true ) )
272
  $reply = 'yes'; ?>
273
 
274
  <table class="notification-settings" id="activity-notification-settings">
@@ -284,7 +286,7 @@ function bp_activity_screen_notification_settings() {
284
  <tbody>
285
  <tr id="activity-notification-settings-mentions">
286
  <td>&nbsp;</td>
287
- <td><?php printf( __( 'A member mentions you in an update using "@%s"', 'buddypress' ), bp_core_get_username( bp_displayed_user_id() ) ) ?></td>
288
  <td class="yes"><input type="radio" name="notifications[notification_activity_new_mention]" value="yes" <?php checked( $mention, 'yes', true ) ?>/></td>
289
  <td class="no"><input type="radio" name="notifications[notification_activity_new_mention]" value="no" <?php checked( $mention, 'no', true ) ?>/></td>
290
  </tr>
@@ -303,4 +305,4 @@ function bp_activity_screen_notification_settings() {
303
  }
304
  add_action( 'bp_notification_settings', 'bp_activity_screen_notification_settings', 1 );
305
 
306
- ?>
13
  /**
14
  * Activity screen index
15
  *
16
+ * @since 1.5.0
17
  *
18
  * @uses bp_displayed_user_id()
19
  * @uses bp_is_activity_component()
37
  /**
38
  * Activity screen 'my activity' index
39
  *
40
+ * @since 1.0.0
41
  *
42
  * @uses do_action() To call the 'bp_activity_screen_my_activity' hook
43
  * @uses bp_core_load_template()
51
  /**
52
  * Activity screen 'friends' index
53
  *
54
+ * @since 1.0.0
55
  *
56
  * @uses bp_is_active()
57
  * @uses bp_update_is_item_admin()
58
+ * @uses is_super_admin()
59
  * @uses do_action() To call the 'bp_activity_screen_friends' hook
60
  * @uses bp_core_load_template()
61
  * @uses apply_filters() To call the 'bp_activity_template_friends_activity' hook
64
  if ( !bp_is_active( 'friends' ) )
65
  return false;
66
 
67
+ bp_update_is_item_admin( is_super_admin(), 'activity' );
68
  do_action( 'bp_activity_screen_friends' );
69
  bp_core_load_template( apply_filters( 'bp_activity_template_friends_activity', 'members/single/home' ) );
70
  }
72
  /**
73
  * Activity screen 'groups' index
74
  *
75
+ * @since 1.2.0
76
  *
77
  * @uses bp_is_active()
78
  * @uses bp_update_is_item_admin()
79
+ * @uses is_super_admin()
80
  * @uses do_action() To call the 'bp_activity_screen_groups' hook
81
  * @uses bp_core_load_template()
82
  * @uses apply_filters() To call the 'bp_activity_template_groups_activity' hook
85
  if ( !bp_is_active( 'groups' ) )
86
  return false;
87
 
88
+ bp_update_is_item_admin( is_super_admin(), 'activity' );
89
  do_action( 'bp_activity_screen_groups' );
90
  bp_core_load_template( apply_filters( 'bp_activity_template_groups_activity', 'members/single/home' ) );
91
  }
93
  /**
94
  * Activity screen 'favorites' index
95
  *
96
+ * @since 1.2.0
97
  *
98
  * @uses bp_update_is_item_admin()
99
+ * @uses is_super_admin()
100
  * @uses do_action() To call the 'bp_activity_screen_favorites' hook
101
  * @uses bp_core_load_template()
102
  * @uses apply_filters() To call the 'bp_activity_template_favorite_activity' hook
103
  */
104
  function bp_activity_screen_favorites() {
105
+ bp_update_is_item_admin( is_super_admin(), 'activity' );
106
  do_action( 'bp_activity_screen_favorites' );
107
  bp_core_load_template( apply_filters( 'bp_activity_template_favorite_activity', 'members/single/home' ) );
108
  }
110
  /**
111
  * Activity screen 'mentions' index
112
  *
113
+ * @since 1.2.0
114
  *
115
  * @uses bp_update_is_item_admin()
116
+ * @uses is_super_admin()
117
  * @uses do_action() To call the 'bp_activity_screen_mentions' hook
118
  * @uses bp_core_load_template()
119
  * @uses apply_filters() To call the 'bp_activity_template_mention_activity' hook
120
  */
121
  function bp_activity_screen_mentions() {
122
+ bp_update_is_item_admin( is_super_admin(), 'activity' );
123
  do_action( 'bp_activity_screen_mentions' );
124
  bp_core_load_template( apply_filters( 'bp_activity_template_mention_activity', 'members/single/home' ) );
125
  }
128
  * Removes activity notifications from the notification menu when a user clicks on them and
129
  * is taken to a specific screen.
130
  *
131
+ * @since 1.5.0
132
  *
133
  * @global object $bp BuddyPress global settings
134
  * @uses bp_core_delete_notifications_by_type()
136
  function bp_activity_remove_screen_notifications() {
137
  global $bp;
138
 
139
+ bp_core_delete_notifications_by_type( $bp->loggedin_user->id, $bp->activity->id, 'new_at_mention' );
140
  }
141
  add_action( 'bp_activity_screen_my_activity', 'bp_activity_remove_screen_notifications' );
142
  add_action( 'bp_activity_screen_single_activity_permalink', 'bp_activity_remove_screen_notifications' );
145
  /**
146
  * Reset the logged-in user's new mentions data when he visits his mentions screen
147
  *
148
+ * @since 1.5.0
149
  *
150
  * @uses bp_is_my_profile()
151
  * @uses bp_activity_clear_new_mentions()
160
  /**
161
  * Reset the logged-in user's new mentions data when he visits his mentions screen
162
  *
163
+ * @since 1.2.0
164
  *
165
  * @global object $bp BuddyPress global settings
166
  * @uses bp_is_activity_component()
190
  if ( !bp_is_activity_component() )
191
  return false;
192
 
193
+ if ( empty( $bp->current_action ) || !is_numeric( $bp->current_action ) )
194
  return false;
195
 
196
  // Get the activity details
197
+ $activity = bp_activity_get_specific( array( 'activity_ids' => bp_current_action(), 'show_hidden' => true ) );
198
 
199
  // 404 if activity does not exist
200
  if ( empty( $activity['activities'][0] ) || bp_action_variables() ) {
225
  if ( 'public' != $group->status ) {
226
 
227
  // User is not a member of group
228
+ if ( !groups_is_user_member( $bp->loggedin_user->id, $group->id ) ) {
229
  $has_access = false;
230
  }
231
  }
246
 
247
  // Redirect based on logged in status
248
  is_user_logged_in() ?
249
+ bp_core_redirect( $bp->loggedin_user->domain ) :
250
+ 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 ) ) );
251
  }
252
 
253
  bp_core_load_template( apply_filters( 'bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink' ) );
257
  /**
258
  * Add activity notifications settings to the notifications settings page
259
  *
260
+ * @since 1.2.0
261
  *
262
+ * @global object $bp BuddyPress global settings
263
  * @uses bp_get_user_meta()
264
  * @uses bp_core_get_username()
265
  * @uses do_action() To call the 'bp_activity_screen_notification_settings' hook
266
  */
267
  function bp_activity_screen_notification_settings() {
268
+ global $bp;
269
 
270
+ if ( !$mention = bp_get_user_meta( $bp->displayed_user->id, 'notification_activity_new_mention', true ) )
271
  $mention = 'yes';
272
 
273
+ if ( !$reply = bp_get_user_meta( $bp->displayed_user->id, 'notification_activity_new_reply', true ) )
274
  $reply = 'yes'; ?>
275
 
276
  <table class="notification-settings" id="activity-notification-settings">
286
  <tbody>
287
  <tr id="activity-notification-settings-mentions">
288
  <td>&nbsp;</td>
289
+ <td><?php printf( __( 'A member mentions you in an update using "@%s"', 'buddypress' ), bp_core_get_username( $bp->displayed_user->id, $bp->displayed_user->userdata->user_nicename, $bp->displayed_user->userdata->user_login ) ) ?></td>
290
  <td class="yes"><input type="radio" name="notifications[notification_activity_new_mention]" value="yes" <?php checked( $mention, 'yes', true ) ?>/></td>
291
  <td class="no"><input type="radio" name="notifications[notification_activity_new_mention]" value="no" <?php checked( $mention, 'no', true ) ?>/></td>
292
  </tr>
305
  }
306
  add_action( 'bp_notification_settings', 'bp_activity_screen_notification_settings', 1 );
307
 
308
+ ?>
bp-activity/bp-activity-template.php CHANGED
@@ -13,7 +13,7 @@ if ( !defined( 'ABSPATH' ) ) exit;
13
  /**
14
  * Output the activity component slug
15
  *
16
- * @since BuddyPress (1.5)
17
  *
18
  * @uses bp_get_activity_slug()
19
  */
@@ -23,7 +23,7 @@ function bp_activity_slug() {
23
  /**
24
  * Return the activity component slug
25
  *
26
- * @since BuddyPress (1.5)
27
  *
28
  * @global object $bp BuddyPress global settings
29
  * @uses apply_filters() To call the 'bp_get_activity_slug' hook
@@ -36,7 +36,7 @@ function bp_activity_slug() {
36
  /**
37
  * Output the activity component root slug
38
  *
39
- * @since BuddyPress (1.5)
40
  *
41
  * @uses bp_get_activity_root_slug()
42
  */
@@ -46,7 +46,7 @@ function bp_activity_root_slug() {
46
  /**
47
  * Return the activity component root slug
48
  *
49
- * @since BuddyPress (1.5)
50
  *
51
  * @global object $bp BuddyPress global settings
52
  * @uses apply_filters() To call the 'bp_get_activity_root_slug' hook
@@ -59,7 +59,7 @@ function bp_activity_root_slug() {
59
  /**
60
  * Output member directory permalink
61
  *
62
- * @since BuddyPress (1.5)
63
  *
64
  * @uses bp_get_activity_directory_permalink()
65
  */
@@ -69,7 +69,7 @@ function bp_activity_directory_permalink() {
69
  /**
70
  * Return member directory permalink
71
  *
72
- * @since BuddyPress (1.5)
73
  *
74
  * @uses traisingslashit()
75
  * @uses bp_get_root_domain()
@@ -87,7 +87,7 @@ function bp_activity_directory_permalink() {
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;
@@ -104,80 +104,33 @@ class BP_Activity_Template {
104
 
105
  var $full_name;
106
 
107
- /**
108
- * Constructor method
109
- *
110
- * See definition of $defaults below, as well as $defaults in bp_has_activities(), for
111
- * description of $args array
112
- *
113
- * @param array $args
114
- */
115
- function __construct( $args ) {
116
  global $bp;
117
 
118
- // Backward compatibility with old method of passing arguments
119
- if ( !is_array( $args ) || func_num_args() > 1 ) {
120
- _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__ ) );
121
-
122
- $old_args_keys = array(
123
- 0 => 'page',
124
- 1 => 'per_page',
125
- 2 => 'max',
126
- 3 => 'include',
127
- 4 => 'sort',
128
- 5 => 'filter',
129
- 6 => 'search_terms',
130
- 7 => 'display_comments',
131
- 8 => 'show_hidden',
132
- 9 => 'exclude',
133
- 10 => 'in',
134
- 11 => 'spam',
135
- 12 => 'page_arg'
136
- );
137
-
138
- $func_args = func_get_args();
139
- $args = bp_core_parse_args_array( $old_args_keys, $func_args );
140
- }
141
-
142
- $defaults = array(
143
- 'page' => 1,
144
- 'per_page' => 20,
145
- 'page_arg' => 'acpage',
146
- 'max' => false,
147
- 'sort' => false,
148
- 'include' => false,
149
- 'exclude' => false,
150
- 'in' => false,
151
- 'filter' => false,
152
- 'search_terms' => false,
153
- 'display_comments' => 'threaded',
154
- 'show_hidden' => false,
155
- 'spam' => 'ham_only',
156
- );
157
- $r = wp_parse_args( $args, $defaults );
158
- extract( $r );
159
-
160
- $this->pag_page = isset( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[$page_arg] ) : $page;
161
  $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
162
 
163
  // Check if blog/forum replies are disabled
164
  $this->disable_blogforum_replies = isset( $bp->site_options['bp-disable-blogforum-comments'] ) ? $bp->site_options['bp-disable-blogforum-comments'] : false;
165
 
166
  // Get an array of the logged in user's favorite activities
167
- $this->my_favs = maybe_unserialize( bp_get_user_meta( bp_loggedin_user_id(), 'bp_favorite_activities', true ) );
168
 
169
  // Fetch specific activity items based on ID's
170
  if ( !empty( $include ) )
171
- $this->activities = bp_activity_get_specific( array( 'activity_ids' => explode( ',', $include ), 'max' => $max, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'sort' => $sort, 'display_comments' => $display_comments, 'show_hidden' => $show_hidden, 'spam' => $spam ) );
172
-
173
  // Fetch all activity items
174
  else
175
- $this->activities = bp_activity_get( array( 'display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter, 'show_hidden' => $show_hidden, 'exclude' => $exclude, 'in' => $in, 'spam' => $spam ) );
176
 
177
- if ( !$max || $max >= (int) $this->activities['total'] )
178
- $this->total_activity_count = (int) $this->activities['total'];
179
  else
180
- $this->total_activity_count = (int) $max;
181
 
182
  $this->activities = $this->activities['activities'];
183
 
@@ -185,16 +138,16 @@ class BP_Activity_Template {
185
  if ( $max >= count($this->activities) ) {
186
  $this->activity_count = count( $this->activities );
187
  } else {
188
- $this->activity_count = (int) $max;
189
  }
190
  } else {
191
  $this->activity_count = count( $this->activities );
192
  }
193
 
194
- $this->full_name = bp_get_displayed_user_fullname();
195
 
196
  // Fetch parent content for activity comments so we do not have to query in the loop
197
- foreach ( (array) $this->activities as $activity ) {
198
  if ( 'activity_comment' != $activity->type )
199
  continue;
200
 
@@ -211,12 +164,12 @@ class BP_Activity_Template {
211
  unset( $activity_parents );
212
  }
213
 
214
- if ( (int) $this->total_activity_count && (int) $this->pag_num ) {
215
  $this->pag_links = paginate_links( array(
216
- 'base' => add_query_arg( $page_arg, '%#%' ),
217
  'format' => '',
218
- 'total' => ceil( (int) $this->total_activity_count / (int) $this->pag_num ),
219
- 'current' => (int) $this->pag_page,
220
  'prev_text' => _x( '&larr;', 'Activity pagination previous text', 'buddypress' ),
221
  'next_text' => _x( '&rarr;', 'Activity pagination next text', 'buddypress' ),
222
  'mid_size' => 1
@@ -259,9 +212,10 @@ class BP_Activity_Template {
259
  }
260
 
261
  function the_activity() {
 
262
 
263
  $this->in_the_loop = true;
264
- $this->activity = $this->next_activity();
265
 
266
  if ( is_array( $this->activity ) )
267
  $this->activity = (object) $this->activity;
@@ -276,7 +230,7 @@ class BP_Activity_Template {
276
  *
277
  * Based on the $args passed, bp_has_activities() populates the $activities_template global.
278
  *
279
- * @since BuddyPress (1.0)
280
  *
281
  * @param array $args Arguments for limiting the contents of the activity loop. Can be passed as an associative array or as a URL argument string
282
  *
@@ -313,21 +267,21 @@ function bp_has_activities( $args = '' ) {
313
  $primary_id = false;
314
 
315
  // User filtering
316
- if ( bp_displayed_user_id() )
317
- $user_id = bp_displayed_user_id();
318
 
319
  // Group filtering
320
  if ( !empty( $bp->groups->current_group ) ) {
321
  $object = $bp->groups->id;
322
  $primary_id = $bp->groups->current_group->id;
323
 
324
- 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' ) ) )
325
  $show_hidden = true;
326
  }
327
 
328
  // The default scope should recognize custom slugs
329
- if ( array_key_exists( bp_current_action(), (array) $bp->loaded_components ) ) {
330
- $scope = $bp->loaded_components[bp_current_action()];
331
  }
332
  else
333
  $scope = bp_current_action();
@@ -347,9 +301,6 @@ function bp_has_activities( $args = '' ) {
347
  'per_page' => 20, // number of items per page
348
  'max' => false, // max number to return
349
  'show_hidden' => $show_hidden, // Show activity items that are hidden site-wide?
350
- 'spam' => 'ham_only', // Hide spammed items
351
-
352
- 'page_arg' => 'acpage', // See https://buddypress.trac.wordpress.org/ticket/3679
353
 
354
  // Scope - pre-built activity filters for a user (friends/groups/favorites/mentions)
355
  'scope' => $scope,
@@ -375,11 +326,11 @@ function bp_has_activities( $args = '' ) {
375
 
376
  // determine which user_id applies
377
  if ( empty( $user_id ) )
378
- $user_id = bp_displayed_user_id() ? bp_displayed_user_id() : bp_loggedin_user_id();
379
 
380
  // are we displaying user specific activity?
381
  if ( is_numeric( $user_id ) ) {
382
- $show_hidden = ( $user_id == bp_loggedin_user_id() && $scope != 'friends' ) ? 1 : 0;
383
 
384
  switch ( $scope ) {
385
  case 'friends':
@@ -388,7 +339,7 @@ function bp_has_activities( $args = '' ) {
388
  if ( empty( $friends ) )
389
  return false;
390
 
391
- $user_id = implode( ',', (array) $friends );
392
  break;
393
  case 'groups':
394
  if ( bp_is_active( 'groups' ) ) {
@@ -397,7 +348,7 @@ function bp_has_activities( $args = '' ) {
397
  return false;
398
 
399
  $object = $bp->groups->id;
400
- $primary_id = implode( ',', (array) $groups['groups'] );
401
 
402
  $user_id = 0;
403
  }
@@ -407,13 +358,13 @@ function bp_has_activities( $args = '' ) {
407
  if ( empty( $favs ) )
408
  return false;
409
 
410
- $include = implode( ',', (array) $favs );
411
  $display_comments = true;
412
  break;
413
  case 'mentions':
414
-
415
- // Start search at @ symbol and stop search at closing tag delimiter.
416
- $search_terms = '@' . bp_core_get_username( $user_id ) . '<';
417
  $display_comments = 'stream';
418
  $user_id = 0;
419
  break;
@@ -422,48 +373,26 @@ function bp_has_activities( $args = '' ) {
422
  }
423
 
424
  // Do not exceed the maximum per page
425
- if ( !empty( $max ) && ( (int) $per_page > (int) $max ) )
426
  $per_page = $max;
427
 
428
- // Support for basic filters in earlier BP versions is disabled by default. To enable, put
429
- // add_filter( 'bp_activity_enable_afilter_support', '__return_true' );
430
- // into bp-custom.php or your theme's functions.php
431
- if ( isset( $_GET['afilter'] ) && apply_filters( 'bp_activity_enable_afilter_support', false ) )
432
  $filter = array( 'object' => $_GET['afilter'] );
433
  else if ( !empty( $user_id ) || !empty( $object ) || !empty( $action ) || !empty( $primary_id ) || !empty( $secondary_id ) )
434
  $filter = array( 'user_id' => $user_id, 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id );
435
  else
436
  $filter = false;
437
 
438
- // If specific activity items have been requested, override the $hide_spam argument. This prevents backpat errors with AJAX.
439
- if ( !empty( $include ) && ( 'ham_only' == $spam ) )
440
- $spam = 'all';
441
-
442
- $template_args = array(
443
- 'page' => $page,
444
- 'per_page' => $per_page,
445
- 'page_arg' => $page_arg,
446
- 'max' => $max,
447
- 'sort' => $sort,
448
- 'include' => $include,
449
- 'exclude' => $exclude,
450
- 'in' => $in,
451
- 'filter' => $filter,
452
- 'search_terms' => $search_terms,
453
- 'display_comments' => $display_comments,
454
- 'show_hidden' => $show_hidden,
455
- 'spam' => $spam
456
- );
457
-
458
- $activities_template = new BP_Activity_Template( $template_args );
459
 
460
- return apply_filters( 'bp_has_activities', $activities_template->has_activities(), $activities_template, $template_args );
461
  }
462
 
463
  /**
464
  * Determines if there are still activities left in the loop.
465
  *
466
- * @since BuddyPress (1.0)
467
  *
468
  * @global object $activities_template {@link BP_Activity_Template}
469
  * @uses BP_Activity_Template::user_activities() {@link BP_Activity_Template::user_activities()}
@@ -478,7 +407,7 @@ function bp_activities() {
478
  /**
479
  * Gets the current activity object in the loop
480
  *
481
- * @since BuddyPress (1.0)
482
  *
483
  * @global object $activities_template {@link BP_Activity_Template}
484
  * @uses BP_Activity_Template::the_activity() {@link BP_Activity_Template::the_activity()}
@@ -493,7 +422,7 @@ function bp_the_activity() {
493
  /**
494
  * Outputs the activity pagination count
495
  *
496
- * @since BuddyPress (1.0)
497
  *
498
  * @global object $activities_template {@link BP_Activity_Template}
499
  * @uses BP_Activity_Template::the_activity() {@link BP_Activity_Template::the_activity()}
@@ -505,15 +434,16 @@ function bp_activity_pagination_count() {
505
  /**
506
  * Returns the activity pagination count
507
  *
508
- * @since BuddyPress (1.2)
509
  *
 
510
  * @global object $activities_template {@link BP_Activity_Template}
511
  * @uses bp_core_number_format()
512
  *
513
  * @return string The pagination text
514
  */
515
  function bp_get_activity_pagination_count() {
516
- global $activities_template;
517
 
518
  $start_num = intval( ( $activities_template->pag_page - 1 ) * $activities_template->pag_num ) + 1;
519
  $from_num = bp_core_number_format( $start_num );
@@ -526,7 +456,7 @@ function bp_activity_pagination_count() {
526
  /**
527
  * Outputs the activity pagination links
528
  *
529
- * @since BuddyPress (1.0)
530
  *
531
  * @uses bp_get_activity_pagination_links()
532
  */
@@ -537,7 +467,7 @@ function bp_activity_pagination_links() {
537
  /**
538
  * Outputs the activity pagination links
539
  *
540
- * @since BuddyPress (1.0)
541
  *
542
  * @global object $activities_template {@link BP_Activity_Template}
543
  * @uses apply_filters() To call the 'bp_get_activity_pagination_links' hook
@@ -553,7 +483,7 @@ function bp_activity_pagination_links() {
553
  /**
554
  * Returns true when there are more activity items to be shown than currently appear
555
  *
556
- * @since BuddyPress (1.5)
557
  *
558
  * @global object $activities_template {@link BP_Activity_Template}
559
  * @uses apply_filters() To call the 'bp_activity_has_more_items' hook
@@ -564,7 +494,7 @@ function bp_activity_has_more_items() {
564
  global $activities_template;
565
 
566
  $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->pag_num * $activities_template->pag_page ) );
567
- $has_more_items = (int) $remaining_pages ? true : false;
568
 
569
  return apply_filters( 'bp_activity_has_more_items', $has_more_items );
570
  }
@@ -572,7 +502,7 @@ function bp_activity_has_more_items() {
572
  /**
573
  * Outputs the activity count
574
  *
575
- * @since BuddyPress (1.2)
576
  *
577
  * @uses bp_get_activity_count()
578
  */
@@ -583,7 +513,7 @@ function bp_activity_count() {
583
  /**
584
  * Returns the activity count
585
  *
586
- * @since BuddyPress (1.2)
587
  *
588
  * @global object $activities_template {@link BP_Activity_Template}
589
  * @uses apply_filters() To call the 'bp_get_activity_count' hook
@@ -593,13 +523,13 @@ function bp_activity_count() {
593
  function bp_get_activity_count() {
594
  global $activities_template;
595
 
596
- return apply_filters( 'bp_get_activity_count', (int) $activities_template->activity_count );
597
  }
598
 
599
  /**
600
  * Outputs the number of activities per page
601
  *
602
- * @since BuddyPress (1.2)
603
  *
604
  * @uses bp_get_activity_per_page()
605
  */
@@ -610,7 +540,7 @@ function bp_activity_per_page() {
610
  /**
611
  * Returns the number of activities per page
612
  *
613
- * @since BuddyPress (1.2)
614
  *
615
  * @global object $activities_template {@link BP_Activity_Template}
616
  * @uses apply_filters() To call the 'bp_get_activity_per_page' hook
@@ -620,24 +550,26 @@ function bp_activity_per_page() {
620
  function bp_get_activity_per_page() {
621
  global $activities_template;
622
 
623
- return apply_filters( 'bp_get_activity_per_page', (int) $activities_template->pag_num );
624
  }
625
 
626
  /**
627
  * Outputs the activities title
628
  *
629
- * @since BuddyPress (1.0)
630
  *
631
  * @uses bp_get_activities_title()
632
  */
633
  function bp_activities_title() {
 
 
634
  echo bp_get_activities_title();
635
  }
636
 
637
  /**
638
  * Returns the activities title
639
  *
640
- * @since BuddyPress (1.0)
641
  *
642
  * @global string $bp_activity_title
643
  * @uses apply_filters() To call the 'bp_get_activities_title' hook
@@ -653,18 +585,20 @@ function bp_activities_title() {
653
  /**
654
  * {@internal Missing Description}
655
  *
656
- * @since BuddyPress (1.0)
657
  *
658
  * @uses bp_get_activities_no_activity()
659
  */
660
  function bp_activities_no_activity() {
 
 
661
  echo bp_get_activities_no_activity();
662
  }
663
 
664
  /**
665
  * {@internal Missing Description}
666
  *
667
- * @since BuddyPress (1.0)
668
  *
669
  * @global string $bp_activity_no_activity
670
  * @uses apply_filters() To call the 'bp_get_activities_no_activity' hook
@@ -680,7 +614,7 @@ function bp_activities_no_activity() {
680
  /**
681
  * Outputs the activity id
682
  *
683
- * @since BuddyPress (1.2)
684
  *
685
  * @uses bp_get_activity_id()
686
  */
@@ -691,7 +625,7 @@ function bp_activity_id() {
691
  /**
692
  * Returns the activity id
693
  *
694
- * @since BuddyPress (1.2)
695
  *
696
  * @global object $activities_template {@link BP_Activity_Template}
697
  * @uses apply_filters() To call the 'bp_get_activity_id' hook
@@ -706,7 +640,7 @@ function bp_activity_id() {
706
  /**
707
  * Outputs the activity item id
708
  *
709
- * @since BuddyPress (1.2)
710
  *
711
  * @uses bp_get_activity_item_id()
712
  */
@@ -717,7 +651,7 @@ function bp_activity_item_id() {
717
  /**
718
  * Returns the activity item id
719
  *
720
- * @since BuddyPress (1.2)
721
  *
722
  * @global object $activities_template {@link BP_Activity_Template}
723
  * @uses apply_filters() To call the 'bp_get_activity_item_id' hook
@@ -732,7 +666,7 @@ function bp_activity_item_id() {
732
  /**
733
  * Outputs the activity secondary item id
734
  *
735
- * @since BuddyPress (1.2)
736
  *
737
  * @uses bp_get_activity_secondary_item_id()
738
  */
@@ -743,7 +677,7 @@ function bp_activity_secondary_item_id() {
743
  /**
744
  * Returns the activity secondary item id
745
  *
746
- * @since BuddyPress (1.2)
747
  *
748
  * @global object $activities_template {@link BP_Activity_Template}
749
  * @uses apply_filters() To call the 'bp_get_activity_secondary_item_id' hook
@@ -758,7 +692,7 @@ function bp_activity_secondary_item_id() {
758
  /**
759
  * Outputs the date the activity was recorded
760
  *
761
- * @since BuddyPress (1.2)
762
  *
763
  * @uses bp_get_activity_date_recorded()
764
  */
@@ -769,7 +703,7 @@ function bp_activity_date_recorded() {
769
  /**
770
  * Returns the date the activity was recorded
771
  *
772
- * @since BuddyPress (1.2)
773
  *
774
  * @global object $activities_template {@link BP_Activity_Template}
775
  * @uses apply_filters() To call the 'bp_get_activity_date_recorded' hook
@@ -784,7 +718,7 @@ function bp_activity_date_recorded() {
784
  /**
785
  * Outputs the activity object name
786
  *
787
- * @since BuddyPress (1.2)
788
  *
789
  * @uses bp_get_activity_object_name()
790
  */
@@ -795,7 +729,7 @@ function bp_activity_object_name() {
795
  /**
796
  * Returns the activity object name
797
  *
798
- * @since BuddyPress (1.2)
799
  *
800
  * @global object $activities_template {@link BP_Activity_Template}
801
  * @uses apply_filters() To call the 'bp_get_activity_object_name' hook
@@ -810,7 +744,7 @@ function bp_activity_object_name() {
810
  /**
811
  * Outputs the activity type
812
  *
813
- * @since BuddyPress (1.2)
814
  *
815
  * @uses bp_get_activity_type()
816
  */
@@ -821,7 +755,7 @@ function bp_activity_type() {
821
  /**
822
  * Returns the activity type
823
  *
824
- * @since BuddyPress (1.2)
825
  *
826
  * @global object $activities_template {@link BP_Activity_Template}
827
  * @uses apply_filters() To call the 'bp_get_activity_type' hook
@@ -838,8 +772,8 @@ function bp_activity_type() {
838
  *
839
  * Just a wrapper for bp_activity_type()
840
  *
841
- * @since BuddyPress (1.2)
842
- * @deprecated BuddyPress (1.5)
843
  *
844
  * @todo Properly deprecate in favor of bp_activity_type() and
845
  * remove redundant echo
@@ -853,8 +787,8 @@ function bp_activity_type() {
853
  *
854
  * Just a wrapper for bp_get_activity_type()
855
  *
856
- * @since BuddyPress (1.2)
857
- * @deprecated BuddyPress (1.5)
858
  *
859
  * @todo Properly deprecate in favor of bp_get_activity_type()
860
  *
@@ -867,7 +801,7 @@ function bp_activity_type() {
867
  /**
868
  * Outputs the activity user id
869
  *
870
- * @since BuddyPress (1.1)
871
  *
872
  * @uses bp_get_activity_user_id()
873
  */
@@ -878,7 +812,7 @@ function bp_activity_user_id() {
878
  /**
879
  * Returns the activity user id
880
  *
881
- * @since BuddyPress (1.1)
882
  *
883
  * @global object $activities_template {@link BP_Activity_Template}
884
  * @uses apply_filters() To call the 'bp_get_activity_user_id' hook
@@ -893,7 +827,7 @@ function bp_activity_user_id() {
893
  /**
894
  * Outputs the activity user link
895
  *
896
- * @since BuddyPress (1.2)
897
  *
898
  * @uses bp_get_activity_user_link()
899
  */
@@ -904,7 +838,7 @@ function bp_activity_user_link() {
904
  /**
905
  * Returns the activity user link
906
  *
907
- * @since BuddyPress (1.2)
908
  *
909
  * @global object $activities_template {@link BP_Activity_Template}
910
  * @uses bp_core_get_user_domain()
@@ -926,7 +860,7 @@ function bp_activity_user_link() {
926
  /**
927
  * Output the avatar of the user that performed the action
928
  *
929
- * @since BuddyPress (1.1)
930
  *
931
  * @param array $args
932
  *
@@ -938,7 +872,7 @@ function bp_activity_avatar( $args = '' ) {
938
  /**
939
  * Return the avatar of the user that performed the action
940
  *
941
- * @since BuddyPress (1.1)
942
  *
943
  * @param array $args optional
944
  *
@@ -959,16 +893,8 @@ function bp_activity_avatar( $args = '' ) {
959
  // On activity permalink pages, default to the full-size avatar
960
  $type_default = bp_is_single_activity() ? 'full' : 'thumb';
961
 
962
- if ( !empty( $activities_template->activity->display_name ) ) {
963
- $dn_default = $activities_template->activity->display_name;
964
- } else if ( !empty( $activities_template->current_comment->display_name ) ) {
965
- $dn_default = $activities_template->current_comment->display_name;
966
- }
967
-
968
- $alt_default = isset( $dn_default ) ? sprintf( __( 'Profile picture of %s', 'buddypress' ), $activities_template->activity->display_name ) : __( 'Profile picture', 'buddypress' );
969
-
970
  $defaults = array(
971
- 'alt' => $alt_default,
972
  'class' => 'avatar',
973
  'email' => false,
974
  'type' => $type_default,
@@ -1014,7 +940,7 @@ function bp_activity_avatar( $args = '' ) {
1014
  /**
1015
  * Output the avatar of the object that action was performed on
1016
  *
1017
- * @since BuddyPress (1.2)
1018
  *
1019
  * @param array $args optional
1020
  *
@@ -1027,10 +953,11 @@ function bp_activity_secondary_avatar( $args = '' ) {
1027
  /**
1028
  * Return the avatar of the object that action was performed on
1029
  *
1030
- * @since BuddyPress (1.2)
1031
  *
1032
  * @param array $args optional
1033
  *
 
1034
  * @global object $activities_template {@link BP_Activity_Template}
1035
  * @uses wp_parse_args()
1036
  * @uses get_blog_option()
@@ -1042,7 +969,7 @@ function bp_activity_secondary_avatar( $args = '' ) {
1042
  * @return string The secondary avatar
1043
  */
1044
  function bp_get_activity_secondary_avatar( $args = '' ) {
1045
- global $activities_template;
1046
 
1047
  $defaults = array(
1048
  'type' => 'thumb',
@@ -1058,46 +985,36 @@ function bp_activity_secondary_avatar( $args = '' ) {
1058
  // Set item_id and object (default to user)
1059
  switch ( $activities_template->activity->component ) {
1060
  case 'groups' :
1061
- $object = 'group';
1062
  $item_id = $activities_template->activity->item_id;
1063
 
1064
- if ( empty( $alt ) ) {
1065
- $alt = __( 'Group logo', 'buddypress' );
1066
-
1067
- if ( bp_is_active( 'groups' ) ) {
1068
- $group = groups_get_group( $item_id );
1069
- if ( isset( $group->name ) )
1070
- $alt = sprintf( __( 'Group logo of %s', 'buddypress' ), $group->name );
1071
- }
1072
- }
1073
 
1074
  break;
1075
  case 'blogs' :
1076
- $object = 'blog';
1077
  $item_id = $activities_template->activity->item_id;
1078
 
1079
- if ( !$alt ) {
1080
- $alt = sprintf( __( 'Profile picture of the author of the site %s', 'buddypress' ), get_blog_option( $item_id, 'blogname' ) );
1081
- }
1082
 
1083
  break;
1084
  case 'friends' :
1085
  $object = 'user';
1086
  $item_id = $activities_template->activity->secondary_item_id;
1087
 
1088
- if ( empty( $alt ) ) {
1089
- $alt = sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $activities_template->activity->secondary_item_id ) );
1090
- }
1091
 
1092
  break;
1093
  default :
1094
  $object = 'user';
1095
  $item_id = $activities_template->activity->user_id;
1096
- $email = $activities_template->activity->user_email;
1097
 
1098
- if ( !$alt ) {
1099
- $alt = sprintf( __( 'Profile picture of %s', 'buddypress' ), $activities_template->activity->display_name );
1100
- }
1101
 
1102
  break;
1103
  }
@@ -1116,7 +1033,7 @@ function bp_activity_secondary_avatar( $args = '' ) {
1116
  /**
1117
  * Output the activity action
1118
  *
1119
- * @since BuddyPress (1.2)
1120
  *
1121
  * @uses bp_get_activity_action()
1122
  */
@@ -1127,7 +1044,7 @@ function bp_activity_action() {
1127
  /**
1128
  * Return the activity action
1129
  *
1130
- * @since BuddyPress (1.2)
1131
  *
1132
  * @global object $activities_template {@link BP_Activity_Template}
1133
  * @uses apply_filters_ref_array() To call the 'bp_get_activity_action_pre_meta' hook
@@ -1151,7 +1068,7 @@ function bp_activity_action() {
1151
  /**
1152
  * Output the activity content body
1153
  *
1154
- * @since BuddyPress (1.2)
1155
  *
1156
  * @uses bp_get_activity_content_body()
1157
  */
@@ -1162,7 +1079,7 @@ function bp_activity_content_body() {
1162
  /**
1163
  * Return the activity content body
1164
  *
1165
- * @since BuddyPress (1.2)
1166
  *
1167
  * @global object $activities_template {@link BP_Activity_Template}
1168
  * @uses bp_insert_activity_meta()
@@ -1183,7 +1100,7 @@ function bp_activity_content_body() {
1183
  /**
1184
  * Does the activity have content?
1185
  *
1186
- * @since BuddyPress (1.2)
1187
  *
1188
  * @global object $activities_template {@link BP_Activity_Template}
1189
  *
@@ -1201,8 +1118,8 @@ function bp_activity_has_content() {
1201
  /**
1202
  * Output the activity content
1203
  *
1204
- * @since BuddyPress (1.0)
1205
- * @deprecated BuddyPress (1.5)
1206
  *
1207
  * @todo properly deprecate this function
1208
  *
@@ -1215,11 +1132,12 @@ function bp_activity_content() {
1215
  /**
1216
  * Return the activity content
1217
  *
1218
- * @since BuddyPress (1.0)
1219
- * @deprecated BuddyPress (1.5)
1220
  *
1221
  * @todo properly deprecate this function
1222
  *
 
1223
  * @uses bp_get_activity_action()
1224
  * @uses bp_get_activity_content_body()
1225
  * @uses apply_filters() To call the 'bp_get_activity_content' hook
@@ -1227,6 +1145,8 @@ function bp_activity_content() {
1227
  * @return string The activity content
1228
  */
1229
  function bp_get_activity_content() {
 
 
1230
  /**
1231
  * If you want to filter activity update content, please use
1232
  * the filter 'bp_get_activity_content_body'
@@ -1241,11 +1161,12 @@ function bp_activity_content() {
1241
  /**
1242
  * Insert activity meta
1243
  *
1244
- * @since BuddyPress (1.2)
1245
  *
1246
  * @param string $content
1247
  *
1248
  * @global object $activities_template {@link BP_Activity_Template}
 
1249
  * @uses bp_core_time_since()
1250
  * @uses apply_filters_ref_array() To call the 'bp_activity_time_since' hook
1251
  * @uses bp_is_single_activity()
@@ -1257,7 +1178,7 @@ function bp_activity_content() {
1257
  * @return string The activity content
1258
  */
1259
  function bp_insert_activity_meta( $content ) {
1260
- global $activities_template;
1261
 
1262
  // Strip any legacy time since placeholders from BP 1.0-1.1
1263
  $content = str_replace( '<span class="time-since">%s</span>', '', $content );
@@ -1277,17 +1198,18 @@ function bp_insert_activity_meta( $content ) {
1277
  /**
1278
  * Determine if the current user can delete an activity item
1279
  *
1280
- * @since BuddyPress (1.2)
1281
  *
1282
  * @param object $activity Optional
1283
  *
1284
  * @global object $activities_template {@link BP_Activity_Template}
 
1285
  * @uses apply_filters() To call the 'bp_activity_user_can_delete' hook
1286
  *
1287
  * @return bool True if can delete, false otherwise
1288
  */
1289
  function bp_activity_user_can_delete( $activity = false ) {
1290
- global $activities_template;
1291
 
1292
  if ( !$activity )
1293
  $activity = $activities_template->activity;
@@ -1297,13 +1219,13 @@ function bp_activity_user_can_delete( $activity = false ) {
1297
 
1298
  $can_delete = false;
1299
 
1300
- if ( bp_current_user_can( 'bp_moderate' ) )
1301
  $can_delete = true;
1302
 
1303
- if ( $activity->user_id == bp_loggedin_user_id() )
1304
  $can_delete = true;
1305
 
1306
- if ( bp_is_item_admin() && bp_is_single_item() )
1307
  $can_delete = true;
1308
 
1309
  return apply_filters( 'bp_activity_user_can_delete', $can_delete );
@@ -1312,7 +1234,7 @@ function bp_activity_user_can_delete( $activity = false ) {
1312
  /**
1313
  * Output the activity parent content
1314
  *
1315
- * @since BuddyPress (1.2)
1316
  *
1317
  * @param array $args Optional
1318
  *
@@ -1325,10 +1247,11 @@ function bp_activity_parent_content( $args = '' ) {
1325
  /**
1326
  * Return the activity content
1327
  *
1328
- * @since BuddyPress (1.2)
1329
  *
1330
  * @param array $args Optional
1331
  *
 
1332
  * @global object $activities_template {@link BP_Activity_Template}
1333
  * @uses wp_parse_args()
1334
  * @uses apply_filters() To call the 'bp_get_activity_parent_content' hook
@@ -1336,7 +1259,7 @@ function bp_activity_parent_content( $args = '' ) {
1336
  * @return mixed False on failure, otherwise the activity parent content
1337
  */
1338
  function bp_get_activity_parent_content( $args = '' ) {
1339
- global $activities_template;
1340
 
1341
  $defaults = array(
1342
  'hide_user' => false
@@ -1370,7 +1293,7 @@ function bp_activity_parent_content( $args = '' ) {
1370
  /**
1371
  * Output whether or not the current activity is in a current user's favorites
1372
  *
1373
- * @since BuddyPress (1.2)
1374
  *
1375
  * @uses bp_get_activity_is_favorite()
1376
  */
@@ -1381,23 +1304,24 @@ function bp_activity_is_favorite() {
1381
  /**
1382
  * Return whether or not the current activity is in a current user's favorites
1383
  *
1384
- * @since BuddyPress (1.2)
1385
  *
 
1386
  * @global object $activities_template {@link BP_Activity_Template}
1387
  * @uses apply_filters() To call the 'bp_get_activity_is_favorite' hook
1388
  *
1389
  * @return bool True if user favorite, false otherwise
1390
  */
1391
  function bp_get_activity_is_favorite() {
1392
- global $activities_template;
1393
 
1394
- return apply_filters( 'bp_get_activity_is_favorite', in_array( $activities_template->activity->id, (array) $activities_template->my_favs ) );
1395
  }
1396
 
1397
  /**
1398
  * Echoes the comment markup for an activity item
1399
  *
1400
- * @since BuddyPress (1.2)
1401
  *
1402
  * @todo deprecate $args param
1403
  *
@@ -1410,7 +1334,7 @@ function bp_activity_comments( $args = '' ) {
1410
  /**
1411
  * Gets the comment markup for an activity item
1412
  *
1413
- * @since BuddyPress (1.2)
1414
  *
1415
  * @todo deprecate $args param
1416
  *
@@ -1420,10 +1344,11 @@ function bp_activity_comments( $args = '' ) {
1420
  * @param string $args Unused. Appears to be left over from an earlier implementation.
1421
  *
1422
  * @global object $activities_template {@link BP_Activity_Template}
 
1423
  * @uses bp_activity_recurse_comments()
1424
  */
1425
  function bp_activity_get_comments( $args = '' ) {
1426
- global $activities_template;
1427
 
1428
  if ( !isset( $activities_template->activity->children ) || !$activities_template->activity->children )
1429
  return false;
@@ -1437,26 +1362,27 @@ function bp_activity_comments( $args = '' ) {
1437
  * Note: The recursion itself used to happen entirely in this function. Now it is
1438
  * split between here and the comment.php template.
1439
  *
1440
- * @since BuddyPress (1.2)
1441
  *
1442
  * @todo remove $counter global
1443
  *
1444
  * @param object $comment The activity object currently being recursed
1445
  *
1446
  * @global object $activities_template {@link BP_Activity_Template}
 
1447
  * @uses locate_template()
1448
  */
1449
  function bp_activity_recurse_comments( $comment ) {
1450
- global $activities_template;
1451
 
1452
- if ( empty( $comment ) )
1453
  return false;
1454
 
1455
  if ( empty( $comment->children ) )
1456
  return false;
1457
 
1458
- echo apply_filters( 'bp_activity_recurse_comments_start_ul', '<ul>');
1459
- foreach ( (array) $comment->children as $comment_child ) {
1460
  // Put the comment into the global so it's available to filters
1461
  $activities_template->activity->current_comment = $comment_child;
1462
 
@@ -1474,13 +1400,13 @@ function bp_activity_comments( $args = '' ) {
1474
 
1475
  unset( $activities_template->activity->current_comment );
1476
  }
1477
- echo apply_filters( 'bp_activity_recurse_comments_end_ul', '</ul>');
1478
  }
1479
 
1480
  /**
1481
  * Utility function that returns the comment currently being recursed
1482
  *
1483
- * @since BuddyPress (1.5)
1484
  *
1485
  * @global object $activities_template {@link BP_Activity_Template}
1486
  * @uses apply_filters() To call the 'bp_activity_current_comment' hook
@@ -1499,7 +1425,7 @@ function bp_activity_current_comment() {
1499
  /**
1500
  * Echoes the id of the activity comment currently being displayed
1501
  *
1502
- * @since BuddyPress (1.5)
1503
  *
1504
  * @uses bp_get_activity_comment_id()
1505
  */
@@ -1510,7 +1436,7 @@ function bp_activity_comment_id() {
1510
  /**
1511
  * Gets the id of the activity comment currently being displayed
1512
  *
1513
- * @since BuddyPress (1.5)
1514
  *
1515
  * @global object $activities_template {@link BP_Activity_Template}
1516
  * @uses apply_filters() To call the 'bp_activity_comment_id' hook
@@ -1528,7 +1454,7 @@ function bp_activity_comment_id() {
1528
  /**
1529
  * Echoes the user_id of the author of the activity comment currently being displayed
1530
  *
1531
- * @since BuddyPress (1.5)
1532
  *
1533
  * @uses bp_get_activity_comment_user_id()
1534
  */
@@ -1539,7 +1465,7 @@ function bp_activity_comment_user_id() {
1539
  /**
1540
  * Gets the user_id of the author of the activity comment currently being displayed
1541
  *
1542
- * @since BuddyPress (1.5)
1543
  *
1544
  * @global object $activities_template {@link BP_Activity_Template}
1545
  * @uses apply_filters() To call the 'bp_activity_comment_user_id' hook
@@ -1557,7 +1483,7 @@ function bp_activity_comment_user_id() {
1557
  /**
1558
  * Echoes the author link for the activity comment currently being displayed
1559
  *
1560
- * @since BuddyPress (1.5)
1561
  *
1562
  * @uses bp_get_activity_comment_user_link()
1563
  */
@@ -1568,7 +1494,7 @@ function bp_activity_comment_user_link() {
1568
  /**
1569
  * Gets the author link for the activity comment currently being displayed
1570
  *
1571
- * @since BuddyPress (1.5)
1572
  *
1573
  * @uses bp_core_get_user_domain()
1574
  * @uses bp_get_activity_comment_user_id()
@@ -1585,7 +1511,7 @@ function bp_activity_comment_user_link() {
1585
  /**
1586
  * Echoes the author name for the activity comment currently being displayed
1587
  *
1588
- * @since BuddyPress (1.5)
1589
  *
1590
  * @uses bp_get_activity_comment_name()
1591
  */
@@ -1598,7 +1524,7 @@ function bp_activity_comment_name() {
1598
  *
1599
  * The use of the bp_acomment_name filter is deprecated. Please use bp_activity_comment_name
1600
  *
1601
- * @since BuddyPress (1.5)
1602
  *
1603
  * @global object $activities_template {@link BP_Activity_Template}
1604
  * @uses apply_filters() To call the 'bp_acomment_name' hook
@@ -1609,10 +1535,7 @@ function bp_activity_comment_name() {
1609
  function bp_get_activity_comment_name() {
1610
  global $activities_template;
1611
 
1612
- if ( isset( $activities_template->activity->current_comment->user_fullname ) )
1613
- $name = apply_filters( 'bp_acomment_name', $activities_template->activity->current_comment->user_fullname, $activities_template->activity->current_comment ); // backward compatibility
1614
- else
1615
- $name = $activities_template->activity->current_comment->display_name;
1616
 
1617
  return apply_filters( 'bp_activity_comment_name', $name );
1618
  }
@@ -1620,7 +1543,7 @@ function bp_activity_comment_name() {
1620
  /**
1621
  * Echoes the date_recorded of the activity comment currently being displayed
1622
  *
1623
- * @since BuddyPress (1.5)
1624
  *
1625
  * @uses bp_get_activity_comment_date_recorded()
1626
  */
@@ -1631,7 +1554,7 @@ function bp_activity_comment_date_recorded() {
1631
  /**
1632
  * Gets the date_recorded for the activity comment currently being displayed
1633
  *
1634
- * @since BuddyPress (1.5)
1635
  *
1636
  * @global object $activities_template {@link BP_Activity_Template}
1637
  * @uses bp_core_time_since()
@@ -1653,7 +1576,7 @@ function bp_activity_comment_date_recorded() {
1653
  /**
1654
  * Echoes the 'delete' URL for the activity comment currently being displayed
1655
  *
1656
- * @since BuddyPress (1.5)
1657
  *
1658
  * @uses bp_get_activity_comment_delete_link()
1659
  */
@@ -1664,8 +1587,9 @@ function bp_activity_comment_delete_link() {
1664
  /**
1665
  * Gets the 'delete' URL for the activity comment currently being displayed
1666
  *
1667
- * @since BuddyPress (1.5)
1668
  *
 
1669
  * @uses wp_nonce_url()
1670
  * @uses bp_get_root_domain()
1671
  * @uses bp_get_activity_slug()
@@ -1675,7 +1599,9 @@ function bp_activity_comment_delete_link() {
1675
  * @return string $link The nonced URL for deleting the current activity comment
1676
  */
1677
  function bp_get_activity_comment_delete_link() {
1678
- $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' );
 
 
1679
 
1680
  return apply_filters( 'bp_activity_comment_delete_link', $link );
1681
  }
@@ -1683,7 +1609,7 @@ function bp_activity_comment_delete_link() {
1683
  /**
1684
  * Echoes the content of the activity comment currently being displayed
1685
  *
1686
- * @since BuddyPress (1.5)
1687
  *
1688
  * @uses bp_get_activity_comment_content()
1689
  */
@@ -1698,7 +1624,7 @@ function bp_activity_comment_content() {
1698
  * applied to activity items in general. Use bp_activity_comment_content to modify the
1699
  * content of activity comments only.
1700
  *
1701
- * @since BuddyPress (1.5)
1702
  *
1703
  * @global object $activities_template {@link BP_Activity_Template}
1704
  * @uses apply_filters() To call the 'bp_get_activity_content' hook
@@ -1717,7 +1643,7 @@ function bp_activity_comment_content() {
1717
  /**
1718
  * Echoes the activity comment count
1719
  *
1720
- * @since BuddyPress (1.2)
1721
  *
1722
  * @uses bp_activity_get_comment_count()
1723
  */
@@ -1732,25 +1658,26 @@ function bp_activity_comment_count() {
1732
  * applied to activity items in general. Use bp_activity_comment_content to modify the
1733
  * content of activity comments only.
1734
  *
1735
- * @since BuddyPress (1.2)
1736
  *
1737
  * @todo deprecate $args
1738
  *
1739
  * @global object $activities_template {@link BP_Activity_Template}
 
1740
  * @uses bp_activity_recurse_comment_count()
1741
  * @uses apply_filters() To call the 'bp_activity_get_comment_count' hook
1742
  *
1743
  * @return int $count The activity comment count. Defaults to zero
1744
  */
1745
  function bp_activity_get_comment_count( $args = '' ) {
1746
- global $activities_template;
1747
 
1748
  if ( !isset( $activities_template->activity->children ) || !$activities_template->activity->children )
1749
  return 0;
1750
 
1751
  $count = bp_activity_recurse_comment_count( $activities_template->activity );
1752
 
1753
- return apply_filters( 'bp_activity_get_comment_count', (int) $count );
1754
  }
1755
 
1756
  /**
@@ -1760,23 +1687,26 @@ function bp_activity_comment_count() {
1760
  * applied to activity items in general. Use bp_activity_comment_content to modify the
1761
  * content of activity comments only.
1762
  *
1763
- * @since BuddyPress (1.2)
1764
  *
1765
  * @todo investigate why bp_activity_recurse_comment_count() is used while being declared
1766
  *
1767
  * @param object $comment Activity comments object
1768
  *
 
 
1769
  * @uses bp_activity_recurse_comment_count()
1770
  * @uses apply_filters() To call the 'bp_activity_get_comment_count' hook
1771
  *
1772
  * @return int $count The activity comment count.
1773
  */
1774
  function bp_activity_recurse_comment_count( $comment, $count = 0 ) {
 
1775
 
1776
- if ( empty( $comment->children ) )
1777
  return $count;
1778
 
1779
- foreach ( (array) $comment->children as $comment ) {
1780
  $count++;
1781
  $count = bp_activity_recurse_comment_count( $comment, $count );
1782
  }
@@ -1787,7 +1717,7 @@ function bp_activity_comment_count() {
1787
  /**
1788
  * Echoes the activity comment link
1789
  *
1790
- * @since BuddyPress (1.2)
1791
  *
1792
  * @uses bp_get_activity_comment_link()
1793
  */
@@ -1798,7 +1728,7 @@ function bp_activity_comment_link() {
1798
  /**
1799
  * Gets the activity comment link
1800
  *
1801
- * @since BuddyPress (1.2)
1802
  *
1803
  * @global object $activities_template {@link BP_Activity_Template}
1804
  * @uses apply_filters() To call the 'bp_get_activity_comment_link' hook
@@ -1813,7 +1743,7 @@ function bp_activity_comment_link() {
1813
  /**
1814
  * Echoes the activity comment form no javascript display CSS
1815
  *
1816
- * @since BuddyPress (1.2)
1817
  *
1818
  * @uses bp_get_activity_comment_form_nojs_display()
1819
  */
@@ -1824,7 +1754,7 @@ function bp_activity_comment_form_nojs_display() {
1824
  /**
1825
  * Gets the activity comment form no javascript display CSS
1826
  *
1827
- * @since BuddyPress (1.2)
1828
  *
1829
  * @global object $activities_template {@link BP_Activity_Template}
1830
  *
@@ -1841,7 +1771,7 @@ function bp_activity_comment_form_nojs_display() {
1841
  /**
1842
  * Echoes the activity comment form action
1843
  *
1844
- * @since BuddyPress (1.2)
1845
  *
1846
  * @uses bp_get_activity_comment_form_action()
1847
  */
@@ -1852,8 +1782,9 @@ function bp_activity_comment_form_action() {
1852
  /**
1853
  * Gets the activity comment form action
1854
  *
1855
- * @since BuddyPress (1.2)
1856
  *
 
1857
  * @uses home_url()
1858
  * @uses bp_get_activity_root_slug()
1859
  * @uses apply_filters() To call the 'bp_get_activity_comment_form_action' hook
@@ -1861,13 +1792,15 @@ function bp_activity_comment_form_action() {
1861
  * @return string The activity comment form action
1862
  */
1863
  function bp_get_activity_comment_form_action() {
 
 
1864
  return apply_filters( 'bp_get_activity_comment_form_action', home_url( bp_get_activity_root_slug() . '/reply/' ) );
1865
  }
1866
 
1867
  /**
1868
  * Echoes the activity permalink id
1869
  *
1870
- * @since BuddyPress (1.2)
1871
  *
1872
  * @uses bp_get_activity_permalink_id()
1873
  */
@@ -1878,20 +1811,23 @@ function bp_activity_permalink_id() {
1878
  /**
1879
  * Gets the activity permalink id
1880
  *
1881
- * @since BuddyPress (1.2)
1882
  *
 
1883
  * @uses apply_filters() To call the 'bp_get_activity_permalink_id' hook
1884
  *
1885
  * @return string The activity permalink id
1886
  */
1887
  function bp_get_activity_permalink_id() {
1888
- return apply_filters( 'bp_get_activity_permalink_id', bp_current_action() );
 
 
1889
  }
1890
 
1891
  /**
1892
  * Echoes the activity thread permalink
1893
  *
1894
- * @since BuddyPress (1.2)
1895
  *
1896
  * @uses bp_get_activity_permalink_id()
1897
  */
@@ -1902,15 +1838,16 @@ function bp_activity_thread_permalink() {
1902
  /**
1903
  * Gets the activity thread permalink
1904
  *
1905
- * @since BuddyPress (1.2)
1906
  *
 
1907
  * @uses bp_activity_get_permalink()
1908
  * @uses apply_filters() To call the 'bp_get_activity_thread_permalink' hook
1909
  *
1910
  * @return string $link The activity thread permalink
1911
  */
1912
  function bp_get_activity_thread_permalink() {
1913
- global $activities_template;
1914
 
1915
  $link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity );
1916
 
@@ -1920,7 +1857,7 @@ function bp_activity_thread_permalink() {
1920
  /**
1921
  * Echoes the activity favorite link
1922
  *
1923
- * @since BuddyPress (1.2)
1924
  *
1925
  * @uses bp_get_activity_favorite_link()
1926
  */
@@ -1931,8 +1868,9 @@ function bp_activity_favorite_link() {
1931
  /**
1932
  * Gets the activity favorite link
1933
  *
1934
- * @since BuddyPress (1.2)
1935
  *
 
1936
  * @global object $activities_template {@link BP_Activity_Template}
1937
  * @uses wp_nonce_url()
1938
  * @uses home_url()
@@ -1942,14 +1880,14 @@ function bp_activity_favorite_link() {
1942
  * @return string The activity favorite link
1943
  */
1944
  function bp_get_activity_favorite_link() {
1945
- global $activities_template;
1946
  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' ) );
1947
  }
1948
 
1949
  /**
1950
  * Echoes the activity unfavorite link
1951
  *
1952
- * @since BuddyPress (1.2)
1953
  *
1954
  * @uses bp_get_activity_unfavorite_link()
1955
  */
@@ -1960,8 +1898,9 @@ function bp_activity_unfavorite_link() {
1960
  /**
1961
  * Gets the activity unfavorite link
1962
  *
1963
- * @since BuddyPress (1.2)
1964
  *
 
1965
  * @global object $activities_template {@link BP_Activity_Template}
1966
  * @uses wp_nonce_url()
1967
  * @uses home_url()
@@ -1971,14 +1910,14 @@ function bp_activity_unfavorite_link() {
1971
  * @return string The activity unfavorite link
1972
  */
1973
  function bp_get_activity_unfavorite_link() {
1974
- global $activities_template;
1975
  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' ) );
1976
  }
1977
 
1978
  /**
1979
  * Echoes the activity CSS class
1980
  *
1981
- * @since BuddyPress (1.0)
1982
  *
1983
  * @uses bp_get_activity_css_class()
1984
  */
@@ -1989,7 +1928,7 @@ function bp_activity_css_class() {
1989
  /**
1990
  * Gets the activity CSS class
1991
  *
1992
- * @since BuddyPress (1.0)
1993
  *
1994
  * @global object $activities_template {@link BP_Activity_Template}
1995
  * @uses apply_filters() To call the 'bp_activity_mini_activity_types' hook
@@ -2011,10 +1950,9 @@ function bp_activity_css_class() {
2011
  'new_member'
2012
  ) );
2013
 
2014
- $class = ' activity-item';
2015
-
2016
- if ( in_array( $activities_template->activity->type, (array) $mini_activity_actions ) || empty( $activities_template->activity->content ) )
2017
- $class .= ' mini';
2018
 
2019
  if ( bp_activity_get_comment_count() && bp_activity_can_comment() )
2020
  $class .= ' has-comments';
@@ -2025,7 +1963,7 @@ function bp_activity_css_class() {
2025
  /**
2026
  * Display the activity delete link.
2027
  *
2028
- * @since BuddyPress (1.1)
2029
  *
2030
  * @uses bp_get_activity_delete_link()
2031
  */
@@ -2036,9 +1974,10 @@ function bp_activity_delete_link() {
2036
  /**
2037
  * Return the activity delete link.
2038
  *
2039
- * @since BuddyPress (1.1)
2040
  *
2041
  * @global object $activities_template {@link BP_Activity_Template}
 
2042
  * @uses bp_get_root_domain()
2043
  * @uses bp_get_activity_root_slug()
2044
  * @uses bp_is_activity_component()
@@ -2051,7 +1990,7 @@ function bp_activity_delete_link() {
2051
  * @return string $link Activity delete link. Contains $redirect_to arg if on single activity page.
2052
  */
2053
  function bp_get_activity_delete_link() {
2054
- global $activities_template;
2055
 
2056
  $url = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/delete/' . $activities_template->activity->id;
2057
  $class = 'delete-activity';
@@ -2069,7 +2008,7 @@ function bp_activity_delete_link() {
2069
  /**
2070
  * Display the activity latest update link.
2071
  *
2072
- * @since BuddyPress (1.2)
2073
  *
2074
  * @param int $user_id Defaults to 0
2075
  *
@@ -2082,11 +2021,12 @@ function bp_activity_latest_update( $user_id = 0 ) {
2082
  /**
2083
  * Return the activity latest update link.
2084
  *
2085
- * @since BuddyPress (1.2)
2086
  *
2087
  * @param int $user_id Defaults to 0
2088
  *
2089
- * @uses bp_is_user_inactive()
 
2090
  * @uses bp_core_is_user_deleted()
2091
  * @uses bp_get_user_meta()
2092
  * @uses apply_filters() To call the 'bp_get_activity_latest_update_excerpt' hook
@@ -2098,11 +2038,12 @@ function bp_activity_latest_update( $user_id = 0 ) {
2098
  * @return string|bool $latest_update The activity latest update link. False on failure
2099
  */
2100
  function bp_get_activity_latest_update( $user_id = 0 ) {
 
2101
 
2102
- if ( empty( $user_id ) )
2103
- $user_id = bp_displayed_user_id();
2104
 
2105
- if ( bp_is_user_inactive( $user_id ) )
2106
  return false;
2107
 
2108
  if ( !$update = bp_get_user_meta( $user_id, 'bp_latest_update', true ) )
@@ -2117,7 +2058,7 @@ function bp_activity_latest_update( $user_id = 0 ) {
2117
  /**
2118
  * Display the activity filter links.
2119
  *
2120
- * @since BuddyPress (1.1)
2121
  *
2122
  * @param array $args Defaults to false
2123
  *
@@ -2130,10 +2071,12 @@ function bp_activity_filter_links( $args = false ) {
2130
  /**
2131
  * Return the activity filter links.
2132
  *
2133
- * @since BuddyPress (1.1)
2134
  *
2135
  * @param array $args Defaults to false
2136
  *
 
 
2137
  * @uses wp_parse_args()
2138
  * @uses BP_Activity_Activity::get_recorded_components() {@link BP_Activity_Activity}
2139
  * @uses esc_attr()
@@ -2145,6 +2088,7 @@ function bp_activity_filter_links( $args = false ) {
2145
  * @return string|bool $component_links The activity filter links. False on failure
2146
  */
2147
  function bp_get_activity_filter_links( $args = false ) {
 
2148
 
2149
  $defaults = array(
2150
  'style' => 'list'
@@ -2153,18 +2097,14 @@ function bp_activity_filter_links( $args = false ) {
2153
  $r = wp_parse_args( $args, $defaults );
2154
  extract( $r, EXTR_SKIP );
2155
 
2156
- // Define local variable
2157
- $component_links = array();
2158
-
2159
  // Fetch the names of components that have activity recorded in the DB
2160
  $components = BP_Activity_Activity::get_recorded_components();
2161
 
2162
- if ( empty( $components ) )
2163
  return false;
2164
 
2165
  foreach ( (array) $components as $component ) {
2166
-
2167
- // Skip the activity comment filter
2168
  if ( 'activity' == $component )
2169
  continue;
2170
 
@@ -2195,9 +2135,13 @@ function bp_activity_filter_links( $args = false ) {
2195
 
2196
  $link = add_query_arg( 'afilter', $component );
2197
  $link = remove_query_arg( 'acpage' , $link );
 
2198
  $link = apply_filters( 'bp_get_activity_filter_link_href', $link, $component );
2199
 
2200
- $component_links[] = $before . '<a href="' . esc_attr( $link ) . '">' . ucwords( $component ) . '</a>' . $after;
 
 
 
2201
  }
2202
 
2203
  $link = remove_query_arg( 'afilter' , $link );
@@ -2211,20 +2155,21 @@ function bp_activity_filter_links( $args = false ) {
2211
  /**
2212
  * Determine if a comment can be made on an activity item
2213
  *
2214
- * @since BuddyPress (1.2)
2215
  *
2216
  * @global object $activities_template {@link BP_Activity_Template}
 
2217
  * @uses bp_get_activity_action_name()
2218
  * @uses apply_filters() To call the 'bp_activity_can_comment' hook
2219
  *
2220
  * @return bool $can_comment Defaults to true
2221
  */
2222
  function bp_activity_can_comment() {
2223
- global $activities_template;
2224
 
2225
  $can_comment = true;
2226
 
2227
- if ( false === $activities_template->disable_blogforum_replies || (int) $activities_template->disable_blogforum_replies ) {
2228
  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() )
2229
  $can_comment = false;
2230
  }
@@ -2238,7 +2183,7 @@ function bp_activity_can_comment() {
2238
  /**
2239
  * Determine if a comment can be made on an activity reply item
2240
  *
2241
- * @since BuddyPress (1.5)
2242
  *
2243
  * @param object $comment Activity comment
2244
  *
@@ -2255,7 +2200,7 @@ function bp_activity_can_comment_reply( $comment ) {
2255
  /**
2256
  * Determine if an favorites are allowed
2257
  *
2258
- * @since BuddyPress (1.5)
2259
  *
2260
  * @uses apply_filters() To call the 'bp_activity_can_favorite' hook
2261
  *
@@ -2270,7 +2215,7 @@ function bp_activity_can_favorite() {
2270
  /**
2271
  * Echoes the total favorite count for a specified user
2272
  *
2273
- * @since BuddyPress (1.2)
2274
  *
2275
  * @param int $user_id Defaults to 0
2276
  *
@@ -2283,7 +2228,7 @@ function bp_total_favorite_count_for_user( $user_id = 0 ) {
2283
  /**
2284
  * Returns the total favorite count for a specified user
2285
  *
2286
- * @since BuddyPress (1.2)
2287
  *
2288
  * @param int $user_id Defaults to 0
2289
  *
@@ -2299,7 +2244,7 @@ function bp_total_favorite_count_for_user( $user_id = 0 ) {
2299
  /**
2300
  * Echoes the total mention count for a specified user
2301
  *
2302
- * @since BuddyPress (1.2)
2303
  *
2304
  * @param int $user_id Defaults to 0
2305
  *
@@ -2312,21 +2257,27 @@ function bp_total_mention_count_for_user( $user_id = 0 ) {
2312
  /**
2313
  * Returns the total mention count for a specified user
2314
  *
2315
- * @since BuddyPress (1.2)
 
 
2316
  *
2317
  * @param int $user_id Defaults to 0
 
2318
  * @uses bp_get_user_meta()
2319
  * @uses apply_filters() To call the 'bp_get_total_mention_count_for_user' hook
 
2320
  * @return int The total mention count for a specified user
2321
  */
2322
  function bp_get_total_mention_count_for_user( $user_id = 0 ) {
 
 
2323
  return apply_filters( 'bp_get_total_mention_count_for_user', bp_get_user_meta( $user_id, 'bp_new_mention_count', true ) );
2324
  }
2325
 
2326
  /**
2327
  * Echoes the public message link for displayed user
2328
  *
2329
- * @since BuddyPress (1.2)
2330
  *
2331
  * @uses bp_get_send_public_message_link()
2332
  */
@@ -2337,7 +2288,7 @@ function bp_send_public_message_link() {
2337
  /**
2338
  * Returns the public message link for displayed user
2339
  *
2340
- * @since BuddyPress (1.2)
2341
  *
2342
  * @global object $bp BuddyPress global settings
2343
  * @uses bp_is_my_profile()
@@ -2356,13 +2307,13 @@ function bp_send_public_message_link() {
2356
  if ( bp_is_my_profile() || !is_user_logged_in() )
2357
  return false;
2358
 
2359
- return apply_filters( 'bp_get_send_public_message_link', wp_nonce_url( bp_loggedin_user_domain() . bp_get_activity_slug() . '/?r=' . bp_core_get_username( bp_displayed_user_id(), bp_get_displayed_user_username(), $bp->displayed_user->userdata->user_login ) ) );
2360
  }
2361
 
2362
  /**
2363
  * Echoes the mentioned user display name
2364
  *
2365
- * @since BuddyPress (1.2)
2366
  *
2367
  * @param int|string User id or username
2368
  *
@@ -2375,7 +2326,7 @@ function bp_mentioned_user_display_name( $user_id_or_username ) {
2375
  /**
2376
  * Returns the mentioned user display name
2377
  *
2378
- * @since BuddyPress (1.2)
2379
  *
2380
  * @param int|string User id or username
2381
  *
@@ -2394,7 +2345,7 @@ function bp_mentioned_user_display_name( $user_id_or_username ) {
2394
  /**
2395
  * Output button for sending a public message
2396
  *
2397
- * @since BuddyPress (1.2)
2398
  *
2399
  * @param array $args Optional
2400
  *
@@ -2407,7 +2358,7 @@ function bp_send_public_message_button( $args = '' ) {
2407
  /**
2408
  * Return button for sending a public message
2409
  *
2410
- * @since BuddyPress (1.2)
2411
  *
2412
  * @param array $args Optional
2413
  *
@@ -2440,7 +2391,7 @@ function bp_send_public_message_button( $args = '' ) {
2440
  /**
2441
  * Outputs the activity post form action
2442
  *
2443
- * @since BuddyPress (1.2)
2444
  *
2445
  * @uses bp_get_activity_post_form_action()
2446
  */
@@ -2451,7 +2402,7 @@ function bp_activity_post_form_action() {
2451
  /**
2452
  * Returns the activity post form action
2453
  *
2454
- * @since BuddyPress (1.2)
2455
  *
2456
  * @uses home_url()
2457
  * @uses bp_get_activity_root_slug()
@@ -2468,7 +2419,7 @@ function bp_activity_post_form_action() {
2468
  /**
2469
  * Outputs the sitewide activity feed link
2470
  *
2471
- * @since BuddyPress (1.0)
2472
  *
2473
  * @uses bp_get_sitewide_activity_feed_link()
2474
  */
@@ -2479,7 +2430,7 @@ function bp_sitewide_activity_feed_link() {
2479
  /**
2480
  * Returns the sitewide activity feed link
2481
  *
2482
- * @since BuddyPress (1.0)
2483
  *
2484
  * @uses home_url()
2485
  * @uses bp_get_activity_root_slug()
@@ -2494,7 +2445,7 @@ function bp_sitewide_activity_feed_link() {
2494
  /**
2495
  * Outputs the member activity feed link
2496
  *
2497
- * @since BuddyPress (1.2)
2498
  *
2499
  * @uses bp_get_member_activity_feed_link()
2500
  */
@@ -2505,8 +2456,8 @@ function bp_member_activity_feed_link() {
2505
  /**
2506
  * Outputs the member activity feed link
2507
  *
2508
- * @since BuddyPress (1.0)
2509
- * @deprecated BuddyPress (1.2)
2510
  *
2511
  * @todo properly deprecated in favor of bp_member_activity_feed_link()
2512
  *
@@ -2517,7 +2468,7 @@ function bp_activities_member_rss_link() { echo bp_get_member_activity_feed_link
2517
  /**
2518
  * Returns the member activity feed link
2519
  *
2520
- * @since BuddyPress (1.2)
2521
  *
2522
  * @uses bp_is_profile_component()
2523
  * @uses bp_is_current_action()
@@ -2531,6 +2482,7 @@ function bp_activities_member_rss_link() { echo bp_get_member_activity_feed_link
2531
  * @return string $link The member activity feed link
2532
  */
2533
  function bp_get_member_activity_feed_link() {
 
2534
 
2535
  if ( bp_is_profile_component() || bp_is_current_action( 'just-me' ) )
2536
  $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/feed/';
@@ -2538,9 +2490,9 @@ function bp_activities_member_rss_link() { echo bp_get_member_activity_feed_link
2538
  $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_friends_slug() . '/feed/';
2539
  elseif ( bp_is_active( 'groups' ) && bp_is_current_action( bp_get_groups_slug() ) )
2540
  $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_groups_slug() . '/feed/';
2541
- elseif ( 'favorites' == bp_current_action() )
2542
  $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/favorites/feed/';
2543
- elseif ( 'mentions' == bp_current_action() )
2544
  $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/mentions/feed/';
2545
  else
2546
  $link = '';
@@ -2551,8 +2503,8 @@ function bp_activities_member_rss_link() { echo bp_get_member_activity_feed_link
2551
  /**
2552
  * Returns the member activity feed link
2553
  *
2554
- * @since BuddyPress (1.0)
2555
- * @deprecated BuddyPress (1.2)
2556
  *
2557
  * @todo properly deprecated in favor of bp_get_member_activity_feed_link()
2558
  *
@@ -2568,7 +2520,7 @@ function bp_activities_member_rss_link() { echo bp_get_member_activity_feed_link
2568
  /**
2569
  * Outputs the activity feed item guid
2570
  *
2571
- * @since BuddyPress (1.0)
2572
  *
2573
  * @uses bp_activity_feed_item_guid()
2574
  */
@@ -2579,7 +2531,7 @@ function bp_activity_feed_item_guid() {
2579
  /**
2580
  * Returns the activity feed item guid
2581
  *
2582
- * @since BuddyPress (1.2)
2583
  *
2584
  * @global object $activities_template {@link BP_Activity_Template}
2585
  * @uses apply_filters() To call the 'bp_get_activity_feed_item_guid' hook
@@ -2595,7 +2547,7 @@ function bp_activity_feed_item_guid() {
2595
  /**
2596
  * Outputs the activity feed item title
2597
  *
2598
- * @since BuddyPress (1.0)
2599
  *
2600
  * @uses bp_get_activity_feed_item_title()
2601
  */
@@ -2606,7 +2558,7 @@ function bp_activity_feed_item_title() {
2606
  /**
2607
  * Returns the activity feed item title
2608
  *
2609
- * @since BuddyPress (1.0)
2610
  *
2611
  * @global object $activities_template {@link BP_Activity_Template}
2612
  * @uses ent2ncr()
@@ -2639,7 +2591,7 @@ function bp_activity_feed_item_title() {
2639
  /**
2640
  * Outputs the activity feed item link
2641
  *
2642
- * @since BuddyPress (1.0)
2643
  *
2644
  * @uses bp_get_activity_feed_item_link()
2645
  */
@@ -2650,7 +2602,7 @@ function bp_activity_feed_item_link() {
2650
  /**
2651
  * Returns the activity feed item link
2652
  *
2653
- * @since BuddyPress (1.0)
2654
  *
2655
  * @global object $activities_template {@link BP_Activity_Template}
2656
  * @uses apply_filters() To call the 'bp_get_activity_feed_item_link' hook
@@ -2666,7 +2618,7 @@ function bp_activity_feed_item_link() {
2666
  /**
2667
  * Outputs the activity feed item date
2668
  *
2669
- * @since BuddyPress (1.0)
2670
  *
2671
  * @uses bp_get_activity_feed_item_date()
2672
  */
@@ -2677,7 +2629,7 @@ function bp_activity_feed_item_date() {
2677
  /**
2678
  * Returns the activity feed item date
2679
  *
2680
- * @since BuddyPress (1.0)
2681
  *
2682
  * @global object $activities_template {@link BP_Activity_Template}
2683
  * @uses apply_filters() To call the 'bp_get_activity_feed_item_date' hook
@@ -2693,7 +2645,7 @@ function bp_activity_feed_item_date() {
2693
  /**
2694
  * Outputs the activity feed item description
2695
  *
2696
- * @since BuddyPress (1.0)
2697
  *
2698
  * @uses bp_get_activity_feed_item_description()
2699
  */
@@ -2704,7 +2656,7 @@ function bp_activity_feed_item_description() {
2704
  /**
2705
  * Returns the activity feed item description
2706
  *
2707
- * @since BuddyPress (1.0)
2708
  *
2709
  * @global object $activities_template {@link BP_Activity_Template}
2710
  * @uses ent2ncr()
@@ -2716,9 +2668,10 @@ function bp_activity_feed_item_description() {
2716
  function bp_get_activity_feed_item_description() {
2717
  global $activities_template;
2718
 
2719
- $content = '';
2720
- if ( ! empty( $activities_template->activity->content ) )
2721
  $content = $activities_template->activity->content;
 
 
2722
 
2723
  return apply_filters( 'bp_get_activity_feed_item_description', ent2ncr( convert_chars( str_replace( '%s', '', $content ) ) ) );
2724
  }
@@ -2726,7 +2679,7 @@ function bp_activity_feed_item_description() {
2726
  /**
2727
  * Template tag so we can hook activity feed to <head>
2728
  *
2729
- * @since BuddyPress (1.5)
2730
  *
2731
  * @uses bloginfo()
2732
  * @uses bp_sitewide_activity_feed_link()
@@ -2740,4 +2693,4 @@ function bp_activity_sitewide_feed() {
2740
  }
2741
  add_action( 'bp_head', 'bp_activity_sitewide_feed' );
2742
 
2743
- ?>
13
  /**
14
  * Output the activity component slug
15
  *
16
+ * @since 1.5.0
17
  *
18
  * @uses bp_get_activity_slug()
19
  */
23
  /**
24
  * Return the activity component slug
25
  *
26
+ * @since 1.5.0
27
  *
28
  * @global object $bp BuddyPress global settings
29
  * @uses apply_filters() To call the 'bp_get_activity_slug' hook
36
  /**
37
  * Output the activity component root slug
38
  *
39
+ * @since 1.5.0
40
  *
41
  * @uses bp_get_activity_root_slug()
42
  */
46
  /**
47
  * Return the activity component root slug
48
  *
49
+ * @since 1.5.0
50
  *
51
  * @global object $bp BuddyPress global settings
52
  * @uses apply_filters() To call the 'bp_get_activity_root_slug' hook
59
  /**
60
  * Output member directory permalink
61
  *
62
+ * @since 1.5.0
63
  *
64
  * @uses bp_get_activity_directory_permalink()
65
  */
69
  /**
70
  * Return member directory permalink
71
  *
72
+ * @since 1.5.0
73
  *
74
  * @uses traisingslashit()
75
  * @uses bp_get_root_domain()
87
  *
88
  * This is responsible for loading a group of activity items and displaying them
89
  *
90
+ * @since 1.0.0
91
  */
92
  class BP_Activity_Template {
93
  var $current_activity = -1;
104
 
105
  var $full_name;
106
 
107
+ function bp_activity_template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden, $exclude = false, $in = false ) {
108
+ $this->__construct( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden, $exclude, $in );
109
+ }
110
+
111
+ function __construct( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden, $exclude = false, $in = false ) {
 
 
 
 
112
  global $bp;
113
 
114
+ $this->pag_page = isset( $_REQUEST['acpage'] ) ? intval( $_REQUEST['acpage'] ) : $page;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
116
 
117
  // Check if blog/forum replies are disabled
118
  $this->disable_blogforum_replies = isset( $bp->site_options['bp-disable-blogforum-comments'] ) ? $bp->site_options['bp-disable-blogforum-comments'] : false;
119
 
120
  // Get an array of the logged in user's favorite activities
121
+ $this->my_favs = maybe_unserialize( bp_get_user_meta( $bp->loggedin_user->id, 'bp_favorite_activities', true ) );
122
 
123
  // Fetch specific activity items based on ID's
124
  if ( !empty( $include ) )
125
+ $this->activities = bp_activity_get_specific( array( 'activity_ids' => explode( ',', $include ), 'max' => $max, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'sort' => $sort, 'display_comments' => $display_comments, 'show_hidden' => $show_hidden ) );
 
126
  // Fetch all activity items
127
  else
128
+ $this->activities = bp_activity_get( array( 'display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter, 'show_hidden' => $show_hidden, 'exclude' => $exclude, 'in' => $in ) );
129
 
130
+ if ( !$max || $max >= (int)$this->activities['total'] )
131
+ $this->total_activity_count = (int)$this->activities['total'];
132
  else
133
+ $this->total_activity_count = (int)$max;
134
 
135
  $this->activities = $this->activities['activities'];
136
 
138
  if ( $max >= count($this->activities) ) {
139
  $this->activity_count = count( $this->activities );
140
  } else {
141
+ $this->activity_count = (int)$max;
142
  }
143
  } else {
144
  $this->activity_count = count( $this->activities );
145
  }
146
 
147
+ $this->full_name = $bp->displayed_user->fullname;
148
 
149
  // Fetch parent content for activity comments so we do not have to query in the loop
150
+ foreach ( (array)$this->activities as $activity ) {
151
  if ( 'activity_comment' != $activity->type )
152
  continue;
153
 
164
  unset( $activity_parents );
165
  }
166
 
167
+ if ( (int)$this->total_activity_count && (int)$this->pag_num ) {
168
  $this->pag_links = paginate_links( array(
169
+ 'base' => add_query_arg( 'acpage', '%#%' ),
170
  'format' => '',
171
+ 'total' => ceil( (int)$this->total_activity_count / (int)$this->pag_num ),
172
+ 'current' => (int)$this->pag_page,
173
  'prev_text' => _x( '&larr;', 'Activity pagination previous text', 'buddypress' ),
174
  'next_text' => _x( '&rarr;', 'Activity pagination next text', 'buddypress' ),
175
  'mid_size' => 1
212
  }
213
 
214
  function the_activity() {
215
+ global $activity;
216
 
217
  $this->in_the_loop = true;
218
+ $this->activity = $this->next_activity();
219
 
220
  if ( is_array( $this->activity ) )
221
  $this->activity = (object) $this->activity;
230
  *
231
  * Based on the $args passed, bp_has_activities() populates the $activities_template global.
232
  *
233
+ * @since 1.0.0
234
  *
235
  * @param array $args Arguments for limiting the contents of the activity loop. Can be passed as an associative array or as a URL argument string
236
  *
267
  $primary_id = false;
268
 
269
  // User filtering
270
+ if ( !empty( $bp->displayed_user->id ) )
271
+ $user_id = $bp->displayed_user->id;
272
 
273
  // Group filtering
274
  if ( !empty( $bp->groups->current_group ) ) {
275
  $object = $bp->groups->id;
276
  $primary_id = $bp->groups->current_group->id;
277
 
278
+ if ( 'public' != $bp->groups->current_group->status && ( groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) || $bp->loggedin_user->is_super_admin ) )
279
  $show_hidden = true;
280
  }
281
 
282
  // The default scope should recognize custom slugs
283
+ if ( array_key_exists( $bp->current_action, (array)$bp->loaded_components ) ) {
284
+ $scope = $bp->loaded_components[$bp->current_action];
285
  }
286
  else
287
  $scope = bp_current_action();
301
  'per_page' => 20, // number of items per page
302
  'max' => false, // max number to return
303
  'show_hidden' => $show_hidden, // Show activity items that are hidden site-wide?
 
 
 
304
 
305
  // Scope - pre-built activity filters for a user (friends/groups/favorites/mentions)
306
  'scope' => $scope,
326
 
327
  // determine which user_id applies
328
  if ( empty( $user_id ) )
329
+ $user_id = ( !empty( $bp->displayed_user->id ) ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
330
 
331
  // are we displaying user specific activity?
332
  if ( is_numeric( $user_id ) ) {
333
+ $show_hidden = ( $user_id == $bp->loggedin_user->id && $scope != 'friends' ) ? 1 : 0;
334
 
335
  switch ( $scope ) {
336
  case 'friends':
339
  if ( empty( $friends ) )
340
  return false;
341
 
342
+ $user_id = implode( ',', (array)$friends );
343
  break;
344
  case 'groups':
345
  if ( bp_is_active( 'groups' ) ) {
348
  return false;
349
 
350
  $object = $bp->groups->id;
351
+ $primary_id = implode( ',', (array)$groups['groups'] );
352
 
353
  $user_id = 0;
354
  }
358
  if ( empty( $favs ) )
359
  return false;
360
 
361
+ $include = implode( ',', (array)$favs );
362
  $display_comments = true;
363
  break;
364
  case 'mentions':
365
+ $user_nicename = ( !empty( $bp->displayed_user->id ) ) ? $bp->displayed_user->userdata->user_nicename : $bp->loggedin_user->userdata->user_nicename;
366
+ $user_login = ( !empty( $bp->displayed_user->id ) ) ? $bp->displayed_user->userdata->user_login : $bp->loggedin_user->userdata->user_login;
367
+ $search_terms = '@' . bp_core_get_username( $user_id, $user_nicename, $user_login ) . '<'; // Start search at @ symbol and stop search at closing tag delimiter.
368
  $display_comments = 'stream';
369
  $user_id = 0;
370
  break;
373
  }
374
 
375
  // Do not exceed the maximum per page
376
+ if ( !empty( $max ) && ( (int)$per_page > (int)$max ) )
377
  $per_page = $max;
378
 
379
+ // Support for basic filters in earlier BP versions.
380
+ if ( isset( $_GET['afilter'] ) )
 
 
381
  $filter = array( 'object' => $_GET['afilter'] );
382
  else if ( !empty( $user_id ) || !empty( $object ) || !empty( $action ) || !empty( $primary_id ) || !empty( $secondary_id ) )
383
  $filter = array( 'user_id' => $user_id, 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id );
384
  else
385
  $filter = false;
386
 
387
+ $activities_template = new BP_Activity_Template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden, $exclude, $in );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
388
 
389
+ return apply_filters( 'bp_has_activities', $activities_template->has_activities(), $activities_template );
390
  }
391
 
392
  /**
393
  * Determines if there are still activities left in the loop.
394
  *
395
+ * @since 1.0.0
396
  *
397
  * @global object $activities_template {@link BP_Activity_Template}
398
  * @uses BP_Activity_Template::user_activities() {@link BP_Activity_Template::user_activities()}
407
  /**
408
  * Gets the current activity object in the loop
409
  *
410
+ * @since 1.0.0
411
  *
412
  * @global object $activities_template {@link BP_Activity_Template}
413
  * @uses BP_Activity_Template::the_activity() {@link BP_Activity_Template::the_activity()}
422
  /**
423
  * Outputs the activity pagination count
424
  *
425
+ * @since 1.0.0
426
  *
427
  * @global object $activities_template {@link BP_Activity_Template}
428
  * @uses BP_Activity_Template::the_activity() {@link BP_Activity_Template::the_activity()}
434
  /**
435
  * Returns the activity pagination count
436
  *
437
+ * @since 1.2.0
438
  *
439
+ * @global object $bp BuddyPress global settings
440
  * @global object $activities_template {@link BP_Activity_Template}
441
  * @uses bp_core_number_format()
442
  *
443
  * @return string The pagination text
444
  */
445
  function bp_get_activity_pagination_count() {
446
+ global $bp, $activities_template;
447
 
448
  $start_num = intval( ( $activities_template->pag_page - 1 ) * $activities_template->pag_num ) + 1;
449
  $from_num = bp_core_number_format( $start_num );
456
  /**
457
  * Outputs the activity pagination links
458
  *
459
+ * @since 1.0.0
460
  *
461
  * @uses bp_get_activity_pagination_links()
462
  */
467
  /**
468
  * Outputs the activity pagination links
469
  *
470
+ * @since 1.0.0
471
  *
472
  * @global object $activities_template {@link BP_Activity_Template}
473
  * @uses apply_filters() To call the 'bp_get_activity_pagination_links' hook
483
  /**
484
  * Returns true when there are more activity items to be shown than currently appear
485
  *
486
+ * @since 1.5.0
487
  *
488
  * @global object $activities_template {@link BP_Activity_Template}
489
  * @uses apply_filters() To call the 'bp_activity_has_more_items' hook
494
  global $activities_template;
495
 
496
  $remaining_pages = floor( ( $activities_template->total_activity_count - 1 ) / ( $activities_template->pag_num * $activities_template->pag_page ) );
497
+ $has_more_items = (int)$remaining_pages ? true : false;
498
 
499
  return apply_filters( 'bp_activity_has_more_items', $has_more_items );
500
  }
502
  /**
503
  * Outputs the activity count
504
  *
505
+ * @since 1.2.0
506
  *
507
  * @uses bp_get_activity_count()
508
  */
513
  /**
514
  * Returns the activity count
515
  *
516
+ * @since 1.2.0
517
  *
518
  * @global object $activities_template {@link BP_Activity_Template}
519
  * @uses apply_filters() To call the 'bp_get_activity_count' hook
523
  function bp_get_activity_count() {
524
  global $activities_template;
525
 
526
+ return apply_filters( 'bp_get_activity_count', (int)$activities_template->activity_count );
527
  }
528
 
529
  /**
530
  * Outputs the number of activities per page
531
  *
532
+ * @since 1.2.0
533
  *
534
  * @uses bp_get_activity_per_page()
535
  */
540
  /**
541
  * Returns the number of activities per page
542
  *
543
+ * @since 1.2.0
544
  *
545
  * @global object $activities_template {@link BP_Activity_Template}
546
  * @uses apply_filters() To call the 'bp_get_activity_per_page' hook
550
  function bp_get_activity_per_page() {
551
  global $activities_template;
552
 
553
+ return apply_filters( 'bp_get_activity_per_page', (int)$activities_template->pag_num );
554
  }
555
 
556
  /**
557
  * Outputs the activities title
558
  *
559
+ * @since 1.0.0
560
  *
561
  * @uses bp_get_activities_title()
562
  */
563
  function bp_activities_title() {
564
+ global $bp_activity_title;
565
+
566
  echo bp_get_activities_title();
567
  }
568
 
569
  /**
570
  * Returns the activities title
571
  *
572
+ * @since 1.0.0
573
  *
574
  * @global string $bp_activity_title
575
  * @uses apply_filters() To call the 'bp_get_activities_title' hook
585
  /**
586
  * {@internal Missing Description}
587
  *
588
+ * @since 1.0.0
589
  *
590
  * @uses bp_get_activities_no_activity()
591
  */
592
  function bp_activities_no_activity() {
593
+ global $bp_activity_no_activity;
594
+
595
  echo bp_get_activities_no_activity();
596
  }
597
 
598
  /**
599
  * {@internal Missing Description}
600
  *
601
+ * @since 1.0.0
602
  *
603
  * @global string $bp_activity_no_activity
604
  * @uses apply_filters() To call the 'bp_get_activities_no_activity' hook
614
  /**
615
  * Outputs the activity id
616
  *
617
+ * @since 1.2.0
618
  *
619
  * @uses bp_get_activity_id()
620
  */
625
  /**
626
  * Returns the activity id
627
  *
628
+ * @since 1.2.0
629
  *
630
  * @global object $activities_template {@link BP_Activity_Template}
631
  * @uses apply_filters() To call the 'bp_get_activity_id' hook
640
  /**
641
  * Outputs the activity item id
642
  *
643
+ * @since 1.2.0
644
  *
645
  * @uses bp_get_activity_item_id()
646
  */
651
  /**
652
  * Returns the activity item id
653
  *
654
+ * @since 1.2.0
655
  *
656
  * @global object $activities_template {@link BP_Activity_Template}
657
  * @uses apply_filters() To call the 'bp_get_activity_item_id' hook
666
  /**
667
  * Outputs the activity secondary item id
668
  *
669
+ * @since 1.2.0
670
  *
671
  * @uses bp_get_activity_secondary_item_id()
672
  */
677
  /**
678
  * Returns the activity secondary item id
679
  *
680
+ * @since 1.2.0
681
  *
682
  * @global object $activities_template {@link BP_Activity_Template}
683
  * @uses apply_filters() To call the 'bp_get_activity_secondary_item_id' hook
692
  /**
693
  * Outputs the date the activity was recorded
694
  *
695
+ * @since 1.2.0
696
  *
697
  * @uses bp_get_activity_date_recorded()
698
  */
703
  /**
704
  * Returns the date the activity was recorded
705
  *
706
+ * @since 1.2.0
707
  *
708
  * @global object $activities_template {@link BP_Activity_Template}
709
  * @uses apply_filters() To call the 'bp_get_activity_date_recorded' hook
718
  /**
719
  * Outputs the activity object name
720
  *
721
+ * @since 1.2.0
722
  *
723
  * @uses bp_get_activity_object_name()
724
  */
729
  /**
730
  * Returns the activity object name
731
  *
732
+ * @since 1.2.0
733
  *
734
  * @global object $activities_template {@link BP_Activity_Template}
735
  * @uses apply_filters() To call the 'bp_get_activity_object_name' hook
744
  /**
745
  * Outputs the activity type
746
  *
747
+ * @since 1.2.0
748
  *
749
  * @uses bp_get_activity_type()
750
  */
755
  /**
756
  * Returns the activity type
757
  *
758
+ * @since 1.2.0
759
  *
760
  * @global object $activities_template {@link BP_Activity_Template}
761
  * @uses apply_filters() To call the 'bp_get_activity_type' hook
772
  *
773
  * Just a wrapper for bp_activity_type()
774
  *
775
+ * @since 1.2.0
776
+ * @deprecated 1.5.0
777
  *
778
  * @todo Properly deprecate in favor of bp_activity_type() and
779
  * remove redundant echo
787
  *
788
  * Just a wrapper for bp_get_activity_type()
789
  *
790
+ * @since 1.2.0
791
+ * @deprecated 1.5.0
792
  *
793
  * @todo Properly deprecate in favor of bp_get_activity_type()
794
  *
801
  /**
802
  * Outputs the activity user id
803
  *
804
+ * @since 1.1.0
805
  *
806
  * @uses bp_get_activity_user_id()
807
  */
812
  /**
813
  * Returns the activity user id
814
  *
815
+ * @since 1.1.0
816
  *
817
  * @global object $activities_template {@link BP_Activity_Template}
818
  * @uses apply_filters() To call the 'bp_get_activity_user_id' hook
827
  /**
828
  * Outputs the activity user link
829
  *
830
+ * @since 1.2.0
831
  *
832
  * @uses bp_get_activity_user_link()
833
  */
838
  /**
839
  * Returns the activity user link
840
  *
841
+ * @since 1.2.0
842
  *
843
  * @global object $activities_template {@link BP_Activity_Template}
844
  * @uses bp_core_get_user_domain()
860
  /**
861
  * Output the avatar of the user that performed the action
862
  *
863
+ * @since 1.1.0
864
  *
865
  * @param array $args
866
  *
872
  /**
873
  * Return the avatar of the user that performed the action
874
  *
875
+ * @since 1.1.0
876
  *
877
  * @param array $args optional
878
  *
893
  // On activity permalink pages, default to the full-size avatar
894
  $type_default = bp_is_single_activity() ? 'full' : 'thumb';
895
 
 
 
 
 
 
 
 
 
896
  $defaults = array(
897
+ 'alt' => __( 'Profile picture of %s', 'buddypress' ),
898
  'class' => 'avatar',
899
  'email' => false,
900
  'type' => $type_default,
940
  /**
941
  * Output the avatar of the object that action was performed on
942
  *
943
+ * @since 1.2.0
944
  *
945
  * @param array $args optional
946
  *
953
  /**
954
  * Return the avatar of the object that action was performed on
955
  *
956
+ * @since 1.2.0
957
  *
958
  * @param array $args optional
959
  *
960
+ * @global object $bp BuddyPress global settings
961
  * @global object $activities_template {@link BP_Activity_Template}
962
  * @uses wp_parse_args()
963
  * @uses get_blog_option()
969
  * @return string The secondary avatar
970
  */
971
  function bp_get_activity_secondary_avatar( $args = '' ) {
972
+ global $bp, $activities_template;
973
 
974
  $defaults = array(
975
  'type' => 'thumb',
985
  // Set item_id and object (default to user)
986
  switch ( $activities_template->activity->component ) {
987
  case 'groups' :
988
+ $object = 'group';
989
  $item_id = $activities_template->activity->item_id;
990
 
991
+ if ( empty( $alt ) )
992
+ $alt = __( 'Group logo of %s', 'buddypress' );
 
 
 
 
 
 
 
993
 
994
  break;
995
  case 'blogs' :
996
+ $object = 'blog';
997
  $item_id = $activities_template->activity->item_id;
998
 
999
+ if ( !$alt )
1000
+ $alt = sprintf( __( 'Site authored by %s', 'buddypress' ), get_blog_option( $item_id, 'blogname' ) );
 
1001
 
1002
  break;
1003
  case 'friends' :
1004
  $object = 'user';
1005
  $item_id = $activities_template->activity->secondary_item_id;
1006
 
1007
+ if ( empty( $alt ) )
1008
+ $alt = __( 'Profile picture of %s', 'buddypress' );
 
1009
 
1010
  break;
1011
  default :
1012
  $object = 'user';
1013
  $item_id = $activities_template->activity->user_id;
1014
+ $email = $activities_template->activity->user_email;
1015
 
1016
+ if ( !$alt )
1017
+ $alt = __( 'Profile picture of %s', 'buddypress' );
 
1018
 
1019
  break;
1020
  }
1033
  /**
1034
  * Output the activity action
1035
  *
1036
+ * @since 1.2.0
1037
  *
1038
  * @uses bp_get_activity_action()
1039
  */
1044
  /**
1045
  * Return the activity action
1046
  *
1047
+ * @since 1.2.0
1048
  *
1049
  * @global object $activities_template {@link BP_Activity_Template}
1050
  * @uses apply_filters_ref_array() To call the 'bp_get_activity_action_pre_meta' hook
1068
  /**
1069
  * Output the activity content body
1070
  *
1071
+ * @since 1.2.0
1072
  *
1073
  * @uses bp_get_activity_content_body()
1074
  */
1079
  /**
1080
  * Return the activity content body
1081
  *
1082
+ * @since 1.2.0
1083
  *
1084
  * @global object $activities_template {@link BP_Activity_Template}
1085
  * @uses bp_insert_activity_meta()
1100
  /**
1101
  * Does the activity have content?
1102
  *
1103
+ * @since 1.2.0
1104
  *
1105
  * @global object $activities_template {@link BP_Activity_Template}
1106
  *
1118
  /**
1119
  * Output the activity content
1120
  *
1121
+ * @since 1.0.0
1122
+ * @deprecated 1.5.0
1123
  *
1124
  * @todo properly deprecate this function
1125
  *
1132
  /**
1133
  * Return the activity content
1134
  *
1135
+ * @since 1.0.0
1136
+ * @deprecated 1.5.0
1137
  *
1138
  * @todo properly deprecate this function
1139
  *
1140
+ * @global object $activities_template {@link BP_Activity_Template}
1141
  * @uses bp_get_activity_action()
1142
  * @uses bp_get_activity_content_body()
1143
  * @uses apply_filters() To call the 'bp_get_activity_content' hook
1145
  * @return string The activity content
1146
  */
1147
  function bp_get_activity_content() {
1148
+ global $activities_template;
1149
+
1150
  /**
1151
  * If you want to filter activity update content, please use
1152
  * the filter 'bp_get_activity_content_body'
1161
  /**
1162
  * Insert activity meta
1163
  *
1164
+ * @since 1.2.0
1165
  *
1166
  * @param string $content
1167
  *
1168
  * @global object $activities_template {@link BP_Activity_Template}
1169
+ * @global object $bp BuddyPress global settings
1170
  * @uses bp_core_time_since()
1171
  * @uses apply_filters_ref_array() To call the 'bp_activity_time_since' hook
1172
  * @uses bp_is_single_activity()
1178
  * @return string The activity content
1179
  */
1180
  function bp_insert_activity_meta( $content ) {
1181
+ global $activities_template, $bp;
1182
 
1183
  // Strip any legacy time since placeholders from BP 1.0-1.1
1184
  $content = str_replace( '<span class="time-since">%s</span>', '', $content );
1198
  /**
1199
  * Determine if the current user can delete an activity item
1200
  *
1201
+ * @since 1.2.0
1202
  *
1203
  * @param object $activity Optional
1204
  *
1205
  * @global object $activities_template {@link BP_Activity_Template}
1206
+ * @global object $bp BuddyPress global settings
1207
  * @uses apply_filters() To call the 'bp_activity_user_can_delete' hook
1208
  *
1209
  * @return bool True if can delete, false otherwise
1210
  */
1211
  function bp_activity_user_can_delete( $activity = false ) {
1212
+ global $activities_template, $bp;
1213
 
1214
  if ( !$activity )
1215
  $activity = $activities_template->activity;
1219
 
1220
  $can_delete = false;
1221
 
1222
+ if ( $bp->loggedin_user->is_super_admin )
1223
  $can_delete = true;
1224
 
1225
+ if ( $activity->user_id == $bp->loggedin_user->id )
1226
  $can_delete = true;
1227
 
1228
+ if ( $bp->is_item_admin && $bp->is_single_item )
1229
  $can_delete = true;
1230
 
1231
  return apply_filters( 'bp_activity_user_can_delete', $can_delete );
1234
  /**
1235
  * Output the activity parent content
1236
  *
1237
+ * @since 1.2.0
1238
  *
1239
  * @param array $args Optional
1240
  *
1247
  /**
1248
  * Return the activity content
1249
  *
1250
+ * @since 1.2.0
1251
  *
1252
  * @param array $args Optional
1253
  *
1254
+ * @global object $bp BuddyPress global settings
1255
  * @global object $activities_template {@link BP_Activity_Template}
1256
  * @uses wp_parse_args()
1257
  * @uses apply_filters() To call the 'bp_get_activity_parent_content' hook
1259
  * @return mixed False on failure, otherwise the activity parent content
1260
  */
1261
  function bp_get_activity_parent_content( $args = '' ) {
1262
+ global $bp, $activities_template;
1263
 
1264
  $defaults = array(
1265
  'hide_user' => false
1293
  /**
1294
  * Output whether or not the current activity is in a current user's favorites
1295
  *
1296
+ * @since 1.2.0
1297
  *
1298
  * @uses bp_get_activity_is_favorite()
1299
  */
1304
  /**
1305
  * Return whether or not the current activity is in a current user's favorites
1306
  *
1307
+ * @since 1.2.0
1308
  *
1309
+ * @global object $bp BuddyPress global settings
1310
  * @global object $activities_template {@link BP_Activity_Template}
1311
  * @uses apply_filters() To call the 'bp_get_activity_is_favorite' hook
1312
  *
1313
  * @return bool True if user favorite, false otherwise
1314
  */
1315
  function bp_get_activity_is_favorite() {
1316
+ global $bp, $activities_template;
1317
 
1318
+ return apply_filters( 'bp_get_activity_is_favorite', in_array( $activities_template->activity->id, (array)$activities_template->my_favs ) );
1319
  }
1320
 
1321
  /**
1322
  * Echoes the comment markup for an activity item
1323
  *
1324
+ * @since 1.2.0
1325
  *
1326
  * @todo deprecate $args param
1327
  *
1334
  /**
1335
  * Gets the comment markup for an activity item
1336
  *
1337
+ * @since 1.2.0
1338
  *
1339
  * @todo deprecate $args param
1340
  *
1344
  * @param string $args Unused. Appears to be left over from an earlier implementation.
1345
  *
1346
  * @global object $activities_template {@link BP_Activity_Template}
1347
+ * @global object $bp BuddyPress global settings
1348
  * @uses bp_activity_recurse_comments()
1349
  */
1350
  function bp_activity_get_comments( $args = '' ) {
1351
+ global $activities_template, $bp;
1352
 
1353
  if ( !isset( $activities_template->activity->children ) || !$activities_template->activity->children )
1354
  return false;
1362
  * Note: The recursion itself used to happen entirely in this function. Now it is
1363
  * split between here and the comment.php template.
1364
  *
1365
+ * @since 1.2.0
1366
  *
1367
  * @todo remove $counter global
1368
  *
1369
  * @param object $comment The activity object currently being recursed
1370
  *
1371
  * @global object $activities_template {@link BP_Activity_Template}
1372
+ * @global object $bp BuddyPress global settings
1373
  * @uses locate_template()
1374
  */
1375
  function bp_activity_recurse_comments( $comment ) {
1376
+ global $activities_template, $bp, $counter;
1377
 
1378
+ if ( !$comment )
1379
  return false;
1380
 
1381
  if ( empty( $comment->children ) )
1382
  return false;
1383
 
1384
+ echo '<ul>';
1385
+ foreach ( (array)$comment->children as $comment_child ) {
1386
  // Put the comment into the global so it's available to filters
1387
  $activities_template->activity->current_comment = $comment_child;
1388
 
1400
 
1401
  unset( $activities_template->activity->current_comment );
1402
  }
1403
+ echo '</ul>';
1404
  }
1405
 
1406
  /**
1407
  * Utility function that returns the comment currently being recursed
1408
  *
1409
+ * @since 1.5.0
1410
  *
1411
  * @global object $activities_template {@link BP_Activity_Template}
1412
  * @uses apply_filters() To call the 'bp_activity_current_comment' hook
1425
  /**
1426
  * Echoes the id of the activity comment currently being displayed
1427
  *
1428
+ * @since 1.5.0
1429
  *
1430
  * @uses bp_get_activity_comment_id()
1431
  */
1436
  /**
1437
  * Gets the id of the activity comment currently being displayed
1438
  *
1439
+ * @since 1.5.0
1440
  *
1441
  * @global object $activities_template {@link BP_Activity_Template}
1442
  * @uses apply_filters() To call the 'bp_activity_comment_id' hook
1454
  /**
1455
  * Echoes the user_id of the author of the activity comment currently being displayed
1456
  *
1457
+ * @since 1.5.0
1458
  *
1459
  * @uses bp_get_activity_comment_user_id()
1460
  */
1465
  /**
1466
  * Gets the user_id of the author of the activity comment currently being displayed
1467
  *
1468
+ * @since 1.5.0
1469
  *
1470
  * @global object $activities_template {@link BP_Activity_Template}
1471
  * @uses apply_filters() To call the 'bp_activity_comment_user_id' hook
1483
  /**
1484
  * Echoes the author link for the activity comment currently being displayed
1485
  *
1486
+ * @since 1.5.0
1487
  *
1488
  * @uses bp_get_activity_comment_user_link()
1489
  */
1494
  /**
1495
  * Gets the author link for the activity comment currently being displayed
1496
  *
1497
+ * @since 1.5.0
1498
  *
1499
  * @uses bp_core_get_user_domain()
1500
  * @uses bp_get_activity_comment_user_id()
1511
  /**
1512
  * Echoes the author name for the activity comment currently being displayed
1513
  *
1514
+ * @since 1.5.0
1515
  *
1516
  * @uses bp_get_activity_comment_name()
1517
  */
1524
  *
1525
  * The use of the bp_acomment_name filter is deprecated. Please use bp_activity_comment_name
1526
  *
1527
+ * @since 1.5.0
1528
  *
1529
  * @global object $activities_template {@link BP_Activity_Template}
1530
  * @uses apply_filters() To call the 'bp_acomment_name' hook
1535
  function bp_get_activity_comment_name() {
1536
  global $activities_template;
1537
 
1538
+ $name = apply_filters( 'bp_acomment_name', $activities_template->activity->current_comment->user_fullname, $activities_template->activity->current_comment ); // backward compatibility
 
 
 
1539
 
1540
  return apply_filters( 'bp_activity_comment_name', $name );
1541
  }
1543
  /**
1544
  * Echoes the date_recorded of the activity comment currently being displayed
1545
  *
1546
+ * @since 1.5.0
1547
  *
1548
  * @uses bp_get_activity_comment_date_recorded()
1549
  */
1554
  /**
1555
  * Gets the date_recorded for the activity comment currently being displayed
1556
  *
1557
+ * @since 1.5.0
1558
  *
1559
  * @global object $activities_template {@link BP_Activity_Template}
1560
  * @uses bp_core_time_since()
1576
  /**
1577
  * Echoes the 'delete' URL for the activity comment currently being displayed
1578
  *
1579
+ * @since 1.5.0
1580
  *
1581
  * @uses bp_get_activity_comment_delete_link()
1582
  */
1587
  /**
1588
  * Gets the 'delete' URL for the activity comment currently being displayed
1589
  *
1590
+ * @since 1.5.0
1591
  *
1592
+ * @global object $bp BuddyPress global settings
1593
  * @uses wp_nonce_url()
1594
  * @uses bp_get_root_domain()
1595
  * @uses bp_get_activity_slug()
1599
  * @return string $link The nonced URL for deleting the current activity comment
1600
  */
1601
  function bp_get_activity_comment_delete_link() {
1602
+ global $bp;
1603
+
1604
+ $link = wp_nonce_url( bp_get_root_domain() . '/' . bp_get_activity_slug() . '/delete/?cid=' . bp_get_activity_comment_id(), 'bp_activity_delete_link' );
1605
 
1606
  return apply_filters( 'bp_activity_comment_delete_link', $link );
1607
  }
1609
  /**
1610
  * Echoes the content of the activity comment currently being displayed
1611
  *
1612
+ * @since 1.5.0
1613
  *
1614
  * @uses bp_get_activity_comment_content()
1615
  */
1624
  * applied to activity items in general. Use bp_activity_comment_content to modify the
1625
  * content of activity comments only.
1626
  *
1627
+ * @since 1.5.0
1628
  *
1629
  * @global object $activities_template {@link BP_Activity_Template}
1630
  * @uses apply_filters() To call the 'bp_get_activity_content' hook
1643
  /**
1644
  * Echoes the activity comment count
1645
  *
1646
+ * @since 1.2.0
1647
  *
1648
  * @uses bp_activity_get_comment_count()
1649
  */
1658
  * applied to activity items in general. Use bp_activity_comment_content to modify the
1659
  * content of activity comments only.
1660
  *
1661
+ * @since 1.2.0
1662
  *
1663
  * @todo deprecate $args
1664
  *
1665
  * @global object $activities_template {@link BP_Activity_Template}
1666
+ * @global object $bp BuddyPress global settings
1667
  * @uses bp_activity_recurse_comment_count()
1668
  * @uses apply_filters() To call the 'bp_activity_get_comment_count' hook
1669
  *
1670
  * @return int $count The activity comment count. Defaults to zero
1671
  */
1672
  function bp_activity_get_comment_count( $args = '' ) {
1673
+ global $activities_template, $bp;
1674
 
1675
  if ( !isset( $activities_template->activity->children ) || !$activities_template->activity->children )
1676
  return 0;
1677
 
1678
  $count = bp_activity_recurse_comment_count( $activities_template->activity );
1679
 
1680
+ return apply_filters( 'bp_activity_get_comment_count', (int)$count );
1681
  }
1682
 
1683
  /**
1687
  * applied to activity items in general. Use bp_activity_comment_content to modify the
1688
  * content of activity comments only.
1689
  *
1690
+ * @since 1.2.0
1691
  *
1692
  * @todo investigate why bp_activity_recurse_comment_count() is used while being declared
1693
  *
1694
  * @param object $comment Activity comments object
1695
  *
1696
+ * @global object $activities_template {@link BP_Activity_Template}
1697
+ * @global object $bp BuddyPress global settings
1698
  * @uses bp_activity_recurse_comment_count()
1699
  * @uses apply_filters() To call the 'bp_activity_get_comment_count' hook
1700
  *
1701
  * @return int $count The activity comment count.
1702
  */
1703
  function bp_activity_recurse_comment_count( $comment, $count = 0 ) {
1704
+ global $activities_template, $bp;
1705
 
1706
+ if ( !$comment->children )
1707
  return $count;
1708
 
1709
+ foreach ( (array)$comment->children as $comment ) {
1710
  $count++;
1711
  $count = bp_activity_recurse_comment_count( $comment, $count );
1712
  }
1717
  /**
1718
  * Echoes the activity comment link
1719
  *
1720
+ * @since 1.2.0
1721
  *
1722
  * @uses bp_get_activity_comment_link()
1723
  */
1728
  /**
1729
  * Gets the activity comment link
1730
  *
1731
+ * @since 1.2.0
1732
  *
1733
  * @global object $activities_template {@link BP_Activity_Template}
1734
  * @uses apply_filters() To call the 'bp_get_activity_comment_link' hook
1743
  /**
1744
  * Echoes the activity comment form no javascript display CSS
1745
  *
1746
+ * @since 1.2.0
1747
  *
1748
  * @uses bp_get_activity_comment_form_nojs_display()
1749
  */
1754
  /**
1755
  * Gets the activity comment form no javascript display CSS
1756
  *
1757
+ * @since 1.2.0
1758
  *
1759
  * @global object $activities_template {@link BP_Activity_Template}
1760
  *
1771
  /**
1772
  * Echoes the activity comment form action
1773
  *
1774
+ * @since 1.2.0
1775
  *
1776
  * @uses bp_get_activity_comment_form_action()
1777
  */
1782
  /**
1783
  * Gets the activity comment form action
1784
  *
1785
+ * @since 1.2.0
1786
  *
1787
+ * @global object $bp BuddyPress global settings
1788
  * @uses home_url()
1789
  * @uses bp_get_activity_root_slug()
1790
  * @uses apply_filters() To call the 'bp_get_activity_comment_form_action' hook
1792
  * @return string The activity comment form action
1793
  */
1794
  function bp_get_activity_comment_form_action() {
1795
+ global $bp;
1796
+
1797
  return apply_filters( 'bp_get_activity_comment_form_action', home_url( bp_get_activity_root_slug() . '/reply/' ) );
1798
  }
1799
 
1800
  /**
1801
  * Echoes the activity permalink id
1802
  *
1803
+ * @since 1.2.0
1804
  *
1805
  * @uses bp_get_activity_permalink_id()
1806
  */
1811
  /**
1812
  * Gets the activity permalink id
1813
  *
1814
+ * @since 1.2.0
1815
  *
1816
+ * @global object $bp BuddyPress global settings
1817
  * @uses apply_filters() To call the 'bp_get_activity_permalink_id' hook
1818
  *
1819
  * @return string The activity permalink id
1820
  */
1821
  function bp_get_activity_permalink_id() {
1822
+ global $bp;
1823
+
1824
+ return apply_filters( 'bp_get_activity_permalink_id', $bp->current_action );
1825
  }
1826
 
1827
  /**
1828
  * Echoes the activity thread permalink
1829
  *
1830
+ * @since 1.2.0
1831
  *
1832
  * @uses bp_get_activity_permalink_id()
1833
  */
1838
  /**
1839
  * Gets the activity thread permalink
1840
  *
1841
+ * @since 1.2.0
1842
  *
1843
+ * @global object $bp BuddyPress global settings
1844
  * @uses bp_activity_get_permalink()
1845
  * @uses apply_filters() To call the 'bp_get_activity_thread_permalink' hook
1846
  *
1847
  * @return string $link The activity thread permalink
1848
  */
1849
  function bp_get_activity_thread_permalink() {
1850
+ global $bp, $activities_template;
1851
 
1852
  $link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity );
1853
 
1857
  /**
1858
  * Echoes the activity favorite link
1859
  *
1860
+ * @since 1.2.0
1861
  *
1862
  * @uses bp_get_activity_favorite_link()
1863
  */
1868
  /**
1869
  * Gets the activity favorite link
1870
  *
1871
+ * @since 1.2.0
1872
  *
1873
+ * @global object $bp BuddyPress global settings
1874
  * @global object $activities_template {@link BP_Activity_Template}
1875
  * @uses wp_nonce_url()
1876
  * @uses home_url()
1880
  * @return string The activity favorite link
1881
  */
1882
  function bp_get_activity_favorite_link() {
1883
+ global $bp, $activities_template;
1884
  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' ) );
1885
  }
1886
 
1887
  /**
1888
  * Echoes the activity unfavorite link
1889
  *
1890
+ * @since 1.2.0
1891
  *
1892
  * @uses bp_get_activity_unfavorite_link()
1893
  */
1898
  /**
1899
  * Gets the activity unfavorite link
1900
  *
1901
+ * @since 1.2.0
1902
  *
1903
+ * @global object $bp BuddyPress global settings
1904
  * @global object $activities_template {@link BP_Activity_Template}
1905
  * @uses wp_nonce_url()
1906
  * @uses home_url()
1910
  * @return string The activity unfavorite link
1911
  */
1912
  function bp_get_activity_unfavorite_link() {
1913
+ global $bp, $activities_template;
1914
  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' ) );
1915
  }
1916
 
1917
  /**
1918
  * Echoes the activity CSS class
1919
  *
1920
+ * @since 1.0.0
1921
  *
1922
  * @uses bp_get_activity_css_class()
1923
  */
1928
  /**
1929
  * Gets the activity CSS class
1930
  *
1931
+ * @since 1.0.0
1932
  *
1933
  * @global object $activities_template {@link BP_Activity_Template}
1934
  * @uses apply_filters() To call the 'bp_activity_mini_activity_types' hook
1950
  'new_member'
1951
  ) );
1952
 
1953
+ $class = '';
1954
+ if ( in_array( $activities_template->activity->type, (array)$mini_activity_actions ) || empty( $activities_template->activity->content ) )
1955
+ $class = ' mini';
 
1956
 
1957
  if ( bp_activity_get_comment_count() && bp_activity_can_comment() )
1958
  $class .= ' has-comments';
1963
  /**
1964
  * Display the activity delete link.
1965
  *
1966
+ * @since 1.1.0
1967
  *
1968
  * @uses bp_get_activity_delete_link()
1969
  */
1974
  /**
1975
  * Return the activity delete link.
1976
  *
1977
+ * @since 1.1.0
1978
  *
1979
  * @global object $activities_template {@link BP_Activity_Template}
1980
+ * @global object $bp BuddyPress global settings
1981
  * @uses bp_get_root_domain()
1982
  * @uses bp_get_activity_root_slug()
1983
  * @uses bp_is_activity_component()
1990
  * @return string $link Activity delete link. Contains $redirect_to arg if on single activity page.
1991
  */
1992
  function bp_get_activity_delete_link() {
1993
+ global $activities_template, $bp;
1994
 
1995
  $url = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/delete/' . $activities_template->activity->id;
1996
  $class = 'delete-activity';
2008
  /**
2009
  * Display the activity latest update link.
2010
  *
2011
+ * @since 1.2.0
2012
  *
2013
  * @param int $user_id Defaults to 0
2014
  *
2021
  /**
2022
  * Return the activity latest update link.
2023
  *
2024
+ * @since 1.2.0
2025
  *
2026
  * @param int $user_id Defaults to 0
2027
  *
2028
+ * @global object $bp BuddyPress global settings
2029
+ * @uses bp_core_is_user_spammer()
2030
  * @uses bp_core_is_user_deleted()
2031
  * @uses bp_get_user_meta()
2032
  * @uses apply_filters() To call the 'bp_get_activity_latest_update_excerpt' hook
2038
  * @return string|bool $latest_update The activity latest update link. False on failure
2039
  */
2040
  function bp_get_activity_latest_update( $user_id = 0 ) {
2041
+ global $bp;
2042
 
2043
+ if ( !$user_id )
2044
+ $user_id = $bp->displayed_user->id;
2045
 
2046
+ if ( bp_core_is_user_spammer( $user_id ) || bp_core_is_user_deleted( $user_id ) )
2047
  return false;
2048
 
2049
  if ( !$update = bp_get_user_meta( $user_id, 'bp_latest_update', true ) )
2058
  /**
2059
  * Display the activity filter links.
2060
  *
2061
+ * @since 1.1.0
2062
  *
2063
  * @param array $args Defaults to false
2064
  *
2071
  /**
2072
  * Return the activity filter links.
2073
  *
2074
+ * @since 1.1.0
2075
  *
2076
  * @param array $args Defaults to false
2077
  *
2078
+ * @global object $activities_template {@link BP_Activity_Template}
2079
+ * @global object $bp BuddyPress global settings
2080
  * @uses wp_parse_args()
2081
  * @uses BP_Activity_Activity::get_recorded_components() {@link BP_Activity_Activity}
2082
  * @uses esc_attr()
2088
  * @return string|bool $component_links The activity filter links. False on failure
2089
  */
2090
  function bp_get_activity_filter_links( $args = false ) {
2091
+ global $activities_template, $bp;
2092
 
2093
  $defaults = array(
2094
  'style' => 'list'
2097
  $r = wp_parse_args( $args, $defaults );
2098
  extract( $r, EXTR_SKIP );
2099
 
 
 
 
2100
  // Fetch the names of components that have activity recorded in the DB
2101
  $components = BP_Activity_Activity::get_recorded_components();
2102
 
2103
+ if ( !$components )
2104
  return false;
2105
 
2106
  foreach ( (array) $components as $component ) {
2107
+ /* Skip the activity comment filter */
 
2108
  if ( 'activity' == $component )
2109
  continue;
2110
 
2135
 
2136
  $link = add_query_arg( 'afilter', $component );
2137
  $link = remove_query_arg( 'acpage' , $link );
2138
+
2139
  $link = apply_filters( 'bp_get_activity_filter_link_href', $link, $component );
2140
 
2141
+ // Make sure all core internal component names are translatable
2142
+ $translatable_components = array( __( 'xprofile', 'buddypress'), __( 'friends', 'buddypress' ), __( 'groups', 'buddypress' ), __( 'status', 'buddypress' ), __( 'sites', 'buddypress' ) );
2143
+
2144
+ $component_links[] = $before . '<a href="' . esc_attr( $link ) . '">' . ucwords( __( $component, 'buddypress' ) ) . '</a>' . $after;
2145
  }
2146
 
2147
  $link = remove_query_arg( 'afilter' , $link );
2155
  /**
2156
  * Determine if a comment can be made on an activity item
2157
  *
2158
+ * @since 1.2.0
2159
  *
2160
  * @global object $activities_template {@link BP_Activity_Template}
2161
+ * @global object $bp BuddyPress global settings
2162
  * @uses bp_get_activity_action_name()
2163
  * @uses apply_filters() To call the 'bp_activity_can_comment' hook
2164
  *
2165
  * @return bool $can_comment Defaults to true
2166
  */
2167
  function bp_activity_can_comment() {
2168
+ global $activities_template, $bp;
2169
 
2170
  $can_comment = true;
2171
 
2172
+ if ( false === $activities_template->disable_blogforum_replies || (int)$activities_template->disable_blogforum_replies ) {
2173
  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() )
2174
  $can_comment = false;
2175
  }
2183
  /**
2184
  * Determine if a comment can be made on an activity reply item
2185
  *
2186
+ * @since 1.5.0
2187
  *
2188
  * @param object $comment Activity comment
2189
  *
2200
  /**
2201
  * Determine if an favorites are allowed
2202
  *
2203
+ * @since 1.5.0
2204
  *
2205
  * @uses apply_filters() To call the 'bp_activity_can_favorite' hook
2206
  *
2215
  /**
2216
  * Echoes the total favorite count for a specified user
2217
  *
2218
+ * @since 1.2.0
2219
  *
2220
  * @param int $user_id Defaults to 0
2221
  *
2228
  /**
2229
  * Returns the total favorite count for a specified user
2230
  *
2231
+ * @since 1.2.0
2232
  *
2233
  * @param int $user_id Defaults to 0
2234
  *
2244
  /**
2245
  * Echoes the total mention count for a specified user
2246
  *
2247
+ * @since 1.2.0
2248
  *
2249
  * @param int $user_id Defaults to 0
2250
  *
2257
  /**
2258
  * Returns the total mention count for a specified user
2259
  *
2260
+ * @since 1.2.0
2261
+ *
2262
+ * @todo remove unnecessary $bp global
2263
  *
2264
  * @param int $user_id Defaults to 0
2265
+ *
2266
  * @uses bp_get_user_meta()
2267
  * @uses apply_filters() To call the 'bp_get_total_mention_count_for_user' hook
2268
+ *
2269
  * @return int The total mention count for a specified user
2270
  */
2271
  function bp_get_total_mention_count_for_user( $user_id = 0 ) {
2272
+ global $bp;
2273
+
2274
  return apply_filters( 'bp_get_total_mention_count_for_user', bp_get_user_meta( $user_id, 'bp_new_mention_count', true ) );
2275
  }
2276
 
2277
  /**
2278
  * Echoes the public message link for displayed user
2279
  *
2280
+ * @since 1.2.0
2281
  *
2282
  * @uses bp_get_send_public_message_link()
2283
  */
2288
  /**
2289
  * Returns the public message link for displayed user
2290
  *
2291
+ * @since 1.2.0
2292
  *
2293
  * @global object $bp BuddyPress global settings
2294
  * @uses bp_is_my_profile()
2307
  if ( bp_is_my_profile() || !is_user_logged_in() )
2308
  return false;
2309
 
2310
+ return apply_filters( 'bp_get_send_public_message_link', wp_nonce_url( bp_loggedin_user_domain() . bp_get_activity_slug() . '/?r=' . bp_core_get_username( $bp->displayed_user->id, $bp->displayed_user->userdata->user_nicename, $bp->displayed_user->userdata->user_login ) ) );
2311
  }
2312
 
2313
  /**
2314
  * Echoes the mentioned user display name
2315
  *
2316
+ * @since 1.2.0
2317
  *
2318
  * @param int|string User id or username
2319
  *
2326
  /**
2327
  * Returns the mentioned user display name
2328
  *
2329
+ * @since 1.2.0
2330
  *
2331
  * @param int|string User id or username
2332
  *
2345
  /**
2346
  * Output button for sending a public message
2347
  *
2348
+ * @since 1.2.0
2349
  *
2350
  * @param array $args Optional
2351
  *
2358
  /**
2359
  * Return button for sending a public message
2360
  *
2361
+ * @since 1.2.0
2362
  *
2363
  * @param array $args Optional
2364
  *
2391
  /**
2392
  * Outputs the activity post form action
2393
  *
2394
+ * @since 1.2.0
2395
  *
2396
  * @uses bp_get_activity_post_form_action()
2397
  */
2402
  /**
2403
  * Returns the activity post form action
2404
  *
2405
+ * @since 1.2.0
2406
  *
2407
  * @uses home_url()
2408
  * @uses bp_get_activity_root_slug()
2419
  /**
2420
  * Outputs the sitewide activity feed link
2421
  *
2422
+ * @since 1.0.0
2423
  *
2424
  * @uses bp_get_sitewide_activity_feed_link()
2425
  */
2430
  /**
2431
  * Returns the sitewide activity feed link
2432
  *
2433
+ * @since 1.0.0
2434
  *
2435
  * @uses home_url()
2436
  * @uses bp_get_activity_root_slug()
2445
  /**
2446
  * Outputs the member activity feed link
2447
  *
2448
+ * @since 1.2.0
2449
  *
2450
  * @uses bp_get_member_activity_feed_link()
2451
  */
2456
  /**
2457
  * Outputs the member activity feed link
2458
  *
2459
+ * @since 1.0.0
2460
+ * @deprecated 1.2.0
2461
  *
2462
  * @todo properly deprecated in favor of bp_member_activity_feed_link()
2463
  *
2468
  /**
2469
  * Returns the member activity feed link
2470
  *
2471
+ * @since 1.2.0
2472
  *
2473
  * @uses bp_is_profile_component()
2474
  * @uses bp_is_current_action()
2482
  * @return string $link The member activity feed link
2483
  */
2484
  function bp_get_member_activity_feed_link() {
2485
+ global $bp;
2486
 
2487
  if ( bp_is_profile_component() || bp_is_current_action( 'just-me' ) )
2488
  $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/feed/';
2490
  $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_friends_slug() . '/feed/';
2491
  elseif ( bp_is_active( 'groups' ) && bp_is_current_action( bp_get_groups_slug() ) )
2492
  $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_groups_slug() . '/feed/';
2493
+ elseif ( 'favorites' == $bp->current_action )
2494
  $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/favorites/feed/';
2495
+ elseif ( 'mentions' == $bp->current_action )
2496
  $link = bp_displayed_user_domain() . bp_get_activity_slug() . '/mentions/feed/';
2497
  else
2498
  $link = '';
2503
  /**
2504
  * Returns the member activity feed link
2505
  *
2506
+ * @since 1.0.0
2507
+ * @deprecated 1.2.0
2508
  *
2509
  * @todo properly deprecated in favor of bp_get_member_activity_feed_link()
2510
  *
2520
  /**
2521
  * Outputs the activity feed item guid
2522
  *
2523
+ * @since 1.0.0
2524
  *
2525
  * @uses bp_activity_feed_item_guid()
2526
  */
2531
  /**
2532
  * Returns the activity feed item guid
2533
  *
2534
+ * @since 1.2.0
2535
  *
2536
  * @global object $activities_template {@link BP_Activity_Template}
2537
  * @uses apply_filters() To call the 'bp_get_activity_feed_item_guid' hook
2547
  /**
2548
  * Outputs the activity feed item title
2549
  *
2550
+ * @since 1.0.0
2551
  *
2552
  * @uses bp_get_activity_feed_item_title()
2553
  */
2558
  /**
2559
  * Returns the activity feed item title
2560
  *
2561
+ * @since 1.0.0
2562
  *
2563
  * @global object $activities_template {@link BP_Activity_Template}
2564
  * @uses ent2ncr()
2591
  /**
2592
  * Outputs the activity feed item link
2593
  *
2594
+ * @since 1.0.0
2595
  *
2596
  * @uses bp_get_activity_feed_item_link()
2597
  */
2602
  /**
2603
  * Returns the activity feed item link
2604
  *
2605
+ * @since 1.0.0
2606
  *
2607
  * @global object $activities_template {@link BP_Activity_Template}
2608
  * @uses apply_filters() To call the 'bp_get_activity_feed_item_link' hook
2618
  /**
2619
  * Outputs the activity feed item date
2620
  *
2621
+ * @since 1.0.0
2622
  *
2623
  * @uses bp_get_activity_feed_item_date()
2624
  */
2629
  /**
2630
  * Returns the activity feed item date
2631
  *
2632
+ * @since 1.0.0
2633
  *
2634
  * @global object $activities_template {@link BP_Activity_Template}
2635
  * @uses apply_filters() To call the 'bp_get_activity_feed_item_date' hook
2645
  /**
2646
  * Outputs the activity feed item description
2647
  *
2648
+ * @since 1.0.0
2649
  *
2650
  * @uses bp_get_activity_feed_item_description()
2651
  */
2656
  /**
2657
  * Returns the activity feed item description
2658
  *
2659
+ * @since 1.0.0
2660
  *
2661
  * @global object $activities_template {@link BP_Activity_Template}
2662
  * @uses ent2ncr()
2668
  function bp_get_activity_feed_item_description() {
2669
  global $activities_template;
2670
 
2671
+ if ( empty( $activities_template->activity->action ) )
 
2672
  $content = $activities_template->activity->content;
2673
+ else
2674
+ $content = $activities_template->activity->action . ' ' . $activities_template->activity->content;
2675
 
2676
  return apply_filters( 'bp_get_activity_feed_item_description', ent2ncr( convert_chars( str_replace( '%s', '', $content ) ) ) );
2677
  }
2679
  /**
2680
  * Template tag so we can hook activity feed to <head>
2681
  *
2682
+ * @since 1.5.0
2683
  *
2684
  * @uses bloginfo()
2685
  * @uses bp_sitewide_activity_feed_link()
2693
  }
2694
  add_action( 'bp_head', 'bp_activity_sitewide_feed' );
2695
 
2696
+ ?>
bp-activity/feeds/bp-activity-favorites-feed.php CHANGED
@@ -24,11 +24,10 @@ header('Status: 200 OK');
24
  >
25
 
26
  <channel>
27
- <?php /* translators: Favorited activity RSS title - "[Site Name] | [Displayed User Name] | Favorite Activity" */ ?>
28
- <title><?php printf( '%1$s | %2$s | %3$s', bp_get_site_name(), bp_get_displayed_user_fullname(), __( 'Favorite Activity', 'buddypress' ) ) ?></title>
29
  <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
30
  <link><?php echo home_url( bp_get_activity_root_slug() . '/#my-favorites/' ) ?></link>
31
- <description><?php printf( __( '%s - Favorite Activity', 'buddypress' ), bp_get_displayed_user_fullname() ) ?></description>
32
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_activity_get_last_updated(), false); ?></pubDate>
33
  <generator>http://buddypress.org/?v=<?php echo BP_VERSION ?></generator>
34
  <language><?php echo get_option('rss_language'); ?></language>
@@ -36,8 +35,8 @@ header('Status: 200 OK');
36
  <?php do_action('bp_activity_favorites_feed_head'); ?>
37
 
38
  <?php
39
- $favs = bp_activity_get_user_favorites( bp_displayed_user_id() );
40
- $fav_ids = implode( ',', (array) $favs );
41
  ?>
42
 
43
  <?php if ( bp_has_activities( 'include=' . $fav_ids . '&max=50&display_comments=stream' ) ) : ?>
24
  >
25
 
26
  <channel>
27
+ <title><?php bp_site_name() ?> | <?php echo $bp->displayed_user->fullname; ?> | <?php _e( 'Favorite Activity', 'buddypress' ) ?></title>
 
28
  <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
29
  <link><?php echo home_url( bp_get_activity_root_slug() . '/#my-favorites/' ) ?></link>
30
+ <description><?php echo $bp->displayed_user->fullname; ?> - <?php _e( 'Favorite Activity', 'buddypress' ) ?></description>
31
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_activity_get_last_updated(), false); ?></pubDate>
32
  <generator>http://buddypress.org/?v=<?php echo BP_VERSION ?></generator>
33
  <language><?php echo get_option('rss_language'); ?></language>
35
  <?php do_action('bp_activity_favorites_feed_head'); ?>
36
 
37
  <?php
38
+ $favs = bp_activity_get_user_favorites( $bp->displayed_user->id );
39
+ $fav_ids = implode( ',', (array)$favs );
40
  ?>
41
 
42
  <?php if ( bp_has_activities( 'include=' . $fav_ids . '&max=50&display_comments=stream' ) ) : ?>
bp-activity/feeds/bp-activity-friends-feed.php CHANGED
@@ -24,7 +24,6 @@ header('Status: 200 OK');
24
  >
25
 
26
  <channel>
27
- <?php /* translators: Member friends activity RSS title - "[Site Name] | Friends Activity" */ ?>
28
  <title><?php bp_site_name() ?> | <?php bp_displayed_user_fullname(); ?> | <?php _e( 'Friends Activity', 'buddypress' ); ?></title>
29
  <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
30
  <link><?php echo bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_friends_slug() . '/feed'; ?></link>
24
  >
25
 
26
  <channel>
 
27
  <title><?php bp_site_name() ?> | <?php bp_displayed_user_fullname(); ?> | <?php _e( 'Friends Activity', 'buddypress' ); ?></title>
28
  <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
29
  <link><?php echo bp_displayed_user_domain() . bp_get_activity_slug() . '/' . bp_get_friends_slug() . '/feed'; ?></link>
bp-activity/feeds/bp-activity-group-feed.php CHANGED
@@ -24,8 +24,7 @@ header('Status: 200 OK');
24
  >
25
 
26
  <channel>
27
- <?php /* translators: Single group activity RSS title - "[Site Name] | [Group Name] | Group Activity" */ ?>
28
- <title><?php printf( '%1$s | %2$s | %3$s', bp_get_site_name(), bp_get_current_group_name(), __( 'Group Activity', 'buddypress' ) ) ?></title>
29
  <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
30
  <link><?php echo bp_get_group_permalink( $bp->groups->current_group ) . bp_get_activity_slug() . '/feed' ?></link>
31
  <description><?php printf( __( '%s - Group Activity Feed', 'buddypress' ), $bp->groups->current_group->name ) ?></description>
24
  >
25
 
26
  <channel>
27
+ <title><?php bp_site_name() ?> | <?php echo $bp->groups->current_group->name ?> | <?php _e( 'Group Activity', 'buddypress' ) ?></title>
 
28
  <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
29
  <link><?php echo bp_get_group_permalink( $bp->groups->current_group ) . bp_get_activity_slug() . '/feed' ?></link>
30
  <description><?php printf( __( '%s - Group Activity Feed', 'buddypress' ), $bp->groups->current_group->name ) ?></description>
bp-activity/feeds/bp-activity-mentions-feed.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
 
3
  /**
4
- * RSS2 Feed Template for displaying a member's activity mentions
5
  *
6
  * @package BuddyPress
7
  * @subpackage ActivityFeeds
@@ -24,18 +24,16 @@ header('Status: 200 OK');
24
  >
25
 
26
  <channel>
27
- <?php /* translators: Mentions RSS title - "[Site Name] | [Displayed User Name] | Mentions" */ ?>
28
- <title><?php printf( '%1$s | %2$s | %3$s', bp_get_site_name(), bp_get_displayed_user_fullname(), __( 'Mentions', 'buddypress' ) ) ?></title>
29
  <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
30
  <link><?php echo home_url( bp_get_activity_root_slug() . '/#mentions/' ) ?></link>
31
- <?php /* translators: Mentions RSS title - "[Site Name] | [Displayed User Name] | Mentions" */ ?>
32
- <description><?php printf( __( '%s - Mentions', 'buddypress' ), bp_get_displayed_user_fullname() ) ?></description>
33
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_activity_get_last_updated(), false); ?></pubDate>
34
  <generator>http://buddypress.org/?v=<?php echo BP_VERSION ?></generator>
35
  <language><?php echo get_option('rss_language'); ?></language>
36
  <?php do_action('bp_activity_mentions_feed_head'); ?>
37
 
38
- <?php if ( bp_has_activities( 'max=50&display_comments=stream&search_terms=@' . bp_core_get_username( bp_displayed_user_id() ) ) ) : ?>
39
  <?php while ( bp_activities() ) : bp_the_activity(); ?>
40
  <item>
41
  <guid><?php bp_activity_thread_permalink() ?></guid>
1
  <?php
2
 
3
  /**
4
+ * RSS2 Feed Template for displaying a member's group's activity
5
  *
6
  * @package BuddyPress
7
  * @subpackage ActivityFeeds
24
  >
25
 
26
  <channel>
27
+ <title><?php bp_site_name() ?> | <?php echo $bp->displayed_user->fullname; ?> | <?php _e( 'Mentions', 'buddypress' ) ?></title>
 
28
  <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
29
  <link><?php echo home_url( bp_get_activity_root_slug() . '/#mentions/' ) ?></link>
30
+ <description><?php echo $bp->displayed_user->fullname; ?> - <?php _e( 'Mentions', 'buddypress' ) ?></description>
 
31
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_activity_get_last_updated(), false); ?></pubDate>
32
  <generator>http://buddypress.org/?v=<?php echo BP_VERSION ?></generator>
33
  <language><?php echo get_option('rss_language'); ?></language>
34
  <?php do_action('bp_activity_mentions_feed_head'); ?>
35
 
36
+ <?php if ( bp_has_activities( 'max=50&display_comments=stream&search_terms=@' . bp_core_get_username( $bp->displayed_user->id, $bp->displayed_user->userdata->user_nicename, $bp->displayed_user->userdata->user_login ) ) ) : ?>
37
  <?php while ( bp_activities() ) : bp_the_activity(); ?>
38
  <item>
39
  <guid><?php bp_activity_thread_permalink() ?></guid>
bp-activity/feeds/bp-activity-mygroups-feed.php CHANGED
@@ -24,19 +24,17 @@ header('Status: 200 OK');
24
  >
25
 
26
  <channel>
27
- <?php /* translators: Member groups activity RSS title - "[Site Name] | [Displayed User Name] | My Groups - Public Activity" */ ?>
28
- <title><?php printf( '%1$s | %2$s | %3$s', bp_get_site_name(), bp_get_displayed_user_fullname(), __( 'My Groups - Public Activity', 'buddypress' ) ) ?></title>
29
  <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
30
  <link><?php echo home_url( bp_get_activity_root_slug() . '/#my-groups/' ) ?></link>
31
- <?php /* translators: Member groups activity RSS description - "[Displayed user name] - My Groups - Public Activity" */ ?>
32
- <description><?php printf( __( '%1$s - My Groups - Public Activity', 'buddypress' ), bp_get_displayed_user_fullname() ) ?></description>
33
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_activity_get_last_updated(), false); ?></pubDate>
34
  <generator>http://buddypress.org/?v=<?php echo BP_VERSION ?></generator>
35
  <language><?php echo get_option('rss_language'); ?></language>
36
  <?php do_action('bp_activity_mygroups_feed_head'); ?>
37
 
38
  <?php
39
- $groups = groups_get_user_groups( bp_loggedin_user_id() );
40
  $group_ids = implode( ',', $groups['groups'] );
41
  ?>
42
 
24
  >
25
 
26
  <channel>
27
+ <title><?php bp_site_name() ?> | <?php echo $bp->displayed_user->fullname; ?> | <?php _e( 'My Groups - Public Activity', 'buddypress' ) ?></title>
 
28
  <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
29
  <link><?php echo home_url( bp_get_activity_root_slug() . '/#my-groups/' ) ?></link>
30
+ <description><?php echo $bp->displayed_user->fullname; ?> - <?php _e( 'My Groups - Public Activity', 'buddypress' ) ?></description>
 
31
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_activity_get_last_updated(), false); ?></pubDate>
32
  <generator>http://buddypress.org/?v=<?php echo BP_VERSION ?></generator>
33
  <language><?php echo get_option('rss_language'); ?></language>
34
  <?php do_action('bp_activity_mygroups_feed_head'); ?>
35
 
36
  <?php
37
+ $groups = groups_get_user_groups( $bp->loggedin_user->id );
38
  $group_ids = implode( ',', $groups['groups'] );
39
  ?>
40
 
bp-activity/feeds/bp-activity-personal-feed.php CHANGED
@@ -24,17 +24,16 @@ header('Status: 200 OK');
24
  >
25
 
26
  <channel>
27
- <?php /* translators: Personal activity RSS title - "[Site Name] | [Displayed User Name] | Activity" */ ?>
28
- <title><?php printf( '%1$s | %2$s | %3$s', bp_get_site_name(), bp_get_displayed_user_fullname(), __( 'Activity', 'buddypress' ) ) ?></title>
29
  <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
30
  <link><?php echo bp_displayed_user_domain() . bp_get_activity_slug() . '/feed' ?></link>
31
- <description><?php printf( __( '%s - Activity Feed', 'buddypress' ), bp_get_displayed_user_fullname() ) ?></description>
32
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_activity_get_last_updated(), false); ?></pubDate>
33
  <generator>http://buddypress.org/?v=<?php echo BP_VERSION ?></generator>
34
  <language><?php echo get_option('rss_language'); ?></language>
35
  <?php do_action('bp_activity_personal_feed_head'); ?>
36
 
37
- <?php if ( bp_has_activities( 'user_id=' . bp_displayed_user_id() . '&max=50&display_comments=stream' ) ) : ?>
38
  <?php while ( bp_activities() ) : bp_the_activity(); ?>
39
  <item>
40
  <guid><?php bp_activity_thread_permalink() ?></guid>
24
  >
25
 
26
  <channel>
27
+ <title><?php bp_site_name() ?> | <?php echo $bp->displayed_user->fullname; ?> | <?php _e( 'Activity', 'buddypress' ) ?></title>
 
28
  <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
29
  <link><?php echo bp_displayed_user_domain() . bp_get_activity_slug() . '/feed' ?></link>
30
+ <description><?php printf( __( '%s - Activity Feed', 'buddypress' ), $bp->displayed_user->fullname ) ?></description>
31
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_activity_get_last_updated(), false); ?></pubDate>
32
  <generator>http://buddypress.org/?v=<?php echo BP_VERSION ?></generator>
33
  <language><?php echo get_option('rss_language'); ?></language>
34
  <?php do_action('bp_activity_personal_feed_head'); ?>
35
 
36
+ <?php if ( bp_has_activities( 'user_id=' . $bp->displayed_user->id . '&max=50&display_comments=stream' ) ) : ?>
37
  <?php while ( bp_activities() ) : bp_the_activity(); ?>
38
  <item>
39
  <guid><?php bp_activity_thread_permalink() ?></guid>
bp-activity/feeds/bp-activity-sitewide-feed.php CHANGED
@@ -24,8 +24,7 @@ header('Status: 200 OK');
24
  >
25
 
26
  <channel>
27
- <?php /* translators: Sitewide activity RSS title - "[Site Name] | Site Wide Activity" */ ?>
28
- <title><?php printf( '%1$s | %2$s', bp_get_site_name(), __( 'Site Wide Activity', 'buddypress' ) ) ?></title>
29
  <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
30
  <link><?php echo bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/feed' ?></link>
31
  <description><?php _e( 'Site Wide Activity Feed', 'buddypress' ) ?></description>
24
  >
25
 
26
  <channel>
27
+ <title><?php bp_site_name() ?> | <?php _e( 'Site Wide Activity', 'buddypress' ) ?></title>
 
28
  <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
29
  <link><?php echo bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/feed' ?></link>
30
  <description><?php _e( 'Site Wide Activity Feed', 'buddypress' ) ?></description>
bp-blogs/bp-blogs-actions.php CHANGED
@@ -1,38 +1,16 @@
1
  <?php
2
-
3
- /**
4
- * BuddyPress Blogs Actions
5
- *
6
- * @package BuddyPress
7
- * @subpackage BlogsActions
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)
17
- * @package BuddyPress
18
- * @subpackage BlogsActions
19
- */
20
  function bp_blogs_redirect_to_random_blog() {
 
21
 
22
- // Bail if not looking for a random blog
23
- if ( ! bp_is_blogs_component() || ! isset( $_GET['random-blog'] ) )
24
- return;
25
-
26
- // Multisite is active so find a random blog
27
- if ( is_multisite() ) {
28
  $blog = bp_blogs_get_random_blogs( 1, 1 );
29
- bp_core_redirect( get_site_url( $blog['blogs'][0]->blog_id ) );
30
 
31
- // No multisite and still called, always redirect to root
32
- } else {
33
- bp_core_redirect( bp_core_get_root_domain() );
34
  }
35
  }
36
  add_action( 'bp_actions', 'bp_blogs_redirect_to_random_blog' );
37
 
38
- ?>
1
  <?php
 
 
 
 
 
 
 
 
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
 
 
 
 
 
 
 
5
  function bp_blogs_redirect_to_random_blog() {
6
+ global $bp, $wpdb;
7
 
8
+ if ( bp_is_blogs_component() && isset( $_GET['random-blog'] ) ) {
 
 
 
 
 
9
  $blog = bp_blogs_get_random_blogs( 1, 1 );
 
10
 
11
+ bp_core_redirect( get_site_url( $blog['blogs'][0]->blog_id ) );
 
 
12
  }
13
  }
14
  add_action( 'bp_actions', 'bp_blogs_redirect_to_random_blog' );
15
 
16
+ ?>
bp-blogs/bp-blogs-activity.php CHANGED
@@ -1,29 +1,17 @@
1
  <?php
2
-
3
- /**
4
- * BuddyPress Blogs Activity
5
- *
6
- * @package BuddyPress
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)
17
- * @package BuddyPress
18
- * @subpackage BlogsActivity
19
- * @global type $bp
20
- * @return boolean
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' ) )
27
  return false;
28
 
29
  bp_activity_set_action( $bp->blogs->id, 'new_blog', __( 'New site created', 'buddypress' ) );
@@ -34,25 +22,14 @@ function bp_blogs_register_activity_actions() {
34
  }
35
  add_action( 'bp_register_activity_actions', 'bp_blogs_register_activity_actions' );
36
 
37
- /**
38
- * Record the activity to the actvity stream
39
- *
40
- * @since BuddyPress (1.0)
41
- * @package BuddyPress
42
- * @subpackage BlogsActivity
43
- * @global BuddyPress $bp
44
- * @param array $args
45
- * @return boolean
46
- */
47
  function bp_blogs_record_activity( $args = '' ) {
48
  global $bp;
49
 
50
- // Bail if activity is not active
51
- if ( ! bp_is_active( 'activity' ) )
52
  return false;
53
 
54
  $defaults = array(
55
- 'user_id' => bp_loggedin_user_id(),
56
  'action' => '',
57
  'content' => '',
58
  'primary_link' => '',
@@ -68,7 +45,7 @@ function bp_blogs_record_activity( $args = '' ) {
68
  extract( $r, EXTR_SKIP );
69
 
70
  // Remove large images and replace them with just one image thumbnail
71
- if ( !empty( $content ) )
72
  $content = bp_activity_thumbnail_content_images( $content, $primary_link );
73
 
74
  if ( !empty( $action ) )
@@ -89,41 +66,29 @@ function bp_blogs_record_activity( $args = '' ) {
89
  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 ) );
90
  }
91
 
92
- /**
93
- * Delete a blogs activity stream item
94
- *
95
- * @since BuddyPress (1.0)
96
- * @package BuddyPress
97
- * @subpackage BlogsActivity
98
- * @global BuddyPress $bp
99
- * @param array $args
100
- * @return If activity is not active
101
- */
102
  function bp_blogs_delete_activity( $args = true ) {
103
  global $bp;
104
 
105
- // Bail if activity is not active
106
- if ( ! bp_is_active( 'activity' ) )
107
- return false;
108
-
109
- $defaults = array(
110
- 'item_id' => false,
111
- 'component' => $bp->blogs->id,
112
- 'type' => false,
113
- 'user_id' => false,
114
- 'secondary_item_id' => false
115
- );
116
-
117
- $params = wp_parse_args( $args, $defaults );
118
- extract( $params, EXTR_SKIP );
119
-
120
- bp_activity_delete_by_item_id( array(
121
- 'item_id' => $item_id,
122
- 'component' => $component,
123
- 'type' => $type,
124
- 'user_id' => $user_id,
125
- 'secondary_item_id' => $secondary_item_id
126
- ) );
127
  }
128
 
129
- ?>
1
  <?php
2
+ /******************************************************************************
3
+ * These functions handle the recording, deleting and formatting of activity and
4
+ * notifications for the user and for this specific component.
 
 
 
5
  */
6
 
7
  // Exit if accessed directly
8
  if ( !defined( 'ABSPATH' ) ) exit;
9
 
10
+
 
 
 
 
 
 
 
 
11
  function bp_blogs_register_activity_actions() {
12
  global $bp;
13
 
14
+ if ( !bp_is_active( 'activity' ) )
 
15
  return false;
16
 
17
  bp_activity_set_action( $bp->blogs->id, 'new_blog', __( 'New site created', 'buddypress' ) );
22
  }
23
  add_action( 'bp_register_activity_actions', 'bp_blogs_register_activity_actions' );
24
 
 
 
 
 
 
 
 
 
 
 
25
  function bp_blogs_record_activity( $args = '' ) {
26
  global $bp;
27
 
28
+ if ( !bp_is_active( 'activity' ) )
 
29
  return false;
30
 
31
  $defaults = array(
32
+ 'user_id' => $bp->loggedin_user->id,
33
  'action' => '',
34
  'content' => '',
35
  'primary_link' => '',
45
  extract( $r, EXTR_SKIP );
46
 
47
  // Remove large images and replace them with just one image thumbnail
48
+ if ( bp_is_active( 'activity' ) && !empty( $content ) )
49
  $content = bp_activity_thumbnail_content_images( $content, $primary_link );
50
 
51
  if ( !empty( $action ) )
66
  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 ) );
67
  }
68
 
 
 
 
 
 
 
 
 
 
 
69
  function bp_blogs_delete_activity( $args = true ) {
70
  global $bp;
71
 
72
+ if ( bp_is_active( 'activity' ) ) {
73
+ $defaults = array(
74
+ 'item_id' => false,
75
+ 'component' => $bp->blogs->id,
76
+ 'type' => false,
77
+ 'user_id' => false,
78
+ 'secondary_item_id' => false
79
+ );
80
+
81
+ $params = wp_parse_args( $args, $defaults );
82
+ extract( $params, EXTR_SKIP );
83
+
84
+ bp_activity_delete_by_item_id( array(
85
+ 'item_id' => $item_id,
86
+ 'component' => $component,
87
+ 'type' => $type,
88
+ 'user_id' => $user_id,
89
+ 'secondary_item_id' => $secondary_item_id
90
+ ) );
91
+ }
 
 
92
  }
93
 
94
+ ?>
bp-blogs/bp-blogs-buddybar.php CHANGED
@@ -1,25 +1,8 @@
1
  <?php
2
-
3
- /**
4
- * BuddyPress Blogs Activity
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)
17
- * @package BuddyPress
18
- * @subpackage BlogsBuddyBar
19
- * @global BuddyPress $bp
20
- * @return boolean
21
- */
22
-
23
  function bp_adminbar_blogs_menu() {
24
  global $bp;
25
 
@@ -29,23 +12,22 @@ function bp_adminbar_blogs_menu() {
29
  if ( !is_multisite() )
30
  return false;
31
 
32
- $blogs = wp_cache_get( 'bp_blogs_of_user_' . bp_loggedin_user_id() . '_inc_hidden', 'bp' );
33
- if ( empty( $blogs ) ) {
34
- $blogs = bp_blogs_get_blogs_for_user( bp_loggedin_user_id(), true );
35
- wp_cache_set( 'bp_blogs_of_user_' . bp_loggedin_user_id() . '_inc_hidden', $blogs, 'bp' );
36
  }
37
 
38
  $counter = 0;
39
- if ( is_array( $blogs['blogs'] ) && (int) $blogs['count'] ) {
40
 
41
- echo '<li id="bp-adminbar-blogs-menu"><a href="' . trailingslashit( bp_loggedin_user_domain() . bp_get_blogs_slug() ) . '">';
42
 
43
  _e( 'My Sites', 'buddypress' );
44
 
45
  echo '</a>';
46
  echo '<ul>';
47
 
48
- foreach ( (array) $blogs['blogs'] as $blog ) {
49
  $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
50
  $site_url = esc_attr( $blog->siteurl );
51
 
@@ -78,4 +60,4 @@ function bp_adminbar_blogs_menu() {
78
  }
79
  add_action( 'bp_adminbar_menus', 'bp_adminbar_blogs_menu', 6 );
80
 
81
- ?>
1
  <?php
 
 
 
 
 
 
 
 
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
5
+ // *** "My Blogs" Menu ********
 
 
 
 
 
 
 
 
 
6
  function bp_adminbar_blogs_menu() {
7
  global $bp;
8
 
12
  if ( !is_multisite() )
13
  return false;
14
 
15
+ if ( !$blogs = wp_cache_get( 'bp_blogs_of_user_' . $bp->loggedin_user->id . '_inc_hidden', 'bp' ) ) {
16
+ $blogs = bp_blogs_get_blogs_for_user( $bp->loggedin_user->id, true );
17
+ wp_cache_set( 'bp_blogs_of_user_' . $bp->loggedin_user->id . '_inc_hidden', $blogs, 'bp' );
 
18
  }
19
 
20
  $counter = 0;
21
+ if ( is_array( $blogs['blogs'] ) && (int)$blogs['count'] ) {
22
 
23
+ echo '<li id="bp-adminbar-blogs-menu"><a href="' . trailingslashit( $bp->loggedin_user->domain . bp_get_blogs_slug() ) . '">';
24
 
25
  _e( 'My Sites', 'buddypress' );
26
 
27
  echo '</a>';
28
  echo '<ul>';
29
 
30
+ foreach ( (array)$blogs['blogs'] as $blog ) {
31
  $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
32
  $site_url = esc_attr( $blog->siteurl );
33
 
60
  }
61
  add_action( 'bp_adminbar_menus', 'bp_adminbar_blogs_menu', 6 );
62
 
63
+ ?>
bp-blogs/bp-blogs-cache.php CHANGED
@@ -1,40 +1,19 @@
1
  <?php
2
-
3
- /**
4
- * BuddyPress Blogs Caching
5
  *
6
  * Caching functions handle the clearing of cached objects and pages on specific
7
  * actions throughout BuddyPress.
8
- *
9
- * @package BuddyPress
10
- * @subpackage BlogsBuddyBar
11
  */
12
 
13
  // Exit if accessed directly
14
  if ( !defined( 'ABSPATH' ) ) exit;
15
 
16
- /**
17
- * Clear the blog object cache
18
- *
19
- * @since BuddyPress (1.0)
20
- * @package BuddyPress
21
- * @subpackage BlogsBuddyBar
22
- * @param int $blog_id
23
- * @param int $user_id
24
- */
25
  function bp_blogs_clear_blog_object_cache( $blog_id, $user_id ) {
26
- wp_cache_delete( 'bp_blogs_of_user_' . $user_id, 'bp' );
27
  wp_cache_delete( 'bp_total_blogs_for_user_' . $user_id, 'bp' );
28
  }
29
 
30
- /**
31
- * Clear cache when a new blog is created
32
- *
33
- * @since BuddyPress (1.0)
34
- * @package BuddyPress
35
- * @subpackage BlogsBuddyBar
36
- * @param Blog $recorded_blog_obj
37
- */
38
  function bp_blogs_format_clear_blog_cache( $recorded_blog_obj ) {
39
  bp_blogs_clear_blog_object_cache( false, $recorded_blog_obj->user_id );
40
  wp_cache_delete( 'bp_total_blogs', 'bp' );
@@ -55,4 +34,4 @@ add_action( 'bp_blogs_new_blog_post', 'bp_core_clear_cache' );
55
  add_action( 'bp_blogs_new_blog', 'bp_core_clear_cache' );
56
  add_action( 'bp_blogs_remove_data', 'bp_core_clear_cache' );
57
 
58
- ?>
1
  <?php
2
+ /*******************************************************************************
3
+ * Caching
 
4
  *
5
  * Caching functions handle the clearing of cached objects and pages on specific
6
  * actions throughout BuddyPress.
 
 
 
7
  */
8
 
9
  // Exit if accessed directly
10
  if ( !defined( 'ABSPATH' ) ) exit;
11
 
 
 
 
 
 
 
 
 
 
12
  function bp_blogs_clear_blog_object_cache( $blog_id, $user_id ) {
13
+ wp_cache_delete( 'bp_blogs_of_user_' . $user_id, 'bp' );
14
  wp_cache_delete( 'bp_total_blogs_for_user_' . $user_id, 'bp' );
15
  }
16
 
 
 
 
 
 
 
 
 
17
  function bp_blogs_format_clear_blog_cache( $recorded_blog_obj ) {
18
  bp_blogs_clear_blog_object_cache( false, $recorded_blog_obj->user_id );
19
  wp_cache_delete( 'bp_total_blogs', 'bp' );
34
  add_action( 'bp_blogs_new_blog', 'bp_core_clear_cache' );
35
  add_action( 'bp_blogs_remove_data', 'bp_core_clear_cache' );
36
 
37
+ ?>
bp-blogs/bp-blogs-classes.php CHANGED
@@ -1,29 +1,22 @@
1
  <?php
2
-
3
- /**
4
- * BuddyPress Blogs Classes
5
- *
6
- * @package BuddyPress
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
- * @since BuddyPress (1.0)
17
- * @package BuddyPress
18
- * @subpackage BlogsClasses
19
- */
20
- class BP_Blogs_Blog {
21
  var $id;
22
  var $user_id;
23
  var $blog_id;
24
 
 
 
 
 
25
  function __construct( $id = null ) {
26
- if ( !empty( $id ) ) {
 
 
 
 
27
  $this->id = $id;
28
  $this->populate();
29
  }
@@ -84,7 +77,7 @@ class BP_Blogs_Blog {
84
  function get( $type, $limit = false, $page = false, $user_id = 0, $search_terms = false ) {
85
  global $bp, $wpdb;
86
 
87
- if ( !is_user_logged_in() || ( !bp_current_user_can( 'bp_moderate' ) && ( $user_id != bp_loggedin_user_id() ) ) )
88
  $hidden_sql = "AND wb.public = 1";
89
  else
90
  $hidden_sql = '';
@@ -118,11 +111,11 @@ class BP_Blogs_Blog {
118
  }
119
 
120
  $blog_ids = array();
121
- foreach ( (array) $paged_blogs as $blog ) {
122
  $blog_ids[] = $blog->blog_id;
123
  }
124
 
125
- $blog_ids = $wpdb->escape( join( ',', (array) $blog_ids ) );
126
  $paged_blogs = BP_Blogs_Blog::get_blog_extras( $paged_blogs, $blog_ids, $type );
127
 
128
  return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
@@ -139,7 +132,7 @@ class BP_Blogs_Blog {
139
  global $wpdb, $bp;
140
 
141
  if ( !$user_id )
142
- $user_id = bp_loggedin_user_id();
143
 
144
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $user_id, $blog_id ) );
145
  }
@@ -148,7 +141,7 @@ class BP_Blogs_Blog {
148
  global $wpdb, $bp;
149
 
150
  if ( !$user_id )
151
- $user_id = bp_loggedin_user_id();
152
 
153
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) );
154
  }
@@ -157,7 +150,7 @@ class BP_Blogs_Blog {
157
  global $bp, $wpdb;
158
 
159
  if ( !$user_id )
160
- $user_id = bp_displayed_user_id();
161
 
162
  // Show logged in users their hidden blogs.
163
  if ( !bp_is_my_profile() && !$show_hidden )
@@ -168,7 +161,7 @@ class BP_Blogs_Blog {
168
  $total_blog_count = BP_Blogs_Blog::total_blog_count_for_user( $user_id );
169
 
170
  $user_blogs = array();
171
- foreach ( (array) $blogs as $blog ) {
172
  $user_blogs[$blog->blog_id] = new stdClass;
173
  $user_blogs[$blog->blog_id]->id = $blog->id;
174
  $user_blogs[$blog->blog_id]->blog_id = $blog->blog_id;
@@ -183,7 +176,7 @@ class BP_Blogs_Blog {
183
  global $bp, $wpdb;
184
 
185
  if ( !$user_id )
186
- $user_id = bp_displayed_user_id();
187
 
188
  return $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) );
189
  }
@@ -198,10 +191,10 @@ class BP_Blogs_Blog {
198
  global $bp, $wpdb;
199
 
200
  if ( !$user_id )
201
- $user_id = bp_displayed_user_id();
202
 
203
  // If the user is logged in return the blog count including their hidden blogs.
204
- if ( ( is_user_logged_in() && $user_id == bp_loggedin_user_id() ) || bp_current_user_can( 'bp_moderate' ) )
205
  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) );
206
  else
207
  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) );
@@ -212,7 +205,7 @@ class BP_Blogs_Blog {
212
 
213
  $filter = like_escape( $wpdb->escape( $filter ) );
214
 
215
- if ( !bp_current_user_can( 'bp_moderate' ) )
216
  $hidden_sql = "AND wb.public = 1";
217
 
218
  if ( $limit && $page )
@@ -227,7 +220,7 @@ class BP_Blogs_Blog {
227
  function get_all( $limit = null, $page = null ) {
228
  global $bp, $wpdb;
229
 
230
- $hidden_sql = !bp_current_user_can( 'bp_moderate' ) ? "AND wb.public = 1" : '';
231
  $pag_sql = ( $limit && $page ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ) : '';
232
 
233
  $paged_blogs = $wpdb->get_results( $wpdb->prepare( "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}" ) );
@@ -241,7 +234,7 @@ class BP_Blogs_Blog {
241
 
242
  $letter = like_escape( $wpdb->escape( $letter ) );
243
 
244
- if ( !bp_current_user_can( 'bp_moderate' ) )
245
  $hidden_sql = "AND wb.public = 1";
246
 
247
  if ( $limit && $page )
@@ -268,7 +261,7 @@ class BP_Blogs_Blog {
268
  $blog_descs = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, meta_value as description FROM {$bp->blogs->table_name_blogmeta} WHERE meta_key = 'description' AND blog_id IN ( {$blog_ids} )" ) );
269
 
270
  for ( $i = 0, $count = count( $paged_blogs ); $i < $count; ++$i ) {
271
- foreach ( (array) $blog_descs as $desc ) {
272
  if ( $desc->blog_id == $paged_blogs[$i]->blog_id )
273
  $paged_blogs[$i]->description = $desc->description;
274
  }
@@ -280,11 +273,10 @@ class BP_Blogs_Blog {
280
  function is_hidden( $blog_id ) {
281
  global $wpdb;
282
 
283
- if ( !(int) $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT public FROM {$wpdb->base_prefix}blogs WHERE blog_id = %d", $blog_id ) ) )
284
  return true;
285
 
286
  return false;
287
  }
288
  }
289
-
290
- ?>
1
  <?php
 
 
 
 
 
 
 
 
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
5
+ Class BP_Blogs_Blog {
 
 
 
 
 
 
 
6
  var $id;
7
  var $user_id;
8
  var $blog_id;
9
 
10
+ function bp_blogs_blog( $id = null ) {
11
+ $this->__construct( $id );
12
+ }
13
+
14
  function __construct( $id = null ) {
15
+ global $bp, $wpdb;
16
+
17
+ $user_id = bp_displayed_user_id();
18
+
19
+ if ( $id ) {
20
  $this->id = $id;
21
  $this->populate();
22
  }
77
  function get( $type, $limit = false, $page = false, $user_id = 0, $search_terms = false ) {
78
  global $bp, $wpdb;
79
 
80
+ if ( !is_user_logged_in() || ( !is_super_admin() && ( $user_id != $bp->loggedin_user->id ) ) )
81
  $hidden_sql = "AND wb.public = 1";
82
  else
83
  $hidden_sql = '';
111
  }
112
 
113
  $blog_ids = array();
114
+ foreach ( (array)$paged_blogs as $blog ) {
115
  $blog_ids[] = $blog->blog_id;
116
  }
117
 
118
+ $blog_ids = $wpdb->escape( join( ',', (array)$blog_ids ) );
119
  $paged_blogs = BP_Blogs_Blog::get_blog_extras( $paged_blogs, $blog_ids, $type );
120
 
121
  return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
132
  global $wpdb, $bp;
133
 
134
  if ( !$user_id )
135
+ $user_id = $bp->loggedin_user->id;
136
 
137
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $user_id, $blog_id ) );
138
  }
141
  global $wpdb, $bp;
142
 
143
  if ( !$user_id )
144
+ $user_id = $bp->loggedin_user->id;
145
 
146
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) );
147
  }
150
  global $bp, $wpdb;
151
 
152
  if ( !$user_id )
153
+ $user_id = $bp->displayed_user->id;
154
 
155
  // Show logged in users their hidden blogs.
156
  if ( !bp_is_my_profile() && !$show_hidden )
161
  $total_blog_count = BP_Blogs_Blog::total_blog_count_for_user( $user_id );
162
 
163
  $user_blogs = array();
164
+ foreach ( (array)$blogs as $blog ) {
165
  $user_blogs[$blog->blog_id] = new stdClass;
166
  $user_blogs[$blog->blog_id]->id = $blog->id;
167
  $user_blogs[$blog->blog_id]->blog_id = $blog->blog_id;
176
  global $bp, $wpdb;
177
 
178
  if ( !$user_id )
179
+ $user_id = $bp->displayed_user->id;
180
 
181
  return $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) );
182
  }
191
  global $bp, $wpdb;
192
 
193
  if ( !$user_id )
194
+ $user_id = $bp->displayed_user->id;
195
 
196
  // If the user is logged in return the blog count including their hidden blogs.
197
+ if ( ( is_user_logged_in() && $user_id == $bp->loggedin_user->id ) || is_super_admin() )
198
  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) );
199
  else
200
  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) );
205
 
206
  $filter = like_escape( $wpdb->escape( $filter ) );
207
 
208
+ if ( !is_super_admin() )
209
  $hidden_sql = "AND wb.public = 1";
210
 
211
  if ( $limit && $page )
220
  function get_all( $limit = null, $page = null ) {
221
  global $bp, $wpdb;
222
 
223
+ $hidden_sql = !is_super_admin() ? "AND wb.public = 1" : '';
224
  $pag_sql = ( $limit && $page ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ) : '';
225
 
226
  $paged_blogs = $wpdb->get_results( $wpdb->prepare( "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}" ) );
234
 
235
  $letter = like_escape( $wpdb->escape( $letter ) );
236
 
237
+ if ( !is_super_admin() )
238
  $hidden_sql = "AND wb.public = 1";
239
 
240
  if ( $limit && $page )
261
  $blog_descs = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, meta_value as description FROM {$bp->blogs->table_name_blogmeta} WHERE meta_key = 'description' AND blog_id IN ( {$blog_ids} )" ) );
262
 
263
  for ( $i = 0, $count = count( $paged_blogs ); $i < $count; ++$i ) {
264
+ foreach ( (array)$blog_descs as $desc ) {
265
  if ( $desc->blog_id == $paged_blogs[$i]->blog_id )
266
  $paged_blogs[$i]->description = $desc->description;
267
  }
273
  function is_hidden( $blog_id ) {
274
  global $wpdb;
275
 
276
+ if ( !(int)$wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT public FROM {$wpdb->base_prefix}blogs WHERE blog_id = %d", $blog_id ) ) )
277
  return true;
278
 
279
  return false;
280
  }
281
  }
282
+ ?>
 
bp-blogs/bp-blogs-filters.php DELETED
@@ -1,26 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Filters related to the Blogs component.
5
- *
6
- * @package BuddyPress
7
- * @subpackage Blogs
8
- * @since 1.6
9
- */
10
-
11
- /**
12
- * Ensures that the 'Create a new site' link at wp-admin/my-sites.php points to the BP blog signup
13
- *
14
- * @since 1.6
15
- * @uses apply_filters() Filter bp_blogs_creation_location to alter the returned value
16
- *
17
- * @param string $url The original URL (points to wp-signup.php by default)
18
- * @return string The new URL
19
- */
20
- function bp_blogs_creation_location( $url ) {
21
- return apply_filters( 'bp_blogs_creation_location', trailingslashit( bp_get_root_domain() . '/' . bp_get_blogs_slug() . '/create', $url ) );
22
- }
23
- add_filter( 'wp_signup_location', 'bp_blogs_creation_location' );
24
-
25
-
26
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-blogs/bp-blogs-functions.php CHANGED
@@ -5,9 +5,9 @@ if ( !defined( 'ABSPATH' ) ) exit;
5
  /**
6
  * Checks $bp pages global and looks for directory page
7
  *
8
- * @since BuddyPress (1.5)
9
  *
10
- * @global BuddyPress $bp The one true BuddyPress instance
11
  * @return bool True if set, False if empty
12
  */
13
  function bp_blogs_has_directory() {
@@ -17,6 +17,7 @@ function bp_blogs_has_directory() {
17
  }
18
 
19
  function bp_blogs_get_blogs( $args = '' ) {
 
20
 
21
  $defaults = array(
22
  'type' => 'active', // active, alphabetical, newest, or random
@@ -54,12 +55,12 @@ function bp_blogs_record_existing_blogs() {
54
  $blog_ids = 1;
55
 
56
  if ( $blog_ids ) {
57
- foreach( (array) $blog_ids as $blog_id ) {
58
  $users = get_users( array( 'blog_id' => $blog_id ) );
59
  $subscribers = get_users( array( 'blog_id' => $blog_id, 'role' => 'subscriber' ) );
60
 
61
  if ( !empty( $users ) ) {
62
- foreach ( (array) $users as $user ) {
63
  // Don't record blogs for subscribers
64
  if ( !in_array( $user, $subscribers ) )
65
  bp_blogs_record_blog( $blog_id, $user->ID, true );
@@ -72,16 +73,18 @@ function bp_blogs_record_existing_blogs() {
72
  /**
73
  * Makes BuddyPress aware of a new site so that it can track its activity.
74
  *
75
- * @since BuddyPress (1.0)
76
  * @param int $blog_id
77
  * @param int $user_id
78
  * @param $bool $no_activity ; optional.
 
79
  * @uses BP_Blogs_Blog
80
  */
81
  function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) {
 
82
 
83
- if ( empty( $user_id ) )
84
- $user_id = bp_loggedin_user_id();
85
 
86
  $name = get_blog_option( $blog_id, 'blogname' );
87
  $description = get_blog_option( $blog_id, 'blogdescription' );
@@ -92,14 +95,16 @@ function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) {
92
  $recorded_blog = new BP_Blogs_Blog;
93
  $recorded_blog->user_id = $user_id;
94
  $recorded_blog->blog_id = $blog_id;
95
- $recorded_blog_id = $recorded_blog->save();
96
- $is_recorded = !empty( $recorded_blog_id ) ? true : false;
 
 
97
 
98
  bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'name', $name );
99
  bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description );
100
  bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', bp_core_current_time() );
101
 
102
- $is_private = !empty( $_POST['blog_public'] ) && (int) $_POST['blog_public'] ? false : true;
103
  $is_private = !apply_filters( 'bp_is_new_blog_public', !$is_private );
104
 
105
  // Only record this activity if the blog is public
@@ -149,11 +154,11 @@ add_action( 'update_option_blogdescription', 'bp_blogs_update_option_blogdescrip
149
  function bp_blogs_record_post( $post_id, $post, $user_id = 0 ) {
150
  global $bp, $wpdb;
151
 
152
- $post_id = (int) $post_id;
153
- $blog_id = (int) $wpdb->blogid;
154
 
155
  if ( !$user_id )
156
- $user_id = (int) $post->post_author;
157
 
158
  // Stop infinite loops with WordPress MU Sitewide Tags.
159
  // That plugin changed the way its settings were stored at some point. Thus the dual check.
@@ -164,7 +169,7 @@ function bp_blogs_record_post( $post_id, $post, $user_id = 0 ) {
164
  $tags_blog_id = isset( $bp->site_options['tags_blog_id'] ) ? $bp->site_options['tags_blog_id'] : 0;
165
  }
166
 
167
- if ( (int) $blog_id == $tags_blog_id && apply_filters( 'bp_blogs_block_sitewide_tags_activity', true ) )
168
  return false;
169
 
170
  // Don't record this if it's not a post
@@ -175,35 +180,18 @@ function bp_blogs_record_post( $post_id, $post, $user_id = 0 ) {
175
 
176
  if ( 'publish' == $post->post_status && empty( $post->post_password ) ) {
177
  if ( $is_blog_public || !is_multisite() ) {
178
-
179
  // Record this in activity streams
180
  $post_permalink = get_permalink( $post_id );
181
 
182
  if ( is_multisite() )
183
- $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>' );
184
  else
185
- $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>' );
186
-
187
- // Make sure there's not an existing entry for this post (prevent bumping)
188
- if ( bp_is_active( 'activity' ) ) {
189
- $existing = bp_activity_get( array(
190
- 'filter' => array(
191
- 'user_id' => (int) $post->post_author,
192
- 'action' => 'new_blog_post',
193
- 'primary_id' => $blog_id,
194
- 'secondary_id' => $post_id,
195
- )
196
- ) );
197
-
198
- if ( !empty( $existing['activities'] ) ) {
199
- return;
200
- }
201
- }
202
 
203
  $activity_content = $post->post_content;
204
 
205
  bp_blogs_record_activity( array(
206
- 'user_id' => (int) $post->post_author,
207
  'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, $post, $post_permalink ),
208
  'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, $post, $post_permalink ),
209
  'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
@@ -228,11 +216,14 @@ add_action( 'save_post', 'bp_blogs_record_post', 10, 2 );
228
  * Record blog comment activity. Checks if blog is public and post is not
229
  * password protected.
230
  *
 
231
  * @param int $comment_id
232
- * @param mixed $is_approved
233
  * @return mixed
234
  */
235
  function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
 
 
236
  // Get the users comment
237
  $recorded_comment = get_comment( $comment_id );
238
 
@@ -244,20 +235,14 @@ function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
244
  if ( empty( $recorded_comment->comment_author_email ) )
245
  return false;
246
 
247
- // Don't record activity if the comment has already been marked as spam
248
- if ( 'spam' === $is_approved )
249
- return false;
250
 
251
- // Get the user by the comment author email.
252
- $user = get_user_by( 'email', $recorded_comment->comment_author_email );
253
-
254
- // If user isn't registered, don't record activity
255
- if ( empty( $user ) )
256
  return false;
257
 
258
- // Get the user_id
259
- $user_id = (int) $user->ID;
260
-
261
  // Get blog and post data
262
  $blog_id = get_current_blog_id();
263
  $recorded_comment->post = get_post( $recorded_comment->comment_post_ID );
@@ -311,6 +296,14 @@ function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
311
  add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
312
  add_action( 'edit_comment', 'bp_blogs_record_comment', 10 );
313
 
 
 
 
 
 
 
 
 
314
  function bp_blogs_add_user_to_blog( $user_id, $role = false, $blog_id = 0 ) {
315
  global $wpdb;
316
 
@@ -321,7 +314,7 @@ function bp_blogs_add_user_to_blog( $user_id, $role = false, $blog_id = 0 ) {
321
  if ( empty( $role ) ) {
322
  $key = $wpdb->get_blog_prefix( $blog_id ). 'capabilities';
323
 
324
- $roles = bp_get_user_meta( $user_id, $key, true );
325
 
326
  if ( is_array( $roles ) )
327
  $role = array_search( 1, $roles );
@@ -346,28 +339,10 @@ function bp_blogs_remove_user_from_blog( $user_id, $blog_id = 0 ) {
346
  }
347
  add_action( 'remove_user_from_blog', 'bp_blogs_remove_user_from_blog', 10, 2 );
348
 
349
- /**
350
- * Rehooks WP's maybe_add_existing_user_to_blog with a later priority
351
- *
352
- * WordPress catches add-user-to-blog requests at init:10. In some cases, this can precede BP's
353
- * Blogs component. This function bumps the priority of the core function, so that we can be sure
354
- * that the Blogs component is loaded first. See http://buddypress.trac.wordpress.org/ticket/3916
355
- *
356
- * @since 1.6
357
- */
358
- function bp_blogs_maybe_add_user_to_blog() {
359
- if ( ! is_multisite() )
360
- return;
361
-
362
- remove_action( 'init', 'maybe_add_existing_user_to_blog' );
363
- add_action( 'init', 'maybe_add_existing_user_to_blog', 20 );
364
- }
365
- add_action( 'init', 'bp_blogs_maybe_add_user_to_blog', 1 );
366
-
367
  function bp_blogs_remove_blog( $blog_id ) {
368
  global $bp;
369
 
370
- $blog_id = (int) $blog_id;
371
  do_action( 'bp_blogs_before_remove_blog', $blog_id );
372
 
373
  BP_Blogs_Blog::delete_blog_for_all( $blog_id );
@@ -380,21 +355,17 @@ function bp_blogs_remove_blog( $blog_id ) {
380
  add_action( 'delete_blog', 'bp_blogs_remove_blog' );
381
 
382
  function bp_blogs_remove_blog_for_user( $user_id, $blog_id ) {
383
- global $bp;
384
 
385
- $blog_id = (int) $blog_id;
386
- $user_id = (int) $user_id;
387
 
388
  do_action( 'bp_blogs_before_remove_blog_for_user', $blog_id, $user_id );
389
 
390
  BP_Blogs_Blog::delete_blog_for_user( $blog_id, $user_id );
391
 
392
  // Delete activity stream item
393
- bp_blogs_delete_activity( array(
394
- 'item_id' => $blog_id,
395
- 'component' => $bp->blogs->id,
396
- 'type' => 'new_blog'
397
- ) );
398
 
399
  do_action( 'bp_blogs_remove_blog_for_user', $blog_id, $user_id );
400
  }
@@ -406,13 +377,13 @@ function bp_blogs_remove_post( $post_id, $blog_id = 0, $user_id = 0 ) {
406
  if ( empty( $wpdb->blogid ) )
407
  return false;
408
 
409
- $post_id = (int) $post_id;
410
 
411
  if ( !$blog_id )
412
- $blog_id = (int) $wpdb->blogid;
413
 
414
  if ( !$user_id )
415
- $user_id = bp_loggedin_user_id();
416
 
417
  do_action( 'bp_blogs_before_remove_post', $blog_id, $post_id, $user_id );
418
 
@@ -424,87 +395,15 @@ function bp_blogs_remove_post( $post_id, $blog_id = 0, $user_id = 0 ) {
424
  add_action( 'delete_post', 'bp_blogs_remove_post' );
425
 
426
  function bp_blogs_remove_comment( $comment_id ) {
427
- global $wpdb;
428
 
429
  // Delete activity stream item
430
  bp_blogs_delete_activity( array( 'item_id' => $wpdb->blogid, 'secondary_item_id' => $comment_id, 'type' => 'new_blog_comment' ) );
431
 
432
- do_action( 'bp_blogs_remove_comment', $wpdb->blogid, $comment_id, bp_loggedin_user_id() );
433
  }
434
  add_action( 'delete_comment', 'bp_blogs_remove_comment' );
435
 
436
- /**
437
- * When a blog comment status transition occurs, update the relevant activity's status.
438
- *
439
- * @global object $bp BuddyPress global settings
440
- * @param string $new_status New comment status.
441
- * @param string $old_status Previous comment status.
442
- * @param object $comment Comment data.
443
- * @since 1.6
444
- */
445
- function bp_blogs_transition_activity_status( $new_status, $old_status, $comment ) {
446
- global $bp;
447
-
448
- // Check the Activity component is active
449
- if ( ! bp_is_active( 'activity' ) )
450
- return;
451
-
452
- /**
453
- * Activity currently doesn't have any concept of a trash, or an unapproved/approved state.
454
- *
455
- * If a blog comment transitions to a "delete" or "hold" status, delete the activity item.
456
- * If a blog comment transitions to trashed, or spammed, mark the activity as spam.
457
- * If a blog comment transitions to approved (and the activity exists), mark the activity as ham.
458
- * Otherwise, record the comment into the activity stream.
459
- */
460
-
461
- // This clause was moved in from bp_blogs_remove_comment() in BuddyPress 1.6. It handles delete/hold.
462
- if ( in_array( $new_status, array( 'delete', 'hold' ) ) )
463
- return bp_blogs_remove_comment( $comment->comment_ID );
464
-
465
- // These clauses handle trash, spam, and un-spams.
466
- elseif ( in_array( $new_status, array( 'trash', 'spam' ) ) )
467
- $action = 'spam_activity';
468
- elseif ( 'approved' == $new_status )
469
- $action = 'ham_activity';
470
-
471
- // Get the activity
472
- $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', ) );
473
-
474
- // Check activity item exists
475
- if ( ! $activity_id ) {
476
-
477
- // If no activity exists, but the comment has been approved, record it into the activity table.
478
- if ( 'approved' == $new_status )
479
- return bp_blogs_record_comment( $comment->comment_ID, true );
480
-
481
- return;
482
- }
483
-
484
- // Create an activity object
485
- $activity = new BP_Activity_Activity( $activity_id );
486
- if ( empty( $activity->component ) )
487
- return;
488
-
489
- // Spam/ham the activity if it's not already in that state
490
- if ( 'spam_activity' == $action && ! $activity->is_spam ) {
491
- bp_activity_mark_as_spam( $activity );
492
- } elseif ( 'ham_activity' == $action) {
493
- bp_activity_mark_as_ham( $activity );
494
- }
495
-
496
- // Add "new_blog_comment" to the whitelisted activity types, so that the activity's Akismet history is generated
497
- $comment_akismet_history = create_function( '$t', '$t[] = "new_blog_comment"; return $t;' );
498
- add_filter( 'bp_akismet_get_activity_types', $comment_akismet_history );
499
-
500
- // Save the updated activity
501
- $activity->save();
502
-
503
- // Remove the "new_blog_comment" activity type whitelist so we don't break anything
504
- remove_filter( 'bp_akismet_get_activity_types', $comment_akismet_history );
505
- }
506
- add_action( 'transition_comment_status', 'bp_blogs_transition_activity_status', 10, 3 );
507
-
508
  function bp_blogs_total_blogs() {
509
  if ( !$count = wp_cache_get( 'bp_total_blogs', 'bp' ) ) {
510
  $blogs = BP_Blogs_Blog::get_all();
@@ -515,9 +414,10 @@ function bp_blogs_total_blogs() {
515
  }
516
 
517
  function bp_blogs_total_blogs_for_user( $user_id = 0 ) {
 
518
 
519
- if ( empty( $user_id ) )
520
- $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
521
 
522
  if ( !$count = wp_cache_get( 'bp_total_blogs_for_user_' . $user_id, 'bp' ) ) {
523
  $count = BP_Blogs_Blog::total_blog_count_for_user( $user_id );
@@ -618,7 +518,7 @@ function bp_blogs_get_blogmeta( $blog_id, $meta_key = '') {
618
  return '';
619
  }
620
 
621
- $metas = array_map('maybe_unserialize', (array) $metas);
622
 
623
  if ( 1 == count($metas) )
624
  return $metas[0];
@@ -670,5 +570,4 @@ function bp_blogs_remove_data( $user_id ) {
670
  add_action( 'wpmu_delete_user', 'bp_blogs_remove_data' );
671
  add_action( 'delete_user', 'bp_blogs_remove_data' );
672
  add_action( 'bp_make_spam_user', 'bp_blogs_remove_data' );
673
-
674
- ?>
5
  /**
6
  * Checks $bp pages global and looks for directory page
7
  *
8
+ * @since 1.5
9
  *
10
+ * @global object $bp Global BuddyPress settings object
11
  * @return bool True if set, False if empty
12
  */
13
  function bp_blogs_has_directory() {
17
  }
18
 
19
  function bp_blogs_get_blogs( $args = '' ) {
20
+ global $bp;
21
 
22
  $defaults = array(
23
  'type' => 'active', // active, alphabetical, newest, or random
55
  $blog_ids = 1;
56
 
57
  if ( $blog_ids ) {
58
+ foreach( (array)$blog_ids as $blog_id ) {
59
  $users = get_users( array( 'blog_id' => $blog_id ) );
60
  $subscribers = get_users( array( 'blog_id' => $blog_id, 'role' => 'subscriber' ) );
61
 
62
  if ( !empty( $users ) ) {
63
+ foreach ( (array)$users as $user ) {
64
  // Don't record blogs for subscribers
65
  if ( !in_array( $user, $subscribers ) )
66
  bp_blogs_record_blog( $blog_id, $user->ID, true );
73
  /**
74
  * Makes BuddyPress aware of a new site so that it can track its activity.
75
  *
76
+ * @global object $bp BuddyPress global settings
77
  * @param int $blog_id
78
  * @param int $user_id
79
  * @param $bool $no_activity ; optional.
80
+ * @since 1.0
81
  * @uses BP_Blogs_Blog
82
  */
83
  function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) {
84
+ global $bp;
85
 
86
+ if ( !$user_id )
87
+ $user_id = $bp->loggedin_user->id;
88
 
89
  $name = get_blog_option( $blog_id, 'blogname' );
90
  $description = get_blog_option( $blog_id, 'blogdescription' );
95
  $recorded_blog = new BP_Blogs_Blog;
96
  $recorded_blog->user_id = $user_id;
97
  $recorded_blog->blog_id = $blog_id;
98
+
99
+ $recorded_blog_id = $recorded_blog->save();
100
+
101
+ $is_recorded = !empty( $recorded_blog_id ) ? true : false;
102
 
103
  bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'name', $name );
104
  bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description );
105
  bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', bp_core_current_time() );
106
 
107
+ $is_private = !empty( $_POST['blog_public'] ) && (int)$_POST['blog_public'] ? false : true;
108
  $is_private = !apply_filters( 'bp_is_new_blog_public', !$is_private );
109
 
110
  // Only record this activity if the blog is public
154
  function bp_blogs_record_post( $post_id, $post, $user_id = 0 ) {
155
  global $bp, $wpdb;
156
 
157
+ $post_id = (int)$post_id;
158
+ $blog_id = (int)$wpdb->blogid;
159
 
160
  if ( !$user_id )
161
+ $user_id = (int)$post->post_author;
162
 
163
  // Stop infinite loops with WordPress MU Sitewide Tags.
164
  // That plugin changed the way its settings were stored at some point. Thus the dual check.
169
  $tags_blog_id = isset( $bp->site_options['tags_blog_id'] ) ? $bp->site_options['tags_blog_id'] : 0;
170
  }
171
 
172
+ if ( (int)$blog_id == $tags_blog_id && apply_filters( 'bp_blogs_block_sitewide_tags_activity', true ) )
173
  return false;
174
 
175
  // Don't record this if it's not a post
180
 
181
  if ( 'publish' == $post->post_status && empty( $post->post_password ) ) {
182
  if ( $is_blog_public || !is_multisite() ) {
 
183
  // Record this in activity streams
184
  $post_permalink = get_permalink( $post_id );
185
 
186
  if ( is_multisite() )
187
+ $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>' );
188
  else
189
+ $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>' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
 
191
  $activity_content = $post->post_content;
192
 
193
  bp_blogs_record_activity( array(
194
+ 'user_id' => (int)$post->post_author,
195
  'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, $post, $post_permalink ),
196
  'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, $post, $post_permalink ),
197
  'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
216
  * Record blog comment activity. Checks if blog is public and post is not
217
  * password protected.
218
  *
219
+ * @global $bp $bp
220
  * @param int $comment_id
221
+ * @param bool $is_approved
222
  * @return mixed
223
  */
224
  function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
225
+ global $bp;
226
+
227
  // Get the users comment
228
  $recorded_comment = get_comment( $comment_id );
229
 
235
  if ( empty( $recorded_comment->comment_author_email ) )
236
  return false;
237
 
238
+ // Get the user_id from the comment author email.
239
+ $user = get_user_by( 'email', $recorded_comment->comment_author_email );
240
+ $user_id = (int)$user->ID;
241
 
242
+ // If there's no registered user id, don't record activity
243
+ if ( empty( $user_id ) )
 
 
 
244
  return false;
245
 
 
 
 
246
  // Get blog and post data
247
  $blog_id = get_current_blog_id();
248
  $recorded_comment->post = get_post( $recorded_comment->comment_post_ID );
296
  add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
297
  add_action( 'edit_comment', 'bp_blogs_record_comment', 10 );
298
 
299
+ function bp_blogs_manage_comment( $comment_id, $comment_status ) {
300
+ if ( 'spam' == $comment_status || 'hold' == $comment_status || 'delete' == $comment_status || 'trash' == $comment_status )
301
+ return bp_blogs_remove_comment( $comment_id );
302
+
303
+ return bp_blogs_record_comment( $comment_id, true );
304
+ }
305
+ add_action( 'wp_set_comment_status', 'bp_blogs_manage_comment', 10, 2 );
306
+
307
  function bp_blogs_add_user_to_blog( $user_id, $role = false, $blog_id = 0 ) {
308
  global $wpdb;
309
 
314
  if ( empty( $role ) ) {
315
  $key = $wpdb->get_blog_prefix( $blog_id ). 'capabilities';
316
 
317
+ $roles = get_user_meta( $user_id, $key, true );
318
 
319
  if ( is_array( $roles ) )
320
  $role = array_search( 1, $roles );
339
  }
340
  add_action( 'remove_user_from_blog', 'bp_blogs_remove_user_from_blog', 10, 2 );
341
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
342
  function bp_blogs_remove_blog( $blog_id ) {
343
  global $bp;
344
 
345
+ $blog_id = (int)$blog_id;
346
  do_action( 'bp_blogs_before_remove_blog', $blog_id );
347
 
348
  BP_Blogs_Blog::delete_blog_for_all( $blog_id );
355
  add_action( 'delete_blog', 'bp_blogs_remove_blog' );
356
 
357
  function bp_blogs_remove_blog_for_user( $user_id, $blog_id ) {
358
+ global $bp, $current_user;
359
 
360
+ $blog_id = (int)$blog_id;
361
+ $user_id = (int)$user_id;
362
 
363
  do_action( 'bp_blogs_before_remove_blog_for_user', $blog_id, $user_id );
364
 
365
  BP_Blogs_Blog::delete_blog_for_user( $blog_id, $user_id );
366
 
367
  // Delete activity stream item
368
+ bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->id, 'type' => 'new_blog' ) );
 
 
 
 
369
 
370
  do_action( 'bp_blogs_remove_blog_for_user', $blog_id, $user_id );
371
  }
377
  if ( empty( $wpdb->blogid ) )
378
  return false;
379
 
380
+ $post_id = (int)$post_id;
381
 
382
  if ( !$blog_id )
383
+ $blog_id = (int)$wpdb->blogid;
384
 
385
  if ( !$user_id )
386
+ $user_id = $bp->loggedin_user->id;
387
 
388
  do_action( 'bp_blogs_before_remove_post', $blog_id, $post_id, $user_id );
389
 
395
  add_action( 'delete_post', 'bp_blogs_remove_post' );
396
 
397
  function bp_blogs_remove_comment( $comment_id ) {
398
+ global $wpdb, $bp;
399
 
400
  // Delete activity stream item
401
  bp_blogs_delete_activity( array( 'item_id' => $wpdb->blogid, 'secondary_item_id' => $comment_id, 'type' => 'new_blog_comment' ) );
402
 
403
+ do_action( 'bp_blogs_remove_comment', $wpdb->blogid, $comment_id, $bp->loggedin_user->id );
404
  }
405
  add_action( 'delete_comment', 'bp_blogs_remove_comment' );
406
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
407
  function bp_blogs_total_blogs() {
408
  if ( !$count = wp_cache_get( 'bp_total_blogs', 'bp' ) ) {
409
  $blogs = BP_Blogs_Blog::get_all();
414
  }
415
 
416
  function bp_blogs_total_blogs_for_user( $user_id = 0 ) {
417
+ global $bp;
418
 
419
+ if ( !$user_id )
420
+ $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
421
 
422
  if ( !$count = wp_cache_get( 'bp_total_blogs_for_user_' . $user_id, 'bp' ) ) {
423
  $count = BP_Blogs_Blog::total_blog_count_for_user( $user_id );
518
  return '';
519
  }
520
 
521
+ $metas = array_map('maybe_unserialize', (array)$metas);
522
 
523
  if ( 1 == count($metas) )
524
  return $metas[0];
570
  add_action( 'wpmu_delete_user', 'bp_blogs_remove_data' );
571
  add_action( 'delete_user', 'bp_blogs_remove_data' );
572
  add_action( 'bp_make_spam_user', 'bp_blogs_remove_data' );
573
+ ?>
 
bp-blogs/bp-blogs-loader.php CHANGED
@@ -1,5 +1,4 @@
1
  <?php
2
-
3
  /**
4
  * BuddyPress Blogs Streams Loader
5
  *
@@ -17,7 +16,7 @@ class BP_Blogs_Component extends BP_Component {
17
  /**
18
  * Start the blogs component creation process
19
  *
20
- * @since BuddyPress (1.5)
21
  */
22
  function __construct() {
23
  parent::start(
@@ -33,8 +32,8 @@ class BP_Blogs_Component extends BP_Component {
33
  * The BP_BLOGS_SLUG constant is deprecated, and only used here for
34
  * backwards compatibility.
35
  *
36
- * @since BuddyPress (1.5)
37
- * @global BuddyPress $bp The one true BuddyPress instance
38
  */
39
  function setup_globals() {
40
  global $bp;
@@ -51,6 +50,7 @@ class BP_Blogs_Component extends BP_Component {
51
  // All globals for messaging component.
52
  // Note that global_tables is included in this array.
53
  $globals = array(
 
54
  'slug' => BP_BLOGS_SLUG,
55
  'root_slug' => isset( $bp->pages->blogs->slug ) ? $bp->pages->blogs->slug : BP_BLOGS_SLUG,
56
  'has_directory' => is_multisite(), // Non-multisite installs don't need a top-level Sites directory, since there's only one site
@@ -75,7 +75,6 @@ class BP_Blogs_Component extends BP_Component {
75
  'screens',
76
  'classes',
77
  'template',
78
- 'filters',
79
  'activity',
80
  'functions',
81
  'buddybar'
@@ -91,7 +90,7 @@ class BP_Blogs_Component extends BP_Component {
91
  /**
92
  * Setup BuddyBar navigation
93
  *
94
- * @global BuddyPress $bp The one true BuddyPress instance
95
  */
96
  function setup_nav() {
97
  global $bp;
@@ -104,37 +103,24 @@ class BP_Blogs_Component extends BP_Component {
104
  if ( !is_multisite() )
105
  return false;
106
 
107
- $sub_nav = array();
108
-
109
  // Add 'Sites' to the main navigation
110
  $main_nav = array(
111
  'name' => sprintf( __( 'Sites <span>%d</span>', 'buddypress' ), bp_blogs_total_blogs_for_user() ),
112
  'slug' => $this->slug,
113
  'position' => 30,
114
  'screen_function' => 'bp_blogs_screen_my_blogs',
115
- 'default_subnav_slug' => 'my-sites',
116
  'item_css_id' => $this->id
117
  );
118
-
119
- $parent_url = trailingslashit( bp_displayed_user_domain() . bp_get_blogs_slug() );
120
-
121
- $sub_nav[] = array(
122
- 'name' => __( 'My Sites', 'buddypress' ),
123
- 'slug' => 'my-sites',
124
- 'parent_url' => $parent_url,
125
- 'parent_slug' => $bp->blogs->slug,
126
- 'screen_function' => 'bp_blogs_screen_my_blogs',
127
- 'position' => 10
128
- );
129
 
130
  // Setup navigation
131
- parent::setup_nav( $main_nav, $sub_nav );
132
  }
133
 
134
  /**
135
- * Set up the Toolbar
136
  *
137
- * @global BuddyPress $bp The one true BuddyPress instance
138
  */
139
  function setup_admin_bar() {
140
  global $bp;
@@ -153,7 +139,7 @@ class BP_Blogs_Component extends BP_Component {
153
  // Menus for logged in user
154
  if ( is_user_logged_in() ) {
155
 
156
- $blogs_link = trailingslashit( bp_loggedin_user_domain() . $this->slug );
157
 
158
  // Add the "Blogs" sub menu
159
  $wp_admin_nav[] = array(
@@ -179,7 +165,7 @@ class BP_Blogs_Component extends BP_Component {
179
  /**
180
  * Sets up the title for pages and <title>
181
  *
182
- * @global BuddyPress $bp The one true BuddyPress instance
183
  */
184
  function setup_title() {
185
  global $bp;
@@ -195,22 +181,17 @@ class BP_Blogs_Component extends BP_Component {
195
  // users avatar and name
196
  } else {
197
  $bp->bp_options_avatar = bp_core_fetch_avatar( array(
198
- 'item_id' => bp_displayed_user_id(),
199
- 'type' => 'thumb',
200
- 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() )
201
  ) );
202
- $bp->bp_options_title = bp_get_displayed_user_fullname();
203
  }
204
  }
205
 
206
  parent::setup_title();
207
  }
208
  }
 
 
209
 
210
- function bp_setup_blogs() {
211
- global $bp;
212
- $bp->blogs = new BP_Blogs_Component();
213
- }
214
- add_action( 'bp_setup_components', 'bp_setup_blogs', 6 );
215
-
216
- ?>
1
  <?php
 
2
  /**
3
  * BuddyPress Blogs Streams Loader
4
  *
16
  /**
17
  * Start the blogs component creation process
18
  *
19
+ * @since 1.5
20
  */
21
  function __construct() {
22
  parent::start(
32
  * The BP_BLOGS_SLUG constant is deprecated, and only used here for
33
  * backwards compatibility.
34
  *
35
+ * @since 1.5
36
+ * @global obj $bp
37
  */
38
  function setup_globals() {
39
  global $bp;
50
  // All globals for messaging component.
51
  // Note that global_tables is included in this array.
52
  $globals = array(
53
+ 'path' => BP_PLUGIN_DIR,
54
  'slug' => BP_BLOGS_SLUG,
55
  'root_slug' => isset( $bp->pages->blogs->slug ) ? $bp->pages->blogs->slug : BP_BLOGS_SLUG,
56
  'has_directory' => is_multisite(), // Non-multisite installs don't need a top-level Sites directory, since there's only one site
75
  'screens',
76
  'classes',
77
  'template',
 
78
  'activity',
79
  'functions',
80
  'buddybar'
90
  /**
91
  * Setup BuddyBar navigation
92
  *
93
+ * @global obj $bp
94
  */
95
  function setup_nav() {
96
  global $bp;
103
  if ( !is_multisite() )
104
  return false;
105
 
 
 
106
  // Add 'Sites' to the main navigation
107
  $main_nav = array(
108
  'name' => sprintf( __( 'Sites <span>%d</span>', 'buddypress' ), bp_blogs_total_blogs_for_user() ),
109
  'slug' => $this->slug,
110
  'position' => 30,
111
  'screen_function' => 'bp_blogs_screen_my_blogs',
112
+ 'default_subnav_slug' => 'my-blogs',
113
  'item_css_id' => $this->id
114
  );
 
 
 
 
 
 
 
 
 
 
 
115
 
116
  // Setup navigation
117
+ parent::setup_nav( $main_nav );
118
  }
119
 
120
  /**
121
+ * Set up the admin bar
122
  *
123
+ * @global obj $bp
124
  */
125
  function setup_admin_bar() {
126
  global $bp;
139
  // Menus for logged in user
140
  if ( is_user_logged_in() ) {
141
 
142
+ $blogs_link = trailingslashit( $bp->loggedin_user->domain . $this->slug );
143
 
144
  // Add the "Blogs" sub menu
145
  $wp_admin_nav[] = array(
165
  /**
166
  * Sets up the title for pages and <title>
167
  *
168
+ * @global obj $bp
169
  */
170
  function setup_title() {
171
  global $bp;
181
  // users avatar and name
182
  } else {
183
  $bp->bp_options_avatar = bp_core_fetch_avatar( array(
184
+ 'item_id' => $bp->displayed_user->id,
185
+ 'type' => 'thumb'
 
186
  ) );
187
+ $bp->bp_options_title = $bp->displayed_user->fullname;
188
  }
189
  }
190
 
191
  parent::setup_title();
192
  }
193
  }
194
+ // Create the blogs component
195
+ $bp->blogs = new BP_Blogs_Component();
196
 
197
+ ?>
 
 
 
 
 
 
bp-blogs/bp-blogs-screens.php CHANGED
@@ -1,12 +1,4 @@
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
 
@@ -43,4 +35,4 @@ function bp_blogs_screen_index() {
43
  }
44
  add_action( 'bp_screens', 'bp_blogs_screen_index', 2 );
45
 
46
- ?>
1
  <?php
 
 
 
 
 
 
 
 
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
35
  }
36
  add_action( 'bp_screens', 'bp_blogs_screen_index', 2 );
37
 
38
+ ?>
bp-blogs/bp-blogs-template.php CHANGED
@@ -1,12 +1,4 @@
1
  <?php
2
-
3
- /**
4
- * BuddyPress Blogs Template Tags
5
- *
6
- * @package BuddyPress
7
- * @subpackage BlogsTemplate
8
- */
9
-
10
  // Exit if accessed directly
11
  if ( !defined( 'ABSPATH' ) ) exit;
12
 
@@ -14,8 +6,8 @@ if ( !defined( 'ABSPATH' ) ) exit;
14
  * Output the blogs component slug
15
  *
16
  * @package BuddyPress
17
- * @subpackage BlogsTemplate
18
- * @since BuddyPress (1.5)
19
  *
20
  * @uses bp_get_blogs_slug()
21
  */
@@ -26,8 +18,8 @@ function bp_blogs_slug() {
26
  * Return the blogs component slug
27
  *
28
  * @package BuddyPress
29
- * @subpackage BlogsTemplate
30
- * @since BuddyPress (1.5)
31
  */
32
  function bp_get_blogs_slug() {
33
  global $bp;
@@ -38,8 +30,8 @@ function bp_blogs_slug() {
38
  * Output the blogs component root slug
39
  *
40
  * @package BuddyPress
41
- * @subpackage BlogsTemplate
42
- * @since BuddyPress (1.5)
43
  *
44
  * @uses bp_get_blogs_root_slug()
45
  */
@@ -50,8 +42,8 @@ function bp_blogs_root_slug() {
50
  * Return the blogs component root slug
51
  *
52
  * @package BuddyPress
53
- * @subpackage BlogsTemplate
54
- * @since BuddyPress (1.5)
55
  */
56
  function bp_get_blogs_root_slug() {
57
  global $bp;
@@ -62,8 +54,8 @@ function bp_blogs_root_slug() {
62
  * Output blog directory permalink
63
  *
64
  * @package BuddyPress
65
- * @subpackage BlogsTemplate
66
- * @since BuddyPress (1.5)
67
  * @uses bp_get_blogs_directory_permalink()
68
  */
69
  function bp_blogs_directory_permalink() {
@@ -73,8 +65,8 @@ function bp_blogs_directory_permalink() {
73
  * Return blog directory permalink
74
  *
75
  * @package BuddyPress
76
- * @subpackage BlogsTemplate
77
- * @since BuddyPress (1.5)
78
  * @uses apply_filters()
79
  * @uses traisingslashit()
80
  * @uses bp_get_root_domain()
@@ -102,9 +94,14 @@ class BP_Blogs_Template {
102
  var $pag_links;
103
  var $total_blog_count;
104
 
105
- function __construct( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg = 'bpage' ) {
 
 
106
 
107
- $this->pag_page = isset( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[$page_arg] ) : $page;
 
 
 
108
  $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
109
 
110
  if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] )
@@ -112,10 +109,10 @@ class BP_Blogs_Template {
112
  else
113
  $this->blogs = bp_blogs_get_blogs( array( 'type' => $type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms ) );
114
 
115
- if ( !$max || $max >= (int) $this->blogs['total'] )
116
- $this->total_blog_count = (int) $this->blogs['total'];
117
  else
118
- $this->total_blog_count = (int) $max;
119
 
120
  $this->blogs = $this->blogs['blogs'];
121
 
@@ -123,18 +120,18 @@ class BP_Blogs_Template {
123
  if ( $max >= count($this->blogs) ) {
124
  $this->blog_count = count( $this->blogs );
125
  } else {
126
- $this->blog_count = (int) $max;
127
  }
128
  } else {
129
  $this->blog_count = count( $this->blogs );
130
  }
131
 
132
- if ( (int) $this->total_blog_count && (int) $this->pag_num ) {
133
  $this->pag_links = paginate_links( array(
134
- 'base' => add_query_arg( $page_arg, '%#%' ),
135
  'format' => '',
136
- 'total' => ceil( (int) $this->total_blog_count / (int) $this->pag_num ),
137
- 'current' => (int) $this->pag_page,
138
  'prev_text' => _x( '&larr;', 'Blog pagination previous text', 'buddypress' ),
139
  'next_text' => _x( '&rarr;', 'Blog pagination next text', 'buddypress' ),
140
  'mid_size' => 1
@@ -177,6 +174,7 @@ class BP_Blogs_Template {
177
  }
178
 
179
  function the_blog() {
 
180
 
181
  $this->in_the_loop = true;
182
  $this->blog = $this->next_blog();
@@ -193,7 +191,7 @@ function bp_rewind_blogs() {
193
  }
194
 
195
  function bp_has_blogs( $args = '' ) {
196
- global $blogs_template;
197
 
198
  /***
199
  * Set the defaults based on the current page. Any of these will be overridden
@@ -204,9 +202,9 @@ function bp_has_blogs( $args = '' ) {
204
  $user_id = 0;
205
  $search_terms = null;
206
 
207
- // User filtering
208
- if ( bp_displayed_user_id() )
209
- $user_id = bp_displayed_user_id();
210
 
211
  $defaults = array(
212
  'type' => $type,
@@ -214,10 +212,8 @@ function bp_has_blogs( $args = '' ) {
214
  'per_page' => 20,
215
  'max' => false,
216
 
217
- 'page_arg' => 'bpage', // See https://buddypress.trac.wordpress.org/ticket/3679
218
-
219
- 'user_id' => $user_id, // Pass a user_id to limit to only blogs this user has higher than subscriber access to
220
- 'search_terms' => $search_terms // Pass search terms to filter on the blog title or description.
221
  );
222
 
223
  $r = wp_parse_args( $args, $defaults );
@@ -231,12 +227,11 @@ function bp_has_blogs( $args = '' ) {
231
  }
232
 
233
  if ( $max ) {
234
- if ( $per_page > $max ) {
235
  $per_page = $max;
236
- }
237
  }
238
 
239
- $blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms, $page_arg );
240
  return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), $blogs_template );
241
  }
242
 
@@ -253,7 +248,7 @@ function bp_the_blog() {
253
  }
254
 
255
  function bp_blogs_pagination_count() {
256
- global $blogs_template;
257
 
258
  $start_num = intval( ( $blogs_template->pag_page - 1 ) * $blogs_template->pag_num ) + 1;
259
  $from_num = bp_core_number_format( $start_num );
@@ -276,7 +271,7 @@ function bp_blog_avatar( $args = '' ) {
276
  echo bp_get_blog_avatar( $args );
277
  }
278
  function bp_get_blog_avatar( $args = '' ) {
279
- global $blogs_template;
280
 
281
  $defaults = array(
282
  'type' => 'full',
@@ -284,7 +279,7 @@ function bp_blog_avatar( $args = '' ) {
284
  'height' => false,
285
  'class' => 'avatar',
286
  'id' => false,
287
- 'alt' => sprintf( __( 'Profile picture of site author %s', 'buddypress' ), bp_core_get_user_displayname( $blogs_template->blog->admin_user_id ) ),
288
  'no_grav' => true
289
  );
290
 
@@ -406,7 +401,8 @@ function bp_blog_signup_enabled() {
406
  }
407
 
408
  function bp_show_blog_signup_form($blogname = '', $blog_title = '', $errors = '') {
409
- global $current_user;
 
410
 
411
  if ( isset($_POST['submit']) ) {
412
  bp_blogs_validate_blog_signup();
@@ -525,7 +521,7 @@ function bp_blogs_subdomain_base() {
525
  */
526
  function bp_blogs_get_subdomain_base() {
527
  global $current_site;
528
-
529
  return apply_filters( 'bp_blogs_subdomain_base', preg_replace( '|^www\.|', '', $current_site->domain ) . $current_site->path );
530
  }
531
 
@@ -585,11 +581,14 @@ function bp_blogs_confirm_blog_signup( $domain, $path, $blog_title, $user_name,
585
  }
586
 
587
  function bp_create_blog_link() {
 
 
588
  if ( bp_is_my_profile() )
589
  echo apply_filters( 'bp_create_blog_link', '<a href="' . bp_get_root_domain() . '/' . bp_get_blogs_root_slug() . '/create/">' . __( 'Create a Site', 'buddypress' ) . '</a>' );
590
  }
591
 
592
  function bp_blogs_blog_tabs() {
 
593
 
594
  // Don't show these tabs on a user's own profile
595
  if ( bp_is_my_profile() )
@@ -608,12 +607,13 @@ function bp_blogs_blog_tabs() {
608
  }
609
 
610
  function bp_directory_blogs_search_form() {
 
611
 
612
  $default_search_value = bp_get_search_default_text();
613
- $search_value = !empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value; ?>
614
 
615
  <form action="" method="get" id="search-blogs-form">
616
- <label><input type="text" name="s" id="blogs_search" placeholder="<?php echo esc_attr( $search_value ) ?>" /></label>
617
  <input type="submit" id="blogs_search_submit" name="blogs_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
618
  </form>
619
 
1
  <?php
 
 
 
 
 
 
 
 
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
6
  * Output the blogs component slug
7
  *
8
  * @package BuddyPress
9
+ * @subpackage Blogs Template
10
+ * @since BuddyPress (r4100)
11
  *
12
  * @uses bp_get_blogs_slug()
13
  */
18
  * Return the blogs component slug
19
  *
20
  * @package BuddyPress
21
+ * @subpackage Blogs Template
22
+ * @since BuddyPress (r4100)
23
  */
24
  function bp_get_blogs_slug() {
25
  global $bp;
30
  * Output the blogs component root slug
31
  *
32
  * @package BuddyPress
33
+ * @subpackage Blogs Template
34
+ * @since BuddyPress (r4100)
35
  *
36
  * @uses bp_get_blogs_root_slug()
37
  */
42
  * Return the blogs component root slug
43
  *
44
  * @package BuddyPress
45
+ * @subpackage Blogs Template
46
+ * @since BuddyPress (r4100)
47
  */
48
  function bp_get_blogs_root_slug() {
49
  global $bp;
54
  * Output blog directory permalink
55
  *
56
  * @package BuddyPress
57
+ * @subpackage Blogs Template
58
+ * @since 1.5
59
  * @uses bp_get_blogs_directory_permalink()
60
  */
61
  function bp_blogs_directory_permalink() {
65
  * Return blog directory permalink
66
  *
67
  * @package BuddyPress
68
+ * @subpackage Blogs Template
69
+ * @since 1.5
70
  * @uses apply_filters()
71
  * @uses traisingslashit()
72
  * @uses bp_get_root_domain()
94
  var $pag_links;
95
  var $total_blog_count;
96
 
97
+ function bp_blogs_template( $type, $page, $per_page, $max, $user_id, $search_terms ) {
98
+ $this->__construct( $type, $page, $per_page, $max, $user_id, $search_terms );
99
+ }
100
 
101
+ function __construct( $type, $page, $per_page, $max, $user_id, $search_terms ) {
102
+ global $bp;
103
+
104
+ $this->pag_page = isset( $_REQUEST['bpage'] ) ? intval( $_REQUEST['bpage'] ) : $page;
105
  $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
106
 
107
  if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] )
109
  else
110
  $this->blogs = bp_blogs_get_blogs( array( 'type' => $type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms ) );
111
 
112
+ if ( !$max || $max >= (int)$this->blogs['total'] )
113
+ $this->total_blog_count = (int)$this->blogs['total'];
114
  else
115
+ $this->total_blog_count = (int)$max;
116
 
117
  $this->blogs = $this->blogs['blogs'];
118
 
120
  if ( $max >= count($this->blogs) ) {
121
  $this->blog_count = count( $this->blogs );
122
  } else {
123
+ $this->blog_count = (int)$max;
124
  }
125
  } else {
126
  $this->blog_count = count( $this->blogs );
127
  }
128
 
129
+ if ( (int)$this->total_blog_count && (int)$this->pag_num ) {
130
  $this->pag_links = paginate_links( array(
131
+ 'base' => add_query_arg( 'bpage', '%#%' ),
132
  'format' => '',
133
+ 'total' => ceil( (int)$this->total_blog_count / (int)$this->pag_num ),
134
+ 'current' => (int)$this->pag_page,
135
  'prev_text' => _x( '&larr;', 'Blog pagination previous text', 'buddypress' ),
136
  'next_text' => _x( '&rarr;', 'Blog pagination next text', 'buddypress' ),
137
  'mid_size' => 1
174
  }
175
 
176
  function the_blog() {
177
+ global $blog;
178
 
179
  $this->in_the_loop = true;
180
  $this->blog = $this->next_blog();
191
  }
192
 
193
  function bp_has_blogs( $args = '' ) {
194
+ global $bp, $blogs_template;
195
 
196
  /***
197
  * Set the defaults based on the current page. Any of these will be overridden
202
  $user_id = 0;
203
  $search_terms = null;
204
 
205
+ /* User filtering */
206
+ if ( !empty( $bp->displayed_user->id ) )
207
+ $user_id = $bp->displayed_user->id;
208
 
209
  $defaults = array(
210
  'type' => $type,
212
  'per_page' => 20,
213
  'max' => false,
214
 
215
+ 'user_id' => $user_id, // Pass a user_id to limit to only blogs this user has higher than subscriber access to
216
+ 'search_terms' => $search_terms // Pass search terms to filter on the blog title or description.
 
 
217
  );
218
 
219
  $r = wp_parse_args( $args, $defaults );
227
  }
228
 
229
  if ( $max ) {
230
+ if ( $per_page > $max )
231
  $per_page = $max;
 
232
  }
233
 
234
+ $blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms );
235
  return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), $blogs_template );
236
  }
237
 
248
  }
249
 
250
  function bp_blogs_pagination_count() {
251
+ global $bp, $blogs_template;
252
 
253
  $start_num = intval( ( $blogs_template->pag_page - 1 ) * $blogs_template->pag_num ) + 1;
254
  $from_num = bp_core_number_format( $start_num );
271
  echo bp_get_blog_avatar( $args );
272
  }
273
  function bp_get_blog_avatar( $args = '' ) {
274
+ global $blogs_template, $bp;
275
 
276
  $defaults = array(
277
  'type' => 'full',
279
  'height' => false,
280
  'class' => 'avatar',
281
  'id' => false,
282
+ 'alt' => __( 'Site authored by %s', 'buddypress' ),
283
  'no_grav' => true
284
  );
285
 
401
  }
402
 
403
  function bp_show_blog_signup_form($blogname = '', $blog_title = '', $errors = '') {
404
+ global $current_user, $current_site;
405
+ global $bp;
406
 
407
  if ( isset($_POST['submit']) ) {
408
  bp_blogs_validate_blog_signup();
521
  */
522
  function bp_blogs_get_subdomain_base() {
523
  global $current_site;
524
+
525
  return apply_filters( 'bp_blogs_subdomain_base', preg_replace( '|^www\.|', '', $current_site->domain ) . $current_site->path );
526
  }
527
 
581
  }
582
 
583
  function bp_create_blog_link() {
584
+ global $bp;
585
+
586
  if ( bp_is_my_profile() )
587
  echo apply_filters( 'bp_create_blog_link', '<a href="' . bp_get_root_domain() . '/' . bp_get_blogs_root_slug() . '/create/">' . __( 'Create a Site', 'buddypress' ) . '</a>' );
588
  }
589
 
590
  function bp_blogs_blog_tabs() {
591
+ global $bp, $groups_template;
592
 
593
  // Don't show these tabs on a user's own profile
594
  if ( bp_is_my_profile() )
607
  }
608
 
609
  function bp_directory_blogs_search_form() {
610
+ global $bp;
611
 
612
  $default_search_value = bp_get_search_default_text();
613
+ $search_value = !empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value; ?>
614
 
615
  <form action="" method="get" id="search-blogs-form">
616
+ <label><input type="text" name="s" id="blogs_search" value="<?php echo esc_attr( $search_value ) ?>" onfocus="if (this.value == '<?php echo $default_search_value ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php echo $default_search_value ?>';}" /></label>
617
  <input type="submit" id="blogs_search_submit" name="blogs_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
618
  </form>
619
 
bp-blogs/bp-blogs-widgets.php CHANGED
@@ -1,31 +1,32 @@
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
- // @todo not use create_function()
 
 
 
 
14
  function bp_blogs_register_widgets() {
15
- global $wpdb;
16
 
17
- if ( bp_is_active( 'activity' ) && (int) $wpdb->blogid == bp_get_root_blog_id() )
18
  add_action('widgets_init', create_function('', 'return register_widget("BP_Blogs_Recent_Posts_Widget");') );
19
  }
20
  add_action( 'bp_register_widgets', 'bp_blogs_register_widgets' );
21
 
22
  class BP_Blogs_Recent_Posts_Widget extends WP_Widget {
23
 
 
 
 
 
24
  function __construct() {
25
  parent::__construct( false, $name = __( 'Recent Networkwide Posts', 'buddypress' ) );
26
  }
27
 
28
  function widget($args, $instance) {
 
29
 
30
  extract( $args );
31
 
1
  <?php
 
 
 
 
 
 
 
 
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
5
+ /***
6
+ * The recent blogs widget is actually just the activity feed filtered on "new_blog_post".
7
+ * Why not make some of your own widgets using a filtered activity stream?
8
+ */
9
+
10
  function bp_blogs_register_widgets() {
11
+ global $wpdb, $bp;
12
 
13
+ if ( bp_is_active( 'activity' ) && (int)$wpdb->blogid == bp_get_root_blog_id() )
14
  add_action('widgets_init', create_function('', 'return register_widget("BP_Blogs_Recent_Posts_Widget");') );
15
  }
16
  add_action( 'bp_register_widgets', 'bp_blogs_register_widgets' );
17
 
18
  class BP_Blogs_Recent_Posts_Widget extends WP_Widget {
19
 
20
+ function bp_blogs_recent_posts_widget() {
21
+ $this->__construct();
22
+ }
23
+
24
  function __construct() {
25
  parent::__construct( false, $name = __( 'Recent Networkwide Posts', 'buddypress' ) );
26
  }
27
 
28
  function widget($args, $instance) {
29
+ global $bp;
30
 
31
  extract( $args );
32
 
bp-core/admin/bp-core-admin.php ADDED
@@ -0,0 +1,637 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Exit if accessed directly
3
+ if ( !defined( 'ABSPATH' ) ) exit;
4
+
5
+ /**
6
+ * Add an extra update message to the update plugin notification.
7
+ *
8
+ * @package BuddyPress Core
9
+ */
10
+ function bp_core_update_message() {
11
+ echo '<p style="color: red; margin: 3px 0 0 0; border-top: 1px solid #ddd; padding-top: 3px">' . __( 'IMPORTANT: <a href="http://codex.buddypress.org/buddypress-site-administration/upgrading-buddypress/">Read this before attempting to update BuddyPress</a>', 'buddypress' ) . '</p>';
12
+ }
13
+ add_action( 'in_plugin_update_message-buddypress/bp-loader.php', 'bp_core_update_message' );
14
+
15
+ /**
16
+ * Output the tabs in the admin area
17
+ *
18
+ * @since 1.5
19
+ * @param string $active_tab Name of the tab that is active
20
+ */
21
+ function bp_core_admin_tabs( $active_tab = '' ) {
22
+
23
+ // Declare local variables
24
+ $tabs_html = '';
25
+ $idle_class = 'nav-tab';
26
+ $active_class = 'nav-tab nav-tab-active';
27
+
28
+ // Setup core admin tabs
29
+ $tabs = array(
30
+ '0' => array(
31
+ 'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bp-general-settings' ), 'admin.php' ) ),
32
+ 'name' => __( 'Components', 'buddypress' )
33
+ ),
34
+ '1' => array(
35
+ 'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) ),
36
+ 'name' => __( 'Pages', 'buddypress' )
37
+ ),
38
+ '2' => array(
39
+ 'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bp-settings' ), 'admin.php' ) ),
40
+ 'name' => __( 'Settings', 'buddypress' )
41
+ )
42
+ );
43
+
44
+ // If forums component is active, add additional tab
45
+ if ( bp_is_active( 'forums' ) ) {
46
+ $tabs['3'] = array(
47
+ 'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bb-forums-setup' ), 'admin.php' ) ),
48
+ 'name' => __( 'Forums', 'buddypress' )
49
+ );
50
+ }
51
+
52
+ // Loop through tabs and build navigation
53
+ foreach( $tabs as $tab_id => $tab_data ) {
54
+ $is_current = (bool) ( $tab_data['name'] == $active_tab );
55
+ $tab_class = $is_current ? $active_class : $idle_class;
56
+ $tabs_html .= '<a href="' . $tab_data['href'] . '" class="' . $tab_class . '">' . $tab_data['name'] . '</a>';
57
+ }
58
+
59
+ // Output the tabs
60
+ echo $tabs_html;
61
+
62
+ // Do other fun things
63
+ do_action( 'bp_admin_tabs' );
64
+ }
65
+
66
+ /**
67
+ * Renders the Settings admin panel.
68
+ *
69
+ * @package BuddyPress Core
70
+ * @since {@internal Unknown}}
71
+ */
72
+ function bp_core_admin_settings() {
73
+ global $wpdb, $bp;
74
+
75
+ $ud = get_userdata( $bp->loggedin_user->id );
76
+
77
+ if ( isset( $_POST['bp-admin-submit'] ) && isset( $_POST['bp-admin'] ) ) {
78
+ if ( !check_admin_referer('bp-admin') )
79
+ return false;
80
+
81
+ // Settings form submitted, now save the settings.
82
+ foreach ( (array)$_POST['bp-admin'] as $key => $value )
83
+ bp_update_option( $key, $value );
84
+
85
+ } ?>
86
+
87
+ <div class="wrap">
88
+
89
+ <?php screen_icon( 'buddypress' ); ?>
90
+
91
+ <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( __( 'Settings', 'buddypress' ) ); ?></h2>
92
+
93
+ <?php if ( isset( $_POST['bp-admin'] ) ) : ?>
94
+
95
+ <div id="message" class="updated fade">
96
+ <p><?php _e( 'Settings Saved', 'buddypress' ); ?></p>
97
+ </div>
98
+
99
+ <?php endif; ?>
100
+
101
+ <form action="" method="post" id="bp-admin-form">
102
+
103
+ <table class="form-table">
104
+ <tbody>
105
+
106
+ <?php if ( bp_is_active( 'xprofile' ) ) : ?>
107
+
108
+ <tr>
109
+ <th scope="row"><?php _e( 'Disable BuddyPress to WordPress profile syncing?', 'buddypress' ) ?></th>
110
+ <td>
111
+ <input type="radio" name="bp-admin[bp-disable-profile-sync]"<?php if ( (int)bp_get_option( 'bp-disable-profile-sync' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-profile-sync" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
112
+ <input type="radio" name="bp-admin[bp-disable-profile-sync]"<?php if ( !(int)bp_get_option( 'bp-disable-profile-sync' ) || '' == bp_get_option( 'bp-disable-profile-sync' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-profile-sync" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
113
+ </td>
114
+ </tr>
115
+
116
+ <?php endif; ?>
117
+
118
+ <tr>
119
+ <th scope="row"><?php _e( 'Hide admin bar for logged out users?', 'buddypress' ) ?></th>
120
+ <td>
121
+ <input type="radio" name="bp-admin[hide-loggedout-adminbar]"<?php if ( (int)bp_get_option( 'hide-loggedout-adminbar' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-hide-loggedout-adminbar-yes" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
122
+ <input type="radio" name="bp-admin[hide-loggedout-adminbar]"<?php if ( !(int)bp_get_option( 'hide-loggedout-adminbar' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-hide-loggedout-adminbar-no" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
123
+ </td>
124
+ </tr>
125
+
126
+ <tr>
127
+ <th scope="row"><?php _e( 'Disable avatar uploads? (Gravatars will still work)', 'buddypress' ) ?></th>
128
+ <td>
129
+ <input type="radio" name="bp-admin[bp-disable-avatar-uploads]"<?php if ( (int)bp_get_option( 'bp-disable-avatar-uploads' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-disable-avatar-uploads-yes" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
130
+ <input type="radio" name="bp-admin[bp-disable-avatar-uploads]"<?php if ( !(int)bp_get_option( 'bp-disable-avatar-uploads' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-disable-avatar-uploads-no" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
131
+ </td>
132
+ </tr>
133
+
134
+ <tr>
135
+ <th scope="row"><?php _e( 'Disable user account deletion?', 'buddypress' ) ?></th>
136
+ <td>
137
+ <input type="radio" name="bp-admin[bp-disable-account-deletion]"<?php if ( (int)bp_get_option( 'bp-disable-account-deletion' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-account-deletion" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
138
+ <input type="radio" name="bp-admin[bp-disable-account-deletion]"<?php if ( !(int)bp_get_option( 'bp-disable-account-deletion' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-account-deletion" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
139
+ </td>
140
+ </tr>
141
+
142
+ <?php if ( bp_is_active( 'activity' ) ) : ?>
143
+
144
+ <tr>
145
+ <th scope="row"><?php _e( 'Disable activity stream commenting on blog and forum posts?', 'buddypress' ) ?></th>
146
+ <td>
147
+ <input type="radio" name="bp-admin[bp-disable-blogforum-comments]"<?php if ( (int)bp_get_option( 'bp-disable-blogforum-comments' ) || false === bp_get_option( 'bp-disable-blogforum-comments' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-blogforum-comments" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
148
+ <input type="radio" name="bp-admin[bp-disable-blogforum-comments]"<?php if ( !(int)bp_get_option( 'bp-disable-blogforum-comments' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-blogforum-comments" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
149
+ </td>
150
+ </tr>
151
+
152
+ <?php endif; ?>
153
+
154
+ <?php if ( bp_is_active( 'groups' ) ) : ?>
155
+
156
+ <tr>
157
+ <th scope="row"><?php _e( 'Restrict group creation to Site Admins?', 'buddypress' ) ?></th>
158
+ <td>
159
+ <input type="radio" name="bp-admin[bp_restrict_group_creation]"<?php checked( '1', bp_get_option( 'bp_restrict_group_creation', '0' ) ); ?>id="bp-restrict-group-creation" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
160
+ <input type="radio" name="bp-admin[bp_restrict_group_creation]"<?php checked( '0', bp_get_option( 'bp_restrict_group_creation', '0' ) ); ?>id="bp-restrict-group-creation" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
161
+ </td>
162
+ </tr>
163
+
164
+ <?php endif; ?>
165
+
166
+ <?php do_action( 'bp_core_admin_screen_fields' ) ?>
167
+
168
+ </tbody>
169
+ </table>
170
+
171
+ <?php do_action( 'bp_core_admin_screen' ); ?>
172
+
173
+ <p class="submit">
174
+ <input class="button-primary" type="submit" name="bp-admin-submit" id="bp-admin-submit" value="<?php _e( 'Save Settings', 'buddypress' ); ?>" />
175
+ </p>
176
+
177
+ <?php wp_nonce_field( 'bp-admin' ); ?>
178
+
179
+ </form>
180
+
181
+ </div>
182
+
183
+ <?php
184
+ }
185
+
186
+ function bp_core_admin_component_setup_handler() {
187
+ global $wpdb, $bp;
188
+
189
+ if ( isset( $_POST['bp-admin-component-submit'] ) ) {
190
+ if ( !check_admin_referer('bp-admin-component-setup') )
191
+ return false;
192
+
193
+ // Settings form submitted, now save the settings. First, set active components
194
+ if ( isset( $_POST['bp_components'] ) ) {
195
+ // Save settings and upgrade schema
196
+ require( BP_PLUGIN_DIR . '/bp-core/admin/bp-core-update.php' );
197
+ $bp->active_components = stripslashes_deep( $_POST['bp_components'] );
198
+ bp_core_install( $bp->active_components );
199
+
200
+ bp_update_option( 'bp-active-components', $bp->active_components );
201
+ }
202
+
203
+ $base_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-general-settings', 'updated' => 'true' ), 'admin.php' ) );
204
+
205
+ wp_redirect( $base_url );
206
+ }
207
+ }
208
+ add_action( 'admin_init', 'bp_core_admin_component_setup_handler' );
209
+
210
+ function bp_core_admin_pages_setup_handler() {
211
+ global $wpdb, $bp;
212
+
213
+ if ( isset( $_POST['bp-admin-pages-submit'] ) || isset( $_POST['bp-admin-pages-single'] ) ) {
214
+ if ( !check_admin_referer( 'bp-admin-pages-setup' ) )
215
+ return false;
216
+
217
+ // Then, update the directory pages
218
+ if ( isset( $_POST['bp_pages'] ) ) {
219
+
220
+ $directory_pages = array();
221
+
222
+ foreach ( (array)$_POST['bp_pages'] as $key => $value ) {
223
+ if ( !empty( $value ) ) {
224
+ $directory_pages[$key] = (int)$value;
225
+ }
226
+ }
227
+ bp_core_update_directory_page_ids( $directory_pages );
228
+ }
229
+
230
+ $base_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings', 'updated' => 'true' ), 'admin.php' ) );
231
+
232
+ wp_redirect( $base_url );
233
+ }
234
+ }
235
+ add_action( 'admin_init', 'bp_core_admin_pages_setup_handler' );
236
+
237
+ /**
238
+ * Renders the Component Setup admin panel.
239
+ *
240
+ * @package BuddyPress Core
241
+ * @since {@internal Unknown}}
242
+ * @uses bp_core_admin_component_options()
243
+ */
244
+ function bp_core_admin_component_setup() {
245
+ ?>
246
+
247
+ <div class="wrap">
248
+
249
+ <?php screen_icon( 'buddypress'); ?>
250
+
251
+ <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( __( 'Components', 'buddypress' ) ); ?></h2>
252
+
253
+ <?php if ( isset( $_GET['updated'] ) && 'true' === $_GET['updated'] ) : ?>
254
+
255
+ <div id="message" class="updated fade">
256
+
257
+ <p><?php _e( 'Settings Saved', 'buddypress' ); ?></p>
258
+
259
+ </div>
260
+
261
+ <?php endif; ?>
262
+
263
+ <form action="" method="post" id="bp-admin-component-form">
264
+
265
+ <?php bp_core_admin_component_options(); ?>
266
+
267
+ <p class="submit clear">
268
+ <input class="button-primary" type="submit" name="bp-admin-component-submit" id="bp-admin-component-submit" value="<?php _e( 'Save Settings', 'buddypress' ) ?>"/>
269
+ </p>
270
+
271
+ <?php wp_nonce_field( 'bp-admin-component-setup' ); ?>
272
+
273
+ </form>
274
+ </div>
275
+
276
+ <?php
277
+ }
278
+
279
+ /**
280
+ * Renders the Component Setup admin panel.
281
+ *
282
+ * @package BuddyPress Core
283
+ * @since {@internal Unknown}}
284
+ * @uses bp_core_admin_component_options()
285
+ */
286
+ function bp_core_admin_page_setup() {
287
+ ?>
288
+
289
+ <div class="wrap">
290
+
291
+ <?php screen_icon( 'buddypress'); ?>
292
+
293
+ <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( __( 'Pages', 'buddypress' ) ); ?></h2>
294
+
295
+ <?php if ( isset( $_GET['updated'] ) && 'true' === $_GET['updated'] ) : ?>
296
+
297
+ <div id="message" class="updated fade">
298
+
299
+ <p><?php _e( 'Settings Saved', 'buddypress' ); ?></p>
300
+
301
+ </div>
302
+
303
+ <?php endif; ?>
304
+
305
+ <form action="" method="post" id="bp-admin-page-form">
306
+
307
+ <?php bp_core_admin_page_options(); ?>
308
+
309
+ <p class="submit clear">
310
+ <input class="button-primary" type="submit" name="bp-admin-pages-submit" id="bp-admin-pages-submit" value="<?php _e( 'Save All', 'buddypress' ) ?>"/>
311
+ </p>
312
+
313
+ <?php wp_nonce_field( 'bp-admin-pages-setup' ); ?>
314
+
315
+ </form>
316
+ </div>
317
+
318
+ <?php
319
+ }
320
+
321
+ /**
322
+ * Creates reusable markup for component setup on the Components and Pages dashboard panel.
323
+ *
324
+ * This markup has been abstracted so that it can be used both during the setup wizard as well as
325
+ * when BP has been fully installed.
326
+ *
327
+ * @package BuddyPress Core
328
+ * @since 1.5
329
+ */
330
+ function bp_core_admin_component_options() {
331
+ global $bp_wizard;
332
+
333
+ // Load core functions, if needed
334
+ if ( !function_exists( 'bp_get_option' ) )
335
+ require( BP_PLUGIN_DIR . '/bp-core/bp-core-functions.php' );
336
+
337
+ $active_components = apply_filters( 'bp_active_components', bp_get_option( 'bp-active-components' ) );
338
+
339
+ // An array of strings looped over to create component setup markup
340
+ $optional_components = array(
341
+ 'xprofile' => array(
342
+ 'title' => __( 'Extended Profiles', 'buddypress' ),
343
+ 'description' => __( 'Customize your community with fully editable profile fields that allow your users to describe themselves.', 'buddypress' )
344
+ ),
345
+ 'settings' => array(
346
+ 'title' => __( 'Account Settings', 'buddypress' ),
347
+ 'description' => __( 'Allow your users to modify their account and notification settings directly from within their profiles.', 'buddypress' )
348
+ ),
349
+ 'friends' => array(
350
+ 'title' => __( 'Friend Connections', 'buddypress' ),
351
+ 'description' => __( 'Let your users make connections so they can track the activity of others and focus on the people they care about the most.', 'buddypress' )
352
+ ),
353
+ 'messages' => array(
354
+ 'title' => __( 'Private Messaging', 'buddypress' ),
355
+ 'description' => __( 'Allow your users to talk to each other directly and in private. Not just limited to one-on-one discussions, messages can be sent between any number of members.', 'buddypress' )
356
+ ),
357
+ 'activity' => array(
358
+ 'title' => __( 'Activity Streams', 'buddypress' ),
359
+ 'description' => __( 'Global, personal, and group activity streams with threaded commenting, direct posting, favoriting and @mentions, all with full RSS feed and email notification support.', 'buddypress' )
360
+ ),
361
+ 'groups' => array(
362
+ 'title' => __( 'User Groups', 'buddypress' ),
363
+ 'description' => __( 'Groups allow your users to organize themselves into specific public, private or hidden sections with separate activity streams and member listings.', 'buddypress' )
364
+ ),
365
+ 'forums' => array(
366
+ 'title' => __( 'Discussion Forums', 'buddypress' ),
367
+ 'description' => __( 'Full-powered discussion forums built directly into groups allow for more conventional in-depth conversations. NOTE: This will require an extra (but easy) setup step.', 'buddypress' )
368
+ ),
369
+ 'blogs' => array(
370
+ 'title' => __( 'Site Tracking', 'buddypress' ),
371
+ 'description' => __( 'Make BuddyPress aware of new posts and new comments from your site.', 'buddypress' )
372
+ )
373
+ );
374
+
375
+ if ( is_multisite() )
376
+ $optional_components['blogs']['description'] = __( 'Make BuddyPress aware of new sites, new posts and new comments from across your entire network.', 'buddypress' );
377
+
378
+ // If this is an upgrade from before BuddyPress 1.5, we'll have to convert deactivated
379
+ // components into activated ones
380
+ if ( empty( $active_components ) ) {
381
+ $deactivated_components = bp_get_option( 'bp-deactivated-components' );
382
+
383
+ // Trim off namespace and filename
384
+ $trimmed = array();
385
+ foreach ( (array) $deactivated_components as $component => $value ) {
386
+ $trimmed[] = str_replace( '.php', '', str_replace( 'bp-', '', $component ) );
387
+ }
388
+
389
+ // Loop through the optional components to create an active component array
390
+ foreach ( (array) $optional_components as $ocomponent => $ovalue ) {
391
+ if ( !in_array( $ocomponent, $trimmed ) ) {
392
+ $active_components[$ocomponent] = 1;
393
+ }
394
+ }
395
+ }
396
+
397
+ // Required components
398
+ $required_components = array(
399
+ 'core' => array(
400
+ 'title' => __( 'BuddyPress Core', 'buddypress' ),
401
+ 'description' => __( 'It&#8216;s what makes <del>time travel</del> BuddyPress possible!', 'buddypress' )
402
+ ),
403
+ 'members' => array(
404
+ 'title' => __( 'Community Members', 'buddypress' ),
405
+ 'description' => __( 'Everything in a BuddyPress community revolves around its members.', 'buddypress' )
406
+ ),
407
+ );
408
+
409
+ // On new install, set all components to be active by default
410
+ if ( !empty( $bp_wizard ) && 'install' == $bp_wizard->setup_type && empty( $active_components ) )
411
+ $active_components = $optional_components;
412
+
413
+ ?>
414
+
415
+ <?php /* The setup wizard uses different, more descriptive text here */ ?>
416
+ <?php if ( empty( $bp_wizard ) ) : ?>
417
+
418
+ <h3><?php _e( 'Available Components', 'buddypress' ); ?></h3>
419
+
420
+ <p><?php _e( 'Each component has a unique purpose, and your community may not need each one.', 'buddypress' ); ?></p>
421
+
422
+ <?php endif ?>
423
+
424
+ <table class="form-table">
425
+ <tbody>
426
+
427
+ <?php foreach ( $optional_components as $name => $labels ) : ?>
428
+
429
+ <tr valign="top">
430
+ <th scope="row"><?php echo esc_html( $labels['title'] ); ?></th>
431
+
432
+ <td>
433
+ <label for="bp_components[<?php echo esc_attr( $name ); ?>]">
434
+ <input type="checkbox" id="bp_components[<?php echo esc_attr( $name ); ?>]" name="bp_components[<?php echo esc_attr( $name ); ?>]" value="1"<?php checked( isset( $active_components[esc_attr( $name )] ) ); ?> />
435
+
436
+ <?php echo $labels['description']; ?>
437
+
438
+ </label>
439
+
440
+ </td>
441
+ </tr>
442
+
443
+ <?php endforeach ?>
444
+
445
+ </tbody>
446
+ </table>
447
+
448
+ <?php if ( empty( $bp_wizard ) ) : ?>
449
+
450
+ <h3><?php _e( 'Required Components', 'buddypress' ); ?></h3>
451
+
452
+ <p><?php _e( 'The following components are required by BuddyPress and cannot be turned off.', 'buddypress' ); ?></p>
453
+
454
+ <?php endif ?>
455
+
456
+ <table class="form-table">
457
+ <tbody>
458
+
459
+ <?php foreach ( $required_components as $name => $labels ) : ?>
460
+
461
+ <tr valign="top">
462
+ <th scope="row"><?php echo esc_html( $labels['title'] ); ?></th>
463
+
464
+ <td>
465
+ <label for="bp_components[<?php echo esc_attr( $name ); ?>]">
466
+ <input type="checkbox" id="bp_components[<?php echo esc_attr( $name ); ?>]" name="" disabled="disabled" value="1"<?php checked( true ); ?> />
467
+
468
+ <?php echo $labels['description']; ?>
469
+
470
+ </label>
471
+
472
+ </td>
473
+ </tr>
474
+
475
+ <?php endforeach ?>
476
+
477
+ </tbody>
478
+ </table>
479
+
480
+ <input type="hidden" name="bp_components[members]" value="1" />
481
+
482
+ <?php
483
+ }
484
+
485
+ /**
486
+ * Creates reusable markup for page setup on the Components and Pages dashboard panel.
487
+ *
488
+ * This markup has been abstracted so that it can be used both during the setup wizard as well as
489
+ * when BP has been fully installed.
490
+ *
491
+ * @package BuddyPress Core
492
+ * @since 1.5
493
+ */
494
+ function bp_core_admin_page_options() {
495
+ global $bp;
496
+
497
+ // Get the existing WP pages
498
+ $existing_pages = bp_core_get_directory_page_ids();
499
+
500
+ // Set up an array of components (along with component names) that have
501
+ // directory pages.
502
+ $directory_pages = array();
503
+
504
+ foreach( $bp->loaded_components as $component_slug => $component_id ) {
505
+
506
+ // Only components that need directories should be listed here
507
+ if ( isset( $bp->{$component_id} ) && !empty( $bp->{$component_id}->has_directory ) ) {
508
+
509
+ // component->name was introduced in BP 1.5, so we must provide a fallback
510
+ $component_name = !empty( $bp->{$component_id}->name ) ? $bp->{$component_id}->name : ucwords( $component_id );
511
+
512
+ $directory_pages[$component_id] = $component_name;
513
+ }
514
+ }
515
+
516
+ $directory_pages = apply_filters( 'bp_directory_pages', $directory_pages );
517
+
518
+ ?>
519
+
520
+ <h3><?php _e( 'Directories', 'buddypress' ); ?></h3>
521
+
522
+ <p><?php _e( 'Associate a WordPress Page with each BuddyPress component directory.', 'buddypress' ); ?></p>
523
+
524
+ <table class="form-table">
525
+ <tbody>
526
+
527
+ <?php foreach ( $directory_pages as $name => $label ) : ?>
528
+ <?php $disabled = !bp_is_active( $name ) ? ' disabled="disabled"' : ''; ?>
529
+
530
+ <tr valign="top">
531
+ <th scope="row">
532
+ <label for="bp_pages[<?php echo esc_attr( $name ) ?>]"><?php echo esc_html( $label ) ?></label>
533
+ </th>
534
+
535
+ <td>
536
+ <?php if ( !bp_is_root_blog() )
537
+ switch_to_blog( bp_get_root_blog_id() ) ?>
538
+
539
+ <?php echo wp_dropdown_pages( array(
540
+ 'name' => 'bp_pages[' . esc_attr( $name ) . ']',
541
+ 'echo' => false,
542
+ 'show_option_none' => __( '- None -', 'buddypress' ),
543
+ 'selected' => !empty( $existing_pages[$name] ) ? $existing_pages[$name] : false
544
+ ) ); ?>
545
+
546
+ <a href="<?php echo admin_url( add_query_arg( array( 'post_type' => 'page' ), 'post-new.php' ) ); ?>" class="button-secondary"><?php _e( 'New Page' ); ?></a>
547
+ <input class="button-primary" type="submit" name="bp-admin-pages-single" value="<?php _e( 'Save', 'buddypress' ) ?>" />
548
+
549
+ <?php if ( !empty( $existing_pages[$name] ) ) : ?>
550
+
551
+ <a href="<?php echo get_permalink( $existing_pages[$name] ); ?>" class="button-secondary" target="_bp"><?php _e( 'View' ); ?></a>
552
+
553
+ <?php endif; ?>
554
+
555
+ <?php if ( !bp_is_root_blog() )
556
+ restore_current_blog() ?>
557
+
558
+ </td>
559
+ </tr>
560
+
561
+
562
+ <?php endforeach ?>
563
+
564
+ <?php do_action( 'bp_active_external_directories' ); ?>
565
+
566
+ </tbody>
567
+ </table>
568
+
569
+ <?php
570
+
571
+ // Static pages
572
+ $static_pages = array(
573
+ 'register' => __( 'Register', 'buddypress' ),
574
+ 'activate' => __( 'Activate', 'buddypress' ),
575
+ ); ?>
576
+
577
+ <h3><?php _e( 'Registration', 'buddypress' ); ?></h3>
578
+
579
+ <p><?php _e( 'Associate WordPress Pages with the following BuddyPress Registration pages.', 'buddypress' ); ?></p>
580
+
581
+ <table class="form-table">
582
+ <tbody>
583
+
584
+ <?php foreach ( $static_pages as $name => $label ) : ?>
585
+
586
+ <tr valign="top">
587
+ <th scope="row">
588
+ <label for="bp_pages[<?php echo esc_attr( $name ) ?>]"><?php echo esc_html( $label ) ?></label>
589
+ </th>
590
+
591
+ <td>
592
+ <?php echo wp_dropdown_pages( array(
593
+ 'name' => 'bp_pages[' . esc_attr( $name ) . ']',
594
+ 'echo' => false,
595
+ 'show_option_none' => __( '- None -', 'buddypress' ),
596
+ 'selected' => !empty( $existing_pages[$name] ) ? $existing_pages[$name] : false
597
+ ) ) ?>
598
+
599
+ <a href="<?php echo admin_url( add_query_arg( array( 'post_type' => 'page' ), 'post-new.php' ) ); ?>" class="button-secondary"><?php _e( 'New Page' ); ?></a>
600
+ <input class="button-primary" type="submit" name="bp-admin-pages-single" value="<?php _e( 'Save', 'buddypress' ) ?>" />
601
+
602
+ <?php if ( !empty( $existing_pages[$name] ) ) : ?>
603
+
604
+ <a href="<?php echo get_permalink( $existing_pages[$name] ); ?>" class="button-secondary" target="_bp"><?php _e( 'View' ); ?></a>
605
+
606
+ <?php endif; ?>
607
+
608
+ </td>
609
+ </tr>
610
+
611
+ <?php endforeach ?>
612
+
613
+ <?php do_action( 'bp_active_external_pages' ); ?>
614
+
615
+ </tbody>
616
+ </table>
617
+
618
+ <?php
619
+ }
620
+
621
+ /**
622
+ * Loads admin panel styles and scripts.
623
+ *
624
+ * @package BuddyPress Core
625
+ * @since {@internal Unknown}}
626
+ */
627
+ function bp_core_add_admin_menu_styles() {
628
+ if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG )
629
+ wp_enqueue_style( 'bp-admin-css', apply_filters( 'bp_core_admin_css', BP_PLUGIN_URL . '/bp-core/css/admin.dev.css' ), array(), '20110723' );
630
+ else
631
+ wp_enqueue_style( 'bp-admin-css', apply_filters( 'bp_core_admin_css', BP_PLUGIN_URL . '/bp-core/css/admin.css' ), array(), '20110723' );
632
+
633
+ wp_enqueue_script( 'thickbox' );
634
+ wp_enqueue_style( 'thickbox' );
635
+ }
636
+
637
+ ?>
bp-core/admin/bp-core-components.php DELETED
@@ -1,300 +0,0 @@
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">
28
-
29
- <?php bp_core_admin_components_options(); ?>
30
-
31
- <p class="submit clear">
32
- <input class="button-primary" type="submit" name="bp-admin-component-submit" id="bp-admin-component-submit" value="<?php _e( 'Save Settings', 'buddypress' ) ?>"/>
33
- </p>
34
-
35
- <?php wp_nonce_field( 'bp-admin-component-setup' ); ?>
36
-
37
- </form>
38
- </div>
39
-
40
- <?php
41
- }
42
-
43
- /**
44
- * Creates reusable markup for component setup on the Components and Pages dashboard panel.
45
- *
46
- * This markup has been abstracted so that it can be used both during the setup wizard as well as
47
- * when BP has been fully installed.
48
- *
49
- * @package BuddyPress
50
- * @since BuddyPress (1.6)
51
- * @todo Use settings API
52
- */
53
- function bp_core_admin_components_options() {
54
-
55
- // Load core functions, if needed
56
- if ( !function_exists( 'bp_get_option' ) )
57
- require( BP_PLUGIN_DIR . '/bp-core/bp-core-functions.php' );
58
-
59
- // Declare local variables
60
- $deactivated_components = array();
61
- $required_components = array();
62
- $active_components = apply_filters( 'bp_active_components', bp_get_option( 'bp-active-components' ) );
63
-
64
- // Optional core components
65
- $optional_components = array(
66
- 'xprofile' => array(
67
- 'title' => __( 'Extended Profiles', 'buddypress' ),
68
- 'description' => __( 'Customize your community with fully editable profile fields that allow your users to describe themselves.', 'buddypress' )
69
- ),
70
- 'settings' => array(
71
- 'title' => __( 'Account Settings', 'buddypress' ),
72
- 'description' => __( 'Allow your users to modify their account and notification settings directly from within their profiles.', 'buddypress' )
73
- ),
74
- 'friends' => array(
75
- 'title' => __( 'Friend Connections', 'buddypress' ),
76
- 'description' => __( 'Let your users make connections so they can track the activity of others and focus on the people they care about the most.', 'buddypress' )
77
- ),
78
- 'messages' => array(
79
- 'title' => __( 'Private Messaging', 'buddypress' ),
80
- 'description' => __( 'Allow your users to talk to each other directly and in private. Not just limited to one-on-one discussions, messages can be sent between any number of members.', 'buddypress' )
81
- ),
82
- 'activity' => array(
83
- 'title' => __( 'Activity Streams', 'buddypress' ),
84
- 'description' => __( 'Global, personal, and group activity streams with threaded commenting, direct posting, favoriting and @mentions, all with full RSS feed and email notification support.', 'buddypress' )
85
- ),
86
- 'groups' => array(
87
- 'title' => __( 'User Groups', 'buddypress' ),
88
- 'description' => __( 'Groups allow your users to organize themselves into specific public, private or hidden sections with separate activity streams and member listings.', 'buddypress' )
89
- ),
90
- 'forums' => array(
91
- 'title' => __( 'Discussion Forums', 'buddypress' ),
92
- 'description' => __( 'Site-wide and Group forums allow for focused, bulletin-board style conversations. Powered by bbPress.', 'buddypress' )
93
- ),
94
- 'blogs' => array(
95
- 'title' => __( 'Site Tracking', 'buddypress' ),
96
- 'description' => __( 'Record activity for new posts and comments from your site.', 'buddypress' )
97
- )
98
- );
99
-
100
- // Add blogs tracking if multisite
101
- if ( is_multisite() ) {
102
- $optional_components['blogs']['description'] = __( 'Record activity for new sites, posts, and comments across your network.', 'buddypress' );
103
- }
104
-
105
- // Required components
106
- $required_components = array(
107
- 'core' => array(
108
- 'title' => __( 'BuddyPress Core', 'buddypress' ),
109
- 'description' => __( 'It&#8216;s what makes <del>time travel</del> BuddyPress possible!', 'buddypress' )
110
- ),
111
- 'members' => array(
112
- 'title' => __( 'Community Members', 'buddypress' ),
113
- 'description' => __( 'Everything in a BuddyPress community revolves around its members.', 'buddypress' )
114
- ),
115
- );
116
-
117
- // Merge optional and required together
118
- $all_components = $optional_components + $required_components;
119
-
120
- // If this is an upgrade from before BuddyPress 1.5, we'll have to convert
121
- // deactivated components into activated ones.
122
- if ( empty( $active_components ) ) {
123
- $deactivated_components = bp_get_option( 'bp-deactivated-components' );
124
- if ( !empty( $deactivated_components ) ) {
125
-
126
- // Trim off namespace and filename
127
- $trimmed = array();
128
- foreach ( (array) $deactivated_components as $component => $value ) {
129
- $trimmed[] = str_replace( '.php', '', str_replace( 'bp-', '', $component ) );
130
- }
131
-
132
- // Loop through the optional components to create an active component array
133
- foreach ( (array) $optional_components as $ocomponent => $ovalue ) {
134
- if ( !in_array( $ocomponent, $trimmed ) ) {
135
- $active_components[$ocomponent] = 1;
136
- }
137
- }
138
- }
139
- }
140
-
141
- // On new install, set all components to be active by default
142
- if ( empty( $active_components ) && ( bp_get_maintenance_mode() == 'install' ) ) {
143
- $active_components = $optional_components;
144
- }
145
-
146
- // Core component is always active
147
- $active_components['core'] = $all_components['core'];
148
- $inactive_components = array_diff( array_keys( $all_components ) , array_keys( $active_components ) );
149
-
150
- /** Display ***************************************************************/
151
-
152
- // Get the total count of all plugins
153
- $all_count = count( $all_components );
154
- $page = bp_core_do_network_admin() ? 'settings.php' : 'options-general.php';
155
- $action = !empty( $_GET['action'] ) ? $_GET['action'] : 'all';
156
-
157
- switch( $action ) {
158
- case 'all' :
159
- $current_components = $all_components;
160
- break;
161
- case 'active' :
162
- foreach ( array_keys( $active_components ) as $component ) {
163
- $current_components[$component] = $all_components[$component];
164
- }
165
- break;
166
- case 'inactive' :
167
- foreach ( $inactive_components as $component ) {
168
- $current_components[$component] = $all_components[$component];
169
- }
170
- break;
171
- case 'mustuse' :
172
- $current_components = $required_components;
173
- break;
174
- }
175
-
176
- // The setup wizard uses different, more descriptive text
177
- if ( bp_get_maintenance_mode() ) : ?>
178
-
179
- <h3><?php _e( 'Available Components', 'buddypress' ); ?></h3>
180
-
181
- <p><?php _e( 'Each component has a unique purpose, and your community may not need each one.', 'buddypress' ); ?></p>
182
-
183
- <?php endif ?>
184
-
185
- <ul class="subsubsub">
186
- <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>
187
- <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>
188
- <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>
189
- <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>
190
- </ul>
191
-
192
- <table class="widefat fixed plugins" cellspacing="0">
193
- <thead>
194
- <tr>
195
- <th scope="col" id="cb" class="manage-column column-cb check-column">&nbsp;</th>
196
- <th scope="col" id="name" class="manage-column column-name" style="width: 190px;"><?php _e( 'Component', 'buddypress' ); ?></th>
197
- <th scope="col" id="description" class="manage-column column-description"><?php _e( 'Description', 'buddypress' ); ?></th>
198
- </tr>
199
- </thead>
200
-
201
- <tfoot>
202
- <tr>
203
- <th scope="col" class="manage-column column-cb check-column">&nbsp;</th>
204
- <th scope="col" class="manage-column column-name" style="width: 190px;"><?php _e( 'Component', 'buddypress' ); ?></th>
205
- <th scope="col" class="manage-column column-description"><?php _e( 'Description', 'buddypress' ); ?></th>
206
- </tr>
207
- </tfoot>
208
-
209
- <tbody id="the-list">
210
-
211
- <?php if ( !empty( $current_components ) ) : ?>
212
-
213
- <?php foreach ( $current_components as $name => $labels ) : ?>
214
-
215
- <?php if ( !in_array( $name, array( 'core', 'members' ) ) ) :
216
- $class = isset( $active_components[esc_attr( $name )] ) ? 'active' : 'inactive';
217
- else :
218
- $class = 'active';
219
- endif; ?>
220
-
221
- <tr id="<?php echo $name; ?>" class="<?php echo $name . ' ' . $class; ?>">
222
- <th scope="row">
223
-
224
- <?php if ( !in_array( $name, array( 'core', 'members' ) ) ) : ?>
225
-
226
- <input type="checkbox" id="bp_components[<?php echo esc_attr( $name ); ?>]" name="bp_components[<?php echo esc_attr( $name ); ?>]" value="1"<?php checked( isset( $active_components[esc_attr( $name )] ) ); ?> />
227
-
228
- <?php endif; ?>
229
-
230
- <label class="screen-reader-text" for="bp_components[<?php echo esc_attr( $name ); ?>]"><?php sprintf( __( 'Select %s', 'buddypress' ), esc_html( $labels['title'] ) ); ?></label>
231
- </th>
232
- <td class="plugin-title" style="width: 190px;">
233
- <span></span>
234
- <strong><?php echo esc_html( $labels['title'] ); ?></strong>
235
- <div class="row-actions-visible">
236
-
237
- </div>
238
- </td>
239
-
240
- <td class="column-description desc">
241
- <div class="plugin-description">
242
- <p><?php echo $labels['description']; ?></p>
243
- </div>
244
- <div class="active second plugin-version-author-uri">
245
-
246
- </div>
247
- </td>
248
- </tr>
249
-
250
- <?php endforeach ?>
251
-
252
- <?php else : ?>
253
-
254
- <tr class="no-items">
255
- <td class="colspanchange" colspan="3"><?php _e( 'No components found.', 'buddypress' ); ?></td>
256
- </tr>
257
-
258
- <?php endif; ?>
259
-
260
- </tbody>
261
- </table>
262
-
263
- <input type="hidden" name="bp_components[members]" value="1" />
264
-
265
- <?php
266
- }
267
-
268
- /**
269
- * Handle saving the Component settings
270
- *
271
- * @since BuddyPress (1.6)
272
- * @todo Use settings API
273
- * @global BuddyPress $bp
274
- * @return false On failure
275
- */
276
- function bp_core_admin_components_settings_handler() {
277
- global $bp;
278
-
279
- if ( isset( $_POST['bp-admin-component-submit'] ) ) {
280
- if ( !check_admin_referer('bp-admin-component-setup') )
281
- return false;
282
-
283
- // Settings form submitted, now save the settings. First, set active components
284
- if ( isset( $_POST['bp_components'] ) ) {
285
- // Save settings and upgrade schema
286
- require_once( BP_PLUGIN_DIR . '/bp-core/admin/bp-core-schema.php' );
287
- $bp->active_components = stripslashes_deep( $_POST['bp_components'] );
288
- bp_core_install( $bp->active_components );
289
-
290
- bp_update_option( 'bp-active-components', $bp->active_components );
291
- }
292
-
293
- $base_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-components', 'updated' => 'true' ), 'admin.php' ) );
294
-
295
- wp_redirect( $base_url );
296
- }
297
- }
298
- add_action( 'admin_init', 'bp_core_admin_components_settings_handler' );
299
-
300
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-core/admin/bp-core-functions.php DELETED
@@ -1,399 +0,0 @@
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
-
15
- /**
16
- * Initializes the wp-admin area "BuddyPress" menus and sub menus.
17
- *
18
- * @package BuddyPress Core
19
- * @uses bp_current_user_can() returns true if the current user is a site admin, false if not
20
- */
21
- function bp_core_admin_menu_init() {
22
- add_action( bp_core_admin_hook(), 'bp_core_add_admin_menu', 9 );
23
- }
24
-
25
- /**
26
- * In BP 1.6, the top-level admin menu was removed. For backpat, this function
27
- * keeps the top-level menu if a plugin has registered a menu into the old
28
- * 'bp-general-settings' menu.
29
- *
30
- * The old "bp-general-settings" page was renamed "bp-components".
31
- *
32
- * @global array $_parent_pages
33
- * @global array $_registered_pages
34
- * @global array $submenu
35
- * @since 1.6
36
- */
37
- function bp_core_admin_backpat_menu() {
38
- global $_parent_pages, $_registered_pages, $submenu;
39
-
40
- if ( ! is_super_admin() )
41
- return;
42
-
43
- // Don't do anything if a BP upgrade is in progress, or if the bp-wizard is in progress.
44
- if ( defined( 'BP_IS_UPGRADE' ) && BP_IS_UPGRADE || empty( $submenu['bp-general-settings'] ) )
45
- return;
46
-
47
- /**
48
- * By default, only the core "Help" submenu is added under the top-level BuddyPress menu.
49
- * This means that if no third-party plugins have registered their admin pages into the
50
- * 'bp-general-settings' menu, it will only contain one item. Kill it.
51
- */
52
- if ( 1 == count( $submenu['bp-general-settings'] ) ) {
53
-
54
- // This removes the top-level menu
55
- remove_submenu_page( 'bp-general-settings', 'bp-general-settings' );
56
- remove_menu_page( 'bp-general-settings' );
57
-
58
- // These stop people accessing the URL directly
59
- unset( $_parent_pages['bp-general-settings'] );
60
- unset( $_registered_pages['toplevel_page_bp-general-settings'] );
61
- }
62
- }
63
- add_action( bp_core_admin_hook(), 'bp_core_admin_backpat_menu', 999 );
64
-
65
- /**
66
- * Tweak the Settings subnav menu to show only one BuddyPress menu item (Settings > BuddyPress).
67
- *
68
- * @since 1.6
69
- */
70
- function bp_core_modify_admin_menu() {
71
- $page = bp_core_do_network_admin() ? 'settings.php' : 'options-general.php';
72
-
73
- remove_submenu_page( $page, 'bb-forums-setup' );
74
- remove_submenu_page( $page, 'bp-page-settings' );
75
- remove_submenu_page( $page, 'bp-settings' );
76
- }
77
- add_action( 'admin_head', 'bp_core_modify_admin_menu', 999 );
78
-
79
- /**
80
- * This tells WP to highlight the Settings > BuddyPress menu item,
81
- * regardless of which actual BuddyPress admin screen we are on.
82
- *
83
- * The conditional prevents the behaviour when the user is viewing the
84
- * backpat "Help" page, the Activity page, or any third-party plugins.
85
- *
86
- * @global string $plugin_page
87
- * @global array $submenu
88
- * @since 1.6
89
- */
90
- function bp_core_modify_admin_menu_highlight() {
91
- global $plugin_page, $submenu_file;
92
-
93
- // This tweaks the Settings subnav menu to show only one BuddyPress menu item
94
- if ( ! in_array( $plugin_page, array( 'bp-activity', 'bp-general-settings', ) ) )
95
- $submenu_file = 'bp-components';
96
- }
97
-
98
- /**
99
- * Generates markup for a fallback top-level BuddyPress menu page, if the site is running
100
- * a legacy plugin which hasn't been updated. If the site is up to date, this page
101
- * will never appear.
102
- *
103
- * @see bp_core_admin_backpat_menu()
104
- * @since 1.6
105
- * @todo Add convenience links into the markup once new positions are finalised.
106
- */
107
- function bp_core_admin_backpat_page() {
108
- $url = bp_core_do_network_admin() ? network_admin_url( 'settings.php' ) : admin_url( 'options-general.php' );
109
- $settings_url = add_query_arg( 'page', 'bp-components', $url ); ?>
110
-
111
- <div class="wrap">
112
- <?php screen_icon( 'buddypress'); ?>
113
- <h2><?php _e( 'Why have all my BuddyPress menus disappeared?', 'buddypress' ); ?></h2>
114
-
115
- <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>
116
- <p><?php printf( __( 'Components, Pages, Settings, and Forums, have been moved to <a href="%s">Settings &gt; BuddyPress</a>. Profile Fields has been moved into the <a href="%s">Users</a> menu.', 'buddypress' ), $settings_url, network_admin_url( 'users.php?page=bp-profile-setup' ) ); ?></p>
117
- </div>
118
-
119
- <?php
120
- }
121
-
122
- /** Notices *******************************************************************/
123
-
124
- /**
125
- * Print admin messages to admin_notices or network_admin_notices
126
- *
127
- * BuddyPress combines all its messages into a single notice, to avoid a preponderance of yellow
128
- * boxes.
129
- *
130
- * @package BuddyPress Core
131
- * @since BuddyPress (1.5)
132
- *
133
- * @global BuddyPress $bp The one true BuddyPress instance
134
- * @uses bp_current_user_can() to check current user permissions before showing the notices
135
- * @uses bp_is_root_blog()
136
- */
137
- function bp_core_print_admin_notices() {
138
- global $bp;
139
-
140
- // Only the super admin should see messages
141
- if ( !bp_current_user_can( 'bp_moderate' ) )
142
- return;
143
-
144
- // On multisite installs, don't show on the Site Admin of a non-root blog, unless
145
- // do_network_admin is overridden
146
- if ( is_multisite() && bp_core_do_network_admin() && !bp_is_root_blog() )
147
- return;
148
-
149
- // Show the messages
150
- if ( !empty( $bp->admin->notices ) ) {
151
- ?>
152
- <div id="message" class="updated fade">
153
- <?php foreach( $bp->admin->notices as $notice ) : ?>
154
- <p><?php echo $notice ?></p>
155
- <?php endforeach ?>
156
- </div>
157
- <?php
158
- }
159
- }
160
- add_action( 'admin_notices', 'bp_core_print_admin_notices' );
161
- add_action( 'network_admin_notices', 'bp_core_print_admin_notices' );
162
-
163
- /**
164
- * Add an admin notice to the BP queue
165
- *
166
- * Messages added with this function are displayed in BuddyPress's general purpose admin notices
167
- * box. It is recommended that you hook this function to admin_init, so that your messages are
168
- * loaded in time.
169
- *
170
- * @package BuddyPress Core
171
- * @since BuddyPress (1.5)
172
- *
173
- * @global BuddyPress $bp The one true BuddyPress instance
174
- * @param string $notice The notice you are adding to the queue
175
- */
176
- function bp_core_add_admin_notice( $notice ) {
177
- global $bp;
178
-
179
- if ( empty( $bp->admin->notices ) ) {
180
- $bp->admin->notices = array();
181
- }
182
-
183
- $bp->admin->notices[] = $notice;
184
- }
185
-
186
- /**
187
- * Verify that some BP prerequisites are set up properly, and notify the admin if not
188
- *
189
- * On every Dashboard page, this function checks the following:
190
- * - that pretty permalinks are enabled
191
- * - that a BP-compatible theme is activated
192
- * - that every BP component that needs a WP page for a directory has one
193
- * - that no WP page has multiple BP components associated with it
194
- * The administrator will be shown a notice for each check that fails.
195
- *
196
- * @package BuddyPress Core
197
- */
198
- function bp_core_activation_notice() {
199
- global $wp_rewrite, $wpdb, $bp;
200
-
201
- // Only the super admin gets warnings
202
- if ( !bp_current_user_can( 'bp_moderate' ) )
203
- return;
204
-
205
- // On multisite installs, don't load on a non-root blog, unless do_network_admin is
206
- // overridden
207
- if ( is_multisite() && bp_core_do_network_admin() && !bp_is_root_blog() )
208
- return;
209
-
210
- // Don't show these messages during setup or upgrade
211
- if ( !empty( $bp->maintenance_mode ) )
212
- return;
213
-
214
- /**
215
- * Check to make sure that the blog setup routine has run. This can't happen during the
216
- * wizard because of the order which the components are loaded. We check for multisite here
217
- * on the off chance that someone has activated the blogs component and then disabled MS
218
- */
219
- if ( bp_is_active( 'blogs' ) ) {
220
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$bp->blogs->table_name}" ) );
221
-
222
- if ( empty( $count ) ) {
223
- bp_blogs_record_existing_blogs();
224
- }
225
- }
226
-
227
- /**
228
- * Are pretty permalinks enabled?
229
- */
230
- if ( isset( $_POST['permalink_structure'] ) )
231
- return false;
232
-
233
- if ( empty( $wp_rewrite->permalink_structure ) ) {
234
- 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' ) ) );
235
- }
236
-
237
- /**
238
- * Are you using a BP-compatible theme?
239
- */
240
-
241
- // Get current theme info
242
- $ct = wp_get_theme();
243
-
244
- // Make sure tags is an array to suppress notices
245
- if ( ! isset( $ct->tags ) )
246
- $ct->tags = array();
247
- else
248
- $ct->tags = (array) $ct->tags;
249
-
250
- // The best way to remove this notice is to add a "buddypress" tag to
251
- // your active theme's CSS header.
252
- if ( !defined( 'BP_SILENCE_THEME_NOTICE' ) && !in_array( 'buddypress', $ct->tags ) ) {
253
- bp_core_add_admin_notice( sprintf( __( "You'll need to <a href='%s'>activate a <strong>BuddyPress-compatible theme</strong></a> to take advantage of all of BuddyPress's features. We've bundled a default theme, but you can always <a href='%s'>install some other compatible themes</a> or <a href='%s'>update your existing WordPress theme</a>.", 'buddypress' ), admin_url( 'themes.php' ), network_admin_url( 'theme-install.php?type=tag&s=buddypress&tab=search' ), network_admin_url( 'plugin-install.php?type=term&tab=search&s=%22bp-template-pack%22' ) ) );
254
- }
255
-
256
- /**
257
- * Check for orphaned BP components (BP component is enabled, no WP page exists)
258
- */
259
-
260
- $orphaned_components = array();
261
- $wp_page_components = array();
262
-
263
- // Only components with 'has_directory' require a WP page to function
264
- foreach( $bp->loaded_components as $component_id => $is_active ) {
265
- if ( !empty( $bp->{$component_id}->has_directory ) ) {
266
- $wp_page_components[] = array(
267
- 'id' => $component_id,
268
- 'name' => isset( $bp->{$component_id}->name ) ? $bp->{$component_id}->name : ucwords( $bp->{$component_id}->id )
269
- );
270
- }
271
- }
272
-
273
- // Activate and Register are special cases. They are not components but they need WP pages.
274
- // If user registration is disabled, we can skip this step.
275
- if ( bp_get_signup_allowed() ) {
276
- $wp_page_components[] = array(
277
- 'id' => 'activate',
278
- 'name' => __( 'Activate', 'buddypress' )
279
- );
280
-
281
- $wp_page_components[] = array(
282
- 'id' => 'register',
283
- 'name' => __( 'Register', 'buddypress' )
284
- );
285
- }
286
-
287
- foreach( $wp_page_components as $component ) {
288
- if ( !isset( $bp->pages->{$component['id']} ) ) {
289
- $orphaned_components[] = $component['name'];
290
- }
291
- }
292
-
293
- // Special case: If the Forums component is orphaned, but the bbPress 1.x installation is
294
- // not correctly set up, don't show a nag. (In these cases, it's probably the case that the
295
- // user is using bbPress 2.x; see https://buddypress.trac.wordpress.org/ticket/4292
296
- if ( isset( $bp->forums->name ) && in_array( $bp->forums->name, $orphaned_components ) && !bp_forums_is_installed_correctly() ) {
297
- $forum_key = array_search( $bp->forums->name, $orphaned_components );
298
- unset( $orphaned_components[$forum_key] );
299
- $orphaned_components = array_values( $orphaned_components );
300
- }
301
-
302
- if ( !empty( $orphaned_components ) ) {
303
- $admin_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) );
304
- $notice = sprintf( __( 'The following active BuddyPress Components do not have associated WordPress Pages: %2$s. <a href="%1$s" class="button-secondary">Repair</a>', 'buddypress' ), $admin_url, '<strong>' . implode( '</strong>, <strong>', $orphaned_components ) . '</strong>' );
305
-
306
- bp_core_add_admin_notice( $notice );
307
- }
308
-
309
- /**
310
- * BP components cannot share a single WP page. Check for duplicate assignments, and post
311
- * a message if found.
312
- */
313
- $dupe_names = array();
314
- $page_ids = (array)bp_core_get_directory_page_ids();
315
- $dupes = array_diff_assoc( $page_ids, array_unique( $page_ids ) );
316
-
317
- if ( !empty( $dupes ) ) {
318
- foreach( $dupes as $dupe_component => $dupe_id ) {
319
- $dupe_names[] = $bp->pages->{$dupe_component}->title;
320
- }
321
-
322
- // Make sure that there are no duplicate duplicates :)
323
- $dupe_names = array_unique( $dupe_names );
324
- }
325
-
326
- // If there are duplicates, post a message about them
327
- if ( !empty( $dupe_names ) ) {
328
- $admin_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) );
329
- $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" class="button-secondary">Repair</a>', 'buddypress' ), $admin_url, '<strong>' . implode( '</strong>, <strong>', $dupe_names ) . '</strong>' );
330
-
331
- bp_core_add_admin_notice( $notice );
332
- }
333
- }
334
- add_action( 'admin_init', 'bp_core_activation_notice' );
335
-
336
- /**
337
- * Add an extra update message to the update plugin notification.
338
- *
339
- * @package BuddyPress Core
340
- */
341
- function bp_core_update_message() {
342
- echo '<p style="color: red; margin: 3px 0 0 0; border-top: 1px solid #ddd; padding-top: 3px">' . __( 'IMPORTANT: <a href="http://codex.buddypress.org/buddypress-site-administration/upgrading-buddypress/">Read this before attempting to update BuddyPress</a>', 'buddypress' ) . '</p>';
343
- }
344
- add_action( 'in_plugin_update_message-buddypress/bp-loader.php', 'bp_core_update_message' );
345
-
346
- /** UI/Styling ****************************************************************/
347
-
348
- /**
349
- * Output the tabs in the admin area
350
- *
351
- * @since BuddyPress (1.5)
352
- * @param string $active_tab Name of the tab that is active
353
- */
354
- function bp_core_admin_tabs( $active_tab = '' ) {
355
-
356
- // Declare local variables
357
- $tabs_html = '';
358
- $idle_class = 'nav-tab';
359
- $active_class = 'nav-tab nav-tab-active';
360
-
361
- // Setup core admin tabs
362
- $tabs = array(
363
- '0' => array(
364
- 'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bp-components' ), 'admin.php' ) ),
365
- 'name' => __( 'Components', 'buddypress' )
366
- ),
367
- '1' => array(
368
- 'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) ),
369
- 'name' => __( 'Pages', 'buddypress' )
370
- ),
371
- '2' => array(
372
- 'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bp-settings' ), 'admin.php' ) ),
373
- 'name' => __( 'Settings', 'buddypress' )
374
- )
375
- );
376
-
377
- // If forums component is active, add additional tab
378
- if ( bp_is_active( 'forums' ) ) {
379
- $tabs['3'] = array(
380
- 'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bb-forums-setup' ), 'admin.php' ) ),
381
- 'name' => __( 'Forums', 'buddypress' )
382
- );
383
- }
384
-
385
- // Loop through tabs and build navigation
386
- foreach( $tabs as $tab_id => $tab_data ) {
387
- $is_current = (bool) ( $tab_data['name'] == $active_tab );
388
- $tab_class = $is_current ? $active_class : $idle_class;
389
- $tabs_html .= '<a href="' . $tab_data['href'] . '" class="' . $tab_class . '">' . $tab_data['name'] . '</a>';
390
- }
391
-
392
- // Output the tabs
393
- echo $tabs_html;
394
-
395
- // Do other fun things
396
- do_action( 'bp_admin_tabs' );
397
- }
398
-
399
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-core/admin/bp-core-schema.php CHANGED
@@ -1,5 +1,4 @@
1
  <?php
2
-
3
  // Exit if accessed directly
4
  if ( !defined( 'ABSPATH' ) ) exit;
5
 
@@ -15,44 +14,11 @@ function bp_core_set_charset() {
15
  return '';
16
  }
17
 
18
- function bp_core_install( $active_components = false ) {
19
-
20
- if ( empty( $active_components ) )
21
- $active_components = apply_filters( 'bp_active_components', bp_get_option( 'bp-active-components' ) );
22
-
23
- // Core DB Tables
24
- bp_core_install_notifications();
25
-
26
- // Activity Streams
27
- if ( !empty( $active_components['activity'] ) )
28
- bp_core_install_activity_streams();
29
-
30
- // Friend Connections
31
- if ( !empty( $active_components['friends'] ) )
32
- bp_core_install_friends();
33
-
34
- // Extensible Groups
35
- if ( !empty( $active_components['groups'] ) )
36
- bp_core_install_groups();
37
-
38
- // Private Messaging
39
- if ( !empty( $active_components['messages'] ) )
40
- bp_core_install_private_messaging();
41
-
42
- // Extended Profiles
43
- if ( !empty( $active_components['xprofile'] ) )
44
- bp_core_install_extended_profiles();
45
-
46
- // Blog tracking
47
- if ( !empty( $active_components['blogs'] ) )
48
- bp_core_install_blog_tracking();
49
- }
50
-
51
  function bp_core_install_notifications() {
 
52
 
53
- $sql = array();
54
  $charset_collate = bp_core_set_charset();
55
- $bp_prefix = bp_core_get_table_prefix();
56
 
57
  $sql[] = "CREATE TABLE {$bp_prefix}bp_notifications (
58
  id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
@@ -72,30 +38,29 @@ function bp_core_install_notifications() {
72
  KEY useritem (user_id,is_new)
73
  ) {$charset_collate};";
74
 
75
- dbDelta( $sql );
76
  }
77
 
78
  function bp_core_install_activity_streams() {
 
79
 
80
- $sql = array();
81
  $charset_collate = bp_core_set_charset();
82
- $bp_prefix = bp_core_get_table_prefix();
83
 
84
  $sql[] = "CREATE TABLE {$bp_prefix}bp_activity (
85
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
86
  user_id bigint(20) NOT NULL,
87
  component varchar(75) NOT NULL,
88
  type varchar(75) NOT NULL,
89
  action text NOT NULL,
90
  content longtext NOT NULL,
91
- primary_link varchar(255) NOT NULL,
92
- item_id bigint(20) NOT NULL,
93
- secondary_item_id bigint(20) DEFAULT NULL,
94
  date_recorded datetime NOT NULL,
95
  hide_sitewide bool DEFAULT 0,
96
  mptt_left int(11) NOT NULL DEFAULT 0,
97
  mptt_right int(11) NOT NULL DEFAULT 0,
98
- is_spam tinyint(1) NOT NULL DEFAULT 0,
99
  KEY date_recorded (date_recorded),
100
  KEY user_id (user_id),
101
  KEY item_id (item_id),
@@ -104,9 +69,8 @@ function bp_core_install_activity_streams() {
104
  KEY type (type),
105
  KEY mptt_left (mptt_left),
106
  KEY mptt_right (mptt_right),
107
- KEY hide_sitewide (hide_sitewide),
108
- KEY is_spam (is_spam)
109
- ) {$charset_collate};";
110
 
111
  $sql[] = "CREATE TABLE {$bp_prefix}bp_activity_meta (
112
  id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
@@ -117,14 +81,14 @@ function bp_core_install_activity_streams() {
117
  KEY meta_key (meta_key)
118
  ) {$charset_collate};";
119
 
120
- dbDelta( $sql );
121
  }
122
 
123
  function bp_core_install_friends() {
 
124
 
125
- $sql = array();
126
  $charset_collate = bp_core_set_charset();
127
- $bp_prefix = bp_core_get_table_prefix();
128
 
129
  $sql[] = "CREATE TABLE {$bp_prefix}bp_friends (
130
  id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
@@ -137,14 +101,14 @@ function bp_core_install_friends() {
137
  KEY friend_user_id (friend_user_id)
138
  ) {$charset_collate};";
139
 
140
- dbDelta( $sql );
141
  }
142
 
143
  function bp_core_install_groups() {
 
144
 
145
- $sql = array();
146
  $charset_collate = bp_core_set_charset();
147
- $bp_prefix = bp_core_get_table_prefix();
148
 
149
  $sql[] = "CREATE TABLE {$bp_prefix}bp_groups (
150
  id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
@@ -189,14 +153,14 @@ function bp_core_install_groups() {
189
  KEY meta_key (meta_key)
190
  ) {$charset_collate};";
191
 
192
- dbDelta( $sql );
193
  }
194
 
195
  function bp_core_install_private_messaging() {
 
196
 
197
- $sql = array();
198
  $charset_collate = bp_core_set_charset();
199
- $bp_prefix = bp_core_get_table_prefix();
200
 
201
  $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_messages (
202
  id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
@@ -232,24 +196,23 @@ function bp_core_install_private_messaging() {
232
  KEY is_active (is_active)
233
  ) {$charset_collate};";
234
 
235
- dbDelta( $sql );
236
  }
237
 
238
  function bp_core_install_extended_profiles() {
239
  global $wpdb;
240
 
241
- $sql = array();
242
  $charset_collate = bp_core_set_charset();
243
- $bp_prefix = bp_core_get_table_prefix();
244
 
245
- // These values should only be updated if they are not already present
246
- if ( !$base_group_name = bp_get_option( 'bp-xprofile-base-group-name' ) ) {
247
- bp_update_option( 'bp-xprofile-base-group-name', _x( 'Base', 'First XProfile group name', 'buddypress' ) );
248
- }
249
 
250
- if ( !$fullname_field_name = bp_get_option( 'bp-xprofile-fullname-field-name' ) ) {
251
- bp_update_option( 'bp-xprofile-fullname-field-name', _x( 'Name', 'XProfile fullname field name', 'buddypress' ) );
252
- }
253
 
254
  $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_groups (
255
  id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
@@ -315,10 +278,10 @@ function bp_core_install_extended_profiles() {
315
  }
316
 
317
  function bp_core_install_blog_tracking() {
 
318
 
319
- $sql = array();
320
  $charset_collate = bp_core_set_charset();
321
- $bp_prefix = bp_core_get_table_prefix();
322
 
323
  $sql[] = "CREATE TABLE {$bp_prefix}bp_user_blogs (
324
  id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
@@ -337,54 +300,7 @@ function bp_core_install_blog_tracking() {
337
  KEY meta_key (meta_key)
338
  ) {$charset_collate};";
339
 
340
- dbDelta( $sql );
341
- }
342
-
343
- /**
344
- * I don't appear to be used anymore, but I'm here anyways. I was originally
345
- * used in olden days to update pre-1.1 schemas, but that was before we had
346
- * a legitimate update process. Keep me around just incase.
347
- *
348
- * @global WPDB $wpdb
349
- * @global BuddyPress $bp
350
- */
351
- function bp_update_db_stuff() {
352
- global $wpdb, $bp;
353
-
354
- $bp_prefix = bp_core_get_table_prefix();
355
-
356
- // Rename the old user activity cached table if needed.
357
- if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$bp_prefix}bp_activity_user_activity_cached%'" ) )
358
- $wpdb->query( "RENAME TABLE {$bp_prefix}bp_activity_user_activity_cached TO {$bp->activity->table_name}" );
359
-
360
- // Rename fields from pre BP 1.2
361
- if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$bp->activity->table_name}%'" ) ) {
362
- if ( $wpdb->get_var( "SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_action'" ) ) {
363
- $wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE component_action type varchar(75) NOT NULL" );
364
- }
365
-
366
- if ( $wpdb->get_var( "SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_name'" ) ) {
367
- $wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE component_name component varchar(75) NOT NULL" );
368
- }
369
- }
370
-
371
- // On first installation - record all existing blogs in the system.
372
- if ( !(int) $bp->site_options['bp-blogs-first-install'] ) {
373
- bp_blogs_record_existing_blogs();
374
- bp_update_option( 'bp-blogs-first-install', 1 );
375
- }
376
-
377
- if ( is_multisite() ) {
378
- bp_core_add_illegal_names();
379
- }
380
-
381
- // Update and remove the message threads table if it exists
382
- if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$bp_prefix}bp_messages_threads%'" ) ) {
383
- if ( BP_Messages_Thread::update_tables() ) {
384
- $wpdb->query( "DROP TABLE {$bp_prefix}bp_messages_threads" );
385
- }
386
- }
387
-
388
  }
389
 
390
  ?>
1
  <?php
 
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
14
  return '';
15
  }
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  function bp_core_install_notifications() {
18
+ global $wpdb;
19
 
 
20
  $charset_collate = bp_core_set_charset();
21
+ $bp_prefix = bp_core_get_table_prefix();
22
 
23
  $sql[] = "CREATE TABLE {$bp_prefix}bp_notifications (
24
  id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
38
  KEY useritem (user_id,is_new)
39
  ) {$charset_collate};";
40
 
41
+ dbDelta($sql);
42
  }
43
 
44
  function bp_core_install_activity_streams() {
45
+ global $wpdb;
46
 
 
47
  $charset_collate = bp_core_set_charset();
48
+ $bp_prefix = bp_core_get_table_prefix();
49
 
50
  $sql[] = "CREATE TABLE {$bp_prefix}bp_activity (
51
+ id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
52
  user_id bigint(20) NOT NULL,
53
  component varchar(75) NOT NULL,
54
  type varchar(75) NOT NULL,
55
  action text NOT NULL,
56
  content longtext NOT NULL,
57
+ primary_link varchar(150) NOT NULL,
58
+ item_id varchar(75) NOT NULL,
59
+ secondary_item_id varchar(75) DEFAULT NULL,
60
  date_recorded datetime NOT NULL,
61
  hide_sitewide bool DEFAULT 0,
62
  mptt_left int(11) NOT NULL DEFAULT 0,
63
  mptt_right int(11) NOT NULL DEFAULT 0,
 
64
  KEY date_recorded (date_recorded),
65
  KEY user_id (user_id),
66
  KEY item_id (item_id),
69
  KEY type (type),
70
  KEY mptt_left (mptt_left),
71
  KEY mptt_right (mptt_right),
72
+ KEY hide_sitewide (hide_sitewide)
73
+ ) {$charset_collate};";
 
74
 
75
  $sql[] = "CREATE TABLE {$bp_prefix}bp_activity_meta (
76
  id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
81
  KEY meta_key (meta_key)
82
  ) {$charset_collate};";
83
 
84
+ dbDelta($sql);
85
  }
86
 
87
  function bp_core_install_friends() {
88
+ global $wpdb;
89
 
 
90
  $charset_collate = bp_core_set_charset();
91
+ $bp_prefix = bp_core_get_table_prefix();
92
 
93
  $sql[] = "CREATE TABLE {$bp_prefix}bp_friends (
94
  id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
101
  KEY friend_user_id (friend_user_id)
102
  ) {$charset_collate};";
103
 
104
+ dbDelta($sql);
105
  }
106
 
107
  function bp_core_install_groups() {
108
+ global $wpdb;
109
 
 
110
  $charset_collate = bp_core_set_charset();
111
+ $bp_prefix = bp_core_get_table_prefix();
112
 
113
  $sql[] = "CREATE TABLE {$bp_prefix}bp_groups (
114
  id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
153
  KEY meta_key (meta_key)
154
  ) {$charset_collate};";
155
 
156
+ dbDelta($sql);
157
  }
158
 
159
  function bp_core_install_private_messaging() {
160
+ global $wpdb;
161
 
 
162
  $charset_collate = bp_core_set_charset();
163
+ $bp_prefix = bp_core_get_table_prefix();
164
 
165
  $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_messages (
166
  id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
196
  KEY is_active (is_active)
197
  ) {$charset_collate};";
198
 
199
+ dbDelta($sql);
200
  }
201
 
202
  function bp_core_install_extended_profiles() {
203
  global $wpdb;
204
 
 
205
  $charset_collate = bp_core_set_charset();
206
+ $bp_prefix = bp_core_get_table_prefix();
207
 
208
+ // These values should only be updated if they are not already present
209
+ if ( !$base_group_name = bp_get_option( 'bp-xprofile-base-group-name' ) ) {
210
+ bp_update_option( 'bp-xprofile-base-group-name', _x( 'Base', 'First XProfile group name', 'buddypress' ) );
211
+ }
212
 
213
+ if ( !$fullname_field_name = bp_get_option( 'bp-xprofile-fullname-field-name' ) ) {
214
+ bp_update_option( 'bp-xprofile-fullname-field-name', _x( 'Name', 'XProfile fullname field name', 'buddypress' ) );
215
+ }
216
 
217
  $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_groups (
218
  id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
278
  }
279
 
280
  function bp_core_install_blog_tracking() {
281
+ global $wpdb;
282
 
 
283
  $charset_collate = bp_core_set_charset();
284
+ $bp_prefix = bp_core_get_table_prefix();
285
 
286
  $sql[] = "CREATE TABLE {$bp_prefix}bp_user_blogs (
287
  id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
300
  KEY meta_key (meta_key)
301
  ) {$charset_collate};";
302
 
303
+ dbDelta($sql);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
304
  }
305
 
306
  ?>
bp-core/admin/bp-core-settings.php DELETED
@@ -1,368 +0,0 @@
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
- ?>
29
-
30
- <input id="hide-loggedout-adminbar" name="hide-loggedout-adminbar" type="checkbox" value="1" <?php checked( !bp_hide_loggedout_adminbar( false ) ); ?> />
31
- <label for="hide-loggedout-adminbar"><?php _e( 'Show the Toolbar for logged out users', 'buddypress' ); ?></label>
32
-
33
- <?php
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
- ?>
45
-
46
- <input id="bp-disable-account-deletion" name="bp-disable-account-deletion" type="checkbox" value="1" <?php checked( !bp_disable_account_deletion( false ) ); ?> />
47
- <label for="bp-disable-account-deletion"><?php _e( 'Allow registered members to delete their own accounts', 'buddypress' ); ?></label>
48
-
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
- ?>
85
-
86
- <input id="_bp_enable_akismet" name="_bp_enable_akismet" type="checkbox" value="1" <?php checked( bp_is_akismet_active( true ) ); ?> />
87
- <label for="_bp_enable_akismet"><?php _e( 'Allow Akismet to scan for activity stream spam', 'buddypress' ); ?></label>
88
-
89
- <?php
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
- ?>
99
-
100
- <input id="bp-disable-blogforum-comments" name="bp-disable-blogforum-comments" type="checkbox" value="1" <?php checked( !bp_disable_blogforum_comments( false ) ); ?> />
101
- <label for="bp-disable-blogforum-comments"><?php _e( 'Allow activity stream commenting on blog and forum posts', 'buddypress' ); ?></label>
102
-
103
- <?php
104
- }
105
-
106
- /**
107
- * Sanitization for _bp_force_buddyvar
108
- *
109
- * If upgraded to 1.6 and you chose to keep the BuddyBar, a checkbox asks if you want to switch to
110
- * the WP Toolbar. The option we store is 1 if the BuddyBar is forced on, so we use this function
111
- * to flip the boolean before saving the intval.
112
- *
113
- * @since BuddyPress (1.6)
114
- * @access Private
115
- */
116
- function bp_admin_sanitize_callback_force_buddybar( $value = false ) {
117
- return $value ? 0 : 1;
118
- }
119
-
120
- /**
121
- * Sanitization for bp-disable-blogforum-comments setting
122
- *
123
- * In the UI, a checkbox asks whether you'd like to *enable* blog/forum activity comments. For
124
- * legacy reasons, the option that we store is 1 if these comments are *disabled*. So we use this
125
- * function to flip the boolean before saving the intval.
126
- *
127
- * @since BuddyPress (1.6)
128
- */
129
- function bp_admin_sanitize_callback_blogforum_comments( $value = false ) {
130
- return $value ? 0 : 1;
131
- }
132
-
133
- /** XProfile ******************************************************************/
134
-
135
- /**
136
- * Profile settings section description for the settings page
137
- *
138
- * @since BuddyPress (1.6)
139
- */
140
- function bp_admin_setting_callback_xprofile_section() { }
141
-
142
- /**
143
- * Enable BP->WP profile syncing field
144
- *
145
- * @since BuddyPress (1.6)
146
- *
147
- * @uses bp_form_option() To output the option value
148
- */
149
- function bp_admin_setting_callback_profile_sync() {
150
- ?>
151
-
152
- <input id="bp-disable-profile-sync" name="bp-disable-profile-sync" type="checkbox" value="1" <?php checked( !bp_disable_profile_sync( false ) ); ?> />
153
- <label for="bp-disable-profile-sync"><?php _e( 'Enable BuddyPress to WordPress profile syncing', 'buddypress' ); ?></label>
154
-
155
- <?php
156
- }
157
-
158
- /**
159
- * Allow members to upload avatars field
160
- *
161
- * @since BuddyPress (1.6)
162
- *
163
- * @uses checked() To display the checked attribute
164
- */
165
- function bp_admin_setting_callback_avatar_uploads() {
166
- ?>
167
-
168
- <input id="bp-disable-avatar-uploads" name="bp-disable-avatar-uploads" type="checkbox" value="1" <?php checked( !bp_disable_avatar_uploads( false ) ); ?> />
169
- <label for="bp-disable-avatar-uploads"><?php _e( 'Allow registered members to upload avatars', 'buddypress' ); ?></label>
170
-
171
- <?php
172
- }
173
-
174
- /** Groups Section ************************************************************/
175
-
176
- /**
177
- * Groups settings section description for the settings page
178
- *
179
- * @since BuddyPress (1.6)
180
- */
181
- function bp_admin_setting_callback_groups_section() { }
182
-
183
- /**
184
- * Allow all users to create groups field
185
- *
186
- * @since BuddyPress (1.6)
187
- *
188
- * @uses checked() To display the checked attribute
189
- */
190
- function bp_admin_setting_callback_group_creation() {
191
- ?>
192
-
193
- <input id="bp_restrict_group_creation" name="bp_restrict_group_creation" type="checkbox"value="1" <?php checked( !bp_restrict_group_creation( false ) ); ?> />
194
- <label for="bp_restrict_group_creation"><?php _e( 'Enable group creation for all users', 'buddypress' ); ?></label>
195
- <p class="description"><?php _e( 'Administrators can always create groups, regardless of this setting.', 'buddypress' ); ?></p>
196
-
197
- <?php
198
- }
199
-
200
- /** Forums Section ************************************************************/
201
-
202
- /**
203
- * Forums settings section description for the settings page
204
- *
205
- * @since BuddyPress (1.6)
206
- */
207
- function bp_admin_setting_callback_bbpress_section() { }
208
-
209
- /**
210
- * bb-config.php location field
211
- *
212
- * @since BuddyPress (1.6)
213
- * @uses checked() To display the checked attribute
214
- * @uses bp_get_option() To get the config location
215
- * @uses bp_form_option() To get the sanitized form option
216
- */
217
- function bp_admin_setting_callback_bbpress_configuration() {
218
-
219
- $config_location = bp_get_option( 'bb-config-location' );
220
- $file_exists = (bool) ( file_exists( $config_location ) || is_file( $config_location ) ); ?>
221
-
222
- <input name="bb-config-location" type="text" id="bb-config-location" value="<?php bp_form_option( 'bb-config-location', '' ); ?>" class="medium-text" style="width: 300px;" />
223
-
224
- <?php if ( false === $file_exists ) : ?>
225
-
226
- <a class="button" href="<?php bp_admin_url( 'admin.php?page=bb-forums-setup&repair=1' ); ?>" title="<?php _e( 'Attempt to save a new config file.', 'buddypress' ); ?>"><?php _e( 'Repair', 'buddypress' ) ?></a>
227
- <span class="attention"><?php _e( 'File does not exist', 'buddypress' ); ?></span>
228
-
229
- <?php endif; ?>
230
-
231
- <p class="description"><?php _e( 'Absolute path to your bbPress configuration file.', 'buddypress' ); ?></p>
232
-
233
- <?php
234
- }
235
-
236
- /** Settings Page *************************************************************/
237
-
238
- /**
239
- * The main settings page
240
- *
241
- * @since BuddyPress (1.6)
242
- *
243
- * @uses screen_icon() To display the screen icon
244
- * @uses settings_fields() To output the hidden fields for the form
245
- * @uses do_settings_sections() To output the settings sections
246
- */
247
- function bp_core_admin_settings() {
248
-
249
- // We're saving our own options, until the WP Settings API is updated to work with Multisite
250
- $form_action = add_query_arg( 'page', 'bp-settings', bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
251
-
252
- ?>
253
-
254
- <div class="wrap">
255
-
256
- <?php screen_icon( 'buddypress' ); ?>
257
-
258
- <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( __( 'Settings', 'buddypress' ) ); ?></h2>
259
-
260
- <form action="<?php echo $form_action ?>" method="post">
261
-
262
- <?php settings_fields( 'buddypress' ); ?>
263
-
264
- <?php do_settings_sections( 'buddypress' ); ?>
265
-
266
- <p class="submit">
267
- <input type="submit" name="submit" class="button-primary" value="<?php _e( 'Save Changes', 'buddypress' ); ?>" />
268
- </p>
269
- </form>
270
- </div>
271
-
272
- <?php
273
- }
274
-
275
- /**
276
- * Save our settings
277
- *
278
- * @since BuddyPress (1.6)
279
- */
280
- function bp_core_admin_settings_save() {
281
- global $wp_settings_fields;
282
-
283
- if ( isset( $_GET['page'] ) && 'bp-settings' == $_GET['page'] && !empty( $_POST['submit'] ) ) {
284
- check_admin_referer( 'buddypress-options' );
285
-
286
- // Because many settings are saved with checkboxes, and thus will have no values
287
- // in the $_POST array when unchecked, we loop through the registered settings
288
- if ( isset( $wp_settings_fields['buddypress'] ) ) {
289
- foreach( (array) $wp_settings_fields['buddypress'] as $section => $settings ) {
290
- foreach( $settings as $setting_name => $setting ) {
291
- $value = isset( $_POST[$setting_name] ) ? $_POST[$setting_name] : '';
292
-
293
- bp_update_option( $setting_name, $value );
294
- }
295
- }
296
- }
297
-
298
- // Some legacy options are not registered with the Settings API
299
- $legacy_options = array(
300
- 'bp-disable-account-deletion',
301
- 'bp-disable-avatar-uploads',
302
- 'bp_disable_blogforum_comments',
303
- 'bp-disable-profile-sync',
304
- 'bp_restrict_group_creation',
305
- 'hide-loggedout-adminbar',
306
- );
307
-
308
- foreach( $legacy_options as $legacy_option ) {
309
- // Note: Each of these options is represented by its opposite in the UI
310
- // Ie, the Profile Syncing option reads "Enable Sync", so when it's checked,
311
- // the corresponding option should be unset
312
- $value = isset( $_POST[$legacy_option] ) ? '' : 1;
313
- bp_update_option( $legacy_option, $value );
314
- }
315
-
316
- bp_core_redirect( add_query_arg( 'page', 'bp-settings', bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) ) );
317
- }
318
- }
319
- add_action( 'bp_admin_init', 'bp_core_admin_settings_save', 100 );
320
-
321
- /**
322
- * Output settings API option
323
- *
324
- * @since BuddyPress (1.6)
325
- *
326
- * @uses bp_get_bp_form_option()
327
- *
328
- * @param string $option
329
- * @param string $default
330
- * @param bool $slug
331
- */
332
- function bp_form_option( $option, $default = '' , $slug = false ) {
333
- echo bp_get_form_option( $option, $default, $slug );
334
- }
335
- /**
336
- * Return settings API option
337
- *
338
- * @since BuddyPress (1.6)
339
- *
340
- * @uses bp_get_option()
341
- * @uses esc_attr()
342
- * @uses apply_filters()
343
- *
344
- * @param string $option
345
- * @param string $default
346
- * @param bool $slug
347
- */
348
- function bp_get_form_option( $option, $default = '', $slug = false ) {
349
-
350
- // Get the option and sanitize it
351
- $value = bp_get_option( $option, $default );
352
-
353
- // Slug?
354
- if ( true === $slug )
355
- $value = esc_attr( apply_filters( 'editable_slug', $value ) );
356
-
357
- // Not a slug
358
- else
359
- $value = esc_attr( $value );
360
-
361
- // Fallback to default
362
- if ( empty( $value ) )
363
- $value = $default;
364
-
365
- // Allow plugins to further filter the output
366
- return apply_filters( 'bp_get_form_option', $value, $option );
367
- }
368
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-core/admin/bp-core-slugs.php DELETED
@@ -1,224 +0,0 @@
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
- */
20
- function bp_core_admin_slugs_settings() {
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">
28
-
29
- <?php bp_core_admin_slugs_options(); ?>
30
-
31
- <p class="submit clear">
32
- <input class="button-primary" type="submit" name="bp-admin-pages-submit" id="bp-admin-pages-submit" value="<?php _e( 'Save All', 'buddypress' ) ?>"/>
33
- </p>
34
-
35
- <?php wp_nonce_field( 'bp-admin-pages-setup' ); ?>
36
-
37
- </form>
38
- </div>
39
-
40
- <?php
41
- }
42
-
43
- /**
44
- * Creates reusable markup for page setup on the Components and Pages dashboard panel.
45
- *
46
- * This markup has been abstracted so that it can be used both during the setup wizard as well as
47
- * when BP has been fully installed.
48
- *
49
- * @package BuddyPress
50
- * @since BuddyPress (1.6)
51
- * @todo Use settings API
52
- */
53
- function bp_core_admin_slugs_options() {
54
- global $bp;
55
-
56
- // Get the existing WP pages
57
- $existing_pages = bp_core_get_directory_page_ids();
58
-
59
- // Set up an array of components (along with component names) that have
60
- // directory pages.
61
- $directory_pages = array();
62
-
63
- // Loop through loaded components and collect directories
64
- if ( is_array( $bp->loaded_components ) ) {
65
- foreach( $bp->loaded_components as $component_slug => $component_id ) {
66
-
67
- // Only components that need directories should be listed here
68
- if ( isset( $bp->{$component_id} ) && !empty( $bp->{$component_id}->has_directory ) ) {
69
-
70
- // component->name was introduced in BP 1.5, so we must provide a fallback
71
- $directory_pages[$component_id] = !empty( $bp->{$component_id}->name ) ? $bp->{$component_id}->name : ucwords( $component_id );
72
- }
73
- }
74
- }
75
-
76
- /** Directory Display *****************************************************/
77
-
78
- $directory_pages = apply_filters( 'bp_directory_pages', $directory_pages );
79
-
80
- if ( !empty( $directory_pages ) ) : ?>
81
-
82
- <h3><?php _e( 'Directories', 'buddypress' ); ?></h3>
83
-
84
- <p><?php _e( 'Associate a WordPress Page with each BuddyPress component directory.', 'buddypress' ); ?></p>
85
-
86
- <table class="form-table">
87
- <tbody>
88
-
89
- <?php foreach ( $directory_pages as $name => $label ) : ?>
90
-
91
- <tr valign="top">
92
- <th scope="row">
93
- <label for="bp_pages[<?php echo esc_attr( $name ) ?>]"><?php echo esc_html( $label ) ?></label>
94
- </th>
95
-
96
- <td>
97
- <?php if ( !bp_is_root_blog() )
98
- switch_to_blog( bp_get_root_blog_id() ) ?>
99
-
100
- <?php echo wp_dropdown_pages( array(
101
- 'name' => 'bp_pages[' . esc_attr( $name ) . ']',
102
- 'echo' => false,
103
- 'show_option_none' => __( '- None -', 'buddypress' ),
104
- 'selected' => !empty( $existing_pages[$name] ) ? $existing_pages[$name] : false
105
- ) ); ?>
106
-
107
- <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>
108
- <input class="button-primary" type="submit" name="bp-admin-pages-single" value="<?php _e( 'Save', 'buddypress' ) ?>" />
109
-
110
- <?php if ( !empty( $existing_pages[$name] ) ) : ?>
111
-
112
- <a href="<?php echo get_permalink( $existing_pages[$name] ); ?>" class="button-secondary" target="_bp"><?php _e( 'View', 'buddypress' ); ?></a>
113
-
114
- <?php endif; ?>
115
-
116
- <?php if ( !bp_is_root_blog() )
117
- restore_current_blog() ?>
118
-
119
- </td>
120
- </tr>
121
-
122
-
123
- <?php endforeach ?>
124
-
125
- <?php do_action( 'bp_active_external_directories' ); ?>
126
-
127
- </tbody>
128
- </table>
129
-
130
- <?php
131
-
132
- endif;
133
-
134
- /** Static Display ********************************************************/
135
-
136
- // Static pages
137
- $static_pages = array(
138
- 'register' => __( 'Register', 'buddypress' ),
139
- 'activate' => __( 'Activate', 'buddypress' ),
140
- );
141
-
142
- $static_pages = apply_filters( 'bp_static_pages', $static_pages );
143
-
144
- if ( !empty( $static_pages ) ) : ?>
145
-
146
- <h3><?php _e( 'Registration', 'buddypress' ); ?></h3>
147
-
148
- <p><?php _e( 'Associate WordPress Pages with the following BuddyPress Registration pages.', 'buddypress' ); ?></p>
149
-
150
- <table class="form-table">
151
- <tbody>
152
-
153
- <?php foreach ( $static_pages as $name => $label ) : ?>
154
-
155
- <tr valign="top">
156
- <th scope="row">
157
- <label for="bp_pages[<?php echo esc_attr( $name ) ?>]"><?php echo esc_html( $label ) ?></label>
158
- </th>
159
-
160
- <td>
161
- <?php echo wp_dropdown_pages( array(
162
- 'name' => 'bp_pages[' . esc_attr( $name ) . ']',
163
- 'echo' => false,
164
- 'show_option_none' => __( '- None -', 'buddypress' ),
165
- 'selected' => !empty( $existing_pages[$name] ) ? $existing_pages[$name] : false
166
- ) ) ?>
167
-
168
- <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>
169
- <input class="button-primary" type="submit" name="bp-admin-pages-single" value="<?php _e( 'Save', 'buddypress' ) ?>" />
170
-
171
- <?php if ( !empty( $existing_pages[$name] ) ) : ?>
172
-
173
- <a href="<?php echo get_permalink( $existing_pages[$name] ); ?>" class="button-secondary" target="_bp"><?php _e( 'View', 'buddypress' ); ?></a>
174
-
175
- <?php endif; ?>
176
-
177
- </td>
178
- </tr>
179
-
180
- <?php endforeach ?>
181
-
182
- <?php do_action( 'bp_active_external_pages' ); ?>
183
-
184
- </tbody>
185
- </table>
186
-
187
- <?php
188
- endif;
189
- }
190
-
191
- /**
192
- * Handle saving of the BuddyPress slugs
193
- *
194
- * @since BuddyPress (1.6)
195
- * @todo Use settings API
196
- * @return False if referer does not check out
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
-
204
- // Then, update the directory pages
205
- if ( isset( $_POST['bp_pages'] ) ) {
206
-
207
- $directory_pages = array();
208
-
209
- foreach ( (array) $_POST['bp_pages'] as $key => $value ) {
210
- if ( !empty( $value ) ) {
211
- $directory_pages[$key] = (int) $value;
212
- }
213
- }
214
- bp_core_update_directory_page_ids( $directory_pages );
215
- }
216
-
217
- $base_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings', 'updated' => 'true' ), 'admin.php' ) );
218
-
219
- wp_redirect( $base_url );
220
- }
221
- }
222
- add_action( 'admin_init', 'bp_core_admin_slugs_setup_handler' );
223
-
224
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-core/admin/bp-core-update.php CHANGED
@@ -1,28 +1,44 @@
1
  <?php
2
-
3
  // Exit if accessed directly
4
  if ( !defined( 'ABSPATH' ) ) exit;
5
 
6
  class BP_Core_Setup_Wizard {
7
-
8
- /**
9
- * @var int The current step of the updater
10
- */
11
  var $current_step;
12
-
13
- /**
14
- *
15
- * @var array The total steps to be completed
16
- */
17
  var $steps;
18
 
19
- /** Methods ***************************************************************/
 
 
 
 
 
 
 
20
 
21
  function __construct() {
 
 
 
 
 
22
 
23
- // Set/reset the wizard cookie
24
- setcookie( 'bp-wizard-step', 0, time() + 60 * 60 * 24, COOKIEPATH );
25
- $_COOKIE['bp-wizard-step'] = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  // Call the save method that will save data and modify $current_step
28
  if ( isset( $_POST['save'] ) )
@@ -34,25 +50,24 @@ class BP_Core_Setup_Wizard {
34
 
35
  function current_step() {
36
  if ( isset( $_POST['step'] ) ) {
37
- $current_step = (int) $_POST['step'] + 1;
38
  } else {
39
- if ( !empty( $_COOKIE['bp-wizard-step'] ) ) {
40
  $current_step = $_COOKIE['bp-wizard-step'];
41
- } else {
42
  $current_step = 0;
43
- }
44
  }
45
 
46
  return $current_step;
47
  }
48
 
49
  function add_steps() {
 
50
 
51
  // Setup wizard steps
52
  $steps = array();
53
 
54
- // This is a first time installation
55
- if ( bp_get_maintenance_mode() == 'install' ) {
56
  $steps = array(
57
  __( 'Components', 'buddypress' ),
58
  __( 'Pages', 'buddypress' ),
@@ -61,22 +76,19 @@ class BP_Core_Setup_Wizard {
61
  __( 'Finish', 'buddypress' )
62
  );
63
 
64
- // This is an update to an existing install
65
  } else {
 
 
66
 
67
- // New for BP 1.5
68
- if ( bp_get_db_version_raw() < 1801 || !bp_core_get_directory_page_ids() ) {
 
 
69
  $steps[] = __( 'Components', 'buddypress' );
70
- $steps[] = __( 'Pages', 'buddypress' );
71
  }
72
 
73
- // New for BP 1.6
74
- if ( bp_get_db_version_raw() < 5222 && !defined( 'BP_USE_WP_ADMIN_BAR' ) )
75
- $steps[] = __( 'Toolbar', 'buddypress' );
76
-
77
- if ( bp_get_db_version_raw() < (int) bp_get_db_version() )
78
- $steps[] = __( 'Database Update', 'buddypress' );
79
-
80
  $steps[] = __( 'Finish', 'buddypress' );
81
  }
82
 
@@ -85,58 +97,56 @@ class BP_Core_Setup_Wizard {
85
 
86
  function save( $step_name ) {
87
 
88
- // Bail if user is not capable of being here
89
- if ( ! bp_current_user_can( 'activate_plugins' ) )
90
- wp_die( 'Uh... No.' );
91
-
92
  // Save any posted values
93
  switch ( $step_name ) {
94
- case 'db_update':
95
  $result = $this->step_db_update_save();
96
  break;
97
 
98
- case 'components':
 
 
 
 
 
 
 
 
99
  $result = $this->step_components_save();
100
  break;
101
 
102
- case 'pages':
103
  $result = $this->step_pages_save();
104
  break;
105
 
106
- case 'permalinks':
107
  $result = $this->step_permalinks_save();
108
  break;
109
 
110
- case 'theme':
111
  $result = $this->step_theme_save();
112
  break;
113
 
114
- case 'admin_bar':
115
- $result = $this->step_admin_bar_save();
116
- break;
117
-
118
- case 'finish':
119
- default:
120
  $result = $this->step_finish_save();
121
  break;
122
  }
123
 
 
 
 
124
  if ( 'finish' != $step_name )
125
- setcookie( 'bp-wizard-step', (int) $this->current_step(), time() + 60 * 60 * 24, COOKIEPATH );
126
  }
127
 
128
  function html() {
129
 
130
- // Bail if user is not capable of being here
131
- if ( ! bp_current_user_can( 'activate_plugins' ) )
132
- wp_die( 'You do not have sufficient permissions to access this page.' );
133
-
134
  // Update or Setup
135
- $type = ( 'update' == bp_get_maintenance_mode() ) ? __( 'Update', 'buddypress' ) : __( 'Setup', 'buddypress' );
136
 
137
  ?>
138
 
139
- <div class="wrap" id="bp-wizard">
140
 
141
  <?php screen_icon( 'buddypress' ); ?>
142
 
@@ -146,18 +156,18 @@ class BP_Core_Setup_Wizard {
146
  do_action( 'bp_admin_notices' );
147
 
148
  $step_count = count( $this->steps ) - 1;
149
- $wiz_or_set = $this->current_step() >= $step_count ? 'bp-components' : 'bp-wizard';
150
- $form_action = bp_core_do_network_admin() ? network_admin_url( add_query_arg( array( 'page' => $wiz_or_set ), 'admin.php' ) ) : admin_url( add_query_arg( array( 'page' => $wiz_or_set ), 'index.php' ) );
151
  ?>
152
 
153
- <form action="<?php echo $form_action; ?>" method="post" id="bp-wizard-form">
154
- <div id="bp-wizard-nav">
155
  <ol>
156
 
157
- <?php foreach( (array) $this->steps as $i => $name ) : ?>
158
 
159
- <li<?php if ( $this->current_step() == $i ) : ?> class="current"<?php endif; ?>>
160
- <?php if ( $this->current_step() > $i ) : ?>
161
 
162
  <span class="complete">&nbsp;</span>
163
 
@@ -175,7 +185,7 @@ class BP_Core_Setup_Wizard {
175
 
176
  </ol>
177
 
178
- <?php if ( __( 'Finish', 'buddypress' ) == $this->steps[$this->current_step()] ) : ?>
179
 
180
  <div class="prev-next submit clear">
181
  <input type="submit" value="<?php _e( 'Finish &amp; Activate', 'buddypress' ); ?>" name="submit" />
@@ -191,13 +201,21 @@ class BP_Core_Setup_Wizard {
191
 
192
  </div>
193
 
194
- <div id="bp-wizard-content">
195
 
196
- <?php switch ( $this->steps[$this->current_step()] ) {
197
  case __( 'Database Update', 'buddypress') :
198
  $this->step_db_update();
199
  break;
200
 
 
 
 
 
 
 
 
 
201
  case __( 'Components', 'buddypress') :
202
  $this->step_components();
203
  break;
@@ -214,13 +232,10 @@ class BP_Core_Setup_Wizard {
214
  $this->step_theme();
215
  break;
216
 
217
- case __( 'Toolbar', 'buddypress' ) :
218
- $this->step_admin_bar();
219
- break;
220
-
221
  case __( 'Finish', 'buddypress') :
222
  $this->step_finish();
223
  break;
 
224
  } ?>
225
 
226
  </div>
@@ -233,13 +248,14 @@ class BP_Core_Setup_Wizard {
233
  /** Screen methods ********************************************************/
234
 
235
  function step_db_update() {
236
- ?>
 
237
 
238
- <p><?php _e( 'To complete the update, a few changes need to be made to your database. These changes are not destructive and will not remove or change any existing settings.', 'buddypress' ); ?></p>
239
 
240
  <div class="submit clear">
241
  <input type="hidden" name="save" value="db_update" />
242
- <input type="hidden" name="step" value="<?php echo esc_attr( $this->current_step() ); ?>" />
243
 
244
  <?php wp_nonce_field( 'bpwizard_db_update' ) ?>
245
 
@@ -248,18 +264,104 @@ class BP_Core_Setup_Wizard {
248
  <?php
249
  }
250
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
  function step_components() {
 
 
252
 
253
- if ( !function_exists( 'bp_core_admin_components_options' ) )
254
- require ( BP_PLUGIN_DIR . 'bp-core/admin/bp-core-components.php' ); ?>
255
 
256
  <p><?php _e( "BuddyPress bundles several individual social components together, each one adding a distinct feature. This first step decides which features are enabled on your site; all features are enabled by default. Don't worry, you can change your mind at any point in the future.", 'buddypress' ); ?></p>
257
 
258
- <?php bp_core_admin_components_options(); ?>
259
 
260
  <div class="submit clear">
261
  <input type="hidden" name="save" value="components" />
262
- <input type="hidden" name="step" value="<?php echo esc_attr( $this->current_step() ); ?>" />
263
 
264
  <?php wp_nonce_field( 'bpwizard_components' ); ?>
265
 
@@ -276,14 +378,16 @@ class BP_Core_Setup_Wizard {
276
  if ( !empty( $wpdb->blogid ) && ( $wpdb->blogid != bp_get_root_blog_id() ) && ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) )
277
  switch_to_blog( bp_get_root_blog_id() );
278
 
279
- $existing_pages = bp_core_get_directory_page_ids();
 
 
 
280
 
281
  // Provide empty indexes to avoid PHP errors with wp_dropdown_pages()
282
  $indexes = array( 'members', 'activity', 'groups', 'forums', 'blogs', 'register', 'activate' );
283
  foreach ( $indexes as $index ) {
284
- if ( !isset( $existing_pages[$index] ) ) {
285
  $existing_pages[$index] = '';
286
- }
287
  }
288
 
289
  if ( !empty( $existing_pages['blogs'] ) )
@@ -325,9 +429,11 @@ class BP_Core_Setup_Wizard {
325
  });
326
  </script>
327
 
328
- <p><?php _e( 'BuddyPress uses WordPress pages to display directories. This allows you to easily change their titles and relocate them.', 'buddypress' ); ?></p>
 
 
329
 
330
- <p><?php _e( 'Choose an existing page, have one auto-created, or create them manually and come back here once you are finished.', 'buddypress' ); ?></p>
331
 
332
  <table class="form-table">
333
 
@@ -338,83 +444,66 @@ class BP_Core_Setup_Wizard {
338
  </th>
339
  <td>
340
  <p><label><input type="radio" name="bp_pages[members]" <?php checked( empty( $existing_pages['members'] ) ); ?> value="<?php echo $members_slug; ?>" /> <?php _e( 'Automatically create a page at:', 'buddypress' ) ?> <?php echo home_url( $members_slug ); ?>/</label></p>
341
-
342
- <?php if ( $members_page_dropdown = wp_dropdown_pages( "name=bp-members-page&echo=0&selected={$existing_pages['members']}&show_option_none=" . __( '- Select -', 'buddypress' ) ) ) : ?>
343
-
344
- <p><label><input type="radio" name="bp_pages[members]" <?php checked( !empty( $existing_pages['members'] ) ); ?> value="page" /> <?php _e( 'Use an existing page:', 'buddypress' ); ?> <?php echo $members_page_dropdown ?></label></p>
345
-
346
- <?php endif ?>
347
  </td>
348
  </tr>
349
 
350
- <?php if ( isset( $active_components['groups'] ) ) : ?>
351
 
352
  <tr valign="top">
353
  <th scope="row">
354
- <h5><?php _e( 'Groups', 'buddypress' ); ?></h5>
355
- <p><?php _e( 'Displays individual groups as well as a directory of groups.', 'buddypress' ); ?></p>
356
  </th>
357
  <td>
358
- <p><label><input type="radio" name="bp_pages[groups]" <?php checked( empty( $existing_pages['groups'] ) ); ?> value="<?php echo $groups_slug; ?>" /> <?php _e( 'Automatically create a page at:', 'buddypress' ); ?> <?php echo home_url( $groups_slug ); ?>/</label></p>
359
-
360
- <?php if ( $groups_page_dropdown = wp_dropdown_pages( "name=bp-groups-page&echo=0&selected={$existing_pages['groups']}&show_option_none=" . __( '- Select -', 'buddypress' ) ) ) : ?>
361
- <p><label><input type="radio" name="bp_pages[groups]" <?php checked( !empty( $existing_pages['groups'] ) ); ?> value="page" /> <?php _e( 'Use an existing page:', 'buddypress' ); ?> <?php echo $groups_page_dropdown ?></label></p>
362
- <?php endif ?>
363
  </td>
364
  </tr>
365
 
366
  <?php endif; ?>
367
 
368
- <?php /* The Blogs component only needs a directory page when Multisite is enabled */ ?>
369
- <?php if ( is_multisite() && isset( $active_components['blogs'] ) ) : ?>
370
 
371
  <tr valign="top">
372
  <th scope="row">
373
- <h5><?php _e( 'Blogs', 'buddypress' ); ?></h5>
374
- <p><?php _e( 'Displays a directory of the blogs in your network.', 'buddypress' ); ?></p>
375
  </th>
376
  <td>
377
- <p><label><input type="radio" name="bp_pages[blogs]" <?php checked( empty( $existing_pages['blogs'] ) ); ?> value="<?php echo $blogs_slug; ?>" /> <?php _e( 'Automatically create a page at:', 'buddypress' ); ?> <?php echo home_url( $blogs_slug ); ?>/</label></p>
378
-
379
- <?php if ( $blogs_page_dropdown = wp_dropdown_pages( "name=bp-blogs-page&echo=0&selected={$existing_pages['blogs']}&show_option_none=" . __( '- Select -', 'buddypress' ) ) ) : ?>
380
- <p><label><input type="radio" name="bp_pages[blogs]" <?php checked( !empty( $existing_pages['blogs'] ) ); ?> value="page" /> <?php _e( 'Use an existing page:', 'buddypress' ); ?> <?php echo $blogs_page_dropdown ?></label></p>
381
- <?php endif ?>
382
  </td>
383
  </tr>
384
 
385
  <?php endif; ?>
386
 
387
- <?php if ( isset( $active_components['activity'] ) ) : ?>
388
 
389
  <tr valign="top">
390
  <th scope="row">
391
- <h5><?php _e( 'Activity', 'buddypress' ); ?></h5>
392
- <p><?php _e( "Displays the activity for the entire site, a member's friends, groups and @mentions.", 'buddypress' ); ?></p>
393
  </th>
394
  <td>
395
- <p><label><input type="radio" name="bp_pages[activity]" <?php checked( empty( $existing_pages['activity'] ) ); ?> value="<?php echo $activity_slug; ?>" /> <?php _e( 'Automatically create a page at:', 'buddypress' ); ?> <?php echo home_url( $activity_slug ); ?>/</label></p>
396
-
397
- <?php if ( $activity_page_dropdown = wp_dropdown_pages( "name=bp-activity-page&echo=0&selected={$existing_pages['activity']}&show_option_none=" . __( '- Select -', 'buddypress' ) ) ) : ?>
398
- <p><label><input type="radio" name="bp_pages[activity]" <?php checked( !empty( $existing_pages['activity'] ) ); ?> value="page" /> <?php _e( 'Use an existing page:', 'buddypress' ); ?> <?php echo $activity_page_dropdown ?></label></p>
399
- <?php endif ?>
400
  </td>
401
  </tr>
402
 
403
  <?php endif; ?>
404
 
405
- <?php if ( isset( $active_components['forums'] ) ) : ?>
 
406
 
407
  <tr valign="top">
408
  <th scope="row">
409
- <h5><?php _e( 'Forums', 'buddypress' ); ?></h5>
410
- <p><?php _e( 'Displays a directory of public forum topics.', 'buddypress' ); ?></p>
411
  </th>
412
  <td>
413
- <p><label><input type="radio" name="bp_pages[forums]" <?php checked( empty( $existing_pages['forums'] ) ); ?> value="<?php echo $forums_slug; ?>" /> <?php _e( 'Automatically create a page at:', 'buddypress' ); ?> <?php echo home_url( $forums_slug ); ?>/</label></p>
414
-
415
- <?php if ( $forums_page_dropdown = wp_dropdown_pages( "name=bp-forums-page&echo=0&selected={$existing_pages['forums']}&show_option_none=" . __( '- Select -', 'buddypress' ) ) ) : ?>
416
- <p><label><input type="radio" name="bp_pages[forums]" <?php checked( !empty( $existing_pages['forums'] ) ); ?> value="page" /> <?php _e( 'Use an existing page:', 'buddypress' ); ?> <?php echo $forums_page_dropdown ?></label></p>
417
- <?php endif ?>
418
  </td>
419
  </tr>
420
 
@@ -427,10 +516,7 @@ class BP_Core_Setup_Wizard {
427
  </th>
428
  <td>
429
  <p><label><input type="radio" name="bp_pages[register]" <?php checked( empty( $existing_pages['register'] ) ); ?> value="<?php echo $register_slug; ?>" /> <?php _e( 'Automatically create a page at:', 'buddypress' ) ?> <?php echo home_url( $register_slug ) ?>/</label></p>
430
-
431
- <?php if ( $register_page_dropdown = wp_dropdown_pages( "name=bp-register-page&echo=0&selected={$existing_pages['register']}&show_option_none=" . __( '- Select -', 'buddypress' ) ) ) : ?>
432
- <p><label><input type="radio" name="bp_pages[register]" <?php checked( !empty( $existing_pages['register'] ) ); ?> value="page" /> <?php _e( 'Use an existing page:', 'buddypress' ); ?> <?php echo $register_page_dropdown ?></label></p>
433
- <?php endif ?>
434
  </td>
435
  </tr>
436
 
@@ -441,17 +527,14 @@ class BP_Core_Setup_Wizard {
441
  </th>
442
  <td>
443
  <p><label><input type="radio" name="bp_pages[activate]" <?php checked( empty( $existing_pages['activate'] ) ); ?> value="<?php echo $activation_slug; ?>" /> <?php _e( 'Automatically create a page at:', 'buddypress' ); ?> <?php echo home_url( $activation_slug ); ?>/</label></p>
444
-
445
- <?php if ( $activate_page_dropdown = wp_dropdown_pages( "name=bp-activate-page&echo=0&selected={$existing_pages['activate']}&show_option_none=" . __( '- Select -', 'buddypress' ) ) ) : ?>
446
- <p><label><input type="radio" name="bp_pages[activate]" <?php checked( !empty( $existing_pages['activate'] ) ); ?> value="page" /> <?php _e( 'Use an existing page:', 'buddypress' ); ?> <?php echo $activate_page_dropdown ?></label></p>
447
- <?php endif ?>
448
  </td>
449
  </tr>
450
  </table>
451
 
452
  <div class="submit clear">
453
  <input type="hidden" name="save" value="pages" />
454
- <input type="hidden" name="step" value="<?php echo esc_attr( $this->current_step() ); ?>" />
455
 
456
  <?php wp_nonce_field( 'bpwizard_pages' ); ?>
457
 
@@ -463,22 +546,25 @@ class BP_Core_Setup_Wizard {
463
  }
464
 
465
  function step_permalinks() {
 
 
466
 
467
  $prefix = '';
468
- $permalink_structure = bp_get_option( 'permalink_structure' );
 
469
  $structures = array( '', $prefix . '/%year%/%monthnum%/%day%/%postname%/', $prefix . '/%year%/%monthnum%/%postname%/', $prefix . '/archives/%post_id%' );
470
 
471
  // If we're using permalinks already, adjust text accordingly
472
- if ( !empty( $permalink_structure ) )
473
- $permalink_setup_text = __( 'Your permalink settings are compatible with BuddyPress.', 'buddypress' );
474
  else
475
- $permalink_setup_text = __( 'Pretty permalinks must be active on your site.', 'buddypress' );
476
 
477
  if ( !got_mod_rewrite() && !iis7_supports_permalinks() )
478
  $prefix = '/index.php'; ?>
479
 
480
  <p><?php echo $permalink_setup_text; ?></p>
481
- <p><?php printf( __( 'For more advanced options please visit the <a href="%s">permalink settings page</a> now and come back here later.', 'buddypress' ), admin_url( 'options-permalink.php' ) ); ?>
482
 
483
  <table class="form-table">
484
  <tr>
@@ -497,7 +583,7 @@ class BP_Core_Setup_Wizard {
497
 
498
  <div class="submit clear">
499
  <input type="hidden" name="save" value="permalinks" />
500
- <input type="hidden" name="step" value="<?php echo esc_attr( $this->current_step() ); ?>" />
501
 
502
  <?php if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && empty( $_POST['skip-htaccess'] ) ) : ?>
503
 
@@ -513,23 +599,30 @@ class BP_Core_Setup_Wizard {
513
  }
514
 
515
  function step_theme() {
516
- global $bp;
 
517
 
518
  $installed_plugins = get_plugins();
519
- $installed_themes = wp_get_themes();
520
- $bp_themes = array();
 
 
 
 
 
521
 
522
  $template_pack_installed = false;
 
523
  $bp_theme_installed = false;
524
 
525
- foreach ( (array) $installed_plugins as $plugin ) {
526
  if ( 'BuddyPress Template Pack' == $plugin['Name'] ) {
527
  $template_pack_installed = true;
528
  }
529
  }
530
 
531
- foreach ( (array) $installed_themes as $theme ) {
532
- foreach ( (array) $theme['Tags'] as $tag ) {
533
  if ( ( 'BuddyPress Default' != $theme['Name'] ) && ( 'buddypress' == $tag ) ) {
534
  $bp_theme_installed = true;
535
  $bp_themes[] = $theme;
@@ -538,12 +631,17 @@ class BP_Core_Setup_Wizard {
538
  }
539
 
540
  // Get theme screenshot
541
- $current_theme = wp_get_theme();
 
 
 
 
 
542
  $screenshot = '';
543
 
544
- if ( !empty( $installed_themes[$current_theme->stylesheet]['Screenshot'] ) ) {
545
- $screenshot = trailingslashit( get_stylesheet_directory_uri() ) . $installed_themes[$current_theme->stylesheet]['Screenshot'];
546
- } ?>
547
 
548
  <script type="text/javascript">
549
  jQuery( document ).ready( function() {
@@ -553,28 +651,29 @@ class BP_Core_Setup_Wizard {
553
  });
554
  </script>
555
 
 
 
556
  <table class="form-table">
557
  <tr>
558
  <th>
559
  <h5><?php _e( 'Use BuddyPress Default', 'buddypress' ); ?></h5>
560
- <img src="<?php echo plugins_url( 'bp-themes/bp-default/screenshot.png', $bp->file ); ?>" alt="<?php _e( 'BuddyPress Default', 'buddypress' ); ?>" />
561
  </th>
562
  <td>
563
- <p><?php _e( 'The default BuddyPress theme comes with the basics, to get up and running out of the box. It supports all features and is highly customizable.', 'buddypress' ); ?></p>
564
- <p><strong><?php _e( 'This is the best choice if you want to start using BuddyPress immediately.', 'buddypress' ); ?></strong></p>
565
  <p><label><input type="radio" name="theme" value="bp_default" checked="checked" /> <?php _e( 'Yes, please!', 'buddypress' ); ?></label></p>
566
  </td>
567
  </tr>
568
 
569
- <?php if ( !empty( $bp_theme_installed ) ) : ?>
570
-
571
  <tr>
572
  <th>
573
  <h5><?php _e( 'Other themes', 'buddypress' ); ?></h5>
574
- <img src="<?php echo plugins_url( 'bp-core/admin/images/find.png', $bp->file ); ?>" alt="<?php _e( 'A BuddyPress theme', 'buddypress' ); ?>" />
575
  </th>
576
  <td>
577
- <p><?php _e( "You have some other BuddyPress compatible themes available. Pick one of them from this list to use it.", 'buddypress' ); ?></p>
578
  <p>
579
  <label>
580
  <input type="radio" name="theme" value="3rd_party" /> <?php _e( 'Use this theme', 'buddypress' ); ?>
@@ -582,49 +681,38 @@ class BP_Core_Setup_Wizard {
582
  <select name="3rd_party_theme">
583
 
584
  <?php foreach( (array) $bp_themes as $theme ) : ?>
585
-
586
  <option value="<?php echo $theme['Template'] . ',' . $theme['Stylesheet']; ?>"><?php echo $theme['Name']; ?></option>
587
-
588
  <?php endforeach; ?>
589
 
590
  </select>
591
  </p>
592
  </td>
593
  </tr>
594
-
595
  <?php endif; ?>
596
 
597
- <?php if ( ! current_theme_supports( 'buddypress' ) ) : ?>
598
-
599
- <tr>
600
- <th>
601
- <h5><?php _e( 'Manually update current theme', 'buddypress' ); ?></h5>
602
-
603
- <?php if ( !empty( $screenshot ) ) : ?>
604
-
605
- <img src="<?php echo esc_url( $screenshot ); ?>" alt="<?php _e( 'Your existing theme', 'buddypress' ); ?>" />
606
-
607
- <?php endif; ?>
608
-
609
- </th>
610
- <td>
611
- <p><?php _e( 'The BuddyPress Template Pack will guide you through the process of manually editing your existing theme. It comes with a step-by-step guide and involves copying the BuddyPress template files into your theme. <strong>This option requires knowledge of CSS and HTML.</strong> You will need to tweak the new templates to match your existing theme.', 'buddypress' ); ?></p>
612
-
613
- <?php if ( empty( $template_pack_installed ) ) : ?>
614
 
615
- <p><a id="bp-template-pack" class="thickbox onclick button" href="<?php echo network_admin_url( 'plugin-install.php?tab=plugin-information&plugin=bp-template-pack&TB_iframe=true&width=640&height=500' ); ?>"><?php _e( 'Install BuddyPress Template Pack', 'buddypress' ); ?></a></p>
616
 
617
- <?php else : ?>
618
 
619
- <p><label><input type="radio" name="theme" value="manual_wp" /> <?php _e( 'Choose this option (go to Appearance &rarr; BP Compatibility after setup is complete)', 'buddypress' ); ?></label></p>
620
- <p><a id="bp-template-pack" class="button installed disabled" href="javascript:void();"><span></span><?php _e( 'Plugin Installed', 'buddypress' ); ?></a></p>
621
 
622
- <?php endif; ?>
 
623
 
624
- </td>
625
- </tr>
626
 
627
- <?php endif; ?>
 
628
 
629
  <tr>
630
  <th>
@@ -632,7 +720,7 @@ class BP_Core_Setup_Wizard {
632
  </th>
633
  <td>
634
  <p><?php _e( "You are happy with your current theme and plan on changing it later.", 'buddypress' ); ?></p>
635
- <p><strong><?php _e( 'This is the best choice if you have a custom theme already and want to manually integrate BuddyPress later.', 'buddypress' ); ?></strong></p>
636
 
637
  <p><label><input type="radio" name="theme" value="do_not_change" /> <?php _e( "Don't change my current theme", 'buddypress' ); ?></label></p>
638
 
@@ -642,7 +730,7 @@ class BP_Core_Setup_Wizard {
642
 
643
  <div class="submit clear">
644
  <input type="hidden" name="save" value="theme" />
645
- <input type="hidden" name="step" value="<?php echo esc_attr( $this->current_step() ) ?>" />
646
 
647
  <?php wp_nonce_field( 'bpwizard_theme' ) ?>
648
 
@@ -651,46 +739,18 @@ class BP_Core_Setup_Wizard {
651
  <?php
652
  }
653
 
654
- /**
655
- * When upgrading to BP 1.6, prompt the admin to switch to WordPress' Toolbar.
656
- *
657
- * @since 1.6
658
- */
659
- function step_admin_bar() {
660
- ?>
661
-
662
- <p><?php _e( "BuddyPress now uses the WordPress Toolbar; we've turbo-charged it by adding social items to help your users explore your site and manage their content.", 'buddypress' ); ?></p>
663
-
664
- <p><?php _e( "We've noticed that your site uses the old bar from earlier versions of BuddyPress.", 'buddypress' ); ?></p>
665
-
666
- <p>
667
- <label>
668
- <input type="checkbox" name="keep_buddybar" value="1" />
669
- <?php _e( "If you'd prefer to not switch to the WordPress Toolbar just yet, check this box. Don't worry, you can change your mind later.", 'buddypress' ); ?>
670
- </label>
671
- </p>
672
-
673
- <div class="submit clear">
674
- <input type="hidden" name="save" value="admin_bar" />
675
- <input type="hidden" name="step" value="<?php echo esc_attr( $this->current_step() ); ?>" />
676
-
677
- <?php wp_nonce_field( 'bpwizard_admin_bar' ) ?>
678
-
679
- </div>
680
-
681
- <?php
682
- }
683
-
684
  function step_finish() {
 
 
685
 
686
  // What type of action is happening here?
687
- $type = ( bp_get_maintenance_mode() == 'install' ) ? __( 'setup', 'buddypress' ) : __( 'update', 'buddypress' ); ?>
688
 
689
- <p><?php printf( __( "The BuddyPress %1\$s is complete, and your site is ready to go!", 'buddypress' ), $type ); ?></p>
690
 
691
  <div class="submit clear">
692
  <input type="hidden" name="save" value="finish" />
693
- <input type="hidden" name="step" value="<?php echo esc_attr( $this->current_step() ); ?>" />
694
 
695
  <?php wp_nonce_field( 'bpwizard_finish' ); ?>
696
 
@@ -702,6 +762,7 @@ class BP_Core_Setup_Wizard {
702
  /** Save Step Methods *****************************************************/
703
 
704
  function step_db_update_save() {
 
705
 
706
  if ( isset( $_POST['submit'] ) ) {
707
  check_admin_referer( 'bpwizard_db_update' );
@@ -709,13 +770,12 @@ class BP_Core_Setup_Wizard {
709
  // Run the schema install to update tables
710
  bp_core_install();
711
 
712
- // Update to 1.5
713
- if ( bp_get_db_version_raw() < 1801 )
714
  $this->update_1_5();
715
 
716
- // Update to 1.6
717
- if ( bp_get_db_version_raw() < bp_get_db_version() )
718
- $this->update_1_6();
719
 
720
  return true;
721
  }
@@ -723,18 +783,62 @@ class BP_Core_Setup_Wizard {
723
  return false;
724
  }
725
 
726
- function step_components_save() {
 
727
 
728
- if ( isset( $_POST['submit'] ) && isset( $_POST['bp_components'] ) ) {
 
729
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
730
  check_admin_referer( 'bpwizard_components' );
731
 
732
  $active_components = array();
733
 
734
  // Settings form submitted, now save the settings.
735
- foreach ( (array) $_POST['bp_components'] as $key => $value ) {
736
  $active_components[$key] = 1;
737
- }
738
 
739
  bp_update_option( 'bp-active-components', $active_components );
740
 
@@ -758,13 +862,12 @@ class BP_Core_Setup_Wizard {
758
  switch_to_blog( bp_get_root_blog_id() );
759
 
760
  // Delete any existing pages
761
- $existing_pages = bp_core_get_directory_page_ids();
762
 
763
- foreach ( (array) $existing_pages as $page_id ) {
764
  wp_delete_post( $page_id, true );
765
- }
766
 
767
- $blog_pages = $this->setup_pages( (array) $_POST['bp_pages'] );
768
  bp_update_option( 'bp-pages', $blog_pages );
769
 
770
  if ( !empty( $wpdb->blogid ) && ( $wpdb->blogid != bp_get_root_blog_id() ) && ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) )
@@ -878,8 +981,6 @@ class BP_Core_Setup_Wizard {
878
  }
879
 
880
  function step_theme_save() {
881
- global $bp;
882
-
883
  if ( isset( $_POST['submit'] ) && isset( $_POST['theme'] ) ) {
884
  check_admin_referer( 'bpwizard_theme' );
885
 
@@ -890,7 +991,6 @@ class BP_Core_Setup_Wizard {
890
 
891
  // Activate the bp-default theme
892
  case 'bp_default' :
893
- register_theme_directory( $bp->themes_dir );
894
  switch_theme( 'bp-default', 'bp-default' );
895
  break;
896
 
@@ -932,60 +1032,41 @@ class BP_Core_Setup_Wizard {
932
  return false;
933
  }
934
 
935
- /**
936
- * When upgrading to BP 1.6, the admin is prompted to switch to WordPress' Toolbar.
937
- * If they choose not to, record that preference in the options table.
938
- *
939
- * @since 1.6
940
- */
941
- function step_admin_bar_save() {
942
- if ( isset( $_POST['submit'] ) ) {
943
- check_admin_referer( 'bpwizard_admin_bar' );
944
-
945
- if ( !empty( $_POST['keep_buddybar'] ) ) {
946
- bp_update_option( '_bp_force_buddybar', 1 );
947
- }
948
-
949
- return true;
950
- }
951
-
952
- return false;
953
- }
954
-
955
  function step_finish_save() {
956
-
957
  if ( isset( $_POST['submit'] ) ) {
958
-
959
  check_admin_referer( 'bpwizard_finish' );
960
 
961
  // Update the DB version in the database
962
- bp_version_bump();
 
 
963
 
964
  // Delete the setup cookie
965
  @setcookie( 'bp-wizard-step', '', time() - 3600, COOKIEPATH );
966
 
 
 
 
 
 
 
967
  // Redirect to the BuddyPress dashboard
968
- $redirect = bp_core_do_network_admin() ? network_admin_url( 'settings.php' ) : admin_url( 'options-general.php' );
969
- $redirect = add_query_arg( array( 'page' => 'bp-components' ), $redirect );
970
 
971
- wp_safe_redirect( $redirect );
972
 
973
- // That's all!
974
- exit();
975
  }
976
 
977
  return false;
978
  }
979
 
980
  function setup_pages( $pages ) {
981
-
982
- $bp_pages = array();
983
-
984
  foreach ( $pages as $key => $value ) {
985
  if ( 'page' == $value ) {
986
  // Check for the selected page
987
  if ( !empty( $_POST['bp-' . $key . '-page'] ) )
988
- $bp_pages[$key] = (int) $_POST['bp-' . $key . '-page'];
989
  else
990
  $bp_pages[$key] = wp_insert_post( array( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_title' => ucwords( $key ), 'post_status' => 'publish', 'post_type' => 'page' ) );
991
  } else {
@@ -999,7 +1080,6 @@ class BP_Core_Setup_Wizard {
999
 
1000
  // Database update methods based on version numbers
1001
  function update_1_5() {
1002
-
1003
  // Delete old database version options
1004
  delete_site_option( 'bp-activity-db-version' );
1005
  delete_site_option( 'bp-blogs-db-version' );
@@ -1009,22 +1089,6 @@ class BP_Core_Setup_Wizard {
1009
  delete_site_option( 'bp-xprofile-db-version' );
1010
  }
1011
 
1012
- // Database update methods based on version numbers
1013
- function update_1_6() {
1014
-
1015
- // Delete possible site options
1016
- delete_site_option( 'bp-db-version' );
1017
- delete_site_option( '_bp_db_version' );
1018
- delete_site_option( 'bp-core-db-version' );
1019
- delete_site_option( '_bp-core-db-version' );
1020
-
1021
- // Delete possible blog options
1022
- delete_blog_option( bp_get_root_blog_id(), 'bp-db-version' );
1023
- delete_blog_option( bp_get_root_blog_id(), 'bp-core-db-version' );
1024
- delete_site_option( bp_get_root_blog_id(), '_bp-core-db-version' );
1025
- delete_site_option( bp_get_root_blog_id(), '_bp_db_version' );
1026
- }
1027
-
1028
  /**
1029
  * Reset the cookie so the install script starts over
1030
  */
@@ -1033,19 +1097,258 @@ class BP_Core_Setup_Wizard {
1033
  }
1034
  }
1035
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1036
  /**
1037
- * Get the wizard
1038
  *
1039
- * @global type $bp
1040
- * @return boolean
 
 
1041
  */
1042
- function bp_get_wizard() {
1043
- global $bp;
1044
 
1045
- if ( !empty( $bp->admin->wizard ) )
1046
- return $bp->admin->wizard;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1047
 
1048
- return false;
1049
  }
 
 
1050
 
1051
- ?>
1
  <?php
 
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
5
  class BP_Core_Setup_Wizard {
 
 
 
 
6
  var $current_step;
 
 
 
 
 
7
  var $steps;
8
 
9
+ var $database_version;
10
+ var $is_network_activate;
11
+ var $new_version;
12
+ var $setup_type;
13
+
14
+ function bp_core_setup_wizard() {
15
+ $this->__construct();
16
+ }
17
 
18
  function __construct() {
19
+ global $bp;
20
+
21
+ // Ensure that we have access to some utility functions. Must use require_once()
22
+ // because BP Core is loaded during incremental upgrades
23
+ require_once( BP_PLUGIN_DIR . '/bp-core/bp-core-functions.php' );
24
 
25
+ // Get current DB version
26
+ $this->database_version = !empty( $bp->database_version ) ? (int) $bp->database_version : 0;
27
+
28
+ if ( !empty( $bp->is_network_activate ) ) {
29
+ $this->is_network_activate = $bp->is_network_activate;
30
+
31
+ } elseif ( !$this->current_step() ) {
32
+ setcookie( 'bp-wizard-step', 0, time() + 60 * 60 * 24, COOKIEPATH );
33
+ $_COOKIE['bp-wizard-step'] = 0;
34
+ }
35
+
36
+ $this->new_version = constant( 'BP_DB_VERSION' );
37
+ $this->setup_type = !empty( $bp->maintenance_mode ) ? $bp->maintenance_mode : '';
38
+ $this->current_step = $this->current_step();
39
+
40
+ // Remove the admin menu while we update/install
41
+ remove_action( bp_core_admin_hook(), 'bp_core_add_admin_menu', 9 );
42
 
43
  // Call the save method that will save data and modify $current_step
44
  if ( isset( $_POST['save'] ) )
50
 
51
  function current_step() {
52
  if ( isset( $_POST['step'] ) ) {
53
+ $current_step = (int)$_POST['step'] + 1;
54
  } else {
55
+ if ( !empty( $_COOKIE['bp-wizard-step'] ) )
56
  $current_step = $_COOKIE['bp-wizard-step'];
57
+ else
58
  $current_step = 0;
 
59
  }
60
 
61
  return $current_step;
62
  }
63
 
64
  function add_steps() {
65
+ global $wp_rewrite;
66
 
67
  // Setup wizard steps
68
  $steps = array();
69
 
70
+ if ( 'install' == $this->setup_type ) {
 
71
  $steps = array(
72
  __( 'Components', 'buddypress' ),
73
  __( 'Pages', 'buddypress' ),
76
  __( 'Finish', 'buddypress' )
77
  );
78
 
79
+ // Update wizard steps
80
  } else {
81
+ if ( $this->is_network_activate )
82
+ $steps[] = __( 'Multisite Update', 'buddypress' );
83
 
84
+ if ( $this->database_version < (int) $this->new_version )
85
+ $steps[] = __( 'Database Update', 'buddypress' );
86
+
87
+ if ( $this->database_version < 1801 || !bp_core_get_directory_page_ids() ) {
88
  $steps[] = __( 'Components', 'buddypress' );
89
+ $steps[] = __( 'Pages', 'buddypress' );
90
  }
91
 
 
 
 
 
 
 
 
92
  $steps[] = __( 'Finish', 'buddypress' );
93
  }
94
 
97
 
98
  function save( $step_name ) {
99
 
 
 
 
 
100
  // Save any posted values
101
  switch ( $step_name ) {
102
+ case 'db_update': default:
103
  $result = $this->step_db_update_save();
104
  break;
105
 
106
+ case 'ms_update': default:
107
+ $result = $this->step_ms_update_save();
108
+ break;
109
+
110
+ case 'ms_pages': default:
111
+ $result = $this->step_ms_update_save();
112
+ break;
113
+
114
+ case 'components': default:
115
  $result = $this->step_components_save();
116
  break;
117
 
118
+ case 'pages': default:
119
  $result = $this->step_pages_save();
120
  break;
121
 
122
+ case 'permalinks': default:
123
  $result = $this->step_permalinks_save();
124
  break;
125
 
126
+ case 'theme': default:
127
  $result = $this->step_theme_save();
128
  break;
129
 
130
+ case 'finish': default:
 
 
 
 
 
131
  $result = $this->step_finish_save();
132
  break;
133
  }
134
 
135
+ if ( !$result && $this->current_step )
136
+ $this->current_step--;
137
+
138
  if ( 'finish' != $step_name )
139
+ setcookie( 'bp-wizard-step', (int)$this->current_step, time() + 60 * 60 * 24, COOKIEPATH );
140
  }
141
 
142
  function html() {
143
 
 
 
 
 
144
  // Update or Setup
145
+ $type = ( 'update' == $this->setup_type ) ? __( 'Update', 'buddypress' ) : __( 'Setup', 'buddypress' );
146
 
147
  ?>
148
 
149
+ <div class="wrap" id="bp-admin">
150
 
151
  <?php screen_icon( 'buddypress' ); ?>
152
 
156
  do_action( 'bp_admin_notices' );
157
 
158
  $step_count = count( $this->steps ) - 1;
159
+ $wiz_or_set = $this->current_step >= $step_count ? 'bp-general-settings' : 'bp-wizard';
160
+ $form_action = bp_core_update_do_network_admin() ? network_admin_url( add_query_arg( array( 'page' => $wiz_or_set ), 'admin.php' ) ) : admin_url( add_query_arg( array( 'page' => $wiz_or_set ), 'admin.php' ) );
161
  ?>
162
 
163
+ <form action="<?php echo $form_action; ?>" method="post" id="bp-admin-form">
164
+ <div id="bp-admin-nav">
165
  <ol>
166
 
167
+ <?php foreach( (array)$this->steps as $i => $name ) : ?>
168
 
169
+ <li<?php if ( $this->current_step == $i ) : ?> class="current"<?php endif; ?>>
170
+ <?php if ( $this->current_step > $i ) : ?>
171
 
172
  <span class="complete">&nbsp;</span>
173
 
185
 
186
  </ol>
187
 
188
+ <?php if ( __( 'Finish', 'buddypress' ) == $this->steps[$this->current_step] ) : ?>
189
 
190
  <div class="prev-next submit clear">
191
  <input type="submit" value="<?php _e( 'Finish &amp; Activate', 'buddypress' ); ?>" name="submit" />
201
 
202
  </div>
203
 
204
+ <div id="bp-admin-content">
205
 
206
+ <?php switch ( $this->steps[$this->current_step] ) {
207
  case __( 'Database Update', 'buddypress') :
208
  $this->step_db_update();
209
  break;
210
 
211
+ case __( 'Multisite Update', 'buddypress') :
212
+ $this->step_ms_update();
213
+ break;
214
+
215
+ case __( 'Site Directory', 'buddypress') :
216
+ $this->step_ms_update();
217
+ break;
218
+
219
  case __( 'Components', 'buddypress') :
220
  $this->step_components();
221
  break;
232
  $this->step_theme();
233
  break;
234
 
 
 
 
 
235
  case __( 'Finish', 'buddypress') :
236
  $this->step_finish();
237
  break;
238
+
239
  } ?>
240
 
241
  </div>
248
  /** Screen methods ********************************************************/
249
 
250
  function step_db_update() {
251
+ if ( !current_user_can( 'activate_plugins' ) )
252
+ return false; ?>
253
 
254
+ <p><?php _e( 'Before you can continue using BuddyPress, a few minor adjustments need to be made. These changes are not destructive and will not remove or change any existing settings.', 'buddypress' ); ?></p>
255
 
256
  <div class="submit clear">
257
  <input type="hidden" name="save" value="db_update" />
258
+ <input type="hidden" name="step" value="<?php echo esc_attr( $this->current_step ); ?>" />
259
 
260
  <?php wp_nonce_field( 'bpwizard_db_update' ) ?>
261
 
264
  <?php
265
  }
266
 
267
+ function step_ms_update() {
268
+ global $wpdb;
269
+
270
+ // Make sure that page info is pulled from bp_get_root_blog_id() (except when in
271
+ // multisite mode)
272
+ if ( !empty( $wpdb->blogid ) && ( $wpdb->blogid != bp_get_root_blog_id() ) && ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) )
273
+ switch_to_blog( bp_get_root_blog_id() );
274
+
275
+ if ( !current_user_can( 'activate_plugins' ) )
276
+ return false;
277
+
278
+ $active_components = bp_get_option( 'bp-active-components' );
279
+
280
+ if ( defined( 'BP_BLOGS_SLUG' ) )
281
+ $blogs_slug = constant( 'BP_BLOGS_SLUG' );
282
+ else
283
+ $blogs_slug = 'blogs';
284
+
285
+ // Call up old bp-pages to see if a page has been previously linked to Blogs
286
+ $existing_pages = bp_get_option( 'bp-pages' );
287
+
288
+ if ( !empty( $existing_pages['blogs'] ) )
289
+ $existing_blog_page = '&selected=' . $existing_pages['blogs'];
290
+ else
291
+ $existing_blog_page = '';
292
+ ?>
293
+
294
+ <script type="text/javascript">
295
+ jQuery( document ).ready( function() {
296
+ jQuery( 'select' ).change( function() {
297
+ jQuery( this ).siblings( 'input[@type=radio]' ).click();
298
+ });
299
+ });
300
+ </script>
301
+
302
+ <p><?php printf( __( 'BuddyPress has detected a recent change to WordPress Multisite, which allows members of your community to have their own WordPress sites. You can enable or disable this feature at any time at <a href="%s">Network Options</a>.', 'buddypress' ), network_admin_url( 'settings.php' ) ); ?></p>
303
+
304
+ <p><?php __( "Please select the WordPress page you would like to use to display the site directory. You can either choose an existing page or let BuddyPress auto-create a page for you. If you'd like, you can go to manually create pages now, and return to this step when you are finished.", 'buddypress' ) ?></p>
305
+
306
+ <p><strong><?php _e( 'Please Note:', 'buddypress' ) ?></strong> <?php _e( "If you have manually added BuddyPress navigation links in your theme you may need to remove these from your header.php to avoid duplicate links.", 'buddypress' ) ?></p>
307
+
308
+ <p><?php _e( 'Would you like to enable site tracking, which tracks blog posts and comments from across your network?', 'buddypress' ); ?></p>
309
+
310
+ <table class="form-table">
311
+
312
+ <tr valign="top">
313
+ <th scope="row"><?php _e( "Enable Site Tracking?", 'buddypress' ) ?></th>
314
+
315
+ <td>
316
+ <label for="bp_components[blogs]">
317
+ <input id="site-tracking-enabled" type="checkbox" id="bp_components[blogs]" name="bp_components[blogs]" value="1"<?php checked( isset( $active_components['blogs'] ) ); ?> />
318
+
319
+ <?php _e( "Track new sites, new posts and new comments across your entire network.", 'buddypress' ) ?>
320
+
321
+ </label>
322
+
323
+ </td>
324
+ </tr>
325
+
326
+ <tr valign="top" id="site-tracking-page-selector">
327
+ <th scope="row"><?php _e( 'Select a WordPress page for the Sites directory.', 'buddypress' ); ?></th>
328
+
329
+ <td>
330
+ <p><input type="radio" name="bp_pages[blogs]" checked="checked" value="<?php echo $blogs_slug; ?>" /> <?php _e( 'Automatically create a page at:', 'buddypress' ); ?> <?php echo site_url( $blogs_slug ); ?>/</p>
331
+ <p><input type="radio" name="bp_pages[blogs]" value="page" /> <?php _e( 'Use an existing page:', 'buddypress' ); ?> <?php echo wp_dropdown_pages( "name=bp-blogs-page&echo=0&show_option_none=" . __( '- Select -', 'buddypress' ) . $existing_blog_page ); ?></p>
332
+ </td>
333
+ </tr>
334
+
335
+ </table>
336
+
337
+
338
+ <div class="submit clear">
339
+ <input type="hidden" name="save" value="ms_update" />
340
+ <input type="hidden" name="step" value="<?php echo esc_attr( $this->current_step ); ?>" />
341
+
342
+ <?php wp_nonce_field( 'bpwizard_ms_update' ); ?>
343
+
344
+ </div>
345
+
346
+ <?php
347
+
348
+ restore_current_blog();
349
+ }
350
+
351
  function step_components() {
352
+ if ( !current_user_can( 'activate_plugins' ) )
353
+ return false;
354
 
355
+ if ( !function_exists( 'bp_core_admin_component_options' ) )
356
+ require ( WP_PLUGIN_DIR . '/buddypress/bp-core/admin/bp-core-admin.php' ); ?>
357
 
358
  <p><?php _e( "BuddyPress bundles several individual social components together, each one adding a distinct feature. This first step decides which features are enabled on your site; all features are enabled by default. Don't worry, you can change your mind at any point in the future.", 'buddypress' ); ?></p>
359
 
360
+ <?php bp_core_admin_component_options(); ?>
361
 
362
  <div class="submit clear">
363
  <input type="hidden" name="save" value="components" />
364
+ <input type="hidden" name="step" value="<?php echo esc_attr( $this->current_step ); ?>" />
365
 
366
  <?php wp_nonce_field( 'bpwizard_components' ); ?>
367
 
378
  if ( !empty( $wpdb->blogid ) && ( $wpdb->blogid != bp_get_root_blog_id() ) && ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) )
379
  switch_to_blog( bp_get_root_blog_id() );
380
 
381
+ if ( !current_user_can( 'activate_plugins' ) )
382
+ return false;
383
+
384
+ $existing_pages = bp_core_update_get_page_meta();
385
 
386
  // Provide empty indexes to avoid PHP errors with wp_dropdown_pages()
387
  $indexes = array( 'members', 'activity', 'groups', 'forums', 'blogs', 'register', 'activate' );
388
  foreach ( $indexes as $index ) {
389
+ if ( !isset( $existing_pages[$index] ) )
390
  $existing_pages[$index] = '';
 
391
  }
392
 
393
  if ( !empty( $existing_pages['blogs'] ) )
429
  });
430
  </script>
431
 
432
+ <p><?php _e( 'BuddyPress now uses WordPress pages to display content. This allows you to easily change the names of pages or move them to a sub page.', 'buddypress' ); ?></p>
433
+
434
+ <p><?php _e( 'Either choose an existing page or let BuddyPress auto-create pages for you. To manually create custom pages, come back to this step once you are finished.', 'buddypress' ); ?></p>
435
 
436
+ <p><strong><?php _e( 'Please Note:', 'buddypress' ); ?></strong> <?php _e( 'If you have manually added BuddyPress navigation links in your theme you may need to remove these from your header.php to avoid duplicate links.', 'buddypress' ); ?></p>
437
 
438
  <table class="form-table">
439
 
444
  </th>
445
  <td>
446
  <p><label><input type="radio" name="bp_pages[members]" <?php checked( empty( $existing_pages['members'] ) ); ?> value="<?php echo $members_slug; ?>" /> <?php _e( 'Automatically create a page at:', 'buddypress' ) ?> <?php echo home_url( $members_slug ); ?>/</label></p>
447
+ <p><label><input type="radio" name="bp_pages[members]" <?php checked( !empty( $existing_pages['members'] ) ); ?> value="page" /> <?php _e( 'Use an existing page:', 'buddypress' ); ?> <?php echo wp_dropdown_pages( "name=bp-members-page&echo=0&show_option_none=" . __( '- Select -', 'buddypress' ) . "&selected=" . $existing_pages['members'] ); ?></label></p>
 
 
 
 
 
448
  </td>
449
  </tr>
450
 
451
+ <?php if ( isset( $active_components['activity'] ) ) : ?>
452
 
453
  <tr valign="top">
454
  <th scope="row">
455
+ <h5><?php _e( 'Site Activity', 'buddypress' ); ?></h5>
456
+ <p><?php _e( "Displays the activity for the entire site, a member's friends, groups and @mentions.", 'buddypress' ); ?></p>
457
  </th>
458
  <td>
459
+ <p><label><input type="radio" name="bp_pages[activity]" <?php checked( empty( $existing_pages['activity'] ) ); ?> value="<?php echo $activity_slug; ?>" /> <?php _e( 'Automatically create a page at:', 'buddypress' ); ?> <?php echo home_url( $activity_slug ); ?>/</label></p>
460
+ <p><label><input type="radio" name="bp_pages[activity]" <?php checked( !empty( $existing_pages['activity'] ) ); ?> value="page" /> <?php _e( 'Use an existing page:', 'buddypress' ); ?> <?php echo wp_dropdown_pages( "name=bp-activity-page&echo=0&show_option_none=" . __( '- Select -', 'buddypress' ) . "&selected=" . $existing_pages['activity'] ); ?></label></p>
 
 
 
461
  </td>
462
  </tr>
463
 
464
  <?php endif; ?>
465
 
466
+ <?php if ( isset( $active_components['groups'] ) ) : ?>
 
467
 
468
  <tr valign="top">
469
  <th scope="row">
470
+ <h5><?php _e( 'Groups', 'buddypress' ); ?></h5>
471
+ <p><?php _e( 'Displays individual groups as well as a directory of groups.', 'buddypress' ); ?></p>
472
  </th>
473
  <td>
474
+ <p><label><input type="radio" name="bp_pages[groups]" <?php checked( empty( $existing_pages['groups'] ) ); ?> value="<?php echo $groups_slug; ?>" /> <?php _e( 'Automatically create a page at:', 'buddypress' ); ?> <?php echo home_url( $groups_slug ); ?>/</label></p>
475
+ <p><label><input type="radio" name="bp_pages[groups]" <?php checked( !empty( $existing_pages['groups'] ) ); ?> value="page" /> <?php _e( 'Use an existing page:', 'buddypress' ); ?> <?php echo wp_dropdown_pages( "name=bp-groups-page&echo=0&show_option_none=" . __( '- Select -', 'buddypress' ) . "&selected=" . $existing_pages['groups'] ); ?></label></p>
 
 
 
476
  </td>
477
  </tr>
478
 
479
  <?php endif; ?>
480
 
481
+ <?php if ( isset( $active_components['forums'] ) ) : ?>
482
 
483
  <tr valign="top">
484
  <th scope="row">
485
+ <h5><?php _e( 'Forums', 'buddypress' ); ?></h5>
486
+ <p><?php _e( 'Displays a directory of public forum topics.', 'buddypress' ); ?></p>
487
  </th>
488
  <td>
489
+ <p><label><input type="radio" name="bp_pages[forums]" <?php checked( empty( $existing_pages['forums'] ) ); ?> value="<?php echo $forums_slug; ?>" /> <?php _e( 'Automatically create a page at:', 'buddypress' ); ?> <?php echo home_url( $forums_slug ); ?>/</label></p>
490
+ <p><label><input type="radio" name="bp_pages[forums]" <?php checked( !empty( $existing_pages['forums'] ) ); ?> value="page" /> <?php _e( 'Use an existing page:', 'buddypress' ); ?> <?php echo wp_dropdown_pages( "name=bp-forums-page&echo=0&show_option_none=" . __( '- Select -', 'buddypress' ) . "&selected=" . $existing_pages['forums'] ); ?></label></p>
 
 
 
491
  </td>
492
  </tr>
493
 
494
  <?php endif; ?>
495
 
496
+ <?php /* The Blogs component only needs a directory page when Multisite is enabled */ ?>
497
+ <?php if ( is_multisite() && isset( $active_components['blogs'] ) ) : ?>
498
 
499
  <tr valign="top">
500
  <th scope="row">
501
+ <h5><?php _e( 'Sites', 'buddypress' ); ?></h5>
502
+ <p><?php _e( 'Displays a directory of the sites in your network.', 'buddypress' ); ?></p>
503
  </th>
504
  <td>
505
+ <p><label><input type="radio" name="bp_pages[blogs]" <?php checked( empty( $existing_pages['blogs'] ) ); ?> value="<?php echo $blogs_slug; ?>" /> <?php _e( 'Automatically create a page at:', 'buddypress' ); ?> <?php echo home_url( $blogs_slug ); ?>/</label></p>
506
+ <p><label><input type="radio" name="bp_pages[blogs]" <?php checked( !empty( $existing_pages['blogs'] ) ); ?> value="page" /> <?php _e( 'Use an existing page:', 'buddypress' ); ?> <?php echo wp_dropdown_pages( "name=bp-blogs-page&echo=0&show_option_none=" . __( '- Select -', 'buddypress' ) . "&selected=" . $existing_pages['blogs'] ); ?></label></p>
 
 
 
507
  </td>
508
  </tr>
509
 
516
  </th>
517
  <td>
518
  <p><label><input type="radio" name="bp_pages[register]" <?php checked( empty( $existing_pages['register'] ) ); ?> value="<?php echo $register_slug; ?>" /> <?php _e( 'Automatically create a page at:', 'buddypress' ) ?> <?php echo home_url( $register_slug ) ?>/</label></p>
519
+ <p><label><input type="radio" name="bp_pages[register]" <?php checked( !empty( $existing_pages['register'] ) ); ?> value="page" /> <?php _e( 'Use an existing page:', 'buddypress' ) ?> <?php echo wp_dropdown_pages( "name=bp-register-page&echo=0&show_option_none=" . __( '- Select -', 'buddypress' ) . "&selected=" . $existing_pages['register'] ); ?></label></p>
 
 
 
520
  </td>
521
  </tr>
522
 
527
  </th>
528
  <td>
529
  <p><label><input type="radio" name="bp_pages[activate]" <?php checked( empty( $existing_pages['activate'] ) ); ?> value="<?php echo $activation_slug; ?>" /> <?php _e( 'Automatically create a page at:', 'buddypress' ); ?> <?php echo home_url( $activation_slug ); ?>/</label></p>
530
+ <p><label><input type="radio" name="bp_pages[activate]" <?php checked( !empty( $existing_pages['activate'] ) ); ?> value="page" /> <?php _e( 'Use an existing page:', 'buddypress' ); ?> <?php echo wp_dropdown_pages( "name=bp-activate-page&echo=0&show_option_none=" . __( '- Select -', 'buddypress' ) . "&selected=" . $existing_pages['activate'] ); ?></label></p>
 
 
 
531
  </td>
532
  </tr>
533
  </table>
534
 
535
  <div class="submit clear">
536
  <input type="hidden" name="save" value="pages" />
537
+ <input type="hidden" name="step" value="<?php echo esc_attr( $this->current_step ); ?>" />
538
 
539
  <?php wp_nonce_field( 'bpwizard_pages' ); ?>
540
 
546
  }
547
 
548
  function step_permalinks() {
549
+ if ( !current_user_can( 'activate_plugins' ) )
550
+ return false;
551
 
552
  $prefix = '';
553
+ $permalink_structure = get_option( 'permalink_structure' );
554
+ $using_permalinks = ( !empty( $permalink_structure ) ) ? true : false;
555
  $structures = array( '', $prefix . '/%year%/%monthnum%/%day%/%postname%/', $prefix . '/%year%/%monthnum%/%postname%/', $prefix . '/archives/%post_id%' );
556
 
557
  // If we're using permalinks already, adjust text accordingly
558
+ if ( $permalink_structure )
559
+ $permalink_setup_text = __( 'Congratulations! You are already using pretty permalinks, which BuddyPress requires. If you\'d like to change your settings, you may do so now. If you\'re happy with your current settings, click Save &amp; Next to continue.', 'buddypress' );
560
  else
561
+ $permalink_setup_text = __( 'To make sure the pages created in the previous step work correctly, pretty permalinks must be active on your site.', 'buddypress' );
562
 
563
  if ( !got_mod_rewrite() && !iis7_supports_permalinks() )
564
  $prefix = '/index.php'; ?>
565
 
566
  <p><?php echo $permalink_setup_text; ?></p>
567
+ <p><?php printf( __( 'Please select the permalink setting you would like to use. For more advanced options please visit the <a href="%s">permalink settings page</a> first, and complete this setup wizard later.', 'buddypress' ), admin_url( 'options-permalink.php' ) ); ?>
568
 
569
  <table class="form-table">
570
  <tr>
583
 
584
  <div class="submit clear">
585
  <input type="hidden" name="save" value="permalinks" />
586
+ <input type="hidden" name="step" value="<?php echo esc_attr( $this->current_step ); ?>" />
587
 
588
  <?php if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && empty( $_POST['skip-htaccess'] ) ) : ?>
589
 
599
  }
600
 
601
  function step_theme() {
602
+ if ( !current_user_can( 'activate_plugins' ) )
603
+ return false;
604
 
605
  $installed_plugins = get_plugins();
606
+
607
+ // Backward-compatibility with WP < 3.4 will be removed in a future release
608
+ if ( bp_get_major_wp_version() >= 3.4 ) {
609
+ $installed_themes = wp_get_themes();
610
+ } else {
611
+ $installed_themes = get_themes();
612
+ }
613
 
614
  $template_pack_installed = false;
615
+ $bp_autotheme_installed = false;
616
  $bp_theme_installed = false;
617
 
618
+ foreach ( (array)$installed_plugins as $plugin ) {
619
  if ( 'BuddyPress Template Pack' == $plugin['Name'] ) {
620
  $template_pack_installed = true;
621
  }
622
  }
623
 
624
+ foreach ( (array)$installed_themes as $theme ) {
625
+ foreach ( (array)$theme['Tags'] as $tag ) {
626
  if ( ( 'BuddyPress Default' != $theme['Name'] ) && ( 'buddypress' == $tag ) ) {
627
  $bp_theme_installed = true;
628
  $bp_themes[] = $theme;
631
  }
632
 
633
  // Get theme screenshot
634
+ // Backward-compatibility with WP < 3.4 will be removed in a future release
635
+ if ( bp_get_major_wp_version() >= 3.4 ) {
636
+ $current_theme = wp_get_theme();
637
+ } else {
638
+ $current_theme = get_current_theme();
639
+ }
640
  $screenshot = '';
641
 
642
+ if ( !empty( $installed_themes[$current_theme]['Screenshot'] ) )
643
+ $screenshot = trailingslashit( get_stylesheet_directory_uri() ) . $installed_themes[$current_theme]['Screenshot'];
644
+ ?>
645
 
646
  <script type="text/javascript">
647
  jQuery( document ).ready( function() {
651
  });
652
  </script>
653
 
654
+ <p><?php _e( "BuddyPress introduces a whole range of new screens to display content. To display these screens, you need to decide how you want to handle them in your current theme.", 'buddypress' ); ?></p>
655
+
656
  <table class="form-table">
657
  <tr>
658
  <th>
659
  <h5><?php _e( 'Use BuddyPress Default', 'buddypress' ); ?></h5>
660
+ <img src="<?php echo plugins_url( '/buddypress/bp-themes/bp-default/screenshot.png' ); ?>" alt="<?php _e( 'BuddyPress Default', 'buddypress' ); ?>" />
661
  </th>
662
  <td>
663
+ <p><?php _e( 'BuddyPress Default contains everything you need to get up and running out of the box. It supports all features and is highly customizable.', 'buddypress' ); ?></p>
664
+ <p><strong><?php _e( 'This is the best choice if you do not have an existing WordPress theme, or want to start using BuddyPress immediately.', 'buddypress' ); ?></strong></p>
665
  <p><label><input type="radio" name="theme" value="bp_default" checked="checked" /> <?php _e( 'Yes, please!', 'buddypress' ); ?></label></p>
666
  </td>
667
  </tr>
668
 
669
+ <?php if ( $bp_theme_installed ) : ?>
 
670
  <tr>
671
  <th>
672
  <h5><?php _e( 'Other themes', 'buddypress' ); ?></h5>
673
+ <img src="<?php echo plugins_url( '/buddypress/bp-core/images/find.png' ); ?>" alt="<?php _e( 'A BuddyPress theme', 'buddypress' ); ?>" />
674
  </th>
675
  <td>
676
+ <p><?php _e( "We've found that you already have some other BuddyPress-compatible themes available. To use one of those, pick it from this list.", 'buddypress' ); ?></p>
677
  <p>
678
  <label>
679
  <input type="radio" name="theme" value="3rd_party" /> <?php _e( 'Use this theme', 'buddypress' ); ?>
681
  <select name="3rd_party_theme">
682
 
683
  <?php foreach( (array) $bp_themes as $theme ) : ?>
 
684
  <option value="<?php echo $theme['Template'] . ',' . $theme['Stylesheet']; ?>"><?php echo $theme['Name']; ?></option>
 
685
  <?php endforeach; ?>
686
 
687
  </select>
688
  </p>
689
  </td>
690
  </tr>
 
691
  <?php endif; ?>
692
 
693
+ <tr>
694
+ <th>
695
+ <h5><?php _e( 'Manually update current theme', 'buddypress' ); ?></h5>
696
+ <?php if ( !empty( $screenshot ) ) : ?>
697
+ <img src="<?php echo esc_url( $screenshot ); ?>" alt="<?php _e( 'Your existing theme', 'buddypress' ); ?>" />
698
+ <?php endif; ?>
699
+ </th>
700
+ <td>
701
+ <p><?php _e( 'The BuddyPress Template Pack plugin will guide you through the process of manually upgrading your existing WordPress theme. This usually involves following the step-by-step instructions and copying the BuddyPress template files into your theme. This option requires a working knowledge of CSS and HTML, as you will need to tweak the new templates to match your existing theme.', 'buddypress' ); ?></p>
 
 
 
 
 
 
 
 
702
 
703
+ <?php if ( empty( $template_pack_installed ) ) : ?>
704
 
705
+ <p><a id="bp-template-pack" class="thickbox onclick button" href="<?php echo network_admin_url( 'plugin-install.php?tab=plugin-information&plugin=bp-template-pack&TB_iframe=true&width=640&height=500' ); ?>"><?php _e( 'Install BuddyPress Template Pack', 'buddypress' ); ?></a></p>
706
 
707
+ <?php else : ?>
 
708
 
709
+ <p><label><input type="radio" name="theme" value="manual_wp" /> <?php _e( 'Choose this option (go to Appearance &rarr; BP Compatibility after setup is complete)', 'buddypress' ); ?></label></p>
710
+ <p><a id="bp-template-pack" class="button installed disabled" href="javascript:void();"><span></span><?php _e( 'Plugin Installed', 'buddypress' ); ?></a></p>
711
 
712
+ <?php endif; ?>
 
713
 
714
+ </td>
715
+ </tr>
716
 
717
  <tr>
718
  <th>
720
  </th>
721
  <td>
722
  <p><?php _e( "You are happy with your current theme and plan on changing it later.", 'buddypress' ); ?></p>
723
+ <p><strong><?php _e( 'This is the best choice if you have a highly customized theme on your site already, and want to later manually integrate BuddyPress into your site.', 'buddypress' ); ?></strong></p>
724
 
725
  <p><label><input type="radio" name="theme" value="do_not_change" /> <?php _e( "Don't change my current theme", 'buddypress' ); ?></label></p>
726
 
730
 
731
  <div class="submit clear">
732
  <input type="hidden" name="save" value="theme" />
733
+ <input type="hidden" name="step" value="<?php echo esc_attr( $this->current_step ) ?>" />
734
 
735
  <?php wp_nonce_field( 'bpwizard_theme' ) ?>
736
 
739
  <?php
740
  }
741
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
742
  function step_finish() {
743
+ if ( !current_user_can( 'activate_plugins' ) )
744
+ return false;
745
 
746
  // What type of action is happening here?
747
+ $type = ( 'install' == $this->setup_type ) ? __( 'setup', 'buddypress' ) : __( 'update', 'buddypress' ); ?>
748
 
749
+ <p><?php printf( __( "The BuddyPress %1\$s is complete, and your site is ready to go!", 'buddypress' ), $type, $type ); ?></p>
750
 
751
  <div class="submit clear">
752
  <input type="hidden" name="save" value="finish" />
753
+ <input type="hidden" name="step" value="<?php echo esc_attr( $this->current_step ); ?>" />
754
 
755
  <?php wp_nonce_field( 'bpwizard_finish' ); ?>
756
 
762
  /** Save Step Methods *****************************************************/
763
 
764
  function step_db_update_save() {
765
+ global $bp;
766
 
767
  if ( isset( $_POST['submit'] ) ) {
768
  check_admin_referer( 'bpwizard_db_update' );
770
  // Run the schema install to update tables
771
  bp_core_install();
772
 
773
+ if ( $this->database_version < 1801 )
 
774
  $this->update_1_5();
775
 
776
+ // Update the active components option early if we're updating
777
+ if ( 'update' == $this->setup_type )
778
+ bp_update_option( 'bp-active-components', $bp->active_components );
779
 
780
  return true;
781
  }
783
  return false;
784
  }
785
 
786
+ function step_ms_update_save() {
787
+ global $wpdb;
788
 
789
+ if ( isset( $_POST['submit'] ) ) {
790
+ check_admin_referer( 'bpwizard_ms_update' );
791
 
792
+ if ( !$active_components = bp_get_option( 'bp-active-components' ) )
793
+ $active_components = array();
794
+
795
+ // Transfer important settings from blog options to site options
796
+ $options = array(
797
+ 'bp-db-version' => $this->database_version,
798
+ 'bp-active-components' => $active_components,
799
+ 'avatar-default' => get_option( 'avatar-default' )
800
+ );
801
+ bp_core_activate_site_options( $options );
802
+
803
+ if ( isset( $_POST['bp_components']['blogs'] ) ) {
804
+ $active_components['blogs'] = 1;
805
+
806
+ // Make sure that the pages are created on the bp_get_root_blog_id(), no matter which Dashboard the setup is being run on
807
+ if ( !empty( $wpdb->blogid ) && ( $wpdb->blogid != bp_get_root_blog_id() ) && ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) )
808
+ switch_to_blog( bp_get_root_blog_id() );
809
+
810
+ // Move bp-pages data from the blog options table to site options
811
+ $existing_pages = bp_get_option( 'bp-pages' );
812
+
813
+ $bp_pages = $this->setup_pages( (array)$_POST['bp_pages'] );
814
+ $bp_pages = array_merge( (array)$existing_pages, (array)$bp_pages );
815
+
816
+ bp_update_option( 'bp-pages', $bp_pages );
817
+
818
+ if ( !empty( $wpdb->blogid ) && ( $wpdb->blogid != bp_get_root_blog_id() ) && ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) )
819
+ restore_current_blog();
820
+
821
+ bp_core_install( $active_components );
822
+ }
823
+
824
+ bp_update_option( 'bp-active-components', $active_components );
825
+
826
+ return true;
827
+ }
828
+
829
+ return false;
830
+ }
831
+
832
+
833
+ function step_components_save() {
834
+ if ( isset( $_POST['submit'] ) && isset( $_POST['bp_components'] ) ) {
835
  check_admin_referer( 'bpwizard_components' );
836
 
837
  $active_components = array();
838
 
839
  // Settings form submitted, now save the settings.
840
+ foreach ( (array)$_POST['bp_components'] as $key => $value )
841
  $active_components[$key] = 1;
 
842
 
843
  bp_update_option( 'bp-active-components', $active_components );
844
 
862
  switch_to_blog( bp_get_root_blog_id() );
863
 
864
  // Delete any existing pages
865
+ $existing_pages = bp_core_update_get_page_meta( 'bp-pages' );
866
 
867
+ foreach ( (array)$existing_pages as $page_id )
868
  wp_delete_post( $page_id, true );
 
869
 
870
+ $blog_pages = $this->setup_pages( (array)$_POST['bp_pages'] );
871
  bp_update_option( 'bp-pages', $blog_pages );
872
 
873
  if ( !empty( $wpdb->blogid ) && ( $wpdb->blogid != bp_get_root_blog_id() ) && ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) )
981
  }
982
 
983
  function step_theme_save() {
 
 
984
  if ( isset( $_POST['submit'] ) && isset( $_POST['theme'] ) ) {
985
  check_admin_referer( 'bpwizard_theme' );
986
 
991
 
992
  // Activate the bp-default theme
993
  case 'bp_default' :
 
994
  switch_theme( 'bp-default', 'bp-default' );
995
  break;
996
 
1032
  return false;
1033
  }
1034
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1035
  function step_finish_save() {
 
1036
  if ( isset( $_POST['submit'] ) ) {
 
1037
  check_admin_referer( 'bpwizard_finish' );
1038
 
1039
  // Update the DB version in the database
1040
+ // Stored in sitemeta. Do not use bp_update_option()
1041
+ update_site_option( 'bp-db-version', $this->new_version );
1042
+ delete_site_option( 'bp-core-db-version' );
1043
 
1044
  // Delete the setup cookie
1045
  @setcookie( 'bp-wizard-step', '', time() - 3600, COOKIEPATH );
1046
 
1047
+ // Load BP and hook the admin menu, so that the redirect is successful
1048
+ if ( !function_exists( 'bp_core_update_message' ) )
1049
+ require( WP_PLUGIN_DIR . '/buddypress/bp-core/admin/bp-core-admin.php' );
1050
+
1051
+ bp_core_add_admin_menu();
1052
+
1053
  // Redirect to the BuddyPress dashboard
1054
+ $redirect = bp_core_update_do_network_admin() ? add_query_arg( array( 'page' => 'bp-general-settings' ), network_admin_url( 'admin.php' ) ) : add_query_arg( array( 'page' => 'bp-general-settings' ), admin_url( 'admin.php' ) );
 
1055
 
1056
+ wp_redirect( $redirect );
1057
 
1058
+ return true;
 
1059
  }
1060
 
1061
  return false;
1062
  }
1063
 
1064
  function setup_pages( $pages ) {
 
 
 
1065
  foreach ( $pages as $key => $value ) {
1066
  if ( 'page' == $value ) {
1067
  // Check for the selected page
1068
  if ( !empty( $_POST['bp-' . $key . '-page'] ) )
1069
+ $bp_pages[$key] = (int)$_POST['bp-' . $key . '-page'];
1070
  else
1071
  $bp_pages[$key] = wp_insert_post( array( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_title' => ucwords( $key ), 'post_status' => 'publish', 'post_type' => 'page' ) );
1072
  } else {
1080
 
1081
  // Database update methods based on version numbers
1082
  function update_1_5() {
 
1083
  // Delete old database version options
1084
  delete_site_option( 'bp-activity-db-version' );
1085
  delete_site_option( 'bp-blogs-db-version' );
1089
  delete_site_option( 'bp-xprofile-db-version' );
1090
  }
1091
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1092
  /**
1093
  * Reset the cookie so the install script starts over
1094
  */
1097
  }
1098
  }
1099
 
1100
+ function bp_core_setup_wizard_init() {
1101
+ global $bp_wizard;
1102
+
1103
+ $bp_wizard = new BP_Core_Setup_Wizard;
1104
+ }
1105
+ add_action( bp_core_update_admin_hook(), 'bp_core_setup_wizard_init', 7 );
1106
+
1107
+ function bp_core_install( $active_components = false ) {
1108
+ global $wpdb;
1109
+
1110
+ if ( empty( $active_components ) )
1111
+ $active_components = apply_filters( 'bp_active_components', bp_get_option( 'bp-active-components' ) );
1112
+
1113
+ require( dirname( __FILE__ ) . '/bp-core-schema.php' );
1114
+
1115
+ // Core DB Tables
1116
+ bp_core_install_notifications();
1117
+
1118
+ // Activity Streams
1119
+ if ( !empty( $active_components['activity'] ) )
1120
+ bp_core_install_activity_streams();
1121
+
1122
+ // Friend Connections
1123
+ if ( !empty( $active_components['friends'] ) )
1124
+ bp_core_install_friends();
1125
+
1126
+ // Extensible Groups
1127
+ if ( !empty( $active_components['groups'] ) )
1128
+ bp_core_install_groups();
1129
+
1130
+ // Private Messaging
1131
+ if ( !empty( $active_components['messages'] ) )
1132
+ bp_core_install_private_messaging();
1133
+
1134
+ // Extended Profiles
1135
+ if ( !empty( $active_components['xprofile'] ) )
1136
+ bp_core_install_extended_profiles();
1137
+
1138
+ // Blog tracking
1139
+ if ( !empty( $active_components['blogs'] ) )
1140
+ bp_core_install_blog_tracking();
1141
+ }
1142
+
1143
+ function bp_core_update( $disabled ) {
1144
+ global $wpdb;
1145
+
1146
+ require( dirname( __FILE__ ) . '/bp-core-schema.php' );
1147
+ }
1148
+
1149
+ function bp_update_db_stuff() {
1150
+ $bp_prefix = bp_core_get_table_prefix();
1151
+ // Rename the old user activity cached table if needed.
1152
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$bp_prefix}bp_activity_user_activity_cached%'" ) )
1153
+ $wpdb->query( "RENAME TABLE {$bp_prefix}bp_activity_user_activity_cached TO {$bp->activity->table_name}" );
1154
+
1155
+ // Rename fields from pre BP 1.2
1156
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$bp->activity->table_name}%'" ) ) {
1157
+ if ( $wpdb->get_var( "SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_action'" ) )
1158
+ $wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE component_action type varchar(75) NOT NULL" );
1159
+
1160
+ if ( $wpdb->get_var( "SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_name'" ) )
1161
+ $wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE component_name component varchar(75) NOT NULL" );
1162
+ }
1163
+
1164
+ // On first installation - record all existing blogs in the system.
1165
+ if ( !(int)$bp->site_options['bp-blogs-first-install'] ) {
1166
+ bp_blogs_record_existing_blogs();
1167
+ bp_update_option( 'bp-blogs-first-install', 1 );
1168
+ }
1169
+
1170
+ if ( is_multisite() )
1171
+ bp_core_add_illegal_names();
1172
+
1173
+ // Update and remove the message threads table if it exists
1174
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$bp_prefix}bp_messages_threads%'" ) ) {
1175
+ $update = BP_Messages_Thread::update_tables();
1176
+
1177
+ if ( $update )
1178
+ $wpdb->query( "DROP TABLE {$bp_prefix}bp_messages_threads" );
1179
+ }
1180
+
1181
+ }
1182
+
1183
+ function bp_core_wizard_message() {
1184
+ if ( isset( $_GET['updated'] ) )
1185
+ $message = __( 'Installation was successful. The available options have now been updated, please continue with your selection.', 'buddypress' );
1186
+ else
1187
+ return false; ?>
1188
+
1189
+ <div id="message" class="updated">
1190
+ <p><?php echo esc_attr( $message ) ?></p>
1191
+ </div>
1192
+
1193
+ <?php
1194
+ }
1195
+ add_action( 'bp_admin_notices', 'bp_core_wizard_message' );
1196
+
1197
+ // Alter thickbox screens so the entire plugin download and install
1198
+ // interface is contained within.
1199
+ function bp_core_wizard_thickbox() {
1200
+ $form_action = bp_core_update_do_network_admin() ? network_admin_url( add_query_arg( array( 'page' => 'bp-wizard', 'updated' => '1' ), 'admin.php' ) ) : admin_url( add_query_arg( array( 'page' => 'bp-wizard', 'updated' => '1' ), 'admin.php' ) ); ?>
1201
+
1202
+ <script type="text/javascript">
1203
+ jQuery('p.action-button a').attr( 'target', '' );
1204
+
1205
+ if ( window.location != window.parent.location ) {
1206
+ jQuery('#adminmenu, #wphead, #footer, #update-nag, #screen-meta').hide();
1207
+ jQuery('#wpbody').css( 'margin', '15px' );
1208
+ jQuery('body').css( 'min-width', '30px' );
1209
+ jQuery('#wpwrap').css( 'min-height', '30px' );
1210
+ jQuery('a').removeClass( 'thickbox thickbox-preview onclick' );
1211
+ jQuery('body.update-php div.wrap p:last').hide();
1212
+ jQuery('body.update-php div.wrap p:last').after( '<p><a class="button" target="_parent" href="<?php echo $form_action; ?>"><?php _e( 'Finish', 'buddypress' ) ?></a></p>' );
1213
+ }
1214
+ </script>
1215
+
1216
+ <?php
1217
+ }
1218
+ add_action( 'admin_footer', 'bp_core_wizard_thickbox' );
1219
+
1220
  /**
1221
+ * Adds the "BuddyPress" admin submenu item to the Site Admin tab.
1222
  *
1223
+ * @package BuddyPress Core
1224
+ * @global object $bp Global BuddyPress settings object
1225
+ * @global $wpdb WordPress DB access object.
1226
+ * @uses add_submenu_page() WP function to add a submenu item
1227
  */
1228
+ function bp_core_update_add_admin_menu() {
1229
+ global $bp_wizard;
1230
 
1231
+ // Only load this version of the menu if this is an upgrade or a new installation
1232
+ if ( empty( $bp_wizard->setup_type ) )
1233
+ return false;
1234
+
1235
+ if ( !current_user_can( 'activate_plugins' ) )
1236
+ return false;
1237
+
1238
+ if ( 'install' == $bp_wizard->setup_type )
1239
+ $status = __( 'Setup', 'buddypress' );
1240
+ else
1241
+ $status = __( 'Update', 'buddypress' );
1242
+
1243
+ // Add the administration tab under the "Site Admin" tab for site administrators
1244
+ add_menu_page( __( 'BuddyPress', 'buddypress' ), __( 'BuddyPress', 'buddypress' ), 'manage_options', 'bp-wizard', '' );
1245
+ $hook = add_submenu_page( 'bp-wizard', $status, $status, 'manage_options', 'bp-wizard', array( $bp_wizard, 'html' ) );
1246
+
1247
+ // Add a hook for css/js
1248
+ add_action( "admin_print_styles-$hook", 'bp_core_update_add_admin_menu_styles' );
1249
+ }
1250
+ add_action( bp_core_update_admin_hook(), 'bp_core_update_add_admin_menu', 9 );
1251
+
1252
+ function bp_core_update_add_admin_menu_styles() {
1253
+ if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
1254
+ wp_enqueue_style( 'bp-admin-css', apply_filters( 'bp_core_admin_css', plugins_url( '/buddypress' ) . '/bp-core/css/admin.dev.css' ), array(), '20110723' );
1255
+ wp_enqueue_script( 'bp-update-js', apply_filters( 'bp_core_update_js', plugins_url( '/buddypress' ) . '/bp-core/js/update.dev.js' ), array( 'jquery' ), '20110723' );
1256
+ } else {
1257
+ wp_enqueue_style( 'bp-admin-css', apply_filters( 'bp_core_admin_css', plugins_url( '/buddypress' ) . '/bp-core/css/admin.css' ), array(), '20110723' );
1258
+ wp_enqueue_script( 'bp-update-js', apply_filters( 'bp_core_update_js', plugins_url( '/buddypress' ) . '/bp-core/js/update.js' ), array( 'jquery' ), '20110723' );
1259
+
1260
+ }
1261
+
1262
+ wp_enqueue_script( 'thickbox' );
1263
+ wp_enqueue_style( 'thickbox' ); ?>
1264
+
1265
+ <style type="text/css">
1266
+ /* Wizard Icon */
1267
+ ul#adminmenu li.toplevel_page_bp-wizard .wp-menu-image a img { display: none; }
1268
+ ul#adminmenu li.toplevel_page_bp-wizard .wp-menu-image a { background-image: url( <?php echo plugins_url( 'buddypress/bp-core/images/admin_menu_icon.png' ) ?> ) !important; background-position: -1px -32px; }
1269
+ ul#adminmenu li.toplevel_page_bp-wizard:hover .wp-menu-image a,
1270
+ ul#adminmenu li.toplevel_page_bp-wizard.wp-has-current-submenu .wp-menu-image a {
1271
+ background-position: -1px 0;
1272
+ }
1273
+
1274
+ /* Settings Icon */
1275
+ ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image a img { display: none; }
1276
+ ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image a { background-image: url( <?php echo plugins_url( 'buddypress/bp-core/images/admin_menu_icon.png' ) ?> ) !important; background-position: -1px -32px; }
1277
+ ul#adminmenu li.toplevel_page_bp-general-settings:hover .wp-menu-image a,
1278
+ ul#adminmenu li.toplevel_page_bp-general-settings.wp-has-current-submenu .wp-menu-image a {
1279
+ background-position: -1px 0;
1280
+ }
1281
+ </style>
1282
+
1283
+ <?php
1284
+ }
1285
+ add_action( 'admin_head', 'bp_core_update_add_admin_menu_styles' );
1286
+
1287
+ /**
1288
+ * Fetches BP pages from the meta table
1289
+ *
1290
+ * @package BuddyPress Core
1291
+ * @since 1.5
1292
+ *
1293
+ * @return array $page_ids
1294
+ */
1295
+ function bp_core_update_get_page_meta() {
1296
+ if ( !$page_ids = bp_get_option( 'bp-pages' ) )
1297
+ $page_ids = array();
1298
+
1299
+ return apply_filters( 'bp_core_update_get_page_meta', $page_ids );
1300
+ }
1301
+
1302
+ function bp_core_update_do_network_admin() {
1303
+ $do_network_admin = false;
1304
+
1305
+ if ( is_multisite() && ( !defined( 'BP_ENABLE_MULTIBLOG' ) || !BP_ENABLE_MULTIBLOG ) )
1306
+ $do_network_admin = true;
1307
+
1308
+ return apply_filters( 'bp_core_do_network_admin', $do_network_admin );
1309
+ }
1310
+
1311
+ function bp_core_update_admin_hook() {
1312
+ $hook = bp_core_update_do_network_admin() ? 'network_admin_menu' : 'admin_menu';
1313
+
1314
+ return apply_filters( 'bp_core_admin_hook', $hook );
1315
+ }
1316
+
1317
+ /**
1318
+ * Adds an admin nag about running the BP upgrade/install wizard
1319
+ *
1320
+ * @package BuddyPress Core
1321
+ * @since 1.5
1322
+ * @global $pagenow The current admin page
1323
+ */
1324
+ function bp_core_update_nag() {
1325
+ global $bp_wizard, $pagenow;
1326
+
1327
+ if ( empty( $bp_wizard->setup_type ) )
1328
+ return;
1329
+
1330
+ if ( !is_super_admin() )
1331
+ return;
1332
+
1333
+ if ( 'admin.php' == $pagenow && ( empty( $_GET['page'] ) || 'bp-wizard' == $_GET['page'] ) )
1334
+ return;
1335
+
1336
+ $url = bp_core_update_do_network_admin() ? network_admin_url( 'admin.php?page=bp-wizard' ) : admin_url( 'admin.php?page=bp-wizard' );
1337
+
1338
+ switch( $bp_wizard->setup_type ) {
1339
+ case 'update':
1340
+ $msg = sprintf( __( 'BuddyPress has been updated! Please run the <a href="%s">update wizard</a>.', 'buddypress' ), $url );
1341
+ break;
1342
+
1343
+ default:
1344
+ case 'install':
1345
+ $msg = sprintf( __( 'BuddyPress was successfully installed! Please run the <a href="%s">installation wizard</a>.', 'buddypress' ), $url );
1346
+ break;
1347
+ }
1348
 
1349
+ echo '<div class="update-nag">' . $msg . '</div>';
1350
  }
1351
+ add_action( 'admin_notices', 'bp_core_update_nag', 5 );
1352
+ add_action( 'network_admin_notices', 'bp_core_update_nag', 5 );
1353
 
1354
+ ?>
bp-core/admin/css/common.css DELETED
@@ -1 +0,0 @@
1
- div#icon-buddypress{background:url(../images/icons32.png) no-repeat -370px -6px}div#icon-buddypress-activity{background:url(../images/icons32.png) no-repeat -10px -6px}ul#adminmenu li.toplevel_page_bp-wizard .wp-menu-image a img{display:none}ul#adminmenu li.toplevel_page_bp-wizard .wp-menu-image a{background-image:url(../images/menu.png)!important;background-position:-178pxpx -34px}ul#adminmenu li.toplevel_page_bp-wizard:hover .wp-menu-image a,ul#adminmenu li.toplevel_page_bp-wizard.wp-has-current-submenu .wp-menu-image a{background-position:-178px -2px}ul#adminmenu li.toplevel_page_bp-components .wp-menu-image a img,ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image a img{display:none}ul#adminmenu li.toplevel_page_bp-components .wp-menu-image a,ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image a{background-image:url(../images/menu.png)!important;background-position:-178px -34px}ul#adminmenu li.toplevel_page_bp-components:hover .wp-menu-image a,ul#adminmenu li.toplevel_page_bp-general-settings:hover .wp-menu-image a,ul#adminmenu li.toplevel_page_bp-components.wp-has-current-submenu .wp-menu-image a,ul#adminmenu li.toplevel_page_bp-general-settings.wp-has-current-submenu .wp-menu-image a{background-position:-178px -2px}ul#adminmenu li.toplevel_page_bp-activity .wp-menu-image a img,ul#adminmenu li.toplevel_page_bp-activity_network .wp-menu-image a img{display:none}ul#adminmenu li.toplevel_page_bp-activity .wp-menu-image a,ul#adminmenu li.toplevel_page_bp-activity_network .wp-menu-image a{background-image:url(../images/menu.png)!important;background-position:0 -34px}ul#adminmenu li.toplevel_page_bp-activity:hover .wp-menu-image a,ul#adminmenu li.toplevel_page_bp-activity.current .wp-menu-image a,ul#adminmenu li.toplevel_page_bp-activity.wp-has-current-submenu .wp-menu-image a,ul#adminmenu li.toplevel_page_bp-activity_network:hover .wp-menu-image a,ul#adminmenu li.toplevel_page_bp-activity_network.current .wp-menu-image a,ul#adminmenu li.toplevel_page_bp-activity_network.wp-has-current-submenu .wp-menu-image a{background-position:0 -2px}.dashboard_page_bp-wizard td.plugin-title span,.settings_page_bp-components td.plugin-title span{float:left;width:18px;height:18px;background-image:url(../images/menu.png);background-position:-4px -40px;background-repeat:no-repeat;margin-right:5px}.dashboard_page_bp-wizard tr.active td.plugin-title span,.settings_page_bp-components tr.active td.plugin-title span{background-position-y:-7px}.dashboard_page_bp-wizard tr.activity td.plugin-title span,.settings_page_bp-components tr.activity td.plugin-title span{background-position-x:-4px}.dashboard_page_bp-wizard tr.xprofile td.plugin-title span,.settings_page_bp-components tr.xprofile td.plugin-title span{background-image:url(../images/menu-wp.png);background-position-x:-305px}.dashboard_page_bp-wizard tr.settings td.plugin-title span,.settings_page_bp-components tr.settings td.plugin-title span{background-image:url(../images/menu-wp.png);background-position-x:-334px}.dashboard_page_bp-wizard tr.groups td.plugin-title span,.settings_page_bp-components tr.groups td.plugin-title span{background-position-x:-66px}.dashboard_page_bp-wizard tr.messages td.plugin-title span,.settings_page_bp-components tr.messages td.plugin-title span{background-position-x:-154px}.dashboard_page_bp-wizard tr.forums td.plugin-title span,.settings_page_bp-components tr.forums td.plugin-title span{background-image:url(../images/menu-wp.png);background-position-x:-36px}.dashboard_page_bp-wizard tr.blogs td.plugin-title span,.settings_page_bp-components tr.blogs td.plugin-title span{background-position-x:-125px}.dashboard_page_bp-wizard tr.friends td.plugin-title span,.settings_page_bp-components tr.friends td.plugin-title span{background-position-x:-95px}.dashboard_page_bp-wizard tr.core td.plugin-title span,.settings_page_bp-components tr.core td.plugin-title span{background-position-x:-184px}.dashboard_page_bp-wizard tr.members td.plugin-title span,.settings_page_bp-components tr.members td.plugin-title span{background-position-x:-36px}
 
bp-core/admin/css/common.dev.css DELETED
@@ -1,143 +0,0 @@
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
- div#icon-buddypress {
11
- background: url( ../images/icons32.png ) no-repeat -370px -6px;
12
- }
13
-
14
- div#icon-buddypress-activity {
15
- background: url( ../images/icons32.png ) no-repeat -10px -6px;
16
- }
17
-
18
- /* Menu Icons
19
- ------------------------------------------------------------------------------*/
20
-
21
- /* Wizard */
22
- ul#adminmenu li.toplevel_page_bp-wizard .wp-menu-image a img {
23
- display: none;
24
- }
25
- ul#adminmenu li.toplevel_page_bp-wizard .wp-menu-image a {
26
- background-image: url( ../images/menu.png ) !important;
27
- background-position: -178pxpx -34px;
28
- }
29
- ul#adminmenu li.toplevel_page_bp-wizard:hover .wp-menu-image a,
30
- ul#adminmenu li.toplevel_page_bp-wizard.wp-has-current-submenu .wp-menu-image a {
31
- background-position: -178px -2px;
32
- }
33
-
34
- /* Backpat */
35
- ul#adminmenu li.toplevel_page_bp-components .wp-menu-image a img,
36
- ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image a img {
37
- display: none;
38
- }
39
-
40
- ul#adminmenu li.toplevel_page_bp-components .wp-menu-image a,
41
- ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image a {
42
- background-image: url( ../images/menu.png ) !important;
43
- background-position: -178px -34px;
44
- }
45
-
46
- ul#adminmenu li.toplevel_page_bp-components:hover .wp-menu-image a,
47
- ul#adminmenu li.toplevel_page_bp-general-settings:hover .wp-menu-image a,
48
- ul#adminmenu li.toplevel_page_bp-components.wp-has-current-submenu .wp-menu-image a,
49
- ul#adminmenu li.toplevel_page_bp-general-settings.wp-has-current-submenu .wp-menu-image a {
50
- background-position: -178px -2px;
51
- }
52
-
53
- /* Activity */
54
- ul#adminmenu li.toplevel_page_bp-activity .wp-menu-image a img,
55
- ul#adminmenu li.toplevel_page_bp-activity_network .wp-menu-image a img {
56
- display: none;
57
- }
58
- ul#adminmenu li.toplevel_page_bp-activity .wp-menu-image a,
59
- ul#adminmenu li.toplevel_page_bp-activity_network .wp-menu-image a {
60
- background-image: url( ../images/menu.png ) !important;
61
- background-position: 0 -34px;
62
- }
63
- ul#adminmenu li.toplevel_page_bp-activity:hover .wp-menu-image a,
64
- ul#adminmenu li.toplevel_page_bp-activity.current .wp-menu-image a,
65
- ul#adminmenu li.toplevel_page_bp-activity.wp-has-current-submenu .wp-menu-image a,
66
- ul#adminmenu li.toplevel_page_bp-activity_network:hover .wp-menu-image a,
67
- ul#adminmenu li.toplevel_page_bp-activity_network.current .wp-menu-image a,
68
- ul#adminmenu li.toplevel_page_bp-activity_network.wp-has-current-submenu .wp-menu-image a {
69
- background-position: 0 -2px;
70
- }
71
-
72
-
73
- /* Components
74
- ------------------------------------------------------------------------------*/
75
-
76
- .dashboard_page_bp-wizard td.plugin-title span,
77
- .settings_page_bp-components td.plugin-title span {
78
- float: left;
79
- width: 18px;
80
- height: 18px;
81
- background-image: url( ../images/menu.png );
82
- background-position: -4px -40px;
83
- background-repeat: no-repeat;
84
- margin-right: 5px;
85
- }
86
-
87
- .dashboard_page_bp-wizard tr.active td.plugin-title span,
88
- .settings_page_bp-components tr.active td.plugin-title span {
89
- background-position-y: -7px;
90
- }
91
-
92
- .dashboard_page_bp-wizard tr.activity td.plugin-title span,
93
- .settings_page_bp-components tr.activity td.plugin-title span {
94
- background-position-x: -4px;
95
- }
96
-
97
- .dashboard_page_bp-wizard tr.xprofile td.plugin-title span,
98
- .settings_page_bp-components tr.xprofile td.plugin-title span {
99
- background-image: url( ../images/menu-wp.png );
100
- background-position-x: -305px;
101
- }
102
-
103
- .dashboard_page_bp-wizard tr.settings td.plugin-title span,
104
- .settings_page_bp-components tr.settings td.plugin-title span {
105
- background-image: url( ../images/menu-wp.png );
106
- background-position-x: -334px;
107
- }
108
-
109
- .dashboard_page_bp-wizard tr.groups td.plugin-title span,
110
- .settings_page_bp-components tr.groups td.plugin-title span {
111
- background-position-x: -66px;
112
- }
113
-
114
- .dashboard_page_bp-wizard tr.messages td.plugin-title span,
115
- .settings_page_bp-components tr.messages td.plugin-title span {
116
- background-position-x: -154px;
117
- }
118
-
119
- .dashboard_page_bp-wizard tr.forums td.plugin-title span,
120
- .settings_page_bp-components tr.forums td.plugin-title span {
121
- background-image: url( ../images/menu-wp.png );
122
- background-position-x: -36px;
123
- }
124
-
125
- .dashboard_page_bp-wizard tr.blogs td.plugin-title span,
126
- .settings_page_bp-components tr.blogs td.plugin-title span {
127
- background-position-x: -125px;
128
- }
129
-
130
- .dashboard_page_bp-wizard tr.friends td.plugin-title span,
131
- .settings_page_bp-components tr.friends td.plugin-title span {
132
- background-position-x: -95px;
133
- }
134
-
135
- .dashboard_page_bp-wizard tr.core td.plugin-title span,
136
- .settings_page_bp-components tr.core td.plugin-title span {
137
- background-position-x: -184px;
138
- }
139
-
140
- .dashboard_page_bp-wizard tr.members td.plugin-title span,
141
- .settings_page_bp-components tr.members td.plugin-title span {
142
- background-position-x: -36px;
143
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-core/admin/css/wizard.css DELETED
@@ -1 +0,0 @@
1
- div#bp-wizard{color:#555;min-width:680px}div#bp-wizard p{line-height:170%}form#bp-wizard-form{margin:0 10px}div#bp-wizard-nav{background:#e0e0e0;margin:15px -10px 10px;padding:10px 10px 0 10px;height:30px;-moz-border-radius:2px;-webkit-border-radius:2px;border-radius:2px}div#bp-wizard-nav div.submit{position:relative;float:right;margin-top:-36px!important}div#bp-wizard-nav div.submit input{padding:6px 10px}div#bp-wizard-nav ol{list-style-type:decimal;margin:0;padding:0}div#bp-wizard-nav ol li{float:left;margin:0 10px 0 0;color:#666}div#bp-wizard-nav ol li{padding:8px 12px;display:block;-moz-border-radius:2px;-webkit-border-radius:2px;border-radius:2px;text-decoration:none}div#bp-wizard-nav ol li.current{background:#fff;color:#555}div#bp-wizard-nav ol li span.complete{background:url(../images/completed.gif) center left no-repeat;padding:6px}div.component{width:323px;float:left;margin:15px 30px 0 0}div.component div.radio{position:relative;background:#e0e0e0;padding:5px 10px;-moz-border-radius:2px;-webkit-border-radius:2px;border-radius:2px;top:-6px}div.component img{margin-top:10px}div.component p{margin-left:4px}div.component h5{font-size:18px;float:left;margin:0 0 0 4px;width:100px}div.component div.radio{font-size:11px;float:right;top:5px}div#bp-wizard div.prev-next,div#bp-wizard div.prev-next p,div#bp-wizard div.submit,div#bp-wizard div.submit p{margin:0;padding:0}div#bp-wizard div.submit{margin-top:30px}div#bp-wizard div.prev-next{text-align:right;margin-top:0}div#bp-wizard div.prev-next{margin:0 -20px;padding:0 20px 10px}div#bp-wizard table td{font-family:helvetica,arial,tahoma,sans-serif;vertical-align:top}div#bp-wizard table.form-table th{border-right:1px solid #eee;padding:15px 25px 15px 0;color:#555;vertical-align:top}div#bp-wizard table.form-table tr{border-bottom:1px dotted #f0f0f0}div#bp-wizard table.form-table td{padding-left:25px;font-size:12px}div#bp-wizard table.form-table th h5{font-size:14px;margin:0;line-height:150%}div#bp-wizard table.form-table th img{margin-top:5px}div#bp-wizard table.form-table th p{margin:3px 0 0 0}div#bp-wizard code,div#bp-wizard kbd{font-size:12px;background:#f0f0f0}div#bp-wizard div#message code,div#bp-wizard div#message kbd{background:#ffe293}a.button{padding-top:4px}a.installed,a.installed:hover,a.installed:active{padding-left:15px;color:#888;border-color:#ccc;cursor:default}a.installed span{background:url(../images/installed.gif) left center no-repeat;padding:6px 10px 7px 6px;margin-left:-5px}
 
bp-core/admin/images/icons32.png DELETED
Binary file
bp-core/admin/images/menu-wp.png DELETED
Binary file
bp-core/admin/images/menu.png DELETED
Binary file
bp-core/bp-core-actions.php DELETED
@@ -1,267 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * BuddyPress Filters & Actions
5
- *
6
- * @package BuddyPress
7
- * @subpackage Hooks
8
- *
9
- * This file contains the actions and filters that are used through-out BuddyPress.
10
- * They are consolidated here to make searching for them easier, and to help
11
- * developers understand at a glance the order in which things occur.
12
- *
13
- */
14
-
15
- // Exit if accessed directly
16
- if ( !defined( 'ABSPATH' ) ) exit;
17
-
18
- /**
19
- * Attach BuddyPress to WordPress
20
- *
21
- * BuddyPress uses its own internal actions to help aid in third-party plugin
22
- * development, and to limit the amount of potential future code changes when
23
- * updates to WordPress core occur.
24
- *
25
- * These actions exist to create the concept of 'plugin dependencies'. They
26
- * provide a safe way for plugins to execute code *only* when BuddyPress is
27
- * installed and activated, without needing to do complicated guesswork.
28
- *
29
- * For more information on how this works, see the 'Plugin Dependency' section
30
- * near the bottom of this file.
31
- *
32
- * v--WordPress Actions v--BuddyPress Sub-actions
33
- */
34
- add_action( 'plugins_loaded', 'bp_loaded', 10 );
35
- add_action( 'init', 'bp_init', 10 );
36
- add_action( 'wp', 'bp_ready', 10 );
37
- add_action( 'setup_theme', 'bp_setup_theme', 10 );
38
- add_action( 'after_theme_setup', 'bp_after_theme_setup', 10 );
39
- add_action( 'wp_enqueue_scripts', 'bp_enqueue_scripts', 10 );
40
- add_action( 'admin_bar_menu', 'bp_setup_admin_bar', 20 ); // After WP core
41
- add_action( 'template_redirect', 'bp_template_redirect', 10 );
42
- add_action( 'widgets_init', 'bp_widgets_init', 10 );
43
- add_filter( 'template_include', 'bp_template_include', 10 );
44
- add_filter( 'map_meta_cap', 'bp_map_meta_caps', 10, 4 );
45
-
46
- /**
47
- * bp_loaded - Attached to 'plugins_loaded' above
48
- *
49
- * Attach various loader actions to the bp_loaded action.
50
- * The load order helps to execute code at the correct time.
51
- * v---Load order
52
- */
53
- add_action( 'bp_loaded', 'bp_setup_components', 2 );
54
- add_action( 'bp_loaded', 'bp_include', 4 );
55
- add_action( 'bp_loaded', 'bp_setup_widgets', 6 );
56
- add_action( 'bp_loaded', 'bp_core_load_admin_bar', 10 );
57
-
58
- /**
59
- * bp_init - Attached to 'init' above
60
- *
61
- * Attach various initialization actions to the bp_init action.
62
- * The load order helps to execute code at the correct time.
63
- * v---Load order
64
- */
65
- add_action( 'bp_init', 'bp_core_set_uri_globals', 2 );
66
- add_action( 'bp_init', 'bp_setup_globals', 4 );
67
- add_action( 'bp_init', 'bp_setup_nav', 6 );
68
- add_action( 'bp_init', 'bp_setup_title', 8 );
69
-
70
- /**
71
- * bp_template_redirect - Attached to 'template_redirect' above
72
- *
73
- * Attach various template actions to the bp_template_redirect action.
74
- * The load order helps to execute code at the correct time.
75
- *
76
- * Note that we currently use template_redirect versus template include because
77
- * BuddyPress is a bully and overrides the existing themes output in many
78
- * places. This won't always be this way, we promise.
79
- * v---Load order
80
- */
81
- add_action( 'bp_template_redirect', 'bp_redirect_canonical', 2 );
82
- add_action( 'bp_template_redirect', 'bp_actions', 4 );
83
- add_action( 'bp_template_redirect', 'bp_screens', 6 );
84
-
85
- // Load the admin
86
- if ( is_admin() ) {
87
- add_action( 'bp_loaded', 'bp_admin' );
88
- }
89
-
90
- /**
91
- * Plugin Dependency
92
- *
93
- * The purpose of the following actions is to mimic the behavior of something
94
- * called 'plugin dependency' which enables a plugin to have plugins of their
95
- * own in a safe and reliable way.
96
- *
97
- * We do this in BuddyPress by mirroring existing WordPress actions in many places
98
- * allowing dependant plugins to hook into the BuddyPress specific ones, thus
99
- * guaranteeing proper code execution only whenBuddyPresss is active.
100
- *
101
- * The following functions are wrappers for their actions, allowing them to be
102
- * manually called and/or piggy-backed on top of other actions if needed.
103
- */
104
-
105
- /** Sub-actions ***************************************************************/
106
-
107
- /**
108
- * Include files on this action
109
- */
110
- function bp_include() {
111
- do_action( 'bp_include' );
112
- }
113
-
114
- /**
115
- * Include files on this action
116
- */
117
- function bp_setup_components() {
118
- do_action( 'bp_setup_components' );
119
- }
120
-
121
- /**
122
- * Setup global variables and objects
123
- */
124
- function bp_setup_globals() {
125
- do_action( 'bp_setup_globals' );
126
- }
127
-
128
- /**
129
- * Set navigation elements
130
- */
131
- function bp_setup_nav() {
132
- do_action( 'bp_setup_nav' );
133
- }
134
-
135
- /**
136
- * Set up BuddyPress implementation of the WP Toolbar
137
- */
138
- function bp_setup_admin_bar() {
139
- if ( bp_use_wp_admin_bar() )
140
- do_action( 'bp_setup_admin_bar' );
141
- }
142
-
143
- /**
144
- * Set the page title
145
- */
146
- function bp_setup_title() {
147
- do_action( 'bp_setup_title' );
148
- }
149
-
150
- /**
151
- * Register widgets
152
- */
153
- function bp_setup_widgets() {
154
- do_action( 'bp_register_widgets' );
155
- }
156
-
157
- /**
158
- * Initlialize code
159
- */
160
- function bp_init() {
161
- do_action( 'bp_init' );
162
- }
163
-
164
- /**
165
- * Attached to plugins_loaded
166
- */
167
- function bp_loaded() {
168
- do_action( 'bp_loaded' );
169
- }
170
-
171
- /**
172
- * Attached to wp
173
- */
174
- function bp_ready() {
175
- do_action( 'bp_ready' );
176
- }
177
-
178
- /**
179
- * Attach potential template actions
180
- */
181
- function bp_actions() {
182
- do_action( 'bp_actions' );
183
- }
184
-
185
- /**
186
- * Attach potential template screens
187
- */
188
- function bp_screens() {
189
- do_action( 'bp_screens' );
190
- }
191
-
192
- /**
193
- * Initialize widgets
194
- */
195
- function bp_widgets_init() {
196
- do_action ( 'bp_widgets_init' );
197
- }
198
-
199
- /** Theme *********************************************************************/
200
-
201
- /**
202
- * Enqueue BuddyPress specific CSS and JS
203
- *
204
- * @since BuddyPress (1.6)
205
- *
206
- * @uses do_action() Calls 'bp_enqueue_scripts'
207
- */
208
- function bp_enqueue_scripts() {
209
- do_action ( 'bp_enqueue_scripts' );
210
- }
211
-
212
- /**
213
- * Piggy back action for BuddyPress sepecific theme actions before the theme has
214
- * been setup and the theme's functions.php has loaded.
215
- *
216
- * @since BuddyPress (1.6)
217
- *
218
- * @uses do_action() Calls 'bp_setup_theme'
219
- */
220
- function bp_setup_theme() {
221
- do_action ( 'bp_setup_theme' );
222
- }
223
-
224
- /**
225
- * Piggy back action for BuddyPress sepecific theme actions once the theme has
226
- * been setup and the theme's functions.php has loaded.
227
- *
228
- * @since BuddyPress (1.6)
229
- *
230
- * @uses do_action() Calls 'bp_after_theme_setup'
231
- */
232
- function bp_after_theme_setup() {
233
- do_action ( 'bp_after_theme_setup' );
234
- }
235
-
236
- /** Theme Compatibility Filter ************************************************/
237
-
238
- /**
239
- * The main filter used for theme compatibility and displaying custom BuddyPress
240
- * theme files.
241
- *
242
- * @since BuddyPress (1.6)
243
- *
244
- * @uses apply_filters()
245
- *
246
- * @param string $template
247
- * @return string Template file to use
248
- */
249
- function bp_template_include( $template = '' ) {
250
- return apply_filters( 'bp_template_include', $template );
251
- }
252
-
253
- /** Theme Permissions *********************************************************/
254
-
255
- /**
256
- * The main action used for redirecting BuddyPress theme actions that are not
257
- * permitted by the current_user
258
- *
259
- * @since BuddyPress (1.6)
260
- *
261
- * @uses do_action()
262
- */
263
- function bp_template_redirect() {
264
- do_action( 'bp_template_redirect' );
265
- }
266
-
267
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-core/bp-core-admin.php DELETED
@@ -1,511 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Main BuddyPress Admin Class
5
- *
6
- * @package BuddyPress
7
- * @subpackage CoreAdministration
8
- */
9
-
10
- // Exit if accessed directly
11
- if ( !defined( 'ABSPATH' ) ) exit;
12
-
13
- if ( !class_exists( 'BP_Admin' ) ) :
14
- /**
15
- * Loads BuddyPress plugin admin area
16
- *
17
- * @package BuddyPress
18
- * @subpackage CoreAdministration
19
- * @since BuddyPress (1.6)
20
- */
21
- class BP_Admin {
22
-
23
- /**
24
- * Instance of the setup wizard
25
- *
26
- * @since BuddyPress (1.6)
27
- * @var BP_Core_Setup_Wizard
28
- */
29
- public $wizard;
30
-
31
- /** Directory *************************************************************/
32
-
33
- /**
34
- * @var string Path to the BuddyPress admin directory
35
- */
36
- public $admin_dir = '';
37
-
38
- /** URLs ******************************************************************/
39
-
40
- /**
41
- * @var string URL to the BuddyPress admin directory
42
- */
43
- public $admin_url = '';
44
-
45
- /**
46
- * @var string URL to the BuddyPress images directory
47
- */
48
- public $images_url = '';
49
-
50
- /**
51
- * @var string URL to the BuddyPress admin CSS directory
52
- */
53
- public $css_url = '';
54
-
55
- /**
56
- * @var string URL to the BuddyPress admin JS directory
57
- */
58
- public $js_url = '';
59
-
60
-
61
- /** Methods ***************************************************************/
62
-
63
- /**
64
- * The main BuddyPress admin loader
65
- *
66
- * @since BuddyPress (1.6)
67
- *
68
- * @uses BBP_Admin::setup_globals() Setup the globals needed
69
- * @uses BBP_Admin::includes() Include the required files
70
- * @uses BBP_Admin::setup_actions() Setup the hooks and actions
71
- */
72
- public function __construct() {
73
- $this->setup_globals();
74
- $this->includes();
75
- $this->setup_actions();
76
- }
77
-
78
- /**
79
- * Admin globals
80
- *
81
- * @since BuddyPress (1.6)
82
- * @access private
83
- */
84
- private function setup_globals() {
85
- global $bp;
86
-
87
- // Admin url
88
- $this->admin_dir = trailingslashit( $bp->plugin_dir . 'bp-core/admin' );
89
-
90
- // Admin url
91
- $this->admin_url = trailingslashit( $bp->plugin_url . 'bp-core/admin' );
92
-
93
- // Admin images URL
94
- $this->images_url = trailingslashit( $this->admin_url . 'images' );
95
-
96
- // Admin css URL
97
- $this->css_url = trailingslashit( $this->admin_url . 'css' );
98
-
99
- // Admin css URL
100
- $this->js_url = trailingslashit( $this->admin_url . 'js' );
101
- }
102
-
103
- /**
104
- * Include required files
105
- *
106
- * @since BuddyPress (1.6)
107
- * @access private
108
- */
109
- private function includes() {
110
-
111
- // If in maintenance mode, only include updater and schema
112
- if ( bp_get_maintenance_mode() ) {
113
- require( $this->admin_dir . 'bp-core-schema.php' );
114
- require( $this->admin_dir . 'bp-core-update.php' );
115
-
116
- // No update needed so proceed with loading everything
117
- } else {
118
- require( $this->admin_dir . 'bp-core-settings.php' );
119
- require( $this->admin_dir . 'bp-core-functions.php' );
120
- require( $this->admin_dir . 'bp-core-components.php' );
121
- require( $this->admin_dir . 'bp-core-slugs.php' );
122
- }
123
- }
124
-
125
- /**
126
- * Setup the admin hooks, actions and filters
127
- *
128
- * @since BuddyPress (1.6)
129
- * @access private
130
- *
131
- * @uses add_action() To add various actions
132
- * @uses add_filter() To add various filters
133
- */
134
- private function setup_actions() {
135
-
136
- // Start the wizard if in maintenance mode
137
- if ( bp_get_maintenance_mode() ) {
138
- add_action( bp_core_admin_hook(), array( $this, 'start_wizard' ), 2 );
139
- }
140
-
141
- /** General Actions ***************************************************/
142
-
143
- // Attach the BuddyPress admin_init action to the WordPress admin_init action.
144
- add_action( 'admin_init', array( $this, 'admin_init' ) );
145
-
146
- // Add some page specific output to the <head>
147
- add_action( 'admin_head', array( $this, 'admin_head' ) );
148
-
149
- // Add menu item to settings menu
150
- add_action( bp_core_admin_hook(), array( $this, 'admin_menus' ), 5 );
151
-
152
- // Add notice if not using a BuddyPress theme
153
- add_action( 'admin_notices', array( $this, 'admin_notices' ) );
154
- add_action( 'network_admin_notices', array( $this, 'admin_notices' ) );
155
-
156
- // Enqueue all admin JS and CSS
157
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
158
-
159
- /** BuddyPress Actions ************************************************/
160
-
161
- // Add settings
162
- add_action( 'bp_admin_init', array( $this, 'register_admin_settings' ) );
163
-
164
- /** Filters ***********************************************************/
165
-
166
- // Add link to settings page
167
- add_filter( 'plugin_action_links', array( $this, 'add_settings_link' ), 10, 2 );
168
- }
169
-
170
- public function start_wizard() {
171
- $this->wizard = new BP_Core_Setup_Wizard;
172
- }
173
-
174
- /**
175
- * Add the navigational menu elements
176
- *
177
- * @since BuddyPress (1.6)
178
- *
179
- * @uses add_management_page() To add the Recount page in Tools section
180
- * @uses add_options_page() To add the Forums settings page in Settings
181
- * section
182
- */
183
- public function admin_menus() {
184
-
185
- // In maintenance mode
186
- if ( bp_get_maintenance_mode() ) {
187
-
188
- if ( !current_user_can( 'manage_options' ) )
189
- return;
190
-
191
- if ( bp_get_maintenance_mode() == 'install' )
192
- $status = __( 'BuddyPress Setup', 'buddypress' );
193
- else
194
- $status = __( 'Update BuddyPress', 'buddypress' );
195
-
196
- if ( bp_get_wizard() ) {
197
- if ( ! is_multisite() || bp_is_multiblog_mode() ) {
198
- $hook = add_dashboard_page( $status, $status, 'manage_options', 'bp-wizard', array( bp_get_wizard(), 'html' ) );
199
- } else {
200
- $hook = add_submenu_page( 'update-core.php', $status, $status, 'manage_options', 'bp-wizard', array( bp_get_wizard(), 'html' ) );
201
- }
202
- }
203
-
204
- // Not in maintenance mode
205
- } else {
206
-
207
- // Bail if user cannot moderate
208
- if ( ! bp_current_user_can( 'manage_options' ) )
209
- return;
210
-
211
- $hooks = array();
212
- $page = bp_core_do_network_admin() ? 'settings.php' : 'options-general.php';
213
-
214
- // Changed in BP 1.6 . See bp_core_admin_backpat_menu()
215
- $hooks[] = add_menu_page(
216
- __( 'BuddyPress', 'buddypress' ),
217
- __( 'BuddyPress', 'buddypress' ),
218
- 'manage_options',
219
- 'bp-general-settings',
220
- 'bp_core_admin_backpat_menu',
221
- ''
222
- );
223
-
224
- $hooks[] = add_submenu_page(
225
- 'bp-general-settings',
226
- __( 'BuddyPress Help', 'buddypress' ),
227
- __( 'Help', 'buddypress' ),
228
- 'manage_options',
229
- 'bp-general-settings',
230
- 'bp_core_admin_backpat_page'
231
- );
232
-
233
- // Add the option pages
234
- $hooks[] = add_submenu_page(
235
- $page,
236
- __( 'BuddyPress Components', 'buddypress' ),
237
- __( 'BuddyPress', 'buddypress' ),
238
- 'manage_options',
239
- 'bp-components',
240
- 'bp_core_admin_components_settings'
241
- );
242
-
243
- $hooks[] = add_submenu_page(
244
- $page,
245
- __( 'BuddyPress Pages', 'buddypress' ),
246
- __( 'BuddyPress Pages', 'buddypress' ),
247
- 'manage_options',
248
- 'bp-page-settings',
249
- 'bp_core_admin_slugs_settings'
250
- );
251
-
252
- $hooks[] = add_submenu_page(
253
- $page,
254
- __( 'BuddyPress Settings', 'buddypress' ),
255
- __( 'BuddyPress Settings', 'buddypress' ),
256
- 'manage_options',
257
- 'bp-settings',
258
- 'bp_core_admin_settings'
259
- );
260
-
261
- // Fudge the highlighted subnav item when on a BuddyPress admin page
262
- foreach( $hooks as $hook ) {
263
- add_action( "admin_head-$hook", 'bp_core_modify_admin_menu_highlight' );
264
- }
265
- }
266
- }
267
-
268
- /**
269
- * Register the settings
270
- *
271
- * @since BuddyPress (1.6)
272
- *
273
- * @uses add_settings_section() To add our own settings section
274
- * @uses add_settings_field() To add various settings fields
275
- * @uses register_setting() To register various settings
276
- * @uses do_action() Calls 'bp_register_admin_settings'
277
- */
278
- public function register_admin_settings() {
279
-
280
- /** Main Section ******************************************************/
281
-
282
- // Add the main section
283
- add_settings_section( 'bp_main', __( 'Main Settings', 'buddypress' ), 'bp_admin_setting_callback_main_section', 'buddypress' );
284
-
285
- // Hide toolbar for logged out users setting
286
- add_settings_field( 'hide-loggedout-adminbar', __( 'Toolbar', 'buddypress' ), 'bp_admin_setting_callback_admin_bar', 'buddypress', 'bp_main' );
287
- register_setting ( 'buddypress', 'hide-loggedout-adminbar', 'intval' );
288
-
289
- // Only show 'switch to Toolbar' option if the user chose to retain the BuddyBar during the 1.6 upgrade
290
- if ( (bool) bp_get_option( '_bp_force_buddybar', false ) ) {
291
- add_settings_field( '_bp_force_buddybar', __( 'Toolbar', 'buddypress' ), 'bp_admin_setting_callback_force_buddybar', 'buddypress', 'bp_main' );
292
- register_setting( 'buddypress', '_bp_force_buddybar', 'bp_admin_sanitize_callback_force_buddybar' );
293
- }
294
-
295
- // Allow account deletion
296
- add_settings_field( 'bp-disable-account-deletion', __( 'Account Deletion', 'buddypress' ), 'bp_admin_setting_callback_account_deletion', 'buddypress', 'bp_main' );
297
- register_setting ( 'buddypress', 'bp-disable-account-deletion', 'intval' );
298
-
299
- /** XProfile Section **************************************************/
300
-
301
- if ( bp_is_active( 'xprofile' ) ) {
302
-
303
- // Add the main section
304
- add_settings_section( 'bp_xprofile', __( 'Profile Settings', 'buddypress' ), 'bp_admin_setting_callback_xprofile_section', 'buddypress' );
305
-
306
- // Allow avatar uploads
307
- add_settings_field( 'bp-disable-avatar-uploads', __( 'Avatar Uploads', 'buddypress' ), 'bp_admin_setting_callback_avatar_uploads', 'buddypress', 'bp_xprofile' );
308
- register_setting ( 'buddypress', 'bp-disable-avatar-uploads', 'intval' );
309
-
310
- // Profile sync setting
311
- add_settings_field( 'bp-disable-profile-sync', __( 'Profile Syncing', 'buddypress' ), 'bp_admin_setting_callback_profile_sync', 'buddypress', 'bp_xprofile' );
312
- register_setting ( 'buddypress', 'bp-disable-profile-sync', 'intval' );
313
- }
314
-
315
- /** Groups Section ****************************************************/
316
-
317
- if ( bp_is_active( 'groups' ) ) {
318
-
319
- // Add the main section
320
- add_settings_section( 'bp_groups', __( 'Groups Settings', 'buddypress' ), 'bp_admin_setting_callback_groups_section', 'buddypress' );
321
-
322
- // Allow subscriptions setting
323
- add_settings_field( 'bp_restrict_group_creation', __( 'Group Creation', 'buddypress' ), 'bp_admin_setting_callback_group_creation', 'buddypress', 'bp_groups' );
324
- register_setting ( 'buddypress', 'bp_restrict_group_creation', 'intval' );
325
- }
326
-
327
- /** Forums ************************************************************/
328
-
329
- if ( bp_is_active( 'forums' ) && bp_forums_is_installed_correctly() ) {
330
-
331
- // Add the main section
332
- add_settings_section( 'bp_forums', __( 'Forums Settings', 'buddypress' ), 'bp_admin_setting_callback_bbpress_section', 'buddypress' );
333
-
334
- // Allow subscriptions setting
335
- add_settings_field( 'bb-config-location', __( 'bbPress Configuration', 'buddypress' ), 'bp_admin_setting_callback_bbpress_configuration', 'buddypress', 'bp_forums' );
336
- register_setting ( 'buddypress', 'bb-config-location', '' );
337
- }
338
-
339
- /** Activity Section **************************************************/
340
-
341
- if ( bp_is_active( 'activity' ) ) {
342
-
343
- // Add the main section
344
- add_settings_section( 'bp_activity', __( 'Activity Settings', 'buddypress' ), 'bp_admin_setting_callback_activity_section', 'buddypress' );
345
-
346
- // Activity commenting on blog and forum posts
347
- add_settings_field( 'bp-disable-blogforum-comments', __( 'Blog &amp; Forum Comments', 'buddypress' ), 'bp_admin_setting_callback_blogforum_comments', 'buddypress', 'bp_activity' );
348
- register_setting( 'buddypress', 'bp-disable-blogforum-comments', 'bp_admin_sanitize_callback_blogforum_comments' );
349
-
350
- // Allow activity akismet
351
- if ( is_plugin_active( 'akismet/akismet.php' ) && defined( 'AKISMET_VERSION' ) ) {
352
- add_settings_field( '_bp_enable_akismet', __( 'Akismet', 'buddypress' ), 'bp_admin_setting_callback_activity_akismet', 'buddypress', 'bp_activity' );
353
- register_setting ( 'buddypress', '_bp_enable_akismet', 'intval' );
354
- }
355
- }
356
-
357
- do_action( 'bp_register_admin_settings' );
358
- }
359
-
360
- /**
361
- * Add Settings link to plugins area
362
- *
363
- * @since BuddyPress (1.6)
364
- *
365
- * @param array $links Links array in which we would prepend our link
366
- * @param string $file Current plugin basename
367
- * @return array Processed links
368
- */
369
- public function add_settings_link( $links, $file ) {
370
- global $bp;
371
-
372
- if ( plugin_basename( $bp->file ) == $file ) {
373
- $url = bp_core_do_network_admin() ? network_admin_url( 'settings.php' ) : admin_url( 'options-general.php' );
374
- $settings_link = '<a href="' . add_query_arg( array( 'page' => 'bp-components' ), $url ) . '">' . __( 'Settings', 'buddypress' ) . '</a>';
375
- array_unshift( $links, $settings_link );
376
- }
377
-
378
- return $links;
379
- }
380
-
381
- /**
382
- * BuddyPress's dedicated admin init action
383
- *
384
- * @since BuddyPress (1.6)
385
- *
386
- * @uses do_action() Calls 'bp_admin_init'
387
- */
388
- public function admin_init() {
389
- do_action( 'bp_admin_init' );
390
- }
391
-
392
- /**
393
- * Add some general styling to the admin area
394
- *
395
- * @since BuddyPress (1.6)
396
- */
397
- public function admin_head() { }
398
-
399
- /**
400
- * Add some general styling to the admin area
401
- *
402
- * @since BuddyPress (1.6)
403
- */
404
- public function enqueue_scripts() {
405
-
406
- $maybe_dev = '';
407
- if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG )
408
- $maybe_dev = '.dev';
409
-
410
- $file = $this->css_url . "common{$maybe_dev}.css";
411
- $file = apply_filters( 'bp_core_admin_common_css', $file );
412
- wp_enqueue_style( 'bp-admin-common-css', $file, array(), bp_get_version() );
413
-
414
- // Extra bits for the installation wizard
415
- if ( bp_get_maintenance_mode() ) {
416
-
417
- // Styling
418
- $file = $this->css_url . "wizard{$maybe_dev}.css";
419
- $file = apply_filters( 'bp_core_admin_wizard_css', $file );
420
- wp_enqueue_style( 'bp-admin-wizard-css', $file, array(), bp_get_version() );
421
-
422
- // JS
423
- $file = $this->js_url . "wizard{$maybe_dev}.js";
424
- $file = apply_filters( 'bp_core_admin_wizard_js', $file );
425
- wp_enqueue_script( 'bp-admin-wizard-js', $file, array(), bp_get_version() );
426
-
427
- // We'll need the thickbox too
428
- wp_enqueue_script( 'thickbox' );
429
- wp_enqueue_style( 'thickbox' );
430
- }
431
-
432
- do_action( 'bp_admin_head' );
433
- }
434
-
435
- /**
436
- * Add any admin notices we might need, mostly for update or new installs
437
- *
438
- * @since BuddyPress (1.6)
439
- *
440
- * @global string $pagenow
441
- * @return If no notice is needed
442
- */
443
- public function admin_notices() {
444
- global $pagenow;
445
-
446
- // Bail if not in maintenance mode
447
- if ( ! bp_get_maintenance_mode() )
448
- return;
449
-
450
- // Bail if user cannot manage options
451
- if ( ! current_user_can( 'manage_options' ) )
452
- return;
453
-
454
- // Are we looking at a network?
455
- if ( bp_core_do_network_admin() ) {
456
-
457
- // Bail if looking at wizard page
458
- if ( ( 'admin.php' == $pagenow ) && ( !empty( $_GET['page'] ) && ( 'bp-wizard' == $_GET['page'] ) ) ) {
459
- return;
460
- }
461
-
462
- // Set the url for the nag
463
- $url = network_admin_url( 'admin.php?page=bp-wizard' );
464
-
465
- // Single site
466
- } else {
467
-
468
- // Bail if looking at wizard page
469
- if ( ( 'index.php' == $pagenow ) && ( !empty( $_GET['page'] ) && ( 'bp-wizard' == $_GET['page'] ) ) ) {
470
- return;
471
- }
472
-
473
- // Set the url for the nag
474
- $url = admin_url( 'index.php?page=bp-wizard' );
475
- }
476
-
477
- // What does the nag say?
478
- switch ( bp_get_maintenance_mode() ) {
479
-
480
- // Update text
481
- case 'update' :
482
- $msg = sprintf( __( 'BuddyPress has been updated! Please run the <a href="%s">update wizard</a>.', 'buddypress' ), $url );
483
- break;
484
-
485
- // First install text
486
- case 'install' : default :
487
- $msg = sprintf( __( 'BuddyPress was successfully activated! Please run the <a href="%s">installation wizard</a>.', 'buddypress' ), $url );
488
- break;
489
- } ?>
490
-
491
- <div class="update-nag"><?php echo $msg; ?></div>
492
-
493
- <?php
494
- }
495
- }
496
- endif; // class_exists check
497
-
498
- /**
499
- * Setup BuddyPress Admin
500
- *
501
- * @since BuddyPress (1.6)
502
- *
503
- * @uses BP_Admin
504
- */
505
- function bp_admin() {
506
- global $bp;
507
-
508
- $bp->admin = new BP_Admin();
509
- }
510
-
511
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-core/bp-core-adminbar.php CHANGED
@@ -1,9 +1,8 @@
1
  <?php
2
-
3
  /**
4
- * BuddyPress Core Toolbar
5
  *
6
- * Handles the core functions related to the WordPress Toolbar
7
  *
8
  * @package BuddyPress
9
  * @subpackage Core
@@ -12,65 +11,256 @@
12
  // Exit if accessed directly
13
  if ( !defined( 'ABSPATH' ) ) exit;
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  /**
16
- * Adds the secondary BuddyPress area to the my-account menu
17
  *
18
- * @since BuddyPress 1.6
19
- * @global WP_Admin_Bar $wp_admin_bar
20
- * @return If doing ajax
21
  */
22
- function bp_admin_bar_my_account_root() {
23
  global $wp_admin_bar;
24
 
25
- // Bail if this is an ajax request
26
- if ( !bp_use_wp_admin_bar() || defined( 'DOING_AJAX' ) )
27
- return;
 
 
 
28
 
29
- // Only add menu for logged in user
30
  if ( is_user_logged_in() ) {
31
 
32
- // Add secondary parent item for all BuddyPress components
33
- $wp_admin_bar->add_menu( array(
34
- 'parent' => 'my-account',
35
- 'id' => 'my-account-buddypress',
36
- 'title' => __( 'My Account' ),
37
- 'group' => true,
38
- 'meta' => array(
39
- 'class' => 'ab-sub-secondary'
40
- )
41
- ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  }
43
  }
44
- add_action( 'admin_bar_menu', 'bp_admin_bar_my_account_root', 100 );
45
 
46
  /**
47
- * Handle the Toolbar CSS
48
- *
49
- * @since BuddyPress 1.5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  */
51
  function bp_core_load_admin_bar_css() {
52
 
53
- if ( ! bp_use_wp_admin_bar() || ! is_admin_bar_showing() )
54
  return;
55
 
56
- // Toolbar styles
57
  if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG )
58
- $stylesheet = BP_PLUGIN_URL . 'bp-core/css/admin-bar.dev.css';
59
  else
60
- $stylesheet = BP_PLUGIN_URL . 'bp-core/css/admin-bar.css';
61
 
62
- wp_enqueue_style( 'bp-admin-bar', apply_filters( 'bp_core_admin_bar_css', $stylesheet ), array( 'admin-bar' ), bp_get_version() );
63
 
64
  if ( !is_rtl() )
65
  return;
66
 
67
  if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG )
68
- $stylesheet = BP_PLUGIN_URL . 'bp-core/css/admin-bar-rtl.dev.css';
69
  else
70
- $stylesheet = BP_PLUGIN_URL . 'bp-core/css/admin-bar-rtl.css';
71
 
72
- wp_enqueue_style( 'bp-admin-bar-rtl', apply_filters( 'bp_core_admin_bar_rtl_css', $stylesheet ), array( 'bp-admin-bar' ), bp_get_version() );
73
  }
74
  add_action( 'bp_init', 'bp_core_load_admin_bar_css' );
75
 
76
- ?>
1
  <?php
 
2
  /**
3
+ * BuddyPress Core Admin Bar
4
  *
5
+ * Handles the core functions related to the WordPress Admin Bar
6
  *
7
  * @package BuddyPress
8
  * @subpackage Core
11
  // Exit if accessed directly
12
  if ( !defined( 'ABSPATH' ) ) exit;
13
 
14
+ if ( !bp_use_wp_admin_bar() || defined( 'DOING_AJAX' ) )
15
+ return;
16
+
17
+ /**
18
+ * Adjust the admin bar menus based on which WordPress version this is
19
+ *
20
+ * @since BuddyPress (1.5.2)
21
+ */
22
+ function bp_core_admin_bar_version_check() {
23
+ if ( 3.2 == bp_get_major_wp_version() ) {
24
+ add_action( 'bp_setup_admin_bar', 'bp_admin_bar_root_site', 3 );
25
+ add_action( 'bp_setup_admin_bar', 'bp_admin_bar_comments_menu', 3 );
26
+ add_action( 'bp_setup_admin_bar', 'bp_admin_bar_appearance_menu', 3 );
27
+ add_action( 'bp_setup_admin_bar', 'bp_admin_bar_updates_menu', 3 );
28
+ }
29
+ }
30
+ add_action( 'admin_bar_menu', 'bp_core_admin_bar_version_check', 4 );
31
+
32
+ /**
33
+ * Unhook the WordPress core menus.
34
+ *
35
+ * @since BuddyPress (r4151)
36
+ *
37
+ * @uses remove_action
38
+ * @uses is_network_admin()
39
+ * @uses is_user_admin()
40
+ */
41
+ function bp_admin_bar_remove_wp_menus() {
42
+
43
+ if ( 3.2 == bp_get_major_wp_version() ) {
44
+ remove_action( 'admin_bar_menu', 'wp_admin_bar_my_account_menu', 10 );
45
+ remove_action( 'admin_bar_menu', 'wp_admin_bar_my_sites_menu', 20 );
46
+ remove_action( 'admin_bar_menu', 'wp_admin_bar_dashboard_view_site_menu', 25 );
47
+
48
+ // Don't show the 'Edit Page' menu on BP pages
49
+ if ( !bp_is_blog_page() )
50
+ remove_action( 'admin_bar_menu', 'wp_admin_bar_edit_menu', 30 );
51
+
52
+ remove_action( 'admin_bar_menu', 'wp_admin_bar_shortlink_menu', 80 );
53
+ remove_action( 'admin_bar_menu', 'wp_admin_bar_updates_menu', 70 );
54
+
55
+ if ( !is_network_admin() && !is_user_admin() ) {
56
+ remove_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 50 );
57
+ remove_action( 'admin_bar_menu', 'wp_admin_bar_appearance_menu', 60 );
58
+ }
59
+
60
+ remove_action( 'admin_bar_menu', 'wp_admin_bar_updates_menu', 70 );
61
+ } else {
62
+ if ( !bp_is_blog_page() ) {
63
+ remove_action( 'admin_bar_menu', 'wp_admin_bar_edit_menu', 80 );
64
+ }
65
+ }
66
+ }
67
+ add_action( 'bp_init', 'bp_admin_bar_remove_wp_menus', 2 );
68
+
69
  /**
70
+ * Add a menu for the root site of this BuddyPress network
71
  *
72
+ * @global type $wp_admin_bar
73
+ * @return If in ajax
 
74
  */
75
+ function bp_admin_bar_root_site() {
76
  global $wp_admin_bar;
77
 
78
+ // Create the root blog menu
79
+ $wp_admin_bar->add_menu( array(
80
+ 'id' => 'bp-root-blog',
81
+ 'title' => get_blog_option( bp_get_root_blog_id(), 'blogname' ),
82
+ 'href' => bp_get_root_domain()
83
+ ) );
84
 
85
+ // Logged in user
86
  if ( is_user_logged_in() ) {
87
 
88
+ // Dashboard links
89
+ if ( is_super_admin() ) {
90
+
91
+ // Add site admin link
92
+ $wp_admin_bar->add_menu( array(
93
+ 'id' => 'dashboard',
94
+ 'parent' => 'bp-root-blog',
95
+ 'title' => __( 'Admin Dashboard', 'buddypress' ),
96
+ 'href' => get_admin_url( bp_get_root_blog_id() )
97
+ ) );
98
+
99
+ // Add network admin link
100
+ if ( is_multisite() ) {
101
+
102
+ // Link to the network admin dashboard
103
+ $wp_admin_bar->add_menu( array(
104
+ 'id' => 'network-dashboard',
105
+ 'parent' => 'bp-root-blog',
106
+ 'title' => __( 'Network Dashboard', 'buddypress' ),
107
+ 'href' => network_admin_url()
108
+ ) );
109
+ }
110
+ }
111
  }
112
  }
 
113
 
114
  /**
115
+ * Add the "My Sites/[Site Name]" menu and all submenus.
116
+ */
117
+ function bp_admin_bar_my_sites_menu() {
118
+ global $wp_admin_bar;
119
+
120
+ /* Add the 'My Sites' menu if the user has more than one site. */
121
+ if ( count( $wp_admin_bar->user->blogs ) <= 1 )
122
+ return;
123
+
124
+ $wp_admin_bar->add_menu( array( 'id' => 'my-blogs', 'title' => __( 'My Sites' ), 'href' => admin_url( 'my-sites.php' ) ) );
125
+
126
+ $default = includes_url( 'images/wpmini-blue.png' );
127
+
128
+ foreach ( (array)$wp_admin_bar->user->blogs as $blog ) {
129
+ // @todo Replace with some favicon lookup.
130
+ //$blavatar = '<img src="' . esc_url( blavatar_url( blavatar_domain( $blog->siteurl ), 'img', 16, $default ) ) . '" alt="Blavatar" width="16" height="16" />';
131
+ $blavatar = '<img src="' . esc_url( $default ) . '" alt="' . esc_attr__( 'Blavatar' ) . '" width="16" height="16" class="blavatar"/>';
132
+
133
+ $blogname = empty( $blog->blogname ) ? $blog->domain : $blog->blogname;
134
+
135
+ $wp_admin_bar->add_menu( array( 'parent' => 'my-blogs', 'id' => 'blog-' . $blog->userblog_id, 'title' => $blavatar . $blogname, 'href' => get_admin_url( $blog->userblog_id ) ) );
136
+ $wp_admin_bar->add_menu( array( 'parent' => 'blog-' . $blog->userblog_id, 'id' => 'blog-' . $blog->userblog_id . '-d', 'title' => __( 'Dashboard' ), 'href' => get_admin_url( $blog->userblog_id ) ) );
137
+
138
+ if ( current_user_can_for_blog( $blog->userblog_id, 'edit_posts' ) ) {
139
+ $wp_admin_bar->add_menu( array( 'parent' => 'blog-' . $blog->userblog_id, 'id' => 'blog-' . $blog->userblog_id . '-n', 'title' => __( 'New Post' ), 'href' => get_admin_url( $blog->userblog_id, 'post-new.php' ) ) );
140
+ $wp_admin_bar->add_menu( array( 'parent' => 'blog-' . $blog->userblog_id, 'id' => 'blog-' . $blog->userblog_id . '-c', 'title' => __( 'Manage Comments' ), 'href' => get_admin_url( $blog->userblog_id, 'edit-comments.php' ) ) );
141
+ }
142
+
143
+ $wp_admin_bar->add_menu( array( 'parent' => 'blog-' . $blog->userblog_id, 'id' => 'blog-' . $blog->userblog_id . '-v', 'title' => __( 'Visit Site' ), 'href' => get_home_url( $blog->userblog_id ) ) );
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Add edit comments link with awaiting moderation count bubble
149
+ */
150
+ function bp_admin_bar_comments_menu( $wp_admin_bar ) {
151
+ global $wp_admin_bar;
152
+
153
+ if ( !current_user_can( 'edit_posts' ) )
154
+ return;
155
+
156
+ $awaiting_mod = wp_count_comments();
157
+ $awaiting_mod = $awaiting_mod->moderated;
158
+
159
+ $awaiting_mod = $awaiting_mod ? "<span id='ab-awaiting-mod' class='pending-count'>" . number_format_i18n( $awaiting_mod ) . "</span>" : '';
160
+ $wp_admin_bar->add_menu( array( 'parent' => 'dashboard', 'id' => 'comments', 'title' => sprintf( __( 'Comments %s' ), $awaiting_mod ), 'href' => admin_url( 'edit-comments.php' ) ) );
161
+ }
162
+
163
+ /**
164
+ * Add "Appearance" menu with widget and nav menu submenu
165
+ */
166
+ function bp_admin_bar_appearance_menu() {
167
+ global $wp_admin_bar;
168
+
169
+ // You can have edit_theme_options but not switch_themes.
170
+ if ( !current_user_can( 'switch_themes' ) && !current_user_can( 'edit_theme_options' ) )
171
+ return;
172
+
173
+ $wp_admin_bar->add_menu( array( 'parent' => 'dashboard', 'id' => 'appearance', 'title' => __( 'Appearance' ), 'href' => admin_url( 'themes.php' ) ) );
174
+
175
+ if ( !current_user_can( 'edit_theme_options' ) )
176
+ return;
177
+
178
+ if ( current_user_can( 'switch_themes' ) )
179
+ $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'themes', 'title' => __( 'Themes' ), 'href' => admin_url( 'themes.php' ) ) );
180
+
181
+ if ( current_theme_supports( 'widgets' ) )
182
+ $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'widgets', 'title' => __( 'Widgets' ), 'href' => admin_url( 'widgets.php' ) ) );
183
+
184
+ if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) )
185
+ $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __( 'Menus' ), 'href' => admin_url( 'nav-menus.php' ) ) );
186
+
187
+ if ( current_theme_supports( 'custom-background' ) )
188
+ $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'background', 'title' => __( 'Background' ), 'href' => admin_url( 'themes.php?page=custom-background' ) ) );
189
+
190
+ if ( current_theme_supports( 'custom-header' ) )
191
+ $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'header', 'title' => __( 'Header' ), 'href' => admin_url( 'themes.php?page=custom-header' ) ) );
192
+ }
193
+
194
+ /**
195
+ * Provide an update link if theme/plugin/core updates are available
196
+ */
197
+ function bp_admin_bar_updates_menu() {
198
+ global $wp_admin_bar;
199
+
200
+ if ( !current_user_can( 'install_plugins' ) )
201
+ return;
202
+
203
+ $plugin_update_count = $theme_update_count = $wordpress_update_count = 0;
204
+ $update_plugins = get_site_transient( 'update_plugins' );
205
+ if ( !empty( $update_plugins->response ) )
206
+ $plugin_update_count = count( $update_plugins->response );
207
+ $update_themes = get_site_transient( 'update_themes' );
208
+ if ( !empty( $update_themes->response ) )
209
+ $theme_update_count = count( $update_themes->response );
210
+ /* @todo get_core_updates() is only available on admin page loads
211
+ $update_wordpress = get_core_updates( array('dismissed' => false) );
212
+ if ( !empty($update_wordpress) && !in_array( $update_wordpress[0]->response, array('development', 'latest') ) )
213
+ $wordpress_update_count = 1;
214
+ */
215
+
216
+ $update_count = $plugin_update_count + $theme_update_count + $wordpress_update_count;
217
+
218
+ if ( !$update_count )
219
+ return;
220
+
221
+ $update_title = array( );
222
+ if ( !empty( $wordpress_update_count ) )
223
+ $update_title[] = sprintf( __( '%d WordPress Update' ), $wordpress_update_count );
224
+ if ( $plugin_update_count )
225
+ $update_title[] = sprintf( _n( '%d Plugin Update', '%d Plugin Updates', $plugin_update_count ), $plugin_update_count );
226
+ if ( $theme_update_count )
227
+ $update_title[] = sprintf( _n( '%d Theme Update', '%d Theme Updates', $theme_update_count ), $theme_update_count );
228
+
229
+ $update_title = !empty( $update_title ) ? esc_attr( implode( ', ', $update_title ) ) : '';
230
+
231
+ $update_title = "<span title='$update_title'>";
232
+ $update_title .= sprintf( __( 'Updates %s' ), "<span id='ab-updates' class='update-count'>" . number_format_i18n( $update_count ) . '</span>' );
233
+ $update_title .= '</span>';
234
+
235
+ $wp_admin_bar->add_menu( array( 'parent' => 'dashboard', 'id' => 'updates', 'title' => $update_title, 'href' => network_admin_url( 'update-core.php' ) ) );
236
+ }
237
+
238
+ /**
239
+ * Handle the Admin Bar CSS
240
  */
241
  function bp_core_load_admin_bar_css() {
242
 
243
+ if ( !bp_use_wp_admin_bar() )
244
  return;
245
 
246
+ // Admin bar styles
247
  if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG )
248
+ $stylesheet = BP_PLUGIN_URL . '/bp-core/css/admin-bar.dev.css';
249
  else
250
+ $stylesheet = BP_PLUGIN_URL . '/bp-core/css/admin-bar.css';
251
 
252
+ wp_enqueue_style( 'bp-admin-bar', apply_filters( 'bp_core_admin_bar_css', $stylesheet ), array( 'admin-bar' ), '20110723' );
253
 
254
  if ( !is_rtl() )
255
  return;
256
 
257
  if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG )
258
+ $stylesheet = BP_PLUGIN_URL . '/bp-core/css/admin-bar-rtl.dev.css';
259
  else
260
+ $stylesheet = BP_PLUGIN_URL . '/bp-core/css/admin-bar-rtl.css';
261
 
262
+ wp_enqueue_style( 'bp-admin-bar-rtl', apply_filters( 'bp_core_admin_bar_rtl_css', $stylesheet ), array( 'bp-admin-bar' ), '20110723' );
263
  }
264
  add_action( 'bp_init', 'bp_core_load_admin_bar_css' );
265
 
266
+ ?>
bp-core/bp-core-avatars.php CHANGED
@@ -14,7 +14,7 @@ if ( !defined( 'ABSPATH' ) ) exit;
14
  */
15
  function bp_core_set_avatar_constants() {
16
  global $bp;
17
-
18
  if ( !defined( 'BP_AVATAR_THUMB_WIDTH' ) )
19
  define( 'BP_AVATAR_THUMB_WIDTH', 50 );
20
 
@@ -31,54 +31,41 @@ function bp_core_set_avatar_constants() {
31
  define( 'BP_AVATAR_ORIGINAL_MAX_WIDTH', 450 );
32
 
33
  if ( !defined( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE' ) ) {
34
- if ( !isset( $bp->site_options['fileupload_maxk'] ) ) {
35
  define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', 5120000 ); // 5mb
36
- } else {
37
  define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', $bp->site_options['fileupload_maxk'] * 1024 );
38
- }
39
  }
40
 
41
  if ( !defined( 'BP_AVATAR_DEFAULT' ) )
42
- define( 'BP_AVATAR_DEFAULT', BP_PLUGIN_URL . 'bp-core/images/mystery-man.jpg' );
43
 
44
  if ( !defined( 'BP_AVATAR_DEFAULT_THUMB' ) )
45
- define( 'BP_AVATAR_DEFAULT_THUMB', BP_PLUGIN_URL . 'bp-core/images/mystery-man-50.jpg' );
46
  }
47
  add_action( 'bp_init', 'bp_core_set_avatar_constants', 3 );
48
 
49
  function bp_core_set_avatar_globals() {
50
  global $bp;
51
-
52
- $bp->avatar = new stdClass;
53
- $bp->avatar->thumb = new stdClass;
54
- $bp->avatar->full = new stdClass;
55
-
56
  // Dimensions
57
  $bp->avatar->thumb->width = BP_AVATAR_THUMB_WIDTH;
58
  $bp->avatar->thumb->height = BP_AVATAR_THUMB_HEIGHT;
59
  $bp->avatar->full->width = BP_AVATAR_FULL_WIDTH;
60
  $bp->avatar->full->height = BP_AVATAR_FULL_HEIGHT;
61
-
62
  // Upload maximums
63
  $bp->avatar->original_max_width = BP_AVATAR_ORIGINAL_MAX_WIDTH;
64
  $bp->avatar->original_max_filesize = BP_AVATAR_ORIGINAL_MAX_FILESIZE;
65
-
66
  // Defaults
67
- $bp->avatar->thumb->default = BP_AVATAR_DEFAULT_THUMB;
68
- $bp->avatar->full->default = BP_AVATAR_DEFAULT;
69
-
70
  // These have to be set on page load in order to avoid infinite filter loops at runtime
71
- $bp->avatar->upload_path = bp_core_avatar_upload_path();
72
- $bp->avatar->url = bp_core_avatar_url();
73
-
74
- // Backpat for pre-1.5
75
- if ( ! defined( 'BP_AVATAR_UPLOAD_PATH' ) )
76
- define( 'BP_AVATAR_UPLOAD_PATH', $bp->avatar->upload_path );
77
-
78
- // Backpat for pre-1.5
79
- if ( ! defined( 'BP_AVATAR_URL' ) )
80
- define( 'BP_AVATAR_URL', $bp->avatar->url );
81
-
82
  do_action( 'bp_core_set_avatar_globals' );
83
  }
84
  add_action( 'bp_setup_globals', 'bp_core_set_avatar_globals' );
@@ -89,7 +76,7 @@ add_action( 'bp_setup_globals', 'bp_core_set_avatar_globals' );
89
  * Fetches an avatar from a BuddyPress object. Supports user/group/blog as
90
  * default, but can be extended to include your own custom components too.
91
  *
92
- * @global BuddyPress $bp The one true BuddyPress instance
93
  * @global $current_blog WordPress global containing information and settings for the current blog being viewed.
94
  * @param array $args Determine the output of this function
95
  * @return string Formatted HTML <img> element, or raw avatar URL based on $html arg
@@ -101,6 +88,7 @@ function bp_core_fetch_avatar( $args = '' ) {
101
  $def_object = 'user';
102
  $def_type = 'thumb';
103
  $def_class = 'avatar';
 
104
 
105
  // Set the default variables array
106
  $defaults = array(
@@ -112,7 +100,7 @@ function bp_core_fetch_avatar( $args = '' ) {
112
  'height' => false, // Custom height (int)
113
  'class' => $def_class, // Custom <img> class (string)
114
  'css_id' => false, // Custom <img> ID (string)
115
- 'alt' => '', // Custom <img> alt (string)
116
  'email' => false, // Pass the user email (for gravatar) to prevent querying the DB for it
117
  'no_grav' => false, // If there is no avatar found, return false instead of a grav?
118
  'html' => true, // Wrap the return img URL in <img />
@@ -123,136 +111,76 @@ function bp_core_fetch_avatar( $args = '' ) {
123
  $params = wp_parse_args( $args, $defaults );
124
  extract( $params, EXTR_SKIP );
125
 
126
- /** Set item_id ***********************************************************/
127
-
128
- if ( empty( $item_id ) ) {
129
-
130
- switch ( $object ) {
131
-
132
- case 'blog' :
133
- $item_id = $current_blog->id;
134
- break;
135
-
136
- case 'group' :
137
- if ( bp_is_active( 'groups' ) ) {
138
- $item_id = $bp->groups->current_group->id;
139
- } else {
140
- $item_id = false;
141
- }
142
-
143
- break;
144
-
145
- case 'user' :
146
- default :
147
- $item_id = bp_displayed_user_id();
148
- break;
149
- }
150
 
151
- $item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object, $params );
152
 
153
- if ( empty( $item_id ) ) {
154
  return false;
155
- }
156
  }
157
 
158
- $class = apply_filters( 'bp_core_avatar_class', $class, $item_id, $object, $params );
159
-
160
- /** Set avatar_dir ********************************************************/
161
-
162
- if ( empty( $avatar_dir ) ) {
163
-
164
- switch ( $object ) {
165
-
166
- case 'blog' :
167
- $avatar_dir = 'blog-avatars';
168
- break;
169
-
170
- case 'group' :
171
- if ( bp_is_active( 'groups' ) ) {
172
- $avatar_dir = 'group-avatars';
173
- } else {
174
- $avatar_dir = false;
175
- }
176
-
177
- break;
178
-
179
- case 'user' :
180
- default :
181
- $avatar_dir = 'avatars';
182
- break;
183
- }
184
 
185
- $avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object, $params );
186
 
187
- if ( empty( $avatar_dir ) ) {
188
  return false;
189
- }
190
  }
191
 
192
- /** <img> alt *************************************************************/
193
-
194
- if ( false !== strpos( $alt, '%s' ) || false !== strpos( $alt, '%1$s' ) ) {
195
-
196
- // Get item name for alt/title tags
197
- $item_name = '';
198
-
199
- switch ( $object ) {
200
-
201
- case 'blog' :
202
- $item_name = get_blog_option( $item_id, 'blogname' );
203
- break;
204
-
205
- case 'group' :
206
- $item_name = bp_get_group_name( groups_get_group( array( 'group_id' => $item_id ) ) );
207
- break;
208
-
209
- case 'user' :
210
- default :
211
- $item_name = bp_core_get_user_displayname( $item_id );
212
- break;
213
- }
214
 
215
- $item_name = apply_filters( 'bp_core_avatar_alt', $item_name, $item_id, $object, $params );
216
- $alt = sprintf( $alt, $item_name );
217
- }
218
 
219
- /** Sanity Checks *********************************************************/
 
 
 
 
 
220
 
221
- // Get a fallback for the 'alt' parameter
222
- if ( empty( $alt ) )
223
- $alt = __( 'Avatar Image', 'buddypress' );
224
 
225
- // Set title tag, if it's been provided
226
- if ( !empty( $title ) )
227
- $title = " title='" . esc_attr( apply_filters( 'bp_core_avatar_title', $title, $item_id, $object, $params ) ) . "'";
 
 
228
 
229
  // Set CSS ID if passed
230
  if ( !empty( $css_id ) )
231
- $css_id = ' id="' . $css_id . '"';
232
 
233
- // Set image width
234
- if ( false !== $width )
235
- $html_width = ' width="' . $width . '"';
236
  else
237
  $html_width = ( 'thumb' == $type ) ? ' width="' . bp_core_avatar_thumb_width() . '"' : ' width="' . bp_core_avatar_full_width() . '"';
238
 
239
- // Set image height
240
- if ( false !== $height )
241
- $html_height = ' height="' . $height . '"';
242
  else
243
  $html_height = ( 'thumb' == $type ) ? ' height="' . bp_core_avatar_thumb_height() . '"' : ' height="' . bp_core_avatar_full_height() . '"';
244
 
245
- // Set img URL and DIR based on prepopulated constants
246
- $avatar_loc = new stdClass();
247
- $avatar_loc->path = trailingslashit( bp_core_avatar_upload_path() );
248
- $avatar_loc->url = trailingslashit( bp_core_avatar_url() );
249
-
250
- $avatar_loc->dir = trailingslashit( $avatar_dir );
251
- $avatar_folder_url = apply_filters( 'bp_core_avatar_folder_url', ( $avatar_loc->url . $avatar_loc->dir . $item_id ), $item_id, $object, $avatar_dir );
252
- $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', ( $avatar_loc->path . $avatar_loc->dir . $item_id ), $item_id, $object, $avatar_dir );
253
-
254
- // Add an identifying class
255
- $class .= ' ' . $object . '-' . $item_id . '-avatar';
256
 
257
  /****
258
  * Look for uploaded avatar first. Use it if it exists.
@@ -271,11 +199,10 @@ function bp_core_fetch_avatar( $args = '' ) {
271
 
272
  // Stash files in an array once to check for one that matches
273
  $avatar_files = array();
274
- while ( false !== ( $avatar_file = readdir( $av_dir ) ) ) {
275
  // Only add files to the array (skip directories)
276
- if ( 2 < strlen( $avatar_file ) ) {
277
  $avatar_files[] = $avatar_file;
278
- }
279
  }
280
 
281
  // Check for array
@@ -283,25 +210,22 @@ function bp_core_fetch_avatar( $args = '' ) {
283
 
284
  // Check for current avatar
285
  foreach( $avatar_files as $key => $value ) {
286
- if ( strpos ( $value, $avatar_size )!== false ) {
287
  $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
288
- }
289
  }
290
 
291
  // Legacy avatar check
292
  if ( !isset( $avatar_url ) ) {
293
  foreach( $avatar_files as $key => $value ) {
294
- if ( strpos ( $value, $legacy_user_avatar_name )!== false ) {
295
  $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
296
- }
297
  }
298
 
299
  // Legacy group avatar check
300
  if ( !isset( $avatar_url ) ) {
301
  foreach( $avatar_files as $key => $value ) {
302
- if ( strpos ( $value, $legacy_group_avatar_name )!== false ) {
303
  $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
304
- }
305
  }
306
  }
307
  }
@@ -315,7 +239,7 @@ function bp_core_fetch_avatar( $args = '' ) {
315
  if ( isset( $avatar_url ) ) {
316
 
317
  // Return it wrapped in an <img> element
318
- if ( !empty( $html ) ) {
319
  return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $avatar_url . '" alt="' . esc_attr( $alt ) . '" class="' . esc_attr( $class ) . '"' . $css_id . $html_width . $html_height . $title . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
320
 
321
  // ...or only the URL
@@ -331,22 +255,20 @@ function bp_core_fetch_avatar( $args = '' ) {
331
  if ( ! apply_filters( 'bp_core_fetch_avatar_no_grav', $no_grav ) ) {
332
 
333
  // Set gravatar size
334
- if ( false !== $width ) {
335
  $grav_size = $width;
336
- } else if ( 'full' == $type ) {
337
  $grav_size = bp_core_avatar_full_width();
338
- } else if ( 'thumb' == $type ) {
339
  $grav_size = bp_core_avatar_thumb_width();
340
- }
341
 
342
  // Set gravatar type
343
- if ( empty( $bp->grav_default->{$object} ) ) {
344
  $default_grav = 'wavatar';
345
- } else if ( 'mystery' == $bp->grav_default->{$object} ) {
346
  $default_grav = apply_filters( 'bp_core_mysteryman_src', bp_core_avatar_default(), $grav_size );
347
- } else {
348
  $default_grav = $bp->grav_default->{$object};
349
- }
350
 
351
  // Set gravatar object
352
  if ( empty( $email ) ) {
@@ -358,26 +280,21 @@ function bp_core_fetch_avatar( $args = '' ) {
358
  }
359
 
360
  // Set host based on if using ssl
361
- $host = 'http://www.gravatar.com/avatar/';
362
- if ( is_ssl() ) {
363
  $host = 'https://secure.gravatar.com/avatar/';
364
- }
 
365
 
366
  // Filter gravatar vars
367
  $email = apply_filters( 'bp_core_gravatar_email', $email, $item_id, $object );
368
  $gravatar = apply_filters( 'bp_gravatar_url', $host ) . md5( strtolower( $email ) ) . '?d=' . $default_grav . '&amp;s=' . $grav_size;
369
 
370
- // Gravatar rating; http://bit.ly/89QxZA
371
- $rating = get_option( 'avatar_rating' );
372
- if ( ! empty( $rating ) )
373
- $gravatar .= "&amp;r={$rating}";
374
-
375
- // No avatar was found, and we've been told not to use a gravatar.
376
  } else {
377
- $gravatar = apply_filters( "bp_core_default_avatar_$object", BP_PLUGIN_URL . 'bp-core/images/mystery-man.jpg', $params );
 
378
  }
379
 
380
- if ( !empty( $html ) )
381
  return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $gravatar . '" alt="' . esc_attr( $alt ) . '" class="' . esc_attr( $class ) . '"' . $css_id . $html_width . $html_height . $title . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
382
  else
383
  return apply_filters( 'bp_core_fetch_avatar_url', $gravatar );
@@ -407,9 +324,9 @@ function bp_core_delete_existing_avatar( $args = '' ) {
407
  $args = wp_parse_args( $args, $defaults );
408
  extract( $args, EXTR_SKIP );
409
 
410
- if ( empty( $item_id ) ) {
411
  if ( 'user' == $object )
412
- $item_id = bp_displayed_user_id();
413
  else if ( 'group' == $object )
414
  $item_id = $bp->groups->current_group->id;
415
  else if ( 'blog' == $object )
@@ -420,7 +337,7 @@ function bp_core_delete_existing_avatar( $args = '' ) {
420
  if ( !$item_id ) return false;
421
  }
422
 
423
- if ( empty( $avatar_dir ) ) {
424
  if ( 'user' == $object )
425
  $avatar_dir = 'avatars';
426
  else if ( 'group' == $object )
@@ -565,10 +482,12 @@ function bp_core_avatar_handle_upload( $file, $upload_dir_filter ) {
565
  * crop_x - The horizontal starting point of the crop
566
  * crop_y - The vertical starting point of the crop
567
  *
 
568
  * @param mixed $args
569
  * @return bool Success/failure
570
  */
571
  function bp_core_avatar_handle_crop( $args = '' ) {
 
572
 
573
  $defaults = array(
574
  'object' => 'user',
@@ -615,10 +534,10 @@ function bp_core_avatar_handle_crop( $args = '' ) {
615
  bp_core_delete_existing_avatar( array( 'object' => $object, 'avatar_path' => $avatar_folder_dir ) );
616
 
617
  // Make sure we at least have a width and height for cropping
618
- if ( !(int) $crop_w )
619
  $crop_w = bp_core_avatar_full_width();
620
 
621
- if ( !(int) $crop_h )
622
  $crop_h = bp_core_avatar_full_height();
623
 
624
  // Set the full and thumb filenames
@@ -626,12 +545,8 @@ function bp_core_avatar_handle_crop( $args = '' ) {
626
  $thumb_filename = wp_hash( $original_file . time() ) . '-bpthumb.jpg';
627
 
628
  // Crop the image
629
- $full_cropped = wp_crop_image( $original_file, (int) $crop_x, (int) $crop_y, (int) $crop_w, (int) $crop_h, bp_core_avatar_full_width(), bp_core_avatar_full_height(), false, $avatar_folder_dir . '/' . $full_filename );
630
- $thumb_cropped = wp_crop_image( $original_file, (int) $crop_x, (int) $crop_y, (int) $crop_w, (int) $crop_h, bp_core_avatar_thumb_width(), bp_core_avatar_thumb_height(), false, $avatar_folder_dir . '/' . $thumb_filename );
631
-
632
- // Check for errors
633
- if ( ! $full_cropped || ! $thumb_cropped || is_wp_error( $full_cropped ) || is_wp_error( $thumb_cropped ) )
634
- return false;
635
 
636
  // Remove the original
637
  @unlink( $original_file );
@@ -677,7 +592,7 @@ function bp_core_fetch_avatar_filter( $avatar, $user, $size, $default, $alt = ''
677
  return !empty( $avatar ) ? $avatar : $default;
678
 
679
  if ( !$alt )
680
- $alt = sprintf( __( 'Avatar of %s', 'buddypress' ), bp_core_get_user_displayname( $id ) );
681
 
682
  // Let BuddyPress handle the fetching of the avatar
683
  $bp_avatar = bp_core_fetch_avatar( array( 'item_id' => $id, 'width' => $size, 'height' => $size, 'alt' => $alt ) );
@@ -738,7 +653,7 @@ function bp_core_check_avatar_type($file) {
738
  */
739
  function bp_core_avatar_upload_path() {
740
  global $bp;
741
-
742
  // See if the value has already been calculated and stashed in the $bp global
743
  if ( isset( $bp->avatar->upload_path ) ) {
744
  $basedir = $bp->avatar->upload_path;
@@ -751,26 +666,26 @@ function bp_core_avatar_upload_path() {
751
  // Switch dynamically in order to support BP_ENABLE_MULTIBLOG
752
  switch_to_blog( bp_get_root_blog_id() );
753
  }
754
-
755
  // Get upload directory information from current site
756
  $upload_dir = wp_upload_dir();
757
-
758
  // Directory does not exist and cannot be created
759
  if ( !empty( $upload_dir['error'] ) ) {
760
  $basedir = '';
761
-
762
  } else {
763
  $basedir = $upload_dir['basedir'];
764
  }
765
-
766
  // Will bail if not switched
767
  restore_current_blog();
768
  }
769
-
770
  // Stash in $bp for later use
771
  $bp->avatar->upload_path = $basedir;
772
  }
773
-
774
  return apply_filters( 'bp_core_avatar_upload_path', $basedir );
775
  }
776
 
@@ -784,11 +699,10 @@ function bp_core_avatar_upload_path() {
784
  */
785
  function bp_core_avatar_url() {
786
  global $bp;
787
-
788
  // See if the value has already been calculated and stashed in the $bp global
789
  if ( isset( $bp->avatar->url ) ) {
790
  $baseurl = $bp->avatar->url;
791
-
792
  } else {
793
  // If this value has been set in a constant, just use that
794
  if ( defined( 'BP_AVATAR_URL' ) ) {
@@ -796,24 +710,20 @@ function bp_core_avatar_url() {
796
  } else {
797
  // Get upload directory information from current site
798
  $upload_dir = wp_upload_dir();
799
-
800
  // Directory does not exist and cannot be created
801
  if ( !empty( $upload_dir['error'] ) ) {
802
  $baseurl = '';
803
-
804
  } else {
805
  $baseurl = $upload_dir['baseurl'];
806
-
807
- // If we're using https, update the protocol. Workaround for WP13941, WP15928, WP19037.
808
- if ( is_ssl() )
809
- $baseurl = str_replace( 'http://', 'https://', $baseurl );
810
-
811
  // If multisite, and current blog does not match root blog, make adjustments
812
  if ( is_multisite() && bp_get_root_blog_id() != get_current_blog_id() )
813
  $baseurl = trailingslashit( get_blog_option( bp_get_root_blog_id(), 'home' ) ) . get_blog_option( bp_get_root_blog_id(), 'upload_path' );
814
  }
815
  }
816
-
817
  // Stash in $bp for later use
818
  $bp->avatar->url = $baseurl;
819
  }
@@ -821,30 +731,11 @@ function bp_core_avatar_url() {
821
  return apply_filters( 'bp_core_avatar_url', $baseurl );
822
  }
823
 
824
- /**
825
- * Check if a given user ID has an uploaded avatar
826
- *
827
- * @since BuddyPress (1.0)
828
- * @param int $user_id
829
- * @return boolean
830
- */
831
- function bp_get_user_has_avatar( $user_id = 0 ) {
832
-
833
- if ( empty( $user_id ) )
834
- $user_id = bp_displayed_user_id();
835
-
836
- $retval = false;
837
- if ( bp_core_fetch_avatar( array( 'item_id' => $user_id, 'no_grav' => true, 'html' => false ) ) != bp_core_avatar_default() )
838
- $retval = true;
839
-
840
- return (bool) apply_filters( 'bp_get_user_has_avatar', $retval, $user_id );
841
- }
842
-
843
  /**
844
  * Utility function for fetching an avatar dimension setting
845
  *
846
  * @package BuddyPress
847
- * @since BuddyPress (1.5)
848
  *
849
  * @param str $type 'thumb' for thumbs, otherwise full
850
  * @param str $h_or_w 'height' for height, otherwise width
@@ -852,9 +743,9 @@ function bp_get_user_has_avatar( $user_id = 0 ) {
852
  */
853
  function bp_core_avatar_dimension( $type = 'thumb', $h_or_w = 'height' ) {
854
  global $bp;
855
-
856
- $dim = isset( $bp->avatar->{$type}->{$h_or_w} ) ? (int) $bp->avatar->{$type}->{$h_or_w} : false;
857
-
858
  return apply_filters( 'bp_core_avatar_dimension', $dim, $type, $h_or_w );
859
  }
860
 
@@ -862,7 +753,7 @@ function bp_core_avatar_dimension( $type = 'thumb', $h_or_w = 'height' ) {
862
  * Get the avatar thumb width setting
863
  *
864
  * @package BuddyPress
865
- * @since BuddyPress (1.5)
866
  *
867
  * @return int The thumb width
868
  */
@@ -874,7 +765,7 @@ function bp_core_avatar_thumb_width() {
874
  * Get the avatar thumb height setting
875
  *
876
  * @package BuddyPress
877
- * @since BuddyPress (1.5)
878
  *
879
  * @return int The thumb height
880
  */
@@ -886,7 +777,7 @@ function bp_core_avatar_thumb_height() {
886
  * Get the avatar full width setting
887
  *
888
  * @package BuddyPress
889
- * @since BuddyPress (1.5)
890
  *
891
  * @return int The full width
892
  */
@@ -898,7 +789,7 @@ function bp_core_avatar_full_width() {
898
  * Get the avatar full height setting
899
  *
900
  * @package BuddyPress
901
- * @since BuddyPress (1.5)
902
  *
903
  * @return int The full height
904
  */
@@ -910,41 +801,41 @@ function bp_core_avatar_full_height() {
910
  * Get the max width for original avatar uploads
911
  *
912
  * @package BuddyPress
913
- * @since BuddyPress (1.5)
914
  *
915
  * @return int The width
916
  */
917
  function bp_core_avatar_original_max_width() {
918
  global $bp;
919
-
920
- return apply_filters( 'bp_core_avatar_original_max_width', (int) $bp->avatar->original_max_width );
921
  }
922
 
923
  /**
924
  * Get the max filesize for original avatar uploads
925
  *
926
  * @package BuddyPress
927
- * @since BuddyPress (1.5)
928
  *
929
  * @return int The filesize
930
  */
931
  function bp_core_avatar_original_max_filesize() {
932
  global $bp;
933
-
934
- return apply_filters( 'bp_core_avatar_original_max_filesize', (int) $bp->avatar->original_max_filesize );
935
  }
936
 
937
  /**
938
  * Get the default avatar
939
  *
940
  * @package BuddyPress
941
- * @since BuddyPress (1.5)
942
  *
943
  * @return int The URL of the default avatar
944
  */
945
  function bp_core_avatar_default() {
946
  global $bp;
947
-
948
  return apply_filters( 'bp_core_avatar_default', $bp->avatar->full->default );
949
  }
950
 
@@ -952,13 +843,13 @@ function bp_core_avatar_default() {
952
  * Get the default avatar thumb
953
  *
954
  * @package BuddyPress
955
- * @since BuddyPress (1.5)
956
  *
957
  * @return int The URL of the default avatar thumb
958
  */
959
  function bp_core_avatar_default_thumb() {
960
  global $bp;
961
-
962
  return apply_filters( 'bp_core_avatar_thumb', $bp->avatar->thumb->default );
963
  }
964
 
14
  */
15
  function bp_core_set_avatar_constants() {
16
  global $bp;
17
+
18
  if ( !defined( 'BP_AVATAR_THUMB_WIDTH' ) )
19
  define( 'BP_AVATAR_THUMB_WIDTH', 50 );
20
 
31
  define( 'BP_AVATAR_ORIGINAL_MAX_WIDTH', 450 );
32
 
33
  if ( !defined( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE' ) ) {
34
+ if ( !isset( $bp->site_options['fileupload_maxk'] ) )
35
  define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', 5120000 ); // 5mb
36
+ else
37
  define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', $bp->site_options['fileupload_maxk'] * 1024 );
 
38
  }
39
 
40
  if ( !defined( 'BP_AVATAR_DEFAULT' ) )
41
+ define( 'BP_AVATAR_DEFAULT', BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg' );
42
 
43
  if ( !defined( 'BP_AVATAR_DEFAULT_THUMB' ) )
44
+ define( 'BP_AVATAR_DEFAULT_THUMB', BP_PLUGIN_URL . '/bp-core/images/mystery-man-50.jpg' );
45
  }
46
  add_action( 'bp_init', 'bp_core_set_avatar_constants', 3 );
47
 
48
  function bp_core_set_avatar_globals() {
49
  global $bp;
50
+
 
 
 
 
51
  // Dimensions
52
  $bp->avatar->thumb->width = BP_AVATAR_THUMB_WIDTH;
53
  $bp->avatar->thumb->height = BP_AVATAR_THUMB_HEIGHT;
54
  $bp->avatar->full->width = BP_AVATAR_FULL_WIDTH;
55
  $bp->avatar->full->height = BP_AVATAR_FULL_HEIGHT;
56
+
57
  // Upload maximums
58
  $bp->avatar->original_max_width = BP_AVATAR_ORIGINAL_MAX_WIDTH;
59
  $bp->avatar->original_max_filesize = BP_AVATAR_ORIGINAL_MAX_FILESIZE;
60
+
61
  // Defaults
62
+ $bp->avatar->thumb->default = BP_AVATAR_DEFAULT_THUMB;
63
+ $bp->avatar->full->default = BP_AVATAR_DEFAULT;
64
+
65
  // These have to be set on page load in order to avoid infinite filter loops at runtime
66
+ $bp->avatar->upload_path = bp_core_avatar_upload_path();
67
+ $bp->avatar->url = bp_core_avatar_url();
68
+
 
 
 
 
 
 
 
 
69
  do_action( 'bp_core_set_avatar_globals' );
70
  }
71
  add_action( 'bp_setup_globals', 'bp_core_set_avatar_globals' );
76
  * Fetches an avatar from a BuddyPress object. Supports user/group/blog as
77
  * default, but can be extended to include your own custom components too.
78
  *
79
+ * @global object $bp Global BuddyPress settings object
80
  * @global $current_blog WordPress global containing information and settings for the current blog being viewed.
81
  * @param array $args Determine the output of this function
82
  * @return string Formatted HTML <img> element, or raw avatar URL based on $html arg
88
  $def_object = 'user';
89
  $def_type = 'thumb';
90
  $def_class = 'avatar';
91
+ $def_alt = __( 'Avatar Image', 'buddypress' );
92
 
93
  // Set the default variables array
94
  $defaults = array(
100
  'height' => false, // Custom height (int)
101
  'class' => $def_class, // Custom <img> class (string)
102
  'css_id' => false, // Custom <img> ID (string)
103
+ 'alt' => $def_alt, // Custom <img> alt (string)
104
  'email' => false, // Pass the user email (for gravatar) to prevent querying the DB for it
105
  'no_grav' => false, // If there is no avatar found, return false instead of a grav?
106
  'html' => true, // Wrap the return img URL in <img />
111
  $params = wp_parse_args( $args, $defaults );
112
  extract( $params, EXTR_SKIP );
113
 
114
+ // Set item_id if not passed
115
+ if ( !$item_id ) {
116
+ if ( 'user' == $object )
117
+ $item_id = $bp->displayed_user->id;
118
+ else if ( bp_is_active( 'groups' ) && 'group' == $object )
119
+ $item_id = $bp->groups->current_group->id;
120
+ else if ( 'blog' == $object )
121
+ $item_id = $current_blog->id;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
123
+ $item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object );
124
 
125
+ if ( !$item_id )
126
  return false;
 
127
  }
128
 
129
+ // Set avatar_dir if not passed (uses $object)
130
+ if ( !$avatar_dir ) {
131
+ if ( 'user' == $object )
132
+ $avatar_dir = 'avatars';
133
+ else if ( bp_is_active( 'groups' ) && 'group' == $object )
134
+ $avatar_dir = 'group-avatars';
135
+ else if ( 'blog' == $object )
136
+ $avatar_dir = 'blog-avatars';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
 
138
+ $avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object );
139
 
140
+ if ( !$avatar_dir )
141
  return false;
 
142
  }
143
 
144
+ // Add an identifying class to each item
145
+ $class .= ' ' . $object . '-' . $item_id . '-avatar';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
 
147
+ // Get item name for alt/title tags
148
+ $item_name = '';
 
149
 
150
+ if ( 'user' == $object )
151
+ $item_name = bp_core_get_user_displayname( $item_id );
152
+ elseif ( 'group' == $object )
153
+ $item_name = bp_get_group_name( new BP_Groups_Group( $item_id ) );
154
+ elseif ( 'blog' == $object )
155
+ $item_name = get_blog_option( $item_id, 'blogname' );
156
 
157
+ $alt = sprintf( $alt, apply_filters( 'bp_core_avatar_alt', $item_name, $item_id, $object ) );
 
 
158
 
159
+ // Set title tag
160
+ if ( $title )
161
+ $title = " title='" . esc_attr( apply_filters( 'bp_core_avatar_title', $title, $item_id, $object ) ) . "'";
162
+ elseif ( $item_name )
163
+ $title = " title='" . esc_attr( apply_filters( 'bp_core_avatar_title', $item_name, $item_id, $object ) ) . "'";
164
 
165
  // Set CSS ID if passed
166
  if ( !empty( $css_id ) )
167
+ $css_id = " id='{$css_id}'";
168
 
169
+ // Set avatar width
170
+ if ( $width )
171
+ $html_width = " width='{$width}'";
172
  else
173
  $html_width = ( 'thumb' == $type ) ? ' width="' . bp_core_avatar_thumb_width() . '"' : ' width="' . bp_core_avatar_full_width() . '"';
174
 
175
+ // Set avatar height
176
+ if ( $height )
177
+ $html_height = " height='{$height}'";
178
  else
179
  $html_height = ( 'thumb' == $type ) ? ' height="' . bp_core_avatar_thumb_height() . '"' : ' height="' . bp_core_avatar_full_height() . '"';
180
 
181
+ // Set avatar URL and DIR based on prepopulated constants
182
+ $avatar_folder_url = apply_filters( 'bp_core_avatar_folder_url', bp_core_avatar_url() . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
183
+ $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', bp_core_avatar_upload_path() . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
 
 
 
 
 
 
 
 
184
 
185
  /****
186
  * Look for uploaded avatar first. Use it if it exists.
199
 
200
  // Stash files in an array once to check for one that matches
201
  $avatar_files = array();
202
+ while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
203
  // Only add files to the array (skip directories)
204
+ if ( 2 < strlen( $avatar_file ) )
205
  $avatar_files[] = $avatar_file;
 
206
  }
207
 
208
  // Check for array
210
 
211
  // Check for current avatar
212
  foreach( $avatar_files as $key => $value ) {
213
+ if ( strpos ( $value, $avatar_size )!== false )
214
  $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
 
215
  }
216
 
217
  // Legacy avatar check
218
  if ( !isset( $avatar_url ) ) {
219
  foreach( $avatar_files as $key => $value ) {
220
+ if ( strpos ( $value, $legacy_user_avatar_name )!== false )
221
  $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
 
222
  }
223
 
224
  // Legacy group avatar check
225
  if ( !isset( $avatar_url ) ) {
226
  foreach( $avatar_files as $key => $value ) {
227
+ if ( strpos ( $value, $legacy_group_avatar_name )!== false )
228
  $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
 
229
  }
230
  }
231
  }
239
  if ( isset( $avatar_url ) ) {
240
 
241
  // Return it wrapped in an <img> element
242
+ if ( true === $html ) {
243
  return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $avatar_url . '" alt="' . esc_attr( $alt ) . '" class="' . esc_attr( $class ) . '"' . $css_id . $html_width . $html_height . $title . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
244
 
245
  // ...or only the URL
255
  if ( ! apply_filters( 'bp_core_fetch_avatar_no_grav', $no_grav ) ) {
256
 
257
  // Set gravatar size
258
+ if ( $width )
259
  $grav_size = $width;
260
+ else if ( 'full' == $type )
261
  $grav_size = bp_core_avatar_full_width();
262
+ else if ( 'thumb' == $type )
263
  $grav_size = bp_core_avatar_thumb_width();
 
264
 
265
  // Set gravatar type
266
+ if ( empty( $bp->grav_default->{$object} ) )
267
  $default_grav = 'wavatar';
268
+ else if ( 'mystery' == $bp->grav_default->{$object} )
269
  $default_grav = apply_filters( 'bp_core_mysteryman_src', bp_core_avatar_default(), $grav_size );
270
+ else
271
  $default_grav = $bp->grav_default->{$object};
 
272
 
273
  // Set gravatar object
274
  if ( empty( $email ) ) {
280
  }
281
 
282
  // Set host based on if using ssl
283
+ if ( is_ssl() )
 
284
  $host = 'https://secure.gravatar.com/avatar/';
285
+ else
286
+ $host = 'http://www.gravatar.com/avatar/';
287
 
288
  // Filter gravatar vars
289
  $email = apply_filters( 'bp_core_gravatar_email', $email, $item_id, $object );
290
  $gravatar = apply_filters( 'bp_gravatar_url', $host ) . md5( strtolower( $email ) ) . '?d=' . $default_grav . '&amp;s=' . $grav_size;
291
 
 
 
 
 
 
 
292
  } else {
293
+ // No avatar was found, and we've been told not to use a gravatar.
294
+ $gravatar = apply_filters( "bp_core_default_avatar_$object", BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg', $params );
295
  }
296
 
297
+ if ( true === $html )
298
  return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $gravatar . '" alt="' . esc_attr( $alt ) . '" class="' . esc_attr( $class ) . '"' . $css_id . $html_width . $html_height . $title . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
299
  else
300
  return apply_filters( 'bp_core_fetch_avatar_url', $gravatar );
324
  $args = wp_parse_args( $args, $defaults );
325
  extract( $args, EXTR_SKIP );
326
 
327
+ if ( !$item_id ) {
328
  if ( 'user' == $object )
329
+ $item_id = $bp->displayed_user->id;
330
  else if ( 'group' == $object )
331
  $item_id = $bp->groups->current_group->id;
332
  else if ( 'blog' == $object )
337
  if ( !$item_id ) return false;
338
  }
339
 
340
+ if ( !$avatar_dir ) {
341
  if ( 'user' == $object )
342
  $avatar_dir = 'avatars';
343
  else if ( 'group' == $object )
482
  * crop_x - The horizontal starting point of the crop
483
  * crop_y - The vertical starting point of the crop
484
  *
485
+ * @global object $bp BuddyPress global settings
486
  * @param mixed $args
487
  * @return bool Success/failure
488
  */
489
  function bp_core_avatar_handle_crop( $args = '' ) {
490
+ global $bp;
491
 
492
  $defaults = array(
493
  'object' => 'user',
534
  bp_core_delete_existing_avatar( array( 'object' => $object, 'avatar_path' => $avatar_folder_dir ) );
535
 
536
  // Make sure we at least have a width and height for cropping
537
+ if ( !(int)$crop_w )
538
  $crop_w = bp_core_avatar_full_width();
539
 
540
+ if ( !(int)$crop_h )
541
  $crop_h = bp_core_avatar_full_height();
542
 
543
  // Set the full and thumb filenames
545
  $thumb_filename = wp_hash( $original_file . time() ) . '-bpthumb.jpg';
546
 
547
  // Crop the image
548
+ $full_cropped = wp_crop_image( $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, bp_core_avatar_full_width(), bp_core_avatar_full_height(), false, $avatar_folder_dir . '/' . $full_filename );
549
+ $thumb_cropped = wp_crop_image( $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, bp_core_avatar_thumb_width(), bp_core_avatar_thumb_height(), false, $avatar_folder_dir . '/' . $thumb_filename );
 
 
 
 
550
 
551
  // Remove the original
552
  @unlink( $original_file );
592
  return !empty( $avatar ) ? $avatar : $default;
593
 
594
  if ( !$alt )
595
+ $alt = __( 'Avatar of %s', 'buddypress' );
596
 
597
  // Let BuddyPress handle the fetching of the avatar
598
  $bp_avatar = bp_core_fetch_avatar( array( 'item_id' => $id, 'width' => $size, 'height' => $size, 'alt' => $alt ) );
653
  */
654
  function bp_core_avatar_upload_path() {
655
  global $bp;
656
+
657
  // See if the value has already been calculated and stashed in the $bp global
658
  if ( isset( $bp->avatar->upload_path ) ) {
659
  $basedir = $bp->avatar->upload_path;
666
  // Switch dynamically in order to support BP_ENABLE_MULTIBLOG
667
  switch_to_blog( bp_get_root_blog_id() );
668
  }
669
+
670
  // Get upload directory information from current site
671
  $upload_dir = wp_upload_dir();
672
+
673
  // Directory does not exist and cannot be created
674
  if ( !empty( $upload_dir['error'] ) ) {
675
  $basedir = '';
676
+
677
  } else {
678
  $basedir = $upload_dir['basedir'];
679
  }
680
+
681
  // Will bail if not switched
682
  restore_current_blog();
683
  }
684
+
685
  // Stash in $bp for later use
686
  $bp->avatar->upload_path = $basedir;
687
  }
688
+
689
  return apply_filters( 'bp_core_avatar_upload_path', $basedir );
690
  }
691
 
699
  */
700
  function bp_core_avatar_url() {
701
  global $bp;
702
+
703
  // See if the value has already been calculated and stashed in the $bp global
704
  if ( isset( $bp->avatar->url ) ) {
705
  $baseurl = $bp->avatar->url;
 
706
  } else {
707
  // If this value has been set in a constant, just use that
708
  if ( defined( 'BP_AVATAR_URL' ) ) {
710
  } else {
711
  // Get upload directory information from current site
712
  $upload_dir = wp_upload_dir();
713
+
714
  // Directory does not exist and cannot be created
715
  if ( !empty( $upload_dir['error'] ) ) {
716
  $baseurl = '';
717
+
718
  } else {
719
  $baseurl = $upload_dir['baseurl'];
720
+
 
 
 
 
721
  // If multisite, and current blog does not match root blog, make adjustments
722
  if ( is_multisite() && bp_get_root_blog_id() != get_current_blog_id() )
723
  $baseurl = trailingslashit( get_blog_option( bp_get_root_blog_id(), 'home' ) ) . get_blog_option( bp_get_root_blog_id(), 'upload_path' );
724
  }
725
  }
726
+
727
  // Stash in $bp for later use
728
  $bp->avatar->url = $baseurl;
729
  }
731
  return apply_filters( 'bp_core_avatar_url', $baseurl );
732
  }
733
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
734
  /**
735
  * Utility function for fetching an avatar dimension setting
736
  *
737
  * @package BuddyPress
738
+ * @since 1.5
739
  *
740
  * @param str $type 'thumb' for thumbs, otherwise full
741
  * @param str $h_or_w 'height' for height, otherwise width
743
  */
744
  function bp_core_avatar_dimension( $type = 'thumb', $h_or_w = 'height' ) {
745
  global $bp;
746
+
747
+ $dim = isset( $bp->avatar->{$type}->{$h_or_w} ) ? (int)$bp->avatar->{$type}->{$h_or_w} : false;
748
+
749
  return apply_filters( 'bp_core_avatar_dimension', $dim, $type, $h_or_w );
750
  }
751
 
753
  * Get the avatar thumb width setting
754
  *
755
  * @package BuddyPress
756
+ * @since 1.5
757
  *
758
  * @return int The thumb width
759
  */
765
  * Get the avatar thumb height setting
766
  *
767
  * @package BuddyPress
768
+ * @since 1.5
769
  *
770
  * @return int The thumb height
771
  */
777
  * Get the avatar full width setting
778
  *
779
  * @package BuddyPress
780
+ * @since 1.5
781
  *
782
  * @return int The full width
783
  */
789
  * Get the avatar full height setting
790
  *
791
  * @package BuddyPress
792
+ * @since 1.5
793
  *
794
  * @return int The full height
795
  */
801
  * Get the max width for original avatar uploads
802
  *
803
  * @package BuddyPress
804
+ * @since 1.5
805
  *
806
  * @return int The width
807
  */
808
  function bp_core_avatar_original_max_width() {
809
  global $bp;
810
+
811
+ return apply_filters( 'bp_core_avatar_original_max_width', (int)$bp->avatar->original_max_width );
812
  }
813
 
814
  /**
815
  * Get the max filesize for original avatar uploads
816
  *
817
  * @package BuddyPress
818
+ * @since 1.5
819
  *
820
  * @return int The filesize
821
  */
822
  function bp_core_avatar_original_max_filesize() {
823
  global $bp;
824
+
825
+ return apply_filters( 'bp_core_avatar_original_max_filesize', (int)$bp->avatar->original_max_filesize );
826
  }
827
 
828
  /**
829
  * Get the default avatar
830
  *
831
  * @package BuddyPress
832
+ * @since 1.5
833
  *
834
  * @return int The URL of the default avatar
835
  */
836
  function bp_core_avatar_default() {
837
  global $bp;
838
+
839
  return apply_filters( 'bp_core_avatar_default', $bp->avatar->full->default );
840
  }
841
 
843
  * Get the default avatar thumb
844
  *
845
  * @package BuddyPress
846
+ * @since 1.5
847
  *
848
  * @return int The URL of the default avatar thumb
849
  */
850
  function bp_core_avatar_default_thumb() {
851
  global $bp;
852
+
853
  return apply_filters( 'bp_core_avatar_thumb', $bp->avatar->thumb->default );
854
  }
855
 
bp-core/bp-core-buddybar.php CHANGED
@@ -1,13 +1,4 @@
1
  <?php
2
-
3
- /**
4
- * Core BuddyPress Navigational Functions
5
- *
6
- * @package BuddyPress
7
- * @subpackage Core
8
- * @todo Deprecate BuddyBar functions
9
- */
10
-
11
  // Exit if accessed directly
12
  if ( !defined( 'ABSPATH' ) ) exit;
13
 
@@ -15,7 +6,7 @@ if ( !defined( 'ABSPATH' ) ) exit;
15
  * Adds a navigation item to the main navigation array used in BuddyPress themes.
16
  *
17
  * @package BuddyPress Core
18
- * @global BuddyPress $bp The one true BuddyPress instance
19
  */
20
  function bp_core_new_nav_item( $args = '' ) {
21
  global $bp;
@@ -39,7 +30,7 @@ function bp_core_new_nav_item( $args = '' ) {
39
  return false;
40
 
41
  // If this is for site admins only and the user is not one, don't create the subnav item
42
- if ( !empty( $site_admin_only ) && !bp_current_user_can( 'bp_moderate' ) )
43
  return false;
44
 
45
  if ( empty( $item_css_id ) )
@@ -48,23 +39,22 @@ function bp_core_new_nav_item( $args = '' ) {
48
  $bp->bp_nav[$slug] = array(
49
  'name' => $name,
50
  'slug' => $slug,
51
- 'link' => trailingslashit( bp_loggedin_user_domain() . $slug ),
52
  'css_id' => $item_css_id,
53
  'show_for_displayed_user' => $show_for_displayed_user,
54
  'position' => $position,
55
- 'screen_function' => &$screen_function,
56
- 'default_subnav_slug' => $default_subnav_slug
57
  );
58
 
59
- /**
60
  * If this nav item is hidden for the displayed user, and
61
  * the logged in user is not the displayed user
62
  * looking at their own profile, don't create the nav item.
63
  */
64
- if ( empty( $show_for_displayed_user ) && !bp_user_has_access() )
65
  return false;
66
 
67
- /**
68
  * If the nav item is visible, we are not viewing a user, and this is a root
69
  * component, don't attach the default subnav function so we can display a
70
  * directory or something else.
@@ -73,21 +63,24 @@ function bp_core_new_nav_item( $args = '' ) {
73
  return;
74
 
75
  // Look for current component
76
- if ( bp_is_current_component( $slug ) || bp_is_current_item( $slug ) ) {
77
-
78
- // The requested URL has explicitly included the default subnav
79
- // (eg: http://example.com/members/membername/activity/just-me/)
80
- // The canonical version will not contain this subnav slug.
81
- if ( !empty( $default_subnav_slug ) && bp_is_current_action( $default_subnav_slug ) && !bp_action_variable( 0 ) ) {
82
- unset( $bp->canonical_stack['action'] );
83
- } elseif ( ! bp_current_action() ) {
84
- $func = is_object( $screen_function[0] ) ? array( &$screen_function[0], $screen_function[1] ) : $screen_function;
85
- add_action( 'bp_screens', $func, 3 );
86
-
87
- if ( !empty( $default_subnav_slug ) ) {
88
- $bp->current_action = apply_filters( 'bp_default_component_subnav', $default_subnav_slug, $r );
89
- }
90
- }
 
 
 
91
  }
92
 
93
  do_action( 'bp_core_new_nav_item', $r, $args, $defaults );
@@ -97,7 +90,7 @@ function bp_core_new_nav_item( $args = '' ) {
97
  * Modify the default subnav item to load when a top level nav item is clicked.
98
  *
99
  * @package BuddyPress Core
100
- * @global BuddyPress $bp The one true BuddyPress instance
101
  */
102
  function bp_core_new_nav_default( $args = '' ) {
103
  global $bp;
@@ -112,54 +105,23 @@ function bp_core_new_nav_default( $args = '' ) {
112
  extract( $r, EXTR_SKIP );
113
 
114
  if ( $function = $bp->bp_nav[$parent_slug]['screen_function'] ) {
115
- if ( is_object( $function[0] ) ) {
116
- remove_action( 'bp_screens', array( &$function[0], $function[1] ), 3 );
117
- } else {
118
  remove_action( 'bp_screens', $function, 3 );
119
- }
 
120
  }
121
 
122
  $bp->bp_nav[$parent_slug]['screen_function'] = &$screen_function;
123
 
124
- if ( bp_is_current_component( $parent_slug ) ) {
125
-
126
- // The only way to tell whether to set the subnav is to peek at the unfiltered_uri
127
- // Find the component
128
- $component_uri_key = array_search( $parent_slug, $bp->unfiltered_uri );
129
-
130
- if ( false !== $component_uri_key ) {
131
- if ( !empty( $bp->unfiltered_uri[$component_uri_key + 1] ) ) {
132
- $unfiltered_action = $bp->unfiltered_uri[$component_uri_key + 1];
133
- }
134
- }
135
 
136
- // No subnav item has been requested in the URL, so set a new nav default
137
- if ( empty( $unfiltered_action ) ) {
138
- if ( !bp_is_current_action( $subnav_slug ) ) {
139
- if ( is_object( $screen_function[0] ) ) {
140
- add_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ), 3 );
141
- } else {
142
- add_action( 'bp_screens', $screen_function, 3 );
143
- }
144
-
145
- $bp->current_action = $subnav_slug;
146
- unset( $bp->canonical_stack['action'] );
147
- }
148
-
149
- // The URL is explicitly requesting the new subnav item, but should be
150
- // directed to the canonical URL
151
- } elseif ( $unfiltered_action == $subnav_slug ) {
152
- unset( $bp->canonical_stack['action'] );
153
-
154
- // In all other cases (including the case where the original subnav item
155
- // is explicitly called in the URL), the canonical URL will contain the
156
- // subnav slug
157
- } else {
158
- $bp->canonical_stack['action'] = bp_current_action();
159
- }
160
  }
161
-
162
- return;
163
  }
164
 
165
  /**
@@ -167,7 +129,7 @@ function bp_core_new_nav_default( $args = '' ) {
167
  * plugins have registered their navigation items.
168
  *
169
  * @package BuddyPress Core
170
- * @global BuddyPress $bp The one true BuddyPress instance
171
  */
172
  function bp_core_sort_nav_items() {
173
  global $bp;
@@ -175,12 +137,10 @@ function bp_core_sort_nav_items() {
175
  if ( empty( $bp->bp_nav ) || !is_array( $bp->bp_nav ) )
176
  return false;
177
 
178
- $temp = array();
179
-
180
- foreach ( (array) $bp->bp_nav as $slug => $nav_item ) {
181
- if ( empty( $temp[$nav_item['position']]) ) {
182
  $temp[$nav_item['position']] = $nav_item;
183
- } else {
184
  // increase numbers here to fit new items in.
185
  do {
186
  $nav_item['position']++;
@@ -200,7 +160,7 @@ add_action( 'admin_head', 'bp_core_sort_nav_items' );
200
  * Adds a navigation item to the sub navigation array used in BuddyPress themes.
201
  *
202
  * @package BuddyPress Core
203
- * @global BuddyPress $bp The one true BuddyPress instance
204
  */
205
  function bp_core_new_subnav_item( $args = '' ) {
206
  global $bp;
@@ -225,18 +185,11 @@ function bp_core_new_subnav_item( $args = '' ) {
225
  if ( empty( $name ) || empty( $slug ) || empty( $parent_slug ) || empty( $parent_url ) || empty( $screen_function ) )
226
  return false;
227
 
228
- // Link was not forced, so create one
229
- if ( empty( $link ) ) {
230
  $link = $parent_url . $slug;
231
 
232
- // If this sub item is the default for its parent, skip the slug
233
- if ( ! empty( $bp->bp_nav[$parent_slug]['default_subnav_slug'] ) && $slug == $bp->bp_nav[$parent_slug]['default_subnav_slug'] ) {
234
- $link = $parent_url;
235
- }
236
- }
237
-
238
  // If this is for site admins only and the user is not one, don't create the subnav item
239
- if ( !empty( $site_admin_only ) && !bp_current_user_can( 'bp_moderate' ) )
240
  return false;
241
 
242
  if ( empty( $item_css_id ) )
@@ -258,10 +211,10 @@ function bp_core_new_subnav_item( $args = '' ) {
258
  * subnav item. We figure out whether we're currently viewing this subnav by checking the
259
  * following two conditions:
260
  * (1) Either:
261
- * (a) the parent slug matches the current_component, or
262
- * (b) the parent slug matches the current_item
263
  * (2) And either:
264
- * (a) the current_action matches $slug, or
265
  * (b) there is no current_action (ie, this is the default subnav for the parent nav)
266
  * and this subnav item is the default for the parent item (which we check by
267
  * comparing this subnav item's screen function with the screen function of the
@@ -270,49 +223,30 @@ function bp_core_new_subnav_item( $args = '' ) {
270
  */
271
 
272
  // If we *don't* meet condition (1), return
273
- if ( ! bp_is_current_component( $parent_slug ) && ! bp_is_current_item( $parent_slug ) )
274
  return;
275
 
276
  // If we *do* meet condition (2), then the added subnav item is currently being requested
277
- if ( ( bp_current_action() && bp_is_current_action( $slug ) ) || ( bp_is_user() && ! bp_current_action() && ( $screen_function == $bp->bp_nav[$parent_slug]['screen_function'] ) ) ) {
278
 
279
  // Before hooking the screen function, check user access
280
- if ( !empty( $user_has_access ) ) {
281
- if ( is_object( $screen_function[0] ) ) {
282
- add_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ), 3 );
283
- } else {
284
- add_action( 'bp_screens', $screen_function, 3 );
285
- }
286
  } else {
287
-
288
- // When the content is off-limits, we handle the situation
289
- // differently depending on whether the current user is logged in
290
  if ( is_user_logged_in() ) {
291
- if ( !bp_is_my_profile() && empty( $bp->bp_nav[$bp->default_component]['show_for_displayed_user'] ) ) {
292
-
293
- // This covers the edge case where the default component is
294
- // a non-public tab, like 'messages'
295
- if ( bp_is_active( 'activity' ) && isset( $bp->pages->activity ) ) {
296
- $redirect_to = trailingslashit( bp_displayed_user_domain() . bp_get_activity_slug() );
297
- } else {
298
- $redirect_to = trailingslashit( bp_displayed_user_domain() . ( 'xprofile' == $bp->profile->id ? 'profile' : $bp->profile->id ) );
299
- }
300
-
301
- $message = '';
302
- } else {
303
- $message = __( 'You do not have access to this page.', 'buddypress' );
304
- $redirect_to = bp_displayed_user_domain();
305
- }
306
-
307
  // Off-limits to this user. Throw an error and redirect to the displayed user's domain
308
  bp_core_no_access( array(
309
- 'message' => $message,
310
- 'root' => $redirect_to,
311
  'redirect' => false
312
  ) );
313
-
314
- // Not logged in. Allow the user to log in, and attempt to redirect
315
  } else {
 
316
  bp_core_no_access();
317
  }
318
  }
@@ -325,11 +259,11 @@ function bp_core_sort_subnav_items() {
325
  if ( empty( $bp->bp_options_nav ) || !is_array( $bp->bp_options_nav ) )
326
  return false;
327
 
328
- foreach ( (array) $bp->bp_options_nav as $parent_slug => $subnav_items ) {
329
  if ( !is_array( $subnav_items ) )
330
  continue;
331
 
332
- foreach ( (array) $subnav_items as $subnav_item ) {
333
  if ( empty( $temp[$subnav_item['position']]) )
334
  $temp[$subnav_item['position']] = $subnav_item;
335
  else {
@@ -353,7 +287,7 @@ add_action( 'admin_head', 'bp_core_sort_subnav_items' );
353
  * Determines whether a given nav item has subnav items
354
  *
355
  * @package BuddyPress
356
- * @since BuddyPress (1.5)
357
  *
358
  * @param str $nav_item The id of the top-level nav item whose nav items you're checking
359
  * @return bool $has_subnav True if the nav item is found and has subnav items; false otherwise
@@ -381,16 +315,16 @@ function bp_core_remove_nav_item( $parent_id ) {
381
 
382
  // Unset subnav items for this nav item
383
  if ( isset( $bp->bp_options_nav[$parent_id] ) && is_array( $bp->bp_options_nav[$parent_id] ) ) {
384
- foreach( (array) $bp->bp_options_nav[$parent_id] as $subnav_item ) {
385
  bp_core_remove_subnav_item( $parent_id, $subnav_item['slug'] );
386
  }
387
  }
388
 
389
  if ( $function = $bp->bp_nav[$parent_id]['screen_function'] ) {
390
- if ( is_object( $function[0] ) ) {
391
- remove_action( 'bp_screens', array( &$function[0], $function[1] ), 3 );
392
  } else {
393
- remove_action( 'bp_screens', $function, 3 );
394
  }
395
  }
396
 
@@ -407,14 +341,13 @@ function bp_core_remove_nav_item( $parent_id ) {
407
  function bp_core_remove_subnav_item( $parent_id, $slug ) {
408
  global $bp;
409
 
410
- $screen_function = isset( $bp->bp_options_nav[$parent_id][$slug]['screen_function'] ) ? $bp->bp_options_nav[$parent_id][$slug]['screen_function'] : false;
411
 
412
- if ( !empty( $screen_function ) ) {
413
- if ( is_object( $screen_function[0] ) ) {
414
- remove_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ), 3 );
415
- } else {
416
- remove_action( 'bp_screens', $screen_function, 3 );
417
- }
418
  }
419
 
420
  unset( $bp->bp_options_nav[$parent_id][$slug] );
@@ -428,7 +361,7 @@ function bp_core_remove_subnav_item( $parent_id, $slug ) {
428
  *
429
  * @package BuddyPress Core
430
  * @param $parent_id The id of the parent navigation item.
431
- * @global BuddyPress $bp The one true BuddyPress instance
432
  */
433
  function bp_core_reset_subnav_items( $parent_slug ) {
434
  global $bp;
@@ -444,7 +377,7 @@ function bp_core_admin_bar() {
444
  if ( defined( 'BP_DISABLE_ADMIN_BAR' ) && BP_DISABLE_ADMIN_BAR )
445
  return false;
446
 
447
- if ( (int) bp_get_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() )
448
  return false;
449
 
450
  $bp->doing_admin_bar = true;
@@ -465,18 +398,21 @@ function bp_core_admin_bar() {
465
  $bp->doing_admin_bar = false;
466
  }
467
 
468
- // **** Default BuddyPress Toolbar logo ********
469
  function bp_adminbar_logo() {
 
 
470
  echo '<a href="' . bp_get_root_domain() . '" id="admin-bar-logo">' . get_blog_option( bp_get_root_blog_id(), 'blogname' ) . '</a>';
471
  }
472
 
473
  // **** "Log In" and "Sign Up" links (Visible when not logged in) ********
474
  function bp_adminbar_login_menu() {
 
475
 
476
  if ( is_user_logged_in() )
477
  return false;
478
 
479
- echo '<li class="bp-login no-arrow"><a href="' . wp_login_url() . '">' . __( 'Log In', 'buddypress' ) . '</a></li>';
480
 
481
  // Show "Sign Up" link if user registrations are allowed
482
  if ( bp_get_signup_allowed() )
@@ -497,7 +433,7 @@ function bp_adminbar_account_menu() {
497
 
498
  // Loop through each navigation item
499
  $counter = 0;
500
- foreach( (array) $bp->bp_nav as $nav_item ) {
501
  $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
502
 
503
  if ( -1 == $nav_item['position'] )
@@ -510,12 +446,12 @@ function bp_adminbar_account_menu() {
510
  echo '<ul>';
511
  $sub_counter = 0;
512
 
513
- foreach( (array) $bp->bp_options_nav[$nav_item['slug']] as $subnav_item ) {
514
  $link = $subnav_item['link'];
515
  $name = $subnav_item['name'];
516
 
517
- if ( bp_displayed_user_domain() )
518
- $link = str_replace( bp_displayed_user_domain(), bp_loggedin_user_domain(), $subnav_item['link'] );
519
 
520
  if ( isset( $bp->displayed_user->userdata->user_login ) )
521
  $name = str_replace( $bp->displayed_user->userdata->user_login, $bp->loggedin_user->userdata->user_login, $subnav_item['name'] );
@@ -560,7 +496,7 @@ function bp_adminbar_thisblog_menu() {
560
 
561
  // **** "Random" Menu (visible when not logged in) ********
562
  function bp_adminbar_random_menu() {
563
- ?>
564
 
565
  <li class="align-right" id="bp-adminbar-visitrandom-menu">
566
  <a href="#"><?php _e( 'Visit', 'buddypress' ) ?></a>
@@ -588,18 +524,18 @@ function bp_adminbar_random_menu() {
588
  }
589
 
590
  /**
591
- * Retrieve the Toolbar display preference of a user based on context.
592
  *
593
  * This is a direct copy of WP's private _get_admin_bar_pref()
594
  *
595
- * @since BuddyPress (1.5)
596
  *
597
  * @param string $context Context of this preference check, either 'admin' or 'front'.
598
  * @param int $user Optional. ID of the user to check, defaults to 0 for current user.
599
  *
600
  * @uses get_user_option()
601
  *
602
- * @return bool Whether the Toolbar should be showing for this user.
603
  */
604
  function bp_get_admin_bar_pref( $context, $user = 0 ) {
605
  $pref = get_user_option( "show_admin_bar_{$context}", $user );
@@ -610,9 +546,9 @@ function bp_get_admin_bar_pref( $context, $user = 0 ) {
610
  }
611
 
612
  /**
613
- * Handle the Toolbar/BuddyBar business
614
  *
615
- * @since BuddyPress (1.2)
616
  *
617
  * @global string $wp_version
618
  * @uses bp_get_option()
@@ -630,32 +566,32 @@ function bp_get_admin_bar_pref( $context, $user = 0 ) {
630
  function bp_core_load_admin_bar() {
631
  global $wp_version;
632
 
633
- // Don't show if Toolbar is disabled for non-logged in users
634
- if ( (int) bp_get_option( 'hide-loggedout-adminbar' ) && ! is_user_logged_in() )
635
  return;
636
 
637
- // Show the WordPress Toolbar
638
  if ( bp_use_wp_admin_bar() && $wp_version >= 3.1 ) {
639
-
640
- // Respect user's Toolbar display preferences
641
- if ( is_user_logged_in() && ( bp_get_admin_bar_pref( 'front', bp_loggedin_user_id() ) || bp_get_admin_bar_pref( 'admin', bp_loggedin_user_id() ) ) )
642
  return;
643
 
644
  show_admin_bar( true );
645
 
646
- // Hide the WordPress Toolbar
647
  } elseif ( !bp_use_wp_admin_bar() ) {
648
- // Keep the WP Toolbar from loading
 
649
  show_admin_bar( false );
650
 
651
- // Actions used to build the BP Toolbar
652
  add_action( 'bp_adminbar_logo', 'bp_adminbar_logo' );
653
  add_action( 'bp_adminbar_menus', 'bp_adminbar_login_menu', 2 );
654
  add_action( 'bp_adminbar_menus', 'bp_adminbar_account_menu', 4 );
655
  add_action( 'bp_adminbar_menus', 'bp_adminbar_thisblog_menu', 6 );
656
  add_action( 'bp_adminbar_menus', 'bp_adminbar_random_menu', 100 );
657
 
658
- // Actions used to append BP Toolbar to footer
659
  add_action( 'wp_footer', 'bp_core_admin_bar', 8 );
660
  add_action( 'admin_footer', 'bp_core_admin_bar' );
661
  }
@@ -671,22 +607,21 @@ function bp_core_load_buddybar_css() {
671
  if ( file_exists( get_stylesheet_directory() . '/_inc/css/adminbar.css' ) ) // Backwards compatibility
672
  $stylesheet = get_stylesheet_directory_uri() . '/_inc/css/adminbar.css';
673
  elseif ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG )
674
- $stylesheet = BP_PLUGIN_URL . 'bp-core/css/buddybar.dev.css';
675
  else
676
- $stylesheet = BP_PLUGIN_URL . 'bp-core/css/buddybar.css';
677
 
678
- wp_enqueue_style( 'bp-admin-bar', apply_filters( 'bp_core_admin_bar_css', $stylesheet ), array(), bp_get_version() );
679
 
680
  if ( !is_rtl() )
681
  return;
682
 
683
  if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG )
684
- $stylesheet = BP_PLUGIN_URL . 'bp-core/css/buddybar-rtl.dev.css';
685
  else
686
- $stylesheet = BP_PLUGIN_URL . 'bp-core/css/buddybar-rtl.css';
687
 
688
- wp_enqueue_style( 'bp-admin-bar-rtl', apply_filters( 'bp_core_buddybar_rtl_css', $stylesheet ), array( 'bp-admin-bar' ), bp_get_version() );
689
  }
690
  add_action( 'bp_init', 'bp_core_load_buddybar_css' );
691
-
692
  ?>
1
  <?php
 
 
 
 
 
 
 
 
 
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
6
  * Adds a navigation item to the main navigation array used in BuddyPress themes.
7
  *
8
  * @package BuddyPress Core
9
+ * @global object $bp Global BuddyPress settings object
10
  */
11
  function bp_core_new_nav_item( $args = '' ) {
12
  global $bp;
30
  return false;
31
 
32
  // If this is for site admins only and the user is not one, don't create the subnav item
33
+ if ( $site_admin_only && !is_super_admin() )
34
  return false;
35
 
36
  if ( empty( $item_css_id ) )
39
  $bp->bp_nav[$slug] = array(
40
  'name' => $name,
41
  'slug' => $slug,
42
+ 'link' => $bp->loggedin_user->domain . $slug . '/',
43
  'css_id' => $item_css_id,
44
  'show_for_displayed_user' => $show_for_displayed_user,
45
  'position' => $position,
46
+ 'screen_function' => &$screen_function
 
47
  );
48
 
49
+ /***
50
  * If this nav item is hidden for the displayed user, and
51
  * the logged in user is not the displayed user
52
  * looking at their own profile, don't create the nav item.
53
  */
54
+ if ( !$show_for_displayed_user && !bp_user_has_access() )
55
  return false;
56
 
57
+ /***
58
  * If the nav item is visible, we are not viewing a user, and this is a root
59
  * component, don't attach the default subnav function so we can display a
60
  * directory or something else.
63
  return;
64
 
65
  // Look for current component
66
+ if ( bp_is_current_component( $slug ) && !bp_current_action() ) {
67
+ if ( !is_object( $screen_function[0] ) )
68
+ add_action( 'bp_screens', $screen_function );
69
+ else
70
+ add_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ), 3 );
71
+
72
+ if ( !empty( $default_subnav_slug ) )
73
+ $bp->current_action = apply_filters( 'bp_default_component_subnav', $default_subnav_slug, $r );
74
+
75
+ // Look for current item
76
+ } elseif ( bp_is_current_item( $slug ) && !bp_current_action() ) {
77
+ if ( !is_object( $screen_function[0] ) )
78
+ add_action( 'bp_screens', $screen_function );
79
+ else
80
+ add_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ), 3 );
81
+
82
+ if ( !empty( $default_subnav_slug ) )
83
+ $bp->current_action = apply_filters( 'bp_default_component_subnav', $default_subnav_slug, $r );
84
  }
85
 
86
  do_action( 'bp_core_new_nav_item', $r, $args, $defaults );
90
  * Modify the default subnav item to load when a top level nav item is clicked.
91
  *
92
  * @package BuddyPress Core
93
+ * @global object $bp Global BuddyPress settings object
94
  */
95
  function bp_core_new_nav_default( $args = '' ) {
96
  global $bp;
105
  extract( $r, EXTR_SKIP );
106
 
107
  if ( $function = $bp->bp_nav[$parent_slug]['screen_function'] ) {
108
+ if ( !is_object( $function[0] ) )
 
 
109
  remove_action( 'bp_screens', $function, 3 );
110
+ else
111
+ remove_action( 'bp_screens', array( &$function[0], $function[1] ), 3 );
112
  }
113
 
114
  $bp->bp_nav[$parent_slug]['screen_function'] = &$screen_function;
115
 
116
+ if ( $bp->current_component == $parent_slug && !$bp->current_action ) {
117
+ if ( !is_object( $screen_function[0] ) )
118
+ add_action( 'bp_screens', $screen_function );
119
+ else
120
+ add_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ) );
 
 
 
 
 
 
121
 
122
+ if ( $subnav_slug )
123
+ $bp->current_action = $subnav_slug;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  }
 
 
125
  }
126
 
127
  /**
129
  * plugins have registered their navigation items.
130
  *
131
  * @package BuddyPress Core
132
+ * @global object $bp Global BuddyPress settings object
133
  */
134
  function bp_core_sort_nav_items() {
135
  global $bp;
137
  if ( empty( $bp->bp_nav ) || !is_array( $bp->bp_nav ) )
138
  return false;
139
 
140
+ foreach ( (array)$bp->bp_nav as $slug => $nav_item ) {
141
+ if ( empty( $temp[$nav_item['position']]) )
 
 
142
  $temp[$nav_item['position']] = $nav_item;
143
+ else {
144
  // increase numbers here to fit new items in.
145
  do {
146
  $nav_item['position']++;
160
  * Adds a navigation item to the sub navigation array used in BuddyPress themes.
161
  *
162
  * @package BuddyPress Core
163
+ * @global object $bp Global BuddyPress settings object
164
  */
165
  function bp_core_new_subnav_item( $args = '' ) {
166
  global $bp;
185
  if ( empty( $name ) || empty( $slug ) || empty( $parent_slug ) || empty( $parent_url ) || empty( $screen_function ) )
186
  return false;
187
 
188
+ if ( empty( $link ) )
 
189
  $link = $parent_url . $slug;
190
 
 
 
 
 
 
 
191
  // If this is for site admins only and the user is not one, don't create the subnav item
192
+ if ( $site_admin_only && !is_super_admin() )
193
  return false;
194
 
195
  if ( empty( $item_css_id ) )
211
  * subnav item. We figure out whether we're currently viewing this subnav by checking the
212
  * following two conditions:
213
  * (1) Either:
214
+ * (a) the parent slug matches the current_component, or
215
+ * (b) the parent slug matches the current_item
216
  * (2) And either:
217
+ * (a) the current_action matches $slug, or
218
  * (b) there is no current_action (ie, this is the default subnav for the parent nav)
219
  * and this subnav item is the default for the parent item (which we check by
220
  * comparing this subnav item's screen function with the screen function of the
223
  */
224
 
225
  // If we *don't* meet condition (1), return
226
+ if ( $bp->current_component != $parent_slug && $bp->current_item != $parent_slug )
227
  return;
228
 
229
  // If we *do* meet condition (2), then the added subnav item is currently being requested
230
+ if ( ( !empty( $bp->current_action ) && $slug == $bp->current_action ) || ( bp_is_user() && empty( $bp->current_action ) && $screen_function == $bp->bp_nav[$parent_slug]['screen_function'] ) ) {
231
 
232
  // Before hooking the screen function, check user access
233
+ if ( $user_has_access ) {
234
+ if ( !is_object( $screen_function[0] ) )
235
+ add_action( 'bp_screens', $screen_function );
236
+ else
237
+ add_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ) );
 
238
  } else {
239
+ // When the content is off-limits, we handle the situation differently
240
+ // depending on whether the current user is logged in
 
241
  if ( is_user_logged_in() ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  // Off-limits to this user. Throw an error and redirect to the displayed user's domain
243
  bp_core_no_access( array(
244
+ 'message' => __( 'You do not have access to this page.', 'buddypress' ),
245
+ 'root' => bp_displayed_user_domain(),
246
  'redirect' => false
247
  ) );
 
 
248
  } else {
249
+ // Not logged in. Allow the user to log in, and attempt to redirect
250
  bp_core_no_access();
251
  }
252
  }
259
  if ( empty( $bp->bp_options_nav ) || !is_array( $bp->bp_options_nav ) )
260
  return false;
261
 
262
+ foreach ( (array)$bp->bp_options_nav as $parent_slug => $subnav_items ) {
263
  if ( !is_array( $subnav_items ) )
264
  continue;
265
 
266
+ foreach ( (array)$subnav_items as $subnav_item ) {
267
  if ( empty( $temp[$subnav_item['position']]) )
268
  $temp[$subnav_item['position']] = $subnav_item;
269
  else {
287
  * Determines whether a given nav item has subnav items
288
  *
289
  * @package BuddyPress
290
+ * @since 1.5
291
  *
292
  * @param str $nav_item The id of the top-level nav item whose nav items you're checking
293
  * @return bool $has_subnav True if the nav item is found and has subnav items; false otherwise
315
 
316
  // Unset subnav items for this nav item
317
  if ( isset( $bp->bp_options_nav[$parent_id] ) && is_array( $bp->bp_options_nav[$parent_id] ) ) {
318
+ foreach( (array)$bp->bp_options_nav[$parent_id] as $subnav_item ) {
319
  bp_core_remove_subnav_item( $parent_id, $subnav_item['slug'] );
320
  }
321
  }
322
 
323
  if ( $function = $bp->bp_nav[$parent_id]['screen_function'] ) {
324
+ if ( !is_object( $function[0] ) ) {
325
+ remove_action( 'bp_screens', $function );
326
  } else {
327
+ remove_action( 'bp_screens', array( &$function[0], $function[1] ) );
328
  }
329
  }
330
 
341
  function bp_core_remove_subnav_item( $parent_id, $slug ) {
342
  global $bp;
343
 
344
+ $screen_function = ( isset( $bp->bp_options_nav[$parent_id][$slug]['screen_function'] ) ) ? $bp->bp_options_nav[$parent_id][$slug]['screen_function'] : false;
345
 
346
+ if ( $screen_function ) {
347
+ if ( !is_object( $screen_function[0] ) )
348
+ remove_action( 'bp_screens', $screen_function );
349
+ else
350
+ remove_action( 'bp_screens', array( &$screen_function[0], $screen_function[1] ) );
 
351
  }
352
 
353
  unset( $bp->bp_options_nav[$parent_id][$slug] );
361
  *
362
  * @package BuddyPress Core
363
  * @param $parent_id The id of the parent navigation item.
364
+ * @global object $bp Global BuddyPress settings object
365
  */
366
  function bp_core_reset_subnav_items( $parent_slug ) {
367
  global $bp;
377
  if ( defined( 'BP_DISABLE_ADMIN_BAR' ) && BP_DISABLE_ADMIN_BAR )
378
  return false;
379
 
380
+ if ( (int)bp_get_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() )
381
  return false;
382
 
383
  $bp->doing_admin_bar = true;
398
  $bp->doing_admin_bar = false;
399
  }
400
 
401
+ // **** Default BuddyPress admin bar logo ********
402
  function bp_adminbar_logo() {
403
+ global $bp;
404
+
405
  echo '<a href="' . bp_get_root_domain() . '" id="admin-bar-logo">' . get_blog_option( bp_get_root_blog_id(), 'blogname' ) . '</a>';
406
  }
407
 
408
  // **** "Log In" and "Sign Up" links (Visible when not logged in) ********
409
  function bp_adminbar_login_menu() {
410
+ global $bp;
411
 
412
  if ( is_user_logged_in() )
413
  return false;
414
 
415
+ echo '<li class="bp-login no-arrow"><a href="' . bp_get_root_domain() . '/wp-login.php?redirect_to=' . urlencode( bp_get_root_domain() ) . '">' . __( 'Log In', 'buddypress' ) . '</a></li>';
416
 
417
  // Show "Sign Up" link if user registrations are allowed
418
  if ( bp_get_signup_allowed() )
433
 
434
  // Loop through each navigation item
435
  $counter = 0;
436
+ foreach( (array)$bp->bp_nav as $nav_item ) {
437
  $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
438
 
439
  if ( -1 == $nav_item['position'] )
446
  echo '<ul>';
447
  $sub_counter = 0;
448
 
449
+ foreach( (array)$bp->bp_options_nav[$nav_item['slug']] as $subnav_item ) {
450
  $link = $subnav_item['link'];
451
  $name = $subnav_item['name'];
452
 
453
+ if ( isset( $bp->displayed_user->domain ) )
454
+ $link = str_replace( $bp->displayed_user->domain, $bp->loggedin_user->domain, $subnav_item['link'] );
455
 
456
  if ( isset( $bp->displayed_user->userdata->user_login ) )
457
  $name = str_replace( $bp->displayed_user->userdata->user_login, $bp->loggedin_user->userdata->user_login, $subnav_item['name'] );
496
 
497
  // **** "Random" Menu (visible when not logged in) ********
498
  function bp_adminbar_random_menu() {
499
+ global $bp; ?>
500
 
501
  <li class="align-right" id="bp-adminbar-visitrandom-menu">
502
  <a href="#"><?php _e( 'Visit', 'buddypress' ) ?></a>
524
  }
525
 
526
  /**
527
+ * Retrieve the admin bar display preference of a user based on context.
528
  *
529
  * This is a direct copy of WP's private _get_admin_bar_pref()
530
  *
531
+ * @since 1.5.0
532
  *
533
  * @param string $context Context of this preference check, either 'admin' or 'front'.
534
  * @param int $user Optional. ID of the user to check, defaults to 0 for current user.
535
  *
536
  * @uses get_user_option()
537
  *
538
+ * @return bool Whether the admin bar should be showing for this user.
539
  */
540
  function bp_get_admin_bar_pref( $context, $user = 0 ) {
541
  $pref = get_user_option( "show_admin_bar_{$context}", $user );
546
  }
547
 
548
  /**
549
+ * Handle the Admin Bar/BuddyBar business
550
  *
551
+ * @since 1.2.0
552
  *
553
  * @global string $wp_version
554
  * @uses bp_get_option()
566
  function bp_core_load_admin_bar() {
567
  global $wp_version;
568
 
569
+ // Don't show if admin bar is disabled for non-logged in users
570
+ if ( (int) bp_get_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() )
571
  return;
572
 
573
+ // Show the WordPress admin bar
574
  if ( bp_use_wp_admin_bar() && $wp_version >= 3.1 ) {
575
+ // Respect user's admin bar display preferences
576
+ if ( bp_get_admin_bar_pref( 'front', bp_loggedin_user_id() ) || bp_get_admin_bar_pref( 'admin', bp_loggedin_user_id() ) )
 
577
  return;
578
 
579
  show_admin_bar( true );
580
 
581
+ // Hide the WordPress admin bar
582
  } elseif ( !bp_use_wp_admin_bar() ) {
583
+
584
+ // Keep the WP admin bar from loading
585
  show_admin_bar( false );
586
 
587
+ // Actions used to build the BP admin bar
588
  add_action( 'bp_adminbar_logo', 'bp_adminbar_logo' );
589
  add_action( 'bp_adminbar_menus', 'bp_adminbar_login_menu', 2 );
590
  add_action( 'bp_adminbar_menus', 'bp_adminbar_account_menu', 4 );
591
  add_action( 'bp_adminbar_menus', 'bp_adminbar_thisblog_menu', 6 );
592
  add_action( 'bp_adminbar_menus', 'bp_adminbar_random_menu', 100 );
593
 
594
+ // Actions used to append BP admin bar to footer
595
  add_action( 'wp_footer', 'bp_core_admin_bar', 8 );
596
  add_action( 'admin_footer', 'bp_core_admin_bar' );
597
  }
607
  if ( file_exists( get_stylesheet_directory() . '/_inc/css/adminbar.css' ) ) // Backwards compatibility
608
  $stylesheet = get_stylesheet_directory_uri() . '/_inc/css/adminbar.css';
609
  elseif ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG )
610
+ $stylesheet = BP_PLUGIN_URL . '/bp-core/css/buddybar.dev.css';
611
  else
612
+ $stylesheet = BP_PLUGIN_URL . '/bp-core/css/buddybar.css';
613
 
614
+ wp_enqueue_style( 'bp-admin-bar', apply_filters( 'bp_core_admin_bar_css', $stylesheet ), array(), '20110723' );
615
 
616
  if ( !is_rtl() )
617
  return;
618
 
619
  if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG )
620
+ $stylesheet = BP_PLUGIN_URL . '/bp-core/css/buddybar-rtl.dev.css';
621
  else
622
+ $stylesheet = BP_PLUGIN_URL . '/bp-core/css/buddybar-rtl.css';
623
 
624
+ wp_enqueue_style( 'bp-admin-bar-rtl', apply_filters( 'bp_core_buddybar_rtl_css', $stylesheet ), array( 'bp-admin-bar' ), '20110723' );
625
  }
626
  add_action( 'bp_init', 'bp_core_load_buddybar_css' );
 
627
  ?>
bp-core/bp-core-cache.php CHANGED
@@ -44,93 +44,8 @@ function bp_core_clear_user_object_cache( $user_id ) {
44
  wp_cache_delete( 'bp_user_' . $user_id, 'bp' );
45
  }
46
 
47
- /**
48
- * Clears member count caches and transients
49
- */
50
- function bp_core_clear_member_count_caches() {
51
- wp_cache_delete( 'bp_total_member_count', 'bp' );
52
- delete_transient( 'bp_active_member_count' );
53
- }
54
- add_action( 'bp_core_activated_user', 'bp_core_clear_member_count_caches' );
55
- add_action( 'bp_core_process_spammer_status', 'bp_core_clear_member_count_caches' );
56
- add_action( 'bp_core_deleted_account', 'bp_core_clear_member_count_caches' );
57
- add_action( 'bp_first_activity_for_member', 'bp_core_clear_member_count_caches' );
58
- add_action( 'deleted_user', 'bp_core_clear_member_count_caches' );
59
-
60
- /**
61
- * Update the metadata cache for the specified objects.
62
- *
63
- * @since 1.6
64
- * @global $wpdb WordPress database object for queries.
65
- * @param array $args See $defaults definition for more details
66
- * @return mixed Metadata cache for the specified objects, or false on failure.
67
- */
68
- function bp_update_meta_cache( $args = array() ) {
69
- global $wpdb;
70
-
71
- $defaults = array(
72
- 'object_ids' => array(), // Comma-separated list or array of item ids
73
- 'object_type' => '', // Canonical component id: groups, members, etc
74
- 'meta_table' => '', // Name of the table containing the metadata
75
- 'object_column' => '', // DB column for the object ids (group_id, etc)
76
- 'cache_key_prefix' => '' // Prefix to use when creating cache key names. Eg
77
- // 'bp_groups_groupmeta'
78
- );
79
- $r = wp_parse_args( $args, $defaults );
80
- extract( $r );
81
-
82
- if ( empty( $object_ids ) || empty( $object_type ) || empty( $meta_table ) ) {
83
- return false;
84
- }
85
-
86
- if ( empty( $cache_key_prefix ) ) {
87
- $cache_key_prefix = $meta_table;
88
- }
89
-
90
- if ( empty( $object_column ) ) {
91
- $object_column = $object_type . '_id';
92
- }
93
-
94
- if ( !is_array( $object_ids ) ) {
95
- $object_ids = preg_replace( '|[^0-9,]|', '', $object_ids );
96
- $object_ids = explode( ',', $object_ids );
97
- }
98
-
99
- $object_ids = array_map( 'intval', $object_ids );
100
-
101
- $cache = array();
102
-
103
- // Get meta info
104
- $id_list = join( ',', $object_ids );
105
- $meta_list = $wpdb->get_results( $wpdb->prepare( "SELECT $object_column, meta_key, meta_value FROM $meta_table WHERE $object_column IN ($id_list)" ), ARRAY_A );
106
-
107
- if ( !empty( $meta_list ) ) {
108
- foreach ( $meta_list as $metarow ) {
109
- $mpid = intval( $metarow[$object_column] );
110
- $mkey = $metarow['meta_key'];
111
- $mval = $metarow['meta_value'];
112
-
113
- // Force subkeys to be array type:
114
- if ( !isset( $cache[$mpid] ) || !is_array( $cache[$mpid] ) )
115
- $cache[$mpid] = array();
116
- if ( !isset( $cache[$mpid][$mkey] ) || !is_array( $cache[$mpid][$mkey] ) )
117
- $cache[$mpid][$mkey] = array();
118
-
119
- // Add a value to the current pid/key:
120
- $cache[$mpid][$mkey][] = $mval;
121
- }
122
- }
123
-
124
- foreach ( $object_ids as $id ) {
125
- if ( ! isset($cache[$id]) )
126
- $cache[$id] = array();
127
-
128
- foreach( $cache[$id] as $meta_key => $meta_value ) {
129
- wp_cache_set( $cache_key_prefix . '_' . $id . '_' . $meta_key, $meta_value, 'bp' );
130
- }
131
- }
132
-
133
- return $cache;
134
- }
135
 
136
  ?>
44
  wp_cache_delete( 'bp_user_' . $user_id, 'bp' );
45
  }
46
 
47
+ // List actions to clear super cached pages on, if super cache is installed
48
+ add_action( 'wp_login', 'bp_core_clear_cache' );
49
+ add_action( 'bp_core_render_notice', 'bp_core_clear_cache' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
  ?>
bp-core/bp-core-caps.php DELETED
@@ -1,426 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * BuddyPress Capabilites
5
- *
6
- * @package BuddyPress
7
- * @subpackage Capabilities
8
- */
9
-
10
- // Exit if accessed directly
11
- if ( !defined( 'ABSPATH' ) ) exit;
12
-
13
- /**
14
- * Adds BuddyPress-specific user roles.
15
- *
16
- * This is called on plugin activation.
17
- *
18
- * @since BuddyPress (1.6)
19
- *
20
- * @uses get_option() To get the default role
21
- * @uses get_role() To get the default role object
22
- * @uses add_role() To add our own roles
23
- * @uses do_action() Calls 'bp_add_roles'
24
- */
25
- function bp_add_roles() {
26
-
27
- // Get new role names
28
- $moderator_role = bp_get_moderator_role();
29
- $participant_role = bp_get_participant_role();
30
-
31
- // Add the Moderator role and add the default role caps.
32
- // Mod caps are added by the bp_add_caps() function
33
- $default = get_role( get_option( 'default_role' ) );
34
-
35
- // If role does not exist, default to read cap
36
- if ( empty( $default->capabilities ) )
37
- $default->capabilities = array( 'read' );
38
-
39
- // Moderators are default role + community moderating caps in bp_add_caps()
40
- add_role( $moderator_role, 'Community Moderator', $default->capabilities );
41
-
42
- // Forum Subscribers are auto added to sites with global communities
43
- add_role( $participant_role, 'Community Participant', $default->capabilities );
44
-
45
- do_action( 'bp_add_roles' );
46
- }
47
-
48
- /**
49
- * Adds capabilities to WordPress user roles.
50
- *
51
- * This is called on plugin activation.
52
- *
53
- * @since BuddyPress (1.6)
54
- *
55
- * @uses get_role() To get the administrator, default and moderator roles
56
- * @uses WP_Role::add_cap() To add various capabilities
57
- * @uses do_action() Calls 'bp_add_caps'
58
- */
59
- function bp_add_caps() {
60
- global $wp_roles;
61
-
62
- // Load roles if not set
63
- if ( ! isset( $wp_roles ) )
64
- $wp_roles = new WP_Roles();
65
-
66
- // Loop through available roles
67
- foreach( $wp_roles->roles as $role => $details ) {
68
-
69
- // Load this role
70
- $this_role = get_role( $role );
71
-
72
- // Loop through caps for this role and remove them
73
- foreach ( bp_get_caps_for_role( $role ) as $cap ) {
74
- $this_role->add_cap( $cap );
75
- }
76
- }
77
-
78
- do_action( 'bp_add_caps' );
79
- }
80
-
81
- /**
82
- * Removes capabilities from WordPress user roles.
83
- *
84
- * This is called on plugin deactivation.
85
- *
86
- * @since BuddyPress (1.6)
87
- *
88
- * @uses get_role() To get the administrator and default roles
89
- * @uses WP_Role::remove_cap() To remove various capabilities
90
- * @uses do_action() Calls 'bp_remove_caps'
91
- */
92
- function bp_remove_caps() {
93
- global $wp_roles;
94
-
95
- // Load roles if not set
96
- if ( ! isset( $wp_roles ) )
97
- $wp_roles = new WP_Roles();
98
-
99
- // Loop through available roles
100
- foreach( $wp_roles->roles as $role => $details ) {
101
-
102
- // Load this role
103
- $this_role = get_role( $role );
104
-
105
- // Loop through caps for this role and remove them
106
- foreach ( bp_get_caps_for_role( $role ) as $cap ) {
107
- $this_role->remove_cap( $cap );
108
- }
109
- }
110
-
111
- do_action( 'bp_remove_caps' );
112
- }
113
-
114
- /**
115
- * Removes BuddyPress-specific user roles.
116
- *
117
- * This is called on plugin deactivation.
118
- *
119
- * @since BuddyPress (1.6)
120
- *
121
- * @uses remove_role() To remove our roles
122
- * @uses do_action() Calls 'bp_remove_roles'
123
- */
124
- function bp_remove_roles() {
125
-
126
- // Get new role names
127
- $moderator_role = bp_get_moderator_role();
128
- $participant_role = bp_get_participant_role();
129
-
130
- // Remove the Moderator role
131
- remove_role( $moderator_role );
132
-
133
- // Remove the Moderator role
134
- remove_role( $participant_role );
135
-
136
- do_action( 'bp_remove_roles' );
137
- }
138
-
139
- /**
140
- * Maps community caps to built in WordPress caps
141
- *
142
- * @since BuddyPress (1.6)
143
- *
144
- * @param array $caps Capabilities for meta capability
145
- * @param string $cap Capability name
146
- * @param int $user_id User id
147
- * @param mixed $args Arguments
148
- * @uses get_post() To get the post
149
- * @uses get_post_type_object() To get the post type object
150
- * @uses apply_filters() Calls 'bp_map_meta_caps' with caps, cap, user id and
151
- * args
152
- * @return array Actual capabilities for meta capability
153
- */
154
- function bp_map_meta_caps( $caps, $cap, $user_id, $args ) {
155
- return apply_filters( 'bp_map_meta_caps', $caps, $cap, $user_id, $args );
156
- }
157
-
158
- /**
159
- * Return community capabilities
160
- *
161
- * @since BuddyPress (1.6)
162
- *
163
- * @uses apply_filters() Calls 'bp_get_community_caps' with the capabilities
164
- * @return array Forum capabilities
165
- */
166
- function bp_get_community_caps() {
167
-
168
- // Forum meta caps
169
- $caps = array();
170
-
171
- return apply_filters( 'bp_get_community_caps', $caps );
172
- }
173
-
174
- /**
175
- * Returns an array of capabilities based on the role that is being requested.
176
- *
177
- * @since BuddyPress (1.6)
178
- *
179
- * @param string $role Optional. Defaults to The role to load caps for
180
- * @uses apply_filters() Allow return value to be filtered
181
- *
182
- * @return array Capabilities for $role
183
- */
184
- function bp_get_caps_for_role( $role = '' ) {
185
-
186
- // Get new role names
187
- $moderator_role = bp_get_moderator_role();
188
- $participant_role = bp_get_participant_role();
189
-
190
- // Which role are we looking for?
191
- switch ( $role ) {
192
-
193
- // Administrator
194
- case 'administrator' :
195
- $caps = array(
196
- // Misc
197
- 'bp_moderate',
198
- );
199
-
200
- break;
201
-
202
- // Moderator
203
- case $moderator_role :
204
- $caps = array(
205
- // Misc
206
- 'bp_moderate',
207
- );
208
-
209
- break;
210
-
211
- // WordPress Core Roles
212
- case 'editor' :
213
- case 'author' :
214
- case 'contributor' :
215
- case 'subscriber' :
216
-
217
- // BuddyPress Participant Role
218
- case $participant_role :
219
- default :
220
- $caps = array();
221
- break;
222
- }
223
-
224
- return apply_filters( 'bp_get_caps_for_role', $caps, $role );
225
- }
226
-
227
- /**
228
- * Give a user the default 'Forum Participant' role when creating a topic/reply
229
- * on a site they do not have a role or capability on.
230
- *
231
- * @since BuddyPress (1.6)
232
- *
233
- * @global BuddyPress $bbp
234
- *
235
- * @uses is_multisite()
236
- * @uses bp_allow_global_access()
237
- * @uses bp_is_user_inactive()
238
- * @uses is_user_logged_in()
239
- * @uses current_user_can()
240
- * @uses WP_User::set_role()
241
- *
242
- * @return If user is not spam/deleted or is already capable
243
- */
244
- function bp_global_access_auto_role() {
245
-
246
- // Bail if not multisite or community is not global
247
- if ( !is_multisite() || !bp_allow_global_access() )
248
- return;
249
-
250
- // Bail if user is not active
251
- if ( bp_is_user_inactive() )
252
- return;
253
-
254
- // Bail if user is not logged in
255
- if ( !is_user_logged_in() )
256
- return;
257
-
258
- // Give the user the 'Forum Participant' role
259
- if ( current_user_can( 'bp_masked' ) ) {
260
- global $bbp;
261
-
262
- // Get the default role
263
- $default_role = bp_get_participant_role();
264
-
265
- // Set the current users default role
266
- $bbp->current_user->set_role( $default_role );
267
- }
268
- }
269
-
270
- /**
271
- * The participant role for registered users without roles
272
- *
273
- * This is primarily for multisite compatibility when users without roles on
274
- * sites that have global communities enabled
275
- *
276
- * @since BuddyPress (1.6)
277
- *
278
- * @param string $role
279
- * @uses apply_filters()
280
- * @return string
281
- */
282
- function bp_get_participant_role() {
283
-
284
- // Hardcoded participant role
285
- $role = 'bp_participant';
286
-
287
- // Allow override
288
- return apply_filters( 'bp_get_participant_role', $role );
289
- }
290
-
291
- /**
292
- * The moderator role for BuddyPress users
293
- *
294
- * @since BuddyPress (1.6)
295
- *
296
- * @param string $role
297
- * @uses apply_filters()
298
- * @return string
299
- */
300
- function bp_get_moderator_role() {
301
-
302
- // Hardcoded moderated user role
303
- $role = 'bp_moderator';
304
-
305
- // Allow override
306
- return apply_filters( 'bp_get_moderator_role', $role );
307
- }
308
-
309
- /**
310
- * Add the default role and mapped BuddyPress caps to the current user if needed
311
- *
312
- * This function will bail if the community is not global in a multisite
313
- * installation of WordPress, or if the user is marked as spam or deleted.
314
- *
315
- * @since BuddyPress (1.6)
316
- *
317
- * @uses is_multisite()
318
- * @uses bp_allow_global_access()
319
- * @uses bp_is_user_inactive()
320
- * @uses is_user_logged_in()
321
- * @uses current_user_can()
322
- * @uses get_option()
323
- * @uses bp_get_caps_for_role()
324
- *
325
- * @global BuddyPress $bbp
326
- * @return If not multisite, not global, or user is deleted/spammed
327
- */
328
- function bp_global_access_role_mask() {
329
-
330
- // Bail if not multisite or community is not global
331
- if ( !is_multisite() || !bp_allow_global_access() )
332
- return;
333
-
334
- // Bail if user is marked as spam or is deleted
335
- if ( bp_is_user_inactive() )
336
- return;
337
-
338
- // Normal user is logged in but has no caps
339
- if ( is_user_logged_in() && !current_user_can( 'read' ) ) {
340
-
341
- // Define local variable
342
- $mapped_meta_caps = array();
343
-
344
- // Assign user the minimal participant role to map caps to
345
- $default_role = bp_get_participant_role();
346
-
347
- // Get BuddyPress caps for the default role
348
- $caps_for_role = bp_get_caps_for_role( $default_role );
349
-
350
- // Set all caps to true
351
- foreach ( $caps_for_role as $cap ) {
352
- $mapped_meta_caps[$cap] = true;
353
- }
354
-
355
- // Add 'read' cap just in case
356
- $mapped_meta_caps['read'] = true;
357
- $mapped_meta_caps['bp_masked'] = true;
358
-
359
- // Allow global access caps to be manipulated
360
- $mapped_meta_caps = apply_filters( 'bp_global_access_mapped_meta_caps', $mapped_meta_caps );
361
-
362
- // Assign the role and mapped caps to the current user
363
- global $bp;
364
- $bp->current_user->roles[0] = $default_role;
365
- $bp->current_user->caps = $mapped_meta_caps;
366
- $bp->current_user->allcaps = $mapped_meta_caps;
367
- }
368
- }
369
-
370
- /**
371
- * Whether current user has a capability or role. Can be passed blog ID, or will
372
- * use the root blod by default
373
- *
374
- * @since BuddyPress (1.6)
375
- *
376
- * @param string $capability Capability or role name.
377
- * @param int $blog_id Blog ID
378
- * @return bool
379
- */
380
- function bp_current_user_can( $capability, $blog_id = 0 ) {
381
-
382
- // Use root blog if no ID passed
383
- if ( empty( $blog_id ) )
384
- $blog_id = bp_get_root_blog_id();
385
-
386
- $retval = current_user_can_for_blog( $blog_id, $capability );
387
-
388
- return (bool) apply_filters( 'bp_current_user_can', $retval, $capability, $blog_id );
389
- }
390
-
391
- /**
392
- * Temporary implementation of 'bp_moderate' cap
393
- *
394
- * In BuddyPress 1.6, the 'bp_moderate' cap was introduced. In order to enforce that
395
- * bp_current_user_can( 'bp_moderate' ) always returns true for Administrators, we must manually
396
- * add the 'bp_moderate' cap to the list of user caps for Admins.
397
- *
398
- * Note that this level of enforcement is only necessary in the case of non-Multisite. This is
399
- * because WordPress automatically assigns every capability - and thus 'bp_moderate' - to Super
400
- * Admins on a Multisite installation. See WP_User::has_cap().
401
- *
402
- * This implementation of 'bp_moderate' is temporary, until BuddyPress properly matches caps to
403
- * roles and stores them in the database. Plugin authors: Do not use this function.
404
- *
405
- * @since BuddyPress (1.6)
406
- * @see WP_User::has_cap()
407
- *
408
- * @param array $allcaps The caps that WP associates with the given role
409
- * @param array $caps The caps being tested for in WP_User::has_cap()
410
- * @param array $args Miscellaneous arguments passed to the user_has_cap filter
411
- * @return array $allcaps The user's cap list, with 'bp_moderate' appended, if relevant
412
- */
413
- function _bp_enforce_bp_moderate_cap_for_admins( $allcaps, $caps, $args ) {
414
- if ( in_array( 'bp_moderate', $caps ) && // We only care if checking for bp_moderate
415
- !in_array( 'do_not_allow', $caps ) && // 'do_not_allow' overrides everything else
416
- !is_multisite() && // Check not necessary on Multisite
417
- isset( $allcaps['delete_users'] ) ) // Mimicking WP's check for Administrator status
418
- {
419
- $allcaps['bp_moderate'] = true;
420
- }
421
-
422
- return $allcaps;
423
- }
424
- add_filter( 'user_has_cap', '_bp_enforce_bp_moderate_cap_for_admins', 10, 3 );
425
-
426
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-core/bp-core-catchuri.php CHANGED
@@ -1,29 +1,21 @@
1
  <?php
2
-
3
- /**
4
- * BuddyPress URI catcher
5
- *
6
- * Functions for parsing the URI and determining which BuddyPress template file
7
- * to use on-screen.
8
- *
9
- * Based on contributions from: Chris Taylor - http://www.stillbreathing.co.uk/
10
- * Modified for BuddyPress by: Andy Peatling - http://apeatling.wordpress.com/
11
- *
12
- * @package BuddyPress
13
- * @subpackage Core
14
- */
15
-
16
  // Exit if accessed directly
17
  if ( !defined( 'ABSPATH' ) ) exit;
18
 
 
 
 
 
 
19
  /**
20
  * Analyzes the URI structure and breaks it down into parts for use in code.
21
- * BuddyPress can use complete custom friendly URI's without the user having to
22
- * add new re-write rules. Custom components are able to use their own custom
23
- * URI structures with very little work.
 
24
  *
25
  * @package BuddyPress Core
26
- * @since BuddyPress (1.0)
27
  *
28
  * The URI's are broken down as follows:
29
  * - http:// domain.com / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ...
@@ -37,22 +29,23 @@ if ( !defined( 'ABSPATH' ) ) exit;
37
  *
38
  */
39
  function bp_core_set_uri_globals() {
40
- global $bp, $current_blog, $wp_rewrite;
 
 
 
 
 
41
 
42
  // Don't catch URIs on non-root blogs unless multiblog mode is on
43
  if ( !bp_is_root_blog() && !bp_is_multiblog_mode() )
44
  return false;
45
 
46
- // Define local variables
47
- $root_profile = $match = false;
48
- $key_slugs = $matches = $uri_chunks = array();
49
-
50
  // Fetch all the WP page names for each component
51
  if ( empty( $bp->pages ) )
52
  $bp->pages = bp_core_get_directory_pages();
53
 
54
  // Ajax or not?
55
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX || strpos( $_SERVER['REQUEST_URI'], 'wp-load.php' ) )
56
  $path = bp_core_referrer();
57
  else
58
  $path = esc_url( $_SERVER['REQUEST_URI'] );
@@ -60,39 +53,30 @@ function bp_core_set_uri_globals() {
60
  // Filter the path
61
  $path = apply_filters( 'bp_uri', $path );
62
 
63
- // Take GET variables off the URL to avoid problems
64
- $path = strtok( $path, '?' );
 
 
65
 
66
- // Fetch current URI and explode each part separated by '/' into an array
67
  $bp_uri = explode( '/', $path );
68
 
69
  // Loop and remove empties
70
- foreach ( (array) $bp_uri as $key => $uri_chunk ) {
71
- if ( empty( $bp_uri[$key] ) ) {
72
- unset( $bp_uri[$key] );
73
- }
74
- }
75
 
76
- // If running off blog other than root, any subdirectory names must be
77
- // removed from $bp_uri. This includes two cases:
78
- //
79
- // 1. when WP is installed in a subdirectory,
80
- // 2. when BP is running on secondary blog of a subdirectory
81
- // multisite installation. Phew!
82
  if ( is_multisite() && !is_subdomain_install() && ( bp_is_multiblog_mode() || 1 != bp_get_root_blog_id() ) ) {
83
 
84
- // Blow chunks
85
- $chunks = explode( '/', $current_blog->path );
86
-
87
- // If chunks exist...
88
- if ( !empty( $chunks ) ) {
89
-
90
- // ...loop through them...
91
  foreach( $chunks as $key => $chunk ) {
92
  $bkey = array_search( $chunk, $bp_uri );
93
 
94
- // ...and unset offending keys
95
- if ( false !== $bkey ) {
96
  unset( $bp_uri[$bkey] );
97
  }
98
 
@@ -101,6 +85,10 @@ function bp_core_set_uri_globals() {
101
  }
102
  }
103
 
 
 
 
 
104
  // Get site path items
105
  $paths = explode( '/', bp_core_get_site_path() );
106
 
@@ -112,13 +100,9 @@ function bp_core_set_uri_globals() {
112
  if ( empty( $paths[0] ) )
113
  array_shift( $paths );
114
 
115
- // Reset indexes
116
- $bp_uri = array_values( $bp_uri );
117
- $paths = array_values( $paths );
118
-
119
  // Unset URI indices if they intersect with the paths
120
  foreach ( (array) $bp_uri as $key => $uri_chunk ) {
121
- if ( isset( $paths[$key] ) && $uri_chunk == $paths[$key] ) {
122
  unset( $bp_uri[$key] );
123
  }
124
  }
@@ -137,7 +121,7 @@ function bp_core_set_uri_globals() {
137
  }
138
 
139
  // Keep the unfiltered URI safe
140
- $bp->unfiltered_uri = $bp_uri;
141
 
142
  // Get slugs of pages into array
143
  foreach ( (array) $bp->pages as $page_key => $bp_page )
@@ -199,13 +183,10 @@ function bp_core_set_uri_globals() {
199
  }
200
 
201
  // URLs with BP_ENABLE_ROOT_PROFILES enabled won't be caught above
202
- if ( empty( $matches ) && bp_core_enable_root_profiles() ) {
203
-
204
- // Switch field based on compat
205
- $field = bp_is_username_compatibility_mode() ? 'login' : 'slug';
206
 
207
  // Make sure there's a user corresponding to $bp_uri[0]
208
- if ( !empty( $bp->pages->members ) && !empty( $bp_uri[0] ) && $root_profile = get_user_by( $field, $bp_uri[0] ) ) {
209
 
210
  // Force BP to recognize that this is a members page
211
  $matches[] = 1;
@@ -227,11 +208,9 @@ function bp_core_set_uri_globals() {
227
  }
228
 
229
  // This is not a BuddyPress page, so just return.
230
- if ( empty( $matches ) )
231
  return false;
232
 
233
- $wp_rewrite->use_verbose_page_rules = false;
234
-
235
  // Find the offset. With $root_profile set, we fudge the offset down so later parsing works
236
  $slug = !empty ( $match ) ? explode( '/', $match->slug ) : '';
237
  $uri_offset = empty( $root_profile ) ? 0 : -1;
@@ -244,7 +223,7 @@ function bp_core_set_uri_globals() {
244
 
245
  // Global the unfiltered offset to use in bp_core_load_template().
246
  // To avoid PHP warnings in bp_core_load_template(), it must always be >= 0
247
- $bp->unfiltered_uri_offset = $uri_offset >= 0 ? $uri_offset : 0;
248
 
249
  // We have an exact match
250
  if ( isset( $match->key ) ) {
@@ -259,14 +238,12 @@ function bp_core_set_uri_globals() {
259
  if ( !empty( $bp_uri[$uri_offset + 1] ) ) {
260
 
261
  // Switch the displayed_user based on compatbility mode
262
- if ( bp_is_username_compatibility_mode() ) {
263
  $bp->displayed_user->id = (int) bp_core_get_userid( urldecode( $bp_uri[$uri_offset + 1] ) );
264
- } else {
265
  $bp->displayed_user->id = (int) bp_core_get_userid_from_nicename( urldecode( $bp_uri[$uri_offset + 1] ) );
266
- }
267
-
268
- if ( !bp_displayed_user_id() ) {
269
 
 
270
  // Prevent components from loading their templates
271
  $bp->current_component = '';
272
 
@@ -276,9 +253,9 @@ function bp_core_set_uri_globals() {
276
 
277
  // If the displayed user is marked as a spammer, 404 (unless logged-
278
  // in user is a super admin)
279
- if ( bp_displayed_user_id() && bp_is_user_spammer( bp_displayed_user_id() ) ) {
280
- if ( bp_current_user_can( 'bp_moderate' ) ) {
281
- bp_core_add_message( __( 'This user has been marked as a spammer. Only site admins can view this profile.', 'buddypress' ), 'warning' );
282
  } else {
283
  bp_do_404();
284
  return;
@@ -312,26 +289,15 @@ function bp_core_set_uri_globals() {
312
  // Set the entire URI as the action variables, we will unset the current_component and action in a second
313
  $bp->action_variables = $bp_uri;
314
 
 
 
 
 
 
315
  // Reset the keys by merging with an empty array
316
  $bp->action_variables = array_merge( array(), $bp->action_variables );
317
  }
318
 
319
- /**
320
- * Are root profiles enabled and allowed
321
- *
322
- * @since BuddyPress (1.6)
323
- * @return bool True if yes, false if no
324
- */
325
- function bp_core_enable_root_profiles() {
326
-
327
- $retval = false;
328
-
329
- if ( defined( 'BP_ENABLE_ROOT_PROFILES' ) && ( true == BP_ENABLE_ROOT_PROFILES ) )
330
- $retval = true;
331
-
332
- return apply_filters( 'bp_core_enable_root_profiles', $retval );
333
- }
334
-
335
  /**
336
  * bp_core_load_template()
337
  *
@@ -347,20 +313,16 @@ function bp_core_enable_root_profiles() {
347
  * @return false|int The user ID of the matched user, or false.
348
  */
349
  function bp_core_load_template( $templates ) {
350
- global $post, $bp, $wp_query, $wpdb;
351
 
352
- // Determine if the root object WP page exists for this request
353
- // note: get_page_by_path() breaks non-root pages
354
- if ( !empty( $bp->unfiltered_uri_offset ) ) {
355
- if ( !$page_exists = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_name = %s", $bp->unfiltered_uri[$bp->unfiltered_uri_offset] ) ) ) {
356
- return false;
357
- }
358
- }
359
 
360
  // Set the root object as the current wp_query-ied item
361
  $object_id = 0;
362
- foreach ( (array) $bp->pages as $page ) {
363
- if ( $page->name == $bp->unfiltered_uri[$bp->unfiltered_uri_offset] ) {
364
  $object_id = $page->id;
365
  }
366
  }
@@ -372,28 +334,18 @@ function bp_core_load_template( $templates ) {
372
  $post = $wp_query->queried_object;
373
  }
374
 
375
- // Define local variables
376
- $located_template = false;
377
- $filtered_templates = array();
378
-
379
  // Fetch each template and add the php suffix
380
- foreach ( (array) $templates as $template )
381
  $filtered_templates[] = $template . '.php';
382
 
383
  // Filter the template locations so that plugins can alter where they are located
384
- $located_template = apply_filters( 'bp_located_template', locate_template( (array) $filtered_templates, false ), $filtered_templates );
385
- if ( !empty( $located_template ) ) {
386
-
387
  // Template was located, lets set this as a valid page and not a 404.
388
  status_header( 200 );
389
- $wp_query->is_page = $wp_query->is_singular = true;
390
- $wp_query->is_404 = false;
391
-
392
- do_action( 'bp_core_pre_load_template', $located_template );
393
 
394
  load_template( apply_filters( 'bp_load_template', $located_template ) );
395
-
396
- do_action( 'bp_core_post_load_template', $located_template );
397
  }
398
 
399
  // Kill any other output after this.
@@ -408,30 +360,31 @@ function bp_core_load_template( $templates ) {
408
  *
409
  */
410
  function bp_core_catch_profile_uri() {
411
- if ( !bp_is_active( 'xprofile' ) ) {
 
 
412
  bp_core_load_template( apply_filters( 'bp_core_template_display_profile', 'members/single/home' ) );
413
- }
414
  }
415
 
416
  /**
417
  * Catches invalid access to BuddyPress pages and redirects them accordingly.
418
  *
419
  * @package BuddyPress Core
420
- * @since BuddyPress (1.5)
421
  */
422
  function bp_core_catch_no_access() {
423
- global $bp, $wp_query;
424
 
425
- // If coming from bp_core_redirect() and $bp_no_status_set is true,
426
- // we are redirecting to an accessible page so skip this check.
427
- if ( !empty( $bp->no_status_set ) )
428
  return false;
429
 
430
  if ( !isset( $wp_query->queried_object ) && !bp_is_blog_page() ) {
431
  bp_do_404();
432
  }
433
  }
434
- add_action( 'bp_template_redirect', 'bp_core_catch_no_access', 1 );
435
 
436
  /**
437
  * Redirects a user to login for BP pages that require access control and adds an error message (if
@@ -439,42 +392,33 @@ add_action( 'bp_template_redirect', 'bp_core_catch_no_access', 1 );
439
  * If authenticated, redirects user back to requested content by default.
440
  *
441
  * @package BuddyPress Core
442
- * @since BuddyPress (1.5)
443
  */
444
  function bp_core_no_access( $args = '' ) {
445
-
446
- // Build the redirect URL
447
- $redirect_url = is_ssl() ? 'https://' : 'http://';
448
- $redirect_url .= $_SERVER['HTTP_HOST'];
449
- $redirect_url .= $_SERVER['REQUEST_URI'];
450
 
451
  $defaults = array(
452
- 'mode' => '1', // 1 = $root, 2 = wp-login.php
453
- 'redirect' => $redirect_url, // the URL you get redirected to when a user successfully logs in
454
- 'root' => bp_get_root_domain(), // the landing page you get redirected to when a user doesn't have access
455
- 'message' => __( 'You must log in to access the page you requested.', 'buddypress' )
456
  );
457
 
458
  $r = wp_parse_args( $args, $defaults );
459
- $r = apply_filters( 'bp_core_no_access', $r );
460
  extract( $r, EXTR_SKIP );
461
 
462
- /**
463
- * @ignore Ignore these filters and use 'bp_core_no_access' above
464
- */
465
- $mode = apply_filters( 'bp_no_access_mode', $mode, $root, $redirect, $message );
466
- $redirect = apply_filters( 'bp_no_access_redirect', $redirect, $root, $message, $mode );
467
- $root = apply_filters( 'bp_no_access_root', $root, $redirect, $message, $mode );
468
- $message = apply_filters( 'bp_no_access_message', $message, $root, $redirect, $mode );
469
- $root = trailingslashit( $root );
470
 
471
  switch ( $mode ) {
472
-
473
  // Option to redirect to wp-login.php
474
  // Error message is displayed with bp_core_no_access_wp_login_error()
475
  case 2 :
476
- if ( !empty( $redirect ) ) {
477
- bp_core_redirect( add_query_arg( array( 'action' => 'bpnoaccess' ), wp_login_url( $redirect ) ) );
478
  } else {
479
  bp_core_redirect( $root );
480
  }
@@ -485,12 +429,13 @@ function bp_core_no_access( $args = '' ) {
485
  // Error message is displayed with bp_core_add_message()
486
  case 1 :
487
  default :
488
-
489
- $url = $root;
490
- if ( !empty( $redirect ) )
491
  $url = add_query_arg( 'redirect_to', urlencode( $redirect ), $root );
 
 
 
492
 
493
- if ( !empty( $message ) ) {
494
  bp_core_add_message( $message, 'error' );
495
  }
496
 
@@ -506,7 +451,7 @@ function bp_core_no_access( $args = '' ) {
506
  *
507
  * @package BuddyPress Core
508
  * @global $error
509
- * @since BuddyPress (1.5)
510
  */
511
  function bp_core_no_access_wp_login_error() {
512
  global $error;
@@ -518,185 +463,4 @@ function bp_core_no_access_wp_login_error() {
518
  }
519
  add_action( 'login_form_bpnoaccess', 'bp_core_no_access_wp_login_error' );
520
 
521
- /**
522
- * Canonicalizes BuddyPress URLs
523
- *
524
- * This function ensures that requests for BuddyPress content are always redirected to their
525
- * canonical versions. Canonical versions are always trailingslashed, and are typically the most
526
- * general possible versions of the URL - eg, example.com/groups/mygroup/ instead of
527
- * example.com/groups/mygroup/home/
528
- *
529
- * @since 1.6
530
- * @see BP_Members_Component::setup_globals() where $bp->canonical_stack['base_url'] and
531
- * ['component'] may be set
532
- * @see bp_core_new_nav_item() where $bp->canonical_stack['action'] may be set
533
- * @uses bp_get_canonical_url()
534
- * @uses bp_get_requested_url()
535
- */
536
- function bp_redirect_canonical() {
537
- global $bp;
538
-
539
- if ( !bp_is_blog_page() && apply_filters( 'bp_do_redirect_canonical', true ) ) {
540
- // If this is a POST request, don't do a canonical redirect.
541
- // This is for backward compatibility with plugins that submit form requests to
542
- // non-canonical URLs. Plugin authors should do their best to use canonical URLs in
543
- // their form actions.
544
- if ( !empty( $_POST ) ) {
545
- return;
546
- }
547
-
548
- // build the URL in the address bar
549
- $requested_url = bp_get_requested_url();
550
-
551
- // Stash query args
552
- $url_stack = explode( '?', $requested_url );
553
- $req_url_clean = $url_stack[0];
554
- $query_args = isset( $url_stack[1] ) ? $url_stack[1] : '';
555
-
556
- $canonical_url = bp_get_canonical_url();
557
-
558
- // Only redirect if we've assembled a URL different from the request
559
- if ( $canonical_url !== $req_url_clean ) {
560
-
561
- // Template messages have been deleted from the cookie by this point, so
562
- // they must be readded before redirecting
563
- if ( isset( $bp->template_message ) ) {
564
- $message = stripslashes( $bp->template_message );
565
- $message_type = isset( $bp->template_message_type ) ? $bp->template_message_type : 'success';
566
-
567
- bp_core_add_message( $message, $message_type );
568
- }
569
-
570
- if ( !empty( $query_args ) ) {
571
- $canonical_url .= '?' . $query_args;
572
- }
573
-
574
- bp_core_redirect( $canonical_url, 301 );
575
- }
576
- }
577
- }
578
-
579
- /**
580
- * Output rel=canonical header tag for BuddyPress content
581
- *
582
- * @since 1.6
583
- */
584
- function bp_rel_canonical() {
585
- $canonical_url = bp_get_canonical_url();
586
-
587
- // Output rel=canonical tag
588
- echo "<link rel='canonical' href='" . esc_attr( $canonical_url ) . "' />\n";
589
- }
590
-
591
- /**
592
- * Returns the canonical URL of the current page
593
- *
594
- * @since BuddyPress (1.6)
595
- * @uses apply_filters() Filter bp_get_canonical_url to modify return value
596
- * @param array $args
597
- * @return string
598
- */
599
- function bp_get_canonical_url( $args = array() ) {
600
- global $bp;
601
-
602
- // For non-BP content, return the requested url, and let WP do the work
603
- if ( bp_is_blog_page() ) {
604
- return bp_get_requested_url();
605
- }
606
-
607
- $defaults = array(
608
- 'include_query_args' => false // Include URL arguments, eg ?foo=bar&foo2=bar2
609
- );
610
- $r = wp_parse_args( $args, $defaults );
611
- extract( $r );
612
-
613
- if ( empty( $bp->canonical_stack['canonical_url'] ) ) {
614
- // Build the URL in the address bar
615
- $requested_url = bp_get_requested_url();
616
-
617
- // Stash query args
618
- $url_stack = explode( '?', $requested_url );
619
-
620
- // Build the canonical URL out of the redirect stack
621
- if ( isset( $bp->canonical_stack['base_url'] ) )
622
- $url_stack[0] = $bp->canonical_stack['base_url'];
623
-
624
- if ( isset( $bp->canonical_stack['component'] ) )
625
- $url_stack[0] = trailingslashit( $url_stack[0] . $bp->canonical_stack['component'] );
626
-
627
- if ( isset( $bp->canonical_stack['action'] ) )
628
- $url_stack[0] = trailingslashit( $url_stack[0] . $bp->canonical_stack['action'] );
629
-
630
- if ( !empty( $bp->canonical_stack['action_variables'] ) ) {
631
- foreach( (array) $bp->canonical_stack['action_variables'] as $av ) {
632
- $url_stack[0] = trailingslashit( $url_stack[0] . $av );
633
- }
634
- }
635
-
636
- // Add trailing slash
637
- $url_stack[0] = trailingslashit( $url_stack[0] );
638
-
639
- // Stash in the $bp global
640
- $bp->canonical_stack['canonical_url'] = implode( '?', $url_stack );
641
- }
642
-
643
- $canonical_url = $bp->canonical_stack['canonical_url'];
644
-
645
- if ( !$include_query_args ) {
646
- $canonical_url = array_pop( array_reverse( explode( '?', $canonical_url ) ) );
647
- }
648
-
649
- return apply_filters( 'bp_get_canonical_url', $canonical_url, $args );
650
- }
651
-
652
- /**
653
- * Returns the URL as requested on the current page load by the user agent
654
- *
655
- * @since BuddyPress (1.6)
656
- * @return string
657
- */
658
- function bp_get_requested_url() {
659
- global $bp;
660
-
661
- if ( empty( $bp->canonical_stack['requested_url'] ) ) {
662
- $bp->canonical_stack['requested_url'] = is_ssl() ? 'https://' : 'http://';
663
- $bp->canonical_stack['requested_url'] .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
664
- }
665
-
666
- return $bp->canonical_stack['requested_url'];
667
- }
668
-
669
- /**
670
- * Remove WordPress's really awesome canonical redirect if we are trying to load
671
- * BuddyPress specific content. Avoids issues with WordPress thinking that a
672
- * BuddyPress URL might actually be a blog post or page.
673
- *
674
- * This function should be considered temporary, and may be removed without
675
- * notice in future versions of BuddyPress.
676
- *
677
- * @since BuddyPress (1.6)
678
- * @uses bp_is_blog_page()
679
- */
680
- function _bp_maybe_remove_redirect_canonical() {
681
- if ( ! bp_is_blog_page() )
682
- remove_action( 'template_redirect', 'redirect_canonical' );
683
- }
684
- add_action( 'bp_init', '_bp_maybe_remove_redirect_canonical' );
685
-
686
- /**
687
- * Remove WordPress's rel=canonical HTML tag if we are trying to load BuddyPress
688
- * specific content.
689
- *
690
- * This function should be considered temporary, and may be removed without
691
- * notice in future versions of BuddyPress.
692
- *
693
- * @since 1.6
694
- */
695
- function _bp_maybe_remove_rel_canonical() {
696
- if ( ! bp_is_blog_page() && ! is_404() ) {
697
- remove_action( 'wp_head', 'rel_canonical' );
698
- add_action( 'bp_head', 'bp_rel_canonical' );
699
- }
700
- }
701
- add_action( 'wp_head', '_bp_maybe_remove_rel_canonical', 8 );
702
  ?>
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
5
+ /*
6
+ Based on contributions from: Chris Taylor - http://www.stillbreathing.co.uk/
7
+ Modified for BuddyPress by: Andy Peatling - http://apeatling.wordpress.com/
8
+ */
9
+
10
  /**
11
  * Analyzes the URI structure and breaks it down into parts for use in code.
12
+ * The idea is that BuddyPress can use complete custom friendly URI's without the
13
+ * user having to add new re-write rules.
14
+ *
15
+ * Future custom components would then be able to use their own custom URI structure.
16
  *
17
  * @package BuddyPress Core
18
+ * @since BuddyPress (r100)
19
  *
20
  * The URI's are broken down as follows:
21
  * - http:// domain.com / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ...
29
  *
30
  */
31
  function bp_core_set_uri_globals() {
32
+ global $bp, $bp_unfiltered_uri, $bp_unfiltered_uri_offset;
33
+ global $current_blog, $wpdb;
34
+
35
+ // Create global component, action, and item variables
36
+ $bp->current_component = $bp->current_action = $bp->current_item ='';
37
+ $bp->action_variables = $bp->displayed_user->id = '';
38
 
39
  // Don't catch URIs on non-root blogs unless multiblog mode is on
40
  if ( !bp_is_root_blog() && !bp_is_multiblog_mode() )
41
  return false;
42
 
 
 
 
 
43
  // Fetch all the WP page names for each component
44
  if ( empty( $bp->pages ) )
45
  $bp->pages = bp_core_get_directory_pages();
46
 
47
  // Ajax or not?
48
+ if ( strpos( $_SERVER['REQUEST_URI'], 'wp-load.php' ) )
49
  $path = bp_core_referrer();
50
  else
51
  $path = esc_url( $_SERVER['REQUEST_URI'] );
53
  // Filter the path
54
  $path = apply_filters( 'bp_uri', $path );
55
 
56
+ // Take GET variables off the URL to avoid problems,
57
+ // they are still registered in the global $_GET variable
58
+ if ( $noget = substr( $path, 0, strpos( $path, '?' ) ) )
59
+ $path = $noget;
60
 
61
+ // Fetch the current URI and explode each part separated by '/' into an array
62
  $bp_uri = explode( '/', $path );
63
 
64
  // Loop and remove empties
65
+ foreach ( (array)$bp_uri as $key => $uri_chunk )
66
+ if ( empty( $bp_uri[$key] ) ) unset( $bp_uri[$key] );
 
 
 
67
 
68
+ // Running off blog other than root
 
 
 
 
 
69
  if ( is_multisite() && !is_subdomain_install() && ( bp_is_multiblog_mode() || 1 != bp_get_root_blog_id() ) ) {
70
 
71
+ // Any subdirectory names must be removed from $bp_uri.
72
+ // This includes two cases: (1) when WP is installed in a subdirectory,
73
+ // and (2) when BP is running on secondary blog of a subdirectory
74
+ // multisite installation. Phew!
75
+ if ( $chunks = explode( '/', $current_blog->path ) ) {
 
 
76
  foreach( $chunks as $key => $chunk ) {
77
  $bkey = array_search( $chunk, $bp_uri );
78
 
79
+ if ( $bkey !== false ) {
 
80
  unset( $bp_uri[$bkey] );
81
  }
82
 
85
  }
86
  }
87
 
88
+ // Set the indexes, these are incresed by one if we are not on a VHOST install
89
+ $component_index = 0;
90
+ $action_index = $component_index + 1;
91
+
92
  // Get site path items
93
  $paths = explode( '/', bp_core_get_site_path() );
94
 
100
  if ( empty( $paths[0] ) )
101
  array_shift( $paths );
102
 
 
 
 
 
103
  // Unset URI indices if they intersect with the paths
104
  foreach ( (array) $bp_uri as $key => $uri_chunk ) {
105
+ if ( in_array( $uri_chunk, $paths ) ) {
106
  unset( $bp_uri[$key] );
107
  }
108
  }
121
  }
122
 
123
  // Keep the unfiltered URI safe
124
+ $bp_unfiltered_uri = $bp_uri;
125
 
126
  // Get slugs of pages into array
127
  foreach ( (array) $bp->pages as $page_key => $bp_page )
183
  }
184
 
185
  // URLs with BP_ENABLE_ROOT_PROFILES enabled won't be caught above
186
+ if ( empty( $matches ) && defined( 'BP_ENABLE_ROOT_PROFILES' ) && BP_ENABLE_ROOT_PROFILES ) {
 
 
 
187
 
188
  // Make sure there's a user corresponding to $bp_uri[0]
189
+ if ( !empty( $bp->pages->members ) && !empty( $bp_uri[0] ) && $root_profile = get_user_by( 'login', $bp_uri[0] ) ) {
190
 
191
  // Force BP to recognize that this is a members page
192
  $matches[] = 1;
208
  }
209
 
210
  // This is not a BuddyPress page, so just return.
211
+ if ( !isset( $matches ) )
212
  return false;
213
 
 
 
214
  // Find the offset. With $root_profile set, we fudge the offset down so later parsing works
215
  $slug = !empty ( $match ) ? explode( '/', $match->slug ) : '';
216
  $uri_offset = empty( $root_profile ) ? 0 : -1;
223
 
224
  // Global the unfiltered offset to use in bp_core_load_template().
225
  // To avoid PHP warnings in bp_core_load_template(), it must always be >= 0
226
+ $bp_unfiltered_uri_offset = $uri_offset >= 0 ? $uri_offset : 0;
227
 
228
  // We have an exact match
229
  if ( isset( $match->key ) ) {
238
  if ( !empty( $bp_uri[$uri_offset + 1] ) ) {
239
 
240
  // Switch the displayed_user based on compatbility mode
241
+ if ( bp_is_username_compatibility_mode() )
242
  $bp->displayed_user->id = (int) bp_core_get_userid( urldecode( $bp_uri[$uri_offset + 1] ) );
243
+ else
244
  $bp->displayed_user->id = (int) bp_core_get_userid_from_nicename( urldecode( $bp_uri[$uri_offset + 1] ) );
 
 
 
245
 
246
+ if ( empty( $bp->displayed_user->id ) ) {
247
  // Prevent components from loading their templates
248
  $bp->current_component = '';
249
 
253
 
254
  // If the displayed user is marked as a spammer, 404 (unless logged-
255
  // in user is a super admin)
256
+ if ( !empty( $bp->displayed_user->id ) && bp_core_is_user_spammer( $bp->displayed_user->id ) ) {
257
+ if ( is_super_admin() ) {
258
+ bp_core_add_message( __( 'This user has been marked as a spammer. Only site admins can view this profile.', 'buddypress' ), 'error' );
259
  } else {
260
  bp_do_404();
261
  return;
289
  // Set the entire URI as the action variables, we will unset the current_component and action in a second
290
  $bp->action_variables = $bp_uri;
291
 
292
+ // Remove the username from action variables if this is not a VHOST install
293
+ // @todo - move or remove this all together
294
+ if ( defined( 'VHOST' ) && ( 'no' == VHOST ) && empty( $bp->current_component ) )
295
+ array_shift( $bp_uri );
296
+
297
  // Reset the keys by merging with an empty array
298
  $bp->action_variables = array_merge( array(), $bp->action_variables );
299
  }
300
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
301
  /**
302
  * bp_core_load_template()
303
  *
313
  * @return false|int The user ID of the matched user, or false.
314
  */
315
  function bp_core_load_template( $templates ) {
316
+ global $post, $bp, $wpdb, $wp_query, $bp_unfiltered_uri, $bp_unfiltered_uri_offset;
317
 
318
+ // Determine if the root object WP page exists for this request (TODO: is there an API function for this?
319
+ if ( !empty( $bp_unfiltered_uri_offset ) && !$page_exists = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_name = %s", $bp_unfiltered_uri[$bp_unfiltered_uri_offset] ) ) )
320
+ return false;
 
 
 
 
321
 
322
  // Set the root object as the current wp_query-ied item
323
  $object_id = 0;
324
+ foreach ( (array)$bp->pages as $page ) {
325
+ if ( isset( $bp_unfiltered_uri[$bp_unfiltered_uri_offset] ) && $page->name == $bp_unfiltered_uri[$bp_unfiltered_uri_offset] ) {
326
  $object_id = $page->id;
327
  }
328
  }
334
  $post = $wp_query->queried_object;
335
  }
336
 
 
 
 
 
337
  // Fetch each template and add the php suffix
338
+ foreach ( (array)$templates as $template )
339
  $filtered_templates[] = $template . '.php';
340
 
341
  // Filter the template locations so that plugins can alter where they are located
342
+ if ( $located_template = apply_filters( 'bp_located_template', locate_template( (array) $filtered_templates, false ), $filtered_templates ) ) {
 
 
343
  // Template was located, lets set this as a valid page and not a 404.
344
  status_header( 200 );
345
+ $wp_query->is_page = true;
346
+ $wp_query->is_404 = false;
 
 
347
 
348
  load_template( apply_filters( 'bp_load_template', $located_template ) );
 
 
349
  }
350
 
351
  // Kill any other output after this.
360
  *
361
  */
362
  function bp_core_catch_profile_uri() {
363
+ global $bp;
364
+
365
+ if ( !bp_is_active( 'xprofile' ) )
366
  bp_core_load_template( apply_filters( 'bp_core_template_display_profile', 'members/single/home' ) );
 
367
  }
368
 
369
  /**
370
  * Catches invalid access to BuddyPress pages and redirects them accordingly.
371
  *
372
  * @package BuddyPress Core
373
+ * @since 1.5
374
  */
375
  function bp_core_catch_no_access() {
376
+ global $bp, $bp_no_status_set, $wp_query;
377
 
378
+ // If bp_core_redirect() and $bp_no_status_set is true,
379
+ // we are redirecting to an accessible page, so skip this check.
380
+ if ( $bp_no_status_set )
381
  return false;
382
 
383
  if ( !isset( $wp_query->queried_object ) && !bp_is_blog_page() ) {
384
  bp_do_404();
385
  }
386
  }
387
+ add_action( 'wp', 'bp_core_catch_no_access' );
388
 
389
  /**
390
  * Redirects a user to login for BP pages that require access control and adds an error message (if
392
  * If authenticated, redirects user back to requested content by default.
393
  *
394
  * @package BuddyPress Core
395
+ * @since 1.5
396
  */
397
  function bp_core_no_access( $args = '' ) {
398
+ global $bp;
 
 
 
 
399
 
400
  $defaults = array(
401
+ 'mode' => '1', // 1 = $root, 2 = wp-login.php
402
+ 'message' => __( 'You must log in to access the page you requested.', 'buddypress' ),
403
+ 'redirect' => wp_guess_url(), // the URL you get redirected to when a user successfully logs in
404
+ 'root' => $bp->root_domain // the landing page you get redirected to when a user doesn't have access
405
  );
406
 
407
  $r = wp_parse_args( $args, $defaults );
 
408
  extract( $r, EXTR_SKIP );
409
 
410
+ // Apply filters to these variables
411
+ $mode = apply_filters( 'bp_no_access_mode', $mode, $root, $redirect, $message );
412
+ $redirect = apply_filters( 'bp_no_access_redirect', $redirect, $root, $message, $mode );
413
+ $root = trailingslashit( apply_filters( 'bp_no_access_root', $root, $redirect, $message, $mode ) );
414
+ $message = apply_filters( 'bp_no_access_message', $message, $root, $redirect, $mode );
 
 
 
415
 
416
  switch ( $mode ) {
 
417
  // Option to redirect to wp-login.php
418
  // Error message is displayed with bp_core_no_access_wp_login_error()
419
  case 2 :
420
+ if ( $redirect ) {
421
+ bp_core_redirect( wp_login_url( $redirect ) . '&action=bpnoaccess' );
422
  } else {
423
  bp_core_redirect( $root );
424
  }
429
  // Error message is displayed with bp_core_add_message()
430
  case 1 :
431
  default :
432
+ if ( $redirect ) {
 
 
433
  $url = add_query_arg( 'redirect_to', urlencode( $redirect ), $root );
434
+ } else {
435
+ $url = $root;
436
+ }
437
 
438
+ if ( $message ) {
439
  bp_core_add_message( $message, 'error' );
440
  }
441
 
451
  *
452
  * @package BuddyPress Core
453
  * @global $error
454
+ * @since 1.5
455
  */
456
  function bp_core_no_access_wp_login_error() {
457
  global $error;
463
  }
464
  add_action( 'login_form_bpnoaccess', 'bp_core_no_access_wp_login_error' );
465
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
466
  ?>
bp-core/bp-core-classes.php CHANGED
@@ -109,14 +109,13 @@ class BP_Core_User {
109
  var $total_groups;
110
 
111
  /**
112
- * Profile information for the specific user.
113
  *
114
- * @since BuddyPress (1.2)
115
- * @var array
116
  */
117
- public $profile_data;
118
-
119
- /** Public Methods *******************************************************/
120
 
121
  /**
122
  * Class constructor.
@@ -125,21 +124,19 @@ class BP_Core_User {
125
  * @param boolean $populate_extras Whether to fetch extra information such as group/friendship counts or not.
126
  */
127
  function __construct( $user_id, $populate_extras = false ) {
128
- if ( !empty( $user_id ) ) {
129
  $this->id = $user_id;
130
  $this->populate();
131
 
132
- if ( !empty( $populate_extras ) ) {
133
  $this->populate_extras();
134
- }
135
  }
136
  }
137
 
138
- /** Private Methods *******************************************************/
139
-
140
  /**
141
  * Populate the instantiated class with data based on the User ID provided.
142
  *
 
143
  * @uses bp_core_get_userurl() Returns the URL with no HTML markup for a user based on their user id
144
  * @uses bp_core_get_userlink() Returns a HTML formatted link for a user with the user's full name as the link text
145
  * @uses bp_core_get_user_email() Returns the email address for the user based on user ID
@@ -148,6 +145,7 @@ class BP_Core_User {
148
  * @uses bp_profile_last_updated_date() Returns the last updated date for a user.
149
  */
150
  function populate() {
 
151
 
152
  if ( bp_is_active( 'xprofile' ) )
153
  $this->profile_data = $this->get_profile_data();
@@ -171,24 +169,26 @@ class BP_Core_User {
171
  wp_cache_set( 'bp_user_email_' . $this->id, $this->email, 'bp' );
172
  wp_cache_set( 'bp_user_url_' . $this->id, $this->user_url, 'bp' );
173
 
174
- $this->avatar = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'full', 'alt' => sprintf( __( 'Avatar of %s', 'buddypress' ), $this->fullname ) ) );
175
- $this->avatar_thumb = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb', 'alt' => sprintf( __( 'Avatar of %s', 'buddypress' ), $this->fullname ) ) );
176
- $this->avatar_mini = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb', 'alt' => sprintf( __( 'Avatar of %s', 'buddypress' ), $this->fullname ), 'width' => 30, 'height' => 30 ) );
177
  $this->last_active = bp_core_get_last_activity( bp_get_user_meta( $this->id, 'last_activity', true ), __( 'active %s', 'buddypress' ) );
178
  }
179
 
180
  /**
181
  * Populates extra fields such as group and friendship counts.
 
 
182
  */
183
  function populate_extras() {
 
184
 
185
- if ( bp_is_active( 'friends' ) ) {
186
  $this->total_friends = BP_Friends_Friendship::total_friend_count( $this->id );
187
- }
188
 
189
  if ( bp_is_active( 'groups' ) ) {
190
  $this->total_groups = BP_Groups_Member::total_group_count( $this->id );
191
- $this->total_groups = sprintf( _n( '%d group', '%d groups', $this->total_groups, 'buddypress' ), $this->total_groups );
192
  }
193
  }
194
 
@@ -196,7 +196,7 @@ class BP_Core_User {
196
  return BP_XProfile_ProfileData::get_all_for_user( $this->id );
197
  }
198
 
199
- /** Static Methods ********************************************************/
200
 
201
  function get_users( $type, $limit = 0, $page = 1, $user_id = 0, $include = false, $search_terms = false, $populate_extras = true, $exclude = false, $meta_key = false, $meta_value = false ) {
202
  global $wpdb, $bp;
@@ -205,99 +205,81 @@ class BP_Core_User {
205
 
206
  $sql['select_main'] = "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.display_name, u.user_email";
207
 
208
- if ( 'active' == $type || 'online' == $type || 'newest' == $type ) {
209
  $sql['select_active'] = ", um.meta_value as last_activity";
210
- }
211
 
212
- if ( 'popular' == $type ) {
213
  $sql['select_popular'] = ", um.meta_value as total_friend_count";
214
- }
215
 
216
- if ( 'alphabetical' == $type ) {
217
  $sql['select_alpha'] = ", pd.value as fullname";
218
- }
219
 
220
  if ( $meta_key ) {
221
  $sql['select_meta'] = ", umm.meta_key";
222
 
223
- if ( $meta_value ) {
224
  $sql['select_meta'] .= ", umm.meta_value";
225
- }
226
  }
227
 
228
- $sql['from'] = "FROM {$wpdb->users} u LEFT JOIN {$wpdb->usermeta} um ON um.user_id = u.ID";
229
 
230
  // We search against xprofile fields, so we must join the table
231
- if ( $search_terms && bp_is_active( 'xprofile' ) ) {
232
  $sql['join_profiledata_search'] = "LEFT JOIN {$bp->profile->table_name_data} spd ON u.ID = spd.user_id";
233
- }
234
 
235
  // Alphabetical sorting is done by the xprofile Full Name field
236
- if ( 'alphabetical' == $type ) {
237
  $sql['join_profiledata_alpha'] = "LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id";
238
- }
239
 
240
- if ( $meta_key ) {
241
  $sql['join_meta'] = "LEFT JOIN {$wpdb->usermeta} umm ON umm.user_id = u.ID";
242
- }
243
 
244
  $sql['where'] = 'WHERE ' . bp_core_get_status_sql( 'u.' );
245
 
246
- if ( 'active' == $type || 'online' == $type || 'newest' == $type ) {
247
  $sql['where_active'] = $wpdb->prepare( "AND um.meta_key = %s", bp_get_user_meta_key( 'last_activity' ) );
248
- }
249
 
250
- if ( 'popular' == $type ) {
251
  $sql['where_popular'] = $wpdb->prepare( "AND um.meta_key = %s", bp_get_user_meta_key( 'total_friend_count' ) );
252
- }
253
 
254
- if ( 'online' == $type ) {
255
  $sql['where_online'] = "AND DATE_ADD( um.meta_value, INTERVAL 5 MINUTE ) >= UTC_TIMESTAMP()";
256
- }
257
 
258
- if ( 'alphabetical' == $type ) {
259
  $sql['where_alpha'] = "AND pd.field_id = 1";
260
- }
261
 
262
- if ( !empty( $exclude ) ) {
263
  $sql['where_exclude'] = "AND u.ID NOT IN ({$exclude})";
 
 
 
 
 
 
 
 
 
264
  }
265
 
266
- // Passing an $include value of 0 or '0' will necessarily result in an empty set
267
- // returned. The default value of false will hit the 'else' clause.
268
- if ( 0 === $include || '0' === $include ) {
269
- $sql['where_users'] = "AND 0 = 1";
270
- } else {
271
- if ( !empty( $include ) ) {
272
- if ( is_array( $include ) ) {
273
- $uids = $wpdb->escape( implode( ',', (array) $include ) );
274
- } else {
275
- $uids = $wpdb->escape( $include );
276
- }
277
 
278
- if ( !empty( $uids ) ) {
279
- $sql['where_users'] = "AND u.ID IN ({$uids})";
280
- }
281
- } elseif ( !empty( $user_id ) && bp_is_active( 'friends' ) ) {
282
- $friend_ids = friends_get_friend_user_ids( $user_id );
283
- $friend_ids = $wpdb->escape( implode( ',', (array) $friend_ids ) );
284
 
285
- if ( !empty( $friend_ids ) ) {
286
- $sql['where_friends'] = "AND u.ID IN ({$friend_ids})";
 
287
 
288
- // User has no friends, return false since there will be no users to fetch.
289
- } else {
290
- return false;
291
- }
292
- }
293
  }
294
 
295
- if ( !empty( $search_terms ) && bp_is_active( 'xprofile' ) ) {
296
  $search_terms = like_escape( $wpdb->escape( $search_terms ) );
297
  $sql['where_searchterms'] = "AND spd.value LIKE '%%$search_terms%%'";
298
  }
299
 
300
- if ( !empty( $meta_key ) ) {
301
  $sql['where_meta'] = $wpdb->prepare( " AND umm.meta_key = %s", $meta_key );
302
 
303
  // If a meta value is provided, match it
@@ -324,37 +306,32 @@ class BP_Core_User {
324
  break;
325
  }
326
 
327
- if ( !empty( $limit ) && !empty( $page ) ) {
328
  $sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
329
- }
330
 
331
  // Get paginated results
332
- $paged_users_sql = apply_filters( 'bp_core_get_paged_users_sql', join( ' ', (array) $sql ), $sql );
333
  $paged_users = $wpdb->get_results( $paged_users_sql );
334
 
335
  // Re-jig the SQL so we can get the total user count
336
  unset( $sql['select_main'] );
337
 
338
- if ( !empty( $sql['select_active'] ) ) {
339
  unset( $sql['select_active'] );
340
- }
341
 
342
- if ( !empty( $sql['select_popular'] ) ) {
343
  unset( $sql['select_popular'] );
344
- }
345
 
346
- if ( !empty( $sql['select_alpha'] ) ) {
347
  unset( $sql['select_alpha'] );
348
- }
349
 
350
- if ( !empty( $sql['pagination'] ) ) {
351
  unset( $sql['pagination'] );
352
- }
353
 
354
  array_unshift( $sql, "SELECT COUNT(DISTINCT u.ID)" );
355
 
356
  // Get total user results
357
- $total_users_sql = apply_filters( 'bp_core_get_total_users_sql', join( ' ', (array) $sql ), $sql );
358
  $total_users = $wpdb->get_var( $total_users_sql );
359
 
360
  /***
@@ -364,11 +341,10 @@ class BP_Core_User {
364
  if ( !empty( $populate_extras ) ) {
365
  $user_ids = array();
366
 
367
- foreach ( (array) $paged_users as $user ) {
368
  $user_ids[] = $user->id;
369
- }
370
 
371
- $user_ids = $wpdb->escape( join( ',', (array) $user_ids ) );
372
 
373
  // Add additional data to the returned results
374
  $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids, $type );
@@ -381,7 +357,7 @@ class BP_Core_User {
381
  /**
382
  * Fetches the user details for all the users who username starts with the letter given.
383
  *
384
- * @global BuddyPress $bp The one true BuddyPress instance
385
  * @global wpdb $wpdb WordPress database object
386
  * @param string $letter The letter the users names are to start with.
387
  * @param integer $limit The number of users we wish to retrive.
@@ -395,9 +371,8 @@ class BP_Core_User {
395
  global $bp, $wpdb;
396
 
397
  $pag_sql = '';
398
- if ( $limit && $page ) {
399
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
400
- }
401
 
402
  // Multibyte compliance
403
  if ( function_exists( 'mb_strlen' ) ) {
@@ -422,22 +397,18 @@ class BP_Core_User {
422
  $paged_users = $wpdb->get_results( $paged_users_sql );
423
 
424
  /***
425
- * Lets fetch some other useful data in a separate queries, this will be
426
- * faster than querying the data for every user in a list. We can't add
427
- * these to the main query above since only users who have this
428
- * information will be returned (since the much of the data is in
429
- * usermeta and won't support any type of directional join)
430
  */
431
  $user_ids = array();
432
- foreach ( (array) $paged_users as $user )
433
  $user_ids[] = $user->id;
434
 
435
- $user_ids = $wpdb->escape( join( ',', (array) $user_ids ) );
436
 
437
- // Add additional data to the returned results
438
- if ( $populate_extras ) {
439
  $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids );
440
- }
441
 
442
  return array( 'users' => $paged_users, 'total' => $total_users );
443
  }
@@ -445,6 +416,7 @@ class BP_Core_User {
445
  /**
446
  * Get details of specific users from the database
447
  *
 
448
  * @global wpdb $wpdb WordPress database object
449
  * @param array $user_ids The user IDs of the users who we wish to fetch information on.
450
  * @param integer $limit The limit of results we want.
@@ -454,13 +426,12 @@ class BP_Core_User {
454
  * @static
455
  */
456
  function get_specific_users( $user_ids, $limit = null, $page = 1, $populate_extras = true ) {
457
- global $wpdb;
458
 
459
  $pag_sql = '';
460
  if ( $limit && $page )
461
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
462
 
463
- // @todo remove? $user_sql is not used here
464
  $user_sql = " AND user_id IN ( " . $wpdb->escape( $user_ids ) . " ) ";
465
  $status_sql = bp_core_get_status_sql();
466
 
@@ -471,17 +442,13 @@ class BP_Core_User {
471
  $paged_users = $wpdb->get_results( $paged_users_sql );
472
 
473
  /***
474
- * Lets fetch some other useful data in a separate queries, this will be
475
- * faster than querying the data for every user in a list. We can't add
476
- * these to the main query above since only users who have this
477
- * information will be returned (since the much of the data is in
478
- * usermeta and won't support any type of directional join)
479
  */
480
 
481
- // Add additional data to the returned results
482
- if ( !empty( $populate_extras ) ) {
483
  $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids );
484
- }
485
 
486
  return array( 'users' => $paged_users, 'total' => $total_users );
487
  }
@@ -489,7 +456,7 @@ class BP_Core_User {
489
  /**
490
  * Find users who match on the value of an xprofile data.
491
  *
492
- * @global BuddyPress $bp The one true BuddyPress instance
493
  * @global wpdb $wpdb WordPress database object
494
  * @param string $search_terms The terms to search the profile table value column for.
495
  * @param integer $limit The limit of results we want.
@@ -501,8 +468,7 @@ class BP_Core_User {
501
  function search_users( $search_terms, $limit = null, $page = 1, $populate_extras = true ) {
502
  global $bp, $wpdb;
503
 
504
- $user_ids = array();
505
- $pag_sql = $limit && $page ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * intval( $limit ) ), intval( $limit ) ) : '';
506
 
507
  $search_terms = like_escape( $wpdb->escape( $search_terms ) );
508
  $status_sql = bp_core_get_status_sql( 'u.' );
@@ -517,10 +483,10 @@ class BP_Core_User {
517
  * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
518
  * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join)
519
  */
520
- foreach ( (array) $paged_users as $user )
521
  $user_ids[] = $user->id;
522
 
523
- $user_ids = $wpdb->escape( join( ',', (array) $user_ids ) );
524
 
525
  // Add additional data to the returned results
526
  if ( $populate_extras )
@@ -534,7 +500,7 @@ class BP_Core_User {
534
  *
535
  * Accepts multiple user IDs to fetch data for.
536
  *
537
- * @global BuddyPress $bp The one true BuddyPress instance
538
  * @global wpdb $wpdb WordPress database object
539
  * @param array $paged_users an array of stdClass containing the users
540
  * @param string $user_ids the user ids to select information about
@@ -552,7 +518,7 @@ class BP_Core_User {
552
  if ( bp_is_active( 'xprofile' ) && 'alphabetical' != $type ) {
553
  $names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id as id, pd.value as fullname FROM {$bp->profile->table_name_fields} pf, {$bp->profile->table_name_data} pd WHERE pf.id = pd.field_id AND pf.name = %s AND pd.user_id IN ( {$user_ids} )", bp_xprofile_fullname_field_name() ) );
554
  for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
555
- foreach ( (array) $names as $name ) {
556
  if ( $name->id == $paged_users[$i]->id )
557
  $paged_users[$i]->fullname = $name->fullname;
558
  }
@@ -563,18 +529,18 @@ class BP_Core_User {
563
  if ( 'popular' != $type ) {
564
  $friend_count = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as total_friend_count FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'total_friend_count' ) ) );
565
  for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
566
- foreach ( (array) $friend_count as $fcount ) {
567
  if ( $fcount->id == $paged_users[$i]->id )
568
- $paged_users[$i]->total_friend_count = (int) $fcount->total_friend_count;
569
  }
570
  }
571
  }
572
 
573
  // Fetch whether or not the user is a friend
574
  if ( bp_is_active( 'friends' ) ) {
575
- $friend_status = $wpdb->get_results( $wpdb->prepare( "SELECT initiator_user_id, friend_user_id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id IN ( {$user_ids} ) ) OR (initiator_user_id IN ( {$user_ids} ) AND friend_user_id = %d )", bp_loggedin_user_id(), bp_loggedin_user_id() ) );
576
  for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
577
- foreach ( (array) $friend_status as $status ) {
578
  if ( $status->initiator_user_id == $paged_users[$i]->id || $status->friend_user_id == $paged_users[$i]->id )
579
  $paged_users[$i]->is_friend = $status->is_confirmed;
580
  }
@@ -584,7 +550,7 @@ class BP_Core_User {
584
  if ( 'active' != $type ) {
585
  $user_activity = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as last_activity FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'last_activity' ) ) );
586
  for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
587
- foreach ( (array) $user_activity as $activity ) {
588
  if ( $activity->id == $paged_users[$i]->id )
589
  $paged_users[$i]->last_activity = $activity->last_activity;
590
  }
@@ -595,7 +561,7 @@ class BP_Core_User {
595
  if ( 'active' != $type ) {
596
  $user_activity = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as last_activity FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'last_activity' ) ) );
597
  for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
598
- foreach ( (array) $user_activity as $activity ) {
599
  if ( $activity->id == $paged_users[$i]->id )
600
  $paged_users[$i]->last_activity = $activity->last_activity;
601
  }
@@ -605,7 +571,7 @@ class BP_Core_User {
605
  // Fetch the user's latest update
606
  $user_update = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as latest_update FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'bp_latest_update' ) ) );
607
  for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
608
- foreach ( (array) $user_update as $update ) {
609
  if ( $update->id == $paged_users[$i]->id )
610
  $paged_users[$i]->latest_update = $update->latest_update;
611
  }
@@ -698,7 +664,15 @@ class BP_Core_Notification {
698
  */
699
  var $is_new;
700
 
701
- /** Public Methods ********************************************************/
 
 
 
 
 
 
 
 
702
 
703
  /**
704
  * Constructor
@@ -706,16 +680,36 @@ class BP_Core_Notification {
706
  * @param integer $id
707
  */
708
  function __construct( $id = 0 ) {
709
- if ( !empty( $id ) ) {
710
  $this->id = $id;
711
  $this->populate();
712
  }
713
  }
714
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
715
  /**
716
  * Update or insert notification details into the database.
717
  *
718
- * @global BuddyPress $bp The one true BuddyPress instance
719
  * @global wpdb $wpdb WordPress database object
720
  * @return bool Success or failure
721
  */
@@ -723,45 +717,21 @@ class BP_Core_Notification {
723
  global $bp, $wpdb;
724
 
725
  // Update
726
- if ( !empty( $this->id ) ) {
727
  $sql = $wpdb->prepare( "UPDATE {$bp->core->table_name_notifications} SET item_id = %d, secondary_item_id = %d, user_id = %d, component_name = %s, component_action = %d, date_notified = %s, is_new = %d ) WHERE id = %d", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new, $this->id );
728
 
729
  // Save
730
- } else {
731
  $sql = $wpdb->prepare( "INSERT INTO {$bp->core->table_name_notifications} ( item_id, secondary_item_id, user_id, component_name, component_action, date_notified, is_new ) VALUES ( %d, %d, %d, %s, %s, %s, %d )", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new );
732
- }
733
 
734
  if ( !$result = $wpdb->query( $sql ) )
735
  return false;
736
 
737
  $this->id = $wpdb->insert_id;
738
-
739
  return true;
740
  }
741
 
742
- /** Private Methods *******************************************************/
743
-
744
- /**
745
- * Fetches the notification data from the database.
746
- *
747
- * @global BuddyPress $bp The one true BuddyPress instance
748
- * @global wpdb $wpdb WordPress database object
749
- */
750
- function populate() {
751
- global $bp, $wpdb;
752
-
753
- if ( $notification = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE id = %d", $this->id ) ) ) {
754
- $this->item_id = $notification->item_id;
755
- $this->secondary_item_id = $notification->secondary_item_id;
756
- $this->user_id = $notification->user_id;
757
- $this->component_name = $notification->component_name;
758
- $this->component_action = $notification->component_action;
759
- $this->date_notified = $notification->date_notified;
760
- $this->is_new = $notification->is_new;
761
- }
762
- }
763
-
764
- /** Static Methods ********************************************************/
765
 
766
  function check_access( $user_id, $notification_id ) {
767
  global $wpdb, $bp;
@@ -772,25 +742,22 @@ class BP_Core_Notification {
772
  /**
773
  * Fetches all the notifications in the database for a specific user.
774
  *
775
- * @global BuddyPress $bp The one true BuddyPress instance
776
  * @global wpdb $wpdb WordPress database object
777
  * @param integer $user_id User ID
778
- * @param str $status 'is_new' or 'all'
779
  * @return array Associative array
780
  * @static
781
  */
782
- function get_all_for_user( $user_id, $status = 'is_new' ) {
783
  global $bp, $wpdb;
784
 
785
- $is_new = 'is_new' == $status ? ' AND is_new = 1 ' : '';
786
-
787
- return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE user_id = %d {$is_new}", $user_id ) );
788
  }
789
 
790
  /**
791
  * Delete all the notifications for a user based on the component name and action.
792
  *
793
- * @global BuddyPress $bp The one true BuddyPress instance
794
  * @global wpdb $wpdb WordPress database object
795
  * @param integer $user_id
796
  * @param string $component_name
@@ -806,7 +773,7 @@ class BP_Core_Notification {
806
  /**
807
  * Delete all the notifications that have a specific item id, component name and action.
808
  *
809
- * @global BuddyPress $bp The one true BuddyPress instance
810
  * @global wpdb $wpdb WordPress database object
811
  * @param integer $user_id The ID of the user who the notifications are for.
812
  * @param integer $item_id The item ID of the notifications we wish to delete.
@@ -826,7 +793,7 @@ class BP_Core_Notification {
826
  /**
827
  * Deletes all the notifications sent by a specific user, by component and action.
828
  *
829
- * @global BuddyPress $bp The one true BuddyPress instance
830
  * @global wpdb $wpdb WordPress database object
831
  * @param integer $user_id The ID of the user whose sent notifications we wish to delete.
832
  * @param string $component_name The name of the component the notification was sent from.
@@ -842,7 +809,7 @@ class BP_Core_Notification {
842
  /**
843
  * Deletes all the notifications for all users by item id, and optional secondary item id, and component name and action.
844
  *
845
- * @global BuddyPress $bp The one true BuddyPress instance
846
  * @global wpdb $wpdb WordPress database object
847
  * @param string $item_id The item id that they notifications are to be for.
848
  * @param string $component_name The component that the notifications are to be from.
@@ -1002,6 +969,10 @@ class BP_Button {
1002
  * @param array $args
1003
  * @return bool False if not allowed
1004
  */
 
 
 
 
1005
  function __construct( $args = '' ) {
1006
 
1007
  // Default arguments
@@ -1053,16 +1024,14 @@ class BP_Button {
1053
  if ( false !== $this->wrapper ) {
1054
 
1055
  // Wrapper ID
1056
- if ( !empty( $wrapper_id ) ) {
1057
  $this->wrapper_id = ' id="' . $wrapper_id . '"';
1058
- }
1059
 
1060
  // Wrapper class
1061
- if ( !empty( $wrapper_class ) ) {
1062
  $this->wrapper_class = ' class="generic-button ' . $wrapper_class . '"';
1063
- } else {
1064
  $this->wrapper_class = ' class="generic-button"';
1065
- }
1066
 
1067
  // Set before and after
1068
  $before = '<' . $wrapper . $this->wrapper_class . $this->wrapper_id . '>';
@@ -1127,11 +1096,10 @@ class BP_Button {
1127
  * Extends WP_Embed class for use with BuddyPress.
1128
  *
1129
  * @package BuddyPress Core
1130
- * @since BuddyPress (1.5)
1131
  * @see WP_Embed
1132
  */
1133
  class BP_Embed extends WP_Embed {
1134
-
1135
  /**
1136
  * Constructor
1137
  *
@@ -1202,9 +1170,8 @@ class BP_Embed extends WP_Embed {
1202
  foreach ( $this->handlers as $priority => $handlers ) {
1203
  foreach ( $handlers as $hid => $handler ) {
1204
  if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) {
1205
- if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) ) {
1206
  return apply_filters( 'embed_handler_html', $return, $url, $attr );
1207
- }
1208
  }
1209
  }
1210
  }
@@ -1222,7 +1189,7 @@ class BP_Embed extends WP_Embed {
1222
  // If oEmbed discovery is true, skip oEmbed provider check
1223
  $is_oembed_link = false;
1224
  if ( !$attr['discover'] ) {
1225
- foreach ( (array) $oembed_obj->providers as $provider_matchmask => $provider ) {
1226
  $regex = ( $is_regex = $provider[1] ) ? $provider_matchmask : '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $provider_matchmask ), '#' ) ) . '#i';
1227
 
1228
  if ( preg_match( $regex, $url ) )
@@ -1284,5 +1251,4 @@ class BP_Embed extends WP_Embed {
1284
  return $this->maybe_make_link( $url );
1285
  }
1286
  }
1287
-
1288
- ?>
109
  var $total_groups;
110
 
111
  /**
112
+ * PHP4 constructor.
113
  *
114
+ * @see BP_Core_User::__construct()
 
115
  */
116
+ function bp_core_user( $user_id, $populate_extras = false ) {
117
+ $this->__construct( $user_id, $populate_extras );
118
+ }
119
 
120
  /**
121
  * Class constructor.
124
  * @param boolean $populate_extras Whether to fetch extra information such as group/friendship counts or not.
125
  */
126
  function __construct( $user_id, $populate_extras = false ) {
127
+ if ( $user_id ) {
128
  $this->id = $user_id;
129
  $this->populate();
130
 
131
+ if ( $populate_extras )
132
  $this->populate_extras();
 
133
  }
134
  }
135
 
 
 
136
  /**
137
  * Populate the instantiated class with data based on the User ID provided.
138
  *
139
+ * @global object $bp Global BuddyPress settings object
140
  * @uses bp_core_get_userurl() Returns the URL with no HTML markup for a user based on their user id
141
  * @uses bp_core_get_userlink() Returns a HTML formatted link for a user with the user's full name as the link text
142
  * @uses bp_core_get_user_email() Returns the email address for the user based on user ID
145
  * @uses bp_profile_last_updated_date() Returns the last updated date for a user.
146
  */
147
  function populate() {
148
+ global $bp;
149
 
150
  if ( bp_is_active( 'xprofile' ) )
151
  $this->profile_data = $this->get_profile_data();
169
  wp_cache_set( 'bp_user_email_' . $this->id, $this->email, 'bp' );
170
  wp_cache_set( 'bp_user_url_' . $this->id, $this->user_url, 'bp' );
171
 
172
+ $this->avatar = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'full' ) );
173
+ $this->avatar_thumb = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb' ) );
174
+ $this->avatar_mini = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb', 'width' => 30, 'height' => 30 ) );
175
  $this->last_active = bp_core_get_last_activity( bp_get_user_meta( $this->id, 'last_activity', true ), __( 'active %s', 'buddypress' ) );
176
  }
177
 
178
  /**
179
  * Populates extra fields such as group and friendship counts.
180
+ *
181
+ * @global object $bp Global BuddyPress settings object
182
  */
183
  function populate_extras() {
184
+ global $bp;
185
 
186
+ if ( bp_is_active( 'friends' ) )
187
  $this->total_friends = BP_Friends_Friendship::total_friend_count( $this->id );
 
188
 
189
  if ( bp_is_active( 'groups' ) ) {
190
  $this->total_groups = BP_Groups_Member::total_group_count( $this->id );
191
+ $this->total_groups = sprintf( _n( '%d group', '%d groups', $this->total_groups ), $this->total_groups );
192
  }
193
  }
194
 
196
  return BP_XProfile_ProfileData::get_all_for_user( $this->id );
197
  }
198
 
199
+ /** Static Functions ******************************************************/
200
 
201
  function get_users( $type, $limit = 0, $page = 1, $user_id = 0, $include = false, $search_terms = false, $populate_extras = true, $exclude = false, $meta_key = false, $meta_value = false ) {
202
  global $wpdb, $bp;
205
 
206
  $sql['select_main'] = "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.display_name, u.user_email";
207
 
208
+ if ( 'active' == $type || 'online' == $type || 'newest' == $type )
209
  $sql['select_active'] = ", um.meta_value as last_activity";
 
210
 
211
+ if ( 'popular' == $type )
212
  $sql['select_popular'] = ", um.meta_value as total_friend_count";
 
213
 
214
+ if ( 'alphabetical' == $type )
215
  $sql['select_alpha'] = ", pd.value as fullname";
 
216
 
217
  if ( $meta_key ) {
218
  $sql['select_meta'] = ", umm.meta_key";
219
 
220
+ if ( $meta_value )
221
  $sql['select_meta'] .= ", umm.meta_value";
 
222
  }
223
 
224
+ $sql['from'] = "FROM $wpdb->users u LEFT JOIN $wpdb->usermeta um ON um.user_id = u.ID";
225
 
226
  // We search against xprofile fields, so we must join the table
227
+ if ( $search_terms && bp_is_active( 'xprofile' ) )
228
  $sql['join_profiledata_search'] = "LEFT JOIN {$bp->profile->table_name_data} spd ON u.ID = spd.user_id";
 
229
 
230
  // Alphabetical sorting is done by the xprofile Full Name field
231
+ if ( 'alphabetical' == $type )
232
  $sql['join_profiledata_alpha'] = "LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id";
 
233
 
234
+ if ( $meta_key )
235
  $sql['join_meta'] = "LEFT JOIN {$wpdb->usermeta} umm ON umm.user_id = u.ID";
 
236
 
237
  $sql['where'] = 'WHERE ' . bp_core_get_status_sql( 'u.' );
238
 
239
+ if ( 'active' == $type || 'online' == $type || 'newest' == $type )
240
  $sql['where_active'] = $wpdb->prepare( "AND um.meta_key = %s", bp_get_user_meta_key( 'last_activity' ) );
 
241
 
242
+ if ( 'popular' == $type )
243
  $sql['where_popular'] = $wpdb->prepare( "AND um.meta_key = %s", bp_get_user_meta_key( 'total_friend_count' ) );
 
244
 
245
+ if ( 'online' == $type )
246
  $sql['where_online'] = "AND DATE_ADD( um.meta_value, INTERVAL 5 MINUTE ) >= UTC_TIMESTAMP()";
 
247
 
248
+ if ( 'alphabetical' == $type )
249
  $sql['where_alpha'] = "AND pd.field_id = 1";
 
250
 
251
+ if ( !empty( $exclude ) )
252
  $sql['where_exclude'] = "AND u.ID NOT IN ({$exclude})";
253
+
254
+ if ( $include ) {
255
+ if ( is_array( $include ) )
256
+ $uids = $wpdb->escape( implode( ',', (array)$include ) );
257
+ else
258
+ $uids = $wpdb->escape( $include );
259
+
260
+ if ( !empty( $uids ) )
261
+ $sql['where_users'] = "AND u.ID IN ({$uids})";
262
  }
263
 
264
+ else if ( $user_id && bp_is_active( 'friends' ) ) {
265
+ $friend_ids = friends_get_friend_user_ids( $user_id );
266
+ $friend_ids = $wpdb->escape( implode( ',', (array)$friend_ids ) );
 
 
 
 
 
 
 
 
267
 
268
+ if ( !empty( $friend_ids ) )
269
+ $sql['where_friends'] = "AND u.ID IN ({$friend_ids})";
 
 
 
 
270
 
271
+ // User has no friends, return false since there will be no users to fetch.
272
+ else
273
+ return false;
274
 
 
 
 
 
 
275
  }
276
 
277
+ if ( $search_terms && bp_is_active( 'xprofile' ) ) {
278
  $search_terms = like_escape( $wpdb->escape( $search_terms ) );
279
  $sql['where_searchterms'] = "AND spd.value LIKE '%%$search_terms%%'";
280
  }
281
 
282
+ if ( $meta_key ) {
283
  $sql['where_meta'] = $wpdb->prepare( " AND umm.meta_key = %s", $meta_key );
284
 
285
  // If a meta value is provided, match it
306
  break;
307
  }
308
 
309
+ if ( $limit && $page )
310
  $sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
 
311
 
312
  // Get paginated results
313
+ $paged_users_sql = apply_filters( 'bp_core_get_paged_users_sql', join( ' ', (array)$sql ), $sql );
314
  $paged_users = $wpdb->get_results( $paged_users_sql );
315
 
316
  // Re-jig the SQL so we can get the total user count
317
  unset( $sql['select_main'] );
318
 
319
+ if ( !empty( $sql['select_active'] ) )
320
  unset( $sql['select_active'] );
 
321
 
322
+ if ( !empty( $sql['select_popular'] ) )
323
  unset( $sql['select_popular'] );
 
324
 
325
+ if ( !empty( $sql['select_alpha'] ) )
326
  unset( $sql['select_alpha'] );
 
327
 
328
+ if ( !empty( $sql['pagination'] ) )
329
  unset( $sql['pagination'] );
 
330
 
331
  array_unshift( $sql, "SELECT COUNT(DISTINCT u.ID)" );
332
 
333
  // Get total user results
334
+ $total_users_sql = apply_filters( 'bp_core_get_total_users_sql', join( ' ', (array)$sql ), $sql );
335
  $total_users = $wpdb->get_var( $total_users_sql );
336
 
337
  /***
341
  if ( !empty( $populate_extras ) ) {
342
  $user_ids = array();
343
 
344
+ foreach ( (array)$paged_users as $user )
345
  $user_ids[] = $user->id;
 
346
 
347
+ $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
348
 
349
  // Add additional data to the returned results
350
  $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids, $type );
357
  /**
358
  * Fetches the user details for all the users who username starts with the letter given.
359
  *
360
+ * @global object $bp Global BuddyPress settings object
361
  * @global wpdb $wpdb WordPress database object
362
  * @param string $letter The letter the users names are to start with.
363
  * @param integer $limit The number of users we wish to retrive.
371
  global $bp, $wpdb;
372
 
373
  $pag_sql = '';
374
+ if ( $limit && $page )
375
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
 
376
 
377
  // Multibyte compliance
378
  if ( function_exists( 'mb_strlen' ) ) {
397
  $paged_users = $wpdb->get_results( $paged_users_sql );
398
 
399
  /***
400
+ * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
401
+ * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join)
 
 
 
402
  */
403
  $user_ids = array();
404
+ foreach ( (array)$paged_users as $user )
405
  $user_ids[] = $user->id;
406
 
407
+ $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
408
 
409
+ /* Add additional data to the returned results */
410
+ if ( $populate_extras )
411
  $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids );
 
412
 
413
  return array( 'users' => $paged_users, 'total' => $total_users );
414
  }
416
  /**
417
  * Get details of specific users from the database
418
  *
419
+ * @global object $bp Global BuddyPress settings object
420
  * @global wpdb $wpdb WordPress database object
421
  * @param array $user_ids The user IDs of the users who we wish to fetch information on.
422
  * @param integer $limit The limit of results we want.
426
  * @static
427
  */
428
  function get_specific_users( $user_ids, $limit = null, $page = 1, $populate_extras = true ) {
429
+ global $bp, $wpdb;
430
 
431
  $pag_sql = '';
432
  if ( $limit && $page )
433
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
434
 
 
435
  $user_sql = " AND user_id IN ( " . $wpdb->escape( $user_ids ) . " ) ";
436
  $status_sql = bp_core_get_status_sql();
437
 
442
  $paged_users = $wpdb->get_results( $paged_users_sql );
443
 
444
  /***
445
+ * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
446
+ * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join)
 
 
 
447
  */
448
 
449
+ /* Add additional data to the returned results */
450
+ if ( $populate_extras )
451
  $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids );
 
452
 
453
  return array( 'users' => $paged_users, 'total' => $total_users );
454
  }
456
  /**
457
  * Find users who match on the value of an xprofile data.
458
  *
459
+ * @global object $bp Global BuddyPress settings object
460
  * @global wpdb $wpdb WordPress database object
461
  * @param string $search_terms The terms to search the profile table value column for.
462
  * @param integer $limit The limit of results we want.
468
  function search_users( $search_terms, $limit = null, $page = 1, $populate_extras = true ) {
469
  global $bp, $wpdb;
470
 
471
+ $pag_sql = $limit && $page ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * intval( $limit ) ), intval( $limit ) ) : '';
 
472
 
473
  $search_terms = like_escape( $wpdb->escape( $search_terms ) );
474
  $status_sql = bp_core_get_status_sql( 'u.' );
483
  * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
484
  * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join)
485
  */
486
+ foreach ( (array)$paged_users as $user )
487
  $user_ids[] = $user->id;
488
 
489
+ $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
490
 
491
  // Add additional data to the returned results
492
  if ( $populate_extras )
500
  *
501
  * Accepts multiple user IDs to fetch data for.
502
  *
503
+ * @global object $bp Global BuddyPress settings object
504
  * @global wpdb $wpdb WordPress database object
505
  * @param array $paged_users an array of stdClass containing the users
506
  * @param string $user_ids the user ids to select information about
518
  if ( bp_is_active( 'xprofile' ) && 'alphabetical' != $type ) {
519
  $names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id as id, pd.value as fullname FROM {$bp->profile->table_name_fields} pf, {$bp->profile->table_name_data} pd WHERE pf.id = pd.field_id AND pf.name = %s AND pd.user_id IN ( {$user_ids} )", bp_xprofile_fullname_field_name() ) );
520
  for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
521
+ foreach ( (array)$names as $name ) {
522
  if ( $name->id == $paged_users[$i]->id )
523
  $paged_users[$i]->fullname = $name->fullname;
524
  }
529
  if ( 'popular' != $type ) {
530
  $friend_count = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as total_friend_count FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'total_friend_count' ) ) );
531
  for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
532
+ foreach ( (array)$friend_count as $fcount ) {
533
  if ( $fcount->id == $paged_users[$i]->id )
534
+ $paged_users[$i]->total_friend_count = (int)$fcount->total_friend_count;
535
  }
536
  }
537
  }
538
 
539
  // Fetch whether or not the user is a friend
540
  if ( bp_is_active( 'friends' ) ) {
541
+ $friend_status = $wpdb->get_results( $wpdb->prepare( "SELECT initiator_user_id, friend_user_id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id IN ( {$user_ids} ) ) OR (initiator_user_id IN ( {$user_ids} ) AND friend_user_id = %d )", $bp->loggedin_user->id, $bp->loggedin_user->id ) );
542
  for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
543
+ foreach ( (array)$friend_status as $status ) {
544
  if ( $status->initiator_user_id == $paged_users[$i]->id || $status->friend_user_id == $paged_users[$i]->id )
545
  $paged_users[$i]->is_friend = $status->is_confirmed;
546
  }
550
  if ( 'active' != $type ) {
551
  $user_activity = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as last_activity FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'last_activity' ) ) );
552
  for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
553
+ foreach ( (array)$user_activity as $activity ) {
554
  if ( $activity->id == $paged_users[$i]->id )
555
  $paged_users[$i]->last_activity = $activity->last_activity;
556
  }
561
  if ( 'active' != $type ) {
562
  $user_activity = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as last_activity FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'last_activity' ) ) );
563
  for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
564
+ foreach ( (array)$user_activity as $activity ) {
565
  if ( $activity->id == $paged_users[$i]->id )
566
  $paged_users[$i]->last_activity = $activity->last_activity;
567
  }
571
  // Fetch the user's latest update
572
  $user_update = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as latest_update FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'bp_latest_update' ) ) );
573
  for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
574
+ foreach ( (array)$user_update as $update ) {
575
  if ( $update->id == $paged_users[$i]->id )
576
  $paged_users[$i]->latest_update = $update->latest_update;
577
  }
664
  */
665
  var $is_new;
666
 
667
+
668
+ /**
669
+ * PHP4 constructor
670
+ *
671
+ * @param integer $id
672
+ */
673
+ function bp_core_notification( $id = 0 ) {
674
+ $this->__construct($id);
675
+ }
676
 
677
  /**
678
  * Constructor
680
  * @param integer $id
681
  */
682
  function __construct( $id = 0 ) {
683
+ if ( $id ) {
684
  $this->id = $id;
685
  $this->populate();
686
  }
687
  }
688
 
689
+ /**
690
+ * Fetches the notification data from the database.
691
+ *
692
+ * @global object $bp Global BuddyPress settings object
693
+ * @global wpdb $wpdb WordPress database object
694
+ */
695
+ function populate() {
696
+ global $bp, $wpdb;
697
+
698
+ if ( $notification = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE id = %d", $this->id ) ) ) {
699
+ $this->item_id = $notification->item_id;
700
+ $this->secondary_item_id = $notification->secondary_item_id;
701
+ $this->user_id = $notification->user_id;
702
+ $this->component_name = $notification->component_name;
703
+ $this->component_action = $notification->component_action;
704
+ $this->date_notified = $notification->date_notified;
705
+ $this->is_new = $notification->is_new;
706
+ }
707
+ }
708
+
709
  /**
710
  * Update or insert notification details into the database.
711
  *
712
+ * @global object $bp Global BuddyPress settings object
713
  * @global wpdb $wpdb WordPress database object
714
  * @return bool Success or failure
715
  */
717
  global $bp, $wpdb;
718
 
719
  // Update
720
+ if ( $this->id )
721
  $sql = $wpdb->prepare( "UPDATE {$bp->core->table_name_notifications} SET item_id = %d, secondary_item_id = %d, user_id = %d, component_name = %s, component_action = %d, date_notified = %s, is_new = %d ) WHERE id = %d", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new, $this->id );
722
 
723
  // Save
724
+ else
725
  $sql = $wpdb->prepare( "INSERT INTO {$bp->core->table_name_notifications} ( item_id, secondary_item_id, user_id, component_name, component_action, date_notified, is_new ) VALUES ( %d, %d, %d, %s, %s, %s, %d )", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new );
 
726
 
727
  if ( !$result = $wpdb->query( $sql ) )
728
  return false;
729
 
730
  $this->id = $wpdb->insert_id;
 
731
  return true;
732
  }
733
 
734
+ /** Static functions ******************************************************/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
735
 
736
  function check_access( $user_id, $notification_id ) {
737
  global $wpdb, $bp;
742
  /**
743
  * Fetches all the notifications in the database for a specific user.
744
  *
745
+ * @global object $bp Global BuddyPress settings object
746
  * @global wpdb $wpdb WordPress database object
747
  * @param integer $user_id User ID
 
748
  * @return array Associative array
749
  * @static
750
  */
751
+ function get_all_for_user( $user_id ) {
752
  global $bp, $wpdb;
753
 
754
+ return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND is_new = 1", $user_id ) );
 
 
755
  }
756
 
757
  /**
758
  * Delete all the notifications for a user based on the component name and action.
759
  *
760
+ * @global object $bp Global BuddyPress settings object
761
  * @global wpdb $wpdb WordPress database object
762
  * @param integer $user_id
763
  * @param string $component_name
773
  /**
774
  * Delete all the notifications that have a specific item id, component name and action.
775
  *
776
+ * @global object $bp Global BuddyPress settings object
777
  * @global wpdb $wpdb WordPress database object
778
  * @param integer $user_id The ID of the user who the notifications are for.
779
  * @param integer $item_id The item ID of the notifications we wish to delete.
793
  /**
794
  * Deletes all the notifications sent by a specific user, by component and action.
795
  *
796
+ * @global object $bp Global BuddyPress settings object
797
  * @global wpdb $wpdb WordPress database object
798
  * @param integer $user_id The ID of the user whose sent notifications we wish to delete.
799
  * @param string $component_name The name of the component the notification was sent from.
809
  /**
810
  * Deletes all the notifications for all users by item id, and optional secondary item id, and component name and action.
811
  *
812
+ * @global object $bp Global BuddyPress settings object
813
  * @global wpdb $wpdb WordPress database object
814
  * @param string $item_id The item id that they notifications are to be for.
815
  * @param string $component_name The component that the notifications are to be from.
969
  * @param array $args
970
  * @return bool False if not allowed
971
  */
972
+ function bp_button( $args = '' ) {
973
+ $this->__construct($args);
974
+ }
975
+
976
  function __construct( $args = '' ) {
977
 
978
  // Default arguments
1024
  if ( false !== $this->wrapper ) {
1025
 
1026
  // Wrapper ID
1027
+ if ( !empty( $wrapper_id ) )
1028
  $this->wrapper_id = ' id="' . $wrapper_id . '"';
 
1029
 
1030
  // Wrapper class
1031
+ if ( !empty( $wrapper_class ) )
1032
  $this->wrapper_class = ' class="generic-button ' . $wrapper_class . '"';
1033
+ else
1034
  $this->wrapper_class = ' class="generic-button"';
 
1035
 
1036
  // Set before and after
1037
  $before = '<' . $wrapper . $this->wrapper_class . $this->wrapper_id . '>';
1096
  * Extends WP_Embed class for use with BuddyPress.
1097
  *
1098
  * @package BuddyPress Core
1099
+ * @since 1.5
1100
  * @see WP_Embed
1101
  */
1102
  class BP_Embed extends WP_Embed {
 
1103
  /**
1104
  * Constructor
1105
  *
1170
  foreach ( $this->handlers as $priority => $handlers ) {
1171
  foreach ( $handlers as $hid => $handler ) {
1172
  if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) {
1173
+ if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) )
1174
  return apply_filters( 'embed_handler_html', $return, $url, $attr );
 
1175
  }
1176
  }
1177
  }
1189
  // If oEmbed discovery is true, skip oEmbed provider check
1190
  $is_oembed_link = false;
1191
  if ( !$attr['discover'] ) {
1192
+ foreach ( (array)$oembed_obj->providers as $provider_matchmask => $provider ) {
1193
  $regex = ( $is_regex = $provider[1] ) ? $provider_matchmask : '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $provider_matchmask ), '#' ) ) . '#i';
1194
 
1195
  if ( preg_match( $regex, $url ) )
1251
  return $this->maybe_make_link( $url );
1252
  }
1253
  }
1254
+ ?>
 
bp-core/bp-core-component.php CHANGED
@@ -14,7 +14,7 @@ if ( !class_exists( 'BP_Component' ) ) :
14
  * @package BuddyPress
15
  * @subpackage Component
16
  *
17
- * @since BuddyPress (1.5)
18
  */
19
  class BP_Component {
20
 
@@ -60,30 +60,14 @@ class BP_Component {
60
  var $notification_callback;
61
 
62
  /**
63
- * @var array WordPress Toolbar links
64
  */
65
  var $admin_menu;
66
 
67
- /**
68
- * Search input box placeholder string for the component
69
- *
70
- * @since BuddyPress (1.5)
71
- * @var string
72
- */
73
- public $search_string;
74
-
75
- /**
76
- * Component's root slug
77
- *
78
- * @since BuddyPress (1.5)
79
- * @var string
80
- */
81
- public $root_slug;
82
-
83
  /**
84
  * Component loader
85
  *
86
- * @since BuddyPress (1.5)
87
  *
88
  * @param mixed $args Required. Supports these args:
89
  * - id: Unique ID (for internal identification). Letters, numbers, and underscores only
@@ -108,7 +92,7 @@ class BP_Component {
108
  /**
109
  * Component global variables
110
  *
111
- * @since BuddyPress (1.5)
112
  * @access private
113
  *
114
  * @uses apply_filters() Calls 'bp_{@link bp_Component::name}_id'
@@ -146,16 +130,10 @@ class BP_Component {
146
  // Notifications callback
147
  $this->notification_callback = apply_filters( 'bp_' . $this->id . '_notification_callback', $r['notification_callback'] );
148
 
149
- // Set up global table names
150
- if ( !empty( $r['global_tables'] ) ) {
151
- // This filter allows for component-specific filtering of table names
152
- // To filter *all* tables, use the 'bp_core_get_table_prefix' filter instead
153
- $r['global_tables'] = apply_filters( 'bp_' . $this->id . '_global_tables', $r['global_tables'] );
154
-
155
- foreach ( $r['global_tables'] as $global_name => $table_name ) {
156
  $this->$global_name = $table_name;
157
- }
158
- }
159
 
160
  /** BuddyPress ********************************************************/
161
 
@@ -186,7 +164,7 @@ class BP_Component {
186
  * - ./bp-my_component/actions
187
  * - ./bp-my_component/bp-my_component-actions.php
188
  *
189
- * @since BuddyPress (1.5)
190
  * @access private
191
  *
192
  * @uses do_action() Calls 'bp_{@link bp_Component::name}includes'
@@ -195,30 +173,21 @@ class BP_Component {
195
  if ( empty( $includes ) )
196
  return;
197
 
198
- $slashed_path = trailingslashit( $this->path );
199
-
200
  // Loop through files to be included
201
  foreach ( $includes as $file ) {
202
 
203
- $paths = array(
 
 
204
 
205
- // Passed with no extension
206
- 'bp-' . $this->id . '/bp-' . $this->id . '-' . $file . '.php',
207
- 'bp-' . $this->id . '-' . $file . '.php',
208
- 'bp-' . $this->id . '/' . $file . '.php',
209
 
210
- // Passed with extension
211
- $file,
212
- 'bp-' . $this->id . '-' . $file,
213
- 'bp-' . $this->id . '/' . $file,
214
- );
215
 
216
- foreach ( $paths as $path ) {
217
- if ( @is_file( $slashed_path . $path ) ) {
218
- require( $slashed_path . $path );
219
- continue;
220
- }
221
- }
222
  }
223
 
224
  // Call action
@@ -228,7 +197,7 @@ class BP_Component {
228
  /**
229
  * Setup the actions
230
  *
231
- * @since BuddyPress (1.5)
232
  * @access private
233
  *
234
  * @uses add_action() To add various actions
@@ -249,7 +218,7 @@ class BP_Component {
249
  // Setup navigation
250
  add_action( 'bp_setup_nav', array ( $this, 'setup_nav' ), 10 );
251
 
252
- // Setup WP Toolbar menus
253
  add_action( 'bp_setup_admin_bar', array ( $this, 'setup_admin_bar' ), 10 );
254
 
255
  // Setup component title
@@ -296,7 +265,7 @@ class BP_Component {
296
  }
297
 
298
  /**
299
- * Setup the Toolbar
300
  *
301
  * @global obj $wp_admin_bar
302
  * @param array $wp_admin_menus
@@ -311,7 +280,7 @@ class BP_Component {
311
  if ( !bp_use_wp_admin_bar() )
312
  return;
313
 
314
- // Do we have Toolbar menus to add?
315
  if ( !empty( $wp_admin_nav ) ) {
316
 
317
  // Set this objects menus
@@ -332,7 +301,7 @@ class BP_Component {
332
  /**
333
  * Setup the component title
334
  *
335
- * @since BuddyPress (1.5)
336
  *
337
  * @uses do_action() Calls 'bp_{@link bp_Component::name}setup_title'
338
  */
@@ -343,7 +312,7 @@ class BP_Component {
343
  /**
344
  * Setup the component post types
345
  *
346
- * @since BuddyPress (1.5)
347
  *
348
  * @uses do_action() Calls 'bp_{@link bp_Component::name}_register_post_types'
349
  */
@@ -354,7 +323,7 @@ class BP_Component {
354
  /**
355
  * Register component specific taxonomies
356
  *
357
- * @since BuddyPress (1.5)
358
  *
359
  * @uses do_action() Calls 'bp_{@link bp_Component::name}_register_taxonomies'
360
  */
@@ -365,7 +334,7 @@ class BP_Component {
365
  /**
366
  * Add any additional rewrite tags
367
  *
368
- * @since BuddyPress (1.5)
369
  *
370
  * @uses do_action() Calls 'bp_{@link bp_Component::name}_add_rewrite_tags'
371
  */
@@ -376,7 +345,7 @@ class BP_Component {
376
  /**
377
  * Generate any additional rewrite rules
378
  *
379
- * @since BuddyPress (1.5)
380
  *
381
  * @uses do_action() Calls 'bp_{@link bp_Component::name}_generate_rewrite_rules'
382
  */
14
  * @package BuddyPress
15
  * @subpackage Component
16
  *
17
+ * @since 1.5
18
  */
19
  class BP_Component {
20
 
60
  var $notification_callback;
61
 
62
  /**
63
+ * @var array WordPress admin bar links
64
  */
65
  var $admin_menu;
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  /**
68
  * Component loader
69
  *
70
+ * @since 1.5
71
  *
72
  * @param mixed $args Required. Supports these args:
73
  * - id: Unique ID (for internal identification). Letters, numbers, and underscores only
92
  /**
93
  * Component global variables
94
  *
95
+ * @since 1.5
96
  * @access private
97
  *
98
  * @uses apply_filters() Calls 'bp_{@link bp_Component::name}_id'
130
  // Notifications callback
131
  $this->notification_callback = apply_filters( 'bp_' . $this->id . '_notification_callback', $r['notification_callback'] );
132
 
133
+ // Setup global table names
134
+ if ( !empty( $r['global_tables'] ) )
135
+ foreach ( $r['global_tables'] as $global_name => $table_name )
 
 
 
 
136
  $this->$global_name = $table_name;
 
 
137
 
138
  /** BuddyPress ********************************************************/
139
 
164
  * - ./bp-my_component/actions
165
  * - ./bp-my_component/bp-my_component-actions.php
166
  *
167
+ * @since 1.5
168
  * @access private
169
  *
170
  * @uses do_action() Calls 'bp_{@link bp_Component::name}includes'
173
  if ( empty( $includes ) )
174
  return;
175
 
 
 
176
  // Loop through files to be included
177
  foreach ( $includes as $file ) {
178
 
179
+ // Check path + file
180
+ if ( @is_file( $this->path . '/' . $file ) )
181
+ require( $this->path . '/' . $file );
182
 
183
+ // Check path + /bp-component/ + file
184
+ elseif ( @is_file( $this->path . '/bp-' . $this->id . '/' . $file ) )
185
+ require( $this->path . '/bp-' . $this->id . '/' . $file );
 
186
 
187
+ // Check buddypress/bp-component/bp-component-$file.php
188
+ elseif ( @is_file( $this->path . '/bp-' . $this->id . '/bp-' . $this->id . '-' . $file . '.php' ) )
189
+ require( $this->path . '/bp-' . $this->id . '/bp-' . $this->id . '-' . $file . '.php' );
 
 
190
 
 
 
 
 
 
 
191
  }
192
 
193
  // Call action
197
  /**
198
  * Setup the actions
199
  *
200
+ * @since 1.5
201
  * @access private
202
  *
203
  * @uses add_action() To add various actions
218
  // Setup navigation
219
  add_action( 'bp_setup_nav', array ( $this, 'setup_nav' ), 10 );
220
 
221
+ // Setup WP Admin Bar menus
222
  add_action( 'bp_setup_admin_bar', array ( $this, 'setup_admin_bar' ), 10 );
223
 
224
  // Setup component title
265
  }
266
 
267
  /**
268
+ * Setup the admin bar
269
  *
270
  * @global obj $wp_admin_bar
271
  * @param array $wp_admin_menus
280
  if ( !bp_use_wp_admin_bar() )
281
  return;
282
 
283
+ // Do we have admin bar menus to add?
284
  if ( !empty( $wp_admin_nav ) ) {
285
 
286
  // Set this objects menus
301
  /**
302
  * Setup the component title
303
  *
304
+ * @since 1.5
305
  *
306
  * @uses do_action() Calls 'bp_{@link bp_Component::name}setup_title'
307
  */
312
  /**
313
  * Setup the component post types
314
  *
315
+ * @since 1.5
316
  *
317
  * @uses do_action() Calls 'bp_{@link bp_Component::name}_register_post_types'
318
  */
323
  /**
324
  * Register component specific taxonomies
325
  *
326
+ * @since 1.5
327
  *
328
  * @uses do_action() Calls 'bp_{@link bp_Component::name}_register_taxonomies'
329
  */
334
  /**
335
  * Add any additional rewrite tags
336
  *
337
+ * @since 1.5
338
  *
339
  * @uses do_action() Calls 'bp_{@link bp_Component::name}_add_rewrite_tags'
340
  */
345
  /**
346
  * Generate any additional rewrite rules
347
  *
348
+ * @since 1.5
349
  *
350
  * @uses do_action() Calls 'bp_{@link bp_Component::name}_generate_rewrite_rules'
351
  */
bp-core/bp-core-cssjs.php CHANGED
@@ -2,6 +2,38 @@
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  function bp_core_confirmation_js() {
6
  global $wpdb;
7
 
@@ -74,7 +106,7 @@ function bp_core_add_cropper_inline_js() {
74
  jQuery('#y').val(c.y);
75
  jQuery('#w').val(c.w);
76
  jQuery('#h').val(c.h);
77
- }
78
 
79
  function showPreview(coords) {
80
  if ( parseInt(coords.w) > 0 ) {
@@ -129,12 +161,13 @@ function bp_core_add_cropper_inline_css() {
129
  *
130
  * Adds AJAX target URL so themes can access the WordPress AJAX functionality.
131
  *
132
- * @since 1.1
133
  */
134
  function bp_core_add_ajax_url_js() {
 
135
  ?>
136
 
137
- <script type="text/javascript">var ajaxurl = '<?php echo admin_url( 'admin-ajax.php' ); ?>';</script>
138
 
139
  <?php
140
  }
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
5
+ /**
6
+ * bp_core_admin_menu_icon_css()
7
+ *
8
+ * Add a hover-able icon to the "BuddyPress" wp-admin area menu.
9
+ *
10
+ * @package BuddyPress Core
11
+ */
12
+ function bp_core_admin_menu_icon_css() {
13
+ global $bp; ?>
14
+
15
+ <style type="text/css">
16
+ /* Wizard Icon */
17
+ ul#adminmenu li.toplevel_page_bp-wizard .wp-menu-image a img { display: none; }
18
+ ul#adminmenu li.toplevel_page_bp-wizard .wp-menu-image a { background-image: url( <?php echo plugins_url( 'buddypress/bp-core/images/admin_menu_icon.png' ) ?> ) !important; background-position: -1px -32px; }
19
+ ul#adminmenu li.toplevel_page_bp-wizard:hover .wp-menu-image a,
20
+ ul#adminmenu li.toplevel_page_bp-wizard.wp-has-current-submenu .wp-menu-image a {
21
+ background-position: -1px 0;
22
+ }
23
+
24
+ /* Settings Icon */
25
+ ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image a img { display: none; }
26
+ ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image a { background-image: url( <?php echo plugins_url( 'buddypress/bp-core/images/admin_menu_icon.png' ) ?> ) !important; background-position: -1px -32px; }
27
+ ul#adminmenu li.toplevel_page_bp-general-settings:hover .wp-menu-image a,
28
+ ul#adminmenu li.toplevel_page_bp-general-settings.wp-has-current-submenu .wp-menu-image a {
29
+ background-position: -1px 0;
30
+ }
31
+ </style>
32
+
33
+ <?php
34
+ }
35
+ add_action( 'admin_head', 'bp_core_admin_menu_icon_css' );
36
+
37
  function bp_core_confirmation_js() {
38
  global $wpdb;
39
 
106
  jQuery('#y').val(c.y);
107
  jQuery('#w').val(c.w);
108
  jQuery('#h').val(c.h);
109
+ };
110
 
111
  function showPreview(coords) {
112
  if ( parseInt(coords.w) > 0 ) {
161
  *
162
  * Adds AJAX target URL so themes can access the WordPress AJAX functionality.
163
  *
164
+ * @package BuddyPress Core
165
  */
166
  function bp_core_add_ajax_url_js() {
167
+ global $bp;
168
  ?>
169
 
170
+ <script type="text/javascript">var ajaxurl = "<?php echo site_url( 'wp-load.php' ); ?>";</script>
171
 
172
  <?php
173
  }
bp-core/bp-core-filters.php CHANGED
@@ -1,5 +1,4 @@
1
  <?php
2
-
3
  // Exit if accessed directly
4
  if ( !defined( 'ABSPATH' ) ) exit;
5
 
@@ -21,14 +20,14 @@ add_filter( 'bp_core_render_message_content', 'shortcode_unautop' );
21
  */
22
  function bp_core_exclude_pages( $pages ) {
23
  global $bp;
24
-
25
  if ( bp_is_root_blog() ) {
26
  if ( !empty( $bp->pages->activate ) )
27
  $pages[] = $bp->pages->activate->id;
28
-
29
  if ( !empty( $bp->pages->register ) )
30
  $pages[] = $bp->pages->register->id;
31
-
32
  if ( !empty( $bp->pages->forums ) && ( !bp_is_active( 'forums' ) || ( bp_is_active( 'forums' ) && bp_forums_has_directory() && !bp_forums_is_installed_correctly() ) ) )
33
  $pages[] = $bp->pages->forums->id;
34
  }
@@ -51,6 +50,21 @@ function bp_core_email_from_name_filter() {
51
  }
52
  add_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  /**
55
  * bp_core_allow_default_theme()
56
  *
@@ -62,9 +76,9 @@ add_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
62
  * @package BuddyPress Core
63
  */
64
  function bp_core_allow_default_theme( $themes ) {
65
- global $wpdb;
66
 
67
- if ( !bp_current_user_can( 'bp_moderate' ) )
68
  return $themes;
69
 
70
  if ( $wpdb->blogid == bp_get_root_blog_id() ) {
@@ -85,7 +99,7 @@ add_filter( 'allowed_themes', 'bp_core_allow_default_theme' );
85
  function bp_core_filter_comments( $comments, $post_id ) {
86
  global $wpdb;
87
 
88
- foreach( (array) $comments as $comment ) {
89
  if ( $comment->user_id )
90
  $user_ids[] = $comment->user_id;
91
  }
@@ -98,10 +112,10 @@ function bp_core_filter_comments( $comments, $post_id ) {
98
  if ( !$userdata = $wpdb->get_results( $wpdb->prepare( "SELECT ID as user_id, user_login, user_nicename FROM {$wpdb->users} WHERE ID IN ({$user_ids})" ) ) )
99
  return $comments;
100
 
101
- foreach( (array) $userdata as $user )
102
  $users[$user->user_id] = bp_core_get_user_domain( $user->user_id, $user->user_nicename, $user->user_login );
103
 
104
- foreach( (array) $comments as $i => $comment ) {
105
  if ( !empty( $comment->user_id ) ) {
106
  if ( !empty( $users[$comment->user_id] ) )
107
  $comments[$i]->comment_author_url = $users[$comment->user_id];
@@ -113,50 +127,29 @@ function bp_core_filter_comments( $comments, $post_id ) {
113
  add_filter( 'comments_array', 'bp_core_filter_comments', 10, 2 );
114
 
115
  /**
116
- * When a user logs in, redirect him in a logical way
117
  *
118
- * @package BuddyPress Core
119
  *
120
- * @uses apply_filters Filter bp_core_login_redirect to modify where users are redirected to on
121
- * login
122
- * @param string $redirect_to The URL to be redirected to, sanitized in wp-login.php
123
- * @param string $redirect_to_raw The unsanitized redirect_to URL ($_REQUEST['redirect_to'])
124
- * @param obj $user The WP_User object corresponding to a successfully logged-in user. Otherwise
125
- * a WP_Error object
126
- * @return string The redirect URL
127
  */
128
- function bp_core_login_redirect( $redirect_to, $redirect_to_raw, $user ) {
 
129
 
130
- // Only modify the redirect if we're on the main BP blog
131
- if ( !bp_is_root_blog() ) {
132
  return $redirect_to;
133
- }
134
 
135
- // Only modify the redirect once the user is logged in
136
- if ( !is_a( $user, 'WP_User' ) ) {
137
  return $redirect_to;
138
- }
139
-
140
- // Allow plugins to allow or disallow redirects, as desired
141
- $maybe_redirect = apply_filters( 'bp_core_login_redirect', false, $redirect_to, $redirect_to_raw, $user );
142
- if ( false !== $maybe_redirect ) {
143
- return $maybe_redirect;
144
- }
145
-
146
- // If a 'redirect_to' parameter has been passed that contains 'wp-admin', verify that the
147
- // logged-in user has any business to conduct in the Dashboard before allowing the
148
- // redirect to go through
149
- if ( !empty( $redirect_to ) && ( false === strpos( $redirect_to, 'wp-admin' ) || user_can( $user, 'edit_posts' ) ) ) {
150
- return $redirect_to;
151
- }
152
 
153
- if ( false === strpos( wp_get_referer(), 'wp-login.php' ) && false === strpos( wp_get_referer(), 'activate' ) && empty( $_REQUEST['nr'] ) ) {
154
  return wp_get_referer();
155
- }
156
 
157
  return bp_get_root_domain();
158
  }
159
- add_filter( 'login_redirect', 'bp_core_login_redirect', 10, 3 );
160
 
161
  /***
162
  * bp_core_filter_user_welcome_email()
@@ -169,8 +162,7 @@ add_filter( 'login_redirect', 'bp_core_login_redirect', 10, 3 );
169
  * @return string Filtered $welcome_email with 'PASSWORD' replaced by [User Set]
170
  */
171
  function bp_core_filter_user_welcome_email( $welcome_email ) {
172
-
173
- // Don't touch the email if we don't have a custom registration template
174
  if ( '' == locate_template( array( 'registration/register.php' ), false ) && '' == locate_template( array( 'register.php' ), false ) )
175
  return $welcome_email;
176
 
@@ -194,8 +186,7 @@ if ( !is_admin() && empty( $_GET['e'] ) )
194
  * @return string Filtered $welcome_email with $password replaced by [User Set]
195
  */
196
  function bp_core_filter_blog_welcome_email( $welcome_email, $blog_id, $user_id, $password ) {
197
-
198
- // Don't touch the email if we don't have a custom registration template
199
  if ( '' == locate_template( array( 'registration/register.php' ), false ) && '' == locate_template( array( 'register.php' ), false ) )
200
  return $welcome_email;
201
 
@@ -252,7 +243,7 @@ function bp_core_activation_signup_user_notification( $user, $user_email, $key,
252
 
253
  $from_name = ( '' == get_site_option( 'site_name' ) ) ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );
254
  $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n";
255
- $message = sprintf( __( "Thanks for registering! To complete the activation of your account please click the following link:\n\n%1\$s\n\n", 'buddypress' ), $activate_url . $email );
256
  $subject = '[' . $from_name . '] ' . __( 'Activate Your Account', 'buddypress' );
257
 
258
  // Send the message
@@ -274,15 +265,17 @@ if ( !is_admin() || ( is_admin() && empty( $_POST['noconfirmation'] ) ) )
274
  * Filter the page title for BuddyPress pages
275
  *
276
  * @global object $bp BuddyPress global settings
 
 
277
  * @param string $title Original page title
278
  * @param string $sep How to separate the various items within the page title.
279
  * @param string $seplocation Direction to display title
280
  * @return string new page title
281
  * @see wp_title()
282
- * @since BuddyPress (1.5)
283
  */
284
  function bp_modify_page_title( $title, $sep, $seplocation ) {
285
- global $bp;
286
 
287
  // If this is not a BP page, just return the title produced by WP
288
  if ( bp_is_blog_page() )
@@ -295,41 +288,27 @@ function bp_modify_page_title( $title, $sep, $seplocation ) {
295
  $title = '';
296
 
297
  // Displayed user
298
- if ( bp_get_displayed_user_fullname() && !is_404() ) {
299
-
300
- // Get the component's ID to try and get it's name
301
- $component_id = $component_name = bp_current_component();
302
-
303
- // Use the actual component name
304
- if ( !empty( $bp->{$component_id}->name ) ) {
305
- $component_name = $bp->{$component_id}->name;
306
-
307
- // Fall back on the component ID (probably same as current_component)
308
- } elseif ( !empty( $bp->{$component_id}->id ) ) {
309
- $component_name = $bp->{$component_id}->id;
310
- }
311
-
312
  // translators: "displayed user's name | canonicalised component name"
313
- $title = strip_tags( sprintf( __( '%1$s | %2$s', 'buddypress' ), bp_get_displayed_user_fullname(), ucwords( $component_name ) ) );
314
 
315
  // A single group
316
  } elseif ( bp_is_active( 'groups' ) && !empty( $bp->groups->current_group ) && !empty( $bp->bp_options_nav[$bp->groups->current_group->slug] ) ) {
317
- $subnav = isset( $bp->bp_options_nav[$bp->groups->current_group->slug][bp_current_action()]['name'] ) ? $bp->bp_options_nav[$bp->groups->current_group->slug][bp_current_action()]['name'] : '';
318
  // translators: "group name | group nav section name"
319
  $title = sprintf( __( '%1$s | %2$s', 'buddypress' ), $bp->bp_options_title, $subnav );
320
 
321
  // A single item from a component other than groups
322
  } elseif ( bp_is_single_item() ) {
323
  // translators: "component item name | component nav section name | root component name"
324
- $title = sprintf( __( '%1$s | %2$s | %3$s', 'buddypress' ), $bp->bp_options_title, $bp->bp_options_nav[bp_current_item()][bp_current_action()]['name'], bp_get_name_from_root_slug( bp_get_root_slug() ) );
325
 
326
  // An index or directory
327
  } elseif ( bp_is_directory() ) {
328
- if ( !bp_current_component() ) {
329
- $title = sprintf( __( '%s Directory', 'buddypress' ), bp_get_name_from_root_slug() );
330
- } else {
331
- $title = sprintf( __( '%s Directory', 'buddypress' ), bp_get_name_from_root_slug() );
332
- }
333
 
334
  // Sign up page
335
  } elseif ( bp_is_register_page() ) {
@@ -351,11 +330,11 @@ function bp_modify_page_title( $title, $sep, $seplocation ) {
351
  // Some BP nav items contain item counts. Remove them
352
  $title = preg_replace( '|<span>[0-9]+</span>|', '', $title );
353
 
354
- return apply_filters( 'bp_modify_page_title', $title . ' ' . $sep . ' ', $title, $sep, $seplocation );
355
  }
356
  add_filter( 'wp_title', 'bp_modify_page_title', 10, 3 );
357
  add_filter( 'bp_modify_page_title', 'wptexturize' );
358
  add_filter( 'bp_modify_page_title', 'convert_chars' );
359
  add_filter( 'bp_modify_page_title', 'esc_html' );
360
 
361
- ?>
1
  <?php
 
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
20
  */
21
  function bp_core_exclude_pages( $pages ) {
22
  global $bp;
23
+
24
  if ( bp_is_root_blog() ) {
25
  if ( !empty( $bp->pages->activate ) )
26
  $pages[] = $bp->pages->activate->id;
27
+
28
  if ( !empty( $bp->pages->register ) )
29
  $pages[] = $bp->pages->register->id;
30
+
31
  if ( !empty( $bp->pages->forums ) && ( !bp_is_active( 'forums' ) || ( bp_is_active( 'forums' ) && bp_forums_has_directory() && !bp_forums_is_installed_correctly() ) ) )
32
  $pages[] = $bp->pages->forums->id;
33
  }
50
  }
51
  add_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
52
 
53
+ /**
54
+ * bp_core_email_from_name_filter()
55
+ *
56
+ * Sets the "From" address in emails sent
57
+ *
58
+ * @package BuddyPress Core
59
+ * @return noreply@sitedomain email address
60
+ */
61
+ function bp_core_email_from_address_filter() {
62
+ $domain = (array) explode( '/', site_url() );
63
+
64
+ return apply_filters( 'bp_core_email_from_address_filter', 'noreply@' . $domain[2] );
65
+ }
66
+ add_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );
67
+
68
  /**
69
  * bp_core_allow_default_theme()
70
  *
76
  * @package BuddyPress Core
77
  */
78
  function bp_core_allow_default_theme( $themes ) {
79
+ global $bp, $wpdb;
80
 
81
+ if ( !is_super_admin() )
82
  return $themes;
83
 
84
  if ( $wpdb->blogid == bp_get_root_blog_id() ) {
99
  function bp_core_filter_comments( $comments, $post_id ) {
100
  global $wpdb;
101
 
102
+ foreach( (array)$comments as $comment ) {
103
  if ( $comment->user_id )
104
  $user_ids[] = $comment->user_id;
105
  }
112
  if ( !$userdata = $wpdb->get_results( $wpdb->prepare( "SELECT ID as user_id, user_login, user_nicename FROM {$wpdb->users} WHERE ID IN ({$user_ids})" ) ) )
113
  return $comments;
114
 
115
+ foreach( (array)$userdata as $user )
116
  $users[$user->user_id] = bp_core_get_user_domain( $user->user_id, $user->user_nicename, $user->user_login );
117
 
118
+ foreach( (array)$comments as $i => $comment ) {
119
  if ( !empty( $comment->user_id ) ) {
120
  if ( !empty( $users[$comment->user_id] ) )
121
  $comments[$i]->comment_author_url = $users[$comment->user_id];
127
  add_filter( 'comments_array', 'bp_core_filter_comments', 10, 2 );
128
 
129
  /**
130
+ * bp_core_login_redirect()
131
  *
132
+ * When a user logs in, always redirect them back to the previous page. NOT the admin area.
133
  *
134
+ * @package BuddyPress Core
 
 
 
 
 
 
135
  */
136
+ function bp_core_login_redirect( $redirect_to ) {
137
+ global $bp, $wpdb;
138
 
139
+ // Don't mess with the redirect if this is not the root blog
140
+ if ( is_multisite() && $wpdb->blogid != bp_get_root_blog_id() )
141
  return $redirect_to;
 
142
 
143
+ // If the redirect doesn't contain 'wp-admin', it's OK
144
+ if ( !empty( $_REQUEST['redirect_to'] ) && false === strpos( $_REQUEST['redirect_to'], 'wp-admin' ) )
145
  return $redirect_to;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
 
147
+ if ( false === strpos( wp_get_referer(), 'wp-login.php' ) && false === strpos( wp_get_referer(), 'activate' ) && empty( $_REQUEST['nr'] ) )
148
  return wp_get_referer();
 
149
 
150
  return bp_get_root_domain();
151
  }
152
+ add_filter( 'login_redirect', 'bp_core_login_redirect' );
153
 
154
  /***
155
  * bp_core_filter_user_welcome_email()
162
  * @return string Filtered $welcome_email with 'PASSWORD' replaced by [User Set]
163
  */
164
  function bp_core_filter_user_welcome_email( $welcome_email ) {
165
+ /* Don't touch the email if we don't have a custom registration template */
 
166
  if ( '' == locate_template( array( 'registration/register.php' ), false ) && '' == locate_template( array( 'register.php' ), false ) )
167
  return $welcome_email;
168
 
186
  * @return string Filtered $welcome_email with $password replaced by [User Set]
187
  */
188
  function bp_core_filter_blog_welcome_email( $welcome_email, $blog_id, $user_id, $password ) {
189
+ /* Don't touch the email if we don't have a custom registration template */
 
190
  if ( '' == locate_template( array( 'registration/register.php' ), false ) && '' == locate_template( array( 'register.php' ), false ) )
191
  return $welcome_email;
192
 
243
 
244
  $from_name = ( '' == get_site_option( 'site_name' ) ) ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );
245
  $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n";
246
+ $message = sprintf( __( "Thanks for registering! To complete the activation of your account please click the following link:\n\n%s\n\n", 'buddypress' ), $activate_url . $email );
247
  $subject = '[' . $from_name . '] ' . __( 'Activate Your Account', 'buddypress' );
248
 
249
  // Send the message
265
  * Filter the page title for BuddyPress pages
266
  *
267
  * @global object $bp BuddyPress global settings
268
+ * @global unknown $post
269
+ * @global WP_Query $wp_query WordPress query object
270
  * @param string $title Original page title
271
  * @param string $sep How to separate the various items within the page title.
272
  * @param string $seplocation Direction to display title
273
  * @return string new page title
274
  * @see wp_title()
275
+ * @since 1.5
276
  */
277
  function bp_modify_page_title( $title, $sep, $seplocation ) {
278
+ global $bp, $post, $wp_query;
279
 
280
  // If this is not a BP page, just return the title produced by WP
281
  if ( bp_is_blog_page() )
288
  $title = '';
289
 
290
  // Displayed user
291
+ if ( !empty( $bp->displayed_user->fullname ) && !is_404() ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
292
  // translators: "displayed user's name | canonicalised component name"
293
+ $title = strip_tags( sprintf( __( '%1$s | %2$s', 'buddypress' ), bp_get_displayed_user_fullname(), __( ucwords( bp_current_component() ), 'buddypress' ) ) );
294
 
295
  // A single group
296
  } elseif ( bp_is_active( 'groups' ) && !empty( $bp->groups->current_group ) && !empty( $bp->bp_options_nav[$bp->groups->current_group->slug] ) ) {
297
+ $subnav = isset( $bp->bp_options_nav[$bp->groups->current_group->slug][$bp->current_action]['name'] ) ? $bp->bp_options_nav[$bp->groups->current_group->slug][$bp->current_action]['name'] : '';
298
  // translators: "group name | group nav section name"
299
  $title = sprintf( __( '%1$s | %2$s', 'buddypress' ), $bp->bp_options_title, $subnav );
300
 
301
  // A single item from a component other than groups
302
  } elseif ( bp_is_single_item() ) {
303
  // translators: "component item name | component nav section name | root component name"
304
+ $title = sprintf( __( '%1$s | %2$s | %3$s', 'buddypress' ), $bp->bp_options_title, $bp->bp_options_nav[$bp->current_item][$bp->current_action]['name'], bp_get_name_from_root_slug( bp_get_root_slug() ) );
305
 
306
  // An index or directory
307
  } elseif ( bp_is_directory() ) {
308
+ if ( !bp_current_component() )
309
+ $title = sprintf( __( '%s Directory', 'buddypress' ), __( bp_get_name_from_root_slug(), 'buddypress' ) );
310
+ else
311
+ $title = sprintf( __( '%s Directory', 'buddypress' ), __( bp_get_name_from_root_slug(), 'buddypress' ) );
 
312
 
313
  // Sign up page
314
  } elseif ( bp_is_register_page() ) {
330
  // Some BP nav items contain item counts. Remove them
331
  $title = preg_replace( '|<span>[0-9]+</span>|', '', $title );
332
 
333
+ return apply_filters( 'bp_modify_page_title', $title . " $sep ", $title, $sep, $seplocation );
334
  }
335
  add_filter( 'wp_title', 'bp_modify_page_title', 10, 3 );
336
  add_filter( 'bp_modify_page_title', 'wptexturize' );
337
  add_filter( 'bp_modify_page_title', 'convert_chars' );
338
  add_filter( 'bp_modify_page_title', 'esc_html' );
339
 
340
+ ?>
bp-core/bp-core-functions.php CHANGED
@@ -1,107 +1,61 @@
1
  <?php
2
-
3
- /**
4
- * BuddyPress Common Functions
5
- *
6
- * @package BuddyPress
7
- * @subpackage Functions
8
- */
9
-
10
  // Exit if accessed directly
11
  if ( !defined( 'ABSPATH' ) ) exit;
12
 
13
- /** Versions ******************************************************************/
14
-
15
  /**
16
- * Output the BuddyPress version
17
  *
18
- * @since BuddyPress (1.6)
19
- * @uses bp_get_version() To get the BuddyPress version
20
- */
21
- function bp_version() {
22
- echo bp_get_version();
23
- }
24
- /**
25
- * Return the BuddyPress version
26
- *
27
- * @since BuddyPress (1.6)
28
- * @global BuddyPress $bp
29
- * @return string The BuddyPress version
30
- */
31
- function bp_get_version() {
32
- global $bp;
33
- return $bp->version;
34
- }
35
-
36
- /**
37
- * Output the BuddyPress database version
38
  *
39
- * @since BuddyPress (1.6)
40
- * @uses bp_get_db_version() To get the BuddyPress version
 
 
41
  */
42
- function bp_db_version() {
43
- echo bp_get_db_version();
 
 
44
  }
45
- /**
46
- * Return the BuddyPress database version
47
- *
48
- * @since BuddyPress (1.6)
49
- * @global BuddyPress $bp
50
- * @return string The BuddyPress version
51
- */
52
- function bp_get_db_version() {
53
- global $bp;
54
- return $bp->db_version;
55
- }
56
 
57
  /**
58
- * Output the BuddyPress database version
 
 
 
 
 
 
59
  *
60
- * @since BuddyPress (1.6)
61
- * @uses bp_get_db_version_raw() To get the current BuddyPress version
 
62
  */
63
- function bp_db_version_raw() {
64
- echo bp_get_db_version_raw();
65
  }
66
- /**
67
- * Return the BuddyPress database version
68
- *
69
- * @since BuddyPress (1.6)
70
- * @global BuddyPress $bp
71
- * @return string The BuddyPress version direct from the database
72
- */
73
- function bp_get_db_version_raw() {
74
- global $bp;
75
-
76
- $retval = 0;
77
- if ( !empty( $bp->db_version_raw ) )
78
- $retval = $bp->db_version_raw;
79
-
80
- return $retval;
81
- }
82
 
83
  /**
84
- * Output the BuddyPress maintenance mode
 
 
 
 
 
 
85
  *
86
- * @since BuddyPress (1.6)
87
- * @uses bp_get_maintenance_mode() To get the BuddyPress maintenance mode
88
  */
89
- function bp_maintenance_mode() {
90
- echo bp_get_maintenance_mode();
91
  }
92
- /**
93
- * Return the BuddyPress maintenance mode
94
- *
95
- * @since BuddyPress (1.6)
96
- * @global BuddyPress $bp
97
- * @return string The BuddyPress maintenance mode
98
- */
99
- function bp_get_maintenance_mode() {
100
- global $bp;
101
- return $bp->maintenance_mode;
102
- }
103
-
104
- /** Functions *****************************************************************/
105
 
106
  /**
107
  * Allow filtering of database prefix. Intended for use in multinetwork installations.
@@ -119,14 +73,28 @@ function bp_core_get_table_prefix() {
119
  * Fetches BP pages from the meta table, depending on setup
120
  *
121
  * @package BuddyPress Core
122
- * @since BuddyPress (1.5)
 
 
 
123
  */
124
  function bp_core_get_directory_page_ids() {
125
  $page_ids = bp_get_option( 'bp-pages' );
126
 
 
 
 
 
 
 
 
 
 
 
 
127
  // Ensure that empty indexes are unset. Should only matter in edge cases
128
- if ( !empty( $page_ids ) && is_array( $page_ids ) ) {
129
- foreach( (array) $page_ids as $component_name => $page_id ) {
130
  if ( empty( $component_name ) || empty( $page_id ) ) {
131
  unset( $page_ids[$component_name] );
132
  }
@@ -143,7 +111,7 @@ function bp_core_get_directory_page_ids() {
143
  * blog_id. This allows you to change your bp_get_root_blog_id() and go through the setup process again.
144
  *
145
  * @package BuddyPress Core
146
- * @since BuddyPress (1.5)
147
  *
148
  * @param array $blog_page_ids The IDs of the WP pages corresponding to BP component directories
149
  */
@@ -155,33 +123,28 @@ function bp_core_update_directory_page_ids( $blog_page_ids ) {
155
  * Get bp-pages names and slugs
156
  *
157
  * @package BuddyPress Core
158
- * @since BuddyPress (1.5)
159
  *
160
  * @return obj $pages Page names, IDs, and slugs
161
  */
162
  function bp_core_get_directory_pages() {
163
- global $wpdb;
164
 
165
  // Set pages as standard class
166
  $pages = new stdClass;
167
 
168
  // Get pages and IDs
169
- $page_ids = bp_core_get_directory_page_ids();
170
- if ( !empty( $page_ids ) ) {
171
 
172
  // Always get page data from the root blog, except on multiblog mode, when it comes
173
  // from the current blog
174
  $posts_table_name = bp_is_multiblog_mode() ? $wpdb->posts : $wpdb->get_blog_prefix( bp_get_root_blog_id() ) . 'posts';
175
- $page_ids_sql = implode( ',', (array) $page_ids );
176
  $page_names = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent, post_title FROM {$posts_table_name} WHERE ID IN ({$page_ids_sql}) AND post_status = 'publish' " ) );
177
 
178
- foreach ( (array) $page_ids as $component_id => $page_id ) {
179
- foreach ( (array) $page_names as $page_name ) {
180
  if ( $page_name->ID == $page_id ) {
181
- if ( !isset( $pages->{$component_id} ) || !is_object( $pages->{$component_id} ) ) {
182
- $pages->{$component_id} = new stdClass;
183
- }
184
-
185
  $pages->{$component_id}->name = $page_name->post_name;
186
  $pages->{$component_id}->id = $page_name->ID;
187
  $pages->{$component_id}->title = $page_name->post_title;
@@ -194,7 +157,7 @@ function bp_core_get_directory_pages() {
194
  $page_name->post_parent = $parent[0]->post_parent;
195
  }
196
 
197
- $pages->{$component_id}->slug = implode( '/', array_reverse( (array) $slug ) );
198
  }
199
 
200
  unset( $slug );
@@ -223,7 +186,7 @@ function bp_core_get_directory_pages() {
223
  * to override specific component slugs.
224
  *
225
  * @package BuddyPress Core
226
- * @since BuddyPress (1.5)
227
  *
228
  * @param str $root_slug The root slug, which comes from $bp->pages->[component]->slug
229
  * @return str $slug The short slug for use in the middle of URLs
@@ -235,6 +198,268 @@ function bp_core_component_slug_from_root_slug( $root_slug ) {
235
  return apply_filters( 'bp_core_component_slug_from_root_slug', $slug, $root_slug );
236
  }
237
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  /**
239
  * Returns the domain for the root blog.
240
  * eg: http://domain.com/ OR https://domain.com
@@ -244,6 +469,7 @@ function bp_core_component_slug_from_root_slug( $root_slug ) {
244
  * @return $domain The domain URL for the blog.
245
  */
246
  function bp_core_get_root_domain() {
 
247
 
248
  $domain = get_home_url( bp_get_root_blog_id() );
249
 
@@ -269,7 +495,7 @@ function bp_core_current_time( $gmt = true ) {
269
  *
270
  * @package BuddyPress Core
271
  *
272
- * @global BuddyPress $bp The one true BuddyPress instance
273
  * @param str $message Feedback to give to user
274
  * @param str $type updated|success|error|warning
275
  */
@@ -326,7 +552,7 @@ add_action( 'bp_actions', 'bp_core_setup_message', 5 );
326
  * The hook action 'template_notices' is used to call this function, it is not called directly.
327
  *
328
  * @package BuddyPress Core
329
- * @global BuddyPress $bp The one true BuddyPress instance
330
  */
331
  function bp_core_render_message() {
332
  global $bp;
@@ -356,12 +582,11 @@ function bp_core_render_message() {
356
  * @return str
357
  */
358
  function bp_core_number_format( $number, $decimals = false ) {
359
-
360
- // Force number to 0 if needed
361
  if ( empty( $number ) )
362
- $number = 0;
363
 
364
- return apply_filters( 'bp_core_number_format', number_format_i18n( $number, $decimals ), $number, $decimals );
365
  }
366
 
367
  /**
@@ -399,7 +624,7 @@ function bp_core_time_since( $older_date, $newer_date = false ) {
399
  if ( !empty( $older_date ) && !is_numeric( $older_date ) ) {
400
  $time_chunks = explode( ':', str_replace( ' ', ':', $older_date ) );
401
  $date_chunks = explode( '-', str_replace( ' ', '-', $older_date ) );
402
- $older_date = gmmktime( (int) $time_chunks[1], (int) $time_chunks[2], (int) $time_chunks[3], (int) $date_chunks[1], (int) $date_chunks[2], (int) $date_chunks[0] );
403
  }
404
 
405
  /**
@@ -429,8 +654,7 @@ function bp_core_time_since( $older_date, $newer_date = false ) {
429
  $seconds = $chunks[$i][0];
430
 
431
  // Finding the biggest chunk (if the chunk fits, break)
432
- $count = floor( $since / $seconds );
433
- if ( 0 != $count ) {
434
  break;
435
  }
436
  }
@@ -447,17 +671,16 @@ function bp_core_time_since( $older_date, $newer_date = false ) {
447
  // Step two: the second chunk
448
  if ( $i + 2 < $j ) {
449
  $seconds2 = $chunks[$i + 1][0];
450
- $name2 = $chunks[$i + 1][1];
451
- $count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 );
452
 
453
- // Add to output var
454
- if ( 0 != $count2 ) {
455
- $output .= ( 1 == $count2 ) ? _x( ',', 'Separator in time since', 'buddypress' ) . ' 1 '. $name2 : _x( ',', 'Separator in time since', 'buddypress' ) . ' ' . $count2 . ' ' . $chunks[$i + 1][2];
456
  }
457
  }
458
 
459
  // No output, so happened right now
460
- if ( ! (int) trim( $output ) ) {
461
  $output = $right_now_text;
462
  }
463
  }
@@ -481,13 +704,14 @@ function bp_core_time_since( $older_date, $newer_date = false ) {
481
  * @uses bp_update_user_meta() BP function to update user metadata in the usermeta table.
482
  */
483
  function bp_core_record_activity() {
 
484
 
485
  if ( !is_user_logged_in() )
486
  return false;
487
 
488
- $user_id = bp_loggedin_user_id();
489
 
490
- if ( bp_is_user_inactive( $user_id ) )
491
  return false;
492
 
493
  $activity = bp_get_user_meta( $user_id, 'last_activity', true );
@@ -498,11 +722,6 @@ function bp_core_record_activity() {
498
  // Get current time
499
  $current_time = bp_core_current_time();
500
 
501
- // Use this action to detect the very first activity for a given member
502
- if ( empty( $activity ) ) {
503
- do_action( 'bp_first_activity_for_member', $user_id );
504
- }
505
-
506
  if ( empty( $activity ) || strtotime( $current_time ) >= strtotime( '+5 minutes', $activity ) )
507
  bp_update_user_meta( $user_id, 'last_activity', $current_time );
508
  }
@@ -518,9 +737,8 @@ add_action( 'wp_head', 'bp_core_record_activity' );
518
  * @uses bp_core_time_since() This function will return an English representation of the time elapsed.
519
  */
520
  function bp_core_get_last_activity( $last_activity_date, $string ) {
521
-
522
- if ( empty( $last_activity_date ) )
523
- $last_active = __( 'Not recently active', 'buddypress' );
524
  else
525
  $last_active = sprintf( $string, bp_core_time_since( $last_activity_date ) );
526
 
@@ -532,11 +750,12 @@ function bp_core_get_last_activity( $last_activity_date, $string ) {
532
  *
533
  * @package BuddyPress Core
534
  *
 
535
  * @global object $current_site
536
  * @return string
537
  */
538
  function bp_core_get_site_path() {
539
- global $current_site;
540
 
541
  if ( is_multisite() )
542
  $site_path = $current_site->path;
@@ -565,22 +784,16 @@ function bp_core_get_site_path() {
565
  * Performs a status safe wp_redirect() that is compatible with bp_catch_uri()
566
  *
567
  * @package BuddyPress Core
568
- * @global BuddyPress $bp Makes sure that there are no conflicts with
569
- * status_header() called in bp_core_do_catch_uri()
570
- * @uses wp_redirect()
571
  */
572
  function bp_core_redirect( $location, $status = 302 ) {
573
- global $bp;
574
-
575
- // On some setups, passing the value of wp_get_referer() may result in an empty value for
576
- // $location, which results in an error. Ensure that we have a valid URL.
577
- if ( empty( $location ) ) {
578
- $location = bp_get_root_domain();
579
- }
580
 
581
  // Make sure we don't call status_header() in bp_core_do_catch_uri()
582
  // as this conflicts with wp_redirect()
583
- $bp->no_status_set = true;
584
 
585
  wp_redirect( $location, $status );
586
  die;
@@ -612,9 +825,11 @@ function bp_core_add_illegal_names() {
612
  * A javascript free implementation of the search functions in BuddyPress
613
  *
614
  * @package BuddyPress Core
 
615
  * @param string $slug The slug to redirect to for searching.
616
  */
617
  function bp_core_action_search_site( $slug = '' ) {
 
618
 
619
  if ( !bp_is_current_component( bp_get_search_slug() ) )
620
  return;
@@ -697,7 +912,7 @@ function bp_core_load_buddypress_textdomain() {
697
  $locale = apply_filters( 'buddypress_locale', get_locale() );
698
  $mofile = sprintf( 'buddypress-%s.mo', $locale );
699
  $mofile_global = WP_LANG_DIR . '/' . $mofile;
700
- $mofile_local = BP_PLUGIN_DIR . 'bp-languages/' . $mofile;
701
 
702
  if ( file_exists( $mofile_global ) )
703
  return load_textdomain( 'buddypress', $mofile_global );
@@ -706,14 +921,21 @@ function bp_core_load_buddypress_textdomain() {
706
  else
707
  return false;
708
  }
709
- add_action ( 'bp_core_loaded', 'bp_core_load_buddypress_textdomain' );
 
 
 
 
 
 
 
710
 
711
  /**
712
  * Initializes {@link BP_Embed} after everything is loaded.
713
  *
714
  * @global object $bp BuddyPress global settings
715
  * @package BuddyPress Core
716
- * @since BuddyPress (1.5)
717
  */
718
  function bp_embed_init() {
719
  global $bp;
@@ -723,6 +945,135 @@ function bp_embed_init() {
723
  }
724
  add_action( 'bp_init', 'bp_embed_init', 9 );
725
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
726
  /**
727
  * This function originally let plugins add support for pages in the root of the install.
728
  * These root level pages are now handled by actual WordPress pages and this function is now
@@ -740,7 +1091,7 @@ function bp_core_add_root_component( $slug ) {
740
  $match = false;
741
 
742
  // Check if the slug is registered in the $bp->pages global
743
- foreach ( (array) $bp->pages as $key => $page ) {
744
  if ( $key == $slug || $page->slug == $slug )
745
  $match = true;
746
  }
@@ -762,7 +1113,7 @@ function bp_core_create_root_component_page() {
762
 
763
  $new_page_ids = array();
764
 
765
- foreach ( (array) $bp->add_root as $slug )
766
  $new_page_ids[$slug] = wp_insert_post( array( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_title' => ucwords( $slug ), 'post_status' => 'publish', 'post_type' => 'page' ) );
767
 
768
  $page_ids = array_merge( (array) $new_page_ids, (array) bp_core_get_directory_page_ids() );
@@ -773,13 +1124,12 @@ function bp_core_create_root_component_page() {
773
  * Is this the root blog ID?
774
  *
775
  * @package BuddyPress
776
- * @since BuddyPress (1.5)
777
  *
778
  * @param int $blog_id Optional. Defaults to the current blog id.
779
  * @return bool $is_root_blog Returns true if this is bp_get_root_blog_id().
780
  */
781
  function bp_is_root_blog( $blog_id = 0 ) {
782
-
783
  // Assume false
784
  $is_root_blog = false;
785
 
@@ -791,21 +1141,45 @@ function bp_is_root_blog( $blog_id = 0 ) {
791
  if ( $blog_id == bp_get_root_blog_id() )
792
  $is_root_blog = true;
793
 
794
- return (bool) apply_filters( 'bp_is_root_blog', (bool) $is_root_blog );
795
  }
796
 
797
  /**
798
  * Is this bp_get_root_blog_id()?
799
  *
800
  * @package BuddyPress
801
- * @since BuddyPress (1.5)
802
  *
803
- * @return int Return the root site ID
 
804
  */
805
- function bp_get_root_blog_id() {
806
- global $bp;
 
 
 
 
 
 
 
 
 
 
 
807
 
808
- return (int) apply_filters( 'bp_get_root_blog_id', (int) $bp->root_blog_id );
 
 
 
 
 
 
 
 
 
 
 
 
809
  }
810
 
811
  /**
@@ -822,7 +1196,7 @@ function bp_get_root_blog_id() {
822
  * If using the WP functions, do not not hardcode your meta keys.
823
  *
824
  * @package BuddyPress
825
- * @since BuddyPress (1.5)
826
  *
827
  * @uses apply_filters() Filter bp_get_user_meta_key to modify keys individually
828
  * @param str $key
@@ -839,7 +1213,7 @@ function bp_get_user_meta_key( $key = false ) {
839
  * increasing compatibility with non-standard BP setups.
840
  *
841
  * @package BuddyPress
842
- * @since BuddyPress (1.5)
843
  *
844
  * @uses bp_get_user_meta_key() For a filterable version of the meta key
845
  * @uses get_user_meta() See get_user_meta() docs for more details on parameters
@@ -860,7 +1234,7 @@ function bp_get_user_meta( $user_id, $key, $single = false ) {
860
  * thereby increasing compatibility with non-standard BP setups.
861
  *
862
  * @package BuddyPress
863
- * @since BuddyPress (1.5)
864
  *
865
  * @uses bp_get_user_meta_key() For a filterable version of the meta key
866
  * @uses update_user_meta() See update_user_meta() docs for more details on parameters
@@ -881,7 +1255,7 @@ function bp_update_user_meta( $user_id, $key, $value, $prev_value = '' ) {
881
  * thereby increasing compatibility with non-standard BP setups.
882
  *
883
  * @package BuddyPress
884
- * @since BuddyPress (1.5)
885
  *
886
  * @uses bp_get_user_meta_key() For a filterable version of the meta key
887
  * @uses delete_user_meta() See delete_user_meta() docs for more details on parameters
@@ -898,7 +1272,7 @@ function bp_delete_user_meta( $user_id, $key, $value = '' ) {
898
  * Are we running username compatibility mode?
899
  *
900
  * @package BuddyPress
901
- * @since BuddyPress (1.5)
902
  *
903
  * @uses apply_filters() Filter 'bp_is_username_compatibility_mode' to alter
904
  * @return bool False when compatibility mode is disabled (default); true when enabled
@@ -922,7 +1296,7 @@ function bp_is_username_compatibility_mode() {
922
  * blog.
923
  *
924
  * @package BuddyPress
925
- * @since BuddyPress (1.5)
926
  *
927
  * @uses apply_filters() Filter 'bp_is_multiblog_mode' to alter
928
  * @return bool False when multiblog mode is disabled (default); true when enabled
@@ -932,83 +1306,29 @@ function bp_is_multiblog_mode() {
932
  }
933
 
934
  /**
935
- * Should we use the WP Toolbar?
936
- *
937
- * The WP Toolbar, introduced in WP 3.1, is fully supported in BuddyPress as of BP 1.5.
938
- * For BP 1.6, the WP Toolbar is the default.
939
- *
940
- * @return bool False when WP Toolbar support is disabled; true when enabled (default)
941
- * @since BuddyPress (1.5)
942
- * @uses apply_filters() Filter 'bp_use_wp_admin_bar' to alter
943
- */
944
- function bp_use_wp_admin_bar() {
945
- $use_admin_bar = true;
946
-
947
- // Has the WP Toolbar constant been explicity set?
948
- if ( defined( 'BP_USE_WP_ADMIN_BAR' ) && ! BP_USE_WP_ADMIN_BAR )
949
- $use_admin_bar = false;
950
-
951
- // Has the admin chosen to use the BuddyBar during an upgrade?
952
- elseif ( (bool) bp_get_option( '_bp_force_buddybar', false ) )
953
- $use_admin_bar = false;
954
-
955
- return apply_filters( 'bp_use_wp_admin_bar', $use_admin_bar );
956
- }
957
-
958
- /**
959
- * A utility for parsing individual function arguments into an array.
960
- *
961
- * The purpose of this function is to help with backward compatibility in cases where
962
- *
963
- * function foo( $bar = 1, $baz = false, $barry = array(), $blip = false ) { // ...
964
- *
965
- * is deprecated in favor of
966
- *
967
- * function foo( $args = array() ) {
968
- * $defaults = array(
969
- * 'bar' => 1,
970
- * 'arg2' => false,
971
- * 'arg3' => array(),
972
- * 'arg4' => false,
973
- * );
974
- * $r = wp_parse_args( $args, $defaults ); // ...
975
  *
976
- * The first argument, $old_args_keys, is an array that matches the parameter positions (keys) to
977
- * the new $args keys (values):
978
  *
979
- * $old_args_keys = array(
980
- * 0 => 'bar', // because $bar was the 0th parameter for foo()
981
- * 1 => 'baz', // because $baz was the 1st parameter for foo()
982
- * 2 => 'barry', // etc
983
- * 3 => 'blip'
984
- * );
985
  *
986
- * For the second argument, $func_args, you should just pass the value of func_get_args().
 
987
  *
988
- * @since BuddyPress (1.6)
989
- * @param array $old_args_keys
990
- * @param array $func_args
991
- * @return array $new_args
992
  */
993
- function bp_core_parse_args_array( $old_args_keys, $func_args ) {
994
- $new_args = array();
995
-
996
- foreach( $old_args_keys as $arg_num => $arg_key ) {
997
- if ( isset( $func_args[$arg_num] ) ) {
998
- $new_args[$arg_key] = $func_args[$arg_num];
999
- }
1000
- }
1001
-
1002
- return $new_args;
1003
  }
1004
 
1005
- /** Embeds ********************************************************************/
1006
-
1007
  /**
1008
  * Are oembeds allowed in activity items?
1009
  *
1010
  * @return bool False when activity embed support is disabled; true when enabled (default)
1011
- * @since BuddyPress (1.5)
1012
  */
1013
  function bp_use_embed_in_activity() {
1014
  return apply_filters( 'bp_use_oembed_in_activity', !defined( 'BP_EMBED_DISABLE_ACTIVITY' ) || !BP_EMBED_DISABLE_ACTIVITY );
@@ -1018,7 +1338,7 @@ function bp_use_embed_in_activity() {
1018
  * Are oembeds allwoed in activity replies?
1019
  *
1020
  * @return bool False when activity replies embed support is disabled; true when enabled (default)
1021
- * @since BuddyPress (1.5)
1022
  */
1023
  function bp_use_embed_in_activity_replies() {
1024
  return apply_filters( 'bp_use_embed_in_activity_replies', !defined( 'BP_EMBED_DISABLE_ACTIVITY_REPLIES' ) || !BP_EMBED_DISABLE_ACTIVITY_REPLIES );
@@ -1028,7 +1348,7 @@ function bp_use_embed_in_activity_replies() {
1028
  * Are oembeds allowed in forum posts?
1029
  *
1030
  * @return bool False when form post embed support is disabled; true when enabled (default)
1031
- * @since BuddyPress (1.5)
1032
  */
1033
  function bp_use_embed_in_forum_posts() {
1034
  return apply_filters( 'bp_use_embed_in_forum_posts', !defined( 'BP_EMBED_DISABLE_FORUM_POSTS' ) || !BP_EMBED_DISABLE_FORUM_POSTS );
@@ -1038,19 +1358,17 @@ function bp_use_embed_in_forum_posts() {
1038
  * Are oembeds allowed in private messages?
1039
  *
1040
  * @return bool False when form post embed support is disabled; true when enabled (default)
1041
- * @since BuddyPress (1.5)
1042
  */
1043
  function bp_use_embed_in_private_messages() {
1044
  return apply_filters( 'bp_use_embed_in_private_messages', !defined( 'BP_EMBED_DISABLE_PRIVATE_MESSAGES' ) || !BP_EMBED_DISABLE_PRIVATE_MESSAGES );
1045
  }
1046
 
1047
- /** Admin *********************************************************************/
1048
-
1049
  /**
1050
  * Output the correct URL based on BuddyPress and WordPress configuration
1051
  *
1052
  * @package BuddyPress
1053
- * @since BuddyPress (1.5)
1054
  *
1055
  * @param string $path
1056
  * @param string $scheme
@@ -1064,7 +1382,7 @@ function bp_admin_url( $path = '', $scheme = 'admin' ) {
1064
  * Return the correct URL based on BuddyPress and WordPress configuration
1065
  *
1066
  * @package BuddyPress
1067
- * @since BuddyPress (1.5)
1068
  *
1069
  * @param string $path
1070
  * @param string $scheme
@@ -1086,27 +1404,12 @@ function bp_admin_url( $path = '', $scheme = 'admin' ) {
1086
  return $url;
1087
  }
1088
 
1089
- function bp_core_do_network_admin() {
1090
- $do_network_admin = false;
1091
-
1092
- if ( is_multisite() && !bp_is_multiblog_mode() )
1093
- $do_network_admin = true;
1094
-
1095
- return apply_filters( 'bp_core_do_network_admin', $do_network_admin );
1096
- }
1097
-
1098
- function bp_core_admin_hook() {
1099
- $hook = bp_core_do_network_admin() ? 'network_admin_menu' : 'admin_menu';
1100
-
1101
- return apply_filters( 'bp_core_admin_hook', $hook );
1102
- }
1103
-
1104
  /** Global Manipulators *******************************************************/
1105
 
1106
  /**
1107
  * Set the $bp->is_directory global
1108
  *
1109
- * @global BuddyPress $bp The one true BuddyPress instance
1110
  * @param bool $is_directory
1111
  * @param str $component
1112
  */
@@ -1122,7 +1425,7 @@ function bp_update_is_directory( $is_directory = false, $component = '' ) {
1122
  /**
1123
  * Set the $bp->is_item_admin global
1124
  *
1125
- * @global BuddyPress $bp The one true BuddyPress instance
1126
  * @param bool $is_item_admin
1127
  * @param str $component
1128
  */
@@ -1138,7 +1441,7 @@ function bp_update_is_item_admin( $is_item_admin = false, $component = '' ) {
1138
  /**
1139
  * Set the $bp->is_item_mod global
1140
  *
1141
- * @global BuddyPress $bp The one true BuddyPress instance
1142
  * @param bool $is_item_mod
1143
  * @param str $component
1144
  */
@@ -1154,13 +1457,13 @@ function bp_update_is_item_mod( $is_item_mod = false, $component = '' ) {
1154
  /**
1155
  * Trigger a 404
1156
  *
1157
- * @global BuddyPress $bp The one true BuddyPress instance
1158
  * @global WP_Query $wp_query WordPress query object
1159
  * @param string $redirect If 'remove_canonical_direct', remove WordPress' "helpful" redirect_canonical action.
1160
- * @since BuddyPress (1.5)
1161
  */
1162
  function bp_do_404( $redirect = 'remove_canonical_direct' ) {
1163
- global $wp_query;
1164
 
1165
  do_action( 'bp_do_404', $redirect );
1166
 
@@ -1171,5 +1474,4 @@ function bp_do_404( $redirect = 'remove_canonical_direct' ) {
1171
  if ( 'remove_canonical_direct' == $redirect )
1172
  remove_action( 'template_redirect', 'redirect_canonical' );
1173
  }
1174
-
1175
  ?>
1
  <?php
 
 
 
 
 
 
 
 
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
 
 
5
  /**
6
+ * Retrieve an option
7
  *
8
+ * This is a wrapper for get_blog_option(), which in turn stores settings data (such as bp-pages)
9
+ * on the appropriate blog, given your current setup.
10
+ *
11
+ * The 'bp_get_option' filter is primarily for backward-compatibility.
12
+ *
13
+ * @package BuddyPress
14
+ * @since 1.5
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  *
16
+ * @uses bp_get_root_blog_id()
17
+ * @param str $option_name The option to be retrieved
18
+ * @param str $default Optional. Default value to be returned if the option isn't set
19
+ * @return mixed The value for the option
20
  */
21
+ function bp_get_option( $option_name, $default = '' ) {
22
+ $value = get_blog_option( bp_get_root_blog_id(), $option_name, $default );
23
+
24
+ return apply_filters( 'bp_get_option', $value );
25
  }
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  /**
28
+ * Save an option
29
+ *
30
+ * This is a wrapper for update_blog_option(), which in turn stores settings data (such as bp-pages)
31
+ * on the appropriate blog, given your current setup.
32
+ *
33
+ * @package BuddyPress
34
+ * @since 1.5
35
  *
36
+ * @uses bp_get_root_blog_id()
37
+ * @param str $option_name The option key to be set
38
+ * @param str $value The value to be set
39
  */
40
+ function bp_update_option( $option_name, $value ) {
41
+ update_blog_option( bp_get_root_blog_id(), $option_name, $value );
42
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
  /**
45
+ * Delete an option
46
+ *
47
+ * This is a wrapper for delete_blog_option(), which in turn deletes settings data (such as
48
+ * bp-pages) on the appropriate blog, given your current setup.
49
+ *
50
+ * @package BuddyPress
51
+ * @since 1.5
52
  *
53
+ * @uses bp_get_root_blog_id()
54
+ * @param str $option_name The option key to be set
55
  */
56
+ function bp_delete_option( $option_name ) {
57
+ delete_blog_option( bp_get_root_blog_id(), $option_name );
58
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
  /**
61
  * Allow filtering of database prefix. Intended for use in multinetwork installations.
73
  * Fetches BP pages from the meta table, depending on setup
74
  *
75
  * @package BuddyPress Core
76
+ * @since 1.5
77
+ *
78
+ * @todo Remove the "Upgrading from an earlier version of BP pre-1.5" block. Temporary measure for
79
+ * people running trunk installations. Leave for a version or two, then remove.
80
  */
81
  function bp_core_get_directory_page_ids() {
82
  $page_ids = bp_get_option( 'bp-pages' );
83
 
84
+ // Upgrading from an earlier version of BP pre-1.5
85
+ if ( !isset( $page_ids['members'] ) && $ms_page_ids = get_site_option( 'bp-pages' ) ) {
86
+ $page_blog_id = bp_is_multiblog_mode() ? get_current_blog_id() : bp_get_root_blog_id();
87
+
88
+ if ( isset( $ms_page_ids[$page_blog_id] ) ) {
89
+ $page_ids = $ms_page_ids[$page_blog_id];
90
+
91
+ bp_update_option( 'bp-pages', $page_ids );
92
+ }
93
+ }
94
+
95
  // Ensure that empty indexes are unset. Should only matter in edge cases
96
+ if ( $page_ids && is_array( $page_ids ) ) {
97
+ foreach( (array)$page_ids as $component_name => $page_id ) {
98
  if ( empty( $component_name ) || empty( $page_id ) ) {
99
  unset( $page_ids[$component_name] );
100
  }
111
  * blog_id. This allows you to change your bp_get_root_blog_id() and go through the setup process again.
112
  *
113
  * @package BuddyPress Core
114
+ * @since 1.5
115
  *
116
  * @param array $blog_page_ids The IDs of the WP pages corresponding to BP component directories
117
  */
123
  * Get bp-pages names and slugs
124
  *
125
  * @package BuddyPress Core
126
+ * @since 1.5
127
  *
128
  * @return obj $pages Page names, IDs, and slugs
129
  */
130
  function bp_core_get_directory_pages() {
131
+ global $wpdb, $bp;
132
 
133
  // Set pages as standard class
134
  $pages = new stdClass;
135
 
136
  // Get pages and IDs
137
+ if ( $page_ids = bp_core_get_directory_page_ids() ) {
 
138
 
139
  // Always get page data from the root blog, except on multiblog mode, when it comes
140
  // from the current blog
141
  $posts_table_name = bp_is_multiblog_mode() ? $wpdb->posts : $wpdb->get_blog_prefix( bp_get_root_blog_id() ) . 'posts';
142
+ $page_ids_sql = implode( ',', (array)$page_ids );
143
  $page_names = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent, post_title FROM {$posts_table_name} WHERE ID IN ({$page_ids_sql}) AND post_status = 'publish' " ) );
144
 
145
+ foreach ( (array)$page_ids as $component_id => $page_id ) {
146
+ foreach ( (array)$page_names as $page_name ) {
147
  if ( $page_name->ID == $page_id ) {
 
 
 
 
148
  $pages->{$component_id}->name = $page_name->post_name;
149
  $pages->{$component_id}->id = $page_name->ID;
150
  $pages->{$component_id}->title = $page_name->post_title;
157
  $page_name->post_parent = $parent[0]->post_parent;
158
  }
159
 
160
+ $pages->{$component_id}->slug = implode( '/', array_reverse( (array)$slug ) );
161
  }
162
 
163
  unset( $slug );
186
  * to override specific component slugs.
187
  *
188
  * @package BuddyPress Core
189
+ * @since 1.5
190
  *
191
  * @param str $root_slug The root slug, which comes from $bp->pages->[component]->slug
192
  * @return str $slug The short slug for use in the middle of URLs
198
  return apply_filters( 'bp_core_component_slug_from_root_slug', $slug, $root_slug );
199
  }
200
 
201
+ function bp_core_do_network_admin() {
202
+ $do_network_admin = false;
203
+
204
+ if ( is_multisite() && !bp_is_multiblog_mode() )
205
+ $do_network_admin = true;
206
+
207
+ return apply_filters( 'bp_core_do_network_admin', $do_network_admin );
208
+ }
209
+
210
+ function bp_core_admin_hook() {
211
+ $hook = bp_core_do_network_admin() ? 'network_admin_menu' : 'admin_menu';
212
+
213
+ return apply_filters( 'bp_core_admin_hook', $hook );
214
+ }
215
+
216
+ /**
217
+ * Initializes the wp-admin area "BuddyPress" menus and sub menus.
218
+ *
219
+ * @package BuddyPress Core
220
+ * @uses is_super_admin() returns true if the current user is a site admin, false if not
221
+ */
222
+ function bp_core_admin_menu_init() {
223
+ if ( !is_super_admin() )
224
+ return false;
225
+
226
+ add_action( bp_core_admin_hook(), 'bp_core_add_admin_menu', 9 );
227
+
228
+ require ( BP_PLUGIN_DIR . '/bp-core/admin/bp-core-admin.php' );
229
+ }
230
+ add_action( 'bp_init', 'bp_core_admin_menu_init' );
231
+
232
+ /**
233
+ * Adds the "BuddyPress" admin submenu item to the Site Admin tab.
234
+ *
235
+ * @package BuddyPress Core
236
+ * @global object $bp Global BuddyPress settings object
237
+ * @uses is_super_admin() returns true if the current user is a site admin, false if not
238
+ * @uses add_submenu_page() WP function to add a submenu item
239
+ */
240
+ function bp_core_add_admin_menu() {
241
+ if ( !is_super_admin() )
242
+ return false;
243
+
244
+ // Don't add this version of the admin menu if a BP upgrade is in progress
245
+ // See bp_core_update_add_admin_menu()
246
+ if ( defined( 'BP_IS_UPGRADE' ) && BP_IS_UPGRADE )
247
+ return false;
248
+
249
+ $hooks = array();
250
+
251
+ // Add the administration tab under the "Site Admin" tab for site administrators
252
+ $hooks[] = add_menu_page( __( 'BuddyPress', 'buddypress' ), __( 'BuddyPress', 'buddypress' ), 'manage_options', 'bp-general-settings', 'bp_core_admin_component_setup', '' );
253
+ $hooks[] = add_submenu_page( 'bp-general-settings', __( 'Components', 'buddypress' ), __( 'Components', 'buddypress' ), 'manage_options', 'bp-general-settings', 'bp_core_admin_component_setup' );
254
+ $hooks[] = add_submenu_page( 'bp-general-settings', __( 'Pages', 'buddypress' ), __( 'Pages', 'buddypress' ), 'manage_options', 'bp-page-settings', 'bp_core_admin_page_setup' );
255
+ $hooks[] = add_submenu_page( 'bp-general-settings', __( 'Settings', 'buddypress' ), __( 'Settings', 'buddypress' ), 'manage_options', 'bp-settings', 'bp_core_admin_settings' );
256
+
257
+ // Add a hook for css/js
258
+ foreach( $hooks as $hook )
259
+ add_action( "admin_print_styles-$hook", 'bp_core_add_admin_menu_styles' );
260
+ }
261
+
262
+ /**
263
+ * Print admin messages to admin_notices or network_admin_notices
264
+ *
265
+ * BuddyPress combines all its messages into a single notice, to avoid a preponderance of yellow
266
+ * boxes.
267
+ *
268
+ * @package BuddyPress Core
269
+ * @since 1.5
270
+ *
271
+ * @global object $bp Global BuddyPress settings object
272
+ * @uses is_super_admin() to check current user permissions before showing the notices
273
+ * @uses bp_is_root_blog()
274
+ */
275
+ function bp_core_print_admin_notices() {
276
+ global $bp;
277
+
278
+ // Only the super admin should see messages
279
+ if ( !is_super_admin() )
280
+ return;
281
+
282
+ // On multisite installs, don't show on the Site Admin of a non-root blog, unless
283
+ // do_network_admin is overridden
284
+ if ( is_multisite() && bp_core_do_network_admin() && !bp_is_root_blog() )
285
+ return;
286
+
287
+ // Show the messages
288
+ if ( !empty( $bp->admin->notices ) ) {
289
+ ?>
290
+ <div id="message" class="updated fade">
291
+ <?php foreach( $bp->admin->notices as $notice ) : ?>
292
+ <p><?php echo $notice ?></p>
293
+ <?php endforeach ?>
294
+ </div>
295
+ <?php
296
+ }
297
+ }
298
+ add_action( 'admin_notices', 'bp_core_print_admin_notices' );
299
+ add_action( 'network_admin_notices', 'bp_core_print_admin_notices' );
300
+
301
+ /**
302
+ * Add an admin notice to the BP queue
303
+ *
304
+ * Messages added with this function are displayed in BuddyPress's general purpose admin notices
305
+ * box. It is recommended that you hook this function to admin_init, so that your messages are
306
+ * loaded in time.
307
+ *
308
+ * @package BuddyPress Core
309
+ * @since 1.5
310
+ *
311
+ * @global object $bp Global BuddyPress settings object
312
+ * @param string $notice The notice you are adding to the queue
313
+ */
314
+ function bp_core_add_admin_notice( $notice ) {
315
+ global $bp;
316
+
317
+ if ( empty( $bp->admin->notices ) ) {
318
+ $bp->admin->notices = array();
319
+ }
320
+
321
+ $bp->admin->notices[] = $notice;
322
+ }
323
+
324
+ /**
325
+ * Verify that some BP prerequisites are set up properly, and notify the admin if not
326
+ *
327
+ * On every Dashboard page, this function checks the following:
328
+ * - that pretty permalinks are enabled
329
+ * - that a BP-compatible theme is activated
330
+ * - that every BP component that needs a WP page for a directory has one
331
+ * - that no WP page has multiple BP components associated with it
332
+ * The administrator will be shown a notice for each check that fails.
333
+ *
334
+ * @package BuddyPress Core
335
+ */
336
+ function bp_core_activation_notice() {
337
+ global $wp_rewrite, $wpdb, $bp;
338
+
339
+ // Only the super admin gets warnings
340
+ if ( !is_super_admin() )
341
+ return;
342
+
343
+ // On multisite installs, don't load on a non-root blog, unless do_network_admin is
344
+ // overridden
345
+ if ( is_multisite() && bp_core_do_network_admin() && !bp_is_root_blog() )
346
+ return;
347
+
348
+ // Don't show these messages during setup or upgrade
349
+ if ( isset( $bp->maintenance_mode ) )
350
+ return;
351
+
352
+ /**
353
+ * Check to make sure that the blog setup routine has run. This can't happen during the
354
+ * wizard because of the order which the components are loaded. We check for multisite here
355
+ * on the off chance that someone has activated the blogs component and then disabled MS
356
+ */
357
+ if ( bp_is_active( 'blogs' ) ) {
358
+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$bp->blogs->table_name}" ) );
359
+
360
+ if ( !$count )
361
+ bp_blogs_record_existing_blogs();
362
+ }
363
+
364
+ /**
365
+ * Are pretty permalinks enabled?
366
+ */
367
+ if ( isset( $_POST['permalink_structure'] ) )
368
+ return false;
369
+
370
+ if ( empty( $wp_rewrite->permalink_structure ) ) {
371
+ 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' ) ) );
372
+ }
373
+
374
+ /**
375
+ * Are you using a BP-compatible theme?
376
+ */
377
+
378
+ // Get current theme info
379
+ // Backward-compatibility with WP < 3.4 will be removed in a future release
380
+ if ( function_exists( 'wp_get_theme' ) ) {
381
+ $ct = wp_get_theme();
382
+ } else {
383
+ $ct = current_theme_info();
384
+ }
385
+
386
+ // The best way to remove this notice is to add a "buddypress" tag to
387
+ // your active theme's CSS header.
388
+ if ( !defined( 'BP_SILENCE_THEME_NOTICE' ) && !in_array( 'buddypress', (array)$ct->tags ) ) {
389
+ bp_core_add_admin_notice( sprintf( __( "You'll need to <a href='%s'>activate a <strong>BuddyPress-compatible theme</strong></a> to take advantage of all of BuddyPress's features. We've bundled a default theme, but you can always <a href='%s'>install some other compatible themes</a> or <a href='%s'>update your existing WordPress theme</a>.", 'buddypress' ), admin_url( 'themes.php' ), network_admin_url( 'theme-install.php?type=tag&s=buddypress&tab=search' ), network_admin_url( 'plugin-install.php?type=term&tab=search&s=%22bp-template-pack%22' ) ) );
390
+ }
391
+
392
+ /**
393
+ * Check for orphaned BP components (BP component is enabled, no WP page exists)
394
+ */
395
+
396
+ $orphaned_components = array();
397
+ $wp_page_components = array();
398
+
399
+ // Only components with 'has_directory' require a WP page to function
400
+ foreach( $bp->loaded_components as $component_id => $is_active ) {
401
+ if ( !empty( $bp->{$component_id}->has_directory ) ) {
402
+ $wp_page_components[] = array(
403
+ 'id' => $component_id,
404
+ 'name' => isset( $bp->{$component_id}->name ) ? $bp->{$component_id}->name : ucwords( $bp->{$component_id}->id )
405
+ );
406
+ }
407
+ }
408
+
409
+ // Activate and Register are special cases. They are not components but they need WP pages.
410
+ // If user registration is disabled, we can skip this step.
411
+ if ( bp_get_signup_allowed() ) {
412
+ $wp_page_components[] = array(
413
+ 'id' => 'activate',
414
+ 'name' => __( 'Activate', 'buddypress' )
415
+ );
416
+
417
+ $wp_page_components[] = array(
418
+ 'id' => 'register',
419
+ 'name' => __( 'Register', 'buddypress' )
420
+ );
421
+ }
422
+
423
+ foreach( $wp_page_components as $component ) {
424
+ if ( !isset( $bp->pages->{$component['id']} ) ) {
425
+ $orphaned_components[] = $component['name'];
426
+ }
427
+ }
428
+
429
+ if ( !empty( $orphaned_components ) ) {
430
+ $admin_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) );
431
+ $notice = sprintf( __( 'The following active BuddyPress Components do not have associated WordPress Pages: %2$s. <a href="%1$s" class="button-secondary">Repair</a>', 'buddypress' ), $admin_url, '<strong>' . implode( '</strong>, <strong>', $orphaned_components ) . '</strong>' );
432
+
433
+ bp_core_add_admin_notice( $notice );
434
+ }
435
+
436
+ /**
437
+ * BP components cannot share a single WP page. Check for duplicate assignments, and post
438
+ * a message if found.
439
+ */
440
+ $dupe_names = array();
441
+ $page_ids = (array)bp_core_get_directory_page_ids();
442
+ $dupes = array_diff_assoc( $page_ids, array_unique( $page_ids ) );
443
+
444
+ if ( !empty( $dupes ) ) {
445
+ foreach( $dupes as $dupe_component => $dupe_id ) {
446
+ $dupe_names[] = $bp->pages->{$dupe_component}->title;
447
+ }
448
+
449
+ // Make sure that there are no duplicate duplicates :)
450
+ $dupe_names = array_unique( $dupe_names );
451
+ }
452
+
453
+ // If there are duplicates, post a message about them
454
+ if ( !empty( $dupe_names ) ) {
455
+ $admin_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) );
456
+ $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" class="button-secondary">Repair</a>', 'buddypress' ), $admin_url, '<strong>' . implode( '</strong>, <strong>', $dupe_names ) . '</strong>' );
457
+
458
+ bp_core_add_admin_notice( $notice );
459
+ }
460
+ }
461
+ add_action( 'admin_init', 'bp_core_activation_notice' );
462
+
463
  /**
464
  * Returns the domain for the root blog.
465
  * eg: http://domain.com/ OR https://domain.com
469
  * @return $domain The domain URL for the blog.
470
  */
471
  function bp_core_get_root_domain() {
472
+ global $wpdb;
473
 
474
  $domain = get_home_url( bp_get_root_blog_id() );
475
 
495
  *
496
  * @package BuddyPress Core
497
  *
498
+ * @global obj $bp
499
  * @param str $message Feedback to give to user
500
  * @param str $type updated|success|error|warning
501
  */
552
  * The hook action 'template_notices' is used to call this function, it is not called directly.
553
  *
554
  * @package BuddyPress Core
555
+ * @global object $bp Global BuddyPress settings object
556
  */
557
  function bp_core_render_message() {
558
  global $bp;
582
  * @return str
583
  */
584
  function bp_core_number_format( $number, $decimals = false ) {
585
+ // Check we actually have a number first.
 
586
  if ( empty( $number ) )
587
+ return $number;
588
 
589
+ return apply_filters( 'bp_core_number_format', number_format( $number, $decimals ), $number, $decimals );
590
  }
591
 
592
  /**
624
  if ( !empty( $older_date ) && !is_numeric( $older_date ) ) {
625
  $time_chunks = explode( ':', str_replace( ' ', ':', $older_date ) );
626
  $date_chunks = explode( '-', str_replace( ' ', '-', $older_date ) );
627
+ $older_date = gmmktime( (int)$time_chunks[1], (int)$time_chunks[2], (int)$time_chunks[3], (int)$date_chunks[1], (int)$date_chunks[2], (int)$date_chunks[0] );
628
  }
629
 
630
  /**
654
  $seconds = $chunks[$i][0];
655
 
656
  // Finding the biggest chunk (if the chunk fits, break)
657
+ if ( ( $count = floor($since / $seconds) ) != 0 ) {
 
658
  break;
659
  }
660
  }
671
  // Step two: the second chunk
672
  if ( $i + 2 < $j ) {
673
  $seconds2 = $chunks[$i + 1][0];
674
+ $name2 = $chunks[$i + 1][1];
 
675
 
676
+ if ( ( $count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 ) ) != 0 ) {
677
+ // Add to output var
678
+ $output .= ( 1 == $count2 ) ? _x( ',', 'Separator in time since', 'buddypress' ) . ' 1 '. $chunks[$i + 1][1] : _x( ',', 'Separator in time since', 'buddypress' ) . ' ' . $count2 . ' ' . $chunks[$i + 1][2];
679
  }
680
  }
681
 
682
  // No output, so happened right now
683
+ if ( !(int)trim( $output ) ) {
684
  $output = $right_now_text;
685
  }
686
  }
704
  * @uses bp_update_user_meta() BP function to update user metadata in the usermeta table.
705
  */
706
  function bp_core_record_activity() {
707
+ global $bp;
708
 
709
  if ( !is_user_logged_in() )
710
  return false;
711
 
712
+ $user_id = $bp->loggedin_user->id;
713
 
714
+ if ( bp_core_is_user_spammer( $user_id ) || bp_core_is_user_deleted( $user_id ) )
715
  return false;
716
 
717
  $activity = bp_get_user_meta( $user_id, 'last_activity', true );
722
  // Get current time
723
  $current_time = bp_core_current_time();
724
 
 
 
 
 
 
725
  if ( empty( $activity ) || strtotime( $current_time ) >= strtotime( '+5 minutes', $activity ) )
726
  bp_update_user_meta( $user_id, 'last_activity', $current_time );
727
  }
737
  * @uses bp_core_time_since() This function will return an English representation of the time elapsed.
738
  */
739
  function bp_core_get_last_activity( $last_activity_date, $string ) {
740
+ if ( !$last_activity_date || empty( $last_activity_date ) )
741
+ $last_active = __( 'not recently active', 'buddypress' );
 
742
  else
743
  $last_active = sprintf( $string, bp_core_time_since( $last_activity_date ) );
744
 
750
  *
751
  * @package BuddyPress Core
752
  *
753
+ * @global $bp $bp
754
  * @global object $current_site
755
  * @return string
756
  */
757
  function bp_core_get_site_path() {
758
+ global $bp, $current_site;
759
 
760
  if ( is_multisite() )
761
  $site_path = $current_site->path;
784
  * Performs a status safe wp_redirect() that is compatible with bp_catch_uri()
785
  *
786
  * @package BuddyPress Core
787
+ * @global $bp_no_status_set Makes sure that there are no conflicts with status_header() called in bp_core_do_catch_uri()
788
+ * @uses get_themes()
789
+ * @return An array containing all of the themes.
790
  */
791
  function bp_core_redirect( $location, $status = 302 ) {
792
+ global $bp_no_status_set;
 
 
 
 
 
 
793
 
794
  // Make sure we don't call status_header() in bp_core_do_catch_uri()
795
  // as this conflicts with wp_redirect()
796
+ $bp_no_status_set = true;
797
 
798
  wp_redirect( $location, $status );
799
  die;
825
  * A javascript free implementation of the search functions in BuddyPress
826
  *
827
  * @package BuddyPress Core
828
+ * @global object $bp Global BuddyPress settings object
829
  * @param string $slug The slug to redirect to for searching.
830
  */
831
  function bp_core_action_search_site( $slug = '' ) {
832
+ global $bp;
833
 
834
  if ( !bp_is_current_component( bp_get_search_slug() ) )
835
  return;
912
  $locale = apply_filters( 'buddypress_locale', get_locale() );
913
  $mofile = sprintf( 'buddypress-%s.mo', $locale );
914
  $mofile_global = WP_LANG_DIR . '/' . $mofile;
915
+ $mofile_local = BP_PLUGIN_DIR . '/bp-languages/' . $mofile;
916
 
917
  if ( file_exists( $mofile_global ) )
918
  return load_textdomain( 'buddypress', $mofile_global );
921
  else
922
  return false;
923
  }
924
+ add_action ( 'bp_init', 'bp_core_load_buddypress_textdomain', 2 );
925
+
926
+ function bp_core_add_ajax_hook() {
927
+ // Theme only, we already have the wp_ajax_ hook firing in wp-admin
928
+ if ( !defined( 'WP_ADMIN' ) && isset( $_REQUEST['action'] ) )
929
+ do_action( 'wp_ajax_' . $_REQUEST['action'] );
930
+ }
931
+ add_action( 'bp_init', 'bp_core_add_ajax_hook' );
932
 
933
  /**
934
  * Initializes {@link BP_Embed} after everything is loaded.
935
  *
936
  * @global object $bp BuddyPress global settings
937
  * @package BuddyPress Core
938
+ * @since 1.5
939
  */
940
  function bp_embed_init() {
941
  global $bp;
945
  }
946
  add_action( 'bp_init', 'bp_embed_init', 9 );
947
 
948
+ /**
949
+ * When switching from single to multisite we need to copy blog options to
950
+ * site options.
951
+ *
952
+ * @package BuddyPress Core
953
+ * @todo Does this need to be here anymore after the introduction of bp_get_option etc?
954
+ */
955
+ function bp_core_activate_site_options( $keys = array() ) {
956
+ global $bp;
957
+
958
+ if ( !empty( $keys ) && is_array( $keys ) ) {
959
+ $errors = false;
960
+
961
+ foreach ( $keys as $key => $default ) {
962
+ if ( empty( $bp->site_options[ $key ] ) ) {
963
+ $bp->site_options[ $key ] = bp_get_option( $key, $default );
964
+
965
+ if ( !bp_update_option( $key, $bp->site_options[ $key ] ) )
966
+ $errors = true;
967
+ }
968
+ }
969
+
970
+ if ( empty( $errors ) )
971
+ return true;
972
+ }
973
+
974
+ return false;
975
+ }
976
+
977
+ /**
978
+ * BuddyPress uses common options to store configuration settings. Many of these
979
+ * settings are needed at run time. Instead of fetching them all and adding many
980
+ * initial queries to each page load, let's fetch them all in one go.
981
+ *
982
+ * @package BuddyPress Core
983
+ * @todo Use settings API and audit these methods
984
+ */
985
+ function bp_core_get_root_options() {
986
+ global $wpdb;
987
+
988
+ // These options come from the root blog options table
989
+ $root_blog_options = apply_filters( 'bp_core_site_options', array(
990
+
991
+ // BuddyPress core settings
992
+ 'bp-deactivated-components' => serialize( array( ) ),
993
+ 'bp-blogs-first-install' => '0',
994
+ 'bp-disable-blogforum-comments' => '0',
995
+ 'bp-xprofile-base-group-name' => 'Base',
996
+ 'bp-xprofile-fullname-field-name' => 'Name',
997
+ 'bp-disable-profile-sync' => '0',
998
+ 'bp-disable-avatar-uploads' => '0',
999
+ 'bp-disable-account-deletion' => '0',
1000
+ 'bp-disable-blogforum-comments' => '0',
1001
+ 'bb-config-location' => ABSPATH . 'bb-config.php',
1002
+ 'hide-loggedout-adminbar' => '0',
1003
+
1004
+ // Useful WordPress settings
1005
+ 'registration' => '0',
1006
+ 'avatar_default' => 'mysteryman'
1007
+ ) );
1008
+
1009
+ $root_blog_option_keys = array_keys( $root_blog_options );
1010
+ $blog_options_keys = "'" . join( "', '", (array) $root_blog_option_keys ) . "'";
1011
+ $blog_options_table = bp_is_multiblog_mode() ? $wpdb->options : $wpdb->get_blog_prefix( bp_get_root_blog_id() ) . 'options';
1012
+
1013
+ $blog_options_query = $wpdb->prepare( "SELECT option_name AS name, option_value AS value FROM {$blog_options_table} WHERE option_name IN ( {$blog_options_keys} )" );
1014
+ $root_blog_options_meta = $wpdb->get_results( $blog_options_query );
1015
+
1016
+ // On Multisite installations, some options must always be fetched from sitemeta
1017
+ if ( is_multisite() ) {
1018
+ $network_options = apply_filters( 'bp_core_network_options', array(
1019
+ 'tags_blog_id' => '0',
1020
+ 'sitewide_tags_blog' => '',
1021
+ 'registration' => '0',
1022
+ 'fileupload_maxk' => '1500'
1023
+ ) );
1024
+
1025
+ $current_site = get_current_site();
1026
+ $network_option_keys = array_keys( $network_options );
1027
+ $sitemeta_options_keys = "'" . join( "', '", (array) $network_option_keys ) . "'";
1028
+ $sitemeta_options_query = $wpdb->prepare( "SELECT meta_key AS name, meta_value AS value FROM {$wpdb->sitemeta} WHERE meta_key IN ( {$sitemeta_options_keys} ) AND site_id = %d", $current_site->id );
1029
+ $network_options_meta = $wpdb->get_results( $sitemeta_options_query );
1030
+
1031
+ // Sitemeta comes second in the merge, so that network 'registration' value wins
1032
+ $root_blog_options_meta = array_merge( $root_blog_options_meta, $network_options_meta );
1033
+ }
1034
+
1035
+ // Missing some options, so do some one-time fixing
1036
+ if ( empty( $root_blog_options_meta ) || ( count( $root_blog_options_meta ) < count( $root_blog_option_keys ) ) ) {
1037
+
1038
+ // Unset the query - We'll be resetting it soon
1039
+ unset( $root_blog_options_meta );
1040
+
1041
+ // Loop through options
1042
+ foreach ( $root_blog_options as $old_meta_key => $old_meta_default ) {
1043
+ // Clear out the value from the last time around
1044
+ unset( $old_meta_value );
1045
+
1046
+ // Get old site option
1047
+ if ( is_multisite() )
1048
+ $old_meta_value = get_site_option( $old_meta_key );
1049
+
1050
+ // No site option so look in root blog
1051
+ if ( empty( $old_meta_value ) )
1052
+ $old_meta_value = bp_get_option( $old_meta_key, $old_meta_default );
1053
+
1054
+ // Update the root blog option
1055
+ bp_update_option( $old_meta_key, $old_meta_value );
1056
+
1057
+ // Update the global array
1058
+ $root_blog_options_meta[$old_meta_key] = $old_meta_value;
1059
+ }
1060
+
1061
+ // We're all matched up
1062
+ } else {
1063
+ // Loop through our results and make them usable
1064
+ foreach ( $root_blog_options_meta as $root_blog_option )
1065
+ $root_blog_options[$root_blog_option->name] = $root_blog_option->value;
1066
+
1067
+ // Copy the options no the return val
1068
+ $root_blog_options_meta = $root_blog_options;
1069
+
1070
+ // Clean up our temporary copy
1071
+ unset( $root_blog_options );
1072
+ }
1073
+
1074
+ return apply_filters( 'bp_core_get_root_options', $root_blog_options_meta );
1075
+ }
1076
+
1077
  /**
1078
  * This function originally let plugins add support for pages in the root of the install.
1079
  * These root level pages are now handled by actual WordPress pages and this function is now
1091
  $match = false;
1092
 
1093
  // Check if the slug is registered in the $bp->pages global
1094
+ foreach ( (array)$bp->pages as $key => $page ) {
1095
  if ( $key == $slug || $page->slug == $slug )
1096
  $match = true;
1097
  }
1113
 
1114
  $new_page_ids = array();
1115
 
1116
+ foreach ( (array)$bp->add_root as $slug )
1117
  $new_page_ids[$slug] = wp_insert_post( array( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_title' => ucwords( $slug ), 'post_status' => 'publish', 'post_type' => 'page' ) );
1118
 
1119
  $page_ids = array_merge( (array) $new_page_ids, (array) bp_core_get_directory_page_ids() );
1124
  * Is this the root blog ID?
1125
  *
1126
  * @package BuddyPress
1127
+ * @since 1.5
1128
  *
1129
  * @param int $blog_id Optional. Defaults to the current blog id.
1130
  * @return bool $is_root_blog Returns true if this is bp_get_root_blog_id().
1131
  */
1132
  function bp_is_root_blog( $blog_id = 0 ) {
 
1133
  // Assume false
1134
  $is_root_blog = false;
1135
 
1141
  if ( $blog_id == bp_get_root_blog_id() )
1142
  $is_root_blog = true;
1143
 
1144
+ return apply_filters( 'bp_is_root_blog', (bool) $is_root_blog );
1145
  }
1146
 
1147
  /**
1148
  * Is this bp_get_root_blog_id()?
1149
  *
1150
  * @package BuddyPress
1151
+ * @since 1.5
1152
  *
1153
+ * @param int $blog_id Optional. Defaults to the current blog id.
1154
+ * @return bool $is_root_blog Returns true if this is bp_get_root_blog_id().
1155
  */
1156
+ function bp_get_root_blog_id( $blog_id = false ) {
1157
+
1158
+ // Define on which blog ID BuddyPress should run
1159
+ if ( !defined( 'BP_ROOT_BLOG' ) ) {
1160
+
1161
+ // Root blog is the main site on this network
1162
+ if ( is_multisite() && !bp_is_multiblog_mode() ) {
1163
+ $current_site = get_current_site();
1164
+ $root_blog_id = $current_site->blog_id;
1165
+
1166
+ // Root blog is whatever the current site is (could be any site on the network)
1167
+ } elseif ( is_multisite() && bp_is_multiblog_mode() ) {
1168
+ $root_blog_id = get_current_blog_id();
1169
 
1170
+ // Root blog is the only blog on this network
1171
+ } elseif( !is_multisite() ) {
1172
+ $root_blog_id = 1;
1173
+ }
1174
+
1175
+ define( 'BP_ROOT_BLOG', $root_blog_id );
1176
+
1177
+ // Root blog is defined
1178
+ } else {
1179
+ $root_blog_id = BP_ROOT_BLOG;
1180
+ }
1181
+
1182
+ return apply_filters( 'bp_get_root_blog_id', (int) $root_blog_id );
1183
  }
1184
 
1185
  /**
1196
  * If using the WP functions, do not not hardcode your meta keys.
1197
  *
1198
  * @package BuddyPress
1199
+ * @since 1.5
1200
  *
1201
  * @uses apply_filters() Filter bp_get_user_meta_key to modify keys individually
1202
  * @param str $key
1213
  * increasing compatibility with non-standard BP setups.
1214
  *
1215
  * @package BuddyPress
1216
+ * @since 1.5
1217
  *
1218
  * @uses bp_get_user_meta_key() For a filterable version of the meta key
1219
  * @uses get_user_meta() See get_user_meta() docs for more details on parameters
1234
  * thereby increasing compatibility with non-standard BP setups.
1235
  *
1236
  * @package BuddyPress
1237
+ * @since 1.5
1238
  *
1239
  * @uses bp_get_user_meta_key() For a filterable version of the meta key
1240
  * @uses update_user_meta() See update_user_meta() docs for more details on parameters
1255
  * thereby increasing compatibility with non-standard BP setups.
1256
  *
1257
  * @package BuddyPress
1258
+ * @since 1.5
1259
  *
1260
  * @uses bp_get_user_meta_key() For a filterable version of the meta key
1261
  * @uses delete_user_meta() See delete_user_meta() docs for more details on parameters
1272
  * Are we running username compatibility mode?
1273
  *
1274
  * @package BuddyPress
1275
+ * @since 1.5
1276
  *
1277
  * @uses apply_filters() Filter 'bp_is_username_compatibility_mode' to alter
1278
  * @return bool False when compatibility mode is disabled (default); true when enabled
1296
  * blog.
1297
  *
1298
  * @package BuddyPress
1299
+ * @since 1.5
1300
  *
1301
  * @uses apply_filters() Filter 'bp_is_multiblog_mode' to alter
1302
  * @return bool False when multiblog mode is disabled (default); true when enabled
1306
  }
1307
 
1308
  /**
1309
+ * Should we use the WP admin bar?
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1310
  *
1311
+ * The WP Admin Bar, introduced in WP 3.1, is fully supported in BuddyPress as of BP 1.5.
 
1312
  *
1313
+ * For the BP 1.5 development cycle, the BuddyBar will remain the default navigation for BP
1314
+ * installations. In the future, this behavior will be changed, so that the WP Admin Bar is the
1315
+ * default.
 
 
 
1316
  *
1317
+ * @package BuddyPress
1318
+ * @since 1.5
1319
  *
1320
+ * @uses apply_filters() Filter 'bp_use_wp_admin_bar' to alter
1321
+ * @return bool False when WP Admin Bar support is disabled (default); true when enabled
 
 
1322
  */
1323
+ function bp_use_wp_admin_bar() {
1324
+ return apply_filters( 'bp_use_wp_admin_bar', defined( 'BP_USE_WP_ADMIN_BAR' ) && BP_USE_WP_ADMIN_BAR );
 
 
 
 
 
 
 
 
1325
  }
1326
 
 
 
1327
  /**
1328
  * Are oembeds allowed in activity items?
1329
  *
1330
  * @return bool False when activity embed support is disabled; true when enabled (default)
1331
+ * @since 1.5
1332
  */
1333
  function bp_use_embed_in_activity() {
1334
  return apply_filters( 'bp_use_oembed_in_activity', !defined( 'BP_EMBED_DISABLE_ACTIVITY' ) || !BP_EMBED_DISABLE_ACTIVITY );
1338
  * Are oembeds allwoed in activity replies?
1339
  *
1340
  * @return bool False when activity replies embed support is disabled; true when enabled (default)
1341
+ * @since 1.5
1342
  */
1343
  function bp_use_embed_in_activity_replies() {
1344
  return apply_filters( 'bp_use_embed_in_activity_replies', !defined( 'BP_EMBED_DISABLE_ACTIVITY_REPLIES' ) || !BP_EMBED_DISABLE_ACTIVITY_REPLIES );
1348
  * Are oembeds allowed in forum posts?
1349
  *
1350
  * @return bool False when form post embed support is disabled; true when enabled (default)
1351
+ * @since 1.5
1352
  */
1353
  function bp_use_embed_in_forum_posts() {
1354
  return apply_filters( 'bp_use_embed_in_forum_posts', !defined( 'BP_EMBED_DISABLE_FORUM_POSTS' ) || !BP_EMBED_DISABLE_FORUM_POSTS );
1358
  * Are oembeds allowed in private messages?
1359
  *
1360
  * @return bool False when form post embed support is disabled; true when enabled (default)
1361
+ * @since 1.5
1362
  */
1363
  function bp_use_embed_in_private_messages() {
1364
  return apply_filters( 'bp_use_embed_in_private_messages', !defined( 'BP_EMBED_DISABLE_PRIVATE_MESSAGES' ) || !BP_EMBED_DISABLE_PRIVATE_MESSAGES );
1365
  }
1366
 
 
 
1367
  /**
1368
  * Output the correct URL based on BuddyPress and WordPress configuration
1369
  *
1370
  * @package BuddyPress
1371
+ * @since 1.5
1372
  *
1373
  * @param string $path
1374
  * @param string $scheme
1382
  * Return the correct URL based on BuddyPress and WordPress configuration
1383
  *
1384
  * @package BuddyPress
1385
+ * @since 1.5
1386
  *
1387
  * @param string $path
1388
  * @param string $scheme
1404
  return $url;
1405
  }
1406
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1407
  /** Global Manipulators *******************************************************/
1408
 
1409
  /**
1410
  * Set the $bp->is_directory global
1411
  *
1412
+ * @global obj $bp
1413
  * @param bool $is_directory
1414
  * @param str $component
1415
  */
1425
  /**
1426
  * Set the $bp->is_item_admin global
1427
  *
1428
+ * @global obj $bp
1429
  * @param bool $is_item_admin
1430
  * @param str $component
1431
  */
1441
  /**
1442
  * Set the $bp->is_item_mod global
1443
  *
1444
+ * @global obj $bp
1445
  * @param bool $is_item_mod
1446
  * @param str $component
1447
  */
1457
  /**
1458
  * Trigger a 404
1459
  *
1460
+ * @global object $bp Global BuddyPress settings object
1461
  * @global WP_Query $wp_query WordPress query object
1462
  * @param string $redirect If 'remove_canonical_direct', remove WordPress' "helpful" redirect_canonical action.
1463
+ * @since 1.5
1464
  */
1465
  function bp_do_404( $redirect = 'remove_canonical_direct' ) {
1466
+ global $bp, $wp_query;
1467
 
1468
  do_action( 'bp_do_404', $redirect );
1469
 
1474
  if ( 'remove_canonical_direct' == $redirect )
1475
  remove_action( 'template_redirect', 'redirect_canonical' );
1476
  }
 
1477
  ?>
bp-core/bp-core-hooks.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Exit if accessed directly
3
+ if ( !defined( 'ABSPATH' ) ) exit;
4
+
5
+ /** Loaded ********************************************************************/
6
+
7
+ add_action( 'plugins_loaded', 'bp_loaded', 10 );
8
+
9
+ add_action( 'bp_loaded', 'bp_include', 2 );
10
+
11
+ add_action( 'wp', 'bp_actions', 3 );
12
+
13
+ add_action( 'wp', 'bp_screens', 4 );
14
+
15
+ /** Init **********************************************************************/
16
+
17
+ // Attach bp_init to WordPress init
18
+ add_action( 'init', 'bp_init' );
19
+
20
+ // Parse the URI and set globals
21
+ add_action( 'bp_init', 'bp_core_set_uri_globals', 2 );
22
+
23
+ // Setup component globals
24
+ add_action( 'bp_init', 'bp_setup_globals', 4 );
25
+
26
+ // Setup the navigation menu
27
+ add_action( 'bp_init', 'bp_setup_nav', 7 );
28
+
29
+ // Setup the navigation menu
30
+ add_action( 'admin_bar_menu', 'bp_setup_admin_bar' );
31
+
32
+ // Setup the title
33
+ add_action( 'bp_init', 'bp_setup_title', 9 );
34
+
35
+ // Setup widgets
36
+ add_action( 'bp_loaded', 'bp_setup_widgets' );
37
+
38
+ // Setup admin bar
39
+ add_action( 'bp_loaded', 'bp_core_load_admin_bar' );
40
+
41
+ /** The hooks *****************************************************************/
42
+
43
+ /**
44
+ * Include files on this action
45
+ */
46
+ function bp_include() {
47
+ do_action( 'bp_include' );
48
+ }
49
+
50
+ /**
51
+ * Setup global variables and objects
52
+ */
53
+ function bp_setup_globals() {
54
+ do_action( 'bp_setup_globals' );
55
+ }
56
+
57
+ /**
58
+ * Set navigation elements
59
+ */
60
+ function bp_setup_nav() {
61
+ do_action( 'bp_setup_nav' );
62
+ }
63
+
64
+ /**
65
+ * Set up BuddyPress implementation of the WP admin bar
66
+ */
67
+ function bp_setup_admin_bar() {
68
+ if ( bp_use_wp_admin_bar() )
69
+ do_action( 'bp_setup_admin_bar' );
70
+ }
71
+
72
+ /**
73
+ * Set the page title
74
+ */
75
+ function bp_setup_title() {
76
+ do_action( 'bp_setup_title' );
77
+ }
78
+
79
+ /**
80
+ * Register widgets
81
+ */
82
+ function bp_setup_widgets() {
83
+ do_action( 'bp_register_widgets' );
84
+ }
85
+
86
+ /**
87
+ * Initlialize code
88
+ */
89
+ function bp_init() {
90
+ do_action( 'bp_init' );
91
+ }
92
+
93
+ /**
94
+ * Attached to plugins_loaded
95
+ */
96
+ function bp_loaded() {
97
+ do_action( 'bp_loaded' );
98
+ }
99
+
100
+ /**
101
+ * Attach potential template actions
102
+ */
103
+ function bp_actions() {
104
+ do_action( 'bp_actions' );
105
+ }
106
+
107
+ /**
108
+ * Attach potential template screens
109
+ */
110
+ function bp_screens() {
111
+ do_action( 'bp_screens' );
112
+ }
113
+
114
+ ?>
bp-core/bp-core-loader.php CHANGED
@@ -1,29 +1,40 @@
1
  <?php
2
-
3
- /**
4
- * BuddyPress Core Loader
5
- *
6
- * Core contains the commonly used functions, classes, and API's
7
- *
8
- * @package BuddyPress
9
- * @subpackage Core
10
- */
11
-
12
  // Exit if accessed directly
13
  if ( !defined( 'ABSPATH' ) ) exit;
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  class BP_Core extends BP_Component {
16
 
17
- /**
18
- * Start the members component creation process
19
- *
20
- * @since BuddyPress (1.5)
21
- *
22
- * @uses BP_Core::bootstrap()
23
- */
24
  function __construct() {
25
  parent::start(
26
- 'core',
27
  __( 'BuddyPress Core', 'buddypress' )
28
  , BP_PLUGIN_DIR
29
  );
@@ -31,16 +42,6 @@ class BP_Core extends BP_Component {
31
  $this->bootstrap();
32
  }
33
 
34
- /**
35
- * Populate the global data needed before BuddyPress can continue
36
- *
37
- * This involves figuring out the currently required, active, deactive,
38
- * and optional components.
39
- *
40
- * @since BuddyPress (1.5)
41
- *
42
- * @global BuddyPress $bp
43
- */
44
  private function bootstrap() {
45
  global $bp;
46
 
@@ -68,7 +69,6 @@ class BP_Core extends BP_Component {
68
 
69
  // Pre 1.5 Backwards compatibility
70
  } elseif ( $deactivated_components = bp_get_option( 'bp-deactivated-components' ) ) {
71
-
72
  // Trim off namespace and filename
73
  foreach ( (array) $deactivated_components as $component => $value )
74
  $trimmed[] = str_replace( '.php', '', str_replace( 'bp-', '', $component ) );
@@ -77,19 +77,24 @@ class BP_Core extends BP_Component {
77
  $bp->deactivated_components = apply_filters( 'bp_deactivated_components', $trimmed );
78
 
79
  // Setup the active components
80
- $active_components = array_fill_keys( array_diff( array_values( array_merge( $optional_components, $required_components ) ), array_values( $deactivated_components ) ), '1' );
 
 
 
81
 
82
  // Set the active component global
83
  $bp->active_components = apply_filters( 'bp_active_components', $bp->active_components );
84
 
85
  // Default to all components active
86
  } else {
87
-
88
  // Set globals
89
  $bp->deactivated_components = array();
90
 
91
  // Setup the active components
92
- $active_components = array_fill_keys( array_values( array_merge( $bp->optional_components, $bp->required_components ) ), '1' );
 
 
 
93
 
94
  // Set the active component global
95
  $bp->active_components = apply_filters( 'bp_active_components', $bp->active_components );
@@ -109,26 +114,6 @@ class BP_Core extends BP_Component {
109
  $bp->required_components[] = 'core';
110
  }
111
 
112
- function includes() {
113
-
114
- if ( !is_admin() )
115
- return;
116
-
117
- $includes = array(
118
- 'admin'
119
- );
120
-
121
- parent::includes( $includes );
122
- }
123
-
124
- /**
125
- * Sets up a majority of the BuddyPress globals that require a minimal
126
- * amount of processing, meaning they cannot be set in the BuddyPress class.
127
- *
128
- * @since BuddyPress (1.5)
129
- *
130
- * @global BuddyPress $bp
131
- */
132
  function setup_globals() {
133
  global $bp;
134
 
@@ -150,19 +135,40 @@ class BP_Core extends BP_Component {
150
  if ( empty( $bp->pages ) )
151
  $bp->pages = bp_core_get_directory_pages();
152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  /** Basic current user data *******************************************/
154
 
155
  // Logged in user is the 'current_user'
156
  $current_user = wp_get_current_user();
157
 
158
  // The user ID of the user who is currently logged in.
159
- $bp->loggedin_user = new stdClass;
160
- $bp->loggedin_user->id = isset( $current_user->ID ) ? $current_user->ID : 0;
161
 
162
  /** Avatars ***********************************************************/
163
 
164
  // Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar
165
- $bp->grav_default = new stdClass;
166
  $bp->grav_default->user = apply_filters( 'bp_user_gravatar_default', $bp->site_options['avatar_default'] );
167
  $bp->grav_default->group = apply_filters( 'bp_group_gravatar_default', $bp->grav_default->user );
168
  $bp->grav_default->blog = apply_filters( 'bp_blog_gravatar_default', $bp->grav_default->user );
@@ -186,22 +192,15 @@ class BP_Core extends BP_Component {
186
  do_action( 'bp_core_setup_globals' );
187
  }
188
 
189
- /**
190
- * Setup BuddyBar navigation
191
- *
192
- * @since BuddyPress (1.5)
193
- *
194
- * @global BuddyPress $bp
195
- */
196
  function setup_nav() {
197
  global $bp;
198
 
199
- // If xprofile component is disabled, revert to WordPress profile
 
 
 
200
  if ( !bp_is_active( 'xprofile' ) ) {
201
 
202
- // Define local variable
203
- $sub_nav = array();
204
-
205
  // Fallback values if xprofile is disabled
206
  $bp->core->profile->slug = 'profile';
207
  $bp->active_components[$bp->core->profile->slug] = $bp->core->profile->slug;
@@ -215,7 +214,7 @@ class BP_Core extends BP_Component {
215
  'default_subnav_slug' => 'public'
216
  );
217
 
218
- $profile_link = trailingslashit( bp_loggedin_user_domain() . '/' . $bp->core->profile->slug );
219
 
220
  // Add the subnav items to the profile
221
  $sub_nav[] = array(
@@ -225,23 +224,11 @@ class BP_Core extends BP_Component {
225
  'parent_slug' => $bp->core->profile->slug,
226
  'screen_function' => 'bp_core_catch_profile_uri'
227
  );
228
-
229
- parent::setup_nav( $main_nav, $sub_nav );
230
  }
231
  }
232
  }
233
 
234
- /**
235
- * Setup the BuddyPress Core component
236
- *
237
- * @since BuddyPress (1.6)
238
- *
239
- * @global BuddyPress $bp
240
- */
241
- function bp_setup_core() {
242
- global $bp;
243
- $bp->core = new BP_Core();
244
- }
245
- add_action( 'bp_setup_components', 'bp_setup_core', 2 );
246
 
247
  ?>
1
  <?php
 
 
 
 
 
 
 
 
 
 
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
5
+ // Require all of the BuddyPress core libraries
6
+ require( BP_PLUGIN_DIR . '/bp-core/bp-core-cache.php' );
7
+ require( BP_PLUGIN_DIR . '/bp-core/bp-core-hooks.php' );
8
+ require( BP_PLUGIN_DIR . '/bp-core/bp-core-cssjs.php' );
9
+ require( BP_PLUGIN_DIR . '/bp-core/bp-core-classes.php' );
10
+ require( BP_PLUGIN_DIR . '/bp-core/bp-core-filters.php' );
11
+ require( BP_PLUGIN_DIR . '/bp-core/bp-core-avatars.php' );
12
+ require( BP_PLUGIN_DIR . '/bp-core/bp-core-widgets.php' );
13
+ require( BP_PLUGIN_DIR . '/bp-core/bp-core-template.php' );
14
+ require( BP_PLUGIN_DIR . '/bp-core/bp-core-buddybar.php' );
15
+ require( BP_PLUGIN_DIR . '/bp-core/bp-core-catchuri.php' );
16
+ require( BP_PLUGIN_DIR . '/bp-core/bp-core-component.php' );
17
+ require( BP_PLUGIN_DIR . '/bp-core/bp-core-functions.php' );
18
+
19
+ // Load deprecated functions
20
+ require( BP_PLUGIN_DIR . '/bp-core/deprecated/1.5.php' );
21
+
22
+ // Load the WP admin bar.
23
+ if ( !defined( 'BP_DISABLE_ADMIN_BAR' ) )
24
+ require( BP_PLUGIN_DIR . '/bp-core/bp-core-adminbar.php' );
25
+
26
+ // Move active components from sitemeta, if necessary
27
+ // Provides backpat with earlier versions of BP
28
+ if ( is_multisite() && $active_components = get_site_option( 'bp-active-components' ) )
29
+ bp_update_option( 'bp-active-components', $active_components );
30
+
31
+ /** "And now for something completely different" ******************************/
32
+
33
  class BP_Core extends BP_Component {
34
 
 
 
 
 
 
 
 
35
  function __construct() {
36
  parent::start(
37
+ '_core',
38
  __( 'BuddyPress Core', 'buddypress' )
39
  , BP_PLUGIN_DIR
40
  );
42
  $this->bootstrap();
43
  }
44
 
 
 
 
 
 
 
 
 
 
 
45
  private function bootstrap() {
46
  global $bp;
47
 
69
 
70
  // Pre 1.5 Backwards compatibility
71
  } elseif ( $deactivated_components = bp_get_option( 'bp-deactivated-components' ) ) {
 
72
  // Trim off namespace and filename
73
  foreach ( (array) $deactivated_components as $component => $value )
74
  $trimmed[] = str_replace( '.php', '', str_replace( 'bp-', '', $component ) );
77
  $bp->deactivated_components = apply_filters( 'bp_deactivated_components', $trimmed );
78
 
79
  // Setup the active components
80
+ $active_components = array_flip( array_diff( array_values( array_merge( $bp->optional_components, $bp->required_components ) ), array_values( $bp->deactivated_components ) ) );
81
+
82
+ // Loop through active components and set the values
83
+ $bp->active_components = array_map( '__return_true', $active_components );
84
 
85
  // Set the active component global
86
  $bp->active_components = apply_filters( 'bp_active_components', $bp->active_components );
87
 
88
  // Default to all components active
89
  } else {
 
90
  // Set globals
91
  $bp->deactivated_components = array();
92
 
93
  // Setup the active components
94
+ $active_components = array_flip( array_values( array_merge( $bp->optional_components, $bp->required_components ) ) );
95
+
96
+ // Loop through active components and set the values
97
+ $bp->active_components = array_map( '__return_true', $active_components );
98
 
99
  // Set the active component global
100
  $bp->active_components = apply_filters( 'bp_active_components', $bp->active_components );
114
  $bp->required_components[] = 'core';
115
  }
116
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  function setup_globals() {
118
  global $bp;
119
 
135
  if ( empty( $bp->pages ) )
136
  $bp->pages = bp_core_get_directory_pages();
137
 
138
+ /** Admin Bar *********************************************************/
139
+
140
+ // Set the 'My Account' global to prevent debug notices
141
+ $bp->my_account_menu_id = false;
142
+
143
+ /** Component and Action **********************************************/
144
+
145
+ // Used for overriding the 2nd level navigation menu so it can be used to
146
+ // display custom navigation for an item (for example a group)
147
+ $bp->is_single_item = false;
148
+
149
+ // Sets up the array container for the component navigation rendered
150
+ // by bp_get_nav()
151
+ $bp->bp_nav = array();
152
+
153
+ // Sets up the array container for the component options navigation
154
+ // rendered by bp_get_options_nav()
155
+ $bp->bp_options_nav = array();
156
+
157
+ // Contains an array of all the active components. The key is the slug,
158
+ // value the internal ID of the component.
159
+ //$bp->active_components = array();
160
+
161
  /** Basic current user data *******************************************/
162
 
163
  // Logged in user is the 'current_user'
164
  $current_user = wp_get_current_user();
165
 
166
  // The user ID of the user who is currently logged in.
167
+ $bp->loggedin_user->id = $current_user->ID;
 
168
 
169
  /** Avatars ***********************************************************/
170
 
171
  // Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar
 
172
  $bp->grav_default->user = apply_filters( 'bp_user_gravatar_default', $bp->site_options['avatar_default'] );
173
  $bp->grav_default->group = apply_filters( 'bp_group_gravatar_default', $bp->grav_default->user );
174
  $bp->grav_default->blog = apply_filters( 'bp_blog_gravatar_default', $bp->grav_default->user );
192
  do_action( 'bp_core_setup_globals' );
193
  }
194
 
 
 
 
 
 
 
 
195
  function setup_nav() {
196
  global $bp;
197
 
198
+ /***
199
+ * If the extended profiles component is disabled, we need to revert to using the
200
+ * built in WordPress profile information
201
+ */
202
  if ( !bp_is_active( 'xprofile' ) ) {
203
 
 
 
 
204
  // Fallback values if xprofile is disabled
205
  $bp->core->profile->slug = 'profile';
206
  $bp->active_components[$bp->core->profile->slug] = $bp->core->profile->slug;
214
  'default_subnav_slug' => 'public'
215
  );
216
 
217
+ $profile_link = trailingslashit( $bp->loggedin_user->domain . '/' . $bp->core->profile->slug );
218
 
219
  // Add the subnav items to the profile
220
  $sub_nav[] = array(
224
  'parent_slug' => $bp->core->profile->slug,
225
  'screen_function' => 'bp_core_catch_profile_uri'
226
  );
 
 
227
  }
228
  }
229
  }
230
 
231
+ // Initialize the BuddyPress Core
232
+ $bp->core = new BP_Core();
 
 
 
 
 
 
 
 
 
 
233
 
234
  ?>
bp-core/bp-core-moderation.php DELETED
@@ -1,268 +0,0 @@
1
- <?php
2
- /**
3
- * BuddyPress Moderation Functions
4
- *
5
- * @package BuddyPress
6
- * @subpackage Core
7
- * @since 1.6
8
- */
9
-
10
- // Exit if accessed directly
11
- if ( !defined( 'ABSPATH' ) ) exit;
12
-
13
- /** Moderation ****************************************************************/
14
-
15
- /**
16
- * Check for flooding
17
- *
18
- * Check to make sure that a user is not making too many posts in a short amount
19
- * of time.
20
- *
21
- * @param int $user_id User id to check for flood
22
- * @return bool True if there is no flooding, true if there is
23
- * @since 1.6
24
- * @uses current_user_can() To check if the current user can throttle
25
- * @uses bp_get_option() To get the throttle time
26
- * @uses get_transient() To get the last posted transient of the ip
27
- * @uses get_user_meta() To get the last posted meta of the user
28
- */
29
- function bp_core_check_for_flood( $user_id = 0 ) {
30
-
31
- // Option disabled. No flood checks.
32
- if ( !$throttle_time = bp_get_option( '_bp_throttle_time' ) )
33
- return true;
34
-
35
- // Bail if no user ID passed
36
- if ( empty( $user_id ) )
37
- return false;
38
-
39
- $last_posted = get_user_meta( $user_id, '_bp_last_posted', true );
40
- if ( isset( $last_posted ) && ( time() < ( $last_posted + $throttle_time ) ) && !current_user_can( 'throttle' ) )
41
- return false;
42
-
43
- return true;
44
- }
45
-
46
- /**
47
- * Check for moderation keys and too many links
48
- *
49
- * @param int $user_id Topic or reply author ID
50
- * @param string $title The title of the content
51
- * @param string $content The content being posted
52
- * @return bool True if test is passed, false if fail
53
- * @since 1.6
54
- * @uses bp_current_author_ip() To get current user IP address
55
- * @uses bp_current_author_ua() To get current user agent
56
- * @uses bp_current_user_can() Allow super admins to bypass blacklist
57
- */
58
- function bp_core_check_for_moderation( $user_id = 0, $title = '', $content = '' ) {
59
-
60
- // Bail if super admin is author
61
- if ( is_super_admin( $user_id ) )
62
- return true;
63
-
64
- // Define local variable(s)
65
- $post = array();
66
- $match_out = '';
67
-
68
- /** Blacklist *************************************************************/
69
-
70
- // Get the moderation keys
71
- $blacklist = trim( get_option( 'moderation_keys' ) );
72
-
73
- // Bail if blacklist is empty
74
- if ( empty( $blacklist ) )
75
- return true;
76
-
77
- /** User Data *************************************************************/
78
-
79
- if ( !empty( $user_id ) ) {
80
-
81
- // Get author data
82
- $user = get_userdata( $user_id );
83
-
84
- // If data exists, map it
85
- if ( !empty( $user ) ) {
86
- $post['author'] = $user->display_name;
87
- $post['email'] = $user->user_email;
88
- $post['url'] = $user->user_url;
89
- }
90
- }
91
-
92
- // Current user IP and user agent
93
- $post['user_ip'] = bp_core_current_user_ip();
94
- $post['user_ua'] = bp_core_current_user_ua();
95
-
96
- // Post title and content
97
- $post['title'] = $title;
98
- $post['content'] = $content;
99
-
100
- /** Max Links *************************************************************/
101
-
102
- $max_links = get_option( 'comment_max_links' );
103
- if ( !empty( $max_links ) ) {
104
-
105
- // How many links?
106
- $num_links = preg_match_all( '/<a [^>]*href/i', $content, $match_out );
107
-
108
- // Allow for bumping the max to include the user's URL
109
- $num_links = apply_filters( 'comment_max_links_url', $num_links, $post['url'] );
110
-
111
- // Das ist zu viele links!
112
- if ( $num_links >= $max_links ) {
113
- return false;
114
- }
115
- }
116
-
117
- /** Words *****************************************************************/
118
-
119
- // Get words separated by new lines
120
- $words = explode( "\n", $blacklist );
121
-
122
- // Loop through words
123
- foreach ( (array) $words as $word ) {
124
-
125
- // Trim the whitespace from the word
126
- $word = trim( $word );
127
-
128
- // Skip empty lines
129
- if ( empty( $word ) ) { continue; }
130
-
131
- // Do some escaping magic so that '#' chars in the
132
- // spam words don't break things:
133
- $word = preg_quote( $word, '#' );
134
- $pattern = "#$word#i";
135
-
136
- // Loop through post data
137
- foreach( $post as $post_data ) {
138
-
139
- // Check each user data for current word
140
- if ( preg_match( $pattern, $post_data ) ) {
141
-
142
- // Post does not pass
143
- return false;
144
- }
145
- }
146
- }
147
-
148
- // Check passed successfully
149
- return true;
150
- }
151
-
152
- /**
153
- * Checks for blocked keys
154
- *
155
- * @param int $user_id Topic or reply author ID
156
- * @param string $title The title of the content
157
- * @param string $content The content being posted
158
- * @return bool True if test is passed, false if fail
159
- * @uses bp_current_author_ip() To get current user IP address
160
- * @uses bp_current_author_ua() To get current user agent
161
- * @uses bp_current_user_can() Allow super admins to bypass blacklist
162
- * @since 1.6
163
- */
164
- function bp_core_check_for_blacklist( $user_id = 0, $title = '', $content = '' ) {
165
-
166
- // Bail if super admin is author
167
- if ( is_super_admin( $user_id ) )
168
- return true;
169
-
170
- // Define local variable
171
- $post = array();
172
-
173
- /** Blacklist *************************************************************/
174
-
175
- // Get the moderation keys
176
- $blacklist = trim( get_option( 'blacklist_keys' ) );
177
-
178
- // Bail if blacklist is empty
179
- if ( empty( $blacklist ) )
180
- return true;
181
-
182
- /** User Data *************************************************************/
183
-
184
- // Map current user data
185
- if ( !empty( $user_id ) ) {
186
-
187
- // Get author data
188
- $user = get_userdata( $user_id );
189
-
190
- // If data exists, map it
191
- if ( !empty( $user ) ) {
192
- $post['author'] = $user->display_name;
193
- $post['email'] = $user->user_email;
194
- $post['url'] = $user->user_url;
195
- }
196
- }
197
-
198
- // Current user IP and user agent
199
- $post['user_ip'] = bp_core_current_user_ip();
200
- $post['user_ua'] = bp_core_current_user_ua();
201
-
202
- // Post title and content
203
- $post['title'] = $title;
204
- $post['content'] = $content;
205
-
206
- /** Words *****************************************************************/
207
-
208
- // Get words separated by new lines
209
- $words = explode( "\n", $blacklist );
210
-
211
- // Loop through words
212
- foreach ( (array) $words as $word ) {
213
-
214
- // Trim the whitespace from the word
215
- $word = trim( $word );
216
-
217
- // Skip empty lines
218
- if ( empty( $word ) ) { continue; }
219
-
220
- // Do some escaping magic so that '#' chars in the spam words don't break things:
221
- $word = preg_quote( $word, '#' );
222
- $pattern = "#$word#i";
223
-
224
- // Loop through post data
225
- foreach( $post as $post_data ) {
226
-
227
- // Check each user data for current word
228
- if ( preg_match( $pattern, $post_data ) ) {
229
-
230
- // Post does not pass
231
- return false;
232
- }
233
- }
234
- }
235
-
236
- // Check passed successfully
237
- return true;
238
- }
239
-
240
- /**
241
- * Get the current-user IP address
242
- *
243
- * @return string
244
- * @since 1.6
245
- */
246
- function bp_core_current_user_ip() {
247
- $retval = preg_replace( '/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR'] );
248
-
249
- return apply_filters( 'bp_core_current_user_ip', $retval );
250
- }
251
-
252
- /**
253
- * Get the current-user user-agent
254
- *
255
- * @return string
256
- * @since 1.6
257
- */
258
- function bp_core_current_user_ua() {
259
-
260
- // Sanity check the user agent
261
- if ( !empty( $_SERVER['HTTP_USER_AGENT'] ) )
262
- $retval = substr( $_SERVER['HTTP_USER_AGENT'], 0, 254 );
263
- else
264
- $retval = '';
265
-
266
- return apply_filters( 'bp_core_current_user_ua', $retval );
267
- }
268
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-core/bp-core-options.php DELETED
@@ -1,524 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * BuddyPress Options
5
- *
6
- * @package BuddyPress
7
- * @subpackage Options
8
- */
9
-
10
- // Exit if accessed directly
11
- if ( !defined( 'ABSPATH' ) ) exit;
12
-
13
- /**
14
- * Get the default site options and their values
15
- *
16
- * @since BuddyPress (1.6)
17
- *
18
- * @return array Filtered option names and values
19
- */
20
- function bp_get_default_options() {
21
-
22
- // Default options
23
- $options = array (
24
-
25
- /** Components ********************************************************/
26
-
27
- 'bp-deactivated-components' => array(),
28
-
29
- /** bbPress ***********************************************************/
30
-
31
- // Legacy bbPress config location
32
- 'bb-config-location' => ABSPATH . 'bb-config.php',
33
-
34
- /** XProfile **********************************************************/
35
-
36
- // Base profile groups name
37
- 'bp-xprofile-base-group-name' => 'Base',
38
-
39
- // Base fullname field name
40
- 'bp-xprofile-fullname-field-name' => 'Name',
41
-
42
- /** Blogs *************************************************************/
43
-
44
- // Used to decide if blogs need indexing
45
- 'bp-blogs-first-install' => false,
46
-
47
- /** Settings **********************************************************/
48
-
49
- // Disable the WP to BP profile sync
50
- 'bp-disable-profile-sync' => false,
51
-
52
- // Hide the Toolbar for logged out users
53
- 'hide-loggedout-adminbar' => false,
54
-
55
- // Avatar uploads
56
- 'bp-disable-avatar-uploads' => false,
57
-
58
- // Allow users to delete their own accounts
59
- 'bp-disable-account-deletion' => false,
60
-
61
- // Allow comments on blog and forum activity items
62
- 'bp-disable-blogforum-comments' => true,
63
-
64
- /** Groups ************************************************************/
65
-
66
- // @todo Move this into the groups component
67
-
68
- // Restrict group creation to super admins
69
- 'bp_restrict_group_creation' => false,
70
-
71
- /** Akismet ***********************************************************/
72
-
73
- // Users from all sites can post
74
- '_bp_enable_akismet' => true,
75
-
76
- /** BuddyBar **********************************************************/
77
-
78
- // Force the BuddyBar
79
- '_bp_force_buddybar' => false
80
- );
81
-
82
- return apply_filters( 'bp_get_default_options', $options );
83
- }
84
-
85
- /**
86
- * Add default options
87
- *
88
- * Hooked to bp_activate, it is only called once when BuddyPress is activated.
89
- * This is non-destructive, so existing settings will not be overridden.
90
- *
91
- * @since BuddyPress (1.6)
92
- *
93
- * @uses bp_get_default_options() To get default options
94
- * @uses add_option() Adds default options
95
- * @uses do_action() Calls 'bp_add_options'
96
- */
97
- function bp_add_options() {
98
-
99
- // Get the default options and values
100
- $options = bp_get_default_options();
101
-
102
- // Add default options
103
- foreach ( $options as $key => $value )
104
- add_option( $key, $value );
105
-
106
- // Allow previously activated plugins to append their own options.
107
- do_action( 'bp_add_options' );
108
- }
109
-
110
- /**
111
- * Delete default options
112
- *
113
- * Hooked to bp_uninstall, it is only called once when BuddyPress is uninstalled.
114
- * This is destructive, so existing settings will be destroyed.
115
- *
116
- * @since BuddyPress (1.6)
117
- *
118
- * @uses bp_get_default_options() To get default options
119
- * @uses delete_option() Removes default options
120
- * @uses do_action() Calls 'bp_delete_options'
121
- */
122
- function bp_delete_options() {
123
-
124
- // Get the default options and values
125
- $options = bp_get_default_options();
126
-
127
- // Add default options
128
- foreach ( $options as $key => $value )
129
- delete_option( $key );
130
-
131
- // Allow previously activated plugins to append their own options.
132
- do_action( 'bp_delete_options' );
133
- }
134
-
135
- /**
136
- * Add filters to each BuddyPress option and allow them to be overloaded from
137
- * inside the $bp->options array.
138
- *
139
- * @since BuddyPress (1.6)
140
- *
141
- * @uses bp_get_default_options() To get default options
142
- * @uses add_filter() To add filters to 'pre_option_{$key}'
143
- * @uses do_action() Calls 'bp_add_option_filters'
144
- */
145
- function bp_setup_option_filters() {
146
-
147
- // Get the default options and values
148
- $options = bp_get_default_options();
149
-
150
- // Add filters to each BuddyPress option
151
- foreach ( $options as $key => $value )
152
- add_filter( 'pre_option_' . $key, 'bp_pre_get_option' );
153
-
154
- // Allow previously activated plugins to append their own options.
155
- do_action( 'bp_setup_option_filters' );
156
- }
157
-
158
- /**
159
- * Filter default options and allow them to be overloaded from inside the
160
- * $bp->options array.
161
- *
162
- * @since BuddyPress (1.6)
163
- *
164
- * @global BuddyPress $bp
165
- * @param bool $value Optional. Default value false
166
- * @return mixed false if not overloaded, mixed if set
167
- */
168
- function bp_pre_get_option( $value = false ) {
169
- global $bp;
170
-
171
- // Get the name of the current filter so we can manipulate it
172
- $filter = current_filter();
173
-
174
- // Remove the filter prefix
175
- $option = str_replace( 'pre_option_', '', $filter );
176
-
177
- // Check the options global for preset value
178
- if ( !empty( $bp->options[$option] ) )
179
- $value = $bp->options[$option];
180
-
181
- // Always return a value, even if false
182
- return $value;
183
- }
184
-
185
- /**
186
- * Retrieve an option
187
- *
188
- * This is a wrapper for get_blog_option(), which in turn stores settings data (such as bp-pages)
189
- * on the appropriate blog, given your current setup.
190
- *
191
- * The 'bp_get_option' filter is primarily for backward-compatibility.
192
- *
193
- * @package BuddyPress
194
- * @since BuddyPress (1.5)
195
- *
196
- * @uses bp_get_root_blog_id()
197
- * @param str $option_name The option to be retrieved
198
- * @param str $default Optional. Default value to be returned if the option isn't set
199
- * @return mixed The value for the option
200
- */
201
- function bp_get_option( $option_name, $default = '' ) {
202
- $value = get_blog_option( bp_get_root_blog_id(), $option_name, $default );
203
-
204
- return apply_filters( 'bp_get_option', $value );
205
- }
206
-
207
- /**
208
- * Save an option
209
- *
210
- * This is a wrapper for update_blog_option(), which in turn stores settings data (such as bp-pages)
211
- * on the appropriate blog, given your current setup.
212
- *
213
- * @package BuddyPress
214
- * @since BuddyPress (1.5)
215
- *
216
- * @uses bp_get_root_blog_id()
217
- * @param str $option_name The option key to be set
218
- * @param str $value The value to be set
219
- */
220
- function bp_update_option( $option_name, $value ) {
221
- update_blog_option( bp_get_root_blog_id(), $option_name, $value );
222
- }
223
-
224
- /**
225
- * Delete an option
226
- *
227
- * This is a wrapper for delete_blog_option(), which in turn deletes settings data (such as
228
- * bp-pages) on the appropriate blog, given your current setup.
229
- *
230
- * @package BuddyPress
231
- * @since BuddyPress (1.5)
232
- *
233
- * @uses bp_get_root_blog_id()
234
- * @param str $option_name The option key to be set
235
- */
236
- function bp_delete_option( $option_name ) {
237
- delete_blog_option( bp_get_root_blog_id(), $option_name );
238
- }
239
-
240
- /**
241
- * When switching from single to multisite we need to copy blog options to
242
- * site options.
243
- *
244
- * This function is no longer used
245
- *
246
- * @package BuddyPress Core
247
- * @deprecated Since BuddyPress (1.6)
248
- */
249
- function bp_core_activate_site_options( $keys = array() ) {
250
- global $bp;
251
-
252
- if ( !empty( $keys ) && is_array( $keys ) ) {
253
- $errors = false;
254
-
255
- foreach ( $keys as $key => $default ) {
256
- if ( empty( $bp->site_options[ $key ] ) ) {
257
- $bp->site_options[ $key ] = bp_get_option( $key, $default );
258
-
259
- if ( !bp_update_option( $key, $bp->site_options[ $key ] ) ) {
260
- $errors = true;
261
- }
262
- }
263
- }
264
-
265
- if ( empty( $errors ) ) {
266
- return true;
267
- }
268
- }
269
-
270
- return false;
271
- }
272
-
273
- /**
274
- * BuddyPress uses common options to store configuration settings. Many of these
275
- * settings are needed at run time. Instead of fetching them all and adding many
276
- * initial queries to each page load, let's fetch them all in one go.
277
- *
278
- * @package BuddyPress Core
279
- * @todo Use settings API and audit these methods
280
- */
281
- function bp_core_get_root_options() {
282
- global $wpdb;
283
-
284
- // Get all the BuddyPress settings, and a few useful WP ones too
285
- $root_blog_options = bp_get_default_options();
286
- $root_blog_options['registration'] = '0';
287
- $root_blog_options['avatar_default'] = 'mysteryman';
288
- $root_blog_option_keys = array_keys( $root_blog_options );
289
-
290
- // Do some magic to get all the root blog options in 1 swoop
291
- $blog_options_keys = "'" . join( "', '", (array) $root_blog_option_keys ) . "'";
292
- $blog_options_table = bp_is_multiblog_mode() ? $wpdb->options : $wpdb->get_blog_prefix( bp_get_root_blog_id() ) . 'options';
293
- $blog_options_query = $wpdb->prepare( "SELECT option_name AS name, option_value AS value FROM {$blog_options_table} WHERE option_name IN ( {$blog_options_keys} )" );
294
- $root_blog_options_meta = $wpdb->get_results( $blog_options_query );
295
-
296
- // On Multisite installations, some options must always be fetched from sitemeta
297
- if ( is_multisite() ) {
298
- $network_options = apply_filters( 'bp_core_network_options', array(
299
- 'tags_blog_id' => '0',
300
- 'sitewide_tags_blog' => '',
301
- 'registration' => '0',
302
- 'fileupload_maxk' => '1500'
303
- ) );
304
-
305
- $current_site = get_current_site();
306
- $network_option_keys = array_keys( $network_options );
307
- $sitemeta_options_keys = "'" . join( "', '", (array) $network_option_keys ) . "'";
308
- $sitemeta_options_query = $wpdb->prepare( "SELECT meta_key AS name, meta_value AS value FROM {$wpdb->sitemeta} WHERE meta_key IN ( {$sitemeta_options_keys} ) AND site_id = %d", $current_site->id );
309
- $network_options_meta = $wpdb->get_results( $sitemeta_options_query );
310
-
311
- // Sitemeta comes second in the merge, so that network 'registration' value wins
312
- $root_blog_options_meta = array_merge( $root_blog_options_meta, $network_options_meta );
313
- }
314
-
315
- // Missing some options, so do some one-time fixing
316
- if ( empty( $root_blog_options_meta ) || ( count( $root_blog_options_meta ) < count( $root_blog_option_keys ) ) ) {
317
-
318
- // Get a list of the keys that are already populated
319
- $existing_options = array();
320
- foreach( $root_blog_options_meta as $already_option ) {
321
- $existing_options[$already_option->name] = $already_option->value;
322
- }
323
-
324
- // Unset the query - We'll be resetting it soon
325
- unset( $root_blog_options_meta );
326
-
327
- // Loop through options
328
- foreach ( $root_blog_options as $old_meta_key => $old_meta_default ) {
329
- // Clear out the value from the last time around
330
- unset( $old_meta_value );
331
-
332
- if ( isset( $existing_options[$old_meta_key] ) ) {
333
- continue;
334
- }
335
-
336
- // Get old site option
337
- if ( is_multisite() )
338
- $old_meta_value = get_site_option( $old_meta_key );
339
-
340
- // No site option so look in root blog
341
- if ( empty( $old_meta_value ) )
342
- $old_meta_value = bp_get_option( $old_meta_key, $old_meta_default );
343
-
344
- // Update the root blog option
345
- bp_update_option( $old_meta_key, $old_meta_value );
346
-
347
- // Update the global array
348
- $root_blog_options_meta[$old_meta_key] = $old_meta_value;
349
- }
350
-
351
- $root_blog_options_meta = array_merge( $root_blog_options_meta, $existing_options );
352
- unset( $existing_options );
353
-
354
- // We're all matched up
355
- } else {
356
- // Loop through our results and make them usable
357
- foreach ( $root_blog_options_meta as $root_blog_option )
358
- $root_blog_options[$root_blog_option->name] = $root_blog_option->value;
359
-
360
- // Copy the options no the return val
361
- $root_blog_options_meta = $root_blog_options;
362
-
363
- // Clean up our temporary copy
364
- unset( $root_blog_options );
365
- }
366
-
367
- return apply_filters( 'bp_core_get_root_options', $root_blog_options_meta );
368
- }
369
-
370
- /** Active? *******************************************************************/
371
-
372
- /**
373
- * Is profile sycing disabled?
374
- *
375
- * @since BuddyPress (1.6)
376
- *
377
- * @param $default bool Optional.Default value true
378
- *
379
- * @uses bp_get_option() To get the profile sync option
380
- * @return bool Is profile sync enabled or not
381
- */
382
- function bp_disable_profile_sync( $default = true ) {
383
- return (bool) apply_filters( 'bp_disable_profile_sync', (bool) bp_get_option( 'bp-disable-profile-sync', $default ) );
384
- }
385
-
386
- /**
387
- * Is the Toolbar hidden for logged out users?
388
- *
389
- * @since BuddyPress (1.6)
390
- *
391
- * @param $default bool Optional.Default value true
392
- *
393
- * @uses bp_get_option() To get the logged out Toolbar option
394
- * @return bool Is logged out Toolbar enabled or not
395
- */
396
- function bp_hide_loggedout_adminbar( $default = true ) {
397
- return (bool) apply_filters( 'bp_hide_loggedout_adminbar', (bool) bp_get_option( 'hide-loggedout-adminbar', $default ) );
398
- }
399
-
400
- /**
401
- * Are members able to upload their own avatars?
402
- *
403
- * @since BuddyPress (1.6)
404
- *
405
- * @param $default bool Optional. Default value true
406
- *
407
- * @uses bp_get_option() To get the avatar uploads option
408
- * @return bool Are avatar uploads allowed?
409
- */
410
- function bp_disable_avatar_uploads( $default = true ) {
411
- return (bool) apply_filters( 'bp_disable_avatar_uploads', (bool) bp_get_option( 'bp-disable-avatar-uploads', $default ) );
412
- }
413
-
414
- /**
415
- * Are members able to delete their own accounts?
416
- *
417
- * @since BuddyPress (1.6)
418
- *
419
- * @param $default bool Optional. Default value
420
- *
421
- * @uses bp_get_option() To get the account deletion option
422
- * @return bool Is account deletion allowed?
423
- */
424
- function bp_disable_account_deletion( $default = false ) {
425
- return apply_filters( 'bp_disable_account_deletion', (bool) bp_get_option( 'bp-disable-account-deletion', $default ) );
426
- }
427
-
428
- /**
429
- * Are blog and forum activity stream comments disabled?
430
- *
431
- * @since BuddyPress (1.6)
432
- *
433
- * @param $default bool Optional. Default value false
434
- * @todo split and move into blog and forum components
435
- * @uses bp_get_option() To get the blog/forum comments option
436
- * @return bool Is blog/forum comments allowed?
437
- */
438
- function bp_disable_blogforum_comments( $default = false ) {
439
- return (bool) apply_filters( 'bp_disable_blogforum_comments', (bool) bp_get_option( 'bp-disable-blogforum-comments', $default ) );
440
- }
441
-
442
- /**
443
- * Is group creation turned off?
444
- *
445
- * @since BuddyPress (1.6)
446
- *
447
- * @param $default bool Optional. Default value true
448
- *
449
- * @todo Move into groups component
450
- * @uses bp_get_option() To get the group creation
451
- * @return bool Allow group creation?
452
- */
453
- function bp_restrict_group_creation( $default = true ) {
454
- return (bool) apply_filters( 'bp_restrict_group_creation', (bool) bp_get_option( 'bp_restrict_group_creation', $default ) );
455
- }
456
-
457
- /**
458
- * Have we migrated to using the WordPress Toolbar?
459
- *
460
- * @since BuddyPress (1.6)
461
- *
462
- * @param $default bool Optional. Default value true
463
- *
464
- * @todo Move into groups component
465
- * @uses bp_get_option() To get the WP editor option
466
- * @return bool Use WP editor?
467
- */
468
- function bp_force_buddybar( $default = true ) {
469
- return (bool) apply_filters( 'bp_force_buddybar', (bool) bp_get_option( '_bp_force_buddybar', $default ) );
470
- }
471
-
472
- /**
473
- * Output the group forums root parent forum id
474
- *
475
- * @since BuddyPress (1.6)
476
- *
477
- * @param $default bool Optional. Default value
478
- */
479
- function bp_group_forums_root_id( $default = '0' ) {
480
- echo bp_get_group_forums_root_id( $default );
481
- }
482
- /**
483
- * Return the group forums root parent forum id
484
- *
485
- * @since BuddyPress (1.6)
486
- *
487
- * @param $default bool Optional. Default value 0
488
- *
489
- * @uses bp_get_option() To get the maximum title length
490
- * @return int Is anonymous posting allowed?
491
- */
492
- function bp_get_group_forums_root_id( $default = '0' ) {
493
- return (int) apply_filters( 'bp_get_group_forums_root_id', (int) bp_get_option( '_bbp_group_forums_root_id', $default ) );
494
- }
495
-
496
- /**
497
- * Checks if BuddyPress Group Forums are enabled
498
- *
499
- * @since BuddyPress (1.6)
500
- *
501
- * @param $default bool Optional. Default value true
502
- *
503
- * @uses bp_get_option() To get the group forums option
504
- * @return bool Is group forums enabled or not
505
- */
506
- function bp_is_group_forums_active( $default = true ) {
507
- return (bool) apply_filters( 'bp_is_group_forums_active', (bool) bp_get_option( '_bbp_enable_group_forums', $default ) );
508
- }
509
-
510
- /**
511
- * Checks if Akismet is enabled
512
- *
513
- * @since BuddyPress (1.6)
514
- *
515
- * @param $default bool Optional. Default value true
516
- *
517
- * @uses bp_get_option() To get the Akismet option
518
- * @return bool Is Akismet enabled or not
519
- */
520
- function bp_is_akismet_active( $default = true ) {
521
- return (bool) apply_filters( 'bp_is_akismet_active', (bool) bp_get_option( '_bp_enable_akismet', $default ) );
522
- }
523
-
524
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-core/bp-core-template.php CHANGED
@@ -1,5 +1,4 @@
1
  <?php
2
-
3
  // Exit if accessed directly
4
  if ( !defined( 'ABSPATH' ) ) exit;
5
 
@@ -14,7 +13,7 @@ if ( !defined( 'ABSPATH' ) ) exit;
14
  * or not to highlight a particular sub nav item.
15
  *
16
  * @package BuddyPress Core
17
- * @global BuddyPress $bp The one true BuddyPress instance
18
  * @uses bp_get_user_nav() Renders the navigation for a profile of a currently viewed user.
19
  */
20
  function bp_get_options_nav() {
@@ -22,7 +21,7 @@ function bp_get_options_nav() {
22
 
23
  // If we are looking at a member profile, then the we can use the current component as an
24
  // index. Otherwise we need to use the component's root_slug
25
- $component_index = !empty( $bp->displayed_user ) ? bp_current_component() : bp_get_root_slug( bp_current_component() );
26
 
27
  if ( !bp_is_single_item() ) {
28
  if ( !isset( $bp->bp_options_nav[$component_index] ) || count( $bp->bp_options_nav[$component_index] ) < 1 ) {
@@ -31,20 +30,20 @@ function bp_get_options_nav() {
31
  $the_index = $component_index;
32
  }
33
  } else {
34
- if ( !isset( $bp->bp_options_nav[bp_current_item()] ) || count( $bp->bp_options_nav[bp_current_item()] ) < 1 ) {
35
  return false;
36
  } else {
37
- $the_index = bp_current_item();
38
  }
39
  }
40
 
41
  // Loop through each navigation item
42
- foreach ( (array) $bp->bp_options_nav[$the_index] as $subnav_item ) {
43
  if ( !$subnav_item['user_has_access'] )
44
  continue;
45
 
46
  // If the current action or an action variable matches the nav item id, then add a highlight CSS class.
47
- if ( $subnav_item['slug'] == bp_current_action() ) {
48
  $selected = ' class="current selected"';
49
  } else {
50
  $selected = '';
@@ -74,7 +73,7 @@ function bp_get_options_title() {
74
  * like a group, or a friend. Basically an avatar that appears in the sub nav options bar.
75
  *
76
  * @package BuddyPress Core
77
- * @global BuddyPress $bp The one true BuddyPress instance
78
  */
79
  function bp_has_options_avatar() {
80
  global $bp;
@@ -95,7 +94,7 @@ function bp_comment_author_avatar() {
95
  global $comment;
96
 
97
  if ( function_exists( 'bp_core_fetch_avatar' ) )
98
- echo apply_filters( 'bp_comment_author_avatar', bp_core_fetch_avatar( array( 'item_id' => $comment->user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Avatar of %s', 'buddypress' ), bp_core_get_user_displayname( $comment->user_id ) ) ) ) );
99
  else if ( function_exists('get_avatar') )
100
  get_avatar();
101
  }
@@ -104,7 +103,7 @@ function bp_post_author_avatar() {
104
  global $post;
105
 
106
  if ( function_exists( 'bp_core_fetch_avatar' ) )
107
- echo apply_filters( 'bp_post_author_avatar', bp_core_fetch_avatar( array( 'item_id' => $post->post_author, 'type' => 'thumb', 'alt' => sprintf( __( 'Avatar of %s', 'buddypress' ), bp_core_get_user_displayname( $post->post_author ) ) ) ) );
108
  else if ( function_exists('get_avatar') )
109
  get_avatar();
110
  }
@@ -152,20 +151,9 @@ function bp_avatar_cropper() {
152
  echo '<img id="avatar-to-crop" class="avatar" src="' . $bp->avatar_admin->image . '" />';
153
  }
154
 
155
- /**
156
- * Echoes bp_get_site_name()
157
- */
158
  function bp_site_name() {
159
- echo bp_get_site_name();
160
  }
161
- /**
162
- * Returns the name of the BP site. Used in RSS headers
163
- *
164
- * @since 1.6
165
- */
166
- function bp_get_site_name() {
167
- return apply_filters( 'bp_site_name', get_bloginfo( 'name', 'display' ) );
168
- }
169
 
170
  function bp_get_profile_header() {
171
  locate_template( array( '/profile/profile-header.php' ), true );
@@ -206,25 +194,23 @@ function bp_format_time( $time, $just_date = false, $localize_time = true ) {
206
  }
207
 
208
  function bp_word_or_name( $youtext, $nametext, $capitalize = true, $echo = true ) {
 
209
 
210
- if ( !empty( $capitalize ) )
211
- $youtext = bp_core_ucfirst( $youtext );
212
 
213
- if ( bp_displayed_user_id() == bp_loggedin_user_id() ) {
214
- if ( true == $echo ) {
215
  echo apply_filters( 'bp_word_or_name', $youtext );
216
- } else {
217
  return apply_filters( 'bp_word_or_name', $youtext );
218
- }
219
  } else {
220
- $fullname = bp_get_displayed_user_fullname();
221
- $fullname = (array) explode( ' ', $fullname );
222
  $nametext = sprintf( $nametext, $fullname[0] );
223
- if ( true == $echo ) {
224
  echo apply_filters( 'bp_word_or_name', $nametext );
225
- } else {
226
  return apply_filters( 'bp_word_or_name', $nametext );
227
- }
228
  }
229
  }
230
 
@@ -240,16 +226,18 @@ function bp_styles() {
240
  /** Search Form ***************************************************************/
241
 
242
  function bp_search_form_action() {
243
- return apply_filters( 'bp_search_form_action', trailingslashit( bp_get_root_domain() . '/' . bp_get_search_slug() ) );
244
  }
245
 
246
  /**
247
  * Generates the basic search form as used in BP-Default's header.
248
  *
 
249
  * @return string HTML <select> element
250
  * @since 1.0
251
  */
252
  function bp_search_form_type_select() {
 
253
 
254
  $options = array();
255
 
@@ -272,7 +260,7 @@ function bp_search_form_type_select() {
272
  $selection_box .= '<select name="search-which" id="search-which" style="width: auto">';
273
 
274
  $options = apply_filters( 'bp_search_form_type_select_options', $options );
275
- foreach( (array) $options as $option_value => $option_title )
276
  $selection_box .= sprintf( '<option value="%s">%s</option>', $option_value, $option_title );
277
 
278
  $selection_box .= '</select>';
@@ -285,7 +273,7 @@ function bp_search_form_type_select() {
285
  *
286
  * @global object $bp BuddyPress global settings
287
  * @return string
288
- * @since BuddyPress (1.5)
289
  */
290
  function bp_search_default_text( $component = '' ) {
291
  echo bp_get_search_default_text( $component );
@@ -406,12 +394,12 @@ function bp_create_excerpt( $text, $length = 225, $options = array() ) {
406
  $ending = apply_filters( 'bp_excerpt_append_text', $ending );
407
 
408
  // Remove shortcodes if necessary
409
- if ( !empty( $filter_shortcodes ) )
410
  $text = strip_shortcodes( $text );
411
 
412
  // When $html is true, the excerpt should be created without including HTML tags in the
413
  // excerpt length
414
- if ( !empty( $html ) ) {
415
  // The text is short enough. No need to truncate
416
  if ( mb_strlen( preg_replace( '/<.*?>/', '', $text ) ) <= $length ) {
417
  return $text;
@@ -471,7 +459,7 @@ function bp_create_excerpt( $text, $length = 225, $options = array() ) {
471
  }
472
 
473
  // If $exact is false, we can't break on words
474
- if ( empty( $exact ) ) {
475
  $spacepos = mb_strrpos( $truncate, ' ' );
476
  if ( isset( $spacepos ) ) {
477
  if ( $html ) {
@@ -502,25 +490,11 @@ function bp_create_excerpt( $text, $length = 225, $options = array() ) {
502
  add_filter( 'bp_create_excerpt', 'stripslashes_deep' );
503
  add_filter( 'bp_create_excerpt', 'force_balance_tags' );
504
 
505
- /**
506
- * Echoes the output of bp_get_total_member_count()
507
- */
508
  function bp_total_member_count() {
509
  echo bp_get_total_member_count();
510
  }
511
- /**
512
- * Returns the total member count in your BP instance
513
- *
514
- * Since BuddyPress 1.6, this function has used bp_core_get_active_member_count(), which
515
- * counts non-spam, non-deleted users who have last_activity. This value will correctly
516
- * match the total member count number used for pagination on member directories.
517
- *
518
- * Before BuddyPress 1.6, this function used bp_core_get_total_member_count(), which did
519
- * not take into account last_activity, and thus often resulted in higher counts than
520
- * shown by member directory pagination.
521
- */
522
  function bp_get_total_member_count() {
523
- return apply_filters( 'bp_get_total_member_count', bp_core_get_active_member_count() );
524
  }
525
  add_filter( 'bp_get_total_member_count', 'bp_core_number_format' );
526
 
@@ -581,7 +555,7 @@ function bp_current_component() {
581
 
582
  function bp_current_action() {
583
  global $bp;
584
- $current_action = !empty( $bp->current_action ) ? $bp->current_action : '';
585
  return apply_filters( 'bp_current_action', $current_action );
586
  }
587
 
@@ -608,7 +582,7 @@ function bp_action_variables() {
608
  * Return the value of a given action variable
609
  *
610
  * @package BuddyPress
611
- * @since BuddyPress (1.5)
612
  *
613
  * @param int $position The key of the action_variables array that you want
614
  * @return str $action_variable The value of that position in the array
@@ -640,7 +614,7 @@ function bp_root_domain() {
640
  * Echoes the output of bp_get_root_slug()
641
  *
642
  * @package BuddyPress Core
643
- * @since BuddyPress (1.5)
644
  */
645
  function bp_root_slug( $component = '' ) {
646
  echo bp_get_root_slug( $component );
@@ -661,9 +635,9 @@ function bp_root_slug( $component = '' ) {
661
  * $bp->groups->root_slug.
662
  *
663
  * @package BuddyPress Core
664
- * @since BuddyPress (1.5)
665
  *
666
- * @global BuddyPress $bp The one true BuddyPress instance
667
  * @param string $component Optional. Defaults to the current component
668
  * @return string $root_slug The root slug
669
  */
@@ -674,7 +648,7 @@ function bp_root_slug( $component = '' ) {
674
 
675
  // Use current global component if none passed
676
  if ( empty( $component ) )
677
- $component = bp_current_component();
678
 
679
  // Component is active
680
  if ( !empty( $bp->active_components[$component] ) ) {
@@ -699,7 +673,7 @@ function bp_root_slug( $component = '' ) {
699
  * Return the component name based on the current root slug
700
  *
701
  * @since BuddyPress {r3923}
702
- * @global BuddyPress $bp The one true BuddyPress instance
703
  * @param str $root_slug Needle to our active component haystack
704
  * @return mixed False if none found, component name if found
705
  */
@@ -708,24 +682,24 @@ function bp_get_name_from_root_slug( $root_slug = '' ) {
708
 
709
  // If no slug is passed, look at current_component
710
  if ( empty( $root_slug ) )
711
- $root_slug = bp_current_component();
712
 
713
  // No current component or root slug, so flee
714
  if ( empty( $root_slug ) )
715
  return false;
716
 
717
  // Loop through active components and look for a match
718
- foreach ( $bp->active_components as $component => $id ) {
719
- if ( !empty( $bp->{$component}->root_slug ) && ( $bp->{$component}->root_slug == $root_slug ) ) {
 
 
720
  return $bp->{$component}->name;
721
- }
722
- }
723
 
724
  return false;
725
  }
726
 
727
  function bp_user_has_access() {
728
- $has_access = ( bp_current_user_can( 'bp_moderate' ) || bp_is_my_profile() ) ? true : false;
729
 
730
  return apply_filters( 'bp_user_has_access', $has_access );
731
  }
@@ -734,7 +708,7 @@ function bp_user_has_access() {
734
  * Output the search slug
735
  *
736
  * @package BuddyPress
737
- * @since BuddyPress (1.5)
738
  *
739
  * @uses bp_get_search_slug()
740
  */
@@ -745,7 +719,7 @@ function bp_search_slug() {
745
  * Return the search slug
746
  *
747
  * @package BuddyPress
748
- * @since BuddyPress (1.5)
749
  */
750
  function bp_get_search_slug() {
751
  return apply_filters( 'bp_get_search_slug', BP_SEARCH_SLUG );
@@ -763,7 +737,7 @@ function bp_search_slug() {
763
  * - the component's id, or 'canonical' name
764
  *
765
  * @package BuddyPress Core
766
- * @since BuddyPress (1.5)
767
  * @return bool Returns true if the component matches, or else false.
768
  */
769
  function bp_is_current_component( $component ) {
@@ -776,7 +750,6 @@ function bp_is_current_component( $component ) {
776
  $component = 'profile';
777
 
778
  if ( !empty( $bp->current_component ) ) {
779
-
780
  // First, check to see whether $component_name and the current
781
  // component are a simple match
782
  if ( $bp->current_component == $component ) {
@@ -795,9 +768,8 @@ function bp_is_current_component( $component ) {
795
  // non-translatable component name. If so, we can return its
796
  // corresponding slug from $bp->active_components.
797
  } else if ( $key = array_search( $component, $bp->active_components ) ) {
798
- if ( strstr( $bp->current_component, $key ) ) {
799
  $is_current_component = true;
800
- }
801
 
802
  // If we haven't found a match yet, check against the root_slugs
803
  // created by $bp->pages, as well as the regular slugs
@@ -805,9 +777,8 @@ function bp_is_current_component( $component ) {
805
  foreach ( $bp->active_components as $id ) {
806
  // If the $component parameter does not match the current_component,
807
  // then move along, these are not the droids you are looking for
808
- if ( empty( $bp->{$id}->root_slug ) || $bp->{$id}->root_slug != $bp->current_component ) {
809
  continue;
810
- }
811
 
812
  if ( $id == $component ) {
813
  $is_current_component = true;
@@ -824,9 +795,8 @@ function bp_is_current_component( $component ) {
824
  $page_template = $custom_fields[0];
825
 
826
  // Component name is in the page template name
827
- if ( !empty( $page_template ) && strstr( strtolower( $page_template ), strtolower( $component ) ) ) {
828
  $is_current_component = true;
829
- }
830
  }
831
 
832
  return apply_filters( 'bp_is_current_component', $is_current_component, $component );
@@ -844,13 +814,15 @@ function bp_is_current_component( $component ) {
844
  * the current_action is 'members'.
845
  *
846
  * @package BuddyPress
847
- * @since BuddyPress (1.5)
848
  *
849
  * @param str $action The action being tested against
850
  * @return bool True if the current action matches $action
851
  */
852
  function bp_is_current_action( $action = '' ) {
853
- if ( $action == bp_current_action() )
 
 
854
  return true;
855
 
856
  return false;
@@ -868,7 +840,7 @@ function bp_is_current_action( $action = '' ) {
868
  * $action_variables[0] is 'group-settings'.
869
  *
870
  * @package BuddyPress
871
- * @since BuddyPress (1.5)
872
  *
873
  * @param str $action_variable The action_variable being tested against
874
  * @param int $position The array key you're testing against. If you don't provide a $position,
@@ -967,11 +939,11 @@ function bp_is_root_component( $component_name ) {
967
  * Checks if the site's front page is set to the specified BuddyPress component
968
  * page in wp-admin's Settings > Reading screen.
969
  *
970
- * @global BuddyPress $bp The one true BuddyPress instance
971
  * @global $current_blog WordPress global for the current blog
972
  * @param string $component Optional; Name of the component to check for.
973
  * @return bool True If the specified component is set to be the site's front page.
974
- * @since BuddyPress (1.5)
975
  */
976
  function bp_is_component_front_page( $component = '' ) {
977
  global $bp, $current_blog;
@@ -997,6 +969,7 @@ function bp_is_component_front_page( $component = '' ) {
997
  * @return bool True if it's a non-BP page, false otherwise
998
  */
999
  function bp_is_blog_page() {
 
1000
 
1001
  $is_blog_page = false;
1002
 
@@ -1024,7 +997,7 @@ function bp_is_page( $page ) {
1024
  function bp_is_active( $component ) {
1025
  global $bp;
1026
 
1027
- if ( isset( $bp->active_components[$component] ) || 'core' == $component )
1028
  return true;
1029
 
1030
  return false;
@@ -1096,7 +1069,9 @@ function bp_is_settings_component() {
1096
  /** Activity ******************************************************************/
1097
 
1098
  function bp_is_single_activity() {
1099
- if ( bp_is_activity_component() && is_numeric( bp_current_action() ) )
 
 
1100
  return true;
1101
 
1102
  return false;
@@ -1105,7 +1080,9 @@ function bp_is_single_activity() {
1105
  /** User **********************************************************************/
1106
 
1107
  function bp_is_my_profile() {
1108
- if ( is_user_logged_in() && bp_loggedin_user_id() == bp_displayed_user_id() )
 
 
1109
  $my_profile = true;
1110
  else
1111
  $my_profile = false;
@@ -1114,7 +1091,9 @@ function bp_is_my_profile() {
1114
  }
1115
 
1116
  function bp_is_user() {
1117
- if ( bp_displayed_user_id() && !is_404() )
 
 
1118
  return true;
1119
 
1120
  return false;
@@ -1198,7 +1177,7 @@ function bp_is_user_forums() {
1198
  * Is this a user's "Topics Started" page?
1199
  *
1200
  * @package BuddyPress
1201
- * @since BuddyPress (1.5)
1202
  *
1203
  * @return bool
1204
  */
@@ -1213,7 +1192,7 @@ function bp_is_user_forums_started() {
1213
  * Is this a user's "Replied To" page?
1214
  *
1215
  * @package BuddyPress
1216
- * @since BuddyPress (1.5)
1217
  *
1218
  * @return bool
1219
  */
@@ -1284,7 +1263,7 @@ function bp_is_user_settings() {
1284
  * Is this a user's General Settings page?
1285
  *
1286
  * @package BuddyPress
1287
- * @since BuddyPress (1.5)
1288
  *
1289
  * @return bool
1290
  */
@@ -1299,7 +1278,7 @@ function bp_is_user_settings_general() {
1299
  * Is this a user's Notification Settings page?
1300
  *
1301
  * @package BuddyPress
1302
- * @since BuddyPress (1.5)
1303
  *
1304
  * @return bool
1305
  */
@@ -1314,7 +1293,7 @@ function bp_is_user_settings_notifications() {
1314
  * Is this a user's Account Deletion page?
1315
  *
1316
  * @package BuddyPress
1317
- * @since BuddyPress (1.5)
1318
  *
1319
  * @return bool
1320
  */
@@ -1466,12 +1445,6 @@ function bp_is_notices() {
1466
  return false;
1467
  }
1468
 
1469
- function bp_is_messages_conversation() {
1470
- if ( bp_is_user_messages() && ( bp_is_current_action( 'view' ) ) )
1471
- return true;
1472
-
1473
- return false;
1474
- }
1475
 
1476
  function bp_is_single( $component, $callback ) {
1477
  if ( bp_is_current_component( $component ) && ( true === call_user_func( $callback ) ) )
@@ -1551,9 +1524,6 @@ function bp_the_body_class() {
1551
 
1552
  /** User **************************************************************/
1553
 
1554
- if ( bp_is_user() )
1555
- $bp_classes[] = 'bp-user';
1556
-
1557
  if ( !bp_is_directory() ) :
1558
  if ( bp_is_user_blogs() )
1559
  $bp_classes[] = 'my-blogs';
@@ -1638,15 +1608,11 @@ function bp_the_body_class() {
1638
  if ( bp_is_group_forum() )
1639
  $bp_classes[] = 'group-forum';
1640
 
1641
- if ( bp_is_group_admin_page() ) {
1642
  $bp_classes[] = 'group-admin';
1643
- $bp_classes[] = bp_get_group_current_admin_tab();
1644
- }
1645
 
1646
- if ( bp_is_group_create() ) {
1647
  $bp_classes[] = 'group-create';
1648
- $bp_classes[] = bp_get_groups_current_create_step();
1649
- }
1650
 
1651
  if ( bp_is_group_home() )
1652
  $bp_classes[] = 'group-home';
1
  <?php
 
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
13
  * or not to highlight a particular sub nav item.
14
  *
15
  * @package BuddyPress Core
16
+ * @global object $bp Global BuddyPress settings object
17
  * @uses bp_get_user_nav() Renders the navigation for a profile of a currently viewed user.
18
  */
19
  function bp_get_options_nav() {
21
 
22
  // If we are looking at a member profile, then the we can use the current component as an
23
  // index. Otherwise we need to use the component's root_slug
24
+ $component_index = !empty( $bp->displayed_user ) ? $bp->current_component : bp_get_root_slug( $bp->current_component );
25
 
26
  if ( !bp_is_single_item() ) {
27
  if ( !isset( $bp->bp_options_nav[$component_index] ) || count( $bp->bp_options_nav[$component_index] ) < 1 ) {
30
  $the_index = $component_index;
31
  }
32
  } else {
33
+ if ( !isset( $bp->bp_options_nav[$bp->current_item] ) || count( $bp->bp_options_nav[$bp->current_item] ) < 1 ) {
34
  return false;
35
  } else {
36
+ $the_index = $bp->current_item;
37
  }
38
  }
39
 
40
  // Loop through each navigation item
41
+ foreach ( (array)$bp->bp_options_nav[$the_index] as $subnav_item ) {
42
  if ( !$subnav_item['user_has_access'] )
43
  continue;
44
 
45
  // If the current action or an action variable matches the nav item id, then add a highlight CSS class.
46
+ if ( $subnav_item['slug'] == $bp->current_action ) {
47
  $selected = ' class="current selected"';
48
  } else {
49
  $selected = '';
73
  * like a group, or a friend. Basically an avatar that appears in the sub nav options bar.
74
  *
75
  * @package BuddyPress Core
76
+ * @global object $bp Global BuddyPress settings object
77
  */
78
  function bp_has_options_avatar() {
79
  global $bp;
94
  global $comment;
95
 
96
  if ( function_exists( 'bp_core_fetch_avatar' ) )
97
+ echo apply_filters( 'bp_comment_author_avatar', bp_core_fetch_avatar( array( 'item_id' => $comment->user_id, 'type' => 'thumb' ) ) );
98
  else if ( function_exists('get_avatar') )
99
  get_avatar();
100
  }
103
  global $post;
104
 
105
  if ( function_exists( 'bp_core_fetch_avatar' ) )
106
+ echo apply_filters( 'bp_post_author_avatar', bp_core_fetch_avatar( array( 'item_id' => $post->post_author, 'type' => 'thumb' ) ) );
107
  else if ( function_exists('get_avatar') )
108
  get_avatar();
109
  }
151
  echo '<img id="avatar-to-crop" class="avatar" src="' . $bp->avatar_admin->image . '" />';
152
  }
153
 
 
 
 
154
  function bp_site_name() {
155
+ echo apply_filters( 'bp_site_name', get_bloginfo( 'name', 'display' ) );
156
  }
 
 
 
 
 
 
 
 
157
 
158
  function bp_get_profile_header() {
159
  locate_template( array( '/profile/profile-header.php' ), true );
194
  }
195
 
196
  function bp_word_or_name( $youtext, $nametext, $capitalize = true, $echo = true ) {
197
+ global $bp;
198
 
199
+ if ( $capitalize )
200
+ $youtext = bp_core_ucfirst($youtext);
201
 
202
+ if ( $bp->displayed_user->id == $bp->loggedin_user->id ) {
203
+ if ( $echo )
204
  echo apply_filters( 'bp_word_or_name', $youtext );
205
+ else
206
  return apply_filters( 'bp_word_or_name', $youtext );
 
207
  } else {
208
+ $fullname = (array)explode( ' ', $bp->displayed_user->fullname );
 
209
  $nametext = sprintf( $nametext, $fullname[0] );
210
+ if ( $echo )
211
  echo apply_filters( 'bp_word_or_name', $nametext );
212
+ else
213
  return apply_filters( 'bp_word_or_name', $nametext );
 
214
  }
215
  }
216
 
226
  /** Search Form ***************************************************************/
227
 
228
  function bp_search_form_action() {
229
+ return apply_filters( 'bp_search_form_action', bp_get_root_domain() . '/' . bp_get_search_slug() );
230
  }
231
 
232
  /**
233
  * Generates the basic search form as used in BP-Default's header.
234
  *
235
+ * @global object $bp BuddyPress global settings
236
  * @return string HTML <select> element
237
  * @since 1.0
238
  */
239
  function bp_search_form_type_select() {
240
+ global $bp;
241
 
242
  $options = array();
243
 
260
  $selection_box .= '<select name="search-which" id="search-which" style="width: auto">';
261
 
262
  $options = apply_filters( 'bp_search_form_type_select_options', $options );
263
+ foreach( (array)$options as $option_value => $option_title )
264
  $selection_box .= sprintf( '<option value="%s">%s</option>', $option_value, $option_title );
265
 
266
  $selection_box .= '</select>';
273
  *
274
  * @global object $bp BuddyPress global settings
275
  * @return string
276
+ * @since 1.5
277
  */
278
  function bp_search_default_text( $component = '' ) {
279
  echo bp_get_search_default_text( $component );
394
  $ending = apply_filters( 'bp_excerpt_append_text', $ending );
395
 
396
  // Remove shortcodes if necessary
397
+ if ( $filter_shortcodes )
398
  $text = strip_shortcodes( $text );
399
 
400
  // When $html is true, the excerpt should be created without including HTML tags in the
401
  // excerpt length
402
+ if ( $html ) {
403
  // The text is short enough. No need to truncate
404
  if ( mb_strlen( preg_replace( '/<.*?>/', '', $text ) ) <= $length ) {
405
  return $text;
459
  }
460
 
461
  // If $exact is false, we can't break on words
462
+ if ( !$exact ) {
463
  $spacepos = mb_strrpos( $truncate, ' ' );
464
  if ( isset( $spacepos ) ) {
465
  if ( $html ) {
490
  add_filter( 'bp_create_excerpt', 'stripslashes_deep' );
491
  add_filter( 'bp_create_excerpt', 'force_balance_tags' );
492
 
 
 
 
493
  function bp_total_member_count() {
494
  echo bp_get_total_member_count();
495
  }
 
 
 
 
 
 
 
 
 
 
 
496
  function bp_get_total_member_count() {
497
+ return apply_filters( 'bp_get_total_member_count', bp_core_get_total_member_count() );
498
  }
499
  add_filter( 'bp_get_total_member_count', 'bp_core_number_format' );
500
 
555
 
556
  function bp_current_action() {
557
  global $bp;
558
+ $current_action = !empty( $bp->current_action ) ? $bp->current_action : false;
559
  return apply_filters( 'bp_current_action', $current_action );
560
  }
561
 
582
  * Return the value of a given action variable
583
  *
584
  * @package BuddyPress
585
+ * @since 1.5
586
  *
587
  * @param int $position The key of the action_variables array that you want
588
  * @return str $action_variable The value of that position in the array
614
  * Echoes the output of bp_get_root_slug()
615
  *
616
  * @package BuddyPress Core
617
+ * @since 1.5
618
  */
619
  function bp_root_slug( $component = '' ) {
620
  echo bp_get_root_slug( $component );
635
  * $bp->groups->root_slug.
636
  *
637
  * @package BuddyPress Core
638
+ * @since 1.5
639
  *
640
+ * @global object $bp Global BuddyPress settings object
641
  * @param string $component Optional. Defaults to the current component
642
  * @return string $root_slug The root slug
643
  */
648
 
649
  // Use current global component if none passed
650
  if ( empty( $component ) )
651
+ $component = $bp->current_component;
652
 
653
  // Component is active
654
  if ( !empty( $bp->active_components[$component] ) ) {
673
  * Return the component name based on the current root slug
674
  *
675
  * @since BuddyPress {r3923}
676
+ * @global object $bp Global BuddyPress settings object
677
  * @param str $root_slug Needle to our active component haystack
678
  * @return mixed False if none found, component name if found
679
  */
682
 
683
  // If no slug is passed, look at current_component
684
  if ( empty( $root_slug ) )
685
+ $root_slug = $bp->current_component;
686
 
687
  // No current component or root slug, so flee
688
  if ( empty( $root_slug ) )
689
  return false;
690
 
691
  // Loop through active components and look for a match
692
+ foreach ( $bp->active_components as $component => $id )
693
+ if ( isset( $bp->{$component}->root_slug ) &&
694
+ !empty( $bp->{$component}->root_slug ) &&
695
+ $bp->{$component}->root_slug == $root_slug )
696
  return $bp->{$component}->name;
 
 
697
 
698
  return false;
699
  }
700
 
701
  function bp_user_has_access() {
702
+ $has_access = ( is_super_admin() || bp_is_my_profile() ) ? true : false;
703
 
704
  return apply_filters( 'bp_user_has_access', $has_access );
705
  }
708
  * Output the search slug
709
  *
710
  * @package BuddyPress
711
+ * @since 1.5
712
  *
713
  * @uses bp_get_search_slug()
714
  */
719
  * Return the search slug
720
  *
721
  * @package BuddyPress
722
+ * @since 1.5
723
  */
724
  function bp_get_search_slug() {
725
  return apply_filters( 'bp_get_search_slug', BP_SEARCH_SLUG );
737
  * - the component's id, or 'canonical' name
738
  *
739
  * @package BuddyPress Core
740
+ * @since 1.5
741
  * @return bool Returns true if the component matches, or else false.
742
  */
743
  function bp_is_current_component( $component ) {
750
  $component = 'profile';
751
 
752
  if ( !empty( $bp->current_component ) ) {
 
753
  // First, check to see whether $component_name and the current
754
  // component are a simple match
755
  if ( $bp->current_component == $component ) {
768
  // non-translatable component name. If so, we can return its
769
  // corresponding slug from $bp->active_components.
770
  } else if ( $key = array_search( $component, $bp->active_components ) ) {
771
+ if ( strstr( $bp->current_component, $key ) )
772
  $is_current_component = true;
 
773
 
774
  // If we haven't found a match yet, check against the root_slugs
775
  // created by $bp->pages, as well as the regular slugs
777
  foreach ( $bp->active_components as $id ) {
778
  // If the $component parameter does not match the current_component,
779
  // then move along, these are not the droids you are looking for
780
+ if ( empty( $bp->{$id}->root_slug ) || $bp->{$id}->root_slug != $bp->current_component )
781
  continue;
 
782
 
783
  if ( $id == $component ) {
784
  $is_current_component = true;
795
  $page_template = $custom_fields[0];
796
 
797
  // Component name is in the page template name
798
+ if ( !empty( $page_template ) && strstr( strtolower( $page_template ), strtolower( $component ) ) )
799
  $is_current_component = true;
 
800
  }
801
 
802
  return apply_filters( 'bp_is_current_component', $is_current_component, $component );
814
  * the current_action is 'members'.
815
  *
816
  * @package BuddyPress
817
+ * @since 1.5
818
  *
819
  * @param str $action The action being tested against
820
  * @return bool True if the current action matches $action
821
  */
822
  function bp_is_current_action( $action = '' ) {
823
+ global $bp;
824
+
825
+ if ( $action == $bp->current_action )
826
  return true;
827
 
828
  return false;
840
  * $action_variables[0] is 'group-settings'.
841
  *
842
  * @package BuddyPress
843
+ * @since 1.5
844
  *
845
  * @param str $action_variable The action_variable being tested against
846
  * @param int $position The array key you're testing against. If you don't provide a $position,
939
  * Checks if the site's front page is set to the specified BuddyPress component
940
  * page in wp-admin's Settings > Reading screen.
941
  *
942
+ * @global object $bp Global BuddyPress settings object
943
  * @global $current_blog WordPress global for the current blog
944
  * @param string $component Optional; Name of the component to check for.
945
  * @return bool True If the specified component is set to be the site's front page.
946
+ * @since 1.5
947
  */
948
  function bp_is_component_front_page( $component = '' ) {
949
  global $bp, $current_blog;
969
  * @return bool True if it's a non-BP page, false otherwise
970
  */
971
  function bp_is_blog_page() {
972
+ global $wp_query;
973
 
974
  $is_blog_page = false;
975
 
997
  function bp_is_active( $component ) {
998
  global $bp;
999
 
1000
+ if ( isset( $bp->active_components[$component] ) )
1001
  return true;
1002
 
1003
  return false;
1069
  /** Activity ******************************************************************/
1070
 
1071
  function bp_is_single_activity() {
1072
+ global $bp;
1073
+
1074
+ if ( bp_is_activity_component() && is_numeric( $bp->current_action ) )
1075
  return true;
1076
 
1077
  return false;
1080
  /** User **********************************************************************/
1081
 
1082
  function bp_is_my_profile() {
1083
+ global $bp;
1084
+
1085
+ if ( is_user_logged_in() && $bp->loggedin_user->id == $bp->displayed_user->id )
1086
  $my_profile = true;
1087
  else
1088
  $my_profile = false;
1091
  }
1092
 
1093
  function bp_is_user() {
1094
+ global $bp;
1095
+
1096
+ if ( !empty( $bp->displayed_user->id ) )
1097
  return true;
1098
 
1099
  return false;
1177
  * Is this a user's "Topics Started" page?
1178
  *
1179
  * @package BuddyPress
1180
+ * @since 1.5
1181
  *
1182
  * @return bool
1183
  */
1192
  * Is this a user's "Replied To" page?
1193
  *
1194
  * @package BuddyPress
1195
+ * @since 1.5
1196
  *
1197
  * @return bool
1198
  */
1263
  * Is this a user's General Settings page?
1264
  *
1265
  * @package BuddyPress
1266
+ * @since 1.5
1267
  *
1268
  * @return bool
1269
  */
1278
  * Is this a user's Notification Settings page?
1279
  *
1280
  * @package BuddyPress
1281
+ * @since 1.5
1282
  *
1283
  * @return bool
1284
  */
1293
  * Is this a user's Account Deletion page?
1294
  *
1295
  * @package BuddyPress
1296
+ * @since 1.5
1297
  *
1298
  * @return bool
1299
  */
1445
  return false;
1446
  }
1447
 
 
 
 
 
 
 
1448
 
1449
  function bp_is_single( $component, $callback ) {
1450
  if ( bp_is_current_component( $component ) && ( true === call_user_func( $callback ) ) )
1524
 
1525
  /** User **************************************************************/
1526
 
 
 
 
1527
  if ( !bp_is_directory() ) :
1528
  if ( bp_is_user_blogs() )
1529
  $bp_classes[] = 'my-blogs';
1608
  if ( bp_is_group_forum() )
1609
  $bp_classes[] = 'group-forum';
1610
 
1611
+ if ( bp_is_group_admin_page() )
1612
  $bp_classes[] = 'group-admin';
 
 
1613
 
1614
+ if ( bp_is_group_create() )
1615
  $bp_classes[] = 'group-create';
 
 
1616
 
1617
  if ( bp_is_group_home() )
1618
  $bp_classes[] = 'group-home';
bp-core/bp-core-update.php DELETED
@@ -1,197 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * BuddyPress Updater
5
- *
6
- * @package BuddyPress
7
- * @subpackage Updater
8
- */
9
-
10
- // Exit if accessed directly
11
- if ( !defined( 'ABSPATH' ) ) exit;
12
-
13
- /**
14
- * Compare the BuddyPress version to the DB version to determine if updating
15
- *
16
- * @since BuddyPress (1.6)
17
- *
18
- * @uses get_option()
19
- * @uses bp_get_db_version() To get BuddyPress's database version
20
- * @return bool True if update, False if not
21
- */
22
- function bp_is_update() {
23
-
24
- // Current DB version of this site (per site in a multisite network)
25
- $current_db = bp_get_option( '_bp_db_version' );
26
- $current_live = bp_get_db_version();
27
-
28
- // Compare versions (cast as int and bool to be safe)
29
- $is_update = (bool) ( (int) $current_db < (int) $current_live );
30
-
31
- // Return the product of version comparison
32
- return $is_update;
33
- }
34
-
35
- /**
36
- * Determine if BuddyPress is being activated
37
- *
38
- * @since BuddyPress (1.6)
39
- *
40
- * @global BuddyPress $bp
41
- * @return bool True if activating BuddyPress, false if not
42
- */
43
- function bp_is_activation( $basename = '' ) {
44
- global $bp;
45
-
46
- // Baif if action or plugin are empty
47
- if ( empty( $_GET['action'] ) || empty( $_GET['plugin'] ) )
48
- return false;
49
-
50
- // Bail if not activating
51
- if ( 'activate' !== $_GET['action'] )
52
- return false;
53
-
54
- // The plugin being activated
55
- $plugin = isset( $_GET['plugin'] ) ? $_GET['plugin'] : '';
56
-
57
- // Set basename if empty
58
- if ( empty( $basename ) && !empty( $bp->basename ) )
59
- $basename = $bp->basename;
60
-
61
- // Bail if no basename
62
- if ( empty( $basename ) )
63
- return false;
64
-
65
- // Bail if plugin is not BuddyPress
66
- if ( $basename !== $plugin )
67
- return false;
68
-
69
- return true;
70
- }
71
-
72
- /**
73
- * Determine if BuddyPress is being deactivated
74
- *
75
- * @since BuddyPress (1.6)
76
- *
77
- * @global BuddyPress $bp
78
- * @return bool True if deactivating BuddyPress, false if not
79
- */
80
- function bp_is_deactivation( $basename = '' ) {
81
- global $bp;
82
-
83
- // Baif if action or plugin are empty
84
- if ( empty( $_GET['action'] ) || empty( $_GET['plugin'] ) )
85
- return false;
86
-
87
- // Bail if not deactivating
88
- if ( 'deactivate' !== $_GET['action'] )
89
- return false;
90
-
91
- // The plugin being deactivated
92
- $plugin = isset( $_GET['plugin'] ) ? $_GET['plugin'] : '';
93
-
94
- // Set basename if empty
95
- if ( empty( $basename ) && !empty( $bp->basename ) )
96
- $basename = $bp->basename;
97
-
98
- // Bail if no basename
99
- if ( empty( $basename ) )
100
- return false;
101
-
102
- // Bail if plugin is not BuddyPress
103
- if ( $basename !== $plugin )
104
- return false;
105
-
106
- return true;
107
- }
108
-
109
- /**
110
- * Update the DB to the latest version
111
- *
112
- * @since BuddyPress (1.6)
113
- *
114
- * @uses update_option()
115
- * @uses bp_get_db_version() To get BuddyPress's database version
116
- * @uses bp_update_option() To update BuddyPress's database version
117
- */
118
- function bp_version_bump() {
119
- $db_version = bp_get_db_version();
120
- bp_update_option( '_bp_db_version', $db_version );
121
- }
122
-
123
- /**
124
- * Setup the BuddyPress updater
125
- *
126
- * @since BuddyPress (1.6)
127
- *
128
- * @uses BBP_Updater
129
- */
130
- function bp_setup_updater() {
131
-
132
- // Are we running an outdated version of BuddyPress?
133
- if ( bp_is_update() ) {
134
-
135
- // Bump the version
136
- bp_version_bump();
137
-
138
- // Run the deactivation function to wipe roles, caps, and rewrite rules
139
- bp_deactivation();
140
-
141
- // Run the activation function to reset roles, caps, and rewrite rules
142
- bp_activation();
143
- }
144
- }
145
-
146
- /** Activation Actions ********************************************************/
147
-
148
- /**
149
- * Runs on BuddyPress activation
150
- *
151
- * @since BuddyPress (1.6)
152
- *
153
- * @uses do_action() Calls 'bp_activation' hook
154
- */
155
- function bp_activation() {
156
-
157
- // Force refresh theme roots.
158
- delete_site_transient( 'theme_roots' );
159
-
160
- // Use as of (1.6)
161
- do_action( 'bp_activation' );
162
-
163
- // @deprecated as of (1.6)
164
- do_action( 'bp_loader_activate' );
165
- }
166
-
167
- /**
168
- * Runs on BuddyPress deactivation
169
- *
170
- * @since BuddyPress (1.6)
171
- *
172
- * @uses do_action() Calls 'bp_deactivation' hook
173
- */
174
- function bp_deactivation() {
175
-
176
- // Force refresh theme roots.
177
- delete_site_transient( 'theme_roots' );
178
-
179
- // Use as of (1.6)
180
- do_action( 'bp_deactivation' );
181
-
182
- // @deprecated as of (1.6)
183
- do_action( 'bp_loader_deactivate' );
184
- }
185
-
186
- /**
187
- * Runs when uninstalling BuddyPress
188
- *
189
- * @since BuddyPress (1.6)
190
- *
191
- * @uses do_action() Calls 'bp_uninstall' hook
192
- */
193
- function bp_uninstall() {
194
- do_action( 'bp_uninstall' );
195
- }
196
-
197
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-core/bp-core-widgets.php CHANGED
@@ -14,20 +14,24 @@ add_action( 'bp_register_widgets', 'bp_core_register_widgets' );
14
 
15
  class BP_Core_Members_Widget extends WP_Widget {
16
 
 
 
 
 
17
  function __construct() {
18
  $widget_ops = array( 'description' => __( 'A dynamic list of recently active, popular, and newest members', 'buddypress' ) );
19
  parent::__construct( false, $name = __( 'Members', 'buddypress' ), $widget_ops );
20
 
21
  if ( is_active_widget( false, false, $this->id_base ) && !is_admin() && !is_network_admin() ) {
22
- if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
23
- wp_enqueue_script( 'bp_core_widget_members-js', BP_PLUGIN_URL . 'bp-core/js/widget-members.dev.js', array( 'jquery' ), bp_get_version() );
24
- } else {
25
- wp_enqueue_script( 'bp_core_widget_members-js', BP_PLUGIN_URL . 'bp-core/js/widget-members.js', array( 'jquery' ), bp_get_version() );
26
- }
27
  }
28
  }
29
 
30
  function widget( $args, $instance ) {
 
31
 
32
  extract( $args );
33
 
@@ -35,11 +39,8 @@ class BP_Core_Members_Widget extends WP_Widget {
35
  $instance['member_default'] = 'active';
36
 
37
  echo $before_widget;
38
-
39
- $title = $instance['link_title'] ? '<a href="' . trailingslashit( bp_get_root_domain() . '/' . bp_get_members_root_slug() ) . '">' . $instance['title'] . '</a>' : $instance['title'];
40
-
41
  echo $before_title
42
- . $title
43
  . $after_title; ?>
44
 
45
  <?php if ( bp_has_members( 'user_id=0&type=' . $instance['member_default'] . '&max=' . $instance['max_members'] . '&populate_extras=0' ) ) : ?>
@@ -97,34 +98,28 @@ class BP_Core_Members_Widget extends WP_Widget {
97
 
98
  function update( $new_instance, $old_instance ) {
99
  $instance = $old_instance;
100
-
101
- $instance['title'] = strip_tags( $new_instance['title'] );
102
- $instance['max_members'] = strip_tags( $new_instance['max_members'] );
103
  $instance['member_default'] = strip_tags( $new_instance['member_default'] );
104
- $instance['link_title'] = (bool)$new_instance['link_title'];
105
 
106
  return $instance;
107
  }
108
 
109
  function form( $instance ) {
110
  $defaults = array(
111
- 'title' => __( 'Members', 'buddypress' ),
112
- 'max_members' => 5,
113
- 'member_default' => 'active',
114
- 'link_title' => false
115
  );
116
  $instance = wp_parse_args( (array) $instance, $defaults );
117
 
118
- $title = strip_tags( $instance['title'] );
119
- $max_members = strip_tags( $instance['max_members'] );
120
  $member_default = strip_tags( $instance['member_default'] );
121
- $link_title = (bool)$instance['link_title'];
122
  ?>
123
 
124
  <p><label for="bp-core-widget-title"><?php _e('Title:', '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>
125
 
126
- <p><label for="<?php echo $this->get_field_name('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 Members directory', 'buddypress' ) ?></label></p>
127
-
128
  <p><label for="bp-core-widget-members-max"><?php _e('Max members to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="text" value="<?php echo esc_attr( $max_members ); ?>" style="width: 30%" /></label></p>
129
 
130
  <p>
@@ -145,12 +140,17 @@ class BP_Core_Members_Widget extends WP_Widget {
145
 
146
  class BP_Core_Whos_Online_Widget extends WP_Widget {
147
 
 
 
 
 
148
  function __construct() {
149
  $widget_ops = array( 'description' => __( 'Avatars of users who are currently online', 'buddypress' ) );
150
  parent::__construct( false, $name = __( "Who's Online Avatars", 'buddypress' ), $widget_ops );
151
  }
152
 
153
  function widget($args, $instance) {
 
154
 
155
  extract( $args );
156
 
@@ -209,12 +209,17 @@ class BP_Core_Whos_Online_Widget extends WP_Widget {
209
 
210
  class BP_Core_Recently_Active_Widget extends WP_Widget {
211
 
 
 
 
 
212
  function __construct() {
213
  $widget_ops = array( 'description' => __( 'Avatars of recently active members', 'buddypress' ) );
214
  parent::__construct( false, $name = __( 'Recently Active Member Avatars', 'buddypress' ), $widget_ops );
215
  }
216
 
217
- function widget( $args, $instance ) {
 
218
 
219
  extract( $args );
220
 
@@ -272,6 +277,7 @@ class BP_Core_Recently_Active_Widget extends WP_Widget {
272
  /** Widget AJAX ******************/
273
 
274
  function bp_core_ajax_widget_members() {
 
275
 
276
  check_ajax_referer( 'bp_core_widget_members' );
277
 
14
 
15
  class BP_Core_Members_Widget extends WP_Widget {
16
 
17
+ function bp_core_members_widget() {
18
+ $this->__construct();
19
+ }
20
+
21
  function __construct() {
22
  $widget_ops = array( 'description' => __( 'A dynamic list of recently active, popular, and newest members', 'buddypress' ) );
23
  parent::__construct( false, $name = __( 'Members', 'buddypress' ), $widget_ops );
24
 
25
  if ( is_active_widget( false, false, $this->id_base ) && !is_admin() && !is_network_admin() ) {
26
+ if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG )
27
+ wp_enqueue_script( 'bp_core_widget_members-js', BP_PLUGIN_URL . '/bp-core/js/widget-members.dev.js', array( 'jquery' ), '20110723' );
28
+ else
29
+ wp_enqueue_script( 'bp_core_widget_members-js', BP_PLUGIN_URL . '/bp-core/js/widget-members.js', array( 'jquery' ), '20110723' );
 
30
  }
31
  }
32
 
33
  function widget( $args, $instance ) {
34
+ global $bp;
35
 
36
  extract( $args );
37
 
39
  $instance['member_default'] = 'active';
40
 
41
  echo $before_widget;
 
 
 
42
  echo $before_title
43
+ . $instance['title']
44
  . $after_title; ?>
45
 
46
  <?php if ( bp_has_members( 'user_id=0&type=' . $instance['member_default'] . '&max=' . $instance['max_members'] . '&populate_extras=0' ) ) : ?>
98
 
99
  function update( $new_instance, $old_instance ) {
100
  $instance = $old_instance;
101
+ $instance['title'] = strip_tags( $new_instance['title'] );
102
+ $instance['max_members'] = strip_tags( $new_instance['max_members'] );
 
103
  $instance['member_default'] = strip_tags( $new_instance['member_default'] );
 
104
 
105
  return $instance;
106
  }
107
 
108
  function form( $instance ) {
109
  $defaults = array(
110
+ 'title' => __( 'Members', 'buddypress' ),
111
+ 'max_members' => 5,
112
+ 'member_default' => 'active'
 
113
  );
114
  $instance = wp_parse_args( (array) $instance, $defaults );
115
 
116
+ $title = strip_tags( $instance['title'] );
117
+ $max_members = strip_tags( $instance['max_members'] );
118
  $member_default = strip_tags( $instance['member_default'] );
 
119
  ?>
120
 
121
  <p><label for="bp-core-widget-title"><?php _e('Title:', '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>
122
 
 
 
123
  <p><label for="bp-core-widget-members-max"><?php _e('Max members to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="text" value="<?php echo esc_attr( $max_members ); ?>" style="width: 30%" /></label></p>
124
 
125
  <p>
140
 
141
  class BP_Core_Whos_Online_Widget extends WP_Widget {
142
 
143
+ function bp_core_whos_online_widget() {
144
+ $this->__construct();
145
+ }
146
+
147
  function __construct() {
148
  $widget_ops = array( 'description' => __( 'Avatars of users who are currently online', 'buddypress' ) );
149
  parent::__construct( false, $name = __( "Who's Online Avatars", 'buddypress' ), $widget_ops );
150
  }
151
 
152
  function widget($args, $instance) {
153
+ global $bp;
154
 
155
  extract( $args );
156
 
209
 
210
  class BP_Core_Recently_Active_Widget extends WP_Widget {
211
 
212
+ function bp_core_recently_active_widget() {
213
+ $this->__construct();
214
+ }
215
+
216
  function __construct() {
217
  $widget_ops = array( 'description' => __( 'Avatars of recently active members', 'buddypress' ) );
218
  parent::__construct( false, $name = __( 'Recently Active Member Avatars', 'buddypress' ), $widget_ops );
219
  }
220
 
221
+ function widget($args, $instance) {
222
+ global $bp;
223
 
224
  extract( $args );
225
 
277
  /** Widget AJAX ******************/
278
 
279
  function bp_core_ajax_widget_members() {
280
+ global $bp;
281
 
282
  check_ajax_referer( 'bp_core_widget_members' );
283
 
bp-core/bp-core-wpabstraction.php CHANGED
@@ -5,27 +5,28 @@
5
  * The functions within this file will detect the version of WordPress you are running
6
  * and will alter the environment so BuddyPress can run regardless.
7
  *
8
- * The code below mostly contains function mappings. This file is subject to change at any time.
 
9
  */
10
 
11
  // Exit if accessed directly
12
  if ( !defined( 'ABSPATH' ) ) exit;
13
 
14
  /**
15
- * Parse the WordPress core version number into the major release
16
  *
17
  * @since BuddyPress (1.5.2)
18
  * @global string $wp_version
19
- * @return string
20
  */
21
  function bp_get_major_wp_version() {
22
  global $wp_version;
23
-
24
  return (float) $wp_version;
25
  }
26
 
27
  /**
28
- * Only add MS-specific abstraction functions if WordPress is not in multisite mode
29
  */
30
  if ( !is_multisite() ) {
31
  global $wpdb;
5
  * The functions within this file will detect the version of WordPress you are running
6
  * and will alter the environment so BuddyPress can run regardless.
7
  *
8
+ * The code below mostly contains function mappings. This code is subject to change once
9
+ * the 3.0 WordPress version merge takes place.
10
  */
11
 
12
  // Exit if accessed directly
13
  if ( !defined( 'ABSPATH' ) ) exit;
14
 
15
  /**
16
+ * Parso the WordPress core version number into the major release
17
  *
18
  * @since BuddyPress (1.5.2)
19
  * @global string $wp_version
20
+ * @return string
21
  */
22
  function bp_get_major_wp_version() {
23
  global $wp_version;
24
+
25
  return (float) $wp_version;
26
  }
27
 
28
  /**
29
+ * Only add abstraction functions if WordPress is not in multisite mode
30
  */
31
  if ( !is_multisite() ) {
32
  global $wpdb;
bp-core/css/admin-bar-rtl.css CHANGED
@@ -1 +1 @@
1
- #wpadminbar .quicklinks li#wp-admin-bar-my-account ul,#wpadminbar .quicklinks li#wp-admin-bar-my-account-with-avatar ul{left:auto;right:0}#wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar>a img,#wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar>a img{margin:-2px -5px 0 23px}#wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar ul,#wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul{left:auto;right:30px}#wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar ul ul,#wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul ul{left:auto;right:0}#wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul{left:auto;right:0}#wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul ul{left:auto;right:0}
1
+ #wpadminbar .quicklinks li#wp-admin-bar-my-account ul,#wpadminbar .quicklinks li#wp-admin-bar-my-account-with-avatar ul{left:auto;right:0;}#wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar>a img,#wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar>a img{margin:-2px -5px 0 23px;}#wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar ul,#wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul{left:auto;right:30px;}#wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar ul ul,#wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul ul{left:auto;right:0;}#wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul{left:auto;right:0;}#wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul ul{left:auto;right:0;}
bp-core/css/admin-bar.css CHANGED
@@ -1 +1 @@
1
- #wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar>a img,#wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar>a img{width:16px;height:16px;display:inline;border:1px solid #999;vertical-align:middle;margin:-2px 10px 0 -5px;padding:0;background:#eee;float:none}#wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul{left:0}#wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul ul{left:0}#wpadminbar .quicklinks li#wp-admin-bar-my-account a span.count,#wpadminbar .quicklinks li#wp-admin-bar-my-account-with-avatar a span.count,#wpadminbar .quicklinks li#wp-admin-bar-bp-notifications #ab-pending-notifications{background:#21759b;color:#fff;text-shadow:none;display:inline;padding:2px 5px;font-size:10px;font-weight:bold;-moz-border-radius:10px;-khtml-border-radius:10px;-webkit-border-radius:10px;border-radius:10px}#wpadminbar .quicklinks li#wp-admin-bar-bp-notifications #ab-pending-notifications{background:#ddd;color:#333;margin:0}#wpadminbar .quicklinks li#wp-admin-bar-bp-notifications #ab-pending-notifications.alert{background-color:#1fb3dd;color:#fff}#wpadminbar .quicklinks li#wp-admin-bar-bp-notifications>a{padding:0 .5em}#wp-admin-bar-user-info img.avatar{height:64px;width:64px}
1
+ #wpadminbar .quicklinks li#wp-admin-bar-my-account ul,#wpadminbar .quicklinks li#wp-admin-bar-my-account-with-avatar ul{left:0;right:auto;}#wp-admin-bar-user-info img.avatar{height:64px;width:64px;}#wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar>a{border-left:none;background:url(../images/admin-bar-sprite.png?d=11122010) top left no-repeat;}#wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar>a img,#wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar>a img{width:16px;height:16px;display:inline;border:1px solid #999;vertical-align:middle;margin:-2px 23px 0 -5px;padding:0;background:#eee;float:none;}#wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar ul,#wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul{left:30px;}#wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar ul ul,#wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul ul{left:0;}#wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar>a{border-left:none;background:url(../images/admin-bar-sprite.png?d=11122010) top left no-repeat;}#wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul{left:0;}#wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul ul{left:0;}#wpadminbar .quicklinks li#wp-admin-bar-my-account a span.count,#wpadminbar .quicklinks li#wp-admin-bar-my-account-with-avatar a span.count,#wpadminbar .quicklinks li#wp-admin-bar-bp-notifications #ab-pending-notifications{background:#eee;color:#333;text-shadow:none;display:inline;padding:2px 5px;font-size:10px;font-weight:bold;-moz-border-radius:10px;-khtml-border-radius:10px;-webkit-border-radius:10px;border-radius:10px;}
bp-core/css/admin-bar.dev.css CHANGED
@@ -1,4 +1,18 @@
 
 
 
 
 
 
 
 
 
 
1
  /* Displayed User */
 
 
 
 
2
  #wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar > a img,
3
  #wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar > a img {
4
  width: 16px;
@@ -6,26 +20,36 @@
6
  display: inline;
7
  border: 1px solid #999;
8
  vertical-align: middle;
9
- margin: -2px 10px 0 -5px;
10
  padding: 0;
11
  background: #eee;
12
  float: none;
13
  }
 
 
 
 
 
 
 
 
14
 
15
  /* Displayed Group */
 
 
 
 
16
  #wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul {
17
  left: 0;
18
  }
19
  #wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul ul {
20
  left: 0;
21
  }
22
-
23
- /* Notifications */
24
  #wpadminbar .quicklinks li#wp-admin-bar-my-account a span.count,
25
  #wpadminbar .quicklinks li#wp-admin-bar-my-account-with-avatar a span.count,
26
  #wpadminbar .quicklinks li#wp-admin-bar-bp-notifications #ab-pending-notifications {
27
- background: #21759B;
28
- color: #fff;
29
  text-shadow: none;
30
  display: inline;
31
  padding: 2px 5px;
@@ -35,24 +59,4 @@
35
  -khtml-border-radius: 10px;
36
  -webkit-border-radius: 10px;
37
  border-radius: 10px;
38
- }
39
-
40
- #wpadminbar .quicklinks li#wp-admin-bar-bp-notifications #ab-pending-notifications {
41
- background: #ddd;
42
- color: #333;
43
- margin: 0
44
- }
45
-
46
- #wpadminbar .quicklinks li#wp-admin-bar-bp-notifications #ab-pending-notifications.alert {
47
- background-color: #1fb3dd;
48
- color: #fff;
49
- }
50
-
51
- #wpadminbar .quicklinks li#wp-admin-bar-bp-notifications > a {
52
- padding: 0 .5em;
53
- }
54
-
55
- #wp-admin-bar-user-info img.avatar {
56
- height: 64px;
57
- width: 64px;
58
  }
1
+ #wpadminbar .quicklinks li#wp-admin-bar-my-account ul,
2
+ #wpadminbar .quicklinks li#wp-admin-bar-my-account-with-avatar ul {
3
+ left: 0;
4
+ right: auto;
5
+ }
6
+ #wp-admin-bar-user-info img.avatar {
7
+ height: 64px;
8
+ width: 64px;
9
+ }
10
+
11
  /* Displayed User */
12
+ #wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar > a {
13
+ border-left: none;
14
+ background: url(../images/admin-bar-sprite.png?d=11122010) top left no-repeat;
15
+ }
16
  #wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar > a img,
17
  #wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar > a img {
18
  width: 16px;
20
  display: inline;
21
  border: 1px solid #999;
22
  vertical-align: middle;
23
+ margin: -2px 23px 0 -5px;
24
  padding: 0;
25
  background: #eee;
26
  float: none;
27
  }
28
+ #wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar ul,
29
+ #wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul {
30
+ left: 30px;
31
+ }
32
+ #wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar ul ul,
33
+ #wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul ul {
34
+ left: 0;
35
+ }
36
 
37
  /* Displayed Group */
38
+ #wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar > a {
39
+ border-left: none;
40
+ background: url(../images/admin-bar-sprite.png?d=11122010) top left no-repeat;
41
+ }
42
  #wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul {
43
  left: 0;
44
  }
45
  #wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul ul {
46
  left: 0;
47
  }
 
 
48
  #wpadminbar .quicklinks li#wp-admin-bar-my-account a span.count,
49
  #wpadminbar .quicklinks li#wp-admin-bar-my-account-with-avatar a span.count,
50
  #wpadminbar .quicklinks li#wp-admin-bar-bp-notifications #ab-pending-notifications {
51
+ background: #eee;
52
+ color: #333;
53
  text-shadow: none;
54
  display: inline;
55
  padding: 2px 5px;
59
  -khtml-border-radius: 10px;
60
  -webkit-border-radius: 10px;
61
  border-radius: 10px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  }
bp-core/css/admin.css ADDED
@@ -0,0 +1 @@
 
1
+ div#icon-buddypress{background:url(../images/icons32.png) no-repeat -4px 0;}div#bp-admin{color:#555;min-width:680px;}div#bp-admin p{line-height:170%;}form#bp-admin-form{margin:0 10px;}div#bp-admin-nav{background:#e0e0e0;margin:15px -10px 10px;padding:10px 10px 0 10px;height:30px;-moz-border-radius:6px;-webkit-border-radius:6px;border-radius:6px;}div#bp-admin-nav div.submit{position:relative;float:right;margin-top:-36px!important;}div#bp-admin-nav div.submit input{padding:6px 10px;}div#bp-admin-nav ol{list-style-type:decimal;margin:0;padding:0;}div#bp-admin-nav ol li{float:left;margin:0 10px 0 0;color:#666;}div#bp-admin-nav ol li{padding:8px 12px;display:block;-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;text-decoration:none;}div#bp-admin-nav ol li.current{background:#f9f9f9;color:#555;}div#bp-admin-nav ol li span.complete{background:url(../images/completed.gif) center left no-repeat;padding:6px;}div.component{width:323px;float:left;margin:15px 30px 0 0;}div.component div.radio{position:relative;background:#e0e0e0;padding:5px 10px;-moz-border-radius:6px;-webkit-border-radius:6px;border-radius:6px;top:-6px;}div.component img{margin-top:10px;}div.component p{margin-left:4px;}div.component h5{font-size:18px;float:left;margin:0 0 0 4px;width:100px;}div.component div.radio{font-size:11px;float:right;top:5px;}div#bp-admin div.prev-next,div#bp-admin div.prev-next p,div#bp-admin div.submit,div#bp-admin div.submit p{margin:0;padding:0;}div#bp-admin div.submit{margin-top:30px;}div#bp-admin div.prev-next{text-align:right;margin-top:0;}div#bp-admin div.prev-next{margin:0 -20px;padding:0 20px 10px;}div#bp-admin table td{font-family:helvetica,arial,tahoma,sans-serif;vertical-align:top;}div#bp-admin table.form-table th{border-right:1px solid #eee;padding:15px 25px 15px 0;color:#555;vertical-align:top;}div#bp-admin table.form-table tr{border-bottom:1px dotted #f0f0f0;}div#bp-admin table.form-table td{padding-left:25px;font-size:12px;}div#bp-admin table.form-table th h5{font-size:14px;margin:0;line-height:150%;}div#bp-admin table.form-table th img{margin-top:5px;}div#bp-admin table.form-table th p{margin:3px 0 0 0;}div#bp-admin code,div#bp-admin kbd{font-size:12px;background:#f0f0f0;}div#bp-admin div#message code,div#bp-admin div#message kbd{background:#ffe293;}a.button{padding-top:4px;}a.installed,a.installed:hover,a.installed:active{padding-left:15px;color:#888;border-color:#ccc;cursor:default;}a.installed span{background:url(../images/installed.gif) left center no-repeat;padding:6px 10px 7px 6px;margin-left:-5px;}
bp-core/{admin/css/wizard.dev.css → css/admin.dev.css} RENAMED
@@ -1,60 +1,57 @@
 
 
 
1
 
2
- /* General Admin Styling
3
- ------------------------------------------------------------------------------*/
4
-
5
- div#bp-wizard {
6
  color: #555;
7
  min-width: 680px;
8
- }
9
- div#bp-wizard p {
10
- line-height: 170%;
11
- }
12
 
13
- form#bp-wizard-form {
14
  margin: 0 10px;
15
  }
16
 
17
- div#bp-wizard-nav {
18
  background: #e0e0e0;
19
  margin: 15px -10px 10px;
20
  padding: 10px 10px 0 10px;
21
  height: 30px;
22
- -moz-border-radius: 2px;
23
- -webkit-border-radius: 2px;
24
- border-radius: 2px;
25
  }
26
- div#bp-wizard-nav div.submit {
27
  position: relative;
28
  float: right;
29
  margin-top: -36px !important;
30
  }
31
- div#bp-wizard-nav div.submit input {
32
  padding: 6px 10px;
33
  }
34
- div#bp-wizard-nav ol {
35
  list-style-type: decimal;
36
  margin: 0;
37
  padding: 0;
38
  }
39
- div#bp-wizard-nav ol li {
40
  float: left;
41
  margin: 0 10px 0 0;
42
  color: #666;
43
  }
44
- div#bp-wizard-nav ol li {
45
  padding: 8px 12px;
46
  display: block;
47
- -moz-border-radius: 2px;
48
- -webkit-border-radius: 2px;
49
- border-radius: 2px;
50
  text-decoration: none;
51
  }
52
- div#bp-wizard-nav ol li.current {
53
- background: #fff;
54
  color: #555;
55
  }
56
-
57
- div#bp-wizard-nav ol li span.complete {
58
  background: url( ../images/completed.gif ) center left no-repeat;
59
  padding: 6px;
60
  }
@@ -68,9 +65,9 @@ div.component {
68
  position: relative;
69
  background: #e0e0e0;
70
  padding: 5px 10px;
71
- -moz-border-radius: 2px;
72
- -webkit-border-radius: 2px;
73
- border-radius: 2px;
74
  top: -6px;
75
  }
76
 
@@ -95,63 +92,53 @@ div.component {
95
  top: 5px;
96
  }
97
 
98
- div#bp-wizard div.prev-next, div#bp-wizard div.prev-next p,
99
- div#bp-wizard div.submit, div#bp-wizard div.submit p {
100
  margin: 0;
101
  padding: 0;
102
  }
103
- div#bp-wizard div.submit {
104
- margin-top: 30px;
105
- }
106
- div#bp-wizard div.prev-next {
107
- text-align: right;
108
- margin-top: 0;
109
- }
110
 
111
- div#bp-wizard div.prev-next {
112
  margin: 0 -20px;
113
  padding: 0 20px 10px;
114
  }
115
 
116
- div#bp-wizard table td {
117
  font-family: helvetica, arial, tahoma, sans-serif;
118
  vertical-align: top;
119
  }
120
 
121
- div#bp-wizard table.form-table th {
122
  border-right: 1px solid #eee;
123
  padding: 15px 25px 15px 0;
124
  color: #555;
125
  vertical-align: top;
126
  }
127
- div#bp-wizard table.form-table tr {
128
  border-bottom: 1px dotted #f0f0f0;
129
  }
130
- div#bp-wizard table.form-table td {
131
- padding-left: 25px;
132
- font-size: 12px;
133
- }
134
 
135
- div#bp-wizard table.form-table th h5 {
136
  font-size: 14px;
137
  margin: 0;
138
  line-height: 150%;
139
  }
140
 
141
- div#bp-wizard table.form-table th img {
142
  margin-top: 5px;
143
  }
144
 
145
- div#bp-wizard table.form-table th p {
146
- margin: 3px 0 0 0;
147
- }
148
 
149
- div#bp-wizard code, div#bp-wizard kbd {
150
  font-size: 12px;
151
  background: #f0f0f0;
152
  }
153
 
154
- div#bp-wizard div#message code, div#bp-wizard div#message kbd {
155
  background: #ffe293;
156
  }
157
 
@@ -159,9 +146,7 @@ a.button {
159
  padding-top: 4px;
160
  }
161
 
162
- a.installed,
163
- a.installed:hover,
164
- a.installed:active {
165
  padding-left: 15px;
166
  color: #888;
167
  border-color: #ccc;
@@ -169,7 +154,7 @@ a.installed:active {
169
  }
170
 
171
  a.installed span {
172
- background: url( ../images/installed.gif ) left center no-repeat;
173
  padding: 6px 10px 7px 6px;
174
  margin-left: -5px;
175
  }
1
+ div#icon-buddypress {
2
+ background: url( ../images/icons32.png ) no-repeat -4px 0px;
3
+ }
4
 
5
+ div#bp-admin {
 
 
 
6
  color: #555;
7
  min-width: 680px;
8
+ }
9
+ div#bp-admin p { line-height: 170%; }
 
 
10
 
11
+ form#bp-admin-form {
12
  margin: 0 10px;
13
  }
14
 
15
+ div#bp-admin-nav {
16
  background: #e0e0e0;
17
  margin: 15px -10px 10px;
18
  padding: 10px 10px 0 10px;
19
  height: 30px;
20
+ -moz-border-radius: 6px;
21
+ -webkit-border-radius: 6px;
22
+ border-radius: 6px;
23
  }
24
+ div#bp-admin-nav div.submit {
25
  position: relative;
26
  float: right;
27
  margin-top: -36px !important;
28
  }
29
+ div#bp-admin-nav div.submit input {
30
  padding: 6px 10px;
31
  }
32
+ div#bp-admin-nav ol {
33
  list-style-type: decimal;
34
  margin: 0;
35
  padding: 0;
36
  }
37
+ div#bp-admin-nav ol li {
38
  float: left;
39
  margin: 0 10px 0 0;
40
  color: #666;
41
  }
42
+ div#bp-admin-nav ol li {
43
  padding: 8px 12px;
44
  display: block;
45
+ -moz-border-radius: 3px;
46
+ -webkit-border-radius: 3px;
47
+ border-radius: 3px;
48
  text-decoration: none;
49
  }
50
+ div#bp-admin-nav ol li.current {
51
+ background: #f9f9f9;
52
  color: #555;
53
  }
54
+ div#bp-admin-nav ol li span.complete {
 
55
  background: url( ../images/completed.gif ) center left no-repeat;
56
  padding: 6px;
57
  }
65
  position: relative;
66
  background: #e0e0e0;
67
  padding: 5px 10px;
68
+ -moz-border-radius: 6px;
69
+ -webkit-border-radius: 6px;
70
+ border-radius: 6px;
71
  top: -6px;
72
  }
73
 
92
  top: 5px;
93
  }
94
 
95
+ div#bp-admin div.prev-next, div#bp-admin div.prev-next p,
96
+ div#bp-admin div.submit, div#bp-admin div.submit p {
97
  margin: 0;
98
  padding: 0;
99
  }
100
+ div#bp-admin div.submit { margin-top: 30px; }
101
+ div#bp-admin div.prev-next { text-align: right; margin-top: 0; }
 
 
 
 
 
102
 
103
+ div#bp-admin div.prev-next {
104
  margin: 0 -20px;
105
  padding: 0 20px 10px;
106
  }
107
 
108
+ div#bp-admin table td {
109
  font-family: helvetica, arial, tahoma, sans-serif;
110
  vertical-align: top;
111
  }
112
 
113
+ div#bp-admin table.form-table th {
114
  border-right: 1px solid #eee;
115
  padding: 15px 25px 15px 0;
116
  color: #555;
117
  vertical-align: top;
118
  }
119
+ div#bp-admin table.form-table tr {
120
  border-bottom: 1px dotted #f0f0f0;
121
  }
122
+ div#bp-admin table.form-table td { padding-left: 25px; font-size: 12px; }
 
 
 
123
 
124
+ div#bp-admin table.form-table th h5 {
125
  font-size: 14px;
126
  margin: 0;
127
  line-height: 150%;
128
  }
129
 
130
+ div#bp-admin table.form-table th img {
131
  margin-top: 5px;
132
  }
133
 
134
+ div#bp-admin table.form-table th p { margin: 3px 0 0 0; }
 
 
135
 
136
+ div#bp-admin code, div#bp-admin kbd {
137
  font-size: 12px;
138
  background: #f0f0f0;
139
  }
140
 
141
+ div#bp-admin div#message code, div#bp-admin div#message kbd {
142
  background: #ffe293;
143
  }
144
 
146
  padding-top: 4px;
147
  }
148
 
149
+ a.installed, a.installed:hover, a.installed:active {
 
 
150
  padding-left: 15px;
151
  color: #888;
152
  border-color: #ccc;
154
  }
155
 
156
  a.installed span {
157
+ background: url( ../images/installed.gif) left center no-repeat;
158
  padding: 6px 10px 7px 6px;
159
  margin-left: -5px;
160
  }
bp-core/css/buddybar-rtl.css CHANGED
@@ -1 +1 @@
1
- #wp-admin-bar{right:0;left:auto}#wp-admin-bar div#admin-bar-logo{right:10px;left:auto}#wp-admin-bar li{text-align:right}#wp-admin-bar li.no-arrow a{padding-left:15px;padding-right:0}#admin-bar-logo{float:right}#wp-admin-bar ul li{float:right;background:url(_inc/images/admin-menu-arrow.gif) 12% 53% no-repeat;padding-left:11px;padding-right:0}#wp-admin-bar ul li.no-arrow{padding-left:0}#wp-admin-bar ul li.align-right{left:0;right:auto}#wp-admin-bar ul li ul{right:-999em;left:auto;margin-right:0}#wp-admin-bar ul li ul li{float:right}#wp-admin-bar ul li ul ul{margin:-25px 184px 0 0}#wp-admin-bar ul li:hover ul,#wp-admin-bar ul li li:hover ul,#wp-admin-bar ul li.sfhover ul,#wp-admin-bar ul li ul li.sfhover ul{right:auto}#wp-admin-bar ul li.align-right:hover ul{left:0;right:auto}#wp-admin-bar ul li:hover ul ul,#wp-admin-bar li.sfhover ul li ul{right:-999em;left:auto}#wp-admin-bar img.avatar{float:right;margin-left:8px;margin-right:0}#wp-admin-bar span.activity{margin-right:34px;margin-left:0}#wp-admin-bar ul li#bp-adminbar-notifications-menu a span{margin-right:2px;margin-left:0}
1
+ #wp-admin-bar{right:0;left:auto;}#wp-admin-bar div#admin-bar-logo{right:10px;left:auto;}#wp-admin-bar li{text-align:right;}#wp-admin-bar li.no-arrow a{padding-left:15px;padding-right:0;}#admin-bar-logo{float:right;}#wp-admin-bar ul li{float:right;background:url(_inc/images/admin-menu-arrow.gif) 12% 53% no-repeat;padding-left:11px;padding-right:0;}#wp-admin-bar ul li.no-arrow{padding-left:0;}#wp-admin-bar ul li.align-right{left:0;right:auto;}#wp-admin-bar ul li ul{right:-999em;left:auto;margin-right:0;}#wp-admin-bar ul li ul li{float:right;}#wp-admin-bar ul li ul ul{margin:-25px 184px 0 0;}#wp-admin-bar ul li:hover ul,#wp-admin-bar ul li li:hover ul,#wp-admin-bar ul li.sfhover ul,#wp-admin-bar ul li ul li.sfhover ul{right:auto;}#wp-admin-bar ul li.align-right:hover ul{left:0;right:auto;}#wp-admin-bar ul li:hover ul ul,#wp-admin-bar li.sfhover ul li ul{right:-999em;left:auto;}#wp-admin-bar img.avatar{float:right;margin-left:8px;margin-right:0;}#wp-admin-bar span.activity{margin-right:34px;margin-left:0;}#wp-admin-bar ul li#bp-adminbar-notifications-menu a span{margin-right:2px;margin-left:0;}
bp-core/css/buddybar.css CHANGED
@@ -1 +1 @@
1
- body:not(.wp-admin){padding-top:25px!important}#wp-admin-bar{position:fixed;top:0;left:0;height:25px;font-size:11px;width:100%;z-index:9999}#wp-admin-bar .padder{position:relative;padding:0;width:100%;margin:0 auto;background:url(../images/60pc_black.png);height:25px}body#bp-default #wp-admin-bar .padder{max-width:1250px}#wp-admin-bar *{z-index:999}#wp-admin-bar div#admin-bar-logo{position:absolute;top:5px;left:10px}#wp-admin-bar a img{border:0}#wp-admin-bar li{list-style:none;margin:0;padding:0;line-height:100%;text-align:left}#wp-admin-bar li a{padding:7px 15px 7px 15px;color:#eee;text-decoration:none;font-size:11px}#wp-admin-bar li.alt{border:0}#wp-admin-bar li.no-arrow a{padding-right:15px}#wp-admin-bar ul li ul li a span{display:none}#wp-admin-bar li:hover,#wp-admin-bar li.hover{position:static}#admin-bar-logo{float:left;font-weight:bold;font-size:11px;padding:5px 8px;margin:0;text-decoration:none;color:#fff}body#bp-default #admin-bar-logo{padding:2px 8px}#wp-admin-bar ul{margin:0;list-style:none;line-height:1;cursor:pointer;height:auto;padding:0}#wp-admin-bar ul li{padding:0;float:left;position:relative;background:url(../images/admin-menu-arrow.gif) 88% 53% no-repeat;padding-right:11px}#wp-admin-bar ul li.no-arrow{background:0;padding-right:0}#wp-admin-bar ul li ul li{background-image:none}#wp-admin-bar ul li.align-right{position:absolute;right:0}#wp-admin-bar ul li a{display:block}#wp-admin-bar ul.main-nav li:hover,#wp-admin-bar ul.main-nav li.sfhover,#wp-admin-bar ul.main-nav li ul li.sfhover{background-color:#333}#wp-admin-bar ul li ul{position:absolute;width:185px;left:-999em;margin-left:0;background:#333;border:1px solid #222;-moz-box-shadow:0 4px 8px rgba(0,0,0,0.1);-webkit-box-shadow:0 4px 8px rgba(0,0,0,0.1);-moz-border-radius:3px;-webkit-border-radius:3px;-moz-border-radius-topleft:0;-webkit-border-top-left-radius:0;-moz-border-radius-topright:0;-webkit-border-top-right-radius:0}#wp-admin-bar ul li>ul{border-top:0}#wp-admin-bar ul li ul a{color:#eee}#wp-admin-bar ul li ul li{float:left;width:174px;margin:0}#wp-admin-bar ul li ul li:hover a{color:#fff}#wp-admin-bar ul li div.admin-bar-clear{clear:both}#wp-admin-bar ul.main-nav li ul li:hover,#wp-admin-bar ul.main-nav li ul li.sfhover,#wp-admin-bar ul.main-nav li ul li.sfhover{background-color:#222}#wp-admin-bar ul li ul ul{margin:-25px 0 0 184px;-moz-border-radius:3px;-webkit-border-radius:3px}#wp-admin-bar ul li ul li:hover ul li a{color:#eee}#wp-admin-bar ul li ul li ul li:hover a{color:#fff}#wp-admin-bar ul li:hover ul,#wp-admin-bar ul li ul li:hover ul,#wp-admin-bar ul li.sfhover ul,#wp-admin-bar ul li ul li.sfhover ul{left:auto}#wp-admin-bar ul li.align-right:hover ul{right:0}#wp-admin-bar ul li:hover ul ul,#wp-admin-bar li.sfhover ul li ul{left:-999em}#wp-admin-bar img.avatar{float:left;margin-right:8px}#wp-admin-bar span.activity{display:block;margin-left:34px;padding:0}#wp-admin-bar ul.author-list li a{height:17px}#wp-admin-bar ul li#bp-adminbar-notifications-menu a span{padding:0 6px;margin-left:2px;background:#fff;color:#000;-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px}#wp-admin-bar-user-info img.avatar{height:64px;width:64px}
1
+ body,body.wp-admin{padding-top:25px!important;}#wp-admin-bar{position:fixed;top:0;left:0;z-index:99;height:25px;font-size:11px;width:100%;z-index:1000;}#wp-admin-bar .padder{position:relative;padding:0;width:100%;margin:0 auto;background:url(../images/60pc_black.png);height:25px;}body#bp-default #wp-admin-bar .padder{min-width:960px;max-width:1250px;}#wp-admin-bar *{z-index:999;}#wp-admin-bar div#admin-bar-logo{position:absolute;top:5px;left:10px;}#wp-admin-bar a img{border:none;}#wp-admin-bar li{list-style:none;margin:0;padding:0;line-height:100%;text-align:left;}#wp-admin-bar li a{padding:7px 15px 7px 15px;color:#eee;text-decoration:none;font-size:11px;}#wp-admin-bar li.alt{border:none;}#wp-admin-bar li.no-arrow a{padding-right:15px;}#wp-admin-bar ul li ul li a span{display:none;}#wp-admin-bar li:hover,#wp-admin-bar li.hover{position:static;}#admin-bar-logo{float:left;font-weight:bold;font-size:11px;padding:5px 8px;margin:0;text-decoration:none;color:#fff;}body#bp-default #admin-bar-logo{padding:2px 8px;}#wp-admin-bar ul{margin:0;list-style:none;line-height:1;cursor:pointer;height:auto;padding:0;}#wp-admin-bar ul li{padding:0;float:left;position:relative;background:url(../images/admin-menu-arrow.gif) 88% 53% no-repeat;padding-right:11px;}#wp-admin-bar ul li.no-arrow{background:none;padding-right:0;}#wp-admin-bar ul li ul li{background-image:none;}#wp-admin-bar ul li.align-right{position:absolute;right:0;}#wp-admin-bar ul li a{display:block;}#wp-admin-bar ul.main-nav li:hover,#wp-admin-bar ul.main-nav li.sfhover,#wp-admin-bar ul.main-nav li ul li.sfhover{background-color:#333;}#wp-admin-bar ul li ul{position:absolute;width:185px;left:-999em;margin-left:0;background:#333;border:1px solid #222;-moz-box-shadow:0 4px 8px rgba(0,0,0,0.1);-webkit-box-shadow:0 4px 8px rgba(0,0,0,0.1);-moz-border-radius:3px;-webkit-border-radius:3px;-moz-border-radius-topleft:0;-webkit-border-top-left-radius:0;-moz-border-radius-topright:0;-webkit-border-top-right-radius:0;}#wp-admin-bar ul li>ul{border-top:none;}#wp-admin-bar ul li ul a{color:#eee;}#wp-admin-bar ul li ul li{float:left;width:174px;margin:0;}#wp-admin-bar ul li ul li:hover a{color:#fff;}#wp-admin-bar ul li div.admin-bar-clear{clear:both;}#wp-admin-bar ul.main-nav li ul li:hover,#wp-admin-bar ul.main-nav li ul li.sfhover,#wp-admin-bar ul.main-nav li ul li.sfhover{background-color:#222;}#wp-admin-bar ul li ul ul{margin:-25px 0 0 184px;-moz-border-radius:3px;-webkit-border-radius:3px;}#wp-admin-bar ul li ul li:hover ul li a{color:#eee;}#wp-admin-bar ul li ul li ul li:hover a{color:#fff;}#wp-admin-bar ul li:hover ul,#wp-admin-bar ul li ul li:hover ul,#wp-admin-bar ul li.sfhover ul,#wp-admin-bar ul li ul li.sfhover ul{left:auto;}#wp-admin-bar ul li.align-right:hover ul{right:0;}#wp-admin-bar ul li:hover ul ul,#wp-admin-bar li.sfhover ul li ul{left:-999em;}#wp-admin-bar img.avatar{float:left;margin-right:8px;}#wp-admin-bar span.activity{display:block;margin-left:34px;padding:0;}#wp-admin-bar ul.author-list li a{height:17px;}#wp-admin-bar ul li#bp-adminbar-notifications-menu a span{padding:0 6px;margin-left:2px;background:#fff;color:#000;-moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;}
bp-core/css/buddybar.dev.css CHANGED
@@ -1,14 +1,16 @@
1
- body:not(.wp-admin) {
 
2
  padding-top: 25px !important;
3
  }
4
  #wp-admin-bar {
5
  position: fixed;
6
  top: 0;
7
  left: 0;
 
8
  height: 25px;
9
  font-size: 11px;
10
  width: 100%;
11
- z-index: 9999;
12
  }
13
  #wp-admin-bar .padder {
14
  position: relative;
1
+ body,
2
+ body.wp-admin {
3
  padding-top: 25px !important;
4
  }
5
  #wp-admin-bar {
6
  position: fixed;
7
  top: 0;
8
  left: 0;
9
+ z-index: 99;
10
  height: 25px;
11
  font-size: 11px;
12
  width: 100%;
13
+ z-index: 1000;
14
  }
15
  #wp-admin-bar .padder {
16
  position: relative;
bp-core/deprecated/1.5.php CHANGED
@@ -129,7 +129,7 @@ function bp_core_get_wp_profile() {
129
 
130
  global $bp;
131
 
132
- $ud = get_userdata( bp_displayed_user_id() ); ?>
133
 
134
  <div class="bp-widget wp-profile">
135
  <h4><?php _e( 'My Profile' ) ?></h4>
@@ -227,7 +227,7 @@ function bp_is_activity_front_page() {
227
 
228
  function bp_is_member() {
229
  _deprecated_function( __FUNCTION__, '1.5', 'bp_is_user' );
230
- return bp_is_user();
231
  }
232
 
233
  function bp_loggedinuser_link() {
@@ -309,7 +309,7 @@ function groups_at_message_notification( $content, $poster_user_id, $group_id, $
309
 
310
  $group = new BP_Groups_Group( $group_id );
311
 
312
- foreach( (array) $usernames as $username ) {
313
  if ( !$receiver_user_id = bp_core_get_userid( $username ) )
314
  continue;
315
 
@@ -426,7 +426,7 @@ function bp_is_friend_requests() {
426
  * Contains functions which were moved out of BP-Default's functions.php
427
  * in BuddyPress 1.5.
428
  *
429
- * @since BuddyPress (1.5)
430
  */
431
  function bp_dtheme_deprecated() {
432
  if ( !function_exists( 'bp_dtheme_wp_pages_filter' ) ) :
@@ -462,7 +462,7 @@ function bp_dtheme_deprecated() {
462
  */
463
  function bp_dtheme_page_on_front_update( $oldvalue, $newvalue ) {
464
  _deprecated_function( __FUNCTION__, '1.5', "No longer required." );
465
- if ( !is_admin() || !bp_current_user_can( 'bp_moderate' ) )
466
  return false;
467
 
468
  return $oldvalue;
@@ -534,133 +534,4 @@ function bp_dtheme_deprecated() {
534
  endif;
535
  }
536
  add_action( 'after_setup_theme', 'bp_dtheme_deprecated', 15 );
537
-
538
- /**
539
- * In BP 1.5, the Settings functions were moved out of the Core and Members
540
- * components, and moved into a new Settings component. This function is no
541
- * longer needed as the nav structure is set up by the {@link BP_Component} class.
542
- *
543
- * @deprecated BuddyPress (1.5)
544
- * @since BuddyPress (1.6)
545
- */
546
- function bp_core_add_settings_nav() {
547
- _deprecated_function( __FUNCTION__, '1.5' );
548
- }
549
-
550
- /**
551
- * In BP 1.5, the Settings functions were moved out of the Core and Members
552
- * components, and moved into a new Settings component. This function is no
553
- * longer needed as new template files for the Settings component were
554
- * introduced.
555
- *
556
- * @deprecated BuddyPress (1.5)
557
- * @since BuddyPress (1.6)
558
- */
559
- function bp_core_screen_general_settings() {
560
- _deprecated_function( __FUNCTION__, '1.5', 'Moved into theme template' );
561
- }
562
-
563
- /**
564
- * In BP 1.5, the Settings functions were moved out of the Core and Members
565
- * components, and moved into a new Settings component. This function is no
566
- * longer needed as new template files for the Settings component were
567
- * introduced.
568
- *
569
- * @deprecated BuddyPress (1.5)
570
- * @since BuddyPress (1.6)
571
- */
572
- function bp_core_screen_general_settings_title() {
573
- _deprecated_function( __FUNCTION__, '1.5', 'Moved into theme template' );
574
- }
575
-
576
- /**
577
- * In BP 1.5, the Settings functions were moved out of the Core and Members
578
- * components, and moved into a new Settings component. This function is no
579
- * longer needed as new template files for the Settings component were
580
- * introduced.
581
- *
582
- * @deprecated BuddyPress (1.5)
583
- * @since BuddyPress (1.6)
584
- */
585
- function bp_core_screen_general_settings_content() {
586
- _deprecated_function( __FUNCTION__, '1.5', 'Moved into theme template' );
587
- }
588
-
589
- /**
590
- * In BP 1.5, the Settings functions were moved out of the Core and Members
591
- * components, and moved into a new Settings component. This function is no
592
- * longer needed as new template files for the Settings component were
593
- * introduced.
594
- *
595
- * @deprecated BuddyPress (1.5)
596
- * @since BuddyPress (1.6)
597
- */
598
- function bp_core_screen_notification_settings() {
599
- _deprecated_function( __FUNCTION__, '1.5', 'Moved into theme template' );
600
- }
601
-
602
- /**
603
- * In BP 1.5, the Settings functions were moved out of the Core and Members
604
- * components, and moved into a new Settings component. This function is no
605
- * longer needed as new template files for the Settings component were
606
- * introduced.
607
- *
608
- * @deprecated BuddyPress (1.5)
609
- * @since BuddyPress (1.6)
610
- */
611
- function bp_core_screen_notification_settings_title() {
612
- _deprecated_function( __FUNCTION__, '1.5', 'Moved into theme template' );
613
- }
614
-
615
- /**
616
- * In BP 1.5, the Settings functions were moved out of the Core and Members
617
- * components, and moved into a new Settings component. This function is no
618
- * longer needed as new template files for the Settings component were
619
- * introduced.
620
- *
621
- * @deprecated BuddyPress (1.5)
622
- * @since BuddyPress (1.6)
623
- */
624
- function bp_core_screen_notification_settings_content() {
625
- _deprecated_function( __FUNCTION__, '1.5', 'Moved into theme template' );
626
- }
627
-
628
- /**
629
- * In BP 1.5, the Settings functions were moved out of the Core and Members
630
- * components, and moved into a new Settings component. This function is no
631
- * longer needed as new template files for the Settings component were
632
- * introduced.
633
- *
634
- * @deprecated BuddyPress (1.5)
635
- * @since BuddyPress (1.6)
636
- */
637
- function bp_core_screen_delete_account() {
638
- _deprecated_function( __FUNCTION__, '1.5', 'Moved into theme template' );
639
- }
640
-
641
- /**
642
- * In BP 1.5, the Settings functions were moved out of the Core and Members
643
- * components, and moved into a new Settings component. This function is no
644
- * longer needed as new template files for the Settings component were
645
- * introduced.
646
- *
647
- * @deprecated BuddyPress (1.5)
648
- * @since BuddyPress (1.6)
649
- */
650
- function bp_core_screen_delete_account_title() {
651
- _deprecated_function( __FUNCTION__, '1.5', 'Moved into theme template' );
652
- }
653
-
654
- /**
655
- * In BP 1.5, the Settings functions were moved out of the Core and Members
656
- * components, and moved into a new Settings component. This function is no
657
- * longer needed as new template files for the Settings component were
658
- * introduced.
659
- *
660
- * @deprecated BuddyPress (1.5)
661
- * @since BuddyPress (1.6)
662
- */
663
- function bp_core_screen_delete_account_content() {
664
- _deprecated_function( __FUNCTION__, '1.5', 'Moved into theme template' );
665
- }
666
  ?>
129
 
130
  global $bp;
131
 
132
+ $ud = get_userdata( $bp->displayed_user->id ); ?>
133
 
134
  <div class="bp-widget wp-profile">
135
  <h4><?php _e( 'My Profile' ) ?></h4>
227
 
228
  function bp_is_member() {
229
  _deprecated_function( __FUNCTION__, '1.5', 'bp_is_user' );
230
+ bp_is_user();
231
  }
232
 
233
  function bp_loggedinuser_link() {
309
 
310
  $group = new BP_Groups_Group( $group_id );
311
 
312
+ foreach( (array)$usernames as $username ) {
313
  if ( !$receiver_user_id = bp_core_get_userid( $username ) )
314
  continue;
315
 
426
  * Contains functions which were moved out of BP-Default's functions.php
427
  * in BuddyPress 1.5.
428
  *
429
+ * @since 1.5
430
  */
431
  function bp_dtheme_deprecated() {
432
  if ( !function_exists( 'bp_dtheme_wp_pages_filter' ) ) :
462
  */
463
  function bp_dtheme_page_on_front_update( $oldvalue, $newvalue ) {
464
  _deprecated_function( __FUNCTION__, '1.5', "No longer required." );
465
+ if ( !is_admin() || !is_super_admin() )
466
  return false;
467
 
468
  return $oldvalue;
534
  endif;
535
  }
536
  add_action( 'after_setup_theme', 'bp_dtheme_deprecated', 15 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
537
  ?>
bp-core/deprecated/1.6.php DELETED
@@ -1,264 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * Deprecated Functions
5
- *
6
- * @package BuddyPress
7
- * @subpackage Core
8
- * @deprecated Since 1.6
9
- */
10
-
11
- /** Toolbar functions *********************************************************/
12
-
13
- function bp_admin_bar_remove_wp_menus() {
14
- _deprecated_function( __FUNCTION__, '1.6' );
15
- }
16
-
17
- function bp_admin_bar_root_site() {
18
- _deprecated_function( __FUNCTION__, '1.6' );
19
- }
20
-
21
- function bp_admin_bar_my_sites_menu() {
22
- _deprecated_function( __FUNCTION__, '1.6' );
23
- }
24
-
25
- function bp_admin_bar_comments_menu( $wp_admin_bar ) {
26
- _deprecated_function( __FUNCTION__, '1.6' );
27
- }
28
-
29
- function bp_admin_bar_appearance_menu() {
30
- _deprecated_function( __FUNCTION__, '1.6' );
31
- }
32
-
33
- function bp_admin_bar_updates_menu() {
34
- _deprecated_function( __FUNCTION__, '1.6' );
35
- }
36
-
37
- function bp_members_admin_bar_my_account_logout() {
38
- _deprecated_function( __FUNCTION__, '1.6' );
39
- }
40
-
41
- function bp_core_is_user_deleted( $user_id = 0 ) {
42
- _deprecated_function( __FUNCTION__, '1.6' );
43
- bp_is_user_deleted( $user_id );
44
- }
45
-
46
- function bp_core_is_user_spammer( $user_id = 0 ) {
47
- _deprecated_function( __FUNCTION__, '1.6' );
48
- bp_is_user_spammer( $user_id );
49
- }
50
-
51
-
52
- /**
53
- * Blogs functions
54
- */
55
-
56
- /**
57
- * @deprecated 1.6
58
- * @deprecated No longer used; see bp_blogs_transition_activity_status()
59
- */
60
- function bp_blogs_manage_comment( $comment_id, $comment_status ) {
61
- _deprecated_function( __FUNCTION__, '1.6', 'No longer used' );
62
- }
63
-
64
- /**
65
- * Core functions
66
- */
67
-
68
- /**
69
- * @deprecated 1.6
70
- * @deprecated No longer used; see BP_Admin::admin_menus()
71
- */
72
- function bp_core_add_admin_menu() {
73
- _deprecated_function( __FUNCTION__, '1.6', 'No longer used' );
74
- }
75
-
76
- /**
77
- * @deprecated 1.6
78
- * @deprecated No longer used. We do ajax properly now.
79
- */
80
- function bp_core_add_ajax_hook() {
81
- _deprecated_function( __FUNCTION__, '1.6', 'No longer used' );
82
- }
83
-
84
- /**
85
- * Members functions
86
- */
87
-
88
- /**
89
- * @deprecated 1.6
90
- * @deprecated No longer used. Check for $bp->pages->activate->slug instead.
91
- */
92
- function bp_has_custom_activation_page() {
93
- _deprecated_function( __FUNCTION__, '1.6' );
94
- }
95
-
96
- /**
97
- * Friends functions
98
- */
99
-
100
- /**
101
- * Displays Friends header tabs
102
- *
103
- * @deprecated 1.6
104
- * @deprecated No longer used
105
- */
106
- function bp_friends_header_tabs() {
107
- _deprecated_function( __FUNCTION__, '1.6', 'Since BuddyPress 1.2, BP has not supported ordering of friend lists by URL parameters.' );
108
- ?>
109
-
110
- <li<?php if ( !bp_action_variable( 0 ) || bp_is_action_variable( 'recently-active', 0 ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_friends_slug() . '/my-friends/recently-active' ) ?>"><?php _e( 'Recently Active', 'buddypress' ) ?></a></li>
111
- <li<?php if ( bp_is_action_variable( 'newest', 0 ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_friends_slug() . '/my-friends/newest' ) ?>"><?php _e( 'Newest', 'buddypress' ) ?></a></li>
112
- <li<?php if ( bp_is_action_variable( 'alphabetically', 0 ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_friends_slug() . '/my-friends/alphabetically' ) ?>"><?php _e( 'Alphabetically', 'buddypress' ) ?></a></li>
113
-
114
- <?php
115
- do_action( 'friends_header_tabs' );
116
- }
117
-
118
- /**
119
- * Filters the title for the Friends component
120
- *
121
- * @deprecated 1.6
122
- * @deprecated No longer used
123
- */
124
- function bp_friends_filter_title() {
125
- _deprecated_function( __FUNCTION__, '1.6', 'Since BuddyPress 1.2, BP has not supported ordering of friend lists by URL parameters.' );
126
-
127
- $current_filter = bp_action_variable( 0 );
128
-
129
- switch ( $current_filter ) {
130
- case 'recently-active': default:
131
- _e( 'Recently Active', 'buddypress' );
132
- break;
133
- case 'newest':
134
- _e( 'Newest', 'buddypress' );
135
- break;
136
- case 'alphabetically':
137
- _e( 'Alphabetically', 'buddypress' );
138
- break;
139
- }
140
- }
141
-
142
-
143
- /**
144
- * Groups functions
145
- */
146
-
147
- /**
148
- * @deprecated 1.6
149
- * @deprecated Renamed to groups_get_id() for greater consistency
150
- */
151
- function groups_check_group_exists( $group_slug ) {
152
- _deprecated_function( __FUNCTION__, '1.6', 'groups_get_id()' );
153
- return groups_get_id( $group_slug );
154
- }
155
-
156
- /**
157
- * Admin functions
158
- */
159
-
160
- /**
161
- * Loads admin panel styles and scripts.
162
- *
163
- * @deprecated 1.6
164
- * @deprecated No longer used.
165
- */
166
- function bp_core_add_admin_menu_styles() {
167
- _deprecated_function( __FUNCTION__, '1.6' );
168
- }
169
-
170
- /**
171
- * Activity functions
172
- */
173
-
174
- /**
175
- * @deprecated 1.6
176
- * @deprecated No longer used. Renamed to bp_activity_register_activity_actions().
177
- */
178
- function updates_register_activity_actions() {
179
- _deprecated_function( __FUNCTION__, '1.6' );
180
- }
181
-
182
- /**
183
- * Sets the "From" address in emails sent
184
- *
185
- * @deprecated 1.6
186
- * @deprecated No longer used.
187
- * @return noreply@sitedomain email address
188
- */
189
- function bp_core_email_from_address_filter() {
190
- _deprecated_function( __FUNCTION__, '1.6' );
191
-
192
- $domain = (array) explode( '/', site_url() );
193
- return apply_filters( 'bp_core_email_from_address_filter', 'noreply@' . $domain[2] );
194
- }
195
-
196
- /**
197
- * Backward compatibility for AJAX callbacks that do not die() on their own
198
- *
199
- * In BuddyPress 1.6, BP was altered so that it uses admin-ajax.php (instead of wp-load.php) for
200
- * AJAX requests. admin-ajax.php dies with an output of '0' (to signify an error), so that if an
201
- * AJAX callback does not kill PHP execution, a '0' character will be erroneously appended to the
202
- * output. All bp-default AJAX callbacks (/bp-themes/bp-default/_inc/ajax.php) have been updated
203
- * for BP 1.6 so that they die() properly; any theme that dynamically includes this file will
204
- * inherit the fixes. However, any theme that contains a copy of BP's pre-1.5 ajax.php file will
205
- * continue to witness the 'trailing "0"' problem.
206
- *
207
- * This function provides a backward compatible workaround for these themes, by hooking to the
208
- * BP wp_ajax_ actions that were problematic prior to BP 1.6, and killing PHP execution with die().
209
- *
210
- * Note that this hack only runs if the function bp_dtheme_register_actions() is not found (this
211
- * function was introduced in BP 1.6 for related backward compatibility reasons).
212
- */
213
- if ( !function_exists( 'bp_dtheme_register_actions' ) ) :
214
- function bp_die_legacy_ajax_callbacks() {
215
-
216
- // This is a list of the BP wp_ajax_ hook suffixes whose associated functions did
217
- // not die properly before BP 1.6
218
- $actions = array(
219
- // Directory template loaders
220
- 'members_filter',
221
- 'groups_filter',
222
- 'blogs_filter',
223
- 'forums_filter',
224
- 'messages_filter',
225
-
226
- // Activity
227
- 'activity_widget_filter',
228
- 'activity_get_older_updates',
229
- 'post_update',
230
- 'new_activity_comment',
231
- 'delete_activity',
232
- 'delete_activity_comment',
233
- 'spam_activity',
234
- 'spam_activity_comment',
235
- 'activity_mark_fav',
236
- 'activity_mark_unfav',
237
-
238
- // Groups
239
- 'groups_invite_user',
240
- 'joinleave_group',
241
-
242
- // Members
243
- 'addremove_friend',
244
- 'accept_friendship',
245
- 'reject_friendship',
246
-
247
- // Messages
248
- 'messages_close_notice',
249
- 'messages_send_reply',
250
- 'messages_markunread',
251
- 'messages_markread',
252
- 'messages_delete',
253
- 'messages_autocomplete_results'
254
- );
255
-
256
- // For each of the problematic hooks, exit at the very end of execution
257
- foreach( $actions as $action ) {
258
- add_action( 'wp_ajax_' . $action, create_function( '', 'exit;' ), 9999 );
259
- add_action( 'wp_ajax_nopriv_' . $action, create_function( '', 'exit;' ), 9999 );
260
- }
261
- }
262
- add_action( 'after_setup_theme', 'bp_die_legacy_ajax_callbacks', 20 );
263
- endif;
264
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-core/images/admin-bar-sprite-rtl.png ADDED
Binary file
bp-core/images/admin-bar-sprite.png ADDED
Binary file
bp-core/images/admin_menu_icon.png ADDED
Binary file
bp-core/{admin/images → images}/completed.gif RENAMED
File without changes
bp-core/{admin/images → images}/find.png RENAMED
File without changes
bp-core/images/icons32.png ADDED
Binary file
bp-core/{admin/images → images}/installed.gif RENAMED
File without changes
bp-core/images/logo-column-header.png ADDED
Binary file
bp-core/images/logo.png ADDED
Binary file
bp-core/{admin/js/wizard.dev.js → js/update.dev.js} RENAMED
File without changes
bp-core/{admin/js/wizard.js → js/update.js} RENAMED
File without changes
bp-forums/bp-forums-admin.php CHANGED
@@ -8,37 +8,15 @@ function bp_forums_add_admin_menu() {
8
  if ( !is_super_admin() )
9
  return false;
10
 
11
- $page = bp_core_do_network_admin() ? 'settings.php' : 'options-general.php';
12
-
13
  // Add the administration tab under the "Site Admin" tab for site administrators
14
- $hook = add_submenu_page( $page, __( 'Forums', 'buddypress' ), __( 'Forums', 'buddypress' ), 'manage_options', 'bb-forums-setup', "bp_forums_bbpress_admin" );
15
-
16
- // Fudge the highlighted subnav item when on the BuddyPress Forums admin page
17
- add_action( "admin_head-$hook", 'bp_core_modify_admin_menu_highlight' );
18
  }
19
  add_action( bp_core_admin_hook(), 'bp_forums_add_admin_menu' );
20
 
21
- /**
22
- * Outputs the markup for the bb-forums-admin panel
23
- */
24
  function bp_forums_bbpress_admin() {
25
  global $bp;
26
 
27
- // The text and URL of the Site Wide Forums button differs depending on whether bbPress
28
- // is running
29
- if ( is_plugin_active( 'bbpress/bbpress.php' ) ) {
30
- // The bbPress admin page will always be on the root blog. switch_to_blog() will
31
- // pass through if we're already there.
32
- switch_to_blog( bp_get_root_blog_id() );
33
- $button_url = admin_url( add_query_arg( array( 'page' => 'bbpress' ), 'options-general.php' ) );
34
- restore_current_blog();
35
-
36
- $button_text = __( 'Configure Site Wide Forums', 'buddypress' );
37
- } else {
38
- $button_url = bp_get_admin_url( add_query_arg( array( 'tab' => 'plugin-information', 'plugin' => 'bbpress', 'TB_iframe' => 'true', 'width' => '640', 'height' => '500' ), 'plugin-install.php' ) );
39
- $button_text = __( 'Install Site Wide Forums', 'buddypress' );
40
- }
41
-
42
  $action = bp_get_admin_url( 'admin.php?page=bb-forums-setup&reinstall=1' ); ?>
43
 
44
  <div class="wrap">
@@ -95,15 +73,13 @@ function bp_forums_bbpress_admin() {
95
  <li><?php _e( 'Activity Stream Integration', 'buddypress' ); ?></p></li>
96
  <li><?php _e( '@ Mention Integration', 'buddypress' ); ?></p></li>
97
  </ul>
98
-
99
  <div>
100
- <a class="button thickbox button-primary" href="<?php echo esc_attr( $button_url ) ?>"><?php echo esc_html( $button_text ) ?></a> &nbsp;
101
  </div>
102
  </div>
103
 
104
  <?php endif; ?>
105
 
106
- <p class="clear description"><?php printf( __( 'Need help deciding between Group Forums and Site Wide Forums? Visit <a href="%s">the BuddyPress codex</a> for more information.', 'buddypress' ), 'http://codex.buddypress.org/getting-started/installing-group-and-sitewide-forums/' ) ?></p>
107
  </div>
108
  <?php
109
  }
@@ -113,21 +89,6 @@ function bp_forums_bbpress_install_wizard() {
113
 
114
  $step = isset( $_REQUEST['step'] ) ? $_REQUEST['step'] : '';
115
 
116
- // The text and URL of the Site Wide Forums button differs depending on whether bbPress
117
- // is running
118
- if ( is_plugin_active( 'bbpress/bbpress.php' ) ) {
119
- // The bbPress admin page will always be on the root blog. switch_to_blog() will
120
- // pass through if we're already there.
121
- switch_to_blog( bp_get_root_blog_id() );
122
- $button_url = admin_url( add_query_arg( array( 'page' => 'bbpress' ), 'options-general.php' ) );
123
- restore_current_blog();
124
-
125
- $button_text = __( 'Configure Site Wide Forums', 'buddypress' );
126
- } else {
127
- $button_url = bp_get_admin_url( add_query_arg( array( 'tab' => 'plugin-information', 'plugin' => 'bbpress', 'TB_iframe' => 'true', 'width' => '640', 'height' => '500' ), 'plugin-install.php' ) );
128
- $button_text = __( 'Install Site Wide Forums', 'buddypress' );
129
- }
130
-
131
  switch( $step ) {
132
  case 'existing':
133
  if ( isset( $_REQUEST['doinstall'] ) && ( 1 == (int) $_REQUEST['doinstall'] ) ) {
@@ -231,7 +192,7 @@ function bp_forums_bbpress_install_wizard() {
231
  <li><?php _e( '@ Mention Integration', 'buddypress' ); ?></p></li>
232
  </ul>
233
  <div>
234
- <a class="button thickbox button-primary" href="<?php echo esc_attr( $button_url ) ?>"><?php echo esc_html( $button_text ) ?></a> &nbsp;
235
  </div>
236
  </div>
237
 
@@ -257,26 +218,21 @@ function bp_forums_configure_existing_install() {
257
 
258
  bp_update_option( 'bb-config-location', $_REQUEST['bbconfigloc'] );
259
 
260
- if ( !file_exists( $_REQUEST['bbconfigloc'] ) ) {
261
  return false;
262
- }
263
 
264
  return true;
265
  }
266
 
267
- function bp_forums_bbpress_install( $location = '' ) {
268
  global $wpdb, $bbdb, $bp;
269
 
270
  check_admin_referer( 'bp_forums_new_install_init' );
271
 
272
- if ( empty( $location ) ) {
273
- $location = ABSPATH . 'bb-config.php';
274
- }
275
-
276
  // Create the bb-config.php file
277
  $initial_write = bp_forums_bbpress_write(
278
  BP_PLUGIN_DIR . '/bp-forums/bbpress/bb-config-sample.php',
279
- $location,
280
  array(
281
  "define( 'BBDB_NAME'," => array( "'bbpress'", "'" . DB_NAME . "'" ),
282
  "define( 'BBDB_USER'," => array( "'username'", "'" . DB_USER . "'" ),
@@ -294,66 +250,57 @@ function bp_forums_bbpress_install( $location = '' ) {
294
  );
295
 
296
  // Add the custom user and usermeta entries to the config file
297
- if ( $initial_write == 1 ) {
298
- $file = file_get_contents( $location );
299
- } else {
300
  $file = &$initial_write;
301
- }
302
 
303
  $file = trim( $file );
304
- if ( '?>' == substr( $file, -2, 2 ) ) {
305
  $file = substr( $file, 0, -2 );
306
- }
307
 
308
  $file .= "\n" . '$bb->custom_user_table = \'' . $wpdb->users . '\';';
309
  $file .= "\n" . '$bb->custom_user_meta_table = \'' . $wpdb->usermeta . '\';';
310
  $file .= "\n\n" . '$bb->uri = \'' . BP_PLUGIN_URL . '/bp-forums/bbpress/\';';
311
  $file .= "\n" . '$bb->name = \'' . get_blog_option( bp_get_root_blog_id(), 'blogname' ) . ' ' . __( 'Forums', 'buddypress' ) . '\';';
312
 
313
- if ( is_multisite() ) {
314
  $file .= "\n" . '$bb->wordpress_mu_primary_blog_id = ' . bp_get_root_blog_id() . ';';
315
- }
316
 
317
- if ( defined( 'AUTH_SALT' ) ) {
318
  $file .= "\n\n" . 'define(\'BB_AUTH_SALT\', \'' . addslashes( AUTH_SALT ) . '\');';
319
- }
320
 
321
- if ( defined( 'LOGGED_IN_SALT' ) ) {
322
  $file .= "\n" . 'define(\'BB_LOGGED_IN_SALT\', \'' . addslashes( LOGGED_IN_SALT ) . '\');';
323
- }
324
 
325
- if ( defined( 'SECURE_AUTH_SALT' ) ) {
326
  $file .= "\n" . 'define(\'BB_SECURE_AUTH_SALT\', \'' . addslashes( SECURE_AUTH_SALT ) . '\');';
327
- }
328
 
329
  $file .= "\n\n" . 'define(\'WP_AUTH_COOKIE_VERSION\', 2);';
330
  $file .= "\n\n" . '?>';
331
 
332
  if ( $initial_write == 1 ) {
333
- $file_handle = fopen( $location, 'w' );
334
  fwrite( $file_handle, $file );
335
  fclose( $file_handle );
336
  } else {
337
  $initial_write = $file;
338
  }
339
 
340
- bp_update_option( 'bb-config-location', $location );
341
  return $initial_write;
342
  }
343
 
344
  function bp_forums_bbpress_write( $file_source, $file_target, $alterations ) {
345
 
346
- if ( empty( $file_source ) || !file_exists( $file_source ) || !is_file( $file_source ) ) {
347
  return -1;
348
- }
349
 
350
- if ( empty( $file_target ) ) {
351
  $file_target = $file_source;
352
- }
353
 
354
- if ( empty( $alterations ) || !is_array( $alterations ) ) {
355
  return -2;
356
- }
357
 
358
  // Get the existing lines in the file
359
  $lines = file( $file_source );
@@ -362,7 +309,7 @@ function bp_forums_bbpress_write( $file_source, $file_target, $alterations ) {
362
  $modified_lines = array();
363
 
364
  // Loop through the lines and modify them
365
- foreach ( (array) $lines as $line ) {
366
  if ( isset( $alterations[substr( $line, 0, 20 )] ) ) {
367
  $alteration = $alterations[substr( $line, 0, 20 )];
368
  $modified_lines[] = str_replace( $alteration[0], $alteration[1], $line );
@@ -388,19 +335,17 @@ function bp_forums_bbpress_write( $file_source, $file_target, $alterations ) {
388
  }
389
  }
390
 
391
- if ( empty( $writable ) ) {
392
  return trim( join( null, $modified_lines ) );
393
- }
394
 
395
  // Open the file for writing - rewrites the whole file
396
  $file_handle = fopen( $file_target, 'w' );
397
 
398
  // Write lines one by one to avoid OS specific newline hassles
399
- foreach ( (array) $modified_lines as $modified_line ) {
400
- if ( strlen( $modified_line ) - 2 === strrpos( $modified_line, '?>' ) ) {
401
  $modified_line = '?>';
402
  }
403
-
404
  fwrite( $file_handle, $modified_line );
405
  if ( $modified_line == '?>' ) {
406
  break;
@@ -415,4 +360,4 @@ function bp_forums_bbpress_write( $file_source, $file_target, $alterations ) {
415
  return 1;
416
  }
417
 
418
- ?>
8
  if ( !is_super_admin() )
9
  return false;
10
 
 
 
11
  // Add the administration tab under the "Site Admin" tab for site administrators
12
+ $hook = add_submenu_page( 'bp-general-settings', __( 'Forums', 'buddypress' ), __( 'Forums', 'buddypress' ), 'manage_options', 'bb-forums-setup', "bp_forums_bbpress_admin" );
13
+ add_action( "admin_print_styles-$hook", 'bp_core_add_admin_menu_styles' );
 
 
14
  }
15
  add_action( bp_core_admin_hook(), 'bp_forums_add_admin_menu' );
16
 
 
 
 
17
  function bp_forums_bbpress_admin() {
18
  global $bp;
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  $action = bp_get_admin_url( 'admin.php?page=bb-forums-setup&reinstall=1' ); ?>
21
 
22
  <div class="wrap">
73
  <li><?php _e( 'Activity Stream Integration', 'buddypress' ); ?></p></li>
74
  <li><?php _e( '@ Mention Integration', 'buddypress' ); ?></p></li>
75
  </ul>
 
76
  <div>
77
+ <a class="button thickbox button-primary" href="<?php bp_admin_url( add_query_arg( array( 'tab' => 'plugin-information', 'plugin' => 'bbpress', 'TB_iframe' => 'true', 'width' => '640', 'height' => '500' ), 'plugin-install.php' ) ); ?>"><?php _e( 'Install Site Wide Forums', 'buddypress' ) ?></a> &nbsp;
78
  </div>
79
  </div>
80
 
81
  <?php endif; ?>
82
 
 
83
  </div>
84
  <?php
85
  }
89
 
90
  $step = isset( $_REQUEST['step'] ) ? $_REQUEST['step'] : '';
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  switch( $step ) {
93
  case 'existing':
94
  if ( isset( $_REQUEST['doinstall'] ) && ( 1 == (int) $_REQUEST['doinstall'] ) ) {
192
  <li><?php _e( '@ Mention Integration', 'buddypress' ); ?></p></li>
193
  </ul>
194
  <div>
195
+ <a class="button thickbox button-primary" href="<?php bp_admin_url( add_query_arg( array( 'tab' => 'plugin-information', 'plugin' => 'bbpress', 'TB_iframe' => 'true', 'width' => '640', 'height' => '500' ), 'plugin-install.php' ) ); ?>"><?php _e( 'Install Site Wide Forums', 'buddypress' ) ?></a> &nbsp;
196
  </div>
197
  </div>
198
 
218
 
219
  bp_update_option( 'bb-config-location', $_REQUEST['bbconfigloc'] );
220
 
221
+ if ( !file_exists( $_REQUEST['bbconfigloc'] ) )
222
  return false;
 
223
 
224
  return true;
225
  }
226
 
227
+ function bp_forums_bbpress_install() {
228
  global $wpdb, $bbdb, $bp;
229
 
230
  check_admin_referer( 'bp_forums_new_install_init' );
231
 
 
 
 
 
232
  // Create the bb-config.php file
233
  $initial_write = bp_forums_bbpress_write(
234
  BP_PLUGIN_DIR . '/bp-forums/bbpress/bb-config-sample.php',
235
+ ABSPATH . 'bb-config.php',
236
  array(
237
  "define( 'BBDB_NAME'," => array( "'bbpress'", "'" . DB_NAME . "'" ),
238
  "define( 'BBDB_USER'," => array( "'username'", "'" . DB_USER . "'" ),
250
  );
251
 
252
  // Add the custom user and usermeta entries to the config file
253
+ if ( $initial_write == 1 )
254
+ $file = file_get_contents( ABSPATH . 'bb-config.php' );
255
+ else
256
  $file = &$initial_write;
 
257
 
258
  $file = trim( $file );
259
+ if ( '?>' == substr( $file, -2, 2 ) )
260
  $file = substr( $file, 0, -2 );
 
261
 
262
  $file .= "\n" . '$bb->custom_user_table = \'' . $wpdb->users . '\';';
263
  $file .= "\n" . '$bb->custom_user_meta_table = \'' . $wpdb->usermeta . '\';';
264
  $file .= "\n\n" . '$bb->uri = \'' . BP_PLUGIN_URL . '/bp-forums/bbpress/\';';
265
  $file .= "\n" . '$bb->name = \'' . get_blog_option( bp_get_root_blog_id(), 'blogname' ) . ' ' . __( 'Forums', 'buddypress' ) . '\';';
266
 
267
+ if ( is_multisite() )
268
  $file .= "\n" . '$bb->wordpress_mu_primary_blog_id = ' . bp_get_root_blog_id() . ';';
 
269
 
270
+ if ( defined( 'AUTH_SALT' ) )
271
  $file .= "\n\n" . 'define(\'BB_AUTH_SALT\', \'' . addslashes( AUTH_SALT ) . '\');';
 
272
 
273
+ if ( defined( 'LOGGED_IN_SALT' ) )
274
  $file .= "\n" . 'define(\'BB_LOGGED_IN_SALT\', \'' . addslashes( LOGGED_IN_SALT ) . '\');';
 
275
 
276
+ if ( defined( 'SECURE_AUTH_SALT' ) )
277
  $file .= "\n" . 'define(\'BB_SECURE_AUTH_SALT\', \'' . addslashes( SECURE_AUTH_SALT ) . '\');';
 
278
 
279
  $file .= "\n\n" . 'define(\'WP_AUTH_COOKIE_VERSION\', 2);';
280
  $file .= "\n\n" . '?>';
281
 
282
  if ( $initial_write == 1 ) {
283
+ $file_handle = fopen( ABSPATH . 'bb-config.php', 'w' );
284
  fwrite( $file_handle, $file );
285
  fclose( $file_handle );
286
  } else {
287
  $initial_write = $file;
288
  }
289
 
290
+ bp_update_option( 'bb-config-location', ABSPATH . 'bb-config.php' );
291
  return $initial_write;
292
  }
293
 
294
  function bp_forums_bbpress_write( $file_source, $file_target, $alterations ) {
295
 
296
+ if ( !$file_source || !file_exists( $file_source ) || !is_file( $file_source ) )
297
  return -1;
 
298
 
299
+ if ( !$file_target )
300
  $file_target = $file_source;
 
301
 
302
+ if ( !$alterations || !is_array( $alterations ) )
303
  return -2;
 
304
 
305
  // Get the existing lines in the file
306
  $lines = file( $file_source );
309
  $modified_lines = array();
310
 
311
  // Loop through the lines and modify them
312
+ foreach ( (array)$lines as $line ) {
313
  if ( isset( $alterations[substr( $line, 0, 20 )] ) ) {
314
  $alteration = $alterations[substr( $line, 0, 20 )];
315
  $modified_lines[] = str_replace( $alteration[0], $alteration[1], $line );
335
  }
336
  }
337
 
338
+ if ( empty( $writable ) )
339
  return trim( join( null, $modified_lines ) );
 
340
 
341
  // Open the file for writing - rewrites the whole file
342
  $file_handle = fopen( $file_target, 'w' );
343
 
344
  // Write lines one by one to avoid OS specific newline hassles
345
+ foreach ( (array)$modified_lines as $modified_line ) {
346
+ if ( false !== strpos( $modified_line, '?>' ) ) {
347
  $modified_line = '?>';
348
  }
 
349
  fwrite( $file_handle, $modified_line );
350
  if ( $modified_line == '?>' ) {
351
  break;
360
  return 1;
361
  }
362
 
363
+ ?>
bp-forums/bp-forums-bbpress-sa.php CHANGED
@@ -16,7 +16,7 @@ function bp_forums_load_bbpress() {
16
 
17
  define( 'BB_PATH', BP_PLUGIN_DIR . '/bp-forums/bbpress/' );
18
  define( 'BACKPRESS_PATH', BP_PLUGIN_DIR . '/bp-forums/bbpress/bb-includes/backpress/' );
19
- define( 'BB_URL', BP_PLUGIN_URL . 'bp-forums/bbpress/' );
20
  define( 'BB_INC', 'bb-includes/' );
21
 
22
  require( BB_PATH . BB_INC . 'class.bb-query.php' );
@@ -39,7 +39,7 @@ function bp_forums_load_bbpress() {
39
  require( BB_PATH . 'bb-admin/includes/functions.bb-admin.php' );
40
 
41
  $bb = new stdClass();
42
- require( bp_get_option( 'bb-config-location' ) );
43
 
44
  // Setup the global database connection
45
  $bbdb = new BPDB ( BBDB_USER, BBDB_PASSWORD, BBDB_NAME, BBDB_HOST );
@@ -100,8 +100,8 @@ function bp_forums_load_bbpress() {
100
 
101
  // Set the site admins as the keymasters
102
  $site_admins = get_site_option( 'site_admins', array('admin') );
103
- foreach ( (array) $site_admins as $site_admin )
104
- bp_update_user_meta( bp_core_get_userid( $site_admin ), $bb_table_prefix . 'capabilities', array( 'keymaster' => true ) );
105
 
106
  // Create the first forum.
107
  bb_new_forum( array( 'forum_name' => 'Default Forum' ) );
@@ -128,7 +128,7 @@ class BP_Forums_BB_Auth {
128
  $args = wp_parse_args( $args, $defaults );
129
  extract( $args, EXTR_SKIP );
130
 
131
- return bp_update_user_meta( $id, $meta_key, $meta_value );
132
  }
133
  }
134
 
@@ -144,6 +144,10 @@ if ( ! class_exists( 'BPDB' ) ) :
144
  class BPDB extends WPDB {
145
  var $db_servers = array();
146
 
 
 
 
 
147
  function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) {
148
  parent::__construct( $dbuser, $dbpassword, $dbname, $dbhost );
149
 
16
 
17
  define( 'BB_PATH', BP_PLUGIN_DIR . '/bp-forums/bbpress/' );
18
  define( 'BACKPRESS_PATH', BP_PLUGIN_DIR . '/bp-forums/bbpress/bb-includes/backpress/' );
19
+ define( 'BB_URL', BP_PLUGIN_URL . '/bp-forums/bbpress/' );
20
  define( 'BB_INC', 'bb-includes/' );
21
 
22
  require( BB_PATH . BB_INC . 'class.bb-query.php' );
39
  require( BB_PATH . 'bb-admin/includes/functions.bb-admin.php' );
40
 
41
  $bb = new stdClass();
42
+ require( $bp->forums->bbconfig );
43
 
44
  // Setup the global database connection
45
  $bbdb = new BPDB ( BBDB_USER, BBDB_PASSWORD, BBDB_NAME, BBDB_HOST );
100
 
101
  // Set the site admins as the keymasters
102
  $site_admins = get_site_option( 'site_admins', array('admin') );
103
+ foreach ( (array)$site_admins as $site_admin )
104
+ update_user_meta( bp_core_get_userid( $site_admin ), $bb_table_prefix . 'capabilities', array( 'keymaster' => true ) );
105
 
106
  // Create the first forum.
107
  bb_new_forum( array( 'forum_name' => 'Default Forum' ) );
128
  $args = wp_parse_args( $args, $defaults );
129
  extract( $args, EXTR_SKIP );
130
 
131
+ return update_user_meta( $id, $meta_key, $meta_value );
132
  }
133
  }
134
 
144
  class BPDB extends WPDB {
145
  var $db_servers = array();
146
 
147
+ function BPDB( $dbuser, $dbpassword, $dbname, $dbhost ) {
148
+ $this->__construct( $dbuser, $dbpassword, $dbname, $dbhost );
149
+ }
150
+
151
  function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) {
152
  parent::__construct( $dbuser, $dbpassword, $dbname, $dbhost );
153
 
bp-forums/bp-forums-filters.php CHANGED
@@ -148,7 +148,7 @@ add_filter( 'bp_get_the_topic_text', 'bp_forums_strip_mentions_on_post_edit' );
148
  * This filter is added in bp_has_forum_topics()
149
  *
150
  * @package BuddyPress
151
- * @since BuddyPress (1.5)
152
  *
153
  * @global object $wpdb The WordPress database global
154
  * @param string $sql
@@ -168,7 +168,7 @@ function bp_forums_add_replied_distinct_sql( $sql ) {
168
  * This filter is added in bp_has_forum_topics()
169
  *
170
  * @package BuddyPress
171
- * @since BuddyPress (1.5)
172
  *
173
  * @global object $bbdb The bbPress database global
174
  * @global object $wpdb The WordPress database global
@@ -189,7 +189,7 @@ function bp_forums_add_replied_join_sql( $sql ) {
189
  * This filter is added in bp_has_forum_topics()
190
  *
191
  * @package BuddyPress
192
- * @since BuddyPress (1.5)
193
  *
194
  * @global object $wpdb The WordPress database global
195
  * @param string $sql
148
  * This filter is added in bp_has_forum_topics()
149
  *
150
  * @package BuddyPress
151
+ * @since 1.5
152
  *
153
  * @global object $wpdb The WordPress database global
154
  * @param string $sql
168
  * This filter is added in bp_has_forum_topics()
169
  *
170
  * @package BuddyPress
171
+ * @since 1.5
172
  *
173
  * @global object $bbdb The bbPress database global
174
  * @global object $wpdb The WordPress database global
189
  * This filter is added in bp_has_forum_topics()
190
  *
191
  * @package BuddyPress
192
+ * @since 1.5
193
  *
194
  * @global object $wpdb The WordPress database global
195
  * @param string $sql
bp-forums/bp-forums-functions.php CHANGED
@@ -1,38 +1,7 @@
1
  <?php
2
-
3
  // Exit if accessed directly
4
  if ( !defined( 'ABSPATH' ) ) exit;
5
 
6
- /** bbPress 2.x ***************************************************************/
7
-
8
- /**
9
- * Used to see if bbPress 2.x is installed and active
10
- *
11
- * @since BuddyPress (1.6)
12
- * @return boolean True if bbPress 2.x is active, false if not
13
- */
14
- function bp_forums_is_bbpress_active() {
15
-
16
- // Single site
17
- if ( is_plugin_active( 'bbpress/bbpress.php' ) )
18
- return true;
19
-
20
- // Network active
21
- if ( is_plugin_active_for_network( 'bbpress/bbpress.php' ) )
22
- return true;
23
-
24
- // Nope
25
- return false;
26
- }
27
-
28
- /** bbPress 1.x ***************************************************************/
29
-
30
- /**
31
- * If the bb-config-location option exists, bbPress 1.x was previously installed
32
- *
33
- * @since BuddyPress (1.2)
34
- * @return boolean True if option exists, false if not
35
- */
36
  function bp_forums_is_installed_correctly() {
37
  global $bp;
38
 
@@ -45,9 +14,9 @@ function bp_forums_is_installed_correctly() {
45
  /**
46
  * Checks $bp pages global and looks for directory page
47
  *
48
- * @since BuddyPress (1.5)
49
  *
50
- * @global BuddyPress $bp The one true BuddyPress instance
51
  * @return bool True if set, False if empty
52
  */
53
  function bp_forums_has_directory() {
@@ -96,18 +65,8 @@ function bp_forums_update_forum( $args = '' ) {
96
  $r = wp_parse_args( $args, $defaults );
97
  extract( $r, EXTR_SKIP );
98
 
99
- return bb_update_forum( array( 'forum_id' => (int) $forum_id, 'forum_name' => stripslashes( $forum_name ), 'forum_desc' => stripslashes( $forum_desc ), 'forum_slug' => stripslashes( $forum_slug ), 'forum_parent' => $forum_parent_id, 'forum_order' => $forum_order, 'forum_is_category' => $forum_is_category ) );
100
- }
101
-
102
- function bp_forums_delete_group_forum( $group_id ) {
103
- $forum_id = groups_get_groupmeta( $group_id, 'forum_id' );
104
-
105
- if ( !empty( $forum_id ) && is_int( $forum_id ) ) {
106
- do_action( 'bbpress_init' );
107
- bb_delete_forum( $forum_id );
108
- }
109
  }
110
- add_action( 'groups_delete_group', 'bp_forums_delete_group_forum' );
111
 
112
  /** Topic Functions ***********************************************************/
113
 
@@ -187,9 +146,9 @@ function bp_forums_new_topic( $args = '' ) {
187
  'topic_title' => '',
188
  'topic_slug' => '',
189
  'topic_text' => '',
190
- 'topic_poster' => bp_loggedin_user_id(), // accepts ids
191
  'topic_poster_name' => $bp->loggedin_user->fullname, // accept names
192
- 'topic_last_poster' => bp_loggedin_user_id(), // accepts ids
193
  'topic_last_poster_name' => $bp->loggedin_user->fullname, // accept names
194
  'topic_start_time' => bp_core_current_time(),
195
  'topic_time' => bp_core_current_time(),
@@ -209,13 +168,13 @@ function bp_forums_new_topic( $args = '' ) {
209
  if ( empty( $topic_poster ) )
210
  return false;
211
 
212
- if ( bp_is_user_inactive( $topic_poster ) )
213
  return false;
214
 
215
  if ( empty( $topic_slug ) )
216
  $topic_slug = sanitize_title( $topic_title );
217
 
218
- if ( !$topic_id = bb_insert_topic( array( 'topic_title' => stripslashes( $topic_title ), 'topic_slug' => $topic_slug, 'topic_poster' => $topic_poster, 'topic_poster_name' => $topic_poster_name, 'topic_last_poster' => $topic_last_poster, 'topic_last_poster_name' => $topic_last_poster_name, 'topic_start_time' => $topic_start_time, 'topic_time' => $topic_time, 'topic_open' => $topic_open, 'forum_id' => (int) $forum_id, 'tags' => $topic_tags ) ) )
219
  return false;
220
 
221
  // Now insert the first post.
@@ -243,7 +202,7 @@ function bp_forums_update_topic( $args = '' ) {
243
  extract( $r, EXTR_SKIP );
244
 
245
  // Check if the user is a spammer
246
- if ( bp_is_user_inactive( bp_loggedin_user_id() ) )
247
  return false;
248
 
249
  // bb_insert_topic() will append tags, but not remove them. So we remove all existing tags.
@@ -333,7 +292,7 @@ function bp_forums_total_topic_count() {
333
  $groups_where_sql = "t.topic_status = 0";
334
  }
335
  $count = $bbdb->get_results( $bbdb->prepare( "SELECT t.topic_id FROM {$bbdb->topics} AS t {$groups_table_sql} WHERE {$groups_where_sql}" ) );
336
- $count = count( (array) $count );
337
  } else {
338
  $count = 0;
339
  }
@@ -341,38 +300,6 @@ function bp_forums_total_topic_count() {
341
  return apply_filters( 'bp_forums_total_topic_count', $count );
342
  }
343
 
344
- /**
345
- * Check to see whether a user has already left this particular reply on a given post.
346
- * Prevents dupes.
347
- *
348
- * @since 1.6
349
- *
350
- * @param str $text The text of the comment
351
- * @param int $topic_id The topic id
352
- * @param int $user_id The user id
353
- */
354
- function bp_forums_reply_exists( $text = '', $topic_id = 0, $user_id = 0 ) {
355
- $reply_exists = false;
356
-
357
- if ( $text && $topic_id && $user_id ) {
358
- do_action( 'bbpress_init' );
359
-
360
- $args = array(
361
- 'post_author_id' => $user_id,
362
- 'topic_id' => $topic_id
363
- );
364
-
365
- // BB_Query's post_text parameter does a MATCH, while we need exact matches
366
- add_filter( 'get_posts_where', create_function( '$q', 'return $q . " AND p.post_text = \'' . $text . '\'";' ) );
367
-
368
- $query = new BB_Query( 'post', $args );
369
-
370
- $reply_exists = !empty( $query->results );
371
- }
372
-
373
- return apply_filters( 'bp_forums_reply_exists', $reply_exists, $text, $topic_id, $user_id );
374
- }
375
-
376
  /**
377
  * Get a total "Topics Started" count for a given user
378
  *
@@ -388,7 +315,7 @@ function bp_forums_total_topic_count_for_user( $user_id = 0, $type = 'active' )
388
  do_action( 'bbpress_init' );
389
 
390
  if ( !$user_id )
391
- $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
392
 
393
  if ( class_exists( 'BB_Query' ) ) {
394
  $args = array(
@@ -417,7 +344,7 @@ function bp_forums_total_topic_count_for_user( $user_id = 0, $type = 'active' )
417
  * Uses an unfortunate technique to count unique topics, due to limitations in BB_Query.
418
  *
419
  * @package BuddyPress
420
- * @since BuddyPress (1.5)
421
  *
422
  * @param int $user_id Defaults to displayed user, then to logged-in user
423
  * @return int $count
@@ -466,13 +393,13 @@ function bp_forums_get_topic_extras( $topics ) {
466
  return $topics;
467
 
468
  // Get the topic ids
469
- foreach ( (array) $topics as $topic ) $topic_ids[] = $topic->topic_id;
470
- $topic_ids = $wpdb->escape( join( ',', (array) $topic_ids ) );
471
 
472
  // Fetch the topic's last poster details
473
  $poster_details = $wpdb->get_results( $wpdb->prepare( "SELECT t.topic_id, t.topic_last_poster, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$wpdb->users} u, {$bbdb->topics} t WHERE u.ID = t.topic_last_poster AND t.topic_id IN ( {$topic_ids} )" ) );
474
  for ( $i = 0, $count = count( $topics ); $i < $count; ++$i ) {
475
- foreach ( (array) $poster_details as $poster ) {
476
  if ( $poster->topic_id == $topics[$i]->topic_id ) {
477
  $topics[$i]->topic_last_poster_email = $poster->user_email;
478
  $topics[$i]->topic_last_poster_nicename = $poster->user_nicename;
@@ -486,7 +413,7 @@ function bp_forums_get_topic_extras( $topics ) {
486
  if ( bp_is_active( 'xprofile' ) ) {
487
  $poster_names = $wpdb->get_results( $wpdb->prepare( "SELECT t.topic_id, pd.value FROM {$bp->profile->table_name_data} pd, {$bbdb->topics} t WHERE pd.user_id = t.topic_last_poster AND pd.field_id = 1 AND t.topic_id IN ( {$topic_ids} )" ) );
488
  for ( $i = 0, $count = count( $topics ); $i < $count; ++$i ) {
489
- foreach ( (array) $poster_names as $name ) {
490
  if ( $name->topic_id == $topics[$i]->topic_id )
491
  $topics[$i]->topic_last_poster_displayname = $name->value;
492
  }
@@ -495,7 +422,7 @@ function bp_forums_get_topic_extras( $topics ) {
495
 
496
  // Loop through to make sure that each topic has the proper values set. This covers the
497
  // case of deleted users
498
- foreach ( (array) $topics as $key => $topic ) {
499
  if ( !isset( $topic->topic_last_poster_email ) )
500
  $topics[$key]->topic_last_poster_email = '';
501
 
@@ -560,7 +487,7 @@ function bp_forums_insert_post( $args = '' ) {
560
  'topic_id' => false,
561
  'post_text' => '',
562
  'post_time' => bp_core_current_time(),
563
- 'poster_id' => bp_loggedin_user_id(), // accepts ids or names
564
  'poster_ip' => $_SERVER['REMOTE_ADDR'],
565
  'post_status' => 0, // use bb_delete_post() instead
566
  'post_position' => false
@@ -587,7 +514,7 @@ function bp_forums_insert_post( $args = '' ) {
587
  if ( empty( $poster_id ) )
588
  return false;
589
 
590
- if ( bp_is_user_inactive( bp_loggedin_user_id() ) )
591
  return false;
592
 
593
  $post_id = bb_insert_post( array( 'post_id' => $post_id, 'topic_id' => $topic_id, 'post_text' => stripslashes( trim( $post_text ) ), 'post_time' => $post_time, 'poster_id' => $poster_id, 'poster_ip' => $poster_ip, 'post_status' => $post_status, 'post_position' => $post_position ) );
@@ -605,14 +532,14 @@ function bp_forums_get_post_extras( $posts ) {
605
  return $posts;
606
 
607
  // Get the user ids
608
- foreach ( (array) $posts as $post ) $user_ids[] = $post->poster_id;
609
- $user_ids = $wpdb->escape( join( ',', (array) $user_ids ) );
610
 
611
  // Fetch the poster's user_email, user_nicename and user_login
612
  $poster_details = $wpdb->get_results( $wpdb->prepare( "SELECT u.ID as user_id, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$wpdb->users} u WHERE u.ID IN ( {$user_ids} )" ) );
613
 
614
  for ( $i = 0, $count = count( $posts ); $i < $count; ++$i ) {
615
- foreach ( (array) $poster_details as $poster ) {
616
  if ( $poster->user_id == $posts[$i]->poster_id ) {
617
  $posts[$i]->poster_email = $poster->user_email;
618
  $posts[$i]->poster_login = $poster->user_login;
@@ -626,7 +553,7 @@ function bp_forums_get_post_extras( $posts ) {
626
  if ( bp_is_active( 'xprofile' ) ) {
627
  $poster_names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id, pd.value FROM {$bp->profile->table_name_data} pd WHERE pd.user_id IN ( {$user_ids} )" ) );
628
  for ( $i = 0, $count = count( $posts ); $i < $count; ++$i ) {
629
- foreach ( (array) $poster_names as $name ) {
630
  if ( isset( $topics[$i] ) && $name->user_id == $topics[$i]->user_id )
631
  $posts[$i]->poster_name = $poster->value;
632
  }
@@ -648,10 +575,10 @@ function bp_forums_get_forum_topicpost_count( $forum_id ) {
648
  function bp_forums_filter_caps( $allcaps ) {
649
  global $bp, $wp_roles, $bb_table_prefix;
650
 
651
- if ( !bp_loggedin_user_id() )
652
  return $allcaps;
653
 
654
- $bb_cap = bp_get_user_meta( bp_loggedin_user_id(), $bb_table_prefix . 'capabilities', true );
655
 
656
  if ( empty( $bb_cap ) )
657
  return $allcaps;
@@ -668,7 +595,7 @@ add_filter( 'user_has_cap', 'bp_forums_filter_caps' );
668
  * Returns the parent forum id for the bbPress abstraction layer
669
  *
670
  * @package BuddyPress
671
- * @since BuddyPress (1.5)
672
  *
673
  * @return int
674
  */
@@ -683,7 +610,7 @@ function bp_forums_parent_forum_id() {
683
  * bp_forums_enable_global_directory_stickies, to change this behavior.
684
  *
685
  * @package BuddyPress
686
- * @since BuddyPress (1.5)
687
  *
688
  * @return bool True if stickies should be displayed at the top of the global directory, false
689
  * otherwise.
@@ -716,7 +643,7 @@ add_action( 'bp_forums_new_post', 'bp_core_clear_cache' );
716
  * @see bp_embed_forum_cache()
717
  * @see bp_embed_forum_save_cache()
718
  * @package BuddyPress_Forums
719
- * @since BuddyPress (1.5)
720
  */
721
  function bp_forums_embed() {
722
  add_filter( 'embed_post_id', 'bp_get_the_topic_post_id' );
@@ -730,7 +657,7 @@ add_action( 'topic_loop_start', 'bp_forums_embed' );
730
  * Used during {@link BP_Embed::parse_oembed()} via {@link bp_forums_embed()}.
731
  *
732
  * @package BuddyPress_Forums
733
- * @since BuddyPress (1.5)
734
  */
735
  function bp_embed_forum_cache( $cache, $id, $cachekey ) {
736
  return bb_get_postmeta( $id, $cachekey );
@@ -741,7 +668,7 @@ function bp_embed_forum_cache( $cache, $id, $cachekey ) {
741
  * Used during {@link BP_Embed::parse_oembed()} via {@link bp_forums_embed()}.
742
  *
743
  * @package BuddyPress_Forums
744
- * @since BuddyPress (1.5)
745
  */
746
  function bp_embed_forum_save_cache( $cache, $cachekey, $id ) {
747
  bb_update_postmeta( $id, $cachekey, $cache );
1
  <?php
 
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  function bp_forums_is_installed_correctly() {
6
  global $bp;
7
 
14
  /**
15
  * Checks $bp pages global and looks for directory page
16
  *
17
+ * @since 1.5
18
  *
19
+ * @global object $bp Global BuddyPress settings object
20
  * @return bool True if set, False if empty
21
  */
22
  function bp_forums_has_directory() {
65
  $r = wp_parse_args( $args, $defaults );
66
  extract( $r, EXTR_SKIP );
67
 
68
+ return bb_update_forum( array( 'forum_id' => (int)$forum_id, 'forum_name' => stripslashes( $forum_name ), 'forum_desc' => stripslashes( $forum_desc ), 'forum_slug' => stripslashes( $forum_slug ), 'forum_parent' => $forum_parent_id, 'forum_order' => $forum_order, 'forum_is_category' => $forum_is_category ) );
 
 
 
 
 
 
 
 
 
69
  }
 
70
 
71
  /** Topic Functions ***********************************************************/
72
 
146
  'topic_title' => '',
147
  'topic_slug' => '',
148
  'topic_text' => '',
149
+ 'topic_poster' => $bp->loggedin_user->id, // accepts ids
150
  'topic_poster_name' => $bp->loggedin_user->fullname, // accept names
151
+ 'topic_last_poster' => $bp->loggedin_user->id, // accepts ids
152
  'topic_last_poster_name' => $bp->loggedin_user->fullname, // accept names
153
  'topic_start_time' => bp_core_current_time(),
154
  'topic_time' => bp_core_current_time(),
168
  if ( empty( $topic_poster ) )
169
  return false;
170
 
171
+ if ( bp_core_is_user_spammer( $topic_poster ) || bp_core_is_user_deleted( $topic_poster ) )
172
  return false;
173
 
174
  if ( empty( $topic_slug ) )
175
  $topic_slug = sanitize_title( $topic_title );
176
 
177
+ if ( !$topic_id = bb_insert_topic( array( 'topic_title' => stripslashes( $topic_title ), 'topic_slug' => $topic_slug, 'topic_poster' => $topic_poster, 'topic_poster_name' => $topic_poster_name, 'topic_last_poster' => $topic_last_poster, 'topic_last_poster_name' => $topic_last_poster_name, 'topic_start_time' => $topic_start_time, 'topic_time' => $topic_time, 'topic_open' => $topic_open, 'forum_id' => (int)$forum_id, 'tags' => $topic_tags ) ) )
178
  return false;
179
 
180
  // Now insert the first post.
202
  extract( $r, EXTR_SKIP );
203
 
204
  // Check if the user is a spammer
205
+ if ( bp_core_is_user_spammer( $bp->loggedin_user->id ) || bp_core_is_user_deleted( $bp->loggedin_user->id ) )
206
  return false;
207
 
208
  // bb_insert_topic() will append tags, but not remove them. So we remove all existing tags.
292
  $groups_where_sql = "t.topic_status = 0";
293
  }
294
  $count = $bbdb->get_results( $bbdb->prepare( "SELECT t.topic_id FROM {$bbdb->topics} AS t {$groups_table_sql} WHERE {$groups_where_sql}" ) );
295
+ $count = count( (array)$count );
296
  } else {
297
  $count = 0;
298
  }
300
  return apply_filters( 'bp_forums_total_topic_count', $count );
301
  }
302
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
303
  /**
304
  * Get a total "Topics Started" count for a given user
305
  *
315
  do_action( 'bbpress_init' );
316
 
317
  if ( !$user_id )
318
+ $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
319
 
320
  if ( class_exists( 'BB_Query' ) ) {
321
  $args = array(
344
  * Uses an unfortunate technique to count unique topics, due to limitations in BB_Query.
345
  *
346
  * @package BuddyPress
347
+ * @since 1.5
348
  *
349
  * @param int $user_id Defaults to displayed user, then to logged-in user
350
  * @return int $count
393
  return $topics;
394
 
395
  // Get the topic ids
396
+ foreach ( (array)$topics as $topic ) $topic_ids[] = $topic->topic_id;
397
+ $topic_ids = $wpdb->escape( join( ',', (array)$topic_ids ) );
398
 
399
  // Fetch the topic's last poster details
400
  $poster_details = $wpdb->get_results( $wpdb->prepare( "SELECT t.topic_id, t.topic_last_poster, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$wpdb->users} u, {$bbdb->topics} t WHERE u.ID = t.topic_last_poster AND t.topic_id IN ( {$topic_ids} )" ) );
401
  for ( $i = 0, $count = count( $topics ); $i < $count; ++$i ) {
402
+ foreach ( (array)$poster_details as $poster ) {
403
  if ( $poster->topic_id == $topics[$i]->topic_id ) {
404
  $topics[$i]->topic_last_poster_email = $poster->user_email;
405
  $topics[$i]->topic_last_poster_nicename = $poster->user_nicename;
413
  if ( bp_is_active( 'xprofile' ) ) {
414
  $poster_names = $wpdb->get_results( $wpdb->prepare( "SELECT t.topic_id, pd.value FROM {$bp->profile->table_name_data} pd, {$bbdb->topics} t WHERE pd.user_id = t.topic_last_poster AND pd.field_id = 1 AND t.topic_id IN ( {$topic_ids} )" ) );
415
  for ( $i = 0, $count = count( $topics ); $i < $count; ++$i ) {
416
+ foreach ( (array)$poster_names as $name ) {
417
  if ( $name->topic_id == $topics[$i]->topic_id )
418
  $topics[$i]->topic_last_poster_displayname = $name->value;
419
  }
422
 
423
  // Loop through to make sure that each topic has the proper values set. This covers the
424
  // case of deleted users
425
+ foreach ( (array)$topics as $key => $topic ) {
426
  if ( !isset( $topic->topic_last_poster_email ) )
427
  $topics[$key]->topic_last_poster_email = '';
428
 
487
  'topic_id' => false,
488
  'post_text' => '',
489
  'post_time' => bp_core_current_time(),
490
+ 'poster_id' => $bp->loggedin_user->id, // accepts ids or names
491
  'poster_ip' => $_SERVER['REMOTE_ADDR'],
492
  'post_status' => 0, // use bb_delete_post() instead
493
  'post_position' => false
514
  if ( empty( $poster_id ) )
515
  return false;
516
 
517
+ if ( bp_core_is_user_spammer( $bp->loggedin_user->id ) || bp_core_is_user_deleted( $bp->loggedin_user->id ) )
518
  return false;
519
 
520
  $post_id = bb_insert_post( array( 'post_id' => $post_id, 'topic_id' => $topic_id, 'post_text' => stripslashes( trim( $post_text ) ), 'post_time' => $post_time, 'poster_id' => $poster_id, 'poster_ip' => $poster_ip, 'post_status' => $post_status, 'post_position' => $post_position ) );
532
  return $posts;
533
 
534
  // Get the user ids
535
+ foreach ( (array)$posts as $post ) $user_ids[] = $post->poster_id;
536
+ $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
537
 
538
  // Fetch the poster's user_email, user_nicename and user_login
539
  $poster_details = $wpdb->get_results( $wpdb->prepare( "SELECT u.ID as user_id, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$wpdb->users} u WHERE u.ID IN ( {$user_ids} )" ) );
540
 
541
  for ( $i = 0, $count = count( $posts ); $i < $count; ++$i ) {
542
+ foreach ( (array)$poster_details as $poster ) {
543
  if ( $poster->user_id == $posts[$i]->poster_id ) {
544
  $posts[$i]->poster_email = $poster->user_email;
545
  $posts[$i]->poster_login = $poster->user_login;
553
  if ( bp_is_active( 'xprofile' ) ) {
554
  $poster_names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id, pd.value FROM {$bp->profile->table_name_data} pd WHERE pd.user_id IN ( {$user_ids} )" ) );
555
  for ( $i = 0, $count = count( $posts ); $i < $count; ++$i ) {
556
+ foreach ( (array)$poster_names as $name ) {
557
  if ( isset( $topics[$i] ) && $name->user_id == $topics[$i]->user_id )
558
  $posts[$i]->poster_name = $poster->value;
559
  }
575
  function bp_forums_filter_caps( $allcaps ) {
576
  global $bp, $wp_roles, $bb_table_prefix;
577
 
578
+ if ( !isset( $bp->loggedin_user->id ) )
579
  return $allcaps;
580
 
581
+ $bb_cap = get_user_meta( $bp->loggedin_user->id, $bb_table_prefix . 'capabilities', true );
582
 
583
  if ( empty( $bb_cap ) )
584
  return $allcaps;
595
  * Returns the parent forum id for the bbPress abstraction layer
596
  *
597
  * @package BuddyPress
598
+ * @since 1.5
599
  *
600
  * @return int
601
  */
610
  * bp_forums_enable_global_directory_stickies, to change this behavior.
611
  *
612
  * @package BuddyPress
613
+ * @since 1.5
614
  *
615
  * @return bool True if stickies should be displayed at the top of the global directory, false
616
  * otherwise.
643
  * @see bp_embed_forum_cache()
644
  * @see bp_embed_forum_save_cache()
645
  * @package BuddyPress_Forums
646
+ * @since 1.5
647
  */
648
  function bp_forums_embed() {
649
  add_filter( 'embed_post_id', 'bp_get_the_topic_post_id' );
657
  * Used during {@link BP_Embed::parse_oembed()} via {@link bp_forums_embed()}.
658
  *
659
  * @package BuddyPress_Forums
660
+ * @since 1.5
661
  */
662
  function bp_embed_forum_cache( $cache, $id, $cachekey ) {
663
  return bb_get_postmeta( $id, $cachekey );
668
  * Used during {@link BP_Embed::parse_oembed()} via {@link bp_forums_embed()}.
669
  *
670
  * @package BuddyPress_Forums
671
+ * @since 1.5
672
  */
673
  function bp_embed_forum_save_cache( $cache, $cachekey, $id ) {
674
  bb_update_postmeta( $id, $cachekey, $cache );
bp-forums/bp-forums-loader.php CHANGED
@@ -1,5 +1,4 @@
1
  <?php
2
-
3
  /**
4
  * BuddyPress Forums Loader
5
  *
@@ -17,7 +16,7 @@ class BP_Forums_Component extends BP_Component {
17
  /**
18
  * Start the forums component creation process
19
  *
20
- * @since BuddyPress (1.5)
21
  */
22
  function __construct() {
23
  parent::start(
@@ -33,8 +32,8 @@ class BP_Forums_Component extends BP_Component {
33
  * The BP_FORUMS_SLUG constant is deprecated, and only used here for
34
  * backwards compatibility.
35
  *
36
- * @since BuddyPress (1.5)
37
- * @global BuddyPress $bp The one true BuddyPress instance
38
  */
39
  function setup_globals() {
40
  global $bp;
@@ -54,6 +53,7 @@ class BP_Forums_Component extends BP_Component {
54
  // All globals for messaging component.
55
  // Note that global_tables is included in this array.
56
  $globals = array(
 
57
  'slug' => BP_FORUMS_SLUG,
58
  'root_slug' => isset( $bp->pages->forums->slug ) ? $bp->pages->forums->slug : BP_FORUMS_SLUG,
59
  'has_directory' => true,
@@ -93,7 +93,7 @@ class BP_Forums_Component extends BP_Component {
93
  /**
94
  * Setup BuddyBar navigation
95
  *
96
- * @global BuddyPress $bp The one true BuddyPress instance
97
  */
98
  function setup_nav() {
99
  global $bp;
@@ -103,7 +103,7 @@ class BP_Forums_Component extends BP_Component {
103
  return;
104
 
105
  // Stop if there is no user displayed or logged in
106
- if ( !is_user_logged_in() && !bp_displayed_user_id() )
107
  return;
108
 
109
  // Add 'Forums' to the main navigation
@@ -117,10 +117,12 @@ class BP_Forums_Component extends BP_Component {
117
  );
118
 
119
  // Determine user to use
120
- if ( bp_displayed_user_domain() ) {
121
- $user_domain = bp_displayed_user_domain();
122
- } elseif ( bp_loggedin_user_domain() ) {
123
- $user_domain = bp_loggedin_user_domain();
 
 
124
  } else {
125
  return;
126
  }
@@ -167,9 +169,9 @@ class BP_Forums_Component extends BP_Component {
167
  }
168
 
169
  /**
170
- * Set up the Toolbar
171
  *
172
- * @global BuddyPress $bp The one true BuddyPress instance
173
  */
174
  function setup_admin_bar() {
175
  global $bp;
@@ -181,7 +183,9 @@ class BP_Forums_Component extends BP_Component {
181
  if ( is_user_logged_in() ) {
182
 
183
  // Setup the logged in user variables
184
- $forums_link = trailingslashit( bp_loggedin_user_domain() . $this->slug );
 
 
185
 
186
  // Add the "My Account" sub menus
187
  $wp_admin_nav[] = array(
@@ -222,7 +226,7 @@ class BP_Forums_Component extends BP_Component {
222
  /**
223
  * Sets up the title for pages and <title>
224
  *
225
- * @global BuddyPress $bp The one true BuddyPress instance
226
  */
227
  function setup_title() {
228
  global $bp;
@@ -233,23 +237,17 @@ class BP_Forums_Component extends BP_Component {
233
  $bp->bp_options_title = __( 'Forums', 'buddypress' );
234
  } else {
235
  $bp->bp_options_avatar = bp_core_fetch_avatar( array(
236
- 'item_id' => bp_displayed_user_id(),
237
- 'type' => 'thumb',
238
- 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() )
239
  ) );
240
- $bp->bp_options_title = bp_get_displayed_user_fullname();
241
  }
242
  }
243
 
244
  parent::setup_title();
245
  }
246
  }
247
-
248
- function bp_setup_forums() {
249
- global $bp;
250
-
251
- $bp->forums = new BP_Forums_Component();
252
- }
253
- add_action( 'bp_setup_components', 'bp_setup_forums', 6 );
254
 
255
  ?>
1
  <?php
 
2
  /**
3
  * BuddyPress Forums Loader
4
  *
16
  /**
17
  * Start the forums component creation process
18
  *
19
+ * @since 1.5
20
  */
21
  function __construct() {
22
  parent::start(
32
  * The BP_FORUMS_SLUG constant is deprecated, and only used here for
33
  * backwards compatibility.
34
  *
35
+ * @since 1.5
36
+ * @global obj $bp
37
  */
38
  function setup_globals() {
39
  global $bp;
53
  // All globals for messaging component.
54
  // Note that global_tables is included in this array.
55
  $globals = array(
56
+ 'path' => BP_PLUGIN_DIR,
57
  'slug' => BP_FORUMS_SLUG,
58
  'root_slug' => isset( $bp->pages->forums->slug ) ? $bp->pages->forums->slug : BP_FORUMS_SLUG,
59
  'has_directory' => true,
93
  /**
94
  * Setup BuddyBar navigation
95
  *
96
+ * @global obj $bp
97
  */
98
  function setup_nav() {
99
  global $bp;
103
  return;
104
 
105
  // Stop if there is no user displayed or logged in
106
+ if ( !is_user_logged_in() && !isset( $bp->displayed_user->id ) )
107
  return;
108
 
109
  // Add 'Forums' to the main navigation
117
  );
118
 
119
  // Determine user to use
120
+ if ( isset( $bp->displayed_user->domain ) ) {
121
+ $user_domain = $bp->displayed_user->domain;
122
+ $user_login = $bp->displayed_user->userdata->user_login;
123
+ } elseif ( isset( $bp->loggedin_user->domain ) ) {
124
+ $user_domain = $bp->loggedin_user->domain;
125
+ $user_login = $bp->loggedin_user->userdata->user_login;
126
  } else {
127
  return;
128
  }
169
  }
170
 
171
  /**
172
+ * Set up the admin bar
173
  *
174
+ * @global obj $bp
175
  */
176
  function setup_admin_bar() {
177
  global $bp;
183
  if ( is_user_logged_in() ) {
184
 
185
  // Setup the logged in user variables
186
+ $user_domain = $bp->loggedin_user->domain;
187
+ $user_login = $bp->loggedin_user->userdata->user_login;
188
+ $forums_link = trailingslashit( $user_domain . $this->slug );
189
 
190
  // Add the "My Account" sub menus
191
  $wp_admin_nav[] = array(
226
  /**
227
  * Sets up the title for pages and <title>
228
  *
229
+ * @global obj $bp
230
  */
231
  function setup_title() {
232
  global $bp;
237
  $bp->bp_options_title = __( 'Forums', 'buddypress' );
238
  } else {
239
  $bp->bp_options_avatar = bp_core_fetch_avatar( array(
240
+ 'item_id' => $bp->displayed_user->id,
241
+ 'type' => 'thumb'
 
242
  ) );
243
+ $bp->bp_options_title = $bp->displayed_user->fullname;
244
  }
245
  }
246
 
247
  parent::setup_title();
248
  }
249
  }
250
+ // Create the forums component
251
+ $bp->forums = new BP_Forums_Component();
 
 
 
 
 
252
 
253
  ?>
bp-forums/bp-forums-screens.php CHANGED
@@ -25,7 +25,7 @@ function bp_forums_directory_forums_setup() {
25
  $bp->groups->current_group = groups_get_group( array( 'group_id' => $_POST['topic_group_id'] ) );
26
  if ( !empty( $bp->groups->current_group->id ) ) {
27
  // Auto join this user if they are not yet a member of this group
28
- if ( !bp_current_user_can( 'bp_moderate' ) && 'public' == $bp->groups->current_group->status && !groups_is_user_member( bp_loggedin_user_id(), $bp->groups->current_group->id ) )
29
  groups_join_group( $bp->groups->current_group->id );
30
 
31
  $error_message = '';
@@ -124,4 +124,4 @@ function bp_forums_screen_single_topic() {
124
  bp_core_load_template( apply_filters( 'bp_forums_screen_single_topic', 'forums/single/topic' ) );
125
  }
126
  add_action( 'bp_screens', 'bp_forums_screen_single_topic' );
127
- ?>
25
  $bp->groups->current_group = groups_get_group( array( 'group_id' => $_POST['topic_group_id'] ) );
26
  if ( !empty( $bp->groups->current_group->id ) ) {
27
  // Auto join this user if they are not yet a member of this group
28
+ if ( !is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
29
  groups_join_group( $bp->groups->current_group->id );
30
 
31
  $error_message = '';
124
  bp_core_load_template( apply_filters( 'bp_forums_screen_single_topic', 'forums/single/topic' ) );
125
  }
126
  add_action( 'bp_screens', 'bp_forums_screen_single_topic' );
127
+ ?>
bp-forums/bp-forums-template.php CHANGED
@@ -7,7 +7,7 @@ if ( !defined( 'ABSPATH' ) ) exit;
7
  *
8
  * @package BuddyPress
9
  * @subpackage Forums Template
10
- * @since BuddyPress (1.5)
11
  *
12
  * @uses bp_get_forums_slug()
13
  */
@@ -19,7 +19,7 @@ function bp_forums_slug() {
19
  *
20
  * @package BuddyPress
21
  * @subpackage Forums Template
22
- * @since BuddyPress (1.5)
23
  */
24
  function bp_get_forums_slug() {
25
  global $bp;
@@ -31,7 +31,7 @@ function bp_forums_slug() {
31
  *
32
  * @package BuddyPress
33
  * @subpackage Forums Template
34
- * @since BuddyPress (1.5)
35
  *
36
  * @uses bp_get_forums_root_slug()
37
  */
@@ -43,7 +43,7 @@ function bp_forums_root_slug() {
43
  *
44
  * @package BuddyPress
45
  * @subpackage Forums Template
46
- * @since BuddyPress (1.5)
47
  */
48
  function bp_get_forums_root_slug() {
49
  global $bp;
@@ -55,7 +55,7 @@ function bp_forums_root_slug() {
55
  *
56
  * @package BuddyPress
57
  * @subpackage Forums Template
58
- * @since BuddyPress (1.5)
59
  * @uses bp_get_forums_directory_permalink()
60
  */
61
  function bp_forums_directory_permalink() {
@@ -66,7 +66,7 @@ function bp_forums_directory_permalink() {
66
  *
67
  * @package BuddyPress
68
  * @subpackage Forums Template
69
- * @since BuddyPress (1.5)
70
  * @uses apply_filters()
71
  * @uses traisingslashit()
72
  * @uses bp_get_root_domain()
@@ -97,6 +97,10 @@ class BP_Forums_Template_Forum {
97
  var $sort_by;
98
  var $order;
99
 
 
 
 
 
100
  function __construct( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms, $offset = false, $number = false ) {
101
  global $bp;
102
 
@@ -128,7 +132,7 @@ class BP_Forums_Template_Forum {
128
 
129
  $this->topics = apply_filters( 'bp_forums_template_topics', $this->topics, $type, $forum_id, $per_page, $max, $no_stickies );
130
 
131
- if ( !(int) $this->topics ) {
132
  $this->topic_count = 0;
133
  $this->total_topic_count = 0;
134
  } else {
@@ -137,7 +141,7 @@ class BP_Forums_Template_Forum {
137
  if ( !empty( $forum_id ) ) {
138
  // Group forums
139
  $topic_count = bp_forums_get_forum( $forum_id );
140
- $topic_count = (int) $topic_count->topics;
141
  } else if ( !empty( $bp->groups->current_group ) ) {
142
  $topic_count = (int)groups_total_public_forum_topic_count( $type );
143
  } else if ( bp_is_user_forums_started() || ( bp_is_directory() && $user_id ) ) {
@@ -147,26 +151,23 @@ class BP_Forums_Template_Forum {
147
  } else if ( bp_is_user_forums_replied_to() ) {
148
  // Profile > Forums > Replied To
149
  $topic_count = bp_forums_total_replied_count_for_user( bp_displayed_user_id(), $type );
150
- } else if ( 'tags' == $type ) {
151
- $tag = bb_get_tag( $search_terms );
152
- $topic_count = $tag->count;
153
  } else {
154
  // For forum directories (All Topics), get a true count
155
- $status = bp_current_user_can( 'bp_moderate' ) ? 'all' : 'public'; // todo: member-of
156
  $topic_count = (int)groups_total_forum_topic_count( $status, $search_terms );
157
  }
158
 
159
  if ( !$max || $max >= $topic_count ) {
160
  $this->total_topic_count = $topic_count;
161
  } else {
162
- $this->total_topic_count = (int) $max;
163
  }
164
 
165
  if ( $max ) {
166
  if ( $max >= count($this->topics) ) {
167
  $this->topic_count = count( $this->topics );
168
  } else {
169
- $this->topic_count = (int) $max;
170
  }
171
  } else {
172
  $this->topic_count = count( $this->topics );
@@ -179,11 +180,11 @@ class BP_Forums_Template_Forum {
179
  // Fetch extra information for topics, so we don't have to query inside the loop
180
  $this->topics = bp_forums_get_topic_extras( $this->topics );
181
 
182
- if ( (int) $this->total_topic_count && (int) $this->pag_num ) {
183
  $this->pag_links = paginate_links( array(
184
  'base' => add_query_arg( array( 'p' => '%#%', 'n' => $this->pag_num ) ),
185
  'format' => '',
186
- 'total' => ceil( (int) $this->total_topic_count / (int) $this->pag_num),
187
  'current' => $this->pag_page,
188
  'prev_text' => _x( '&larr;', 'Forum topic pagination previous text', 'buddypress' ),
189
  'next_text' => _x( '&rarr;', 'Forum topic pagination next text', 'buddypress' ),
@@ -267,8 +268,8 @@ function bp_has_forum_topics( $args = '' ) {
267
  $do_stickies = false;
268
 
269
  // User filtering
270
- if ( bp_displayed_user_id() )
271
- $user_id = bp_displayed_user_id();
272
 
273
  // "Replied" query must be manually modified
274
  if ( 'replies' == bp_current_action() ) {
@@ -374,13 +375,13 @@ function bp_has_forum_topics( $args = '' ) {
374
  // If there are stickies to merge on this page, do it now
375
  if ( $this_page_stickies ) {
376
  // Correct the topic_count
377
- $forum_template->topic_count += (int) $this_page_stickies;
378
 
379
  // Figure out which stickies need to be included
380
  $this_page_sticky_topics = array_slice( $stickies_template->topics, 0 - $this_page_stickies );
381
 
382
  // Merge these topics into the forum template
383
- $forum_template->topics = array_merge( $this_page_sticky_topics, (array) $forum_template->topics );
384
  }
385
  } else {
386
  // This page has no non-stickies
@@ -399,7 +400,7 @@ function bp_has_forum_topics( $args = '' ) {
399
  $forum_template->pag_links = paginate_links( array(
400
  'base' => add_query_arg( array( 'p' => '%#%', 'n' => $forum_template->pag_num ) ),
401
  'format' => '',
402
- 'total' => ceil( (int) $forum_template->total_topic_count / (int) $forum_template->pag_num ),
403
  'current' => $forum_template->pag_page,
404
  'prev_text' => _x( '&larr;', 'Forum topic pagination previous text', 'buddypress' ),
405
  'next_text' => _x( '&rarr;', 'Forum topic pagination next text', 'buddypress' ),
@@ -414,7 +415,7 @@ function bp_has_forum_topics( $args = '' ) {
414
  // When skipping the sticky logic, just pull up the forum topics like usual
415
  $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, 'all', $search_terms );
416
  }
417
-
418
  return apply_filters( 'bp_has_topics', $forum_template->has_topics(), $forum_template );
419
  }
420
 
@@ -461,7 +462,7 @@ function bp_the_topic_text() {
461
  function bp_get_the_topic_text() {
462
  global $forum_template;
463
 
464
- $post = bb_get_first_post( (int) $forum_template->topic->topic_id, false );
465
  return apply_filters( 'bp_get_the_topic_text', esc_attr( $post->post_text ) );
466
  }
467
 
@@ -479,12 +480,12 @@ function bp_the_topic_poster_avatar( $args = '' ) {
479
  }
480
  function bp_get_the_topic_poster_avatar( $args = '' ) {
481
  global $forum_template;
482
-
483
  $defaults = array(
484
  'type' => 'thumb',
485
  'width' => false,
486
  'height' => false,
487
- 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $forum_template->topic->topic_poster ) )
488
  );
489
 
490
  $r = wp_parse_args( $args, $defaults );
@@ -574,7 +575,7 @@ function bp_the_topic_object_avatar( $args = '' ) {
574
  }
575
  function bp_get_the_topic_object_avatar( $args = '' ) {
576
  global $forum_template;
577
-
578
  if ( !isset( $forum_template->topic->object_id ) )
579
  return false;
580
 
@@ -770,16 +771,16 @@ function bp_the_topic_is_mine() {
770
  echo bp_get_the_topic_is_mine();
771
  }
772
  function bp_get_the_topic_is_mine() {
773
- global $forum_template;
774
 
775
- return bp_loggedin_user_id() == $forum_template->topic->topic_poster;
776
  }
777
 
778
  function bp_the_topic_admin_links( $args = '' ) {
779
  echo bp_get_the_topic_admin_links( $args );
780
  }
781
  function bp_get_the_topic_admin_links( $args = '' ) {
782
- global $forum_template;
783
 
784
  $defaults = array(
785
  'seperator' => '|'
@@ -790,13 +791,13 @@ function bp_the_topic_admin_links( $args = '' ) {
790
 
791
  $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'edit', 'bp_forums_edit_topic' ) . '">' . __( 'Edit Topic', 'buddypress' ) . '</a>';
792
 
793
- if ( bp_is_item_admin() || bp_is_item_mod() || bp_current_user_can( 'bp_moderate' ) ) {
794
- if ( 0 == (int) $forum_template->topic->topic_sticky )
795
  $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'stick', 'bp_forums_stick_topic' ) . '">' . __( 'Sticky Topic', 'buddypress' ) . '</a>';
796
  else
797
  $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'unstick', 'bp_forums_unstick_topic' ) . '">' . __( 'Un-stick Topic', 'buddypress' ) . '</a>';
798
 
799
- if ( 0 == (int) $forum_template->topic->topic_open )
800
  $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'open', 'bp_forums_open_topic' ) . '">' . __( 'Open Topic', 'buddypress' ) . '</a>';
801
  else
802
  $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'close', 'bp_forums_close_topic' ) . '">' . __( 'Close Topic', 'buddypress' ) . '</a>';
@@ -819,10 +820,10 @@ function bp_the_topic_css_class() {
819
  if ( $forum_template->current_topic % 2 == 1 )
820
  $class .= 'alt';
821
 
822
- if ( isset( $forum_template->topic->topic_sticky ) && 1 == (int) $forum_template->topic->topic_sticky )
823
  $class .= ' sticky';
824
 
825
- if ( !isset( $forum_template->topic->topic_open ) || 0 == (int) $forum_template->topic->topic_open )
826
  $class .= ' closed';
827
 
828
  return apply_filters( 'bp_get_the_topic_css_class', trim( $class ) );
@@ -881,7 +882,7 @@ function bp_forum_topic_type() {
881
  * Echoes the output of bp_get_forum_topic_new_reply_link()
882
  *
883
  * @package BuddyPress
884
- * @since BuddyPress (1.5)
885
  */
886
  function bp_forum_topic_new_reply_link() {
887
  echo bp_get_forum_topic_new_reply_link();
@@ -890,7 +891,7 @@ function bp_forum_topic_new_reply_link() {
890
  * Returns the permalink for the New Reply button at the top of forum topics
891
  *
892
  * @package BuddyPress
893
- * @since BuddyPress (1.5)
894
  *
895
  * @uses apply_filters() Filter bp_get_forum_topic_new_reply_link to modify
896
  * @return str The URL for the New Reply link
@@ -970,6 +971,7 @@ function bp_is_edit_topic() {
970
  return true;
971
  }
972
 
 
973
  class BP_Forums_Template_Topic {
974
  var $current_post = -1;
975
  var $post_count;
@@ -982,14 +984,6 @@ class BP_Forums_Template_Topic {
982
 
983
  var $in_the_loop;
984
 
985
- /**
986
- * Contains a 'total_pages' property holding total number of pages in this loop.
987
- *
988
- * @since BuddyPress (1.2)
989
- * @var stdClass
990
- */
991
- public $pag;
992
-
993
  var $pag_page;
994
  var $pag_num;
995
  var $pag_links;
@@ -1000,6 +994,10 @@ class BP_Forums_Template_Topic {
1000
  var $sort_by;
1001
  var $order;
1002
 
 
 
 
 
1003
  function __construct( $topic_id, $per_page, $max, $order ) {
1004
  global $bp, $current_user, $forum_template;
1005
 
@@ -1017,17 +1015,17 @@ class BP_Forums_Template_Topic {
1017
  $this->post_count = 0;
1018
  $this->total_post_count = 0;
1019
  } else {
1020
- if ( !$max || $max >= (int) $forum_template->topic->topic_posts ) {
1021
- $this->total_post_count = (int) $forum_template->topic->topic_posts;
1022
  } else {
1023
- $this->total_post_count = (int) $max;
1024
  }
1025
 
1026
  if ( $max ) {
1027
  if ( $max >= count( $this->posts ) ) {
1028
  $this->post_count = count( $this->posts );
1029
  } else {
1030
- $this->post_count = (int) $max;
1031
  }
1032
  } else {
1033
  $this->post_count = count( $this->posts );
@@ -1037,20 +1035,18 @@ class BP_Forums_Template_Topic {
1037
  // Load topic tags
1038
  $this->topic_tags = bb_get_topic_tags( $this->topic_id );
1039
 
1040
- $this->pag = new stdClass;
1041
-
1042
- if ( (int) $this->total_post_count && (int) $this->pag_num ) {
1043
  $this->pag_links = paginate_links( array(
1044
- 'base' => add_query_arg( array( 'topic_page' => '%#%', 'num' => (int) $this->pag_num ) ),
1045
  'format' => '',
1046
- 'total' => ceil( (int) $this->total_post_count / (int) $this->pag_num ),
1047
  'current' => $this->pag_page,
1048
  'prev_text' => _x( '&larr;', 'Forum thread pagination previous text', 'buddypress' ),
1049
  'next_text' => _x( '&rarr;', 'Forum thread pagination next text', 'buddypress' ),
1050
  'mid_size' => 1
1051
  ) );
1052
 
1053
- $this->pag->total_pages = ceil( (int) $this->total_post_count / (int) $this->pag_num );
1054
  } else {
1055
  $this->pag->total_pages = 1;
1056
  }
@@ -1174,10 +1170,10 @@ function bp_the_topic_post_css_class() {
1174
  if ( $topic_template->current_post % 2 == 1 )
1175
  $class .= 'alt';
1176
 
1177
- if ( 1 == (int) $topic_template->post->post_status )
1178
  $class .= ' deleted';
1179
 
1180
- if ( 0 == (int) $topic_template->post->post_status )
1181
  $class .= ' open';
1182
 
1183
  return apply_filters( 'bp_get_the_topic_post_css_class', trim( $class ) );
@@ -1208,7 +1204,7 @@ function bp_the_topic_post_poster_name() {
1208
  function bp_get_the_topic_post_poster_name() {
1209
  global $topic_template;
1210
 
1211
- if ( empty( $topic_template->post->poster_name ) || ( !$link = bp_core_get_user_domain( $topic_template->post->poster_id ) ) )
1212
  return __( 'Deleted User', 'buddypress' );
1213
 
1214
  return apply_filters( 'bp_get_the_topic_post_poster_name', '<a href="' . $link . '" title="' . $topic_template->post->poster_name . '">' . $topic_template->post->poster_name . '</a>' );
@@ -1220,7 +1216,7 @@ function bp_the_topic_post_poster_link() {
1220
  function bp_get_the_topic_post_poster_link() {
1221
  global $topic_template;
1222
 
1223
- return apply_filters( 'bp_the_topic_post_poster_link', bp_core_get_user_domain( $topic_template->post->poster_id ) );
1224
  }
1225
 
1226
  function bp_the_topic_post_time_since() {
@@ -1238,7 +1234,7 @@ function bp_the_topic_post_is_mine() {
1238
  function bp_get_the_topic_post_is_mine() {
1239
  global $bp, $topic_template;
1240
 
1241
- return bp_loggedin_user_id() == $topic_template->post->poster_id;
1242
  }
1243
 
1244
  function bp_the_topic_post_admin_links( $args = '' ) {
@@ -1313,7 +1309,7 @@ function bp_directory_forums_search_form() {
1313
  $search_value = !empty( $_REQUEST['fs'] ) ? stripslashes( $_REQUEST['fs'] ) : $default_search_value; ?>
1314
 
1315
  <form action="" method="get" id="search-forums-form">
1316
- <label><input type="text" name="s" id="forums_search" placeholder="<?php echo esc_attr( $search_value ); ?>" /></label>
1317
  <input type="submit" id="forums_search_submit" name="forums_search_submit" value="<?php _e( 'Search', 'buddypress' ); ?>" />
1318
  </form>
1319
 
@@ -1380,7 +1376,7 @@ function bp_forums_tag_heat_map( $args = '' ) {
1380
  * Echo the current topic's tag list, comma-separated
1381
  *
1382
  * @package BuddyPress
1383
- * @since BuddyPress (1.5)
1384
  */
1385
  function bp_forum_topic_tag_list() {
1386
  echo bp_get_forum_topic_tag_list();
@@ -1389,7 +1385,7 @@ function bp_forum_topic_tag_list() {
1389
  * Get the current topic's tag list
1390
  *
1391
  * @package BuddyPress
1392
- * @since BuddyPress (1.5)
1393
  *
1394
  * @param str $format 'string' returns comma-separated string; otherwise returns array
1395
  * @return mixed $tags
@@ -1417,7 +1413,7 @@ function bp_forum_topic_tag_list() {
1417
  * Returns true if the current topic has tags
1418
  *
1419
  * @package BuddyPress
1420
- * @since BuddyPress (1.5)
1421
  *
1422
  * @return bool
1423
  */
7
  *
8
  * @package BuddyPress
9
  * @subpackage Forums Template
10
+ * @since 1.5
11
  *
12
  * @uses bp_get_forums_slug()
13
  */
19
  *
20
  * @package BuddyPress
21
  * @subpackage Forums Template
22
+ * @since 1.5
23
  */
24
  function bp_get_forums_slug() {
25
  global $bp;
31
  *
32
  * @package BuddyPress
33
  * @subpackage Forums Template
34
+ * @since 1.5
35
  *
36
  * @uses bp_get_forums_root_slug()
37
  */
43
  *
44
  * @package BuddyPress
45
  * @subpackage Forums Template
46
+ * @since 1.5
47
  */
48
  function bp_get_forums_root_slug() {
49
  global $bp;
55
  *
56
  * @package BuddyPress
57
  * @subpackage Forums Template
58
+ * @since 1.5
59
  * @uses bp_get_forums_directory_permalink()
60
  */
61
  function bp_forums_directory_permalink() {
66
  *
67
  * @package BuddyPress
68
  * @subpackage Forums Template
69
+ * @since 1.5
70
  * @uses apply_filters()
71
  * @uses traisingslashit()
72
  * @uses bp_get_root_domain()
97
  var $sort_by;
98
  var $order;
99
 
100
+ function BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms, $offset = false, $number = false ) {
101
+ $this->__construct( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms, $offset, $number );
102
+ }
103
+
104
  function __construct( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms, $offset = false, $number = false ) {
105
  global $bp;
106
 
132
 
133
  $this->topics = apply_filters( 'bp_forums_template_topics', $this->topics, $type, $forum_id, $per_page, $max, $no_stickies );
134
 
135
+ if ( !(int)$this->topics ) {
136
  $this->topic_count = 0;
137
  $this->total_topic_count = 0;
138
  } else {
141
  if ( !empty( $forum_id ) ) {
142
  // Group forums
143
  $topic_count = bp_forums_get_forum( $forum_id );
144
+ $topic_count = (int)$topic_count->topics;
145
  } else if ( !empty( $bp->groups->current_group ) ) {
146
  $topic_count = (int)groups_total_public_forum_topic_count( $type );
147
  } else if ( bp_is_user_forums_started() || ( bp_is_directory() && $user_id ) ) {
151
  } else if ( bp_is_user_forums_replied_to() ) {
152
  // Profile > Forums > Replied To
153
  $topic_count = bp_forums_total_replied_count_for_user( bp_displayed_user_id(), $type );
 
 
 
154
  } else {
155
  // For forum directories (All Topics), get a true count
156
+ $status = is_super_admin() ? 'all' : 'public'; // todo: member-of
157
  $topic_count = (int)groups_total_forum_topic_count( $status, $search_terms );
158
  }
159
 
160
  if ( !$max || $max >= $topic_count ) {
161
  $this->total_topic_count = $topic_count;
162
  } else {
163
+ $this->total_topic_count = (int)$max;
164
  }
165
 
166
  if ( $max ) {
167
  if ( $max >= count($this->topics) ) {
168
  $this->topic_count = count( $this->topics );
169
  } else {
170
+ $this->topic_count = (int)$max;
171
  }
172
  } else {
173
  $this->topic_count = count( $this->topics );
180
  // Fetch extra information for topics, so we don't have to query inside the loop
181
  $this->topics = bp_forums_get_topic_extras( $this->topics );
182
 
183
+ if ( (int)$this->total_topic_count && (int)$this->pag_num ) {
184
  $this->pag_links = paginate_links( array(
185
  'base' => add_query_arg( array( 'p' => '%#%', 'n' => $this->pag_num ) ),
186
  'format' => '',
187
+ 'total' => ceil( (int)$this->total_topic_count / (int)$this->pag_num),
188
  'current' => $this->pag_page,
189
  'prev_text' => _x( '&larr;', 'Forum topic pagination previous text', 'buddypress' ),
190
  'next_text' => _x( '&rarr;', 'Forum topic pagination next text', 'buddypress' ),
268
  $do_stickies = false;
269
 
270
  // User filtering
271
+ if ( !empty( $bp->displayed_user->id ) )
272
+ $user_id = $bp->displayed_user->id;
273
 
274
  // "Replied" query must be manually modified
275
  if ( 'replies' == bp_current_action() ) {
375
  // If there are stickies to merge on this page, do it now
376
  if ( $this_page_stickies ) {
377
  // Correct the topic_count
378
+ $forum_template->topic_count += (int)$this_page_stickies;
379
 
380
  // Figure out which stickies need to be included
381
  $this_page_sticky_topics = array_slice( $stickies_template->topics, 0 - $this_page_stickies );
382
 
383
  // Merge these topics into the forum template
384
+ $forum_template->topics = array_merge( $this_page_sticky_topics, (array)$forum_template->topics );
385
  }
386
  } else {
387
  // This page has no non-stickies
400
  $forum_template->pag_links = paginate_links( array(
401
  'base' => add_query_arg( array( 'p' => '%#%', 'n' => $forum_template->pag_num ) ),
402
  'format' => '',
403
+ 'total' => ceil( (int)$forum_template->total_topic_count / (int)$forum_template->pag_num ),
404
  'current' => $forum_template->pag_page,
405
  'prev_text' => _x( '&larr;', 'Forum topic pagination previous text', 'buddypress' ),
406
  'next_text' => _x( '&rarr;', 'Forum topic pagination next text', 'buddypress' ),
415
  // When skipping the sticky logic, just pull up the forum topics like usual
416
  $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, 'all', $search_terms );
417
  }
418
+
419
  return apply_filters( 'bp_has_topics', $forum_template->has_topics(), $forum_template );
420
  }
421
 
462
  function bp_get_the_topic_text() {
463
  global $forum_template;
464
 
465
+ $post = bb_get_first_post( (int)$forum_template->topic->topic_id, false );
466
  return apply_filters( 'bp_get_the_topic_text', esc_attr( $post->post_text ) );
467
  }
468
 
480
  }
481
  function bp_get_the_topic_poster_avatar( $args = '' ) {
482
  global $forum_template;
483
+
484
  $defaults = array(
485
  'type' => 'thumb',
486
  'width' => false,
487
  'height' => false,
488
+ 'alt' => __( 'Profile picture of %s', 'buddypress' )
489
  );
490
 
491
  $r = wp_parse_args( $args, $defaults );
575
  }
576
  function bp_get_the_topic_object_avatar( $args = '' ) {
577
  global $forum_template;
578
+
579
  if ( !isset( $forum_template->topic->object_id ) )
580
  return false;
581
 
771
  echo bp_get_the_topic_is_mine();
772
  }
773
  function bp_get_the_topic_is_mine() {
774
+ global $bp, $forum_template;
775
 
776
+ return $bp->loggedin_user->id == $forum_template->topic->topic_poster;
777
  }
778
 
779
  function bp_the_topic_admin_links( $args = '' ) {
780
  echo bp_get_the_topic_admin_links( $args );
781
  }
782
  function bp_get_the_topic_admin_links( $args = '' ) {
783
+ global $bp, $forum_template;
784
 
785
  $defaults = array(
786
  'seperator' => '|'
791
 
792
  $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'edit', 'bp_forums_edit_topic' ) . '">' . __( 'Edit Topic', 'buddypress' ) . '</a>';
793
 
794
+ if ( $bp->is_item_admin || $bp->is_item_mod || is_super_admin() ) {
795
+ if ( 0 == (int)$forum_template->topic->topic_sticky )
796
  $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'stick', 'bp_forums_stick_topic' ) . '">' . __( 'Sticky Topic', 'buddypress' ) . '</a>';
797
  else
798
  $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'unstick', 'bp_forums_unstick_topic' ) . '">' . __( 'Un-stick Topic', 'buddypress' ) . '</a>';
799
 
800
+ if ( 0 == (int)$forum_template->topic->topic_open )
801
  $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'open', 'bp_forums_open_topic' ) . '">' . __( 'Open Topic', 'buddypress' ) . '</a>';
802
  else
803
  $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'close', 'bp_forums_close_topic' ) . '">' . __( 'Close Topic', 'buddypress' ) . '</a>';
820
  if ( $forum_template->current_topic % 2 == 1 )
821
  $class .= 'alt';
822
 
823
+ if ( isset( $forum_template->topic->topic_sticky ) && 1 == (int)$forum_template->topic->topic_sticky )
824
  $class .= ' sticky';
825
 
826
+ if ( !isset( $forum_template->topic->topic_open ) || 0 == (int)$forum_template->topic->topic_open )
827
  $class .= ' closed';
828
 
829
  return apply_filters( 'bp_get_the_topic_css_class', trim( $class ) );
882
  * Echoes the output of bp_get_forum_topic_new_reply_link()
883
  *
884
  * @package BuddyPress
885
+ * @since 1.5
886
  */
887
  function bp_forum_topic_new_reply_link() {
888
  echo bp_get_forum_topic_new_reply_link();
891
  * Returns the permalink for the New Reply button at the top of forum topics
892
  *
893
  * @package BuddyPress
894
+ * @since 1.5
895
  *
896
  * @uses apply_filters() Filter bp_get_forum_topic_new_reply_link to modify
897
  * @return str The URL for the New Reply link
971
  return true;
972
  }
973
 
974
+
975
  class BP_Forums_Template_Topic {
976
  var $current_post = -1;
977
  var $post_count;
984
 
985
  var $in_the_loop;
986
 
 
 
 
 
 
 
 
 
987
  var $pag_page;
988
  var $pag_num;
989
  var $pag_links;
994
  var $sort_by;
995
  var $order;
996
 
997
+ function BP_Forums_Template_Topic( $topic_id, $per_page, $max, $order ) {
998
+ $this->__construct( $topic_id, $per_page, $max, $order );
999
+ }
1000
+
1001
  function __construct( $topic_id, $per_page, $max, $order ) {
1002
  global $bp, $current_user, $forum_template;
1003
 
1015
  $this->post_count = 0;
1016
  $this->total_post_count = 0;
1017
  } else {
1018
+ if ( !$max || $max >= (int)$forum_template->topic->topic_posts ) {
1019
+ $this->total_post_count = (int)$forum_template->topic->topic_posts;
1020
  } else {
1021
+ $this->total_post_count = (int)$max;
1022
  }
1023
 
1024
  if ( $max ) {
1025
  if ( $max >= count( $this->posts ) ) {
1026
  $this->post_count = count( $this->posts );
1027
  } else {
1028
+ $this->post_count = (int)$max;
1029
  }
1030
  } else {
1031
  $this->post_count = count( $this->posts );
1035
  // Load topic tags
1036
  $this->topic_tags = bb_get_topic_tags( $this->topic_id );
1037
 
1038
+ if ( (int)$this->total_post_count && (int)$this->pag_num ) {
 
 
1039
  $this->pag_links = paginate_links( array(
1040
+ 'base' => add_query_arg( array( 'topic_page' => '%#%', 'num' => (int)$this->pag_num ) ),
1041
  'format' => '',
1042
+ 'total' => ceil( (int)$this->total_post_count / (int)$this->pag_num ),
1043
  'current' => $this->pag_page,
1044
  'prev_text' => _x( '&larr;', 'Forum thread pagination previous text', 'buddypress' ),
1045
  'next_text' => _x( '&rarr;', 'Forum thread pagination next text', 'buddypress' ),
1046
  'mid_size' => 1
1047
  ) );
1048
 
1049
+ $this->pag->total_pages = ceil( (int)$this->total_post_count / (int)$this->pag_num );
1050
  } else {
1051
  $this->pag->total_pages = 1;
1052
  }
1170
  if ( $topic_template->current_post % 2 == 1 )
1171
  $class .= 'alt';
1172
 
1173
+ if ( 1 == (int)$topic_template->post->post_status )
1174
  $class .= ' deleted';
1175
 
1176
+ if ( 0 == (int)$topic_template->post->post_status )
1177
  $class .= ' open';
1178
 
1179
  return apply_filters( 'bp_get_the_topic_post_css_class', trim( $class ) );
1204
  function bp_get_the_topic_post_poster_name() {
1205
  global $topic_template;
1206
 
1207
+ if ( !$link = bp_core_get_user_domain( $topic_template->post->poster_id, $topic_template->post->poster_nicename, $topic_template->post->poster_login ) )
1208
  return __( 'Deleted User', 'buddypress' );
1209
 
1210
  return apply_filters( 'bp_get_the_topic_post_poster_name', '<a href="' . $link . '" title="' . $topic_template->post->poster_name . '">' . $topic_template->post->poster_name . '</a>' );
1216
  function bp_get_the_topic_post_poster_link() {
1217
  global $topic_template;
1218
 
1219
+ return apply_filters( 'bp_the_topic_post_poster_link', bp_core_get_user_domain( $topic_template->post->poster_id, $topic_template->post->poster_nicename, $topic_template->post->poster_login ) );
1220
  }
1221
 
1222
  function bp_the_topic_post_time_since() {
1234
  function bp_get_the_topic_post_is_mine() {
1235
  global $bp, $topic_template;
1236
 
1237
+ return $bp->loggedin_user->id == $topic_template->post->poster_id;
1238
  }
1239
 
1240
  function bp_the_topic_post_admin_links( $args = '' ) {
1309
  $search_value = !empty( $_REQUEST['fs'] ) ? stripslashes( $_REQUEST['fs'] ) : $default_search_value; ?>
1310
 
1311
  <form action="" method="get" id="search-forums-form">
1312
+ <label><input type="text" name="s" id="forums_search" value="<?php echo esc_attr( $search_value ); ?>" onfocus="if (this.value == '<?php echo $default_search_value ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php echo $default_search_value ?>';}" /></label>
1313
  <input type="submit" id="forums_search_submit" name="forums_search_submit" value="<?php _e( 'Search', 'buddypress' ); ?>" />
1314
  </form>
1315
 
1376
  * Echo the current topic's tag list, comma-separated
1377
  *
1378
  * @package BuddyPress
1379
+ * @since 1.5
1380
  */
1381
  function bp_forum_topic_tag_list() {
1382
  echo bp_get_forum_topic_tag_list();
1385
  * Get the current topic's tag list
1386
  *
1387
  * @package BuddyPress
1388
+ * @since 1.5
1389
  *
1390
  * @param str $format 'string' returns comma-separated string; otherwise returns array
1391
  * @return mixed $tags
1413
  * Returns true if the current topic has tags
1414
  *
1415
  * @package BuddyPress
1416
+ * @since 1.5
1417
  *
1418
  * @return bool
1419
  */
bp-forums/deprecated/1.6.php DELETED
@@ -1,203 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * BuddyPress Forums Deprecated Functions
5
- *
6
- * This file contains all the deprecated functions for BuddyPress forums since
7
- * version 1.6. This was a major update for the forums component, moving from
8
- * bbPress 1.1 to bbPress 2.1.
9
- *
10
- * @package BuddyPress
11
- * @subpackage Forums
12
- */
13
-
14
- // Exit if accessed directly
15
- if ( !defined( 'ABSPATH' ) ) exit;
16
-
17
- function bp_forums_bbpress_admin() {
18
-
19
- $action = bp_get_admin_url( 'admin.php?page=bb-forums-setup&reinstall=1' ); ?>
20
-
21
- <div class="wrap">
22
- <?php screen_icon( 'buddypress' ); ?>
23
-
24
- <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( __( 'Forums', 'buddypress' ) ); ?></h2>
25
-
26
- <?php if ( isset( $_POST['submit'] ) ) : ?>
27
-
28
- <div id="message" class="updated fade">
29
- <p><?php _e( 'Settings Saved.', 'buddypress' ) ?></p>
30
- </div>
31
-
32
- <?php endif; ?>
33
-
34
- <?php
35
-
36
- if ( isset( $_REQUEST['reinstall'] ) || !bp_forums_is_installed_correctly() ) :
37
-
38
- // Delete the bb-config.php location option
39
- bp_delete_option( 'bb-config-location' );
40
- bp_forums_bbpress_install_wizard();
41
-
42
- else : ?>
43
-
44
- <div style="width: 45%; float: left; margin-top: 20px;">
45
- <h3><?php _e( 'Forums for Groups', 'buddypress' ) ?></h3>
46
-
47
- <p><?php _e( 'Give each individual group its own discussion forum. Choose this if you\'d like to keep your members\' conversations separated into distinct areas.' , 'buddypress' ); ?></p>
48
- <p class="description"><?php _e( 'You may use an existing bbPress installation if you have one.', 'buddypress' ); ?></p>
49
-
50
- <h4 style="margin-bottom: 10px;"><?php _e( 'Features', 'buddypress' ); ?></h4>
51
- <ul class="description" style="list-style: square; margin-left: 30px;">
52
- <li><?php _e( 'Group Integration', 'buddypress' ); ?></p></li>
53
- <li><?php _e( 'Member Profile Integration', 'buddypress' ); ?></p></li>
54
- <li><?php _e( 'Activity Stream Integration', 'buddypress' ); ?></p></li>
55
- <li><?php _e( '@ Mention Integration', 'buddypress' ); ?></p></li>
56
- </ul>
57
-
58
- <div>
59
- <a class="button button-primary" href="<?php echo $action ?>"><?php _e( 'Reinstall Group Forums', 'buddypress' ) ?></a> &nbsp;
60
- </div>
61
- </div>
62
-
63
- <div style="width: 45%; float: left; margin: 20px 0 20px 20px; padding: 0 20px 20px 20px; border: 1px solid #ddd; background-color: #fff;">
64
- <h3><?php _e( 'New! Site Wide Forums', 'buddypress' ) ?></h3>
65
- <p><?php _e( 'Your site will have central forums that are not isolated to any specific group. Choose this if you\'d like to have a central forum area for your members.', 'buddypress' ) ?></p>
66
- <p class="description"><?php _e( 'You may activate both Group and Site Wide forums, but this may create a poor experience for your members.', 'buddypress' ) ?></p>
67
-
68
- <h4 style="margin-bottom: 10px;"><?php _e( 'Features', 'buddypress' ); ?></h4>
69
- <ul class="description" style="list-style: square; margin-left: 30px;">
70
- <li><?php _e( 'Central Discussion Area', 'buddypress' ); ?></p></li>
71
- <li><?php _e( 'Forum Plugins Available', 'buddypress' ); ?></p></li>
72
- <li><?php _e( 'Activity Stream Integration', 'buddypress' ); ?></p></li>
73
- <li><?php _e( '@ Mention Integration', 'buddypress' ); ?></p></li>
74
- </ul>
75
- <div>
76
- <a class="button thickbox button-primary" href="<?php bp_admin_url( add_query_arg( array( 'tab' => 'plugin-information', 'plugin' => 'bbpress', 'TB_iframe' => 'true', 'width' => '640', 'height' => '500' ), 'plugin-install.php' ) ); ?>"><?php _e( 'Install Site Wide Forums', 'buddypress' ) ?></a> &nbsp;
77
- </div>
78
- </div>
79
-
80
- <?php endif; ?>
81
-
82
- </div>
83
- <?php
84
- }
85
-
86
- function bp_forums_bbpress_install_wizard() {
87
- $post_url = network_admin_url( 'admin.php?page=bb-forums-setup' );
88
-
89
- $step = isset( $_REQUEST['step'] ) ? $_REQUEST['step'] : '';
90
-
91
- switch( $step ) {
92
- case 'existing':
93
- if ( isset( $_REQUEST['doinstall'] ) && ( 1 == (int) $_REQUEST['doinstall'] ) ) {
94
- if ( !bp_forums_configure_existing_install() ) {
95
- _e( 'The bb-config.php file was not found at that location, please try again.', 'buddypress' );
96
- } else {
97
- ?>
98
- <h3><?php _e( 'Forums were set up correctly using your existing bbPress install!', 'buddypress' ) ?></h3>
99
- <p><?php _e( 'BuddyPress will now use its internal copy of bbPress to run the forums on your site. If you wish, you can remove your old bbPress installation files, as long as you keep the bb-config.php file in the same location.', 'buddypress' ) ?></p><?php
100
- }
101
- } else { ?>
102
-
103
- <form action="" method="post">
104
- <h3><?php _e( 'Existing bbPress Installation', 'buddypress' ) ?></h3>
105
- <p><?php _e( "BuddyPress can make use of your existing bbPress install. Just provide the location of your <code>bb-config.php</code> file, and BuddyPress will do the rest.", 'buddypress' ) ?></p>
106
- <p><label><code>bb-config.php</code> file location:</label><br /><input style="width: 50%" type="text" name="bbconfigloc" id="bbconfigloc" value="<?php echo str_replace( 'buddypress', '', $_SERVER['DOCUMENT_ROOT'] ) ?>" /></p>
107
- <p><input type="submit" class="button-primary" value="<?php _e( 'Complete Installation', 'buddypress' ) ?>" /></p>
108
- <input type="hidden" name="step" value="existing" />
109
- <input type="hidden" name="doinstall" value="1" />
110
- <?php wp_nonce_field( 'bp_forums_existing_install_init' ) ?>
111
- </form>
112
-
113
- <?php
114
- }
115
- break;
116
-
117
- case 'new':
118
- if ( isset( $_REQUEST['doinstall'] ) && 1 == (int) $_REQUEST['doinstall'] ) {
119
- $result = bp_forums_bbpress_install();
120
-
121
- switch ( $result ) {
122
- case 1:
123
- _e( '<p>All done! Configuration settings have been saved to the file <code>bb-config.php</code> in the root of your WordPress install.</p>', 'buddypress' );
124
- break;
125
- default:
126
- // Just write the contents to screen
127
- _e( '<p>A configuration file could not be created. No problem, but you will need to save the text shown below into a file named <code>bb-config.php</code> in the root directory of your WordPress installation before you can start using the forum functionality.</p>', 'buddypress' ); ?>
128
-
129
- <textarea style="display:block; margin-top: 30px; width: 80%;" rows="50"><?php echo htmlspecialchars( $result ); ?></textarea>
130
-
131
- <?php
132
- break;
133
- }
134
- } else { ?>
135
-
136
- <h3><?php _e( 'New bbPress Installation', 'buddypress' ) ?></h3>
137
- <p><?php _e( "You've decided to set up a new installation of bbPress for forum management in BuddyPress. This is very simple and is usually just a one click
138
- process. When you're ready, hit the link below.", 'buddypress' ) ?></p>
139
- <p><a class="button-primary" href="<?php echo wp_nonce_url( $post_url . '&step=new&doinstall=1', 'bp_forums_new_install_init' ) ?>"><?php _e( 'Complete Installation', 'buddypress' ) ?></a></p>
140
-
141
- <?php
142
- }
143
- break;
144
-
145
- default:
146
- if ( !file_exists( BP_PLUGIN_DIR . '/bp-forums/bbpress/' ) ) { ?>
147
-
148
- <div id="message" class="error">
149
- <p><?php printf( __( 'bbPress files were not found. To install the forums component you must download a copy of bbPress and make sure it is in the folder: "%s"', 'buddypress' ), 'wp-content/plugins/buddypress/bp-forums/bbpress/' ) ?></p>
150
- </div>
151
-
152
- <?php } else {
153
-
154
- // Include the plugin install
155
-
156
- add_thickbox();
157
- wp_enqueue_script( 'plugin-install' );
158
- wp_admin_css( 'plugin-install' );
159
- ?>
160
-
161
- <div style="width: 45%; float: left; margin-top: 20px;">
162
- <h3><?php _e( 'Forums for Groups', 'buddypress' ) ?></h3>
163
-
164
- <p><?php _e( 'Give each individual group its own discussion forum. Choose this if you\'d like to keep your members\' conversations separated into distinct areas.' , 'buddypress' ); ?></p>
165
- <p class="description"><?php _e( 'You may use an existing bbPress installation if you have one.', 'buddypress' ); ?></p>
166
-
167
- <h4 style="margin-bottom: 10px;"><?php _e( 'Features', 'buddypress' ); ?></h4>
168
- <ul class="description" style="list-style: square; margin-left: 30px;">
169
- <li><?php _e( 'Group Integration', 'buddypress' ); ?></p></li>
170
- <li><?php _e( 'Member Profile Integration', 'buddypress' ); ?></p></li>
171
- <li><?php _e( 'Activity Stream Integration', 'buddypress' ); ?></p></li>
172
- <li><?php _e( '@ Mention Integration', 'buddypress' ); ?></p></li>
173
- </ul>
174
-
175
- <div>
176
- <a class="button button-primary" href="<?php echo $post_url . '&step=new' ?>"><?php _e( 'Install Group Forums', 'buddypress' ) ?></a> &nbsp;
177
- <a class="button" href="<?php echo $post_url . '&step=existing' ?>"><?php _e( 'Use Existing Installation', 'buddypress' ) ?></a>
178
- </div>
179
- </div>
180
-
181
- <div style="width: 45%; float: left; margin: 20px 0 20px 20px; padding: 0 20px 20px 20px; border: 1px solid #ddd; background-color: #fff;">
182
- <h3><?php _e( 'New! Site Wide Forums', 'buddypress' ) ?></h3>
183
- <p><?php _e( 'Your site will have central forums that are not isolated to any specific group. Choose this if you\'d like to have a central forum area for your members.', 'buddypress' ) ?></p>
184
- <p class="description"><?php _e( 'You may activate both Group and Site Wide forums, but this may create a poor experience for your members.', 'buddypress' ) ?></p>
185
-
186
- <h4 style="margin-bottom: 10px;"><?php _e( 'Features', 'buddypress' ); ?></h4>
187
- <ul class="description" style="list-style: square; margin-left: 30px;">
188
- <li><?php _e( 'Central Discussion Area', 'buddypress' ); ?></p></li>
189
- <li><?php _e( 'Forum Plugins Available', 'buddypress' ); ?></p></li>
190
- <li><?php _e( 'Activity Stream Integration', 'buddypress' ); ?></p></li>
191
- <li><?php _e( '@ Mention Integration', 'buddypress' ); ?></p></li>
192
- </ul>
193
- <div>
194
- <a class="button thickbox button-primary" href="<?php bp_admin_url( add_query_arg( array( 'tab' => 'plugin-information', 'plugin' => 'bbpress', 'TB_iframe' => 'true', 'width' => '640', 'height' => '500' ), 'plugin-install.php' ) ); ?>"><?php _e( 'Install Site Wide Forums', 'buddypress' ) ?></a> &nbsp;
195
- </div>
196
- </div>
197
-
198
- <?php }
199
- break;
200
- }
201
- }
202
-
203
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-friends/bp-friends-actions.php CHANGED
@@ -1,14 +1,8 @@
1
  <?php
2
-
3
  /**
4
- * BuddyPress Friends Actions
5
- *
6
  * Action functions are exactly the same as screen functions, however they do not
7
  * have a template screen associated with them. Usually they will send the user
8
  * back to the default screen after execution.
9
- *
10
- * @package BuddyPress
11
- * @subpackage FriendsActions
12
  */
13
 
14
  // Exit if accessed directly
@@ -84,4 +78,4 @@ function friends_action_remove_friend() {
84
  }
85
  add_action( 'bp_init', 'friends_action_remove_friend' );
86
 
87
- ?>
1
  <?php
 
2
  /**
 
 
3
  * Action functions are exactly the same as screen functions, however they do not
4
  * have a template screen associated with them. Usually they will send the user
5
  * back to the default screen after execution.
 
 
 
6
  */
7
 
8
  // Exit if accessed directly
78
  }
79
  add_action( 'bp_init', 'friends_action_remove_friend' );
80
 
81
+ ?>
bp-friends/bp-friends-activity.php CHANGED
@@ -1,13 +1,7 @@
1
  <?php
2
-
3
  /**
4
- * BuddyPress Friends Activity Functions
5
- *
6
- * These functions handle the recording, deleting and formatting of activity
7
- * for the user and for this specific component.
8
- *
9
- * @package BuddyPress
10
- * @subpackage FriendsActivity
11
  */
12
 
13
  // Exit if accessed directly
@@ -20,7 +14,7 @@ function friends_record_activity( $args = '' ) {
20
  return false;
21
 
22
  $defaults = array (
23
- 'user_id' => bp_loggedin_user_id(),
24
  'action' => '',
25
  'content' => '',
26
  'primary_link' => '',
@@ -42,7 +36,7 @@ function friends_delete_activity( $args ) {
42
  global $bp;
43
 
44
  if ( bp_is_active( 'activity' ) ) {
45
- extract( (array) $args );
46
  bp_activity_delete_by_item_id( array( 'item_id' => $item_id, 'component' => $bp->friends->id, 'type' => $type, 'user_id' => $user_id ) );
47
  }
48
  }
@@ -53,11 +47,6 @@ function friends_register_activity_actions() {
53
  if ( !bp_is_active( 'activity' ) )
54
  return false;
55
 
56
- // These two added in BP 1.6
57
- bp_activity_set_action( $bp->friends->id, 'friendship_accepted', __( 'Friendships accepted', 'buddypress' ) );
58
- bp_activity_set_action( $bp->friends->id, 'friendship_created', __( 'New friendships', 'buddypress' ) );
59
-
60
- // < BP 1.6 backpat
61
  bp_activity_set_action( $bp->friends->id, 'friends_register_activity_action', __( 'New friendship created', 'buddypress' ) );
62
 
63
  do_action( 'friends_register_activity_actions' );
@@ -65,7 +54,7 @@ function friends_register_activity_actions() {
65
  add_action( 'bp_register_activity_actions', 'friends_register_activity_actions' );
66
 
67
  /**
68
- * Format the BuddyBar/Toolbar notifications for the Friends component
69
  *
70
  * @package BuddyPress
71
  *
@@ -73,17 +62,18 @@ add_action( 'bp_register_activity_actions', 'friends_register_activity_actions'
73
  * @param int $item_id The primary item id
74
  * @param int $secondary_item_id The secondary item id
75
  * @param int $total_items The total number of messaging-related notifications waiting for the user
76
- * @param str $format 'string' for BuddyBar-compatible notifications; 'array' for WP Toolbar
77
  */
78
  function friends_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
 
79
 
80
  switch ( $action ) {
81
  case 'friendship_accepted':
82
- $link = trailingslashit( bp_loggedin_user_domain() . bp_get_friends_slug() . '/my-friends' );
83
 
84
  // Set up the string and the filter
85
- if ( (int) $total_items > 1 ) {
86
- $text = sprintf( __( '%d friends accepted your friendship requests', 'buddypress' ), (int) $total_items );
87
  $filter = 'bp_friends_multiple_friendship_accepted_notification';
88
  } else {
89
  $text = sprintf( __( '%s accepted your friendship request', 'buddypress' ), bp_core_get_user_displayname( $item_id ) );
@@ -93,11 +83,11 @@ function friends_format_notifications( $action, $item_id, $secondary_item_id, $t
93
  break;
94
 
95
  case 'friendship_request':
96
- $link = bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/?new';
97
 
98
  // Set up the string and the filter
99
- if ( (int) $total_items > 1 ) {
100
- $text = sprintf( __( 'You have %d pending friendship requests', 'buddypress' ), (int) $total_items );
101
  $filter = 'bp_friends_multiple_friendship_request_notification';
102
  } else {
103
  $text = sprintf( __( 'You have a friendship request from %s', 'buddypress' ), bp_core_get_user_displayname( $item_id ) );
@@ -109,12 +99,12 @@ function friends_format_notifications( $action, $item_id, $secondary_item_id, $t
109
 
110
  // Return either an HTML link or an array, depending on the requested format
111
  if ( 'string' == $format ) {
112
- $return = apply_filters( $filter, '<a href="' . $link . '">' . $text . '</a>', (int) $total_items );
113
  } else {
114
  $return = apply_filters( $filter, array(
115
  'link' => $link,
116
  'text' => $text
117
- ), (int) $total_items );
118
  }
119
 
120
  do_action( 'friends_format_notifications', $action, $item_id, $secondary_item_id, $total_items, $return );
@@ -122,4 +112,4 @@ function friends_format_notifications( $action, $item_id, $secondary_item_id, $t
122
  return $return;
123
  }
124
 
125
- ?>
1
  <?php
 
2
  /**
3
+ * These functions handle the recording, deleting and formatting of activity and
4
+ * notifications for the user and for this specific component.
 
 
 
 
 
5
  */
6
 
7
  // Exit if accessed directly
14
  return false;
15
 
16
  $defaults = array (
17
+ 'user_id' => $bp->loggedin_user->id,
18
  'action' => '',
19
  'content' => '',
20
  'primary_link' => '',
36
  global $bp;
37
 
38
  if ( bp_is_active( 'activity' ) ) {
39
+ extract( (array)$args );
40
  bp_activity_delete_by_item_id( array( 'item_id' => $item_id, 'component' => $bp->friends->id, 'type' => $type, 'user_id' => $user_id ) );
41
  }
42
  }
47
  if ( !bp_is_active( 'activity' ) )
48
  return false;
49
 
 
 
 
 
 
50
  bp_activity_set_action( $bp->friends->id, 'friends_register_activity_action', __( 'New friendship created', 'buddypress' ) );
51
 
52
  do_action( 'friends_register_activity_actions' );
54
  add_action( 'bp_register_activity_actions', 'friends_register_activity_actions' );
55
 
56
  /**
57
+ * Format the BuddyBar/admin bar notifications for the Friends component
58
  *
59
  * @package BuddyPress
60
  *
62
  * @param int $item_id The primary item id
63
  * @param int $secondary_item_id The secondary item id
64
  * @param int $total_items The total number of messaging-related notifications waiting for the user
65
+ * @param str $format 'string' for BuddyBar-compatible notifications; 'array' for WP Admin Bar
66
  */
67
  function friends_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
68
+ global $bp;
69
 
70
  switch ( $action ) {
71
  case 'friendship_accepted':
72
+ $link = bp_loggedin_user_domain() . bp_get_friends_slug() . '/my-friends/newest';
73
 
74
  // Set up the string and the filter
75
+ if ( (int)$total_items > 1 ) {
76
+ $text = sprintf( __( '%d friends accepted your friendship requests', 'buddypress' ), (int)$total_items );
77
  $filter = 'bp_friends_multiple_friendship_accepted_notification';
78
  } else {
79
  $text = sprintf( __( '%s accepted your friendship request', 'buddypress' ), bp_core_get_user_displayname( $item_id ) );
83
  break;
84
 
85
  case 'friendship_request':
86
+ $link = bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests?new';
87
 
88
  // Set up the string and the filter
89
+ if ( (int)$total_items > 1 ) {
90
+ $text = sprintf( __( 'You have %d pending friendship requests', 'buddypress' ), (int)$total_items );
91
  $filter = 'bp_friends_multiple_friendship_request_notification';
92
  } else {
93
  $text = sprintf( __( 'You have a friendship request from %s', 'buddypress' ), bp_core_get_user_displayname( $item_id ) );
99
 
100
  // Return either an HTML link or an array, depending on the requested format
101
  if ( 'string' == $format ) {
102
+ $return = apply_filters( $filter, '<a href="' . $link . '">' . $text . '</a>', (int)$total_items );
103
  } else {
104
  $return = apply_filters( $filter, array(
105
  'link' => $link,
106
  'text' => $text
107
+ ), (int)$total_items );
108
  }
109
 
110
  do_action( 'friends_format_notifications', $action, $item_id, $secondary_item_id, $total_items, $return );
112
  return $return;
113
  }
114
 
115
+ ?>
bp-friends/bp-friends-cache.php CHANGED
@@ -1,16 +1,9 @@
1
  <?php
2
-
3
  /**
4
- * BuddyPress Friends Caching
5
- *
6
  * Caching functions handle the clearing of cached objects and pages on specific
7
  * actions throughout BuddyPress.
8
- *
9
- * @package BuddyPress
10
- * @subpackage FriendsCaching
11
  */
12
 
13
-
14
  // Exit if accessed directly
15
  if ( !defined( 'ABSPATH' ) ) exit;
16
 
@@ -20,13 +13,15 @@ function friends_clear_friend_object_cache( $friendship_id ) {
20
 
21
  wp_cache_delete( 'friends_friend_ids_' . $friendship->initiator_user_id, 'bp' );
22
  wp_cache_delete( 'friends_friend_ids_' . $friendship->friend_user_id, 'bp' );
 
 
23
  }
24
 
25
  function friends_clear_friend_notifications() {
26
  global $bp;
27
 
28
  if ( isset( $_GET['new'] ) )
29
- bp_core_delete_notifications_by_type( bp_loggedin_user_id(), $bp->friends->id, 'friendship_accepted' );
30
  }
31
  add_action( 'bp_activity_screen_my_activity', 'friends_clear_friend_notifications' );
32
 
@@ -40,4 +35,4 @@ add_action( 'friends_friendship_accepted', 'bp_core_clear_cache' );
40
  add_action( 'friends_friendship_deleted', 'bp_core_clear_cache' );
41
  add_action( 'friends_friendship_requested', 'bp_core_clear_cache' );
42
 
43
- ?>
1
  <?php
 
2
  /**
 
 
3
  * Caching functions handle the clearing of cached objects and pages on specific
4
  * actions throughout BuddyPress.
 
 
 
5
  */
6
 
 
7
  // Exit if accessed directly
8
  if ( !defined( 'ABSPATH' ) ) exit;
9
 
13
 
14
  wp_cache_delete( 'friends_friend_ids_' . $friendship->initiator_user_id, 'bp' );
15
  wp_cache_delete( 'friends_friend_ids_' . $friendship->friend_user_id, 'bp' );
16
+ wp_cache_delete( 'bp_total_friend_count_' . $friendship->initiator_user_id, 'bp' );
17
+ wp_cache_delete( 'bp_total_friend_count_' . $friendship->friend_user_id, 'bp' );
18
  }
19
 
20
  function friends_clear_friend_notifications() {
21
  global $bp;
22
 
23
  if ( isset( $_GET['new'] ) )
24
+ bp_core_delete_notifications_by_type( $bp->loggedin_user->id, $bp->friends->id, 'friendship_accepted' );
25
  }
26
  add_action( 'bp_activity_screen_my_activity', 'friends_clear_friend_notifications' );
27
 
35
  add_action( 'friends_friendship_deleted', 'bp_core_clear_cache' );
36
  add_action( 'friends_friendship_requested', 'bp_core_clear_cache' );
37
 
38
+ ?>
bp-friends/bp-friends-classes.php CHANGED
@@ -1,5 +1,4 @@
1
  <?php
2
-
3
  // Exit if accessed directly
4
  if ( !defined( 'ABSPATH' ) ) exit;
5
 
@@ -16,18 +15,22 @@ class BP_Friends_Friendship {
16
 
17
  var $friend;
18
 
 
 
 
 
19
  function __construct( $id = null, $is_request = false, $populate_friend_details = true ) {
20
  $this->is_request = $is_request;
21
 
22
- if ( !empty( $id ) ) {
23
- $this->id = $id;
24
  $this->populate_friend_details = $populate_friend_details;
25
  $this->populate( $this->id );
26
  }
27
  }
28
 
29
  function populate() {
30
- global $wpdb, $bp;
31
 
32
  if ( $friendship = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->friends->table_name} WHERE id = %d", $this->id ) ) ) {
33
  $this->initiator_user_id = $friendship->initiator_user_id;
@@ -37,8 +40,12 @@ class BP_Friends_Friendship {
37
  $this->date_created = $friendship->date_created;
38
  }
39
 
40
- if ( !empty( $this->populate_friend_details ) ) {
41
- if ( $this->friend_user_id == bp_displayed_user_id() ) {
 
 
 
 
42
  $this->friend = new BP_Core_User( $this->initiator_user_id );
43
  } else {
44
  $this->friend = new BP_Core_User( $this->friend_user_id );
@@ -57,12 +64,11 @@ class BP_Friends_Friendship {
57
 
58
  do_action_ref_array( 'friends_friendship_before_save', array( &$this ) );
59
 
60
- // Update
61
- if (!empty( $this->id ) ) {
62
  $result = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET initiator_user_id = %d, friend_user_id = %d, is_confirmed = %d, is_limited = %d, date_created = %s ) WHERE id = %d", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created, $this->id ) );
63
-
64
- // Save
65
  } else {
 
66
  $result = $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->friends->table_name} ( initiator_user_id, friend_user_id, is_confirmed, is_limited, date_created ) VALUES ( %d, %d, %d, %d, %s )", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created ) );
67
  $this->id = $wpdb->insert_id;
68
  }
@@ -78,12 +84,12 @@ class BP_Friends_Friendship {
78
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE id = %d", $this->id ) );
79
  }
80
 
81
- /** Static Methods ********************************************************/
82
 
83
  function get_friend_user_ids( $user_id, $friend_requests_only = false, $assoc_arr = false ) {
84
  global $wpdb, $bp;
85
 
86
- if ( !empty( $friend_requests_only ) ) {
87
  $oc_sql = $wpdb->prepare( "AND is_confirmed = 0" );
88
  $friend_sql = $wpdb->prepare ( " WHERE friend_user_id = %d", $user_id );
89
  } else {
@@ -95,11 +101,10 @@ class BP_Friends_Friendship {
95
  $fids = array();
96
 
97
  for ( $i = 0, $count = count( $friends ); $i < $count; ++$i ) {
98
- if ( !empty( $assoc_arr ) ) {
99
  $fids[] = array( 'user_id' => ( $friends[$i]->friend_user_id == $user_id ) ? $friends[$i]->initiator_user_id : $friends[$i]->friend_user_id );
100
- } else {
101
  $fids[] = ( $friends[$i]->friend_user_id == $user_id ) ? $friends[$i]->initiator_user_id : $friends[$i]->friend_user_id;
102
- }
103
  }
104
 
105
  return $fids;
@@ -120,8 +125,8 @@ class BP_Friends_Friendship {
120
  function total_friend_count( $user_id = 0 ) {
121
  global $wpdb, $bp;
122
 
123
- if ( empty( $user_id ) )
124
- $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
125
 
126
  /* This is stored in 'total_friend_count' usermeta.
127
  This function will recalculate, update and return. */
@@ -129,11 +134,11 @@ class BP_Friends_Friendship {
129
  $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d OR friend_user_id = %d) AND is_confirmed = 1", $user_id, $user_id ) );
130
 
131
  // Do not update meta if user has never had friends
132
- if ( empty( $count ) && !bp_get_user_meta( $user_id, 'total_friend_count', true ) )
133
  return 0;
134
 
135
- bp_update_user_meta( $user_id, 'total_friend_count', (int) $count );
136
- return (int) $count;
137
  }
138
 
139
  function search_friends( $filter, $user_id, $limit = null, $page = null ) {
@@ -141,12 +146,12 @@ class BP_Friends_Friendship {
141
 
142
  // TODO: Optimize this function.
143
 
144
- if ( empty( $user_id ) )
145
- $user_id = bp_loggedin_user_id();
146
 
147
  $filter = like_escape( $wpdb->escape( $filter ) );
148
 
149
- if ( !empty( $limit ) && !empty( $page ) )
150
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
151
 
152
  if ( !$friend_ids = BP_Friends_Friendship::get_friend_user_ids( $user_id ) )
@@ -155,7 +160,7 @@ class BP_Friends_Friendship {
155
  // Get all the user ids for the current user's friends.
156
  $fids = implode( ',', $friend_ids );
157
 
158
- if ( empty( $fids ) )
159
  return false;
160
 
161
  // filter the user_ids based on the search criteria.
@@ -167,25 +172,25 @@ class BP_Friends_Friendship {
167
  $total_sql = "SELECT COUNT(DISTINCT user_id) FROM {$wpdb->usermeta} WHERE user_id IN ($fids) AND meta_key = 'nickname' AND meta_value LIKE '$filter%%'";
168
  }
169
 
170
- $filtered_friend_ids = $wpdb->get_col( $sql );
171
- $total_friend_ids = $wpdb->get_var( $total_sql );
172
 
173
- if ( empty( $filtered_friend_ids ) )
174
  return false;
175
 
176
- return array( 'friends' => $filtered_friend_ids, 'total' => (int) $total_friend_ids );
177
  }
178
 
179
  function check_is_friend( $loggedin_userid, $possible_friend_userid ) {
180
  global $wpdb, $bp;
181
 
182
- if ( empty( $loggedin_userid ) || empty( $possible_friend_userid ) )
183
  return false;
184
 
185
  $result = $wpdb->get_results( $wpdb->prepare( "SELECT id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id = %d) OR (initiator_user_id = %d AND friend_user_id = %d)", $loggedin_userid, $possible_friend_userid, $possible_friend_userid, $loggedin_userid ) );
186
 
187
- if ( !empty( $result ) ) {
188
- if ( 0 == (int) $result[0]->is_confirmed ) {
189
  return 'pending';
190
  } else {
191
  return 'is_friend';
@@ -196,7 +201,7 @@ class BP_Friends_Friendship {
196
  }
197
 
198
  function get_bulk_last_active( $user_ids ) {
199
- global $wpdb;
200
 
201
  return $wpdb->get_results( $wpdb->prepare( "SELECT meta_value as last_activity, user_id FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} ) ORDER BY meta_value DESC", bp_get_user_meta_key( 'last_activity' ) ) );
202
  }
@@ -204,30 +209,24 @@ class BP_Friends_Friendship {
204
  function accept($friendship_id) {
205
  global $wpdb, $bp;
206
 
207
- return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET is_confirmed = 1, date_created = %s WHERE id = %d AND friend_user_id = %d", bp_core_current_time(), $friendship_id, bp_loggedin_user_id() ) );
208
- }
209
-
210
- function withdraw($friendship_id) {
211
- global $wpdb, $bp;
212
-
213
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE id = %d AND initiator_user_id = %d", $friendship_id, bp_loggedin_user_id() ) );
214
  }
215
 
216
  function reject($friendship_id) {
217
  global $wpdb, $bp;
218
 
219
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE id = %d AND friend_user_id = %d", $friendship_id, bp_loggedin_user_id() ) );
220
  }
221
 
222
  function search_users( $filter, $user_id, $limit = null, $page = null ) {
223
- global $wpdb;
224
 
225
  $filter = like_escape( $wpdb->escape( $filter ) );
226
 
227
  $usermeta_table = $wpdb->base_prefix . 'usermeta';
228
- $users_table = $wpdb->base_prefix . 'users';
229
 
230
- if ( !empty( $limit ) && !empty( $page ) )
231
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * intval( $limit ) ), intval( $limit ) );
232
 
233
  // filter the user_ids based on the search criteria.
@@ -239,7 +238,7 @@ class BP_Friends_Friendship {
239
 
240
  $filtered_fids = $wpdb->get_col($sql);
241
 
242
- if ( empty( $filtered_fids ) )
243
  return false;
244
 
245
  return $filtered_fids;
@@ -251,7 +250,7 @@ class BP_Friends_Friendship {
251
  $filter = like_escape( $wpdb->escape( $filter ) );
252
 
253
  $usermeta_table = $wpdb->prefix . 'usermeta';
254
- $users_table = $wpdb->base_prefix . 'users';
255
 
256
  // filter the user_ids based on the search criteria.
257
  if ( bp_is_active( 'xprofile' ) ) {
@@ -262,7 +261,7 @@ class BP_Friends_Friendship {
262
 
263
  $user_count = $wpdb->get_col($sql);
264
 
265
- if ( empty( $user_count ) )
266
  return false;
267
 
268
  return $user_count[0];
@@ -280,9 +279,8 @@ class BP_Friends_Friendship {
280
  function get_random_friends( $user_id, $total_friends = 5 ) {
281
  global $wpdb, $bp;
282
 
283
- $fids = array();
284
- $sql = $wpdb->prepare( "SELECT friend_user_id, initiator_user_id FROM {$bp->friends->table_name} WHERE (friend_user_id = %d || initiator_user_id = %d) && is_confirmed = 1 ORDER BY rand() LIMIT %d", $user_id, $user_id, $total_friends );
285
- $results = $wpdb->get_results( $sql );
286
 
287
  for ( $i = 0, $count = count( $results ); $i < $count; ++$i ) {
288
  $fids[] = ( $results[$i]->friend_user_id == $user_id ) ? $results[$i]->initiator_user_id : $results[$i]->friend_user_id;
@@ -290,7 +288,7 @@ class BP_Friends_Friendship {
290
 
291
  // remove duplicates
292
  if ( count( $fids ) > 0 )
293
- return array_flip( array_flip( $fids ) );
294
  else
295
  return false;
296
  }
@@ -341,10 +339,9 @@ class BP_Friends_Friendship {
341
  $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE component_name = 'friends' AND ( component_action = 'friendship_request' OR component_action = 'friendship_accepted' ) AND item_id = %d", $user_id ) );
342
 
343
  // Loop through friend_ids and update their counts
344
- foreach ( (array) $friend_ids as $friend_id ) {
345
  BP_Friends_Friendship::total_friend_count( $friend_id );
346
  }
347
  }
348
  }
349
-
350
- ?>
1
  <?php
 
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
15
 
16
  var $friend;
17
 
18
+ function bp_friends_friendship( $id = null, $is_request = false, $populate_friend_details = true ) {
19
+ $this->__construct( $id, $is_request, $populate_friend_details );
20
+ }
21
+
22
  function __construct( $id = null, $is_request = false, $populate_friend_details = true ) {
23
  $this->is_request = $is_request;
24
 
25
+ if ( $id ) {
26
+ $this->id = $id;
27
  $this->populate_friend_details = $populate_friend_details;
28
  $this->populate( $this->id );
29
  }
30
  }
31
 
32
  function populate() {
33
+ global $wpdb, $bp, $creds;
34
 
35
  if ( $friendship = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->friends->table_name} WHERE id = %d", $this->id ) ) ) {
36
  $this->initiator_user_id = $friendship->initiator_user_id;
40
  $this->date_created = $friendship->date_created;
41
  }
42
 
43
+ // if running from ajax.
44
+ if ( !$bp->displayed_user->id )
45
+ $bp->displayed_user->id = $creds['current_userid'];
46
+
47
+ if ( $this->populate_friend_details ) {
48
+ if ( $this->friend_user_id == $bp->displayed_user->id ) {
49
  $this->friend = new BP_Core_User( $this->initiator_user_id );
50
  } else {
51
  $this->friend = new BP_Core_User( $this->friend_user_id );
64
 
65
  do_action_ref_array( 'friends_friendship_before_save', array( &$this ) );
66
 
67
+ if ( $this->id ) {
68
+ // Update
69
  $result = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET initiator_user_id = %d, friend_user_id = %d, is_confirmed = %d, is_limited = %d, date_created = %s ) WHERE id = %d", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created, $this->id ) );
 
 
70
  } else {
71
+ // Save
72
  $result = $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->friends->table_name} ( initiator_user_id, friend_user_id, is_confirmed, is_limited, date_created ) VALUES ( %d, %d, %d, %d, %s )", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created ) );
73
  $this->id = $wpdb->insert_id;
74
  }
84
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE id = %d", $this->id ) );
85
  }
86
 
87
+ /* Static Functions */
88
 
89
  function get_friend_user_ids( $user_id, $friend_requests_only = false, $assoc_arr = false ) {
90
  global $wpdb, $bp;
91
 
92
+ if ( $friend_requests_only ) {
93
  $oc_sql = $wpdb->prepare( "AND is_confirmed = 0" );
94
  $friend_sql = $wpdb->prepare ( " WHERE friend_user_id = %d", $user_id );
95
  } else {
101
  $fids = array();
102
 
103
  for ( $i = 0, $count = count( $friends ); $i < $count; ++$i ) {
104
+ if ( $assoc_arr )
105
  $fids[] = array( 'user_id' => ( $friends[$i]->friend_user_id == $user_id ) ? $friends[$i]->initiator_user_id : $friends[$i]->friend_user_id );
106
+ else
107
  $fids[] = ( $friends[$i]->friend_user_id == $user_id ) ? $friends[$i]->initiator_user_id : $friends[$i]->friend_user_id;
 
108
  }
109
 
110
  return $fids;
125
  function total_friend_count( $user_id = 0 ) {
126
  global $wpdb, $bp;
127
 
128
+ if ( !$user_id )
129
+ $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
130
 
131
  /* This is stored in 'total_friend_count' usermeta.
132
  This function will recalculate, update and return. */
134
  $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d OR friend_user_id = %d) AND is_confirmed = 1", $user_id, $user_id ) );
135
 
136
  // Do not update meta if user has never had friends
137
+ if ( !$count && !bp_get_user_meta( $user_id, 'total_friend_count', true ) )
138
  return 0;
139
 
140
+ bp_update_user_meta( $user_id, 'total_friend_count', (int)$count );
141
+ return (int)$count;
142
  }
143
 
144
  function search_friends( $filter, $user_id, $limit = null, $page = null ) {
146
 
147
  // TODO: Optimize this function.
148
 
149
+ if ( !$user_id )
150
+ $user_id = $bp->loggedin_user->id;
151
 
152
  $filter = like_escape( $wpdb->escape( $filter ) );
153
 
154
+ if ( $limit && $page )
155
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
156
 
157
  if ( !$friend_ids = BP_Friends_Friendship::get_friend_user_ids( $user_id ) )
160
  // Get all the user ids for the current user's friends.
161
  $fids = implode( ',', $friend_ids );
162
 
163
+ if ( empty($fids) )
164
  return false;
165
 
166
  // filter the user_ids based on the search criteria.
172
  $total_sql = "SELECT COUNT(DISTINCT user_id) FROM {$wpdb->usermeta} WHERE user_id IN ($fids) AND meta_key = 'nickname' AND meta_value LIKE '$filter%%'";
173
  }
174
 
175
+ $filtered_friend_ids = $wpdb->get_col($sql);
176
+ $total_friend_ids = $wpdb->get_var($total_sql);
177
 
178
+ if ( !$filtered_friend_ids )
179
  return false;
180
 
181
+ return array( 'friends' => $filtered_friend_ids, 'total' => (int)$total_friend_ids );
182
  }
183
 
184
  function check_is_friend( $loggedin_userid, $possible_friend_userid ) {
185
  global $wpdb, $bp;
186
 
187
+ if ( !$loggedin_userid || !$possible_friend_userid )
188
  return false;
189
 
190
  $result = $wpdb->get_results( $wpdb->prepare( "SELECT id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id = %d) OR (initiator_user_id = %d AND friend_user_id = %d)", $loggedin_userid, $possible_friend_userid, $possible_friend_userid, $loggedin_userid ) );
191
 
192
+ if ( $result ) {
193
+ if ( 0 == (int)$result[0]->is_confirmed ) {
194
  return 'pending';
195
  } else {
196
  return 'is_friend';
201
  }
202
 
203
  function get_bulk_last_active( $user_ids ) {
204
+ global $wpdb, $bp;
205
 
206
  return $wpdb->get_results( $wpdb->prepare( "SELECT meta_value as last_activity, user_id FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} ) ORDER BY meta_value DESC", bp_get_user_meta_key( 'last_activity' ) ) );
207
  }
209
  function accept($friendship_id) {
210
  global $wpdb, $bp;
211
 
212
+ return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET is_confirmed = 1, date_created = %s WHERE id = %d AND friend_user_id = %d", bp_core_current_time(), $friendship_id, $bp->loggedin_user->id ) );
 
 
 
 
 
 
213
  }
214
 
215
  function reject($friendship_id) {
216
  global $wpdb, $bp;
217
 
218
+ return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE id = %d AND friend_user_id = %d", $friendship_id, $bp->loggedin_user->id ) );
219
  }
220
 
221
  function search_users( $filter, $user_id, $limit = null, $page = null ) {
222
+ global $wpdb, $bp;
223
 
224
  $filter = like_escape( $wpdb->escape( $filter ) );
225
 
226
  $usermeta_table = $wpdb->base_prefix . 'usermeta';
227
+ $users_table = $wpdb->base_prefix . 'users';
228
 
229
+ if ( $limit && $page )
230
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * intval( $limit ) ), intval( $limit ) );
231
 
232
  // filter the user_ids based on the search criteria.
238
 
239
  $filtered_fids = $wpdb->get_col($sql);
240
 
241
+ if ( !$filtered_fids )
242
  return false;
243
 
244
  return $filtered_fids;
250
  $filter = like_escape( $wpdb->escape( $filter ) );
251
 
252
  $usermeta_table = $wpdb->prefix . 'usermeta';
253
+ $users_table = $wpdb->base_prefix . 'users';
254
 
255
  // filter the user_ids based on the search criteria.
256
  if ( bp_is_active( 'xprofile' ) ) {
261
 
262
  $user_count = $wpdb->get_col($sql);
263
 
264
+ if ( !$user_count )
265
  return false;
266
 
267
  return $user_count[0];
279
  function get_random_friends( $user_id, $total_friends = 5 ) {
280
  global $wpdb, $bp;
281
 
282
+ $sql = $wpdb->prepare( "SELECT friend_user_id, initiator_user_id FROM {$bp->friends->table_name} WHERE (friend_user_id = %d || initiator_user_id = %d) && is_confirmed = 1 ORDER BY rand() LIMIT %d", $user_id, $user_id, $total_friends );
283
+ $results = $wpdb->get_results($sql);
 
284
 
285
  for ( $i = 0, $count = count( $results ); $i < $count; ++$i ) {
286
  $fids[] = ( $results[$i]->friend_user_id == $user_id ) ? $results[$i]->initiator_user_id : $results[$i]->friend_user_id;
288
 
289
  // remove duplicates
290
  if ( count( $fids ) > 0 )
291
+ return array_flip(array_flip($fids));
292
  else
293
  return false;
294
  }
339
  $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE component_name = 'friends' AND ( component_action = 'friendship_request' OR component_action = 'friendship_accepted' ) AND item_id = %d", $user_id ) );
340
 
341
  // Loop through friend_ids and update their counts
342
+ foreach ( (array)$friend_ids as $friend_id ) {
343
  BP_Friends_Friendship::total_friend_count( $friend_id );
344
  }
345
  }
346
  }
347
+ ?>
 
bp-friends/bp-friends-functions.php CHANGED
@@ -1,15 +1,11 @@
1
  <?php
2
-
3
- /**
4
- * BuddyPress Friends Functions
5
  *
6
- * Functions are where all the magic happens in BuddyPress. They will
7
  * handle the actual saving or manipulation of information. Usually they will
8
  * hand off to a database class for data access, then return
9
  * true or false on success or failure.
10
- *
11
- * @package BuddyPress
12
- * @subpackage FriendsFunctions
13
  */
14
 
15
  // Exit if accessed directly
@@ -20,7 +16,7 @@ function friends_add_friend( $initiator_userid, $friend_userid, $force_accept =
20
 
21
  $friendship = new BP_Friends_Friendship;
22
 
23
- if ( (int) $friendship->is_confirmed )
24
  return true;
25
 
26
  $friendship->initiator_user_id = $initiator_userid;
@@ -43,9 +39,6 @@ function friends_add_friend( $initiator_userid, $friend_userid, $force_accept =
43
 
44
  do_action( 'friends_friendship_requested', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id );
45
  } else {
46
- // Update friend totals
47
- friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id, 'add' );
48
-
49
  do_action( 'friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id );
50
  }
51
 
@@ -56,6 +49,7 @@ function friends_add_friend( $initiator_userid, $friend_userid, $force_accept =
56
  }
57
 
58
  function friends_remove_friend( $initiator_userid, $friend_userid ) {
 
59
 
60
  $friendship_id = BP_Friends_Friendship::get_friendship_id( $initiator_userid, $friend_userid );
61
  $friendship = new BP_Friends_Friendship( $friendship_id );
@@ -63,7 +57,7 @@ function friends_remove_friend( $initiator_userid, $friend_userid ) {
63
  do_action( 'friends_before_friendship_delete', $friendship_id, $initiator_userid, $friend_userid );
64
 
65
  // Remove the activity stream item for the user who canceled the friendship
66
- friends_delete_activity( array( 'item_id' => $friendship_id, 'type' => 'friendship_accepted', 'user_id' => bp_displayed_user_id() ) );
67
 
68
  do_action( 'friends_friendship_deleted', $friendship_id, $initiator_userid, $friend_userid );
69
 
@@ -139,24 +133,8 @@ function friends_reject_friendship( $friendship_id ) {
139
  return false;
140
  }
141
 
142
- function friends_withdraw_friendship( $initiator_userid, $friend_userid ) {
143
- global $bp;
144
-
145
- $friendship_id = BP_Friends_Friendship::get_friendship_id( $initiator_userid, $friend_userid );
146
- $friendship = new BP_Friends_Friendship( $friendship_id, true, false );
147
-
148
- if ( !$friendship->is_confirmed && BP_Friends_Friendship::withdraw( $friendship_id ) ) {
149
- // Remove the friend request notice
150
- bp_core_delete_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_request' );
151
-
152
- do_action_ref_array( 'friends_friendship_whithdrawn', array( $friendship_id, &$friendship ) );
153
- return true;
154
- }
155
-
156
- return false;
157
- }
158
-
159
  function friends_check_friendship( $user_id, $possible_friend_id ) {
 
160
 
161
  if ( 'is_friend' == BP_Friends_Friendship::check_is_friend( $user_id, $possible_friend_id ) )
162
  return true;
@@ -170,12 +148,16 @@ function friends_check_friendship_status( $user_id, $possible_friend_id ) {
170
  }
171
 
172
  function friends_get_total_friend_count( $user_id = 0 ) {
173
- if ( empty( $user_id ) )
174
- $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
 
 
175
 
176
- $count = bp_get_user_meta( $user_id, 'total_friend_count', true );
177
- if ( empty( $count ) )
178
- $count = 0;
 
 
179
 
180
  return apply_filters( 'friends_get_total_friend_count', $count );
181
  }
@@ -186,7 +168,7 @@ function friends_check_user_has_friends( $user_id ) {
186
  if ( empty( $friend_count ) )
187
  return false;
188
 
189
- if ( !(int) $friend_count )
190
  return false;
191
 
192
  return true;
@@ -196,7 +178,7 @@ function friends_get_friendship_id( $initiator_user_id, $friend_user_id ) {
196
  return BP_Friends_Friendship::get_friendship_id( $initiator_user_id, $friend_user_id );
197
  }
198
 
199
- function friends_get_friend_user_ids( $user_id, $friend_requests_only = false, $assoc_arr = false ) {
200
  return BP_Friends_Friendship::get_friend_user_ids( $user_id, $friend_requests_only, $assoc_arr );
201
  }
202
 
@@ -307,13 +289,13 @@ function friends_get_friend_count_for_user( $user_id ) {
307
  }
308
 
309
  function friends_search_users( $search_terms, $user_id, $pag_num = 0, $pag_page = 0 ) {
 
310
 
311
  $user_ids = BP_Friends_Friendship::search_users( $search_terms, $user_id, $pag_num, $pag_page );
312
 
313
- if ( empty( $user_ids ) )
314
  return false;
315
 
316
- $users = array();
317
  for ( $i = 0, $count = count( $user_ids ); $i < $count; ++$i )
318
  $users[] = new BP_Core_User( $user_ids[$i] );
319
 
@@ -326,6 +308,7 @@ function friends_is_friendship_confirmed( $friendship_id ) {
326
  }
327
 
328
  function friends_update_friend_totals( $initiator_user_id, $friend_user_id, $status = 'add' ) {
 
329
 
330
  if ( 'add' == $status ) {
331
  bp_update_user_meta( $initiator_user_id, 'total_friend_count', (int)bp_get_user_meta( $initiator_user_id, 'total_friend_count', true ) + 1 );
@@ -341,7 +324,7 @@ function friends_remove_data( $user_id ) {
341
 
342
  do_action( 'friends_before_remove_data', $user_id );
343
 
344
- BP_Friends_Friendship::delete_all_for_user( $user_id );
345
 
346
  // Remove usermeta
347
  bp_delete_user_meta( $user_id, 'total_friend_count' );
@@ -355,4 +338,4 @@ add_action( 'wpmu_delete_user', 'friends_remove_data' );
355
  add_action( 'delete_user', 'friends_remove_data' );
356
  add_action( 'bp_make_spam_user', 'friends_remove_data' );
357
 
358
- ?>
1
  <?php
2
+ /********************************************************************************
3
+ * Business Functions
 
4
  *
5
+ * Business functions are where all the magic happens in BuddyPress. They will
6
  * handle the actual saving or manipulation of information. Usually they will
7
  * hand off to a database class for data access, then return
8
  * true or false on success or failure.
 
 
 
9
  */
10
 
11
  // Exit if accessed directly
16
 
17
  $friendship = new BP_Friends_Friendship;
18
 
19
+ if ( (int)$friendship->is_confirmed )
20
  return true;
21
 
22
  $friendship->initiator_user_id = $initiator_userid;
39
 
40
  do_action( 'friends_friendship_requested', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id );
41
  } else {
 
 
 
42
  do_action( 'friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id );
43
  }
44
 
49
  }
50
 
51
  function friends_remove_friend( $initiator_userid, $friend_userid ) {
52
+ global $bp;
53
 
54
  $friendship_id = BP_Friends_Friendship::get_friendship_id( $initiator_userid, $friend_userid );
55
  $friendship = new BP_Friends_Friendship( $friendship_id );
57
  do_action( 'friends_before_friendship_delete', $friendship_id, $initiator_userid, $friend_userid );
58
 
59
  // Remove the activity stream item for the user who canceled the friendship
60
+ friends_delete_activity( array( 'item_id' => $friendship_id, 'type' => 'friendship_accepted', 'user_id' => $bp->displayed_user->id ) );
61
 
62
  do_action( 'friends_friendship_deleted', $friendship_id, $initiator_userid, $friend_userid );
63
 
133
  return false;
134
  }
135
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  function friends_check_friendship( $user_id, $possible_friend_id ) {
137
+ global $bp;
138
 
139
  if ( 'is_friend' == BP_Friends_Friendship::check_is_friend( $user_id, $possible_friend_id ) )
140
  return true;
148
  }
149
 
150
  function friends_get_total_friend_count( $user_id = 0 ) {
151
+ global $bp;
152
+
153
+ if ( !$user_id )
154
+ $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
155
 
156
+ if ( !$count = wp_cache_get( 'bp_total_friend_count_' . $user_id, 'bp' ) ) {
157
+ $count = bp_get_user_meta( $user_id, 'total_friend_count', true );
158
+ if ( empty( $count ) ) $count = 0;
159
+ wp_cache_set( 'bp_total_friend_count_' . $user_id, $count, 'bp' );
160
+ }
161
 
162
  return apply_filters( 'friends_get_total_friend_count', $count );
163
  }
168
  if ( empty( $friend_count ) )
169
  return false;
170
 
171
+ if ( !(int)$friend_count )
172
  return false;
173
 
174
  return true;
178
  return BP_Friends_Friendship::get_friendship_id( $initiator_user_id, $friend_user_id );
179
  }
180
 
181
+ function friends_get_friend_user_ids( $user_id, $friend_requests_only = false, $assoc_arr = false, $filter = false ) {
182
  return BP_Friends_Friendship::get_friend_user_ids( $user_id, $friend_requests_only, $assoc_arr );
183
  }
184
 
289
  }
290
 
291
  function friends_search_users( $search_terms, $user_id, $pag_num = 0, $pag_page = 0 ) {
292
+ global $bp;
293
 
294
  $user_ids = BP_Friends_Friendship::search_users( $search_terms, $user_id, $pag_num, $pag_page );
295
 
296
+ if ( !$user_ids )
297
  return false;
298
 
 
299
  for ( $i = 0, $count = count( $user_ids ); $i < $count; ++$i )
300
  $users[] = new BP_Core_User( $user_ids[$i] );
301
 
308
  }
309
 
310
  function friends_update_friend_totals( $initiator_user_id, $friend_user_id, $status = 'add' ) {
311
+ global $bp;
312
 
313
  if ( 'add' == $status ) {
314
  bp_update_user_meta( $initiator_user_id, 'total_friend_count', (int)bp_get_user_meta( $initiator_user_id, 'total_friend_count', true ) + 1 );
324
 
325
  do_action( 'friends_before_remove_data', $user_id );
326
 
327
+ BP_Friends_Friendship::delete_all_for_user($user_id);
328
 
329
  // Remove usermeta
330
  bp_delete_user_meta( $user_id, 'total_friend_count' );
338
  add_action( 'delete_user', 'friends_remove_data' );
339
  add_action( 'bp_make_spam_user', 'friends_remove_data' );
340
 
341
+ ?>
bp-friends/bp-friends-loader.php CHANGED
@@ -16,7 +16,7 @@ class BP_Friends_Component extends BP_Component {
16
  /**
17
  * Start the friends component creation process
18
  *
19
- * @since BuddyPress (1.5)
20
  */
21
  function __construct() {
22
  parent::start(
@@ -51,8 +51,8 @@ class BP_Friends_Component extends BP_Component {
51
  * The BP_FRIENDS_SLUG constant is deprecated, and only used here for
52
  * backwards compatibility.
53
  *
54
- * @since BuddyPress (1.5)
55
- * @global BuddyPress $bp The one true BuddyPress instance
56
  */
57
  function setup_globals() {
58
  global $bp;
@@ -72,6 +72,7 @@ class BP_Friends_Component extends BP_Component {
72
  // All globals for the friends component.
73
  // Note that global_tables is included in this array.
74
  $globals = array(
 
75
  'slug' => BP_FRIENDS_SLUG,
76
  'has_directory' => false,
77
  'search_string' => __( 'Search Friends...', 'buddypress' ),
@@ -85,13 +86,11 @@ class BP_Friends_Component extends BP_Component {
85
  /**
86
  * Setup BuddyBar navigation
87
  *
88
- * @global BuddyPress $bp The one true BuddyPress instance
89
  */
90
  function setup_nav() {
91
  global $bp;
92
 
93
- $sub_nav = array();
94
-
95
  // Add 'Friends' to the main navigation
96
  $main_nav = array(
97
  'name' => sprintf( __( 'Friends <span>%d</span>', 'buddypress' ), friends_get_total_friend_count() ),
@@ -102,7 +101,7 @@ class BP_Friends_Component extends BP_Component {
102
  'item_css_id' => $bp->friends->id
103
  );
104
 
105
- $friends_link = trailingslashit( bp_loggedin_user_domain() . bp_get_friends_slug() );
106
 
107
  // Add the subnav items to the friends nav item
108
  $sub_nav[] = array(
@@ -129,9 +128,9 @@ class BP_Friends_Component extends BP_Component {
129
  }
130
 
131
  /**
132
- * Set up the Toolbar
133
  *
134
- * @global BuddyPress $bp The one true BuddyPress instance
135
  */
136
  function setup_admin_bar() {
137
  global $bp;
@@ -143,14 +142,13 @@ class BP_Friends_Component extends BP_Component {
143
  if ( is_user_logged_in() ) {
144
 
145
  // Setup the logged in user variables
146
- $user_domain = bp_loggedin_user_domain();
147
  $friends_link = trailingslashit( $user_domain . $this->slug );
148
 
149
  // Pending friend requests
150
- $count = count( friends_get_friendship_request_user_ids( bp_loggedin_user_id() ) );
151
- if ( !empty( $count ) ) {
152
- $title = sprintf( __( 'Friends <span class="count">%s</span>', 'buddypress' ), number_format_i18n( $count ) );
153
- $pending = sprintf( __( 'Pending Requests <span class="count">%s</span>', 'buddypress' ), number_format_i18n( $count ) );
154
  } else {
155
  $title = __( 'Friends', 'buddypress' );
156
  $pending = __( 'No Pending Requests', 'buddypress' );
@@ -187,7 +185,7 @@ class BP_Friends_Component extends BP_Component {
187
  /**
188
  * Sets up the title for pages and <title>
189
  *
190
- * @global BuddyPress $bp The one true BuddyPress instance
191
  */
192
  function setup_title() {
193
  global $bp;
@@ -198,22 +196,17 @@ class BP_Friends_Component extends BP_Component {
198
  $bp->bp_options_title = __( 'Friendships', 'buddypress' );
199
  } else {
200
  $bp->bp_options_avatar = bp_core_fetch_avatar( array(
201
- 'item_id' => bp_displayed_user_id(),
202
- 'type' => 'thumb',
203
- 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() )
204
  ) );
205
- $bp->bp_options_title = bp_get_displayed_user_fullname();
206
  }
207
  }
208
 
209
  parent::setup_title();
210
  }
211
  }
212
-
213
- function bp_setup_friends() {
214
- global $bp;
215
- $bp->friends = new BP_Friends_Component();
216
- }
217
- add_action( 'bp_setup_components', 'bp_setup_friends', 6 );
218
 
219
  ?>
16
  /**
17
  * Start the friends component creation process
18
  *
19
+ * @since 1.5
20
  */
21
  function __construct() {
22
  parent::start(
51
  * The BP_FRIENDS_SLUG constant is deprecated, and only used here for
52
  * backwards compatibility.
53
  *
54
+ * @since 1.5
55
+ * @global obj $bp
56
  */
57
  function setup_globals() {
58
  global $bp;
72
  // All globals for the friends component.
73
  // Note that global_tables is included in this array.
74
  $globals = array(
75
+ 'path' => BP_PLUGIN_DIR,
76
  'slug' => BP_FRIENDS_SLUG,
77
  'has_directory' => false,
78
  'search_string' => __( 'Search Friends...', 'buddypress' ),
86
  /**
87
  * Setup BuddyBar navigation
88
  *
89
+ * @global obj $bp
90
  */
91
  function setup_nav() {
92
  global $bp;
93
 
 
 
94
  // Add 'Friends' to the main navigation
95
  $main_nav = array(
96
  'name' => sprintf( __( 'Friends <span>%d</span>', 'buddypress' ), friends_get_total_friend_count() ),
101
  'item_css_id' => $bp->friends->id
102
  );
103
 
104
+ $friends_link = trailingslashit( $bp->loggedin_user->domain . bp_get_friends_slug() );
105
 
106
  // Add the subnav items to the friends nav item
107
  $sub_nav[] = array(
128
  }
129
 
130
  /**
131
+ * Set up the admin bar
132
  *
133
+ * @global obj $bp
134
  */
135
  function setup_admin_bar() {
136
  global $bp;
142
  if ( is_user_logged_in() ) {
143
 
144
  // Setup the logged in user variables
145
+ $user_domain = $bp->loggedin_user->domain;
146
  $friends_link = trailingslashit( $user_domain . $this->slug );
147
 
148
  // Pending friend requests
149
+ if ( $count = count( friends_get_friendship_request_user_ids( $bp->loggedin_user->id ) ) ) {
150
+ $title = sprintf( __( 'Friends <span class="count">%s</span>', 'buddypress' ), $count );
151
+ $pending = sprintf( __( 'Pending Requests <span class="count">%s</span>', 'buddypress' ), $count );
 
152
  } else {
153
  $title = __( 'Friends', 'buddypress' );
154
  $pending = __( 'No Pending Requests', 'buddypress' );
185
  /**
186
  * Sets up the title for pages and <title>
187
  *
188
+ * @global obj $bp
189
  */
190
  function setup_title() {
191
  global $bp;
196
  $bp->bp_options_title = __( 'Friendships', 'buddypress' );
197
  } else {
198
  $bp->bp_options_avatar = bp_core_fetch_avatar( array(
199
+ 'item_id' => $bp->displayed_user->id,
200
+ 'type' => 'thumb'
 
201
  ) );
202
+ $bp->bp_options_title = $bp->displayed_user->fullname;
203
  }
204
  }
205
 
206
  parent::setup_title();
207
  }
208
  }
209
+ // Create the friends component
210
+ $bp->friends = new BP_Friends_Component();
 
 
 
 
211
 
212
  ?>
bp-friends/bp-friends-notifications.php CHANGED
@@ -1,30 +1,22 @@
1
  <?php
2
-
3
- /**
4
- * BuddyPress Friends Activity Functions
5
- *
6
- * These functions handle the recording, deleting and formatting of activity
7
- * for the user and for this specific component.
8
- *
9
- * @package BuddyPress
10
- * @subpackage FriendsActivity
11
- */
12
-
13
  // Exit if accessed directly
14
  if ( !defined( 'ABSPATH' ) ) exit;
15
 
16
  function friends_notification_new_request( $friendship_id, $initiator_id, $friend_id ) {
 
17
 
18
  $initiator_name = bp_core_get_user_displayname( $initiator_id );
19
 
20
- if ( 'no' == bp_get_user_meta( (int) $friend_id, 'notification_friends_friendship_request', true ) )
21
  return false;
22
 
23
- $ud = get_userdata( $friend_id );
 
 
24
  $all_requests_link = bp_core_get_user_domain( $friend_id ) . bp_get_friends_slug() . '/requests/';
25
- $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
26
- $settings_link = trailingslashit( bp_core_get_user_domain( $friend_id ) . $settings_slug . '/notifications' );
27
- $initiator_link = bp_core_get_user_domain( $initiator_id );
28
 
29
  // Set up and send the message
30
  $to = $ud->user_email;
@@ -54,16 +46,20 @@ To view %3$s\'s profile: %4$s
54
  }
55
 
56
  function friends_notification_accepted_request( $friendship_id, $initiator_id, $friend_id ) {
 
 
 
57
 
58
  $friend_name = bp_core_get_user_displayname( $friend_id );
59
 
60
- if ( 'no' == bp_get_user_meta( (int) $initiator_id, 'notification_friends_friendship_accepted', true ) )
61
  return false;
62
 
63
- $ud = get_userdata( $initiator_id );
 
64
  $friend_link = bp_core_get_user_domain( $friend_id );
65
  $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
66
- $settings_link = trailingslashit( bp_core_get_user_domain( $initiator_id ) . $settings_slug . '/notifications' );
67
 
68
  // Set up and send the message
69
  $to = $ud->user_email;
@@ -90,4 +86,4 @@ To view %2$s\'s profile: %3$s
90
  do_action( 'bp_friends_sent_accepted_email', $initiator_id, $subject, $message, $friendship_id, $friend_id );
91
  }
92
 
93
- ?>
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
5
  function friends_notification_new_request( $friendship_id, $initiator_id, $friend_id ) {
6
+ global $bp;
7
 
8
  $initiator_name = bp_core_get_user_displayname( $initiator_id );
9
 
10
+ if ( 'no' == bp_get_user_meta( (int)$friend_id, 'notification_friends_friendship_request', true ) )
11
  return false;
12
 
13
+ $ud = get_userdata( $friend_id );
14
+ $initiator_ud = get_userdata( $initiator_id );
15
+
16
  $all_requests_link = bp_core_get_user_domain( $friend_id ) . bp_get_friends_slug() . '/requests/';
17
+ $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
18
+ $settings_link = bp_core_get_user_domain( $friend_id ) . $settings_slug . '/notifications';
19
+ $initiator_link = bp_core_get_user_domain( $initiator_id );
20
 
21
  // Set up and send the message
22
  $to = $ud->user_email;
46
  }
47
 
48
  function friends_notification_accepted_request( $friendship_id, $initiator_id, $friend_id ) {
49
+ global $bp;
50
+
51
+ $friendship = new BP_Friends_Friendship( $friendship_id, false, false );
52
 
53
  $friend_name = bp_core_get_user_displayname( $friend_id );
54
 
55
+ if ( 'no' == bp_get_user_meta( (int)$initiator_id, 'notification_friends_friendship_accepted', true ) )
56
  return false;
57
 
58
+ $ud = get_userdata( $initiator_id );
59
+
60
  $friend_link = bp_core_get_user_domain( $friend_id );
61
  $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
62
+ $settings_link = bp_core_get_user_domain( $initiator_id ) . $settings_slug . '/notifications';
63
 
64
  // Set up and send the message
65
  $to = $ud->user_email;
86
  do_action( 'bp_friends_sent_accepted_email', $initiator_id, $subject, $message, $friendship_id, $friend_id );
87
  }
88
 
89
+ ?>
bp-friends/bp-friends-screens.php CHANGED
@@ -1,14 +1,8 @@
1
  <?php
2
-
3
  /**
4
- * BuddyPress Friends Screen Functions
5
- *
6
  * Screen functions are the controllers of BuddyPress. They will execute when their
7
  * specific URL is caught. They will first save or manipulate data using business
8
  * functions, then pass on the user to a template file.
9
- *
10
- * @package BuddyPress
11
- * @subpackage FriendsScreens
12
  */
13
 
14
  // Exit if accessed directly
@@ -18,7 +12,7 @@ function friends_screen_my_friends() {
18
  global $bp;
19
 
20
  // Delete any friendship acceptance notifications for the user when viewing a profile
21
- bp_core_delete_notifications_by_type( bp_loggedin_user_id(), $bp->friends->id, 'friendship_accepted' );
22
 
23
  do_action( 'friends_screen_my_friends' );
24
 
@@ -35,7 +29,7 @@ function friends_screen_requests() {
35
  else
36
  bp_core_add_message( __( 'Friendship could not be accepted', 'buddypress' ), 'error' );
37
 
38
- bp_core_redirect( trailingslashit( bp_loggedin_user_domain() . bp_current_component() . '/' . bp_current_action() ) );
39
 
40
  } elseif ( bp_is_action_variable( 'reject', 0 ) && is_numeric( bp_action_variable( 1 ) ) ) {
41
  // Check the nonce
@@ -46,18 +40,7 @@ function friends_screen_requests() {
46
  else
47
  bp_core_add_message( __( 'Friendship could not be rejected', 'buddypress' ), 'error' );
48
 
49
- bp_core_redirect( trailingslashit( bp_loggedin_user_domain() . bp_current_component() . '/' . bp_current_action() ) );
50
-
51
- } elseif ( bp_is_action_variable( 'cancel', 0 ) && is_numeric( bp_action_variable( 1 ) ) ) {
52
- // Check the nonce
53
- check_admin_referer( 'friends_withdraw_friendship' );
54
-
55
- if ( friends_withdraw_friendship( bp_loggedin_user_id(), bp_action_variable( 1 ) ) )
56
- bp_core_add_message( __( 'Friendship request withdrawn', 'buddypress' ) );
57
- else
58
- bp_core_add_message( __( 'Friendship request could not be withdrawn', 'buddypress' ), 'error' );
59
-
60
- bp_core_redirect( trailingslashit( bp_loggedin_user_domain() . bp_current_component() . '/' . bp_current_action() ) );
61
  }
62
 
63
  do_action( 'friends_screen_requests' );
@@ -69,12 +52,14 @@ function friends_screen_requests() {
69
  }
70
 
71
  function friends_screen_notification_settings() {
 
72
 
73
- if ( !$send_requests = bp_get_user_meta( bp_displayed_user_id(), 'notification_friends_friendship_request', true ) )
74
  $send_requests = 'yes';
75
 
76
- if ( !$accept_requests = bp_get_user_meta( bp_displayed_user_id(), 'notification_friends_friendship_accepted', true ) )
77
- $accept_requests = 'yes'; ?>
 
78
 
79
  <table class="notification-settings" id="friends-notification-settings">
80
  <thead>
@@ -109,4 +94,4 @@ function friends_screen_notification_settings() {
109
  }
110
  add_action( 'bp_notification_settings', 'friends_screen_notification_settings' );
111
 
112
- ?>
1
  <?php
 
2
  /**
 
 
3
  * Screen functions are the controllers of BuddyPress. They will execute when their
4
  * specific URL is caught. They will first save or manipulate data using business
5
  * functions, then pass on the user to a template file.
 
 
 
6
  */
7
 
8
  // Exit if accessed directly
12
  global $bp;
13
 
14
  // Delete any friendship acceptance notifications for the user when viewing a profile
15
+ bp_core_delete_notifications_by_type( $bp->loggedin_user->id, $bp->friends->id, 'friendship_accepted' );
16
 
17
  do_action( 'friends_screen_my_friends' );
18
 
29
  else
30
  bp_core_add_message( __( 'Friendship could not be accepted', 'buddypress' ), 'error' );
31
 
32
+ bp_core_redirect( bp_loggedin_user_domain() . bp_current_component() . '/' . bp_current_action() );
33
 
34
  } elseif ( bp_is_action_variable( 'reject', 0 ) && is_numeric( bp_action_variable( 1 ) ) ) {
35
  // Check the nonce
40
  else
41
  bp_core_add_message( __( 'Friendship could not be rejected', 'buddypress' ), 'error' );
42
 
43
+ bp_core_redirect( bp_loggedin_user_domain() . bp_current_component() . '/' . bp_current_action() );
 
 
 
 
 
 
 
 
 
 
 
44
  }
45
 
46
  do_action( 'friends_screen_requests' );
52
  }
53
 
54
  function friends_screen_notification_settings() {
55
+ global $bp;
56
 
57
+ if ( !$send_requests = bp_get_user_meta( $bp->displayed_user->id, 'notification_friends_friendship_request', true ) )
58
  $send_requests = 'yes';
59
 
60
+ if ( !$accept_requests = bp_get_user_meta( $bp->displayed_user->id, 'notification_friends_friendship_accepted', true ) )
61
+ $accept_requests = 'yes';
62
+ ?>
63
 
64
  <table class="notification-settings" id="friends-notification-settings">
65
  <thead>
94
  }
95
  add_action( 'bp_notification_settings', 'friends_screen_notification_settings' );
96
 
97
+ ?>
bp-friends/bp-friends-template.php CHANGED
@@ -1,12 +1,4 @@
1
  <?php
2
-
3
- /**
4
- * BuddyPress Friends Template Functions
5
- *
6
- * @package BuddyPress
7
- * @subpackage FriendsTemplate
8
- */
9
-
10
  // Exit if accessed directly
11
  if ( !defined( 'ABSPATH' ) ) exit;
12
 
@@ -15,7 +7,7 @@ if ( !defined( 'ABSPATH' ) ) exit;
15
  *
16
  * @package BuddyPress
17
  * @subpackage Friends Template
18
- * @since BuddyPress (1.5)
19
  *
20
  * @uses bp_get_friends_slug()
21
  */
@@ -27,7 +19,7 @@ function bp_friends_slug() {
27
  *
28
  * @package BuddyPress
29
  * @subpackage Friends Template
30
- * @since BuddyPress (1.5)
31
  */
32
  function bp_get_friends_slug() {
33
  global $bp;
@@ -39,7 +31,7 @@ function bp_friends_slug() {
39
  *
40
  * @package BuddyPress
41
  * @subpackage Friends Template
42
- * @since BuddyPress (1.5)
43
  *
44
  * @uses bp_get_friends_root_slug()
45
  */
@@ -51,22 +43,62 @@ function bp_friends_root_slug() {
51
  *
52
  * @package BuddyPress
53
  * @subpackage Friends Template
54
- * @since BuddyPress (1.5)
55
  */
56
  function bp_get_friends_root_slug() {
57
  global $bp;
58
  return apply_filters( 'bp_get_friends_root_slug', $bp->friends->root_slug );
59
  }
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  function bp_friends_random_friends() {
 
62
 
63
- if ( !$friend_ids = wp_cache_get( 'friends_friend_ids_' . bp_displayed_user_id(), 'bp' ) ) {
64
- $friend_ids = BP_Friends_Friendship::get_random_friends( bp_displayed_user_id() );
65
- wp_cache_set( 'friends_friend_ids_' . bp_displayed_user_id(), $friend_ids, 'bp' );
66
  } ?>
67
 
68
  <div class="info-group">
69
- <h4><?php bp_word_or_name( __( "My Friends", 'buddypress' ), __( "%s's Friends", 'buddypress' ) ) ?> (<?php echo BP_Friends_Friendship::total_friend_count( bp_displayed_user_id() ) ?>) <span><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_friends_slug() ) ?>"><?php _e('See All', 'buddypress') ?></a></span></h4>
70
 
71
  <?php if ( $friend_ids ) { ?>
72
 
@@ -90,10 +122,8 @@ function bp_friends_random_friends() {
90
  </div>
91
 
92
  <?php } ?>
93
-
94
  <div class="clear"></div>
95
  </div>
96
-
97
  <?php
98
  }
99
 
@@ -107,6 +137,7 @@ function bp_friends_random_friends() {
107
  * @param int $total_members The number of members to retrieve
108
  */
109
  function bp_friends_random_members( $total_members = 5 ) {
 
110
 
111
  if ( !$user_ids = wp_cache_get( 'friends_random_users', 'bp' ) ) {
112
  $user_ids = BP_Core_User::get_users( 'random', $total_members );
@@ -164,9 +195,10 @@ function bp_friends_random_members( $total_members = 5 ) {
164
  }
165
 
166
  function bp_friend_search_form() {
 
167
 
168
- $action = bp_displayed_user_domain() . bp_get_friends_slug() . '/my-friends/search/';
169
- $label = __( 'Filter Friends', 'buddypress' ); ?>
170
 
171
  <form action="<?php echo $action ?>" id="friend-search-form" method="post">
172
 
@@ -175,7 +207,7 @@ function bp_friend_search_form() {
175
 
176
  <?php wp_nonce_field( 'friends_search', '_wpnonce_friend_search' ) ?>
177
 
178
- <input type="hidden" name="initiator" id="initiator" value="<?php echo esc_attr( bp_displayed_user_id() ) ?>" />
179
 
180
  </form>
181
 
@@ -195,6 +227,8 @@ function bp_member_add_friend_button() {
195
  add_action( 'bp_directory_members_actions', 'bp_member_add_friend_button' );
196
 
197
  function bp_member_total_friend_count() {
 
 
198
  echo bp_get_member_total_friend_count();
199
  }
200
  function bp_get_member_total_friend_count() {
@@ -222,19 +256,20 @@ function bp_potential_friend_id( $user_id = 0 ) {
222
  *
223
  * Returns the ID of the potential friend
224
  *
 
225
  * @global object $friends_template
226
  * @param int $user_id
227
  * @return int ID of potential friend
228
  */
229
  function bp_get_potential_friend_id( $user_id = 0 ) {
230
- global $friends_template;
231
 
232
  if ( empty( $user_id ) && isset( $friends_template->friendship->friend ) )
233
  $user_id = $friends_template->friendship->friend->id;
234
  else if ( empty( $user_id ) && !isset( $friends_template->friendship->friend ) )
235
- $user_id = bp_displayed_user_id();
236
 
237
- return apply_filters( 'bp_get_potential_friend_id', (int) $user_id );
238
  }
239
 
240
  /**
@@ -242,10 +277,12 @@ function bp_potential_friend_id( $user_id = 0 ) {
242
  *
243
  * Returns - 'is_friend', 'not_friends', 'pending'
244
  *
 
245
  * @param int $potential_friend_id
246
  * @return string
247
  */
248
  function bp_is_friend( $user_id = 0 ) {
 
249
 
250
  if ( !is_user_logged_in() )
251
  return false;
@@ -253,16 +290,17 @@ function bp_is_friend( $user_id = 0 ) {
253
  if ( empty( $user_id ) )
254
  $user_id = bp_get_potential_friend_id( $user_id );
255
 
256
- if ( bp_loggedin_user_id() == $user_id )
257
  return false;
258
 
259
- return apply_filters( 'bp_is_friend', friends_check_friendship_status( bp_loggedin_user_id(), $user_id ), $user_id );
260
  }
261
 
262
  function bp_add_friend_button( $potential_friend_id = 0, $friend_status = false ) {
263
  echo bp_get_add_friend_button( $potential_friend_id, $friend_status );
264
  }
265
  function bp_get_add_friend_button( $potential_friend_id = 0, $friend_status = false ) {
 
266
 
267
  if ( empty( $potential_friend_id ) )
268
  $potential_friend_id = bp_get_potential_friend_id( $potential_friend_id );
@@ -279,14 +317,12 @@ function bp_add_friend_button( $potential_friend_id = 0, $friend_status = false
279
  'component' => 'friends',
280
  'must_be_logged_in' => true,
281
  'block_self' => true,
282
- 'wrapper_class' => 'friendship-button pending_friend',
283
  'wrapper_id' => 'friendship-button-' . $potential_friend_id,
284
- 'link_href' => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . $potential_friend_id . '/', 'friends_withdraw_friendship' ),
285
- 'link_text' => __( 'Cancel Friendship Request', 'buddypress' ),
286
- 'link_title' => __( 'Cancel Friendship Requested', 'buddypress' ),
287
- 'link_id' => 'friend-' . $potential_friend_id,
288
- 'link_rel' => 'remove',
289
- 'link_class' => 'friendship-button pending_friend requested'
290
  );
291
  break;
292
 
@@ -298,7 +334,7 @@ function bp_add_friend_button( $potential_friend_id = 0, $friend_status = false
298
  'block_self' => false,
299
  'wrapper_class' => 'friendship-button is_friend',
300
  'wrapper_id' => 'friendship-button-' . $potential_friend_id,
301
- 'link_href' => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/remove-friend/' . $potential_friend_id . '/', 'friends_remove_friend' ),
302
  'link_text' => __( 'Cancel Friendship', 'buddypress' ),
303
  'link_title' => __( 'Cancel Friendship', 'buddypress' ),
304
  'link_id' => 'friend-' . $potential_friend_id,
@@ -315,7 +351,7 @@ function bp_add_friend_button( $potential_friend_id = 0, $friend_status = false
315
  'block_self' => true,
316
  'wrapper_class' => 'friendship-button not_friends',
317
  'wrapper_id' => 'friendship-button-' . $potential_friend_id,
318
- 'link_href' => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $potential_friend_id . '/', 'friends_add_friend' ),
319
  'link_text' => __( 'Add Friend', 'buddypress' ),
320
  'link_title' => __( 'Add Friend', 'buddypress' ),
321
  'link_id' => 'friend-' . $potential_friend_id,
@@ -330,9 +366,10 @@ function bp_add_friend_button( $potential_friend_id = 0, $friend_status = false
330
  }
331
 
332
  function bp_get_friend_ids( $user_id = 0 ) {
 
333
 
334
- if ( empty( $user_id ) )
335
- $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
336
 
337
  $friend_ids = friends_get_friend_user_ids( $user_id );
338
 
@@ -341,45 +378,21 @@ function bp_get_friend_ids( $user_id = 0 ) {
341
 
342
  return implode( ',', friends_get_friend_user_ids( $user_id ) );
343
  }
 
 
344
 
345
- /**
346
- * Get a user's friendship requests
347
- *
348
- * Note that we return a 0 if no pending requests are found. This is necessary because of the
349
- * structure of the $include parameter in bp_has_members().
350
- *
351
- * @param int $user_id Defaults to displayed user
352
- * @return mixed Returns an array of users if found, or a 0 if none are found
353
- */
354
- function bp_get_friendship_requests( $user_id = 0 ) {
355
- if ( !$user_id ) {
356
- $user_id = bp_displayed_user_id();
357
- }
358
-
359
- if ( !$user_id ) {
360
- return 0;
361
- }
362
-
363
- $requests = friends_get_friendship_request_user_ids( $user_id );
364
-
365
- if ( !empty( $requests ) ) {
366
- $requests = implode( ',', (array) $requests );
367
- } else {
368
- $requests = 0;
369
- }
370
-
371
- return apply_filters( 'bp_get_friendship_requests', $requests );
372
  }
373
 
374
  function bp_friend_friendship_id() {
375
  echo bp_get_friend_friendship_id();
376
  }
377
  function bp_get_friend_friendship_id() {
378
- global $members_template;
379
 
380
- if ( !$friendship_id = wp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id() ) ) {
381
- $friendship_id = friends_get_friendship_id( $members_template->member->id, bp_loggedin_user_id() );
382
- wp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id(), $friendship_id, 'bp' );
383
  }
384
 
385
  return apply_filters( 'bp_get_friend_friendship_id', $friendship_id );
@@ -389,28 +402,28 @@ function bp_friend_accept_request_link() {
389
  echo bp_get_friend_accept_request_link();
390
  }
391
  function bp_get_friend_accept_request_link() {
392
- global $members_template;
393
 
394
- if ( !$friendship_id = wp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id() ) ) {
395
- $friendship_id = friends_get_friendship_id( $members_template->member->id, bp_loggedin_user_id() );
396
- wp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id(), $friendship_id, 'bp' );
397
  }
398
 
399
- return apply_filters( 'bp_get_friend_accept_request_link', wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/accept/' . $friendship_id, 'friends_accept_friendship' ) );
400
  }
401
 
402
  function bp_friend_reject_request_link() {
403
  echo bp_get_friend_reject_request_link();
404
  }
405
  function bp_get_friend_reject_request_link() {
406
- global $members_template;
407
 
408
- if ( !$friendship_id = wp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id() ) ) {
409
- $friendship_id = friends_get_friendship_id( $members_template->member->id, bp_loggedin_user_id() );
410
- wp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . bp_loggedin_user_id(), $friendship_id, 'bp' );
411
  }
412
 
413
- return apply_filters( 'bp_get_friend_reject_request_link', wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/reject/' . $friendship_id, 'friends_reject_friendship' ) );
414
  }
415
 
416
  function bp_total_friend_count( $user_id = 0 ) {
@@ -425,10 +438,12 @@ function bp_friend_total_requests_count( $user_id = 0 ) {
425
  echo bp_friend_get_total_requests_count( $user_id );
426
  }
427
  function bp_friend_get_total_requests_count( $user_id = 0 ) {
 
 
428
  if ( empty( $user_id ) )
429
- $user_id = bp_loggedin_user_id();
430
 
431
  return apply_filters( 'bp_friend_get_total_requests_count', count( BP_Friends_Friendship::get_friend_user_ids( $user_id, true ) ) );
432
  }
433
 
434
- ?>
1
  <?php
 
 
 
 
 
 
 
 
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
7
  *
8
  * @package BuddyPress
9
  * @subpackage Friends Template
10
+ * @since 1.5
11
  *
12
  * @uses bp_get_friends_slug()
13
  */
19
  *
20
  * @package BuddyPress
21
  * @subpackage Friends Template
22
+ * @since 1.5
23
  */
24
  function bp_get_friends_slug() {
25
  global $bp;
31
  *
32
  * @package BuddyPress
33
  * @subpackage Friends Template
34
+ * @since 1.5
35
  *
36
  * @uses bp_get_friends_root_slug()
37
  */
43
  *
44
  * @package BuddyPress
45
  * @subpackage Friends Template
46
+ * @since 1.5
47
  */
48
  function bp_get_friends_root_slug() {
49
  global $bp;
50
  return apply_filters( 'bp_get_friends_root_slug', $bp->friends->root_slug );
51
  }
52
 
53
+ /**
54
+ * Displays Friends header tabs
55
+ *
56
+ * @package BuddyPress
57
+ * @todo Deprecate?
58
+ */
59
+ function bp_friends_header_tabs() {
60
+ global $bp; ?>
61
+
62
+ <li<?php if ( !bp_action_variable( 0 ) || bp_is_action_variable( 'recently-active', 0 ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . bp_get_friends_slug() ?>/my-friends/recently-active"><?php _e( 'Recently Active', 'buddypress' ) ?></a></li>
63
+ <li<?php if ( bp_is_action_variable( 'newest', 0 ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . bp_get_friends_slug() ?>/my-friends/newest"><?php _e( 'Newest', 'buddypress' ) ?></a></li>
64
+ <li<?php if ( bp_is_action_variable( 'alphabetically', 0 ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . bp_get_friends_slug() ?>/my-friends/alphabetically"><?php _e( 'Alphabetically', 'buddypress' ) ?></a></li>
65
+
66
+ <?php
67
+ do_action( 'friends_header_tabs' );
68
+ }
69
+
70
+ /**
71
+ * Filters the title for the Friends component
72
+ *
73
+ * @package BuddyPress
74
+ * @todo Deprecate?
75
+ */
76
+ function bp_friends_filter_title() {
77
+ $current_filter = bp_action_variable( 0 );
78
+
79
+ switch ( $current_filter ) {
80
+ case 'recently-active': default:
81
+ _e( 'Recently Active', 'buddypress' );
82
+ break;
83
+ case 'newest':
84
+ _e( 'Newest', 'buddypress' );
85
+ break;
86
+ case 'alphabetically':
87
+ _e( 'Alphabetically', 'buddypress' );
88
+ break;
89
+ }
90
+ }
91
+
92
  function bp_friends_random_friends() {
93
+ global $bp;
94
 
95
+ if ( !$friend_ids = wp_cache_get( 'friends_friend_ids_' . $bp->displayed_user->id, 'bp' ) ) {
96
+ $friend_ids = BP_Friends_Friendship::get_random_friends( $bp->displayed_user->id );
97
+ wp_cache_set( 'friends_friend_ids_' . $bp->displayed_user->id, $friend_ids, 'bp' );
98
  } ?>
99
 
100
  <div class="info-group">
101
+ <h4><?php bp_word_or_name( __( "My Friends", 'buddypress' ), __( "%s's Friends", 'buddypress' ) ) ?> (<?php echo BP_Friends_Friendship::total_friend_count( $bp->displayed_user->id ) ?>) <span><a href="<?php echo $bp->displayed_user->domain . bp_get_friends_slug() ?>"><?php _e('See All', 'buddypress') ?></a></span></h4>
102
 
103
  <?php if ( $friend_ids ) { ?>
104
 
122
  </div>
123
 
124
  <?php } ?>
 
125
  <div class="clear"></div>
126
  </div>
 
127
  <?php
128
  }
129
 
137
  * @param int $total_members The number of members to retrieve
138
  */
139
  function bp_friends_random_members( $total_members = 5 ) {
140
+ global $bp;
141
 
142
  if ( !$user_ids = wp_cache_get( 'friends_random_users', 'bp' ) ) {
143
  $user_ids = BP_Core_User::get_users( 'random', $total_members );
195
  }
196
 
197
  function bp_friend_search_form() {
198
+ global $friends_template, $bp;
199
 
200
+ $action = $bp->displayed_user->domain . bp_get_friends_slug() . '/my-friends/search/';
201
+ $label = __( 'Filter Friends', 'buddypress' ); ?>
202
 
203
  <form action="<?php echo $action ?>" id="friend-search-form" method="post">
204
 
207
 
208
  <?php wp_nonce_field( 'friends_search', '_wpnonce_friend_search' ) ?>
209
 
210
+ <input type="hidden" name="initiator" id="initiator" value="<?php echo esc_attr( $bp->displayed_user->id ) ?>" />
211
 
212
  </form>
213
 
227
  add_action( 'bp_directory_members_actions', 'bp_member_add_friend_button' );
228
 
229
  function bp_member_total_friend_count() {
230
+ global $members_template;
231
+
232
  echo bp_get_member_total_friend_count();
233
  }
234
  function bp_get_member_total_friend_count() {
256
  *
257
  * Returns the ID of the potential friend
258
  *
259
+ * @global object $bp
260
  * @global object $friends_template
261
  * @param int $user_id
262
  * @return int ID of potential friend
263
  */
264
  function bp_get_potential_friend_id( $user_id = 0 ) {
265
+ global $bp, $friends_template;
266
 
267
  if ( empty( $user_id ) && isset( $friends_template->friendship->friend ) )
268
  $user_id = $friends_template->friendship->friend->id;
269
  else if ( empty( $user_id ) && !isset( $friends_template->friendship->friend ) )
270
+ $user_id = $bp->displayed_user->id;
271
 
272
+ return apply_filters( 'bp_get_potential_friend_id', (int)$user_id );
273
  }
274
 
275
  /**
277
  *
278
  * Returns - 'is_friend', 'not_friends', 'pending'
279
  *
280
+ * @global object $bp
281
  * @param int $potential_friend_id
282
  * @return string
283
  */
284
  function bp_is_friend( $user_id = 0 ) {
285
+ global $bp;
286
 
287
  if ( !is_user_logged_in() )
288
  return false;
290
  if ( empty( $user_id ) )
291
  $user_id = bp_get_potential_friend_id( $user_id );
292
 
293
+ if ( $bp->loggedin_user->id == $user_id )
294
  return false;
295
 
296
+ return apply_filters( 'bp_is_friend', friends_check_friendship_status( $bp->loggedin_user->id, $user_id ), $user_id );
297
  }
298
 
299
  function bp_add_friend_button( $potential_friend_id = 0, $friend_status = false ) {
300
  echo bp_get_add_friend_button( $potential_friend_id, $friend_status );
301
  }
302
  function bp_get_add_friend_button( $potential_friend_id = 0, $friend_status = false ) {
303
+ global $bp, $friends_template;
304
 
305
  if ( empty( $potential_friend_id ) )
306
  $potential_friend_id = bp_get_potential_friend_id( $potential_friend_id );
317
  'component' => 'friends',
318
  'must_be_logged_in' => true,
319
  'block_self' => true,
320
+ 'wrapper_class' => 'friendship-button pending',
321
  'wrapper_id' => 'friendship-button-' . $potential_friend_id,
322
+ 'link_href' => trailingslashit( $bp->loggedin_user->domain . bp_get_friends_slug() . '/requests' ),
323
+ 'link_text' => __( 'Friendship Requested', 'buddypress' ),
324
+ 'link_title' => __( 'Friendship Requested', 'buddypress' ),
325
+ 'link_class' => 'friendship-button pending requested'
 
 
326
  );
327
  break;
328
 
334
  'block_self' => false,
335
  'wrapper_class' => 'friendship-button is_friend',
336
  'wrapper_id' => 'friendship-button-' . $potential_friend_id,
337
+ 'link_href' => wp_nonce_url( $bp->loggedin_user->domain . bp_get_friends_slug() . '/remove-friend/' . $potential_friend_id . '/', 'friends_remove_friend' ),
338
  'link_text' => __( 'Cancel Friendship', 'buddypress' ),
339
  'link_title' => __( 'Cancel Friendship', 'buddypress' ),
340
  'link_id' => 'friend-' . $potential_friend_id,
351
  'block_self' => true,
352
  'wrapper_class' => 'friendship-button not_friends',
353
  'wrapper_id' => 'friendship-button-' . $potential_friend_id,
354
+ 'link_href' => wp_nonce_url( $bp->loggedin_user->domain . bp_get_friends_slug() . '/add-friend/' . $potential_friend_id . '/', 'friends_add_friend' ),
355
  'link_text' => __( 'Add Friend', 'buddypress' ),
356
  'link_title' => __( 'Add Friend', 'buddypress' ),
357
  'link_id' => 'friend-' . $potential_friend_id,
366
  }
367
 
368
  function bp_get_friend_ids( $user_id = 0 ) {
369
+ global $bp;
370
 
371
+ if ( !$user_id )
372
+ $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
373
 
374
  $friend_ids = friends_get_friend_user_ids( $user_id );
375
 
378
 
379
  return implode( ',', friends_get_friend_user_ids( $user_id ) );
380
  }
381
+ function bp_get_friendship_requests() {
382
+ global $bp;
383
 
384
+ return apply_filters( 'bp_get_friendship_requests', implode( ',', (array) friends_get_friendship_request_user_ids( $bp->loggedin_user->id ) ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
385
  }
386
 
387
  function bp_friend_friendship_id() {
388
  echo bp_get_friend_friendship_id();
389
  }
390
  function bp_get_friend_friendship_id() {
391
+ global $members_template, $bp;
392
 
393
+ if ( !$friendship_id = wp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . $bp->loggedin_user->id ) ) {
394
+ $friendship_id = friends_get_friendship_id( $members_template->member->id, $bp->loggedin_user->id );
395
+ wp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . $bp->loggedin_user->id, $friendship_id, 'bp' );
396
  }
397
 
398
  return apply_filters( 'bp_get_friend_friendship_id', $friendship_id );
402
  echo bp_get_friend_accept_request_link();
403
  }
404
  function bp_get_friend_accept_request_link() {
405
+ global $members_template, $bp;
406
 
407
+ if ( !$friendship_id = wp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . $bp->loggedin_user->id ) ) {
408
+ $friendship_id = friends_get_friendship_id( $members_template->member->id, $bp->loggedin_user->id );
409
+ wp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . $bp->loggedin_user->id, $friendship_id, 'bp' );
410
  }
411
 
412
+ return apply_filters( 'bp_get_friend_accept_request_link', wp_nonce_url( $bp->loggedin_user->domain . bp_get_friends_slug() . '/requests/accept/' . $friendship_id, 'friends_accept_friendship' ) );
413
  }
414
 
415
  function bp_friend_reject_request_link() {
416
  echo bp_get_friend_reject_request_link();
417
  }
418
  function bp_get_friend_reject_request_link() {
419
+ global $members_template, $bp;
420
 
421
+ if ( !$friendship_id = wp_cache_get( 'friendship_id_' . $members_template->member->id . '_' . $bp->loggedin_user->id ) ) {
422
+ $friendship_id = friends_get_friendship_id( $members_template->member->id, $bp->loggedin_user->id );
423
+ wp_cache_set( 'friendship_id_' . $members_template->member->id . '_' . $bp->loggedin_user->id, $friendship_id, 'bp' );
424
  }
425
 
426
+ return apply_filters( 'bp_get_friend_reject_request_link', wp_nonce_url( $bp->loggedin_user->domain . bp_get_friends_slug() . '/requests/reject/' . $friendship_id, 'friends_reject_friendship' ) );
427
  }
428
 
429
  function bp_total_friend_count( $user_id = 0 ) {
438
  echo bp_friend_get_total_requests_count( $user_id );
439
  }
440
  function bp_friend_get_total_requests_count( $user_id = 0 ) {
441
+ global $bp;
442
+
443
  if ( empty( $user_id ) )
444
+ $user_id = $bp->loggedin_user->id;
445
 
446
  return apply_filters( 'bp_friend_get_total_requests_count', count( BP_Friends_Friendship::get_friend_user_ids( $user_id, true ) ) );
447
  }
448
 
449
+ ?>
bp-groups/bp-groups-actions.php CHANGED
@@ -1,14 +1,10 @@
1
  <?php
2
-
3
- /**
4
- * BuddyPress Groups Actions
5
  *
6
  * Action functions are exactly the same as screen functions, however they do not
7
  * have a template screen associated with them. Usually they will send the user
8
  * back to the default screen after execution.
9
- *
10
- * @package BuddyPress
11
- * @subpackage GroupsActions
12
  */
13
 
14
  // Exit if accessed directly
@@ -34,7 +30,7 @@ function groups_action_create_group() {
34
 
35
  // If no current step is set, reset everything so we can start a fresh group creation
36
  $bp->groups->current_create_step = bp_action_variable( 1 );
37
- if ( !bp_get_groups_current_create_step() ) {
38
  unset( $bp->groups->current_create_step );
39
  unset( $bp->groups->completed_create_steps );
40
 
@@ -46,7 +42,7 @@ function groups_action_create_group() {
46
  }
47
 
48
  // If this is a creation step that is not recognized, just redirect them back to the first screen
49
- if ( bp_get_groups_current_create_step() && empty( $bp->groups->group_creation_steps[bp_get_groups_current_create_step()] ) ) {
50
  bp_core_add_message( __('There was an error saving group details. Please try again.', 'buddypress'), 'error' );
51
  bp_core_redirect( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/' );
52
  }
@@ -58,33 +54,33 @@ function groups_action_create_group() {
58
  // Set the ID of the new group, if it has already been created in a previous step
59
  if ( isset( $_COOKIE['bp_new_group_id'] ) ) {
60
  $bp->groups->new_group_id = $_COOKIE['bp_new_group_id'];
61
- $bp->groups->current_group = groups_get_group( array( 'group_id' => $bp->groups->new_group_id ) );
62
  }
63
 
64
  // If the save, upload or skip button is hit, lets calculate what we need to save
65
  if ( isset( $_POST['save'] ) ) {
66
 
67
  // Check the nonce
68
- check_admin_referer( 'groups_create_save_' . bp_get_groups_current_create_step() );
69
 
70
- if ( 'group-details' == bp_get_groups_current_create_step() ) {
71
  if ( empty( $_POST['group-name'] ) || empty( $_POST['group-desc'] ) || !strlen( trim( $_POST['group-name'] ) ) || !strlen( trim( $_POST['group-desc'] ) ) ) {
72
  bp_core_add_message( __( 'Please fill in all of the required fields', 'buddypress' ), 'error' );
73
- bp_core_redirect( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/' );
74
  }
75
 
76
  $new_group_id = isset( $bp->groups->new_group_id ) ? $bp->groups->new_group_id : 0;
77
 
78
  if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $new_group_id, 'name' => $_POST['group-name'], 'description' => $_POST['group-desc'], 'slug' => groups_check_slug( sanitize_title( esc_attr( $_POST['group-name'] ) ) ), 'date_created' => bp_core_current_time(), 'status' => 'public' ) ) ) {
79
  bp_core_add_message( __( 'There was an error saving group details, please try again.', 'buddypress' ), 'error' );
80
- bp_core_redirect( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/' );
81
  }
82
 
83
  groups_update_groupmeta( $bp->groups->new_group_id, 'total_member_count', 1 );
84
  groups_update_groupmeta( $bp->groups->new_group_id, 'last_activity', bp_core_current_time() );
85
  }
86
 
87
- if ( 'group-settings' == bp_get_groups_current_create_step() ) {
88
  $group_status = 'public';
89
  $group_enable_forum = 1;
90
 
@@ -92,7 +88,7 @@ function groups_action_create_group() {
92
  $group_enable_forum = 0;
93
  } else {
94
  // Create the forum if enable_forum = 1
95
- if ( bp_is_active( 'forums' ) && !groups_get_groupmeta( $bp->groups->new_group_id, 'forum_id' ) ) {
96
  groups_new_group_forum();
97
  }
98
  }
@@ -104,21 +100,21 @@ function groups_action_create_group() {
104
 
105
  if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'status' => $group_status, 'enable_forum' => $group_enable_forum ) ) ) {
106
  bp_core_add_message( __( 'There was an error saving group details, please try again.', 'buddypress' ), 'error' );
107
- bp_core_redirect( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/' );
108
  }
109
 
110
- // Set the invite status
111
  // Checked against a whitelist for security
112
  $allowed_invite_status = apply_filters( 'groups_allowed_invite_status', array( 'members', 'mods', 'admins' ) );
113
- $invite_status = !empty( $_POST['group-invite-status'] ) && in_array( $_POST['group-invite-status'], (array) $allowed_invite_status ) ? $_POST['group-invite-status'] : 'members';
114
 
115
  groups_update_groupmeta( $bp->groups->new_group_id, 'invite_status', $invite_status );
116
  }
117
 
118
- if ( 'group-invites' == bp_get_groups_current_create_step() )
119
- groups_send_invites( bp_loggedin_user_id(), $bp->groups->new_group_id );
120
 
121
- do_action( 'groups_create_group_step_save_' . bp_get_groups_current_create_step() );
122
  do_action( 'groups_create_group_step_complete' ); // Mostly for clearing cache on a generic action name
123
 
124
  /**
@@ -127,8 +123,8 @@ function groups_action_create_group() {
127
  * holding the information
128
  */
129
  $completed_create_steps = isset( $bp->groups->completed_create_steps ) ? $bp->groups->completed_create_steps : array();
130
- if ( !in_array( bp_get_groups_current_create_step(), $completed_create_steps ) )
131
- $bp->groups->completed_create_steps[] = bp_get_groups_current_create_step();
132
 
133
  // Reset cookie info
134
  setcookie( 'bp_new_group_id', $bp->groups->new_group_id, time()+60*60*24, COOKIEPATH );
@@ -136,13 +132,13 @@ function groups_action_create_group() {
136
 
137
  // If we have completed all steps and hit done on the final step we
138
  // can redirect to the completed group
139
- if ( count( $bp->groups->completed_create_steps ) == count( $bp->groups->group_creation_steps ) && bp_get_groups_current_create_step() == array_pop( array_keys( $bp->groups->group_creation_steps ) ) ) {
140
  unset( $bp->groups->current_create_step );
141
  unset( $bp->groups->completed_create_steps );
142
 
143
  // Once we compelete all steps, record the group creation in the activity stream.
144
  groups_record_activity( array(
145
- 'action' => apply_filters( 'groups_activity_created_group_action', sprintf( __( '%1$s created the group %2$s', 'buddypress'), bp_core_get_userlink( bp_loggedin_user_id() ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' ) ),
146
  'type' => 'created_group',
147
  'item_id' => $bp->groups->new_group_id
148
  ) );
@@ -155,8 +151,8 @@ function groups_action_create_group() {
155
  * Since we don't know what the next step is going to be (any plugin can insert steps)
156
  * we need to loop the step array and fetch the next step that way.
157
  */
158
- foreach ( (array) $bp->groups->group_creation_steps as $key => $value ) {
159
- if ( $key == bp_get_groups_current_create_step() ) {
160
  $next = 1;
161
  continue;
162
  }
@@ -172,7 +168,7 @@ function groups_action_create_group() {
172
  }
173
 
174
  // Group avatar is handled separately
175
- if ( 'group-avatar' == bp_get_groups_current_create_step() && isset( $_POST['upload'] ) ) {
176
  if ( !empty( $_FILES ) && isset( $_POST['upload'] ) ) {
177
  // Normally we would check a nonce here, but the group save nonce is used instead
178
 
@@ -211,11 +207,11 @@ function groups_action_join_group() {
211
  return false;
212
 
213
  // Skip if banned or already a member
214
- if ( !groups_is_user_member( bp_loggedin_user_id(), $bp->groups->current_group->id ) && !groups_is_user_banned( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) {
215
 
216
  // User wants to join a group that is not public
217
  if ( $bp->groups->current_group->status != 'public' ) {
218
- if ( !groups_check_user_has_invite( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) {
219
  bp_core_add_message( __( 'There was an error joining the group.', 'buddypress' ), 'error' );
220
  bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) );
221
  }
@@ -246,11 +242,11 @@ function groups_action_leave_group() {
246
  return false;
247
 
248
  // User wants to leave any group
249
- if ( groups_is_user_member( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) {
250
 
251
  // Stop sole admins from abandoning their group
252
  $group_admins = groups_get_group_admins( $bp->groups->current_group->id );
253
- if ( 1 == count( $group_admins ) && $group_admins[0]->user_id == bp_loggedin_user_id() )
254
  bp_core_add_message( __( 'This group must have at least one admin', 'buddypress' ), 'error' );
255
 
256
  elseif ( !groups_leave_group( $bp->groups->current_group->id ) )
@@ -275,7 +271,7 @@ function groups_action_sort_creation_steps() {
275
  if ( !is_array( $bp->groups->group_creation_steps ) )
276
  return false;
277
 
278
- foreach ( (array) $bp->groups->group_creation_steps as $slug => $step ) {
279
  while ( !empty( $temp[$step['position']] ) )
280
  $step['position']++;
281
 
@@ -286,17 +282,15 @@ function groups_action_sort_creation_steps() {
286
  ksort($temp);
287
  unset($bp->groups->group_creation_steps);
288
 
289
- foreach( (array) $temp as $position => $step )
290
  $bp->groups->group_creation_steps[$step['slug']] = array( 'name' => $step['name'], 'position' => $position );
291
  }
292
 
293
- /**
294
- * Catches requests for a random group page (example.com/groups/?random-group) and redirects
295
- */
296
  function groups_action_redirect_to_random_group() {
 
297
 
298
  if ( bp_is_groups_component() && isset( $_GET['random-group'] ) ) {
299
- $group = BP_Groups_Group::get_random( 1, 1 );
300
 
301
  bp_core_redirect( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/' . $group['groups'][0]->slug . '/' );
302
  }
@@ -313,7 +307,7 @@ function groups_action_group_feed() {
313
  status_header( 200 );
314
 
315
  if ( 'public' != $bp->groups->current_group->status ) {
316
- if ( !groups_is_user_member( bp_loggedin_user_id(), $bp->groups->current_group->id ) )
317
  return false;
318
  }
319
 
@@ -321,5 +315,4 @@ function groups_action_group_feed() {
321
  die;
322
  }
323
  add_action( 'bp_actions', 'groups_action_group_feed' );
324
-
325
- ?>
1
  <?php
2
+ /********************************************************************************
3
+ * Action Functions
 
4
  *
5
  * Action functions are exactly the same as screen functions, however they do not
6
  * have a template screen associated with them. Usually they will send the user
7
  * back to the default screen after execution.
 
 
 
8
  */
9
 
10
  // Exit if accessed directly
30
 
31
  // If no current step is set, reset everything so we can start a fresh group creation
32
  $bp->groups->current_create_step = bp_action_variable( 1 );
33
+ if ( !$bp->groups->current_create_step ) {
34
  unset( $bp->groups->current_create_step );
35
  unset( $bp->groups->completed_create_steps );
36
 
42
  }
43
 
44
  // If this is a creation step that is not recognized, just redirect them back to the first screen
45
+ if ( !empty( $bp->groups->current_create_step ) && empty( $bp->groups->group_creation_steps[$bp->groups->current_create_step] ) ) {
46
  bp_core_add_message( __('There was an error saving group details. Please try again.', 'buddypress'), 'error' );
47
  bp_core_redirect( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/' );
48
  }
54
  // Set the ID of the new group, if it has already been created in a previous step
55
  if ( isset( $_COOKIE['bp_new_group_id'] ) ) {
56
  $bp->groups->new_group_id = $_COOKIE['bp_new_group_id'];
57
+ $bp->groups->current_group = new BP_Groups_Group( $bp->groups->new_group_id );
58
  }
59
 
60
  // If the save, upload or skip button is hit, lets calculate what we need to save
61
  if ( isset( $_POST['save'] ) ) {
62
 
63
  // Check the nonce
64
+ check_admin_referer( 'groups_create_save_' . $bp->groups->current_create_step );
65
 
66
+ if ( 'group-details' == $bp->groups->current_create_step ) {
67
  if ( empty( $_POST['group-name'] ) || empty( $_POST['group-desc'] ) || !strlen( trim( $_POST['group-name'] ) ) || !strlen( trim( $_POST['group-desc'] ) ) ) {
68
  bp_core_add_message( __( 'Please fill in all of the required fields', 'buddypress' ), 'error' );
69
+ bp_core_redirect( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . $bp->groups->current_create_step . '/' );
70
  }
71
 
72
  $new_group_id = isset( $bp->groups->new_group_id ) ? $bp->groups->new_group_id : 0;
73
 
74
  if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $new_group_id, 'name' => $_POST['group-name'], 'description' => $_POST['group-desc'], 'slug' => groups_check_slug( sanitize_title( esc_attr( $_POST['group-name'] ) ) ), 'date_created' => bp_core_current_time(), 'status' => 'public' ) ) ) {
75
  bp_core_add_message( __( 'There was an error saving group details, please try again.', 'buddypress' ), 'error' );
76
+ bp_core_redirect( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . $bp->groups->current_create_step . '/' );
77
  }
78
 
79
  groups_update_groupmeta( $bp->groups->new_group_id, 'total_member_count', 1 );
80
  groups_update_groupmeta( $bp->groups->new_group_id, 'last_activity', bp_core_current_time() );
81
  }
82
 
83
+ if ( 'group-settings' == $bp->groups->current_create_step ) {
84
  $group_status = 'public';
85
  $group_enable_forum = 1;
86
 
88
  $group_enable_forum = 0;
89
  } else {
90
  // Create the forum if enable_forum = 1
91
+ if ( bp_is_active( 'forums' ) && '' == groups_get_groupmeta( $bp->groups->new_group_id, 'forum_id' ) ) {
92
  groups_new_group_forum();
93
  }
94
  }
100
 
101
  if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'status' => $group_status, 'enable_forum' => $group_enable_forum ) ) ) {
102
  bp_core_add_message( __( 'There was an error saving group details, please try again.', 'buddypress' ), 'error' );
103
+ bp_core_redirect( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . $bp->groups->current_create_step . '/' );
104
  }
105
 
106
+ // Set the invite status
107
  // Checked against a whitelist for security
108
  $allowed_invite_status = apply_filters( 'groups_allowed_invite_status', array( 'members', 'mods', 'admins' ) );
109
+ $invite_status = !empty( $_POST['group-invite-status'] ) && in_array( $_POST['group-invite-status'], (array)$allowed_invite_status ) ? $_POST['group-invite-status'] : 'members';
110
 
111
  groups_update_groupmeta( $bp->groups->new_group_id, 'invite_status', $invite_status );
112
  }
113
 
114
+ if ( 'group-invites' == $bp->groups->current_create_step )
115
+ groups_send_invites( $bp->loggedin_user->id, $bp->groups->new_group_id );
116
 
117
+ do_action( 'groups_create_group_step_save_' . $bp->groups->current_create_step );
118
  do_action( 'groups_create_group_step_complete' ); // Mostly for clearing cache on a generic action name
119
 
120
  /**
123
  * holding the information
124
  */
125
  $completed_create_steps = isset( $bp->groups->completed_create_steps ) ? $bp->groups->completed_create_steps : array();
126
+ if ( !in_array( $bp->groups->current_create_step, $completed_create_steps ) )
127
+ $bp->groups->completed_create_steps[] = $bp->groups->current_create_step;
128
 
129
  // Reset cookie info
130
  setcookie( 'bp_new_group_id', $bp->groups->new_group_id, time()+60*60*24, COOKIEPATH );
132
 
133
  // If we have completed all steps and hit done on the final step we
134
  // can redirect to the completed group
135
+ if ( count( $bp->groups->completed_create_steps ) == count( $bp->groups->group_creation_steps ) && $bp->groups->current_create_step == array_pop( array_keys( $bp->groups->group_creation_steps ) ) ) {
136
  unset( $bp->groups->current_create_step );
137
  unset( $bp->groups->completed_create_steps );
138
 
139
  // Once we compelete all steps, record the group creation in the activity stream.
140
  groups_record_activity( array(
141
+ 'action' => apply_filters( 'groups_activity_created_group_action', sprintf( __( '%1$s created the group %2$s', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' ) ),
142
  'type' => 'created_group',
143
  'item_id' => $bp->groups->new_group_id
144
  ) );
151
  * Since we don't know what the next step is going to be (any plugin can insert steps)
152
  * we need to loop the step array and fetch the next step that way.
153
  */
154
+ foreach ( (array)$bp->groups->group_creation_steps as $key => $value ) {
155
+ if ( $key == $bp->groups->current_create_step ) {
156
  $next = 1;
157
  continue;
158
  }
168
  }
169
 
170
  // Group avatar is handled separately
171
+ if ( 'group-avatar' == $bp->groups->current_create_step && isset( $_POST['upload'] ) ) {
172
  if ( !empty( $_FILES ) && isset( $_POST['upload'] ) ) {
173
  // Normally we would check a nonce here, but the group save nonce is used instead
174
 
207
  return false;
208
 
209
  // Skip if banned or already a member
210
+ if ( !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) && !groups_is_user_banned( $bp->loggedin_user->id, $bp->groups->current_group->id ) ) {
211
 
212
  // User wants to join a group that is not public
213
  if ( $bp->groups->current_group->status != 'public' ) {
214
+ if ( !groups_check_user_has_invite( $bp->loggedin_user->id, $bp->groups->current_group->id ) ) {
215
  bp_core_add_message( __( 'There was an error joining the group.', 'buddypress' ), 'error' );
216
  bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) );
217
  }
242
  return false;
243
 
244
  // User wants to leave any group
245
+ if ( groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) ) {
246
 
247
  // Stop sole admins from abandoning their group
248
  $group_admins = groups_get_group_admins( $bp->groups->current_group->id );
249
+ if ( 1 == count( $group_admins ) && $group_admins[0]->user_id == $bp->loggedin_user->id )
250
  bp_core_add_message( __( 'This group must have at least one admin', 'buddypress' ), 'error' );
251
 
252
  elseif ( !groups_leave_group( $bp->groups->current_group->id ) )
271
  if ( !is_array( $bp->groups->group_creation_steps ) )
272
  return false;
273
 
274
+ foreach ( (array)$bp->groups->group_creation_steps as $slug => $step ) {
275
  while ( !empty( $temp[$step['position']] ) )
276
  $step['position']++;
277
 
282
  ksort($temp);
283
  unset($bp->groups->group_creation_steps);
284
 
285
+ foreach( (array)$temp as $position => $step )
286
  $bp->groups->group_creation_steps[$step['slug']] = array( 'name' => $step['name'], 'position' => $position );
287
  }
288
 
 
 
 
289
  function groups_action_redirect_to_random_group() {
290
+ global $bp, $wpdb;
291
 
292
  if ( bp_is_groups_component() && isset( $_GET['random-group'] ) ) {
293
+ $group = groups_get_groups( array( 'type' => 'random', 'per_page' => 1 ) );
294
 
295
  bp_core_redirect( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/' . $group['groups'][0]->slug . '/' );
296
  }
307
  status_header( 200 );
308
 
309
  if ( 'public' != $bp->groups->current_group->status ) {
310
+ if ( !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
311
  return false;
312
  }
313
 
315
  die;
316
  }
317
  add_action( 'bp_actions', 'groups_action_group_feed' );
318
+ ?>
 
bp-groups/bp-groups-activity.php CHANGED
@@ -1,13 +1,12 @@
1
  <?php
2
-
3
  /**
4
- * BuddyPress Groups Activity Functions
5
  *
6
- * These functions handle the recording, deleting and formatting of activity
7
- * for the user and for this specific component.
8
  *
9
  * @package BuddyPress
10
- * @subpackage GroupsActivity
11
  */
12
 
13
  // Exit if accessed directly
@@ -34,23 +33,15 @@ function groups_record_activity( $args = '' ) {
34
  if ( !bp_is_active( 'activity' ) )
35
  return false;
36
 
37
- // Set the default for hide_sitewide by checking the status of the group
38
- $hide_sitewide = false;
39
- if ( !empty( $args['item_id'] ) ) {
40
- if ( bp_get_current_group_id() == $args['item_id'] ) {
41
- $group = groups_get_current_group();
42
- } else {
43
- $group = groups_get_group( array( 'group_id' => $args['item_id'] ) );
44
- }
45
-
46
- if ( isset( $group->status ) && 'public' != $group->status ) {
47
- $hide_sitewide = true;
48
- }
49
- }
50
 
51
  $defaults = array (
52
  'id' => false,
53
- 'user_id' => bp_loggedin_user_id(),
54
  'action' => '',
55
  'content' => '',
56
  'primary_link' => '',
@@ -71,34 +62,35 @@ function groups_record_activity( $args = '' ) {
71
  function groups_update_last_activity( $group_id = 0 ) {
72
  global $bp;
73
 
74
- if ( empty( $group_id ) )
75
  $group_id = $bp->groups->current_group->id;
76
 
77
- if ( empty( $group_id ) )
78
  return false;
79
 
80
  groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() );
81
  }
82
- add_action( 'groups_leave_group', 'groups_update_last_activity' );
83
- add_action( 'groups_created_group', 'groups_update_last_activity' );
84
- add_action( 'groups_new_forum_topic', 'groups_update_last_activity' );
85
  add_action( 'groups_new_forum_topic_post', 'groups_update_last_activity' );
86
 
87
  function groups_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
 
88
 
89
  switch ( $action ) {
90
  case 'new_membership_request':
91
  $group_id = $secondary_item_id;
92
  $requesting_user_id = $item_id;
93
 
94
- $group = groups_get_group( array( 'group_id' => $group_id ) );
95
  $group_link = bp_get_group_permalink( $group );
96
 
97
  // Set up the string and the filter
98
  // Because different values are passed to the filters, we'll return the
99
  // values inline
100
- if ( (int) $total_items > 1 ) {
101
- $text = sprintf( __( '%1$d new membership requests for the group "%2$s"', 'buddypress' ), (int) $total_items, $group->name );
102
  $filter = 'bp_groups_multiple_new_membership_requests_notification';
103
  $notification_link = $group_link . 'admin/membership-requests/?n=1';
104
 
@@ -131,13 +123,13 @@ function groups_format_notifications( $action, $item_id, $secondary_item_id, $to
131
  case 'membership_request_accepted':
132
  $group_id = $item_id;
133
 
134
- $group = groups_get_group( array( 'group_id' => $group_id ) );
135
  $group_link = bp_get_group_permalink( $group );
136
 
137
- if ( (int) $total_items > 1 ) {
138
- $text = sprintf( __( '%d accepted group membership requests', 'buddypress' ), (int) $total_items, $group->name );
139
  $filter = 'bp_groups_multiple_membership_request_accepted_notification';
140
- $notification_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) . '?n=1';
141
 
142
  if ( 'string' == $format ) {
143
  return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Groups', 'buddypress' ) . '">' . $text . '</a>', $total_items, $group->name, $text, $notification_link );
@@ -167,13 +159,13 @@ function groups_format_notifications( $action, $item_id, $secondary_item_id, $to
167
  case 'membership_request_rejected':
168
  $group_id = $item_id;
169
 
170
- $group = groups_get_group( array( 'group_id' => $group_id ) );
171
  $group_link = bp_get_group_permalink( $group );
172
 
173
- if ( (int) $total_items > 1 ) {
174
- $text = sprintf( __( '%d rejected group membership requests', 'buddypress' ), (int) $total_items, $group->name );
175
  $filter = 'bp_groups_multiple_membership_request_rejected_notification';
176
- $notification_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) . '?n=1';
177
 
178
  if ( 'string' == $format ) {
179
  return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Groups', 'buddypress' ) . '">' . $text . '</a>', $total_items, $group->name );
@@ -203,13 +195,13 @@ function groups_format_notifications( $action, $item_id, $secondary_item_id, $to
203
  case 'member_promoted_to_admin':
204
  $group_id = $item_id;
205
 
206
- $group = groups_get_group( array( 'group_id' => $group_id ) );
207
  $group_link = bp_get_group_permalink( $group );
208
 
209
- if ( (int) $total_items > 1 ) {
210
- $text = sprintf( __( 'You were promoted to an admin in %d groups', 'buddypress' ), (int) $total_items );
211
  $filter = 'bp_groups_multiple_member_promoted_to_admin_notification';
212
- $notification_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) . '?n=1';
213
 
214
  if ( 'string' == $format ) {
215
  return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Groups', 'buddypress' ) . '">' . $text . '</a>', $total_items, $text, $notification_link );
@@ -239,13 +231,13 @@ function groups_format_notifications( $action, $item_id, $secondary_item_id, $to
239
  case 'member_promoted_to_mod':
240
  $group_id = $item_id;
241
 
242
- $group = groups_get_group( array( 'group_id' => $group_id ) );
243
  $group_link = bp_get_group_permalink( $group );
244
 
245
- if ( (int) $total_items > 1 ) {
246
- $text = sprintf( __( 'You were promoted to a mod in %d groups', 'buddypress' ), (int) $total_items );
247
  $filter = 'bp_groups_multiple_member_promoted_to_mod_notification';
248
- $notification_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) . '?n=1';
249
 
250
  if ( 'string' == $format ) {
251
  return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Groups', 'buddypress' ) . '">' . $text . '</a>', $total_items, $text, $notification_link );
@@ -274,13 +266,13 @@ function groups_format_notifications( $action, $item_id, $secondary_item_id, $to
274
 
275
  case 'group_invite':
276
  $group_id = $item_id;
277
- $group = groups_get_group( array( 'group_id' => $group_id ) );
278
  $group_link = bp_get_group_permalink( $group );
279
 
280
  $notification_link = bp_loggedin_user_domain() . bp_get_groups_slug() . '/invites/?n=1';
281
 
282
- if ( (int) $total_items > 1 ) {
283
- $text = sprintf( __( 'You have %d new group invitations', 'buddypress' ), (int) $total_items );
284
  $filter = 'bp_groups_multiple_group_invite_notification';
285
 
286
  if ( 'string' == $format ) {
@@ -312,5 +304,4 @@ function groups_format_notifications( $action, $item_id, $secondary_item_id, $to
312
 
313
  return false;
314
  }
315
-
316
- ?>
1
  <?php
 
2
  /**
3
+ * BuddyPress Groups Activity & Notification Functions
4
  *
5
+ * These functions handle the recording, deleting and formatting of activity and
6
+ * notifications for the user and for this specific component.
7
  *
8
  * @package BuddyPress
9
+ * @subpackage Groups
10
  */
11
 
12
  // Exit if accessed directly
33
  if ( !bp_is_active( 'activity' ) )
34
  return false;
35
 
36
+ // If the group is not public, hide the activity sitewide.
37
+ if ( isset( $bp->groups->current_group->status ) && 'public' == $bp->groups->current_group->status )
38
+ $hide_sitewide = false;
39
+ else
40
+ $hide_sitewide = true;
 
 
 
 
 
 
 
 
41
 
42
  $defaults = array (
43
  'id' => false,
44
+ 'user_id' => $bp->loggedin_user->id,
45
  'action' => '',
46
  'content' => '',
47
  'primary_link' => '',
62
  function groups_update_last_activity( $group_id = 0 ) {
63
  global $bp;
64
 
65
+ if ( !$group_id )
66
  $group_id = $bp->groups->current_group->id;
67
 
68
+ if ( !$group_id )
69
  return false;
70
 
71
  groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() );
72
  }
73
+ add_action( 'groups_leave_group', 'groups_update_last_activity' );
74
+ add_action( 'groups_created_group', 'groups_update_last_activity' );
75
+ add_action( 'groups_new_forum_topic', 'groups_update_last_activity' );
76
  add_action( 'groups_new_forum_topic_post', 'groups_update_last_activity' );
77
 
78
  function groups_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
79
+ global $bp;
80
 
81
  switch ( $action ) {
82
  case 'new_membership_request':
83
  $group_id = $secondary_item_id;
84
  $requesting_user_id = $item_id;
85
 
86
+ $group = new BP_Groups_Group( $group_id );
87
  $group_link = bp_get_group_permalink( $group );
88
 
89
  // Set up the string and the filter
90
  // Because different values are passed to the filters, we'll return the
91
  // values inline
92
+ if ( (int)$total_items > 1 ) {
93
+ $text = sprintf( __( '%1$d new membership requests for the group "%2$s"', 'buddypress' ), (int)$total_items, $group->name );
94
  $filter = 'bp_groups_multiple_new_membership_requests_notification';
95
  $notification_link = $group_link . 'admin/membership-requests/?n=1';
96
 
123
  case 'membership_request_accepted':
124
  $group_id = $item_id;
125
 
126
+ $group = new BP_Groups_Group( $group_id );
127
  $group_link = bp_get_group_permalink( $group );
128
 
129
+ if ( (int)$total_items > 1 ) {
130
+ $text = sprintf( __( '%d accepted group membership requests', 'buddypress' ), (int)$total_items, $group->name );
131
  $filter = 'bp_groups_multiple_membership_request_accepted_notification';
132
+ $notification_link = bp_loggedin_user_domain() . bp_get_groups_slug() . '/?n=1';
133
 
134
  if ( 'string' == $format ) {
135
  return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Groups', 'buddypress' ) . '">' . $text . '</a>', $total_items, $group->name, $text, $notification_link );
159
  case 'membership_request_rejected':
160
  $group_id = $item_id;
161
 
162
+ $group = new BP_Groups_Group( $group_id );
163
  $group_link = bp_get_group_permalink( $group );
164
 
165
+ if ( (int)$total_items > 1 ) {
166
+ $text = sprintf( __( '%d rejected group membership requests', 'buddypress' ), (int)$total_items, $group->name );
167
  $filter = 'bp_groups_multiple_membership_request_rejected_notification';
168
+ $notification_link = bp_loggedin_user_domain() . bp_get_groups_slug() . '/?n=1';
169
 
170
  if ( 'string' == $format ) {
171
  return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Groups', 'buddypress' ) . '">' . $text . '</a>', $total_items, $group->name );
195
  case 'member_promoted_to_admin':
196
  $group_id = $item_id;
197
 
198
+ $group = new BP_Groups_Group( $group_id );
199
  $group_link = bp_get_group_permalink( $group );
200
 
201
+ if ( (int)$total_items > 1 ) {
202
+ $text = sprintf( __( 'You were promoted to an admin in %d groups', 'buddypress' ), (int)$total_items );
203
  $filter = 'bp_groups_multiple_member_promoted_to_admin_notification';
204
+ $notification_link = bp_loggedin_user_domain() . bp_get_groups_slug() . '?n=1';
205
 
206
  if ( 'string' == $format ) {
207
  return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Groups', 'buddypress' ) . '">' . $text . '</a>', $total_items, $text, $notification_link );
231
  case 'member_promoted_to_mod':
232
  $group_id = $item_id;
233
 
234
+ $group = new BP_Groups_Group( $group_id );
235
  $group_link = bp_get_group_permalink( $group );
236
 
237
+ if ( (int)$total_items > 1 ) {
238
+ $text = sprintf( __( 'You were promoted to a mod in %d groups', 'buddypress' ), (int)$total_items );
239
  $filter = 'bp_groups_multiple_member_promoted_to_mod_notification';
240
+ $notification_link = bp_loggedin_user_domain() . bp_get_groups_slug() . '?n=1';
241
 
242
  if ( 'string' == $format ) {
243
  return apply_filters( $filter, '<a href="' . $notification_link . '" title="' . __( 'Groups', 'buddypress' ) . '">' . $text . '</a>', $total_items, $text, $notification_link );
266
 
267
  case 'group_invite':
268
  $group_id = $item_id;
269
+ $group = new BP_Groups_Group( $group_id );
270
  $group_link = bp_get_group_permalink( $group );
271
 
272
  $notification_link = bp_loggedin_user_domain() . bp_get_groups_slug() . '/invites/?n=1';
273
 
274
+ if ( (int)$total_items > 1 ) {
275
+ $text = sprintf( __( 'You have %d new group invitations', 'buddypress' ), (int)$total_items );
276
  $filter = 'bp_groups_multiple_group_invite_notification';
277
 
278
  if ( 'string' == $format ) {
304
 
305
  return false;
306
  }
307
+ ?>
 
bp-groups/bp-groups-adminbar.php CHANGED
@@ -1,9 +1,8 @@
1
  <?php
2
-
3
  /**
4
- * BuddyPress Groups Toolbar
5
  *
6
- * Handles the groups functions related to the WordPress Toolbar
7
  *
8
  * @package BuddyPress
9
  * @subpackage Groups
@@ -12,11 +11,30 @@
12
  // Exit if accessed directly
13
  if ( !defined( 'ABSPATH' ) ) exit;
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  /**
16
  * Adds the Group Admin top-level menu to group pages
17
  *
18
  * @package BuddyPress
19
- * @since BuddyPress (1.5)
20
  *
21
  * @todo Add dynamic menu items for group extensions
22
  */
@@ -28,18 +46,43 @@ function bp_groups_group_admin_menu() {
28
  return false;
29
 
30
  // Only show this menu to group admins and super admins
31
- if ( !bp_current_user_can( 'bp_moderate' ) && !bp_group_is_admin() )
32
  return false;
33
 
34
- // Unique ID for the 'Edit Group' menu
35
- $bp->group_admin_menu_id = 'group-admin';
36
 
37
- // Add the top-level Group Admin button
38
- $wp_admin_bar->add_menu( array(
39
- 'id' => $bp->group_admin_menu_id,
40
- 'title' => __( 'Edit Group', 'buddypress' ),
41
- 'href' => bp_get_group_permalink( $bp->groups->current_group )
42
- ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
  // Group Admin > Edit details
45
  $wp_admin_bar->add_menu( array(
@@ -103,18 +146,5 @@ function bp_groups_group_admin_menu() {
103
  'href' => bp_get_groups_action_link( 'admin/delete-group' )
104
  ) );
105
  }
106
- add_action( 'admin_bar_menu', 'bp_groups_group_admin_menu', 99 );
107
-
108
- /**
109
- * Remove rogue WP core edit menu when viewing a group
110
- *
111
- * @since BuddyPress (1.6)
112
- */
113
- function bp_groups_remove_edit_page_menu() {
114
- if ( bp_is_group() ) {
115
- remove_action( 'admin_bar_menu', 'wp_admin_bar_edit_menu', 80 );
116
- }
117
- }
118
- add_action( 'bp_init', 'bp_groups_remove_edit_page_menu', 99 );
119
 
120
- ?>
1
  <?php
 
2
  /**
3
+ * BuddyPress Groups Admin Bar
4
  *
5
+ * Handles the groups functions related to the WordPress Admin Bar
6
  *
7
  * @package BuddyPress
8
  * @subpackage Groups
11
  // Exit if accessed directly
12
  if ( !defined( 'ABSPATH' ) ) exit;
13
 
14
+ /**
15
+ * Adjust the admin bar menus based on which WordPress version this is
16
+ *
17
+ * @since BuddyPress (1.5.2)
18
+ */
19
+ function bp_groups_admin_bar_version_check() {
20
+ switch( bp_get_major_wp_version() ) {
21
+ case 3.2 :
22
+ add_action( 'bp_setup_admin_bar', 'bp_groups_group_admin_menu', 99 );
23
+ break;
24
+ case 3.3 :
25
+ case 3.4 :
26
+ default :
27
+ add_action( 'admin_bar_menu', 'bp_groups_group_admin_menu', 400 );
28
+ break;
29
+ }
30
+ }
31
+ add_action( 'admin_bar_menu', 'bp_groups_admin_bar_version_check', 4 );
32
+
33
  /**
34
  * Adds the Group Admin top-level menu to group pages
35
  *
36
  * @package BuddyPress
37
+ * @since 1.5
38
  *
39
  * @todo Add dynamic menu items for group extensions
40
  */
46
  return false;
47
 
48
  // Only show this menu to group admins and super admins
49
+ if ( !is_super_admin() && !bp_group_is_admin() )
50
  return false;
51
 
52
+ if ( 3.2 == bp_get_major_wp_version() ) {
 
53
 
54
+ // Group avatar
55
+ $avatar = bp_core_fetch_avatar( array(
56
+ 'object' => 'group',
57
+ 'type' => 'thumb',
58
+ 'avatar_dir' => 'group-avatars',
59
+ 'item_id' => $bp->groups->current_group->id,
60
+ 'width' => 16,
61
+ 'height' => 16
62
+ ) );
63
+
64
+ // Unique ID for the 'My Account' menu
65
+ $bp->group_admin_menu_id = ( ! empty( $avatar ) ) ? 'group-admin-with-avatar' : 'group-admin';
66
+
67
+ // Add the top-level Group Admin button
68
+ $wp_admin_bar->add_menu( array(
69
+ 'id' => $bp->group_admin_menu_id,
70
+ 'title' => $avatar . bp_get_current_group_name(),
71
+ 'href' => bp_get_group_permalink( $bp->groups->current_group )
72
+ ) );
73
+
74
+ } elseif ( 3.3 <= bp_get_major_wp_version() ) {
75
+
76
+ // Unique ID for the 'My Account' menu
77
+ $bp->group_admin_menu_id = 'group-admin';
78
+
79
+ // Add the top-level Group Admin button
80
+ $wp_admin_bar->add_menu( array(
81
+ 'id' => $bp->group_admin_menu_id,
82
+ 'title' => __( 'Edit Group', 'buddypress' ),
83
+ 'href' => bp_get_group_permalink( $bp->groups->current_group )
84
+ ) );
85
+ }
86
 
87
  // Group Admin > Edit details
88
  $wp_admin_bar->add_menu( array(
146
  'href' => bp_get_groups_action_link( 'admin/delete-group' )
147
  ) );
148
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
149
 
150
+ ?>
bp-groups/bp-groups-buddybar.php CHANGED
@@ -1,30 +1,15 @@
1
  <?php
2
-
3
- /**
4
- * BuddyPress Groups BuddyBar
5
- *
6
- * @package BuddyPress
7
- * @subpackage GroupsBuddyBar
8
- */
9
-
10
  // Exit if accessed directly
11
  if ( !defined( 'ABSPATH' ) ) exit;
12
 
13
- /**
14
- * Adds menu items to the BuddyBar
15
- *
16
- * @since BuddyPress (1.0)
17
- * @global BuddyPress $bp
18
- * @return False if no menu
19
- */
20
  function bp_groups_adminbar_admin_menu() {
21
- global $bp;
22
 
23
  if ( empty( $bp->groups->current_group ) )
24
  return false;
25
 
26
- // Only group admins and site admins can see this menu
27
- if ( !current_user_can( 'edit_users' ) && !bp_current_user_can( 'bp_moderate' ) && !bp_is_item_admin() )
28
  return false; ?>
29
 
30
  <li id="bp-adminbar-adminoptions-menu">
@@ -66,4 +51,4 @@ function bp_groups_adminbar_admin_menu() {
66
  }
67
  add_action( 'bp_adminbar_menus', 'bp_groups_adminbar_admin_menu', 20 );
68
 
69
- ?>
1
  <?php
 
 
 
 
 
 
 
 
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
 
 
 
 
 
 
 
5
  function bp_groups_adminbar_admin_menu() {
6
+ global $bp, $groups_template;
7
 
8
  if ( empty( $bp->groups->current_group ) )
9
  return false;
10
 
11
+ // Don't show this menu to non site admins or if you're viewing your own profile
12
+ if ( !current_user_can( 'edit_users' ) || !is_super_admin() || ( !$bp->is_item_admin && !$bp->is_item_mod ) )
13
  return false; ?>
14
 
15
  <li id="bp-adminbar-adminoptions-menu">
51
  }
52
  add_action( 'bp_adminbar_menus', 'bp_groups_adminbar_admin_menu', 20 );
53
 
54
+ ?>
bp-groups/bp-groups-cache.php CHANGED
@@ -1,5 +1,4 @@
1
  <?php
2
-
3
  /**
4
  * BuddyPress Groups Caching
5
  *
@@ -13,33 +12,6 @@
13
  // Exit if accessed directly
14
  if ( !defined( 'ABSPATH' ) ) exit;
15
 
16
- /**
17
- * Slurps up groupmeta
18
- *
19
- * This function is called in two places in the BP_Groups_Group class:
20
- * - in the populate() method, when single group objects are populated
21
- * - in the get() method, when multiple groups are queried
22
- *
23
- * It grabs all groupmeta associated with all of the groups passed in $group_ids and adds it to
24
- * the WP cache. This improves efficiency when using groupmeta inline
25
- *
26
- * @param int|str|array $group_ids Accepts a single group_id, or a comma-separated list or array of
27
- * group ids
28
- */
29
- function bp_groups_update_meta_cache( $group_ids = false ) {
30
- global $bp;
31
-
32
- $cache_args = array(
33
- 'object_ids' => $group_ids,
34
- 'object_type' => $bp->groups->id,
35
- 'object_column' => 'group_id',
36
- 'meta_table' => $bp->groups->table_name_groupmeta,
37
- 'cache_key_prefix' => 'bp_groups_groupmeta'
38
- );
39
-
40
- bp_update_meta_cache( $cache_args );
41
- }
42
-
43
  function groups_clear_group_object_cache( $group_id ) {
44
  wp_cache_delete( 'bp_total_group_count', 'bp' );
45
  }
@@ -49,35 +21,8 @@ add_action( 'groups_details_updated', 'groups_clear_group_object_cach
49
  add_action( 'groups_group_avatar_updated', 'groups_clear_group_object_cache' );
50
  add_action( 'groups_create_group_step_complete', 'groups_clear_group_object_cache' );
51
 
52
- /**
53
- * Clears caches for the group creator when a group is created
54
- *
55
- * @param int $group_id
56
- * @param BP_Groups_Group $group_obj
57
- * @since BuddyPress (1.6)
58
- */
59
- function bp_groups_clear_group_creator_cache( $group_id, $group_obj ) {
60
- // Clears the 'total groups' for this user
61
- groups_clear_group_user_object_cache( $group_obj->id, $group_obj->creator_id );
62
- }
63
- add_action( 'groups_created_group', 'bp_groups_clear_group_creator_cache', 10, 2 );
64
-
65
- /**
66
- * Clears caches for all members in a group when a group is deleted
67
- *
68
- * @param BP_Groups_Group $group_obj
69
- * @param array User IDs who were in this group
70
- * @since BuddyPress (1.6)
71
- */
72
- function bp_groups_clear_group_members_caches( $group_obj, $user_ids ) {
73
- // Clears the 'total groups' cache for each member in a group
74
- foreach ( (array) $user_ids as $user_id )
75
- groups_clear_group_user_object_cache( $group_obj->id, $user_id );
76
- }
77
- add_action( 'bp_groups_delete_group', 'bp_groups_clear_group_members_caches', 10, 2 );
78
-
79
  function groups_clear_group_user_object_cache( $group_id, $user_id ) {
80
- wp_cache_delete( 'bp_total_groups_for_user_' . $user_id, 'bp' );
81
  }
82
  add_action( 'groups_join_group', 'groups_clear_group_user_object_cache', 10, 2 );
83
  add_action( 'groups_leave_group', 'groups_clear_group_user_object_cache', 10, 2 );
@@ -96,7 +41,7 @@ add_action( 'groups_settings_updated', 'bp_core_clear_cache' );
96
  add_action( 'groups_unban_member', 'bp_core_clear_cache' );
97
  add_action( 'groups_ban_member', 'bp_core_clear_cache' );
98
  add_action( 'groups_demote_member', 'bp_core_clear_cache' );
99
- add_action( 'groups_promote_member', 'bp_core_clear_cache' );
100
  add_action( 'groups_membership_rejected', 'bp_core_clear_cache' );
101
  add_action( 'groups_membership_accepted', 'bp_core_clear_cache' );
102
  add_action( 'groups_membership_requested', 'bp_core_clear_cache' );
@@ -104,4 +49,4 @@ add_action( 'groups_create_group_step_complete', 'bp_core_clear_cache' );
104
  add_action( 'groups_created_group', 'bp_core_clear_cache' );
105
  add_action( 'groups_group_avatar_updated', 'bp_core_clear_cache' );
106
 
107
- ?>
1
  <?php
 
2
  /**
3
  * BuddyPress Groups Caching
4
  *
12
  // Exit if accessed directly
13
  if ( !defined( 'ABSPATH' ) ) exit;
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  function groups_clear_group_object_cache( $group_id ) {
16
  wp_cache_delete( 'bp_total_group_count', 'bp' );
17
  }
21
  add_action( 'groups_group_avatar_updated', 'groups_clear_group_object_cache' );
22
  add_action( 'groups_create_group_step_complete', 'groups_clear_group_object_cache' );
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  function groups_clear_group_user_object_cache( $group_id, $user_id ) {
25
+ wp_cache_delete( 'bp_total_groups_for_user_' . $user_id );
26
  }
27
  add_action( 'groups_join_group', 'groups_clear_group_user_object_cache', 10, 2 );
28
  add_action( 'groups_leave_group', 'groups_clear_group_user_object_cache', 10, 2 );
41
  add_action( 'groups_unban_member', 'bp_core_clear_cache' );
42
  add_action( 'groups_ban_member', 'bp_core_clear_cache' );
43
  add_action( 'groups_demote_member', 'bp_core_clear_cache' );
44
+ add_action( 'groups_premote_member', 'bp_core_clear_cache' );
45
  add_action( 'groups_membership_rejected', 'bp_core_clear_cache' );
46
  add_action( 'groups_membership_accepted', 'bp_core_clear_cache' );
47
  add_action( 'groups_membership_requested', 'bp_core_clear_cache' );
49
  add_action( 'groups_created_group', 'bp_core_clear_cache' );
50
  add_action( 'groups_group_avatar_updated', 'bp_core_clear_cache' );
51
 
52
+ ?>
bp-groups/bp-groups-classes.php CHANGED
@@ -1,16 +1,8 @@
1
  <?php
2
-
3
- /**
4
- * BuddyPress Groups Classes
5
- *
6
- * @package BuddyPress
7
- * @subpackage GroupsClasses
8
- */
9
-
10
  // Exit if accessed directly
11
  if ( !defined( 'ABSPATH' ) ) exit;
12
 
13
- class BP_Groups_Group {
14
  var $id;
15
  var $creator_id;
16
  var $name;
@@ -24,32 +16,12 @@ class BP_Groups_Group {
24
  var $mods;
25
  var $total_member_count;
26
 
27
- /**
28
- * Is the current user a member of this group?
29
- *
30
- * @since BuddyPress (1.2)
31
- * @var bool
32
- */
33
- public $is_member;
34
-
35
- /**
36
- * Timestamp of the last activity that happened in this group.
37
- *
38
- * @since BuddyPress (1.2)
39
- * @var string
40
- */
41
- public $last_activity;
42
-
43
- /**
44
- * If this is a private or hidden group, does the current user have access?
45
- *
46
- * @since BuddyPress (1.6)
47
- * @var bool
48
- */
49
- public $user_has_access;
50
 
51
  function __construct( $id = null ) {
52
- if ( !empty( $id ) ) {
53
  $this->id = $id;
54
  $this->populate();
55
  }
@@ -58,9 +30,7 @@ class BP_Groups_Group {
58
  function populate() {
59
  global $wpdb, $bp;
60
 
61
- if ( $group = $wpdb->get_row( $wpdb->prepare( "SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id = %d", $this->id ) ) ) {
62
- bp_groups_update_meta_cache( $this->id );
63
-
64
  $this->id = $group->id;
65
  $this->creator_id = $group->creator_id;
66
  $this->name = stripslashes($group->name);
@@ -69,24 +39,14 @@ class BP_Groups_Group {
69
  $this->status = $group->status;
70
  $this->enable_forum = $group->enable_forum;
71
  $this->date_created = $group->date_created;
72
- $this->last_activity = groups_get_groupmeta( $this->id, 'last_activity' );
73
- $this->total_member_count = groups_get_groupmeta( $this->id, 'total_member_count' );
74
- $this->is_member = BP_Groups_Member::check_is_member( bp_loggedin_user_id(), $this->id );
75
-
76
- // If this is a private or hidden group, does the current user have access?
77
- if ( 'private' == $this->status || 'hidden' == $this->status ) {
78
- if ( $this->is_member && is_user_logged_in() || bp_current_user_can( 'bp_moderate' ) )
79
- $this->user_has_access = true;
80
- else
81
- $this->user_has_access = false;
82
- } else {
83
- $this->user_has_access = true;
84
- }
85
 
86
  // Get group admins and mods
87
  $admin_mods = $wpdb->get_results( apply_filters( 'bp_group_admin_mods_user_join_filter', $wpdb->prepare( "SELECT u.ID as user_id, u.user_login, u.user_email, u.user_nicename, m.is_admin, m.is_mod FROM {$wpdb->users} u, {$bp->groups->table_name_members} m WHERE u.ID = m.user_id AND m.group_id = %d AND ( m.is_admin = 1 OR m.is_mod = 1 )", $this->id ) ) );
88
- foreach( (array) $admin_mods as $user ) {
89
- if ( (int) $user->is_admin )
90
  $this->admins[] = $user;
91
  else
92
  $this->mods[] = $user;
@@ -159,8 +119,6 @@ class BP_Groups_Group {
159
  $this->id = $wpdb->insert_id;
160
 
161
  do_action_ref_array( 'groups_group_after_save', array( &$this ) );
162
-
163
- wp_cache_delete( 'bp_groups_group_' . $this->id, 'bp' );
164
 
165
  return true;
166
  }
@@ -172,18 +130,16 @@ class BP_Groups_Group {
172
  groups_delete_groupmeta( $this->id );
173
 
174
  // Fetch the user IDs of all the members of the group
175
- $user_ids = BP_Groups_Member::get_group_member_ids( $this->id );
176
- $user_id_str = implode( ',', (array) $user_ids );
177
 
178
  // Modify group count usermeta for members
179
- $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->usermeta} SET meta_value = meta_value - 1 WHERE meta_key = 'total_group_count' AND user_id IN ( {$user_id_str} )" ) );
180
 
181
  // Now delete all group member entries
182
  BP_Groups_Member::delete_all( $this->id );
183
 
184
- do_action_ref_array( 'bp_groups_delete_group', array( &$this, $user_ids ) );
185
-
186
- wp_cache_delete( 'bp_groups_group_' . $this->id, 'bp' );
187
 
188
  // Finally remove the group entry from the DB
189
  if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name} WHERE id = %d", $this->id ) ) )
@@ -192,15 +148,15 @@ class BP_Groups_Group {
192
  return true;
193
  }
194
 
195
- /** Static Methods ********************************************************/
196
 
197
  function group_exists( $slug, $table_name = false ) {
198
  global $wpdb, $bp;
199
 
200
- if ( empty( $table_name ) )
201
  $table_name = $bp->groups->table_name;
202
 
203
- if ( empty( $slug ) )
204
  return false;
205
 
206
  return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$table_name} WHERE slug = %s", $slug ) );
@@ -218,18 +174,18 @@ class BP_Groups_Group {
218
  function filter_user_groups( $filter, $user_id = 0, $order = false, $limit = null, $page = null ) {
219
  global $wpdb, $bp;
220
 
221
- if ( empty( $user_id ) )
222
- $user_id = bp_displayed_user_id();
223
 
224
  $filter = like_escape( $wpdb->escape( $filter ) );
225
 
226
- if ( !empty( $limit ) && !empty( $page ) )
227
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
228
 
229
  // Get all the group ids for the current user's groups.
230
  $gids = BP_Groups_Member::get_group_ids( $user_id );
231
 
232
- if ( empty( $gids['groups'] ) )
233
  return false;
234
 
235
  $gids = implode( ',', $gids['groups'] );
@@ -245,16 +201,16 @@ class BP_Groups_Group {
245
 
246
  $filter = like_escape( $wpdb->escape( $filter ) );
247
 
248
- if ( !empty( $limit ) && !empty( $page ) )
249
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
250
 
251
- if ( !empty( $sort_by ) && !empty( $order ) ) {
252
- $sort_by = $wpdb->escape( $sort_by );
253
- $order = $wpdb->escape( $order );
254
  $order_sql = "ORDER BY $sort_by $order";
255
  }
256
 
257
- if ( !bp_current_user_can( 'bp_moderate' ) )
258
  $hidden_sql = "AND status != 'hidden'";
259
 
260
  $paged_groups = $wpdb->get_results( "SELECT id as group_id FROM {$bp->groups->table_name} WHERE ( name LIKE '%%$filter%%' OR description LIKE '%%$filter%%' ) {$hidden_sql} {$order_sql} {$pag_sql}" );
@@ -280,7 +236,7 @@ class BP_Groups_Group {
280
 
281
  $members = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name_members} WHERE group_id = %d", $group_id ) );
282
 
283
- if ( empty( $members ) )
284
  return false;
285
 
286
  return true;
@@ -295,7 +251,7 @@ class BP_Groups_Group {
295
  function get_membership_requests( $group_id, $limit = null, $page = null ) {
296
  global $wpdb, $bp;
297
 
298
- if ( !empty( $limit ) && !empty( $page ) ) {
299
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
300
  }
301
 
@@ -308,8 +264,7 @@ class BP_Groups_Group {
308
  function get( $type = 'newest', $per_page = null, $page = null, $user_id = 0, $search_terms = false, $include = false, $populate_extras = true, $exclude = false, $show_hidden = false ) {
309
  global $wpdb, $bp;
310
 
311
- $sql = array();
312
- $total_sql = array();
313
 
314
  $sql['select'] = "SELECT g.*, gm1.meta_value AS total_member_count, gm2.meta_value AS last_activity";
315
  $sql['from'] = " FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2,";
@@ -369,11 +324,11 @@ class BP_Groups_Group {
369
  break;
370
  }
371
 
372
- if ( !empty( $per_page ) && !empty( $page ) )
373
  $sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page), intval( $per_page ) );
374
 
375
- // Get paginated results
376
- $paged_groups_sql = apply_filters( 'bp_groups_get_paged_groups_sql', join( ' ', (array) $sql ), $sql );
377
  $paged_groups = $wpdb->get_results( $paged_groups_sql );
378
 
379
  $total_sql['select'] = "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name} g, {$bp->groups->table_name_members} gm1, {$bp->groups->table_name_groupmeta} gm2";
@@ -390,13 +345,10 @@ class BP_Groups_Group {
390
  if ( !empty( $user_id ) )
391
  $total_sql['where'][] = "m.group_id = g.id AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0";
392
 
393
- // Already escaped in the paginated results block
394
- if ( ! empty( $include ) )
395
- $total_sql['where'][] = "g.id IN ({$include})";
396
-
397
- // Already escaped in the paginated results block
398
- if ( ! empty( $exclude ) )
399
- $total_sql['where'][] = "g.id NOT IN ({$exclude})";
400
 
401
  $total_sql['where'][] = "g.id = gm1.group_id";
402
  $total_sql['where'][] = "g.id = gm2.group_id";
@@ -405,25 +357,19 @@ class BP_Groups_Group {
405
  $t_sql = $total_sql['select'];
406
 
407
  if ( !empty( $total_sql['where'] ) )
408
- $t_sql .= " WHERE " . join( ' AND ', (array) $total_sql['where'] );
409
 
410
- // Get total group results
411
- $total_groups_sql = apply_filters( 'bp_groups_get_total_groups_sql', $t_sql, $total_sql );
412
  $total_groups = $wpdb->get_var( $total_groups_sql );
413
 
414
- $group_ids = array();
415
- foreach ( (array) $paged_groups as $group ) {
416
- $group_ids[] = $group->id;
417
- }
418
-
419
- // Populate some extra information instead of querying each time in the loop
420
  if ( !empty( $populate_extras ) ) {
421
- $group_ids = $wpdb->escape( join( ',', (array) $group_ids ) );
 
 
422
  $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, $type );
423
  }
424
-
425
- // Grab all groupmeta
426
- bp_groups_update_meta_cache( $group_ids );
427
 
428
  unset( $sql, $total_sql );
429
 
@@ -433,14 +379,14 @@ class BP_Groups_Group {
433
  function get_by_most_forum_topics( $limit = null, $page = null, $user_id = 0, $search_terms = false, $populate_extras = true, $exclude = false ) {
434
  global $wpdb, $bp, $bbdb;
435
 
436
- if ( empty( $bbdb ) )
437
  do_action( 'bbpress_init' );
438
 
439
- if ( !empty( $limit ) && !empty( $page ) ) {
440
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
441
  }
442
 
443
- if ( !is_user_logged_in() || ( !bp_current_user_can( 'bp_moderate' ) && ( $user_id != bp_loggedin_user_id() ) ) )
444
  $hidden_sql = " AND g.status != 'hidden'";
445
 
446
  if ( !empty( $search_terms ) ) {
@@ -453,7 +399,7 @@ class BP_Groups_Group {
453
  $exclude_sql = " AND g.id NOT IN ({$exclude})";
454
  }
455
 
456
- if ( !empty( $user_id ) ) {
457
  $user_id = $wpdb->escape( $user_id );
458
  $paged_groups = $wpdb->get_results( "SELECT DISTINCT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bp->groups->table_name_members} m, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) AND f.topics > 0 {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} ORDER BY f.topics DESC {$pag_sql}" );
459
  $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) AND f.topics > 0 {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql}" );
@@ -463,8 +409,8 @@ class BP_Groups_Group {
463
  }
464
 
465
  if ( !empty( $populate_extras ) ) {
466
- foreach ( (array) $paged_groups as $group ) $group_ids[] = $group->id;
467
- $group_ids = $wpdb->escape( join( ',', (array) $group_ids ) );
468
  $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, 'newest' );
469
  }
470
 
@@ -474,17 +420,17 @@ class BP_Groups_Group {
474
  function get_by_most_forum_posts( $limit = null, $page = null, $search_terms = false, $populate_extras = true, $exclude = false ) {
475
  global $wpdb, $bp, $bbdb;
476
 
477
- if ( empty( $bbdb ) )
478
  do_action( 'bbpress_init' );
479
 
480
- if ( !empty( $limit ) && !empty( $page ) ) {
481
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
482
  }
483
 
484
- if ( !is_user_logged_in() || ( !bp_current_user_can( 'bp_moderate' ) && ( $user_id != bp_loggedin_user_id() ) ) )
485
  $hidden_sql = " AND g.status != 'hidden'";
486
 
487
- if ( !empty( $search_terms ) ) {
488
  $search_terms = like_escape( $wpdb->escape( $search_terms ) );
489
  $search_sql = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )";
490
  }
@@ -494,7 +440,7 @@ class BP_Groups_Group {
494
  $exclude_sql = " AND g.id NOT IN ({$exclude})";
495
  }
496
 
497
- if ( !empty( $user_id ) ) {
498
  $user_id = $wpdb->escape( $user_id );
499
  $paged_groups = $wpdb->get_results( "SELECT DISTINCT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bp->groups->table_name_members} m, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} ORDER BY f.posts ASC {$pag_sql}" );
500
  $total_groups = $wpdb->get_results( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bp->groups->table_name_members} m, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) AND f.posts > 0 {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} " );
@@ -504,8 +450,8 @@ class BP_Groups_Group {
504
  }
505
 
506
  if ( !empty( $populate_extras ) ) {
507
- foreach ( (array) $paged_groups as $group ) $group_ids[] = $group->id;
508
- $group_ids = $wpdb->escape( join( ',', (array) $group_ids ) );
509
  $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, 'newest' );
510
  }
511
 
@@ -531,12 +477,12 @@ class BP_Groups_Group {
531
  $exclude_sql = " AND g.id NOT IN ({$exclude})";
532
  }
533
 
534
- if ( !bp_current_user_can( 'bp_moderate' ) )
535
  $hidden_sql = $wpdb->prepare( " AND status != 'hidden'");
536
 
537
  $letter = like_escape( $wpdb->escape( $letter ) );
538
 
539
- if ( !empty( $limit ) && !empty( $page ) ) {
540
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
541
  $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND g.name LIKE '$letter%%' {$hidden_sql} {$search_sql} {$exclude_sql}" ) );
542
  }
@@ -544,8 +490,8 @@ class BP_Groups_Group {
544
  $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND g.name LIKE '$letter%%' {$hidden_sql} {$search_sql} {$exclude_sql} ORDER BY g.name ASC {$pag_sql}" ) );
545
 
546
  if ( !empty( $populate_extras ) ) {
547
- foreach ( (array) $paged_groups as $group ) $group_ids[] = $group->id;
548
- $group_ids = $wpdb->escape( join( ',', (array) $group_ids ) );
549
  $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, 'newest' );
550
  }
551
 
@@ -555,15 +501,13 @@ class BP_Groups_Group {
555
  function get_random( $limit = null, $page = null, $user_id = 0, $search_terms = false, $populate_extras = true, $exclude = false ) {
556
  global $wpdb, $bp;
557
 
558
- $pag_sql = $hidden_sql = $search_sql = $exclude_sql = '';
559
-
560
- if ( !empty( $limit ) && !empty( $page ) )
561
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
562
 
563
- if ( !is_user_logged_in() || ( !bp_current_user_can( 'bp_moderate' ) && ( $user_id != bp_loggedin_user_id() ) ) )
564
  $hidden_sql = "AND g.status != 'hidden'";
565
 
566
- if ( !empty( $search_terms ) ) {
567
  $search_terms = like_escape( $wpdb->escape( $search_terms ) );
568
  $search_sql = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )";
569
  }
@@ -573,7 +517,7 @@ class BP_Groups_Group {
573
  $exclude_sql = " AND g.id NOT IN ({$exclude})";
574
  }
575
 
576
- if ( !empty( $user_id ) ) {
577
  $user_id = $wpdb->escape( $user_id );
578
  $paged_groups = $wpdb->get_results( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} ORDER BY rand() {$pag_sql}" );
579
  $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m LEFT JOIN {$bp->groups->table_name_groupmeta} gm ON m.group_id = gm.group_id INNER JOIN {$bp->groups->table_name} g ON m.group_id = g.id WHERE gm.meta_key = 'last_activity'{$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql}" );
@@ -583,8 +527,8 @@ class BP_Groups_Group {
583
  }
584
 
585
  if ( !empty( $populate_extras ) ) {
586
- foreach ( (array) $paged_groups as $group ) $group_ids[] = $group->id;
587
- $group_ids = $wpdb->escape( join( ',', (array) $group_ids ) );
588
  $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, 'newest' );
589
  }
590
 
@@ -597,26 +541,24 @@ class BP_Groups_Group {
597
  if ( empty( $group_ids ) )
598
  return $paged_groups;
599
 
600
- // Fetch the logged in users status within each group
601
- $user_status = $wpdb->get_col( $wpdb->prepare( "SELECT group_id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id IN ( {$group_ids} ) AND is_confirmed = 1 AND is_banned = 0", bp_loggedin_user_id() ) );
602
  for ( $i = 0, $count = count( $paged_groups ); $i < $count; ++$i ) {
603
  $paged_groups[$i]->is_member = false;
604
 
605
- foreach ( (array) $user_status as $group_id ) {
606
- if ( $group_id == $paged_groups[$i]->id ) {
607
  $paged_groups[$i]->is_member = true;
608
- }
609
  }
610
  }
611
 
612
- $user_banned = $wpdb->get_col( $wpdb->prepare( "SELECT group_id FROM {$bp->groups->table_name_members} WHERE is_banned = 1 AND user_id = %d AND group_id IN ( {$group_ids} )", bp_loggedin_user_id() ) );
613
  for ( $i = 0, $count = count( $paged_groups ); $i < $count; ++$i ) {
614
  $paged_groups[$i]->is_banned = false;
615
 
616
- foreach ( (array) $user_banned as $group_id ) {
617
- if ( $group_id == $paged_groups[$i]->id ) {
618
  $paged_groups[$i]->is_banned = true;
619
- }
620
  }
621
  }
622
 
@@ -633,7 +575,7 @@ class BP_Groups_Group {
633
  global $wpdb, $bp;
634
 
635
  $hidden_sql = '';
636
- if ( !bp_current_user_can( 'bp_moderate' ) )
637
  $hidden_sql = "WHERE status != 'hidden'";
638
 
639
  return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name} {$hidden_sql}" ) );
@@ -645,24 +587,7 @@ class BP_Groups_Group {
645
  if ( 'unreplied' == $type )
646
  $bp->groups->filter_sql = ' AND t.topic_posts = 1';
647
 
648
- /**
649
- * Provide backward-compatibility for the groups_total_public_forum_topic_count SQL filter.
650
- * Developers: DO NOT use this filter. It will be removed in BP 1.7. Instead, use
651
- * get_global_forum_topic_count_extra_sql. See https://buddypress.trac.wordpress.org/ticket/4306
652
- */
653
- $maybe_extra_sql = apply_filters( 'groups_total_public_forum_topic_count', $bp->groups->filter_sql, $type );
654
-
655
- if ( is_int( $maybe_extra_sql ) )
656
- $extra_sql = $bp->groups->filter_sql;
657
- else
658
- $extra_sql = $maybe_extra_sql;
659
-
660
- // Developers: use this filter instead
661
- $extra_sql = apply_filters( 'get_global_forum_topic_count_extra_sql', $bp->groups->filter_sql, $type );
662
-
663
- // Make sure the $extra_sql begins with an AND
664
- if ( 'AND' != substr( trim( strtoupper( $extra_sql ) ), 0, 3 ) )
665
- $extra_sql = ' AND ' . $extra_sql;
666
 
667
  return $wpdb->get_var( "SELECT COUNT(t.topic_id) FROM {$bbdb->topics} AS t, {$bp->groups->table_name} AS g LEFT JOIN {$bp->groups->table_name_groupmeta} AS gm ON g.id = gm.group_id WHERE (gm.meta_key = 'forum_id' AND gm.meta_value = t.forum_id) AND g.status = 'public' AND t.topic_status = '0' AND t.topic_sticky != '2' {$extra_sql} " );
668
  }
@@ -673,11 +598,12 @@ class BP_Groups_Group {
673
  return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 AND is_banned = 0", $group_id ) );
674
  }
675
 
 
676
  /**
677
  * Get a total count of all topics of a given status, across groups/forums
678
  *
679
  * @package BuddyPress
680
- * @since BuddyPress (1.5)
681
  *
682
  * @param str $status 'public', 'private', 'hidden', 'all' Which group types to count
683
  * @return int The topic count
@@ -721,7 +647,7 @@ class BP_Groups_Group {
721
  }
722
  }
723
 
724
- class BP_Groups_Member {
725
  var $id;
726
  var $group_id;
727
  var $user_id;
@@ -734,27 +660,27 @@ class BP_Groups_Member {
734
  var $is_confirmed;
735
  var $comments;
736
  var $invite_sent;
 
737
  var $user;
738
 
739
- function __construct( $user_id = 0, $group_id = 0, $id = false, $populate = true ) {
 
 
740
 
741
- // User and group are not empty, and ID is
742
- if ( !empty( $user_id ) && !empty( $group_id ) && empty( $id ) ) {
743
- $this->user_id = $user_id;
744
  $this->group_id = $group_id;
745
 
746
- if ( !empty( $populate ) ) {
747
  $this->populate();
748
- }
749
  }
750
 
751
- // ID is not empty
752
- if ( !empty( $id ) ) {
753
  $this->id = $id;
754
 
755
- if ( !empty( $populate ) ) {
756
  $this->populate();
757
- }
758
  }
759
  }
760
 
@@ -764,12 +690,12 @@ class BP_Groups_Member {
764
  if ( $this->user_id && $this->group_id && !$this->id )
765
  $sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $this->user_id, $this->group_id );
766
 
767
- if ( !empty( $this->id ) )
768
  $sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name_members} WHERE id = %d", $this->id );
769
 
770
  $member = $wpdb->get_row($sql);
771
 
772
- if ( !empty( $member ) ) {
773
  $this->id = $member->id;
774
  $this->group_id = $member->group_id;
775
  $this->user_id = $member->user_id;
@@ -804,18 +730,12 @@ class BP_Groups_Member {
804
 
805
  do_action_ref_array( 'groups_member_before_save', array( &$this ) );
806
 
807
- if ( !empty( $this->id ) ) {
808
  $sql = $wpdb->prepare( "UPDATE {$bp->groups->table_name_members} SET inviter_id = %d, is_admin = %d, is_mod = %d, is_banned = %d, user_title = %s, date_modified = %s, is_confirmed = %d, comments = %s, invite_sent = %d WHERE id = %d", $this->inviter_id, $this->is_admin, $this->is_mod, $this->is_banned, $this->user_title, $this->date_modified, $this->is_confirmed, $this->comments, $this->invite_sent, $this->id );
809
- } else {
810
- // Ensure that user is not already a member of the group before inserting
811
- if ( $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d LIMIT 1", $this->user_id, $this->group_id ) ) ) {
812
- return false;
813
- }
814
-
815
  $sql = $wpdb->prepare( "INSERT INTO {$bp->groups->table_name_members} ( user_id, group_id, inviter_id, is_admin, is_mod, is_banned, user_title, date_modified, is_confirmed, comments, invite_sent ) VALUES ( %d, %d, %d, %d, %d, %d, %s, %s, %d, %s, %d )", $this->user_id, $this->group_id, $this->inviter_id, $this->is_admin, $this->is_mod, $this->is_banned, $this->user_title, $this->date_modified, $this->is_confirmed, $this->comments, $this->invite_sent );
816
- }
817
 
818
- if ( !$wpdb->query( $sql ) )
819
  return false;
820
 
821
  $this->id = $wpdb->insert_id;
@@ -827,14 +747,14 @@ class BP_Groups_Member {
827
 
828
  function promote( $status = 'mod' ) {
829
  if ( 'mod' == $status ) {
830
- $this->is_admin = 0;
831
- $this->is_mod = 1;
832
  $this->user_title = __( 'Group Mod', 'buddypress' );
833
  }
834
 
835
  if ( 'admin' == $status ) {
836
- $this->is_admin = 1;
837
- $this->is_mod = 0;
838
  $this->user_title = __( 'Group Admin', 'buddypress' );
839
  }
840
 
@@ -842,16 +762,17 @@ class BP_Groups_Member {
842
  }
843
 
844
  function demote() {
845
- $this->is_mod = 0;
846
- $this->is_admin = 0;
847
  $this->user_title = false;
848
 
849
  return $this->save();
850
  }
851
 
852
  function ban() {
 
853
 
854
- if ( !empty( $this->is_admin ) )
855
  return false;
856
 
857
  $this->is_mod = 0;
@@ -861,39 +782,42 @@ class BP_Groups_Member {
861
 
862
  $group_count = bp_get_user_meta( $this->user_id, 'total_group_count', true );
863
  if ( !empty( $group_count ) )
864
- bp_update_user_meta( $this->user_id, 'total_group_count', (int) $group_count - 1 );
865
 
866
  return $this->save();
867
  }
868
 
869
  function unban() {
 
870
 
871
- if ( !empty( $this->is_admin ) )
872
  return false;
873
 
874
  $this->is_banned = 0;
875
 
876
  groups_update_groupmeta( $this->group_id, 'total_member_count', ( (int) groups_get_groupmeta( $this->group_id, 'total_member_count' ) + 1 ) );
877
- bp_update_user_meta( $this->user_id, 'total_group_count', (int) bp_get_user_meta( $this->user_id, 'total_group_count', true ) + 1 );
878
 
879
  return $this->save();
880
  }
881
 
882
  function accept_invite() {
 
883
 
884
  $this->inviter_id = 0;
885
  $this->is_confirmed = 1;
886
  $this->date_modified = bp_core_current_time();
887
 
888
- bp_update_user_meta( $this->user_id, 'total_group_count', (int) bp_get_user_meta( $this->user_id, 'total_group_count', true ) + 1 );
889
  }
890
 
891
  function accept_request() {
 
892
 
893
  $this->is_confirmed = 1;
894
  $this->date_modified = bp_core_current_time();
895
 
896
- bp_update_user_meta( $this->user_id, 'total_group_count', (int) bp_get_user_meta( $this->user_id, 'total_group_count', true ) + 1 );
897
  }
898
 
899
  function remove() {
@@ -908,12 +832,12 @@ class BP_Groups_Member {
908
 
909
  $group_count = bp_get_user_meta( $this->user_id, 'total_group_count', true );
910
  if ( !empty( $group_count ) )
911
- bp_update_user_meta( $this->user_id, 'total_group_count', (int) $group_count - 1 );
912
 
913
  return $result;
914
  }
915
 
916
- /** Static Methods ********************************************************/
917
 
918
  function delete( $user_id, $group_id ) {
919
  global $wpdb, $bp;
@@ -925,11 +849,11 @@ class BP_Groups_Member {
925
  global $wpdb, $bp;
926
 
927
  $pag_sql = '';
928
- if ( !empty( $limit ) && !empty( $page ) )
929
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
930
 
931
  // If the user is logged in and viewing their own groups, we can show hidden and private groups
932
- if ( $user_id != bp_loggedin_user_id() ) {
933
  $group_sql = $wpdb->prepare( "SELECT DISTINCT m.group_id FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0{$pag_sql}", $user_id );
934
  $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) );
935
  } else {
@@ -947,15 +871,15 @@ class BP_Groups_Member {
947
 
948
  $pag_sql = $hidden_sql = $filter_sql = '';
949
 
950
- if ( !empty( $limit ) && !empty( $page ) )
951
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
952
 
953
- if ( !empty( $filter ) ) {
954
  $filter = like_escape( $wpdb->escape( $filter ) );
955
  $filter_sql = " AND ( g.name LIKE '%%{$filter}%%' OR g.description LIKE '%%{$filter}%%' )";
956
  }
957
 
958
- if ( $user_id != bp_loggedin_user_id() )
959
  $hidden_sql = " AND g.status != 'hidden'";
960
 
961
  $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count'{$hidden_sql}{$filter_sql} AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0 ORDER BY m.date_modified DESC {$pag_sql}", $user_id ) );
@@ -969,15 +893,15 @@ class BP_Groups_Member {
969
 
970
  $pag_sql = $hidden_sql = $filter_sql = '';
971
 
972
- if ( !empty( $limit ) && !empty( $page ) )
973
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
974
 
975
- if ( !empty( $filter ) ) {
976
  $filter = like_escape( $wpdb->escape( $filter ) );
977
  $filter_sql = " AND ( g.name LIKE '%%{$filter}%%' OR g.description LIKE '%%{$filter}%%' )";
978
  }
979
 
980
- if ( $user_id != bp_loggedin_user_id() )
981
  $hidden_sql = " AND g.status != 'hidden'";
982
 
983
  $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count'{$hidden_sql}{$filter_sql} AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0 AND m.is_admin = 1 ORDER BY m.date_modified ASC {$pag_sql}", $user_id ) );
@@ -991,15 +915,15 @@ class BP_Groups_Member {
991
 
992
  $pag_sql = $hidden_sql = $filter_sql = '';
993
 
994
- if ( !empty( $limit ) && !empty( $page ) )
995
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
996
 
997
- if ( !empty( $filter ) ) {
998
  $filter = like_escape( $wpdb->escape( $filter ) );
999
  $filter_sql = " AND ( g.name LIKE '%%{$filter}%%' OR g.description LIKE '%%{$filter}%%' )";
1000
  }
1001
 
1002
- if ( $user_id != bp_loggedin_user_id() )
1003
  $hidden_sql = " AND g.status != 'hidden'";
1004
 
1005
  $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count'{$hidden_sql}{$filter_sql} AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0 AND m.is_mod = 1 ORDER BY m.date_modified ASC {$pag_sql}", $user_id ) );
@@ -1011,10 +935,10 @@ class BP_Groups_Member {
1011
  function total_group_count( $user_id = 0 ) {
1012
  global $bp, $wpdb;
1013
 
1014
- if ( empty( $user_id ) )
1015
- $user_id = bp_displayed_user_id();
1016
 
1017
- if ( $user_id != bp_loggedin_user_id() && !bp_current_user_can( 'bp_moderate' ) ) {
1018
  return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) );
1019
  } else {
1020
  return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) );
@@ -1037,7 +961,7 @@ class BP_Groups_Member {
1037
  function check_has_invite( $user_id, $group_id, $type = 'sent' ) {
1038
  global $wpdb, $bp;
1039
 
1040
- if ( empty( $user_id ) )
1041
  return false;
1042
 
1043
  $sql = "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND inviter_id != 0";
@@ -1051,7 +975,7 @@ class BP_Groups_Member {
1051
  function delete_invite( $user_id, $group_id ) {
1052
  global $wpdb, $bp;
1053
 
1054
- if ( empty( $user_id ) )
1055
  return false;
1056
 
1057
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND inviter_id != 0 AND invite_sent = 1", $user_id, $group_id ) );
@@ -1060,7 +984,7 @@ class BP_Groups_Member {
1060
  function delete_request( $user_id, $group_id ) {
1061
  global $wpdb, $bp;
1062
 
1063
- if ( empty( $user_id ) )
1064
  return false;
1065
 
1066
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND inviter_id = 0 AND invite_sent = 0", $user_id, $group_id ) );
@@ -1069,7 +993,7 @@ class BP_Groups_Member {
1069
  function check_is_admin( $user_id, $group_id ) {
1070
  global $wpdb, $bp;
1071
 
1072
- if ( empty( $user_id ) )
1073
  return false;
1074
 
1075
  return $wpdb->query( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_admin = 1 AND is_banned = 0", $user_id, $group_id ) );
@@ -1078,7 +1002,7 @@ class BP_Groups_Member {
1078
  function check_is_mod( $user_id, $group_id ) {
1079
  global $wpdb, $bp;
1080
 
1081
- if ( empty( $user_id ) )
1082
  return false;
1083
 
1084
  return $wpdb->query( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_mod = 1 AND is_banned = 0", $user_id, $group_id ) );
@@ -1087,7 +1011,7 @@ class BP_Groups_Member {
1087
  function check_is_member( $user_id, $group_id ) {
1088
  global $wpdb, $bp;
1089
 
1090
- if ( empty( $user_id ) )
1091
  return false;
1092
 
1093
  return $wpdb->query( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 1 AND is_banned = 0", $user_id, $group_id ) );
@@ -1096,7 +1020,7 @@ class BP_Groups_Member {
1096
  function check_is_banned( $user_id, $group_id ) {
1097
  global $wpdb, $bp;
1098
 
1099
- if ( empty( $user_id ) )
1100
  return false;
1101
 
1102
  return $wpdb->get_var( $wpdb->prepare( "SELECT is_banned FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $user_id, $group_id ) );
@@ -1114,7 +1038,7 @@ class BP_Groups_Member {
1114
  function check_is_creator( $user_id, $group_id ) {
1115
  global $bp, $wpdb;
1116
 
1117
- if ( empty( $user_id ) )
1118
  return false;
1119
 
1120
  return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name} WHERE creator_id = %d AND id = %d", $user_id, $group_id ) );
@@ -1123,7 +1047,7 @@ class BP_Groups_Member {
1123
  function check_for_membership_request( $user_id, $group_id ) {
1124
  global $wpdb, $bp;
1125
 
1126
- if ( empty( $user_id ) )
1127
  return false;
1128
 
1129
  return $wpdb->query( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND is_banned = 0 AND inviter_id = 0", $user_id, $group_id ) );
@@ -1168,19 +1092,19 @@ class BP_Groups_Member {
1168
  global $bp, $wpdb;
1169
 
1170
  $pag_sql = '';
1171
- if ( !empty( $limit ) && !empty( $page ) )
1172
  $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
1173
 
1174
  $exclude_admins_sql = '';
1175
- if ( !empty( $exclude_admins_mods ) )
1176
  $exclude_admins_sql = $wpdb->prepare( "AND is_admin = 0 AND is_mod = 0" );
1177
 
1178
  $banned_sql = '';
1179
- if ( !empty( $exclude_banned ) )
1180
  $banned_sql = $wpdb->prepare( " AND is_banned = 0" );
1181
 
1182
  $exclude_sql = '';
1183
- if ( !empty( $exclude ) )
1184
  $exclude_sql = $wpdb->prepare( " AND m.user_id NOT IN ({$exclude})" );
1185
 
1186
  if ( bp_is_active( 'xprofile' ) )
@@ -1188,7 +1112,7 @@ class BP_Groups_Member {
1188
  else
1189
  $members = $wpdb->get_results( apply_filters( 'bp_group_members_user_join_filter', $wpdb->prepare( "SELECT m.user_id, m.date_modified, m.is_banned, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$bp->groups->table_name_members} m, {$wpdb->users} u WHERE u.ID = m.user_id AND group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_admins_sql} {$exclude_sql} ORDER BY m.date_modified DESC {$pag_sql}", $group_id ) ) );
1190
 
1191
- if ( empty( $members ) )
1192
  return false;
1193
 
1194
  if ( empty( $pag_sql ) )
@@ -1196,19 +1120,16 @@ class BP_Groups_Member {
1196
  else
1197
  $total_member_count = $wpdb->get_var( apply_filters( 'bp_group_members_count_user_join_filter', $wpdb->prepare( "SELECT COUNT(user_id) FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_admins_sql} {$exclude_sql}", $group_id ) ) );
1198
 
1199
- // Fetch whether or not the user is a friend
1200
- foreach ( (array) $members as $user )
1201
- $user_ids[] = $user->user_id;
1202
-
1203
- $user_ids = $wpdb->escape( join( ',', (array) $user_ids ) );
1204
 
1205
  if ( bp_is_active( 'friends' ) ) {
1206
- $friend_status = $wpdb->get_results( $wpdb->prepare( "SELECT initiator_user_id, friend_user_id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id IN ( {$user_ids} ) ) OR (initiator_user_id IN ( {$user_ids} ) AND friend_user_id = %d )", bp_loggedin_user_id(), bp_loggedin_user_id() ) );
1207
  for ( $i = 0, $count = count( $members ); $i < $count; ++$i ) {
1208
- foreach ( (array) $friend_status as $status ) {
1209
- if ( $status->initiator_user_id == $members[$i]->user_id || $status->friend_user_id == $members[$i]->user_id ) {
1210
  $members[$i]->is_friend = $status->is_confirmed;
1211
- }
1212
  }
1213
  }
1214
  }
@@ -1265,16 +1186,8 @@ class BP_Groups_Member {
1265
  class BP_Group_Extension {
1266
  var $name = false;
1267
  var $slug = false;
1268
-
1269
- // The name/slug of the Group Admin tab for this extension
1270
- var $admin_name = '';
1271
- var $admin_slug = '';
1272
 
1273
- // The name/slug of the Group Creation tab for this extension
1274
- var $create_name = '';
1275
- var $create_slug = '';
1276
-
1277
- // Will this extension be visible to non-members of a group? Options: public/private
1278
  var $visibility = 'public';
1279
 
1280
  var $create_step_position = 81;
@@ -1307,34 +1220,16 @@ class BP_Group_Extension {
1307
 
1308
  function _register() {
1309
  global $bp;
1310
-
1311
- // If admin/create names and slugs are not provided, they fall back on the main
1312
- // name and slug for the extension
1313
- if ( !$this->admin_name ) {
1314
- $this->admin_name = $this->name;
1315
- }
1316
-
1317
- if ( !$this->admin_slug ) {
1318
- $this->admin_slug = $this->slug;
1319
- }
1320
-
1321
- if ( !$this->create_name ) {
1322
- $this->create_name = $this->name;
1323
- }
1324
-
1325
- if ( !$this->create_slug ) {
1326
- $this->create_slug = $this->slug;
1327
- }
1328
 
1329
  if ( !empty( $this->enable_create_step ) ) {
1330
  // Insert the group creation step for the new group extension
1331
- $bp->groups->group_creation_steps[$this->create_slug] = array( 'name' => $this->create_name, 'slug' => $this->create_slug, 'position' => $this->create_step_position );
1332
 
1333
  // Attach the group creation step display content action
1334
  add_action( 'groups_custom_create_steps', array( &$this, 'create_screen' ) );
1335
 
1336
  // Attach the group creation step save content action
1337
- add_action( 'groups_create_group_step_save_' . $this->create_slug, array( &$this, 'create_screen_save' ) );
1338
  }
1339
 
1340
  // When we are viewing a single group, add the group extension nav item
@@ -1357,11 +1252,11 @@ class BP_Group_Extension {
1357
  }
1358
 
1359
  // Construct the admin edit tab for the new group extension
1360
- if ( !empty( $this->enable_edit_item ) && bp_is_item_admin() ) {
1361
- add_action( 'groups_admin_tabs', create_function( '$current, $group_slug', '$selected = ""; if ( "' . esc_attr( $this->admin_slug ) . '" == $current ) $selected = " class=\"current\""; echo "<li{$selected}><a href=\"' . trailingslashit( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/{$group_slug}/admin/' . esc_attr( $this->admin_slug ) ) . '\">' . esc_attr( $this->admin_name ) . '</a></li>";' ), 10, 2 );
1362
 
1363
  // Catch the edit screen and forward it to the plugin template
1364
- if ( bp_is_groups_component() && bp_is_current_action( 'admin' ) && bp_is_action_variable( $this->admin_slug, 0 ) ) {
1365
  // Check whether the user is saving changes
1366
  $this->edit_screen_save();
1367
 
@@ -1385,12 +1280,12 @@ class BP_Group_Extension {
1385
  }
1386
 
1387
  function bp_register_group_extension( $group_extension_class ) {
 
1388
 
1389
  if ( !class_exists( $group_extension_class ) )
1390
  return false;
1391
 
1392
- // Register the group extension on the bp_init action so we have access
1393
- // to all plugins.
1394
  add_action( 'bp_init', create_function( '', '$extension = new ' . $group_extension_class . '; add_action( "bp_actions", array( &$extension, "_register" ), 8 );' ), 11 );
1395
  }
1396
 
1
  <?php
 
 
 
 
 
 
 
 
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
5
+ Class BP_Groups_Group {
6
  var $id;
7
  var $creator_id;
8
  var $name;
16
  var $mods;
17
  var $total_member_count;
18
 
19
+ function bp_groups_group( $id = null ) {
20
+ $this->__construct($id);
21
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  function __construct( $id = null ) {
24
+ if ( $id ) {
25
  $this->id = $id;
26
  $this->populate();
27
  }
30
  function populate() {
31
  global $wpdb, $bp;
32
 
33
+ if ( $group = $wpdb->get_row( $wpdb->prepare( "SELECT g.*, gm.meta_value as last_activity, gm2.meta_value as total_member_count FROM {$bp->groups->table_name} g, {$bp->groups->table_name_groupmeta} gm, {$bp->groups->table_name_groupmeta} gm2 WHERE g.id = gm.group_id AND g.id = gm2.group_id AND gm.meta_key = 'last_activity' AND gm2.meta_key = 'total_member_count' AND g.id = %d", $this->id ) ) ) {
 
 
34
  $this->id = $group->id;
35
  $this->creator_id = $group->creator_id;
36
  $this->name = stripslashes($group->name);
39
  $this->status = $group->status;
40
  $this->enable_forum = $group->enable_forum;
41
  $this->date_created = $group->date_created;
42
+ $this->last_activity = $group->last_activity;
43
+ $this->total_member_count = $group->total_member_count;
44
+ $this->is_member = BP_Groups_Member::check_is_member( $bp->loggedin_user->id, $this->id );
 
 
 
 
 
 
 
 
 
 
45
 
46
  // Get group admins and mods
47
  $admin_mods = $wpdb->get_results( apply_filters( 'bp_group_admin_mods_user_join_filter', $wpdb->prepare( "SELECT u.ID as user_id, u.user_login, u.user_email, u.user_nicename, m.is_admin, m.is_mod FROM {$wpdb->users} u, {$bp->groups->table_name_members} m WHERE u.ID = m.user_id AND m.group_id = %d AND ( m.is_admin = 1 OR m.is_mod = 1 )", $this->id ) ) );
48
+ foreach( (array)$admin_mods as $user ) {
49
+ if ( (int)$user->is_admin )
50
  $this->admins[] = $user;
51
  else
52
  $this->mods[] = $user;
119
  $this->id = $wpdb->insert_id;
120
 
121
  do_action_ref_array( 'groups_group_after_save', array( &$this ) );
 
 
122
 
123
  return true;
124
  }
130
  groups_delete_groupmeta( $this->id );
131
 
132
  // Fetch the user IDs of all the members of the group
133
+ $user_ids = BP_Groups_Member::get_group_member_ids( $this->id );
134
+ $user_ids = implode( ',', (array)$user_ids );
135
 
136
  // Modify group count usermeta for members
137
+ $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->usermeta} SET meta_value = meta_value - 1 WHERE meta_key = 'total_group_count' AND user_id IN ( {$user_ids} )" ) );
138
 
139
  // Now delete all group member entries
140
  BP_Groups_Member::delete_all( $this->id );
141
 
142
+ do_action_ref_array( 'bp_groups_delete_group', array( &$this ) );
 
 
143
 
144
  // Finally remove the group entry from the DB
145
  if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name} WHERE id = %d", $this->id ) ) )
148
  return true;
149
  }
150
 
151
+ /* Static Functions */
152
 
153
  function group_exists( $slug, $table_name = false ) {
154
  global $wpdb, $bp;
155
 
156
+ if ( !$table_name )
157
  $table_name = $bp->groups->table_name;
158
 
159
+ if ( !$slug )
160
  return false;
161
 
162
  return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$table_name} WHERE slug = %s", $slug ) );
174
  function filter_user_groups( $filter, $user_id = 0, $order = false, $limit = null, $page = null ) {
175
  global $wpdb, $bp;
176
 
177
+ if ( !$user_id )
178
+ $user_id = $bp->displayed_user->id;
179
 
180
  $filter = like_escape( $wpdb->escape( $filter ) );
181
 
182
+ if ( $limit && $page )
183
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
184
 
185
  // Get all the group ids for the current user's groups.
186
  $gids = BP_Groups_Member::get_group_ids( $user_id );
187
 
188
+ if ( !$gids['groups'] )
189
  return false;
190
 
191
  $gids = implode( ',', $gids['groups'] );
201
 
202
  $filter = like_escape( $wpdb->escape( $filter ) );
203
 
204
+ if ( $limit && $page )
205
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
206
 
207
+ if ( $sort_by && $order ) {
208
+ $sort_by = $wpdb->escape( $sort_by );
209
+ $order = $wpdb->escape( $order );
210
  $order_sql = "ORDER BY $sort_by $order";
211
  }
212
 
213
+ if ( !is_super_admin() )
214
  $hidden_sql = "AND status != 'hidden'";
215
 
216
  $paged_groups = $wpdb->get_results( "SELECT id as group_id FROM {$bp->groups->table_name} WHERE ( name LIKE '%%$filter%%' OR description LIKE '%%$filter%%' ) {$hidden_sql} {$order_sql} {$pag_sql}" );
236
 
237
  $members = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name_members} WHERE group_id = %d", $group_id ) );
238
 
239
+ if ( !$members )
240
  return false;
241
 
242
  return true;
251
  function get_membership_requests( $group_id, $limit = null, $page = null ) {
252
  global $wpdb, $bp;
253
 
254
+ if ( $limit && $page ) {
255
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
256
  }
257
 
264
  function get( $type = 'newest', $per_page = null, $page = null, $user_id = 0, $search_terms = false, $include = false, $populate_extras = true, $exclude = false, $show_hidden = false ) {
265
  global $wpdb, $bp;
266
 
267
+ $sql = array();
 
268
 
269
  $sql['select'] = "SELECT g.*, gm1.meta_value AS total_member_count, gm2.meta_value AS last_activity";
270
  $sql['from'] = " FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2,";
324
  break;
325
  }
326
 
327
+ if ( $per_page && $page )
328
  $sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page), intval( $per_page ) );
329
 
330
+ /* Get paginated results */
331
+ $paged_groups_sql = apply_filters( 'bp_groups_get_paged_groups_sql', join( ' ', (array)$sql ), $sql );
332
  $paged_groups = $wpdb->get_results( $paged_groups_sql );
333
 
334
  $total_sql['select'] = "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name} g, {$bp->groups->table_name_members} gm1, {$bp->groups->table_name_groupmeta} gm2";
345
  if ( !empty( $user_id ) )
346
  $total_sql['where'][] = "m.group_id = g.id AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0";
347
 
348
+ if ( !empty( $exclude ) ) {
349
+ $exclude = $wpdb->escape( $exclude );
350
+ $total_sql['where'][] = " g.id NOT IN ({$exclude})";
351
+ }
 
 
 
352
 
353
  $total_sql['where'][] = "g.id = gm1.group_id";
354
  $total_sql['where'][] = "g.id = gm2.group_id";
357
  $t_sql = $total_sql['select'];
358
 
359
  if ( !empty( $total_sql['where'] ) )
360
+ $t_sql .= " WHERE " . join( ' AND ', (array)$total_sql['where'] );
361
 
362
+ /* Get total group results */
363
+ $total_groups_sql = apply_filters( 'bp_groups_get_total_groups_sql', join( ' ', (array)$t_sql ), $t_sql );
364
  $total_groups = $wpdb->get_var( $total_groups_sql );
365
 
366
+ /* Populate some extra information instead of querying each time in the loop */
 
 
 
 
 
367
  if ( !empty( $populate_extras ) ) {
368
+ $group_ids = array();
369
+ foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
370
+ $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
371
  $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, $type );
372
  }
 
 
 
373
 
374
  unset( $sql, $total_sql );
375
 
379
  function get_by_most_forum_topics( $limit = null, $page = null, $user_id = 0, $search_terms = false, $populate_extras = true, $exclude = false ) {
380
  global $wpdb, $bp, $bbdb;
381
 
382
+ if ( !$bbdb )
383
  do_action( 'bbpress_init' );
384
 
385
+ if ( $limit && $page ) {
386
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
387
  }
388
 
389
+ if ( !is_user_logged_in() || ( !is_super_admin() && ( $user_id != $bp->loggedin_user->id ) ) )
390
  $hidden_sql = " AND g.status != 'hidden'";
391
 
392
  if ( !empty( $search_terms ) ) {
399
  $exclude_sql = " AND g.id NOT IN ({$exclude})";
400
  }
401
 
402
+ if ( $user_id ) {
403
  $user_id = $wpdb->escape( $user_id );
404
  $paged_groups = $wpdb->get_results( "SELECT DISTINCT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bp->groups->table_name_members} m, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) AND f.topics > 0 {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} ORDER BY f.topics DESC {$pag_sql}" );
405
  $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) AND f.topics > 0 {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql}" );
409
  }
410
 
411
  if ( !empty( $populate_extras ) ) {
412
+ foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
413
+ $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
414
  $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, 'newest' );
415
  }
416
 
420
  function get_by_most_forum_posts( $limit = null, $page = null, $search_terms = false, $populate_extras = true, $exclude = false ) {
421
  global $wpdb, $bp, $bbdb;
422
 
423
+ if ( !$bbdb )
424
  do_action( 'bbpress_init' );
425
 
426
+ if ( $limit && $page ) {
427
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
428
  }
429
 
430
+ if ( !is_user_logged_in() || ( !is_super_admin() && ( $user_id != $bp->loggedin_user->id ) ) )
431
  $hidden_sql = " AND g.status != 'hidden'";
432
 
433
+ if ( $search_terms ) {
434
  $search_terms = like_escape( $wpdb->escape( $search_terms ) );
435
  $search_sql = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )";
436
  }
440
  $exclude_sql = " AND g.id NOT IN ({$exclude})";
441
  }
442
 
443
+ if ( $user_id ) {
444
  $user_id = $wpdb->escape( $user_id );
445
  $paged_groups = $wpdb->get_results( "SELECT DISTINCT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bp->groups->table_name_members} m, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} ORDER BY f.posts ASC {$pag_sql}" );
446
  $total_groups = $wpdb->get_results( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bp->groups->table_name_members} m, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) AND f.posts > 0 {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} " );
450
  }
451
 
452
  if ( !empty( $populate_extras ) ) {
453
+ foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
454
+ $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
455
  $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, 'newest' );
456
  }
457
 
477
  $exclude_sql = " AND g.id NOT IN ({$exclude})";
478
  }
479
 
480
+ if ( !is_super_admin() )
481
  $hidden_sql = $wpdb->prepare( " AND status != 'hidden'");
482
 
483
  $letter = like_escape( $wpdb->escape( $letter ) );
484
 
485
+ if ( $limit && $page ) {
486
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
487
  $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND g.name LIKE '$letter%%' {$hidden_sql} {$search_sql} {$exclude_sql}" ) );
488
  }
490
  $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND g.name LIKE '$letter%%' {$hidden_sql} {$search_sql} {$exclude_sql} ORDER BY g.name ASC {$pag_sql}" ) );
491
 
492
  if ( !empty( $populate_extras ) ) {
493
+ foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
494
+ $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
495
  $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, 'newest' );
496
  }
497
 
501
  function get_random( $limit = null, $page = null, $user_id = 0, $search_terms = false, $populate_extras = true, $exclude = false ) {
502
  global $wpdb, $bp;
503
 
504
+ if ( $limit && $page )
 
 
505
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
506
 
507
+ if ( !is_user_logged_in() || ( !is_super_admin() && ( $user_id != $bp->loggedin_user->id ) ) )
508
  $hidden_sql = "AND g.status != 'hidden'";
509
 
510
+ if ( $search_terms ) {
511
  $search_terms = like_escape( $wpdb->escape( $search_terms ) );
512
  $search_sql = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )";
513
  }
517
  $exclude_sql = " AND g.id NOT IN ({$exclude})";
518
  }
519
 
520
+ if ( $user_id ) {
521
  $user_id = $wpdb->escape( $user_id );
522
  $paged_groups = $wpdb->get_results( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} ORDER BY rand() {$pag_sql}" );
523
  $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m LEFT JOIN {$bp->groups->table_name_groupmeta} gm ON m.group_id = gm.group_id INNER JOIN {$bp->groups->table_name} g ON m.group_id = g.id WHERE gm.meta_key = 'last_activity'{$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql}" );
527
  }
528
 
529
  if ( !empty( $populate_extras ) ) {
530
+ foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
531
+ $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
532
  $paged_groups = BP_Groups_Group::get_group_extras( $paged_groups, $group_ids, 'newest' );
533
  }
534
 
541
  if ( empty( $group_ids ) )
542
  return $paged_groups;
543
 
544
+ /* Fetch the logged in users status within each group */
545
+ $user_status = $wpdb->get_col( $wpdb->prepare( "SELECT group_id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id IN ( {$group_ids} ) AND is_confirmed = 1 AND is_banned = 0", $bp->loggedin_user->id ) );
546
  for ( $i = 0, $count = count( $paged_groups ); $i < $count; ++$i ) {
547
  $paged_groups[$i]->is_member = false;
548
 
549
+ foreach ( (array)$user_status as $group_id ) {
550
+ if ( $group_id == $paged_groups[$i]->id )
551
  $paged_groups[$i]->is_member = true;
 
552
  }
553
  }
554
 
555
+ $user_banned = $wpdb->get_col( $wpdb->prepare( "SELECT group_id FROM {$bp->groups->table_name_members} WHERE is_banned = 1 AND user_id = %d AND group_id IN ( {$group_ids} )", $bp->loggedin_user->id ) );
556
  for ( $i = 0, $count = count( $paged_groups ); $i < $count; ++$i ) {
557
  $paged_groups[$i]->is_banned = false;
558
 
559
+ foreach ( (array)$user_banned as $group_id ) {
560
+ if ( $group_id == $paged_groups[$i]->id )
561
  $paged_groups[$i]->is_banned = true;
 
562
  }
563
  }
564
 
575
  global $wpdb, $bp;
576
 
577
  $hidden_sql = '';
578
+ if ( !is_super_admin() )
579
  $hidden_sql = "WHERE status != 'hidden'";
580
 
581
  return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name} {$hidden_sql}" ) );
587
  if ( 'unreplied' == $type )
588
  $bp->groups->filter_sql = ' AND t.topic_posts = 1';
589
 
590
+ $extra_sql = apply_filters( 'groups_total_public_forum_topic_count', $bp->groups->filter_sql, $type );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
591
 
592
  return $wpdb->get_var( "SELECT COUNT(t.topic_id) FROM {$bbdb->topics} AS t, {$bp->groups->table_name} AS g LEFT JOIN {$bp->groups->table_name_groupmeta} AS gm ON g.id = gm.group_id WHERE (gm.meta_key = 'forum_id' AND gm.meta_value = t.forum_id) AND g.status = 'public' AND t.topic_status = '0' AND t.topic_sticky != '2' {$extra_sql} " );
593
  }
598
  return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 AND is_banned = 0", $group_id ) );
599
  }
600
 
601
+
602
  /**
603
  * Get a total count of all topics of a given status, across groups/forums
604
  *
605
  * @package BuddyPress
606
+ * @since 1.5
607
  *
608
  * @param str $status 'public', 'private', 'hidden', 'all' Which group types to count
609
  * @return int The topic count
647
  }
648
  }
649
 
650
+ Class BP_Groups_Member {
651
  var $id;
652
  var $group_id;
653
  var $user_id;
660
  var $is_confirmed;
661
  var $comments;
662
  var $invite_sent;
663
+
664
  var $user;
665
 
666
+ function bp_groups_member( $user_id = 0, $group_id = 0, $id = false, $populate = true ) {
667
+ $this->__construct($user_id,$group_id,$id,$populate);
668
+ }
669
 
670
+ function __construct( $user_id = 0, $group_id = 0, $id = false, $populate = true ) {
671
+ if ( $user_id && $group_id && !$id ) {
672
+ $this->user_id = $user_id;
673
  $this->group_id = $group_id;
674
 
675
+ if ( $populate )
676
  $this->populate();
 
677
  }
678
 
679
+ if ( $id ) {
 
680
  $this->id = $id;
681
 
682
+ if ( $populate )
683
  $this->populate();
 
684
  }
685
  }
686
 
690
  if ( $this->user_id && $this->group_id && !$this->id )
691
  $sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $this->user_id, $this->group_id );
692
 
693
+ if ( $this->id )
694
  $sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name_members} WHERE id = %d", $this->id );
695
 
696
  $member = $wpdb->get_row($sql);
697
 
698
+ if ( $member ) {
699
  $this->id = $member->id;
700
  $this->group_id = $member->group_id;
701
  $this->user_id = $member->user_id;
730
 
731
  do_action_ref_array( 'groups_member_before_save', array( &$this ) );
732
 
733
+ if ( $this->id )
734
  $sql = $wpdb->prepare( "UPDATE {$bp->groups->table_name_members} SET inviter_id = %d, is_admin = %d, is_mod = %d, is_banned = %d, user_title = %s, date_modified = %s, is_confirmed = %d, comments = %s, invite_sent = %d WHERE id = %d", $this->inviter_id, $this->is_admin, $this->is_mod, $this->is_banned, $this->user_title, $this->date_modified, $this->is_confirmed, $this->comments, $this->invite_sent, $this->id );
735
+ else
 
 
 
 
 
736
  $sql = $wpdb->prepare( "INSERT INTO {$bp->groups->table_name_members} ( user_id, group_id, inviter_id, is_admin, is_mod, is_banned, user_title, date_modified, is_confirmed, comments, invite_sent ) VALUES ( %d, %d, %d, %d, %d, %d, %s, %s, %d, %s, %d )", $this->user_id, $this->group_id, $this->inviter_id, $this->is_admin, $this->is_mod, $this->is_banned, $this->user_title, $this->date_modified, $this->is_confirmed, $this->comments, $this->invite_sent );
 
737
 
738
+ if ( !$wpdb->query($sql) )
739
  return false;
740
 
741
  $this->id = $wpdb->insert_id;
747
 
748
  function promote( $status = 'mod' ) {
749
  if ( 'mod' == $status ) {
750
+ $this->is_admin = 0;
751
+ $this->is_mod = 1;
752
  $this->user_title = __( 'Group Mod', 'buddypress' );
753
  }
754
 
755
  if ( 'admin' == $status ) {
756
+ $this->is_admin = 1;
757
+ $this->is_mod = 0;
758
  $this->user_title = __( 'Group Admin', 'buddypress' );
759
  }
760
 
762
  }
763
 
764
  function demote() {
765
+ $this->is_mod = 0;
766
+ $this->is_admin = 0;
767
  $this->user_title = false;
768
 
769
  return $this->save();
770
  }
771
 
772
  function ban() {
773
+ global $bp;
774
 
775
+ if ( $this->is_admin )
776
  return false;
777
 
778
  $this->is_mod = 0;
782
 
783
  $group_count = bp_get_user_meta( $this->user_id, 'total_group_count', true );
784
  if ( !empty( $group_count ) )
785
+ bp_update_user_meta( $this->user_id, 'total_group_count', (int)$group_count - 1 );
786
 
787
  return $this->save();
788
  }
789
 
790
  function unban() {
791
+ global $bp;
792
 
793
+ if ( $this->is_admin )
794
  return false;
795
 
796
  $this->is_banned = 0;
797
 
798
  groups_update_groupmeta( $this->group_id, 'total_member_count', ( (int) groups_get_groupmeta( $this->group_id, 'total_member_count' ) + 1 ) );
799
+ bp_update_user_meta( $this->user_id, 'total_group_count', (int)bp_get_user_meta( $this->user_id, 'total_group_count', true ) + 1 );
800
 
801
  return $this->save();
802
  }
803
 
804
  function accept_invite() {
805
+ global $bp;
806
 
807
  $this->inviter_id = 0;
808
  $this->is_confirmed = 1;
809
  $this->date_modified = bp_core_current_time();
810
 
811
+ bp_update_user_meta( $this->user_id, 'total_group_count', (int)bp_get_user_meta( $this->user_id, 'total_group_count', true ) + 1 );
812
  }
813
 
814
  function accept_request() {
815
+ global $bp;
816
 
817
  $this->is_confirmed = 1;
818
  $this->date_modified = bp_core_current_time();
819
 
820
+ bp_update_user_meta( $this->user_id, 'total_group_count', (int)bp_get_user_meta( $this->user_id, 'total_group_count', true ) + 1 );
821
  }
822
 
823
  function remove() {
832
 
833
  $group_count = bp_get_user_meta( $this->user_id, 'total_group_count', true );
834
  if ( !empty( $group_count ) )
835
+ bp_update_user_meta( $this->user_id, 'total_group_count', (int)$group_count - 1 );
836
 
837
  return $result;
838
  }
839
 
840
+ /* Static Functions */
841
 
842
  function delete( $user_id, $group_id ) {
843
  global $wpdb, $bp;
849
  global $wpdb, $bp;
850
 
851
  $pag_sql = '';
852
+ if ( $limit && $page )
853
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
854
 
855
  // If the user is logged in and viewing their own groups, we can show hidden and private groups
856
+ if ( $user_id != $bp->loggedin_user->id ) {
857
  $group_sql = $wpdb->prepare( "SELECT DISTINCT m.group_id FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0{$pag_sql}", $user_id );
858
  $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) );
859
  } else {
871
 
872
  $pag_sql = $hidden_sql = $filter_sql = '';
873
 
874
+ if ( $limit && $page )
875
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
876
 
877
+ if ( $filter ) {
878
  $filter = like_escape( $wpdb->escape( $filter ) );
879
  $filter_sql = " AND ( g.name LIKE '%%{$filter}%%' OR g.description LIKE '%%{$filter}%%' )";
880
  }
881
 
882
+ if ( $user_id != $bp->loggedin_user->id )
883
  $hidden_sql = " AND g.status != 'hidden'";
884
 
885
  $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count'{$hidden_sql}{$filter_sql} AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0 ORDER BY m.date_modified DESC {$pag_sql}", $user_id ) );
893
 
894
  $pag_sql = $hidden_sql = $filter_sql = '';
895
 
896
+ if ( $limit && $page )
897
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
898
 
899
+ if ( $filter ) {
900
  $filter = like_escape( $wpdb->escape( $filter ) );
901
  $filter_sql = " AND ( g.name LIKE '%%{$filter}%%' OR g.description LIKE '%%{$filter}%%' )";
902
  }
903
 
904
+ if ( $user_id != $bp->loggedin_user->id )
905
  $hidden_sql = " AND g.status != 'hidden'";
906
 
907
  $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count'{$hidden_sql}{$filter_sql} AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0 AND m.is_admin = 1 ORDER BY m.date_modified ASC {$pag_sql}", $user_id ) );
915
 
916
  $pag_sql = $hidden_sql = $filter_sql = '';
917
 
918
+ if ( $limit && $page )
919
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
920
 
921
+ if ( $filter ) {
922
  $filter = like_escape( $wpdb->escape( $filter ) );
923
  $filter_sql = " AND ( g.name LIKE '%%{$filter}%%' OR g.description LIKE '%%{$filter}%%' )";
924
  }
925
 
926
+ if ( $user_id != $bp->loggedin_user->id )
927
  $hidden_sql = " AND g.status != 'hidden'";
928
 
929
  $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count'{$hidden_sql}{$filter_sql} AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0 AND m.is_mod = 1 ORDER BY m.date_modified ASC {$pag_sql}", $user_id ) );
935
  function total_group_count( $user_id = 0 ) {
936
  global $bp, $wpdb;
937
 
938
+ if ( !$user_id )
939
+ $user_id = $bp->displayed_user->id;
940
 
941
+ if ( $user_id != $bp->loggedin_user->id && !is_super_admin() ) {
942
  return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) );
943
  } else {
944
  return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) );
961
  function check_has_invite( $user_id, $group_id, $type = 'sent' ) {
962
  global $wpdb, $bp;
963
 
964
+ if ( !$user_id )
965
  return false;
966
 
967
  $sql = "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND inviter_id != 0";
975
  function delete_invite( $user_id, $group_id ) {
976
  global $wpdb, $bp;
977
 
978
+ if ( !$user_id )
979
  return false;
980
 
981
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND inviter_id != 0 AND invite_sent = 1", $user_id, $group_id ) );
984
  function delete_request( $user_id, $group_id ) {
985
  global $wpdb, $bp;
986
 
987
+ if ( !$user_id )
988
  return false;
989
 
990
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND inviter_id = 0 AND invite_sent = 0", $user_id, $group_id ) );
993
  function check_is_admin( $user_id, $group_id ) {
994
  global $wpdb, $bp;
995
 
996
+ if ( !$user_id )
997
  return false;
998
 
999
  return $wpdb->query( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_admin = 1 AND is_banned = 0", $user_id, $group_id ) );
1002
  function check_is_mod( $user_id, $group_id ) {
1003
  global $wpdb, $bp;
1004
 
1005
+ if ( !$user_id )
1006
  return false;
1007
 
1008
  return $wpdb->query( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_mod = 1 AND is_banned = 0", $user_id, $group_id ) );
1011
  function check_is_member( $user_id, $group_id ) {
1012
  global $wpdb, $bp;
1013
 
1014
+ if ( !$user_id )
1015
  return false;
1016
 
1017
  return $wpdb->query( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 1 AND is_banned = 0", $user_id, $group_id ) );
1020
  function check_is_banned( $user_id, $group_id ) {
1021
  global $wpdb, $bp;
1022
 
1023
+ if ( !$user_id )
1024
  return false;
1025
 
1026
  return $wpdb->get_var( $wpdb->prepare( "SELECT is_banned FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $user_id, $group_id ) );
1038
  function check_is_creator( $user_id, $group_id ) {
1039
  global $bp, $wpdb;
1040
 
1041
+ if ( !$user_id )
1042
  return false;
1043
 
1044
  return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name} WHERE creator_id = %d AND id = %d", $user_id, $group_id ) );
1047
  function check_for_membership_request( $user_id, $group_id ) {
1048
  global $wpdb, $bp;
1049
 
1050
+ if ( !$user_id )
1051
  return false;
1052
 
1053
  return $wpdb->query( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND is_banned = 0 AND inviter_id = 0", $user_id, $group_id ) );
1092
  global $bp, $wpdb;
1093
 
1094
  $pag_sql = '';
1095
+ if ( $limit && $page )
1096
  $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
1097
 
1098
  $exclude_admins_sql = '';
1099
+ if ( $exclude_admins_mods )
1100
  $exclude_admins_sql = $wpdb->prepare( "AND is_admin = 0 AND is_mod = 0" );
1101
 
1102
  $banned_sql = '';
1103
+ if ( $exclude_banned )
1104
  $banned_sql = $wpdb->prepare( " AND is_banned = 0" );
1105
 
1106
  $exclude_sql = '';
1107
+ if ( $exclude )
1108
  $exclude_sql = $wpdb->prepare( " AND m.user_id NOT IN ({$exclude})" );
1109
 
1110
  if ( bp_is_active( 'xprofile' ) )
1112
  else
1113
  $members = $wpdb->get_results( apply_filters( 'bp_group_members_user_join_filter', $wpdb->prepare( "SELECT m.user_id, m.date_modified, m.is_banned, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$bp->groups->table_name_members} m, {$wpdb->users} u WHERE u.ID = m.user_id AND group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_admins_sql} {$exclude_sql} ORDER BY m.date_modified DESC {$pag_sql}", $group_id ) ) );
1114
 
1115
+ if ( !$members )
1116
  return false;
1117
 
1118
  if ( empty( $pag_sql ) )
1120
  else
1121
  $total_member_count = $wpdb->get_var( apply_filters( 'bp_group_members_count_user_join_filter', $wpdb->prepare( "SELECT COUNT(user_id) FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_admins_sql} {$exclude_sql}", $group_id ) ) );
1122
 
1123
+ /* Fetch whether or not the user is a friend */
1124
+ foreach ( (array)$members as $user ) $user_ids[] = $user->user_id;
1125
+ $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
 
 
1126
 
1127
  if ( bp_is_active( 'friends' ) ) {
1128
+ $friend_status = $wpdb->get_results( $wpdb->prepare( "SELECT initiator_user_id, friend_user_id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id IN ( {$user_ids} ) ) OR (initiator_user_id IN ( {$user_ids} ) AND friend_user_id = %d )", $bp->loggedin_user->id, $bp->loggedin_user->id ) );
1129
  for ( $i = 0, $count = count( $members ); $i < $count; ++$i ) {
1130
+ foreach ( (array)$friend_status as $status ) {
1131
+ if ( $status->initiator_user_id == $members[$i]->user_id || $status->friend_user_id == $members[$i]->user_id )
1132
  $members[$i]->is_friend = $status->is_confirmed;
 
1133
  }
1134
  }
1135
  }
1186
  class BP_Group_Extension {
1187
  var $name = false;
1188
  var $slug = false;
 
 
 
 
1189
 
1190
+ /* Will this extension be visible to non-members of a group? Options: public/private */
 
 
 
 
1191
  var $visibility = 'public';
1192
 
1193
  var $create_step_position = 81;
1220
 
1221
  function _register() {
1222
  global $bp;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1223
 
1224
  if ( !empty( $this->enable_create_step ) ) {
1225
  // Insert the group creation step for the new group extension
1226
+ $bp->groups->group_creation_steps[$this->slug] = array( 'name' => $this->name, 'slug' => $this->slug, 'position' => $this->create_step_position );
1227
 
1228
  // Attach the group creation step display content action
1229
  add_action( 'groups_custom_create_steps', array( &$this, 'create_screen' ) );
1230
 
1231
  // Attach the group creation step save content action
1232
+ add_action( 'groups_create_group_step_save_' . $this->slug, array( &$this, 'create_screen_save' ) );
1233
  }
1234
 
1235
  // When we are viewing a single group, add the group extension nav item
1252
  }
1253
 
1254
  // Construct the admin edit tab for the new group extension
1255
+ if ( !empty( $this->enable_edit_item ) && !empty( $bp->is_item_admin ) ) {
1256
+ add_action( 'groups_admin_tabs', create_function( '$current, $group_slug', '$selected = ""; if ( "' . esc_attr( $this->slug ) . '" == $current ) $selected = " class=\"current\""; echo "<li{$selected}><a href=\"' . bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/{$group_slug}/admin/' . esc_attr( $this->slug ) . '\">' . esc_attr( $this->name ) . '</a></li>";' ), 10, 2 );
1257
 
1258
  // Catch the edit screen and forward it to the plugin template
1259
+ if ( bp_is_groups_component() && bp_is_current_action( 'admin' ) && bp_is_action_variable( $this->slug, 0 ) ) {
1260
  // Check whether the user is saving changes
1261
  $this->edit_screen_save();
1262
 
1280
  }
1281
 
1282
  function bp_register_group_extension( $group_extension_class ) {
1283
+ global $bp;
1284
 
1285
  if ( !class_exists( $group_extension_class ) )
1286
  return false;
1287
 
1288
+ /* Register the group extension on the bp_init action so we have access to all plugins */
 
1289
  add_action( 'bp_init', create_function( '', '$extension = new ' . $group_extension_class . '; add_action( "bp_actions", array( &$extension, "_register" ), 8 );' ), 11 );
1290
  }
1291
 
bp-groups/bp-groups-filters.php CHANGED
@@ -1,12 +1,4 @@
1
  <?php
2
-
3
- /**
4
- * BuddyPress Groups Filters
5
- *
6
- * @package BuddyPress
7
- * @subpackage GroupsFilters
8
- */
9
-
10
  // Exit if accessed directly
11
  if ( !defined( 'ABSPATH' ) ) exit;
12
 
@@ -64,26 +56,25 @@ function bp_groups_filter_kses( $content ) {
64
  $groups_allowedtags['img']['class'] = array();
65
  $groups_allowedtags['img']['id'] = array();
66
  $groups_allowedtags['code'] = array();
67
- $groups_allowedtags = apply_filters( 'bp_groups_filter_kses', $groups_allowedtags );
68
 
 
69
  return wp_kses( $content, $groups_allowedtags );
70
  }
71
 
72
- /** Group forums **************************************************************/
73
 
74
- /**
75
- * Only filter the forum SQL on group pages or on the forums directory
76
- */
77
  function groups_add_forum_privacy_sql() {
78
- add_filter( 'get_topics_fields', 'groups_add_forum_fields_sql' );
79
- add_filter( 'get_topics_join', 'groups_add_forum_tables_sql' );
80
- add_filter( 'get_topics_where', 'groups_add_forum_where_sql' );
 
 
 
81
  }
82
  add_filter( 'bbpress_init', 'groups_add_forum_privacy_sql' );
83
 
84
  function groups_add_forum_fields_sql( $sql = '' ) {
85
- $sql = 't.*, g.id as object_id, g.name as object_name, g.slug as object_slug';
86
- return $sql;
87
  }
88
 
89
  function groups_add_forum_tables_sql( $sql = '' ) {
@@ -97,9 +88,6 @@ function groups_add_forum_tables_sql( $sql = '' ) {
97
  function groups_add_forum_where_sql( $sql = '' ) {
98
  global $bp;
99
 
100
- // Define locale variable
101
- $parts = array();
102
-
103
  // Set this for groups
104
  $parts['groups'] = "(gm.meta_key = 'forum_id' AND gm.meta_value = t.forum_id)";
105
 
@@ -116,7 +104,7 @@ function groups_add_forum_where_sql( $sql = '' ) {
116
  unset( $parts['private'] );
117
 
118
  // Are we a super admin?
119
- elseif ( bp_current_user_can( 'bp_moderate' ) )
120
  unset( $parts['private'] );
121
 
122
  // No need to filter on a single item
@@ -140,9 +128,9 @@ function groups_add_forum_where_sql( $sql = '' ) {
140
  function groups_filter_bbpress_caps( $value, $cap, $args ) {
141
  global $bp;
142
 
143
- if ( bp_current_user_can( 'bp_moderate' ) )
144
  return true;
145
-
146
  if ( 'add_tag_to' == $cap )
147
  if ( $bp->groups->current_group->user_has_access ) return true;
148
 
@@ -158,11 +146,10 @@ add_filter( 'bb_current_user_can', 'groups_filter_bbpress_caps', 10, 3 );
158
  * information we aren't going to use. This speeds up the query.
159
  *
160
  * @see BB_Query::_filter_sql()
161
- * @since BuddyPress (1.5)
162
  */
163
  function groups_filter_forums_root_page_sql( $sql ) {
164
  return apply_filters( 'groups_filter_bbpress_root_page_sql', 't.topic_id' );
165
  }
166
  add_filter( 'get_latest_topics_fields', 'groups_filter_forums_root_page_sql' );
167
-
168
- ?>
1
  <?php
 
 
 
 
 
 
 
 
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
56
  $groups_allowedtags['img']['class'] = array();
57
  $groups_allowedtags['img']['id'] = array();
58
  $groups_allowedtags['code'] = array();
 
59
 
60
+ $groups_allowedtags = apply_filters( 'bp_groups_filter_kses', $groups_allowedtags );
61
  return wp_kses( $content, $groups_allowedtags );
62
  }
63
 
64
+ /**** Filters for group forums ****/
65
 
 
 
 
66
  function groups_add_forum_privacy_sql() {
67
+ global $bp;
68
+
69
+ // Only filter the forum SQL on group pages or on the forums directory
70
+ add_filter( 'get_topics_fields', 'groups_add_forum_fields_sql' );
71
+ add_filter( 'get_topics_join', 'groups_add_forum_tables_sql' );
72
+ add_filter( 'get_topics_where', 'groups_add_forum_where_sql' );
73
  }
74
  add_filter( 'bbpress_init', 'groups_add_forum_privacy_sql' );
75
 
76
  function groups_add_forum_fields_sql( $sql = '' ) {
77
+ return 't.*, g.id as object_id, g.name as object_name, g.slug as object_slug';
 
78
  }
79
 
80
  function groups_add_forum_tables_sql( $sql = '' ) {
88
  function groups_add_forum_where_sql( $sql = '' ) {
89
  global $bp;
90
 
 
 
 
91
  // Set this for groups
92
  $parts['groups'] = "(gm.meta_key = 'forum_id' AND gm.meta_value = t.forum_id)";
93
 
104
  unset( $parts['private'] );
105
 
106
  // Are we a super admin?
107
+ elseif ( is_super_admin() )
108
  unset( $parts['private'] );
109
 
110
  // No need to filter on a single item
128
  function groups_filter_bbpress_caps( $value, $cap, $args ) {
129
  global $bp;
130
 
131
+ if ( is_super_admin() )
132
  return true;
133
+
134
  if ( 'add_tag_to' == $cap )
135
  if ( $bp->groups->current_group->user_has_access ) return true;
136
 
146
  * information we aren't going to use. This speeds up the query.
147
  *
148
  * @see BB_Query::_filter_sql()
149
+ * @since 1.5
150
  */
151
  function groups_filter_forums_root_page_sql( $sql ) {
152
  return apply_filters( 'groups_filter_bbpress_root_page_sql', 't.topic_id' );
153
  }
154
  add_filter( 'get_latest_topics_fields', 'groups_filter_forums_root_page_sql' );
155
+ ?>
 
bp-groups/bp-groups-forums.php CHANGED
@@ -1,38 +1,17 @@
1
  <?php
2
-
3
- /**
4
- * BuddyPress Groups Forums
5
- *
6
- * Action functions are exactly the same as screen functions, however they do not
7
- * have a template screen associated with them. Usually they will send the user
8
- * back to the default screen after execution.
9
- *
10
- * @package BuddyPress
11
- * @subpackage GroupsForums
12
- */
13
 
14
  // Exit if accessed directly
15
  if ( !defined( 'ABSPATH' ) ) exit;
16
 
17
- /**
18
- * Creates a new forum inside a specific BuddyPress group.
19
- *
20
- * Uses the bundled version of bbPress packaged with BuddyPress.
21
- *
22
- * @param int $group_id The group ID that the new forum should be attached to
23
- * @param string $group_name The group name
24
- * @param string $group_description The group description
25
- *
26
- * @since 1.0
27
- */
28
  function groups_new_group_forum( $group_id = 0, $group_name = '', $group_desc = '' ) {
29
  global $bp;
30
 
31
  if ( empty( $group_id ) )
32
- $group_id = bp_get_current_group_id();
33
 
34
  if ( empty( $group_name ) )
35
- $group_name = bp_get_current_group_name();
36
 
37
  if ( empty( $group_desc ) )
38
  $group_desc = $bp->groups->current_group->description;
@@ -51,12 +30,10 @@ function groups_new_group_forum( $group_id = 0, $group_name = '', $group_desc =
51
  * @subpackage Groups
52
  *
53
  * @param int $group_id Group id, passed from groups_details_updated
54
- *
55
- * @since 1.1
56
  */
57
  function groups_update_group_forum( $group_id ) {
58
 
59
- $group = groups_get_group( array( 'group_id' => $group_id ) );
60
 
61
  /**
62
  * Bail in the following three situations:
@@ -79,19 +56,9 @@ function groups_update_group_forum( $group_id ) {
79
  }
80
  add_action( 'groups_details_updated', 'groups_update_group_forum' );
81
 
82
- /**
83
- * Creates a new group forum post.
84
- *
85
- * Uses the bundled version of bbPress packaged with BuddyPress.
86
- *
87
- * @param string $post_text The text for the forum post
88
- * @param int $topic_id The topic ID used so we can identify where the new forum post should reside
89
- * @param mixed $page The page number where the new forum post should reside. Defaults to boolean false.
90
- * @return mixed The new forum post ID on success. Boolean false on failure.
91
- *
92
- * @since 1.0
93
- */
94
  function groups_new_group_forum_post( $post_text, $topic_id, $page = false ) {
 
 
95
  if ( empty( $post_text ) )
96
  return false;
97
 
@@ -101,24 +68,24 @@ function groups_new_group_forum_post( $post_text, $topic_id, $page = false ) {
101
  if ( $post_id = bp_forums_insert_post( array( 'post_text' => $post_text, 'topic_id' => $topic_id ) ) ) {
102
  $topic = bp_forums_get_topic_details( $topic_id );
103
 
104
- $activity_action = sprintf( __( '%1$s replied to the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( bp_loggedin_user_id() ), '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug .'/">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . '">' . esc_attr( bp_get_current_group_name() ) . '</a>' );
105
  $activity_content = bp_create_excerpt( $post_text );
106
- $primary_link = bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug . '/';
107
 
108
  if ( $page )
109
  $primary_link .= "?topic_page=" . $page;
110
 
111
  // Record this in activity streams
112
  groups_record_activity( array(
113
- 'action' => apply_filters_ref_array( 'groups_activity_new_forum_post_action', array( $activity_action, $post_id, $post_text, &$topic ) ),
114
- 'content' => apply_filters_ref_array( 'groups_activity_new_forum_post_content', array( $activity_content, $post_id, $post_text, &$topic ) ),
115
  'primary_link' => apply_filters( 'groups_activity_new_forum_post_primary_link', "{$primary_link}#post-{$post_id}" ),
116
  'type' => 'new_forum_post',
117
- 'item_id' => bp_get_current_group_id(),
118
  'secondary_item_id' => $post_id
119
  ) );
120
 
121
- do_action( 'groups_new_forum_topic_post', bp_get_current_group_id(), $post_id );
122
 
123
  return $post_id;
124
  }
@@ -126,20 +93,9 @@ function groups_new_group_forum_post( $post_text, $topic_id, $page = false ) {
126
  return false;
127
  }
128
 
129
- /**
130
- * Creates a new group forum topic.
131
- *
132
- * Uses the bundled version of bbPress packaged with BuddyPress.
133
- *
134
- * @param string $topic_title The title for the forum topic
135
- * @param string $topic_text The text for the forum topic
136
- * @param string $topic_tags A comma-delimited string of topic tags
137
- * @param int $forum_id The forum ID this forum topic resides in
138
- * @return mixed The new topic object on success. Boolean false on failure.
139
- *
140
- * @since 1.0
141
- */
142
  function groups_new_group_forum_topic( $topic_title, $topic_text, $topic_tags, $forum_id ) {
 
 
143
  if ( empty( $topic_title ) || empty( $topic_text ) )
144
  return false;
145
 
@@ -151,20 +107,20 @@ function groups_new_group_forum_topic( $topic_title, $topic_text, $topic_tags, $
151
  if ( $topic_id = bp_forums_new_topic( array( 'topic_title' => $topic_title, 'topic_text' => $topic_text, 'topic_tags' => $topic_tags, 'forum_id' => $forum_id ) ) ) {
152
  $topic = bp_forums_get_topic_details( $topic_id );
153
 
154
- $activity_action = sprintf( __( '%1$s started the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( bp_loggedin_user_id() ), '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug .'/">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . '">' . esc_attr( bp_get_current_group_name() ) . '</a>' );
155
  $activity_content = bp_create_excerpt( $topic_text );
156
 
157
  // Record this in activity streams
158
  groups_record_activity( array(
159
  'action' => apply_filters_ref_array( 'groups_activity_new_forum_topic_action', array( $activity_action, $topic_text, &$topic ) ),
160
  'content' => apply_filters_ref_array( 'groups_activity_new_forum_topic_content', array( $activity_content, $topic_text, &$topic ) ),
161
- 'primary_link' => apply_filters( 'groups_activity_new_forum_topic_primary_link', bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug . '/' ),
162
  'type' => 'new_forum_topic',
163
- 'item_id' => bp_get_current_group_id(),
164
  'secondary_item_id' => $topic->topic_id
165
  ) );
166
 
167
- do_action_ref_array( 'groups_new_forum_topic', array( bp_get_current_group_id(), &$topic ) );
168
 
169
  return $topic;
170
  }
@@ -172,19 +128,6 @@ function groups_new_group_forum_topic( $topic_title, $topic_text, $topic_tags, $
172
  return false;
173
  }
174
 
175
- /**
176
- * Updates an existing group forum topic.
177
- *
178
- * Uses the bundled version of bbPress packaged with BuddyPress.
179
- *
180
- * @param int $topic_id The topic ID of the existing forum topic
181
- * @param string $topic_title The title for the forum topic
182
- * @param string $topic_text The text for the forum topic
183
- * @param mixed $topic_tags A comma-delimited string of topic tags. Defaults to boolean false.
184
- * @return mixed The topic object on success. Boolean false on failure.
185
- *
186
- * @since 1.1
187
- */
188
  function groups_update_group_forum_topic( $topic_id, $topic_title, $topic_text, $topic_tags = false ) {
189
  global $bp;
190
 
@@ -192,29 +135,21 @@ function groups_update_group_forum_topic( $topic_id, $topic_title, $topic_text,
192
  $topic_text = apply_filters( 'group_forum_topic_text_before_save', $topic_text );
193
 
194
  if ( $topic = bp_forums_update_topic( array( 'topic_title' => $topic_title, 'topic_text' => $topic_text, 'topic_id' => $topic_id, 'topic_tags' => $topic_tags ) ) ) {
 
 
 
195
 
196
- // Get the corresponding activity item
197
- if ( bp_is_active( 'activity' ) ) {
198
- $id = bp_activity_get_activity_id( array(
199
- 'item_id' => bp_get_current_group_id(),
200
- 'secondary_item_id' => $topic_id,
201
- 'component' => $bp->groups->id,
202
- 'type' => 'new_forum_topic'
203
- ) );
204
- }
205
-
206
- $activity_action = sprintf( __( '%1$s started the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( $topic->topic_poster ), '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug .'/">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . '">' . esc_attr( bp_get_current_group_name() ) . '</a>' );
207
  $activity_content = bp_create_excerpt( $topic_text );
208
 
209
  // Record this in activity streams
210
  groups_record_activity( array(
211
- 'id' => $id,
212
  'action' => apply_filters_ref_array( 'groups_activity_new_forum_topic_action', array( $activity_action, $topic_text, &$topic ) ),
213
  'content' => apply_filters_ref_array( 'groups_activity_new_forum_topic_content', array( $activity_content, $topic_text, &$topic ) ),
214
- 'primary_link' => apply_filters( 'groups_activity_new_forum_topic_primary_link', bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug . '/' ),
215
  'type' => 'new_forum_topic',
216
- 'item_id' => (int) bp_get_current_group_id(),
217
- 'user_id' => (int) $topic->topic_poster,
218
  'secondary_item_id' => $topic->topic_id,
219
  'recorded_time ' => $topic->topic_time
220
  ) );
@@ -227,19 +162,6 @@ function groups_update_group_forum_topic( $topic_id, $topic_title, $topic_text,
227
  return false;
228
  }
229
 
230
- /**
231
- * Updates an existing group forum post.
232
- *
233
- * Uses the bundled version of bbPress packaged with BuddyPress.
234
- *
235
- * @param int $post_id The post ID of the existing forum post
236
- * @param string $post_text The text for the forum post
237
- * @param int $topic_id The topic ID of the existing forum topic
238
- * @param mixed $page The page number where the new forum post should reside. Defaults to boolean false.
239
- * @return mixed The forum post ID on success. Boolean false on failure.
240
- *
241
- * @since 1.1
242
- */
243
  function groups_update_group_forum_post( $post_id, $post_text, $topic_id, $page = false ) {
244
  global $bp;
245
 
@@ -250,33 +172,26 @@ function groups_update_group_forum_post( $post_id, $post_text, $topic_id, $page
250
  if ( $post_id = bp_forums_insert_post( array( 'post_id' => $post_id, 'post_text' => $post_text, 'post_time' => $post->post_time, 'topic_id' => $topic_id, 'poster_id' => $post->poster_id ) ) ) {
251
  $topic = bp_forums_get_topic_details( $topic_id );
252
 
253
- $activity_action = sprintf( __( '%1$s replied to the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( $post->poster_id ), '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug .'">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . '">' . esc_attr( bp_get_current_group_name() ) . '</a>' );
254
  $activity_content = bp_create_excerpt( $post_text );
255
- $primary_link = bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug . '/';
256
 
257
  if ( $page )
258
  $primary_link .= "?topic_page=" . $page;
259
 
260
- // Get the corresponding activity item
261
- if ( bp_is_active( 'activity' ) ) {
262
- $id = bp_activity_get_activity_id( array(
263
- 'user_id' => $post->poster_id,
264
- 'component' => $bp->groups->id,
265
- 'type' => 'new_forum_post',
266
- 'item_id' => bp_get_current_group_id(),
267
- 'secondary_item_id' => $post_id
268
- ) );
269
- }
270
 
271
  // Update the entry in activity streams
272
  groups_record_activity( array(
273
  'id' => $id,
274
- 'action' => apply_filters_ref_array( 'groups_activity_new_forum_post_action', array( $activity_action, $post_text, &$topic, &$topic ) ),
275
- 'content' => apply_filters_ref_array( 'groups_activity_new_forum_post_content', array( $activity_content, $post_text, &$topic, &$topic ) ),
276
  'primary_link' => apply_filters( 'groups_activity_new_forum_post_primary_link', $primary_link . "#post-" . $post_id ),
277
  'type' => 'new_forum_post',
278
- 'item_id' => (int) bp_get_current_group_id(),
279
- 'user_id' => (int) $post->poster_id,
280
  'secondary_item_id' => $post_id,
281
  'recorded_time' => $post->post_time
282
  ) );
@@ -290,9 +205,7 @@ function groups_update_group_forum_post( $post_id, $post_text, $topic_id, $page
290
  }
291
 
292
  /**
293
- * Deletes a group forum topic and also any corresponding activity items.
294
- *
295
- * Uses the bundled version of bbPress packaged with BuddyPress.
296
  *
297
  * @package BuddyPress
298
  *
@@ -301,8 +214,6 @@ function groups_update_group_forum_post( $post_id, $post_text, $topic_id, $page
301
  * @uses bp_forums_delete_topic() to do the deletion itself
302
  * @param int $topic_id The id of the topic to be deleted
303
  * @return bool True if the delete routine went through properly
304
- *
305
- * @since 1.1
306
  */
307
  function groups_delete_group_forum_topic( $topic_id ) {
308
  global $bp;
@@ -313,24 +224,14 @@ function groups_delete_group_forum_topic( $topic_id ) {
313
  if ( bp_forums_delete_topic( array( 'topic_id' => $topic_id ) ) ) {
314
  do_action( 'groups_before_delete_group_forum_topic', $topic_id );
315
 
316
- // Delete the corresponding activity stream items
317
  if ( bp_is_active( 'activity' ) ) {
318
  // The activity item for the initial topic
319
- bp_activity_delete( array(
320
- 'item_id' => bp_get_current_group_id(),
321
- 'secondary_item_id' => $topic_id,
322
- 'component' => $bp->groups->id,
323
- 'type' => 'new_forum_topic'
324
- ) );
325
 
326
  // The activity item for each post
327
- foreach ( (array) $posts as $post ) {
328
- bp_activity_delete( array(
329
- 'item_id' => bp_get_current_group_id(),
330
- 'secondary_item_id' => $post->post_id,
331
- 'component' => $bp->groups->id,
332
- 'type' => 'new_forum_post'
333
- ) );
334
  }
335
  }
336
 
@@ -343,9 +244,7 @@ function groups_delete_group_forum_topic( $topic_id ) {
343
  }
344
 
345
  /**
346
- * Deletes a group forum post and its corresponding activity item.
347
- *
348
- * Uses the bundled version of bbPress packaged with BuddyPress.
349
  *
350
  * @package BuddyPress
351
  *
@@ -353,8 +252,6 @@ function groups_delete_group_forum_topic( $topic_id ) {
353
  * @param int $topic_id Optional. The topic to which the post belongs. This value isn't used in the
354
  * function but is passed along to do_action() hooks.
355
  * @return bool True on success.
356
- *
357
- * @since 1.1
358
  */
359
  function groups_delete_group_forum_post( $post_id, $topic_id = false ) {
360
  global $bp;
@@ -362,14 +259,9 @@ function groups_delete_group_forum_post( $post_id, $topic_id = false ) {
362
  if ( bp_forums_delete_post( array( 'post_id' => $post_id ) ) ) {
363
  do_action( 'groups_before_delete_group_forum_post', $post_id, $topic_id );
364
 
365
- // Delete the corresponding activity stream item
366
  if ( bp_is_active( 'activity' ) )
367
- bp_activity_delete( array(
368
- 'item_id' => bp_get_current_group_id(),
369
- 'secondary_item_id' => $post_id,
370
- 'component' => $bp->groups->id,
371
- 'type' => 'new_forum_post'
372
- ) );
373
 
374
  do_action( 'groups_delete_group_forum_post', $post_id, $topic_id );
375
 
@@ -379,15 +271,6 @@ function groups_delete_group_forum_post( $post_id, $topic_id = false ) {
379
  return false;
380
  }
381
 
382
- /**
383
- * Get a total count of all public topics of a given type, across groups/forums
384
- *
385
- * @package BuddyPress
386
- * @since 1.5
387
- *
388
- * @param string $type Either 'newest', 'popular', 'unreplied', 'tags'. Defaults to 'newest'.
389
- * @return int The topic count
390
- */
391
  function groups_total_public_forum_topic_count( $type = 'newest' ) {
392
  return apply_filters( 'groups_total_public_forum_topic_count', BP_Groups_Group::get_global_forum_topic_count( $type ) );
393
  }
1
  <?php
2
+ /*** Group Forums **************************************************************/
 
 
 
 
 
 
 
 
 
 
3
 
4
  // Exit if accessed directly
5
  if ( !defined( 'ABSPATH' ) ) exit;
6
 
 
 
 
 
 
 
 
 
 
 
 
7
  function groups_new_group_forum( $group_id = 0, $group_name = '', $group_desc = '' ) {
8
  global $bp;
9
 
10
  if ( empty( $group_id ) )
11
+ $group_id = $bp->groups->current_group->id;
12
 
13
  if ( empty( $group_name ) )
14
+ $group_name = $bp->groups->current_group->name;
15
 
16
  if ( empty( $group_desc ) )
17
  $group_desc = $bp->groups->current_group->description;
30
  * @subpackage Groups
31
  *
32
  * @param int $group_id Group id, passed from groups_details_updated
 
 
33
  */
34
  function groups_update_group_forum( $group_id ) {
35
 
36
+ $group = new BP_Groups_Group( $group_id );
37
 
38
  /**
39
  * Bail in the following three situations:
56
  }
57
  add_action( 'groups_details_updated', 'groups_update_group_forum' );
58
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  function groups_new_group_forum_post( $post_text, $topic_id, $page = false ) {
60
+ global $bp;
61
+
62
  if ( empty( $post_text ) )
63
  return false;
64
 
68
  if ( $post_id = bp_forums_insert_post( array( 'post_text' => $post_text, 'topic_id' => $topic_id ) ) ) {
69
  $topic = bp_forums_get_topic_details( $topic_id );
70
 
71
+ $activity_action = sprintf( __( '%1$s replied to the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug .'/">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' );
72
  $activity_content = bp_create_excerpt( $post_text );
73
+ $primary_link = bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/';
74
 
75
  if ( $page )
76
  $primary_link .= "?topic_page=" . $page;
77
 
78
  // Record this in activity streams
79
  groups_record_activity( array(
80
+ 'action' => apply_filters_ref_array( 'groups_activity_new_forum_post_action', array( $activity_action, $post_id, $post_text, &$topic ) ),
81
+ 'content' => apply_filters_ref_array( 'groups_activity_new_forum_post_content', array( $activity_content, $post_id, $post_text, &$topic ) ),
82
  'primary_link' => apply_filters( 'groups_activity_new_forum_post_primary_link', "{$primary_link}#post-{$post_id}" ),
83
  'type' => 'new_forum_post',
84
+ 'item_id' => $bp->groups->current_group->id,
85
  'secondary_item_id' => $post_id
86
  ) );
87
 
88
+ do_action( 'groups_new_forum_topic_post', $bp->groups->current_group->id, $post_id );
89
 
90
  return $post_id;
91
  }
93
  return false;
94
  }
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  function groups_new_group_forum_topic( $topic_title, $topic_text, $topic_tags, $forum_id ) {
97
+ global $bp;
98
+
99
  if ( empty( $topic_title ) || empty( $topic_text ) )
100
  return false;
101
 
107
  if ( $topic_id = bp_forums_new_topic( array( 'topic_title' => $topic_title, 'topic_text' => $topic_text, 'topic_tags' => $topic_tags, 'forum_id' => $forum_id ) ) ) {
108
  $topic = bp_forums_get_topic_details( $topic_id );
109
 
110
+ $activity_action = sprintf( __( '%1$s started the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug .'/">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' );
111
  $activity_content = bp_create_excerpt( $topic_text );
112
 
113
  // Record this in activity streams
114
  groups_record_activity( array(
115
  'action' => apply_filters_ref_array( 'groups_activity_new_forum_topic_action', array( $activity_action, $topic_text, &$topic ) ),
116
  'content' => apply_filters_ref_array( 'groups_activity_new_forum_topic_content', array( $activity_content, $topic_text, &$topic ) ),
117
+ 'primary_link' => apply_filters( 'groups_activity_new_forum_topic_primary_link', bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/' ),
118
  'type' => 'new_forum_topic',
119
+ 'item_id' => $bp->groups->current_group->id,
120
  'secondary_item_id' => $topic->topic_id
121
  ) );
122
 
123
+ do_action_ref_array( 'groups_new_forum_topic', array( $bp->groups->current_group->id, &$topic ) );
124
 
125
  return $topic;
126
  }
128
  return false;
129
  }
130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  function groups_update_group_forum_topic( $topic_id, $topic_title, $topic_text, $topic_tags = false ) {
132
  global $bp;
133
 
135
  $topic_text = apply_filters( 'group_forum_topic_text_before_save', $topic_text );
136
 
137
  if ( $topic = bp_forums_update_topic( array( 'topic_title' => $topic_title, 'topic_text' => $topic_text, 'topic_id' => $topic_id, 'topic_tags' => $topic_tags ) ) ) {
138
+ // Update the activity stream item
139
+ if ( bp_is_active( 'activity' ) )
140
+ bp_activity_delete_by_item_id( array( 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $topic_id, 'component' => $bp->groups->id, 'type' => 'new_forum_topic' ) );
141
 
142
+ $activity_action = sprintf( __( '%1$s started the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( $topic->topic_poster ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug .'/">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' );
 
 
 
 
 
 
 
 
 
 
143
  $activity_content = bp_create_excerpt( $topic_text );
144
 
145
  // Record this in activity streams
146
  groups_record_activity( array(
 
147
  'action' => apply_filters_ref_array( 'groups_activity_new_forum_topic_action', array( $activity_action, $topic_text, &$topic ) ),
148
  'content' => apply_filters_ref_array( 'groups_activity_new_forum_topic_content', array( $activity_content, $topic_text, &$topic ) ),
149
+ 'primary_link' => apply_filters( 'groups_activity_new_forum_topic_primary_link', bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/' ),
150
  'type' => 'new_forum_topic',
151
+ 'item_id' => (int)$bp->groups->current_group->id,
152
+ 'user_id' => (int)$topic->topic_poster,
153
  'secondary_item_id' => $topic->topic_id,
154
  'recorded_time ' => $topic->topic_time
155
  ) );
162
  return false;
163
  }
164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  function groups_update_group_forum_post( $post_id, $post_text, $topic_id, $page = false ) {
166
  global $bp;
167
 
172
  if ( $post_id = bp_forums_insert_post( array( 'post_id' => $post_id, 'post_text' => $post_text, 'post_time' => $post->post_time, 'topic_id' => $topic_id, 'poster_id' => $post->poster_id ) ) ) {
173
  $topic = bp_forums_get_topic_details( $topic_id );
174
 
175
+ $activity_action = sprintf( __( '%1$s replied to the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( $post->poster_id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug .'">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' );
176
  $activity_content = bp_create_excerpt( $post_text );
177
+ $primary_link = bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/';
178
 
179
  if ( $page )
180
  $primary_link .= "?topic_page=" . $page;
181
 
182
+ // Fetch an existing entry and update if one exists.
183
+ if ( bp_is_active( 'activity' ) )
184
+ $id = bp_activity_get_activity_id( array( 'user_id' => $post->poster_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post', 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $post_id ) );
 
 
 
 
 
 
 
185
 
186
  // Update the entry in activity streams
187
  groups_record_activity( array(
188
  'id' => $id,
189
+ 'action' => apply_filters_ref_array( 'groups_activity_new_forum_post_action', array( $activity_action, $post_text, &$topic, &$forum_post ) ),
190
+ 'content' => apply_filters_ref_array( 'groups_activity_new_forum_post_content', array( $activity_content, $post_text, &$topic, &$forum_post ) ),
191
  'primary_link' => apply_filters( 'groups_activity_new_forum_post_primary_link', $primary_link . "#post-" . $post_id ),
192
  'type' => 'new_forum_post',
193
+ 'item_id' => (int)$bp->groups->current_group->id,
194
+ 'user_id' => (int)$post->poster_id,
195
  'secondary_item_id' => $post_id,
196
  'recorded_time' => $post->post_time
197
  ) );
205
  }
206
 
207
  /**
208
+ * Handles the forum topic deletion routine
 
 
209
  *
210
  * @package BuddyPress
211
  *
214
  * @uses bp_forums_delete_topic() to do the deletion itself
215
  * @param int $topic_id The id of the topic to be deleted
216
  * @return bool True if the delete routine went through properly
 
 
217
  */
218
  function groups_delete_group_forum_topic( $topic_id ) {
219
  global $bp;
224
  if ( bp_forums_delete_topic( array( 'topic_id' => $topic_id ) ) ) {
225
  do_action( 'groups_before_delete_group_forum_topic', $topic_id );
226
 
227
+ // Delete the activity stream items
228
  if ( bp_is_active( 'activity' ) ) {
229
  // The activity item for the initial topic
230
+ bp_activity_delete( array( 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $topic_id, 'component' => $bp->groups->id, 'type' => 'new_forum_topic' ) );
 
 
 
 
 
231
 
232
  // The activity item for each post
233
+ foreach ( (array)$posts as $post ) {
234
+ bp_activity_delete( array( 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $post->post_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post' ) );
 
 
 
 
 
235
  }
236
  }
237
 
244
  }
245
 
246
  /**
247
+ * Delete a forum post
 
 
248
  *
249
  * @package BuddyPress
250
  *
252
  * @param int $topic_id Optional. The topic to which the post belongs. This value isn't used in the
253
  * function but is passed along to do_action() hooks.
254
  * @return bool True on success.
 
 
255
  */
256
  function groups_delete_group_forum_post( $post_id, $topic_id = false ) {
257
  global $bp;
259
  if ( bp_forums_delete_post( array( 'post_id' => $post_id ) ) ) {
260
  do_action( 'groups_before_delete_group_forum_post', $post_id, $topic_id );
261
 
262
+ // Delete the activity stream item
263
  if ( bp_is_active( 'activity' ) )
264
+ bp_activity_delete( array( 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $post_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post' ) );
 
 
 
 
 
265
 
266
  do_action( 'groups_delete_group_forum_post', $post_id, $topic_id );
267
 
271
  return false;
272
  }
273
 
 
 
 
 
 
 
 
 
 
274
  function groups_total_public_forum_topic_count( $type = 'newest' ) {
275
  return apply_filters( 'groups_total_public_forum_topic_count', BP_Groups_Group::get_global_forum_topic_count( $type ) );
276
  }
bp-groups/bp-groups-functions.php CHANGED
@@ -1,15 +1,9 @@
1
  <?php
2
-
3
  /**
4
- * BuddyPress Groups Functions
5
- *
6
  * Functions are where all the magic happens in BuddyPress. They will
7
  * handle the actual saving or manipulation of information. Usually they will
8
  * hand off to a database class for data access, then return
9
  * true or false on success or failure.
10
- *
11
- * @package BuddyPress
12
- * @subpackage GroupsFunctions
13
  */
14
 
15
  // Exit if accessed directly
@@ -18,9 +12,9 @@ if ( !defined( 'ABSPATH' ) ) exit;
18
  /**
19
  * Checks $bp pages global and looks for directory page
20
  *
21
- * @since BuddyPress (1.5)
22
  *
23
- * @global BuddyPress $bp The one true BuddyPress instance
24
  * @return bool True if set, False if empty
25
  */
26
  function bp_groups_has_directory() {
@@ -29,16 +23,6 @@ function bp_groups_has_directory() {
29
  return (bool) !empty( $bp->pages->groups->id );
30
  }
31
 
32
- /**
33
- * Pulls up the database object corresponding to a group
34
- *
35
- * When calling up a group object, you should always use this function instead
36
- * of instantiating BP_Groups_Group directly, so that you will inherit cache
37
- * support and pass through the groups_get_group filter.
38
- *
39
- * @param $args The load_users parameter is deprecated and does nothing.
40
- * @return obj $group The group object
41
- */
42
  function groups_get_group( $args = '' ) {
43
  $defaults = array(
44
  'group_id' => false,
@@ -48,19 +32,13 @@ function groups_get_group( $args = '' ) {
48
  $args = wp_parse_args( $args, $defaults );
49
  extract( $args, EXTR_SKIP );
50
 
51
- $cache_key = 'bp_groups_group_' . $group_id . ( $load_users ? '_load_users' : '_noload_users' );
52
-
53
- if ( !$group = wp_cache_get( $cache_key, 'bp' ) ) {
54
- $group = new BP_Groups_Group( $group_id, true, $load_users );
55
- wp_cache_set( $cache_key, $group, 'bp' );
56
- }
57
-
58
- return apply_filters( 'groups_get_group', $group );
59
  }
60
 
61
  /*** Group Creation, Editing & Deletion *****************************************/
62
 
63
  function groups_create_group( $args = '' ) {
 
64
 
65
  extract( $args );
66
 
@@ -76,15 +54,15 @@ function groups_create_group( $args = '' ) {
76
  * 'date_created'
77
  */
78
 
79
- if ( !empty( $group_id ) )
80
- $group = groups_get_group( array( 'group_id' => $group_id ) );
81
  else
82
  $group = new BP_Groups_Group;
83
 
84
- if ( !empty( $creator_id ) )
85
  $group->creator_id = $creator_id;
86
  else
87
- $group->creator_id = bp_loggedin_user_id();
88
 
89
  if ( isset( $name ) )
90
  $group->name = $name;
@@ -96,14 +74,13 @@ function groups_create_group( $args = '' ) {
96
  $group->slug = $slug;
97
 
98
  if ( isset( $status ) ) {
99
- if ( groups_is_valid_status( $status ) ) {
100
  $group->status = $status;
101
- }
102
  }
103
 
104
  if ( isset( $enable_forum ) )
105
  $group->enable_forum = $enable_forum;
106
- else if ( empty( $group_id ) && !isset( $enable_forum ) )
107
  $group->enable_forum = 1;
108
 
109
  if ( isset( $date_created ) )
@@ -121,25 +98,26 @@ function groups_create_group( $args = '' ) {
121
  $member->user_title = __( 'Group Admin', 'buddypress' );
122
  $member->is_confirmed = 1;
123
  $member->date_modified = bp_core_current_time();
124
- $member->save();
125
 
 
126
  do_action( 'groups_create_group', $group->id, $member, $group );
127
 
128
  } else {
129
  do_action( 'groups_update_group', $group->id, $group );
130
  }
131
 
132
- do_action( 'groups_created_group', $group->id, $group );
133
 
134
  return $group->id;
135
  }
136
 
137
  function groups_edit_base_group_details( $group_id, $group_name, $group_desc, $notify_members ) {
 
138
 
139
  if ( empty( $group_name ) || empty( $group_desc ) )
140
  return false;
141
 
142
- $group = groups_get_group( array( 'group_id' => $group_id ) );
143
  $group->name = $group_name;
144
  $group->description = $group_desc;
145
 
@@ -156,8 +134,9 @@ function groups_edit_base_group_details( $group_id, $group_name, $group_desc, $n
156
  }
157
 
158
  function groups_edit_group_settings( $group_id, $enable_forum, $status, $invite_status = false ) {
 
159
 
160
- $group = groups_get_group( array( 'group_id' => $group_id ) );
161
  $group->enable_forum = $enable_forum;
162
 
163
  /***
@@ -201,11 +180,11 @@ function groups_delete_group( $group_id ) {
201
  global $bp;
202
 
203
  // Check the user is the group admin.
204
- if ( ! bp_is_item_admin() )
205
  return false;
206
 
207
  // Get the group object
208
- $group = groups_get_group( array( 'group_id' => $group_id ) );
209
  if ( !$group->delete() )
210
  return false;
211
 
@@ -221,6 +200,12 @@ function groups_delete_group( $group_id ) {
221
  // Remove all notifications for any user belonging to this group
222
  bp_core_delete_all_notifications_by_type( $group_id, $bp->groups->id );
223
 
 
 
 
 
 
 
224
  do_action( 'groups_delete_group', $group_id);
225
 
226
  return true;
@@ -229,7 +214,7 @@ function groups_delete_group( $group_id ) {
229
  function groups_is_valid_status( $status ) {
230
  global $bp;
231
 
232
- return in_array( $status, (array) $bp->groups->valid_status );
233
  }
234
 
235
  function groups_check_slug( $slug ) {
@@ -238,7 +223,7 @@ function groups_check_slug( $slug ) {
238
  if ( 'wp' == substr( $slug, 0, 2 ) )
239
  $slug = substr( $slug, 2, strlen( $slug ) - 2 );
240
 
241
- if ( in_array( $slug, (array) $bp->groups->forbidden_names ) )
242
  $slug = $slug . '-' . rand();
243
 
244
  if ( BP_Groups_Group::check_slug( $slug ) ) {
@@ -251,27 +236,9 @@ function groups_check_slug( $slug ) {
251
  return $slug;
252
  }
253
 
254
- /**
255
- * Get a group slug by its ID
256
- *
257
- * @param int $group_id The numeric ID of the group
258
- * @return string The group's slug
259
- */
260
  function groups_get_slug( $group_id ) {
261
- $group = groups_get_group( array( 'group_id' => $group_id ) );
262
- return !empty( $group->slug ) ? $group->slug : '';
263
- }
264
-
265
- /**
266
- * Get a group ID by its slug
267
- *
268
- * @since 1.6
269
- *
270
- * @param string $group_slug The group's slug
271
- * @return int The ID
272
- */
273
- function groups_get_id( $group_slug ) {
274
- return (int)BP_Groups_Group::group_exists( $group_slug );
275
  }
276
 
277
  /*** User Actions ***************************************************************/
@@ -279,8 +246,8 @@ function groups_get_id( $group_slug ) {
279
  function groups_leave_group( $group_id, $user_id = 0 ) {
280
  global $bp;
281
 
282
- if ( empty( $user_id ) )
283
- $user_id = bp_loggedin_user_id();
284
 
285
  // Don't let single admins leave the group.
286
  if ( count( groups_get_group_admins( $group_id ) ) < 2 ) {
@@ -320,14 +287,14 @@ function groups_leave_group( $group_id, $user_id = 0 ) {
320
  function groups_join_group( $group_id, $user_id = 0 ) {
321
  global $bp;
322
 
323
- if ( empty( $user_id ) )
324
- $user_id = bp_loggedin_user_id();
325
 
326
- // Check if the user has an outstanding invite. If so, delete it.
327
  if ( groups_check_user_has_invite( $user_id, $group_id ) )
328
  groups_delete_invite( $user_id, $group_id );
329
 
330
- // Check if the user has an outstanding request. If so, delete it.
331
  if ( groups_check_for_membership_request( $user_id, $group_id ) )
332
  groups_delete_membership_request( $user_id, $group_id );
333
 
@@ -348,7 +315,7 @@ function groups_join_group( $group_id, $user_id = 0 ) {
348
  return false;
349
 
350
  if ( !isset( $bp->groups->current_group ) || !$bp->groups->current_group || $group_id != $bp->groups->current_group->id )
351
- $group = groups_get_group( array( 'group_id' => $group_id ) );
352
  else
353
  $group = $bp->groups->current_group;
354
 
@@ -371,6 +338,10 @@ function groups_join_group( $group_id, $user_id = 0 ) {
371
 
372
  /*** General Group Functions ****************************************************/
373
 
 
 
 
 
374
  function groups_get_group_admins( $group_id ) {
375
  return BP_Groups_Member::get_group_administrator_ids( $group_id );
376
  }
@@ -390,6 +361,7 @@ function groups_get_total_member_count( $group_id ) {
390
  /*** Group Fetching, Filtering & Searching *************************************/
391
 
392
  function groups_get_groups( $args = '' ) {
 
393
 
394
  $defaults = array(
395
  'type' => 'active', // active, newest, alphabetical, random, popular, most-forum-topics or most-forum-posts
@@ -398,6 +370,7 @@ function groups_get_groups( $args = '' ) {
398
  'exclude' => false, // Do not include these specific groups (group_ids)
399
  'search_terms' => false, // Limit to groups that match these search terms
400
  'show_hidden' => false, // Show hidden groups to non-admins
 
401
  'per_page' => 20, // The number of results to return per page
402
  'page' => 1, // The page to return if limiting per page
403
  'populate_extras' => true, // Fetch meta such as is_banned and is_member
@@ -421,17 +394,19 @@ function groups_get_total_group_count() {
421
  }
422
 
423
  function groups_get_user_groups( $user_id = 0, $pag_num = 0, $pag_page = 0 ) {
 
424
 
425
- if ( empty( $user_id ) )
426
- $user_id = bp_displayed_user_id();
427
 
428
  return BP_Groups_Member::get_group_ids( $user_id, $pag_num, $pag_page );
429
  }
430
 
431
  function groups_total_groups_for_user( $user_id = 0 ) {
 
432
 
433
- if ( empty( $user_id ) )
434
- $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
435
 
436
  if ( !$count = wp_cache_get( 'bp_total_groups_for_user_' . $user_id, 'bp' ) ) {
437
  $count = BP_Groups_Member::total_group_count( $user_id );
@@ -445,7 +420,7 @@ function groups_total_groups_for_user( $user_id = 0 ) {
445
  * Returns the group object for the group currently being viewed
446
  *
447
  * @package BuddyPress
448
- * @since BuddyPress (1.5)
449
  *
450
  * @return obj The current group object
451
  */
@@ -515,7 +490,7 @@ function groups_post_update( $args = '' ) {
515
 
516
  $defaults = array(
517
  'content' => false,
518
- 'user_id' => bp_loggedin_user_id(),
519
  'group_id' => 0
520
  );
521
 
@@ -528,10 +503,10 @@ function groups_post_update( $args = '' ) {
528
  if ( empty( $content ) || !strlen( trim( $content ) ) || empty( $user_id ) || empty( $group_id ) )
529
  return false;
530
 
531
- $bp->groups->current_group = groups_get_group( array( 'group_id' => $group_id ) );
532
 
533
  // Be sure the user is a member of the group before posting.
534
- if ( !bp_current_user_can( 'bp_moderate' ) && !groups_is_user_member( $user_id, $group_id ) )
535
  return false;
536
 
537
  // Record this in activity streams
@@ -555,19 +530,21 @@ function groups_post_update( $args = '' ) {
555
  /*** Group Invitations *********************************************************/
556
 
557
  function groups_get_invites_for_user( $user_id = 0, $limit = false, $page = false, $exclude = false ) {
 
558
 
559
- if ( empty( $user_id ) )
560
- $user_id = bp_loggedin_user_id();
561
 
562
  return BP_Groups_Member::get_invites( $user_id, $limit, $page, $exclude );
563
  }
564
 
565
  function groups_invite_user( $args = '' ) {
 
566
 
567
  $defaults = array(
568
  'user_id' => false,
569
  'group_id' => false,
570
- 'inviter_id' => bp_loggedin_user_id(),
571
  'date_modified' => bp_core_current_time(),
572
  'is_confirmed' => 0
573
  );
@@ -575,7 +552,7 @@ function groups_invite_user( $args = '' ) {
575
  $args = wp_parse_args( $args, $defaults );
576
  extract( $args, EXTR_SKIP );
577
 
578
- if ( empty( $user_id ) || empty( $group_id ) )
579
  return false;
580
 
581
  if ( !groups_is_user_member( $user_id, $group_id ) && !groups_check_user_has_invite( $user_id, $group_id, 'all' ) ) {
@@ -596,6 +573,7 @@ function groups_invite_user( $args = '' ) {
596
  }
597
 
598
  function groups_uninvite_user( $user_id, $group_id ) {
 
599
 
600
  if ( !BP_Groups_Member::delete( $user_id, $group_id ) )
601
  return false;
@@ -605,29 +583,11 @@ function groups_uninvite_user( $user_id, $group_id ) {
605
  return true;
606
  }
607
 
608
- /**
609
- * Process the acceptance of a group invitation.
610
- *
611
- * Returns true if a user is already a member of the group.
612
- *
613
- * @param int $user_id
614
- * @param int $group_id
615
- * @return bool True when the user is a member of the group, otherwise false
616
- */
617
  function groups_accept_invite( $user_id, $group_id ) {
618
  global $bp;
619
 
620
- // If the user is already a member (because BP at one point allowed two invitations to
621
- // slip through), delete all existing invitations/requests and return true
622
- if ( groups_is_user_member( $user_id, $group_id ) ) {
623
- if ( groups_check_user_has_invite( $user_id, $group_id ) )
624
- groups_delete_invite( $user_id, $group_id );
625
-
626
- if ( groups_check_for_membership_request( $user_id, $group_id ) )
627
- groups_delete_membership_request( $user_id, $group_id );
628
-
629
- return true;
630
- }
631
 
632
  $member = new BP_Groups_Member( $user_id, $group_id );
633
  $member->accept_invite();
@@ -670,13 +630,14 @@ function groups_delete_invite( $user_id, $group_id ) {
670
  }
671
 
672
  function groups_send_invites( $user_id, $group_id ) {
 
673
 
674
- if ( empty( $user_id ) )
675
- $user_id = bp_loggedin_user_id();
676
 
677
  // Send friend invites.
678
  $invited_users = groups_get_invites_for_group( $user_id, $group_id );
679
- $group = groups_get_group( array( 'group_id' => $group_id ) );
680
 
681
  for ( $i = 0, $count = count( $invited_users ); $i < $count; ++$i ) {
682
  $member = new BP_Groups_Member( $invited_users[$i], $group_id );
@@ -720,25 +681,20 @@ function groups_delete_all_group_invites( $group_id ) {
720
  /*** Group Promotion & Banning *************************************************/
721
 
722
  function groups_promote_member( $user_id, $group_id, $status ) {
 
723
 
724
- if ( ! bp_is_item_admin() )
725
  return false;
726
 
727
  $member = new BP_Groups_Member( $user_id, $group_id );
728
 
729
- // Don't use this action. It's deprecated as of BuddyPress 1.6.
730
  do_action( 'groups_premote_member', $group_id, $user_id, $status );
731
 
732
- // Use this action instead.
733
- do_action( 'groups_promote_member', $group_id, $user_id, $status );
734
-
735
  return $member->promote( $status );
736
  }
737
 
738
  function groups_demote_member( $user_id, $group_id ) {
739
-
740
- if ( ! bp_is_item_admin() )
741
- return false;
742
 
743
  $member = new BP_Groups_Member( $user_id, $group_id );
744
 
@@ -748,8 +704,9 @@ function groups_demote_member( $user_id, $group_id ) {
748
  }
749
 
750
  function groups_ban_member( $user_id, $group_id ) {
 
751
 
752
- if ( ! bp_is_item_admin() )
753
  return false;
754
 
755
  $member = new BP_Groups_Member( $user_id, $group_id );
@@ -760,8 +717,9 @@ function groups_ban_member( $user_id, $group_id ) {
760
  }
761
 
762
  function groups_unban_member( $user_id, $group_id ) {
 
763
 
764
- if ( ! bp_is_item_admin() )
765
  return false;
766
 
767
  $member = new BP_Groups_Member( $user_id, $group_id );
@@ -774,8 +732,9 @@ function groups_unban_member( $user_id, $group_id ) {
774
  /*** Group Removal *******************************************************/
775
 
776
  function groups_remove_member( $user_id, $group_id ) {
 
777
 
778
- if ( ! bp_is_item_admin() )
779
  return false;
780
 
781
  $member = new BP_Groups_Member( $user_id, $group_id );
@@ -788,6 +747,7 @@ function groups_remove_member( $user_id, $group_id ) {
788
  /*** Group Membership ****************************************************/
789
 
790
  function groups_send_membership_request( $requesting_user_id, $group_id ) {
 
791
 
792
  // Prevent duplicate requests
793
  if ( groups_check_for_membership_request( $requesting_user_id, $group_id ) )
@@ -823,8 +783,9 @@ function groups_send_membership_request( $requesting_user_id, $group_id ) {
823
  }
824
 
825
  function groups_accept_membership_request( $membership_id, $user_id = 0, $group_id = 0 ) {
 
826
 
827
- if ( !empty( $user_id ) && !empty( $group_id ) )
828
  $membership = new BP_Groups_Member( $user_id, $group_id );
829
  else
830
  $membership = new BP_Groups_Member( false, false, $membership_id );
@@ -842,7 +803,7 @@ function groups_accept_membership_request( $membership_id, $user_id = 0, $group_
842
  groups_update_groupmeta( $membership->group_id, 'total_member_count', (int) groups_get_groupmeta( $membership->group_id, 'total_member_count') + 1 );
843
 
844
  // Record this in activity streams
845
- $group = groups_get_group( array( 'group_id' => $membership->group_id ) );
846
 
847
  groups_record_activity( array(
848
  'action' => apply_filters_ref_array( 'groups_activity_membership_accepted_action', array( sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( $membership->user_id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>' ), $membership->user_id, &$group ) ),
@@ -872,7 +833,7 @@ function groups_reject_membership_request( $membership_id, $user_id = 0, $group_
872
  }
873
 
874
  function groups_delete_membership_request( $membership_id, $user_id = 0, $group_id = 0 ) {
875
- if ( !empty( $user_id ) && !empty( $group_id ) )
876
  $membership = new BP_Groups_Member( $user_id, $group_id );
877
  else
878
  $membership = new BP_Groups_Member( false, false, $membership_id );
@@ -940,8 +901,7 @@ function groups_get_groupmeta( $group_id, $meta_key = '') {
940
  if ( !empty($meta_key) ) {
941
  $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
942
 
943
- $metas = wp_cache_get( 'bp_groups_groupmeta_' . $group_id . '_' . $meta_key, 'bp' );
944
- if ( false === $metas ) {
945
  $metas = $wpdb->get_col( $wpdb->prepare("SELECT meta_value FROM " . $bp->groups->table_name_groupmeta . " WHERE group_id = %d AND meta_key = %s", $group_id, $meta_key) );
946
  wp_cache_set( 'bp_groups_groupmeta_' . $group_id . '_' . $meta_key, $metas, 'bp' );
947
  }
@@ -956,7 +916,7 @@ function groups_get_groupmeta( $group_id, $meta_key = '') {
956
  return '';
957
  }
958
 
959
- $metas = array_map( 'maybe_unserialize', (array) $metas );
960
 
961
  if ( 1 == count( $metas ) )
962
  return $metas[0];
@@ -977,6 +937,9 @@ function groups_update_groupmeta( $group_id, $meta_key, $meta_value ) {
977
 
978
  $meta_value = maybe_serialize( $meta_value );
979
 
 
 
 
980
  $cur = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $bp->groups->table_name_groupmeta . " WHERE group_id = %d AND meta_key = %s", $group_id, $meta_key ) );
981
 
982
  if ( !$cur )
@@ -995,16 +958,12 @@ function groups_update_groupmeta( $group_id, $meta_key, $meta_value ) {
995
  /*** Group Cleanup Functions ****************************************************/
996
 
997
  function groups_remove_data_for_user( $user_id ) {
998
- global $bp;
999
-
1000
  BP_Groups_Member::delete_all_for_user( $user_id );
1001
 
1002
- bp_core_delete_notifications_from_user( $user_id, $bp->groups->id, 'new_membership_request' );
1003
-
1004
  do_action( 'groups_remove_data_for_user', $user_id );
1005
  }
1006
  add_action( 'wpmu_delete_user', 'groups_remove_data_for_user' );
1007
  add_action( 'delete_user', 'groups_remove_data_for_user' );
1008
  add_action( 'bp_make_spam_user', 'groups_remove_data_for_user' );
1009
 
1010
- ?>
1
  <?php
 
2
  /**
 
 
3
  * Functions are where all the magic happens in BuddyPress. They will
4
  * handle the actual saving or manipulation of information. Usually they will
5
  * hand off to a database class for data access, then return
6
  * true or false on success or failure.
 
 
 
7
  */
8
 
9
  // Exit if accessed directly
12
  /**
13
  * Checks $bp pages global and looks for directory page
14
  *
15
+ * @since 1.5
16
  *
17
+ * @global object $bp Global BuddyPress settings object
18
  * @return bool True if set, False if empty
19
  */
20
  function bp_groups_has_directory() {
23
  return (bool) !empty( $bp->pages->groups->id );
24
  }
25
 
 
 
 
 
 
 
 
 
 
 
26
  function groups_get_group( $args = '' ) {
27
  $defaults = array(
28
  'group_id' => false,
32
  $args = wp_parse_args( $args, $defaults );
33
  extract( $args, EXTR_SKIP );
34
 
35
+ return apply_filters( 'groups_get_group', new BP_Groups_Group( $group_id, true, $load_users ) );
 
 
 
 
 
 
 
36
  }
37
 
38
  /*** Group Creation, Editing & Deletion *****************************************/
39
 
40
  function groups_create_group( $args = '' ) {
41
+ global $bp;
42
 
43
  extract( $args );
44
 
54
  * 'date_created'
55
  */
56
 
57
+ if ( isset( $group_id ) && $group_id )
58
+ $group = new BP_Groups_Group( $group_id );
59
  else
60
  $group = new BP_Groups_Group;
61
 
62
+ if ( isset( $creator_id ) && $creator_id )
63
  $group->creator_id = $creator_id;
64
  else
65
+ $group->creator_id = $bp->loggedin_user->id;
66
 
67
  if ( isset( $name ) )
68
  $group->name = $name;
74
  $group->slug = $slug;
75
 
76
  if ( isset( $status ) ) {
77
+ if ( groups_is_valid_status( $status ) )
78
  $group->status = $status;
 
79
  }
80
 
81
  if ( isset( $enable_forum ) )
82
  $group->enable_forum = $enable_forum;
83
+ else if ( !$group_id && !isset( $enable_forum ) )
84
  $group->enable_forum = 1;
85
 
86
  if ( isset( $date_created ) )
98
  $member->user_title = __( 'Group Admin', 'buddypress' );
99
  $member->is_confirmed = 1;
100
  $member->date_modified = bp_core_current_time();
 
101
 
102
+ $member->save();
103
  do_action( 'groups_create_group', $group->id, $member, $group );
104
 
105
  } else {
106
  do_action( 'groups_update_group', $group->id, $group );
107
  }
108
 
109
+ do_action( 'groups_created_group', $group->id );
110
 
111
  return $group->id;
112
  }
113
 
114
  function groups_edit_base_group_details( $group_id, $group_name, $group_desc, $notify_members ) {
115
+ global $bp;
116
 
117
  if ( empty( $group_name ) || empty( $group_desc ) )
118
  return false;
119
 
120
+ $group = new BP_Groups_Group( $group_id );
121
  $group->name = $group_name;
122
  $group->description = $group_desc;
123
 
134
  }
135
 
136
  function groups_edit_group_settings( $group_id, $enable_forum, $status, $invite_status = false ) {
137
+ global $bp;
138
 
139
+ $group = new BP_Groups_Group( $group_id );
140
  $group->enable_forum = $enable_forum;
141
 
142
  /***
180
  global $bp;
181
 
182
  // Check the user is the group admin.
183
+ if ( !$bp->is_item_admin )
184
  return false;
185
 
186
  // Get the group object
187
+ $group = new BP_Groups_Group( $group_id );
188
  if ( !$group->delete() )
189
  return false;
190
 
200
  // Remove all notifications for any user belonging to this group
201
  bp_core_delete_all_notifications_by_type( $group_id, $bp->groups->id );
202
 
203
+ // Remove forum if component is active and current group has one
204
+ if ( bp_is_active( 'forums' ) && $forum_id = groups_get_groupmeta( $group_id, 'forum_id' ) ) {
205
+ do_action( 'bbpress_init' );
206
+ bb_delete_forum( $forum_id );
207
+ }
208
+
209
  do_action( 'groups_delete_group', $group_id);
210
 
211
  return true;
214
  function groups_is_valid_status( $status ) {
215
  global $bp;
216
 
217
+ return in_array( $status, (array)$bp->groups->valid_status );
218
  }
219
 
220
  function groups_check_slug( $slug ) {
223
  if ( 'wp' == substr( $slug, 0, 2 ) )
224
  $slug = substr( $slug, 2, strlen( $slug ) - 2 );
225
 
226
+ if ( in_array( $slug, (array)$bp->groups->forbidden_names ) )
227
  $slug = $slug . '-' . rand();
228
 
229
  if ( BP_Groups_Group::check_slug( $slug ) ) {
236
  return $slug;
237
  }
238
 
 
 
 
 
 
 
239
  function groups_get_slug( $group_id ) {
240
+ $group = new BP_Groups_Group( $group_id );
241
+ return $group->slug;
 
 
 
 
 
 
 
 
 
 
 
 
242
  }
243
 
244
  /*** User Actions ***************************************************************/
246
  function groups_leave_group( $group_id, $user_id = 0 ) {
247
  global $bp;
248
 
249
+ if ( !$user_id )
250
+ $user_id = $bp->loggedin_user->id;
251
 
252
  // Don't let single admins leave the group.
253
  if ( count( groups_get_group_admins( $group_id ) ) < 2 ) {
287
  function groups_join_group( $group_id, $user_id = 0 ) {
288
  global $bp;
289
 
290
+ if ( !$user_id )
291
+ $user_id = $bp->loggedin_user->id;
292
 
293
+ // Check if the user has an outstanding invite, is so delete it.
294
  if ( groups_check_user_has_invite( $user_id, $group_id ) )
295
  groups_delete_invite( $user_id, $group_id );
296
 
297
+ // Check if the user has an outstanding request, is so delete it.
298
  if ( groups_check_for_membership_request( $user_id, $group_id ) )
299
  groups_delete_membership_request( $user_id, $group_id );
300
 
315
  return false;
316
 
317
  if ( !isset( $bp->groups->current_group ) || !$bp->groups->current_group || $group_id != $bp->groups->current_group->id )
318
+ $group = new BP_Groups_Group( $group_id );
319
  else
320
  $group = $bp->groups->current_group;
321
 
338
 
339
  /*** General Group Functions ****************************************************/
340
 
341
+ function groups_check_group_exists( $group_id ) {
342
+ return BP_Groups_Group::group_exists( $group_id );
343
+ }
344
+
345
  function groups_get_group_admins( $group_id ) {
346
  return BP_Groups_Member::get_group_administrator_ids( $group_id );
347
  }
361
  /*** Group Fetching, Filtering & Searching *************************************/
362
 
363
  function groups_get_groups( $args = '' ) {
364
+ global $bp;
365
 
366
  $defaults = array(
367
  'type' => 'active', // active, newest, alphabetical, random, popular, most-forum-topics or most-forum-posts
370
  'exclude' => false, // Do not include these specific groups (group_ids)
371
  'search_terms' => false, // Limit to groups that match these search terms
372
  'show_hidden' => false, // Show hidden groups to non-admins
373
+
374
  'per_page' => 20, // The number of results to return per page
375
  'page' => 1, // The page to return if limiting per page
376
  'populate_extras' => true, // Fetch meta such as is_banned and is_member
394
  }
395
 
396
  function groups_get_user_groups( $user_id = 0, $pag_num = 0, $pag_page = 0 ) {
397
+ global $bp;
398
 
399
+ if ( !$user_id )
400
+ $user_id = $bp->displayed_user->id;
401
 
402
  return BP_Groups_Member::get_group_ids( $user_id, $pag_num, $pag_page );
403
  }
404
 
405
  function groups_total_groups_for_user( $user_id = 0 ) {
406
+ global $bp;
407
 
408
+ if ( !$user_id )
409
+ $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
410
 
411
  if ( !$count = wp_cache_get( 'bp_total_groups_for_user_' . $user_id, 'bp' ) ) {
412
  $count = BP_Groups_Member::total_group_count( $user_id );
420
  * Returns the group object for the group currently being viewed
421
  *
422
  * @package BuddyPress
423
+ * @since 1.5
424
  *
425
  * @return obj The current group object
426
  */
490
 
491
  $defaults = array(
492
  'content' => false,
493
+ 'user_id' => $bp->loggedin_user->id,
494
  'group_id' => 0
495
  );
496
 
503
  if ( empty( $content ) || !strlen( trim( $content ) ) || empty( $user_id ) || empty( $group_id ) )
504
  return false;
505
 
506
+ $bp->groups->current_group = new BP_Groups_Group( $group_id );
507
 
508
  // Be sure the user is a member of the group before posting.
509
+ if ( !is_super_admin() && !groups_is_user_member( $user_id, $group_id ) )
510
  return false;
511
 
512
  // Record this in activity streams
530
  /*** Group Invitations *********************************************************/
531
 
532
  function groups_get_invites_for_user( $user_id = 0, $limit = false, $page = false, $exclude = false ) {
533
+ global $bp;
534
 
535
+ if ( !$user_id )
536
+ $user_id = $bp->loggedin_user->id;
537
 
538
  return BP_Groups_Member::get_invites( $user_id, $limit, $page, $exclude );
539
  }
540
 
541
  function groups_invite_user( $args = '' ) {
542
+ global $bp;
543
 
544
  $defaults = array(
545
  'user_id' => false,
546
  'group_id' => false,
547
+ 'inviter_id' => $bp->loggedin_user->id,
548
  'date_modified' => bp_core_current_time(),
549
  'is_confirmed' => 0
550
  );
552
  $args = wp_parse_args( $args, $defaults );
553
  extract( $args, EXTR_SKIP );
554
 
555
+ if ( !$user_id || !$group_id )
556
  return false;
557
 
558
  if ( !groups_is_user_member( $user_id, $group_id ) && !groups_check_user_has_invite( $user_id, $group_id, 'all' ) ) {
573
  }
574
 
575
  function groups_uninvite_user( $user_id, $group_id ) {
576
+ global $bp;
577
 
578
  if ( !BP_Groups_Member::delete( $user_id, $group_id ) )
579
  return false;
583
  return true;
584
  }
585
 
 
 
 
 
 
 
 
 
 
586
  function groups_accept_invite( $user_id, $group_id ) {
587
  global $bp;
588
 
589
+ if ( groups_is_user_member( $user_id, $group_id ) )
590
+ return false;
 
 
 
 
 
 
 
 
 
591
 
592
  $member = new BP_Groups_Member( $user_id, $group_id );
593
  $member->accept_invite();
630
  }
631
 
632
  function groups_send_invites( $user_id, $group_id ) {
633
+ global $bp;
634
 
635
+ if ( !$user_id )
636
+ $user_id = $bp->loggedin_user->id;
637
 
638
  // Send friend invites.
639
  $invited_users = groups_get_invites_for_group( $user_id, $group_id );
640
+ $group = new BP_Groups_Group( $group_id );
641
 
642
  for ( $i = 0, $count = count( $invited_users ); $i < $count; ++$i ) {
643
  $member = new BP_Groups_Member( $invited_users[$i], $group_id );
681
  /*** Group Promotion & Banning *************************************************/
682
 
683
  function groups_promote_member( $user_id, $group_id, $status ) {
684
+ global $bp;
685
 
686
+ if ( !$bp->is_item_admin )
687
  return false;
688
 
689
  $member = new BP_Groups_Member( $user_id, $group_id );
690
 
 
691
  do_action( 'groups_premote_member', $group_id, $user_id, $status );
692
 
 
 
 
693
  return $member->promote( $status );
694
  }
695
 
696
  function groups_demote_member( $user_id, $group_id ) {
697
+ global $bp;
 
 
698
 
699
  $member = new BP_Groups_Member( $user_id, $group_id );
700
 
704
  }
705
 
706
  function groups_ban_member( $user_id, $group_id ) {
707
+ global $bp;
708
 
709
+ if ( !$bp->is_item_admin )
710
  return false;
711
 
712
  $member = new BP_Groups_Member( $user_id, $group_id );
717
  }
718
 
719
  function groups_unban_member( $user_id, $group_id ) {
720
+ global $bp;
721
 
722
+ if ( !$bp->is_item_admin )
723
  return false;
724
 
725
  $member = new BP_Groups_Member( $user_id, $group_id );
732
  /*** Group Removal *******************************************************/
733
 
734
  function groups_remove_member( $user_id, $group_id ) {
735
+ global $bp;
736
 
737
+ if ( !$bp->is_item_admin )
738
  return false;
739
 
740
  $member = new BP_Groups_Member( $user_id, $group_id );
747
  /*** Group Membership ****************************************************/
748
 
749
  function groups_send_membership_request( $requesting_user_id, $group_id ) {
750
+ global $bp;
751
 
752
  // Prevent duplicate requests
753
  if ( groups_check_for_membership_request( $requesting_user_id, $group_id ) )
783
  }
784
 
785
  function groups_accept_membership_request( $membership_id, $user_id = 0, $group_id = 0 ) {
786
+ global $bp;
787
 
788
+ if ( $user_id && $group_id )
789
  $membership = new BP_Groups_Member( $user_id, $group_id );
790
  else
791
  $membership = new BP_Groups_Member( false, false, $membership_id );
803
  groups_update_groupmeta( $membership->group_id, 'total_member_count', (int) groups_get_groupmeta( $membership->group_id, 'total_member_count') + 1 );
804
 
805
  // Record this in activity streams
806
+ $group = new BP_Groups_Group( $membership->group_id );
807
 
808
  groups_record_activity( array(
809
  'action' => apply_filters_ref_array( 'groups_activity_membership_accepted_action', array( sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( $membership->user_id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>' ), $membership->user_id, &$group ) ),
833
  }
834
 
835
  function groups_delete_membership_request( $membership_id, $user_id = 0, $group_id = 0 ) {
836
+ if ( $user_id && $group_id )
837
  $membership = new BP_Groups_Member( $user_id, $group_id );
838
  else
839
  $membership = new BP_Groups_Member( false, false, $membership_id );
901
  if ( !empty($meta_key) ) {
902
  $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
903
 
904
+ if ( !$metas = wp_cache_get( 'bp_groups_groupmeta_' . $group_id . '_' . $meta_key, 'bp' ) ) {
 
905
  $metas = $wpdb->get_col( $wpdb->prepare("SELECT meta_value FROM " . $bp->groups->table_name_groupmeta . " WHERE group_id = %d AND meta_key = %s", $group_id, $meta_key) );
906
  wp_cache_set( 'bp_groups_groupmeta_' . $group_id . '_' . $meta_key, $metas, 'bp' );
907
  }
916
  return '';
917
  }
918
 
919
+ $metas = array_map( 'maybe_unserialize', (array)$metas );
920
 
921
  if ( 1 == count( $metas ) )
922
  return $metas[0];
937
 
938
  $meta_value = maybe_serialize( $meta_value );
939
 
940
+ if ( empty( $meta_value ) )
941
+ return groups_delete_groupmeta( $group_id, $meta_key );
942
+
943
  $cur = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $bp->groups->table_name_groupmeta . " WHERE group_id = %d AND meta_key = %s", $group_id, $meta_key ) );
944
 
945
  if ( !$cur )
958
  /*** Group Cleanup Functions ****************************************************/
959
 
960
  function groups_remove_data_for_user( $user_id ) {
 
 
961
  BP_Groups_Member::delete_all_for_user( $user_id );
962
 
 
 
963
  do_action( 'groups_remove_data_for_user', $user_id );
964
  }
965
  add_action( 'wpmu_delete_user', 'groups_remove_data_for_user' );
966
  add_action( 'delete_user', 'groups_remove_data_for_user' );
967
  add_action( 'bp_make_spam_user', 'groups_remove_data_for_user' );
968
 
969
+ ?>
bp-groups/bp-groups-loader.php CHANGED
@@ -1,5 +1,4 @@
1
  <?php
2
-
3
  /**
4
  * BuddyPress Groups Loader
5
  *
@@ -8,7 +7,7 @@
8
  * Comes preconfigured with an activity stream, discussion forums, and settings.
9
  *
10
  * @package BuddyPress
11
- * @subpackage GroupsLoader
12
  */
13
 
14
  // Exit if accessed directly
@@ -16,66 +15,10 @@ if ( !defined( 'ABSPATH' ) ) exit;
16
 
17
  class BP_Groups_Component extends BP_Component {
18
 
19
- /**
20
- * Auto join group when non group member performs group activity
21
- *
22
- * @since BuddyPress (1.5)
23
- * @var bool
24
- */
25
- public $auto_join;
26
-
27
- /**
28
- * The group being currently accessed
29
- *
30
- * @since BuddyPress (1.5)
31
- * @var BP_Groups_Group
32
- */
33
- public $current_group;
34
-
35
- /**
36
- * Default group extension
37
- *
38
- * @since BuddyPress (1.6)
39
- * @todo Is this used anywhere? Is this a duplicate of $default_extension?
40
- */
41
- var $default_component;
42
-
43
- /**
44
- * Default group extension
45
- *
46
- * @since BuddyPress (1.6)
47
- * @var string
48
- */
49
- public $default_extension;
50
-
51
- /**
52
- * Illegal group names/slugs
53
- *
54
- * @since BuddyPress (1.5)
55
- * @var array
56
- */
57
- public $forbidden_names;
58
-
59
- /**
60
- * Group creation/edit steps (e.g. Details, Settings, Avatar, Invites)
61
- *
62
- * @since BuddyPress (1.5)
63
- * @var array
64
- */
65
- public $group_creation_steps;
66
-
67
- /**
68
- * Types of group statuses (Public, Private, Hidden)
69
- *
70
- * @since BuddyPress (1.5)
71
- * @var array
72
- */
73
- public $valid_status;
74
-
75
  /**
76
  * Start the groups component creation process
77
  *
78
- * @since BuddyPress (1.5)
79
  */
80
  function __construct() {
81
  parent::start(
@@ -113,8 +56,8 @@ class BP_Groups_Component extends BP_Component {
113
  * The BP_GROUPS_SLUG constant is deprecated, and only used here for
114
  * backwards compatibility.
115
  *
116
- * @since BuddyPress (1.5)
117
- * @global BuddyPress $bp The one true BuddyPress instance
118
  */
119
  function setup_globals() {
120
  global $bp;
@@ -133,6 +76,7 @@ class BP_Groups_Component extends BP_Component {
133
  // All globals for messaging component.
134
  // Note that global_tables is included in this array.
135
  $globals = array(
 
136
  'slug' => BP_GROUPS_SLUG,
137
  'root_slug' => isset( $bp->pages->groups->slug ) ? $bp->pages->groups->slug : BP_GROUPS_SLUG,
138
  'has_directory' => true,
@@ -159,17 +103,17 @@ class BP_Groups_Component extends BP_Component {
159
  array_shift( $bp->action_variables );
160
 
161
  // Using "item" not "group" for generic support in other components.
162
- if ( bp_current_user_can( 'bp_moderate' ) )
163
  bp_update_is_item_admin( true, 'groups' );
164
  else
165
- bp_update_is_item_admin( groups_is_user_admin( bp_loggedin_user_id(), $this->current_group->id ), 'groups' );
166
 
167
  // If the user is not an admin, check if they are a moderator
168
  if ( !bp_is_item_admin() )
169
- bp_update_is_item_mod ( groups_is_user_mod ( bp_loggedin_user_id(), $this->current_group->id ), 'groups' );
170
 
171
  // Is the logged in user a member of the group?
172
- if ( ( is_user_logged_in() && groups_is_user_member( bp_loggedin_user_id(), $this->current_group->id ) ) )
173
  $this->current_group->is_user_member = true;
174
  else
175
  $this->current_group->is_user_member = false;
@@ -182,7 +126,7 @@ class BP_Groups_Component extends BP_Component {
182
 
183
  // If this is a private or hidden group, does the user have access?
184
  if ( 'private' == $this->current_group->status || 'hidden' == $this->current_group->status ) {
185
- if ( $this->current_group->is_user_member && is_user_logged_in() || bp_current_user_can( 'bp_moderate' ) )
186
  $this->current_group->user_has_access = true;
187
  else
188
  $this->current_group->user_has_access = false;
@@ -214,77 +158,24 @@ class BP_Groups_Component extends BP_Component {
214
  ) );
215
 
216
  // If the user was attempting to access a group, but no group by that name was found, 404
217
- if ( bp_is_groups_component() && empty( $this->current_group ) && bp_current_action() && !in_array( bp_current_action(), $this->forbidden_names ) ) {
218
  bp_do_404();
219
  return;
220
  }
221
 
222
- if ( bp_is_groups_component() && !empty( $this->current_group ) ) {
223
-
224
- $this->default_extension = apply_filters( 'bp_groups_default_extension', defined( 'BP_GROUPS_DEFAULT_EXTENSION' ) ? BP_GROUPS_DEFAULT_EXTENSION : 'home' );
225
-
226
- if ( !bp_current_action() ) {
227
- $bp->current_action = $this->default_extension;
228
- }
229
-
230
- // Prepare for a redirect to the canonical URL
231
- $bp->canonical_stack['base_url'] = bp_get_group_permalink( $this->current_group );
232
-
233
- if ( bp_current_action() ) {
234
- $bp->canonical_stack['action'] = bp_current_action();
235
- }
236
-
237
- if ( !empty( $bp->action_variables ) ) {
238
- $bp->canonical_stack['action_variables'] = bp_action_variables();
239
- }
240
-
241
- // When viewing the default extension, the canonical URL should not have
242
- // that extension's slug, unless more has been tacked onto the URL via
243
- // action variables
244
- if ( bp_is_current_action( $this->default_extension ) && empty( $bp->action_variables ) ) {
245
- unset( $bp->canonical_stack['action'] );
246
- }
247
-
248
- }
249
-
250
  // Group access control
251
- if ( bp_is_groups_component() && !empty( $this->current_group ) ) {
252
- if ( !$this->current_group->user_has_access ) {
253
-
254
- // Hidden groups should return a 404 for non-members.
255
- // Unset the current group so that you're not redirected
256
- // to the default group tab
257
- if ( 'hidden' == $this->current_group->status ) {
258
- $this->current_group = 0;
259
- $bp->is_single_item = false;
260
- bp_do_404();
261
- return;
262
-
263
- // Skip the no_access check on home and membership request pages
264
- } elseif ( !bp_is_current_action( 'home' ) && !bp_is_current_action( 'request-membership' ) ) {
265
-
266
- // Off-limits to this user. Throw an error and redirect to the group's home page
267
- if ( is_user_logged_in() ) {
268
- bp_core_no_access( array(
269
- 'message' => __( 'You do not have access to this group.', 'buddypress' ),
270
- 'root' => bp_get_group_permalink( $bp->groups->current_group ),
271
- 'redirect' => false
272
- ) );
273
-
274
- // User does not have access, and does not get a message
275
- } else {
276
- bp_core_no_access();
277
- }
278
- }
279
- }
280
-
281
- // Protect the admin tab from non-admins
282
- if ( bp_is_current_action( 'admin' ) && !bp_is_item_admin() ) {
283
  bp_core_no_access( array(
284
- 'message' => __( 'You are not an admin of this group.', 'buddypress' ),
285
  'root' => bp_get_group_permalink( $bp->groups->current_group ),
286
  'redirect' => false
287
  ) );
 
 
 
288
  }
289
  }
290
 
@@ -330,12 +221,10 @@ class BP_Groups_Component extends BP_Component {
330
  /**
331
  * Setup BuddyBar navigation
332
  *
333
- * @global BuddyPress $bp The one true BuddyPress instance
334
  */
335
  function setup_nav() {
336
-
337
- // Define local variables
338
- $sub_nav = array();
339
 
340
  // Add 'Groups' to the main navigation
341
  $main_nav = array(
@@ -347,7 +236,7 @@ class BP_Groups_Component extends BP_Component {
347
  'item_css_id' => $this->id
348
  );
349
 
350
- $groups_link = trailingslashit( bp_loggedin_user_domain() . $this->slug );
351
 
352
  // Add the My Groups nav item
353
  $sub_nav[] = array(
@@ -375,8 +264,7 @@ class BP_Groups_Component extends BP_Component {
375
 
376
  if ( bp_is_groups_component() && bp_is_single_item() ) {
377
 
378
- // Reset sub nav
379
- $sub_nav = array();
380
 
381
  // Add 'Groups' to the main navigation
382
  $main_nav = array(
@@ -384,11 +272,11 @@ class BP_Groups_Component extends BP_Component {
384
  'slug' => $this->current_group->slug,
385
  'position' => -1, // Do not show in BuddyBar
386
  'screen_function' => 'groups_screen_group_home',
387
- 'default_subnav_slug' => $this->default_extension,
388
  'item_css_id' => $this->id
389
  );
390
 
391
- $group_link = bp_get_group_permalink( $this->current_group );
392
 
393
  // Add the "Home" subnav item, as this will always be present
394
  $sub_nav[] = array(
@@ -401,11 +289,25 @@ class BP_Groups_Component extends BP_Component {
401
  'item_css_id' => 'home'
402
  );
403
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
404
  // If this is a private group, and the user is not a member, show a "Request Membership" nav item.
405
  if ( is_user_logged_in() &&
406
- !bp_current_user_can( 'bp_moderate' ) &&
407
  !$this->current_group->is_user_member &&
408
- !groups_check_for_membership_request( bp_loggedin_user_id(), $this->current_group->id ) &&
409
  $this->current_group->status == 'private'
410
  ) {
411
  $sub_nav[] = array(
@@ -456,20 +358,6 @@ class BP_Groups_Component extends BP_Component {
456
  );
457
  }
458
 
459
- // If the user is a group mod or more, then show the group admin nav item
460
- if ( bp_is_item_admin() || bp_is_item_mod() ) {
461
- $sub_nav[] = array(
462
- 'name' => __( 'Admin', 'buddypress' ),
463
- 'slug' => 'admin',
464
- 'parent_url' => $group_link,
465
- 'parent_slug' => $this->current_group->slug,
466
- 'screen_function' => 'groups_screen_group_admin',
467
- 'position' => 1000,
468
- 'user_has_access' => true,
469
- 'item_css_id' => 'admin'
470
- );
471
- }
472
-
473
  parent::setup_nav( $main_nav, $sub_nav );
474
  }
475
 
@@ -480,9 +368,9 @@ class BP_Groups_Component extends BP_Component {
480
  }
481
 
482
  /**
483
- * Set up the Toolbar
484
  *
485
- * @global BuddyPress $bp The one true BuddyPress instance
486
  */
487
  function setup_admin_bar() {
488
  global $bp;
@@ -494,17 +382,18 @@ class BP_Groups_Component extends BP_Component {
494
  if ( is_user_logged_in() ) {
495
 
496
  // Setup the logged in user variables
497
- $user_domain = bp_loggedin_user_domain();
498
  $groups_link = trailingslashit( $user_domain . $this->slug );
499
 
500
  // Pending group invites
501
- $count = groups_get_invites_for_user( bp_loggedin_user_id() );
502
- $title = __( 'Groups', 'buddypress' );
503
- $pending = __( 'No Pending Invites', 'buddypress' );
504
 
505
  if ( !empty( $count->total ) ) {
506
  $title = sprintf( __( 'Groups <span class="count">%s</span>', 'buddypress' ), $count->total );
507
  $pending = sprintf( __( 'Pending Invites <span class="count">%s</span>', 'buddypress' ), $count->total );
 
 
 
508
  }
509
 
510
  // Add the "My Account" sub menus
@@ -538,7 +427,7 @@ class BP_Groups_Component extends BP_Component {
538
  /**
539
  * Sets up the title for pages and <title>
540
  *
541
- * @global BuddyPress $bp The one true BuddyPress instance
542
  */
543
  function setup_title() {
544
  global $bp;
@@ -552,11 +441,10 @@ class BP_Groups_Component extends BP_Component {
552
  } else if ( !bp_is_my_profile() && !bp_is_single_item() ) {
553
 
554
  $bp->bp_options_avatar = bp_core_fetch_avatar( array(
555
- 'item_id' => bp_displayed_user_id(),
556
- 'type' => 'thumb',
557
- 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() )
558
  ) );
559
- $bp->bp_options_title = bp_get_displayed_user_fullname();
560
 
561
  // We are viewing a single group, so set up the
562
  // group navigation menu using the $this->current_group global.
@@ -569,22 +457,15 @@ class BP_Groups_Component extends BP_Component {
569
  'avatar_dir' => 'group-avatars',
570
  'alt' => __( 'Group Avatar', 'buddypress' )
571
  ) );
572
- if ( empty( $bp->bp_options_avatar ) ) {
573
  $bp->bp_options_avatar = '<img src="' . esc_attr( $group->avatar_full ) . '" class="avatar" alt="' . esc_attr( $group->name ) . '" />';
574
- }
575
  }
576
  }
577
 
578
  parent::setup_title();
579
  }
580
  }
581
-
582
-
583
- function bp_setup_groups() {
584
- global $bp;
585
-
586
- $bp->groups = new BP_Groups_Component();
587
- }
588
- add_action( 'bp_setup_components', 'bp_setup_groups', 6 );
589
 
590
  ?>
1
  <?php
 
2
  /**
3
  * BuddyPress Groups Loader
4
  *
7
  * Comes preconfigured with an activity stream, discussion forums, and settings.
8
  *
9
  * @package BuddyPress
10
+ * @subpackage Groups Core
11
  */
12
 
13
  // Exit if accessed directly
15
 
16
  class BP_Groups_Component extends BP_Component {
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  /**
19
  * Start the groups component creation process
20
  *
21
+ * @since 1.5
22
  */
23
  function __construct() {
24
  parent::start(
56
  * The BP_GROUPS_SLUG constant is deprecated, and only used here for
57
  * backwards compatibility.
58
  *
59
+ * @since 1.5
60
+ * @global obj $bp
61
  */
62
  function setup_globals() {
63
  global $bp;
76
  // All globals for messaging component.
77
  // Note that global_tables is included in this array.
78
  $globals = array(
79
+ 'path' => BP_PLUGIN_DIR,
80
  'slug' => BP_GROUPS_SLUG,
81
  'root_slug' => isset( $bp->pages->groups->slug ) ? $bp->pages->groups->slug : BP_GROUPS_SLUG,
82
  'has_directory' => true,
103
  array_shift( $bp->action_variables );
104
 
105
  // Using "item" not "group" for generic support in other components.
106
+ if ( is_super_admin() )
107
  bp_update_is_item_admin( true, 'groups' );
108
  else
109
+ bp_update_is_item_admin( groups_is_user_admin( $bp->loggedin_user->id, $this->current_group->id ), 'groups' );
110
 
111
  // If the user is not an admin, check if they are a moderator
112
  if ( !bp_is_item_admin() )
113
+ bp_update_is_item_mod ( groups_is_user_mod ( $bp->loggedin_user->id, $this->current_group->id ), 'groups' );
114
 
115
  // Is the logged in user a member of the group?
116
+ if ( ( is_user_logged_in() && groups_is_user_member( $bp->loggedin_user->id, $this->current_group->id ) ) )
117
  $this->current_group->is_user_member = true;
118
  else
119
  $this->current_group->is_user_member = false;
126
 
127
  // If this is a private or hidden group, does the user have access?
128
  if ( 'private' == $this->current_group->status || 'hidden' == $this->current_group->status ) {
129
+ if ( $this->current_group->is_user_member && is_user_logged_in() || is_super_admin() )
130
  $this->current_group->user_has_access = true;
131
  else
132
  $this->current_group->user_has_access = false;
158
  ) );
159
 
160
  // If the user was attempting to access a group, but no group by that name was found, 404
161
+ if ( bp_is_groups_component() && empty( $this->current_group ) && !empty( $bp->current_action ) && !in_array( $bp->current_action, $this->forbidden_names ) ) {
162
  bp_do_404();
163
  return;
164
  }
165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  // Group access control
167
+ if ( bp_is_groups_component() && !empty( $this->current_group ) && !empty( $bp->current_action ) && !$this->current_group->user_has_access ) {
168
+ if ( is_user_logged_in() ) {
169
+ // Off-limits to this user. Throw an error and redirect to the
170
+ // group's home page
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  bp_core_no_access( array(
172
+ 'message' => __( 'You do not have access to this group.', 'buddypress' ),
173
  'root' => bp_get_group_permalink( $bp->groups->current_group ),
174
  'redirect' => false
175
  ) );
176
+ } else {
177
+ // Allow the user to log in
178
+ bp_core_no_access();
179
  }
180
  }
181
 
221
  /**
222
  * Setup BuddyBar navigation
223
  *
224
+ * @global obj $bp
225
  */
226
  function setup_nav() {
227
+ global $bp;
 
 
228
 
229
  // Add 'Groups' to the main navigation
230
  $main_nav = array(
236
  'item_css_id' => $this->id
237
  );
238
 
239
+ $groups_link = trailingslashit( $bp->loggedin_user->domain . $this->slug );
240
 
241
  // Add the My Groups nav item
242
  $sub_nav[] = array(
264
 
265
  if ( bp_is_groups_component() && bp_is_single_item() ) {
266
 
267
+ unset( $main_nav ); unset( $sub_nav );
 
268
 
269
  // Add 'Groups' to the main navigation
270
  $main_nav = array(
272
  'slug' => $this->current_group->slug,
273
  'position' => -1, // Do not show in BuddyBar
274
  'screen_function' => 'groups_screen_group_home',
275
+ 'default_subnav_slug' => 'home',
276
  'item_css_id' => $this->id
277
  );
278
 
279
+ $group_link = trailingslashit( bp_get_root_domain() . '/' . $this->root_slug . '/' . $this->current_group->slug );
280
 
281
  // Add the "Home" subnav item, as this will always be present
282
  $sub_nav[] = array(
289
  'item_css_id' => 'home'
290
  );
291
 
292
+ // If the user is a group mod or more, then show the group admin nav item
293
+ if ( bp_is_item_admin() || bp_is_item_mod() ) {
294
+ $sub_nav[] = array(
295
+ 'name' => __( 'Admin', 'buddypress' ),
296
+ 'slug' => 'admin',
297
+ 'parent_url' => $group_link,
298
+ 'parent_slug' => $this->current_group->slug,
299
+ 'screen_function' => 'groups_screen_group_admin',
300
+ 'position' => 20,
301
+ 'user_has_access' => ( $bp->is_item_admin + (int)$bp->is_item_mod ),
302
+ 'item_css_id' => 'admin'
303
+ );
304
+ }
305
+
306
  // If this is a private group, and the user is not a member, show a "Request Membership" nav item.
307
  if ( is_user_logged_in() &&
308
+ !is_super_admin() &&
309
  !$this->current_group->is_user_member &&
310
+ !groups_check_for_membership_request( $bp->loggedin_user->id, $this->current_group->id ) &&
311
  $this->current_group->status == 'private'
312
  ) {
313
  $sub_nav[] = array(
358
  );
359
  }
360
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
361
  parent::setup_nav( $main_nav, $sub_nav );
362
  }
363
 
368
  }
369
 
370
  /**
371
+ * Set up the admin bar
372
  *
373
+ * @global obj $bp
374
  */
375
  function setup_admin_bar() {
376
  global $bp;
382
  if ( is_user_logged_in() ) {
383
 
384
  // Setup the logged in user variables
385
+ $user_domain = $bp->loggedin_user->domain;
386
  $groups_link = trailingslashit( $user_domain . $this->slug );
387
 
388
  // Pending group invites
389
+ $count = groups_get_invites_for_user( $bp->loggedin_user->id );
 
 
390
 
391
  if ( !empty( $count->total ) ) {
392
  $title = sprintf( __( 'Groups <span class="count">%s</span>', 'buddypress' ), $count->total );
393
  $pending = sprintf( __( 'Pending Invites <span class="count">%s</span>', 'buddypress' ), $count->total );
394
+ } else {
395
+ $title = __( 'Groups', 'buddypress' );
396
+ $pending = __( 'No Pending Invites', 'buddypress' );
397
  }
398
 
399
  // Add the "My Account" sub menus
427
  /**
428
  * Sets up the title for pages and <title>
429
  *
430
+ * @global obj $bp
431
  */
432
  function setup_title() {
433
  global $bp;
441
  } else if ( !bp_is_my_profile() && !bp_is_single_item() ) {
442
 
443
  $bp->bp_options_avatar = bp_core_fetch_avatar( array(
444
+ 'item_id' => $bp->displayed_user->id,
445
+ 'type' => 'thumb'
 
446
  ) );
447
+ $bp->bp_options_title = $bp->displayed_user->fullname;
448
 
449
  // We are viewing a single group, so set up the
450
  // group navigation menu using the $this->current_group global.
457
  'avatar_dir' => 'group-avatars',
458
  'alt' => __( 'Group Avatar', 'buddypress' )
459
  ) );
460
+ if ( empty( $bp->bp_options_avatar ) )
461
  $bp->bp_options_avatar = '<img src="' . esc_attr( $group->avatar_full ) . '" class="avatar" alt="' . esc_attr( $group->name ) . '" />';
 
462
  }
463
  }
464
 
465
  parent::setup_title();
466
  }
467
  }
468
+ // Create the groups component
469
+ $bp->groups = new BP_Groups_Component();
 
 
 
 
 
 
470
 
471
  ?>
bp-groups/bp-groups-notifications.php CHANGED
@@ -1,26 +1,16 @@
1
  <?php
2
-
3
- /**
4
- * BuddyPress Groups Notification Functions
5
- *
6
- * These functions handle the recording, deleting and formatting of notifications
7
- * for the user and for this specific component.
8
- *
9
- * @package BuddyPress
10
- * @subpackage GroupsActivity
11
- */
12
-
13
  // Exit if accessed directly
14
  if ( !defined( 'ABSPATH' ) ) exit;
15
 
16
  function groups_notification_group_updated( $group_id ) {
 
17
 
18
- $group = groups_get_group( array( 'group_id' => $group_id ) );
19
  $sitename = wp_specialchars_decode( get_blog_option( bp_get_root_blog_id(), 'blogname' ), ENT_QUOTES );
20
  $subject = '[' . $sitename . '] ' . __( 'Group Details Updated', 'buddypress' );
21
 
22
  $user_ids = BP_Groups_Member::get_group_member_ids( $group->id );
23
- foreach ( (array) $user_ids as $user_id ) {
24
  if ( 'no' == bp_get_user_meta( $user_id, 'notification_groups_group_updated', true ) ) continue;
25
 
26
  $ud = bp_core_get_core_userdata( $user_id );
@@ -28,7 +18,7 @@ function groups_notification_group_updated( $group_id ) {
28
  // Set up and send the message
29
  $to = $ud->user_email;
30
 
31
- $group_link = bp_get_group_permalink( $group );
32
  $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
33
  $settings_link = bp_core_get_user_domain( $user_id ) . $settings_slug . '/notifications/';
34
 
@@ -56,6 +46,7 @@ To view the group: %2$s
56
  }
57
 
58
  function groups_notification_new_membership_request( $requesting_user_id, $admin_id, $group_id, $membership_id ) {
 
59
 
60
  bp_core_add_notification( $requesting_user_id, $admin_id, 'groups', 'new_membership_request', $group_id );
61
 
@@ -63,9 +54,11 @@ function groups_notification_new_membership_request( $requesting_user_id, $admin
63
  return false;
64
 
65
  $requesting_user_name = bp_core_get_user_displayname( $requesting_user_id );
66
- $group = groups_get_group( array( 'group_id' => $group_id ) );
 
 
 
67
 
68
- $ud = bp_core_get_core_userdata( $admin_id );
69
  $group_requests = bp_get_group_permalink( $group ) . 'admin/membership-requests';
70
  $profile_link = bp_core_get_user_domain( $requesting_user_id );
71
  $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
@@ -73,7 +66,7 @@ function groups_notification_new_membership_request( $requesting_user_id, $admin
73
 
74
  // Set up and send the message
75
  $to = $ud->user_email;
76
- $sitename = wp_specialchars_decode( bp_get_option( 'blogname' ), ENT_QUOTES );
77
  $subject = '[' . $sitename . '] ' . sprintf( __( 'Membership request for group: %s', 'buddypress' ), $group->name );
78
 
79
  $message = sprintf( __(
@@ -102,6 +95,7 @@ To view %4$s\'s profile: %5$s
102
  }
103
 
104
  function groups_notification_membership_request_completed( $requesting_user_id, $group_id, $accepted = true ) {
 
105
 
106
  // Post a screen notification first.
107
  if ( $accepted )
@@ -112,7 +106,7 @@ function groups_notification_membership_request_completed( $requesting_user_id,
112
  if ( 'no' == bp_get_user_meta( $requesting_user_id, 'notification_membership_request_completed', true ) )
113
  return false;
114
 
115
- $group = groups_get_group( array( 'group_id' => $group_id ) );
116
 
117
  $ud = bp_core_get_core_userdata($requesting_user_id);
118
 
@@ -158,6 +152,7 @@ To submit another request please log in and visit: %2$s
158
  }
159
 
160
  function groups_notification_promoted_member( $user_id, $group_id ) {
 
161
 
162
  if ( groups_is_user_admin( $user_id, $group_id ) ) {
163
  $promoted_to = __( 'an administrator', 'buddypress' );
@@ -173,7 +168,7 @@ function groups_notification_promoted_member( $user_id, $group_id ) {
173
  if ( 'no' == bp_get_user_meta( $user_id, 'notification_groups_admin_promotion', true ) )
174
  return false;
175
 
176
- $group = groups
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
2
  // Exit if accessed directly
3
  if ( !defined( 'ABSPATH' ) ) exit;
4
 
5
  function groups_notification_group_updated( $group_id ) {
6
+ global $bp;
7
 
8
+ $group = new BP_Groups_Group( $group_id );
9
  $sitename = wp_specialchars_decode( get_blog_option( bp_get_root_blog_id(), 'blogname' ), ENT_QUOTES );
10
  $subject = '[' . $sitename . '] ' . __( 'Group Details Updated', 'buddypress' );
11
 
12
  $user_ids = BP_Groups_Member::get_group_member_ids( $group->id );
13
+ foreach ( (array)$user_ids as $user_id ) {
14
  if ( 'no' == bp_get_user_meta( $user_id, 'notification_groups_group_updated', true ) ) continue;
15
 
16
  $ud = bp_core_get_core_userdata( $user_id );
18
  // Set up and send the message
19
  $to = $ud->user_email;
20
 
21
+ $group_link = site_url( bp_get_groups_root_slug(). '/' . $group->slug );
22
  $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
23
  $settings_link = bp_core_get_user_domain( $user_id ) . $settings_slug . '/notifications/';
24
 
46
  }
47
 
48
  function groups_notification_new_membership_request( $requesting_user_id, $admin_id, $group_id, $membership_id ) {
49
+ global $bp;
50
 
51
  bp_core_add_notification( $requesting_user_id, $admin_id, 'groups', 'new_membership_request', $group_id );
52
 
54
  return false;
55
 
56
  $requesting_user_name = bp_core_get_user_displayname( $requesting_user_id );
57
+ $group = new BP_Groups_Group( $group_id );
58
+
59
+ $ud = bp_core_get_core_userdata($admin_id);
60
+ $requesting_ud = bp_core_get_core_userdata($requesting_user_id);
61
 
 
62
  $group_requests = bp_get_group_permalink( $group ) . 'admin/membership-requests';
63
  $profile_link = bp_core_get_user_domain( $requesting_user_id );
64
  $settings_slug = function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings';
66
 
67
  // Set up and send the message
68
  $to = $ud->user_email;
69
+ $sitename = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
70
  $subject = '[' . $sitename . '] ' . sprintf( __( 'Membership request for group: %s', 'buddypress' ), $group->name );
71
 
72
  $message = sprintf( __(
95
  }
96
 
97
  function groups_notification_membership_request_completed( $requesting_user_id, $group_id, $accepted = true ) {
98
+ global $bp;
99
 
100
  // Post a screen notification first.
101
  if ( $accepted )
106
  if ( 'no' == bp_get_user_meta( $requesting_user_id, 'notification_membership_request_completed', true ) )
107
  return false;
108
 
109
+ $group = new BP_Groups_Group( $group_id );
110
 
111
  $ud = bp_core_get_core_userdata($requesting_user_id);
112
 
152
  }
153
 
154
  function groups_notification_promoted_member( $user_id, $group_id ) {
155
+ global $bp;
156
 
157
  if ( groups_is_user_admin( $user_id, $group_id ) ) {
158
  $promoted_to = __( 'an administrator', 'buddypress' );
168
  if ( 'no' == bp_get_user_meta( $user_id, 'notification_groups_admin_promotion', true ) )
169
  return false;
170