BuddyPress - Version 1.5

Version Description

See: http://codex.buddypress.org/releases/version-1-5/

Download this release

Release Info

Developer johnjamesjacoby
Plugin Icon 128x128 BuddyPress
Version 1.5
Comparing to
See all releases

Code changes from version 1.2.10 to 1.5

Files changed (85) hide show
  1. bp-activity.php +0 -1216
  2. bp-activity/bp-activity-actions.php +530 -0
  3. bp-activity/bp-activity-classes.php +190 -190
  4. bp-activity/bp-activity-filters.php +158 -34
  5. bp-activity/bp-activity-functions.php +1437 -0
  6. bp-activity/bp-activity-loader.php +315 -0
  7. bp-activity/bp-activity-notifications.php +129 -49
  8. bp-activity/bp-activity-screens.php +308 -0
  9. bp-activity/bp-activity-template.php +2696 -0
  10. bp-activity/bp-activity-templatetags.php +0 -1074
  11. bp-activity/feeds/bp-activity-favorites-feed.php +17 -6
  12. bp-activity/feeds/bp-activity-friends-feed.php +17 -12
  13. bp-activity/feeds/bp-activity-group-feed.php +9 -3
  14. bp-activity/feeds/bp-activity-mentions-feed.php +9 -3
  15. bp-activity/feeds/bp-activity-mygroups-feed.php +9 -3
  16. bp-activity/feeds/bp-activity-personal-feed.php +9 -3
  17. bp-activity/feeds/bp-activity-sitewide-feed.php +8 -3
  18. bp-blogs.php +0 -821
  19. bp-blogs/bp-blogs-actions.php +16 -0
  20. bp-blogs/bp-blogs-activity.php +94 -0
  21. bp-blogs/bp-blogs-buddybar.php +63 -0
  22. bp-blogs/bp-blogs-cache.php +37 -0
  23. bp-blogs/bp-blogs-classes.php +28 -59
  24. bp-blogs/bp-blogs-functions.php +566 -0
  25. bp-blogs/bp-blogs-loader.php +196 -0
  26. bp-blogs/bp-blogs-screens.php +38 -0
  27. bp-blogs/{bp-blogs-templatetags.php → bp-blogs-template.php} +171 -76
  28. bp-blogs/bp-blogs-widgets.php +13 -5
  29. bp-core.php +0 -2224
  30. bp-core/admin/bp-core-admin.php +637 -0
  31. bp-core/admin/bp-core-schema.php +300 -0
  32. bp-core/admin/bp-core-update.php +1328 -0
  33. bp-core/bp-core-admin.php +0 -251
  34. bp-core/bp-core-adminbar.php +196 -259
  35. bp-core/bp-core-avatars.php +403 -125
  36. bp-core/bp-core-buddybar.php +627 -0
  37. bp-core/bp-core-cache.php +51 -0
  38. bp-core/bp-core-catchuri.php +316 -152
  39. bp-core/bp-core-classes.php +732 -130
  40. bp-core/bp-core-component.php +358 -0
  41. bp-core/bp-core-cssjs.php +42 -42
  42. bp-core/bp-core-filters.php +134 -62
  43. bp-core/bp-core-functions.php +1454 -0
  44. bp-core/bp-core-hooks.php +114 -0
  45. bp-core/bp-core-loader.php +234 -0
  46. bp-core/bp-core-notifications.php +0 -95
  47. bp-core/bp-core-settings.php +0 -197
  48. bp-core/bp-core-template.php +1661 -0
  49. bp-core/bp-core-templatetags.php +0 -2107
  50. bp-core/bp-core-widgets.php +103 -24
  51. bp-core/bp-core-wpabstraction.php +117 -83
  52. bp-core/css/admin-bar-rtl.css +1 -0
  53. bp-core/css/admin-bar-rtl.dev.css +27 -0
  54. bp-core/css/admin-bar.css +1 -0
  55. bp-core/css/admin-bar.dev.css +58 -0
  56. bp-core/css/admin.css +1 -0
  57. bp-core/css/admin.dev.css +160 -0
  58. bp-core/css/buddybar-rtl.css +1 -0
  59. bp-core/css/buddybar-rtl.dev.css +77 -0
  60. bp-core/css/buddybar.css +1 -0
  61. bp-themes/bp-default/_inc/css/adminbar.css → bp-core/css/buddybar.dev.css +73 -88
  62. bp-core/css/widget-members.css +0 -22
  63. bp-core/deprecated/1.5.php +521 -0
  64. bp-core/images/60pc_black.png +0 -0
  65. bp-core/images/admin-bar-sprite-rtl.png +0 -0
  66. bp-core/images/admin-bar-sprite.png +0 -0
  67. bp-core/images/admin-menu-arrow.gif +0 -0
  68. bp-core/images/completed.gif +0 -0
  69. bp-core/images/find.png +0 -0
  70. bp-core/images/icons32.png +0 -0
  71. bp-core/images/installed.gif +0 -0
  72. bp-core/images/logo-column-header.png +0 -0
  73. bp-core/images/logo.png +0 -0
  74. bp-core/js/admin-bar.js +0 -0
  75. bp-core/js/update.dev.js +11 -0
  76. bp-core/js/update.js +1 -0
  77. bp-core/js/widget-members.dev.js +49 -0
  78. bp-core/js/widget-members.js +1 -48
  79. bp-forums.php +0 -556
  80. bp-forums/bbpress/bb-admin/admin-ajax.php +25 -4
  81. bp-forums/bbpress/bb-admin/admin-header.php +6 -0
  82. bp-forums/bbpress/bb-admin/delete-post.php +4 -1
  83. bp-forums/bbpress/bb-admin/export.php +1 -2
  84. bp-forums/bbpress/bb-admin/images/favicon.ico +0 -0
  85. bp-forums/bbpress/bb-admin/includes/class.bb-install.php +3 -3
bp-activity.php DELETED
@@ -1,1216 +0,0 @@
1
- <?php
2
-
3
- define ( 'BP_ACTIVITY_DB_VERSION', '2100' );
4
-
5
- /* Define the slug for the component */
6
- if ( !defined( 'BP_ACTIVITY_SLUG' ) )
7
- define ( 'BP_ACTIVITY_SLUG', 'activity' );
8
-
9
- require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-classes.php' );
10
- require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-templatetags.php' );
11
- require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-filters.php' );
12
-
13
- function bp_activity_install() {
14
- global $wpdb, $bp;
15
-
16
- if ( !empty($wpdb->charset) )
17
- $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
18
-
19
- /* Rename the old user activity cached table if needed. */
20
- if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$wpdb->base_prefix}bp_activity_user_activity_cached%'" ) )
21
- $wpdb->query( "RENAME TABLE {$wpdb->base_prefix}bp_activity_user_activity_cached TO {$bp->activity->table_name}" );
22
-
23
- /* Rename fields from pre BP 1.2 */
24
- if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$bp->activity->table_name}%'" ) ) {
25
- if ( $wpdb->get_var( "SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_action'" ) )
26
- $wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE component_action type varchar(75) NOT NULL" );
27
-
28
- if ( $wpdb->get_var( "SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_name'" ) )
29
- $wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE component_name component varchar(75) NOT NULL" );
30
- }
31
-
32
- /**
33
- * Build the tables
34
- */
35
- $sql[] = "CREATE TABLE {$bp->activity->table_name} (
36
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
37
- user_id bigint(20) NOT NULL,
38
- component varchar(75) NOT NULL,
39
- type varchar(75) NOT NULL,
40
- action text NOT NULL,
41
- content longtext NOT NULL,
42
- primary_link varchar(150) NOT NULL,
43
- item_id varchar(75) NOT NULL,
44
- secondary_item_id varchar(75) DEFAULT NULL,
45
- date_recorded datetime NOT NULL,
46
- hide_sitewide bool DEFAULT 0,
47
- mptt_left int(11) NOT NULL DEFAULT 0,
48
- mptt_right int(11) NOT NULL DEFAULT 0,
49
- KEY date_recorded (date_recorded),
50
- KEY user_id (user_id),
51
- KEY item_id (item_id),
52
- KEY secondary_item_id (secondary_item_id),
53
- KEY component (component),
54
- KEY type (type),
55
- KEY mptt_left (mptt_left),
56
- KEY mptt_right (mptt_right),
57
- KEY hide_sitewide (hide_sitewide)
58
- ) {$charset_collate};";
59
-
60
- $sql[] = "CREATE TABLE {$bp->activity->table_name_meta} (
61
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
62
- activity_id bigint(20) NOT NULL,
63
- meta_key varchar(255) DEFAULT NULL,
64
- meta_value longtext DEFAULT NULL,
65
- KEY activity_id (activity_id),
66
- KEY meta_key (meta_key)
67
- ) {$charset_collate};";
68
-
69
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
70
- dbDelta($sql);
71
-
72
- update_site_option( 'bp-activity-db-version', BP_ACTIVITY_DB_VERSION );
73
- }
74
-
75
- function bp_activity_setup_globals() {
76
- global $bp, $current_blog;
77
-
78
- /* Internal identifier */
79
- $bp->activity->id = 'activity';
80
-
81
- $bp->activity->slug = BP_ACTIVITY_SLUG;
82
-
83
- $bp->activity->table_name = $bp->table_prefix . 'bp_activity';
84
- $bp->activity->table_name_meta = $bp->table_prefix . 'bp_activity_meta';
85
-
86
- $bp->activity->format_notification_function = 'bp_activity_format_notifications';
87
-
88
- /* Register this in the active components array */
89
- $bp->active_components[$bp->activity->slug] = $bp->activity->id;
90
-
91
- do_action( 'bp_activity_setup_globals' );
92
- }
93
- add_action( 'bp_setup_globals', 'bp_activity_setup_globals' );
94
-
95
- function bp_activity_check_installed() {
96
- global $bp;
97
-
98
- if ( get_site_option( 'bp-activity-db-version' ) < BP_ACTIVITY_DB_VERSION )
99
- bp_activity_install();
100
- }
101
- add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', 'bp_activity_check_installed' );
102
-
103
- function bp_activity_setup_root_component() {
104
- /* Register 'activity' as a root component (for RSS feed use) */
105
- bp_core_add_root_component( BP_ACTIVITY_SLUG );
106
- }
107
- add_action( 'bp_setup_root_components', 'bp_activity_setup_root_component' );
108
-
109
- function bp_activity_setup_nav() {
110
- global $bp;
111
-
112
- /* Add 'Activity' to the main navigation */
113
- bp_core_new_nav_item( array( 'name' => __( 'Activity', 'buddypress' ), 'slug' => $bp->activity->slug, 'position' => 10, 'screen_function' => 'bp_activity_screen_my_activity', 'default_subnav_slug' => 'just-me', 'item_css_id' => $bp->activity->id ) );
114
-
115
- $user_domain = ( !empty( $bp->displayed_user->domain ) ) ? $bp->displayed_user->domain : $bp->loggedin_user->domain;
116
- $user_login = ( !empty( $bp->displayed_user->userdata->user_login ) ) ? $bp->displayed_user->userdata->user_login : $bp->loggedin_user->userdata->user_login;
117
- $activity_link = $user_domain . $bp->activity->slug . '/';
118
-
119
- /* Add the subnav items to the activity nav item if we are using a theme that supports this */
120
- bp_core_new_subnav_item( array( 'name' => __( 'Personal', 'buddypress' ), 'slug' => 'just-me', 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_my_activity', 'position' => 10 ) );
121
-
122
- if ( bp_is_active( 'friends' ) )
123
- bp_core_new_subnav_item( array( 'name' => __( 'Friends', 'buddypress' ), 'slug' => BP_FRIENDS_SLUG, 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_friends', 'position' => 20, 'item_css_id' => 'activity-friends' ) );
124
-
125
- if ( bp_is_active( 'groups' ) )
126
- bp_core_new_subnav_item( array( 'name' => __( 'Groups', 'buddypress' ), 'slug' => BP_GROUPS_SLUG, 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_groups', 'position' => 30, 'item_css_id' => 'activity-groups' ) );
127
-
128
- bp_core_new_subnav_item( array( 'name' => __( 'Favorites', 'buddypress' ), 'slug' => 'favorites', 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_favorites', 'position' => 40, 'item_css_id' => 'activity-favs' ) );
129
- bp_core_new_subnav_item( array( 'name' => sprintf( __( '@%s Mentions', 'buddypress' ), $user_login ), 'slug' => 'mentions', 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_mentions', 'position' => 50, 'item_css_id' => 'activity-mentions' ) );
130
-
131
- if ( $bp->current_component == $bp->activity->slug ) {
132
- if ( bp_is_my_profile() ) {
133
- $bp->bp_options_title = __( 'My Activity', 'buddypress' );
134
- } else {
135
- $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
136
- $bp->bp_options_title = $bp->displayed_user->fullname;
137
- }
138
- }
139
-
140
- do_action( 'bp_activity_setup_nav' );
141
- }
142
- add_action( 'bp_setup_nav', 'bp_activity_setup_nav' );
143
-
144
- function bp_activity_directory_activity_setup() {
145
- global $bp;
146
-
147
- if ( $bp->current_component == $bp->activity->slug && empty( $bp->current_action ) ) {
148
- $bp->is_directory = true;
149
-
150
- do_action( 'bp_activity_directory_activity_setup' );
151
- bp_core_load_template( apply_filters( 'bp_activity_directory_activity_setup', 'activity/index' ) );
152
- }
153
- }
154
- add_action( 'wp', 'bp_activity_directory_activity_setup', 2 );
155
-
156
-
157
- /********************************************************************************
158
- * Screen Functions
159
- *
160
- * Screen functions are the controllers of BuddyPress. They will execute when their
161
- * specific URL is caught. They will first save or manipulate data using business
162
- * functions, then pass on the user to a template file.
163
- */
164
-
165
- function bp_activity_screen_my_activity() {
166
- do_action( 'bp_activity_screen_my_activity' );
167
- bp_core_load_template( apply_filters( 'bp_activity_template_my_activity', 'members/single/home' ) );
168
- }
169
-
170
- function bp_activity_screen_friends() {
171
- global $bp;
172
-
173
- if ( !bp_is_active( 'friends' ) )
174
- return false;
175
-
176
- if ( !is_super_admin() )
177
- $bp->is_item_admin = false;
178
-
179
- do_action( 'bp_activity_screen_friends' );
180
- bp_core_load_template( apply_filters( 'bp_activity_template_friends_activity', 'members/single/home' ) );
181
- }
182
-
183
- function bp_activity_screen_groups() {
184
- global $bp;
185
-
186
- if ( !bp_is_active( 'groups' ) )
187
- return false;
188
-
189
- if ( !is_super_admin() )
190
- $bp->is_item_admin = false;
191
-
192
- do_action( 'bp_activity_screen_groups' );
193
- bp_core_load_template( apply_filters( 'bp_activity_template_groups_activity', 'members/single/home' ) );
194
- }
195
-
196
- function bp_activity_screen_favorites() {
197
- global $bp;
198
-
199
- if ( !is_super_admin() )
200
- $bp->is_item_admin = false;
201
-
202
- do_action( 'bp_activity_screen_favorites' );
203
- bp_core_load_template( apply_filters( 'bp_activity_template_favorite_activity', 'members/single/home' ) );
204
- }
205
-
206
- function bp_activity_screen_mentions() {
207
- global $bp;
208
-
209
- if ( !is_super_admin() )
210
- $bp->is_item_admin = false;
211
-
212
- do_action( 'bp_activity_screen_mentions' );
213
- bp_core_load_template( apply_filters( 'bp_activity_template_mention_activity', 'members/single/home' ) );
214
- }
215
-
216
- function bp_activity_screen_single_activity_permalink() {
217
- global $bp;
218
-
219
- if ( !$bp->displayed_user->id || $bp->current_component != $bp->activity->slug )
220
- return false;
221
-
222
- if ( empty( $bp->current_action ) || !is_numeric( $bp->current_action ) )
223
- return false;
224
-
225
- /* Get the activity details */
226
- $activity = bp_activity_get_specific( array( 'activity_ids' => $bp->current_action, 'show_hidden' => true ) );
227
-
228
- if ( !$activity = $activity['activities'][0] )
229
- bp_core_redirect( $bp->root_domain );
230
-
231
- $has_access = true;
232
- /* Redirect based on the type of activity */
233
- if ( $activity->component == $bp->groups->id ) {
234
- if ( !function_exists( 'groups_get_group' ) )
235
- bp_core_redirect( $bp->root_domain );
236
-
237
- if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) ) {
238
- /* Check to see if the group is not public, if so, check the user has access to see this activity */
239
- if ( 'public' != $group->status ) {
240
- if ( !groups_is_user_member( $bp->loggedin_user->id, $group->id ) )
241
- $has_access = false;
242
- }
243
- }
244
- }
245
-
246
- $has_access = apply_filters( 'bp_activity_permalink_access', $has_access, &$activity );
247
-
248
- do_action( 'bp_activity_screen_single_activity_permalink', $activity, $has_access );
249
-
250
- if ( !$has_access ) {
251
- bp_core_add_message( __( 'You do not have access to this activity.', 'buddypress' ), 'error' );
252
-
253
- if ( is_user_logged_in() )
254
- bp_core_redirect( $bp->loggedin_user->domain );
255
- else
256
- bp_core_redirect( site_url( 'wp-login.php?redirect_to=' . esc_url( $bp->root_domain . '/' . $bp->activity->slug . '/p/' . $bp->current_action ) ) );
257
- }
258
-
259
- bp_core_load_template( apply_filters( 'bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink' ) );
260
- }
261
- /* This screen is not attached to a nav item, so we need to add an action for it. */
262
- add_action( 'wp', 'bp_activity_screen_single_activity_permalink', 3 );
263
-
264
- function bp_activity_screen_notification_settings() {
265
- global $bp; ?>
266
- <table class="notification-settings zebra" id="activity-notification-settings">
267
- <thead>
268
- <tr>
269
- <th class="icon"></th>
270
- <th class="title"><?php _e( 'Activity', 'buddypress' ) ?></th>
271
- <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>
272
- <th class="no"><?php _e( 'No', 'buddypress' )?></th>
273
- </tr>
274
- </thead>
275
-
276
- <tbody>
277
- <tr>
278
- <td></td>
279
- <td><?php printf( __( 'A member mentions you in an update using "@%s"', 'buddypress' ), bp_core_get_username( $bp->loggedin_user->id, $bp->loggedin_user->userdata->user_nicename, $bp->loggedin_user->userdata->user_login ) ) ?></td>
280
- <td class="yes"><input type="radio" name="notifications[notification_activity_new_mention]" value="yes" <?php if ( !get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_mention', true ) || 'yes' == get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_mention', true ) ) { ?>checked="checked" <?php } ?>/></td>
281
- <td class="no"><input type="radio" name="notifications[notification_activity_new_mention]" value="no" <?php if ( 'no' == get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_mention', true ) ) { ?>checked="checked" <?php } ?>/></td>
282
- </tr>
283
- <tr>
284
- <td></td>
285
- <td><?php printf( __( "A member replies to an update or comment you've posted", 'buddypress' ), $current_user->user_login ) ?></td>
286
- <td class="yes"><input type="radio" name="notifications[notification_activity_new_reply]" value="yes" <?php if ( !get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_reply', true ) || 'yes' == get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_reply', true ) ) { ?>checked="checked" <?php } ?>/></td>
287
- <td class="no"><input type="radio" name="notifications[notification_activity_new_reply]" value="no" <?php if ( 'no' == get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_reply', true ) ) { ?>checked="checked" <?php } ?>/></td>
288
- </tr>
289
-
290
- <?php do_action( 'bp_activity_screen_notification_settings' ) ?>
291
- </tbody>
292
- </table>
293
- <?php
294
- }
295
- add_action( 'bp_notification_settings', 'bp_activity_screen_notification_settings', 1 );
296
-
297
- /********************************************************************************
298
- * Action Functions
299
- *
300
- * Action functions are exactly the same as screen functions, however they do not
301
- * have a template screen associated with them. Usually they will send the user
302
- * back to the default screen after execution.
303
- */
304
-
305
- function bp_activity_action_permalink_router() {
306
- global $bp;
307
-
308
- if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'p' )
309
- return false;
310
-
311
- if ( empty( $bp->action_variables[0] ) || !is_numeric( $bp->action_variables[0] ) )
312
- return false;
313
-
314
- /* Get the activity details */
315
- $activity = bp_activity_get_specific( array( 'activity_ids' => $bp->action_variables[0], 'show_hidden' => true ) );
316
-
317
- if ( !$activity = $activity['activities'][0] )
318
- bp_core_redirect( $bp->root_domain );
319
-
320
- $redirect = false;
321
- /* Redirect based on the type of activity */
322
- if ( $activity->component == $bp->groups->id ) {
323
- if ( $activity->user_id )
324
- $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id . '/';
325
- else {
326
- if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) )
327
- $redirect = bp_get_group_permalink( $group ) . $bp->activity->slug . '/' . $activity->id . '/';
328
- }
329
- } else
330
- $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id;
331
-
332
- $redirect = apply_filters( 'bp_activity_permalink_redirect_url', $redirect, &$activity );
333
-
334
- if ( !$redirect )
335
- bp_core_redirect( $bp->root_domain );
336
-
337
- /* Redirect to the actual activity permalink page */
338
- bp_core_redirect( $redirect );
339
- }
340
- add_action( 'wp', 'bp_activity_action_permalink_router', 3 );
341
-
342
- function bp_activity_action_delete_activity() {
343
- global $bp;
344
-
345
- if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'delete' )
346
- return false;
347
-
348
- if ( empty( $bp->action_variables[0] ) || !is_numeric( $bp->action_variables[0] ) )
349
- return false;
350
-
351
- /* Check the nonce */
352
- check_admin_referer( 'bp_activity_delete_link' );
353
-
354
- $activity_id = $bp->action_variables[0];
355
- $activity = new BP_Activity_Activity( $activity_id );
356
-
357
- /* Check access */
358
- if ( !is_super_admin() && $activity->user_id != $bp->loggedin_user->id )
359
- return false;
360
-
361
- /* Call the action before the delete so plugins can still fetch information about it */
362
- do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id );
363
-
364
- /* Now delete the activity item */
365
- if ( bp_activity_delete( array( 'id' => $activity_id, 'user_id' => $activity->user_id ) ) )
366
- bp_core_add_message( __( 'Activity deleted', 'buddypress' ) );
367
- else
368
- bp_core_add_message( __( 'There was an error when deleting that activity', 'buddypress' ), 'error' );
369
-
370
- bp_core_redirect( wp_get_referer() );
371
- }
372
- add_action( 'wp', 'bp_activity_action_delete_activity', 3 );
373
-
374
- function bp_activity_action_post_update() {
375
- global $bp;
376
-
377
- if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'post' )
378
- return false;
379
-
380
- /* Check the nonce */
381
- check_admin_referer( 'post_update', '_wpnonce_post_update' );
382
-
383
- $content = apply_filters( 'bp_activity_post_update_content', $_POST['whats-new'] );
384
- $object = apply_filters( 'bp_activity_post_update_object', $_POST['whats-new-post-object'] );
385
- $item_id = apply_filters( 'bp_activity_post_update_item_id', $_POST['whats-new-post-in'] );
386
-
387
- if ( empty( $content ) ) {
388
- bp_core_add_message( __( 'Please enter some content to post.', 'buddypress' ), 'error' );
389
- bp_core_redirect( wp_get_referer() );
390
- }
391
-
392
- if ( !(int)$item_id ) {
393
- $activity_id = bp_activity_post_update( array( 'content' => $content ) );
394
-
395
- } else if ( 'groups' == $object && function_exists( 'groups_post_update' ) ) {
396
- if ( (int)$item_id ) {
397
- $activity_id = groups_post_update( array( 'content' => $content, 'group_id' => $item_id ) );
398
- }
399
- } else
400
- $activity_id = apply_filters( 'bp_activity_custom_update', $object, $item_id, $content );
401
-
402
- if ( !empty( $activity_id ) )
403
- bp_core_add_message( __( 'Update Posted!', 'buddypress' ) );
404
- else
405
- bp_core_add_message( __( 'There was an error when posting your update, please try again.', 'buddypress' ), 'error' );
406
-
407
- bp_core_redirect( wp_get_referer() );
408
- }
409
- add_action( 'wp', 'bp_activity_action_post_update', 3 );
410
-
411
- function bp_activity_action_post_comment() {
412
- global $bp;
413
-
414
- if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'reply' )
415
- return false;
416
-
417
- /* Check the nonce */
418
- check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );
419
-
420
- $activity_id = apply_filters( 'bp_activity_post_comment_activity_id', $_POST['comment_form_id'] );
421
- $content = apply_filters( 'bp_activity_post_comment_content', $_POST['ac_input_' . $activity_id] );
422
-
423
- if ( empty( $content ) ) {
424
- bp_core_add_message( __( 'Please do not leave the comment area blank.', 'buddypress' ), 'error' );
425
- bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
426
- }
427
-
428
- $comment_id = bp_activity_new_comment( array(
429
- 'content' => $content,
430
- 'activity_id' => $activity_id,
431
- 'parent_id' => $parent_id
432
- ));
433
-
434
- if ( !empty( $comment_id ) )
435
- bp_core_add_message( __( 'Reply Posted!', 'buddypress' ) );
436
- else
437
- bp_core_add_message( __( 'There was an error posting that reply, please try again.', 'buddypress' ), 'error' );
438
-
439
- bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
440
- }
441
- add_action( 'wp', 'bp_activity_action_post_comment', 3 );
442
-
443
- function bp_activity_action_mark_favorite() {
444
- global $bp;
445
-
446
- if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'favorite' )
447
- return false;
448
-
449
- /* Check the nonce */
450
- check_admin_referer( 'mark_favorite' );
451
-
452
- if ( bp_activity_add_user_favorite( $bp->action_variables[0] ) )
453
- bp_core_add_message( __( 'Activity marked as favorite.', 'buddypress' ) );
454
- else
455
- bp_core_add_message( __( 'There was an error marking that activity as a favorite, please try again.', 'buddypress' ), 'error' );
456
-
457
- bp_core_redirect( wp_get_referer() . '#activity-' . $bp->action_variables[0] );
458
- }
459
- add_action( 'wp', 'bp_activity_action_mark_favorite', 3 );
460
-
461
- function bp_activity_action_remove_favorite() {
462
- global $bp;
463
-
464
- if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'unfavorite' )
465
- return false;
466
-
467
- /* Check the nonce */
468
- check_admin_referer( 'unmark_favorite' );
469
-
470
- if ( bp_activity_remove_user_favorite( $bp->action_variables[0] ) )
471
- bp_core_add_message( __( 'Activity removed as favorite.', 'buddypress' ) );
472
- else
473
- bp_core_add_message( __( 'There was an error removing that activity as a favorite, please try again.', 'buddypress' ), 'error' );
474
-
475
- bp_core_redirect( wp_get_referer() . '#activity-' . $bp->action_variables[0] );
476
- }
477
- add_action( 'wp', 'bp_activity_action_remove_favorite', 3 );
478
-
479
- function bp_activity_action_sitewide_feed() {
480
- global $bp, $wp_query;
481
-
482
- if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'feed' || $bp->displayed_user->id || $bp->groups->current_group )
483
- return false;
484
-
485
- $wp_query->is_404 = false;
486
- status_header( 200 );
487
-
488
- include_once( 'bp-activity/feeds/bp-activity-sitewide-feed.php' );
489
- die;
490
- }
491
- add_action( 'wp', 'bp_activity_action_sitewide_feed', 3 );
492
-
493
- function bp_activity_action_personal_feed() {
494
- global $bp, $wp_query;
495
-
496
- if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'feed' )
497
- return false;
498
-
499
- $wp_query->is_404 = false;
500
- status_header( 200 );
501
-
502
- include_once( 'bp-activity/feeds/bp-activity-personal-feed.php' );
503
- die;
504
- }
505
- add_action( 'wp', 'bp_activity_action_personal_feed', 3 );
506
-
507
- function bp_activity_action_friends_feed() {
508
- global $bp, $wp_query;
509
-
510
- if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'friends' || $bp->action_variables[0] != 'feed' )
511
- return false;
512
-
513
- $wp_query->is_404 = false;
514
- status_header( 200 );
515
-
516
- include_once( 'bp-activity/feeds/bp-activity-friends-feed.php' );
517
- die;
518
- }
519
- add_action( 'wp', 'bp_activity_action_friends_feed', 3 );
520
-
521
- function bp_activity_action_my_groups_feed() {
522
- global $bp, $wp_query;
523
-
524
- if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'groups' || $bp->action_variables[0] != 'feed' )
525
- return false;
526
-
527
- $wp_query->is_404 = false;
528
- status_header( 200 );
529
-
530
- include_once( 'bp-activity/feeds/bp-activity-mygroups-feed.php' );
531
- die;
532
- }
533
- add_action( 'wp', 'bp_activity_action_my_groups_feed', 3 );
534
-
535
- function bp_activity_action_mentions_feed() {
536
- global $bp, $wp_query;
537
-
538
- if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'mentions' || $bp->action_variables[0] != 'feed' )
539
- return false;
540
-
541
- $wp_query->is_404 = false;
542
- status_header( 200 );
543
-
544
- include_once( 'bp-activity/feeds/bp-activity-mentions-feed.php' );
545
- die;
546
- }
547
- add_action( 'wp', 'bp_activity_action_mentions_feed', 3 );
548
-
549
- function bp_activity_action_favorites_feed() {
550
- global $bp, $wp_query;
551
-
552
- if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'favorites' || $bp->action_variables[0] != 'feed' )
553
- return false;
554
-
555
- $wp_query->is_404 = false;
556
- status_header( 200 );
557
-
558
- include_once( 'bp-activity/feeds/bp-activity-favorites-feed.php' );
559
- die;
560
- }
561
- add_action( 'wp', 'bp_activity_action_favorites_feed', 3 );
562
-
563
- /********************************************************************************
564
- * Business Functions
565
- *
566
- * Business functions are where all the magic happens in BuddyPress. They will
567
- * handle the actual saving or manipulation of information. Usually they will
568
- * hand off to a database class for data access, then return
569
- * true or false on success or failure.
570
- */
571
-
572
- function bp_activity_get( $args = '' ) {
573
- $defaults = array(
574
- 'max' => false, // Maximum number of results to return
575
- 'page' => 1, // page 1 without a per_page will result in no pagination.
576
- 'per_page' => false, // results per page
577
- 'sort' => 'DESC', // sort ASC or DESC
578
- 'display_comments' => false, // false for no comments. 'stream' for within stream display, 'threaded' for below each activity item
579
-
580
- 'search_terms' => false, // Pass search terms as a string
581
- 'show_hidden' => false, // Show activity items that are hidden site-wide?
582
-
583
- /**
584
- * Pass filters as an array -- all filter items can be multiple values comma separated:
585
- * array(
586
- * 'user_id' => false, // user_id to filter on
587
- * 'object' => false, // object to filter on e.g. groups, profile, status, friends
588
- * 'action' => false, // action to filter on e.g. activity_update, profile_updated
589
- * 'primary_id' => false, // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
590
- * 'secondary_id' => false, // secondary object ID to filter on e.g. a post_id
591
- * );
592
- */
593
- 'filter' => array()
594
- );
595
-
596
- $r = wp_parse_args( $args, $defaults );
597
- extract( $r, EXTR_SKIP );
598
-
599
- /* Attempt to return a cached copy of the first page of sitewide activity. */
600
- if ( 1 == (int)$page && empty( $max ) && empty( $search_terms ) && empty( $filter ) && 'DESC' == $sort ) {
601
- if ( !$activity = wp_cache_get( 'bp_activity_sitewide_front', 'bp' ) ) {
602
- $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden );
603
- wp_cache_set( 'bp_activity_sitewide_front', $activity, 'bp' );
604
- }
605
- } else
606
- $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden );
607
-
608
- return apply_filters( 'bp_activity_get', $activity, &$r );
609
- }
610
-
611
- function bp_activity_get_specific( $args = '' ) {
612
- $defaults = array(
613
- 'activity_ids' => false, // A single activity_id or array of IDs.
614
- 'page' => 1, // page 1 without a per_page will result in no pagination.
615
- 'per_page' => false, // results per page
616
- 'max' => false, // Maximum number of results to return
617
- 'sort' => 'DESC', // sort ASC or DESC
618
- 'display_comments' => false, // true or false to display threaded comments for these specific activity items
619
- 'show_hidden' => false
620
- );
621
-
622
- $r = wp_parse_args( $args, $defaults );
623
- extract( $r, EXTR_SKIP );
624
-
625
- return apply_filters( 'bp_activity_get_specific', BP_Activity_Activity::get_specific( $activity_ids, $max, $page, $per_page, $sort, $display_comments, $show_hidden ) );
626
- }
627
-
628
- function bp_activity_add( $args = '' ) {
629
- global $bp;
630
-
631
- $defaults = array(
632
- 'id' => false, // Pass an existing activity ID to update an existing entry.
633
-
634
- 'action' => '', // The activity action - e.g. "Jon Doe posted an update"
635
- 'content' => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!"
636
-
637
- 'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent
638
- 'type' => false, // The activity type e.g. activity_update, profile_updated
639
- 'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink)
640
-
641
- '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.
642
- 'item_id' => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id
643
- 'secondary_item_id' => false, // Optional: A second ID used to further filter e.g. a comment_id
644
- 'recorded_time' => bp_core_current_time(), // The GMT time that this activity was recorded
645
- 'hide_sitewide' => false // Should this be hidden on the sitewide activity stream?
646
- );
647
-
648
- $params = wp_parse_args( $args, $defaults );
649
- extract( $params, EXTR_SKIP );
650
-
651
- /* Make sure we are backwards compatible */
652
- if ( empty( $component ) && !empty( $component_name ) )
653
- $component = $component_name;
654
-
655
- if ( empty( $type ) && !empty( $component_action ) )
656
- $type = $component_action;
657
-
658
- $activity = new BP_Activity_Activity( $id );
659
-
660
- $activity->user_id = $user_id;
661
- $activity->component = $component;
662
- $activity->type = $type;
663
- $activity->action = $action;
664
- $activity->content = $content;
665
- $activity->primary_link = $primary_link;
666
- $activity->item_id = $item_id;
667
- $activity->secondary_item_id = $secondary_item_id;
668
- $activity->date_recorded = $recorded_time;
669
- $activity->hide_sitewide = $hide_sitewide;
670
-
671
- if ( !$activity->save() )
672
- return false;
673
-
674
- /* If this is an activity comment, rebuild the tree */
675
- if ( 'activity_comment' == $activity->type )
676
- BP_Activity_Activity::rebuild_activity_comment_tree( $activity->item_id );
677
-
678
- wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
679
- do_action( 'bp_activity_add', $params );
680
-
681
- return $activity->id;
682
- }
683
-
684
- function bp_activity_post_update( $args = '' ) {
685
- global $bp;
686
-
687
- $defaults = array(
688
- 'content' => false,
689
- 'user_id' => $bp->loggedin_user->id
690
- );
691
-
692
- $r = wp_parse_args( $args, $defaults );
693
- extract( $r, EXTR_SKIP );
694
-
695
- if ( empty( $content ) || !strlen( trim( $content ) ) )
696
- return false;
697
-
698
- /* Record this on the user's profile */
699
- $from_user_link = bp_core_get_userlink( $user_id );
700
- $activity_action = sprintf( __( '%s posted an update:', 'buddypress' ), $from_user_link );
701
- $activity_content = $content;
702
-
703
- $primary_link = bp_core_get_userlink( $user_id, false, true );
704
-
705
- /* Now write the values */
706
- $activity_id = bp_activity_add( array(
707
- 'user_id' => $user_id,
708
- 'action' => apply_filters( 'bp_activity_new_update_action', $activity_action ),
709
- 'content' => apply_filters( 'bp_activity_new_update_content', $activity_content ),
710
- 'primary_link' => apply_filters( 'bp_activity_new_update_primary_link', $primary_link ),
711
- 'component' => $bp->activity->id,
712
- 'type' => 'activity_update'
713
- ) );
714
-
715
- /* Add this update to the "latest update" usermeta so it can be fetched anywhere. */
716
- update_user_meta( $bp->loggedin_user->id, 'bp_latest_update', array( 'id' => $activity_id, 'content' => wp_filter_kses( $content ) ) );
717
-
718
- /* Require the notifications code so email notifications can be set on the 'bp_activity_posted_update' action. */
719
- require_once( BP_PLUGIN_DIR . '/bp-activity/bp-activity-notifications.php' );
720
-
721
- do_action( 'bp_activity_posted_update', $content, $user_id, $activity_id );
722
-
723
- return $activity_id;
724
- }
725
-
726
- function bp_activity_new_comment( $args = '' ) {
727
- global $bp;
728
-
729
- $defaults = array(
730
- 'id' => false,
731
- 'content' => false,
732
- 'user_id' => $bp->loggedin_user->id,
733
- 'activity_id' => false, // ID of the root activity item
734
- 'parent_id' => false // ID of a parent comment (optional)
735
- );
736
-
737
- $params = wp_parse_args( $args, $defaults );
738
- extract( $params, EXTR_SKIP );
739
-
740
- if ( empty($content) || empty($user_id) || empty($activity_id) )
741
- return false;
742
-
743
- if ( empty($parent_id) )
744
- $parent_id = $activity_id;
745
-
746
- /* Check to see if the parent activity is hidden, and if so, hide this comment publically. */
747
- $activity = new BP_Activity_Activity( $activity_id );
748
- $is_hidden = ( (int)$activity->hide_sitewide ) ? 1 : 0;
749
-
750
- /* Insert the activity comment */
751
- $comment_id = bp_activity_add( array(
752
- 'id' => $id,
753
- 'action' => apply_filters( 'bp_activity_comment_action', sprintf( __( '%s posted a new activity comment:', 'buddypress' ), bp_core_get_userlink( $user_id ) ) ),
754
- 'content' => apply_filters( 'bp_activity_comment_content', $content ),
755
- 'component' => $bp->activity->id,
756
- 'type' => 'activity_comment',
757
- 'user_id' => $user_id,
758
- 'item_id' => $activity_id,
759
- 'secondary_item_id' => $parent_id,
760
- 'hide_sitewide' => $is_hidden
761
- ) );
762
-
763
- /* Send an email notification if settings allow */
764
- require_once( BP_PLUGIN_DIR . '/bp-activity/bp-activity-notifications.php' );
765
- bp_activity_new_comment_notification( $comment_id, $user_id, $params );
766
-
767
- /* Clear the comment cache for this activity */
768
- wp_cache_delete( 'bp_activity_comments_' . $parent_id );
769
-
770
- do_action( 'bp_activity_comment_posted', $comment_id, $params );
771
-
772
- return $comment_id;
773
- }
774
-
775
- /**
776
- * bp_activity_get_activity_id()
777
- *
778
- * Fetch the activity_id for an existing activity entry in the DB.
779
- *
780
- * @package BuddyPress Activity
781
- */
782
- function bp_activity_get_activity_id( $args = '' ) {
783
- $defaults = array(
784
- 'user_id' => false,
785
- 'component' => false,
786
- 'type' => false,
787
- 'item_id' => false,
788
- 'secondary_item_id' => false,
789
- 'action' => false,
790
- 'content' => false,
791
- 'date_recorded' => false,
792
- );
793
-
794
- $r = wp_parse_args( $args, $defaults );
795
- extract( $r, EXTR_SKIP );
796
-
797
- return apply_filters( 'bp_activity_get_activity_id', BP_Activity_Activity::get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content, $date_recorded ) );
798
- }
799
-
800
- /***
801
- * Deleting Activity
802
- *
803
- * If you're looking to hook into one action that provides the ID(s) of
804
- * the activity/activities deleted, then use:
805
- *
806
- * add_action( 'bp_activity_deleted_activities', 'my_function' );
807
- *
808
- * The action passes one parameter that is a single activity ID or an
809
- * array of activity IDs depending on the number deleted.
810
- *
811
- * If you are deleting an activity comment please use bp_activity_delete_comment();
812
- */
813
-
814
- function bp_activity_delete( $args = '' ) {
815
- global $bp;
816
-
817
- /* Pass one or more the of following variables to delete by those variables */
818
- $defaults = array(
819
- 'id' => false,
820
- 'action' => false,
821
- 'content' => false,
822
- 'component' => false,
823
- 'type' => false,
824
- 'primary_link' => false,
825
- 'user_id' => false,
826
- 'item_id' => false,
827
- 'secondary_item_id' => false,
828
- 'date_recorded' => false,
829
- 'hide_sitewide' => false
830
- );
831
-
832
- $args = wp_parse_args( $args, $defaults );
833
-
834
- if ( !$activity_ids_deleted = BP_Activity_Activity::delete( $args ) )
835
- return false;
836
-
837
- /* Check if the user's latest update has been deleted */
838
- if ( empty( $args['user_id'] ) )
839
- $user_id = $bp->loggedin_user->id;
840
- else
841
- $user_id = $args['user_id'];
842
-
843
- $latest_update = get_user_meta( $user_id, 'bp_latest_update', true );
844
- if ( !empty( $latest_update ) ) {
845
- if ( in_array( (int)$latest_update['id'], (array)$activity_ids_deleted ) )
846
- delete_user_meta( $user_id, 'bp_latest_update' );
847
- }
848
-
849
- do_action( 'bp_activity_delete', $args );
850
- do_action( 'bp_activity_deleted_activities', $activity_ids_deleted );
851
-
852
- wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
853
-
854
- return true;
855
- }
856
- /* The following functions have been deprecated in place of bp_activity_delete() */
857
- function bp_activity_delete_by_item_id( $args = '' ) {
858
- global $bp;
859
-
860
- $defaults = array( 'item_id' => false, 'component' => false, 'type' => false, 'user_id' => false, 'secondary_item_id' => false );
861
- $r = wp_parse_args( $args, $defaults );
862
- extract( $r, EXTR_SKIP );
863
-
864
- return bp_activity_delete( array( 'item_id' => $item_id, 'component' => $component, 'type' => $type, 'user_id' => $user_id, 'secondary_item_id' => $secondary_item_id ) );
865
- }
866
-
867
- function bp_activity_delete_by_activity_id( $activity_id ) {
868
- return bp_activity_delete( array( 'id' => $activity_id ) );
869
- }
870
-
871
- function bp_activity_delete_by_content( $user_id, $content, $component, $type ) {
872
- return bp_activity_delete( array( 'user_id' => $user_id, 'content' => $content, 'component' => $component, 'type' => $type ) );
873
- }
874
-
875
- function bp_activity_delete_for_user_by_component( $user_id, $component ) {
876
- return bp_activity_delete( array( 'user_id' => $user_id, 'component' => $component ) );
877
- }
878
- /* End deprecation */
879
-
880
- function bp_activity_delete_comment( $activity_id, $comment_id ) {
881
- /***
882
- * You may want to hook into this filter if you want to override this function and
883
- * handle the deletion of child comments differently. Make sure you return false.
884
- */
885
- if ( !apply_filters( 'bp_activity_delete_comment_pre', true, $activity_id, $comment_id ) )
886
- return false;
887
-
888
- /* Delete any children of this comment. */
889
- bp_activity_delete_children( $activity_id, $comment_id );
890
-
891
- /* Delete the actual comment */
892
- if ( !bp_activity_delete( array( 'id' => $comment_id, 'type' => 'activity_comment' ) ) )
893
- return false;
894
-
895
- /* Recalculate the comment tree */
896
- BP_Activity_Activity::rebuild_activity_comment_tree( $activity_id );
897
-
898
- do_action( 'bp_activity_delete_comment', $activity_id, $comment_id );
899
-
900
- return true;
901
- }
902
- function bp_activity_delete_children( $activity_id, $comment_id) {
903
- /* Recursively delete all children of this comment. */
904
- if ( $children = BP_Activity_Activity::get_child_comments( $comment_id ) ) {
905
- foreach( (array)$children as $child )
906
- bp_activity_delete_children( $activity_id, $child->id );
907
- }
908
- bp_activity_delete( array( 'secondary_item_id' => $comment_id, 'type' => 'activity_comment', 'item_id' => $activity_id ) );
909
- }
910
-
911
- function bp_activity_get_permalink( $activity_id, $activity_obj = false ) {
912
- global $bp;
913
-
914
- if ( !$activity_obj )
915
- $activity_obj = new BP_Activity_Activity( $activity_id );
916
-
917
- 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 )
918
- $link = $activity_obj->primary_link;
919
- else {
920
- if ( 'activity_comment' == $activity_obj->type )
921
- $link = $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activity_obj->item_id . '/';
922
- else
923
- $link = $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activity_obj->id . '/';
924
- }
925
-
926
- return apply_filters( 'bp_activity_get_permalink', $link );
927
- }
928
-
929
- function bp_activity_hide_user_activity( $user_id ) {
930
- return BP_Activity_Activity::hide_all_for_user( $user_id );
931
- }
932
-
933
- /**
934
- * bp_activity_thumbnail_content_images()
935
- *
936
- * Take content, remove all images and replace them with one thumbnail image.
937
- *
938
- * @package BuddyPress Activity
939
- * @param $content str - The content to work with
940
- * @return $content str - The content with images stripped and replaced with a single thumb.
941
- */
942
- function bp_activity_thumbnail_content_images( $content ) {
943
- preg_match_all( '/<img[^>]*>/Ui', $content, $matches );
944
- $content = preg_replace('/<img[^>]*>/Ui', '', $content );
945
-
946
- if ( !empty( $matches ) ) {
947
- /* Get the SRC value */
948
- preg_match( '/<img.*?(src\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $src );
949
-
950
- /* Get the width and height */
951
- preg_match( '/<img.*?(height\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $height );
952
- preg_match( '/<img.*?(width\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $width );
953
-
954
- if ( !empty( $src ) ) {
955
- $src = substr( substr( str_replace( 'src=', '', $src[1] ), 0, -1 ), 1 );
956
- $height = substr( substr( str_replace( 'height=', '', $height[1] ), 0, -1 ), 1 );
957
- $width = substr( substr( str_replace( 'width=', '', $width[1] ), 0, -1 ), 1 );
958
-
959
- if ( empty( $width ) || empty( $height ) ) {
960
- $width = 100;
961
- $height = 100;
962
- }
963
-
964
- $ratio = (int)$width / (int)$height;
965
- $new_height = 100;
966
- $new_width = $new_height * $ratio;
967
-
968
- $content = '<img src="' . esc_attr( $src) . '" width="' . $new_width . '" height="' . $new_height . '" alt="' . __( 'Thumbnail', 'buddypress' ) . '" class="align-left thumbnail" />' . $content;
969
- }
970
- }
971
-
972
- return apply_filters( 'bp_activity_thumbnail_content_images', $content, $matches );
973
- }
974
-
975
- function bp_activity_set_action( $component_id, $key, $value ) {
976
- global $bp;
977
-
978
- if ( empty( $component_id ) || empty( $key ) || empty( $value ) )
979
- return false;
980
-
981
- $bp->activity->actions->{$component_id}->{$key} = apply_filters( 'bp_activity_set_action', array(
982
- 'key' => $key,
983
- 'value' => $value
984
- ), $component_id, $key, $value );
985
- }
986
-
987
- function bp_activity_get_action( $component_id, $key ) {
988
- global $bp;
989
-
990
- if ( empty( $component_id ) || empty( $key ) )
991
- return false;
992
-
993
- return apply_filters( 'bp_activity_get_action', $bp->activity->actions->{$component_id}->{$key}, $component_id, $key );
994
- }
995
-
996
- function bp_activity_get_user_favorites( $user_id ) {
997
- $my_favs = maybe_unserialize( get_user_meta( $user_id, 'bp_favorite_activities', true ) );
998
- $existing_favs = bp_activity_get_specific( array( 'activity_ids' => $my_favs, 'show_hidden' => true ) );
999
-
1000
- foreach( (array)$existing_favs['activities'] as $fav )
1001
- $new_favs[] = $fav->id;
1002
-
1003
- $new_favs = array_unique( (array)$new_favs );
1004
- update_user_meta( $user_id, 'bp_favorite_activities', $new_favs );
1005
-
1006
- return apply_filters( 'bp_activity_get_user_favorites', $new_favs );
1007
- }
1008
-
1009
- function bp_activity_add_user_favorite( $activity_id, $user_id = false ) {
1010
- global $bp;
1011
-
1012
- if ( !$user_id )
1013
- $user_id = $bp->loggedin_user->id;
1014
-
1015
- /* Update the user's personal favorites */
1016
- $my_favs = maybe_unserialize( get_user_meta( $bp->loggedin_user->id, 'bp_favorite_activities', true ) );
1017
- $my_favs[] = $activity_id;
1018
-
1019
- /* Update the total number of users who have favorited this activity */
1020
- $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' );
1021
-
1022
- if ( !empty( $fav_count ) )
1023
- $fav_count = (int)$fav_count + 1;
1024
- else
1025
- $fav_count = 1;
1026
-
1027
- update_user_meta( $bp->loggedin_user->id, 'bp_favorite_activities', $my_favs );
1028
- bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count );
1029
-
1030
- do_action( 'bp_activity_add_user_favorite', $activity_id, $user_id );
1031
-
1032
- return true;
1033
- }
1034
-
1035
- function bp_activity_remove_user_favorite( $activity_id, $user_id = false ) {
1036
- global $bp;
1037
-
1038
- if ( !$user_id )
1039
- $user_id = $bp->loggedin_user->id;
1040
-
1041
- /* Remove the fav from the user's favs */
1042
- $my_favs = maybe_unserialize( get_user_meta( $user_id, 'bp_favorite_activities', true ) );
1043
- $my_favs = array_flip( (array) $my_favs );
1044
- unset( $my_favs[$activity_id] );
1045
- $my_favs = array_unique( array_flip( $my_favs ) );
1046
-
1047
- /* Update the total number of users who have favorited this activity */
1048
- $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' );
1049
-
1050
- if ( !empty( $fav_count ) ) {
1051
- $fav_count = (int)$fav_count - 1;
1052
- bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count );
1053
- }
1054
-
1055
- update_user_meta( $user_id, 'bp_favorite_activities', $my_favs );
1056
-
1057
- do_action( 'bp_activity_remove_user_favorite', $activity_id, $user_id );
1058
-
1059
- return true;
1060
- }
1061
-
1062
- function bp_activity_check_exists_by_content( $content ) {
1063
- return apply_filters( 'bp_activity_check_exists_by_content', BP_Activity_Activity::check_exists_by_content( $content ) );
1064
- }
1065
-
1066
- function bp_activity_get_last_updated() {
1067
- return apply_filters( 'bp_activity_get_last_updated', BP_Activity_Activity::get_last_updated() );
1068
- }
1069
-
1070
- function bp_activity_total_favorites_for_user( $user_id = false ) {
1071
- global $bp;
1072
-
1073
- if ( !$user_id )
1074
- $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
1075
-
1076
- return BP_Activity_Activity::total_favorite_count( $user_id );
1077
- }
1078
-
1079
- /********************************************************************************
1080
- * Activity Meta Functions
1081
- *
1082
- * Meta functions allow you to store extra data for a particular item.
1083
- */
1084
-
1085
- function bp_activity_delete_meta( $activity_id, $meta_key = false, $meta_value = false ) {
1086
- global $wpdb, $bp;
1087
-
1088
- if ( !is_numeric( $activity_id ) )
1089
- return false;
1090
-
1091
- $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
1092
-
1093
- if ( is_array( $meta_value ) || is_object( $meta_value ) )
1094
- $meta_value = serialize( $meta_value );
1095
-
1096
- $meta_value = trim( $meta_value );
1097
-
1098
- if ( !$meta_key ) {
1099
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d", $activity_id ) );
1100
- } else if ( $meta_value ) {
1101
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s AND meta_value = %s", $activity_id, $meta_key, $meta_value ) );
1102
- } else {
1103
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s", $activity_id, $meta_key ) );
1104
- }
1105
-
1106
- wp_cache_delete( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, 'bp' );
1107
-
1108
- return true;
1109
- }
1110
-
1111
- function bp_activity_get_meta( $activity_id, $meta_key = '' ) {
1112
- global $wpdb, $bp;
1113
-
1114
- $activity_id = (int)$activity_id;
1115
-
1116
- if ( !$activity_id )
1117
- return false;
1118
-
1119
- if ( !empty($meta_key) ) {
1120
- $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
1121
-
1122
- if ( !$metas = wp_cache_get( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, 'bp' ) ) {
1123
- $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 ) );
1124
- wp_cache_set( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, $metas, 'bp' );
1125
- }
1126
- } else
1127
- $metas = $wpdb->get_col( $wpdb->prepare( "SELECT meta_value FROM {$bp->activity->table_name_meta} WHERE activity_id = %d", $activity_id ) );
1128
-
1129
- if ( empty($metas) )
1130
- return false;
1131
-
1132
- $metas = array_map( 'maybe_unserialize', (array)$metas );
1133
-
1134
- if ( 1 == count($metas) )
1135
- return $metas[0];
1136
- else
1137
- return $metas;
1138
- }
1139
-
1140
- function bp_activity_update_meta( $activity_id, $meta_key, $meta_value ) {
1141
- global $wpdb, $bp;
1142
-
1143
- if ( !is_numeric( $activity_id ) )
1144
- return false;
1145
-
1146
- $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
1147
-
1148
- if ( is_string( $meta_value ) )
1149
- $meta_value = stripslashes( $wpdb->escape( $meta_value ) );
1150
-
1151
- $meta_value = maybe_serialize( $meta_value );
1152
-
1153
- if ( empty( $meta_value ) ) {
1154
- return bp_activity_delete_meta( $activity_id, $meta_key );
1155
- }
1156
-
1157
- $cur = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s", $activity_id, $meta_key ) );
1158
-
1159
- if ( !$cur ) {
1160
- $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->activity->table_name_meta} ( activity_id, meta_key, meta_value ) VALUES ( %d, %s, %s )", $activity_id, $meta_key, $meta_value ) );
1161
- } else if ( $cur->meta_value != $meta_value ) {
1162
- $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name_meta} SET meta_value = %s WHERE activity_id = %d AND meta_key = %s", $meta_value, $activity_id, $meta_key ) );
1163
- } else {
1164
- return false;
1165
- }
1166
-
1167
- wp_cache_set( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, $meta_value, 'bp' );
1168
-
1169
- return true;
1170
- }
1171
-
1172
- function bp_activity_remove_data( $user_id ) {
1173
- // Clear the user's activity from the sitewide stream and clear their activity tables
1174
- bp_activity_delete( array( 'user_id' => $user_id ) );
1175
-
1176
- // Remove any usermeta
1177
- delete_user_meta( $user_id, 'bp_latest_update' );
1178
- delete_user_meta( $user_id, 'bp_favorite_activities' );
1179
-
1180
- do_action( 'bp_activity_remove_data', $user_id );
1181
- }
1182
- add_action( 'wpmu_delete_user', 'bp_activity_remove_data' );
1183
- add_action( 'delete_user', 'bp_activity_remove_data' );
1184
- add_action( 'make_spam_user', 'bp_activity_remove_data' );
1185
-
1186
- /**
1187
- * updates_register_activity_actions()
1188
- *
1189
- * Register the activity stream actions for updates
1190
- *
1191
- * @global array $bp
1192
- */
1193
- function updates_register_activity_actions() {
1194
- global $bp;
1195
-
1196
- bp_activity_set_action( $bp->activity->id, 'activity_update', __( 'Posted an update', 'buddypress' ) );
1197
-
1198
- do_action( 'updates_register_activity_actions' );
1199
- }
1200
- add_action( 'bp_register_activity_actions', 'updates_register_activity_actions' );
1201
-
1202
- /********************************************************************************
1203
- * Custom Actions
1204
- *
1205
- * Functions to set up custom BuddyPress actions that all other components can
1206
- * hook in to.
1207
- */
1208
-
1209
- /* Allow core components and dependent plugins to register activity actions */
1210
- function bp_register_activity_actions() {
1211
- do_action( 'bp_register_activity_actions' );
1212
- }
1213
- add_action( 'bp_loaded', 'bp_register_activity_actions', 8 );
1214
-
1215
-
1216
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-activity/bp-activity-actions.php ADDED
@@ -0,0 +1,530 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Action functions are exactly the same as screen functions, however they do
5
+ * not have a template screen associated with them. Usually they will send the
6
+ * user back to the default screen after execution.
7
+ *
8
+ * @package BuddyPress
9
+ * @subpackage ActivityActions
10
+ */
11
+
12
+ // Exit if accessed directly
13
+ if ( !defined( 'ABSPATH' ) ) exit;
14
+
15
+ /**
16
+ * Allow core components and dependent plugins to register activity actions
17
+ *
18
+ * @since 1.2.0
19
+ *
20
+ * @uses do_action() To call 'bp_register_activity_actions' hook.
21
+ */
22
+ function bp_register_activity_actions() {
23
+ do_action( 'bp_register_activity_actions' );
24
+ }
25
+ add_action( 'bp_init', 'bp_register_activity_actions', 8 );
26
+
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()
34
+ * @uses bp_is_current_action()
35
+ * @uses bp_action_variable()
36
+ * @uses bp_activity_get_specific()
37
+ * @uses bp_is_active()
38
+ * @uses bp_core_get_user_domain()
39
+ * @uses groups_get_group()
40
+ * @uses bp_get_group_permalink()
41
+ * @uses apply_filters_ref_array() To call the 'bp_activity_permalink_redirect_url' hook
42
+ * @uses bp_core_redirect()
43
+ * @uses bp_get_root_domain()
44
+ *
45
+ * @return bool False on failure
46
+ */
47
+ function bp_activity_action_permalink_router() {
48
+ global $bp;
49
+
50
+ // Not viewing activity
51
+ if ( !bp_is_activity_component() || !bp_is_current_action( 'p' ) )
52
+ return false;
53
+
54
+ // No activity to display
55
+ if ( !bp_action_variable( 0 ) || !is_numeric( bp_action_variable( 0 ) ) )
56
+ return false;
57
+
58
+ // Get the activity details
59
+ $activity = bp_activity_get_specific( array( 'activity_ids' => bp_action_variable( 0 ), 'show_hidden' => true ) );
60
+
61
+ // 404 if activity does not exist
62
+ if ( empty( $activity['activities'][0] ) ) {
63
+ bp_do_404();
64
+ return;
65
+
66
+ } else {
67
+ $activity = $activity['activities'][0];
68
+ }
69
+
70
+ // Do not redirect at default
71
+ $redirect = false;
72
+
73
+ // Redirect based on the type of activity
74
+ if ( bp_is_active( 'groups' ) && $activity->component == $bp->groups->id ) {
75
+
76
+ // Activity is a user update
77
+ if ( !empty( $activity->user_id ) ) {
78
+ $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . bp_get_activity_slug() . '/' . $activity->id . '/';
79
+
80
+ // Activity is something else
81
+ } else {
82
+
83
+ // Set redirect to group activity stream
84
+ if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) ) {
85
+ $redirect = bp_get_group_permalink( $group ) . bp_get_activity_slug() . '/' . $activity->id . '/';
86
+ }
87
+ }
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
95
+ if ( !$redirect = apply_filters_ref_array( 'bp_activity_permalink_redirect_url', array( $redirect, &$activity ) ) )
96
+ bp_core_redirect( bp_get_root_domain() );
97
+
98
+ // Redirect to the actual activity permalink page
99
+ bp_core_redirect( $redirect );
100
+ }
101
+ add_action( 'bp_actions', 'bp_activity_action_permalink_router' );
102
+
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()
114
+ * @uses check_admin_referer()
115
+ * @uses bp_activity_user_can_delete()
116
+ * @uses do_action() Calls 'bp_activity_before_action_delete_activity' hook to allow actions to be taken before the activity is deleted.
117
+ * @uses bp_activity_delete()
118
+ * @uses bp_core_add_message()
119
+ * @uses do_action() Calls 'bp_activity_action_delete_activity' hook to allow actions to be taken after the activity is deleted.
120
+ * @uses bp_core_redirect()
121
+ *
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' ) )
129
+ return false;
130
+
131
+ if ( empty( $activity_id ) && bp_action_variable( 0 ) )
132
+ $activity_id = (int) bp_action_variable( 0 );
133
+
134
+ // Not viewing a specific activity item
135
+ if ( empty( $activity_id ) )
136
+ return false;
137
+
138
+ // Check the nonce
139
+ check_admin_referer( 'bp_activity_delete_link' );
140
+
141
+ // Load up the activity item
142
+ $activity = new BP_Activity_Activity( $activity_id );
143
+
144
+ // Check access
145
+ if ( empty( $activity->user_id ) || !bp_activity_user_can_delete( $activity ) )
146
+ return false;
147
+
148
+ // Call the action before the delete so plugins can still fetch information about it
149
+ do_action( 'bp_activity_before_action_delete_activity', $activity_id, $activity->user_id );
150
+
151
+ // Delete the activity item and provide user feedback
152
+ if ( bp_activity_delete( array( 'id' => $activity_id, 'user_id' => $activity->user_id ) ) )
153
+ bp_core_add_message( __( 'Activity deleted successfully', 'buddypress' ) );
154
+ else
155
+ bp_core_add_message( __( 'There was an error when deleting that activity', 'buddypress' ), 'error' );
156
+
157
+ do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id );
158
+
159
+ // Check for the redirect query arg, otherwise let WP handle things
160
+ if ( !empty( $_GET['redirect_to'] ) )
161
+ bp_core_redirect( esc_url( $_GET['redirect_to'] ) );
162
+ else
163
+ bp_core_redirect( wp_get_referer() );
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()
176
+ * @uses check_admin_referer()
177
+ * @uses apply_filters() To call 'bp_activity_post_update_content' hook.
178
+ * @uses apply_filters() To call 'bp_activity_post_update_object' hook.
179
+ * @uses apply_filters() To call 'bp_activity_post_update_item_id' hook.
180
+ * @uses bp_core_add_message()
181
+ * @uses bp_core_redirect()
182
+ * @uses bp_activity_post_update()
183
+ * @uses groups_post_update()
184
+ * @uses bp_core_redirect()
185
+ * @uses apply_filters() To call 'bp_activity_custom_update' hook.
186
+ *
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' ) )
194
+ return false;
195
+
196
+ // Check the nonce
197
+ check_admin_referer( 'post_update', '_wpnonce_post_update' );
198
+
199
+ // Get activity info
200
+ $content = apply_filters( 'bp_activity_post_update_content', $_POST['whats-new'] );
201
+ $object = apply_filters( 'bp_activity_post_update_object', $_POST['whats-new-post-object'] );
202
+ $item_id = apply_filters( 'bp_activity_post_update_item_id', $_POST['whats-new-post-in'] );
203
+
204
+ // No activity content so provide feedback and redirect
205
+ if ( empty( $content ) ) {
206
+ bp_core_add_message( __( 'Please enter some content to post.', 'buddypress' ), 'error' );
207
+ bp_core_redirect( wp_get_referer() );
208
+ }
209
+
210
+ // No existing item_id
211
+ if ( empty( $item_id ) ) {
212
+ $activity_id = bp_activity_post_update( array( 'content' => $content ) );
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
+
220
+ // Special circumstance so let filters handle it
221
+ } else {
222
+ $activity_id = apply_filters( 'bp_activity_custom_update', $object, $item_id, $content );
223
+ }
224
+
225
+ // Provide user feedback
226
+ if ( !empty( $activity_id ) )
227
+ bp_core_add_message( __( 'Update Posted!', 'buddypress' ) );
228
+ else
229
+ bp_core_add_message( __( 'There was an error when posting your update, please try again.', 'buddypress' ), 'error' );
230
+
231
+ // Redirect
232
+ bp_core_redirect( wp_get_referer() );
233
+ }
234
+ add_action( 'bp_actions', 'bp_activity_action_post_update' );
235
+
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()
245
+ * @uses check_admin_referer()
246
+ * @uses apply_filters() To call 'bp_activity_post_comment_activity_id' hook.
247
+ * @uses apply_filters() To call 'bp_activity_post_comment_content' hook.
248
+ * @uses bp_core_add_message()
249
+ * @uses bp_core_redirect()
250
+ * @uses bp_activity_new_comment()
251
+ * @uses wp_get_referer()
252
+ *
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
262
+ check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );
263
+
264
+ $activity_id = apply_filters( 'bp_activity_post_comment_activity_id', $_POST['comment_form_id'] );
265
+ $content = apply_filters( 'bp_activity_post_comment_content', $_POST['ac_input_' . $activity_id] );
266
+
267
+ if ( empty( $content ) ) {
268
+ bp_core_add_message( __( 'Please do not leave the comment area blank.', 'buddypress' ), 'error' );
269
+ bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
270
+ }
271
+
272
+ $comment_id = bp_activity_new_comment( array(
273
+ 'content' => $content,
274
+ 'activity_id' => $activity_id,
275
+ 'parent_id' => $parent_id
276
+ ));
277
+
278
+ if ( !empty( $comment_id ) )
279
+ bp_core_add_message( __( 'Reply Posted!', 'buddypress' ) );
280
+ else
281
+ bp_core_add_message( __( 'There was an error posting that reply, please try again.', 'buddypress' ), 'error' );
282
+
283
+ bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
284
+ }
285
+ add_action( 'bp_actions', 'bp_activity_action_post_comment' );
286
+
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()
296
+ * @uses check_admin_referer()
297
+ * @uses bp_activity_add_user_favorite()
298
+ * @uses bp_action_variable()
299
+ * @uses bp_core_add_message()
300
+ * @uses bp_core_redirect()
301
+ * @uses wp_get_referer()
302
+ *
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
312
+ check_admin_referer( 'mark_favorite' );
313
+
314
+ if ( bp_activity_add_user_favorite( bp_action_variable( 0 ) ) )
315
+ bp_core_add_message( __( 'Activity marked as favorite.', 'buddypress' ) );
316
+ else
317
+ bp_core_add_message( __( 'There was an error marking that activity as a favorite, please try again.', 'buddypress' ), 'error' );
318
+
319
+ bp_core_redirect( wp_get_referer() . '#activity-' . bp_action_variable( 0 ) );
320
+ }
321
+ add_action( 'bp_actions', 'bp_activity_action_mark_favorite' );
322
+
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()
332
+ * @uses check_admin_referer()
333
+ * @uses bp_activity_remove_user_favorite()
334
+ * @uses bp_action_variable()
335
+ * @uses bp_core_add_message()
336
+ * @uses bp_core_redirect()
337
+ * @uses wp_get_referer()
338
+ *
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
348
+ check_admin_referer( 'unmark_favorite' );
349
+
350
+ if ( bp_activity_remove_user_favorite( bp_action_variable( 0 ) ) )
351
+ bp_core_add_message( __( 'Activity removed as favorite.', 'buddypress' ) );
352
+ else
353
+ bp_core_add_message( __( 'There was an error removing that activity as a favorite, please try again.', 'buddypress' ), 'error' );
354
+
355
+ bp_core_redirect( wp_get_referer() . '#activity-' . bp_action_variable( 0 ) );
356
+ }
357
+ add_action( 'bp_actions', 'bp_activity_action_remove_favorite' );
358
+
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
366
+ * @uses bp_is_activity_component()
367
+ * @uses bp_is_current_action()
368
+ * @uses bp_is_user()
369
+ * @uses status_header()
370
+ *
371
+ * @return bool False on failure
372
+ */
373
+ function bp_activity_action_sitewide_feed() {
374
+ global $bp, $wp_query;
375
+
376
+ if ( !bp_is_activity_component() || !bp_is_current_action( 'feed' ) || bp_is_user() || !empty( $bp->groups->current_group ) )
377
+ return false;
378
+
379
+ $wp_query->is_404 = false;
380
+ status_header( 200 );
381
+
382
+ include_once( 'feeds/bp-activity-sitewide-feed.php' );
383
+ die;
384
+ }
385
+ add_action( 'bp_actions', 'bp_activity_action_sitewide_feed' );
386
+
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()
396
+ * @uses status_header()
397
+ *
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;
405
+
406
+ $wp_query->is_404 = false;
407
+ status_header( 200 );
408
+
409
+ include_once( 'feeds/bp-activity-personal-feed.php' );
410
+ die;
411
+ }
412
+ add_action( 'bp_actions', 'bp_activity_action_personal_feed' );
413
+
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()
423
+ * @uses bp_is_current_action()
424
+ * @uses bp_get_friends_slug()
425
+ * @uses bp_is_action_variable()
426
+ * @uses status_header()
427
+ *
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;
435
+
436
+ $wp_query->is_404 = false;
437
+ status_header( 200 );
438
+
439
+ include_once( 'feeds/bp-activity-friends-feed.php' );
440
+ die;
441
+ }
442
+ add_action( 'bp_actions', 'bp_activity_action_friends_feed' );
443
+
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()
453
+ * @uses bp_is_current_action()
454
+ * @uses bp_get_groups_slug()
455
+ * @uses bp_is_action_variable()
456
+ * @uses status_header()
457
+ *
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;
465
+
466
+ $wp_query->is_404 = false;
467
+ status_header( 200 );
468
+
469
+ include_once( 'feeds/bp-activity-mygroups-feed.php' );
470
+ die;
471
+ }
472
+ add_action( 'bp_actions', 'bp_activity_action_my_groups_feed' );
473
+
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()
483
+ * @uses bp_is_action_variable()
484
+ * @uses status_header()
485
+ *
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;
493
+
494
+ $wp_query->is_404 = false;
495
+ status_header( 200 );
496
+
497
+ include_once( 'feeds/bp-activity-mentions-feed.php' );
498
+ die;
499
+ }
500
+ add_action( 'bp_actions', 'bp_activity_action_mentions_feed' );
501
+
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()
511
+ * @uses bp_is_action_variable()
512
+ * @uses status_header()
513
+ *
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;
521
+
522
+ $wp_query->is_404 = false;
523
+ status_header( 200 );
524
+
525
+ include_once( 'feeds/bp-activity-favorites-feed.php' );
526
+ die;
527
+ }
528
+ add_action( 'bp_actions', 'bp_activity_action_favorites_feed' );
529
+
530
+ ?>
bp-activity/bp-activity-classes.php CHANGED
@@ -1,5 +1,15 @@
1
  <?php
2
 
 
 
 
 
 
 
 
 
 
 
3
  Class BP_Activity_Activity {
4
  var $id;
5
  var $item_id;
@@ -12,11 +22,17 @@ Class BP_Activity_Activity {
12
  var $content;
13
  var $date_recorded;
14
  var $hide_sitewide = false;
 
 
15
 
16
  function bp_activity_activity( $id = false ) {
 
 
 
 
17
  global $bp;
18
 
19
- if ( $id ) {
20
  $this->id = $id;
21
  $this->populate();
22
  }
@@ -25,42 +41,42 @@ Class BP_Activity_Activity {
25
  function populate() {
26
  global $wpdb, $bp;
27
 
28
- $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id = %d", $this->id ) );
29
- if ( $row ) {
30
- $this->id = $row->id;
31
- $this->item_id = $row->item_id;
32
  $this->secondary_item_id = $row->secondary_item_id;
33
- $this->user_id = $row->user_id;
34
- $this->primary_link = $row->primary_link;
35
- $this->component = $row->component;
36
- $this->type = $row->type;
37
- $this->action = $row->action;
38
- $this->content = $row->content;
39
- $this->date_recorded = $row->date_recorded;
40
- $this->hide_sitewide = $row->hide_sitewide;
41
- $this->mptt_left = $row->mptt_left;
42
- $this->mptt_right = $row->mptt_right;
43
  }
44
  }
45
 
46
  function save() {
47
  global $wpdb, $bp, $current_user;
48
 
49
- do_action( 'bp_activity_before_save', &$this );
50
-
51
- $this->id = apply_filters( 'bp_activity_id_before_save', $this->id, &$this );
52
- $this->item_id = apply_filters( 'bp_activity_item_id_before_save', $this->item_id, &$this );
53
- $this->secondary_item_id = apply_filters( 'bp_activity_secondary_item_id_before_save', $this->secondary_item_id, &$this );
54
- $this->user_id = apply_filters( 'bp_activity_user_id_before_save', $this->user_id, &$this );
55
- $this->primary_link = apply_filters( 'bp_activity_primary_link_before_save', $this->primary_link, &$this );
56
- $this->component = apply_filters( 'bp_activity_component_before_save', $this->component, &$this );
57
- $this->type = apply_filters( 'bp_activity_type_before_save', $this->type, &$this );
58
- $this->action = apply_filters( 'bp_activity_action_before_save', $this->action, &$this );
59
- $this->content = apply_filters( 'bp_activity_content_before_save', $this->content, &$this );
60
- $this->date_recorded = apply_filters( 'bp_activity_date_recorded_before_save', $this->date_recorded, &$this );
61
- $this->hide_sitewide = apply_filters( 'bp_activity_hide_sitewide_before_save', $this->hide_sitewide, &$this );
62
- $this->mptt_left = apply_filters( 'bp_activity_mptt_left_before_save', $this->mptt_left, &$this );
63
- $this->mptt_right = apply_filters( 'bp_activity_mptt_right_before_save', $this->mptt_right, &$this );
 
64
 
65
  if ( !$this->component || !$this->type )
66
  return false;
@@ -68,7 +84,7 @@ Class BP_Activity_Activity {
68
  if ( !$this->primary_link )
69
  $this->primary_link = $bp->loggedin_user->domain;
70
 
71
- /* If we have an existing ID, update the activity item, otherwise insert it. */
72
  if ( $this->id )
73
  $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 );
74
  else
@@ -80,58 +96,78 @@ Class BP_Activity_Activity {
80
  if ( empty( $this->id ) )
81
  $this->id = $wpdb->insert_id;
82
 
83
- do_action( 'bp_activity_after_save', &$this );
 
84
  return true;
85
  }
86
 
87
- /* Static Functions */
88
 
89
- function get( $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false ) {
90
  global $wpdb, $bp;
91
 
92
- /* Select conditions */
93
  $select_sql = "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name";
94
 
95
  $from_sql = " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID";
96
 
97
- /* Where conditions */
98
  $where_conditions = array();
99
 
100
- /* Searching */
101
  if ( $search_terms ) {
102
  $search_terms = $wpdb->escape( $search_terms );
103
  $where_conditions['search_sql'] = "a.content LIKE '%%" . like_escape( $search_terms ) . "%%'";
104
  }
105
 
106
- /* Filtering */
107
  if ( $filter && $filter_sql = BP_Activity_Activity::get_filter_sql( $filter ) )
108
  $where_conditions['filter_sql'] = $filter_sql;
109
 
110
- /* Sorting */
111
  if ( $sort != 'ASC' && $sort != 'DESC' )
112
  $sort = 'DESC';
113
 
114
- /* Hide Hidden Items? */
115
  if ( !$show_hidden )
116
  $where_conditions['hidden_sql'] = "a.hide_sitewide = 0";
117
 
118
- /* Alter the query based on whether we want to show activity item comments in the stream like normal comments or threaded below the activity */
119
- if ( !$display_comments || 'threaded' == $display_comments ) {
120
- $where_conditions[] = "a.type != 'activity_comment'";
 
 
 
 
 
 
 
 
 
 
121
  }
122
 
 
 
 
 
 
 
123
  $where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
124
 
125
  if ( $per_page && $page ) {
126
  $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page ), intval( $per_page ) );
127
- $activities = $wpdb->get_results( $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}" ) );
128
- } else
129
- $activities = $wpdb->get_results( $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}" ) );
 
130
 
131
- $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(a.id) FROM {$bp->activity->table_name} a {$where_sql} ORDER BY a.date_recorded {$sort}" ) );
132
 
133
- /* Get the fullnames of users so we don't have to query in the loop */
134
- if ( function_exists( 'xprofile_install' ) && $activities ) {
 
 
135
  foreach ( (array)$activities as $activity ) {
136
  if ( (int)$activity->user_id )
137
  $activity_user_ids[] = $activity->user_id;
@@ -155,9 +191,9 @@ Class BP_Activity_Activity {
155
  }
156
 
157
  if ( $activities && $display_comments )
158
- $activities = BP_Activity_Activity::append_comments( &$activities );
159
 
160
- /* If $max is set, only return up to the max results */
161
  if ( !empty( $max ) ) {
162
  if ( (int)$total_activities > (int)$max )
163
  $total_activities = $max;
@@ -166,42 +202,24 @@ Class BP_Activity_Activity {
166
  return array( 'activities' => $activities, 'total' => (int)$total_activities );
167
  }
168
 
169
- function get_specific( $activity_ids, $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $display_comments = false, $show_hidden = false ) {
170
- global $wpdb, $bp;
171
-
172
- if ( is_array( $activity_ids ) )
173
- $activity_ids = implode ( ',', array_map( 'absint', $activity_ids ) );
174
- else
175
- $activity_ids = implode ( ',', array_map( 'absint', explode ( ',', $activity_ids ) ) );
176
-
177
- if ( empty( $activity_ids ) )
178
- return false;
179
-
180
- if ( $per_page && $page )
181
- $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page ), intval( $per_page ) );
182
-
183
- if ( $sort != 'ASC' && $sort != 'DESC' )
184
- $sort = 'DESC';
185
-
186
- // Hide Hidden Items?
187
- if ( !$show_hidden )
188
- $hidden_sql = "AND hide_sitewide = 0";
189
- else
190
- $hidden_sql = '';
191
-
192
- $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id IN ({$activity_ids}) {$hidden_sql} ORDER BY date_recorded {$sort} {$pag_sql}" ) );
193
- $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE id IN ({$activity_ids}) {$hidden_sql}" ) );
194
-
195
- if ( $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
  function get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content, $date_recorded ) {
@@ -244,21 +262,21 @@ Class BP_Activity_Activity {
244
  function delete( $args ) {
245
  global $wpdb, $bp;
246
 
247
- extract( $args );
248
-
249
  $defaults = array(
250
- 'id' => false,
251
- 'action' => false,
252
- 'content' => false,
253
- 'component' => false,
254
- 'type' => false,
255
- 'primary_link' => false,
256
- 'user_id' => false,
257
- 'item_id' => false,
258
  'secondary_item_id' => false,
259
- 'date_recorded' => false,
260
- 'hide_sitewide' => false
261
  );
 
 
262
 
263
  $where_args = false;
264
 
@@ -300,7 +318,7 @@ Class BP_Activity_Activity {
300
  else
301
  return false;
302
 
303
- /* Fetch the activity IDs so we can delete any comments for this activity item */
304
  $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" ) );
305
 
306
  if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} {$where_sql}" ) ) )
@@ -341,6 +359,8 @@ Class BP_Activity_Activity {
341
  function append_comments( $activities ) {
342
  global $bp, $wpdb;
343
 
 
 
344
  /* Now fetch the activity comments and parse them into the correct position in the activities array. */
345
  foreach( (array)$activities as $activity ) {
346
  if ( 'activity_comment' != $activity->type && $activity->mptt_left && $activity->mptt_right )
@@ -349,7 +369,8 @@ Class BP_Activity_Activity {
349
 
350
  /* Merge the comments with the activity items */
351
  foreach( (array)$activities as $key => $activity )
352
- $activities[$key]->children = $activity_comments[$activity->id];
 
353
 
354
  return $activities;
355
  }
@@ -358,30 +379,34 @@ Class BP_Activity_Activity {
358
  global $wpdb, $bp;
359
 
360
  if ( !$comments = wp_cache_get( 'bp_activity_comments_' . $activity_id ) ) {
361
- /* Select the user's fullname with the query so we don't have to fetch it for each comment */
362
- if ( function_exists( 'xprofile_install' ) ) {
363
  $fullname_select = ", pd.value as user_fullname";
364
  $fullname_from = ", {$bp->profile->table_name_data} pd ";
365
  $fullname_where = "AND pd.user_id = a.user_id AND pd.field_id = 1";
 
 
 
 
366
  }
367
 
368
- /* Retrieve all descendants of the $root node */
369
- $descendants = $wpdb->get_results( $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 ) );
370
 
371
- /* Loop descendants and build an assoc array */
372
  foreach ( (array)$descendants as $d ) {
373
- $d->children = array();
374
-
375
- /* If we have a reference on the parent */
376
- if ( isset( $ref[ $d->secondary_item_id ] ) ) {
377
- $ref[ $d->secondary_item_id ]->children[ $d->id ] = $d;
378
- $ref[ $d->id ] =& $ref[ $d->secondary_item_id ]->children[ $d->id ];
379
-
380
- /* If we don't have a reference on the parent, put in the root level */
381
- } else {
382
- $comments[ $d->id ] = $d;
383
- $ref[ $d->id ] =& $comments[ $d->id ];
384
- }
385
  }
386
  wp_cache_set( 'bp_activity_comments_' . $activity_id, $comments, 'bp' );
387
  }
@@ -392,23 +417,24 @@ Class BP_Activity_Activity {
392
  function rebuild_activity_comment_tree( $parent_id, $left = 1 ) {
393
  global $wpdb, $bp;
394
 
395
- /* The right value of this node is the left value + 1 */
396
  $right = $left + 1;
397
 
398
- /* Get all descendants of this node */
399
  $descendants = BP_Activity_Activity::get_child_comments( $parent_id );
400
 
401
- /* Loop the descendants and recalculate the left and right values */
402
  foreach ( (array)$descendants as $descendant )
403
  $right = BP_Activity_Activity::rebuild_activity_comment_tree( $descendant->id, $right );
404
 
405
- /* We've got the left value, and now that we've processed the children of this node we also know the right value */
 
406
  if ( 1 == $left )
407
  $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE id = %d", $left, $right, $parent_id ) );
408
  else
409
  $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE type = 'activity_comment' AND id = %d", $left, $right, $parent_id ) );
410
 
411
- /* Return the right value of this node + 1 */
412
  return $right + 1;
413
  }
414
 
@@ -429,7 +455,7 @@ Class BP_Activity_Activity {
429
 
430
  $activities = bp_activity_get_sitewide( array( 'max' => $limit ) );
431
 
432
- for ( $i = 0; $i < count($activities); $i++ ) {
433
  $title = explode( '<span', $activities[$i]['content'] );
434
 
435
  $activity_feed[$i]['title'] = trim( strip_tags( $title[0] ) );
@@ -441,85 +467,61 @@ Class BP_Activity_Activity {
441
  return $activity_feed;
442
  }
443
 
444
- function get_filter_sql( $filter_array ) {
445
  global $wpdb;
446
 
447
- if ( !empty( $filter_array['user_id'] ) ) {
448
- $user_filter = explode( ',', $filter_array['user_id'] );
449
- $user_sql = ' ( a.user_id IN ( ' . $filter_array['user_id'] . ' ) )';
450
- $filter_sql[] = $user_sql;
451
- }
452
-
453
- if ( !empty( $filter_array['object'] ) ) {
454
- $object_filter = explode( ',', $filter_array['object'] );
455
- $object_sql = ' ( ';
456
-
457
- $counter = 1;
458
- foreach( (array) $object_filter as $object ) {
459
- $object_sql .= $wpdb->prepare( "a.component = %s", trim( $object ) );
460
-
461
- if ( $counter != count( $object_filter ) )
462
- $object_sql .= ' || ';
463
 
464
- $counter++;
465
- }
466
 
467
- $object_sql .= ' )';
468
- $filter_sql[] = $object_sql;
 
 
 
 
469
  }
470
 
471
- if ( !empty( $filter_array['action'] ) ) {
472
- $action_filter = explode( ',', $filter_array['action'] );
473
- $action_sql = ' ( ';
 
 
 
474
 
475
- $counter = 1;
476
- foreach( (array) $action_filter as $action ) {
477
- $action_sql .= $wpdb->prepare( "a.type = %s", trim( $action ) );
478
 
479
- if ( $counter != count( $action_filter ) )
480
- $action_sql .= ' || ';
 
 
 
481
 
482
- $counter++;
483
- }
 
 
 
484
 
485
- $action_sql .= ' )';
486
- $filter_sql[] = $action_sql;
 
 
487
  }
488
 
489
  if ( !empty( $filter_array['primary_id'] ) ) {
490
- $pid_filter = explode( ',', $filter_array['primary_id'] );
491
- $pid_sql = ' ( ';
492
-
493
- $counter = 1;
494
- foreach( (array) $pid_filter as $pid ) {
495
- $pid_sql .= $wpdb->prepare( "a.item_id = %s", trim( $pid ) );
496
-
497
- if ( $counter != count( $pid_filter ) )
498
- $pid_sql .= ' || ';
499
-
500
- $counter++;
501
- }
502
-
503
- $pid_sql .= ' )';
504
- $filter_sql[] = $pid_sql;
505
  }
506
 
507
  if ( !empty( $filter_array['secondary_id'] ) ) {
508
- $sid_filter = explode( ',', $filter_array['secondary_id'] );
509
- $sid_sql = ' ( ';
510
-
511
- $counter = 1;
512
- foreach( (array) $sid_filter as $sid ) {
513
- $sid_sql .= $wpdb->prepare( "a.secondary_item_id = %s", trim( $sid ) );
514
-
515
- if ( $counter != count( $sid_filter ) )
516
- $sid_sql .= ' || ';
517
-
518
- $counter++;
519
- }
520
-
521
- $sid_sql .= ' )';
522
- $filter_sql[] = $sid_sql;
523
  }
524
 
525
  if ( empty($filter_sql) )
@@ -535,9 +537,7 @@ Class BP_Activity_Activity {
535
  }
536
 
537
  function total_favorite_count( $user_id ) {
538
- global $bp;
539
-
540
- if ( !$favorite_activity_entries = get_user_meta( $user_id, 'bp_favorite_activities', true ) )
541
  return 0;
542
 
543
  return count( maybe_unserialize( $favorite_activity_entries ) );
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;
22
  var $content;
23
  var $date_recorded;
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();
38
  }
41
  function populate() {
42
  global $wpdb, $bp;
43
 
44
+ if ( $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id = %d", $this->id ) ) ) {
45
+ $this->id = $row->id;
46
+ $this->item_id = $row->item_id;
 
47
  $this->secondary_item_id = $row->secondary_item_id;
48
+ $this->user_id = $row->user_id;
49
+ $this->primary_link = $row->primary_link;
50
+ $this->component = $row->component;
51
+ $this->type = $row->type;
52
+ $this->action = $row->action;
53
+ $this->content = $row->content;
54
+ $this->date_recorded = $row->date_recorded;
55
+ $this->hide_sitewide = $row->hide_sitewide;
56
+ $this->mptt_left = $row->mptt_left;
57
+ $this->mptt_right = $row->mptt_right;
58
  }
59
  }
60
 
61
  function save() {
62
  global $wpdb, $bp, $current_user;
63
 
64
+ $this->id = apply_filters_ref_array( 'bp_activity_id_before_save', array( $this->id, &$this ) );
65
+ $this->item_id = apply_filters_ref_array( 'bp_activity_item_id_before_save', array( $this->item_id, &$this ) );
66
+ $this->secondary_item_id = apply_filters_ref_array( 'bp_activity_secondary_item_id_before_save', array( $this->secondary_item_id, &$this ) );
67
+ $this->user_id = apply_filters_ref_array( 'bp_activity_user_id_before_save', array( $this->user_id, &$this ) );
68
+ $this->primary_link = apply_filters_ref_array( 'bp_activity_primary_link_before_save', array( $this->primary_link, &$this ) );
69
+ $this->component = apply_filters_ref_array( 'bp_activity_component_before_save', array( $this->component, &$this ) );
70
+ $this->type = apply_filters_ref_array( 'bp_activity_type_before_save', array( $this->type, &$this ) );
71
+ $this->action = apply_filters_ref_array( 'bp_activity_action_before_save', array( $this->action, &$this ) );
72
+ $this->content = apply_filters_ref_array( 'bp_activity_content_before_save', array( $this->content, &$this ) );
73
+ $this->date_recorded = apply_filters_ref_array( 'bp_activity_date_recorded_before_save', array( $this->date_recorded, &$this ) );
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 ) );
80
 
81
  if ( !$this->component || !$this->type )
82
  return false;
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
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;
102
  }
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
 
112
  $from_sql = " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID";
113
 
114
+ // Where conditions
115
  $where_conditions = array();
116
 
117
+ // Searching
118
  if ( $search_terms ) {
119
  $search_terms = $wpdb->escape( $search_terms );
120
  $where_conditions['search_sql'] = "a.content LIKE '%%" . like_escape( $search_terms ) . "%%'";
121
  }
122
 
123
+ // Filtering
124
  if ( $filter && $filter_sql = BP_Activity_Activity::get_filter_sql( $filter ) )
125
  $where_conditions['filter_sql'] = $filter_sql;
126
 
127
+ // Sorting
128
  if ( $sort != 'ASC' && $sort != 'DESC' )
129
  $sort = 'DESC';
130
 
131
+ // Hide Hidden Items?
132
  if ( !$show_hidden )
133
  $where_conditions['hidden_sql'] = "a.hide_sitewide = 0";
134
 
135
+ // Exclude specified items
136
+ if ( $exclude )
137
+ $where_conditions['exclude'] = "a.id NOT IN ({$exclude})";
138
+
139
+ // The specific ids to which you want to limit the query
140
+ if ( !empty( $in ) ) {
141
+ if ( is_array( $in ) ) {
142
+ $in = implode ( ',', array_map( 'absint', $in ) );
143
+ } else {
144
+ $in = implode ( ',', array_map( 'absint', explode ( ',', $in ) ) );
145
+ }
146
+
147
+ $where_conditions['in'] = "a.id IN ({$in})";
148
  }
149
 
150
+ // Alter the query based on whether we want to show activity item
151
+ // comments in the stream like normal comments or threaded below
152
+ // the activity.
153
+ if ( false === $display_comments || 'threaded' === $display_comments )
154
+ $where_conditions[] = "a.type != 'activity_comment'";
155
+
156
  $where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
157
 
158
  if ( $per_page && $page ) {
159
  $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page ), intval( $per_page ) );
160
+ $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 ) );
161
+ } else {
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}" ), $select_sql, $from_sql, $where_sql, $sort ) );
163
+ }
164
 
165
+ $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 );
166
 
167
+ $total_activities = $wpdb->get_var( $total_activities_sql );
168
+
169
+ // Get the fullnames of users so we don't have to query in the loop
170
+ if ( bp_is_active( 'xprofile' ) && $activities ) {
171
  foreach ( (array)$activities as $activity ) {
172
  if ( (int)$activity->user_id )
173
  $activity_user_ids[] = $activity->user_id;
191
  }
192
 
193
  if ( $activities && $display_comments )
194
+ $activities = BP_Activity_Activity::append_comments( $activities );
195
 
196
+ // If $max is set, only return up to the max results
197
  if ( !empty( $max ) ) {
198
  if ( (int)$total_activities > (int)$max )
199
  $total_activities = $max;
202
  return array( 'activities' => $activities, 'total' => (int)$total_activities );
203
  }
204
 
205
+ /**
206
+ * In BuddyPress 1.2.x, this was used to retrieve specific activity stream items (for example, on an activity's permalink page).
207
+ * As of 1.5.x, use BP_Activity_Activity::get( ..., $in ) instead.
208
+ *
209
+ * @deprecated 1.5
210
+ * @deprecated Use BP_Activity_Activity::get( ..., $in ) instead.
211
+ * @param mixed $activity_ids Array or comma-separated string of activity IDs to retrieve
212
+ * @param int $max Maximum number of results to return. (Optional; default is no maximum)
213
+ * @param int $page The set of results that the user is viewing. Used in pagination. (Optional; default is 1)
214
+ * @param int $per_page Specifies how many results per page. Used in pagination. (Optional; default is 25)
215
+ * @param string MySQL column sort; ASC or DESC. (Optional; default is DESC)
216
+ * @param bool $display_comments Retrieve an activity item's associated comments or not. (Optional; default is false)
217
+ * @return array
218
+ * @since 1.2
219
+ */
220
+ function get_specific( $activity_ids, $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $display_comments = false ) {
221
+ _deprecated_function( __FUNCTION__, '1.5', 'Use BP_Activity_Activity::get( ..., $in ) instead.' );
222
+ return BP_Activity_Activity::get( $max, $page, $per_page, $sort, false, false, $display_comments, false, false, $activity_ids );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
223
  }
224
 
225
  function get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content, $date_recorded ) {
262
  function delete( $args ) {
263
  global $wpdb, $bp;
264
 
 
 
265
  $defaults = array(
266
+ 'id' => false,
267
+ 'action' => false,
268
+ 'content' => false,
269
+ 'component' => false,
270
+ 'type' => false,
271
+ 'primary_link' => false,
272
+ 'user_id' => false,
273
+ 'item_id' => false,
274
  'secondary_item_id' => false,
275
+ 'date_recorded' => false,
276
+ 'hide_sitewide' => false
277
  );
278
+ $params = wp_parse_args( $args, $defaults );
279
+ extract( $params );
280
 
281
  $where_args = false;
282
 
318
  else
319
  return false;
320
 
321
+ // Fetch the activity IDs so we can delete any comments for this activity item
322
  $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" ) );
323
 
324
  if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} {$where_sql}" ) ) )
359
  function append_comments( $activities ) {
360
  global $bp, $wpdb;
361
 
362
+ $activity_comments = array();
363
+
364
  /* Now fetch the activity comments and parse them into the correct position in the activities array. */
365
  foreach( (array)$activities as $activity ) {
366
  if ( 'activity_comment' != $activity->type && $activity->mptt_left && $activity->mptt_right )
369
 
370
  /* Merge the comments with the activity items */
371
  foreach( (array)$activities as $key => $activity )
372
+ if ( isset( $activity_comments[$activity->id] ) )
373
+ $activities[$key]->children = $activity_comments[$activity->id];
374
 
375
  return $activities;
376
  }
379
  global $wpdb, $bp;
380
 
381
  if ( !$comments = wp_cache_get( 'bp_activity_comments_' . $activity_id ) ) {
382
+ // Select the user's fullname with the query
383
+ if ( bp_is_active( 'xprofile' ) ) {
384
  $fullname_select = ", pd.value as user_fullname";
385
  $fullname_from = ", {$bp->profile->table_name_data} pd ";
386
  $fullname_where = "AND pd.user_id = a.user_id AND pd.field_id = 1";
387
+
388
+ // Prevent debug errors
389
+ } else {
390
+ $fullname_select = $fullname_from = $fullname_where = '';
391
  }
392
 
393
+ // Retrieve all descendants of the $root node
394
+ $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 ) );
395
 
396
+ // Loop descendants and build an assoc array
397
  foreach ( (array)$descendants as $d ) {
398
+ $d->children = array();
399
+
400
+ // If we have a reference on the parent
401
+ if ( isset( $ref[ $d->secondary_item_id ] ) ) {
402
+ $ref[ $d->secondary_item_id ]->children[ $d->id ] = $d;
403
+ $ref[ $d->id ] =& $ref[ $d->secondary_item_id ]->children[ $d->id ];
404
+
405
+ // If we don't have a reference on the parent, put in the root level
406
+ } else {
407
+ $comments[ $d->id ] = $d;
408
+ $ref[ $d->id ] =& $comments[ $d->id ];
409
+ }
410
  }
411
  wp_cache_set( 'bp_activity_comments_' . $activity_id, $comments, 'bp' );
412
  }
417
  function rebuild_activity_comment_tree( $parent_id, $left = 1 ) {
418
  global $wpdb, $bp;
419
 
420
+ // The right value of this node is the left value + 1
421
  $right = $left + 1;
422
 
423
+ // Get all descendants of this node
424
  $descendants = BP_Activity_Activity::get_child_comments( $parent_id );
425
 
426
+ // Loop the descendants and recalculate the left and right values
427
  foreach ( (array)$descendants as $descendant )
428
  $right = BP_Activity_Activity::rebuild_activity_comment_tree( $descendant->id, $right );
429
 
430
+ // We've got the left value, and now that we've processed the children
431
+ // of this node we also know the right value
432
  if ( 1 == $left )
433
  $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE id = %d", $left, $right, $parent_id ) );
434
  else
435
  $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE type = 'activity_comment' AND id = %d", $left, $right, $parent_id ) );
436
 
437
+ // Return the right value of this node + 1
438
  return $right + 1;
439
  }
440
 
455
 
456
  $activities = bp_activity_get_sitewide( array( 'max' => $limit ) );
457
 
458
+ for ( $i = 0, $count = count( $activities ); $i < $count; ++$i ) {
459
  $title = explode( '<span', $activities[$i]['content'] );
460
 
461
  $activity_feed[$i]['title'] = trim( strip_tags( $title[0] ) );
467
  return $activity_feed;
468
  }
469
 
470
+ function get_in_operator_sql( $field, $items ) {
471
  global $wpdb;
472
 
473
+ // split items at the comma
474
+ $items_dirty = explode( ',', $items );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
475
 
476
+ // array of prepared integers or quoted strings
477
+ $items_prepared = array();
478
 
479
+ // clean up and format each item
480
+ foreach ( $items_dirty as $item ) {
481
+ // clean up the string
482
+ $item = trim( $item );
483
+ // pass everything through prepare for security and to safely quote strings
484
+ $items_prepared[] = ( is_numeric( $item ) ) ? $wpdb->prepare( '%d', $item ) : $wpdb->prepare( '%s', $item );
485
  }
486
 
487
+ // build IN operator sql syntax
488
+ if ( count( $items_prepared ) )
489
+ return sprintf( '%s IN ( %s )', trim( $field ), implode( ',', $items_prepared ) );
490
+ else
491
+ return false;
492
+ }
493
 
494
+ function get_filter_sql( $filter_array ) {
495
+ global $wpdb;
 
496
 
497
+ if ( !empty( $filter_array['user_id'] ) ) {
498
+ $user_sql = BP_Activity_Activity::get_in_operator_sql( 'a.user_id', $filter_array['user_id'] );
499
+ if ( !empty( $user_sql ) )
500
+ $filter_sql[] = $user_sql;
501
+ }
502
 
503
+ if ( !empty( $filter_array['object'] ) ) {
504
+ $object_sql = BP_Activity_Activity::get_in_operator_sql( 'a.component', $filter_array['object'] );
505
+ if ( !empty( $object_sql ) )
506
+ $filter_sql[] = $object_sql;
507
+ }
508
 
509
+ if ( !empty( $filter_array['action'] ) ) {
510
+ $action_sql = BP_Activity_Activity::get_in_operator_sql( 'a.type', $filter_array['action'] );
511
+ if ( !empty( $action_sql ) )
512
+ $filter_sql[] = $action_sql;
513
  }
514
 
515
  if ( !empty( $filter_array['primary_id'] ) ) {
516
+ $pid_sql = BP_Activity_Activity::get_in_operator_sql( 'a.item_id', $filter_array['primary_id'] );
517
+ if ( !empty( $pid_sql ) )
518
+ $filter_sql[] = $pid_sql;
 
 
 
 
 
 
 
 
 
 
 
 
519
  }
520
 
521
  if ( !empty( $filter_array['secondary_id'] ) ) {
522
+ $sid_sql = BP_Activity_Activity::get_in_operator_sql( 'a.secondary_item_id', $filter_array['secondary_id'] );
523
+ if ( !empty( $sid_sql ) )
524
+ $filter_sql[] = $sid_sql;
 
 
 
 
 
 
 
 
 
 
 
 
525
  }
526
 
527
  if ( empty($filter_sql) )
537
  }
538
 
539
  function total_favorite_count( $user_id ) {
540
+ if ( !$favorite_activity_entries = bp_get_user_meta( $user_id, 'bp_favorite_activities', true ) )
 
 
541
  return 0;
542
 
543
  return count( maybe_unserialize( $favorite_activity_entries ) );
bp-activity/bp-activity-filters.php CHANGED
@@ -1,6 +1,16 @@
1
  <?php
2
 
3
- /* Apply WordPress defined filters */
 
 
 
 
 
 
 
 
 
 
4
  add_filter( 'bp_get_activity_action', 'bp_activity_filter_kses', 1 );
5
  add_filter( 'bp_get_activity_content_body', 'bp_activity_filter_kses', 1 );
6
  add_filter( 'bp_get_activity_content', 'bp_activity_filter_kses', 1 );
@@ -46,13 +56,13 @@ add_filter( 'bp_get_activity_content_body', 'wpautop' );
46
  add_filter( 'bp_get_activity_content', 'wpautop' );
47
  add_filter( 'bp_get_activity_feed_item_description', 'wpautop' );
48
 
49
- add_filter( 'bp_get_activity_action', 'make_clickable' );
50
- add_filter( 'bp_get_activity_content_body', 'make_clickable' );
51
- add_filter( 'bp_get_activity_content', 'make_clickable' );
52
- add_filter( 'bp_get_activity_parent_content', 'make_clickable' );
53
- add_filter( 'bp_get_activity_latest_update', 'make_clickable' );
54
- add_filter( 'bp_get_activity_latest_update_excerpt', 'make_clickable' );
55
- add_filter( 'bp_get_activity_feed_item_description', 'make_clickable' );
56
 
57
  add_filter( 'bp_acomment_name', 'stripslashes_deep' );
58
  add_filter( 'bp_get_activity_action', 'stripslashes_deep' );
@@ -63,7 +73,7 @@ add_filter( 'bp_get_activity_latest_update', 'stripslashes_deep' );
63
  add_filter( 'bp_get_activity_latest_update_excerpt', 'stripslashes_deep' );
64
  add_filter( 'bp_get_activity_feed_item_description', 'stripslashes_deep' );
65
 
66
- /* Apply BuddyPress defined filters */
67
  add_filter( 'bp_get_activity_content', 'bp_activity_make_nofollow_filter' );
68
  add_filter( 'bp_get_activity_content_body', 'bp_activity_make_nofollow_filter' );
69
  add_filter( 'bp_get_activity_parent_content', 'bp_activity_make_nofollow_filter' );
@@ -71,12 +81,24 @@ add_filter( 'bp_get_activity_latest_update', 'bp_activity_make_nofollow_
71
  add_filter( 'bp_get_activity_latest_update_excerpt', 'bp_activity_make_nofollow_filter' );
72
  add_filter( 'bp_get_activity_feed_item_description', 'bp_activity_make_nofollow_filter' );
73
 
74
- add_filter( 'bp_get_activity_parent_content', 'bp_create_excerpt' );
 
 
75
 
76
- /* Allow shortcodes in activity posts */
77
- add_filter( 'bp_get_activity_content', 'do_shortcode' );
78
- add_filter( 'bp_get_activity_content_body', 'do_shortcode' );
79
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  function bp_activity_filter_kses( $content ) {
81
  global $allowedtags;
82
 
@@ -87,6 +109,8 @@ function bp_activity_filter_kses( $content ) {
87
  $activity_allowedtags['div']['class'] = array();
88
  $activity_allowedtags['div']['id'] = array();
89
  $activity_allowedtags['a']['class'] = array();
 
 
90
  $activity_allowedtags['img'] = array();
91
  $activity_allowedtags['img']['src'] = array();
92
  $activity_allowedtags['img']['alt'] = array();
@@ -102,43 +126,143 @@ function bp_activity_filter_kses( $content ) {
102
  return wp_kses( $content, $activity_allowedtags );
103
  }
104
 
105
- function bp_activity_at_name_filter( $content ) {
106
- include_once( ABSPATH . WPINC . '/registration.php' );
107
-
108
- $pattern = '/[@]+([A-Za-z0-9-_\.]+)/';
109
- preg_match_all( $pattern, $content, $usernames );
110
-
111
- // Make sure there's only one instance of each username
112
- if ( !$usernames = array_unique( $usernames[1] ) )
113
- return $content;
 
 
 
 
 
 
 
 
 
 
114
 
115
  foreach( (array)$usernames as $username ) {
116
- if ( !$user_id = username_exists( $username ) )
 
 
 
 
 
117
  continue;
118
 
119
- // Increase the number of new @ mentions for the user
120
- $new_mention_count = (int)get_user_meta( $user_id, 'bp_new_mention_count', true );
121
- update_user_meta( $user_id, 'bp_new_mention_count', $new_mention_count + 1 );
 
122
 
123
- $content = str_replace( "@$username", "<a href='" . bp_core_get_user_domain( bp_core_get_userid( $username ) ) . "' rel='nofollow'>@$username</a>", $content );
124
  }
125
 
 
 
 
 
126
  return $content;
127
  }
128
- add_filter( 'bp_activity_new_update_content', 'bp_activity_at_name_filter' );
129
- add_filter( 'groups_activity_new_update_content', 'bp_activity_at_name_filter' );
130
- add_filter( 'pre_comment_content', 'bp_activity_at_name_filter' );
131
- add_filter( 'group_forum_topic_text_before_save', 'bp_activity_at_name_filter' );
132
- add_filter( 'group_forum_post_text_before_save', 'bp_activity_at_name_filter' );
133
- add_filter( 'bp_activity_comment_content', 'bp_activity_at_name_filter' );
134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  function bp_activity_make_nofollow_filter( $text ) {
136
  return preg_replace_callback( '|<a (.+?)>|i', 'bp_activity_make_nofollow_filter_callback', $text );
137
  }
 
 
 
 
 
 
 
 
 
 
138
  function bp_activity_make_nofollow_filter_callback( $matches ) {
139
  $text = $matches[1];
140
  $text = str_replace( array( ' rel="nofollow"', " rel='nofollow'"), '', $text );
141
  return "<a $text rel=\"nofollow\">";
142
  }
143
 
144
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
 
3
+ /**
4
+ * The Activity filters
5
+ *
6
+ * @package BuddyPress
7
+ * @subpackage ActivityFilters
8
+ */
9
+
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 );
16
  add_filter( 'bp_get_activity_content', 'bp_activity_filter_kses', 1 );
56
  add_filter( 'bp_get_activity_content', 'wpautop' );
57
  add_filter( 'bp_get_activity_feed_item_description', 'wpautop' );
58
 
59
+ add_filter( 'bp_get_activity_action', 'make_clickable', 9 );
60
+ add_filter( 'bp_get_activity_content_body', 'make_clickable', 9 );
61
+ add_filter( 'bp_get_activity_content', 'make_clickable', 9 );
62
+ add_filter( 'bp_get_activity_parent_content', 'make_clickable', 9 );
63
+ add_filter( 'bp_get_activity_latest_update', 'make_clickable', 9 );
64
+ add_filter( 'bp_get_activity_latest_update_excerpt', 'make_clickable', 9 );
65
+ add_filter( 'bp_get_activity_feed_item_description', 'make_clickable', 9 );
66
 
67
  add_filter( 'bp_acomment_name', 'stripslashes_deep' );
68
  add_filter( 'bp_get_activity_action', 'stripslashes_deep' );
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' );
79
  add_filter( 'bp_get_activity_parent_content', 'bp_activity_make_nofollow_filter' );
81
  add_filter( 'bp_get_activity_latest_update_excerpt', 'bp_activity_make_nofollow_filter' );
82
  add_filter( 'bp_get_activity_feed_item_description', 'bp_activity_make_nofollow_filter' );
83
 
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
+ *
97
+ * @uses apply_filters() To call the 'bp_activity_allowed_tags' hook.
98
+ * @uses wp_kses()
99
+ *
100
+ * @return string $content Filtered activity content
101
+ */
102
  function bp_activity_filter_kses( $content ) {
103
  global $allowedtags;
104
 
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();
114
  $activity_allowedtags['img'] = array();
115
  $activity_allowedtags['img']['src'] = array();
116
  $activity_allowedtags['img']['alt'] = array();
126
  return wp_kses( $content, $activity_allowedtags );
127
  }
128
 
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
136
+ *
137
+ * @uses bp_activity_find_mentions()
138
+ * @uses bp_is_username_compatibility_mode()
139
+ * @uses bp_core_get_userid_from_nicename()
140
+ * @uses bp_activity_at_message_notification()
141
+ * @uses bp_core_get_user_domain()
142
+ * @uses bp_activity_adjust_mention_count()
143
+ *
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
153
+ $user_id = bp_core_get_userid_from_nicename( $username );
154
+
155
+ if ( empty( $user_id ) )
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
 
163
+ $content = preg_replace( '/(@' . $username . '\b)/', "<a href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $content );
164
  }
165
 
166
+ // Adjust the activity count for this item
167
+ if ( $activity_id )
168
+ bp_activity_adjust_mention_count( $activity_id, 'add' );
169
+
170
  return $content;
171
  }
 
 
 
 
 
 
172
 
173
+ /**
174
+ * Catch mentions in saved activity items
175
+ *
176
+ * @since 1.5.0
177
+ *
178
+ * @param obj $activity
179
+ *
180
+ * @uses remove_filter() To remove the 'bp_activity_at_name_filter_updates' hook.
181
+ * @uses bp_activity_at_name_filter()
182
+ * @uses BP_Activity_Activity::save() {@link BP_Activity_Activity}
183
+ */
184
+ function bp_activity_at_name_filter_updates( $activity ) {
185
+ // Only run this function once for a given activity item
186
+ remove_filter( 'bp_activity_after_save', 'bp_activity_at_name_filter_updates' );
187
+
188
+ // Run the content through the linking filter, making sure to increment mention count
189
+ $activity->content = bp_activity_at_name_filter( $activity->content, $activity->id );
190
+
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
+ *
203
+ * @return string $text Text with rel=nofollow added to any links
204
+ */
205
  function bp_activity_make_nofollow_filter( $text ) {
206
  return preg_replace_callback( '|<a (.+?)>|i', 'bp_activity_make_nofollow_filter_callback', $text );
207
  }
208
+
209
+ /**
210
+ * Adds rel=nofollow to a link
211
+ *
212
+ * @since 1.2.0
213
+ *
214
+ * @param array $matches
215
+ *
216
+ * @return string $text Link with rel=nofollow added
217
+ */
218
  function bp_activity_make_nofollow_filter_callback( $matches ) {
219
  $text = $matches[1];
220
  $text = str_replace( array( ' rel="nofollow"', " rel='nofollow'"), '', $text );
221
  return "<a $text rel=\"nofollow\">";
222
  }
223
 
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
+ *
231
+ * @uses bp_is_single_activity()
232
+ * @uses apply_filters() To call the 'bp_activity_excerpt_append_text' hook
233
+ * @uses apply_filters() To call the 'bp_activity_excerpt_length' hook
234
+ * @uses bp_create_excerpt()
235
+ * @uses bp_get_activity_id()
236
+ * @uses bp_get_activity_thread_permalink()
237
+ * @uses apply_filters() To call the 'bp_activity_truncate_entry' hook
238
+ *
239
+ * @return string $excerpt The truncated text
240
+ */
241
+ function bp_activity_truncate_entry( $text ) {
242
+ global $activities_template;
243
+
244
+ // The full text of the activity update should always show on the single activity screen
245
+ if ( bp_is_single_activity() )
246
+ return $text;
247
+
248
+ $append_text = apply_filters( 'bp_activity_excerpt_append_text', __( '[Read more]', 'buddypress' ) );
249
+ $excerpt_length = apply_filters( 'bp_activity_excerpt_length', 358 );
250
+
251
+ // Run the text through the excerpt function. If it's too short, the original text will be
252
+ // returned.
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 );
261
+ }
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 ADDED
@@ -0,0 +1,1437 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * BuddyPress Activity Functions
5
+ *
6
+ * Functions for the Activity Streams component
7
+ *
8
+ * @package BuddyPress
9
+ * @subpackage ActivityFunctions
10
+ */
11
+
12
+ // Exit if accessed directly
13
+ if ( !defined( 'ABSPATH' ) ) exit;
14
+
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
+ *
22
+ * @return bool True if set, False if empty
23
+ */
24
+ function bp_activity_has_directory() {
25
+ global $bp;
26
+
27
+ return (bool) !empty( $bp->pages->activity->id );
28
+ }
29
+
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
44
+ if ( !$usernames = array_unique( $usernames[1] ) )
45
+ return false;
46
+
47
+ return $usernames;
48
+ }
49
+
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()
57
+ */
58
+ function bp_activity_clear_new_mentions( $user_id ) {
59
+ bp_delete_user_meta( $user_id, 'bp_new_mention_count' );
60
+ bp_delete_user_meta( $user_id, 'bp_new_mentions' );
61
+ }
62
+
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'
70
+ *
71
+ * @uses BP_Activity_Activity() {@link BP_Activity_Activity}
72
+ * @uses bp_activity_find_mentions()
73
+ * @uses bp_is_username_compatibility_mode()
74
+ * @uses bp_core_get_userid_from_nicename()
75
+ * @uses bp_get_user_meta()
76
+ * @uses bp_update_user_meta()
77
+ */
78
+ 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
86
+ $user_id = bp_core_get_userid_from_nicename( $username );
87
+
88
+ if ( empty( $user_id ) )
89
+ continue;
90
+
91
+ // Adjust the mention list and count for the member
92
+ $new_mention_count = (int)bp_get_user_meta( $user_id, 'bp_new_mention_count', true );
93
+ if ( !$new_mentions = bp_get_user_meta( $user_id, 'bp_new_mentions', true ) )
94
+ $new_mentions = array();
95
+
96
+ switch ( $action ) {
97
+ case 'delete' :
98
+ $key = array_search( $activity_id, $new_mentions );
99
+ if ( $key !== false ) {
100
+ unset( $new_mentions[$key] );
101
+ }
102
+ break;
103
+
104
+ case 'add' :
105
+ default :
106
+ if ( !in_array( $activity_id, $new_mentions ) ) {
107
+ $new_mentions[] = (int)$activity_id;
108
+ }
109
+ break;
110
+ }
111
+
112
+ // Get an updated mention count
113
+ $new_mention_count = count( $new_mentions );
114
+
115
+ // Resave the user_meta
116
+ bp_update_user_meta( $user_id, 'bp_new_mention_count', $new_mention_count );
117
+ bp_update_user_meta( $user_id, 'bp_new_mentions', $new_mentions );
118
+ }
119
+ }
120
+ }
121
+
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
129
+ * @param int $secondary_item_id In the case of at-mentions, this is the mentioner's 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()
137
+ * @uses apply_filters() To call the 'bp_activity_multiple_at_mentions_notification' hook
138
+ * @uses apply_filters() To call the 'bp_activity_single_at_mentions_notification' hook
139
+ * @uses do_action() To call 'activity_format_notifications' hook
140
+ *
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 );
174
+
175
+ return $return;
176
+ }
177
+
178
+ /** Actions ******************************************************************/
179
+
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
187
+ * @param string $value
188
+ *
189
+ * @global object $bp BuddyPress global settings
190
+ * @uses apply_filters() To call the 'bp_activity_set_action' hook
191
+ *
192
+ * @return bool False if any param is empty, otherwise true
193
+ */
194
+ function bp_activity_set_action( $component_id, $key, $value ) {
195
+ global $bp;
196
+
197
+ // Return false if any of the above values are not set
198
+ if ( empty( $component_id ) || empty( $key ) || empty( $value ) )
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
205
+ ), $component_id, $key, $value );
206
+
207
+ return true;
208
+ }
209
+
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
217
+ *
218
+ * @global object $bp BuddyPress global settings
219
+ * @uses apply_filters() To call the 'bp_activity_get_action' hook
220
+ *
221
+ * @return mixed False on error, action on success
222
+ */
223
+ function bp_activity_get_action( $component_id, $key ) {
224
+ global $bp;
225
+
226
+ // Return false if any of the above values are not set
227
+ if ( empty( $component_id ) || empty( $key ) )
228
+ return false;
229
+
230
+ return apply_filters( 'bp_activity_get_action', $bp->activity->actions->{$component_id}->{$key}, $component_id, $key );
231
+ }
232
+
233
+ /** Favorites ****************************************************************/
234
+
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 );
257
+
258
+ return apply_filters( 'bp_activity_get_user_favorites', $favs );
259
+ }
260
+
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()
273
+ * @uses bp_update_user_meta()
274
+ * @uses bp_activity_update_meta()
275
+ * @uses do_action() To call the 'bp_activity_add_user_favorite' hook
276
+ * @uses do_action() To call the 'bp_activity_add_user_favorite_fail' hook
277
+ *
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() )
285
+ return false;
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 ) ) {
304
+
305
+ // Execute additional code
306
+ do_action( 'bp_activity_add_user_favorite', $activity_id, $user_id );
307
+
308
+ // Success
309
+ return true;
310
+
311
+ // Saving meta was unsuccessful for an unknown reason
312
+ } else {
313
+ // Execute additional code
314
+ do_action( 'bp_activity_add_user_favorite_fail', $activity_id, $user_id );
315
+
316
+ return false;
317
+ }
318
+ }
319
+
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()
332
+ * @uses bp_activity_update_meta()
333
+ * @uses bp_update_user_meta()
334
+ * @uses do_action() To call the 'bp_activity_remove_user_favorite' hook
335
+ *
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() )
343
+ return false;
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 );
351
+ $my_favs = array_flip( (array) $my_favs );
352
+ unset( $my_favs[$activity_id] );
353
+ $my_favs = array_unique( array_flip( $my_favs ) );
354
+
355
+ // Update the total number of users who have favorited this activity
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 ) ) {
363
+
364
+ // Execute additional code
365
+ do_action( 'bp_activity_remove_user_favorite', $activity_id, $user_id );
366
+
367
+ // Success
368
+ return true;
369
+
370
+ // Error updating
371
+ } else {
372
+ return false;
373
+ }
374
+
375
+ // Error updating favorite count
376
+ } else {
377
+ return false;
378
+ }
379
+
380
+ // Error getting favorite count
381
+ } else {
382
+ return false;
383
+ }
384
+ }
385
+
386
+ /**
387
+ * Check if activity exists by scanning content
388
+ *
389
+ * @since 1.1.0
390
+ *
391
+ * @param string $content
392
+ *
393
+ * @uses BP_Activity_Activity::check_exists_by_content() {@link BP_Activity_Activity}
394
+ * @uses apply_filters() To call the 'bp_activity_check_exists_by_content' hook
395
+ *
396
+ * @return bool
397
+ */
398
+ function bp_activity_check_exists_by_content( $content ) {
399
+ return apply_filters( 'bp_activity_check_exists_by_content', BP_Activity_Activity::check_exists_by_content( $content ) );
400
+ }
401
+
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
409
+ *
410
+ * @return string Date last updated
411
+ */
412
+ function bp_activity_get_last_updated() {
413
+ return apply_filters( 'bp_activity_get_last_updated', BP_Activity_Activity::get_last_updated() );
414
+ }
415
+
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
+ }
437
+
438
+ /** Meta *********************************************************************/
439
+
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
447
+ * @param string $meta_value
448
+ *
449
+ * @global object $wpdb
450
+ * @global object $bp BuddyPress global settings
451
+ * @uses wp_cache_delete()
452
+ * @uses is_wp_error()
453
+ *
454
+ * @return bool True on success, false on failure
455
+ */
456
+ function bp_activity_delete_meta( $activity_id, $meta_key = '', $meta_value = '' ) {
457
+ global $wpdb, $bp;
458
+
459
+ // Return false if any of the above values are not set
460
+ if ( !is_numeric( $activity_id ) )
461
+ return false;
462
+
463
+ // Sanitize key
464
+ $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
465
+
466
+ if ( is_array( $meta_value ) || is_object( $meta_value ) )
467
+ $meta_value = serialize( $meta_value );
468
+
469
+ // Trim off whitespace
470
+ $meta_value = trim( $meta_value );
471
+
472
+ // Delete all for activity_id
473
+ if ( empty( $meta_key ) )
474
+ $retval = $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d", $activity_id ) );
475
+
476
+ // Delete only when all match
477
+ else if ( $meta_value )
478
+ $retval = $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s AND meta_value = %s", $activity_id, $meta_key, $meta_value ) );
479
+
480
+ // Delete only when activity_id and meta_key match
481
+ else
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 ) )
489
+ return true;
490
+
491
+ // Fail
492
+ else
493
+ return false;
494
+ }
495
+
496
+ /**
497
+ * Get activity meta
498
+ *
499
+ * @since 1.2.0
500
+ *
501
+ * @param int $activity_id
502
+ * @param string $meta_key
503
+ *
504
+ * @global object $wpdb
505
+ * @global object $bp BuddyPress global settings
506
+ * @uses wp_cache_get()
507
+ * @uses wp_cache_set()
508
+ * @uses apply_filters() To call the 'bp_activity_get_meta' hook
509
+ *
510
+ * @return bool
511
+ */
512
+ function bp_activity_get_meta( $activity_id = 0, $meta_key = '' ) {
513
+ global $wpdb, $bp;
514
+
515
+ // Make sure activity_id is valid
516
+ if ( empty( $activity_id ) || !is_numeric( $activity_id ) )
517
+ return false;
518
+
519
+ // We have a key to look for
520
+ if ( !empty( $meta_key ) ) {
521
+
522
+ // Sanitize 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 );
549
+
550
+ // Filter result before returning
551
+ return apply_filters( 'bp_activity_get_meta', $retval, $activity_id, $meta_key );
552
+ }
553
+
554
+ /**
555
+ * Update activity meta
556
+ *
557
+ * @since 1.2.0
558
+ *
559
+ * @param int $activity_id
560
+ * @param string $meta_key
561
+ * @param string $meta_value
562
+ *
563
+ * @global object $wpdb
564
+ * @global object $bp BuddyPress global settings
565
+ * @uses maybe_serialize()
566
+ * @uses bp_activity_delete_meta()
567
+ * @uses wp_cache_set()
568
+ *
569
+ * @return bool True on success, false on failure
570
+ */
571
+ function bp_activity_update_meta( $activity_id, $meta_key, $meta_value ) {
572
+ global $wpdb, $bp;
573
+
574
+ // Make sure activity_id is valid
575
+ if ( !is_numeric( $activity_id ) )
576
+ return false;
577
+
578
+ // Sanitize key
579
+ $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
580
+
581
+ // Sanitize value
582
+ if ( is_string( $meta_value ) )
583
+ $meta_value = stripslashes( $wpdb->escape( $meta_value ) );
584
+
585
+ // Maybe, just maybe... serialize
586
+ $meta_value = maybe_serialize( $meta_value );
587
+
588
+ // If value is empty, delete the meta key
589
+ if ( empty( $meta_value ) )
590
+ return bp_activity_delete_meta( $activity_id, $meta_key );
591
+
592
+ // See if meta key exists for activity_id
593
+ $cur = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s", $activity_id, $meta_key ) );
594
+
595
+ // Meta key does not exist so INSERT
596
+ if ( empty( $cur ) )
597
+ $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->activity->table_name_meta} ( activity_id, meta_key, meta_value ) VALUES ( %d, %s, %s )", $activity_id, $meta_key, $meta_value ) );
598
+
599
+ // Meta key exists, so UPDATE
600
+ else if ( $cur->meta_value != $meta_value )
601
+ $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name_meta} SET meta_value = %s WHERE activity_id = %d AND meta_key = %s", $meta_value, $activity_id, $meta_key ) );
602
+
603
+ // Weirdness, so return false
604
+ else
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;
612
+ }
613
+
614
+ /** Clean up *****************************************************************/
615
+
616
+ /**
617
+ * Completely remove a user's activity data
618
+ *
619
+ * @since 1.5.0
620
+ *
621
+ * @param int $user_id
622
+ *
623
+ * @uses is_user_logged_in()
624
+ * @uses bp_activity_delete()
625
+ * @uses bp_delete_user_meta()
626
+ * @uses do_action() To call the 'bp_activity_remove_data' hook
627
+ * @uses do_action() To call the 'bp_activity_remove_all_user_data' hook
628
+ */
629
+ function bp_activity_remove_all_user_data( $user_id = 0 ) {
630
+
631
+ // Do not delete user data unless a logged in user says so
632
+ if ( empty( $user_id ) || !is_user_logged_in() )
633
+ return false;
634
+
635
+ // Clear the user's activity from the sitewide stream and clear their activity tables
636
+ bp_activity_delete( array( 'user_id' => $user_id ) );
637
+
638
+ // Remove any usermeta
639
+ bp_delete_user_meta( $user_id, 'bp_latest_update' );
640
+ bp_delete_user_meta( $user_id, 'bp_favorite_activities' );
641
+
642
+ // Execute additional code
643
+ do_action( 'bp_activity_remove_data', $user_id ); // Deprecated! Do not use!
644
+
645
+ // Use this going forward
646
+ do_action( 'bp_activity_remove_all_user_data', $user_id );
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
672
+ * handle the actual saving or manipulation of information. Usually they will
673
+ * hand off to a database class for data access, then return
674
+ * true or false on success or failure.
675
+ */
676
+
677
+ /**
678
+ * Retrieve an activity or activities
679
+ *
680
+ * @since 1.2.0
681
+ *
682
+ * @param array $args
683
+ *
684
+ * @uses wp_parse_args()
685
+ * @uses wp_cache_get()
686
+ * @uses wp_cache_set()
687
+ * @uses BP_Activity_Activity::get() {@link BP_Activity_Activity}
688
+ * @uses apply_filters_ref_array() To call the 'bp_activity_get' hook
689
+ *
690
+ * @return object $activity The activity/activities object
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:
707
+ * array(
708
+ * 'user_id' => false, // user_id to filter on
709
+ * 'object' => false, // object to filter on e.g. groups, profile, status, friends
710
+ * 'action' => false, // action to filter on e.g. activity_update, profile_updated
711
+ * 'primary_id' => false, // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
712
+ * 'secondary_id' => false, // secondary object ID to filter on e.g. a post_id
713
+ * );
714
+ */
715
+ 'filter' => array()
716
+ );
717
+ $r = wp_parse_args( $args, $defaults );
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
+ }
731
+
732
+ /**
733
+ * Fetch specific activity items
734
+ *
735
+ * @since 1.2.0
736
+ *
737
+ * @param array $args See docs for $defaults for details
738
+ *
739
+ * @uses wp_parse_args()
740
+ * @uses apply_filters() To call the 'bp_activity_get_specific' hook
741
+ * @uses BP_Activity_Activity::get() {@link BP_Activity_Activity}
742
+ *
743
+ * @return array The array returned by BP_Activity_Activity::get()
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}
772
+ * @uses wp_cache_delete()
773
+ * @uses do_action() To call the 'bp_activity_add' hook
774
+ *
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.
782
+
783
+ 'action' => '', // The activity action - e.g. "Jon Doe posted an update"
784
+ 'content' => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!"
785
+
786
+ 'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent
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 );
798
+
799
+ // Make sure we are backwards compatible
800
+ if ( empty( $component ) && !empty( $component_name ) )
801
+ $component = $component_name;
802
+
803
+ if ( empty( $type ) && !empty( $component_action ) )
804
+ $type = $component_action;
805
+
806
+ // Setup activity to be added
807
+ $activity = new BP_Activity_Activity( $id );
808
+ $activity->user_id = $user_id;
809
+ $activity->component = $component;
810
+ $activity->type = $type;
811
+ $activity->action = $action;
812
+ $activity->content = $content;
813
+ $activity->primary_link = $primary_link;
814
+ $activity->item_id = $item_id;
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;
821
+
822
+ // If this is an activity comment, rebuild the tree
823
+ if ( 'activity_comment' == $activity->type )
824
+ BP_Activity_Activity::rebuild_activity_comment_tree( $activity->item_id );
825
+
826
+ wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
827
+ do_action( 'bp_activity_add', $params );
828
+
829
+ return $activity->id;
830
+ }
831
+
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
846
+ * @uses apply_filters() To call the 'bp_activity_new_update_content' hook
847
+ * @uses apply_filters() To call the 'bp_activity_new_update_primary_link' hook
848
+ * @uses bp_update_user_meta()
849
+ * @uses wp_filter_kses()
850
+ * @uses do_action() To call the 'bp_activity_posted_update' hook
851
+ *
852
+ * @return int $activity_id The activity id
853
+ */
854
+ function bp_activity_post_update( $args = '' ) {
855
+ global $bp;
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 );
863
+
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
871
+ $from_user_link = bp_core_get_userlink( $user_id );
872
+ $activity_action = sprintf( __( '%s posted an update', 'buddypress' ), $from_user_link );
873
+ $activity_content = $content;
874
+ $primary_link = bp_core_get_userlink( $user_id, false, true );
875
+
876
+ // Now write the values
877
+ $activity_id = bp_activity_add( array(
878
+ 'user_id' => $user_id,
879
+ 'action' => apply_filters( 'bp_activity_new_update_action', $activity_action ),
880
+ 'content' => apply_filters( 'bp_activity_new_update_content', $activity_content ),
881
+ 'primary_link' => apply_filters( 'bp_activity_new_update_primary_link', $primary_link ),
882
+ 'component' => $bp->activity->id,
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
+
891
+ return $activity_id;
892
+ }
893
+
894
+ /**
895
+ * Add an activity comment
896
+ *
897
+ * @since 1.2.0
898
+ *
899
+ * @param array $args See docs for $defaults for details
900
+ *
901
+ * @global object $bp BuddyPress global settings
902
+ * @uses wp_parse_args()
903
+ * @uses bp_activity_add()
904
+ * @uses apply_filters() To call the 'bp_activity_comment_action' hook
905
+ * @uses apply_filters() To call the 'bp_activity_comment_content' hook
906
+ * @uses bp_activity_new_comment_notification()
907
+ * @uses wp_cache_delete()
908
+ * @uses do_action() To call the 'bp_activity_comment_posted' hook
909
+ *
910
+ * @return int $comment_id The comment id
911
+ */
912
+ function bp_activity_new_comment( $args = '' ) {
913
+ global $bp;
914
+
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
+ );
922
+
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
950
+ bp_activity_new_comment_notification( $comment_id, $user_id, $params );
951
+
952
+ // Clear the comment cache for this activity
953
+ wp_cache_delete( 'bp_activity_comments_' . $parent_id );
954
+
955
+ do_action( 'bp_activity_comment_posted', $comment_id, $params );
956
+
957
+ return $comment_id;
958
+ }
959
+
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
+ *
967
+ * @uses wp_parse_args()
968
+ * @uses apply_filters() To call the 'bp_activity_get_activity_id' hook
969
+ * @uses BP_Activity_Activity::save() {@link BP_Activity_Activity}
970
+ *
971
+ * @return int $activity_id The activity id
972
+ */
973
+ function bp_activity_get_activity_id( $args = '' ) {
974
+ $defaults = array(
975
+ 'user_id' => false,
976
+ 'component' => false,
977
+ 'type' => false,
978
+ 'item_id' => false,
979
+ 'secondary_item_id' => false,
980
+ 'action' => false,
981
+ 'content' => false,
982
+ 'date_recorded' => false,
983
+ );
984
+
985
+ $r = wp_parse_args( $args, $defaults );
986
+ extract( $r, EXTR_SKIP );
987
+
988
+ return apply_filters( 'bp_activity_get_activity_id', BP_Activity_Activity::get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content, $date_recorded ) );
989
+ }
990
+
991
+ /**
992
+ * Deleting Activity
993
+ *
994
+ * If you're looking to hook into one action that provides the ID(s) of
995
+ * the activity/activities deleted, then use:
996
+ *
997
+ * add_action( 'bp_activity_deleted_activities', 'my_function' );
998
+ *
999
+ * The action passes one parameter that is a single activity ID or an
1000
+ * array of activity IDs depending on the number deleted.
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}
1012
+ * @uses do_action() To call the 'bp_before_activity_delete' hook
1013
+ * @uses bp_get_user_meta()
1014
+ * @uses bp_delete_user_meta()
1015
+ * @uses do_action() To call the 'bp_activity_delete' hook
1016
+ * @uses do_action() To call the 'bp_activity_deleted_activities' hook
1017
+ * @uses wp_cache_delete()
1018
+ *
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(
1026
+ 'id' => false,
1027
+ 'action' => false,
1028
+ 'content' => false,
1029
+ 'component' => false,
1030
+ 'type' => false,
1031
+ 'primary_link' => false,
1032
+ 'user_id' => false,
1033
+ 'item_id' => false,
1034
+ 'secondary_item_id' => false,
1035
+ 'date_recorded' => false,
1036
+ 'hide_sitewide' => false
1037
+ );
1038
+
1039
+ $args = wp_parse_args( $args, $defaults );
1040
+
1041
+ // Adjust the new mention count of any mentioned member
1042
+ bp_activity_adjust_mention_count( $args['id'], 'delete' );
1043
+
1044
+ if ( !$activity_ids_deleted = BP_Activity_Activity::delete( $args ) )
1045
+ return false;
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
+
1053
+ do_action( 'bp_before_activity_delete', $args );
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 );
1062
+ do_action( 'bp_activity_deleted_activities', $activity_ids_deleted );
1063
+
1064
+ wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
1065
+
1066
+ return true;
1067
+ }
1068
+
1069
+ /**
1070
+ * Delete an activity item by activity id
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
+
1092
+ return bp_activity_delete( array( 'item_id' => $item_id, 'component' => $component, 'type' => $type, 'user_id' => $user_id, 'secondary_item_id' => $secondary_item_id ) );
1093
+ }
1094
+
1095
+ /**
1096
+ * Delete an activity item by activity id
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
+ *
1105
+ * @uses bp_activity_delete()
1106
+ *
1107
+ * @return bool True on success, false on failure
1108
+ */
1109
+ function bp_activity_delete_by_activity_id( $activity_id ) {
1110
+ return bp_activity_delete( array( 'id' => $activity_id ) );
1111
+ }
1112
+
1113
+ /**
1114
+ * Delete an activity item by it's content
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
1123
+ * @param string $component The activity component
1124
+ * @param string $type The activity type
1125
+ *
1126
+ * @uses bp_activity_delete()
1127
+ *
1128
+ * @return bool True on success, false on failure
1129
+ */
1130
+ function bp_activity_delete_by_content( $user_id, $content, $component, $type ) {
1131
+ return bp_activity_delete( array( 'user_id' => $user_id, 'content' => $content, 'component' => $component, 'type' => $type ) );
1132
+ }
1133
+
1134
+ /**
1135
+ * Delete a user's activity for a component
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
1144
+ *
1145
+ * @uses bp_activity_delete()
1146
+ *
1147
+ * @return bool True on success, false on failure
1148
+ */
1149
+ function bp_activity_delete_for_user_by_component( $user_id, $component ) {
1150
+ return bp_activity_delete( array( 'user_id' => $user_id, 'component' => $component ) );
1151
+ }
1152
+
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
1160
+ *
1161
+ * @uses apply_filters() To call the 'bp_activity_delete_comment_pre' hook
1162
+ * @uses bp_activity_delete_children()
1163
+ * @uses bp_activity_delete()
1164
+ * @uses BP_Activity_Activity::rebuild_activity_comment_tree() {@link BP_Activity_Activity}
1165
+ * @uses do_action() To call the 'bp_activity_delete_comment' hook
1166
+ *
1167
+ * @return bool True on success, false on failure
1168
+ */
1169
+ function bp_activity_delete_comment( $activity_id, $comment_id ) {
1170
+ /***
1171
+ * You may want to hook into this filter if you want to override this function and
1172
+ * handle the deletion of child comments differently. Make sure you return false.
1173
+ */
1174
+ if ( !apply_filters( 'bp_activity_delete_comment_pre', true, $activity_id, $comment_id ) )
1175
+ return false;
1176
+
1177
+ // Delete any children of this comment.
1178
+ bp_activity_delete_children( $activity_id, $comment_id );
1179
+
1180
+ // Delete the actual comment
1181
+ if ( !bp_activity_delete( array( 'id' => $comment_id, 'type' => 'activity_comment' ) ) )
1182
+ return false;
1183
+
1184
+ // Recalculate the comment tree
1185
+ BP_Activity_Activity::rebuild_activity_comment_tree( $activity_id );
1186
+
1187
+ do_action( 'bp_activity_delete_comment', $activity_id, $comment_id );
1188
+
1189
+ return true;
1190
+ }
1191
+
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
1199
+ *
1200
+ * @uses BP_Activity_Activity::get_child_comments() {@link BP_Activity_Activity}
1201
+ * @uses bp_activity_delete_children()
1202
+ * @uses bp_activity_delete()
1203
+ */
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
+ }
1212
+
1213
+ /**
1214
+ * Get the permalink for a single activity item
1215
+ *
1216
+ * When only the $activity_id param is passed, BP has to instantiate a new BP_Activity_Activity
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
1229
+ *
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 ) );
1252
+ }
1253
+
1254
+ /**
1255
+ * Hide a user's activity
1256
+ *
1257
+ * @since 1.2.0
1258
+ *
1259
+ * @param int $user_id The user id
1260
+ *
1261
+ * @uses BP_Activity_Activity::hide_all_for_user() {@link BP_Activity_Activity}
1262
+ *
1263
+ * @return bool True on success, false on failure
1264
+ */
1265
+ function bp_activity_hide_user_activity( $user_id ) {
1266
+ return BP_Activity_Activity::hide_all_for_user( $user_id );
1267
+ }
1268
+
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
1276
+ *
1277
+ * @uses esc_attr()
1278
+ * @uses apply_filters() To call the 'bp_activity_thumbnail_content_images' hook
1279
+ *
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
+
1312
+ if ( !empty( $link ) ) {
1313
+ $image = '<a href="' . $link . '">' . $image . '</a>';
1314
+ }
1315
+
1316
+ $content = $image . $content;
1317
+ }
1318
+ }
1319
+
1320
+ return apply_filters( 'bp_activity_thumbnail_content_images', $content, $matches );
1321
+ }
1322
+
1323
+ /** Embeds *******************************************************************/
1324
+
1325
+ /**
1326
+ * Grabs the activity update ID and attempts to retrieve the oEmbed cache (if it exists)
1327
+ * during the activity loop. If no cache and link is embeddable, cache it.
1328
+ *
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()
1336
+ * @see bp_embed_activity_save_cache()
1337
+ *
1338
+ * @uses add_filter() To attach 'bp_get_activity_id' to 'embed_post_id'
1339
+ * @uses add_filter() To attach 'bp_embed_activity_cache' to 'bp_embed_get_cache'
1340
+ * @uses add_action() To attach 'bp_embed_activity_save_cache' to 'bp_embed_update_cache'
1341
+ */
1342
+ function bp_activity_embed() {
1343
+ add_filter( 'embed_post_id', 'bp_get_activity_id' );
1344
+ add_filter( 'bp_embed_get_cache', 'bp_embed_activity_cache', 10, 3 );
1345
+ add_action( 'bp_embed_update_cache', 'bp_embed_activity_save_cache', 10, 3 );
1346
+ }
1347
+ add_action( 'activity_loop_start', 'bp_activity_embed' );
1348
+
1349
+ /**
1350
+ * Grabs the activity comment ID and attempts to retrieve the oEmbed cache (if it exists)
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()
1358
+ * @see bp_embed_activity_save_cache()
1359
+ *
1360
+ * @uses add_filter() To attach 'bp_get_activity_comment_id' to 'embed_post_id'
1361
+ * @uses add_filter() To attach 'bp_embed_activity_cache' to 'bp_embed_get_cache'
1362
+ * @uses add_action() To attach 'bp_embed_activity_save_cache' to 'bp_embed_update_cache'
1363
+ */
1364
+ function bp_activity_comment_embed() {
1365
+ add_filter( 'embed_post_id', 'bp_get_activity_comment_id' );
1366
+ add_filter( 'bp_embed_get_cache', 'bp_embed_activity_cache', 10, 3 );
1367
+ add_action( 'bp_embed_update_cache', 'bp_embed_activity_save_cache', 10, 3 );
1368
+ }
1369
+ add_action( 'bp_before_activity_comment', 'bp_activity_comment_embed' );
1370
+
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
+ *
1378
+ * @param object $activity The activity that is being expanded
1379
+ *
1380
+ * @global object $bp BuddyPress global settings
1381
+ * @uses add_filter() To attach create_function() to 'embed_post_id'
1382
+ * @uses add_filter() To attach 'bp_embed_activity_cache' to 'bp_embed_get_cache'
1383
+ * @uses add_action() To attach 'bp_embed_activity_save_cache' to 'bp_embed_update_cache'
1384
+ */
1385
+ function bp_dtheme_embed_read_more( $activity ) {
1386
+ global $bp;
1387
+
1388
+ $bp->activity->read_more_id = $activity->id;
1389
+
1390
+ add_filter( 'embed_post_id', create_function( '', 'global $bp; return $bp->activity->read_more_id;' ) );
1391
+ add_filter( 'bp_embed_get_cache', 'bp_embed_activity_cache', 10, 3 );
1392
+ add_action( 'bp_embed_update_cache', 'bp_embed_activity_save_cache', 10, 3 );
1393
+ }
1394
+ add_action( 'bp_dtheme_get_single_activity_content', 'bp_dtheme_embed_read_more' );
1395
+
1396
+ /**
1397
+ * Removes the 'embed_post_id' filter after {@link bp_activity_recurse_comments()}
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
+ *
1405
+ * @uses remove_filter() To remove 'bp_get_activity_comment_id' from 'embed_post_id'
1406
+ */
1407
+ function bp_activity_comment_embed_after_recurse() {
1408
+ remove_filter( 'embed_post_id', 'bp_get_activity_comment_id' );
1409
+ }
1410
+ add_action( 'bp_after_activity_comment', 'bp_activity_comment_embed_after_recurse' );
1411
+
1412
+ /**
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
+ *
1420
+ * @return mixed The activity meta
1421
+ */
1422
+ function bp_embed_activity_cache( $cache, $id, $cachekey ) {
1423
+ return bp_activity_get_meta( $id, $cachekey );
1424
+ }
1425
+
1426
+ /**
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 ADDED
@@ -0,0 +1,315 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * BuddyPress Activity Streams Loader
5
+ *
6
+ * An activity stream component, for users, groups, and blog tracking.
7
+ *
8
+ * @package BuddyPress
9
+ * @subpackage ActivityCore
10
+ */
11
+
12
+ // Exit if accessed directly
13
+ if ( !defined( 'ABSPATH' ) ) exit;
14
+
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',
34
+ __( 'Activity Streams', 'buddypress' ),
35
+ BP_PLUGIN_DIR
36
+ );
37
+ }
38
+
39
+ /**
40
+ * Include files
41
+ *
42
+ * @since 1.5.0
43
+ */
44
+ function includes() {
45
+ // Files to include
46
+ $includes = array(
47
+ 'actions',
48
+ 'screens',
49
+ 'filters',
50
+ 'classes',
51
+ 'template',
52
+ 'functions',
53
+ 'notifications',
54
+ );
55
+
56
+ parent::includes( $includes );
57
+ }
58
+
59
+ /**
60
+ * Setup globals
61
+ *
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
+ */
69
+ function setup_globals() {
70
+ global $bp;
71
+
72
+ // Define a slug, if necessary
73
+ if ( !defined( 'BP_ACTIVITY_SLUG' ) )
74
+ define( 'BP_ACTIVITY_SLUG', $this->id );
75
+
76
+ // Global tables for activity component
77
+ $global_tables = array(
78
+ 'table_name' => $bp->table_prefix . 'bp_activity',
79
+ 'table_name_meta' => $bp->table_prefix . 'bp_activity_meta',
80
+ );
81
+
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,
89
+ 'search_string' => __( 'Search Activity...', 'buddypress' ),
90
+ 'global_tables' => $global_tables,
91
+ 'notification_callback' => 'bp_activity_format_notifications',
92
+ );
93
+
94
+ parent::setup_globals( $globals );
95
+ }
96
+
97
+ /**
98
+ * Setup BuddyBar navigation
99
+ *
100
+ * @since 1.5.0
101
+ *
102
+ * @global object $bp BuddyPress global settings
103
+ * @uses bp_is_active()
104
+ * @uses is_user_logged_in()
105
+ * @uses bp_get_friends_slug()
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(
113
+ 'name' => __( 'Activity', 'buddypress' ),
114
+ 'slug' => $this->slug,
115
+ 'position' => 10,
116
+ 'screen_function' => 'bp_activity_screen_my_activity',
117
+ 'default_subnav_slug' => 'just-me',
118
+ 'item_css_id' => $this->id
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
+
133
+ // User link
134
+ $activity_link = trailingslashit( $user_domain . $this->slug );
135
+
136
+ // Add the subnav items to the activity nav item if we are using a theme that supports this
137
+ $sub_nav[] = array(
138
+ 'name' => __( 'Personal', 'buddypress' ),
139
+ 'slug' => 'just-me',
140
+ 'parent_url' => $activity_link,
141
+ 'parent_slug' => $this->slug,
142
+ 'screen_function' => 'bp_activity_screen_my_activity',
143
+ 'position' => 10
144
+ );
145
+
146
+ // @ mentions
147
+ $sub_nav[] = array(
148
+ 'name' => __( 'Mentions', 'buddypress' ),
149
+ 'slug' => 'mentions',
150
+ 'parent_url' => $activity_link,
151
+ 'parent_slug' => $this->slug,
152
+ 'screen_function' => 'bp_activity_screen_mentions',
153
+ 'position' => 20,
154
+ 'item_css_id' => 'activity-mentions'
155
+ );
156
+
157
+ // Favorite activity items
158
+ $sub_nav[] = array(
159
+ 'name' => __( 'Favorites', 'buddypress' ),
160
+ 'slug' => 'favorites',
161
+ 'parent_url' => $activity_link,
162
+ 'parent_slug' => $this->slug,
163
+ 'screen_function' => 'bp_activity_screen_favorites',
164
+ 'position' => 30,
165
+ 'item_css_id' => 'activity-favs'
166
+ );
167
+
168
+ // Additional menu if friends is active
169
+ if ( bp_is_active( 'friends' ) ) {
170
+ $sub_nav[] = array(
171
+ 'name' => __( 'Friends', 'buddypress' ),
172
+ 'slug' => bp_get_friends_slug(),
173
+ 'parent_url' => $activity_link,
174
+ 'parent_slug' => $this->slug,
175
+ 'screen_function' => 'bp_activity_screen_friends',
176
+ 'position' => 40,
177
+ 'item_css_id' => 'activity-friends'
178
+ ) ;
179
+ }
180
+
181
+ // Additional menu if groups is active
182
+ if ( bp_is_active( 'groups' ) ) {
183
+ $sub_nav[] = array(
184
+ 'name' => __( 'Groups', 'buddypress' ),
185
+ 'slug' => bp_get_groups_slug(),
186
+ 'parent_url' => $activity_link,
187
+ 'parent_slug' => $this->slug,
188
+ 'screen_function' => 'bp_activity_screen_groups',
189
+ 'position' => 50,
190
+ 'item_css_id' => 'activity-groups'
191
+ );
192
+ }
193
+
194
+ parent::setup_nav( $main_nav, $sub_nav );
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()
204
+ * @uses trailingslashit()
205
+ * @uses bp_get_total_mention_count_for_user()
206
+ * @uses bp_loggedin_user_id()
207
+ * @uses bp_is_active()
208
+ * @uses bp_get_friends_slug()
209
+ * @uses bp_get_groups_slug()
210
+ */
211
+ function setup_admin_bar() {
212
+ global $bp;
213
+
214
+ // Prevent debug notices
215
+ $wp_admin_nav = array();
216
+
217
+ // Menus for logged in user
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
+ }
230
+
231
+ // Add the "Activity" sub menu
232
+ $wp_admin_nav[] = array(
233
+ 'parent' => $bp->my_account_menu_id,
234
+ 'id' => 'my-account-' . $this->id,
235
+ 'title' => __( 'Activity', 'buddypress' ),
236
+ 'href' => trailingslashit( $activity_link )
237
+ );
238
+
239
+ // Mentions
240
+ $wp_admin_nav[] = array(
241
+ 'parent' => 'my-account-' . $this->id,
242
+ 'title' => $title,
243
+ 'href' => trailingslashit( $activity_link . 'mentions' )
244
+ );
245
+
246
+ // Personal
247
+ $wp_admin_nav[] = array(
248
+ 'parent' => 'my-account-' . $this->id,
249
+ 'title' => __( 'Personal', 'buddypress' ),
250
+ 'href' => trailingslashit( $activity_link )
251
+ );
252
+
253
+ // Favorites
254
+ $wp_admin_nav[] = array(
255
+ 'parent' => 'my-account-' . $this->id,
256
+ 'title' => __( 'Favorites', 'buddypress' ),
257
+ 'href' => trailingslashit( $activity_link . 'favorites' )
258
+ );
259
+
260
+ // Friends?
261
+ if ( bp_is_active( 'friends' ) ) {
262
+ $wp_admin_nav[] = array(
263
+ 'parent' => 'my-account-' . $this->id,
264
+ 'title' => __( 'Friends', 'buddypress' ),
265
+ 'href' => trailingslashit( $activity_link . bp_get_friends_slug() )
266
+ );
267
+ }
268
+
269
+ // Groups?
270
+ if ( bp_is_active( 'groups' ) ) {
271
+ $wp_admin_nav[] = array(
272
+ 'parent' => 'my-account-' . $this->id,
273
+ 'title' => __( 'Groups', 'buddypress' ),
274
+ 'href' => trailingslashit( $activity_link . bp_get_groups_slug() )
275
+ );
276
+ }
277
+ }
278
+
279
+ parent::setup_admin_bar( $wp_admin_nav );
280
+ }
281
+
282
+ /**
283
+ * Sets up the title for pages and <title>
284
+ *
285
+ * @since 1.5.0
286
+ *
287
+ * @global object $bp BuddyPress global settings
288
+ * @uses bp_is_activity_component()
289
+ * @uses bp_is_my_profile()
290
+ * @uses bp_core_fetch_avatar()
291
+ */
292
+ function setup_title() {
293
+ global $bp;
294
+
295
+ // Adjust title based on view
296
+ if ( bp_is_activity_component() ) {
297
+ if ( bp_is_my_profile() ) {
298
+ $bp->bp_options_title = __( 'My Activity', 'buddypress' );
299
+ } else {
300
+ $bp->bp_options_avatar = bp_core_fetch_avatar( array(
301
+ 'item_id' => $bp->displayed_user->id,
302
+ 'type' => 'thumb'
303
+ ) );
304
+ $bp->bp_options_title = $bp->displayed_user->fullname;
305
+ }
306
+ }
307
+
308
+ parent::setup_title();
309
+ }
310
+ }
311
+
312
+ // Create the activity component
313
+ $bp->activity = new BP_Activity_Component();
314
+
315
+ ?>
bp-activity/bp-activity-notifications.php CHANGED
@@ -1,59 +1,135 @@
1
  <?php
2
 
3
- function bp_activity_at_message_notification( $content, $poster_user_id, $activity_id ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  global $bp;
5
 
6
- /* Scan for @username strings in an activity update. Notify each user. */
7
- $pattern = '/[@]+([A-Za-z0-9-_\.]+)/';
8
- preg_match_all( $pattern, $content, $usernames );
9
 
10
- /* Make sure there's only one instance of each username */
11
- if ( !$usernames = array_unique( $usernames[1] ) )
12
- return false;
13
 
14
- foreach( (array)$usernames as $username ) {
15
- if ( !$receiver_user_id = bp_core_get_userid( $username ) )
16
- continue;
17
 
18
- // Now email the user with the contents of the message (if they have enabled email notifications)
19
- if ( 'no' != get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) {
20
- $poster_name = bp_core_get_user_displayname( $poster_user_id );
21
 
22
- $message_link = bp_activity_get_permalink( $activity_id );
23
- $settings_link = bp_core_get_user_domain( $receiver_user_id ) . BP_SETTINGS_SLUG . '/notifications/';
24
 
25
- $poster_name = stripslashes( $poster_name );
26
- $content = bp_activity_filter_kses( stripslashes($content) );
27
 
28
- // Set up and send the message
29
- $ud = bp_core_get_core_userdata( $receiver_user_id );
30
- $to = $ud->user_email;
31
- $sitename = wp_specialchars_decode( get_blog_option( BP_ROOT_BLOG, 'blogname' ), ENT_QUOTES );
32
- $subject = '[' . $sitename . '] ' . sprintf( __( '%s mentioned you in an update', 'buddypress' ), $poster_name );
33
 
34
- $message = sprintf( __(
35
- '%s mentioned you in an update:
 
36
 
37
- "%s"
38
 
39
- To view and respond to the message, log in and visit: %s
40
 
41
  ---------------------
42
- ', 'buddypress' ), $poster_name, $content, $message_link );
 
 
 
43
 
44
- $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
45
 
46
- /* Send the message */
47
- $to = apply_filters( 'bp_activity_at_message_notification_to', $to );
48
- $subject = apply_filters( 'bp_activity_at_message_notification_subject', $subject, $poster_name );
49
- $message = apply_filters( 'bp_activity_at_message_notification_message', $message, $poster_name, $content, $message_link );
50
 
51
- wp_mail( $to, $subject, $message );
 
52
  }
 
 
 
 
 
 
 
 
 
53
  }
 
 
54
  }
55
- add_action( 'bp_activity_posted_update', 'bp_activity_at_message_notification', 10, 3 );
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  function bp_activity_new_comment_notification( $comment_id, $commenter_id, $params ) {
58
  global $bp;
59
 
@@ -61,10 +137,10 @@ function bp_activity_new_comment_notification( $comment_id, $commenter_id, $para
61
 
62
  $original_activity = new BP_Activity_Activity( $activity_id );
63
 
64
- if ( $original_activity->user_id != $commenter_id && 'no' != get_user_meta( $original_activity->user_id, 'notification_activity_new_reply', true ) ) {
65
  $poster_name = bp_core_get_user_displayname( $commenter_id );
66
  $thread_link = bp_activity_get_permalink( $activity_id );
67
- $settings_link = bp_core_get_user_domain( $original_activity->user_id ) . BP_SETTINGS_SLUG . '/notifications/';
68
 
69
  $poster_name = stripslashes( $poster_name );
70
  $content = bp_activity_filter_kses( stripslashes($content) );
@@ -72,15 +148,15 @@ function bp_activity_new_comment_notification( $comment_id, $commenter_id, $para
72
  // Set up and send the message
73
  $ud = bp_core_get_core_userdata( $original_activity->user_id );
74
  $to = $ud->user_email;
75
- $sitename = wp_specialchars_decode( get_blog_option( BP_ROOT_BLOG, 'blogname' ), ENT_QUOTES );
76
  $subject = '[' . $sitename . '] ' . sprintf( __( '%s replied to one of your updates', 'buddypress' ), $poster_name );
77
 
78
  $message = sprintf( __(
79
- '%s replied to one of your updates:
80
 
81
- "%s"
82
 
83
- To view your original update and all comments, log in and visit: %s
84
 
85
  ---------------------
86
  ', 'buddypress' ), $poster_name, $content, $thread_link );
@@ -90,9 +166,11 @@ To view your original update and all comments, log in and visit: %s
90
  /* Send the message */
91
  $to = apply_filters( 'bp_activity_new_comment_notification_to', $to );
92
  $subject = apply_filters( 'bp_activity_new_comment_notification_subject', $subject, $poster_name );
93
- $message = apply_filters( 'bp_activity_new_comment_notification_message', $message, $poster_name, $content, $thread_link );
94
 
95
  wp_mail( $to, $subject, $message );
 
 
96
  }
97
 
98
  /***
@@ -104,26 +182,26 @@ To view your original update and all comments, log in and visit: %s
104
 
105
  $parent_comment = new BP_Activity_Activity( $parent_id );
106
 
107
- if ( $parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id && 'no' != get_user_meta( $parent_comment->user_id, 'notification_activity_new_reply', true ) ) {
108
  $poster_name = bp_core_get_user_displayname( $commenter_id );
109
  $thread_link = bp_activity_get_permalink( $activity_id );
110
- $settings_link = bp_core_get_user_domain( $parent_comment->user_id ) . BP_SETTINGS_SLUG . '/notifications/';
111
 
112
  // Set up and send the message
113
  $ud = bp_core_get_core_userdata( $parent_comment->user_id );
114
  $to = $ud->user_email;
115
- $sitename = wp_specialchars_decode( get_blog_option( BP_ROOT_BLOG, 'blogname' ), ENT_QUOTES );
116
  $subject = '[' . $sitename . '] ' . sprintf( __( '%s replied to one of your comments', 'buddypress' ), $poster_name );
117
 
118
  $poster_name = stripslashes( $poster_name );
119
  $content = bp_activity_filter_kses( stripslashes( $content ) );
120
 
121
  $message = sprintf( __(
122
- '%s replied to one of your comments:
123
 
124
- "%s"
125
 
126
- To view the original activity, your comment and all replies, log in and visit: %s
127
 
128
  ---------------------
129
  ', 'buddypress' ), $poster_name, $content, $thread_link );
@@ -133,10 +211,12 @@ To view the original activity, your comment and all replies, log in and visit: %
133
  /* Send the message */
134
  $to = apply_filters( 'bp_activity_new_comment_notification_comment_author_to', $to );
135
  $subject = apply_filters( 'bp_activity_new_comment_notification_comment_author_subject', $subject, $poster_name );
136
- $message = apply_filters( 'bp_activity_new_comment_notification_comment_author_message', $message, $poster_name, $content );
137
 
138
  wp_mail( $to, $subject, $message );
 
 
139
  }
140
  }
141
 
142
- ?>
1
  <?php
2
 
3
+ /**
4
+ * BuddyPress Activity Notifications
5
+ *
6
+ * @package BuddyPress
7
+ * @subpackage ActivityNotifications
8
+ */
9
+
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
+
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()
25
+ * @uses bp_activity_get_permalink()
26
+ * @uses bp_core_get_user_domain()
27
+ * @uses bp_get_settings_slug()
28
+ * @uses bp_activity_filter_kses()
29
+ * @uses bp_core_get_core_userdata()
30
+ * @uses wp_specialchars_decode()
31
+ * @uses get_blog_option()
32
+ * @uses bp_is_active()
33
+ * @uses bp_is_group()
34
+ * @uses bp_get_current_group_name()
35
+ * @uses apply_filters() To call the 'bp_activity_at_message_notification_to' hook
36
+ * @uses apply_filters() To call the 'bp_activity_at_message_notification_subject' hook
37
+ * @uses apply_filters() To call the 'bp_activity_at_message_notification_message' hook
38
+ * @uses wp_mail()
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
 
46
+ $subject = '';
47
+ $message = '';
 
48
 
49
+ // Add the BP notification
50
+ bp_core_add_notification( $activity_id, $receiver_user_id, 'activity', 'new_at_mention', $activity->user_id );
 
51
 
52
+ // Now email the user with the contents of the message (if they have enabled email notifications)
53
+ if ( 'no' != bp_get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) {
54
+ $poster_name = bp_core_get_user_displayname( $activity->user_id );
55
 
56
+ $message_link = bp_activity_get_permalink( $activity_id );
57
+ $settings_link = bp_core_get_user_domain( $receiver_user_id ) . bp_get_settings_slug() . '/notifications/';
58
 
59
+ $poster_name = stripslashes( $poster_name );
60
+ $content = bp_activity_filter_kses( strip_tags( stripslashes( $activity->content ) ) );
61
 
62
+ // Set up and send the message
63
+ $ud = bp_core_get_core_userdata( $receiver_user_id );
64
+ $to = $ud->user_email;
65
+ $sitename = wp_specialchars_decode( get_blog_option( bp_get_root_blog_id(), 'blogname' ), ENT_QUOTES );
66
+ $subject = '[' . $sitename . '] ' . sprintf( __( '%s mentioned you in an update', 'buddypress' ), $poster_name );
67
 
68
+ if ( bp_is_active( 'groups' ) && bp_is_group() ) {
69
+ $message = sprintf( __(
70
+ '%1$s mentioned you in the group "%2$s":
71
 
72
+ "%3$s"
73
 
74
+ To view and respond to the message, log in and visit: %4$s
75
 
76
  ---------------------
77
+ ', 'buddypress' ), $poster_name, bp_get_current_group_name(), $content, $message_link );
78
+ } else {
79
+ $message = sprintf( __(
80
+ '%1$s mentioned you in an update:
81
 
82
+ "%2$s"
83
 
84
+ To view and respond to the message, log in and visit: %3$s
 
 
 
85
 
86
+ ---------------------
87
+ ', 'buddypress' ), $poster_name, $content, $message_link );
88
  }
89
+
90
+ $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
91
+
92
+ /* Send the message */
93
+ $to = apply_filters( 'bp_activity_at_message_notification_to', $to );
94
+ $subject = apply_filters( 'bp_activity_at_message_notification_subject', $subject, $poster_name );
95
+ $message = apply_filters( 'bp_activity_at_message_notification_message', $message, $poster_name, $content, $message_link, $settings_link );
96
+
97
+ wp_mail( $to, $subject, $message );
98
  }
99
+
100
+ do_action( 'bp_activity_sent_mention_email', $activity, $subject, $message, $content );
101
  }
 
102
 
103
+ /**
104
+ * Sends an email notification and a BP notification when someone mentions you in an update
105
+ *
106
+ * @since 1.2.0
107
+ *
108
+ * @param int $comment_id The comment id
109
+ * @param int $commenter_id The unique user_id of the user who posted the comment
110
+ * @param array $params {@link bp_activity_new_comment()}
111
+ *
112
+ * @global object $bp BuddyPress global settings
113
+ * @uses bp_get_user_meta()
114
+ * @uses bp_core_get_user_displayname()
115
+ * @uses bp_activity_get_permalink()
116
+ * @uses bp_core_get_user_domain()
117
+ * @uses bp_get_settings_slug()
118
+ * @uses bp_activity_filter_kses()
119
+ * @uses bp_core_get_core_userdata()
120
+ * @uses wp_specialchars_decode()
121
+ * @uses get_blog_option()
122
+ * @uses bp_get_root_blog_id()
123
+ * @uses apply_filters() To call the 'bp_activity_new_comment_notification_to' hook
124
+ * @uses apply_filters() To call the 'bp_activity_new_comment_notification_subject' hook
125
+ * @uses apply_filters() To call the 'bp_activity_new_comment_notification_message' hook
126
+ * @uses wp_mail()
127
+ * @uses do_action() To call the 'bp_activity_sent_reply_to_update_email' hook
128
+ * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_to' hook
129
+ * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_subject' hook
130
+ * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_message' hook
131
+ * @uses do_action() To call the 'bp_activity_sent_reply_to_reply_email' hook
132
+ */
133
  function bp_activity_new_comment_notification( $comment_id, $commenter_id, $params ) {
134
  global $bp;
135
 
137
 
138
  $original_activity = new BP_Activity_Activity( $activity_id );
139
 
140
+ if ( $original_activity->user_id != $commenter_id && 'no' != bp_get_user_meta( $original_activity->user_id, 'notification_activity_new_reply', true ) ) {
141
  $poster_name = bp_core_get_user_displayname( $commenter_id );
142
  $thread_link = bp_activity_get_permalink( $activity_id );
143
+ $settings_link = bp_core_get_user_domain( $original_activity->user_id ) . bp_get_settings_slug() . '/notifications/';
144
 
145
  $poster_name = stripslashes( $poster_name );
146
  $content = bp_activity_filter_kses( stripslashes($content) );
148
  // Set up and send the message
149
  $ud = bp_core_get_core_userdata( $original_activity->user_id );
150
  $to = $ud->user_email;
151
+ $sitename = wp_specialchars_decode( get_blog_option( bp_get_root_blog_id(), 'blogname' ), ENT_QUOTES );
152
  $subject = '[' . $sitename . '] ' . sprintf( __( '%s replied to one of your updates', 'buddypress' ), $poster_name );
153
 
154
  $message = sprintf( __(
155
+ '%1$s replied to one of your updates:
156
 
157
+ "%2$s"
158
 
159
+ To view your original update and all comments, log in and visit: %3$s
160
 
161
  ---------------------
162
  ', 'buddypress' ), $poster_name, $content, $thread_link );
166
  /* Send the message */
167
  $to = apply_filters( 'bp_activity_new_comment_notification_to', $to );
168
  $subject = apply_filters( 'bp_activity_new_comment_notification_subject', $subject, $poster_name );
169
+ $message = apply_filters( 'bp_activity_new_comment_notification_message', $message, $poster_name, $content, $thread_link, $settings_link );
170
 
171
  wp_mail( $to, $subject, $message );
172
+
173
+ do_action( 'bp_activity_sent_reply_to_update_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params );
174
  }
175
 
176
  /***
182
 
183
  $parent_comment = new BP_Activity_Activity( $parent_id );
184
 
185
+ if ( $parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id && 'no' != bp_get_user_meta( $parent_comment->user_id, 'notification_activity_new_reply', true ) ) {
186
  $poster_name = bp_core_get_user_displayname( $commenter_id );
187
  $thread_link = bp_activity_get_permalink( $activity_id );
188
+ $settings_link = bp_core_get_user_domain( $parent_comment->user_id ) . bp_get_settings_slug() . '/notifications/';
189
 
190
  // Set up and send the message
191
  $ud = bp_core_get_core_userdata( $parent_comment->user_id );
192
  $to = $ud->user_email;
193
+ $sitename = wp_specialchars_decode( get_blog_option( bp_get_root_blog_id(), 'blogname' ), ENT_QUOTES );
194
  $subject = '[' . $sitename . '] ' . sprintf( __( '%s replied to one of your comments', 'buddypress' ), $poster_name );
195
 
196
  $poster_name = stripslashes( $poster_name );
197
  $content = bp_activity_filter_kses( stripslashes( $content ) );
198
 
199
  $message = sprintf( __(
200
+ '%1$s replied to one of your comments:
201
 
202
+ "%2$s"
203
 
204
+ To view the original activity, your comment and all replies, log in and visit: %3$s
205
 
206
  ---------------------
207
  ', 'buddypress' ), $poster_name, $content, $thread_link );
211
  /* Send the message */
212
  $to = apply_filters( 'bp_activity_new_comment_notification_comment_author_to', $to );
213
  $subject = apply_filters( 'bp_activity_new_comment_notification_comment_author_subject', $subject, $poster_name );
214
+ $message = apply_filters( 'bp_activity_new_comment_notification_comment_author_message', $message, $poster_name, $content, $settings_link );
215
 
216
  wp_mail( $to, $subject, $message );
217
+
218
+ do_action( 'bp_activity_sent_reply_to_reply_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params );
219
  }
220
  }
221
 
222
+ ?>
bp-activity/bp-activity-screens.php ADDED
@@ -0,0 +1,308 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * BuddyPress Activity Screens
5
+ *
6
+ * @package BuddyPress
7
+ * @subpackage ActivityScreens
8
+ */
9
+
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
+
13
+ /**
14
+ * Activity screen index
15
+ *
16
+ * @since 1.5.0
17
+ *
18
+ * @uses bp_displayed_user_id()
19
+ * @uses bp_is_activity_component()
20
+ * @uses bp_current_action()
21
+ * @uses bp_update_is_directory()
22
+ * @uses do_action() To call the 'bp_activity_screen_index' hook
23
+ * @uses bp_core_load_template()
24
+ * @uses apply_filters() To call the 'bp_activity_screen_index' hook
25
+ */
26
+ function bp_activity_screen_index() {
27
+ if ( !bp_displayed_user_id() && bp_is_activity_component() && !bp_current_action() ) {
28
+ bp_update_is_directory( true, 'activity' );
29
+
30
+ do_action( 'bp_activity_screen_index' );
31
+
32
+ bp_core_load_template( apply_filters( 'bp_activity_screen_index', 'activity/index' ) );
33
+ }
34
+ }
35
+ add_action( 'bp_screens', 'bp_activity_screen_index' );
36
+
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()
44
+ * @uses apply_filters() To call the 'bp_activity_template_my_activity' hook
45
+ */
46
+ function bp_activity_screen_my_activity() {
47
+ do_action( 'bp_activity_screen_my_activity' );
48
+ bp_core_load_template( apply_filters( 'bp_activity_template_my_activity', 'members/single/home' ) );
49
+ }
50
+
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
62
+ */
63
+ function bp_activity_screen_friends() {
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
+ }
71
+
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
83
+ */
84
+ function bp_activity_screen_groups() {
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
+ }
92
+
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
+ }
109
+
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
+ }
126
+
127
+ /**
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()
135
+ */
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' );
143
+ add_action( 'bp_activity_screen_mentions', 'bp_activity_remove_screen_notifications' );
144
+
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()
152
+ * @uses bp_loggedin_user_id()
153
+ */
154
+ function bp_activity_reset_my_new_mentions() {
155
+ if ( bp_is_my_profile() )
156
+ bp_activity_clear_new_mentions( bp_loggedin_user_id() );
157
+ }
158
+ add_action( 'bp_activity_screen_mentions', 'bp_activity_reset_my_new_mentions' );
159
+
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()
167
+ * @uses bp_activity_get_specific()
168
+ * @uses bp_current_action()
169
+ * @uses bp_action_variables()
170
+ * @uses bp_do_404()
171
+ * @uses bp_is_active()
172
+ * @uses groups_get_group()
173
+ * @uses groups_is_user_member()
174
+ * @uses apply_filters_ref_array() To call the 'bp_activity_permalink_access' hook
175
+ * @uses do_action() To call the 'bp_activity_screen_single_activity_permalink' hook
176
+ * @uses bp_core_add_message()
177
+ * @uses is_user_logged_in()
178
+ * @uses bp_core_redirect()
179
+ * @uses site_url()
180
+ * @uses esc_url()
181
+ * @uses bp_get_root_domain()
182
+ * @uses bp_get_activity_root_slug()
183
+ * @uses bp_core_load_template()
184
+ * @uses apply_filters() To call the 'bp_activity_template_profile_activity_permalink' hook
185
+ */
186
+ function bp_activity_screen_single_activity_permalink() {
187
+ global $bp;
188
+
189
+ // No displayed user or not viewing 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() ) {
201
+ bp_do_404();
202
+ return;
203
+
204
+ } else {
205
+ $activity = $activity['activities'][0];
206
+ }
207
+
208
+ // Default access is true
209
+ $has_access = true;
210
+
211
+ // If activity is from a group, do an extra cap check
212
+ if ( isset( $bp->groups->id ) && $activity->component == $bp->groups->id ) {
213
+
214
+ // Activity is from a group, but groups is currently disabled
215
+ if ( !bp_is_active( 'groups') ) {
216
+ bp_do_404();
217
+ return;
218
+ }
219
+
220
+ // Check to see if the group is not public, if so, check the
221
+ // user has access to see this activity
222
+ if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) ) {
223
+
224
+ // Group is not public
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
+ }
232
+ }
233
+ }
234
+
235
+ // Allow access to be filtered
236
+ $has_access = apply_filters_ref_array( 'bp_activity_permalink_access', array( $has_access, &$activity ) );
237
+
238
+ // Allow additional code execution
239
+ do_action( 'bp_activity_screen_single_activity_permalink', $activity, $has_access );
240
+
241
+ // Access is specifically disallowed
242
+ if ( false === $has_access ) {
243
+
244
+ // User feedback
245
+ bp_core_add_message( __( 'You do not have access to this activity.', 'buddypress' ), 'error' );
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' ) );
254
+ }
255
+ add_action( 'bp_screens', 'bp_activity_screen_single_activity_permalink' );
256
+
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">
277
+ <thead>
278
+ <tr>
279
+ <th class="icon">&nbsp;</th>
280
+ <th class="title"><?php _e( 'Activity', 'buddypress' ) ?></th>
281
+ <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>
282
+ <th class="no"><?php _e( 'No', 'buddypress' )?></th>
283
+ </tr>
284
+ </thead>
285
+
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>
293
+ <tr id="activity-notification-settings-replies">
294
+ <td>&nbsp;</td>
295
+ <td><?php _e( "A member replies to an update or comment you've posted", 'buddypress' ) ?></td>
296
+ <td class="yes"><input type="radio" name="notifications[notification_activity_new_reply]" value="yes" <?php checked( $reply, 'yes', true ) ?>/></td>
297
+ <td class="no"><input type="radio" name="notifications[notification_activity_new_reply]" value="no" <?php checked( $reply, 'no', true ) ?>/></td>
298
+ </tr>
299
+
300
+ <?php do_action( 'bp_activity_screen_notification_settings' ) ?>
301
+ </tbody>
302
+ </table>
303
+
304
+ <?php
305
+ }
306
+ add_action( 'bp_notification_settings', 'bp_activity_screen_notification_settings', 1 );
307
+
308
+ ?>
bp-activity/bp-activity-template.php ADDED
@@ -0,0 +1,2696 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * BuddyPress Activity Template Functions
5
+ *
6
+ * @package BuddyPress
7
+ * @subpackage ActivityTemplate
8
+ */
9
+
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
+
13
+ /**
14
+ * Output the activity component slug
15
+ *
16
+ * @since 1.5.0
17
+ *
18
+ * @uses bp_get_activity_slug()
19
+ */
20
+ function bp_activity_slug() {
21
+ echo bp_get_activity_slug();
22
+ }
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
30
+ */
31
+ function bp_get_activity_slug() {
32
+ global $bp;
33
+ return apply_filters( 'bp_get_activity_slug', $bp->activity->slug );
34
+ }
35
+
36
+ /**
37
+ * Output the activity component root slug
38
+ *
39
+ * @since 1.5.0
40
+ *
41
+ * @uses bp_get_activity_root_slug()
42
+ */
43
+ function bp_activity_root_slug() {
44
+ echo bp_get_activity_root_slug();
45
+ }
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
53
+ */
54
+ function bp_get_activity_root_slug() {
55
+ global $bp;
56
+ return apply_filters( 'bp_get_activity_root_slug', $bp->activity->root_slug );
57
+ }
58
+
59
+ /**
60
+ * Output member directory permalink
61
+ *
62
+ * @since 1.5.0
63
+ *
64
+ * @uses bp_get_activity_directory_permalink()
65
+ */
66
+ function bp_activity_directory_permalink() {
67
+ echo bp_get_activity_directory_permalink();
68
+ }
69
+ /**
70
+ * Return member directory permalink
71
+ *
72
+ * @since 1.5.0
73
+ *
74
+ * @uses traisingslashit()
75
+ * @uses bp_get_root_domain()
76
+ * @uses bp_get_activity_root_slug()
77
+ * @uses apply_filters() To call the 'bp_get_activity_directory_permalink' hook
78
+ *
79
+ * @return string Activity directory permalink
80
+ */
81
+ function bp_get_activity_directory_permalink() {
82
+ return apply_filters( 'bp_get_activity_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_activity_root_slug() ) );
83
+ }
84
+
85
+ /**
86
+ * The main activity template loop
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;
94
+ var $activity_count;
95
+ var $total_activity_count;
96
+ var $activities;
97
+ var $activity;
98
+
99
+ var $in_the_loop;
100
+
101
+ var $pag_page;
102
+ var $pag_num;
103
+ var $pag_links;
104
+
105
+ var $full_name;
106
+
107
+ 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
+
137
+ if ( $max ) {
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
+
154
+ $parent_ids[] = $activity->item_id;
155
+ }
156
+
157
+ if ( !empty( $parent_ids ) )
158
+ $activity_parents = bp_activity_get_specific( array( 'activity_ids' => $parent_ids ) );
159
+
160
+ if ( !empty( $activity_parents['activities'] ) ) {
161
+ foreach( $activity_parents['activities'] as $parent )
162
+ $this->activity_parents[$parent->id] = $parent;
163
+
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
176
+ ) );
177
+ }
178
+ }
179
+
180
+ function has_activities() {
181
+ if ( $this->activity_count )
182
+ return true;
183
+
184
+ return false;
185
+ }
186
+
187
+ function next_activity() {
188
+ $this->current_activity++;
189
+ $this->activity = $this->activities[$this->current_activity];
190
+
191
+ return $this->activity;
192
+ }
193
+
194
+ function rewind_activities() {
195
+ $this->current_activity = -1;
196
+ if ( $this->activity_count > 0 ) {
197
+ $this->activity = $this->activities[0];
198
+ }
199
+ }
200
+
201
+ function user_activities() {
202
+ if ( $this->current_activity + 1 < $this->activity_count ) {
203
+ return true;
204
+ } elseif ( $this->current_activity + 1 == $this->activity_count ) {
205
+ do_action('activity_loop_end');
206
+ // Do some cleaning up after the loop
207
+ $this->rewind_activities();
208
+ }
209
+
210
+ $this->in_the_loop = false;
211
+ return false;
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;
222
+
223
+ if ( $this->current_activity == 0 ) // loop has just started
224
+ do_action('activity_loop_start');
225
+ }
226
+ }
227
+
228
+ /**
229
+ * Initializes the activity loop.
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
+ *
237
+ * @global object $activities_template {@link BP_Activity_Template}
238
+ * @global object $bp BuddyPress global settings
239
+ * @uses groups_is_user_member()
240
+ * @uses bp_current_action()
241
+ * @uses bp_is_current_action()
242
+ * @uses bp_get_activity_slug()
243
+ * @uses bp_action_variable()
244
+ * @uses wp_parse_args()
245
+ * @uses bp_is_active()
246
+ * @uses friends_get_friend_user_ids()
247
+ * @uses groups_get_user_groups()
248
+ * @uses bp_activity_get_user_favorites()
249
+ * @uses apply_filters() To call the 'bp_has_activities' hook
250
+ *
251
+ * @return bool Returns true when activities are found
252
+ */
253
+ function bp_has_activities( $args = '' ) {
254
+ global $activities_template, $bp;
255
+
256
+ /***
257
+ * Set the defaults based on the current page. Any of these will be overridden
258
+ * if arguments are directly passed into the loop. Custom plugins should always
259
+ * pass their parameters directly to the loop.
260
+ */
261
+ $user_id = false;
262
+ $include = false;
263
+ $exclude = false;
264
+ $in = false;
265
+ $show_hidden = false;
266
+ $object = false;
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();
288
+
289
+ // Support for permalinks on single item pages: /groups/my-group/activity/124/
290
+ if ( bp_is_current_action( bp_get_activity_slug() ) )
291
+ $include = bp_action_variable( 0 );
292
+
293
+ // Note: any params used for filtering can be a single value, or multiple values comma separated.
294
+ $defaults = array(
295
+ 'display_comments' => 'threaded', // false for none, stream/threaded - show comments in the stream or threaded under items
296
+ 'include' => $include, // pass an activity_id or string of IDs comma-separated
297
+ 'exclude' => $exclude, // pass an activity_id or string of IDs comma-separated
298
+ 'in' => $in, // comma-separated list or array of activity IDs among which to search
299
+ 'sort' => 'DESC', // sort DESC or ASC
300
+ 'page' => 1, // which page to load
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,
307
+
308
+ // Filtering
309
+ 'user_id' => $user_id, // user_id to filter on
310
+ 'object' => $object, // object to filter on e.g. groups, profile, status, friends
311
+ 'action' => false, // action to filter on e.g. activity_update, new_forum_post, profile_updated
312
+ 'primary_id' => $primary_id, // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
313
+ 'secondary_id' => false, // secondary object ID to filter on e.g. a post_id
314
+
315
+ // Searching
316
+ 'search_terms' => false // specify terms to search on
317
+ );
318
+
319
+ $r = wp_parse_args( $args, $defaults );
320
+ extract( $r );
321
+
322
+ // If you have passed a "scope" then this will override any filters you have passed.
323
+ if ( 'just-me' == $scope || 'friends' == $scope || 'groups' == $scope || 'favorites' == $scope || 'mentions' == $scope ) {
324
+ if ( 'just-me' == $scope )
325
+ $display_comments = 'stream';
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':
337
+ if ( bp_is_active( 'friends' ) )
338
+ $friends = friends_get_friend_user_ids( $user_id );
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' ) ) {
346
+ $groups = groups_get_user_groups( $user_id );
347
+ if ( empty( $groups['groups'] ) )
348
+ return false;
349
+
350
+ $object = $bp->groups->id;
351
+ $primary_id = implode( ',', (array)$groups['groups'] );
352
+
353
+ $user_id = 0;
354
+ }
355
+ break;
356
+ case 'favorites':
357
+ $favs = bp_activity_get_user_favorites( $user_id );
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;
371
+ }
372
+ }
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()}
399
+ *
400
+ * @return bool Returns true when activities are found
401
+ */
402
+ function bp_activities() {
403
+ global $activities_template;
404
+ return $activities_template->user_activities();
405
+ }
406
+
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()}
414
+ *
415
+ * @return object The current activity within the loop
416
+ */
417
+ function bp_the_activity() {
418
+ global $activities_template;
419
+ return $activities_template->the_activity();
420
+ }
421
+
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()}
429
+ */
430
+ function bp_activity_pagination_count() {
431
+ echo bp_get_activity_pagination_count();
432
+ }
433
+
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 );
450
+ $to_num = bp_core_number_format( ( $start_num + ( $activities_template->pag_num - 1 ) > $activities_template->total_activity_count ) ? $activities_template->total_activity_count : $start_num + ( $activities_template->pag_num - 1 ) );
451
+ $total = bp_core_number_format( $activities_template->total_activity_count );
452
+
453
+ return sprintf( __( 'Viewing item %1$s to %2$s (of %3$s items)', 'buddypress' ), $from_num, $to_num, $total );
454
+ }
455
+
456
+ /**
457
+ * Outputs the activity pagination links
458
+ *
459
+ * @since 1.0.0
460
+ *
461
+ * @uses bp_get_activity_pagination_links()
462
+ */
463
+ function bp_activity_pagination_links() {
464
+ echo bp_get_activity_pagination_links();
465
+ }
466
+
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
474
+ *
475
+ * @return string The pagination links
476
+ */
477
+ function bp_get_activity_pagination_links() {
478
+ global $activities_template;
479
+
480
+ return apply_filters( 'bp_get_activity_pagination_links', $activities_template->pag_links );
481
+ }
482
+
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
490
+ *
491
+ * @return bool $has_more_items True if more items, false if not
492
+ */
493
+ function bp_activity_has_more_items() {
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
+ }
501
+
502
+ /**
503
+ * Outputs the activity count
504
+ *
505
+ * @since 1.2.0
506
+ *
507
+ * @uses bp_get_activity_count()
508
+ */
509
+ function bp_activity_count() {
510
+ echo bp_get_activity_count();
511
+ }
512
+
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
520
+ *
521
+ * @return int The activity count
522
+ */
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
+ */
536
+ function bp_activity_per_page() {
537
+ echo bp_get_activity_per_page();
538
+ }
539
+
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
547
+ *
548
+ * @return int The activities per page
549
+ */
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
576
+ *
577
+ * @return int The activities title
578
+ */
579
+ function bp_get_activities_title() {
580
+ global $bp_activity_title;
581
+
582
+ return apply_filters( 'bp_get_activities_title', $bp_activity_title );
583
+ }
584
+
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
605
+ *
606
+ * @return unknown_type
607
+ */
608
+ function bp_get_activities_no_activity() {
609
+ global $bp_activity_no_activity;
610
+
611
+ return apply_filters( 'bp_get_activities_no_activity', $bp_activity_no_activity );
612
+ }
613
+
614
+ /**
615
+ * Outputs the activity id
616
+ *
617
+ * @since 1.2.0
618
+ *
619
+ * @uses bp_get_activity_id()
620
+ */
621
+ function bp_activity_id() {
622
+ echo bp_get_activity_id();
623
+ }
624
+
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
632
+ *
633
+ * @return int The activity id
634
+ */
635
+ function bp_get_activity_id() {
636
+ global $activities_template;
637
+ return apply_filters( 'bp_get_activity_id', $activities_template->activity->id );
638
+ }
639
+
640
+ /**
641
+ * Outputs the activity item id
642
+ *
643
+ * @since 1.2.0
644
+ *
645
+ * @uses bp_get_activity_item_id()
646
+ */
647
+ function bp_activity_item_id() {
648
+ echo bp_get_activity_item_id();
649
+ }
650
+
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
658
+ *
659
+ * @return int The activity item id
660
+ */
661
+ function bp_get_activity_item_id() {
662
+ global $activities_template;
663
+ return apply_filters( 'bp_get_activity_item_id', $activities_template->activity->item_id );
664
+ }
665
+
666
+ /**
667
+ * Outputs the activity secondary item id
668
+ *
669
+ * @since 1.2.0
670
+ *
671
+ * @uses bp_get_activity_secondary_item_id()
672
+ */
673
+ function bp_activity_secondary_item_id() {
674
+ echo bp_get_activity_secondary_item_id();
675
+ }
676
+
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
684
+ *
685
+ * @return int The activity secondary item id
686
+ */
687
+ function bp_get_activity_secondary_item_id() {
688
+ global $activities_template;
689
+ return apply_filters( 'bp_get_activity_secondary_item_id', $activities_template->activity->secondary_item_id );
690
+ }
691
+
692
+ /**
693
+ * Outputs the date the activity was recorded
694
+ *
695
+ * @since 1.2.0
696
+ *
697
+ * @uses bp_get_activity_date_recorded()
698
+ */
699
+ function bp_activity_date_recorded() {
700
+ echo bp_get_activity_date_recorded();
701
+ }
702
+
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
710
+ *
711
+ * @return string The date the activity was recorded
712
+ */
713
+ function bp_get_activity_date_recorded() {
714
+ global $activities_template;
715
+ return apply_filters( 'bp_get_activity_date_recorded', $activities_template->activity->date_recorded );
716
+ }
717
+
718
+ /**
719
+ * Outputs the activity object name
720
+ *
721
+ * @since 1.2.0
722
+ *
723
+ * @uses bp_get_activity_object_name()
724
+ */
725
+ function bp_activity_object_name() {
726
+ echo bp_get_activity_object_name();
727
+ }
728
+
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
736
+ *
737
+ * @return string The activity object name
738
+ */
739
+ function bp_get_activity_object_name() {
740
+ global $activities_template;
741
+ return apply_filters( 'bp_get_activity_object_name', $activities_template->activity->component );
742
+ }
743
+
744
+ /**
745
+ * Outputs the activity type
746
+ *
747
+ * @since 1.2.0
748
+ *
749
+ * @uses bp_get_activity_type()
750
+ */
751
+ function bp_activity_type() {
752
+ echo bp_get_activity_type();
753
+ }
754
+
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
762
+ *
763
+ * @return string The activity type
764
+ */
765
+ function bp_get_activity_type() {
766
+ global $activities_template;
767
+ return apply_filters( 'bp_get_activity_type', $activities_template->activity->type );
768
+ }
769
+
770
+ /**
771
+ * Outputs the activity action name
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
780
+ *
781
+ * @uses bp_activity_type()
782
+ */
783
+ function bp_activity_action_name() { echo bp_activity_type(); }
784
+
785
+ /**
786
+ * Returns the activity type
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
+ *
795
+ * @uses bp_get_activity_type()
796
+ *
797
+ * @return string The activity type
798
+ */
799
+ function bp_get_activity_action_name() { return bp_get_activity_type(); }
800
+
801
+ /**
802
+ * Outputs the activity user id
803
+ *
804
+ * @since 1.1.0
805
+ *
806
+ * @uses bp_get_activity_user_id()
807
+ */
808
+ function bp_activity_user_id() {
809
+ echo bp_get_activity_user_id();
810
+ }
811
+
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
819
+ *
820
+ * @return int The activity user id
821
+ */
822
+ function bp_get_activity_user_id() {
823
+ global $activities_template;
824
+ return apply_filters( 'bp_get_activity_user_id', $activities_template->activity->user_id );
825
+ }
826
+
827
+ /**
828
+ * Outputs the activity user link
829
+ *
830
+ * @since 1.2.0
831
+ *
832
+ * @uses bp_get_activity_user_link()
833
+ */
834
+ function bp_activity_user_link() {
835
+ echo bp_get_activity_user_link();
836
+ }
837
+
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()
845
+ * @uses apply_filters() To call the 'bp_get_activity_user_link' hook
846
+ *
847
+ * @return string $link The activity user link
848
+ */
849
+ function bp_get_activity_user_link() {
850
+ global $activities_template;
851
+
852
+ if ( empty( $activities_template->activity->user_id ) )
853
+ $link = $activities_template->activity->primary_link;
854
+ else
855
+ $link = bp_core_get_user_domain( $activities_template->activity->user_id, $activities_template->activity->user_nicename, $activities_template->activity->user_login );
856
+
857
+ return apply_filters( 'bp_get_activity_user_link', $link );
858
+ }
859
+
860
+ /**
861
+ * Output the avatar of the user that performed the action
862
+ *
863
+ * @since 1.1.0
864
+ *
865
+ * @param array $args
866
+ *
867
+ * @uses bp_get_activity_avatar()
868
+ */
869
+ function bp_activity_avatar( $args = '' ) {
870
+ echo bp_get_activity_avatar( $args );
871
+ }
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
+ *
879
+ * @global object $activities_template {@link BP_Activity_Template}
880
+ * @global object $bp BuddyPress global settings
881
+ * @uses bp_is_single_activity()
882
+ * @uses wp_parse_args()
883
+ * @uses apply_filters() To call the 'bp_get_activity_avatar_object_' . $current_activity_item->component hook
884
+ * @uses apply_filters() To call the 'bp_get_activity_avatar_item_id' hook
885
+ * @uses bp_core_fetch_avatar()
886
+ * @uses apply_filters() To call the 'bp_get_activity_avatar' hook
887
+ *
888
+ * @return string User avatar
889
+ */
890
+ function bp_get_activity_avatar( $args = '' ) {
891
+ global $activities_template, $bp;
892
+
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,
901
+ 'user_id' => false
902
+ );
903
+
904
+ $r = wp_parse_args( $args, $defaults );
905
+ extract( $r, EXTR_SKIP );
906
+
907
+ if ( !isset( $height ) && !isset( $width ) ) {
908
+ // Backpat
909
+ if ( isset( $bp->avatar->full->height ) || isset( $bp->avatar->thumb->height ) ) {
910
+ $height = ( 'full' == $type ) ? $bp->avatar->full->height : $bp->avatar->thumb->height;
911
+ } else {
912
+ $height = 20;
913
+ }
914
+
915
+ // Backpat
916
+ if ( isset( $bp->avatar->full->width ) || isset( $bp->avatar->thumb->width ) ) {
917
+ $width = ( 'full' == $type ) ? $bp->avatar->full->width : $bp->avatar->thumb->width;
918
+ } else {
919
+ $width = 20;
920
+ }
921
+
922
+ }
923
+
924
+ // Within the loop, we the current activity should be set first to the
925
+ // current_comment, if available
926
+ $current_activity_item = isset( $activities_template->activity->current_comment ) ? $activities_template->activity->current_comment : $activities_template->activity;
927
+
928
+ // Primary activity avatar is always a user, but can be modified via a filter
929
+ $object = apply_filters( 'bp_get_activity_avatar_object_' . $current_activity_item->component, 'user' );
930
+ $item_id = $user_id ? $user_id : $current_activity_item->user_id;
931
+ $item_id = apply_filters( 'bp_get_activity_avatar_item_id', $item_id );
932
+
933
+ // If this is a user object pass the users' email address for Gravatar so we don't have to refetch it.
934
+ if ( 'user' == $object && empty( $user_id ) && empty( $email ) && isset( $activities_template->activity->user_email ) )
935
+ $email = $current_activity_item->user_email;
936
+
937
+ return apply_filters( 'bp_get_activity_avatar', bp_core_fetch_avatar( array( 'item_id' => $item_id, 'object' => $object, 'type' => $type, 'alt' => $alt, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $email ) ) );
938
+ }
939
+
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
+ *
947
+ * @uses bp_get_activity_secondary_avatar()
948
+ */
949
+ function bp_activity_secondary_avatar( $args = '' ) {
950
+ echo bp_get_activity_secondary_avatar( $args );
951
+ }
952
+
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()
964
+ * @uses apply_filters() To call the 'bp_get_activity_secondary_avatar_object_' . $activities_template->activity->component hook
965
+ * @uses apply_filters() To call the 'bp_get_activity_secondary_avatar_item_id' hook
966
+ * @uses bp_core_fetch_avatar()
967
+ * @uses apply_filters() To call the 'bp_get_activity_secondary_avatar' hook
968
+ *
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',
976
+ 'width' => 20,
977
+ 'height' => 20,
978
+ 'class' => 'avatar',
979
+ 'email' => false
980
+ );
981
+
982
+ $r = wp_parse_args( $args, $defaults );
983
+ extract( $r, EXTR_SKIP );
984
+
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
+ }
1021
+
1022
+ // Allow object and item_id to be filtered
1023
+ $object = apply_filters( 'bp_get_activity_secondary_avatar_object_' . $activities_template->activity->component, $object );
1024
+ $item_id = apply_filters( 'bp_get_activity_secondary_avatar_item_id', $item_id );
1025
+
1026
+ // If we have no item_id or object, there is no avatar to display
1027
+ if ( empty( $item_id ) || empty( $object ) )
1028
+ return false;
1029
+
1030
+ return apply_filters( 'bp_get_activity_secondary_avatar', bp_core_fetch_avatar( array( 'item_id' => $item_id, 'object' => $object, 'type' => $type, 'alt' => $alt, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $email ) ) );
1031
+ }
1032
+
1033
+ /**
1034
+ * Output the activity action
1035
+ *
1036
+ * @since 1.2.0
1037
+ *
1038
+ * @uses bp_get_activity_action()
1039
+ */
1040
+ function bp_activity_action() {
1041
+ echo bp_get_activity_action();
1042
+ }
1043
+
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
1051
+ * @uses bp_insert_activity_meta()
1052
+ * @uses apply_filters_ref_array() To call the 'bp_get_activity_action' hook
1053
+ *
1054
+ * @return string The activity action
1055
+ */
1056
+ function bp_get_activity_action() {
1057
+ global $activities_template;
1058
+
1059
+ $action = $activities_template->activity->action;
1060
+ $action = apply_filters_ref_array( 'bp_get_activity_action_pre_meta', array( $action, &$activities_template->activity ) );
1061
+
1062
+ if ( !empty( $action ) )
1063
+ $action = bp_insert_activity_meta( $action );
1064
+
1065
+ return apply_filters_ref_array( 'bp_get_activity_action', array( $action, &$activities_template->activity ) );
1066
+ }
1067
+
1068
+ /**
1069
+ * Output the activity content body
1070
+ *
1071
+ * @since 1.2.0
1072
+ *
1073
+ * @uses bp_get_activity_content_body()
1074
+ */
1075
+ function bp_activity_content_body() {
1076
+ echo bp_get_activity_content_body();
1077
+ }
1078
+
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()
1086
+ * @uses apply_filters_ref_array() To call the 'bp_get_activity_content_body' hook
1087
+ *
1088
+ * @return string The activity content body
1089
+ */
1090
+ function bp_get_activity_content_body() {
1091
+ global $activities_template;
1092
+
1093
+ // Backwards compatibility if action is not being used
1094
+ if ( empty( $activities_template->activity->action ) && !empty( $activities_template->activity->content ) )
1095
+ $activities_template->activity->content = bp_insert_activity_meta( $activities_template->activity->content );
1096
+
1097
+ return apply_filters_ref_array( 'bp_get_activity_content_body', array( $activities_template->activity->content, &$activities_template->activity ) );
1098
+ }
1099
+
1100
+ /**
1101
+ * Does the activity have content?
1102
+ *
1103
+ * @since 1.2.0
1104
+ *
1105
+ * @global object $activities_template {@link BP_Activity_Template}
1106
+ *
1107
+ * @return bool True if activity has content, false otherwise
1108
+ */
1109
+ function bp_activity_has_content() {
1110
+ global $activities_template;
1111
+
1112
+ if ( !empty( $activities_template->activity->content ) )
1113
+ return true;
1114
+
1115
+ return false;
1116
+ }
1117
+
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
+ *
1126
+ * @uses bp_get_activity_content()
1127
+ */
1128
+ function bp_activity_content() {
1129
+ echo bp_get_activity_content();
1130
+ }
1131
+
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
1144
+ *
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'
1153
+ *
1154
+ * This function is mainly for backwards comptibility.
1155
+ */
1156
+
1157
+ $content = bp_get_activity_action() . ' ' . bp_get_activity_content_body();
1158
+ return apply_filters( 'bp_get_activity_content', $content );
1159
+ }
1160
+
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()
1173
+ * @uses bp_activity_get_permalink()
1174
+ * @uses esc_attr__()
1175
+ * @uses apply_filters_ref_array() To call the 'bp_activity_permalink' hook
1176
+ * @uses apply_filters() To call the 'bp_insert_activity_meta' hook
1177
+ *
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 );
1185
+
1186
+ // Insert the time since.
1187
+ $time_since = apply_filters_ref_array( 'bp_activity_time_since', array( '<span class="time-since">' . bp_core_time_since( $activities_template->activity->date_recorded ) . '</span>', &$activities_template->activity ) );
1188
+
1189
+ // Insert the permalink
1190
+ if ( !bp_is_single_activity() )
1191
+ $content = apply_filters_ref_array( 'bp_activity_permalink', array( sprintf( '%1$s <a href="%2$s" class="view activity-time-since" title="%3$s">%4$s</a>', $content, bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ), esc_attr__( 'View Discussion', 'buddypress' ), $time_since ), &$activities_template->activity ) );
1192
+ else
1193
+ $content .= str_pad( $time_since, strlen( $time_since ) + 2, ' ', STR_PAD_BOTH );
1194
+
1195
+ return apply_filters( 'bp_insert_activity_meta', $content );
1196
+ }
1197
+
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;
1216
+
1217
+ if ( isset( $activity->current_comment ) )
1218
+ $activity = $activity->current_comment;
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 );
1232
+ }
1233
+
1234
+ /**
1235
+ * Output the activity parent content
1236
+ *
1237
+ * @since 1.2.0
1238
+ *
1239
+ * @param array $args Optional
1240
+ *
1241
+ * @uses bp_get_activity_parent_content()
1242
+ */
1243
+ function bp_activity_parent_content( $args = '' ) {
1244
+ echo bp_get_activity_parent_content($args);
1245
+ }
1246
+
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
1258
+ *
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
1266
+ );
1267
+
1268
+ $r = wp_parse_args( $args, $defaults );
1269
+ extract( $r, EXTR_SKIP );
1270
+
1271
+ // Get the ID of the parent activity content
1272
+ if ( !$parent_id = $activities_template->activity->item_id )
1273
+ return false;
1274
+
1275
+ // Get the content of the parent
1276
+ if ( empty( $activities_template->activity_parents[$parent_id] ) )
1277
+ return false;
1278
+
1279
+ if ( empty( $activities_template->activity_parents[$parent_id]->content ) )
1280
+ $content = $activities_template->activity_parents[$parent_id]->action;
1281
+ else
1282
+ $content = $activities_template->activity_parents[$parent_id]->action . ' ' . $activities_template->activity_parents[$parent_id]->content;
1283
+
1284
+ // Remove the time since content for backwards compatibility
1285
+ $content = str_replace( '<span class="time-since">%s</span>', '', $content );
1286
+
1287
+ // Remove images
1288
+ $content = preg_replace( '/<img[^>]*>/Ui', '', $content );
1289
+
1290
+ return apply_filters( 'bp_get_activity_parent_content', $content );
1291
+ }
1292
+
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
+ */
1300
+ function bp_activity_is_favorite() {
1301
+ echo bp_get_activity_is_favorite();
1302
+ }
1303
+
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
+ *
1328
+ * @param string $args Unused. Appears to be left over from an earlier implementation.
1329
+ */
1330
+ function bp_activity_comments( $args = '' ) {
1331
+ echo bp_activity_get_comments( $args );
1332
+ }
1333
+
1334
+ /**
1335
+ * Gets the comment markup for an activity item
1336
+ *
1337
+ * @since 1.2.0
1338
+ *
1339
+ * @todo deprecate $args param
1340
+ *
1341
+ * @todo Given that checks for children already happen in bp_activity_recurse_comments(),
1342
+ * this function can probably be streamlined or removed.
1343
+ *
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;
1355
+
1356
+ bp_activity_recurse_comments( $activities_template->activity );
1357
+ }
1358
+
1359
+ /**
1360
+ * Loops through a level of activity comments and loads the template for each
1361
+ *
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
+
1389
+ $template = locate_template( 'activity/comment.php', false, false );
1390
+
1391
+ // Backward compatibility. In older versions of BP, the markup was
1392
+ // generated in the PHP instead of a template. This ensures that
1393
+ // older themes (which are not children of bp-default and won't
1394
+ // have the new template) will still work.
1395
+ if ( !$template ) {
1396
+ $template = BP_PLUGIN_DIR . '/bp-themes/bp-default/activity/comment.php';
1397
+ }
1398
+
1399
+ load_template( $template, false );
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
1413
+ *
1414
+ * @return object|bool $current_comment The activity comment currently being displayed. False on failure
1415
+ */
1416
+ function bp_activity_current_comment() {
1417
+ global $activities_template;
1418
+
1419
+ $current_comment = !empty( $activities_template->activity->current_comment ) ? $activities_template->activity->current_comment : false;
1420
+
1421
+ return apply_filters( 'bp_activity_current_comment', $current_comment );
1422
+ }
1423
+
1424
+
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
+ */
1432
+ function bp_activity_comment_id() {
1433
+ echo bp_get_activity_comment_id();
1434
+ }
1435
+
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
1443
+ *
1444
+ * @return int $comment_id The id of the activity comment currently being displayed
1445
+ */
1446
+ function bp_get_activity_comment_id() {
1447
+ global $activities_template;
1448
+
1449
+ $comment_id = isset( $activities_template->activity->current_comment->id ) ? $activities_template->activity->current_comment->id : false;
1450
+
1451
+ return apply_filters( 'bp_activity_comment_id', $comment_id );
1452
+ }
1453
+
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
+ */
1461
+ function bp_activity_comment_user_id() {
1462
+ echo bp_get_activity_comment_user_id();
1463
+ }
1464
+
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
1472
+ *
1473
+ * @return int|bool $user_id The user_id of the author of the displayed activity comment. False on failure
1474
+ */
1475
+ function bp_get_activity_comment_user_id() {
1476
+ global $activities_template;
1477
+
1478
+ $user_id = isset( $activities_template->activity->current_comment->user_id ) ? $activities_template->activity->current_comment->user_id : false;
1479
+
1480
+ return apply_filters( 'bp_activity_comment_user_id', $user_id );
1481
+ }
1482
+
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
+ */
1490
+ function bp_activity_comment_user_link() {
1491
+ echo bp_get_activity_comment_user_link();
1492
+ }
1493
+
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()
1501
+ * @uses apply_filters() To call the 'bp_activity_comment_user_link' hook
1502
+ *
1503
+ * @return string $user_link The URL of the activity comment author's profile
1504
+ */
1505
+ function bp_get_activity_comment_user_link() {
1506
+ $user_link = bp_core_get_user_domain( bp_get_activity_comment_user_id() );
1507
+
1508
+ return apply_filters( 'bp_activity_comment_user_link', $user_link );
1509
+ }
1510
+
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
+ */
1518
+ function bp_activity_comment_name() {
1519
+ echo bp_get_activity_comment_name();
1520
+ }
1521
+
1522
+ /**
1523
+ * Gets the author name for the activity comment currently being displayed
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
1531
+ * @uses apply_filters() To call the 'bp_activity_comment_name' hook
1532
+ *
1533
+ * @return string $name The full name of the activity comment author
1534
+ */
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
+ }
1542
+
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
+ */
1550
+ function bp_activity_comment_date_recorded() {
1551
+ echo bp_get_activity_comment_date_recorded();
1552
+ }
1553
+
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()
1561
+ * @uses apply_filters() To call the 'bp_activity_comment_date_recorded' hook
1562
+ *
1563
+ * @return string|bool $date_recorded Time since the activity was recorded, of the form "%s ago". False on failure
1564
+ */
1565
+ function bp_get_activity_comment_date_recorded() {
1566
+ global $activities_template;
1567
+
1568
+ if ( empty( $activities_template->activity->current_comment->date_recorded ) )
1569
+ return false;
1570
+
1571
+ $date_recorded = bp_core_time_since( $activities_template->activity->current_comment->date_recorded );
1572
+
1573
+ return apply_filters( 'bp_activity_comment_date_recorded', $date_recorded );
1574
+ }
1575
+
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
+ */
1583
+ function bp_activity_comment_delete_link() {
1584
+ echo bp_get_activity_comment_delete_link();
1585
+ }
1586
+
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()
1596
+ * @uses bp_get_activity_comment_id()
1597
+ * @uses apply_filters() To call the 'bp_activity_comment_delete_link' hook
1598
+ *
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
+ }
1608
+
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
+ */
1616
+ function bp_activity_comment_content() {
1617
+ echo bp_get_activity_comment_content();
1618
+ }
1619
+
1620
+ /**
1621
+ * Gets the content of the activity comment currently being displayed
1622
+ *
1623
+ * The content is run through two filters. bp_get_activity_content will apply all filters
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
1631
+ * @uses apply_filters() To call the 'bp_activity_comment_content' hook
1632
+ *
1633
+ * @return string $content The content of the current activity comment
1634
+ */
1635
+ function bp_get_activity_comment_content() {
1636
+ global $activities_template;
1637
+
1638
+ $content = apply_filters( 'bp_get_activity_content', $activities_template->activity->current_comment->content );
1639
+
1640
+ return apply_filters( 'bp_activity_comment_content', $content );
1641
+ }
1642
+
1643
+ /**
1644
+ * Echoes the activity comment count
1645
+ *
1646
+ * @since 1.2.0
1647
+ *
1648
+ * @uses bp_activity_get_comment_count()
1649
+ */
1650
+ function bp_activity_comment_count() {
1651
+ echo bp_activity_get_comment_count();
1652
+ }
1653
+
1654
+ /**
1655
+ * Gets the content of the activity comment currently being displayed
1656
+ *
1657
+ * The content is run through two filters. bp_get_activity_content will apply all filters
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
+ /**
1684
+ * Gets the content of the activity comment currently being displayed
1685
+ *
1686
+ * The content is run through two filters. bp_get_activity_content will apply all filters
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
+ }
1713
+
1714
+ return $count;
1715
+ }
1716
+
1717
+ /**
1718
+ * Echoes the activity comment link
1719
+ *
1720
+ * @since 1.2.0
1721
+ *
1722
+ * @uses bp_get_activity_comment_link()
1723
+ */
1724
+ function bp_activity_comment_link() {
1725
+ echo bp_get_activity_comment_link();
1726
+ }
1727
+
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
1735
+ *
1736
+ * @return string The activity comment link
1737
+ */
1738
+ function bp_get_activity_comment_link() {
1739
+ global $activities_template;
1740
+ return apply_filters( 'bp_get_activity_comment_link', '?ac=' . $activities_template->activity->id . '/#ac-form-' . $activities_template->activity->id );
1741
+ }
1742
+
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
+ */
1750
+ function bp_activity_comment_form_nojs_display() {
1751
+ echo bp_get_activity_comment_form_nojs_display();
1752
+ }
1753
+
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
+ *
1761
+ * @return string|bool The activity comment form no javascript display CSS. False on failure
1762
+ */
1763
+ function bp_get_activity_comment_form_nojs_display() {
1764
+ global $activities_template;
1765
+ if ( isset( $_GET['ac'] ) && $_GET['ac'] == $activities_template->activity->id . '/' )
1766
+ return 'style="display: block"';
1767
+
1768
+ return false;
1769
+ }
1770
+
1771
+ /**
1772
+ * Echoes the activity comment form action
1773
+ *
1774
+ * @since 1.2.0
1775
+ *
1776
+ * @uses bp_get_activity_comment_form_action()
1777
+ */
1778
+ function bp_activity_comment_form_action() {
1779
+ echo bp_get_activity_comment_form_action();
1780
+ }
1781
+
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
1791
+ *
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
+ */
1807
+ function bp_activity_permalink_id() {
1808
+ echo bp_get_activity_permalink_id();
1809
+ }
1810
+
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
+ */
1834
+ function bp_activity_thread_permalink() {
1835
+ echo bp_get_activity_thread_permalink();
1836
+ }
1837
+
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
+
1854
+ return apply_filters( 'bp_get_activity_thread_permalink', $link );
1855
+ }
1856
+
1857
+ /**
1858
+ * Echoes the activity favorite link
1859
+ *
1860
+ * @since 1.2.0
1861
+ *
1862
+ * @uses bp_get_activity_favorite_link()
1863
+ */
1864
+ function bp_activity_favorite_link() {
1865
+ echo bp_get_activity_favorite_link();
1866
+ }
1867
+
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()
1877
+ * @uses bp_get_activity_root_slug()
1878
+ * @uses apply_filters() To call the 'bp_get_activity_favorite_link' hook
1879
+ *
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
+ */
1894
+ function bp_activity_unfavorite_link() {
1895
+ echo bp_get_activity_unfavorite_link();
1896
+ }
1897
+
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()
1907
+ * @uses bp_get_activity_root_slug()
1908
+ * @uses apply_filters() To call the 'bp_get_activity_unfavorite_link' hook
1909
+ *
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
+ */
1924
+ function bp_activity_css_class() {
1925
+ echo bp_get_activity_css_class();
1926
+ }
1927
+
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
1935
+ * @uses bp_activity_get_comment_count()
1936
+ * @uses bp_activity_can_comment()
1937
+ * @uses apply_filters() To call the 'bp_get_activity_css_class' hook
1938
+ *
1939
+ * @return string The activity css class
1940
+ */
1941
+ function bp_get_activity_css_class() {
1942
+ global $activities_template;
1943
+
1944
+ $mini_activity_actions = apply_filters( 'bp_activity_mini_activity_types', array(
1945
+ 'friendship_accepted',
1946
+ 'friendship_created',
1947
+ 'new_blog',
1948
+ 'joined_group',
1949
+ 'created_group',
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';
1959
+
1960
+ return apply_filters( 'bp_get_activity_css_class', $activities_template->activity->component . ' ' . $activities_template->activity->type . $class );
1961
+ }
1962
+
1963
+ /**
1964
+ * Display the activity delete link.
1965
+ *
1966
+ * @since 1.1.0
1967
+ *
1968
+ * @uses bp_get_activity_delete_link()
1969
+ */
1970
+ function bp_activity_delete_link() {
1971
+ echo bp_get_activity_delete_link();
1972
+ }
1973
+
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()
1984
+ * @uses bp_current_action()
1985
+ * @uses add_query_arg()
1986
+ * @uses wp_get_referer()
1987
+ * @uses wp_nonce_url()
1988
+ * @uses apply_filters() To call the 'bp_get_activity_delete_link' hook
1989
+ *
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';
1997
+
1998
+ // Determine if we're on a single activity page, and customize accordingly
1999
+ if ( bp_is_activity_component() && is_numeric( bp_current_action() ) ) {
2000
+ $url = add_query_arg( array( 'redirect_to' => wp_get_referer() ), $url );
2001
+ $class = 'delete-activity-single';
2002
+ }
2003
+
2004
+ $link = '<a href="' . wp_nonce_url( $url, 'bp_activity_delete_link' ) . '" class="button item-button bp-secondary-action ' . $class . ' confirm" rel="nofollow">' . __( 'Delete', 'buddypress' ) . '</a>';
2005
+ return apply_filters( 'bp_get_activity_delete_link', $link );
2006
+ }
2007
+
2008
+ /**
2009
+ * Display the activity latest update link.
2010
+ *
2011
+ * @since 1.2.0
2012
+ *
2013
+ * @param int $user_id Defaults to 0
2014
+ *
2015
+ * @uses bp_get_activity_latest_update()
2016
+ */
2017
+ function bp_activity_latest_update( $user_id = 0 ) {
2018
+ echo bp_get_activity_latest_update( $user_id );
2019
+ }
2020
+
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
2033
+ * @uses bp_create_excerpt()
2034
+ * @uses bp_get_root_domain()
2035
+ * @uses bp_get_activity_root_slug()
2036
+ * @uses apply_filters() To call the 'bp_get_activity_latest_update' hook
2037
+ *
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 ) )
2050
+ return false;
2051
+
2052
+ $latest_update = apply_filters( 'bp_get_activity_latest_update_excerpt', trim( strip_tags( bp_create_excerpt( $update['content'], 358 ) ) ) );
2053
+ $latest_update .= ' <a href="' . bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $update['id'] . '/"> ' . __( 'View', 'buddypress' ) . '</a>';
2054
+
2055
+ return apply_filters( 'bp_get_activity_latest_update', $latest_update );
2056
+ }
2057
+
2058
+ /**
2059
+ * Display the activity filter links.
2060
+ *
2061
+ * @since 1.1.0
2062
+ *
2063
+ * @param array $args Defaults to false
2064
+ *
2065
+ * @uses bp_get_activity_filter_links()
2066
+ */
2067
+ function bp_activity_filter_links( $args = false ) {
2068
+ echo bp_get_activity_filter_links( $args );
2069
+ }
2070
+
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()
2083
+ * @uses add_query_arg()
2084
+ * @uses remove_query_arg()
2085
+ * @uses apply_filters() To call the 'bp_get_activity_filter_link_href' hook
2086
+ * @uses apply_filters() To call the 'bp_get_activity_filter_links' hook
2087
+ *
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'
2095
+ );
2096
+
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
+
2111
+ if ( isset( $_GET['afilter'] ) && $component == $_GET['afilter'] )
2112
+ $selected = ' class="selected"';
2113
+ else
2114
+ unset($selected);
2115
+
2116
+ $component = esc_attr( $component );
2117
+
2118
+ switch ( $style ) {
2119
+ case 'list':
2120
+ $tag = 'li';
2121
+ $before = '<li id="afilter-' . $component . '"' . $selected . '>';
2122
+ $after = '</li>';
2123
+ break;
2124
+ case 'paragraph':
2125
+ $tag = 'p';
2126
+ $before = '<p id="afilter-' . $component . '"' . $selected . '>';
2127
+ $after = '</p>';
2128
+ break;
2129
+ case 'span':
2130
+ $tag = 'span';
2131
+ $before = '<span id="afilter-' . $component . '"' . $selected . '>';
2132
+ $after = '</span>';
2133
+ break;
2134
+ }
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 );
2148
+
2149
+ if ( isset( $_GET['afilter'] ) )
2150
+ $component_links[] = '<' . $tag . ' id="afilter-clear"><a href="' . esc_attr( $link ) . '">' . __( 'Clear Filter', 'buddypress' ) . '</a></' . $tag . '>';
2151
+
2152
+ return apply_filters( 'bp_get_activity_filter_links', implode( "\n", $component_links ) );
2153
+ }
2154
+
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
+ }
2176
+
2177
+ if ( 'activity_comment' == bp_get_activity_action_name() )
2178
+ $can_comment = false;
2179
+
2180
+ return apply_filters( 'bp_activity_can_comment', $can_comment );
2181
+ }
2182
+
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
+ *
2190
+ * @uses apply_filters() To call the 'bp_activity_can_comment_reply' hook
2191
+ *
2192
+ * @return bool $can_comment Defaults to true
2193
+ */
2194
+ function bp_activity_can_comment_reply( $comment ) {
2195
+ $can_comment = true;
2196
+
2197
+ return apply_filters( 'bp_activity_can_comment_reply', $can_comment, $comment );
2198
+ }
2199
+
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
+ *
2207
+ * @return bool $can_favorite Defaults to true
2208
+ */
2209
+ function bp_activity_can_favorite() {
2210
+ $can_favorite = true;
2211
+
2212
+ return apply_filters( 'bp_activity_can_favorite', $can_favorite );
2213
+ }
2214
+
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
+ *
2222
+ * @uses bp_get_total_favorite_count_for_user()
2223
+ */
2224
+ function bp_total_favorite_count_for_user( $user_id = 0 ) {
2225
+ echo bp_get_total_favorite_count_for_user( $user_id );
2226
+ }
2227
+
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
+ *
2235
+ * @uses bp_activity_total_favorites_for_user()
2236
+ * @uses apply_filters() To call the 'bp_get_total_favorite_count_for_user' hook
2237
+ *
2238
+ * @return int The total favorite count for a specified user
2239
+ */
2240
+ function bp_get_total_favorite_count_for_user( $user_id = 0 ) {
2241
+ return apply_filters( 'bp_get_total_favorite_count_for_user', bp_activity_total_favorites_for_user( $user_id ) );
2242
+ }
2243
+
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
+ *
2251
+ * @uses bp_get_total_favorite_count_for_user()
2252
+ */
2253
+ function bp_total_mention_count_for_user( $user_id = 0 ) {
2254
+ echo bp_get_total_favorite_count_for_user( $user_id );
2255
+ }
2256
+
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
+ */
2284
+ function bp_send_public_message_link() {
2285
+ echo bp_get_send_public_message_link();
2286
+ }
2287
+
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()
2295
+ * @uses is_user_logged_in()
2296
+ * @uses wp_nonce_url()
2297
+ * @uses bp_loggedin_user_domain()
2298
+ * @uses bp_get_activity_slug()
2299
+ * @uses bp_core_get_username()
2300
+ * @uses apply_filters() To call the 'bp_get_send_public_message_link' hook
2301
+ *
2302
+ * @return string The public message link for displayed user
2303
+ */
2304
+ function bp_get_send_public_message_link() {
2305
+ global $bp;
2306
+
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
+ *
2320
+ * @uses bp_get_mentioned_user_display_name()
2321
+ */
2322
+ function bp_mentioned_user_display_name( $user_id_or_username ) {
2323
+ echo bp_get_mentioned_user_display_name( $user_id_or_username );
2324
+ }
2325
+
2326
+ /**
2327
+ * Returns the mentioned user display name
2328
+ *
2329
+ * @since 1.2.0
2330
+ *
2331
+ * @param int|string User id or username
2332
+ *
2333
+ * @uses bp_core_get_user_displayname()
2334
+ * @uses apply_filters() To call the 'bp_get_mentioned_user_display_name' hook
2335
+ *
2336
+ * @return string The mentioned user display name
2337
+ */
2338
+ function bp_get_mentioned_user_display_name( $user_id_or_username ) {
2339
+ if ( !$name = bp_core_get_user_displayname( $user_id_or_username ) )
2340
+ $name = __( 'a user', 'buddypress' );
2341
+
2342
+ return apply_filters( 'bp_get_mentioned_user_display_name', $name, $user_id_or_username );
2343
+ }
2344
+
2345
+ /**
2346
+ * Output button for sending a public message
2347
+ *
2348
+ * @since 1.2.0
2349
+ *
2350
+ * @param array $args Optional
2351
+ *
2352
+ * @uses bp_get_send_public_message_button()
2353
+ */
2354
+ function bp_send_public_message_button( $args = '' ) {
2355
+ echo bp_get_send_public_message_button( $args );
2356
+ }
2357
+
2358
+ /**
2359
+ * Return button for sending a public message
2360
+ *
2361
+ * @since 1.2.0
2362
+ *
2363
+ * @param array $args Optional
2364
+ *
2365
+ * @uses bp_get_send_public_message_link()
2366
+ * @uses wp_parse_args()
2367
+ * @uses bp_get_button()
2368
+ * @uses apply_filters() To call the 'bp_get_send_public_message_button' hook
2369
+ *
2370
+ * @return string The button for sending a public message
2371
+ */
2372
+ function bp_get_send_public_message_button( $args = '' ) {
2373
+ $defaults = array(
2374
+ 'id' => 'public_message',
2375
+ 'component' => 'activity',
2376
+ 'must_be_logged_in' => true,
2377
+ 'block_self' => true,
2378
+ 'wrapper_id' => 'post-mention',
2379
+ 'link_href' => bp_get_send_public_message_link(),
2380
+ 'link_title' => __( 'Send a public message on your activity stream.', 'buddypress' ),
2381
+ 'link_text' => __( 'Public Message', 'buddypress' ),
2382
+ 'link_class' => 'activity-button mention'
2383
+ );
2384
+
2385
+ $button = wp_parse_args( $args, $defaults );
2386
+
2387
+ // Filter and return the HTML button
2388
+ return bp_get_button( apply_filters( 'bp_get_send_public_message_button', $button ) );
2389
+ }
2390
+
2391
+ /**
2392
+ * Outputs the activity post form action
2393
+ *
2394
+ * @since 1.2.0
2395
+ *
2396
+ * @uses bp_get_activity_post_form_action()
2397
+ */
2398
+ function bp_activity_post_form_action() {
2399
+ echo bp_get_activity_post_form_action();
2400
+ }
2401
+
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()
2409
+ * @uses apply_filters() To call the 'bp_get_activity_post_form_action' hook
2410
+ *
2411
+ * @return string The activity post form action
2412
+ */
2413
+ function bp_get_activity_post_form_action() {
2414
+ return apply_filters( 'bp_get_activity_post_form_action', home_url( bp_get_activity_root_slug() . '/post/' ) );
2415
+ }
2416
+
2417
+ /* RSS Feed Template Tags ****************************************************/
2418
+
2419
+ /**
2420
+ * Outputs the sitewide activity feed link
2421
+ *
2422
+ * @since 1.0.0
2423
+ *
2424
+ * @uses bp_get_sitewide_activity_feed_link()
2425
+ */
2426
+ function bp_sitewide_activity_feed_link() {
2427
+ echo bp_get_sitewide_activity_feed_link();
2428
+ }
2429
+
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()
2437
+ * @uses apply_filters() To call the 'bp_get_sitewide_activity_feed_link' hook
2438
+ *
2439
+ * @return string The sitewide activity feed link
2440
+ */
2441
+ function bp_get_sitewide_activity_feed_link() {
2442
+ return apply_filters( 'bp_get_sitewide_activity_feed_link', home_url( bp_get_activity_root_slug() . '/feed/' ) );
2443
+ }
2444
+
2445
+ /**
2446
+ * Outputs the member activity feed link
2447
+ *
2448
+ * @since 1.2.0
2449
+ *
2450
+ * @uses bp_get_member_activity_feed_link()
2451
+ */
2452
+ function bp_member_activity_feed_link() {
2453
+ echo bp_get_member_activity_feed_link();
2454
+ }
2455
+
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
+ *
2464
+ * @uses bp_get_member_activity_feed_link()
2465
+ */
2466
+ function bp_activities_member_rss_link() { echo bp_get_member_activity_feed_link(); }
2467
+
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()
2475
+ * @uses bp_displayed_user_domain()
2476
+ * @uses bp_get_activity_slug()
2477
+ * @uses bp_is_active()
2478
+ * @uses bp_get_friends_slug()
2479
+ * @uses bp_get_groups_slug()
2480
+ * @uses apply_filters() To call the 'bp_get_activities_member_rss_link' hook
2481
+ *
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/';
2489
+ elseif ( bp_is_active( 'friends' ) && bp_is_current_action( bp_get_friends_slug() ) )
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 = '';
2499
+
2500
+ return apply_filters( 'bp_get_activities_member_rss_link', $link );
2501
+ }
2502
+
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
+ *
2511
+ * @uses bp_get_member_activity_feed_link()
2512
+ *
2513
+ * @return string The member activity feed link
2514
+ */
2515
+ function bp_get_activities_member_rss_link() { return bp_get_member_activity_feed_link(); }
2516
+
2517
+
2518
+ /** Template tags for RSS feed output ****************************************/
2519
+
2520
+ /**
2521
+ * Outputs the activity feed item guid
2522
+ *
2523
+ * @since 1.0.0
2524
+ *
2525
+ * @uses bp_activity_feed_item_guid()
2526
+ */
2527
+ function bp_activity_feed_item_guid() {
2528
+ echo bp_get_activity_feed_item_guid();
2529
+ }
2530
+
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
2538
+ *
2539
+ * @return string The activity feed item guid
2540
+ */
2541
+ function bp_get_activity_feed_item_guid() {
2542
+ global $activities_template;
2543
+
2544
+ return apply_filters( 'bp_get_activity_feed_item_guid', md5( $activities_template->activity->date_recorded . '-' . $activities_template->activity->content ) );
2545
+ }
2546
+
2547
+ /**
2548
+ * Outputs the activity feed item title
2549
+ *
2550
+ * @since 1.0.0
2551
+ *
2552
+ * @uses bp_get_activity_feed_item_title()
2553
+ */
2554
+ function bp_activity_feed_item_title() {
2555
+ echo bp_get_activity_feed_item_title();
2556
+ }
2557
+
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()
2565
+ * @uses convert_chars()
2566
+ * @uses bp_create_excerpt()
2567
+ * @uses apply_filters() To call the 'bp_get_activity_feed_item_title' hook
2568
+ *
2569
+ * @return string $title The activity feed item title
2570
+ */
2571
+ function bp_get_activity_feed_item_title() {
2572
+ global $activities_template;
2573
+
2574
+ if ( !empty( $activities_template->activity->action ) )
2575
+ $content = $activities_template->activity->action;
2576
+ else
2577
+ $content = $activities_template->activity->content;
2578
+
2579
+ $content = explode( '<span', $content );
2580
+ $title = strip_tags( ent2ncr( trim( convert_chars( $content[0] ) ) ) );
2581
+
2582
+ if ( ':' == substr( $title, -1 ) )
2583
+ $title = substr( $title, 0, -1 );
2584
+
2585
+ if ( 'activity_update' == $activities_template->activity->type )
2586
+ $title .= ': ' . strip_tags( ent2ncr( trim( convert_chars( bp_create_excerpt( $activities_template->activity->content, 70, array( 'ending' => " [&#133;]" ) ) ) ) ) );
2587
+
2588
+ return apply_filters( 'bp_get_activity_feed_item_title', $title );
2589
+ }
2590
+
2591
+ /**
2592
+ * Outputs the activity feed item link
2593
+ *
2594
+ * @since 1.0.0
2595
+ *
2596
+ * @uses bp_get_activity_feed_item_link()
2597
+ */
2598
+ function bp_activity_feed_item_link() {
2599
+ echo bp_get_activity_feed_item_link();
2600
+ }
2601
+
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
2609
+ *
2610
+ * @return string The activity feed item link
2611
+ */
2612
+ function bp_get_activity_feed_item_link() {
2613
+ global $activities_template;
2614
+
2615
+ return apply_filters( 'bp_get_activity_feed_item_link', $activities_template->activity->primary_link );
2616
+ }
2617
+
2618
+ /**
2619
+ * Outputs the activity feed item date
2620
+ *
2621
+ * @since 1.0.0
2622
+ *
2623
+ * @uses bp_get_activity_feed_item_date()
2624
+ */
2625
+ function bp_activity_feed_item_date() {
2626
+ echo bp_get_activity_feed_item_date();
2627
+ }
2628
+
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
2636
+ *
2637
+ * @return string The activity feed item date
2638
+ */
2639
+ function bp_get_activity_feed_item_date() {
2640
+ global $activities_template;
2641
+
2642
+ return apply_filters( 'bp_get_activity_feed_item_date', $activities_template->activity->date_recorded );
2643
+ }
2644
+
2645
+ /**
2646
+ * Outputs the activity feed item description
2647
+ *
2648
+ * @since 1.0.0
2649
+ *
2650
+ * @uses bp_get_activity_feed_item_description()
2651
+ */
2652
+ function bp_activity_feed_item_description() {
2653
+ echo bp_get_activity_feed_item_description();
2654
+ }
2655
+
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()
2663
+ * @uses convert_chars()
2664
+ * @uses apply_filters() To call the 'bp_get_activity_feed_item_description' hook
2665
+ *
2666
+ * @return string The activity feed item description
2667
+ */
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
+ }
2678
+
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()
2686
+ */
2687
+ function bp_activity_sitewide_feed() {
2688
+ ?>
2689
+
2690
+ <link rel="alternate" type="application/rss+xml" title="<?php bloginfo( 'name' ) ?> | <?php _e( 'Site Wide Activity RSS Feed', 'buddypress' ) ?>" href="<?php bp_sitewide_activity_feed_link() ?>" />
2691
+
2692
+ <?php
2693
+ }
2694
+ add_action( 'bp_head', 'bp_activity_sitewide_feed' );
2695
+
2696
+ ?>
bp-activity/bp-activity-templatetags.php DELETED
@@ -1,1074 +0,0 @@
1
- <?php
2
-
3
- class BP_Activity_Template {
4
- var $current_activity = -1;
5
- var $activity_count;
6
- var $total_activity_count;
7
- var $activities;
8
- var $activity;
9
-
10
- var $in_the_loop;
11
-
12
- var $pag_page;
13
- var $pag_num;
14
- var $pag_links;
15
-
16
- var $full_name;
17
-
18
- function bp_activity_template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden ) {
19
- global $bp;
20
-
21
- $this->pag_page = isset( $_REQUEST['acpage'] ) ? intval( $_REQUEST['acpage'] ) : $page;
22
- $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
23
-
24
- // Check if blog/forum replies are disabled
25
- $this->disable_blogforum_replies = $bp->site_options['bp-disable-blogforum-comments'];
26
-
27
- // Get an array of the logged in user's favorite activities
28
- $this->my_favs = maybe_unserialize( get_user_meta( $bp->loggedin_user->id, 'bp_favorite_activities', true ) );
29
-
30
- // Fetch specific activity items based on ID's
31
- if ( !empty( $include ) )
32
- $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 ) );
33
- // Fetch all activity items
34
- else
35
- $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 ) );
36
-
37
- if ( !$max || $max >= (int)$this->activities['total'] )
38
- $this->total_activity_count = (int)$this->activities['total'];
39
- else
40
- $this->total_activity_count = (int)$max;
41
-
42
- $this->activities = $this->activities['activities'];
43
-
44
- if ( $max ) {
45
- if ( $max >= count($this->activities) ) {
46
- $this->activity_count = count( $this->activities );
47
- } else {
48
- $this->activity_count = (int)$max;
49
- }
50
- } else {
51
- $this->activity_count = count( $this->activities );
52
- }
53
-
54
- $this->full_name = $bp->displayed_user->fullname;
55
-
56
- // Fetch parent content for activity comments so we do not have to query in the loop
57
- foreach ( (array)$this->activities as $activity ) {
58
- if ( 'activity_comment' != $activity->type )
59
- continue;
60
-
61
- $parent_ids[] = $activity->item_id;
62
- }
63
-
64
- if ( !empty( $parent_ids ) )
65
- $activity_parents = bp_activity_get_specific( array( 'activity_ids' => $parent_ids ) );
66
-
67
- if ( !empty( $activity_parents['activities'] ) ) {
68
- foreach( $activity_parents['activities'] as $parent )
69
- $this->activity_parents[$parent->id] = $parent;
70
-
71
- unset( $activity_parents );
72
- }
73
-
74
- if ( (int)$this->total_activity_count && (int)$this->pag_num ) {
75
- $this->pag_links = paginate_links( array(
76
- 'base' => add_query_arg( 'acpage', '%#%' ),
77
- 'format' => '',
78
- 'total' => ceil( (int)$this->total_activity_count / (int)$this->pag_num ),
79
- 'current' => (int)$this->pag_page,
80
- 'prev_text' => '&larr;',
81
- 'next_text' => '&rarr;',
82
- 'mid_size' => 1
83
- ) );
84
- }
85
- }
86
-
87
- function has_activities() {
88
- if ( $this->activity_count )
89
- return true;
90
-
91
- return false;
92
- }
93
-
94
- function next_activity() {
95
- $this->current_activity++;
96
- $this->activity = $this->activities[$this->current_activity];
97
-
98
- return $this->activity;
99
- }
100
-
101
- function rewind_activities() {
102
- $this->current_activity = -1;
103
- if ( $this->activity_count > 0 ) {
104
- $this->activity = $this->activities[0];
105
- }
106
- }
107
-
108
- function user_activities() {
109
- if ( $this->current_activity + 1 < $this->activity_count ) {
110
- return true;
111
- } elseif ( $this->current_activity + 1 == $this->activity_count ) {
112
- do_action('activity_loop_end');
113
- // Do some cleaning up after the loop
114
- $this->rewind_activities();
115
- }
116
-
117
- $this->in_the_loop = false;
118
- return false;
119
- }
120
-
121
- function the_activity() {
122
- global $activity;
123
-
124
- $this->in_the_loop = true;
125
- $this->activity = $this->next_activity();
126
-
127
- if ( is_array( $this->activity ) )
128
- $this->activity = (object) $this->activity;
129
-
130
- if ( $this->current_activity == 0 ) // loop has just started
131
- do_action('activity_loop_start');
132
- }
133
- }
134
-
135
- function bp_has_activities( $args = '' ) {
136
- global $bp, $activities_template;
137
-
138
- /***
139
- * Set the defaults based on the current page. Any of these will be overridden
140
- * if arguments are directly passed into the loop. Custom plugins should always
141
- * pass their parameters directly to the loop.
142
- */
143
- $user_id = false;
144
- $include = false;
145
- $show_hidden = false;
146
- $object = false;
147
- $primary_id = false;
148
-
149
- /* User filtering */
150
- if ( !empty( $bp->displayed_user->id ) )
151
- $user_id = $bp->displayed_user->id;
152
-
153
- /* Group filtering */
154
- if ( !empty( $bp->groups->current_group ) ) {
155
- $object = $bp->groups->id;
156
- $primary_id = $bp->groups->current_group->id;
157
-
158
- 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 ) )
159
- $show_hidden = true;
160
- }
161
-
162
- /* Support for permalinks on single item pages: /groups/my-group/activity/124/ */
163
- if ( $bp->current_action == $bp->activity->slug )
164
- $include = $bp->action_variables[0];
165
-
166
- /* Note: any params used for filtering can be a single value, or multiple values comma separated. */
167
- $defaults = array(
168
- 'display_comments' => 'threaded', // false for none, stream/threaded - show comments in the stream or threaded under items
169
- 'include' => $include, // pass an activity_id or string of ID's comma separated
170
- 'sort' => 'DESC', // sort DESC or ASC
171
- 'page' => 1, // which page to load
172
- 'per_page' => 20, // number of items per page
173
- 'max' => false, // max number to return
174
- 'show_hidden' => $show_hidden, // Show activity items that are hidden site-wide?
175
-
176
- /* Scope - pre-built activity filters for a user (friends/groups/favorites/mentions) */
177
- 'scope' => $bp->current_action,
178
-
179
- /* Filtering */
180
- 'user_id' => $user_id, // user_id to filter on
181
- 'object' => $object, // object to filter on e.g. groups, profile, status, friends
182
- 'action' => false, // action to filter on e.g. activity_update, new_forum_post, profile_updated
183
- 'primary_id' => $primary_id, // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
184
- 'secondary_id' => false, // secondary object ID to filter on e.g. a post_id
185
-
186
- /* Searching */
187
- 'search_terms' => false // specify terms to search on
188
- );
189
-
190
- $r = wp_parse_args( $args, $defaults );
191
- extract( $r );
192
-
193
- /* If you have passed a "scope" then this will override any filters you have passed. */
194
- if ( 'just-me' == $scope || 'friends' == $scope || 'groups' == $scope || 'favorites' == $scope || 'mentions' == $scope ) {
195
- if ( 'just-me' == $scope )
196
- $display_comments = 'stream';
197
-
198
- if ( $user_id = ( !empty( $bp->displayed_user->id ) ) ? $bp->displayed_user->id : $bp->loggedin_user->id ) {
199
- $show_hidden = ( $user_id == $bp->loggedin_user->id && $scope != 'friends' ) ? 1 : 0;
200
-
201
- switch ( $scope ) {
202
- case 'friends':
203
- if ( function_exists( 'friends_get_friend_user_ids' ) )
204
- $friends = friends_get_friend_user_ids( $user_id );
205
- if ( empty( $friends ) )
206
- return false;
207
-
208
- $user_id = implode( ',', (array)$friends );
209
- break;
210
- case 'groups':
211
- if ( function_exists( 'groups_get_user_groups' ) ) {
212
- $groups = groups_get_user_groups( $user_id );
213
- if ( empty( $groups['groups'] ) )
214
- return false;
215
-
216
- $object = $bp->groups->id;
217
- $primary_id = implode( ',', (array)$groups['groups'] );
218
-
219
- $user_id = false;
220
- }
221
- break;
222
- case 'favorites':
223
- $favs = bp_activity_get_user_favorites( $user_id );
224
- if ( empty( $favs ) )
225
- return false;
226
-
227
- $include = implode( ',', (array)$favs );
228
- break;
229
- case 'mentions':
230
- $user_nicename = ( !empty( $bp->displayed_user->id ) ) ? $bp->displayed_user->userdata->user_nicename : $bp->loggedin_user->userdata->user_nicename;
231
- $user_login = ( !empty( $bp->displayed_user->id ) ) ? $bp->displayed_user->userdata->user_login : $bp->loggedin_user->userdata->user_login;
232
- $search_terms = '@' . bp_core_get_username( $user_id, $user_nicename, $user_login ) . '<'; // Start search at @ symbol and stop search at closing tag delimiter.
233
- $display_comments = 'stream';
234
- $user_id = false;
235
- break;
236
- }
237
- }
238
- }
239
-
240
- if ( $max ) {
241
- if ( $per_page > $max )
242
- $per_page = $max;
243
- }
244
-
245
- /* Support for basic filters in earlier BP versions. */
246
- $filter = false;
247
- if ( isset( $_GET['afilter'] ) )
248
- $filter = array( 'object' => $_GET['afilter'] );
249
- else if ( !empty( $user_id ) || !empty( $object ) || !empty( $action ) || !empty( $primary_id ) || !empty( $secondary_id ) )
250
- $filter = array( 'user_id' => $user_id, 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id );
251
-
252
- $activities_template = new BP_Activity_Template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden );
253
-
254
- return apply_filters( 'bp_has_activities', $activities_template->has_activities(), &$activities_template );
255
- }
256
-
257
- function bp_activities() {
258
- global $activities_template;
259
- return $activities_template->user_activities();
260
- }
261
-
262
- function bp_the_activity() {
263
- global $activities_template;
264
- return $activities_template->the_activity();
265
- }
266
-
267
- function bp_activity_pagination_count() {
268
- echo bp_get_activity_pagination_count();
269
- }
270
- function bp_get_activity_pagination_count() {
271
- global $bp, $activities_template;
272
-
273
- $start_num = intval( ( $activities_template->pag_page - 1 ) * $activities_template->pag_num ) + 1;
274
- $from_num = bp_core_number_format( $start_num );
275
- $to_num = bp_core_number_format( ( $start_num + ( $activities_template->pag_num - 1 ) > $activities_template->total_activity_count ) ? $activities_template->total_activity_count : $start_num + ( $activities_template->pag_num - 1 ) );
276
- $total = bp_core_number_format( $activities_template->total_activity_count );
277
-
278
- return sprintf( __( 'Viewing item %1$s to %2$s (of %3$s items)', 'buddypress' ), $from_num, $to_num, $total ) . ' &nbsp; <span class="ajax-loader"></span>';
279
- }
280
-
281
- function bp_activity_pagination_links() {
282
- echo bp_get_activity_pagination_links();
283
- }
284
- function bp_get_activity_pagination_links() {
285
- global $activities_template;
286
-
287
- return apply_filters( 'bp_get_activity_pagination_links', $activities_template->pag_links );
288
- }
289
-
290
- function bp_activity_count() {
291
- echo bp_get_activity_count();
292
- }
293
- function bp_get_activity_count() {
294
- global $activities_template;
295
-
296
- return apply_filters( 'bp_get_activity_count', (int)$activities_template->activity_count );
297
- }
298
-
299
- function bp_activity_per_page() {
300
- echo bp_get_activity_per_page();
301
- }
302
- function bp_get_activity_per_page() {
303
- global $activities_template;
304
-
305
- return apply_filters( 'bp_get_activity_per_page', (int)$activities_template->pag_num );
306
- }
307
-
308
- function bp_activities_title() {
309
- global $bp_activity_title;
310
-
311
- echo bp_get_activities_title();
312
- }
313
- function bp_get_activities_title() {
314
- global $bp_activity_title;
315
-
316
- return apply_filters( 'bp_get_activities_title', $bp_activity_title );
317
- }
318
-
319
- function bp_activities_no_activity() {
320
- global $bp_activity_no_activity;
321
-
322
- echo bp_get_activities_no_activity();
323
- }
324
- function bp_get_activities_no_activity() {
325
- global $bp_activity_no_activity;
326
-
327
- return apply_filters( 'bp_get_activities_no_activity', $bp_activity_no_activity );
328
- }
329
-
330
- function bp_activity_id() {
331
- echo bp_get_activity_id();
332
- }
333
- function bp_get_activity_id() {
334
- global $activities_template;
335
- return apply_filters( 'bp_get_activity_id', $activities_template->activity->id );
336
- }
337
-
338
- function bp_activity_item_id() {
339
- echo bp_get_activity_item_id();
340
- }
341
- function bp_get_activity_item_id() {
342
- global $activities_template;
343
- return apply_filters( 'bp_get_activity_item_id', $activities_template->activity->item_id );
344
- }
345
-
346
- function bp_activity_secondary_item_id() {
347
- echo bp_get_activity_secondary_item_id();
348
- }
349
- function bp_get_activity_secondary_item_id() {
350
- global $activities_template;
351
- return apply_filters( 'bp_get_activity_secondary_item_id', $activities_template->activity->secondary_item_id );
352
- }
353
-
354
- function bp_activity_date_recorded() {
355
- echo bp_get_activity_date_recorded();
356
- }
357
- function bp_get_activity_date_recorded() {
358
- global $activities_template;
359
- return apply_filters( 'bp_get_activity_date_recorded', $activities_template->activity->date_recorded );
360
- }
361
-
362
- function bp_activity_object_name() {
363
- echo bp_get_activity_object_name();
364
- }
365
- function bp_get_activity_object_name() {
366
- global $activities_template;
367
- return apply_filters( 'bp_get_activity_object_name', $activities_template->activity->component );
368
- }
369
-
370
- function bp_activity_type() {
371
- echo bp_get_activity_type();
372
- }
373
- function bp_get_activity_type() {
374
- global $activities_template;
375
- return apply_filters( 'bp_get_activity_type', $activities_template->activity->type );
376
- }
377
- function bp_activity_action_name() { echo bp_activity_type(); }
378
- function bp_get_activity_action_name() { return bp_get_activity_type(); }
379
-
380
- function bp_activity_user_id() {
381
- echo bp_get_activity_user_id();
382
- }
383
- function bp_get_activity_user_id() {
384
- global $activities_template;
385
- return apply_filters( 'bp_get_activity_user_id', $activities_template->activity->user_id );
386
- }
387
-
388
- function bp_activity_user_link() {
389
- echo bp_get_activity_user_link();
390
- }
391
- function bp_get_activity_user_link() {
392
- global $activities_template;
393
-
394
- if ( empty( $activities_template->activity->user_id ) )
395
- $link = $activities_template->activity->primary_link;
396
- else
397
- $link = bp_core_get_user_domain( $activities_template->activity->user_id, $activities_template->activity->user_nicename, $activities_template->activity->user_login );
398
-
399
- return apply_filters( 'bp_get_activity_user_link', $link );
400
- }
401
-
402
- /**
403
- * bp_activity_avatar( $args )
404
- *
405
- * Output the avatar of the user that performed the action
406
- *
407
- * @param array $args
408
- */
409
- function bp_activity_avatar( $args = '' ) {
410
- echo bp_get_activity_avatar( $args );
411
- }
412
- /**
413
- * bp_get_activity_avatar( $args )
414
- *
415
- * Return the avatar of the user that performed the action
416
- *
417
- * @global array $bp
418
- * @global object $activities_template
419
- * @param array $args optional
420
- * @return string
421
- */
422
- function bp_get_activity_avatar( $args = '' ) {
423
- global $bp, $activities_template;
424
-
425
- $defaults = array(
426
- 'type' => 'thumb',
427
- 'width' => 20,
428
- 'height' => 20,
429
- 'class' => 'avatar',
430
- 'alt' => __( 'Avatar', 'buddypress' ),
431
- 'email' => false
432
- );
433
-
434
- $r = wp_parse_args( $args, $defaults );
435
- extract( $r, EXTR_SKIP );
436
-
437
- // Primary activity avatar is always a user, but can be modified via a filter
438
- $object = apply_filters( 'bp_get_activity_avatar_object_' . $activities_template->activity->component, 'user' );
439
- $item_id = apply_filters( 'bp_get_activity_avatar_item_id', $activities_template->activity->user_id );
440
-
441
- // If this is a user object pass the users' email address for Gravatar so we don't have to refetch it.
442
- if ( 'user' == $object && empty( $email ) )
443
- $email = $activities_template->activity->user_email;
444
-
445
- return apply_filters( 'bp_get_activity_avatar', bp_core_fetch_avatar( array( 'item_id' => $item_id, 'object' => $object, 'type' => $type, 'alt' => $alt, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $email ) ) );
446
- }
447
-
448
- /**
449
- * bp_activity_secondary_avatar( $args )
450
- *
451
- * Output the avatar of the object that action was performed on
452
- *
453
- * @param array $args optional
454
- */
455
- function bp_activity_secondary_avatar( $args = '' ) {
456
- echo bp_get_activity_secondary_avatar( $args );
457
- }
458
- /**
459
- * bp_get_activity_secondary_avatar( $args )
460
- *
461
- * Return the avatar of the object that action was performed on
462
- *
463
- * @global array $bp
464
- * @global object $activities_template
465
- * @param array $args optional
466
- * @return string
467
- */
468
- function bp_get_activity_secondary_avatar( $args = '' ) {
469
- global $bp, $activities_template;
470
-
471
- $defaults = array(
472
- 'type' => 'thumb',
473
- 'width' => 20,
474
- 'height' => 20,
475
- 'class' => 'avatar',
476
- 'alt' => __( 'Avatar', 'buddypress' ),
477
- 'email' => false
478
- );
479
-
480
- $r = wp_parse_args( $args, $defaults );
481
- extract( $r, EXTR_SKIP );
482
-
483
- // Set item_id and object (default to user)
484
- switch ( $activities_template->activity->component ) {
485
- case 'groups' :
486
- $object = 'group';
487
- $item_id = $activities_template->activity->item_id;
488
- break;
489
- case 'blogs' :
490
- $object = 'blog';
491
- $item_id = $activities_template->activity->item_id;
492
- break;
493
- case 'friends' :
494
- $object = 'user';
495
- $item_id = $activities_template->activity->secondary_item_id;
496
- break;
497
- default :
498
- $object = 'user';
499
- $item_id = $activities_template->activity->user_id;
500
- $email = $activities_template->activity->user_email;
501
- break;
502
- }
503
-
504
- // Allow object and item_id to be filtered
505
- $object = apply_filters( 'bp_get_activity_secondary_avatar_object_' . $activities_template->activity->component, $object );
506
- $item_id = apply_filters( 'bp_get_activity_secondary_avatar_item_id', $item_id );
507
-
508
- // If we have no item_id or object, there is no avatar to display
509
- if ( empty( $item_id ) || empty( $object ) )
510
- return false;
511
-
512
- return apply_filters( 'bp_get_activity_secondary_avatar', bp_core_fetch_avatar( array( 'item_id' => $item_id, 'object' => $object, 'type' => $type, 'alt' => $alt, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $email ) ) );
513
- }
514
-
515
- function bp_activity_action() {
516
- echo bp_get_activity_action();
517
- }
518
- function bp_get_activity_action() {
519
- global $activities_template;
520
-
521
- $action = $activities_template->activity->action;
522
-
523
- $action = apply_filters( 'bp_get_activity_action_pre_meta', $action, &$activities_template->activity );
524
-
525
- if ( !empty( $action ) )
526
- $action = bp_insert_activity_meta( $action );
527
-
528
- return apply_filters( 'bp_get_activity_action', $action, &$activities_template->activity );
529
- }
530
-
531
- function bp_activity_content_body() {
532
- echo bp_get_activity_content_body();
533
- }
534
- function bp_get_activity_content_body() {
535
- global $activities_template;
536
-
537
- /* Backwards compatibility if action is not being used */
538
- if ( empty( $activities_template->activity->action ) && !empty( $activities_template->activity->content ) )
539
- $activities_template->activity->content = bp_insert_activity_meta( $activities_template->activity->content );
540
-
541
- return apply_filters( 'bp_get_activity_content_body', $activities_template->activity->content, &$activities_template->activity );
542
- }
543
-
544
- function bp_activity_has_content() {
545
- global $activities_template;
546
-
547
- if ( !empty( $activities_template->activity->content ) )
548
- return true;
549
-
550
- return false;
551
- }
552
-
553
- function bp_activity_content() {
554
- echo bp_get_activity_content();
555
- }
556
- function bp_get_activity_content() {
557
- global $activities_template;
558
-
559
- /***
560
- * If you want to filter activity update content, please use
561
- * the filter 'bp_get_activity_content_body'
562
- *
563
- * This function is mainly for backwards comptibility.
564
- */
565
-
566
- $content = bp_get_activity_action() . ' ' . bp_get_activity_content_body();
567
- return apply_filters( 'bp_get_activity_content', $content );
568
- }
569
-
570
- function bp_insert_activity_meta( $content ) {
571
- global $activities_template, $bp;
572
-
573
- /* Strip any legacy time since placeholders -- TODO: Remove this in 1.3 */
574
- $content = str_replace( '<span class="time-since">%s</span>', '', $content );
575
-
576
- /* Insert the time since. */
577
- $content .= ' ' . apply_filters( 'bp_activity_time_since', '<span class="time-since">' . sprintf( __( '&nbsp; %s ago', 'buddypress' ), bp_core_time_since( $activities_template->activity->date_recorded ) ) . '</span>', &$activities_template->activity );
578
-
579
- /* Insert the permalink */
580
- $content .= apply_filters( 'bp_activity_permalink', ' &middot; <a href="' . bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ) . '" class="view" title="' . __( 'View Thread / Permalink', 'buddypress' ) . '">' . __( 'View', 'buddypress' ) . '</a>', &$activities_template->activity );
581
-
582
- /* Add the delete link if the user has permission on this item */
583
- if ( ( is_user_logged_in() && $activities_template->activity->user_id == $bp->loggedin_user->id ) || $bp->is_item_admin || $bp->loggedin_user->is_super_admin )
584
- $content .= apply_filters( 'bp_activity_delete_link', ' &middot; ' . bp_get_activity_delete_link(), &$activities_template->activity );
585
-
586
- return apply_filters( 'bp_insert_activity_meta', $content );
587
- }
588
-
589
- function bp_activity_parent_content( $args = '' ) {
590
- echo bp_get_activity_parent_content($args);
591
- }
592
- function bp_get_activity_parent_content( $args = '' ) {
593
- global $bp, $activities_template;
594
-
595
- $defaults = array(
596
- 'hide_user' => false
597
- );
598
-
599
- $r = wp_parse_args( $args, $defaults );
600
- extract( $r, EXTR_SKIP );
601
-
602
- /* Get the ID of the parent activity content */
603
- if ( !$parent_id = $activities_template->activity->item_id )
604
- return false;
605
-
606
- /* Get the content of the parent */
607
- if ( empty( $activities_template->activity_parents[$parent_id] ) )
608
- return false;
609
-
610
- if ( empty( $activities_template->activity_parents[$parent_id]->content ) )
611
- $content = $activities_template->activity_parents[$parent_id]->action;
612
- else
613
- $content = $activities_template->activity_parents[$parent_id]->action . ' ' . $activities_template->activity_parents[$parent_id]->content;
614
-
615
- /* Remove the time since content for backwards compatibility */
616
- $content = str_replace( '<span class="time-since">%s</span>', '', $content );
617
-
618
- /* Remove images */
619
- $content = preg_replace( '/<img[^>]*>/Ui', '', $content );
620
-
621
- return apply_filters( 'bp_get_activity_parent_content', $content );
622
- }
623
-
624
- function bp_activity_is_favorite() {
625
- echo bp_get_activity_is_favorite();
626
- }
627
- function bp_get_activity_is_favorite() {
628
- global $bp, $activities_template;
629
-
630
- return apply_filters( 'bp_get_activity_is_favorite', in_array( $activities_template->activity->id, (array)$activities_template->my_favs ) );
631
- }
632
-
633
- function bp_activity_comments( $args = '' ) {
634
- echo bp_activity_get_comments( $args );
635
- }
636
- function bp_activity_get_comments( $args = '' ) {
637
- global $activities_template, $bp;
638
-
639
- if ( !$activities_template->activity->children )
640
- return false;
641
-
642
- $comments_html = bp_activity_recurse_comments( $activities_template->activity );
643
-
644
- return apply_filters( 'bp_activity_get_comments', $comments_html );
645
- }
646
- /* TODO: The HTML in this function is temporary and will be moved to the template in a future version. */
647
- function bp_activity_recurse_comments( $comment ) {
648
- global $activities_template, $bp;
649
-
650
- if ( !$comment->children )
651
- return false;
652
-
653
- $content .= '<ul>';
654
- foreach ( (array)$comment->children as $comment ) {
655
- if ( !$comment->user_fullname )
656
- $comment->user_fullname = $comment->display_name;
657
-
658
- $content .= '<li id="acomment-' . $comment->id . '">';
659
- $content .= '<div class="acomment-avatar"><a href="' . bp_core_get_user_domain( $comment->user_id, $comment->user_nicename, $comment->user_login ) . '">' . bp_core_fetch_avatar( array( 'item_id' => $comment->user_id, 'width' => 20, 'height' => 20, 'email' => $comment->user_email ) ) . '</a></div>';
660
- $content .= '<div class="acomment-meta"><a href="' . bp_core_get_user_domain( $comment->user_id, $comment->user_nicename, $comment->user_login ) . '">' . apply_filters( 'bp_acomment_name', $comment->user_fullname, $comment ) . '</a> &middot; ' . sprintf( __( '%s ago', 'buddypress' ), bp_core_time_since( $comment->date_recorded ) );
661
-
662
- /* Reply link - the span is so that threaded reply links can be hidden when JS is off. */
663
- if ( is_user_logged_in() )
664
- $content .= '<span class="acomment-replylink"> &middot; <a href="#acomment-' . $comment->id . '" class="acomment-reply" id="acomment-reply-' . $activities_template->activity->id . '">' . __( 'Reply', 'buddypress' ) . '</a></span>';
665
-
666
- /* Delete link */
667
- if ( $bp->loggedin_user->is_super_admin || $bp->loggedin_user->id == $comment->user_id )
668
- $content .= ' &middot; <a href="' . wp_nonce_url( $bp->root_domain . '/' . $bp->activity->slug . '/delete/?cid=' . $comment->id, 'bp_activity_delete_link' ) . '" class="delete acomment-delete">' . __( 'Delete', 'buddypress' ) . '</a>';
669
-
670
- $content .= '</div>';
671
- $content .= '<div class="acomment-content">' . apply_filters( 'bp_get_activity_content', $comment->content ) . '</div>';
672
-
673
- $content .= bp_activity_recurse_comments( $comment );
674
- $content .= '</li>';
675
- }
676
- $content .= '</ul>';
677
-
678
- return apply_filters( 'bp_activity_recurse_comments', $content );
679
- }
680
-
681
- function bp_activity_comment_count() {
682
- echo bp_activity_get_comment_count();
683
- }
684
- function bp_activity_get_comment_count( $args = '' ) {
685
- global $activities_template, $bp;
686
-
687
- if ( !$activities_template->activity->children )
688
- return 0;
689
-
690
- $count = bp_activity_recurse_comment_count( $activities_template->activity );
691
-
692
- return apply_filters( 'bp_activity_get_comment_count', (int)$count );
693
- }
694
- function bp_activity_recurse_comment_count( $comment, $count = 0 ) {
695
- global $activities_template, $bp;
696
-
697
- if ( !$comment->children )
698
- return $count;
699
-
700
- foreach ( (array)$comment->children as $comment ) {
701
- $count++;
702
- $count = bp_activity_recurse_comment_count( $comment, $count );
703
- }
704
-
705
- return $count;
706
- }
707
-
708
- function bp_activity_comment_link() {
709
- echo bp_get_activity_comment_link();
710
- }
711
- function bp_get_activity_comment_link() {
712
- global $activities_template;
713
- return apply_filters( 'bp_get_activity_comment_link', '?ac=' . $activities_template->activity->id . '/#ac-form-' . $activities_template->activity->id );
714
- }
715
-
716
- function bp_activity_comment_form_nojs_display() {
717
- echo bp_get_activity_comment_form_nojs_display();
718
- }
719
- function bp_get_activity_comment_form_nojs_display() {
720
- global $activities_template;
721
- if ( $_GET['ac'] == $activities_template->activity->id . '/' )
722
- return 'style="display: block"';
723
-
724
- return false;
725
- }
726
-
727
- function bp_activity_comment_form_action() {
728
- echo bp_get_activity_comment_form_action();
729
- }
730
- function bp_get_activity_comment_form_action() {
731
- return apply_filters( 'bp_get_activity_comment_form_action', site_url( BP_ACTIVITY_SLUG . '/reply/' ) );
732
- }
733
-
734
- function bp_activity_permalink_id() {
735
- echo bp_get_activity_permalink_id();
736
- }
737
- function bp_get_activity_permalink_id() {
738
- global $bp;
739
-
740
- return apply_filters( 'bp_get_activity_permalink_id', $bp->current_action );
741
- }
742
-
743
- function bp_activity_thread_permalink() {
744
- echo bp_get_activity_thread_permalink();
745
- }
746
- function bp_get_activity_thread_permalink() {
747
- global $bp, $activities_template;
748
-
749
- $link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity );
750
-
751
- return apply_filters( 'bp_get_activity_thread_permalink', $link );
752
- }
753
-
754
- function bp_activity_favorite_link() {
755
- echo bp_get_activity_favorite_link();
756
- }
757
- function bp_get_activity_favorite_link() {
758
- global $activities_template;
759
- return apply_filters( 'bp_get_activity_favorite_link', wp_nonce_url( site_url( BP_ACTIVITY_SLUG . '/favorite/' . $activities_template->activity->id . '/' ), 'mark_favorite' ) );
760
- }
761
-
762
- function bp_activity_unfavorite_link() {
763
- echo bp_get_activity_unfavorite_link();
764
- }
765
- function bp_get_activity_unfavorite_link() {
766
- global $activities_template;
767
- return apply_filters( 'bp_get_activity_unfavorite_link', wp_nonce_url( site_url( BP_ACTIVITY_SLUG . '/unfavorite/' . $activities_template->activity->id . '/' ), 'unmark_favorite' ) );
768
- }
769
-
770
- function bp_activity_css_class() {
771
- echo bp_get_activity_css_class();
772
- }
773
- function bp_get_activity_css_class() {
774
- global $activities_template;
775
-
776
- $mini_activity_actions = apply_filters( 'bp_activity_mini_activity_types', array(
777
- 'friendship_accepted',
778
- 'friendship_created',
779
- 'new_blog',
780
- 'joined_group',
781
- 'created_group',
782
- 'new_member'
783
- ) );
784
-
785
- $class = '';
786
- if ( in_array( $activities_template->activity->type, (array)$mini_activity_actions ) || empty( $activities_template->activity->content ) )
787
- $class = ' mini';
788
-
789
- if ( bp_activity_get_comment_count() && bp_activity_can_comment() )
790
- $class .= ' has-comments';
791
-
792
- return apply_filters( 'bp_get_activity_css_class', $activities_template->activity->component . ' ' . $activities_template->activity->type . $class );
793
- }
794
-
795
- function bp_activity_delete_link() {
796
- echo bp_get_activity_delete_link();
797
- }
798
- function bp_get_activity_delete_link() {
799
- global $activities_template, $bp;
800
-
801
- return apply_filters( 'bp_get_activity_delete_link', '<a href="' . wp_nonce_url( $bp->root_domain . '/' . $bp->activity->slug . '/delete/' . $activities_template->activity->id, 'bp_activity_delete_link' ) . '" class="item-button delete-activity confirm">' . __( 'Delete', 'buddypress' ) . '</a>' );
802
- }
803
-
804
- function bp_activity_latest_update( $user_id = false ) {
805
- echo bp_get_activity_latest_update( $user_id );
806
- }
807
- function bp_get_activity_latest_update( $user_id = false ) {
808
- global $bp;
809
-
810
- if ( !$user_id )
811
- $user_id = $bp->displayed_user->id;
812
-
813
- if ( !$update = get_user_meta( $user_id, 'bp_latest_update', true ) )
814
- return false;
815
-
816
- $latest_update = '&quot;' . apply_filters( 'bp_get_activity_latest_update_excerpt', trim( strip_tags( bp_create_excerpt( $update['content'], 40 ) ) ) ) . '&quot;';
817
- $latest_update .= ' &middot; <a href="' . $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $update['id'] . '/"> ' . __( 'View', 'buddypress' ) . '</a>';
818
-
819
- return apply_filters( 'bp_get_activity_latest_update', $latest_update );
820
- }
821
-
822
- function bp_activity_filter_links( $args = false ) {
823
- echo bp_get_activity_filter_links( $args );
824
- }
825
- function bp_get_activity_filter_links( $args = false ) {
826
- global $activities_template, $bp;
827
-
828
- $defaults = array(
829
- 'style' => 'list'
830
- );
831
-
832
- $r = wp_parse_args( $args, $defaults );
833
- extract( $r, EXTR_SKIP );
834
-
835
- /* Fetch the names of components that have activity recorded in the DB */
836
- $components = BP_Activity_Activity::get_recorded_components();
837
-
838
- if ( !$components )
839
- return false;
840
-
841
- foreach ( (array) $components as $component ) {
842
- /* Skip the activity comment filter */
843
- if ( 'activity' == $component )
844
- continue;
845
-
846
- if ( isset( $_GET['afilter'] ) && $component == $_GET['afilter'] )
847
- $selected = ' class="selected"';
848
- else
849
- unset($selected);
850
-
851
- $component = esc_attr( $component );
852
-
853
- switch ( $style ) {
854
- case 'list':
855
- $tag = 'li';
856
- $before = '<li id="afilter-' . $component . '"' . $selected . '>';
857
- $after = '</li>';
858
- break;
859
- case 'paragraph':
860
- $tag = 'p';
861
- $before = '<p id="afilter-' . $component . '"' . $selected . '>';
862
- $after = '</p>';
863
- break;
864
- case 'span':
865
- $tag = 'span';
866
- $before = '<span id="afilter-' . $component . '"' . $selected . '>';
867
- $after = '</span>';
868
- break;
869
- }
870
-
871
- $link = add_query_arg( 'afilter', $component );
872
- $link = remove_query_arg( 'acpage' , $link );
873
-
874
- $link = apply_filters( 'bp_get_activity_filter_link_href', $link, $component );
875
-
876
- /* Make sure all core internal component names are translatable */
877
- $translatable_components = array( __( 'profile', 'buddypress'), __( 'friends', 'buddypress' ), __( 'groups', 'buddypress' ), __( 'status', 'buddypress' ), __( 'blogs', 'buddypress' ) );
878
-
879
- $component_links[] = $before . '<a href="' . esc_attr( $link ) . '">' . ucwords( __( $component, 'buddypress' ) ) . '</a>' . $after;
880
- }
881
-
882
- $link = remove_query_arg( 'afilter' , $link );
883
-
884
- if ( isset( $_GET['afilter'] ) )
885
- $component_links[] = '<' . $tag . ' id="afilter-clear"><a href="' . esc_attr( $link ) . '"">' . __( 'Clear Filter', 'buddypress' ) . '</a></' . $tag . '>';
886
-
887
- return apply_filters( 'bp_get_activity_filter_links', implode( "\n", $component_links ) );
888
- }
889
-
890
- function bp_activity_can_comment() {
891
- global $activities_template, $bp;
892
-
893
- if ( false === $activities_template->disable_blogforum_replies || (int)$activities_template->disable_blogforum_replies ) {
894
- 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() )
895
- return false;
896
- }
897
-
898
- if ( 'activity_comment' == bp_get_activity_action_name() )
899
- return false;
900
-
901
- return true;
902
- }
903
-
904
- function bp_total_favorite_count_for_user( $user_id = false ) {
905
- echo bp_get_total_favorite_count_for_user( $user_id );
906
- }
907
- function bp_get_total_favorite_count_for_user( $user_id = false ) {
908
- return apply_filters( 'bp_get_total_favorite_count_for_user', bp_activity_total_favorites_for_user( $user_id ) );
909
- }
910
-
911
- function bp_total_mention_count_for_user( $user_id = false ) {
912
- echo bp_get_total_favorite_count_for_user( $user_id );
913
- }
914
- function bp_get_total_mention_count_for_user( $user_id = false ) {
915
- return apply_filters( 'bp_get_total_mention_count_for_user', get_user_meta( $user_id, 'bp_new_mention_count', true ) );
916
- }
917
-
918
- function bp_send_public_message_link() {
919
- echo bp_get_send_public_message_link();
920
- }
921
- function bp_get_send_public_message_link() {
922
- global $bp;
923
-
924
- if ( bp_is_my_profile() || !is_user_logged_in() )
925
- return false;
926
-
927
- return apply_filters( 'bp_get_send_public_message_link', wp_nonce_url( $bp->loggedin_user->domain . $bp->activity->slug . '/?r=' . bp_core_get_username( $bp->displayed_user->user_id, $bp->displayed_user->userdata->user_nicename, $bp->displayed_user->userdata->user_login ) ) );
928
- }
929
-
930
- /**
931
- * bp_send_public_message_button( $args )
932
- *
933
- * Output button for sending a public message
934
- *
935
- * @param array $args
936
- */
937
- function bp_send_public_message_button( $args = '' ) {
938
- echo bp_get_send_public_message_button( $args );
939
- }
940
- /**
941
- * bp_get_send_public_message_button( $args )
942
- *
943
- * Return button for sending a public message
944
- *
945
- * @param array $args
946
- * @return string
947
- */
948
- function bp_get_send_public_message_button( $args = '' ) {
949
- $defaults = array(
950
- 'id' => 'public_message',
951
- 'component' => 'activity',
952
- 'must_be_logged_in' => true,
953
- 'block_self' => true,
954
- 'wrapper_id' => 'post-mention',
955
- 'link_href' => bp_get_send_public_message_link(),
956
- 'link_title' => __( 'Mention this user in a new public message, this will send the user a notification to get their attention.', 'buddypress' ),
957
- 'link_text' => __( 'Mention this User', 'buddypress' )
958
- );
959
-
960
- $button = wp_parse_args( $args, $defaults );
961
-
962
- // Filter and return the HTML button
963
- return bp_get_button( apply_filters( 'bp_get_send_public_message_button', $button ) );
964
- }
965
-
966
- function bp_activity_post_form_action() {
967
- echo bp_get_activity_post_form_action();
968
- }
969
- function bp_get_activity_post_form_action() {
970
- return apply_filters( 'bp_get_activity_post_form_action', site_url( BP_ACTIVITY_SLUG . '/post/' ) );
971
- }
972
-
973
- /* RSS Feed Template Tags ***************************/
974
-
975
- function bp_sitewide_activity_feed_link() {
976
- echo bp_get_sitewide_activity_feed_link();
977
- }
978
- function bp_get_sitewide_activity_feed_link() {
979
- global $bp;
980
-
981
- return apply_filters( 'bp_get_sitewide_activity_feed_link', site_url( $bp->activity->slug . '/feed/' ) );
982
- }
983
-
984
- function bp_member_activity_feed_link() {
985
- echo bp_get_member_activity_feed_link();
986
- }
987
- function bp_activities_member_rss_link() { echo bp_get_member_activity_feed_link(); }
988
-
989
- function bp_get_member_activity_feed_link() {
990
- global $bp;
991
-
992
- if ( $bp->current_component == $bp->profile->slug || 'just-me' == $bp->current_action )
993
- $link = $bp->displayed_user->domain . $bp->activity->slug . '/feed/';
994
- else if ( 'friends' == $bp->current_action )
995
- $link = $bp->displayed_user->domain . $bp->activity->slug . '/friends/feed/';
996
- else if ( 'groups' == $bp->current_action )
997
- $link = $bp->displayed_user->domain . $bp->activity->slug . '/groups/feed/';
998
- else if ( 'favorites' == $bp->current_action )
999
- $link = $bp->displayed_user->domain . $bp->activity->slug . '/favorites/feed/';
1000
- else if ( 'mentions' == $bp->current_action )
1001
- $link = $bp->displayed_user->domain . $bp->activity->slug . '/mentions/feed/';
1002
-
1003
- return apply_filters( 'bp_get_activities_member_rss_link', $link );
1004
- }
1005
- function bp_get_activities_member_rss_link() { return bp_get_member_activity_feed_link(); }
1006
-
1007
-
1008
- /* Template tags for RSS feed output */
1009
-
1010
- function bp_activity_feed_item_guid() {
1011
- echo bp_get_activity_feed_item_guid();
1012
- }
1013
- function bp_get_activity_feed_item_guid() {
1014
- global $activities_template;
1015
-
1016
- return apply_filters( 'bp_get_activity_feed_item_guid', md5( $activities_template->activity->date_recorded . '-' . $activities_template->activity->content ) );
1017
- }
1018
-
1019
- function bp_activity_feed_item_title() {
1020
- echo bp_get_activity_feed_item_title();
1021
- }
1022
- function bp_get_activity_feed_item_title() {
1023
- global $activities_template;
1024
-
1025
- if ( !empty( $activities_template->activity->action ) )
1026
- $content = $activities_template->activity->action;
1027
- else
1028
- $content = $activities_template->activity->content;
1029
-
1030
- $content = explode( '<span', $content );
1031
- $title = trim( strip_tags( html_entity_decode( utf8_encode( $content[0] ) ) ) );
1032
-
1033
- if ( ':' == substr( $title, -1 ) )
1034
- $title = substr( $title, 0, -1 );
1035
-
1036
- if ( 'activity_update' == $activities_template->activity->type )
1037
- $title .= ': ' . strip_tags( bp_create_excerpt( $activities_template->activity->content, 15 ) );
1038
-
1039
- return apply_filters( 'bp_get_activity_feed_item_title', $title );
1040
- }
1041
-
1042
- function bp_activity_feed_item_link() {
1043
- echo bp_get_activity_feed_item_link();
1044
- }
1045
- function bp_get_activity_feed_item_link() {
1046
- global $activities_template;
1047
-
1048
- return apply_filters( 'bp_get_activity_feed_item_link', $activities_template->activity->primary_link );
1049
- }
1050
-
1051
- function bp_activity_feed_item_date() {
1052
- echo bp_get_activity_feed_item_date();
1053
- }
1054
- function bp_get_activity_feed_item_date() {
1055
- global $activities_template;
1056
-
1057
- return apply_filters( 'bp_get_activity_feed_item_date', $activities_template->activity->date_recorded );
1058
- }
1059
-
1060
- function bp_activity_feed_item_description() {
1061
- echo bp_get_activity_feed_item_description();
1062
- }
1063
- function bp_get_activity_feed_item_description() {
1064
- global $activities_template;
1065
-
1066
- if ( empty( $activities_template->activity->action ) )
1067
- $content = $activities_template->activity->content;
1068
- else
1069
- $content = $activities_template->activity->action . ' ' . $activities_template->activity->content;
1070
-
1071
- return apply_filters( 'bp_get_activity_feed_item_description', html_entity_decode( str_replace( '%s', '', $content ) ) );
1072
- }
1073
-
1074
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-activity/feeds/bp-activity-favorites-feed.php CHANGED
@@ -1,13 +1,19 @@
1
  <?php
 
2
  /**
3
  * RSS2 Feed Template for displaying a member's favorite activity
4
  *
5
  * @package BuddyPress
 
6
  */
7
- header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
 
 
 
 
8
  header('Status: 200 OK');
9
  ?>
10
- <?php echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
11
 
12
  <rss version="2.0"
13
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
@@ -18,13 +24,14 @@ header('Status: 200 OK');
18
  >
19
 
20
  <channel>
21
- <title><?php echo bp_site_name() ?> | <?php echo $bp->displayed_user->fullname; ?> | <?php _e( 'Favorite Activity', 'buddypress' ) ?></title>
22
  <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
23
- <link><?php echo site_url( BP_ACTIVITY_SLUG . '/#my-favorites/' ) ?></link>
24
  <description><?php echo $bp->displayed_user->fullname; ?> - <?php _e( 'Favorite Activity', 'buddypress' ) ?></description>
25
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_activity_get_last_updated(), false); ?></pubDate>
26
  <generator>http://buddypress.org/?v=<?php echo BP_VERSION ?></generator>
27
  <language><?php echo get_option('rss_language'); ?></language>
 
28
  <?php do_action('bp_activity_favorites_feed_head'); ?>
29
 
30
  <?php
@@ -34,9 +41,10 @@ header('Status: 200 OK');
34
 
35
  <?php if ( bp_has_activities( 'include=' . $fav_ids . '&max=50&display_comments=stream' ) ) : ?>
36
  <?php while ( bp_activities() ) : bp_the_activity(); ?>
 
37
  <item>
38
  <guid><?php bp_activity_thread_permalink() ?></guid>
39
- <title><![CDATA[<?php bp_activity_feed_item_title() ?>]]></title>
40
  <link><?php echo bp_activity_thread_permalink() ?></link>
41
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_get_activity_feed_item_date(), false); ?></pubDate>
42
 
@@ -54,10 +62,13 @@ header('Status: 200 OK');
54
  <?php endif; ?>
55
  ]]>
56
  </description>
 
57
  <?php do_action('bp_activity_favorites_feed_item'); ?>
 
58
  </item>
59
- <?php endwhile; ?>
60
 
 
61
  <?php endif; ?>
 
62
  </channel>
63
  </rss>
1
  <?php
2
+
3
  /**
4
  * RSS2 Feed Template for displaying a member's favorite activity
5
  *
6
  * @package BuddyPress
7
+ * @subpackage ActivityFeeds
8
  */
9
+
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
+
13
+ header('Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
14
  header('Status: 200 OK');
15
  ?>
16
+ <?php echo '<?xml version="1.0" encoding="' . get_option( 'blog_charset' ) . '"?'.'>'; ?>
17
 
18
  <rss version="2.0"
19
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
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>
34
+
35
  <?php do_action('bp_activity_favorites_feed_head'); ?>
36
 
37
  <?php
41
 
42
  <?php if ( bp_has_activities( 'include=' . $fav_ids . '&max=50&display_comments=stream' ) ) : ?>
43
  <?php while ( bp_activities() ) : bp_the_activity(); ?>
44
+
45
  <item>
46
  <guid><?php bp_activity_thread_permalink() ?></guid>
47
+ <title><?php bp_activity_feed_item_title() ?></title>
48
  <link><?php echo bp_activity_thread_permalink() ?></link>
49
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_get_activity_feed_item_date(), false); ?></pubDate>
50
 
62
  <?php endif; ?>
63
  ]]>
64
  </description>
65
+
66
  <?php do_action('bp_activity_favorites_feed_item'); ?>
67
+
68
  </item>
 
69
 
70
+ <?php endwhile; ?>
71
  <?php endif; ?>
72
+
73
  </channel>
74
  </rss>
bp-activity/feeds/bp-activity-friends-feed.php CHANGED
@@ -1,9 +1,15 @@
1
  <?php
 
2
  /**
3
  * RSS2 Feed Template for displaying a member's friends activity stream.
4
  *
5
  * @package BuddyPress
 
6
  */
 
 
 
 
7
  header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
8
  header('Status: 200 OK');
9
  ?>
@@ -18,35 +24,34 @@ header('Status: 200 OK');
18
  >
19
 
20
  <channel>
21
- <title><?php echo bp_site_name() ?> | <?php echo $bp->displayed_user->fullname; ?> | <?php _e( 'Friends Activity', 'buddypress' ) ?></title>
22
  <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
23
- <link><?php echo $bp->displayed_user->domain . $bp->activity->slug . '/my-friends/feed' ?></link>
24
- <description><?php printf( __( '%s - Friends Activity Feed', 'buddypress' ), $bp->displayed_user->fullname ) ?></description>
25
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_activity_get_last_updated(), false); ?></pubDate>
26
- <generator>http://buddypress.org/?v=<?php echo BP_VERSION ?></generator>
27
  <language><?php echo get_option('rss_language'); ?></language>
28
  <?php do_action('bp_activity_friends_feed_head'); ?>
29
 
30
- <?php $friend_ids = implode( ',', friends_get_friend_user_ids( $bp->displayed_user->id ) ); ?>
31
- <?php if ( bp_has_activities( 'user_id=' . $friend_ids . '&max=50&display_comments=stream' ) ) : ?>
32
  <?php while ( bp_activities() ) : bp_the_activity(); ?>
33
  <item>
34
- <guid><?php bp_activity_thread_permalink() ?></guid>
35
- <title><![CDATA[<?php bp_activity_feed_item_title() ?>]]></title>
36
- <link><?php echo bp_activity_thread_permalink() ?></link>
37
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_get_activity_feed_item_date(), false); ?></pubDate>
38
 
39
  <description>
40
  <![CDATA[
41
- <?php bp_activity_feed_item_description() ?>
42
 
43
  <?php if ( bp_activity_can_comment() ) : ?>
44
  <p><?php printf( __( 'Comments: %s', 'buddypress' ), bp_activity_get_comment_count() ); ?></p>
45
  <?php endif; ?>
46
 
47
  <?php if ( 'activity_comment' == bp_get_activity_action_name() ) : ?>
48
- <br /><strong><?php _e( 'In reply to', 'buddypress' ) ?></strong> -
49
- <?php bp_activity_parent_content() ?>
50
  <?php endif; ?>
51
  ]]>
52
  </description>
1
  <?php
2
+
3
  /**
4
  * RSS2 Feed Template for displaying a member's friends activity stream.
5
  *
6
  * @package BuddyPress
7
+ * @subpackage ActivityFeeds
8
  */
9
+
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
+
13
  header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
14
  header('Status: 200 OK');
15
  ?>
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>
30
+ <description><?php printf( __( '%s - Friends Activity Feed', 'buddypress' ), bp_get_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_friends_feed_head'); ?>
35
 
36
+ <?php if ( bp_has_activities( 'scope=friends&max=50&display_comments=stream' ) ) : ?>
 
37
  <?php while ( bp_activities() ) : bp_the_activity(); ?>
38
  <item>
39
+ <guid><?php bp_activity_thread_permalink(); ?></guid>
40
+ <title><?php bp_activity_feed_item_title(); ?></title>
41
+ <link><?php echo bp_activity_thread_permalink(); ?></link>
42
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_get_activity_feed_item_date(), false); ?></pubDate>
43
 
44
  <description>
45
  <![CDATA[
46
+ <?php bp_activity_feed_item_description(); ?>
47
 
48
  <?php if ( bp_activity_can_comment() ) : ?>
49
  <p><?php printf( __( 'Comments: %s', 'buddypress' ), bp_activity_get_comment_count() ); ?></p>
50
  <?php endif; ?>
51
 
52
  <?php if ( 'activity_comment' == bp_get_activity_action_name() ) : ?>
53
+ <br /><strong><?php _e( 'In reply to', 'buddypress' ); ?></strong> -
54
+ <?php bp_activity_parent_content(); ?>
55
  <?php endif; ?>
56
  ]]>
57
  </description>
bp-activity/feeds/bp-activity-group-feed.php CHANGED
@@ -1,9 +1,15 @@
1
  <?php
 
2
  /**
3
  * RSS2 Feed Template for displaying a group activity stream
4
  *
5
  * @package BuddyPress
 
6
  */
 
 
 
 
7
  header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
8
  header('Status: 200 OK');
9
  ?>
@@ -18,9 +24,9 @@ header('Status: 200 OK');
18
  >
19
 
20
  <channel>
21
- <title><?php echo bp_site_name() ?> | <?php echo $bp->groups->current_group->name ?> | <?php _e( 'Group Activity', 'buddypress' ) ?></title>
22
  <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
23
- <link><?php echo bp_get_group_permalink( $bp->groups->current_group ) . $bp->activity->slug . '/feed' ?></link>
24
  <description><?php printf( __( '%s - Group Activity Feed', 'buddypress' ), $bp->groups->current_group->name ) ?></description>
25
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_activity_get_last_updated(), false); ?></pubDate>
26
  <generator>http://buddypress.org/?v=<?php echo BP_VERSION ?></generator>
@@ -31,7 +37,7 @@ header('Status: 200 OK');
31
  <?php while ( bp_activities() ) : bp_the_activity(); ?>
32
  <item>
33
  <guid><?php bp_activity_thread_permalink() ?></guid>
34
- <title><![CDATA[<?php bp_activity_feed_item_title() ?>]]></title>
35
  <link><?php echo bp_activity_thread_permalink() ?></link>
36
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_get_activity_feed_item_date(), false); ?></pubDate>
37
 
1
  <?php
2
+
3
  /**
4
  * RSS2 Feed Template for displaying a group activity stream
5
  *
6
  * @package BuddyPress
7
+ * @subpackage ActivityFeeds
8
  */
9
+
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
+
13
  header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
14
  header('Status: 200 OK');
15
  ?>
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>
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>
37
  <?php while ( bp_activities() ) : bp_the_activity(); ?>
38
  <item>
39
  <guid><?php bp_activity_thread_permalink() ?></guid>
40
+ <title><?php bp_activity_feed_item_title() ?></title>
41
  <link><?php echo bp_activity_thread_permalink() ?></link>
42
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_get_activity_feed_item_date(), false); ?></pubDate>
43
 
bp-activity/feeds/bp-activity-mentions-feed.php CHANGED
@@ -1,9 +1,15 @@
1
  <?php
 
2
  /**
3
  * RSS2 Feed Template for displaying a member's group's activity
4
  *
5
  * @package BuddyPress
 
6
  */
 
 
 
 
7
  header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
8
  header('Status: 200 OK');
9
  ?>
@@ -18,9 +24,9 @@ header('Status: 200 OK');
18
  >
19
 
20
  <channel>
21
- <title><?php echo bp_site_name() ?> | <?php echo $bp->displayed_user->fullname; ?> | <?php _e( 'Mentions', 'buddypress' ) ?></title>
22
  <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
23
- <link><?php echo site_url( BP_ACTIVITY_SLUG . '/#mentions/' ) ?></link>
24
  <description><?php echo $bp->displayed_user->fullname; ?> - <?php _e( 'Mentions', 'buddypress' ) ?></description>
25
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_activity_get_last_updated(), false); ?></pubDate>
26
  <generator>http://buddypress.org/?v=<?php echo BP_VERSION ?></generator>
@@ -31,7 +37,7 @@ header('Status: 200 OK');
31
  <?php while ( bp_activities() ) : bp_the_activity(); ?>
32
  <item>
33
  <guid><?php bp_activity_thread_permalink() ?></guid>
34
- <title><![CDATA[<?php bp_activity_feed_item_title() ?>]]></title>
35
  <link><?php echo bp_activity_thread_permalink() ?></link>
36
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_get_activity_feed_item_date(), false); ?></pubDate>
37
 
1
  <?php
2
+
3
  /**
4
  * RSS2 Feed Template for displaying a member's group's activity
5
  *
6
  * @package BuddyPress
7
+ * @subpackage ActivityFeeds
8
  */
9
+
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
+
13
  header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
14
  header('Status: 200 OK');
15
  ?>
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>
37
  <?php while ( bp_activities() ) : bp_the_activity(); ?>
38
  <item>
39
  <guid><?php bp_activity_thread_permalink() ?></guid>
40
+ <title><?php bp_activity_feed_item_title() ?></title>
41
  <link><?php echo bp_activity_thread_permalink() ?></link>
42
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_get_activity_feed_item_date(), false); ?></pubDate>
43
 
bp-activity/feeds/bp-activity-mygroups-feed.php CHANGED
@@ -1,9 +1,15 @@
1
  <?php
 
2
  /**
3
  * RSS2 Feed Template for displaying a member's group's activity
4
  *
5
  * @package BuddyPress
 
6
  */
 
 
 
 
7
  header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
8
  header('Status: 200 OK');
9
  ?>
@@ -18,9 +24,9 @@ header('Status: 200 OK');
18
  >
19
 
20
  <channel>
21
- <title><?php echo bp_site_name() ?> | <?php echo $bp->displayed_user->fullname; ?> | <?php _e( 'My Groups - Public Activity', 'buddypress' ) ?></title>
22
  <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
23
- <link><?php echo site_url( BP_ACTIVITY_SLUG . '/#my-groups/' ) ?></link>
24
  <description><?php echo $bp->displayed_user->fullname; ?> - <?php _e( 'My Groups - Public Activity', 'buddypress' ) ?></description>
25
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_activity_get_last_updated(), false); ?></pubDate>
26
  <generator>http://buddypress.org/?v=<?php echo BP_VERSION ?></generator>
@@ -36,7 +42,7 @@ header('Status: 200 OK');
36
  <?php while ( bp_activities() ) : bp_the_activity(); ?>
37
  <item>
38
  <guid><?php bp_activity_thread_permalink() ?></guid>
39
- <title><![CDATA[<?php bp_activity_feed_item_title() ?>]]></title>
40
  <link><?php echo bp_activity_thread_permalink() ?></link>
41
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_get_activity_feed_item_date(), false); ?></pubDate>
42
 
1
  <?php
2
+
3
  /**
4
  * RSS2 Feed Template for displaying a member's group's activity
5
  *
6
  * @package BuddyPress
7
+ * @subpackage ActivityFeeds
8
  */
9
+
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
+
13
  header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
14
  header('Status: 200 OK');
15
  ?>
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>
42
  <?php while ( bp_activities() ) : bp_the_activity(); ?>
43
  <item>
44
  <guid><?php bp_activity_thread_permalink() ?></guid>
45
+ <title><?php bp_activity_feed_item_title() ?></title>
46
  <link><?php echo bp_activity_thread_permalink() ?></link>
47
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_get_activity_feed_item_date(), false); ?></pubDate>
48
 
bp-activity/feeds/bp-activity-personal-feed.php CHANGED
@@ -1,9 +1,15 @@
1
  <?php
 
2
  /**
3
  * RSS2 Feed Template for displaying a member's activity stream.
4
  *
5
  * @package BuddyPress
 
6
  */
 
 
 
 
7
  header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
8
  header('Status: 200 OK');
9
  ?>
@@ -18,9 +24,9 @@ header('Status: 200 OK');
18
  >
19
 
20
  <channel>
21
- <title><?php echo bp_site_name() ?> | <?php echo $bp->displayed_user->fullname; ?> | <?php _e( 'Activity', 'buddypress' ) ?></title>
22
  <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
23
- <link><?php echo $bp->displayed_user->domain . $bp->activity->slug . '/feed' ?></link>
24
  <description><?php printf( __( '%s - Activity Feed', 'buddypress' ), $bp->displayed_user->fullname ) ?></description>
25
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_activity_get_last_updated(), false); ?></pubDate>
26
  <generator>http://buddypress.org/?v=<?php echo BP_VERSION ?></generator>
@@ -31,7 +37,7 @@ header('Status: 200 OK');
31
  <?php while ( bp_activities() ) : bp_the_activity(); ?>
32
  <item>
33
  <guid><?php bp_activity_thread_permalink() ?></guid>
34
- <title><![CDATA[<?php bp_activity_feed_item_title() ?>]]></title>
35
  <link><?php echo bp_activity_thread_permalink() ?></link>
36
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_get_activity_feed_item_date(), false); ?></pubDate>
37
 
1
  <?php
2
+
3
  /**
4
  * RSS2 Feed Template for displaying a member's activity stream.
5
  *
6
  * @package BuddyPress
7
+ * @subpackage ActivityFeeds
8
  */
9
+
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
+
13
  header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
14
  header('Status: 200 OK');
15
  ?>
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>
37
  <?php while ( bp_activities() ) : bp_the_activity(); ?>
38
  <item>
39
  <guid><?php bp_activity_thread_permalink() ?></guid>
40
+ <title><?php bp_activity_feed_item_title() ?></title>
41
  <link><?php echo bp_activity_thread_permalink() ?></link>
42
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_get_activity_feed_item_date(), false); ?></pubDate>
43
 
bp-activity/feeds/bp-activity-sitewide-feed.php CHANGED
@@ -1,10 +1,15 @@
1
  <?php
 
2
  /**
3
  * RSS2 Feed Template for displaying the site wide activity stream.
4
  *
5
  * @package BuddyPress
 
6
  */
7
 
 
 
 
8
  header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
9
  header('Status: 200 OK');
10
  ?>
@@ -19,9 +24,9 @@ header('Status: 200 OK');
19
  >
20
 
21
  <channel>
22
- <title><?php echo bp_site_name() ?> | <?php _e( 'Site Wide Activity', 'buddypress' ) ?></title>
23
  <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
24
- <link><?php echo site_url() . '/' . $bp->activity->slug . '/feed' ?></link>
25
  <description><?php _e( 'Site Wide Activity Feed', 'buddypress' ) ?></description>
26
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_activity_get_last_updated(), false); ?></pubDate>
27
  <generator>http://buddypress.org/?v=<?php echo BP_VERSION ?></generator>
@@ -32,7 +37,7 @@ header('Status: 200 OK');
32
  <?php while ( bp_activities() ) : bp_the_activity(); ?>
33
  <item>
34
  <guid><?php bp_activity_thread_permalink() ?></guid>
35
- <title><![CDATA[<?php bp_activity_feed_item_title() ?>]]></title>
36
  <link><?php bp_activity_thread_permalink() ?></link>
37
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_get_activity_feed_item_date(), false); ?></pubDate>
38
 
1
  <?php
2
+
3
  /**
4
  * RSS2 Feed Template for displaying the site wide activity stream.
5
  *
6
  * @package BuddyPress
7
+ * @subpackage ActivityFeeds
8
  */
9
 
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
+
13
  header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
14
  header('Status: 200 OK');
15
  ?>
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>
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>
37
  <?php while ( bp_activities() ) : bp_the_activity(); ?>
38
  <item>
39
  <guid><?php bp_activity_thread_permalink() ?></guid>
40
+ <title><?php bp_activity_feed_item_title() ?></title>
41
  <link><?php bp_activity_thread_permalink() ?></link>
42
  <pubDate><?php echo mysql2date('D, d M Y H:i:s O', bp_get_activity_feed_item_date(), false); ?></pubDate>
43
 
bp-blogs.php DELETED
@@ -1,821 +0,0 @@
1
- <?php
2
-
3
- define ( 'BP_BLOGS_DB_VERSION', '2015' );
4
-
5
- /* Define the slug for the component */
6
- if ( !defined( 'BP_BLOGS_SLUG' ) )
7
- define ( 'BP_BLOGS_SLUG', 'blogs' );
8
-
9
- require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-classes.php' );
10
- require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-templatetags.php' );
11
-
12
- /* Include the sitewide blog posts widget if this is a multisite installation */
13
- if ( bp_core_is_multisite() )
14
- require ( BP_PLUGIN_DIR . '/bp-blogs/bp-blogs-widgets.php' );
15
-
16
- function bp_blogs_install() {
17
- global $wpdb, $bp;
18
-
19
- if ( !empty($wpdb->charset) )
20
- $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
21
-
22
- $sql[] = "CREATE TABLE {$bp->blogs->table_name} (
23
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
24
- user_id bigint(20) NOT NULL,
25
- blog_id bigint(20) NOT NULL,
26
- KEY user_id (user_id),
27
- KEY blog_id (blog_id)
28
- ) {$charset_collate};";
29
-
30
- $sql[] = "CREATE TABLE {$bp->blogs->table_name_blogmeta} (
31
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
32
- blog_id bigint(20) NOT NULL,
33
- meta_key varchar(255) DEFAULT NULL,
34
- meta_value longtext DEFAULT NULL,
35
- KEY blog_id (blog_id),
36
- KEY meta_key (meta_key)
37
- ) {$charset_collate};";
38
-
39
-
40
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
41
-
42
- dbDelta($sql);
43
-
44
- // On first installation - record all existing blogs in the system.
45
- if ( !(int)get_site_option('bp-blogs-first-install') && bp_core_is_multisite() ) {
46
- bp_blogs_record_existing_blogs();
47
- add_site_option( 'bp-blogs-first-install', 1 );
48
- }
49
-
50
- update_site_option( 'bp-blogs-db-version', BP_BLOGS_DB_VERSION );
51
- }
52
-
53
- function bp_blogs_check_installed() {
54
- global $wpdb, $bp, $userdata;
55
-
56
- /* Only create the bp-blogs tables if this is a multisite install */
57
- if ( is_super_admin() && bp_core_is_multisite() ) {
58
- /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
59
- if ( get_site_option( 'bp-blogs-db-version' ) < BP_BLOGS_DB_VERSION )
60
- bp_blogs_install();
61
- }
62
- }
63
- add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', 'bp_blogs_check_installed' );
64
-
65
- function bp_blogs_setup_globals() {
66
- global $bp, $wpdb;
67
-
68
- /* For internal identification */
69
- $bp->blogs->id = 'blogs';
70
-
71
- $bp->blogs->slug = BP_BLOGS_SLUG;
72
-
73
- $bp->blogs->table_name = $bp->table_prefix . 'bp_user_blogs';
74
- $bp->blogs->table_name_blogmeta = $bp->table_prefix . 'bp_user_blogs_blogmeta';
75
-
76
- $bp->blogs->format_notification_function = 'bp_blogs_format_notifications';
77
-
78
- /* Register this in the active components array */
79
- $bp->active_components[$bp->blogs->slug] = $bp->blogs->id;
80
-
81
- do_action( 'bp_blogs_setup_globals' );
82
- }
83
- add_action( 'bp_setup_globals', 'bp_blogs_setup_globals' );
84
-
85
- function bp_blogs_setup_root_component() {
86
- /* Register 'blogs' as a root component */
87
- bp_core_add_root_component( BP_BLOGS_SLUG );
88
- }
89
- add_action( 'bp_setup_root_components', 'bp_blogs_setup_root_component' );
90
-
91
- /**
92
- * bp_blogs_setup_nav()
93
- *
94
- * Adds "Blog" to the navigation arrays for the current and logged in user.
95
- *
96
- * @package BuddyPress Blogs
97
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
98
- * @uses bp_is_my_profile() Checks to see if the current user being viewed is the logged in user
99
- */
100
- function bp_blogs_setup_nav() {
101
- global $bp;
102
-
103
- /* Blog/post/comment menus should not appear on single WordPress setups. Although comments
104
- and posts made by users will still show on their activity stream .*/
105
- if ( !bp_core_is_multisite() )
106
- return false;
107
-
108
- /* Add 'Blogs' to the main navigation */
109
- bp_core_new_nav_item( array( 'name' => sprintf( __( 'Blogs <span>(%d)</span>', 'buddypress' ), bp_blogs_total_blogs_for_user() ), 'slug' => $bp->blogs->slug, 'position' => 30, 'screen_function' => 'bp_blogs_screen_my_blogs', 'default_subnav_slug' => 'my-blogs', 'item_css_id' => $bp->blogs->id ) );
110
-
111
- $blogs_link = $bp->loggedin_user->domain . $bp->blogs->slug . '/';
112
-
113
- /* Set up the component options navigation for Blog */
114
- if ( 'blogs' == $bp->current_component ) {
115
- if ( bp_is_my_profile() ) {
116
- if ( function_exists('xprofile_setup_nav') ) {
117
- $bp->bp_options_title = __('My Blogs', 'buddypress');
118
- }
119
- } else {
120
- /* If we are not viewing the logged in user, set up the current users avatar and name */
121
- $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
122
- $bp->bp_options_title = $bp->displayed_user->fullname;
123
- }
124
- }
125
-
126
- do_action( 'bp_blogs_setup_nav' );
127
- }
128
- add_action( 'bp_setup_nav', 'bp_blogs_setup_nav' );
129
-
130
- function bp_blogs_directory_blogs_setup() {
131
- global $bp;
132
-
133
- if ( bp_core_is_multisite() && $bp->current_component == $bp->blogs->slug && empty( $bp->current_action ) ) {
134
- $bp->is_directory = true;
135
-
136
- do_action( 'bp_blogs_directory_blogs_setup' );
137
- bp_core_load_template( apply_filters( 'bp_blogs_template_directory_blogs_setup', 'blogs/index' ) );
138
- }
139
- }
140
- add_action( 'wp', 'bp_blogs_directory_blogs_setup', 2 );
141
-
142
-
143
- /********************************************************************************
144
- * Screen Functions
145
- *
146
- * Screen functions are the controllers of BuddyPress. They will execute when their
147
- * specific URL is caught. They will first save or manipulate data using business
148
- * functions, then pass on the user to a template file.
149
- */
150
-
151
- function bp_blogs_screen_my_blogs() {
152
- global $bp;
153
-
154
- if ( !bp_core_is_multisite() )
155
- return false;
156
-
157
- do_action( 'bp_blogs_screen_my_blogs' );
158
- bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'members/single/home' ) );
159
- }
160
-
161
- function bp_blogs_screen_create_a_blog() {
162
- global $bp;
163
-
164
- if ( !bp_core_is_multisite() || $bp->current_component != $bp->blogs->slug || 'create' != $bp->current_action )
165
- return false;
166
-
167
- if ( !is_user_logged_in() || !bp_blog_signup_enabled() )
168
- return false;
169
-
170
- do_action( 'bp_blogs_screen_create_a_blog' );
171
- bp_core_load_template( apply_filters( 'bp_blogs_template_create_a_blog', 'blogs/create' ) );
172
- }
173
- /* The create screen is not attached to a nav item, so we need to attach it to an action */
174
- add_action( 'wp', 'bp_blogs_screen_create_a_blog', 3 );
175
-
176
-
177
- /********************************************************************************
178
- * Activity & Notification Functions
179
- *
180
- * These functions handle the recording, deleting and formatting of activity and
181
- * notifications for the user and for this specific component.
182
- */
183
-
184
- function bp_blogs_register_activity_actions() {
185
- global $bp;
186
-
187
- if ( !function_exists( 'bp_activity_set_action' ) )
188
- return false;
189
-
190
- bp_activity_set_action( $bp->blogs->id, 'new_blog', __( 'New blog created', 'buddypress' ) );
191
- bp_activity_set_action( $bp->blogs->id, 'new_blog_post', __( 'New blog post published', 'buddypress' ) );
192
- bp_activity_set_action( $bp->blogs->id, 'new_blog_comment', __( 'New blog post comment posted', 'buddypress' ) );
193
-
194
- do_action( 'bp_blogs_register_activity_actions' );
195
- }
196
- add_action( 'bp_register_activity_actions', 'bp_blogs_register_activity_actions' );
197
-
198
- function bp_blogs_record_activity( $args = '' ) {
199
- global $bp;
200
-
201
- if ( !function_exists( 'bp_activity_add' ) )
202
- return false;
203
-
204
- /* Because blog, comment, and blog post code execution happens before anything else
205
- we may need to manually instantiate the activity component globals */
206
- if ( !$bp->activity && function_exists('bp_activity_setup_globals') )
207
- bp_activity_setup_globals();
208
-
209
- $defaults = array(
210
- 'user_id' => $bp->loggedin_user->id,
211
- 'action' => '',
212
- 'content' => '',
213
- 'primary_link' => '',
214
- 'component' => $bp->blogs->id,
215
- 'type' => false,
216
- 'item_id' => false,
217
- 'secondary_item_id' => false,
218
- 'recorded_time' => bp_core_current_time(),
219
- 'hide_sitewide' => false
220
- );
221
-
222
- $r = wp_parse_args( $args, $defaults );
223
- extract( $r, EXTR_SKIP );
224
-
225
- /* Remove large images and replace them with just one image thumbnail */
226
- if ( function_exists( 'bp_activity_thumbnail_content_images' ) && !empty( $content ) )
227
- $content = bp_activity_thumbnail_content_images( $content );
228
-
229
- if ( !empty( $action ) )
230
- $action = apply_filters( 'bp_blogs_record_activity_action', $action );
231
-
232
- if ( !empty( $content ) )
233
- $content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $content ), $content );
234
-
235
- /* Check for an existing entry and update if one exists. */
236
- $id = bp_activity_get_activity_id( array(
237
- 'user_id' => $user_id,
238
- 'component' => $component,
239
- 'type' => $type,
240
- 'item_id' => $item_id,
241
- 'secondary_item_id' => $secondary_item_id
242
- ) );
243
-
244
- 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 ) );
245
- }
246
-
247
- function bp_blogs_delete_activity( $args = true ) {
248
- global $bp;
249
-
250
- if ( function_exists('bp_activity_delete_by_item_id') ) {
251
- $defaults = array(
252
- 'item_id' => false,
253
- 'component' => $bp->blogs->id,
254
- 'type' => false,
255
- 'user_id' => false,
256
- 'secondary_item_id' => false
257
- );
258
-
259
- $params = wp_parse_args( $args, $defaults );
260
- extract( $params, EXTR_SKIP );
261
-
262
- bp_activity_delete_by_item_id( array(
263
- 'item_id' => $item_id,
264
- 'component' => $component,
265
- 'type' => $type,
266
- 'user_id' => $user_id,
267
- 'secondary_item_id' => $secondary_item_id
268
- ) );
269
- }
270
- }
271
-
272
- /********************************************************************************
273
- * Business Functions
274
- *
275
- * Business functions are where all the magic happens in BuddyPress. They will
276
- * handle the actual saving or manipulation of information. Usually they will
277
- * hand off to a database class for data access, then return
278
- * true or false on success or failure.
279
- */
280
-
281
- function bp_blogs_get_blogs( $args = '' ) {
282
- global $bp;
283
-
284
- $defaults = array(
285
- 'type' => 'active', // active, alphabetical, newest, or random.
286
- 'user_id' => false, // Pass a user_id to limit to only blogs that this user has privilages higher than subscriber on.
287
- 'search_terms' => false, // Limit to blogs that match these search terms
288
-
289
- 'per_page' => 20, // The number of results to return per page
290
- 'page' => 1, // The page to return if limiting per page
291
- );
292
-
293
- $params = wp_parse_args( $args, $defaults );
294
- extract( $params, EXTR_SKIP );
295
-
296
- return apply_filters( 'bp_blogs_get_blogs', BP_Blogs_Blog::get( $type, $per_page, $page, $user_id, $search_terms ), &$params );
297
- }
298
-
299
- function bp_blogs_record_existing_blogs() {
300
- global $bp, $wpdb;
301
-
302
- /* Truncate user blogs table and re-record. */
303
- $wpdb->query( "TRUNCATE TABLE {$bp->blogs->table_name}" );
304
-
305
- $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$wpdb->base_prefix}blogs WHERE mature = 0 AND spam = 0 AND deleted = 0" ) );
306
-
307
- if ( $blog_ids ) {
308
- foreach( (array)$blog_ids as $blog_id ) {
309
- $users = get_users_of_blog( $blog_id );
310
-
311
- if ( $users ) {
312
- foreach ( (array)$users as $user ) {
313
- $role = unserialize( $user->meta_value );
314
-
315
- if ( !isset( $role['subscriber'] ) )
316
- bp_blogs_record_blog( $blog_id, $user->user_id, true );
317
- }
318
- }
319
- }
320
- }
321
- }
322
-
323
- /**
324
- * Makes BuddyPress aware of a new site so that it can track its activity.
325
- *
326
- * @global object $bp BuddyPress global settings
327
- * @param int $blog_id
328
- * @param int $user_id
329
- * @param $bool $no_activity ; optional.
330
- * @since 1.0
331
- * @uses BP_Blogs_Blog
332
- */
333
- function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) {
334
- global $bp;
335
-
336
- if ( !$user_id )
337
- $user_id = $bp->loggedin_user->id;
338
-
339
- $name = get_blog_option( $blog_id, 'blogname' );
340
- $description = get_blog_option( $blog_id, 'blogdescription' );
341
-
342
- if ( empty( $name ) )
343
- return false;
344
-
345
- $recorded_blog = new BP_Blogs_Blog;
346
- $recorded_blog->user_id = $user_id;
347
- $recorded_blog->blog_id = $blog_id;
348
-
349
- $recorded_blog_id = $recorded_blog->save();
350
-
351
- bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'name', $name );
352
- bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description );
353
- bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', bp_core_current_time() );
354
-
355
- // Only record this activity if the blog is public
356
- if ( (int)$_POST['blog_public'] && !$no_activity ) {
357
- // Record this in activity streams
358
- bp_blogs_record_activity( array(
359
- 'user_id' => $recorded_blog->user_id,
360
- 'action' => apply_filters( 'bp_blogs_activity_created_blog_action', sprintf( __( '%s created the blog %s', 'buddypress'), bp_core_get_userlink( $recorded_blog->user_id ), '<a href="' . get_site_url( $recorded_blog->blog_id ) . '">' . esc_attr( $name ) . '</a>' ), &$recorded_blog, $name, $description ),
361
- 'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', get_site_url( $recorded_blog->blog_id ), $recorded_blog->blog_id ),
362
- 'type' => 'new_blog',
363
- 'item_id' => $recorded_blog->blog_id
364
- ) );
365
- }
366
-
367
- do_action( 'bp_blogs_new_blog', &$recorded_blog, $is_private, $is_recorded );
368
- }
369
- add_action( 'wpmu_new_blog', 'bp_blogs_record_blog', 10, 2 );
370
-
371
- /**
372
- * bp_blogs_update_option_blogname()
373
- *
374
- * Updates blogname in BuddyPress blogmeta table
375
- *
376
- * @global object $wpdb DB Layer
377
- * @param string $oldvalue Value before save (not used)
378
- * @param string $newvalue Value to change meta to
379
- */
380
- function bp_blogs_update_option_blogname( $oldvalue, $newvalue ) {
381
- global $wpdb;
382
- bp_blogs_update_blogmeta( $wpdb->blogid, 'name', $newvalue );
383
- }
384
- add_action( 'update_option_blogname', 'bp_blogs_update_option_blogname', 10, 2 );
385
-
386
- /**
387
- * bp_blogs_update_option_blogdescription()
388
- *
389
- * Updates blogdescription in BuddyPress blogmeta table
390
- *
391
- * @global object $wpdb DB Layer
392
- * @param string $oldvalue Value before save (not used)
393
- * @param string $newvalue Value to change meta to
394
- */
395
- function bp_blogs_update_option_blogdescription( $oldvalue, $newvalue ) {
396
- global $wpdb;
397
- bp_blogs_update_blogmeta( $wpdb->blogid, 'description', $newvalue );
398
- }
399
- add_action( 'update_option_blogdescription', 'bp_blogs_update_option_blogdescription', 10, 2 );
400
-
401
- function bp_blogs_record_post( $post_id, $post, $user_id = false ) {
402
- global $bp, $wpdb;
403
-
404
- $post_id = (int)$post_id;
405
- $blog_id = (int)$wpdb->blogid;
406
-
407
- if ( !$user_id )
408
- $user_id = (int)$post->post_author;
409
-
410
- // This is to stop infinite loops with Donncha's sitewide tags plugin
411
- if ( (int)$blog_id == (int)$bp->site_options['tags_blog_id'] )
412
- return false;
413
-
414
- // Don't record this if it's not a post
415
- if ( 'post' != $post->post_type )
416
- return false;
417
-
418
- if ( 'publish' == $post->post_status && empty( $post->post_password ) ) {
419
- if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
420
- // Record this in activity streams
421
- $post_permalink = get_permalink( $post_id );
422
- $activity_action = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
423
- $activity_content = $post->post_content;
424
-
425
- bp_blogs_record_activity( array(
426
- 'user_id' => (int)$post->post_author,
427
- 'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, &$post, $post_permalink ),
428
- 'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink ),
429
- 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
430
- 'type' => 'new_blog_post',
431
- 'item_id' => $blog_id,
432
- 'secondary_item_id' => $post_id,
433
- 'recorded_time' => $post->post_date_gmt
434
- ));
435
- }
436
-
437
- // Update the blogs last activity
438
- bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
439
- } else {
440
- bp_blogs_remove_post( $post_id, $blog_id );
441
- }
442
-
443
- do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
444
- }
445
- add_action( 'save_post', 'bp_blogs_record_post', 10, 2 );
446
-
447
- /**
448
- * bp_blogs_record_comment()
449
- *
450
- * Record blog comment activity. Checks if blog is public and post is not
451
- * password protected.
452
- *
453
- * @global object $wpdb
454
- * @global $bp $bp
455
- * @param int $comment_id
456
- * @param bool $is_approved
457
- * @return mixed
458
- */
459
-
460
- function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
461
- global $wpdb, $bp;
462
-
463
- // Get the users comment
464
- $recorded_comment = get_comment( $comment_id );
465
-
466
- // Don't record activity if the comment hasn't been approved
467
- if ( empty( $is_approved ) )
468
- return false;
469
-
470
- // Don't record activity if no email address has been included
471
- if ( empty( $recorded_comment->comment_author_email ) )
472
- return false;
473
-
474
- // Get the user_id from the comment author email.
475
- $user = get_user_by_email( $recorded_comment->comment_author_email );
476
- $user_id = (int)$user->ID;
477
-
478
- // If there's no registered user id, don't record activity
479
- if ( empty( $user_id ) )
480
- return false;
481
-
482
- // Get blog and post data
483
- $blog_id = (int)$wpdb->blogid;
484
- $recorded_comment->post = get_post( $recorded_comment->comment_post_ID );
485
-
486
- // If this is a password protected post, don't record the comment
487
- if ( !empty( $recorded_comment->post->post_password ) )
488
- return false;
489
-
490
- // If blog is public allow activity to be posted
491
- if ( get_blog_option( $blog_id, 'blog_public' ) ) {
492
-
493
- // Get activity related links
494
- $post_permalink = get_permalink( $recorded_comment->comment_post_ID );
495
- $comment_link = htmlspecialchars( get_comment_link( $recorded_comment->comment_ID ) );
496
-
497
- // Prepare to record in activity streams
498
- $activity_action = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>' );
499
- $activity_content = $recorded_comment->comment_content;
500
-
501
- // Record in activity streams
502
- bp_blogs_record_activity( array(
503
- 'user_id' => $user_id,
504
- 'action' => apply_filters( 'bp_blogs_activity_new_comment_action', $activity_action, &$recorded_comment, $comment_link ),
505
- 'content' => apply_filters( 'bp_blogs_activity_new_comment_content', $activity_content, &$recorded_comment, $comment_link ),
506
- 'primary_link' => apply_filters( 'bp_blogs_activity_new_comment_primary_link', $comment_link, &$recorded_comment ),
507
- 'type' => 'new_blog_comment',
508
- 'item_id' => $blog_id,
509
- 'secondary_item_id' => $comment_id,
510
- 'recorded_time' => $recorded_comment->comment_date_gmt
511
- ) );
512
-
513
- // Update the blogs last active date
514
- bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
515
- }
516
-
517
- return $recorded_comment;
518
- }
519
- add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
520
- add_action( 'edit_comment', 'bp_blogs_record_comment', 10 );
521
-
522
- function bp_blogs_manage_comment( $comment_id, $comment_status ) {
523
- if ( 'spam' == $comment_status || 'hold' == $comment_status || 'delete' == $comment_status || 'trash' == $comment_status )
524
- return bp_blogs_remove_comment( $comment_id );
525
-
526
- return bp_blogs_record_comment( $comment_id, true );
527
- }
528
- add_action( 'wp_set_comment_status', 'bp_blogs_manage_comment', 10, 2 );
529
-
530
- function bp_blogs_add_user_to_blog( $user_id, $role, $blog_id = false ) {
531
- global $current_blog;
532
-
533
- if ( empty( $blog_id ) )
534
- $blog_id = $current_blog->blog_id;
535
-
536
- if ( $role != 'subscriber' )
537
- bp_blogs_record_blog( $blog_id, $user_id, true );
538
- }
539
- add_action( 'add_user_to_blog', 'bp_blogs_add_user_to_blog', 10, 3 );
540
-
541
- function bp_blogs_remove_user_from_blog( $user_id, $blog_id = false ) {
542
- global $current_blog;
543
-
544
- if ( empty( $blog_id ) )
545
- $blog_id = $current_blog->blog_id;
546
-
547
- bp_blogs_remove_blog_for_user( $user_id, $blog_id );
548
- }
549
- add_action( 'remove_user_from_blog', 'bp_blogs_remove_user_from_blog', 10, 2 );
550
-
551
- function bp_blogs_remove_blog( $blog_id ) {
552
- global $bp;
553
-
554
- $blog_id = (int)$blog_id;
555
-
556
- BP_Blogs_Blog::delete_blog_for_all( $blog_id );
557
-
558
- // Delete activity stream item
559
- bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog' ) );
560
-
561
- do_action( 'bp_blogs_remove_blog', $blog_id );
562
- }
563
- add_action( 'delete_blog', 'bp_blogs_remove_blog' );
564
-
565
- function bp_blogs_remove_blog_for_user( $user_id, $blog_id ) {
566
- global $current_user;
567
-
568
- $blog_id = (int)$blog_id;
569
- $user_id = (int)$user_id;
570
-
571
- BP_Blogs_Blog::delete_blog_for_user( $blog_id, $user_id );
572
-
573
- // Delete activity stream item
574
- bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog' ) );
575
-
576
- do_action( 'bp_blogs_remove_blog_for_user', $blog_id, $user_id );
577
- }
578
- add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 );
579
-
580
- function bp_blogs_remove_post( $post_id, $blog_id = false ) {
581
- global $current_blog, $bp;
582
-
583
- $post_id = (int)$post_id;
584
-
585
- if ( !$blog_id )
586
- $blog_id = (int)$current_blog->blog_id;
587
-
588
- // Delete activity stream item
589
- bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog_post' ) );
590
-
591
- do_action( 'bp_blogs_remove_post', $blog_id, $post_id, $post->user_id );
592
- }
593
- add_action( 'delete_post', 'bp_blogs_remove_post' );
594
-
595
- function bp_blogs_remove_comment( $comment_id ) {
596
- global $wpdb, $bp;
597
-
598
- // Delete activity stream item
599
- bp_blogs_delete_activity( array( 'item_id' => $wpdb->blogid , 'secondary_item_id' => $comment_id, 'type' => 'new_blog_comment' ) );
600
-
601
- do_action( 'bp_blogs_remove_comment', $blog_id, $comment_id, $bp->loggedin_user->id );
602
- }
603
- add_action( 'delete_comment', 'bp_blogs_remove_comment' );
604
-
605
- function bp_blogs_total_blogs() {
606
- if ( !$count = wp_cache_get( 'bp_total_blogs', 'bp' ) ) {
607
- $blogs = BP_Blogs_Blog::get_all();
608
- $count = $blogs['total'];
609
- wp_cache_set( 'bp_total_blogs', $count, 'bp' );
610
- }
611
- return $count;
612
- }
613
-
614
- function bp_blogs_total_blogs_for_user( $user_id = false ) {
615
- global $bp;
616
-
617
- if ( !$user_id )
618
- $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
619
-
620
- if ( !$count = wp_cache_get( 'bp_total_blogs_for_user_' . $user_id, 'bp' ) ) {
621
- $count = BP_Blogs_Blog::total_blog_count_for_user( $user_id );
622
- wp_cache_set( 'bp_total_blogs_for_user_' . $user_id, $count, 'bp' );
623
- }
624
-
625
- return $count;
626
- }
627
-
628
- function bp_blogs_remove_data_for_blog( $blog_id ) {
629
- global $bp;
630
-
631
- /* If this is regular blog, delete all data for that blog. */
632
- BP_Blogs_Blog::delete_blog_for_all( $blog_id );
633
-
634
- // Delete activity stream item
635
- bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->slug, 'type' => false ) );
636
-
637
- do_action( 'bp_blogs_remove_data_for_blog', $blog_id );
638
- }
639
- add_action( 'delete_blog', 'bp_blogs_remove_data_for_blog', 1 );
640
-
641
- function bp_blogs_get_blogs_for_user( $user_id, $show_hidden = false ) {
642
- return BP_Blogs_Blog::get_blogs_for_user( $user_id, $show_hidden );
643
- }
644
-
645
- function bp_blogs_get_all_blogs( $limit = null, $page = null ) {
646
- return BP_Blogs_Blog::get_all( $limit, $page );
647
- }
648
-
649
- function bp_blogs_get_random_blogs( $limit = null, $page = null ) {
650
- return BP_Blogs_Blog::get( 'random', $limit, $page );
651
- }
652
-
653
- function bp_blogs_is_blog_hidden( $blog_id ) {
654
- return BP_Blogs_Blog::is_hidden( $blog_id );
655
- }
656
-
657
- function bp_blogs_redirect_to_random_blog() {
658
- global $bp, $wpdb;
659
-
660
- if ( $bp->current_component == $bp->blogs->slug && isset( $_GET['random-blog'] ) ) {
661
- $blog = bp_blogs_get_random_blogs( 1, 1 );
662
-
663
- bp_core_redirect( get_site_url( $blog['blogs'][0]->blog_id ) );
664
- }
665
- }
666
- add_action( 'wp', 'bp_blogs_redirect_to_random_blog', 6 );
667
-
668
-
669
- //
670
- // Blog meta functions
671
- // These functions are used to store specific blogmeta in one global table, rather than in each
672
- // blog's options table. Significantly speeds up global blog queries.
673
- // By default each blog's name, description and last updated time are stored and synced here.
674
- //
675
-
676
- function bp_blogs_delete_blogmeta( $blog_id, $meta_key = false, $meta_value = false ) {
677
- global $wpdb, $bp;
678
-
679
- if ( !is_numeric( $blog_id ) || !bp_core_is_multisite() )
680
- return false;
681
-
682
- $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
683
-
684
- if ( is_array($meta_value) || is_object($meta_value) )
685
- $meta_value = serialize($meta_value);
686
-
687
- $meta_value = trim( $meta_value );
688
-
689
- if ( !$meta_key ) {
690
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d", $blog_id ) );
691
- } else if ( $meta_value ) {
692
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s AND meta_value = %s", $blog_id, $meta_key, $meta_value ) );
693
- } else {
694
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key ) );
695
- }
696
-
697
- wp_cache_delete( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, 'bp' );
698
-
699
- return true;
700
- }
701
-
702
- function bp_blogs_get_blogmeta( $blog_id, $meta_key = '') {
703
- global $wpdb, $bp;
704
-
705
- $blog_id = (int) $blog_id;
706
-
707
- if ( !$blog_id || !bp_core_is_multisite() )
708
- return false;
709
-
710
- if ( !empty($meta_key) ) {
711
- $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
712
-
713
- if ( !$metas = wp_cache_get( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, 'bp' ) ) {
714
- $metas = $wpdb->get_col( $wpdb->prepare( "SELECT meta_value FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key ) );
715
- wp_cache_set( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, $metas, 'bp' );
716
- }
717
- } else {
718
- $metas = $wpdb->get_col( $wpdb->prepare("SELECT meta_value FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d", $blog_id) );
719
- }
720
-
721
- if ( empty($metas) ) {
722
- if ( empty($meta_key) )
723
- return array();
724
- else
725
- return '';
726
- }
727
-
728
- $metas = array_map('maybe_unserialize', (array)$metas);
729
-
730
- if ( 1 == count($metas) )
731
- return $metas[0];
732
- else
733
- return $metas;
734
- }
735
-
736
- function bp_blogs_update_blogmeta( $blog_id, $meta_key, $meta_value ) {
737
- global $wpdb, $bp;
738
-
739
- if ( !is_numeric( $blog_id ) || !bp_core_is_multisite() )
740
- return false;
741
-
742
- $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
743
-
744
- if ( is_string($meta_value) )
745
- $meta_value = stripslashes($wpdb->escape($meta_value));
746
-
747
- $meta_value = maybe_serialize($meta_value);
748
-
749
- if (empty($meta_value)) {
750
- return bp_blogs_delete_blogmeta( $blog_id, $meta_key );
751
- }
752
-
753
- $cur = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key ) );
754
-
755
- if ( !$cur ) {
756
- $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name_blogmeta} ( blog_id, meta_key, meta_value ) VALUES ( %d, %s, %s )", $blog_id, $meta_key, $meta_value ) );
757
- } else if ( $cur->meta_value != $meta_value ) {
758
- $wpdb->query( $wpdb->prepare( "UPDATE {$bp->blogs->table_name_blogmeta} SET meta_value = %s WHERE blog_id = %d AND meta_key = %s", $meta_value, $blog_id, $meta_key ) );
759
- } else {
760
- return false;
761
- }
762
-
763
- wp_cache_set( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, $metas, 'bp' );
764
-
765
- return true;
766
- }
767
-
768
- function bp_blogs_remove_data( $user_id ) {
769
- if ( !bp_core_is_multisite() )
770
- return false;
771
-
772
- /* If this is regular blog, delete all data for that blog. */
773
- BP_Blogs_Blog::delete_blogs_for_user( $user_id );
774
-
775
- do_action( 'bp_blogs_remove_data', $user_id );
776
- }
777
- add_action( 'wpmu_delete_user', 'bp_blogs_remove_data' );
778
- add_action( 'delete_user', 'bp_blogs_remove_data' );
779
- add_action( 'make_spam_user', 'bp_blogs_remove_data' );
780
-
781
-
782
- /********************************************************************************
783
- * Caching
784
- *
785
- * Caching functions handle the clearing of cached objects and pages on specific
786
- * actions throughout BuddyPress.
787
- */
788
-
789
- function bp_blogs_clear_blog_object_cache( $blog_id, $user_id ) {
790
- wp_cache_delete( 'bp_blogs_of_user_' . $user_id, 'bp' );
791
- wp_cache_delete( 'bp_blogs_for_user_' . $user_id, 'bp' );
792
- wp_cache_delete( 'bp_total_blogs_for_user_' . $user_id, 'bp' );
793
-
794
- /* Clear the sitewide activity cache */
795
- wp_cache_delete( 'sitewide_activity', 'bp' );
796
- }
797
-
798
- function bp_blogs_format_clear_blog_cache( $recorded_blog_obj ) {
799
- bp_blogs_clear_blog_object_cache( false, $recorded_blog_obj->user_id );
800
-
801
- /* Clear the sitewide activity cache */
802
- wp_cache_delete( 'sitewide_activity', 'bp' );
803
- wp_cache_delete( 'bp_total_blogs', 'bp' );
804
- }
805
-
806
- // List actions to clear object caches on
807
- add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 );
808
- add_action( 'bp_blogs_new_blog', 'bp_blogs_format_clear_blog_cache', 10, 2 );
809
-
810
- // List actions to clear super cached pages on, if super cache is installed
811
- add_action( 'bp_blogs_remove_data_for_blog', 'bp_core_clear_cache' );
812
- add_action( 'bp_blogs_remove_comment', 'bp_core_clear_cache' );
813
- add_action( 'bp_blogs_remove_post', 'bp_core_clear_cache' );
814
- add_action( 'bp_blogs_remove_blog_for_user', 'bp_core_clear_cache' );
815
- add_action( 'bp_blogs_remove_blog', 'bp_core_clear_cache' );
816
- add_action( 'bp_blogs_new_blog_comment', 'bp_core_clear_cache' );
817
- add_action( 'bp_blogs_new_blog_post', 'bp_core_clear_cache' );
818
- add_action( 'bp_blogs_new_blog', 'bp_core_clear_cache' );
819
- add_action( 'bp_blogs_remove_data', 'bp_core_clear_cache' );
820
-
821
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-blogs/bp-blogs-actions.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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' ) );
18
+ bp_activity_set_action( $bp->blogs->id, 'new_blog_post', __( 'New post published', 'buddypress' ) );
19
+ bp_activity_set_action( $bp->blogs->id, 'new_blog_comment', __( 'New post comment posted', 'buddypress' ) );
20
+
21
+ do_action( 'bp_blogs_register_activity_actions' );
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' => '',
36
+ 'component' => $bp->blogs->id,
37
+ 'type' => false,
38
+ 'item_id' => false,
39
+ 'secondary_item_id' => false,
40
+ 'recorded_time' => bp_core_current_time(),
41
+ 'hide_sitewide' => false
42
+ );
43
+
44
+ $r = wp_parse_args( $args, $defaults );
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 ) )
52
+ $action = apply_filters( 'bp_blogs_record_activity_action', $action );
53
+
54
+ if ( !empty( $content ) )
55
+ $content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $content ), $content );
56
+
57
+ // Check for an existing entry and update if one exists.
58
+ $id = bp_activity_get_activity_id( array(
59
+ 'user_id' => $user_id,
60
+ 'component' => $component,
61
+ 'type' => $type,
62
+ 'item_id' => $item_id,
63
+ 'secondary_item_id' => $secondary_item_id
64
+ ) );
65
+
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 ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
9
+ if ( !is_user_logged_in() || !bp_is_active( 'blogs' ) )
10
+ return false;
11
+
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
+
34
+ echo '<li' . $alt . '>';
35
+ echo '<a href="' . $site_url . '">' . esc_html( $blog->name ) . '</a>';
36
+ echo '<ul>';
37
+ echo '<li class="alt"><a href="' . $site_url . 'wp-admin/">' . __( 'Dashboard', 'buddypress' ) . '</a></li>';
38
+ echo '<li><a href="' . $site_url . 'wp-admin/post-new.php">' . __( 'New Post', 'buddypress' ) . '</a></li>';
39
+ echo '<li class="alt"><a href="' . $site_url . 'wp-admin/edit.php">' . __( 'Manage Posts', 'buddypress' ) . '</a></li>';
40
+ echo '<li><a href="' . $site_url . 'wp-admin/edit-comments.php">' . __( 'Manage Comments', 'buddypress' ) . '</a></li>';
41
+ echo '</ul>';
42
+
43
+ do_action( 'bp_adminbar_blog_items', $blog );
44
+
45
+ echo '</li>';
46
+ $counter++;
47
+ }
48
+
49
+ $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
50
+
51
+ if ( bp_blog_signup_enabled() ) {
52
+ echo '<li' . $alt . '>';
53
+ echo '<a href="' . bp_get_root_domain() . '/' . bp_get_blogs_root_slug() . '/create/">' . __( 'Create a Site!', 'buddypress' ) . '</a>';
54
+ echo '</li>';
55
+ }
56
+
57
+ echo '</ul>';
58
+ echo '</li>';
59
+ }
60
+ }
61
+ add_action( 'bp_adminbar_menus', 'bp_adminbar_blogs_menu', 6 );
62
+
63
+ ?>
bp-blogs/bp-blogs-cache.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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' );
20
+ }
21
+
22
+ // List actions to clear object caches on
23
+ add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 );
24
+ add_action( 'bp_blogs_new_blog', 'bp_blogs_format_clear_blog_cache', 10, 2 );
25
+
26
+ // List actions to clear super cached pages on, if super cache is installed
27
+ add_action( 'bp_blogs_remove_data_for_blog', 'bp_core_clear_cache' );
28
+ add_action( 'bp_blogs_remove_comment', 'bp_core_clear_cache' );
29
+ add_action( 'bp_blogs_remove_post', 'bp_core_clear_cache' );
30
+ add_action( 'bp_blogs_remove_blog_for_user', 'bp_core_clear_cache' );
31
+ add_action( 'bp_blogs_remove_blog', 'bp_core_clear_cache' );
32
+ add_action( 'bp_blogs_new_blog_comment', 'bp_core_clear_cache' );
33
+ add_action( 'bp_blogs_new_blog_post', 'bp_core_clear_cache' );
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,4 +1,6 @@
1
  <?php
 
 
2
 
3
  Class BP_Blogs_Blog {
4
  var $id;
@@ -6,10 +8,13 @@ Class BP_Blogs_Blog {
6
  var $blog_id;
7
 
8
  function bp_blogs_blog( $id = null ) {
 
 
 
 
9
  global $bp, $wpdb;
10
 
11
- if ( !$user_id )
12
- $user_id = $bp->displayed_user->id;
13
 
14
  if ( $id ) {
15
  $this->id = $id;
@@ -32,7 +37,7 @@ Class BP_Blogs_Blog {
32
  $this->user_id = apply_filters( 'bp_blogs_blog_user_id_before_save', $this->user_id, $this->id );
33
  $this->blog_id = apply_filters( 'bp_blogs_blog_id_before_save', $this->blog_id, $this->id );
34
 
35
- do_action( 'bp_blogs_blog_before_save', $this );
36
 
37
  // Don't try and save if there is no user ID or blog ID set.
38
  if ( !$this->user_id || !$this->blog_id )
@@ -53,7 +58,7 @@ Class BP_Blogs_Blog {
53
  if ( !$wpdb->query($sql) )
54
  return false;
55
 
56
- do_action( 'bp_blogs_blog_after_save', $this );
57
 
58
  if ( $this->id )
59
  return $this->id;
@@ -69,20 +74,17 @@ Class BP_Blogs_Blog {
69
 
70
  /* Static Functions */
71
 
72
- function get( $type, $limit = false, $page = false, $user_id = false, $search_terms = false ) {
73
  global $bp, $wpdb;
74
 
75
- if ( !$bp->blogs )
76
- bp_blogs_setup_globals();
77
-
78
  if ( !is_user_logged_in() || ( !is_super_admin() && ( $user_id != $bp->loggedin_user->id ) ) )
79
  $hidden_sql = "AND wb.public = 1";
 
 
80
 
81
- if ( $limit && $page )
82
- $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
83
 
84
- if ( $user_id )
85
- $user_sql = $wpdb->prepare( " AND b.user_id = %d", $user_id );
86
 
87
  switch ( $type ) {
88
  case 'active': default:
@@ -108,9 +110,13 @@ Class BP_Blogs_Blog {
108
  $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb WHERE b.blog_id = wb.blog_id {$user_sql} AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$hidden_sql}" ) );
109
  }
110
 
111
- foreach ( (array)$paged_blogs as $blog ) $blog_ids[] = $blog->blog_id;
 
 
 
 
112
  $blog_ids = $wpdb->escape( join( ',', (array)$blog_ids ) );
113
- $paged_blogs = BP_Blogs_Blog::get_blog_extras( &$paged_blogs, $blog_ids, $type );
114
 
115
  return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
116
  }
@@ -118,20 +124,13 @@ Class BP_Blogs_Blog {
118
  function delete_blog_for_all( $blog_id ) {
119
  global $wpdb, $bp;
120
 
121
- if ( !$bp->blogs )
122
- bp_blogs_setup_globals();
123
-
124
  bp_blogs_delete_blogmeta( $blog_id );
125
-
126
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
127
  }
128
 
129
  function delete_blog_for_user( $blog_id, $user_id = null ) {
130
  global $wpdb, $bp;
131
 
132
- if ( !$bp->blogs )
133
- bp_blogs_setup_globals();
134
-
135
  if ( !$user_id )
136
  $user_id = $bp->loggedin_user->id;
137
 
@@ -141,21 +140,15 @@ Class BP_Blogs_Blog {
141
  function delete_blogs_for_user( $user_id = null ) {
142
  global $wpdb, $bp;
143
 
144
- if ( !$bp->blogs )
145
- bp_blogs_setup_globals();
146
-
147
  if ( !$user_id )
148
  $user_id = $bp->loggedin_user->id;
149
 
150
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) );
151
  }
152
 
153
- function get_blogs_for_user( $user_id = false, $show_hidden = false ) {
154
  global $bp, $wpdb;
155
 
156
- if ( !$bp->blogs )
157
- bp_blogs_setup_globals();
158
-
159
  if ( !$user_id )
160
  $user_id = $bp->displayed_user->id;
161
 
@@ -167,6 +160,7 @@ Class BP_Blogs_Blog {
167
 
168
  $total_blog_count = BP_Blogs_Blog::total_blog_count_for_user( $user_id );
169
 
 
170
  foreach ( (array)$blogs as $blog ) {
171
  $user_blogs[$blog->blog_id] = new stdClass;
172
  $user_blogs[$blog->blog_id]->id = $blog->id;
@@ -178,12 +172,9 @@ Class BP_Blogs_Blog {
178
  return array( 'blogs' => $user_blogs, 'count' => $total_blog_count );
179
  }
180
 
181
- function get_blog_ids_for_user( $user_id = false ) {
182
  global $bp, $wpdb;
183
 
184
- if ( !$bp->blogs )
185
- bp_blogs_setup_globals();
186
-
187
  if ( !$user_id )
188
  $user_id = $bp->displayed_user->id;
189
 
@@ -193,18 +184,12 @@ Class BP_Blogs_Blog {
193
  function is_recorded( $blog_id ) {
194
  global $bp, $wpdb;
195
 
196
- if ( !$bp->blogs )
197
- bp_blogs_setup_globals();
198
-
199
  return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
200
  }
201
 
202
  function total_blog_count_for_user( $user_id = null ) {
203
  global $bp, $wpdb;
204
 
205
- if ( !$bp->blogs )
206
- bp_blogs_setup_globals();
207
-
208
  if ( !$user_id )
209
  $user_id = $bp->displayed_user->id;
210
 
@@ -218,9 +203,6 @@ Class BP_Blogs_Blog {
218
  function search_blogs( $filter, $limit = null, $page = null ) {
219
  global $wpdb, $bp;
220
 
221
- if ( !$bp->blogs )
222
- bp_blogs_setup_globals();
223
-
224
  $filter = like_escape( $wpdb->escape( $filter ) );
225
 
226
  if ( !is_super_admin() )
@@ -238,14 +220,8 @@ Class BP_Blogs_Blog {
238
  function get_all( $limit = null, $page = null ) {
239
  global $bp, $wpdb;
240
 
241
- if ( !$bp->blogs )
242
- bp_blogs_setup_globals();
243
-
244
- if ( !is_super_admin() )
245
- $hidden_sql = "AND wb.public = 1";
246
-
247
- if ( $limit && $page )
248
- $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
249
 
250
  $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}" ) );
251
  $total_blogs = $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.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 {$hidden_sql}" ) );
@@ -256,9 +232,6 @@ Class BP_Blogs_Blog {
256
  function get_by_letter( $letter, $limit = null, $page = null ) {
257
  global $bp, $wpdb;
258
 
259
- if ( !$bp->blogs )
260
- bp_blogs_setup_globals();
261
-
262
  $letter = like_escape( $wpdb->escape( $letter ) );
263
 
264
  if ( !is_super_admin() )
@@ -273,13 +246,13 @@ Class BP_Blogs_Blog {
273
  return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
274
  }
275
 
276
- function get_blog_extras( $paged_blogs, $blog_ids, $type = false ) {
277
  global $bp, $wpdb;
278
 
279
  if ( empty( $blog_ids ) )
280
  return $paged_blogs;
281
 
282
- for ( $i = 0; $i < count( $paged_blogs ); $i++ ) {
283
  $blog_prefix = $wpdb->get_blog_prefix( $paged_blogs[$i]->blog_id );
284
  $paged_blogs[$i]->latest_post = $wpdb->get_row( "SELECT post_title, guid FROM {$blog_prefix}posts WHERE post_status = 'publish' AND post_type = 'post' AND id != 1 ORDER BY id DESC LIMIT 1" );
285
  }
@@ -287,7 +260,7 @@ Class BP_Blogs_Blog {
287
  /* Fetch the blog description for each blog (as it may be empty we can't fetch it in the main query). */
288
  $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} )" ) );
289
 
290
- for ( $i = 0; $i < count( $paged_blogs ); $i++ ) {
291
  foreach ( (array)$blog_descs as $desc ) {
292
  if ( $desc->blog_id == $paged_blogs[$i]->blog_id )
293
  $paged_blogs[$i]->description = $desc->description;
@@ -300,14 +273,10 @@ Class BP_Blogs_Blog {
300
  function is_hidden( $blog_id ) {
301
  global $wpdb;
302
 
303
- if ( !$bp->blogs )
304
- bp_blogs_setup_globals();
305
-
306
  if ( !(int)$wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT public FROM {$wpdb->base_prefix}blogs WHERE blog_id = %d", $blog_id ) ) )
307
  return true;
308
 
309
  return false;
310
  }
311
  }
312
-
313
  ?>
1
  <?php
2
+ // Exit if accessed directly
3
+ if ( !defined( 'ABSPATH' ) ) exit;
4
 
5
  Class BP_Blogs_Blog {
6
  var $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;
37
  $this->user_id = apply_filters( 'bp_blogs_blog_user_id_before_save', $this->user_id, $this->id );
38
  $this->blog_id = apply_filters( 'bp_blogs_blog_id_before_save', $this->blog_id, $this->id );
39
 
40
+ do_action_ref_array( 'bp_blogs_blog_before_save', array( &$this ) );
41
 
42
  // Don't try and save if there is no user ID or blog ID set.
43
  if ( !$this->user_id || !$this->blog_id )
58
  if ( !$wpdb->query($sql) )
59
  return false;
60
 
61
+ do_action_ref_array( 'bp_blogs_blog_after_save', array( &$this ) );
62
 
63
  if ( $this->id )
64
  return $this->id;
74
 
75
  /* Static Functions */
76
 
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 = '';
84
 
85
+ $pag_sql = ( $limit && $page ) ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ) : '';
 
86
 
87
+ $user_sql = !empty( $user_id ) ? $wpdb->prepare( " AND b.user_id = %d", $user_id ) : '';
 
88
 
89
  switch ( $type ) {
90
  case 'active': default:
110
  $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb WHERE b.blog_id = wb.blog_id {$user_sql} AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$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 );
122
  }
124
  function delete_blog_for_all( $blog_id ) {
125
  global $wpdb, $bp;
126
 
 
 
 
127
  bp_blogs_delete_blogmeta( $blog_id );
 
128
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
129
  }
130
 
131
  function delete_blog_for_user( $blog_id, $user_id = null ) {
132
  global $wpdb, $bp;
133
 
 
 
 
134
  if ( !$user_id )
135
  $user_id = $bp->loggedin_user->id;
136
 
140
  function delete_blogs_for_user( $user_id = null ) {
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
  }
148
 
149
+ function get_blogs_for_user( $user_id = 0, $show_hidden = false ) {
150
  global $bp, $wpdb;
151
 
 
 
 
152
  if ( !$user_id )
153
  $user_id = $bp->displayed_user->id;
154
 
160
 
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;
172
  return array( 'blogs' => $user_blogs, 'count' => $total_blog_count );
173
  }
174
 
175
+ function get_blog_ids_for_user( $user_id = 0 ) {
176
  global $bp, $wpdb;
177
 
 
 
 
178
  if ( !$user_id )
179
  $user_id = $bp->displayed_user->id;
180
 
184
  function is_recorded( $blog_id ) {
185
  global $bp, $wpdb;
186
 
 
 
 
187
  return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
188
  }
189
 
190
  function total_blog_count_for_user( $user_id = null ) {
191
  global $bp, $wpdb;
192
 
 
 
 
193
  if ( !$user_id )
194
  $user_id = $bp->displayed_user->id;
195
 
203
  function search_blogs( $filter, $limit = null, $page = null ) {
204
  global $wpdb, $bp;
205
 
 
 
 
206
  $filter = like_escape( $wpdb->escape( $filter ) );
207
 
208
  if ( !is_super_admin() )
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}" ) );
227
  $total_blogs = $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.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 {$hidden_sql}" ) );
232
  function get_by_letter( $letter, $limit = null, $page = null ) {
233
  global $bp, $wpdb;
234
 
 
 
 
235
  $letter = like_escape( $wpdb->escape( $letter ) );
236
 
237
  if ( !is_super_admin() )
246
  return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
247
  }
248
 
249
+ function get_blog_extras( &$paged_blogs, &$blog_ids, $type = false ) {
250
  global $bp, $wpdb;
251
 
252
  if ( empty( $blog_ids ) )
253
  return $paged_blogs;
254
 
255
+ for ( $i = 0, $count = count( $paged_blogs ); $i < $count; ++$i ) {
256
  $blog_prefix = $wpdb->get_blog_prefix( $paged_blogs[$i]->blog_id );
257
  $paged_blogs[$i]->latest_post = $wpdb->get_row( "SELECT post_title, guid FROM {$blog_prefix}posts WHERE post_status = 'publish' AND post_type = 'post' AND id != 1 ORDER BY id DESC LIMIT 1" );
258
  }
260
  /* Fetch the blog description for each blog (as it may be empty we can't fetch it in the main query). */
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;
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-functions.php ADDED
@@ -0,0 +1,566 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Exit if accessed directly
3
+ if ( !defined( 'ABSPATH' ) ) exit;
4
+
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() {
14
+ global $bp;
15
+
16
+ return (bool) !empty( $bp->pages->blogs->id );
17
+ }
18
+
19
+ function bp_blogs_get_blogs( $args = '' ) {
20
+ global $bp;
21
+
22
+ $defaults = array(
23
+ 'type' => 'active', // active, alphabetical, newest, or random
24
+ 'user_id' => false, // Pass a user_id to limit to only blogs that this user has privilages higher than subscriber on
25
+ 'search_terms' => false, // Limit to blogs that match these search terms
26
+ 'per_page' => 20, // The number of results to return per page
27
+ 'page' => 1, // The page to return if limiting per page
28
+ );
29
+
30
+ $params = wp_parse_args( $args, $defaults );
31
+ extract( $params, EXTR_SKIP );
32
+
33
+ return apply_filters( 'bp_blogs_get_blogs', BP_Blogs_Blog::get( $type, $per_page, $page, $user_id, $search_terms ), $params );
34
+ }
35
+
36
+ /**
37
+ * Populates the BP blogs table with existing blogs.
38
+ *
39
+ * @package BuddyPress Blogs
40
+ *
41
+ * @global object $bp BuddyPress global settings
42
+ * @global object $wpdb WordPress database object
43
+ * @uses get_users()
44
+ * @uses bp_blogs_record_blog()
45
+ */
46
+ function bp_blogs_record_existing_blogs() {
47
+ global $bp, $wpdb;
48
+
49
+ // Truncate user blogs table and re-record.
50
+ $wpdb->query( "TRUNCATE TABLE {$bp->blogs->table_name}" );
51
+
52
+ if ( is_multisite() )
53
+ $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$wpdb->base_prefix}blogs WHERE mature = 0 AND spam = 0 AND deleted = 0" ) );
54
+ else
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 );
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+
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' );
91
+
92
+ if ( empty( $name ) )
93
+ return false;
94
+
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
111
+ if ( !$is_private && !$no_activity ) {
112
+ // Record this in activity streams
113
+ bp_blogs_record_activity( array(
114
+ 'user_id' => $recorded_blog->user_id,
115
+ 'action' => apply_filters( 'bp_blogs_activity_created_blog_action', sprintf( __( '%s created the site %s', 'buddypress'), bp_core_get_userlink( $recorded_blog->user_id ), '<a href="' . get_site_url( $recorded_blog->blog_id ) . '">' . esc_attr( $name ) . '</a>' ), $recorded_blog, $name, $description ),
116
+ 'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', get_site_url( $recorded_blog->blog_id ), $recorded_blog->blog_id ),
117
+ 'type' => 'new_blog',
118
+ 'item_id' => $recorded_blog->blog_id
119
+ ) );
120
+ }
121
+
122
+ do_action_ref_array( 'bp_blogs_new_blog', array( &$recorded_blog, $is_private, $is_recorded ) );
123
+ }
124
+ add_action( 'wpmu_new_blog', 'bp_blogs_record_blog', 10, 2 );
125
+
126
+ /**
127
+ * Updates blogname in BuddyPress blogmeta table
128
+ *
129
+ * @global object $wpdb DB Layer
130
+ * @param string $oldvalue Value before save (not used)
131
+ * @param string $newvalue Value to change meta to
132
+ */
133
+ function bp_blogs_update_option_blogname( $oldvalue, $newvalue ) {
134
+ global $wpdb;
135
+
136
+ bp_blogs_update_blogmeta( $wpdb->blogid, 'name', $newvalue );
137
+ }
138
+ add_action( 'update_option_blogname', 'bp_blogs_update_option_blogname', 10, 2 );
139
+
140
+ /**
141
+ * Updates blogdescription in BuddyPress blogmeta table
142
+ *
143
+ * @global object $wpdb DB Layer
144
+ * @param string $oldvalue Value before save (not used)
145
+ * @param string $newvalue Value to change meta to
146
+ */
147
+ function bp_blogs_update_option_blogdescription( $oldvalue, $newvalue ) {
148
+ global $wpdb;
149
+
150
+ bp_blogs_update_blogmeta( $wpdb->blogid, 'description', $newvalue );
151
+ }
152
+ add_action( 'update_option_blogdescription', 'bp_blogs_update_option_blogdescription', 10, 2 );
153
+
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
+ // This is to stop infinite loops with Donncha's sitewide tags plugin
164
+ if ( !empty( $bp->site_options['tags_blog_id'] ) && (int)$blog_id == (int)$bp->site_options['tags_blog_id'] )
165
+ return false;
166
+
167
+ // Don't record this if it's not a post
168
+ if ( !in_array( $post->post_type, apply_filters( 'bp_blogs_record_post_post_types', array( 'post' ) ) ) )
169
+ return false;
170
+
171
+ $is_blog_public = apply_filters( 'bp_is_blog_public', (int)get_blog_option( $blog_id, 'blog_public' ) );
172
+
173
+ if ( 'publish' == $post->post_status && empty( $post->post_password ) ) {
174
+ if ( $is_blog_public || !is_multisite() ) {
175
+ // Record this in activity streams
176
+ $post_permalink = get_permalink( $post_id );
177
+
178
+ if ( is_multisite() )
179
+ $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>' );
180
+ else
181
+ $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>' );
182
+
183
+ $activity_content = $post->post_content;
184
+
185
+ bp_blogs_record_activity( array(
186
+ 'user_id' => (int)$post->post_author,
187
+ 'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, $post, $post_permalink ),
188
+ 'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, $post, $post_permalink ),
189
+ 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
190
+ 'type' => 'new_blog_post',
191
+ 'item_id' => $blog_id,
192
+ 'secondary_item_id' => $post_id,
193
+ 'recorded_time' => $post->post_modified_gmt
194
+ ));
195
+ }
196
+
197
+ // Update the blogs last activity
198
+ bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
199
+ } else {
200
+ bp_blogs_remove_post( $post_id, $blog_id, $user_id );
201
+ }
202
+
203
+ do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
204
+ }
205
+ add_action( 'save_post', 'bp_blogs_record_post', 10, 2 );
206
+
207
+ /**
208
+ * Record blog comment activity. Checks if blog is public and post is not
209
+ * password protected.
210
+ *
211
+ * @global $bp $bp
212
+ * @param int $comment_id
213
+ * @param bool $is_approved
214
+ * @return mixed
215
+ */
216
+ function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
217
+ global $bp;
218
+
219
+ // Get the users comment
220
+ $recorded_comment = get_comment( $comment_id );
221
+
222
+ // Don't record activity if the comment hasn't been approved
223
+ if ( empty( $is_approved ) )
224
+ return false;
225
+
226
+ // Don't record activity if no email address has been included
227
+ if ( empty( $recorded_comment->comment_author_email ) )
228
+ return false;
229
+
230
+ // Get the user_id from the comment author email.
231
+ $user = get_user_by_email( $recorded_comment->comment_author_email );
232
+ $user_id = (int)$user->ID;
233
+
234
+ // If there's no registered user id, don't record activity
235
+ if ( empty( $user_id ) )
236
+ return false;
237
+
238
+ // Get blog and post data
239
+ $blog_id = get_current_blog_id();
240
+ $recorded_comment->post = get_post( $recorded_comment->comment_post_ID );
241
+
242
+ if ( empty( $recorded_comment->post ) || is_wp_error( $recorded_comment->post ) )
243
+ return false;
244
+
245
+ // If this is a password protected post, don't record the comment
246
+ if ( !empty( $recorded_comment->post->post_password ) )
247
+ return false;
248
+
249
+ // Don't record activity if the comment's associated post isn't a WordPress Post
250
+ if ( !in_array( $recorded_comment->post->post_type, apply_filters( 'bp_blogs_record_comment_post_types', array( 'post' ) ) ) )
251
+ return false;
252
+
253
+ $is_blog_public = apply_filters( 'bp_is_blog_public', (int)get_blog_option( $blog_id, 'blog_public' ) );
254
+
255
+ // If blog is public allow activity to be posted
256
+ if ( $is_blog_public ) {
257
+
258
+ // Get activity related links
259
+ $post_permalink = get_permalink( $recorded_comment->comment_post_ID );
260
+ $comment_link = htmlspecialchars( get_comment_link( $recorded_comment->comment_ID ) );
261
+
262
+ // Prepare to record in activity streams
263
+ if ( is_multisite() )
264
+ $activity_action = sprintf( __( '%1$s commented on the post, %2$s, on the site %3$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' );
265
+ else
266
+ $activity_action = sprintf( __( '%1$s commented on the post, %2$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>' );
267
+
268
+ $activity_content = $recorded_comment->comment_content;
269
+
270
+ // Record in activity streams
271
+ bp_blogs_record_activity( array(
272
+ 'user_id' => $user_id,
273
+ 'action' => apply_filters_ref_array( 'bp_blogs_activity_new_comment_action', array( $activity_action, &$recorded_comment, $comment_link ) ),
274
+ 'content' => apply_filters_ref_array( 'bp_blogs_activity_new_comment_content', array( $activity_content, &$recorded_comment, $comment_link ) ),
275
+ 'primary_link' => apply_filters_ref_array( 'bp_blogs_activity_new_comment_primary_link', array( $comment_link, &$recorded_comment ) ),
276
+ 'type' => 'new_blog_comment',
277
+ 'item_id' => $blog_id,
278
+ 'secondary_item_id' => $comment_id,
279
+ 'recorded_time' => $recorded_comment->comment_date_gmt
280
+ ) );
281
+
282
+ // Update the blogs last active date
283
+ bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
284
+ }
285
+
286
+ return $recorded_comment;
287
+ }
288
+ add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
289
+ add_action( 'edit_comment', 'bp_blogs_record_comment', 10 );
290
+
291
+ function bp_blogs_manage_comment( $comment_id, $comment_status ) {
292
+ if ( 'spam' == $comment_status || 'hold' == $comment_status || 'delete' == $comment_status || 'trash' == $comment_status )
293
+ return bp_blogs_remove_comment( $comment_id );
294
+
295
+ return bp_blogs_record_comment( $comment_id, true );
296
+ }
297
+ add_action( 'wp_set_comment_status', 'bp_blogs_manage_comment', 10, 2 );
298
+
299
+ function bp_blogs_add_user_to_blog( $user_id, $role = false, $blog_id = 0 ) {
300
+ global $wpdb;
301
+
302
+ if ( empty( $blog_id ) && isset( $wpdb->blogid ) )
303
+ $blog_id = $wpdb->blogid;
304
+ else
305
+ $blog_id = bp_get_root_blog_id();
306
+
307
+ if ( empty( $role ) ) {
308
+ $key = $wpdb->get_blog_prefix( $blog_id ). 'capabilities';
309
+
310
+ $roles = get_user_meta( $user_id, $key, true );
311
+
312
+ if ( is_array( $roles ) )
313
+ $role = array_search( 1, $roles );
314
+ else
315
+ return false;
316
+ }
317
+
318
+ if ( $role != 'subscriber' )
319
+ bp_blogs_record_blog( $blog_id, $user_id, true );
320
+ }
321
+ add_action( 'add_user_to_blog', 'bp_blogs_add_user_to_blog', 10, 3 );
322
+ add_action( 'profile_update', 'bp_blogs_add_user_to_blog' );
323
+ add_action( 'user_register', 'bp_blogs_add_user_to_blog' );
324
+
325
+ function bp_blogs_remove_user_from_blog( $user_id, $blog_id = 0 ) {
326
+ global $wpdb;
327
+
328
+ if ( empty( $blog_id ) )
329
+ $blog_id = $wpdb->blogid;
330
+
331
+ bp_blogs_remove_blog_for_user( $user_id, $blog_id );
332
+ }
333
+ add_action( 'remove_user_from_blog', 'bp_blogs_remove_user_from_blog', 10, 2 );
334
+
335
+ function bp_blogs_remove_blog( $blog_id ) {
336
+ global $bp;
337
+
338
+ $blog_id = (int)$blog_id;
339
+ do_action( 'bp_blogs_before_remove_blog', $blog_id );
340
+
341
+ BP_Blogs_Blog::delete_blog_for_all( $blog_id );
342
+
343
+ // Delete activity stream item
344
+ bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->id, 'type' => 'new_blog' ) );
345
+
346
+ do_action( 'bp_blogs_remove_blog', $blog_id );
347
+ }
348
+ add_action( 'delete_blog', 'bp_blogs_remove_blog' );
349
+
350
+ function bp_blogs_remove_blog_for_user( $user_id, $blog_id ) {
351
+ global $bp, $current_user;
352
+
353
+ $blog_id = (int)$blog_id;
354
+ $user_id = (int)$user_id;
355
+
356
+ do_action( 'bp_blogs_before_remove_blog_for_user', $blog_id, $user_id );
357
+
358
+ BP_Blogs_Blog::delete_blog_for_user( $blog_id, $user_id );
359
+
360
+ // Delete activity stream item
361
+ bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->id, 'type' => 'new_blog' ) );
362
+
363
+ do_action( 'bp_blogs_remove_blog_for_user', $blog_id, $user_id );
364
+ }
365
+ add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 );
366
+
367
+ function bp_blogs_remove_post( $post_id, $blog_id = 0, $user_id = 0 ) {
368
+ global $wpdb, $bp;
369
+
370
+ if ( empty( $wpdb->blogid ) )
371
+ return false;
372
+
373
+ $post_id = (int)$post_id;
374
+
375
+ if ( !$blog_id )
376
+ $blog_id = (int)$wpdb->blogid;
377
+
378
+ if ( !$user_id )
379
+ $user_id = $bp->loggedin_user->id;
380
+
381
+ do_action( 'bp_blogs_before_remove_post', $blog_id, $post_id, $user_id );
382
+
383
+ // Delete activity stream item
384
+ bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->id, 'type' => 'new_blog_post' ) );
385
+
386
+ do_action( 'bp_blogs_remove_post', $blog_id, $post_id, $user_id );
387
+ }
388
+ add_action( 'delete_post', 'bp_blogs_remove_post' );
389
+
390
+ function bp_blogs_remove_comment( $comment_id ) {
391
+ global $wpdb, $bp;
392
+
393
+ // Delete activity stream item
394
+ bp_blogs_delete_activity( array( 'item_id' => $wpdb->blogid , 'secondary_item_id' => $comment_id, 'type' => 'new_blog_comment' ) );
395
+
396
+ do_action( 'bp_blogs_remove_comment', $blog_id, $comment_id, $bp->loggedin_user->id );
397
+ }
398
+ add_action( 'delete_comment', 'bp_blogs_remove_comment' );
399
+
400
+ function bp_blogs_total_blogs() {
401
+ if ( !$count = wp_cache_get( 'bp_total_blogs', 'bp' ) ) {
402
+ $blogs = BP_Blogs_Blog::get_all();
403
+ $count = $blogs['total'];
404
+ wp_cache_set( 'bp_total_blogs', $count, 'bp' );
405
+ }
406
+ return $count;
407
+ }
408
+
409
+ function bp_blogs_total_blogs_for_user( $user_id = 0 ) {
410
+ global $bp;
411
+
412
+ if ( !$user_id )
413
+ $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
414
+
415
+ if ( !$count = wp_cache_get( 'bp_total_blogs_for_user_' . $user_id, 'bp' ) ) {
416
+ $count = BP_Blogs_Blog::total_blog_count_for_user( $user_id );
417
+ wp_cache_set( 'bp_total_blogs_for_user_' . $user_id, $count, 'bp' );
418
+ }
419
+
420
+ return $count;
421
+ }
422
+
423
+ function bp_blogs_remove_data_for_blog( $blog_id ) {
424
+ global $bp;
425
+
426
+ do_action( 'bp_blogs_before_remove_data_for_blog', $blog_id );
427
+
428
+ // If this is regular blog, delete all data for that blog.
429
+ BP_Blogs_Blog::delete_blog_for_all( $blog_id );
430
+
431
+ // Delete activity stream item
432
+ bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->id, 'type' => false ) );
433
+
434
+ do_action( 'bp_blogs_remove_data_for_blog', $blog_id );
435
+ }
436
+ add_action( 'delete_blog', 'bp_blogs_remove_data_for_blog', 1 );
437
+
438
+ function bp_blogs_get_blogs_for_user( $user_id, $show_hidden = false ) {
439
+ return BP_Blogs_Blog::get_blogs_for_user( $user_id, $show_hidden );
440
+ }
441
+
442
+ function bp_blogs_get_all_blogs( $limit = null, $page = null ) {
443
+ return BP_Blogs_Blog::get_all( $limit, $page );
444
+ }
445
+
446
+ function bp_blogs_get_random_blogs( $limit = null, $page = null ) {
447
+ return BP_Blogs_Blog::get( 'random', $limit, $page );
448
+ }
449
+
450
+ function bp_blogs_is_blog_hidden( $blog_id ) {
451
+ return BP_Blogs_Blog::is_hidden( $blog_id );
452
+ }
453
+
454
+ /*******************************************************************************
455
+ * Blog meta functions
456
+ *
457
+ * These functions are used to store specific blogmeta in one global table,
458
+ * rather than in each blog's options table. Significantly speeds up global blog
459
+ * queries. By default each blog's name, description and last updated time are
460
+ * stored and synced here.
461
+ */
462
+
463
+ function bp_blogs_delete_blogmeta( $blog_id, $meta_key = false, $meta_value = false ) {
464
+ global $wpdb, $bp;
465
+
466
+ if ( !is_numeric( $blog_id ) )
467
+ return false;
468
+
469
+ $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
470
+
471
+ if ( is_array($meta_value) || is_object($meta_value) )
472
+ $meta_value = serialize($meta_value);
473
+
474
+ $meta_value = trim( $meta_value );
475
+
476
+ if ( !$meta_key )
477
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d", $blog_id ) );
478
+ else if ( $meta_value )
479
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s AND meta_value = %s", $blog_id, $meta_key, $meta_value ) );
480
+ else
481
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key ) );
482
+
483
+ wp_cache_delete( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, 'bp' );
484
+
485
+ return true;
486
+ }
487
+
488
+ function bp_blogs_get_blogmeta( $blog_id, $meta_key = '') {
489
+ global $wpdb, $bp;
490
+
491
+ $blog_id = (int) $blog_id;
492
+
493
+ if ( !$blog_id )
494
+ return false;
495
+
496
+ if ( !empty($meta_key) ) {
497
+ $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
498
+
499
+ if ( !$metas = wp_cache_get( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, 'bp' ) ) {
500
+ $metas = $wpdb->get_col( $wpdb->prepare( "SELECT meta_value FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key ) );
501
+ wp_cache_set( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, $metas, 'bp' );
502
+ }
503
+ } else {
504
+ $metas = $wpdb->get_col( $wpdb->prepare("SELECT meta_value FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d", $blog_id) );
505
+ }
506
+
507
+ if ( empty($metas) ) {
508
+ if ( empty($meta_key) )
509
+ return array();
510
+ else
511
+ return '';
512
+ }
513
+
514
+ $metas = array_map('maybe_unserialize', (array)$metas);
515
+
516
+ if ( 1 == count($metas) )
517
+ return $metas[0];
518
+ else
519
+ return $metas;
520
+ }
521
+
522
+ function bp_blogs_update_blogmeta( $blog_id, $meta_key, $meta_value ) {
523
+ global $wpdb, $bp;
524
+
525
+ if ( !is_numeric( $blog_id ) )
526
+ return false;
527
+
528
+ $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
529
+
530
+ if ( is_string($meta_value) )
531
+ $meta_value = stripslashes($wpdb->escape($meta_value));
532
+
533
+ $meta_value = maybe_serialize($meta_value);
534
+
535
+ if (empty( $meta_value ) )
536
+ return bp_blogs_delete_blogmeta( $blog_id, $meta_key );
537
+
538
+ $cur = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key ) );
539
+
540
+ if ( !$cur )
541
+ $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name_blogmeta} ( blog_id, meta_key, meta_value ) VALUES ( %d, %s, %s )", $blog_id, $meta_key, $meta_value ) );
542
+ else if ( $cur->meta_value != $meta_value )
543
+ $wpdb->query( $wpdb->prepare( "UPDATE {$bp->blogs->table_name_blogmeta} SET meta_value = %s WHERE blog_id = %d AND meta_key = %s", $meta_value, $blog_id, $meta_key ) );
544
+ else
545
+ return false;
546
+
547
+ wp_cache_set( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, $meta_value, 'bp' );
548
+
549
+ return true;
550
+ }
551
+
552
+ function bp_blogs_remove_data( $user_id ) {
553
+ if ( !is_multisite() )
554
+ return false;
555
+
556
+ do_action( 'bp_blogs_before_remove_data', $user_id );
557
+
558
+ // If this is regular blog, delete all data for that blog.
559
+ BP_Blogs_Blog::delete_blogs_for_user( $user_id );
560
+
561
+ do_action( 'bp_blogs_remove_data', $user_id );
562
+ }
563
+ add_action( 'wpmu_delete_user', 'bp_blogs_remove_data' );
564
+ add_action( 'delete_user', 'bp_blogs_remove_data' );
565
+ add_action( 'bp_make_spam_user', 'bp_blogs_remove_data' );
566
+ ?>
bp-blogs/bp-blogs-loader.php ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * BuddyPress Blogs Streams Loader
4
+ *
5
+ * An blogs stream component, for users, groups, and blog tracking.
6
+ *
7
+ * @package BuddyPress
8
+ * @subpackage Blogs Core
9
+ */
10
+
11
+ // Exit if accessed directly
12
+ if ( !defined( 'ABSPATH' ) ) exit;
13
+
14
+ class BP_Blogs_Component extends BP_Component {
15
+
16
+ /**
17
+ * Start the blogs component creation process
18
+ *
19
+ * @since 1.5
20
+ */
21
+ function __construct() {
22
+ parent::start(
23
+ 'blogs',
24
+ __( 'Site Tracking', 'buddypress' ),
25
+ BP_PLUGIN_DIR
26
+ );
27
+ }
28
+
29
+ /**
30
+ * Setup globals
31
+ *
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;
40
+
41
+ if ( !defined( 'BP_BLOGS_SLUG' ) )
42
+ define ( 'BP_BLOGS_SLUG', $this->id );
43
+
44
+ // Global tables for messaging component
45
+ $global_tables = array(
46
+ 'table_name' => $bp->table_prefix . 'bp_user_blogs',
47
+ 'table_name_blogmeta' => $bp->table_prefix . 'bp_user_blogs_blogmeta',
48
+ );
49
+
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
57
+ 'notification_callback' => 'bp_blogs_format_notifications',
58
+ 'search_string' => __( 'Search sites...', 'buddypress' ),
59
+ 'autocomplete_all' => defined( 'BP_MESSAGES_AUTOCOMPLETE_ALL' ),
60
+ 'global_tables' => $global_tables,
61
+ );
62
+
63
+ // Setup the globals
64
+ parent::setup_globals( $globals );
65
+ }
66
+
67
+ /**
68
+ * Include files
69
+ */
70
+ function includes() {
71
+ // Files to include
72
+ $includes = array(
73
+ 'cache',
74
+ 'actions',
75
+ 'screens',
76
+ 'classes',
77
+ 'template',
78
+ 'activity',
79
+ 'functions',
80
+ 'buddybar'
81
+ );
82
+
83
+ if ( is_multisite() )
84
+ $includes[] = 'widgets';
85
+
86
+ // Include the files
87
+ parent::includes( $includes );
88
+ }
89
+
90
+ /**
91
+ * Setup BuddyBar navigation
92
+ *
93
+ * @global obj $bp
94
+ */
95
+ function setup_nav() {
96
+ global $bp;
97
+
98
+ /**
99
+ * Blog/post/comment menus should not appear on single WordPress setups.
100
+ * Although comments and posts made by users will still show on their
101
+ * activity stream.
102
+ */
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;
127
+
128
+ /**
129
+ * Blog/post/comment menus should not appear on single WordPress setups.
130
+ * Although comments and posts made by users will still show on their
131
+ * activity stream.
132
+ */
133
+ if ( !is_multisite() )
134
+ return false;
135
+
136
+ // Prevent debug notices
137
+ $wp_admin_nav = array();
138
+
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(
146
+ 'parent' => $bp->my_account_menu_id,
147
+ 'id' => 'my-account-' . $this->id,
148
+ 'title' => __( 'Sites', 'buddypress' ),
149
+ 'href' => trailingslashit( $blogs_link )
150
+ );
151
+
152
+ // My Blogs
153
+ $wp_admin_nav[] = array(
154
+ 'parent' => 'my-account-' . $this->id,
155
+ 'title' => __( 'My Sites', 'buddypress' ),
156
+ 'href' => trailingslashit( $blogs_link )
157
+ );
158
+
159
+ }
160
+
161
+ parent::setup_admin_bar( $wp_admin_nav );
162
+ }
163
+
164
+ /**
165
+ * Sets up the title for pages and <title>
166
+ *
167
+ * @global obj $bp
168
+ */
169
+ function setup_title() {
170
+ global $bp;
171
+
172
+ // Set up the component options navigation for Blog
173
+ if ( bp_is_blogs_component() ) {
174
+ if ( bp_is_my_profile() ) {
175
+ if ( bp_is_active( 'xprofile' ) ) {
176
+ $bp->bp_options_title = __( 'My Sites', 'buddypress' );
177
+ }
178
+
179
+ // If we are not viewing the logged in user, set up the current
180
+ // users avatar and name
181
+ } else {
182
+ $bp->bp_options_avatar = bp_core_fetch_avatar( array(
183
+ 'item_id' => $bp->displayed_user->id,
184
+ 'type' => 'thumb'
185
+ ) );
186
+ $bp->bp_options_title = $bp->displayed_user->fullname;
187
+ }
188
+ }
189
+
190
+ parent::setup_title();
191
+ }
192
+ }
193
+ // Create the blogs component
194
+ $bp->blogs = new BP_Blogs_Component();
195
+
196
+ ?>
bp-blogs/bp-blogs-screens.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Exit if accessed directly
3
+ if ( !defined( 'ABSPATH' ) ) exit;
4
+
5
+ function bp_blogs_screen_my_blogs() {
6
+ if ( !is_multisite() )
7
+ return false;
8
+
9
+ do_action( 'bp_blogs_screen_my_blogs' );
10
+
11
+ bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'members/single/home' ) );
12
+ }
13
+
14
+ function bp_blogs_screen_create_a_blog() {
15
+ if ( !is_multisite() || !bp_is_blogs_component() || !bp_is_current_action( 'create' ) )
16
+ return false;
17
+
18
+ if ( !is_user_logged_in() || !bp_blog_signup_enabled() )
19
+ return false;
20
+
21
+ do_action( 'bp_blogs_screen_create_a_blog' );
22
+
23
+ bp_core_load_template( apply_filters( 'bp_blogs_template_create_a_blog', 'blogs/create' ) );
24
+ }
25
+ add_action( 'bp_screens', 'bp_blogs_screen_create_a_blog', 3 );
26
+
27
+ function bp_blogs_screen_index() {
28
+ if ( is_multisite() && bp_is_blogs_component() && !bp_current_action() ) {
29
+ bp_update_is_directory( true, 'blogs' );
30
+
31
+ do_action( 'bp_blogs_screen_index' );
32
+
33
+ bp_core_load_template( apply_filters( 'bp_blogs_screen_index', 'blogs/index' ) );
34
+ }
35
+ }
36
+ add_action( 'bp_screens', 'bp_blogs_screen_index', 2 );
37
+
38
+ ?>
bp-blogs/{bp-blogs-templatetags.php → bp-blogs-template.php} RENAMED
@@ -1,4 +1,81 @@
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  /**********************************************************************
4
  * Blog listing template class.
@@ -18,6 +95,10 @@ class BP_Blogs_Template {
18
  var $total_blog_count;
19
 
20
  function bp_blogs_template( $type, $page, $per_page, $max, $user_id, $search_terms ) {
 
 
 
 
21
  global $bp;
22
 
23
  $this->pag_page = isset( $_REQUEST['bpage'] ) ? intval( $_REQUEST['bpage'] ) : $page;
@@ -51,8 +132,8 @@ class BP_Blogs_Template {
51
  'format' => '',
52
  'total' => ceil( (int)$this->total_blog_count / (int)$this->pag_num ),
53
  'current' => (int)$this->pag_page,
54
- 'prev_text' => '&larr;',
55
- 'next_text' => '&rarr;',
56
  'mid_size' => 1
57
  ) );
58
  }
@@ -83,7 +164,7 @@ class BP_Blogs_Template {
83
  if ( $this->current_blog + 1 < $this->blog_count ) {
84
  return true;
85
  } elseif ( $this->current_blog + 1 == $this->blog_count ) {
86
- do_action('loop_end');
87
  // Do some cleaning up after the loop
88
  $this->rewind_blogs();
89
  }
@@ -96,10 +177,10 @@ class BP_Blogs_Template {
96
  global $blog;
97
 
98
  $this->in_the_loop = true;
99
- $this->blog = $this->next_blog();
100
 
101
  if ( 0 == $this->current_blog ) // loop has just started
102
- do_action('loop_start');
103
  }
104
  }
105
 
@@ -117,37 +198,41 @@ function bp_has_blogs( $args = '' ) {
117
  * if arguments are directly passed into the loop. Custom plugins should always
118
  * pass their parameters directly to the loop.
119
  */
120
- $type = 'active';
121
- $user_id = false;
122
- $search_terms = false;
123
 
124
  /* User filtering */
125
  if ( !empty( $bp->displayed_user->id ) )
126
  $user_id = $bp->displayed_user->id;
127
 
128
- if ( !empty( $_REQUEST['s'] ) )
129
- $search_terms = $_REQUEST['s'];
130
-
131
  $defaults = array(
132
- 'type' => $type,
133
- 'page' => 1,
134
- 'per_page' => 20,
135
- 'max' => false,
136
 
137
- 'user_id' => $user_id, // Pass a user_id to limit to only blogs this user has higher than subscriber access to
138
  'search_terms' => $search_terms // Pass search terms to filter on the blog title or description.
139
  );
140
 
141
  $r = wp_parse_args( $args, $defaults );
142
  extract( $r );
143
 
 
 
 
 
 
 
 
144
  if ( $max ) {
145
  if ( $per_page > $max )
146
  $per_page = $max;
147
  }
148
 
149
  $blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms );
150
- return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), &$blogs_template );
151
  }
152
 
153
  function bp_blogs() {
@@ -166,12 +251,11 @@ function bp_blogs_pagination_count() {
166
  global $bp, $blogs_template;
167
 
168
  $start_num = intval( ( $blogs_template->pag_page - 1 ) * $blogs_template->pag_num ) + 1;
169
- $from_num = bp_core_number_format( $start_num );
170
- $to_num = bp_core_number_format( ( $start_num + ( $blogs_template->pag_num - 1 ) > $blogs_template->total_blog_count ) ? $blogs_template->total_blog_count : $start_num + ( $blogs_template->pag_num - 1 ) );
171
- $total = bp_core_number_format( $blogs_template->total_blog_count );
172
 
173
- echo sprintf( __( 'Viewing blog %1$s to %2$s (of %3$s blogs)', 'buddypress' ), $from_num, $to_num, $total ); ?> &nbsp;
174
- <span class="ajax-loader"></span><?php
175
  }
176
 
177
  function bp_blogs_pagination_links() {
@@ -190,12 +274,12 @@ function bp_blog_avatar( $args = '' ) {
190
  global $blogs_template, $bp;
191
 
192
  $defaults = array(
193
- 'type' => 'full',
194
- 'width' => false,
195
- 'height' => false,
196
- 'class' => 'avatar',
197
- 'id' => false,
198
- 'alt' => __( 'Blog avatar', 'buddypress' ),
199
  'no_grav' => true
200
  );
201
 
@@ -206,8 +290,13 @@ function bp_blog_avatar( $args = '' ) {
206
  * In future BuddyPress versions you will be able to set the avatar for a blog.
207
  * Right now you can use a filter with the ID of the blog to change it if you wish.
208
  * By default it will return the avatar for the primary blog admin.
 
 
 
209
  */
210
- return apply_filters( 'bp_get_blog_avatar_' . $blogs_template->blog->blog_id, bp_core_fetch_avatar( array( 'item_id' => $blogs_template->blog->admin_user_id, 'type' => $type, 'alt' => $alt, 'width' => $width, 'height' => $height, 'class' => $class, 'email' => $blogs_template->blog->admin_user_email ) ) );
 
 
211
  }
212
 
213
  function bp_blog_permalink() {
@@ -217,7 +306,7 @@ function bp_blog_permalink() {
217
  global $blogs_template;
218
 
219
  if ( empty( $blogs_template->blog->domain ) )
220
- $permalink = $bp->root_domain . $blogs_template->blog->path;
221
  else {
222
  $protocol = 'http://';
223
  if ( is_ssl() )
@@ -253,7 +342,7 @@ function bp_blog_last_active() {
253
  function bp_get_blog_last_active() {
254
  global $blogs_template;
255
 
256
- return apply_filters( 'bp_blog_last_active', bp_core_get_last_activity( $blogs_template->blog->last_activity, __( 'active %s ago', 'buddypress' ) ) );
257
  }
258
 
259
  function bp_blog_latest_post() {
@@ -269,17 +358,14 @@ function bp_blog_latest_post() {
269
  }
270
 
271
  function bp_blog_hidden_fields() {
272
- if ( isset( $_REQUEST['s'] ) ) {
273
  echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['s'] ). '" name="search_terms" />';
274
- }
275
 
276
- if ( isset( $_REQUEST['letter'] ) ) {
277
  echo '<input type="hidden" id="selected_letter" value="' . esc_attr( $_REQUEST['letter'] ) . '" name="selected_letter" />';
278
- }
279
 
280
- if ( isset( $_REQUEST['blogs_search'] ) ) {
281
  echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['blogs_search'] ) . '" name="search_terms" />';
282
- }
283
  }
284
 
285
  function bp_total_blog_count() {
@@ -290,10 +376,10 @@ function bp_total_blog_count() {
290
  }
291
  add_filter( 'bp_get_total_blog_count', 'bp_core_number_format' );
292
 
293
- function bp_total_blog_count_for_user( $user_id = false ) {
294
  echo bp_get_total_blog_count_for_user( $user_id );
295
  }
296
- function bp_get_total_blog_count_for_user( $user_id = false ) {
297
  return apply_filters( 'bp_get_total_blog_count_for_user', bp_blogs_total_blogs_for_user( $user_id ) );
298
  }
299
  add_filter( 'bp_get_total_blog_count_for_user', 'bp_core_number_format' );
@@ -304,10 +390,7 @@ function bp_total_blog_count_for_user( $user_id = false ) {
304
  function bp_blog_signup_enabled() {
305
  global $bp;
306
 
307
- $active_signup = $bp->site_options['registration'];
308
-
309
- if ( !$active_signup )
310
- $active_signup = 'all';
311
 
312
  $active_signup = apply_filters( 'wpmu_active_signup', $active_signup ); // return "all", "none", "blog" or "user"
313
 
@@ -321,8 +404,6 @@ function bp_show_blog_signup_form($blogname = '', $blog_title = '', $errors = ''
321
  global $current_user, $current_site;
322
  global $bp;
323
 
324
- require_once( ABSPATH . WPINC . '/registration.php' );
325
-
326
  if ( isset($_POST['submit']) ) {
327
  bp_blogs_validate_blog_signup();
328
  } else {
@@ -340,9 +421,9 @@ function bp_show_blog_signup_form($blogname = '', $blog_title = '', $errors = ''
340
  echo "<p>" . __('There was a problem, please correct the form below and try again.', 'buddypress') . "</p>";
341
  }
342
  ?>
343
- <p><?php printf(__("By filling out the form below, you can <strong>add a blog to your account</strong>. There is no limit to the number of blogs you can have, so create to your heart's content, but blog responsibly.", 'buddypress'), $current_user->display_name) ?></p>
344
 
345
- <p><?php _e("If you&#8217;re not going to use a great blog domain, leave it for a new user. Now have at it!", 'buddypress') ?></p>
346
 
347
  <form class="standard-form" id="setupform" method="post" action="">
348
 
@@ -351,7 +432,7 @@ function bp_show_blog_signup_form($blogname = '', $blog_title = '', $errors = ''
351
 
352
  <?php bp_blogs_signup_blog($blogname, $blog_title, $errors); ?>
353
  <p>
354
- <input id="submit" type="submit" name="submit" class="submit" value="<?php _e('Create Blog &rarr;', 'buddypress') ?>" />
355
  </p>
356
 
357
  <?php wp_nonce_field( 'bp_blog_signup_form' ) ?>
@@ -365,18 +446,20 @@ function bp_blogs_signup_blog( $blogname = '', $blog_title = '', $errors = '' )
365
 
366
  // Blog name
367
  if( !is_subdomain_install() )
368
- echo '<label for="blogname">' . __('Blog Name:', 'buddypress') . '</label>';
369
  else
370
- echo '<label for="blogname">' . __('Blog Domain:', 'buddypress') . '</label>';
371
 
372
  if ( $errmsg = $errors->get_error_message('blogname') ) { ?>
 
373
  <p class="error"><?php echo $errmsg ?></p>
 
374
  <?php }
375
 
376
  if ( !is_subdomain_install() )
377
  echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span> <input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /><br />';
378
  else
379
- echo '<input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /> <span class="suffix_address">.' . $current_site->domain . $current_site->path . '</span><br />';
380
 
381
  if ( !is_user_logged_in() ) {
382
  print '(<strong>' . __( 'Your address will be ' , 'buddypress');
@@ -392,17 +475,20 @@ function bp_blogs_signup_blog( $blogname = '', $blog_title = '', $errors = '' )
392
 
393
  // Blog Title
394
  ?>
395
- <label for="blog_title"><?php _e('Blog Title:', 'buddypress') ?></label>
 
 
396
  <?php if ( $errmsg = $errors->get_error_message('blog_title') ) { ?>
 
397
  <p class="error"><?php echo $errmsg ?></p>
 
398
  <?php }
399
- echo '<input name="blog_title" type="text" id="blog_title" value="'.wp_specialchars($blog_title, 1).'" /></p>';
400
  ?>
401
 
402
  <p>
403
  <label for="blog_public_on"><?php _e('Privacy:', 'buddypress') ?></label>
404
- <?php _e('I would like my blog to appear in search engines like Google and Technorati, and in public listings around this site.', 'buddypress'); ?>
405
-
406
 
407
  <label class="checkbox" for="blog_public_on">
408
  <input type="radio" id="blog_public_on" name="blog_public" value="1" <?php if( !isset( $_POST['blog_public'] ) || '1' == $_POST['blog_public'] ) { ?>checked="checked"<?php } ?> />
@@ -419,7 +505,7 @@ function bp_blogs_signup_blog( $blogname = '', $blog_title = '', $errors = '' )
419
  }
420
 
421
  function bp_blogs_validate_blog_signup() {
422
- global $wpdb, $current_user, $blogname, $blog_title, $errors, $domain, $path;
423
 
424
  if ( !check_admin_referer( 'bp_blog_signup_form' ) )
425
  return false;
@@ -443,8 +529,9 @@ function bp_blogs_validate_blog_signup() {
443
  $meta = apply_filters( 'signup_create_blog_meta', array( 'lang_id' => 1, 'public' => $public ) ); // depreciated
444
  $meta = apply_filters( 'add_signup_meta', $meta );
445
 
446
- /* If this is a VHOST install, remove the username from the domain as we are setting this blog
447
- up inside a user domain, not the root domain. */
 
448
 
449
  wpmu_create_blog( $domain, $path, $blog_title, $current_user->id, $meta, $wpdb->siteid );
450
  bp_blogs_confirm_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta);
@@ -460,21 +547,23 @@ function bp_blogs_validate_blog_form() {
460
  }
461
 
462
  function bp_blogs_confirm_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = '' ) {
463
- ?>
464
- <p><?php _e('Congratulations! You have successfully registered a new blog.', 'buddypress') ?></p>
 
 
465
  <p>
466
- <?php printf(__('<a href="http://%1$s">http://%2$s</a> is your new blog. <a href="%3$s">Login</a> as "%4$s" using your existing password.', 'buddypress'), $domain.$path, $domain.$path, "http://" . $domain.$path . "wp-login.php", $user_name) ?>
467
  </p>
468
- <?php
 
469
  do_action('signup_finished');
470
  }
471
 
472
  function bp_create_blog_link() {
473
  global $bp;
474
 
475
- if ( bp_is_my_profile() ) {
476
- echo apply_filters( 'bp_create_blog_link', '<a href="' . $bp->root_domain . '/' . $bp->blogs->slug . '/create">' . __('Create a Blog', 'buddypress') . '</a>' );
477
- }
478
  }
479
 
480
  function bp_blogs_blog_tabs() {
@@ -484,23 +573,29 @@ function bp_blogs_blog_tabs() {
484
  if ( bp_is_my_profile() )
485
  return false;
486
 
487
- $current_tab = $bp->current_action
488
- ?>
489
  <ul class="content-header-nav">
490
- <li<?php if ( 'my-blogs' == $current_tab || empty( $current_tab ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . $bp->blogs->slug ?>/my-blogs"><?php printf( __( "%s's Blogs", 'buddypress' ), $bp->displayed_user->fullname ) ?></a></li>
491
- <li<?php if ( 'recent-posts' == $current_tab ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . $bp->blogs->slug ?>/recent-posts"><?php printf( __( "%s's Recent Posts", 'buddypress' ), $bp->displayed_user->fullname ) ?></a></li>
492
- <li<?php if ( 'recent-comments' == $current_tab ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp->displayed_user->domain . $bp->blogs->slug ?>/recent-comments"><?php printf( __( "%s's Recent Comments", 'buddypress' ), $bp->displayed_user->fullname ) ?></a></li>
493
  </ul>
 
494
  <?php
495
  do_action( 'bp_blogs_blog_tabs', $current_tab );
496
  }
497
 
498
  function bp_directory_blogs_search_form() {
499
- global $bp; ?>
 
 
 
 
500
  <form action="" method="get" id="search-blogs-form">
501
- <label><input type="text" name="s" id="blogs_search" value="<?php if ( isset( $_GET['s'] ) ) { echo $_GET['s']; } else { _e( 'Search anything...', 'buddypress' ); } ?>" onfocus="if (this.value == '<?php _e( 'Search anything...', 'buddypress' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search anything...', 'buddypress' ) ?>';}" /></label>
502
  <input type="submit" id="blogs_search_submit" name="blogs_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
503
  </form>
 
504
  <?php
505
  }
506
 
@@ -530,9 +625,9 @@ function bp_blogs_visit_blog_button( $args = '' ) {
530
  'block_self' => false,
531
  'wrapper_class' => 'blog-button visit',
532
  'link_href' => bp_get_blog_permalink(),
533
- 'link_class' => 'visit',
534
- 'link_text' => __( 'Visit Blog', 'buddypress' ),
535
- 'link_title' => __( 'Visit Blog', 'buddypress' ),
536
  );
537
 
538
  $button = wp_parse_args( $args, $defaults );
@@ -541,4 +636,4 @@ function bp_blogs_visit_blog_button( $args = '' ) {
541
  return bp_get_button( apply_filters( 'bp_get_blogs_visit_blog_button', $button ) );
542
  }
543
 
544
- ?>
1
  <?php
2
+ // Exit if accessed directly
3
+ if ( !defined( 'ABSPATH' ) ) exit;
4
+
5
+ /**
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
+ */
14
+ function bp_blogs_slug() {
15
+ echo bp_get_blogs_slug();
16
+ }
17
+ /**
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;
26
+ return apply_filters( 'bp_get_blogs_slug', $bp->blogs->slug );
27
+ }
28
+
29
+ /**
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
+ */
38
+ function bp_blogs_root_slug() {
39
+ echo bp_get_blogs_root_slug();
40
+ }
41
+ /**
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;
50
+ return apply_filters( 'bp_get_blogs_root_slug', $bp->blogs->root_slug );
51
+ }
52
+
53
+ /**
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() {
62
+ echo bp_get_blogs_directory_permalink();
63
+ }
64
+ /**
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()
73
+ * @uses bp_get_blogs_root_slug()
74
+ * @return string
75
+ */
76
+ function bp_get_blogs_directory_permalink() {
77
+ return apply_filters( 'bp_get_blogs_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_blogs_root_slug() ) );
78
+ }
79
 
80
  /**********************************************************************
81
  * Blog listing template class.
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;
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
138
  ) );
139
  }
164
  if ( $this->current_blog + 1 < $this->blog_count ) {
165
  return true;
166
  } elseif ( $this->current_blog + 1 == $this->blog_count ) {
167
+ do_action('blog_loop_end');
168
  // Do some cleaning up after the loop
169
  $this->rewind_blogs();
170
  }
177
  global $blog;
178
 
179
  $this->in_the_loop = true;
180
+ $this->blog = $this->next_blog();
181
 
182
  if ( 0 == $this->current_blog ) // loop has just started
183
+ do_action('blog_loop_start');
184
  }
185
  }
186
 
198
  * if arguments are directly passed into the loop. Custom plugins should always
199
  * pass their parameters directly to the loop.
200
  */
201
+ $type = 'active';
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,
211
+ 'page' => 1,
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 );
220
  extract( $r );
221
 
222
+ if ( is_null( $search_terms ) ) {
223
+ if ( isset( $_REQUEST['s'] ) && !empty( $_REQUEST['s'] ) )
224
+ $search_terms = $_REQUEST['s'];
225
+ else
226
+ $search_terms = false;
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
 
238
  function bp_blogs() {
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 );
255
+ $to_num = bp_core_number_format( ( $start_num + ( $blogs_template->pag_num - 1 ) > $blogs_template->total_blog_count ) ? $blogs_template->total_blog_count : $start_num + ( $blogs_template->pag_num - 1 ) );
256
+ $total = bp_core_number_format( $blogs_template->total_blog_count );
257
 
258
+ echo sprintf( __( 'Viewing site %1$s to %2$s (of %3$s sites)', 'buddypress' ), $from_num, $to_num, $total );
 
259
  }
260
 
261
  function bp_blogs_pagination_links() {
274
  global $blogs_template, $bp;
275
 
276
  $defaults = array(
277
+ 'type' => 'full',
278
+ 'width' => false,
279
+ 'height' => false,
280
+ 'class' => 'avatar',
281
+ 'id' => false,
282
+ 'alt' => __( 'Site authored by %s', 'buddypress' ),
283
  'no_grav' => true
284
  );
285
 
290
  * In future BuddyPress versions you will be able to set the avatar for a blog.
291
  * Right now you can use a filter with the ID of the blog to change it if you wish.
292
  * By default it will return the avatar for the primary blog admin.
293
+ *
294
+ * This filter is deprecated as of BuddyPress 1.5 and may be removed in a future version.
295
+ * Use the 'bp_get_blog_avatar' filter instead.
296
  */
297
+ $avatar = apply_filters( 'bp_get_blog_avatar_' . $blogs_template->blog->blog_id, bp_core_fetch_avatar( array( 'item_id' => $blogs_template->blog->admin_user_id, 'type' => $type, 'alt' => $alt, 'width' => $width, 'height' => $height, 'class' => $class, 'email' => $blogs_template->blog->admin_user_email ) ) );
298
+
299
+ return apply_filters( 'bp_get_blog_avatar', $avatar, $blogs_template->blog->blog_id, array( 'item_id' => $blogs_template->blog->admin_user_id, 'type' => $type, 'alt' => $alt, 'width' => $width, 'height' => $height, 'class' => $class, 'email' => $blogs_template->blog->admin_user_email ) );
300
  }
301
 
302
  function bp_blog_permalink() {
306
  global $blogs_template;
307
 
308
  if ( empty( $blogs_template->blog->domain ) )
309
+ $permalink = bp_get_root_domain() . $blogs_template->blog->path;
310
  else {
311
  $protocol = 'http://';
312
  if ( is_ssl() )
342
  function bp_get_blog_last_active() {
343
  global $blogs_template;
344
 
345
+ return apply_filters( 'bp_blog_last_active', bp_core_get_last_activity( $blogs_template->blog->last_activity, __( 'active %s', 'buddypress' ) ) );
346
  }
347
 
348
  function bp_blog_latest_post() {
358
  }
359
 
360
  function bp_blog_hidden_fields() {
361
+ if ( isset( $_REQUEST['s'] ) )
362
  echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['s'] ). '" name="search_terms" />';
 
363
 
364
+ if ( isset( $_REQUEST['letter'] ) )
365
  echo '<input type="hidden" id="selected_letter" value="' . esc_attr( $_REQUEST['letter'] ) . '" name="selected_letter" />';
 
366
 
367
+ if ( isset( $_REQUEST['blogs_search'] ) )
368
  echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['blogs_search'] ) . '" name="search_terms" />';
 
369
  }
370
 
371
  function bp_total_blog_count() {
376
  }
377
  add_filter( 'bp_get_total_blog_count', 'bp_core_number_format' );
378
 
379
+ function bp_total_blog_count_for_user( $user_id = 0 ) {
380
  echo bp_get_total_blog_count_for_user( $user_id );
381
  }
382
+ function bp_get_total_blog_count_for_user( $user_id = 0 ) {
383
  return apply_filters( 'bp_get_total_blog_count_for_user', bp_blogs_total_blogs_for_user( $user_id ) );
384
  }
385
  add_filter( 'bp_get_total_blog_count_for_user', 'bp_core_number_format' );
390
  function bp_blog_signup_enabled() {
391
  global $bp;
392
 
393
+ $active_signup = isset( $bp->site_options['registration'] ) ? $bp->site_options['registration'] : 'all';
 
 
 
394
 
395
  $active_signup = apply_filters( 'wpmu_active_signup', $active_signup ); // return "all", "none", "blog" or "user"
396
 
404
  global $current_user, $current_site;
405
  global $bp;
406
 
 
 
407
  if ( isset($_POST['submit']) ) {
408
  bp_blogs_validate_blog_signup();
409
  } else {
421
  echo "<p>" . __('There was a problem, please correct the form below and try again.', 'buddypress') . "</p>";
422
  }
423
  ?>
424
+ <p><?php printf(__("By filling out the form below, you can <strong>add a site to your account</strong>. There is no limit to the number of sites that you can have, so create to your heart's content, but blog responsibly!", 'buddypress'), $current_user->display_name) ?></p>
425
 
426
+ <p><?php _e("If you&#8217;re not going to use a great domain, leave it for a new user. Now have at it!", 'buddypress') ?></p>
427
 
428
  <form class="standard-form" id="setupform" method="post" action="">
429
 
432
 
433
  <?php bp_blogs_signup_blog($blogname, $blog_title, $errors); ?>
434
  <p>
435
+ <input id="submit" type="submit" name="submit" class="submit" value="<?php _e('Create Site', 'buddypress') ?>" />
436
  </p>
437
 
438
  <?php wp_nonce_field( 'bp_blog_signup_form' ) ?>
446
 
447
  // Blog name
448
  if( !is_subdomain_install() )
449
+ echo '<label for="blogname">' . __('Site Name:', 'buddypress') . '</label>';
450
  else
451
+ echo '<label for="blogname">' . __('Site Domain:', 'buddypress') . '</label>';
452
 
453
  if ( $errmsg = $errors->get_error_message('blogname') ) { ?>
454
+
455
  <p class="error"><?php echo $errmsg ?></p>
456
+
457
  <?php }
458
 
459
  if ( !is_subdomain_install() )
460
  echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span> <input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /><br />';
461
  else
462
+ echo '<input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /> <span class="suffix_address">.' . preg_replace( '|^www\.|', '', $current_site->domain ) . $current_site->path . '</span><br />';
463
 
464
  if ( !is_user_logged_in() ) {
465
  print '(<strong>' . __( 'Your address will be ' , 'buddypress');
475
 
476
  // Blog Title
477
  ?>
478
+
479
+ <label for="blog_title"><?php _e('Site Title:', 'buddypress') ?></label>
480
+
481
  <?php if ( $errmsg = $errors->get_error_message('blog_title') ) { ?>
482
+
483
  <p class="error"><?php echo $errmsg ?></p>
484
+
485
  <?php }
486
+ echo '<input name="blog_title" type="text" id="blog_title" value="'.esc_html($blog_title, 1).'" /></p>';
487
  ?>
488
 
489
  <p>
490
  <label for="blog_public_on"><?php _e('Privacy:', 'buddypress') ?></label>
491
+ <?php _e( 'I would like my site to appear in search engines, and in public listings around this network.', 'buddypress' ); ?>
 
492
 
493
  <label class="checkbox" for="blog_public_on">
494
  <input type="radio" id="blog_public_on" name="blog_public" value="1" <?php if( !isset( $_POST['blog_public'] ) || '1' == $_POST['blog_public'] ) { ?>checked="checked"<?php } ?> />
505
  }
506
 
507
  function bp_blogs_validate_blog_signup() {
508
+ global $wpdb, $current_user, $blogname, $blog_title, $errors, $domain, $path, $current_site;
509
 
510
  if ( !check_admin_referer( 'bp_blog_signup_form' ) )
511
  return false;
529
  $meta = apply_filters( 'signup_create_blog_meta', array( 'lang_id' => 1, 'public' => $public ) ); // depreciated
530
  $meta = apply_filters( 'add_signup_meta', $meta );
531
 
532
+ // If this is a subdomain install, set up the site inside the root domain.
533
+ if ( is_subdomain_install() )
534
+ $domain = $blogname . '.' . preg_replace( '|^www\.|', '', $current_site->domain );
535
 
536
  wpmu_create_blog( $domain, $path, $blog_title, $current_user->id, $meta, $wpdb->siteid );
537
  bp_blogs_confirm_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta);
547
  }
548
 
549
  function bp_blogs_confirm_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = '' ) {
550
+ $protocol = is_ssl() ? 'https://' : 'http://';
551
+ $blog_url = $protocol . $domain . $path; ?>
552
+
553
+ <p><?php _e( 'Congratulations! You have successfully registered a new site.', 'buddypress' ) ?></p>
554
  <p>
555
+ <?php printf(__( '<a href="%1$s">%2$s</a> is your new site. <a href="%3$s">Login</a> as "%4$s" using your existing password.', 'buddypress' ), $blog_url, $blog_url, $blog_url . "wp-login.php", $user_name ); ?>
556
  </p>
557
+
558
+ <?php
559
  do_action('signup_finished');
560
  }
561
 
562
  function bp_create_blog_link() {
563
  global $bp;
564
 
565
+ if ( bp_is_my_profile() )
566
+ echo apply_filters( 'bp_create_blog_link', '<a href="' . bp_get_root_domain() . '/' . bp_get_blogs_root_slug() . '/create/">' . __( 'Create a Site', 'buddypress' ) . '</a>' );
 
567
  }
568
 
569
  function bp_blogs_blog_tabs() {
573
  if ( bp_is_my_profile() )
574
  return false;
575
 
576
+ ?>
577
+
578
  <ul class="content-header-nav">
579
+ <li<?php if ( bp_is_current_action( 'my-blogs' ) || !bp_current_action() ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_blogs_slug() . '/my-blogs' ); ?>"><?php printf( __( "%s's Sites", 'buddypress' ), bp_get_displayed_user_fullname() ); ?></a></li>
580
+ <li<?php if ( bp_is_current_action( 'recent-posts' ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_blogs_slug() . '/recent-posts' ); ?>"><?php printf( __( "%s's Recent Posts", 'buddypress' ), bp_get_displayed_user_fullname() ); ?></a></li>
581
+ <li<?php if ( bp_is_current_action( 'recent-comments' ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_blogs_slug() . '/recent-comments' ); ?>"><?php printf( __( "%s's Recent Comments", 'buddypress' ), bp_get_displayed_user_fullname() ); ?></a></li>
582
  </ul>
583
+
584
  <?php
585
  do_action( 'bp_blogs_blog_tabs', $current_tab );
586
  }
587
 
588
  function bp_directory_blogs_search_form() {
589
+ global $bp;
590
+
591
+ $default_search_value = bp_get_search_default_text();
592
+ $search_value = !empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value; ?>
593
+
594
  <form action="" method="get" id="search-blogs-form">
595
+ <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>
596
  <input type="submit" id="blogs_search_submit" name="blogs_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
597
  </form>
598
+
599
  <?php
600
  }
601
 
625
  'block_self' => false,
626
  'wrapper_class' => 'blog-button visit',
627
  'link_href' => bp_get_blog_permalink(),
628
+ 'link_class' => 'blog-button visit',
629
+ 'link_text' => __( 'Visit Site', 'buddypress' ),
630
+ 'link_title' => __( 'Visit Site', 'buddypress' ),
631
  );
632
 
633
  $button = wp_parse_args( $args, $defaults );
636
  return bp_get_button( apply_filters( 'bp_get_blogs_visit_blog_button', $button ) );
637
  }
638
 
639
+ ?>
bp-blogs/bp-blogs-widgets.php CHANGED
@@ -1,4 +1,6 @@
1
  <?php
 
 
2
 
3
  /***
4
  * The recent blogs widget is actually just the activity feed filtered on "new_blog_post".
@@ -6,16 +8,21 @@
6
  */
7
 
8
  function bp_blogs_register_widgets() {
9
- global $current_blog, $bp;
10
 
11
- if ( bp_is_active( 'activity' ) && (int)$current_blog->blog_id == BP_ROOT_BLOG )
12
  add_action('widgets_init', create_function('', 'return register_widget("BP_Blogs_Recent_Posts_Widget");') );
13
  }
14
  add_action( 'bp_register_widgets', 'bp_blogs_register_widgets' );
15
 
16
  class BP_Blogs_Recent_Posts_Widget extends WP_Widget {
 
17
  function bp_blogs_recent_posts_widget() {
18
- parent::WP_Widget( false, $name = __( 'Recent Site Wide Posts', 'buddypress' ) );
 
 
 
 
19
  }
20
 
21
  function widget($args, $instance) {
@@ -29,7 +36,8 @@ class BP_Blogs_Recent_Posts_Widget extends WP_Widget {
29
  if ( empty( $instance['max_posts'] ) || !$instance['max_posts'] )
30
  $instance['max_posts'] = 10; ?>
31
 
32
- <?php if ( bp_has_activities( 'action=new_blog_post&max=' . $instance['max_posts'] . '&per_page=' . $instance['max_posts'] ) ) : ?>
 
33
 
34
  <ul id="blog-post-list" class="activity-list item-list">
35
 
@@ -57,7 +65,7 @@ class BP_Blogs_Recent_Posts_Widget extends WP_Widget {
57
 
58
  <?php else : ?>
59
  <div id="message" class="info">
60
- <p><?php _e( 'Sorry, there were no blog posts found. Why not write one?', 'buddypress' ) ?></p>
61
  </div>
62
  <?php endif; ?>
63
 
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".
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) {
36
  if ( empty( $instance['max_posts'] ) || !$instance['max_posts'] )
37
  $instance['max_posts'] = 10; ?>
38
 
39
+ <?php /* Override some of the contextually set parameters for bp_has_activities() */ ?>
40
+ <?php if ( bp_has_activities( array( 'action' => 'new_blog_post', 'max' => $instance['max_posts'], 'per_page' => $instance['max_posts'], 'user_id' => 0, 'scope' => false, 'object' => false, 'primary_id' => false ) ) ) : ?>
41
 
42
  <ul id="blog-post-list" class="activity-list item-list">
43
 
65
 
66
  <?php else : ?>
67
  <div id="message" class="info">
68
+ <p><?php _e( 'Sorry, there were no posts found. Why not write one?', 'buddypress' ) ?></p>
69
  </div>
70
  <?php endif; ?>
71
 
bp-core.php DELETED
@@ -1,2224 +0,0 @@
1
- <?php
2
-
3
- /* Define the current version number for checking if DB tables are up to date. */
4
- define( 'BP_CORE_DB_VERSION', '1800' );
5
-
6
- /***
7
- * Define the path and url of the BuddyPress plugins directory.
8
- * It is important to use plugins_url() core function to obtain
9
- * the correct scheme used (http or https).
10
- */
11
- define( 'BP_PLUGIN_DIR', WP_PLUGIN_DIR . '/buddypress' );
12
- define( 'BP_PLUGIN_URL', plugins_url( $path = '/buddypress' ) );
13
-
14
- /* Load the WP abstraction file so BuddyPress can run on all WordPress setups. */
15
- require ( BP_PLUGIN_DIR . '/bp-core/bp-core-wpabstraction.php' );
16
-
17
- /* Place your custom code (actions/filters) in a file called /plugins/bp-custom.php and it will be loaded before anything else. */
18
- if ( file_exists( WP_PLUGIN_DIR . '/bp-custom.php' ) )
19
- require( WP_PLUGIN_DIR . '/bp-custom.php' );
20
-
21
- /* Define on which blog ID BuddyPress should run */
22
- if ( !defined( 'BP_ROOT_BLOG' ) )
23
- define( 'BP_ROOT_BLOG', 1 );
24
-
25
- /* Define the user and usermeta table names, useful if you are using custom or shared tables. */
26
- if ( !defined( 'CUSTOM_USER_TABLE' ) )
27
- define( 'CUSTOM_USER_TABLE', $wpdb->base_prefix . 'users' );
28
-
29
- if ( !defined( 'CUSTOM_USER_META_TABLE' ) )
30
- define( 'CUSTOM_USER_META_TABLE', $wpdb->base_prefix . 'usermeta' );
31
-
32
- /* Load the files containing functions that we globally will need. */
33
- require ( BP_PLUGIN_DIR . '/bp-core/bp-core-catchuri.php' );
34
- require ( BP_PLUGIN_DIR . '/bp-core/bp-core-classes.php' );
35
- require ( BP_PLUGIN_DIR . '/bp-core/bp-core-filters.php' );
36
- require ( BP_PLUGIN_DIR . '/bp-core/bp-core-cssjs.php' );
37
- require ( BP_PLUGIN_DIR . '/bp-core/bp-core-avatars.php' );
38
- require ( BP_PLUGIN_DIR . '/bp-core/bp-core-templatetags.php' );
39
- require ( BP_PLUGIN_DIR . '/bp-core/bp-core-settings.php' );
40
- require ( BP_PLUGIN_DIR . '/bp-core/bp-core-widgets.php' );
41
- require ( BP_PLUGIN_DIR . '/bp-core/bp-core-notifications.php' );
42
- require ( BP_PLUGIN_DIR . '/bp-core/bp-core-signup.php' );
43
-
44
- /* If BP_DISABLE_ADMIN_BAR is defined, do not load the global admin bar. */
45
- if ( !defined( 'BP_DISABLE_ADMIN_BAR' ) )
46
- require ( BP_PLUGIN_DIR . '/bp-core/bp-core-adminbar.php' );
47
-
48
- /* Define the slug for member pages and the members directory (e.g. domain.com/[members] ) */
49
- if ( !defined( 'BP_MEMBERS_SLUG' ) )
50
- define( 'BP_MEMBERS_SLUG', 'members' );
51
-
52
- /* Define the slug for the register/signup page */
53
- if ( !defined( 'BP_REGISTER_SLUG' ) )
54
- define( 'BP_REGISTER_SLUG', 'register' );
55
-
56
- /* Define the slug for the activation page */
57
- if ( !defined( 'BP_ACTIVATION_SLUG' ) )
58
- define( 'BP_ACTIVATION_SLUG', 'activate' );
59
-
60
- /* Define the slug for the search page */
61
- if ( !defined( 'BP_SEARCH_SLUG' ) )
62
- define( 'BP_SEARCH_SLUG', 'search' );
63
-
64
- /* Register BuddyPress themes contained within the bp-theme folder */
65
- if ( function_exists( 'register_theme_directory') )
66
- register_theme_directory( WP_PLUGIN_DIR . '/buddypress/bp-themes' );
67
-
68
-
69
- /* "And now for something completely different" .... */
70
-
71
-
72
- /**
73
- * bp_core_setup_globals()
74
- *
75
- * Sets up default global BuddyPress configuration settings and stores
76
- * them in a $bp variable.
77
- *
78
- * @package BuddyPress Core Core
79
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
80
- * @global $current_user A WordPress global containing current user information
81
- * @global $current_component Which is set up in /bp-core/bp-core-catch-uri.php
82
- * @global $current_action Which is set up in /bp-core/bp-core-catch-uri.php
83
- * @global $action_variables Which is set up in /bp-core/bp-core-catch-uri.php
84
- * @uses bp_core_get_user_domain() Returns the domain for a user
85
- */
86
- function bp_core_setup_globals() {
87
- global $bp;
88
- global $current_user, $current_component, $current_action, $current_blog;
89
- global $displayed_user_id;
90
- global $action_variables;
91
-
92
- $current_user = wp_get_current_user();
93
-
94
- /* Get the base database prefix */
95
- $bp->table_prefix = bp_core_get_table_prefix();
96
-
97
- /* The domain for the root of the site where the main blog resides */
98
- $bp->root_domain = bp_core_get_root_domain();
99
-
100
- /* The user ID of the user who is currently logged in. */
101
- $bp->loggedin_user->id = $current_user->ID;
102
-
103
- /* The domain for the user currently logged in. eg: http://domain.com/members/andy */
104
- $bp->loggedin_user->domain = bp_core_get_user_domain( $bp->loggedin_user->id );
105
-
106
- /* The core userdata of the user who is currently logged in. */
107
- $bp->loggedin_user->userdata = bp_core_get_core_userdata( $bp->loggedin_user->id );
108
-
109
- /* is_super_admin() hits the DB on single WP installs, so we need to get this separately so we can call it in a loop. */
110
- $bp->loggedin_user->is_super_admin = is_super_admin();
111
- $bp->loggedin_user->is_site_admin = $bp->loggedin_user->is_super_admin; // deprecated 1.2.6
112
-
113
- /* The user id of the user currently being viewed, set in /bp-core/bp-core-catchuri.php */
114
- $bp->displayed_user->id = $displayed_user_id;
115
-
116
- /* The domain for the user currently being displayed */
117
- $bp->displayed_user->domain = bp_core_get_user_domain( $bp->displayed_user->id );
118
-
119
- /* The core userdata of the user who is currently being displayed */
120
- $bp->displayed_user->userdata = bp_core_get_core_userdata( $bp->displayed_user->id );
121
-
122
- /* The component being used eg: http://domain.com/members/andy/ [profile] */
123
- $bp->current_component = $current_component; // type: string
124
-
125
- /* The current action for the component eg: http://domain.com/members/andy/profile/ [edit] */
126
- $bp->current_action = $current_action; // type: string
127
-
128
- /* The action variables for the current action eg: http://domain.com/members/andy/profile/edit/ [group] / [6] */
129
- $bp->action_variables = $action_variables; // type: array
130
-
131
- /* Only used where a component has a sub item, e.g. groups: http://domain.com/members/andy/groups/ [my-group] / home - manipulated in the actual component not in catch uri code.*/
132
- $bp->current_item = ''; // type: string
133
-
134
- /* Used for overriding the 2nd level navigation menu so it can be used to display custom navigation for an item (for example a group) */
135
- $bp->is_single_item = false;
136
-
137
- /* The default component to use if none are set and someone visits: http://domain.com/members/andy */
138
- if ( !defined( 'BP_DEFAULT_COMPONENT' ) ) {
139
- if ( defined( 'BP_ACTIVITY_SLUG' ) )
140
- $bp->default_component = BP_ACTIVITY_SLUG;
141
- else
142
- $bp->default_component = 'profile';
143
- } else {
144
- $bp->default_component = BP_DEFAULT_COMPONENT;
145
- }
146
-
147
- /* Fetches all of the core database based BuddyPress settings in one foul swoop */
148
- $bp->site_options = bp_core_get_site_options();
149
-
150
- /* Sets up the array container for the component navigation rendered by bp_get_nav() */
151
- $bp->bp_nav = array();
152
-
153
- /* Sets up the array container for the component options navigation rendered by bp_get_options_nav() */
154
- $bp->bp_options_nav = array();
155
-
156
- /* Contains an array of all the active components. The key is the slug, value the internal ID of the component */
157
- $bp->active_components = array();
158
-
159
- /* Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar */
160
- $bp->grav_default->user = apply_filters( 'bp_user_gravatar_default', $bp->site_options['user-avatar-default'] );
161
- $bp->grav_default->group = apply_filters( 'bp_group_gravatar_default', 'identicon' );
162
- $bp->grav_default->blog = apply_filters( 'bp_blog_gravatar_default', 'identicon' );
163
-
164
- /* Fetch the full name for the logged in and current user */
165
- $bp->loggedin_user->fullname = bp_core_get_user_displayname( $bp->loggedin_user->id );
166
- $bp->displayed_user->fullname = bp_core_get_user_displayname( $bp->displayed_user->id );
167
-
168
- /* Used to determine if user has admin rights on current content. If the logged in user is viewing
169
- their own profile and wants to delete something, is_item_admin is used. This is a
170
- generic variable so it can be used by other components. It can also be modified, so when viewing a group
171
- 'is_item_admin' would be 1 if they are a group admin, 0 if they are not. */
172
- $bp->is_item_admin = bp_user_has_access();
173
-
174
- /* Used to determine if the logged in user is a moderator for the current content. */
175
- $bp->is_item_mod = false;
176
-
177
- $bp->core->table_name_notifications = $bp->table_prefix . 'bp_notifications';
178
-
179
- if ( !$bp->current_component && $bp->displayed_user->id )
180
- $bp->current_component = $bp->default_component;
181
-
182
- do_action( 'bp_core_setup_globals' );
183
- }
184
- add_action( 'bp_setup_globals', 'bp_core_setup_globals' );
185
-
186
- /**
187
- * bp_core_setup_root_uris()
188
- *
189
- * Adds the core URIs that should run in the root of the installation.
190
- *
191
- * For example: http://example.org/search/ or http://example.org/members/
192
- *
193
- * @package BuddyPress Core
194
- * @uses bp_core_add_root_component() Adds a slug to the root components global variable.
195
- */
196
- function bp_core_setup_root_uris() {
197
- // Add core root components
198
- bp_core_add_root_component( BP_MEMBERS_SLUG );
199
- bp_core_add_root_component( BP_REGISTER_SLUG );
200
- bp_core_add_root_component( BP_ACTIVATION_SLUG );
201
- bp_core_add_root_component( BP_SEARCH_SLUG );
202
- }
203
- add_action( 'bp_setup_root_components', 'bp_core_setup_root_uris' );
204
-
205
- /**
206
- * bp_core_get_table_prefix()
207
- *
208
- * Allow filtering of database prefix. Intended for use in multinetwork installations.
209
- *
210
- * @global object $wpdb WordPress database object
211
- * @return string Filtered database prefix
212
- */
213
- function bp_core_get_table_prefix() {
214
- global $wpdb;
215
-
216
- return apply_filters( 'bp_core_get_table_prefix', $wpdb->base_prefix );
217
- }
218
-
219
- /**
220
- * bp_core_install()
221
- *
222
- * Installs the core DB tables for BuddyPress.
223
- *
224
- * @package BuddyPress Core
225
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
226
- * @global $wpdb WordPress DB access object.
227
- * @uses dbDelta() Performs a table creation, or upgrade based on what already exists in the DB.
228
- * @uses bp_core_add_illegal_names() Adds illegal blog names to the WP settings
229
- */
230
- function bp_core_install() {
231
- global $wpdb, $bp;
232
-
233
- if ( !empty($wpdb->charset) )
234
- $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
235
-
236
- $sql[] = "CREATE TABLE {$bp->core->table_name_notifications} (
237
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
238
- user_id bigint(20) NOT NULL,
239
- item_id bigint(20) NOT NULL,
240
- secondary_item_id bigint(20),
241
- component_name varchar(75) NOT NULL,
242
- component_action varchar(75) NOT NULL,
243
- date_notified datetime NOT NULL,
244
- is_new bool NOT NULL DEFAULT 0,
245
- KEY item_id (item_id),
246
- KEY secondary_item_id (secondary_item_id),
247
- KEY user_id (user_id),
248
- KEY is_new (is_new),
249
- KEY component_name (component_name),
250
- KEY component_action (component_action),
251
- KEY useritem (user_id,is_new)
252
- ) {$charset_collate};";
253
-
254
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
255
- dbDelta( $sql );
256
-
257
- // Add names of root components to the banned name list to avoid conflicts
258
- bp_core_flush_illegal_names();
259
-
260
- update_site_option( 'bp-core-db-version', BP_CORE_DB_VERSION );
261
- }
262
-
263
- /**
264
- * bp_core_check_installed()
265
- *
266
- * Checks to make sure the database tables are set up for the core component.
267
- *
268
- * @package BuddyPress Core
269
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
270
- * @global $current_user WordPress global variable containing current logged in user information
271
- * @uses is_super_admin() returns true if the current user is a site admin, false if not
272
- * @uses get_site_option() fetches the value for a meta_key in the wp_sitemeta table
273
- * @uses bp_core_install() runs the installation of DB tables for the core component
274
- */
275
- function bp_core_check_installed() {
276
- global $bp;
277
-
278
- if ( !is_super_admin() )
279
- return false;
280
-
281
- require ( BP_PLUGIN_DIR . '/bp-core/bp-core-admin.php' );
282
-
283
- /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
284
- if ( get_site_option( 'bp-core-db-version' ) < BP_CORE_DB_VERSION )
285
- bp_core_install();
286
- }
287
- add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', 'bp_core_check_installed' );
288
-
289
- /**
290
- * bp_core_add_admin_menu()
291
- *
292
- * Adds the "BuddyPress" admin submenu item to the Site Admin tab.
293
- *
294
- * @package BuddyPress Core
295
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
296
- * @uses is_super_admin() returns true if the current user is a site admin, false if not
297
- * @uses add_submenu_page() WP function to add a submenu item
298
- */
299
- function bp_core_add_admin_menu() {
300
- if ( !is_super_admin() )
301
- return false;
302
-
303
- // If this is WP 3.1+ and multisite is enabled, only load on the Network Admin
304
- if ( is_multisite() && function_exists( 'is_network_admin' ) && ! is_network_admin() )
305
- return false;
306
-
307
- // Add the administration tab under the "Site Admin" tab for site administrators
308
- bp_core_add_admin_menu_page( array(
309
- 'menu_title' => __( 'BuddyPress', 'buddypress' ),
310
- 'page_title' => __( 'BuddyPress', 'buddypress' ),
311
- 'access_level' => 10, 'file' => 'bp-general-settings',
312
- 'function' => 'bp_core_admin_settings',
313
- 'position' => 2
314
- ) );
315
-
316
- add_submenu_page( 'bp-general-settings', __( 'General Settings', 'buddypress'), __( 'General Settings', 'buddypress' ), 'manage_options', 'bp-general-settings', 'bp_core_admin_settings' );
317
- add_submenu_page( 'bp-general-settings', __( 'Component Setup', 'buddypress'), __( 'Component Setup', 'buddypress' ), 'manage_options', 'bp-component-setup', 'bp_core_admin_component_setup' );
318
- }
319
- add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', 'bp_core_add_admin_menu' );
320
-
321
- /**
322
- * bp_core_is_root_component()
323
- *
324
- * Checks to see if a component's URL should be in the root, not under a member page:
325
- * eg: http://domain.com/groups/the-group NOT http://domain.com/members/andy/groups/the-group
326
- *
327
- * @package BuddyPress Core
328
- * @return true if root component, else false.
329
- */
330
- function bp_core_is_root_component( $component_name ) {
331
- global $bp;
332
-
333
- return in_array( $component_name, $bp->root_components );
334
- }
335
-
336
- /**
337
- * bp_core_setup_nav()
338
- *
339
- * Sets up the profile navigation item if the Xprofile component is not installed.
340
- *
341
- * @package BuddyPress Core
342
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
343
- * @uses bp_core_new_nav_item() Adds a navigation item to the top level buddypress navigation
344
- * @uses bp_core_new_subnav_item() Adds a sub navigation item to a nav item
345
- * @uses bp_is_my_profile() Returns true if the current user being viewed is equal the logged in user
346
- * @uses bp_core_fetch_avatar() Returns the either the thumb or full avatar URL for the user_id passed
347
- */
348
- function bp_core_setup_nav() {
349
- global $bp;
350
-
351
- /***
352
- * If the extended profiles component is disabled, we need to revert to using the
353
- * built in WordPress profile information
354
- */
355
- if ( !function_exists( 'xprofile_install' ) ) {
356
- /* Fallback values if xprofile is disabled */
357
- $bp->core->profile->slug = 'profile';
358
- $bp->active_components[$bp->core->profile->slug] = $bp->core->profile->slug;
359
-
360
- /* Add 'Profile' to the main navigation */
361
- bp_core_new_nav_item( array(
362
- 'name' => __('Profile', 'buddypress'),
363
- 'slug' => $bp->core->profile->slug,
364
- 'position' => 20,
365
- 'screen_function' => 'bp_core_catch_profile_uri',
366
- 'default_subnav_slug' => 'public'
367
- ) );
368
-
369
- $profile_link = $bp->loggedin_user->domain . '/profile/';
370
-
371
- /* Add the subnav items to the profile */
372
- bp_core_new_subnav_item( array(
373
- 'name' => __( 'Public', 'buddypress' ),
374
- 'slug' => 'public',
375
- 'parent_url' => $profile_link,
376
- 'parent_slug' => $bp->core->profile->slug,
377
- 'screen_function' => 'bp_core_catch_profile_uri'
378
- ) );
379
-
380
-
381
- if ( 'profile' == $bp->current_component ) {
382
- if ( bp_is_my_profile() ) {
383
- $bp->bp_options_title = __('My Profile', 'buddypress');
384
- } else {
385
- $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
386
- $bp->bp_options_title = $bp->displayed_user->fullname;
387
- }
388
- }
389
- }
390
- }
391
- add_action( 'bp_setup_nav', 'bp_core_setup_nav' );
392
-
393
- /********************************************************************************
394
- * Action Functions
395
- *
396
- * Action functions are exactly the same as screen functions, however they do not
397
- * have a template screen associated with them. Usually they will send the user
398
- * back to the default screen after execution.
399
- */
400
-
401
- /**
402
- * bp_core_action_directory_members()
403
- *
404
- * Listens to the $bp component and action variables to determine if the user is viewing the members
405
- * directory page. If they are, it will set up the directory and load the members directory template.
406
- *
407
- * @package BuddyPress Core
408
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
409
- * @uses wp_enqueue_script() Loads a JS script into the header of the page.
410
- * @uses bp_core_load_template() Loads a specific template file.
411
- */
412
- function bp_core_action_directory_members() {
413
- global $bp;
414
-
415
- if ( is_null( $bp->displayed_user->id ) && $bp->current_component == BP_MEMBERS_SLUG ) {
416
- $bp->is_directory = true;
417
-
418
- do_action( 'bp_core_action_directory_members' );
419
- bp_core_load_template( apply_filters( 'bp_core_template_directory_members', 'members/index' ) );
420
- }
421
- }
422
- add_action( 'wp', 'bp_core_action_directory_members', 2 );
423
-
424
- /**
425
- * bp_core_action_set_spammer_status()
426
- *
427
- * When a site admin selects "Mark as Spammer/Not Spammer" from the admin menu
428
- * this action will fire and mark or unmark the user and their blogs as spam.
429
- * Must be a site admin for this function to run.
430
- *
431
- * @package BuddyPress Core
432
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
433
- */
434
- function bp_core_action_set_spammer_status() {
435
- global $bp, $wpdb, $wp_version;
436
-
437
- if ( !is_super_admin() || bp_is_my_profile() || !$bp->displayed_user->id )
438
- return false;
439
-
440
- if ( 'admin' == $bp->current_component && ( 'mark-spammer' == $bp->current_action || 'unmark-spammer' == $bp->current_action ) ) {
441
- /* Check the nonce */
442
- check_admin_referer( 'mark-unmark-spammer' );
443
-
444
- /* Get the functions file */
445
- if ( bp_core_is_multisite() ) {
446
- if ( $wp_version >= '3.0' )
447
- require_once( ABSPATH . '/wp-admin/includes/ms.php' );
448
- else
449
- require_once( ABSPATH . '/wp-admin/includes/mu.php' );
450
- }
451
-
452
- if ( 'mark-spammer' == $bp->current_action )
453
- $is_spam = 1;
454
- else
455
- $is_spam = 0;
456
-
457
- /* Get the blogs for the user */
458
- $blogs = get_blogs_of_user( $bp->displayed_user->id, true );
459
-
460
- foreach ( (array) $blogs as $key => $details ) {
461
- /* Do not mark the main or current root blog as spam */
462
- if ( 1 == $details->userblog_id || BP_ROOT_BLOG == $details->userblog_id )
463
- continue;
464
-
465
- /* Update the blog status */
466
- update_blog_status( $details->userblog_id, 'spam', $is_spam );
467
-
468
- /* Fire the standard WPMU hook */
469
- do_action( 'make_spam_blog', $details->userblog_id );
470
- }
471
-
472
- /* Finally, mark this user as a spammer */
473
- if ( bp_core_is_multisite() )
474
- $wpdb->update( $wpdb->users, array( 'spam' => $is_spam ), array( 'ID' => $bp->displayed_user->id ) );
475
-
476
- $wpdb->update( $wpdb->users, array( 'user_status' => $is_spam ), array( 'ID' => $bp->displayed_user->id ) );
477
-
478
- if ( $is_spam )
479
- bp_core_add_message( __( 'User marked as spammer. Spam users are visible only to site admins.', 'buddypress' ) );
480
- else
481
- bp_core_add_message( __( 'User removed as spammer.', 'buddypress' ) );
482
-
483
- /* Hide this user's activity */
484
- if ( $is_spam && function_exists( 'bp_activity_hide_user_activity' ) )
485
- bp_activity_hide_user_activity( $bp->displayed_user->id );
486
-
487
- do_action( 'bp_core_action_set_spammer_status', $bp->displayed_user->id, $is_spam );
488
-
489
- bp_core_redirect( wp_get_referer() );
490
- }
491
- }
492
- add_action( 'wp', 'bp_core_action_set_spammer_status', 3 );
493
-
494
- /**
495
- * bp_core_action_delete_user()
496
- *
497
- * Allows a site admin to delete a user from the adminbar menu.
498
- *
499
- * @package BuddyPress Core
500
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
501
- */
502
- function bp_core_action_delete_user() {
503
- global $bp;
504
-
505
- if ( !is_super_admin() || bp_is_my_profile() || !$bp->displayed_user->id )
506
- return false;
507
-
508
- if ( 'admin' == $bp->current_component && 'delete-user' == $bp->current_action ) {
509
- /* Check the nonce */
510
- check_admin_referer( 'delete-user' );
511
-
512
- $errors = false;
513
-
514
- if ( bp_core_delete_account( $bp->displayed_user->id ) ) {
515
- bp_core_add_message( sprintf( __( '%s has been deleted from the system.', 'buddypress' ), $bp->displayed_user->fullname ) );
516
- } else {
517
- bp_core_add_message( sprintf( __( 'There was an error deleting %s from the system. Please try again.', 'buddypress' ), $bp->displayed_user->fullname ), 'error' );
518
- $errors = true;
519
- }
520
-
521
- do_action( 'bp_core_action_delete_user', $errors );
522
-
523
- if ( $errors )
524
- bp_core_redirect( $bp->displayed_user->domain );
525
- else
526
- bp_core_redirect( $bp->loggedin_user->domain );
527
- }
528
- }
529
- add_action( 'wp', 'bp_core_action_delete_user', 3 );
530
-
531
-
532
- /********************************************************************************
533
- * Business Functions
534
- *
535
- * Business functions are where all the magic happens in BuddyPress. They will
536
- * handle the actual saving or manipulation of information. Usually they will
537
- * hand off to a database class for data access, then return
538
- * true or false on success or failure.
539
- */
540
-
541
- /**
542
- * bp_core_get_users()
543
- *
544
- * Return an array of users IDs based on the parameters passed.
545
- *
546
- * @package BuddyPress Core
547
- */
548
- function bp_core_get_users( $args = '' ) {
549
- global $bp;
550
-
551
- $defaults = array(
552
- 'type' => 'active', // active, newest, alphabetical, random or popular
553
- 'user_id' => false, // Pass a user_id to limit to only friend connections for this user
554
- 'search_terms' => false, // Limit to users that match these search terms
555
-
556
- 'include' => false, // Pass comma separated list of user_ids to limit to only these users
557
- 'per_page' => 20, // The number of results to return per page
558
- 'page' => 1, // The page to return if limiting per page
559
- 'populate_extras' => true, // Fetch the last active, where the user is a friend, total friend count, latest update
560
- );
561
-
562
- $params = wp_parse_args( $args, $defaults );
563
- extract( $params, EXTR_SKIP );
564
-
565
- return apply_filters( 'bp_core_get_users', BP_Core_User::get_users( $type, $per_page, $page, $user_id, $include, $search_terms, $populate_extras ), &$params );
566
- }
567
-
568
- /**
569
- * bp_core_get_user_domain()
570
- *
571
- * Returns the domain for the passed user:
572
- * e.g. http://domain.com/members/andy/
573
- *
574
- * @package BuddyPress Core
575
- * @global $current_user WordPress global variable containing current logged in user information
576
- * @param user_id The ID of the user.
577
- * @uses get_user_meta() WordPress function to get the usermeta for a user.
578
- */
579
- function bp_core_get_user_domain( $user_id, $user_nicename = false, $user_login = false ) {
580
- global $bp;
581
-
582
- if ( !$user_id ) return;
583
-
584
- if ( !$domain = wp_cache_get( 'bp_user_domain_' . $user_id, 'bp' ) ) {
585
- $username = bp_core_get_username( $user_id, $user_nicename, $user_login );
586
-
587
- /* If we are using a members slug, include it. */
588
- if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) )
589
- $domain = $bp->root_domain . '/' . BP_MEMBERS_SLUG . '/' . $username . '/';
590
- else
591
- $domain = $bp->root_domain . '/' . $username . '/';
592
-
593
- /* Cache the link */
594
- if ( !empty( $domain ) )
595
- wp_cache_set( 'bp_user_domain_' . $user_id, $domain, 'bp' );
596
- }
597
-
598
- return apply_filters( 'bp_core_get_user_domain', $domain );
599
- }
600
-
601
- /**
602
- * bp_core_get_core_userdata()
603
- *
604
- * Fetch everything in the wp_users table for a user, without any usermeta.
605
- *
606
- * @package BuddyPress Core
607
- * @param user_id The ID of the user.
608
- * @uses BP_Core_User::get_core_userdata() Performs the query.
609
- */
610
- function bp_core_get_core_userdata( $user_id ) {
611
- if ( empty( $user_id ) )
612
- return false;
613
-
614
- if ( !$userdata = wp_cache_get( 'bp_core_userdata_' . $user_id, 'bp' ) ) {
615
- $userdata = BP_Core_User::get_core_userdata( $user_id );
616
- wp_cache_set( 'bp_core_userdata_' . $user_id, $userdata, 'bp' );
617
- }
618
- return apply_filters( 'bp_core_get_core_userdata', $userdata );
619
- }
620
-
621
- /**
622
- * bp_core_get_root_domain()
623
- *
624
- * Returns the domain for the root blog.
625
- * eg: http://domain.com/ OR https://domain.com
626
- *
627
- * @package BuddyPress Core
628
- * @uses get_blog_option() WordPress function to fetch blog meta.
629
- * @return $domain The domain URL for the blog.
630
- */
631
- function bp_core_get_root_domain() {
632
- global $current_blog;
633
-
634
- if ( defined( 'BP_ENABLE_MULTIBLOG' ) )
635
- $domain = get_blog_option( $current_blog->blog_id, 'home' );
636
- else
637
- $domain = get_blog_option( BP_ROOT_BLOG, 'home' );
638
-
639
- return apply_filters( 'bp_core_get_root_domain', $domain );
640
- }
641
-
642
- /**
643
- * bp_core_get_displayed_userid()
644
- *
645
- * Returns the user id for the user that is currently being displayed.
646
- * eg: http://andy.domain.com/ or http://domain.com/andy/
647
- *
648
- * @package BuddyPress Core
649
- * @global $current_blog WordPress global containing information and settings for the current blog being viewed.
650
- * @uses bp_core_get_userid_from_user_login() Returns the user id for the username passed
651
- * @return The user id for the user that is currently being displayed, return zero if this is not a user home and just a normal blog.
652
- */
653
- function bp_core_get_displayed_userid( $user_login ) {
654
- return apply_filters( 'bp_core_get_displayed_userid', bp_core_get_userid( $user_login ) );
655
- }
656
-
657
- /**
658
- * bp_core_new_nav_item()
659
- *
660
- * Adds a navigation item to the main navigation array used in BuddyPress themes.
661
- *
662
- * @package BuddyPress Core
663
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
664
- */
665
- function bp_core_new_nav_item( $args = '' ) {
666
- global $bp;
667
-
668
- $defaults = array(
669
- 'name' => false, // Display name for the nav item
670
- 'slug' => false, // URL slug for the nav item
671
- 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item
672
- 'show_for_displayed_user' => true, // When viewing another user does this nav item show up?
673
- 'site_admin_only' => false, // Can only site admins see this nav item?
674
- 'position' => 99, // Index of where this nav item should be positioned
675
- 'screen_function' => false, // The name of the function to run when clicked
676
- 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked
677
- );
678
-
679
- $r = wp_parse_args( $args, $defaults );
680
- extract( $r, EXTR_SKIP );
681
-
682
- /* If we don't have the required info we need, don't create this subnav item */
683
- if ( empty($name) || empty($slug) )
684
- return false;
685
-
686
- /* If this is for site admins only and the user is not one, don't create the subnav item */
687
- if ( $site_admin_only && !is_super_admin() )
688
- return false;
689
-
690
- if ( empty( $item_css_id ) )
691
- $item_css_id = $slug;
692
-
693
- $bp->bp_nav[$slug] = array(
694
- 'name' => $name,
695
- 'slug' => $slug,
696
- 'link' => $bp->loggedin_user->domain . $slug . '/',
697
- 'css_id' => $item_css_id,
698
- 'show_for_displayed_user' => $show_for_displayed_user,
699
- 'position' => $position
700
- );
701
-
702
- /***
703
- * If this nav item is hidden for the displayed user, and
704
- * the logged in user is not the displayed user
705
- * looking at their own profile, don't create the nav item.
706
- */
707
- if ( !$show_for_displayed_user && !bp_user_has_access() )
708
- return false;
709
-
710
- /***
711
- * If we are not viewing a user, and this is a root component, don't attach the
712
- * default subnav function so we can display a directory or something else.
713
- */
714
- if ( bp_core_is_root_component( $slug ) && !$bp->displayed_user->id )
715
- return;
716
-
717
- if ( $bp->current_component == $slug && !$bp->current_action ) {
718
- if ( !is_object( $screen_function[0] ) )
719
- add_action( 'wp', $screen_function, 3 );
720
- else
721
- add_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );
722
-
723
- if ( $default_subnav_slug )
724
- $bp->current_action = $default_subnav_slug;
725
- }
726
- }
727
-
728
- /**
729
- * bp_core_new_nav_default()
730
- *
731
- * Modify the default subnav item to load when a top level nav item is clicked.
732
- *
733
- * @package BuddyPress Core
734
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
735
- */
736
- function bp_core_new_nav_default( $args = '' ) {
737
- global $bp;
738
-
739
- $defaults = array(
740
- 'parent_slug' => false, // Slug of the parent
741
- 'screen_function' => false, // The name of the function to run when clicked
742
- 'subnav_slug' => false // The slug of the subnav item to select when clicked
743
- );
744
-
745
- $r = wp_parse_args( $args, $defaults );
746
- extract( $r, EXTR_SKIP );
747
-
748
- if ( $bp->current_component == $parent_slug && !$bp->current_action ) {
749
- if ( !is_object( $screen_function[0] ) )
750
- add_action( 'wp', $screen_function, 3 );
751
- else
752
- add_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );
753
-
754
- if ( $subnav_slug )
755
- $bp->current_action = $subnav_slug;
756
- }
757
- }
758
-
759
- /**
760
- * bp_core_sort_nav_items()
761
- *
762
- * We can only sort nav items by their position integer at a later point in time, once all
763
- * plugins have registered their navigation items.
764
- *
765
- * @package BuddyPress Core
766
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
767
- */
768
- function bp_core_sort_nav_items() {
769
- global $bp;
770
-
771
- if ( empty( $bp->bp_nav ) || !is_array( $bp->bp_nav ) )
772
- return false;
773
-
774
- foreach ( (array)$bp->bp_nav as $slug => $nav_item ) {
775
- if ( empty( $temp[$nav_item['position']]) )
776
- $temp[$nav_item['position']] = $nav_item;
777
- else {
778
- // increase numbers here to fit new items in.
779
- do {
780
- $nav_item['position']++;
781
- } while ( !empty( $temp[$nav_item['position']] ) );
782
-
783
- $temp[$nav_item['position']] = $nav_item;
784
- }
785
- }
786
-
787
- ksort( $temp );
788
- $bp->bp_nav = &$temp;
789
- }
790
- add_action( 'wp_head', 'bp_core_sort_nav_items' );
791
- add_action( 'admin_head', 'bp_core_sort_nav_items' );
792
-
793
- /**
794
- * bp_core_new_subnav_item()
795
- *
796
- * Adds a navigation item to the sub navigation array used in BuddyPress themes.
797
- *
798
- * @package BuddyPress Core
799
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
800
- */
801
- function bp_core_new_subnav_item( $args = '' ) {
802
- global $bp;
803
-
804
- $defaults = array(
805
- 'name' => false, // Display name for the nav item
806
- 'slug' => false, // URL slug for the nav item
807
- 'parent_slug' => false, // URL slug of the parent nav item
808
- 'parent_url' => false, // URL of the parent item
809
- 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item
810
- 'user_has_access' => true, // Can the logged in user see this nav item?
811
- 'site_admin_only' => false, // Can only site admins see this nav item?
812
- 'position' => 90, // Index of where this nav item should be positioned
813
- 'screen_function' => false // The name of the function to run when clicked
814
- );
815
-
816
- $r = wp_parse_args( $args, $defaults );
817
- extract( $r, EXTR_SKIP );
818
-
819
- /* If we don't have the required info we need, don't create this subnav item */
820
- if ( empty($name) || empty($slug) || empty($parent_slug) || empty($parent_url) || empty($screen_function) )
821
- return false;
822
-
823
- /* If this is for site admins only and the user is not one, don't create the subnav item */
824
- if ( $site_admin_only && !is_super_admin() )
825
- return false;
826
-
827
- if ( empty( $item_css_id ) )
828
- $item_css_id = $slug;
829
-
830
- $bp->bp_options_nav[$parent_slug][$slug] = array(
831
- 'name' => $name,
832
- 'link' => $parent_url . $slug . '/',
833
- 'slug' => $slug,
834
- 'css_id' => $item_css_id,
835
- 'position' => $position,
836
- 'user_has_access' => $user_has_access,
837
- 'screen_function' => $screen_function
838
- );
839
-
840
- if ( ( $bp->current_action == $slug && $bp->current_component == $parent_slug ) && $user_has_access ) {
841
- if ( !is_object( $screen_function[0] ) )
842
- add_action( 'wp', $screen_function, 3 );
843
- else
844
- add_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );
845
- }
846
- }
847
-
848
- function bp_core_sort_subnav_items() {
849
- global $bp;
850
-
851
- if ( empty( $bp->bp_options_nav ) || !is_array( $bp->bp_options_nav ) )
852
- return false;
853
-
854
- foreach ( (array)$bp->bp_options_nav as $parent_slug => $subnav_items ) {
855
- if ( !is_array( $subnav_items ) )
856
- continue;
857
-
858
- foreach ( (array)$subnav_items as $subnav_item ) {
859
- if ( empty( $temp[$subnav_item['position']]) )
860
- $temp[$subnav_item['position']] = $subnav_item;
861
- else {
862
- // increase numbers here to fit new items in.
863
- do {
864
- $subnav_item['position']++;
865
- } while ( !empty( $temp[$subnav_item['position']] ) );
866
-
867
- $temp[$subnav_item['position']] = $subnav_item;
868
- }
869
- }
870
- ksort( $temp );
871
- $bp->bp_options_nav[$parent_slug] = &$temp;
872
- unset($temp);
873
- }
874
- }
875
- add_action( 'wp_head', 'bp_core_sort_subnav_items' );
876
- add_action( 'admin_head', 'bp_core_sort_subnav_items' );
877
-
878
- /**
879
- * bp_core_remove_nav_item()
880
- *
881
- * Removes a navigation item from the sub navigation array used in BuddyPress themes.
882
- *
883
- * @package BuddyPress Core
884
- * @param $parent_id The id of the parent navigation item.
885
- * @param $slug The slug of the sub navigation item.
886
- */
887
- function bp_core_remove_nav_item( $parent_id ) {
888
- global $bp;
889
-
890
- /* Unset subnav items for this nav item */
891
- if ( is_array( $bp->bp_options_nav[$parent_id] ) ) {
892
- foreach( (array)$bp->bp_options_nav[$parent_id] as $subnav_item ) {
893
- bp_core_remove_subnav_item( $parent_id, $subnav_item['slug'] );
894
- }
895
- }
896
-
897
- unset( $bp->bp_nav[$parent_id] );
898
- }
899
-
900
- /**
901
- * bp_core_remove_subnav_item()
902
- *
903
- * Removes a navigation item from the sub navigation array used in BuddyPress themes.
904
- *
905
- * @package BuddyPress Core
906
- * @param $parent_id The id of the parent navigation item.
907
- * @param $slug The slug of the sub navigation item.
908
- */
909
- function bp_core_remove_subnav_item( $parent_id, $slug ) {
910
- global $bp;
911
-
912
- $screen_function = $bp->bp_options_nav[$parent_id][$slug]['screen_function'];
913
-
914
- if ( $screen_function ) {
915
- if ( !is_object( $screen_function[0] ) )
916
- remove_action( 'wp', $screen_function, 3 );
917
- else
918
- remove_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );
919
- }
920
-
921
- unset( $bp->bp_options_nav[$parent_id][$slug] );
922
-
923
- if ( !count( $bp->bp_options_nav[$parent_id] ) )
924
- unset($bp->bp_options_nav[$parent_id]);
925
- }
926
-
927
- /**
928
- * bp_core_reset_subnav_items()
929
- *
930
- * Clear the subnav items for a specific nav item.
931
- *
932
- * @package BuddyPress Core
933
- * @param $parent_id The id of the parent navigation item.
934
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
935
- */
936
- function bp_core_reset_subnav_items($parent_slug) {
937
- global $bp;
938
-
939
- unset($bp->bp_options_nav[$parent_slug]);
940
- }
941
-
942
- /**
943
- * bp_core_load_template()
944
- *
945
- * Uses the bp_catch_uri function to load a specific template file with fallback support.
946
- *
947
- * Example:
948
- * bp_core_load_template( 'profile/edit-profile' );
949
- * Loads:
950
- * wp-content/themes/[activated_theme]/profile/edit-profile.php
951
- *
952
- * @package BuddyPress Core
953
- * @param $username str Username to check.
954
- * @return false on no match
955
- * @return int the user ID of the matched user.
956
- */
957
- function bp_core_load_template( $template, $skip_blog_check = false ) {
958
- return bp_catch_uri( $template, $skip_blog_check );
959
- }
960
-
961
- /**
962
- * bp_core_add_root_component()
963
- *
964
- * Adds a component to the $bp->root_components global.
965
- * Any component that runs in the "root" of an install should be added.
966
- * The "root" as in, it can or always runs outside of the /members/username/ path.
967
- *
968
- * Example of a root component:
969
- * Groups: http://domain.com/groups/group-name
970
- * http://community.domain.com/groups/group-name
971
- * http://domain.com/wpmu/groups/group-name
972
- *
973
- * Example of a component that is NOT a root component:
974
- * Friends: http://domain.com/members/andy/friends
975
- * http://community.domain.com/members/andy/friends
976
- * http://domain.com/wpmu/members/andy/friends
977
- *
978
- * @package BuddyPress Core
979
- * @param $slug str The slug of the component
980
- * @global $bp BuddyPress global settings
981
- */
982
- function bp_core_add_root_component( $slug ) {
983
- global $bp;
984
-
985
- $bp->root_components[] = $slug;
986
- }
987
-
988
- /**
989
- * bp_core_get_random_member()
990
- *
991
- * Returns the user_id for a user based on their username.
992
- *
993
- * @package BuddyPress Core
994
- * @param $username str Username to check.
995
- * @return false on no match
996
- * @return int the user ID of the matched user.
997
- */
998
- function bp_core_get_random_member() {
999
- global $bp;
1000
-
1001
- if ( isset( $_GET['random-member'] ) ) {
1002
- $user = bp_core_get_users( array( 'type' => 'random', 'per_page' => 1 ) );
1003
- bp_core_redirect( bp_core_get_user_domain( $user['users'][0]->id ) );
1004
- }
1005
- }
1006
- add_action( 'wp', 'bp_core_get_random_member' );
1007
-
1008
- /**
1009
- * bp_core_get_userid()
1010
- *
1011
- * Returns the user_id for a user based on their username.
1012
- *
1013
- * @package BuddyPress Core
1014
- * @param $username str Username to check.
1015
- * @global $wpdb WordPress DB access object.
1016
- * @return false on no match
1017
- * @return int the user ID of the matched user.
1018
- */
1019
- function bp_core_get_userid( $username ) {
1020
- global $wpdb;
1021
-
1022
- if ( empty( $username ) )
1023
- return false;
1024
-
1025
- return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ) );
1026
- }
1027
-
1028
- /**
1029
- * bp_core_get_userid_from_nicename()
1030
- *
1031
- * Returns the user_id for a user based on their user_nicename.
1032
- *
1033
- * @package BuddyPress Core
1034
- * @param $username str Username to check.
1035
- * @global $wpdb WordPress DB access object.
1036
- * @return false on no match
1037
- * @return int the user ID of the matched user.
1038
- */
1039
- function bp_core_get_userid_from_nicename( $user_nicename ) {
1040
- global $wpdb;
1041
-
1042
- if ( empty( $user_nicename ) )
1043
- return false;
1044
-
1045
- return apply_filters( 'bp_core_get_userid_from_nicename', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_nicename = %s", $user_nicename ) ) );
1046
- }
1047
-
1048
- /**
1049
- * bp_core_get_username()
1050
- *
1051
- * Returns the username for a user based on their user id.
1052
- *
1053
- * @package BuddyPress Core
1054
- * @param $uid int User ID to check.
1055
- * @global $userdata WordPress user data for the current logged in user.
1056
- * @uses get_userdata() WordPress function to fetch the userdata for a user ID
1057
- * @return false on no match
1058
- * @return str the username of the matched user.
1059
- */
1060
- function bp_core_get_username( $user_id, $user_nicename = false, $user_login = false ) {
1061
- global $bp;
1062
-
1063
- if ( !$username = wp_cache_get( 'bp_user_username_' . $user_id, 'bp' ) ) {
1064
- if ( empty( $user_nicename ) && empty( $user_login ) ) {
1065
- $ud = false;
1066
-
1067
- if ( $bp->loggedin_user->id == $user_id )
1068
- $ud = &$bp->loggedin_user->userdata;
1069
-
1070
- if ( $bp->displayed_user->id == $user_id )
1071
- $ud = &$bp->displayed_user->userdata;
1072
-
1073
- if ( empty( $ud ) ) {
1074
- if ( !$ud = bp_core_get_core_userdata( $user_id ) )
1075
- return false;
1076
- }
1077
-
1078
- $user_nicename = $ud->user_nicename;
1079
- $user_login = $ud->user_login;
1080
- }
1081
-
1082
- if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
1083
- $username = $user_login;
1084
- else
1085
- $username = $user_nicename;
1086
- }
1087
-
1088
- /* Add this to cache */
1089
- if ( !empty( $username ) )
1090
- wp_cache_set( 'bp_user_username_' . $user_id, $username, 'bp' );
1091
-
1092
- return apply_filters( 'bp_core_get_username', $username );
1093
- }
1094
-
1095
- /**
1096
- * bp_core_get_user_email()
1097
- *
1098
- * Returns the email address for the user based on user ID
1099
- *
1100
- * @package BuddyPress Core
1101
- * @param $uid int User ID to check.
1102
- * @uses get_userdata() WordPress function to fetch the userdata for a user ID
1103
- * @return false on no match
1104
- * @return str The email for the matched user.
1105
- */
1106
- function bp_core_get_user_email( $uid ) {
1107
- if ( !$email = wp_cache_get( 'bp_user_email_' . $uid, 'bp' ) ) {
1108
- $ud = bp_core_get_core_userdata($uid);
1109
- $email = $ud->user_email;
1110
- wp_cache_set( 'bp_user_email_' . $uid, $email, 'bp' );
1111
- }
1112
-
1113
- return apply_filters( 'bp_core_get_user_email', $email );
1114
- }
1115
-
1116
- /**
1117
- * bp_core_get_userlink()
1118
- *
1119
- * Returns a HTML formatted link for a user with the user's full name as the link text.
1120
- * eg: <a href="http://andy.domain.com/">Andy Peatling</a>
1121
- * Optional parameters will return just the name, or just the URL, or disable "You" text when
1122
- * user matches the logged in user.
1123
- *
1124
- * [NOTES: This function needs to be cleaned up or split into separate functions]
1125
- *
1126
- * @package BuddyPress Core
1127
- * @param $uid int User ID to check.
1128
- * @param $no_anchor bool Disable URL and HTML and just return full name. Default false.
1129
- * @param $just_link bool Disable full name and HTML and just return the URL text. Default false.
1130
- * @param $no_you bool Disable replacing full name with "You" when logged in user is equal to the current user. Default false.
1131
- * @global $userdata WordPress user data for the current logged in user.
1132
- * @uses get_userdata() WordPress function to fetch the userdata for a user ID
1133
- * @uses bp_fetch_user_fullname() Returns the full name for a user based on user ID.
1134
- * @uses bp_core_get_userurl() Returns the URL for the user with no anchor tag based on user ID
1135
- * @return false on no match
1136
- * @return str The link text based on passed parameters.
1137
- */
1138
- function bp_core_get_userlink( $user_id, $no_anchor = false, $just_link = false ) {
1139
- $display_name = bp_core_get_user_displayname( $user_id );
1140
-
1141
- if ( empty( $display_name ) )
1142
- return false;
1143
-
1144
- if ( $no_anchor )
1145
- return $display_name;
1146
-
1147
- if ( !$url = bp_core_get_user_domain($user_id) )
1148
- return false;
1149
-
1150
- if ( $just_link )
1151
- return $url;
1152
-
1153
- return apply_filters( 'bp_core_get_userlink', '<a href="' . $url . '" title="' . $display_name . '">' . $display_name . '</a>', $user_id );
1154
- }
1155
-
1156
-
1157
- /**
1158
- * bp_core_get_user_displayname()
1159
- *
1160
- * Fetch the display name for a user. This will use the "Name" field in xprofile if it is installed.
1161
- * Otherwise, it will fall back to the normal WP display_name, or user_nicename, depending on what has been set.
1162
- *
1163
- * @package BuddyPress Core
1164
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
1165
- * @uses wp_cache_get() Will try and fetch the value from the cache, rather than querying the DB again.
1166
- * @uses get_userdata() Fetches the WP userdata for a specific user.
1167
- * @uses xprofile_set_field_data() Will update the field data for a user based on field name and user id.
1168
- * @uses wp_cache_set() Adds a value to the cache.
1169
- * @return str The display name for the user in question.
1170
- */
1171
- function bp_core_get_user_displayname( $user_id_or_username ) {
1172
- global $bp;
1173
-
1174
- if ( !$user_id_or_username )
1175
- return false;
1176
-
1177
- if ( !is_numeric( $user_id_or_username ) )
1178
- $user_id = bp_core_get_userid( $user_id_or_username );
1179
- else
1180
- $user_id = $user_id_or_username;
1181
-
1182
- if ( !$user_id )
1183
- return false;
1184
-
1185
- if ( !$fullname = wp_cache_get( 'bp_user_fullname_' . $user_id, 'bp' ) ) {
1186
- if ( function_exists('xprofile_install') ) {
1187
- $fullname = xprofile_get_field_data( 1, $user_id );
1188
-
1189
- if ( empty($fullname) ) {
1190
- $ud = bp_core_get_core_userdata( $user_id );
1191
-
1192
- if ( !empty( $ud->display_name ) )
1193
- $fullname = $ud->display_name;
1194
- else
1195
- $fullname = $ud->user_nicename;
1196
-
1197
- xprofile_set_field_data( 1, $user_id, $fullname );
1198
- }
1199
- } else {
1200
- $ud = bp_core_get_core_userdata($user_id);
1201
-
1202
- if ( !empty( $ud->display_name ) )
1203
- $fullname = $ud->display_name;
1204
- else
1205
- $fullname = $ud->user_nicename;
1206
- }
1207
-
1208
- if ( !empty( $fullname ) )
1209
- wp_cache_set( 'bp_user_fullname_' . $user_id, $fullname, 'bp' );
1210
- }
1211
-
1212
- return apply_filters( 'bp_core_get_user_displayname', $fullname, $user_id );
1213
- }
1214
- add_filter( 'bp_core_get_user_displayname', 'strip_tags', 1 );
1215
- add_filter( 'bp_core_get_user_displayname', 'trim' );
1216
- add_filter( 'bp_core_get_user_displayname', 'stripslashes' );
1217
-
1218
-
1219
- /**
1220
- * bp_core_get_userlink_by_email()
1221
- *
1222
- * Returns the user link for the user based on user email address
1223
- *
1224
- * @package BuddyPress Core
1225
- * @param $email str The email address for the user.
1226
- * @uses bp_core_get_userlink() BuddyPress function to get a userlink by user ID.
1227
- * @uses get_user_by_email() WordPress function to get userdata via an email address
1228
- * @return str The link to the users home base. False on no match.
1229
- */
1230
- function bp_core_get_userlink_by_email( $email ) {
1231
- $user = get_user_by_email( $email );
1232
- return apply_filters( 'bp_core_get_userlink_by_email', bp_core_get_userlink( $user->ID, false, false, true ) );
1233
- }
1234
-
1235
- /**
1236
- * bp_core_get_userlink_by_username()
1237
- *
1238
- * Returns the user link for the user based on user's username
1239
- *
1240
- * @package BuddyPress Core
1241
- * @param $username str The username for the user.
1242
- * @uses bp_core_get_userlink() BuddyPress function to get a userlink by user ID.
1243
- * @return str The link to the users home base. False on no match.
1244
- */
1245
- function bp_core_get_userlink_by_username( $username ) {
1246
- global $wpdb;
1247
-
1248
- $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) );
1249
- return apply_filters( 'bp_core_get_userlink_by_username', bp_core_get_userlink( $user_id, false, false, true ) );
1250
- }
1251
-
1252
- /**
1253
- * bp_core_get_total_member_count()
1254
- *
1255
- * Returns the total number of members for the installation.
1256
- *
1257
- * @package BuddyPress Core
1258
- * @return int The total number of members.
1259
- */
1260
- function bp_core_get_total_member_count() {
1261
- global $wpdb, $bp;
1262
-
1263
- if ( !$count = wp_cache_get( 'bp_total_member_count', 'bp' ) ) {
1264
- $status_sql = bp_core_get_status_sql();
1265
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM " . CUSTOM_USER_TABLE . " WHERE {$status_sql}" ) );
1266
- wp_cache_set( 'bp_total_member_count', $count, 'bp' );
1267
- }
1268
-
1269
- return apply_filters( 'bp_core_get_total_member_count', $count );
1270
- }
1271
-
1272
- /**
1273
- * bp_core_is_user_spammer()
1274
- *
1275
- * Checks if the user has been marked as a spammer.
1276
- *
1277
- * @package BuddyPress Core
1278
- * @param $user_id int The id for the user.
1279
- * @return int 1 if spammer, 0 if not.
1280
- */
1281
- function bp_core_is_user_spammer( $user_id ) {
1282
- global $wpdb;
1283
-
1284
- if ( bp_core_is_multisite() )
1285
- $is_spammer = (int) $wpdb->get_var( $wpdb->prepare( "SELECT spam FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) );
1286
- else
1287
- $is_spammer = (int) $wpdb->get_var( $wpdb->prepare( "SELECT user_status FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) );
1288
-
1289
- return apply_filters( 'bp_core_is_user_spammer', $is_spammer );
1290
- }
1291
-
1292
- /**
1293
- * bp_core_is_user_deleted()
1294
- *
1295
- * Checks if the user has been marked as deleted.
1296
- *
1297
- * @package BuddyPress Core
1298
- * @param $user_id int The id for the user.
1299
- * @return int 1 if deleted, 0 if not.
1300
- */
1301
- function bp_core_is_user_deleted( $user_id ) {
1302
- global $wpdb;
1303
-
1304
- return apply_filters( 'bp_core_is_user_spammer', (int) $wpdb->get_var( $wpdb->prepare( "SELECT deleted FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) ) );
1305
- }
1306
-
1307
- /**
1308
- * bp_core_current_time()
1309
- *
1310
- * Get the current GMT time to save into the DB
1311
- *
1312
- * @package BuddyPress Core
1313
- * @since 1.2.6
1314
- */
1315
- function bp_core_current_time( $gmt = true ) {
1316
- // Get current time in MYSQL format
1317
- $current_time = current_time( 'mysql', $gmt );
1318
-
1319
- return apply_filters( 'bp_core_current_time', $current_time );
1320
- }
1321
-
1322
- /**
1323
- * bp_core_add_message()
1324
- *
1325
- * Adds a feedback (error/success) message to the WP cookie so it can be displayed after the page reloads.
1326
- *
1327
- * @package BuddyPress Core
1328
- */
1329
- function bp_core_add_message( $message, $type = false ) {
1330
- global $bp;
1331
-
1332
- if ( !$type )
1333
- $type = 'success';
1334
-
1335
- /* Send the values to the cookie for page reload display */
1336
- @setcookie( 'bp-message', $message, time()+60*60*24, COOKIEPATH );
1337
- @setcookie( 'bp-message-type', $type, time()+60*60*24, COOKIEPATH );
1338
-
1339
- /***
1340
- * Send the values to the $bp global so we can still output messages
1341
- * without a page reload
1342
- */
1343
- $bp->template_message = $message;
1344
- $bp->template_message_type = $type;
1345
- }
1346
-
1347
- /**
1348
- * bp_core_setup_message()
1349
- *
1350
- * Checks if there is a feedback message in the WP cookie, if so, adds a "template_notices" action
1351
- * so that the message can be parsed into the template and displayed to the user.
1352
- *
1353
- * After the message is displayed, it removes the message vars from the cookie so that the message
1354
- * is not shown to the user multiple times.
1355
- *
1356
- * @package BuddyPress Core
1357
- * @global $bp_message The message text
1358
- * @global $bp_message_type The type of message (error/success)
1359
- * @uses setcookie() Sets a cookie value for the user.
1360
- */
1361
- function bp_core_setup_message() {
1362
- global $bp;
1363
-
1364
- if ( empty( $bp->template_message ) )
1365
- $bp->template_message = $_COOKIE['bp-message'];
1366
-
1367
- if ( empty( $bp->template_message_type ) )
1368
- $bp->template_message_type = $_COOKIE['bp-message-type'];
1369
-
1370
- add_action( 'template_notices', 'bp_core_render_message' );
1371
-
1372
- @setcookie( 'bp-message', false, time() - 1000, COOKIEPATH );
1373
- @setcookie( 'bp-message-type', false, time() - 1000, COOKIEPATH );
1374
- }
1375
- add_action( 'wp', 'bp_core_setup_message', 2 );
1376
-
1377
- /**
1378
- * bp_core_render_message()
1379
- *
1380
- * Renders a feedback message (either error or success message) to the theme template.
1381
- * The hook action 'template_notices' is used to call this function, it is not called directly.
1382
- *
1383
- * @package BuddyPress Core
1384
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
1385
- */
1386
- function bp_core_render_message() {
1387
- global $bp;
1388
-
1389
- if ( $bp->template_message ) {
1390
- $type = ( 'success' == $bp->template_message_type ) ? 'updated' : 'error';
1391
- ?>
1392
- <div id="message" class="<?php echo $type; ?>">
1393
- <p><?php echo stripslashes( esc_attr( $bp->template_message ) ); ?></p>
1394
- </div>
1395
- <?php
1396
- do_action( 'bp_core_render_message' );
1397
- }
1398
- }
1399
-
1400
- /**
1401
- * bp_core_time_since()
1402
- *
1403
- * Based on function created by Dunstan Orchard - http://1976design.com
1404
- *
1405
- * This function will return an English representation of the time elapsed
1406
- * since a given date.
1407
- * eg: 2 hours and 50 minutes
1408
- * eg: 4 days
1409
- * eg: 4 weeks and 6 days
1410
- *
1411
- * @package BuddyPress Core
1412
- * @param $older_date int Unix timestamp of date you want to calculate the time since for
1413
- * @param $newer_date int Unix timestamp of date to compare older date to. Default false (current time).
1414
- * @return str The time since.
1415
- */
1416
- function bp_core_time_since( $older_date, $newer_date = false ) {
1417
-
1418
- // array of time period chunks
1419
- $chunks = array(
1420
- array( 60 * 60 * 24 * 365 , __( 'year', 'buddypress' ), __( 'years', 'buddypress' ) ),
1421
- array( 60 * 60 * 24 * 30 , __( 'month', 'buddypress' ), __( 'months', 'buddypress' ) ),
1422
- array( 60 * 60 * 24 * 7, __( 'week', 'buddypress' ), __( 'weeks', 'buddypress' ) ),
1423
- array( 60 * 60 * 24 , __( 'day', 'buddypress' ), __( 'days', 'buddypress' ) ),
1424
- array( 60 * 60 , __( 'hour', 'buddypress' ), __( 'hours', 'buddypress' ) ),
1425
- array( 60 , __( 'minute', 'buddypress' ), __( 'minutes', 'buddypress' ) ),
1426
- array( 1, __( 'second', 'buddypress' ), __( 'seconds', 'buddypress' ) )
1427
- );
1428
-
1429
- if ( !is_numeric( $older_date ) ) {
1430
- $time_chunks = explode( ':', str_replace( ' ', ':', $older_date ) );
1431
- $date_chunks = explode( '-', str_replace( ' ', '-', $older_date ) );
1432
-
1433
- $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] );
1434
- }
1435
-
1436
- /* $newer_date will equal false if we want to know the time elapsed between a date and the current time */
1437
- /* $newer_date will have a value if we want to work out time elapsed between two known dates */
1438
- $newer_date = ( !$newer_date ) ? strtotime( bp_core_current_time() ) : $newer_date;
1439
-
1440
- /* Difference in seconds */
1441
- $since = $newer_date - $older_date;
1442
-
1443
- /* Something went wrong with date calculation and we ended up with a negative date. */
1444
- if ( 0 > $since )
1445
- return __( 'sometime', 'buddypress' );
1446
-
1447
- /**
1448
- * We only want to output two chunks of time here, eg:
1449
- * x years, xx months
1450
- * x days, xx hours
1451
- * so there's only two bits of calculation below:
1452
- */
1453
-
1454
- /* Step one: the first chunk */
1455
- for ( $i = 0, $j = count($chunks); $i < $j; $i++) {
1456
- $seconds = $chunks[$i][0];
1457
-
1458
- /* Finding the biggest chunk (if the chunk fits, break) */
1459
- if ( ( $count = floor($since / $seconds) ) != 0 )
1460
- break;
1461
- }
1462
-
1463
- /* Set output var */
1464
- $output = ( 1 == $count ) ? '1 '. $chunks[$i][1] : $count . ' ' . $chunks[$i][2];
1465
-
1466
- /* Step two: the second chunk */
1467
- if ( $i + 2 < $j ) {
1468
- $seconds2 = $chunks[$i + 1][0];
1469
- $name2 = $chunks[$i + 1][1];
1470
-
1471
- if ( ( $count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 ) ) != 0 ) {
1472
- /* Add to output var */
1473
- $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];
1474
- }
1475
- }
1476
-
1477
- if ( !(int)trim($output) )
1478
- $output = '0 ' . __( 'seconds', 'buddypress' );
1479
-
1480
- return $output;
1481
- }
1482
-
1483
-
1484
- /**
1485
- * bp_core_record_activity()
1486
- *
1487
- * Record user activity to the database. Many functions use a "last active" feature to
1488
- * show the length of time since the user was last active.
1489
- * This function will update that time as a usermeta setting for the user every 5 minutes.
1490
- *
1491
- * @package BuddyPress Core
1492
- * @global $userdata WordPress user data for the current logged in user.
1493
- * @uses update_user_meta() WordPress function to update user metadata in the usermeta table.
1494
- */
1495
- function bp_core_record_activity() {
1496
- global $bp;
1497
-
1498
- if ( !is_user_logged_in() )
1499
- return false;
1500
-
1501
- $activity = get_user_meta( $bp->loggedin_user->id, 'last_activity', true );
1502
-
1503
- if ( !is_numeric( $activity ) )
1504
- $activity = strtotime( $activity );
1505
-
1506
- // Get current time
1507
- $current_time = bp_core_current_time();
1508
-
1509
- if ( '' == $activity || strtotime( $current_time ) >= strtotime( '+5 minutes', $activity ) )
1510
- update_user_meta( $bp->loggedin_user->id, 'last_activity', $current_time );
1511
- }
1512
- add_action( 'wp_head', 'bp_core_record_activity' );
1513
-
1514
-
1515
- /**
1516
- * bp_core_get_last_activity()
1517
- *
1518
- * Formats last activity based on time since date given.
1519
- *
1520
- * @package BuddyPress Core
1521
- * @param last_activity_date The date of last activity.
1522
- * @param $before The text to prepend to the activity time since figure.
1523
- * @param $after The text to append to the activity time since figure.
1524
- * @uses bp_core_time_since() This function will return an English representation of the time elapsed.
1525
- */
1526
- function bp_core_get_last_activity( $last_activity_date, $string ) {
1527
- if ( !$last_activity_date || empty( $last_activity_date ) ) {
1528
- $last_active = __( 'not recently active', 'buddypress' );
1529
- } else {
1530
- $last_active = sprintf( $string, bp_core_time_since( $last_activity_date ) );
1531
- }
1532
-
1533
- return apply_filters( 'bp_core_get_last_activity', $last_active, $last_activity_date, $string );
1534
- }
1535
-
1536
- function bp_core_number_format( $number, $decimals = false ) {
1537
- /* Check we actually have a number first. */
1538
- if ( empty( $number ) )
1539
- return $number;
1540
-
1541
- return apply_filters( 'bp_core_number_format', number_format( $number, $decimals ), $number, $decimals );
1542
- }
1543
-
1544
- /**
1545
- * bp_core_get_all_posts_for_user()
1546
- *
1547
- * Fetch every post that is authored by the given user for the current blog.
1548
- *
1549
- * @package BuddyPress Core
1550
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
1551
- * @global $wpdb WordPress user data for the current logged in user.
1552
- * @return array of post ids.
1553
- */
1554
- function bp_core_get_all_posts_for_user( $user_id = null ) {
1555
- global $bp, $wpdb;
1556
-
1557
- if ( !$user_id )
1558
- $user_id = $bp->displayed_user->id;
1559
-
1560
- return apply_filters( 'bp_core_get_all_posts_for_user', $wpdb->get_col( $wpdb->prepare( "SELECT post_id FROM $wpdb->posts WHERE post_author = %d AND post_status = 'publish' AND post_type = 'post'", $user_id ) ) );
1561
- }
1562
-
1563
- /**
1564
- * bp_core_get_site_path()
1565
- *
1566
- * Get the path of of the current site.
1567
- *
1568
- * @package BuddyPress Core
1569
- *
1570
- * @global $bp $bp
1571
- * @global object $current_site
1572
- * @return string
1573
- */
1574
- function bp_core_get_site_path() {
1575
- global $bp, $current_site;
1576
-
1577
- if ( bp_core_is_multisite() )
1578
- $site_path = $current_site->path;
1579
- else {
1580
- $site_path = (array) explode( '/', site_url() );
1581
-
1582
- if ( count( $site_path ) < 2 )
1583
- $site_path = '/';
1584
- else {
1585
- /* Unset the first three segments (http(s)://domain.com part) */
1586
- unset( $site_path[0] );
1587
- unset( $site_path[1] );
1588
- unset( $site_path[2] );
1589
-
1590
- if ( !count( $site_path ) )
1591
- $site_path = '/';
1592
- else
1593
- $site_path = '/' . implode( '/', $site_path ) . '/';
1594
- }
1595
- }
1596
-
1597
- return apply_filters( 'bp_core_get_site_path', $site_path );
1598
- }
1599
- /**
1600
- * bp_core_get_site_options()
1601
- *
1602
- * BuddyPress uses site options to store configuration settings. Many of these settings are needed
1603
- * at run time. Instead of fetching them all and adding many initial queries to each page load, let's fetch
1604
- * them all in one go.
1605
- *
1606
- * @package BuddyPress Core
1607
- */
1608
- function bp_core_get_site_options() {
1609
- global $bp, $wpdb;
1610
-
1611
- $options = apply_filters( 'bp_core_site_options', array(
1612
- 'bp-deactivated-components',
1613
- 'bp-blogs-first-install',
1614
- 'bp-disable-blog-forum-comments',
1615
- 'bp-xprofile-base-group-name',
1616
- 'bp-xprofile-fullname-field-name',
1617
- 'bp-disable-profile-sync',
1618
- 'bp-disable-avatar-uploads',
1619
- 'bp-disable-account-deletion',
1620
- 'bp-disable-forum-directory',
1621
- 'bp-disable-blogforum-comments',
1622
- 'bb-config-location',
1623
- 'hide-loggedout-adminbar',
1624
-
1625
- /* Useful WordPress settings used often */
1626
- 'user-avatar-default',
1627
- 'tags_blog_id',
1628
- 'registration',
1629
- 'fileupload_maxk'
1630
- ) );
1631
-
1632
- $meta_keys = "'" . implode( "','", (array)$options ) ."'";
1633
-
1634
- if ( bp_core_is_multisite() )
1635
- $meta = $wpdb->get_results( "SELECT meta_key AS name, meta_value AS value FROM {$wpdb->sitemeta} WHERE meta_key IN ({$meta_keys}) AND site_id = {$wpdb->siteid}" );
1636
- else
1637
- $meta = $wpdb->get_results( "SELECT option_name AS name, option_value AS value FROM {$wpdb->options} WHERE option_name IN ({$meta_keys})" );
1638
-
1639
- $site_options = array();
1640
- if ( !empty( $meta ) ) {
1641
- foreach( (array)$meta as $meta_item )
1642
- $site_options[$meta_item->name] = $meta_item->value;
1643
- }
1644
-
1645
- return apply_filters( 'bp_core_get_site_options', $site_options );
1646
- }
1647
-
1648
- /**
1649
- * bp_core_redirect()
1650
- *
1651
- * Performs a status safe wp_redirect() that is compatible with bp_catch_uri()
1652
- *
1653
- * @package BuddyPress Core
1654
- * @global $bp_no_status_set Makes sure that there are no conflicts with status_header() called in bp_core_do_catch_uri()
1655
- * @uses get_themes()
1656
- * @return An array containing all of the themes.
1657
- */
1658
- function bp_core_redirect( $location, $status = 302 ) {
1659
- global $bp_no_status_set;
1660
-
1661
- // Make sure we don't call status_header() in bp_core_do_catch_uri()
1662
- // as this conflicts with wp_redirect()
1663
- $bp_no_status_set = true;
1664
-
1665
- wp_redirect( $location, $status );
1666
- die;
1667
- }
1668
-
1669
- /**
1670
- * bp_core_referrer()
1671
- *
1672
- * Returns the referrer URL without the http(s)://
1673
- *
1674
- * @package BuddyPress Core
1675
- * @return The referrer URL
1676
- */
1677
- function bp_core_referrer() {
1678
- $referer = explode( '/', wp_get_referer() );
1679
- unset( $referer[0], $referer[1], $referer[2] );
1680
- return implode( '/', $referer );
1681
- }
1682
-
1683
- /**
1684
- * bp_core_get_illegal_names()
1685
- *
1686
- * Return a friendly and filtered list of all illegal names to prevent crafty
1687
- * individuals from hi-jacking your network's components and/or administration
1688
- *
1689
- * For example, it would stop someone creating a blog with the slug "groups".
1690
- */
1691
- function bp_core_get_illegal_names() {
1692
-
1693
- // BuddyPress core illegal names
1694
- $bp_illegal_names[] = defined( 'BP_GROUPS_SLUG' ) ? BP_GROUPS_SLUG : 'groups';
1695
- $bp_illegal_names[] = defined( 'BP_MEMBERS_SLUG' ) ? BP_MEMBERS_SLUG : 'members';
1696
- $bp_illegal_names[] = defined( 'BP_FORUMS_SLUG' ) ? BP_FORUMS_SLUG : 'forums';
1697
- $bp_illegal_names[] = defined( 'BP_BLOGS_SLUG' ) ? BP_BLOGS_SLUG : 'blogs';
1698
- $bp_illegal_names[] = defined( 'BP_ACTIVITY_SLUG' ) ? BP_ACTIVITY_SLUG : 'activity';
1699
- $bp_illegal_names[] = defined( 'BP_XPROFILE_SLUG' ) ? BP_XPROFILE_SLUG : 'profile';
1700
- $bp_illegal_names[] = defined( 'BP_FRIENDS_SLUG' ) ? BP_FRIENDS_SLUG : 'friends';
1701
- $bp_illegal_names[] = defined( 'BP_SEARCH_SLUG' ) ? BP_SEARCH_SLUG : 'search';
1702
- $bp_illegal_names[] = defined( 'BP_SETTINGS_SLUG' ) ? BP_SETTINGS_SLUG : 'settings';
1703
- $bp_illegal_names[] = defined( 'BP_REGISTER_SLUG' ) ? BP_REGISTER_SLUG : 'register';
1704
- $bp_illegal_names[] = defined( 'BP_ACTIVATION_SLUG' ) ? BP_ACTIVATION_SLUG : 'activation';
1705
-
1706
- // WordPress core illegal names
1707
- $wp_illegal_names = array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', 'files' );
1708
-
1709
- // Merge illegal names together and filter them
1710
- return apply_filters( 'bp_core_illegal_names', array_merge( $bp_illegal_names, $wp_illegal_names ) );
1711
- }
1712
-
1713
- /**
1714
- * bp_core_update_illegal_names()
1715
- *
1716
- * Filter the illegal_names site option and make sure it includes a few
1717
- * specific BuddyPress and multi-site slugs
1718
- *
1719
- * @param array|string $value Illegal names from field
1720
- * @param array|string $oldvalue The value as it is currently
1721
- * @return array Merged and unique array of illegal names
1722
- */
1723
- function bp_core_update_illegal_names( $value = '', $oldvalue = '' ) {
1724
- if ( !bp_core_is_multisite() )
1725
- return false;
1726
-
1727
- // Make sure $value is array
1728
- if ( is_array( $value ) )
1729
- $db_illegal_names = $value;
1730
- elseif ( is_string( $value ) )
1731
- $db_illegal_names = implode( ' ', $value );
1732
- elseif ( empty( $value ) )
1733
- $db_illegal_names = array();
1734
-
1735
- // Get illegal names, merge with ones in DB, and remove duplicates
1736
- $bp_illegal_names = bp_core_get_illegal_names();
1737
- $merged_names = array_merge( (array)$bp_illegal_names, (array)$db_illegal_names );
1738
- $illegal_names = array_unique( (array)$merged_names );
1739
-
1740
- return apply_filters( 'bp_core_update_illegal_names', $illegal_names );
1741
- }
1742
- add_filter( 'pre_update_site_option_illegal_names', 'bp_core_update_illegal_names', 10, 2 );
1743
-
1744
- /**
1745
- * bp_core_flush_illegal_names()
1746
- *
1747
- * Flush illegal names by getting and setting 'illegal_names' site option
1748
- */
1749
- function bp_core_flush_illegal_names() {
1750
- $illegal_names = get_site_option( 'illegal_names' );
1751
- update_site_option( 'illegal_names', $illegal_names );
1752
- }
1753
-
1754
- /**
1755
- * bp_core_delete_account()
1756
- *
1757
- * Allows a user to completely remove their account from the system
1758
- *
1759
- * @package BuddyPress Core
1760
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
1761
- * @uses is_super_admin() Checks to see if the user is a site administrator.
1762
- * @uses wpmu_delete_user() Deletes a user from the system on multisite installs.
1763
- * @uses wp_delete_user() Deletes a user from the system on singlesite installs.
1764
- * @uses get_site_option Checks if account deletion is allowed
1765
- */
1766
- function bp_core_delete_account( $user_id = false ) {
1767
- global $bp, $wp_version;
1768
-
1769
- if ( !$user_id )
1770
- $user_id = $bp->loggedin_user->id;
1771
-
1772
- /* Make sure account deletion is not disabled */
1773
- if ( (int)get_site_option( 'bp-disable-account-deletion' ) && !$bp->loggedin_user->is_site_admin )
1774
- return false;
1775
-
1776
- /* Site admins cannot be deleted */
1777
- if ( is_super_admin( bp_core_get_username( $user_id ) ) )
1778
- return false;
1779
-
1780
- /* Specifically handle multi-site environment */
1781
- if ( bp_core_is_multisite() ) {
1782
- if ( $wp_version >= '3.0' )
1783
- require_once( ABSPATH . '/wp-admin/includes/ms.php' );
1784
- else
1785
- require_once( ABSPATH . '/wp-admin/includes/mu.php' );
1786
-
1787
- require_once( ABSPATH . '/wp-admin/includes/user.php' );
1788
-
1789
- return wpmu_delete_user( $user_id );
1790
-
1791
- /* Single site user deletion */
1792
- } else {
1793
- require_once( ABSPATH . '/wp-admin/includes/user.php' );
1794
- return wp_delete_user( $user_id );
1795
- }
1796
- }
1797
-
1798
-
1799
- /**
1800
- * bp_core_search_site()
1801
- *
1802
- * A javascript free implementation of the search functions in BuddyPress
1803
- *
1804
- * @package BuddyPress Core
1805
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
1806
- * @param $slug The slug to redirect to for searching.
1807
- */
1808
- function bp_core_action_search_site( $slug = false ) {
1809
- global $bp;
1810
-
1811
- if ( $bp->current_component == BP_SEARCH_SLUG ) {
1812
- $search_terms = $_POST['search-terms'];
1813
- $search_which = $_POST['search-which'];
1814
-
1815
- if ( !$slug || empty( $slug ) ) {
1816
- switch ( $search_which ) {
1817
- case 'members': default:
1818
- $slug = BP_MEMBERS_SLUG;
1819
- $var = '/?s=';
1820
- break;
1821
- case 'groups':
1822
- $slug = BP_GROUPS_SLUG;
1823
- $var = '/?s=';
1824
- break;
1825
- case 'forums':
1826
- $slug = BP_FORUMS_SLUG;
1827
- $var = '/?fs=';
1828
- break;
1829
- case 'blogs':
1830
- $slug = BP_BLOGS_SLUG;
1831
- $var = '/?s=';
1832
- break;
1833
- }
1834
- }
1835
-
1836
- $search_url = apply_filters( 'bp_core_search_site', site_url( $slug . $var . urlencode($search_terms) ), $search_terms );
1837
-
1838
- bp_core_redirect( $search_url );
1839
- }
1840
- }
1841
- add_action( 'init', 'bp_core_action_search_site', 5 );
1842
-
1843
-
1844
- /**
1845
- * bp_core_ucfirst()
1846
- *
1847
- * Localization safe ucfirst() support.
1848
- *
1849
- * @package BuddyPress Core
1850
- */
1851
- function bp_core_ucfirst( $str ) {
1852
- if ( function_exists( 'mb_strtoupper' ) && function_exists( 'mb_substr' ) ) {
1853
- $fc = mb_strtoupper( mb_substr( $str, 0, 1 ) );
1854
- return $fc.mb_substr( $str, 1 );
1855
- } else {
1856
- return ucfirst( $str );
1857
- }
1858
- }
1859
-
1860
-
1861
- /**
1862
- * bp_core_strip_username_spaces()
1863
- *
1864
- * Strips spaces from usernames that are created using add_user() and wp_insert_user()
1865
- *
1866
- * @package BuddyPress Core
1867
- */
1868
- function bp_core_strip_username_spaces( $username ) {
1869
- return str_replace( ' ', '-', $username );
1870
- }
1871
- add_action( 'pre_user_login', 'bp_core_strip_username_spaces' );
1872
-
1873
-
1874
- /**
1875
- * bp_core_clear_cache()
1876
- * REQUIRES WP-SUPER-CACHE
1877
- *
1878
- * When wp-super-cache is installed this function will clear cached pages
1879
- * so that success/error messages are not cached, or time sensitive content.
1880
- *
1881
- * @package BuddyPress Core
1882
- */
1883
- function bp_core_clear_cache() {
1884
- global $cache_path, $cache_filename;
1885
-
1886
- if ( function_exists( 'prune_super_cache' ) ) {
1887
- do_action( 'bp_core_clear_cache' );
1888
-
1889
- return prune_super_cache( $cache_path, true );
1890
- }
1891
- }
1892
-
1893
- /**
1894
- * bp_core_print_generation_time()
1895
- *
1896
- * Prints the generation time in the footer of the site.
1897
- *
1898
- * @package BuddyPress Core
1899
- */
1900
- function bp_core_print_generation_time() {
1901
- ?>
1902
-
1903
- <!-- Generated in <?php timer_stop(1); ?> seconds. -->
1904
-
1905
- <?php
1906
- }
1907
- add_action( 'wp_footer', 'bp_core_print_generation_time' );
1908
-
1909
- /**
1910
- * bp_core_add_admin_menu_page()
1911
- *
1912
- * A better version of add_admin_menu_page() that allows positioning of menus.
1913
- *
1914
- * @package BuddyPress Core
1915
- */
1916
- function bp_core_add_admin_menu_page( $args = '' ) {
1917
- global $menu, $admin_page_hooks, $_registered_pages;
1918
-
1919
- $defaults = array(
1920
- 'page_title' => '',
1921
- 'menu_title' => '',
1922
- 'access_level' => 2,
1923
- 'file' => false,
1924
- 'function' => false,
1925
- 'icon_url' => false,
1926
- 'position' => 100
1927
- );
1928
-
1929
- $r = wp_parse_args( $args, $defaults );
1930
- extract( $r, EXTR_SKIP );
1931
-
1932
- $file = plugin_basename( $file );
1933
-
1934
- $admin_page_hooks[$file] = sanitize_title( $menu_title );
1935
-
1936
- $hookname = get_plugin_page_hookname( $file, '' );
1937
- if (!empty ( $function ) && !empty ( $hookname ))
1938
- add_action( $hookname, $function );
1939
-
1940
- if ( empty($icon_url) )
1941
- $icon_url = 'images/generic.png';
1942
- elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') )
1943
- $icon_url = 'https://' . substr($icon_url, 7);
1944
-
1945
- do {
1946
- $position++;
1947
- } while ( !empty( $menu[$position] ) );
1948
-
1949
- $menu[$position] = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url );
1950
-
1951
- $_registered_pages[$hookname] = true;
1952
-
1953
- return $hookname;
1954
- }
1955
-
1956
- /**
1957
- * bp_core_boot_spammer()
1958
- *
1959
- * When a user logs in, check if they have been marked as a spammer. If yes then simply
1960
- * redirect them to the home page and stop them from logging in.
1961
- *
1962
- * @package BuddyPress Core
1963
- * @param $auth_obj The WP authorization object
1964
- * @param $username The username of the user logging in.
1965
- * @uses get_userdatabylogin() Get the userdata object for a user based on their username
1966
- * @uses bp_core_redirect() Safe redirect to a page
1967
- * @return $auth_obj If the user is not a spammer, return the authorization object
1968
- */
1969
- function bp_core_boot_spammer( $auth_obj, $username ) {
1970
- global $bp;
1971
-
1972
- $user = get_userdatabylogin( $username );
1973
-
1974
- if ( ( bp_core_is_multisite() && (int)$user->spam ) || 1 == (int)$user->user_status )
1975
- bp_core_redirect( $bp->root_domain );
1976
- else
1977
- return $auth_obj;
1978
- }
1979
- add_filter( 'authenticate', 'bp_core_boot_spammer', 11, 2 );
1980
-
1981
- /**
1982
- * bp_core_remove_data()
1983
- *
1984
- * Deletes usermeta for the user when the user is deleted.
1985
- *
1986
- * @package BuddyPress Core
1987
- * @param $user_id The user id for the user to delete usermeta for
1988
- * @uses delete_user_meta() deletes a row from the wp_usermeta table based on meta_key
1989
- */
1990
- function bp_core_remove_data( $user_id ) {
1991
- /* Remove usermeta */
1992
- delete_user_meta( $user_id, 'last_activity' );
1993
-
1994
- /* Flush the cache to remove the user from all cached objects */
1995
- wp_cache_flush();
1996
- }
1997
- add_action( 'wpmu_delete_user', 'bp_core_remove_data' );
1998
- add_action( 'delete_user', 'bp_core_remove_data' );
1999
- add_action( 'make_spam_user', 'bp_core_remove_data' );
2000
-
2001
- /**
2002
- * bp_load_buddypress_textdomain()
2003
- *
2004
- * Load the buddypress translation file for current language
2005
- *
2006
- * @package BuddyPress Core
2007
- */
2008
- function bp_core_load_buddypress_textdomain() {
2009
- $locale = apply_filters( 'buddypress_locale', get_locale() );
2010
- $mofile = sprintf( 'buddypress-%s.mo', $locale );
2011
- $mofile_global = WP_LANG_DIR . '/' . $mofile;
2012
- $mofile_local = BP_PLUGIN_DIR . '/bp-languages/' . $mofile;
2013
-
2014
- if ( file_exists( $mofile_global ) )
2015
- return load_textdomain( 'buddypress', $mofile_global );
2016
- elseif ( file_exists( $mofile_local ) )
2017
- return load_textdomain( 'buddypress', $mofile_local );
2018
- else
2019
- return false;
2020
- }
2021
- add_action ( 'bp_loaded', 'bp_core_load_buddypress_textdomain', 2 );
2022
-
2023
- function bp_core_add_ajax_hook() {
2024
- /* Theme only, we already have the wp_ajax_ hook firing in wp-admin */
2025
- if ( !defined( 'WP_ADMIN' ) )
2026
- do_action( 'wp_ajax_' . $_REQUEST['action'] );
2027
- }
2028
- add_action( 'init', 'bp_core_add_ajax_hook' );
2029
-
2030
- /**
2031
- * bp_core_update_message()
2032
- *
2033
- * Add an extra update message to the update plugin notification.
2034
- *
2035
- * @package BuddyPress Core
2036
- */
2037
- function bp_core_update_message() {
2038
- 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/getting-started/upgrading-from-10x/">Read this before attempting to update BuddyPress</a>', 'buddypress' ) . '</p>';
2039
- }
2040
- add_action( 'in_plugin_update_message-buddypress/bp-loader.php', 'bp_core_update_message' );
2041
-
2042
- /**
2043
- * bp_core_activation_notice()
2044
- *
2045
- * When BuddyPress is activated we must make sure that mod_rewrite is enabled.
2046
- * We must also make sure a BuddyPress compatible theme is enabled. This function
2047
- * will show helpful messages to the administrator.
2048
- *
2049
- * @package BuddyPress Core
2050
- */
2051
- function bp_core_activation_notice() {
2052
- global $wp_rewrite, $current_blog, $bp;
2053
-
2054
- if ( isset( $_POST['permalink_structure'] ) )
2055
- return false;
2056
-
2057
- if ( !is_super_admin() )
2058
- return false;
2059
-
2060
- if ( !empty( $current_blog ) ) {
2061
- if ( $current_blog->blog_id != BP_ROOT_BLOG )
2062
- return false;
2063
- }
2064
-
2065
- if ( empty( $wp_rewrite->permalink_structure ) ) { ?>
2066
- <div id="message" class="updated fade">
2067
- <p><?php printf( __( '<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' ) ) ?></p>
2068
- </div><?php
2069
- } else {
2070
- /* Get current theme info */
2071
- $ct = current_theme_info();
2072
-
2073
- /* The best way to remove this notice is to add a "buddypress" tag to your active theme's CSS header. */
2074
- if ( !defined( 'BP_SILENCE_THEME_NOTICE' ) && !in_array( 'buddypress', (array)$ct->tags ) ) { ?>
2075
- <div id="message" class="updated fade">
2076
- <p style="line-height: 150%"><?php printf( __( "<strong>BuddyPress is ready</strong>. You'll need to <a href='%s'>activate a BuddyPress compatible theme</a> to take advantage of all of the features. We've bundled a default theme, but you can always <a href='%s'>install some other compatible themes</a> or <a href='%s'>upgrade your existing WordPress theme</a>.", 'buddypress' ), admin_url( 'themes.php' ), admin_url( 'theme-install.php?type=tag&s=buddypress&tab=search' ), admin_url( 'plugin-install.php?type=term&tab=search&s=bp-template-pack' ) ) ?></p>
2077
- </div><?php
2078
- }
2079
- }
2080
- }
2081
- add_action( 'admin_notices', 'bp_core_activation_notice' );
2082
-
2083
- /**
2084
- * bp_core_activate_site_options()
2085
- *
2086
- * When switching from single to multisite we need to copy blog options to
2087
- * site options.
2088
- *
2089
- * @package BuddyPress Core
2090
- */
2091
- function bp_core_activate_site_options( $keys = array() ) {
2092
- global $bp;
2093
-
2094
- if ( !empty( $keys ) && is_array( $keys ) ) {
2095
- $errors = false;
2096
-
2097
- foreach ( $keys as $key => $default ) {
2098
- if ( empty( $bp->site_options[ $key ] ) ) {
2099
- $bp->site_options[ $key ] = get_blog_option( BP_ROOT_BLOG, $key, $default );
2100
-
2101
- if ( !update_site_option( $key, $bp->site_options[ $key ] ) )
2102
- $errors = true;
2103
- }
2104
- }
2105
-
2106
- if ( empty( $errors ) )
2107
- return true;
2108
- }
2109
-
2110
- return false;
2111
- }
2112
-
2113
- /********************************************************************************
2114
- * Custom Actions
2115
- *
2116
- * Functions to set up custom BuddyPress actions that all other components can
2117
- * hook in to.
2118
- */
2119
-
2120
- /**
2121
- * bp_include()
2122
- *
2123
- * Allow plugins to include their files ahead of core filters
2124
- */
2125
- function bp_include() {
2126
- do_action( 'bp_include' );
2127
- }
2128
- add_action( 'bp_loaded', 'bp_include', 2 );
2129
-
2130
- /**
2131
- * bp_setup_root_components()
2132
- *
2133
- * Allow core components and dependent plugins to set root components
2134
- */
2135
- function bp_setup_root_components() {
2136
- do_action( 'bp_setup_root_components' );
2137
- }
2138
- add_action( 'bp_loaded', 'bp_setup_root_components', 2 );
2139
-
2140
- /**
2141
- * bp_setup_globals()
2142
- *
2143
- * Allow core components and dependent plugins to set globals
2144
- */
2145
- function bp_setup_globals() {
2146
- do_action( 'bp_setup_globals' );
2147
- }
2148
- add_action( 'bp_loaded', 'bp_setup_globals', 6 );
2149
-
2150
- /**
2151
- * bp_setup_nav()
2152
- *
2153
- * Allow core components and dependent plugins to set their nav
2154
- */
2155
- function bp_setup_nav() {
2156
- do_action( 'bp_setup_nav' );
2157
- }
2158
- add_action( 'bp_loaded', 'bp_setup_nav', 8 );
2159
-
2160
- /**
2161
- * bp_setup_widgets()
2162
- *
2163
- * Allow core components and dependent plugins to register widgets
2164
- */
2165
- function bp_setup_widgets() {
2166
- do_action( 'bp_register_widgets' );
2167
- }
2168
- add_action( 'bp_loaded', 'bp_setup_widgets', 8 );
2169
-
2170
- /**
2171
- * bp_init()
2172
- *
2173
- * Allow components to initialize themselves cleanly
2174
- */
2175
- function bp_init() {
2176
- do_action( 'bp_init' );
2177
- }
2178
- add_action( 'bp_loaded', 'bp_init' );
2179
-
2180
- /********************************************************************************
2181
- * Caching
2182
- *
2183
- * Caching functions handle the clearing of cached objects and pages on specific
2184
- * actions throughout BuddyPress.
2185
- */
2186
-
2187
- /**
2188
- * bp_core_add_global_group()
2189
- *
2190
- * Add's 'bp' to global group of network wide cachable objects
2191
- *
2192
- * @package BuddyPress Core
2193
- */
2194
- function bp_core_add_global_group() {
2195
- wp_cache_init();
2196
-
2197
- if ( function_exists( 'wp_cache_add_global_groups' ) )
2198
- wp_cache_add_global_groups( array( 'bp' ) );
2199
- }
2200
- add_action( 'init', 'bp_core_add_global_group' );
2201
-
2202
- /**
2203
- * bp_core_clear_user_object_cache()
2204
- *
2205
- * Clears all cached objects for a user, or a user is part of.
2206
- *
2207
- * @package BuddyPress Core
2208
- */
2209
- function bp_core_clear_user_object_cache( $user_id ) {
2210
- wp_cache_delete( 'bp_user_' . $user_id, 'bp' );
2211
- wp_cache_delete( 'bp_core_avatar_v1_u' . $user_id, 'bp' );
2212
- wp_cache_delete( 'bp_core_avatar_v2_u' . $user_id, 'bp' );
2213
- wp_cache_delete( 'online_users' );
2214
- wp_cache_delete( 'newest_users' );
2215
- }
2216
-
2217
- // List actions to clear super cached pages on, if super cache is installed
2218
- add_action( 'wp_login', 'bp_core_clear_cache' );
2219
- add_action( 'bp_core_render_notice', 'bp_core_clear_cache' );
2220
-
2221
- // Remove the catch non existent blogs hook so WPMU doesn't think BuddyPress pages are non existing blogs
2222
- remove_action( 'plugins_loaded', 'catch_nonexistant_blogs' );
2223
-
2224
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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-schema.php ADDED
@@ -0,0 +1,300 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Exit if accessed directly
3
+ if ( !defined( 'ABSPATH' ) ) exit;
4
+
5
+ function bp_core_set_charset() {
6
+ global $wpdb;
7
+
8
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
9
+
10
+ /* BuddyPress component DB schema */
11
+ if ( !empty($wpdb->charset) )
12
+ return "DEFAULT CHARACTER SET $wpdb->charset";
13
+
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,
25
+ user_id bigint(20) NOT NULL,
26
+ item_id bigint(20) NOT NULL,
27
+ secondary_item_id bigint(20),
28
+ component_name varchar(75) NOT NULL,
29
+ component_action varchar(75) NOT NULL,
30
+ date_notified datetime NOT NULL,
31
+ is_new bool NOT NULL DEFAULT 0,
32
+ KEY item_id (item_id),
33
+ KEY secondary_item_id (secondary_item_id),
34
+ KEY user_id (user_id),
35
+ KEY is_new (is_new),
36
+ KEY component_name (component_name),
37
+ KEY component_action (component_action),
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),
67
+ KEY secondary_item_id (secondary_item_id),
68
+ KEY component (component),
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,
77
+ activity_id bigint(20) NOT NULL,
78
+ meta_key varchar(255) DEFAULT NULL,
79
+ meta_value longtext DEFAULT NULL,
80
+ KEY activity_id (activity_id),
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,
95
+ initiator_user_id bigint(20) NOT NULL,
96
+ friend_user_id bigint(20) NOT NULL,
97
+ is_confirmed bool DEFAULT 0,
98
+ is_limited bool DEFAULT 0,
99
+ date_created datetime NOT NULL,
100
+ KEY initiator_user_id (initiator_user_id),
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,
115
+ creator_id bigint(20) NOT NULL,
116
+ name varchar(100) NOT NULL,
117
+ slug varchar(200) NOT NULL,
118
+ description longtext NOT NULL,
119
+ status varchar(10) NOT NULL DEFAULT 'public',
120
+ enable_forum tinyint(1) NOT NULL DEFAULT '1',
121
+ date_created datetime NOT NULL,
122
+ KEY creator_id (creator_id),
123
+ KEY status (status)
124
+ ) {$charset_collate};";
125
+
126
+ $sql[] = "CREATE TABLE {$bp_prefix}bp_groups_members (
127
+ id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
128
+ group_id bigint(20) NOT NULL,
129
+ user_id bigint(20) NOT NULL,
130
+ inviter_id bigint(20) NOT NULL,
131
+ is_admin tinyint(1) NOT NULL DEFAULT '0',
132
+ is_mod tinyint(1) NOT NULL DEFAULT '0',
133
+ user_title varchar(100) NOT NULL,
134
+ date_modified datetime NOT NULL,
135
+ comments longtext NOT NULL,
136
+ is_confirmed tinyint(1) NOT NULL DEFAULT '0',
137
+ is_banned tinyint(1) NOT NULL DEFAULT '0',
138
+ invite_sent tinyint(1) NOT NULL DEFAULT '0',
139
+ KEY group_id (group_id),
140
+ KEY is_admin (is_admin),
141
+ KEY is_mod (is_mod),
142
+ KEY user_id (user_id),
143
+ KEY inviter_id (inviter_id),
144
+ KEY is_confirmed (is_confirmed)
145
+ ) {$charset_collate};";
146
+
147
+ $sql[] = "CREATE TABLE {$bp_prefix}bp_groups_groupmeta (
148
+ id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
149
+ group_id bigint(20) NOT NULL,
150
+ meta_key varchar(255) DEFAULT NULL,
151
+ meta_value longtext DEFAULT NULL,
152
+ KEY group_id (group_id),
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,
167
+ thread_id bigint(20) NOT NULL,
168
+ sender_id bigint(20) NOT NULL,
169
+ subject varchar(200) NOT NULL,
170
+ message longtext NOT NULL,
171
+ date_sent datetime NOT NULL,
172
+ KEY sender_id (sender_id),
173
+ KEY thread_id (thread_id)
174
+ ) {$charset_collate};";
175
+
176
+ $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_recipients (
177
+ id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
178
+ user_id bigint(20) NOT NULL,
179
+ thread_id bigint(20) NOT NULL,
180
+ unread_count int(10) NOT NULL DEFAULT '0',
181
+ sender_only tinyint(1) NOT NULL DEFAULT '0',
182
+ is_deleted tinyint(1) NOT NULL DEFAULT '0',
183
+ KEY user_id (user_id),
184
+ KEY thread_id (thread_id),
185
+ KEY is_deleted (is_deleted),
186
+ KEY sender_only (sender_only),
187
+ KEY unread_count (unread_count)
188
+ ) {$charset_collate};";
189
+
190
+ $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_notices (
191
+ id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
192
+ subject varchar(200) NOT NULL,
193
+ message longtext NOT NULL,
194
+ date_sent datetime NOT NULL,
195
+ is_active tinyint(1) NOT NULL DEFAULT '0',
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
+ bp_update_option( 'bp-xprofile-base-group-name', _x( 'Base', 'First XProfile group name', 'buddypress' ) );
209
+ bp_update_option( 'bp-xprofile-fullname-field-name', _x( 'Name', 'XProfile fullname field name', 'buddypress' ) );
210
+
211
+ $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_groups (
212
+ id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
213
+ name varchar(150) NOT NULL,
214
+ description mediumtext NOT NULL,
215
+ group_order bigint(20) NOT NULL DEFAULT '0',
216
+ can_delete tinyint(1) NOT NULL,
217
+ KEY can_delete (can_delete)
218
+ ) {$charset_collate};";
219
+
220
+ $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_fields (
221
+ id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
222
+ group_id bigint(20) unsigned NOT NULL,
223
+ parent_id bigint(20) unsigned NOT NULL,
224
+ type varchar(150) NOT NULL,
225
+ name varchar(150) NOT NULL,
226
+ description longtext NOT NULL,
227
+ is_required tinyint(1) NOT NULL DEFAULT '0',
228
+ is_default_option tinyint(1) NOT NULL DEFAULT '0',
229
+ field_order bigint(20) NOT NULL DEFAULT '0',
230
+ option_order bigint(20) NOT NULL DEFAULT '0',
231
+ order_by varchar(15) NOT NULL DEFAULT '',
232
+ can_delete tinyint(1) NOT NULL DEFAULT '1',
233
+ KEY group_id (group_id),
234
+ KEY parent_id (parent_id),
235
+ KEY field_order (field_order),
236
+ KEY can_delete (can_delete),
237
+ KEY is_required (is_required)
238
+ ) {$charset_collate};";
239
+
240
+ $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_data (
241
+ id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
242
+ field_id bigint(20) unsigned NOT NULL,
243
+ user_id bigint(20) unsigned NOT NULL,
244
+ value longtext NOT NULL,
245
+ last_updated datetime NOT NULL,
246
+ KEY field_id (field_id),
247
+ KEY user_id (user_id)
248
+ ) {$charset_collate};";
249
+
250
+ $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_meta (
251
+ id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
252
+ object_id bigint(20) NOT NULL,
253
+ object_type varchar(150) NOT NULL,
254
+ meta_key varchar(255) DEFAULT NULL,
255
+ meta_value longtext DEFAULT NULL,
256
+ KEY object_id (object_id),
257
+ KEY meta_key (meta_key)
258
+ ) {$charset_collate};";
259
+
260
+ dbDelta( $sql );
261
+
262
+ // Insert the default group and fields
263
+ $insert_sql = array();
264
+
265
+ if ( !$wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_groups WHERE id = 1" ) )
266
+ $insert_sql[] = "INSERT INTO {$bp_prefix}bp_xprofile_groups ( name, description, can_delete ) VALUES ( " . $wpdb->prepare( '%s', stripslashes( bp_get_option( 'bp-xprofile-base-group-name' ) ) ) . ", '', 0 );";
267
+
268
+ if ( !$wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE id = 1" ) )
269
+ $insert_sql[] = "INSERT INTO {$bp_prefix}bp_xprofile_fields ( group_id, parent_id, type, name, description, is_required, can_delete ) VALUES ( 1, 0, 'textbox', " . $wpdb->prepare( '%s', stripslashes( bp_get_option( 'bp-xprofile-fullname-field-name' ) ) ) . ", '', 1, 0 );";
270
+
271
+ dbDelta( $insert_sql );
272
+ }
273
+
274
+ function bp_core_install_blog_tracking() {
275
+ global $wpdb;
276
+
277
+ $charset_collate = bp_core_set_charset();
278
+ $bp_prefix = bp_core_get_table_prefix();
279
+
280
+ $sql[] = "CREATE TABLE {$bp_prefix}bp_user_blogs (
281
+ id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
282
+ user_id bigint(20) NOT NULL,
283
+ blog_id bigint(20) NOT NULL,
284
+ KEY user_id (user_id),
285
+ KEY blog_id (blog_id)
286
+ ) {$charset_collate};";
287
+
288
+ $sql[] = "CREATE TABLE {$bp_prefix}bp_user_blogs_blogmeta (
289
+ id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
290
+ blog_id bigint(20) NOT NULL,
291
+ meta_key varchar(255) DEFAULT NULL,
292
+ meta_value longtext DEFAULT NULL,
293
+ KEY blog_id (blog_id),
294
+ KEY meta_key (meta_key)
295
+ ) {$charset_collate};";
296
+
297
+ dbDelta($sql);
298
+ }
299
+
300
+ ?>
bp-core/admin/bp-core-update.php ADDED
@@ -0,0 +1,1328 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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'] ) )
45
+ $this->save( $_POST['save'] );
46
+
47
+ // Build the steps needed for update or new installations
48
+ $this->steps = $this->add_steps();
49
+ }
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' ),
74
+ __( 'Permalinks', 'buddypress' ),
75
+ __( 'Theme', '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
+
95
+ return $steps;
96
+ }
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
+
153
+ <h2><?php printf( __( 'BuddyPress %s', 'buddypress' ), $type ); ?></h2>
154
+
155
+ <?php
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
+
174
+ <?php else :
175
+
176
+ echo $i + 1 . '. ';
177
+
178
+ endif;
179
+
180
+ echo esc_attr( $name ) ?>
181
+
182
+ </li>
183
+
184
+ <?php endforeach; ?>
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" />
192
+ </div>
193
+
194
+ <?php else : ?>
195
+
196
+ <div class="prev-next submit clear">
197
+ <input type="submit" value="<?php _e( 'Save &amp; Next', 'buddypress' ); ?>" name="submit" />
198
+ </div>
199
+
200
+ <?php endif; ?>
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;
222
+
223
+ case __( 'Pages', 'buddypress') :
224
+ $this->step_pages();
225
+ break;
226
+
227
+ case __( 'Permalinks', 'buddypress') :
228
+ $this->step_permalinks();
229
+ break;
230
+
231
+ case __( 'Theme', 'buddypress') :
232
+ $this->step_theme();
233
+ break;
234
+
235
+ case __( 'Finish', 'buddypress') :
236
+ $this->step_finish();
237
+ break;
238
+
239
+ } ?>
240
+
241
+ </div>
242
+ </form>
243
+ </div>
244
+
245
+ <?php
246
+ }
247
+
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
+
262
+ </div>
263
+
264
+ <?php
265
+ }
266
+
267
+ function step_ms_update() {
268
+ if ( !current_user_can( 'activate_plugins' ) )
269
+ return false;
270
+
271
+ $active_components = bp_get_option( 'bp-active-components' );
272
+
273
+ if ( defined( 'BP_BLOGS_SLUG' ) )
274
+ $blogs_slug = constant( 'BP_BLOGS_SLUG' );
275
+ else
276
+ $blogs_slug = 'blogs';
277
+
278
+ // Call up old bp-pages to see if a page has been previously linked to Blogs
279
+ $existing_pages = bp_get_option( 'bp-pages' );
280
+
281
+ if ( !empty( $existing_pages['blogs'] ) )
282
+ $existing_blog_page = '&selected=' . $existing_pages['blogs'];
283
+ else
284
+ $existing_blog_page = '';
285
+ ?>
286
+
287
+ <script type="text/javascript">
288
+ jQuery( document ).ready( function() {
289
+ jQuery( 'select' ).change( function() {
290
+ jQuery( this ).siblings( 'input[@type=radio]' ).click();
291
+ });
292
+ });
293
+ </script>
294
+
295
+ <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>
296
+
297
+ <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>
298
+
299
+ <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>
300
+
301
+ <p><?php _e( 'Would you like to enable site tracking, which tracks blog posts and comments from across your network?', 'buddypress' ); ?></p>
302
+
303
+ <table class="form-table">
304
+
305
+ <tr valign="top">
306
+ <th scope="row"><?php _e( "Enable Site Tracking?", 'buddypress' ) ?></th>
307
+
308
+ <td>
309
+ <label for="bp_components[blogs]">
310
+ <input id="site-tracking-enabled" type="checkbox" id="bp_components[blogs]" name="bp_components[blogs]" value="1"<?php checked( isset( $active_components['blogs'] ) ); ?> />
311
+
312
+ <?php _e( "Track new sites, new posts and new comments across your entire network.", 'buddypress' ) ?>
313
+
314
+ </label>
315
+
316
+ </td>
317
+ </tr>
318
+
319
+ <tr valign="top" id="site-tracking-page-selector">
320
+ <th scope="row"><?php _e( 'Select a WordPress page for the Sites directory.', 'buddypress' ); ?></th>
321
+
322
+ <td>
323
+ <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>
324
+ <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>
325
+ </td>
326
+ </tr>
327
+
328
+ </table>
329
+
330
+
331
+ <div class="submit clear">
332
+ <input type="hidden" name="save" value="ms_update" />
333
+ <input type="hidden" name="step" value="<?php echo esc_attr( $this->current_step ); ?>" />
334
+
335
+ <?php wp_nonce_field( 'bpwizard_ms_update' ); ?>
336
+
337
+ </div>
338
+
339
+ <?php
340
+ }
341
+
342
+ function step_components() {
343
+ if ( !current_user_can( 'activate_plugins' ) )
344
+ return false;
345
+
346
+ if ( !function_exists( 'bp_core_admin_component_options' ) )
347
+ require ( WP_PLUGIN_DIR . '/buddypress/bp-core/admin/bp-core-admin.php' ); ?>
348
+
349
+ <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>
350
+
351
+ <?php bp_core_admin_component_options(); ?>
352
+
353
+ <div class="submit clear">
354
+ <input type="hidden" name="save" value="components" />
355
+ <input type="hidden" name="step" value="<?php echo esc_attr( $this->current_step ); ?>" />
356
+
357
+ <?php wp_nonce_field( 'bpwizard_components' ); ?>
358
+
359
+ </div>
360
+
361
+ <?php
362
+ }
363
+
364
+ function step_pages() {
365
+ global $bp;
366
+
367
+ if ( !current_user_can( 'activate_plugins' ) )
368
+ return false;
369
+
370
+ $existing_pages = bp_core_update_get_page_meta();
371
+
372
+ // Provide empty indexes to avoid PHP errors with wp_dropdown_pages()
373
+ $indexes = array( 'members', 'activity', 'groups', 'forums', 'blogs', 'register', 'activate' );
374
+ foreach ( $indexes as $index ) {
375
+ if ( !isset( $existing_pages[$index] ) )
376
+ $existing_pages[$index] = '';
377
+ }
378
+
379
+ if ( !empty( $existing_pages['blogs'] ) )
380
+ $existing_blog_page = '&selected=' . $existing_pages['blogs'];
381
+ else
382
+ $existing_blog_page = '';
383
+
384
+ // Get active components
385
+ $active_components = apply_filters( 'bp_active_components', bp_get_option( 'bp-active-components' ) );
386
+
387
+ // Check for defined slugs
388
+ $members_slug = !empty( $bp->members->slug ) ? $bp->members->slug : __( 'members', 'buddypress' );
389
+
390
+ // Groups
391
+ $groups_slug = !empty( $bp->groups->slug ) ? $bp->groups->slug : __( 'groups', 'buddypress' );
392
+
393
+ // Activity
394
+ $activity_slug = !empty( $bp->activity->slug ) ? $bp->activity->slug : __( 'activity', 'buddypress' );
395
+
396
+ // Forums
397
+ $forums_slug = !empty( $bp->forums->slug ) ? $bp->forums->slug : __( 'forums', 'buddypress' );
398
+
399
+ // Blogs
400
+ $blogs_slug = !empty( $bp->blogs->slug ) ? $bp->blogs->slug : __( 'blogs', 'buddypress' );
401
+
402
+ // Register
403
+ $register_slug = !empty( $bp->register->slug ) ? $bp->register->slug : __( 'register', 'buddypress' );
404
+
405
+ // Activation
406
+ $activation_slug = !empty( $bp->activation->slug ) ? $bp->activation->slug : __( 'activate', 'buddypress' );
407
+
408
+ ?>
409
+
410
+ <script type="text/javascript">
411
+ jQuery( document ).ready( function() {
412
+ jQuery( 'select' ).change( function() {
413
+ jQuery( this ).siblings( 'input[@type=radio]' ).click();
414
+ });
415
+ });
416
+ </script>
417
+
418
+ <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>
419
+
420
+ <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>
421
+
422
+ <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>
423
+
424
+ <table class="form-table">
425
+
426
+ <tr valign="top">
427
+ <th scope="row">
428
+ <h5><?php _e( 'Members', 'buddypress' ); ?></h5>
429
+ <p><?php _e( 'Displays member profiles, and a directory of all site members.', 'buddypress' ); ?></p>
430
+ </th>
431
+ <td>
432
+ <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>
433
+ <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>
434
+ </td>
435
+ </tr>
436
+
437
+ <?php if ( isset( $active_components['activity'] ) ) : ?>
438
+
439
+ <tr valign="top">
440
+ <th scope="row">
441
+ <h5><?php _e( 'Site Activity', 'buddypress' ); ?></h5>
442
+ <p><?php _e( "Displays the activity for the entire site, a member's friends, groups and @mentions.", 'buddypress' ); ?></p>
443
+ </th>
444
+ <td>
445
+ <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>
446
+ <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>
447
+ </td>
448
+ </tr>
449
+
450
+ <?php endif; ?>
451
+
452
+ <?php if ( isset( $active_components['groups'] ) ) : ?>
453
+
454
+ <tr valign="top">
455
+ <th scope="row">
456
+ <h5><?php _e( 'Groups', 'buddypress' ); ?></h5>
457
+ <p><?php _e( 'Displays individual groups as well as a directory of groups.', 'buddypress' ); ?></p>
458
+ </th>
459
+ <td>
460
+ <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>
461
+ <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>
462
+ </td>
463
+ </tr>
464
+
465
+ <?php endif; ?>
466
+
467
+ <?php if ( isset( $active_components['forums'] ) ) : ?>
468
+
469
+ <tr valign="top">
470
+ <th scope="row">
471
+ <h5><?php _e( 'Forums', 'buddypress' ); ?></h5>
472
+ <p><?php _e( 'Displays a directory of public forum topics.', 'buddypress' ); ?></p>
473
+ </th>
474
+ <td>
475
+ <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>
476
+ <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>
477
+ </td>
478
+ </tr>
479
+
480
+ <?php endif; ?>
481
+
482
+ <?php /* The Blogs component only needs a directory page when Multisite is enabled */ ?>
483
+ <?php if ( is_multisite() && isset( $active_components['blogs'] ) ) : ?>
484
+
485
+ <tr valign="top">
486
+ <th scope="row">
487
+ <h5><?php _e( 'Sites', 'buddypress' ); ?></h5>
488
+ <p><?php _e( 'Displays a directory of the sites in your network.', 'buddypress' ); ?></p>
489
+ </th>
490
+ <td>
491
+ <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>
492
+ <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>
493
+ </td>
494
+ </tr>
495
+
496
+ <?php endif; ?>
497
+
498
+ <tr valign="top">
499
+ <th scope="row">
500
+ <h5><?php _e( 'Register', 'buddypress' ); ?></h5>
501
+ <p><?php _e( 'Displays a site registration page where users can create new accounts.', 'buddypress' ); ?></p>
502
+ </th>
503
+ <td>
504
+ <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>
505
+ <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>
506
+ </td>
507
+ </tr>
508
+
509
+ <tr valign="top">
510
+ <th scope="row">
511
+ <h5><?php _e( 'Activate', 'buddypress' ); ?></h5>
512
+ <p><?php _e( 'The page users will visit to activate their account once they have registered.', 'buddypress' ); ?></p>
513
+ </th>
514
+ <td>
515
+ <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>
516
+ <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>
517
+ </td>
518
+ </tr>
519
+ </table>
520
+
521
+ <div class="submit clear">
522
+ <input type="hidden" name="save" value="pages" />
523
+ <input type="hidden" name="step" value="<?php echo esc_attr( $this->current_step ); ?>" />
524
+
525
+ <?php wp_nonce_field( 'bpwizard_pages' ); ?>
526
+
527
+ </div>
528
+
529
+ <?php
530
+ }
531
+
532
+ function step_permalinks() {
533
+ if ( !current_user_can( 'activate_plugins' ) )
534
+ return false;
535
+
536
+ $prefix = '';
537
+ $permalink_structure = get_option( 'permalink_structure' );
538
+ $using_permalinks = ( !empty( $permalink_structure ) ) ? true : false;
539
+ $structures = array( '', $prefix . '/%year%/%monthnum%/%day%/%postname%/', $prefix . '/%year%/%monthnum%/%postname%/', $prefix . '/archives/%post_id%' );
540
+
541
+ // If we're using permalinks already, adjust text accordingly
542
+ if ( $permalink_structure )
543
+ $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' );
544
+ else
545
+ $permalink_setup_text = __( 'To make sure the pages created in the previous step work correctly, pretty permalinks must be active on your site.', 'buddypress' );
546
+
547
+ if ( !got_mod_rewrite() && !iis7_supports_permalinks() )
548
+ $prefix = '/index.php'; ?>
549
+
550
+ <p><?php echo $permalink_setup_text; ?></p>
551
+ <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' ) ); ?>
552
+
553
+ <table class="form-table">
554
+ <tr>
555
+ <th><label><input name="permalink_structure" type="radio"<?php if ( empty( $permalink_structure ) || false != strpos( $permalink_structure, $structures[1] ) ) : ?> checked="checked" <?php endif; ?>value="<?php echo esc_attr( $structures[1] ); ?>" class="tog" <?php checked( $structures[1], $permalink_structure ); ?> />&nbsp;<?php _e( 'Day and name' ); ?></label></th>
556
+ <td><code><?php echo get_home_url() . $prefix . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/sample-post/'; ?></code></td>
557
+ </tr>
558
+ <tr>
559
+ <th><label><input name="permalink_structure" type="radio"<?php if ( empty( $permalink_structure ) || false != strpos( $permalink_structure, $structures[2] ) ) : ?> checked="checked" <?php endif; ?> value="<?php echo esc_attr( $structures[2] ); ?>" class="tog" <?php checked( $structures[2], $permalink_structure ); ?> />&nbsp;<?php _e( 'Month and name' ); ?></label></th>
560
+ <td><code><?php echo get_home_url() . $prefix . '/' . date('Y') . '/' . date('m') . '/sample-post/'; ?></code></td>
561
+ </tr>
562
+ <tr>
563
+ <th><label><input name="permalink_structure" type="radio"<?php if ( empty( $permalink_structure ) || false != strpos( $permalink_structure, $structures[3] ) ) : ?> checked="checked" <?php endif; ?> value="<?php echo esc_attr( $structures[3] ); ?>" class="tog" <?php checked( $structures[3], $permalink_structure ); ?> />&nbsp;<?php _e( 'Numeric' ); ?></label></th>
564
+ <td><code><?php echo get_home_url() . $prefix ?>/archives/123</code></td>
565
+ </tr>
566
+ </table>
567
+
568
+ <div class="submit clear">
569
+ <input type="hidden" name="save" value="permalinks" />
570
+ <input type="hidden" name="step" value="<?php echo esc_attr( $this->current_step ); ?>" />
571
+
572
+ <?php if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && empty( $_POST['skip-htaccess'] ) ) : ?>
573
+
574
+ <input type="hidden" name="skip-htaccess" value="skip-htaccess" />
575
+
576
+ <?php endif; ?>
577
+
578
+ <?php wp_nonce_field( 'bpwizard_permalinks' ); ?>
579
+
580
+ </div>
581
+
582
+ <?php
583
+ }
584
+
585
+ function step_theme() {
586
+ if ( !current_user_can( 'activate_plugins' ) )
587
+ return false;
588
+
589
+ $installed_plugins = get_plugins();
590
+ $installed_themes = get_themes();
591
+
592
+ $template_pack_installed = false;
593
+ $bp_autotheme_installed = false;
594
+ $bp_theme_installed = false;
595
+
596
+ foreach ( (array)$installed_plugins as $plugin ) {
597
+ if ( 'BuddyPress Template Pack' == $plugin['Name'] ) {
598
+ $template_pack_installed = true;
599
+ }
600
+ }
601
+
602
+ foreach ( (array)$installed_themes as $theme ) {
603
+ foreach ( (array)$theme['Tags'] as $tag ) {
604
+ if ( ( 'BuddyPress Default' != $theme['Name'] ) && ( 'buddypress' == $tag ) ) {
605
+ $bp_theme_installed = true;
606
+ $bp_themes[] = $theme;
607
+ }
608
+ }
609
+ }
610
+
611
+ // Get theme screenshot
612
+ $current_theme = get_current_theme();
613
+ $screenshot = '';
614
+ $themes = get_themes();
615
+
616
+ if ( !empty( $themes[$current_theme]['Screenshot'] ) )
617
+ $screenshot = trailingslashit( get_stylesheet_directory_uri() ) . $themes[$current_theme]['Screenshot'];
618
+ ?>
619
+
620
+ <script type="text/javascript">
621
+ jQuery( document ).ready( function() {
622
+ jQuery( 'select' ).change( function() {
623
+ jQuery( this ).siblings( 'input[@type=radio]' ).click();
624
+ });
625
+ });
626
+ </script>
627
+
628
+ <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>
629
+
630
+ <table class="form-table">
631
+ <tr>
632
+ <th>
633
+ <h5><?php _e( 'Use BuddyPress Default', 'buddypress' ); ?></h5>
634
+ <img src="<?php echo plugins_url( '/buddypress/bp-themes/bp-default/screenshot.png' ); ?>" alt="<?php _e( 'BuddyPress Default', 'buddypress' ); ?>" />
635
+ </th>
636
+ <td>
637
+ <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>
638
+ <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>
639
+ <p><label><input type="radio" name="theme" value="bp_default" checked="checked" /> <?php _e( 'Yes, please!', 'buddypress' ); ?></label></p>
640
+ </td>
641
+ </tr>
642
+
643
+ <?php if ( $bp_theme_installed ) : ?>
644
+ <tr>
645
+ <th>
646
+ <h5><?php _e( 'Other themes', 'buddypress' ); ?></h5>
647
+ <img src="<?php echo plugins_url( '/buddypress/bp-core/images/find.png' ); ?>" alt="<?php _e( 'A BuddyPress theme', 'buddypress' ); ?>" />
648
+ </th>
649
+ <td>
650
+ <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>
651
+ <p>
652
+ <label>
653
+ <input type="radio" name="theme" value="3rd_party" /> <?php _e( 'Use this theme', 'buddypress' ); ?>
654
+ </label>
655
+ <select name="3rd_party_theme">
656
+
657
+ <?php foreach( (array) $bp_themes as $theme ) : ?>
658
+ <option value="<?php echo $theme['Template'] . ',' . $theme['Stylesheet']; ?>"><?php echo $theme['Name']; ?></option>
659
+ <?php endforeach; ?>
660
+
661
+ </select>
662
+ </p>
663
+ </td>
664
+ </tr>
665
+ <?php endif; ?>
666
+
667
+ <tr>
668
+ <th>
669
+ <h5><?php _e( 'Manually update current theme', 'buddypress' ); ?></h5>
670
+ <?php if ( !empty( $screenshot ) ) : ?>
671
+ <img src="<?php echo esc_url( $screenshot ); ?>" alt="<?php _e( 'Your existing theme', 'buddypress' ); ?>" />
672
+ <?php endif; ?>
673
+ </th>
674
+ <td>
675
+ <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>
676
+
677
+ <?php if ( empty( $template_pack_installed ) ) : ?>
678
+
679
+ <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>
680
+
681
+ <?php else : ?>
682
+
683
+ <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>
684
+ <p><a id="bp-template-pack" class="button installed disabled" href="javascript:void();"><span></span><?php _e( 'Plugin Installed', 'buddypress' ); ?></a></p>
685
+
686
+ <?php endif; ?>
687
+
688
+ </td>
689
+ </tr>
690
+
691
+ <tr>
692
+ <th>
693
+ <h5><?php _e( 'Do not change theme', 'buddypress' ) ?></h5>
694
+ </th>
695
+ <td>
696
+ <p><?php _e( "You are happy with your current theme and plan on changing it later.", 'buddypress' ); ?></p>
697
+ <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>
698
+
699
+ <p><label><input type="radio" name="theme" value="do_not_change" /> <?php _e( "Don't change my current theme", 'buddypress' ); ?></label></p>
700
+
701
+ </td>
702
+ </tr>
703
+ </table>
704
+
705
+ <div class="submit clear">
706
+ <input type="hidden" name="save" value="theme" />
707
+ <input type="hidden" name="step" value="<?php echo esc_attr( $this->current_step ) ?>" />
708
+
709
+ <?php wp_nonce_field( 'bpwizard_theme' ) ?>
710
+
711
+ </div>
712
+
713
+ <?php
714
+ }
715
+
716
+ function step_finish() {
717
+ if ( !current_user_can( 'activate_plugins' ) )
718
+ return false;
719
+
720
+ // What type of action is happening here?
721
+ $type = ( 'install' == $this->setup_type ) ? __( 'setup', 'buddypress' ) : __( 'update', 'buddypress' ); ?>
722
+
723
+ <p><?php printf( __( "The BuddyPress %1\$s is complete, and your site is ready to go!", 'buddypress' ), $type, $type ); ?></p>
724
+
725
+ <div class="submit clear">
726
+ <input type="hidden" name="save" value="finish" />
727
+ <input type="hidden" name="step" value="<?php echo esc_attr( $this->current_step ); ?>" />
728
+
729
+ <?php wp_nonce_field( 'bpwizard_finish' ); ?>
730
+
731
+ </div>
732
+
733
+ <?php
734
+ }
735
+
736
+ /** Save Step Methods *****************************************************/
737
+
738
+ function step_db_update_save() {
739
+ global $bp;
740
+
741
+ if ( isset( $_POST['submit'] ) ) {
742
+ check_admin_referer( 'bpwizard_db_update' );
743
+
744
+ // Run the schema install to update tables
745
+ bp_core_install();
746
+
747
+ if ( $this->database_version < 1801 )
748
+ $this->update_1_5();
749
+
750
+ // Update the active components option early if we're updating
751
+ if ( 'update' == $this->setup_type )
752
+ bp_update_option( 'bp-active-components', $bp->active_components );
753
+
754
+ return true;
755
+ }
756
+
757
+ return false;
758
+ }
759
+
760
+ function step_ms_update_save() {
761
+ global $wpdb;
762
+
763
+ if ( isset( $_POST['submit'] ) ) {
764
+ check_admin_referer( 'bpwizard_ms_update' );
765
+
766
+ if ( !$active_components = bp_get_option( 'bp-active-components' ) )
767
+ $active_components = array();
768
+
769
+ // Transfer important settings from blog options to site options
770
+ $options = array(
771
+ 'bp-db-version' => $this->database_version,
772
+ 'bp-active-components' => $active_components,
773
+ 'avatar-default' => get_option( 'avatar-default' )
774
+ );
775
+ bp_core_activate_site_options( $options );
776
+
777
+ if ( isset( $_POST['bp_components']['blogs'] ) ) {
778
+ $active_components['blogs'] = 1;
779
+
780
+ // Make sure that the pages are created on the bp_get_root_blog_id(), no matter which Dashboard the setup is being run on
781
+ if ( !empty( $wpdb->blogid ) && ( $wpdb->blogid != bp_get_root_blog_id() ) && ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) )
782
+ switch_to_blog( bp_get_root_blog_id() );
783
+
784
+ // Move bp-pages data from the blog options table to site options
785
+ $existing_pages = bp_get_option( 'bp-pages' );
786
+
787
+ $bp_pages = $this->setup_pages( (array)$_POST['bp_pages'] );
788
+ $bp_pages = array_merge( (array)$existing_pages, (array)$bp_pages );
789
+
790
+ bp_update_option( 'bp-pages', $bp_pages );
791
+
792
+ if ( !empty( $wpdb->blogid ) && ( $wpdb->blogid != bp_get_root_blog_id() ) && ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) )
793
+ restore_current_blog();
794
+
795
+ bp_core_install( $active_components );
796
+ }
797
+
798
+ bp_update_option( 'bp-active-components', $active_components );
799
+
800
+ return true;
801
+ }
802
+
803
+ return false;
804
+ }
805
+
806
+
807
+ function step_components_save() {
808
+ if ( isset( $_POST['submit'] ) && isset( $_POST['bp_components'] ) ) {
809
+ check_admin_referer( 'bpwizard_components' );
810
+
811
+ $active_components = array();
812
+
813
+ // Settings form submitted, now save the settings.
814
+ foreach ( (array)$_POST['bp_components'] as $key => $value )
815
+ $active_components[$key] = 1;
816
+
817
+ bp_update_option( 'bp-active-components', $active_components );
818
+
819
+ wp_cache_flush();
820
+ bp_core_install();
821
+
822
+ return true;
823
+ }
824
+
825
+ return false;
826
+ }
827
+
828
+ function step_pages_save() {
829
+ global $wpdb;
830
+
831
+ if ( isset( $_POST['submit'] ) && isset( $_POST['bp_pages'] ) ) {
832
+ check_admin_referer( 'bpwizard_pages' );
833
+
834
+ // Make sure that the pages are created on the bp_get_root_blog_id(), no matter which Dashboard the setup is being run on
835
+ if ( !empty( $wpdb->blogid ) && ( $wpdb->blogid != bp_get_root_blog_id() ) && ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) )
836
+ switch_to_blog( bp_get_root_blog_id() );
837
+
838
+ // Delete any existing pages
839
+ $existing_pages = bp_core_update_get_page_meta( 'bp-pages' );
840
+
841
+ foreach ( (array)$existing_pages as $page_id )
842
+ wp_delete_post( $page_id, true );
843
+
844
+ $blog_pages = $this->setup_pages( (array)$_POST['bp_pages'] );
845
+ bp_update_option( 'bp-pages', $blog_pages );
846
+
847
+ if ( !empty( $wpdb->blogid ) && ( $wpdb->blogid != bp_get_root_blog_id() ) && ( !defined( 'BP_ENABLE_MULTIBLOG' ) ) )
848
+ restore_current_blog();
849
+
850
+ return true;
851
+ }
852
+
853
+ return false;
854
+ }
855
+
856
+ function step_permalinks_save() {
857
+ global $wp_rewrite, $current_site, $current_blog;
858
+
859
+ // Prevent debug notices
860
+ $iis7_permalinks = $usingpi = $writable = false;
861
+
862
+ if ( isset( $_POST['submit'] ) ) {
863
+ check_admin_referer( 'bpwizard_permalinks' );
864
+
865
+ $home_path = get_home_path();
866
+ $iis7_permalinks = iis7_supports_permalinks();
867
+
868
+ if ( isset( $_POST['permalink_structure'] ) ) {
869
+ $permalink_structure = $_POST['permalink_structure'];
870
+
871
+ if ( !empty( $permalink_structure ) )
872
+ $permalink_structure = preg_replace( '#/+#', '/', '/' . $_POST['permalink_structure'] );
873
+
874
+ if ( ( defined( 'VHOST' ) && constant( 'VHOST' ) == 'no' ) && $permalink_structure != '' && $current_site->domain . $current_site->path == $current_blog->domain . $current_blog->path )
875
+ $permalink_structure = '/blog' . $permalink_structure;
876
+
877
+ $wp_rewrite->set_permalink_structure( $permalink_structure );
878
+ }
879
+
880
+ if ( !empty( $iis7_permalinks ) ) {
881
+ if ( ( !file_exists( $home_path . 'web.config' ) && win_is_writable( $home_path ) ) || win_is_writable( $home_path . 'web.config' ) ) {
882
+ $writable = true;
883
+ }
884
+ } else {
885
+ if ( ( !file_exists( $home_path . '.htaccess' ) && is_writable( $home_path ) ) || is_writable( $home_path . '.htaccess' ) ) {
886
+ $writable = true;
887
+ }
888
+ }
889
+
890
+ if ( $wp_rewrite->using_index_permalinks() )
891
+ $usingpi = true;
892
+
893
+ $wp_rewrite->flush_rules();
894
+
895
+ if ( !empty( $iis7_permalinks ) || ( empty( $usingpi ) && empty( $writable ) ) ) {
896
+
897
+ function _bp_core_wizard_step_permalinks_message() {
898
+ global $wp_rewrite; ?>
899
+
900
+ <div id="message" class="updated fade"><p>
901
+
902
+ <?php
903
+ _e( 'Oops, there was a problem creating a configuration file. ', 'buddypress' );
904
+
905
+ if ( !empty( $iis7_permalinks ) ) {
906
+
907
+ if ( !empty( $permalink_structure ) && empty( $usingpi ) && empty( $writable ) ) {
908
+
909
+ _e( 'If your <code>web.config</code> file were <a href="http://codex.wordpress.org/Changing_File_Permissions">writable</a>, we could do this automatically, but it isn&#8217;t so this is the url rewrite rule you should have in your <code>web.config</code> file. Click in the field and press <kbd>CTRL + a</kbd> to select all. Then insert this rule inside of the <code>/&lt;configuration&gt;/&lt;system.webServer&gt;/&lt;rewrite&gt;/&lt;rules&gt;</code> element in <code>web.config</code> file.' ); ?>
910
+
911
+ <br /><br />
912
+
913
+ <textarea rows="9" class="large-text readonly" style="background: #fff;" name="rules" id="rules" readonly="readonly"><?php echo esc_html( $wp_rewrite->iis7_url_rewrite_rules() ); ?></textarea>
914
+
915
+ <?php
916
+
917
+ } else if ( !empty( $permalink_structure ) && empty( $usingpi ) && !empty( $writable ) ); {
918
+ _e( 'Permalink structure updated. Remove write access on web.config file now!' );
919
+ }
920
+
921
+ } else {
922
+
923
+ _e( 'If your <code>.htaccess</code> file were <a href="http://codex.wordpress.org/Changing_File_Permissions">writable</a>, we could do this automatically, but it isn&#8217;t so these are the mod_rewrite rules you should have in your <code>.htaccess</code> file. Click in the field and press <kbd>CTRL + a</kbd> to select all.' ); ?>
924
+
925
+ <br /><br />
926
+
927
+ <textarea rows="6" class="large-text readonly" style="background: #fff;" name="rules" id="rules" readonly="readonly"><?php echo esc_html( $wp_rewrite->mod_rewrite_rules() ); ?></textarea>
928
+
929
+ <?php } ?>
930
+
931
+ <br /><br />
932
+
933
+ <?php
934
+ if ( empty( $iis7_permalinks ) )
935
+ _e( 'Paste all these rules into a new <code>.htaccess</code> file in the root of your WordPress installation and save the file. Once you\'re done, please hit the "Save and Next" button to continue.', 'buddypress' );
936
+ ?>
937
+
938
+ </p></div>
939
+
940
+ <?php
941
+ }
942
+
943
+ if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && !empty( $_POST['skip-htaccess'] ) ) {
944
+ return true;
945
+ } else {
946
+ add_action( 'bp_admin_notices', '_bp_core_wizard_step_permalinks_message' );
947
+ return false;
948
+ }
949
+ }
950
+
951
+ return true;
952
+ }
953
+
954
+ return false;
955
+ }
956
+
957
+ function step_theme_save() {
958
+ if ( isset( $_POST['submit'] ) && isset( $_POST['theme'] ) ) {
959
+ check_admin_referer( 'bpwizard_theme' );
960
+
961
+ if ( is_multisite() && bp_get_root_blog_id() != get_current_blog_id() )
962
+ switch_to_blog( bp_get_root_blog_id() );
963
+
964
+ switch ( $_POST['theme'] ) {
965
+
966
+ // Activate the bp-default theme
967
+ case 'bp_default' :
968
+ switch_theme( 'bp-default', 'bp-default' );
969
+ break;
970
+
971
+ // Activate Template Pack plugin
972
+ case 'manual_wp' :
973
+
974
+ // Include
975
+ require_once( ABSPATH . WPINC . '/plugin.php' );
976
+ $installed_plugins = get_plugins();
977
+
978
+ foreach ( $installed_plugins as $key => $plugin ) {
979
+ if ( 'BuddyPress Template Pack' == $plugin['Name'] ) {
980
+ activate_plugin( $key );
981
+ }
982
+ }
983
+ break;
984
+
985
+ // Pick a theme from the repo
986
+ case '3rd_party' :
987
+ if ( empty( $_POST['3rd_party_theme'] ) )
988
+ return false;
989
+
990
+ $theme = explode( ',', $_POST['3rd_party_theme'] );
991
+ switch_theme( $theme[0], $theme[1] );
992
+ break;
993
+
994
+ // Keep existing theme
995
+ case 'do_not_change' :
996
+ return true;
997
+ break;
998
+ }
999
+
1000
+ if ( is_multisite() )
1001
+ restore_current_blog();
1002
+
1003
+ return true;
1004
+ }
1005
+
1006
+ return false;
1007
+ }
1008
+
1009
+ function step_finish_save() {
1010
+ if ( isset( $_POST['submit'] ) ) {
1011
+ check_admin_referer( 'bpwizard_finish' );
1012
+
1013
+ // Update the DB version in the database
1014
+ // Stored in sitemeta. Do not use bp_update_option()
1015
+ update_site_option( 'bp-db-version', $this->new_version );
1016
+ delete_site_option( 'bp-core-db-version' );
1017
+
1018
+ // Delete the setup cookie
1019
+ @setcookie( 'bp-wizard-step', '', time() - 3600, COOKIEPATH );
1020
+
1021
+ // Load BP and hook the admin menu, so that the redirect is successful
1022
+ if ( !function_exists( 'bp_core_update_message' ) )
1023
+ require( WP_PLUGIN_DIR . '/buddypress/bp-core/admin/bp-core-admin.php' );
1024
+
1025
+ bp_core_add_admin_menu();
1026
+
1027
+ // Redirect to the BuddyPress dashboard
1028
+ $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' ) );
1029
+
1030
+ wp_redirect( $redirect );
1031
+
1032
+ return true;
1033
+ }
1034
+
1035
+ return false;
1036
+ }
1037
+
1038
+ function setup_pages( $pages ) {
1039
+ foreach ( $pages as $key => $value ) {
1040
+ if ( 'page' == $value ) {
1041
+ // Check for the selected page
1042
+ if ( !empty( $_POST['bp-' . $key . '-page'] ) )
1043
+ $bp_pages[$key] = (int)$_POST['bp-' . $key . '-page'];
1044
+ else
1045
+ $bp_pages[$key] = wp_insert_post( array( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_title' => ucwords( $key ), 'post_status' => 'publish', 'post_type' => 'page' ) );
1046
+ } else {
1047
+ // Create a new page
1048
+ $bp_pages[$key] = wp_insert_post( array( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_title' => ucwords( $value ), 'post_status' => 'publish', 'post_type' => 'page' ) );
1049
+ }
1050
+ }
1051
+
1052
+ return $bp_pages;
1053
+ }
1054
+
1055
+ // Database update methods based on version numbers
1056
+ function update_1_5() {
1057
+ // Delete old database version options
1058
+ delete_site_option( 'bp-activity-db-version' );
1059
+ delete_site_option( 'bp-blogs-db-version' );
1060
+ delete_site_option( 'bp-friends-db-version' );
1061
+ delete_site_option( 'bp-groups-db-version' );
1062
+ delete_site_option( 'bp-messages-db-version' );
1063
+ delete_site_option( 'bp-xprofile-db-version' );
1064
+ }
1065
+
1066
+ /**
1067
+ * Reset the cookie so the install script starts over
1068
+ */
1069
+ function reset_cookie() {
1070
+ @setcookie( 'bp-wizard-step', '', time() - 3600, COOKIEPATH );
1071
+ }
1072
+ }
1073
+
1074
+ function bp_core_setup_wizard_init() {
1075
+ global $bp_wizard;
1076
+
1077
+ $bp_wizard = new BP_Core_Setup_Wizard;
1078
+ }
1079
+ add_action( bp_core_update_admin_hook(), 'bp_core_setup_wizard_init', 7 );
1080
+
1081
+ function bp_core_install( $active_components = false ) {
1082
+ global $wpdb;
1083
+
1084
+ if ( empty( $active_components ) )
1085
+ $active_components = apply_filters( 'bp_active_components', bp_get_option( 'bp-active-components' ) );
1086
+
1087
+ require( dirname( __FILE__ ) . '/bp-core-schema.php' );
1088
+
1089
+ // Core DB Tables
1090
+ bp_core_install_notifications();
1091
+
1092
+ // Activity Streams
1093
+ if ( !empty( $active_components['activity'] ) )
1094
+ bp_core_install_activity_streams();
1095
+
1096
+ // Friend Connections
1097
+ if ( !empty( $active_components['friends'] ) )
1098
+ bp_core_install_friends();
1099
+
1100
+ // Extensible Groups
1101
+ if ( !empty( $active_components['groups'] ) )
1102
+ bp_core_install_groups();
1103
+
1104
+ // Private Messaging
1105
+ if ( !empty( $active_components['messages'] ) )
1106
+ bp_core_install_private_messaging();
1107
+
1108
+ // Extended Profiles
1109
+ if ( !empty( $active_components['xprofile'] ) )
1110
+ bp_core_install_extended_profiles();
1111
+
1112
+ // Blog tracking
1113
+ if ( !empty( $active_components['blogs'] ) )
1114
+ bp_core_install_blog_tracking();
1115
+ }
1116
+
1117
+ function bp_core_update( $disabled ) {
1118
+ global $wpdb;
1119
+
1120
+ require( dirname( __FILE__ ) . '/bp-core-schema.php' );
1121
+ }
1122
+
1123
+ function bp_update_db_stuff() {
1124
+ $bp_prefix = bp_core_get_table_prefix();
1125
+ // Rename the old user activity cached table if needed.
1126
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$bp_prefix}bp_activity_user_activity_cached%'" ) )
1127
+ $wpdb->query( "RENAME TABLE {$bp_prefix}bp_activity_user_activity_cached TO {$bp->activity->table_name}" );
1128
+
1129
+ // Rename fields from pre BP 1.2
1130
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$bp->activity->table_name}%'" ) ) {
1131
+ if ( $wpdb->get_var( "SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_action'" ) )
1132
+ $wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE component_action type varchar(75) NOT NULL" );
1133
+
1134
+ if ( $wpdb->get_var( "SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_name'" ) )
1135
+ $wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE component_name component varchar(75) NOT NULL" );
1136
+ }
1137
+
1138
+ // On first installation - record all existing blogs in the system.
1139
+ if ( !(int)$bp->site_options['bp-blogs-first-install'] ) {
1140
+ bp_blogs_record_existing_blogs();
1141
+ bp_update_option( 'bp-blogs-first-install', 1 );
1142
+ }
1143
+
1144
+ if ( is_multisite() )
1145
+ bp_core_add_illegal_names();
1146
+
1147
+ // Update and remove the message threads table if it exists
1148
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$bp_prefix}bp_messages_threads%'" ) ) {
1149
+ $update = BP_Messages_Thread::update_tables();
1150
+
1151
+ if ( $update )
1152
+ $wpdb->query( "DROP TABLE {$bp_prefix}bp_messages_threads" );
1153
+ }
1154
+
1155
+ }
1156
+
1157
+ function bp_core_wizard_message() {
1158
+ if ( isset( $_GET['updated'] ) )
1159
+ $message = __( 'Installation was successful. The available options have now been updated, please continue with your selection.', 'buddypress' );
1160
+ else
1161
+ return false; ?>
1162
+
1163
+ <div id="message" class="updated">
1164
+ <p><?php echo esc_attr( $message ) ?></p>
1165
+ </div>
1166
+
1167
+ <?php
1168
+ }
1169
+ add_action( 'bp_admin_notices', 'bp_core_wizard_message' );
1170
+
1171
+ // Alter thickbox screens so the entire plugin download and install
1172
+ // interface is contained within.
1173
+ function bp_core_wizard_thickbox() {
1174
+ $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' ) ); ?>
1175
+
1176
+ <script type="text/javascript">
1177
+ jQuery('p.action-button a').attr( 'target', '' );
1178
+
1179
+ if ( window.location != window.parent.location ) {
1180
+ jQuery('#adminmenu, #wphead, #footer, #update-nag, #screen-meta').hide();
1181
+ jQuery('#wpbody').css( 'margin', '15px' );
1182
+ jQuery('body').css( 'min-width', '30px' );
1183
+ jQuery('#wpwrap').css( 'min-height', '30px' );
1184
+ jQuery('a').removeClass( 'thickbox thickbox-preview onclick' );
1185
+ jQuery('body.update-php div.wrap p:last').hide();
1186
+ 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>' );
1187
+ }
1188
+ </script>
1189
+
1190
+ <?php
1191
+ }
1192
+ add_action( 'admin_footer', 'bp_core_wizard_thickbox' );
1193
+
1194
+ /**
1195
+ * Adds the "BuddyPress" admin submenu item to the Site Admin tab.
1196
+ *
1197
+ * @package BuddyPress Core
1198
+ * @global object $bp Global BuddyPress settings object
1199
+ * @global $wpdb WordPress DB access object.
1200
+ * @uses add_submenu_page() WP function to add a submenu item
1201
+ */
1202
+ function bp_core_update_add_admin_menu() {
1203
+ global $bp_wizard;
1204
+
1205
+ // Only load this version of the menu if this is an upgrade or a new installation
1206
+ if ( empty( $bp_wizard->setup_type ) )
1207
+ return false;
1208
+
1209
+ if ( !current_user_can( 'activate_plugins' ) )
1210
+ return false;
1211
+
1212
+ if ( 'install' == $bp_wizard->setup_type )
1213
+ $status = __( 'Setup', 'buddypress' );
1214
+ else
1215
+ $status = __( 'Update', 'buddypress' );
1216
+
1217
+ // Add the administration tab under the "Site Admin" tab for site administrators
1218
+ add_menu_page( __( 'BuddyPress', 'buddypress' ), __( 'BuddyPress', 'buddypress' ), 'manage_options', 'bp-wizard', '' );
1219
+ $hook = add_submenu_page( 'bp-wizard', $status, $status, 'manage_options', 'bp-wizard', array( $bp_wizard, 'html' ) );
1220
+
1221
+ // Add a hook for css/js
1222
+ add_action( "admin_print_styles-$hook", 'bp_core_update_add_admin_menu_styles' );
1223
+ }
1224
+ add_action( bp_core_update_admin_hook(), 'bp_core_update_add_admin_menu', 9 );
1225
+
1226
+ function bp_core_update_add_admin_menu_styles() {
1227
+ if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
1228
+ wp_enqueue_style( 'bp-admin-css', apply_filters( 'bp_core_admin_css', plugins_url( '/buddypress' ) . '/bp-core/css/admin.dev.css' ), array(), '20110723' );
1229
+ wp_enqueue_script( 'bp-update-js', apply_filters( 'bp_core_update_js', plugins_url( '/buddypress' ) . '/bp-core/js/update.dev.js' ), array( 'jquery' ), '20110723' );
1230
+ } else {
1231
+ wp_enqueue_style( 'bp-admin-css', apply_filters( 'bp_core_admin_css', plugins_url( '/buddypress' ) . '/bp-core/css/admin.css' ), array(), '20110723' );
1232
+ wp_enqueue_script( 'bp-update-js', apply_filters( 'bp_core_update_js', plugins_url( '/buddypress' ) . '/bp-core/js/update.js' ), array( 'jquery' ), '20110723' );
1233
+
1234
+ }
1235
+
1236
+ wp_enqueue_script( 'thickbox' );
1237
+ wp_enqueue_style( 'thickbox' ); ?>
1238
+
1239
+ <style type="text/css">
1240
+ /* Wizard Icon */
1241
+ ul#adminmenu li.toplevel_page_bp-wizard .wp-menu-image a img { display: none; }
1242
+ 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; }
1243
+ ul#adminmenu li.toplevel_page_bp-wizard:hover .wp-menu-image a,
1244
+ ul#adminmenu li.toplevel_page_bp-wizard.wp-has-current-submenu .wp-menu-image a {
1245
+ background-position: -1px 0;
1246
+ }
1247
+
1248
+ /* Settings Icon */
1249
+ ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image a img { display: none; }
1250
+ 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; }
1251
+ ul#adminmenu li.toplevel_page_bp-general-settings:hover .wp-menu-image a,
1252
+ ul#adminmenu li.toplevel_page_bp-general-settings.wp-has-current-submenu .wp-menu-image a {
1253
+ background-position: -1px 0;
1254
+ }
1255
+ </style>
1256
+
1257
+ <?php
1258
+ }
1259
+ add_action( 'admin_head', 'bp_core_update_add_admin_menu_styles' );
1260
+
1261
+ /**
1262
+ * Fetches BP pages from the meta table
1263
+ *
1264
+ * @package BuddyPress Core
1265
+ * @since 1.5
1266
+ *
1267
+ * @return array $page_ids
1268
+ */
1269
+ function bp_core_update_get_page_meta() {
1270
+ if ( !$page_ids = bp_get_option( 'bp-pages' ) )
1271
+ $page_ids = array();
1272
+
1273
+ return apply_filters( 'bp_core_update_get_page_meta', $page_ids );
1274
+ }
1275
+
1276
+ function bp_core_update_do_network_admin() {
1277
+ $do_network_admin = false;
1278
+
1279
+ if ( is_multisite() && ( !defined( 'BP_ENABLE_MULTIBLOG' ) || !BP_ENABLE_MULTIBLOG ) )
1280
+ $do_network_admin = true;
1281
+
1282
+ return apply_filters( 'bp_core_do_network_admin', $do_network_admin );
1283
+ }
1284
+
1285
+ function bp_core_update_admin_hook() {
1286
+ $hook = bp_core_update_do_network_admin() ? 'network_admin_menu' : 'admin_menu';
1287
+
1288
+ return apply_filters( 'bp_core_admin_hook', $hook );
1289
+ }
1290
+
1291
+ /**
1292
+ * Adds an admin nag about running the BP upgrade/install wizard
1293
+ *
1294
+ * @package BuddyPress Core
1295
+ * @since 1.5
1296
+ * @global $pagenow The current admin page
1297
+ */
1298
+ function bp_core_update_nag() {
1299
+ global $bp_wizard, $pagenow;
1300
+
1301
+ if ( empty( $bp_wizard->setup_type ) )
1302
+ return;
1303
+
1304
+ if ( !is_super_admin() )
1305
+ return;
1306
+
1307
+ if ( 'admin.php' == $pagenow && ( empty( $_GET['page'] ) || 'bp-wizard' == $_GET['page'] ) )
1308
+ return;
1309
+
1310
+ $url = bp_core_update_do_network_admin() ? network_admin_url( 'admin.php?page=bp-wizard' ) : admin_url( 'admin.php?page=bp-wizard' );
1311
+
1312
+ switch( $bp_wizard->setup_type ) {
1313
+ case 'update':
1314
+ $msg = sprintf( __( 'BuddyPress has been updated! Please run the <a href="%s">update wizard</a>.', 'buddypress' ), $url );
1315
+ break;
1316
+
1317
+ default:
1318
+ case 'install':
1319
+ $msg = sprintf( __( 'BuddyPress was successfully installed! Please run the <a href="%s">installation wizard</a>.', 'buddypress' ), $url );
1320
+ break;
1321
+ }
1322
+
1323
+ echo '<div class="update-nag">' . $msg . '</div>';
1324
+ }
1325
+ add_action( 'admin_notices', 'bp_core_update_nag', 5 );
1326
+ add_action( 'network_admin_notices', 'bp_core_update_nag', 5 );
1327
+
1328
+ ?>
bp-core/bp-core-admin.php DELETED
@@ -1,251 +0,0 @@
1
- <?php
2
-
3
- function bp_core_admin_settings() {
4
- global $wpdb, $bp, $current_blog;
5
- ?>
6
-
7
- <?php
8
- if ( isset( $_POST['bp-admin-submit'] ) && isset( $_POST['bp-admin'] ) ) {
9
- if ( !check_admin_referer('bp-admin') )
10
- return false;
11
-
12
- // Settings form submitted, now save the settings.
13
- foreach ( (array)$_POST['bp-admin'] as $key => $value ) {
14
-
15
- if ( function_exists( 'xprofile_install' ) ) {
16
- if ( 'bp-xprofile-base-group-name' == $key ) {
17
- $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_groups} SET name = %s WHERE id = 1", $value ) );
18
- }
19
-
20
- if ( 'bp-xprofile-fullname-field-name' == $key ) {
21
- $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET name = %s WHERE group_id = 1 AND id = 1", $value ) );
22
- }
23
- }
24
-
25
- update_site_option( $key, $value );
26
- }
27
- }
28
- ?>
29
-
30
- <div class="wrap">
31
-
32
- <h2><?php _e( 'BuddyPress Settings', 'buddypress' ) ?></h2>
33
-
34
- <?php if ( isset( $_POST['bp-admin'] ) ) : ?>
35
- <div id="message" class="updated fade">
36
- <p><?php _e( 'Settings Saved', 'buddypress' ) ?></p>
37
- </div>
38
- <?php endif; ?>
39
-
40
- <form action="" method="post" id="bp-admin-form">
41
-
42
- <table class="form-table">
43
- <tbody>
44
- <?php if ( function_exists( 'xprofile_install' ) ) :?>
45
- <tr>
46
- <th scope="row"><p><?php _e( 'Base profile group name', 'buddypress' ) ?>:</p></th>
47
- <td>
48
- <input name="bp-admin[bp-xprofile-base-group-name]" id="bp-xprofile-base-group-name" value="<?php echo get_site_option('bp-xprofile-base-group-name') ?>" />
49
- </td>
50
- </tr>
51
- <tr>
52
- <th scope="row"><p><?php _e( 'Full Name field name', 'buddypress' ) ?>:</p></th>
53
- <td>
54
- <input name="bp-admin[bp-xprofile-fullname-field-name]" id="bp-xprofile-fullname-field-name" value="<?php echo get_site_option('bp-xprofile-fullname-field-name') ?>" />
55
- </td>
56
- </tr>
57
- <tr>
58
- <th scope="row"><p><?php _e( 'Disable BuddyPress to WordPress profile syncing?', 'buddypress' ) ?>:</p></th>
59
- <td>
60
- <input type="radio" name="bp-admin[bp-disable-profile-sync]"<?php if ( (int)get_site_option( 'bp-disable-profile-sync' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-profile-sync" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
61
- <input type="radio" name="bp-admin[bp-disable-profile-sync]"<?php if ( !(int)get_site_option( 'bp-disable-profile-sync' ) || '' == get_site_option( 'bp-disable-profile-sync' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-profile-sync" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
62
- </td>
63
- </tr>
64
- <?php endif; ?>
65
- <tr>
66
- <th scope="row"><p><?php _e( 'Hide admin bar for logged out users?', 'buddypress' ) ?>:</p></th>
67
- <td>
68
- <input type="radio" name="bp-admin[hide-loggedout-adminbar]"<?php if ( (int)get_site_option( 'hide-loggedout-adminbar' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-hide-loggedout-adminbar-yes" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
69
- <input type="radio" name="bp-admin[hide-loggedout-adminbar]"<?php if ( !(int)get_site_option( 'hide-loggedout-adminbar' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-hide-loggedout-adminbar-no" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
70
- </td>
71
- </tr>
72
- <tr>
73
- <th scope="row"><p><?php _e( 'Disable avatar uploads? (Gravatars will still work)', 'buddypress' ) ?>:</p></th>
74
- <td>
75
- <input type="radio" name="bp-admin[bp-disable-avatar-uploads]"<?php if ( (int)get_site_option( 'bp-disable-avatar-uploads' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-disable-avatar-uploads-yes" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
76
- <input type="radio" name="bp-admin[bp-disable-avatar-uploads]"<?php if ( !(int)get_site_option( 'bp-disable-avatar-uploads' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-disable-avatar-uploads-no" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
77
- </td>
78
- </tr>
79
- <tr>
80
- <th scope="row"><p><?php _e( 'Disable user account deletion?', 'buddypress' ) ?>:</p></th>
81
- <td>
82
- <input type="radio" name="bp-admin[bp-disable-account-deletion]"<?php if ( (int)get_site_option( 'bp-disable-account-deletion' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-account-deletion" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
83
- <input type="radio" name="bp-admin[bp-disable-account-deletion]"<?php if ( !(int)get_site_option( 'bp-disable-account-deletion' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-account-deletion" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
84
- </td>
85
- </tr>
86
- <?php if ( function_exists( 'bp_forums_setup') ) : ?>
87
- <tr>
88
- <th scope="row"><p><?php _e( 'Disable global forum directory?', 'buddypress' ) ?>:</p></th>
89
- <td>
90
- <input type="radio" name="bp-admin[bp-disable-forum-directory]"<?php if ( (int)get_site_option( 'bp-disable-forum-directory' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-forum-directory" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
91
- <input type="radio" name="bp-admin[bp-disable-forum-directory]"<?php if ( !(int)get_site_option( 'bp-disable-forum-directory' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-forum-directory" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
92
- </td>
93
- </tr>
94
- <?php endif; ?>
95
- <?php if ( function_exists( 'bp_activity_install') ) : ?>
96
- <tr>
97
- <th scope="row"><p><?php _e( 'Disable activity stream commenting on blog and forum posts?', 'buddypress' ) ?>:</p></th>
98
- <td>
99
- <input type="radio" name="bp-admin[bp-disable-blogforum-comments]"<?php if ( (int)get_site_option( 'bp-disable-blogforum-comments' ) || false === get_site_option( 'bp-disable-blogforum-comments' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-blogforum-comments" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
100
- <input type="radio" name="bp-admin[bp-disable-blogforum-comments]"<?php if ( !(int)get_site_option( 'bp-disable-blogforum-comments' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-blogforum-comments" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
101
- </td>
102
- </tr>
103
- <?php endif; ?>
104
-
105
- <tr>
106
- <th scope="row"><p><?php _e( 'Default User Avatar', 'buddypress' ) ?></p></th>
107
- <td>
108
- <p><?php _e( 'For users without a custom avatar of their own, you can either display a generic logo or a generated one based on their email address', 'buddypress' ) ?></p>
109
-
110
- <label><input name="bp-admin[user-avatar-default]" id="avatar_mystery" value="mystery" type="radio" <?php if ( get_site_option( 'user-avatar-default' ) == 'mystery' ) : ?> checked="checked"<?php endif; ?> /> &nbsp;<img alt="" src="http://www.gravatar.com/avatar/<?php md5( strtolower( $ud->user_email ) ) ?>&amp;?s=32&amp;d=<?php echo BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg' ?>&amp;r=PG&amp;forcedefault=1" class="avatar avatar-32" height="32" width="32"> &nbsp;<?php _e( 'Mystery Man', 'buddypress' ) ?></label><br>
111
- <label><input name="bp-admin[user-avatar-default]" id="avatar_identicon" value="identicon" type="radio" <?php if ( get_site_option( 'user-avatar-default' ) == 'identicon' ) : ?> checked="checked"<?php endif; ?> /> &nbsp;<img alt="" src="http://www.gravatar.com/avatar/<?php md5( strtolower( $ud->user_email ) ) ?>?s=32&amp;d=identicon&amp;r=PG&amp;forcedefault=1" class="avatar avatar-32" height="32" width="32"> &nbsp;<?php _e( 'Identicon (Generated)', 'buddypress' ) ?></label><br>
112
- <label><input name="bp-admin[user-avatar-default]" id="avatar_wavatar" value="wavatar" type="radio" <?php if ( get_site_option( 'user-avatar-default' ) == 'wavatar' ) : ?> checked="checked"<?php endif; ?> /> &nbsp;<img alt="" src="http://www.gravatar.com/avatar/<?php md5( strtolower( $ud->user_email ) ) ?>?s=32&amp;d=wavatar&amp;r=PG&amp;forcedefault=1" class="avatar avatar-32" height="32" width="32"> &nbsp;<?php _e( 'Wavatar (Generated)', 'buddypress' ) ?> </label><br>
113
- <label><input name="bp-admin[user-avatar-default]" id="avatar_monsterid" value="monsterid" type="radio" <?php if ( get_site_option( 'user-avatar-default' ) == 'monsterid' ) : ?> checked="checked"<?php endif; ?> /> &nbsp;<img alt="" src="http://www.gravatar.com/avatar/<?php md5( strtolower( $ud->user_email ) ) ?>?s=32&amp;d=monsterid&amp;r=PG&amp;forcedefault=1" class="avatar avatar-32" height="32" width="32"> &nbsp;<?php _e( 'MonsterID (Generated)', 'buddypress' ) ?></label>
114
- </td>
115
- </tr>
116
-
117
- <?php do_action( 'bp_core_admin_screen_fields' ) ?>
118
- </tbody>
119
- </table>
120
-
121
- <?php do_action( 'bp_core_admin_screen' ) ?>
122
-
123
- <p class="submit">
124
- <input class="button-primary" type="submit" name="bp-admin-submit" id="bp-admin-submit" value="<?php _e( 'Save Settings', 'buddypress' ) ?>"/>
125
- </p>
126
-
127
- <?php wp_nonce_field( 'bp-admin' ) ?>
128
-
129
- </form>
130
-
131
- </div>
132
-
133
- <?php
134
- }
135
-
136
- function bp_core_admin_component_setup() {
137
- global $wpdb, $bp;
138
- ?>
139
-
140
- <?php
141
- if ( isset( $_POST['bp-admin-component-submit'] ) && isset( $_POST['bp_components'] ) ) {
142
- if ( !check_admin_referer('bp-admin-component-setup') )
143
- return false;
144
-
145
- // Settings form submitted, now save the settings.
146
- foreach ( (array)$_POST['bp_components'] as $key => $value ) {
147
- if ( !(int) $value )
148
- $disabled[$key] = 1;
149
- }
150
- update_site_option( 'bp-deactivated-components', $disabled );
151
- }
152
- ?>
153
-
154
- <div class="wrap">
155
-
156
- <h2><?php _e( 'BuddyPress Component Setup', 'buddypress' ) ?></h2>
157
-
158
- <?php if ( isset( $_POST['bp-admin-component-submit'] ) ) : ?>
159
- <div id="message" class="updated fade">
160
- <p><?php _e( 'Settings Saved', 'buddypress' ) ?></p>
161
- </div>
162
- <?php endif; ?>
163
-
164
- <form action="" method="post" id="bp-admin-component-form">
165
-
166
- <p><?php _e('By default, all BuddyPress components are enabled. You can selectively disable any of the components by using the form below. Your BuddyPress installation will continue to function, however the features of the disabled components will no longer be accessible to anyone using the site.', 'buddypress' ) ?></p>
167
-
168
- <?php $disabled_components = get_site_option( 'bp-deactivated-components' ); ?>
169
-
170
- <table class="form-table" style="width: 80%">
171
- <tbody>
172
- <?php if ( file_exists( BP_PLUGIN_DIR . '/bp-activity.php') ) : ?>
173
- <tr>
174
- <td><h3><?php _e( 'Activity Streams', 'buddypress' ) ?></h3><p><?php _e( 'Allow users to post activity updates and track all activity across the entire site.', 'buddypress' ) ?></p></td>
175
- <td>
176
- <input type="radio" name="bp_components[bp-activity.php]" value="1"<?php if ( !isset( $disabled_components['bp-activity.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?> &nbsp;
177
- <input type="radio" name="bp_components[bp-activity.php]" value="0"<?php if ( isset( $disabled_components['bp-activity.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
178
- </td>
179
- </tr>
180
- <?php endif; ?>
181
- <?php if ( file_exists( BP_PLUGIN_DIR . '/bp-blogs.php') && bp_core_is_multisite() ) : ?>
182
- <tr>
183
- <td><h3><?php _e( 'Blog Tracking', 'buddypress' ) ?></h3><p><?php _e( 'Tracks blogs, blog posts and blogs comments for a user across a WPMU installation.', 'buddypress' ) ?></p></td>
184
- <td>
185
- <input type="radio" name="bp_components[bp-blogs.php]" value="1"<?php if ( !isset( $disabled_components['bp-blogs.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?> &nbsp;
186
- <input type="radio" name="bp_components[bp-blogs.php]" value="0"<?php if ( isset( $disabled_components['bp-blogs.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
187
- </td>
188
- </tr>
189
- <?php endif; ?>
190
- <?php if ( file_exists( BP_PLUGIN_DIR . '/bp-forums.php') ) : ?>
191
- <tr>
192
- <td><h3><?php _e( 'bbPress Forums', 'buddypress' ) ?></h3><p><?php _e( 'Activates bbPress forum support within BuddyPress groups or any other custom component.', 'buddypress' ) ?></p></td>
193
- <td>
194
- <input type="radio" name="bp_components[bp-forums.php]" value="1"<?php if ( !isset( $disabled_components['bp-forums.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?> &nbsp;
195
- <input type="radio" name="bp_components[bp-forums.php]" value="0"<?php if ( isset( $disabled_components['bp-forums.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
196
- </td>
197
- </tr>
198
- <?php endif; ?>
199
- <?php if ( file_exists( BP_PLUGIN_DIR . '/bp-friends.php') ) : ?>
200
- <tr>
201
- <td><h3><?php _e( 'Friends', 'buddypress' ) ?></h3><p><?php _e( 'Allows the creation of friend connections between users.', 'buddypress' ) ?></p></td>
202
- <td>
203
- <input type="radio" name="bp_components[bp-friends.php]" value="1"<?php if ( !isset( $disabled_components['bp-friends.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?> &nbsp;
204
- <input type="radio" name="bp_components[bp-friends.php]" value="0"<?php if ( isset( $disabled_components['bp-friends.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
205
- </td>
206
- </tr>
207
- <?php endif; ?>
208
- <?php if ( file_exists( BP_PLUGIN_DIR . '/bp-groups.php') ) : ?>
209
- <tr>
210
- <td><h3><?php _e( 'Groups', 'buddypress' ) ?></h3><p><?php _e( 'Let users create, join and participate in groups.', 'buddypress' ) ?></p></td>
211
- <td>
212
- <input type="radio" name="bp_components[bp-groups.php]" value="1"<?php if ( !isset( $disabled_components['bp-groups.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?> &nbsp;
213
- <input type="radio" name="bp_components[bp-groups.php]" value="0"<?php if ( isset( $disabled_components['bp-groups.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
214
- </td>
215
- </tr>
216
- <?php endif; ?>
217
- <?php if ( file_exists( BP_PLUGIN_DIR . '/bp-messages.php') ) : ?>
218
- <tr>
219
- <td><h3><?php _e( 'Private Messaging', 'buddypress' ) ?></h3><p><?php _e( 'Let users send private messages to one another. Site admins can also send site-wide notices.', 'buddypress' ) ?></p></td>
220
- <td>
221
- <input type="radio" name="bp_components[bp-messages.php]" value="1"<?php if ( !isset( $disabled_components['bp-messages.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?> &nbsp;
222
- <input type="radio" name="bp_components[bp-messages.php]" value="0"<?php if ( isset( $disabled_components['bp-messages.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
223
- </td>
224
- </tr>
225
- <?php endif; ?>
226
- <?php if ( file_exists( BP_PLUGIN_DIR . '/bp-xprofile.php') ) : ?>
227
- <tr>
228
- <td><h3><?php _e( 'Extended Profiles', 'buddypress' ) ?></h3><p><?php _e( 'Activates customizable profiles and avatars for site users.', 'buddypress' ) ?></p></td>
229
- <td width="45%">
230
- <input type="radio" name="bp_components[bp-xprofile.php]" value="1"<?php if ( !isset( $disabled_components['bp-xprofile.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Enabled', 'buddypress' ) ?> &nbsp;
231
- <input type="radio" name="bp_components[bp-xprofile.php]" value="0"<?php if ( isset( $disabled_components['bp-xprofile.php'] ) ) : ?> checked="checked" <?php endif; ?>/> <?php _e( 'Disabled', 'buddypress' ) ?>
232
- </td>
233
- </tr>
234
- <?php endif; ?>
235
- </tbody>
236
- </table>
237
-
238
- <p class="submit">
239
- <input class="button-primary" type="submit" name="bp-admin-component-submit" id="bp-admin-component-submit" value="<?php _e( 'Save Settings', 'buddypress' ) ?>"/>
240
- </p>
241
-
242
- <?php wp_nonce_field( 'bp-admin-component-setup' ) ?>
243
-
244
- </form>
245
-
246
- </div>
247
-
248
- <?php
249
- }
250
-
251
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-core/bp-core-adminbar.php CHANGED
@@ -1,314 +1,251 @@
1
  <?php
 
 
 
 
 
 
 
 
2
 
3
- function bp_core_admin_bar() {
4
- global $bp, $wpdb, $current_blog;
5
-
6
- if ( defined( 'BP_DISABLE_ADMIN_BAR' ) )
7
- return false;
8
-
9
- if ( (int)get_site_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() )
10
- return false;
11
-
12
- $bp->doing_admin_bar = true;
13
-
14
- echo '<div id="wp-admin-bar"><div class="padder">';
15
-
16
- // **** Do bp-adminbar-logo Actions ********
17
- do_action( 'bp_adminbar_logo' );
18
-
19
- echo '<ul class="main-nav">';
20
-
21
- // **** Do bp-adminbar-menus Actions ********
22
- do_action( 'bp_adminbar_menus' );
23
-
24
- echo '</ul>';
25
- echo "</div></div><!-- #wp-admin-bar -->\n\n";
26
 
27
- $bp->doing_admin_bar = false;
28
- }
29
 
30
- // **** Default BuddyPress admin bar logo ********
31
- function bp_adminbar_logo() {
32
- global $bp;
 
 
 
 
 
 
 
33
 
34
- echo '<a href="' . $bp->root_domain . '" id="admin-bar-logo">' . get_blog_option( BP_ROOT_BLOG, 'blogname') . '</a>';
35
- }
 
36
 
37
- // **** "Log In" and "Sign Up" links (Visible when not logged in) ********
38
- function bp_adminbar_login_menu() {
39
- global $bp;
40
 
41
- if ( is_user_logged_in() )
42
- return false;
43
 
44
- echo '<li class="bp-login no-arrow"><a href="' . $bp->root_domain . '/wp-login.php?redirect_to=' . urlencode( $bp->root_domain ) . '">' . __( 'Log In', 'buddypress' ) . '</a></li>';
 
 
 
45
 
46
- // Show "Sign Up" link if user registrations are allowed
47
- if ( bp_get_signup_allowed() )
48
- echo '<li class="bp-signup no-arrow"><a href="' . bp_get_signup_page(false) . '">' . __( 'Sign Up', 'buddypress' ) . '</a></li>';
49
  }
 
50
 
51
-
52
- // **** "My Account" Menu ******
53
- function bp_adminbar_account_menu() {
54
- global $bp;
55
-
56
- if ( !$bp->bp_nav || !is_user_logged_in() )
57
- return false;
58
-
59
- echo '<li id="bp-adminbar-account-menu"><a href="' . bp_loggedin_user_domain() . '">';
60
-
61
- echo __( 'My Account', 'buddypress' ) . '</a>';
62
- echo '<ul>';
63
-
64
- /* Loop through each navigation item */
65
- $counter = 0;
66
- foreach( (array)$bp->bp_nav as $nav_item ) {
67
- $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
68
-
69
- echo '<li' . $alt . '>';
70
- echo '<a id="bp-admin-' . $nav_item['css_id'] . '" href="' . $nav_item['link'] . '">' . $nav_item['name'] . '</a>';
71
-
72
- if ( is_array( $bp->bp_options_nav[$nav_item['slug']] ) ) {
73
- echo '<ul>';
74
- $sub_counter = 0;
75
-
76
- foreach( (array)$bp->bp_options_nav[$nav_item['slug']] as $subnav_item ) {
77
- $link = str_replace( $bp->displayed_user->domain, $bp->loggedin_user->domain, $subnav_item['link'] );
78
- $name = str_replace( $bp->displayed_user->userdata->user_login, $bp->loggedin_user->userdata->user_login, $subnav_item['name'] );
79
- $alt = ( 0 == $sub_counter % 2 ) ? ' class="alt"' : '';
80
- echo '<li' . $alt . '><a id="bp-admin-' . $subnav_item['css_id'] . '" href="' . $link . '">' . $name . '</a></li>';
81
- $sub_counter++;
 
 
 
 
 
 
 
 
 
 
82
  }
83
- echo '</ul>';
84
  }
85
-
86
- echo '</li>';
87
-
88
- $counter++;
89
  }
 
 
90
 
91
- $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
 
 
 
 
92
 
93
- echo '<li' . $alt . '><a id="bp-admin-logout" class="logout" href="' . wp_logout_url( site_url() ) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';
94
- echo '</ul>';
95
- echo '</li>';
96
- }
97
 
98
- // *** "My Blogs" Menu ********
99
- function bp_adminbar_blogs_menu() {
100
- global $bp;
101
 
102
- if ( !is_user_logged_in() || !bp_is_active( 'blogs' ) )
103
- return false;
104
 
105
- if ( !is_multisite() )
106
- return false;
 
 
107
 
108
- if ( !$blogs = wp_cache_get( 'bp_blogs_of_user_' . $bp->loggedin_user->id . '_inc_hidden', 'bp' ) ) {
109
- $blogs = bp_blogs_get_blogs_for_user( $bp->loggedin_user->id, true );
110
- wp_cache_set( 'bp_blogs_of_user_' . $bp->loggedin_user->id . '_inc_hidden', $blogs, 'bp' );
111
- }
112
 
113
- echo '<li id="bp-adminbar-blogs-menu"><a href="' . $bp->loggedin_user->domain . $bp->blogs->slug . '/">';
114
-
115
- _e( 'My Blogs', 'buddypress' );
116
-
117
- echo '</a>';
118
- echo '<ul>';
119
-
120
- if ( is_array( $blogs['blogs'] ) && (int)$blogs['count'] ) {
121
- $counter = 0;
122
- foreach ( (array)$blogs['blogs'] as $blog ) {
123
- $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
124
- $site_url = esc_attr( $blog->siteurl );
125
-
126
- echo '<li' . $alt . '>';
127
- echo '<a href="' . $site_url . '">' . esc_html( $blog->name ) . '</a>';
128
- echo '<ul>';
129
- echo '<li class="alt"><a href="' . $site_url . 'wp-admin/">' . __( 'Dashboard', 'buddypress' ) . '</a></li>';
130
- echo '<li><a href="' . $site_url . 'wp-admin/post-new.php">' . __( 'New Post', 'buddypress' ) . '</a></li>';
131
- echo '<li class="alt"><a href="' . $site_url . 'wp-admin/edit.php">' . __( 'Manage Posts', 'buddypress' ) . '</a></li>';
132
- echo '<li><a href="' . $site_url . 'wp-admin/edit-comments.php">' . __( 'Manage Comments', 'buddypress' ) . '</a></li>';
133
- echo '</ul>';
134
- echo '</li>';
135
- $counter++;
136
- }
137
- }
138
 
139
- $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
 
 
 
140
 
141
- if ( bp_blog_signup_enabled() ) {
142
- echo '<li' . $alt . '>';
143
- echo '<a href="' . $bp->root_domain . '/' . $bp->blogs->slug . '/create/">' . __( 'Create a Blog!', 'buddypress' ) . '</a>';
144
- echo '</li>';
145
  }
146
-
147
- echo '</ul>';
148
- echo '</li>';
149
  }
 
150
 
151
- function bp_adminbar_thisblog_menu() {
152
- if ( current_user_can( 'edit_posts' ) ) {
153
- echo '<li id="bp-adminbar-thisblog-menu"><a href="' . admin_url() . '">';
154
-
155
- _e( 'Dashboard', 'buddypress' );
156
-
157
- echo '</a>';
158
- echo '<ul>';
159
 
160
- echo '<li class="alt"><a href="' . admin_url() . 'post-new.php">' . __( 'New Post', 'buddypress' ) . '</a></li>';
161
- echo '<li><a href="' . admin_url() . 'edit.php">' . __( 'Manage Posts', 'buddypress' ) . '</a></li>';
162
- echo '<li class="alt"><a href="' . admin_url() . 'edit-comments.php">' . __( 'Manage Comments', 'buddypress' ) . '</a></li>';
163
 
164
- do_action( 'bp_adminbar_thisblog_items' );
 
165
 
166
- echo '</ul>';
167
- echo '</li>';
168
- }
169
  }
 
170
 
171
- // **** "Notifications" Menu *********
172
- function bp_adminbar_notifications_menu() {
173
- global $bp;
174
-
175
- if ( !is_user_logged_in() )
176
- return false;
177
-
178
- echo '<li id="bp-adminbar-notifications-menu"><a href="' . $bp->loggedin_user->domain . '">';
179
- _e( 'Notifications', 'buddypress' );
180
-
181
- if ( $notifications = bp_core_get_notifications_for_user( $bp->loggedin_user->id ) ) { ?>
182
- <span><?php echo count( $notifications ) ?></span>
183
- <?php
184
- }
185
 
186
- echo '</a>';
187
- echo '<ul>';
 
188
 
189
- if ( $notifications ) {
190
- $counter = 0;
191
- for ( $i = 0; $i < count($notifications); $i++ ) {
192
- $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : ''; ?>
193
 
194
- <li<?php echo $alt ?>><?php echo $notifications[$i] ?></li>
 
195
 
196
- <?php $counter++;
197
- }
198
- } else { ?>
199
 
200
- <li><a href="<?php echo $bp->loggedin_user->domain ?>"><?php _e( 'No new notifications.', 'buddypress' ); ?></a></li>
 
201
 
202
- <?php
203
- }
204
 
205
- echo '</ul>';
206
- echo '</li>';
207
- }
208
 
209
- // **** "Blog Authors" Menu (visible when not logged in) ********
210
- function bp_adminbar_authors_menu() {
211
- global $bp, $current_blog, $wpdb;
212
-
213
- // Only for multisite
214
- if ( !is_multisite() )
215
- return false;
216
-
217
- // Hide on root blog
218
- if ( $current_blog->blog_id == BP_ROOT_BLOG || !bp_is_active( 'blogs' ) )
219
- return false;
220
-
221
- $blog_prefix = $wpdb->get_blog_prefix( $current_blog->id );
222
- $authors = $wpdb->get_results( "SELECT user_id, user_login, user_nicename, display_name, user_email, meta_value as caps FROM $wpdb->users u, $wpdb->usermeta um WHERE u.ID = um.user_id AND meta_key = '{$blog_prefix}capabilities' ORDER BY um.user_id" );
223
-
224
- if ( !empty( $authors ) ) {
225
- // This is a blog, render a menu with links to all authors
226
- echo '<li id="bp-adminbar-authors-menu"><a href="/">';
227
- _e('Blog Authors', 'buddypress');
228
- echo '</a>';
229
-
230
- echo '<ul class="author-list">';
231
- foreach( (array)$authors as $author ) {
232
- $caps = maybe_unserialize( $author->caps );
233
- if ( isset( $caps['subscriber'] ) || isset( $caps['contributor'] ) ) continue;
234
-
235
- echo '<li>';
236
- echo '<a href="' . bp_core_get_user_domain( $author->user_id, $author->user_nicename, $author->user_login ) . '">';
237
- echo bp_core_fetch_avatar( array( 'item_id' => $author->user_id, 'email' => $author->user_email, 'width' => 15, 'height' => 15 ) ) ;
238
- echo ' ' . $author->display_name . '</a>';
239
- echo '<div class="admin-bar-clear"></div>';
240
- echo '</li>';
241
- }
242
- echo '</ul>';
243
- echo '</li>';
244
- }
245
  }
 
246
 
247
- // **** "Random" Menu (visible when not logged in) ********
248
- function bp_adminbar_random_menu() {
249
- global $bp; ?>
250
-
251
- <li class="align-right" id="bp-adminbar-visitrandom-menu">
252
- <a href="#"><?php _e( 'Visit', 'buddypress' ) ?></a>
253
- <ul class="random-list">
254
- <li><a href="<?php echo $bp->root_domain . '/' . BP_MEMBERS_SLUG . '/?random-member' ?>"><?php _e( 'Random Member', 'buddypress' ) ?></a></li>
255
-
256
- <?php if ( bp_is_active( 'groups' ) ) : ?>
257
-
258
- <li class="alt"><a href="<?php echo $bp->root_domain . '/' . $bp->groups->slug . '/?random-group' ?>"><?php _e( 'Random Group', 'buddypress' ) ?></a></li>
259
-
260
- <?php endif; ?>
261
 
262
- <?php if ( bp_is_active( 'blogs' ) && is_multisite() ) : ?>
 
263
 
264
- <li><a href="<?php echo $bp->root_domain . '/' . $bp->blogs->slug . '/?random-blog' ?>"><?php _e( 'Random Blog', 'buddypress' ) ?></a></li>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
265
 
266
- <?php endif; ?>
 
 
 
 
 
 
267
 
268
- <?php do_action( 'bp_adminbar_random_menu' ) ?>
269
 
270
- </ul>
271
- </li>
 
272
 
273
- <?php
274
  }
 
275
 
276
  /**
277
- * Provides fallback support for the WordPress 3.1 admin bar
278
- *
279
- * By default, this function turns off the WP 3.1 admin bar in favor of the classic BP BuddyBar.
280
- * To turn off the BP BuddyBar in favor of WP's admin bar, place the following in wp-config.php:
281
- * define( 'BP_USE_WP_ADMIN_BAR', true );
282
- *
283
- * @package BuddyPress Core
284
- * @since 1.2.8
285
  */
286
- function bp_core_load_admin_bar() {
287
  global $wp_version;
288
-
289
- if ( defined( 'BP_USE_WP_ADMIN_BAR' ) && BP_USE_WP_ADMIN_BAR && version_compare( $wp_version, 3.1, '>=' ) ) {
290
- // TODO: Add BP support to WP admin bar
291
  return;
292
- } elseif ( !defined( 'BP_DISABLE_ADMIN_BAR' ) || !BP_DISABLE_ADMIN_BAR ) {
293
- // Keep the WP admin bar from loading
294
- if ( function_exists( 'show_admin_bar' ) )
295
- show_admin_bar( false );
296
-
297
- // Actions used to build the BP admin bar
298
- add_action( 'bp_adminbar_logo', 'bp_adminbar_logo' );
299
- add_action( 'bp_adminbar_menus', 'bp_adminbar_login_menu', 2 );
300
- add_action( 'bp_adminbar_menus', 'bp_adminbar_account_menu', 4 );
301
- add_action( 'bp_adminbar_menus', 'bp_adminbar_blogs_menu', 6 );
302
- add_action( 'bp_adminbar_menus', 'bp_adminbar_thisblog_menu', 6 );
303
- add_action( 'bp_adminbar_menus', 'bp_adminbar_notifications_menu', 8 );
304
- add_action( 'bp_adminbar_menus', 'bp_adminbar_authors_menu', 12 );
305
- add_action( 'bp_adminbar_menus', 'bp_adminbar_random_menu', 100 );
306
-
307
- // Actions used to append BP admin bar to footer
308
- add_action( 'wp_footer', 'bp_core_admin_bar', 8 );
309
- add_action( 'admin_footer', 'bp_core_admin_bar' );
310
- }
311
- }
312
- add_action( 'bp_loaded', 'bp_core_load_admin_bar' );
313
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
314
  ?>
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
9
+ */
10
 
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
+ * Unhook the WordPress core menus.
19
+ *
20
+ * @since BuddyPress (r4151)
21
+ *
22
+ * @uses remove_action
23
+ * @uses is_network_admin()
24
+ * @uses is_user_admin()
25
+ */
26
+ function bp_admin_bar_remove_wp_menus() {
27
 
28
+ remove_action( 'admin_bar_menu', 'wp_admin_bar_my_account_menu', 10 );
29
+ remove_action( 'admin_bar_menu', 'wp_admin_bar_my_sites_menu', 20 );
30
+ remove_action( 'admin_bar_menu', 'wp_admin_bar_dashboard_view_site_menu', 25 );
31
 
32
+ // Don't show the 'Edit Page' menu on BP pages
33
+ if ( !bp_is_blog_page() )
34
+ remove_action( 'admin_bar_menu', 'wp_admin_bar_edit_menu', 30 );
35
 
36
+ remove_action( 'admin_bar_menu', 'wp_admin_bar_shortlink_menu', 80 );
37
+ remove_action( 'admin_bar_menu', 'wp_admin_bar_updates_menu', 70 );
38
 
39
+ if ( !is_network_admin() && !is_user_admin() ) {
40
+ remove_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 50 );
41
+ remove_action( 'admin_bar_menu', 'wp_admin_bar_appearance_menu', 60 );
42
+ }
43
 
44
+ remove_action( 'admin_bar_menu', 'wp_admin_bar_updates_menu', 70 );
 
 
45
  }
46
+ add_action( 'bp_init', 'bp_admin_bar_remove_wp_menus', 2 );
47
 
48
+ /**
49
+ * Add a menu for the root site of this BuddyPress network
50
+ *
51
+ * @global type $bp
52
+ * @global type $wp_admin_bar
53
+ * @return If in ajax
54
+ */
55
+ function bp_admin_bar_root_site() {
56
+ global $bp, $wp_admin_bar;
57
+
58
+ // Create the root blog menu
59
+ $wp_admin_bar->add_menu( array(
60
+ 'id' => 'bp-root-blog',
61
+ 'title' => get_blog_option( bp_get_root_blog_id(), 'blogname' ),
62
+ 'href' => bp_get_root_domain()
63
+ ) );
64
+
65
+ // Logged in user
66
+ if ( is_user_logged_in() ) {
67
+
68
+ // Dashboard links
69
+ if ( is_super_admin() ) {
70
+
71
+ // Add site admin link
72
+ $wp_admin_bar->add_menu( array(
73
+ 'id' => 'dashboard',
74
+ 'parent' => 'bp-root-blog',
75
+ 'title' => __( 'Admin Dashboard', 'buddypress' ),
76
+ 'href' => get_admin_url( bp_get_root_blog_id() )
77
+ ) );
78
+
79
+ // Add network admin link
80
+ if ( is_multisite() ) {
81
+
82
+ // Link to the network admin dashboard
83
+ $wp_admin_bar->add_menu( array(
84
+ 'id' => 'network-dashboard',
85
+ 'parent' => 'bp-root-blog',
86
+ 'title' => __( 'Network Dashboard', 'buddypress' ),
87
+ 'href' => network_admin_url()
88
+ ) );
89
  }
 
90
  }
 
 
 
 
91
  }
92
+ }
93
+ add_action( 'bp_setup_admin_bar', 'bp_admin_bar_root_site', 3 );
94
 
95
+ /**
96
+ * Add the "My Sites/[Site Name]" menu and all submenus.
97
+ */
98
+ function bp_admin_bar_my_sites_menu() {
99
+ global $wpdb, $wp_admin_bar;
100
 
101
+ /* Add the 'My Sites' menu if the user has more than one site. */
102
+ if ( count( $wp_admin_bar->user->blogs ) <= 1 )
103
+ return;
 
104
 
105
+ $wp_admin_bar->add_menu( array( 'id' => 'my-blogs', 'title' => __( 'My Sites' ), 'href' => admin_url( 'my-sites.php' ) ) );
 
 
106
 
107
+ $default = includes_url( 'images/wpmini-blue.png' );
 
108
 
109
+ foreach ( (array)$wp_admin_bar->user->blogs as $blog ) {
110
+ // @todo Replace with some favicon lookup.
111
+ //$blavatar = '<img src="' . esc_url( blavatar_url( blavatar_domain( $blog->siteurl ), 'img', 16, $default ) ) . '" alt="Blavatar" width="16" height="16" />';
112
+ $blavatar = '<img src="' . esc_url( $default ) . '" alt="' . esc_attr__( 'Blavatar' ) . '" width="16" height="16" class="blavatar"/>';
113
 
114
+ $blogname = empty( $blog->blogname ) ? $blog->domain : $blog->blogname;
 
 
 
115
 
116
+ $wp_admin_bar->add_menu( array( 'parent' => 'my-blogs', 'id' => 'blog-' . $blog->userblog_id, 'title' => $blavatar . $blogname, 'href' => get_admin_url( $blog->userblog_id ) ) );
117
+ $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 ) ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
+ if ( current_user_can_for_blog( $blog->userblog_id, 'edit_posts' ) ) {
120
+ $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' ) ) );
121
+ $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' ) ) );
122
+ }
123
 
124
+ $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 ) ) );
 
 
 
125
  }
 
 
 
126
  }
127
+ add_action( 'bp_setup_admin_bar', 'bp_admin_bar_my_sites_menu', 3 );
128
 
129
+ /**
130
+ * Add edit comments link with awaiting moderation count bubble
131
+ */
132
+ function bp_admin_bar_comments_menu( $wp_admin_bar ) {
133
+ global $wp_admin_bar;
 
 
 
134
 
135
+ if ( !current_user_can( 'edit_posts' ) )
136
+ return;
 
137
 
138
+ $awaiting_mod = wp_count_comments();
139
+ $awaiting_mod = $awaiting_mod->moderated;
140
 
141
+ $awaiting_mod = $awaiting_mod ? "<span id='ab-awaiting-mod' class='pending-count'>" . number_format_i18n( $awaiting_mod ) . "</span>" : '';
142
+ $wp_admin_bar->add_menu( array( 'parent' => 'dashboard', 'id' => 'comments', 'title' => sprintf( __( 'Comments %s' ), $awaiting_mod ), 'href' => admin_url( 'edit-comments.php' ) ) );
 
143
  }
144
+ add_action( 'bp_setup_admin_bar', 'bp_admin_bar_comments_menu', 3 );
145
 
146
+ /**
147
+ * Add "Appearance" menu with widget and nav menu submenu
148
+ */
149
+ function bp_admin_bar_appearance_menu() {
150
+ global $wp_admin_bar;
 
 
 
 
 
 
 
 
 
151
 
152
+ // You can have edit_theme_options but not switch_themes.
153
+ if ( !current_user_can( 'switch_themes' ) && !current_user_can( 'edit_theme_options' ) )
154
+ return;
155
 
156
+ $wp_admin_bar->add_menu( array( 'parent' => 'dashboard', 'id' => 'appearance', 'title' => __( 'Appearance' ), 'href' => admin_url( 'themes.php' ) ) );
 
 
 
157
 
158
+ if ( !current_user_can( 'edit_theme_options' ) )
159
+ return;
160
 
161
+ if ( current_user_can( 'switch_themes' ) )
162
+ $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'themes', 'title' => __( 'Themes' ), 'href' => admin_url( 'themes.php' ) ) );
 
163
 
164
+ if ( current_theme_supports( 'widgets' ) )
165
+ $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'widgets', 'title' => __( 'Widgets' ), 'href' => admin_url( 'widgets.php' ) ) );
166
 
167
+ if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) )
168
+ $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __( 'Menus' ), 'href' => admin_url( 'nav-menus.php' ) ) );
169
 
170
+ if ( current_theme_supports( 'custom-background' ) )
171
+ $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'background', 'title' => __( 'Background' ), 'href' => admin_url( 'themes.php?page=custom-background' ) ) );
 
172
 
173
+ if ( current_theme_supports( 'custom-header' ) )
174
+ $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'header', 'title' => __( 'Header' ), 'href' => admin_url( 'themes.php?page=custom-header' ) ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  }
176
+ add_action( 'bp_setup_admin_bar', 'bp_admin_bar_appearance_menu', 3 );
177
 
178
+ /**
179
+ * Provide an update link if theme/plugin/core updates are available
180
+ */
181
+ function bp_admin_bar_updates_menu() {
182
+ global $wp_admin_bar;
 
 
 
 
 
 
 
 
 
183
 
184
+ if ( !current_user_can( 'install_plugins' ) )
185
+ return;
186
 
187
+ $plugin_update_count = $theme_update_count = $wordpress_update_count = 0;
188
+ $update_plugins = get_site_transient( 'update_plugins' );
189
+ if ( !empty( $update_plugins->response ) )
190
+ $plugin_update_count = count( $update_plugins->response );
191
+ $update_themes = get_site_transient( 'update_themes' );
192
+ if ( !empty( $update_themes->response ) )
193
+ $theme_update_count = count( $update_themes->response );
194
+ /* @todo get_core_updates() is only available on admin page loads
195
+ $update_wordpress = get_core_updates( array('dismissed' => false) );
196
+ if ( !empty($update_wordpress) && !in_array( $update_wordpress[0]->response, array('development', 'latest') ) )
197
+ $wordpress_update_count = 1;
198
+ */
199
+
200
+ $update_count = $plugin_update_count + $theme_update_count + $wordpress_update_count;
201
+
202
+ if ( !$update_count )
203
+ return;
204
 
205
+ $update_title = array( );
206
+ if ( $wordpress_update_count )
207
+ $update_title[] = sprintf( __( '%d WordPress Update' ), $wordpress_update_count );
208
+ if ( $plugin_update_count )
209
+ $update_title[] = sprintf( _n( '%d Plugin Update', '%d Plugin Updates', $plugin_update_count ), $plugin_update_count );
210
+ if ( $theme_update_count )
211
+ $update_title[] = sprintf( _n( '%d Theme Update', '%d Theme Updates', $theme_update_count ), $theme_update_count );
212
 
213
+ $update_title = !empty( $update_title ) ? esc_attr( implode( ', ', $update_title ) ) : '';
214
 
215
+ $update_title = "<span title='$update_title'>";
216
+ $update_title .= sprintf( __( 'Updates %s' ), "<span id='ab-updates' class='update-count'>" . number_format_i18n( $update_count ) . '</span>' );
217
+ $update_title .= '</span>';
218
 
219
+ $wp_admin_bar->add_menu( array( 'parent' => 'dashboard', 'id' => 'updates', 'title' => $update_title, 'href' => network_admin_url( 'update-core.php' ) ) );
220
  }
221
+ add_action( 'bp_setup_admin_bar', 'bp_admin_bar_updates_menu', 3 );
222
 
223
  /**
224
+ * Handle the Admin Bar CSS
 
 
 
 
 
 
 
225
  */
226
+ function bp_core_load_admin_bar_css() {
227
  global $wp_version;
228
+
229
+ if ( !bp_use_wp_admin_bar() )
 
230
  return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
 
232
+ // Admin bar styles
233
+ if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG )
234
+ $stylesheet = BP_PLUGIN_URL . '/bp-core/css/admin-bar.dev.css';
235
+ else
236
+ $stylesheet = BP_PLUGIN_URL . '/bp-core/css/admin-bar.css';
237
+
238
+ wp_enqueue_style( 'bp-admin-bar', apply_filters( 'bp_core_admin_bar_css', $stylesheet ), array( 'admin-bar' ), '20110723' );
239
+
240
+ if ( !is_rtl() )
241
+ return;
242
+
243
+ if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG )
244
+ $stylesheet = BP_PLUGIN_URL . '/bp-core/css/admin-bar-rtl.dev.css';
245
+ else
246
+ $stylesheet = BP_PLUGIN_URL . '/bp-core/css/admin-bar-rtl.css';
247
+
248
+ wp_enqueue_style( 'bp-admin-bar-rtl', apply_filters( 'bp_core_admin_bar_rtl_css', $stylesheet ), array( 'bp-admin-bar' ), '20110723' );
249
+ }
250
+ add_action( 'bp_init', 'bp_core_load_admin_bar_css' );
251
  ?>
bp-core/bp-core-avatars.php CHANGED
@@ -1,21 +1,20 @@
1
  <?php
2
- /*
3
- Based on contributions from: Beau Lebens - http://www.dentedreality.com.au/
4
- Modified for BuddyPress by: Andy Peatling - http://apeatling.wordpress.com/
5
- */
 
 
 
 
 
6
 
7
  /***
8
  * Set up the constants we need for avatar support
9
  */
10
  function bp_core_set_avatar_constants() {
11
  global $bp;
12
-
13
- if ( !defined( 'BP_AVATAR_UPLOAD_PATH' ) )
14
- define( 'BP_AVATAR_UPLOAD_PATH', bp_core_avatar_upload_path() );
15
-
16
- if ( !defined( 'BP_AVATAR_URL' ) )
17
- define( 'BP_AVATAR_URL', bp_core_avatar_url() );
18
-
19
  if ( !defined( 'BP_AVATAR_THUMB_WIDTH' ) )
20
  define( 'BP_AVATAR_THUMB_WIDTH', 50 );
21
 
@@ -32,8 +31,8 @@ function bp_core_set_avatar_constants() {
32
  define( 'BP_AVATAR_ORIGINAL_MAX_WIDTH', 450 );
33
 
34
  if ( !defined( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE' ) ) {
35
- if ( !$bp->site_options['fileupload_maxk'] )
36
- define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', 5120000 ); /* 5mb */
37
  else
38
  define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', $bp->site_options['fileupload_maxk'] * 1024 );
39
  }
@@ -44,7 +43,32 @@ function bp_core_set_avatar_constants() {
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_loaded', 'bp_core_set_avatar_constants', 8 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
 
49
  /**
50
  * bp_core_fetch_avatar()
@@ -52,8 +76,8 @@ add_action( 'bp_loaded', 'bp_core_set_avatar_constants', 8 );
52
  * Fetches an avatar from a BuddyPress object. Supports user/group/blog as
53
  * default, but can be extended to include your own custom components too.
54
  *
55
- * @global object $bp
56
- * @global object $current_blog
57
  * @param array $args Determine the output of this function
58
  * @return string Formatted HTML <img> element, or raw avatar URL based on $html arg
59
  */
@@ -61,25 +85,26 @@ function bp_core_fetch_avatar( $args = '' ) {
61
  global $bp, $current_blog;
62
 
63
  // Set a few default variables
64
- $def_object = 'user';
65
- $def_type = 'thumb';
66
- $def_class = 'avatar';
67
- $def_alt = __( 'Avatar Image', 'buddypress' );
68
 
69
  // Set the default variables array
70
  $defaults = array(
71
- 'item_id' => false,
72
- 'object' => $def_object, // user/group/blog/custom type (if you use filters)
73
- 'type' => $def_type, // thumb or full
74
- 'avatar_dir' => false, // Specify a custom avatar directory for your object
75
- 'width' => false, // Custom width (int)
76
- 'height' => false, // Custom height (int)
77
- 'class' => $def_class, // Custom <img> class (string)
78
- 'css_id' => false, // Custom <img> ID (string)
79
- 'alt' => $def_alt, // Custom <img> alt (string)
80
- 'email' => false, // Pass the user email (for gravatar) to prevent querying the DB for it
81
- 'no_grav' => false, // If there is no avatar found, return false instead of a grav?
82
- 'html' => true // Wrap the return img URL in <img />
 
83
  );
84
 
85
  // Compare defaults to passed and extract
@@ -90,33 +115,53 @@ function bp_core_fetch_avatar( $args = '' ) {
90
  if ( !$item_id ) {
91
  if ( 'user' == $object )
92
  $item_id = $bp->displayed_user->id;
93
- else if ( 'group' == $object )
94
  $item_id = $bp->groups->current_group->id;
95
  else if ( 'blog' == $object )
96
  $item_id = $current_blog->id;
97
 
98
  $item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object );
99
 
100
- if ( !$item_id ) return false;
 
101
  }
102
 
103
  // Set avatar_dir if not passed (uses $object)
104
  if ( !$avatar_dir ) {
105
  if ( 'user' == $object )
106
  $avatar_dir = 'avatars';
107
- else if ( 'group' == $object )
108
  $avatar_dir = 'group-avatars';
109
  else if ( 'blog' == $object )
110
  $avatar_dir = 'blog-avatars';
111
 
112
  $avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object );
113
 
114
- if ( !$avatar_dir ) return false;
 
115
  }
116
 
117
  // Add an identifying class to each item
118
  $class .= ' ' . $object . '-' . $item_id . '-avatar';
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  // Set CSS ID if passed
121
  if ( !empty( $css_id ) )
122
  $css_id = " id='{$css_id}'";
@@ -125,25 +170,25 @@ function bp_core_fetch_avatar( $args = '' ) {
125
  if ( $width )
126
  $html_width = " width='{$width}'";
127
  else
128
- $html_width = ( 'thumb' == $type ) ? ' width="' . BP_AVATAR_THUMB_WIDTH . '"' : ' width="' . BP_AVATAR_FULL_WIDTH . '"';
129
 
130
  // Set avatar height
131
  if ( $height )
132
  $html_height = " height='{$height}'";
133
  else
134
- $html_height = ( 'thumb' == $type ) ? ' height="' . BP_AVATAR_THUMB_HEIGHT . '"' : ' height="' . BP_AVATAR_FULL_HEIGHT . '"';
135
 
136
  // Set avatar URL and DIR based on prepopulated constants
137
- $avatar_folder_url = apply_filters( 'bp_core_avatar_folder_url', BP_AVATAR_URL . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
138
- $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', BP_AVATAR_UPLOAD_PATH . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
139
 
140
  /****
141
  * Look for uploaded avatar first. Use it if it exists.
142
  * Set the file names to search for, to select the full size
143
  * or thumbnail image.
144
  */
145
- $avatar_size = ( 'full' == $type ) ? '-bpfull' : '-bpthumb';
146
- $legacy_user_avatar_name = ( 'full' == $type ) ? '-avatar2' : '-avatar1';
147
  $legacy_group_avatar_name = ( 'full' == $type ) ? '-groupavatar-full' : '-groupavatar-thumb';
148
 
149
  // Check for directory
@@ -191,11 +236,11 @@ function bp_core_fetch_avatar( $args = '' ) {
191
  closedir( $av_dir );
192
 
193
  // If we found a locally uploaded avatar
194
- if ( $avatar_url ) {
195
 
196
  // Return it wrapped in an <img> element
197
  if ( true === $html ) {
198
- return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $avatar_url . '" alt="' . $alt . '" class="' . $class . '"' . $css_id . $html_width . $html_height . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
199
 
200
  // ...or only the URL
201
  } else {
@@ -207,21 +252,21 @@ function bp_core_fetch_avatar( $args = '' ) {
207
  // If no avatars could be found, try to display a gravatar
208
 
209
  // Skips gravatar check if $no_grav is passed
210
- if ( !$no_grav ) {
211
 
212
  // Set gravatar size
213
  if ( $width )
214
  $grav_size = $width;
215
  else if ( 'full' == $type )
216
- $grav_size = BP_AVATAR_FULL_WIDTH;
217
  else if ( 'thumb' == $type )
218
- $grav_size = BP_AVATAR_THUMB_WIDTH;
219
 
220
  // Set gravatar type
221
  if ( empty( $bp->grav_default->{$object} ) )
222
  $default_grav = 'wavatar';
223
  else if ( 'mystery' == $bp->grav_default->{$object} )
224
- $default_grav = apply_filters( 'bp_core_mysteryman_src', BP_AVATAR_DEFAULT, $grav_size );
225
  else
226
  $default_grav = $bp->grav_default->{$object};
227
 
@@ -230,7 +275,7 @@ function bp_core_fetch_avatar( $args = '' ) {
230
  if ( 'user' == $object ) {
231
  $email = bp_core_get_user_email( $item_id );
232
  } else if ( 'group' == $object || 'blog' == $object ) {
233
- $email = "{$item_id}-{$object}@{$bp->root_domain}";
234
  }
235
  }
236
 
@@ -241,28 +286,38 @@ function bp_core_fetch_avatar( $args = '' ) {
241
  $host = 'http://www.gravatar.com/avatar/';
242
 
243
  // Filter gravatar vars
244
- $email = apply_filters( 'bp_core_gravatar_email', $email, $item_id, $object );
245
- $gravatar = apply_filters( 'bp_gravatar_url', $host ) . md5( strtolower( $email ) ) . '?d=' . $default_grav . '&amp;s=' . $grav_size;
246
-
247
- // Return gravatar wrapped in <img />
248
- if ( true === $html )
249
- return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $gravatar . '" alt="' . $alt . '" class="' . $class . '"' . $css_id . $html_width . $html_height . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
250
-
251
- // ...or only return the gravatar URL
252
- else
253
- return apply_filters( 'bp_core_fetch_avatar_url', $gravatar );
254
 
255
  } else {
256
- return apply_filters( 'bp_core_fetch_avatar', false, $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
 
257
  }
 
 
 
 
 
258
  }
259
 
 
 
 
 
 
 
 
 
 
 
 
 
260
  function bp_core_delete_existing_avatar( $args = '' ) {
261
  global $bp;
262
 
263
  $defaults = array(
264
- 'item_id' => false,
265
- 'object' => 'user', // user OR group OR blog OR custom type (if you use filters)
266
  'avatar_dir' => false
267
  );
268
 
@@ -295,7 +350,7 @@ function bp_core_delete_existing_avatar( $args = '' ) {
295
  if ( !$avatar_dir ) return false;
296
  }
297
 
298
- $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', BP_AVATAR_UPLOAD_PATH . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
299
 
300
  if ( !file_exists( $avatar_folder_dir ) )
301
  return false;
@@ -315,6 +370,20 @@ function bp_core_delete_existing_avatar( $args = '' ) {
315
  return true;
316
  }
317
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
318
  function bp_core_avatar_handle_upload( $file, $upload_dir_filter ) {
319
  global $bp;
320
 
@@ -330,8 +399,8 @@ function bp_core_avatar_handle_upload( $file, $upload_dir_filter ) {
330
 
331
  $uploadErrors = array(
332
  0 => __("There is no error, the file uploaded with success", 'buddypress'),
333
- 1 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE),
334
- 2 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE),
335
  3 => __("The uploaded file was only partially uploaded", 'buddypress'),
336
  4 => __("No file was uploaded", 'buddypress'),
337
  6 => __("Missing a temporary folder", 'buddypress')
@@ -343,7 +412,7 @@ function bp_core_avatar_handle_upload( $file, $upload_dir_filter ) {
343
  }
344
 
345
  if ( !bp_core_check_avatar_size( $file ) ) {
346
- bp_core_add_message( sprintf( __( 'The file you uploaded is too big. Please upload a file under %s', 'buddypress'), size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE) ), 'error' );
347
  return false;
348
  }
349
 
@@ -352,60 +421,83 @@ function bp_core_avatar_handle_upload( $file, $upload_dir_filter ) {
352
  return false;
353
  }
354
 
355
- /* Filter the upload location */
356
  add_filter( 'upload_dir', $upload_dir_filter, 10, 0 );
357
 
358
  $bp->avatar_admin->original = wp_handle_upload( $file['file'], array( 'action'=> 'bp_avatar_upload' ) );
359
 
360
- /* Move the file to the correct upload location. */
361
  if ( !empty( $bp->avatar_admin->original['error'] ) ) {
362
  bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $bp->avatar_admin->original['error'] ), 'error' );
363
  return false;
364
  }
365
 
366
- /* Get image size */
367
  $size = @getimagesize( $bp->avatar_admin->original['file'] );
368
 
369
- /* Check image size and shrink if too large */
370
- if ( $size[0] > BP_AVATAR_ORIGINAL_MAX_WIDTH ) {
371
- $thumb = wp_create_thumbnail( $bp->avatar_admin->original['file'], BP_AVATAR_ORIGINAL_MAX_WIDTH );
372
 
373
- /* Check for thumbnail creation errors */
374
  if ( is_wp_error( $thumb ) ) {
375
  bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $thumb->get_error_message() ), 'error' );
376
  return false;
377
  }
378
 
379
- /* Thumbnail is good so proceed */
380
  $bp->avatar_admin->resized = $thumb;
381
  }
382
 
383
- /* We only want to handle one image after resize. */
384
  if ( empty( $bp->avatar_admin->resized ) )
385
- $bp->avatar_admin->image->dir = str_replace( BP_AVATAR_UPLOAD_PATH, '', $bp->avatar_admin->original['file'] );
386
  else {
387
- $bp->avatar_admin->image->dir = str_replace( BP_AVATAR_UPLOAD_PATH, '', $bp->avatar_admin->resized );
388
  @unlink( $bp->avatar_admin->original['file'] );
389
  }
390
 
391
- /* Set the url value for the image */
392
- $bp->avatar_admin->image->url = BP_AVATAR_URL . $bp->avatar_admin->image->dir;
 
 
 
 
 
 
393
 
394
  return true;
395
  }
396
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
397
  function bp_core_avatar_handle_crop( $args = '' ) {
398
  global $bp;
399
 
400
  $defaults = array(
401
- 'object' => 'user',
402
- 'avatar_dir' => 'avatars',
403
- 'item_id' => false,
404
  'original_file' => false,
405
- 'crop_w' => BP_AVATAR_FULL_WIDTH,
406
- 'crop_h' => BP_AVATAR_FULL_HEIGHT,
407
- 'crop_x' => 0,
408
- 'crop_y' => 0
409
  );
410
 
411
  $r = wp_parse_args( $args, $defaults );
@@ -422,7 +514,7 @@ function bp_core_avatar_handle_crop( $args = '' ) {
422
  if ( !$original_file )
423
  return false;
424
 
425
- $original_file = BP_AVATAR_UPLOAD_PATH . $original_file;
426
 
427
  if ( !file_exists( $original_file ) )
428
  return false;
@@ -430,7 +522,7 @@ function bp_core_avatar_handle_crop( $args = '' ) {
430
  if ( !$item_id )
431
  $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', dirname( $original_file ), $item_id, $object, $avatar_dir );
432
  else
433
- $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', BP_AVATAR_UPLOAD_PATH . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
434
 
435
  if ( !file_exists( $avatar_folder_dir ) )
436
  return false;
@@ -438,25 +530,25 @@ function bp_core_avatar_handle_crop( $args = '' ) {
438
  require_once( ABSPATH . '/wp-admin/includes/image.php' );
439
  require_once( ABSPATH . '/wp-admin/includes/file.php' );
440
 
441
- /* Delete the existing avatar files for the object */
442
  bp_core_delete_existing_avatar( array( 'object' => $object, 'avatar_path' => $avatar_folder_dir ) );
443
 
444
- /* Make sure we at least have a width and height for cropping */
445
  if ( !(int)$crop_w )
446
- $crop_w = BP_AVATAR_FULL_WIDTH;
447
 
448
  if ( !(int)$crop_h )
449
- $crop_h = BP_AVATAR_FULL_HEIGHT;
450
 
451
- /* Set the full and thumb filenames */
452
- $full_filename = wp_hash( $original_file . time() ) . '-bpfull.jpg';
453
  $thumb_filename = wp_hash( $original_file . time() ) . '-bpthumb.jpg';
454
 
455
- /* Crop the image */
456
- $full_cropped = wp_crop_image( $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, BP_AVATAR_FULL_WIDTH, BP_AVATAR_FULL_HEIGHT, false, $avatar_folder_dir . '/' . $full_filename );
457
- $thumb_cropped = wp_crop_image( $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, BP_AVATAR_THUMB_WIDTH, BP_AVATAR_THUMB_HEIGHT, false, $avatar_folder_dir . '/' . $thumb_filename );
458
 
459
- /* Remove the original */
460
  @unlink( $original_file );
461
 
462
  return true;
@@ -476,13 +568,13 @@ function bp_core_avatar_handle_crop( $args = '' ) {
476
  * @param string $alt Alternate text to use in image tag. Defaults to blank
477
  * @return <type>
478
  */
479
- function bp_core_fetch_avatar_filter( $avatar, $user, $size, $default, $alt ) {
480
  global $pagenow;
481
-
482
  // Do not filter if inside WordPress options page
483
  if ( 'options-discussion.php' == $pagenow )
484
  return $avatar;
485
-
486
  // If passed an object, assume $user->user_id
487
  if ( is_object( $user ) )
488
  $id = $user->user_id;
@@ -499,6 +591,9 @@ function bp_core_fetch_avatar_filter( $avatar, $user, $size, $default, $alt ) {
499
  if ( empty( $id ) )
500
  return !empty( $avatar ) ? $avatar : $default;
501
 
 
 
 
502
  // Let BuddyPress handle the fetching of the avatar
503
  $bp_avatar = bp_core_fetch_avatar( array( 'item_id' => $id, 'width' => $size, 'height' => $size, 'alt' => $alt ) );
504
 
@@ -507,22 +602,42 @@ function bp_core_fetch_avatar_filter( $avatar, $user, $size, $default, $alt ) {
507
  }
508
  add_filter( 'get_avatar', 'bp_core_fetch_avatar_filter', 10, 5 );
509
 
510
- function bp_core_check_avatar_upload($file) {
511
- if ( $file['error'] )
 
 
 
 
 
 
512
  return false;
513
 
514
  return true;
515
  }
516
 
517
- function bp_core_check_avatar_size($file) {
518
- if ( $file['file']['size'] > BP_AVATAR_ORIGINAL_MAX_FILESIZE )
 
 
 
 
 
 
519
  return false;
520
 
521
  return true;
522
  }
523
 
 
 
 
 
 
 
 
 
524
  function bp_core_check_avatar_type($file) {
525
- if ( ( !empty( $file['file']['type'] ) && !preg_match('/(jpe?g|gif|png)$/', $file['file']['type'] ) ) || !preg_match( '/(jpe?g|gif|png)$/', $file['file']['name'] ) )
526
  return false;
527
 
528
  return true;
@@ -533,21 +648,41 @@ function bp_core_check_avatar_type($file) {
533
  *
534
  * Returns the absolute upload path for the WP installation
535
  *
536
- * @global object $current_blog Current blog information
537
  * @uses wp_upload_dir To get upload directory info
538
  * @return string Absolute path to WP upload directory
539
  */
540
  function bp_core_avatar_upload_path() {
541
- global $current_blog;
542
-
543
- // Get upload directory information from current site
544
- $upload_dir = wp_upload_dir();
545
-
546
- // If multisite, and current blog does not match root blog, make adjustments
547
- if ( bp_core_is_multisite() && BP_ROOT_BLOG != $current_blog->blog_id )
548
- $upload_dir['basedir'] = get_blog_option( BP_ROOT_BLOG, 'upload_path' );
549
-
550
- return apply_filters( 'bp_core_avatar_upload_path', $upload_dir['basedir'] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
551
  }
552
 
553
  /**
@@ -555,21 +690,164 @@ function bp_core_avatar_upload_path() {
555
  *
556
  * Returns the raw base URL for root site upload location
557
  *
558
- * @global object $current_blog Current blog information
559
  * @uses wp_upload_dir To get upload directory info
560
  * @return string Full URL to current upload location
561
  */
562
  function bp_core_avatar_url() {
563
- global $current_blog;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
564
 
565
- // Get upload directory information from current site
566
- $upload_dir = wp_upload_dir();
 
 
 
 
 
 
 
 
 
567
 
568
- // If multisite, and current blog does not match root blog, make adjustments
569
- if ( bp_core_is_multisite() && BP_ROOT_BLOG != $current_blog->blog_id )
570
- $upload_dir['baseurl'] = trailingslashit( get_blog_option( BP_ROOT_BLOG, 'home' ) ) . get_blog_option( BP_ROOT_BLOG, 'upload_path' );
 
 
 
 
 
 
 
 
571
 
572
- return apply_filters( 'bp_core_avatar_url', $upload_dir['baseurl'] );
 
 
 
 
 
 
 
 
 
573
  }
574
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
575
  ?>
1
  <?php
2
+ /**
3
+ * BuddyPress Avatars
4
+ *
5
+ * Based on contributions from: Beau Lebens - http://www.dentedreality.com.au/
6
+ * Modified for BuddyPress by: Andy Peatling - http://apeatling.wordpress.com/
7
+ */
8
+
9
+ // Exit if accessed directly
10
+ if ( !defined( 'ABSPATH' ) ) exit;
11
 
12
  /***
13
  * Set up the constants we need for avatar support
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
  }
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' );
72
 
73
  /**
74
  * bp_core_fetch_avatar()
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
83
  */
85
  global $bp, $current_blog;
86
 
87
  // Set a few default variables
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(
95
+ 'item_id' => false,
96
+ 'object' => $def_object, // user/group/blog/custom type (if you use filters)
97
+ 'type' => $def_type, // thumb or full
98
+ 'avatar_dir' => false, // Specify a custom avatar directory for your object
99
+ 'width' => false, // Custom width (int)
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 />
107
+ 'title' => '' // Custom <img> title (string)
108
  );
109
 
110
  // Compare defaults to passed and extract
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}'";
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.
187
  * Set the file names to search for, to select the full size
188
  * or thumbnail image.
189
  */
190
+ $avatar_size = ( 'full' == $type ) ? '-bpfull' : '-bpthumb';
191
+ $legacy_user_avatar_name = ( 'full' == $type ) ? '-avatar2' : '-avatar1';
192
  $legacy_group_avatar_name = ( 'full' == $type ) ? '-groupavatar-full' : '-groupavatar-thumb';
193
 
194
  // Check for directory
236
  closedir( $av_dir );
237
 
238
  // If we found a locally uploaded avatar
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
246
  } else {
252
  // If no avatars could be found, try to display a gravatar
253
 
254
  // Skips gravatar check if $no_grav is passed
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
 
275
  if ( 'user' == $object ) {
276
  $email = bp_core_get_user_email( $item_id );
277
  } else if ( 'group' == $object || 'blog' == $object ) {
278
+ $email = "{$item_id}-{$object}@{bp_get_root_domain()}";
279
  }
280
  }
281
 
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 );
301
  }
302
 
303
+ /**
304
+ * Delete an existing avatar
305
+ *
306
+ * Accepted values for $args are:
307
+ * item_id - item id which relates to the object type.
308
+ * object - the objetc type user, group, blog, etc.
309
+ * avatar_dir - The directory where the avatars to be uploaded.
310
+ *
311
+ * @global object $bp BuddyPress global settings
312
+ * @param mixed $args
313
+ * @return bool Success/failure
314
+ */
315
  function bp_core_delete_existing_avatar( $args = '' ) {
316
  global $bp;
317
 
318
  $defaults = array(
319
+ 'item_id' => false,
320
+ 'object' => 'user', // user OR group OR blog OR custom type (if you use filters)
321
  'avatar_dir' => false
322
  );
323
 
350
  if ( !$avatar_dir ) return false;
351
  }
352
 
353
+ $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', bp_core_avatar_upload_path() . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
354
 
355
  if ( !file_exists( $avatar_folder_dir ) )
356
  return false;
370
  return true;
371
  }
372
 
373
+ /**
374
+ * Handles avatar uploading.
375
+ *
376
+ * The functions starts off by checking that the file has been uploaded properly using bp_core_check_avatar_upload().
377
+ * It then checks that the file size is within limits, and that it has an accepted file extension (jpg, gif, png).
378
+ * If everything checks out, crop the image and move it to its real location.
379
+ *
380
+ * @global object $bp BuddyPress global settings
381
+ * @param array $file The appropriate entry the from $_FILES superglobal.
382
+ * @param string $upload_dir_filter A filter to be applied to upload_dir
383
+ * @return bool Success/failure
384
+ * @see bp_core_check_avatar_upload()
385
+ * @see bp_core_check_avatar_type()
386
+ */
387
  function bp_core_avatar_handle_upload( $file, $upload_dir_filter ) {
388
  global $bp;
389
 
399
 
400
  $uploadErrors = array(
401
  0 => __("There is no error, the file uploaded with success", 'buddypress'),
402
+ 1 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format( bp_core_avatar_original_max_filesize() ),
403
+ 2 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format( bp_core_avatar_original_max_filesize() ),
404
  3 => __("The uploaded file was only partially uploaded", 'buddypress'),
405
  4 => __("No file was uploaded", 'buddypress'),
406
  6 => __("Missing a temporary folder", 'buddypress')
412
  }
413
 
414
  if ( !bp_core_check_avatar_size( $file ) ) {
415
+ bp_core_add_message( sprintf( __( 'The file you uploaded is too big. Please upload a file under %s', 'buddypress'), size_format( bp_core_avatar_original_max_filesize() ) ), 'error' );
416
  return false;
417
  }
418
 
421
  return false;
422
  }
423
 
424
+ // Filter the upload location
425
  add_filter( 'upload_dir', $upload_dir_filter, 10, 0 );
426
 
427
  $bp->avatar_admin->original = wp_handle_upload( $file['file'], array( 'action'=> 'bp_avatar_upload' ) );
428
 
429
+ // Move the file to the correct upload location.
430
  if ( !empty( $bp->avatar_admin->original['error'] ) ) {
431
  bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $bp->avatar_admin->original['error'] ), 'error' );
432
  return false;
433
  }
434
 
435
+ // Get image size
436
  $size = @getimagesize( $bp->avatar_admin->original['file'] );
437
 
438
+ // Check image size and shrink if too large
439
+ if ( $size[0] > bp_core_avatar_original_max_width() ) {
440
+ $thumb = wp_create_thumbnail( $bp->avatar_admin->original['file'], bp_core_avatar_original_max_width() );
441
 
442
+ // Check for thumbnail creation errors
443
  if ( is_wp_error( $thumb ) ) {
444
  bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $thumb->get_error_message() ), 'error' );
445
  return false;
446
  }
447
 
448
+ // Thumbnail is good so proceed
449
  $bp->avatar_admin->resized = $thumb;
450
  }
451
 
452
+ // We only want to handle one image after resize.
453
  if ( empty( $bp->avatar_admin->resized ) )
454
+ $bp->avatar_admin->image->dir = str_replace( bp_core_avatar_upload_path(), '', $bp->avatar_admin->original['file'] );
455
  else {
456
+ $bp->avatar_admin->image->dir = str_replace( bp_core_avatar_upload_path(), '', $bp->avatar_admin->resized );
457
  @unlink( $bp->avatar_admin->original['file'] );
458
  }
459
 
460
+ // Check for WP_Error on what should be an image
461
+ if ( is_wp_error( $bp->avatar_admin->image->dir ) ) {
462
+ bp_core_add_message( sprintf( __( 'Upload failed! Error was: %s', 'buddypress' ), $bp->avatar_admin->image->dir->get_error_message() ), 'error' );
463
+ return false;
464
+ }
465
+
466
+ // Set the url value for the image
467
+ $bp->avatar_admin->image->url = bp_core_avatar_url() . $bp->avatar_admin->image->dir;
468
 
469
  return true;
470
  }
471
 
472
+ /**
473
+ * Crop an uploaded avatar
474
+ *
475
+ * $args has the following parameters:
476
+ * object - What component the avatar is for, e.g. "user"
477
+ * avatar_dir The absolute path to the avatar
478
+ * item_id - Item ID
479
+ * original_file - The absolute path to the original avatar file
480
+ * crop_w - Crop width
481
+ * crop_h - Crop height
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',
494
+ 'avatar_dir' => 'avatars',
495
+ 'item_id' => false,
496
  'original_file' => false,
497
+ 'crop_w' => bp_core_avatar_full_width(),
498
+ 'crop_h' => bp_core_avatar_full_height(),
499
+ 'crop_x' => 0,
500
+ 'crop_y' => 0
501
  );
502
 
503
  $r = wp_parse_args( $args, $defaults );
514
  if ( !$original_file )
515
  return false;
516
 
517
+ $original_file = bp_core_avatar_upload_path() . $original_file;
518
 
519
  if ( !file_exists( $original_file ) )
520
  return false;
522
  if ( !$item_id )
523
  $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', dirname( $original_file ), $item_id, $object, $avatar_dir );
524
  else
525
+ $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', bp_core_avatar_upload_path() . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
526
 
527
  if ( !file_exists( $avatar_folder_dir ) )
528
  return false;
530
  require_once( ABSPATH . '/wp-admin/includes/image.php' );
531
  require_once( ABSPATH . '/wp-admin/includes/file.php' );
532
 
533
+ // Delete the existing avatar files for the object
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
544
+ $full_filename = wp_hash( $original_file . time() ) . '-bpfull.jpg';
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 );
553
 
554
  return true;
568
  * @param string $alt Alternate text to use in image tag. Defaults to blank
569
  * @return <type>
570
  */
571
+ function bp_core_fetch_avatar_filter( $avatar, $user, $size, $default, $alt = '' ) {
572
  global $pagenow;
573
+
574
  // Do not filter if inside WordPress options page
575
  if ( 'options-discussion.php' == $pagenow )
576
  return $avatar;
577
+
578
  // If passed an object, assume $user->user_id
579
  if ( is_object( $user ) )
580
  $id = $user->user_id;
591
  if ( empty( $id ) )
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 ) );
599
 
602
  }
603
  add_filter( 'get_avatar', 'bp_core_fetch_avatar_filter', 10, 5 );
604
 
605
+ /**
606
+ * Has the current avatar upload generated an error?
607
+ *
608
+ * @param array $file
609
+ * @return bool
610
+ */
611
+ function bp_core_check_avatar_upload( $file ) {
612
+ if ( isset( $file['error'] ) && $file['error'] )
613
  return false;
614
 
615
  return true;
616
  }
617
 
618
+ /**
619
+ * Is the file size of the current avatar upload permitted?
620
+ *
621
+ * @param array $file
622
+ * @return bool
623
+ */
624
+ function bp_core_check_avatar_size( $file ) {
625
+ if ( $file['file']['size'] > bp_core_avatar_original_max_filesize() )
626
  return false;
627
 
628
  return true;
629
  }
630
 
631
+ /**
632
+ * Does the current avatar upload have an allowed file type?
633
+ *
634
+ * Permitted file types are JPG, GIF and PNG.
635
+ *
636
+ * @param string $file
637
+ * @return bool
638
+ */
639
  function bp_core_check_avatar_type($file) {
640
+ if ( ( !empty( $file['file']['type'] ) && !preg_match('/(jpe?g|gif|png)$/i', $file['file']['type'] ) ) || !preg_match( '/(jpe?g|gif|png)$/i', $file['file']['name'] ) )
641
  return false;
642
 
643
  return true;
648
  *
649
  * Returns the absolute upload path for the WP installation
650
  *
 
651
  * @uses wp_upload_dir To get upload directory info
652
  * @return string Absolute path to WP upload directory
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;
660
+ } else {
661
+ // If this value has been set in a constant, just use that
662
+ if ( defined( 'BP_AVATAR_UPLOAD_PATH' ) ) {
663
+ $basedir = BP_AVATAR_UPLOAD_PATH;
664
+ } else {
665
+ // Get upload directory information from current site
666
+ $upload_dir = wp_upload_dir();
667
+
668
+ // Directory does not exist and cannot be created
669
+ if ( !empty( $upload_dir['error'] ) ) {
670
+ $basedir = '';
671
+
672
+ } else {
673
+ $basedir = $upload_dir['basedir'];
674
+
675
+ // If multisite, and current blog does not match root blog, make adjustments
676
+ if ( is_multisite() && bp_get_root_blog_id() != get_current_blog_id() )
677
+ $basedir = get_blog_option( bp_get_root_blog_id(), 'upload_path' );
678
+ }
679
+ }
680
+
681
+ // Stash in $bp for later use
682
+ $bp->avatar->upload_path = $basedir;
683
+ }
684
+
685
+ return apply_filters( 'bp_core_avatar_upload_path', $basedir );
686
  }
687
 
688
  /**
690
  *
691
  * Returns the raw base URL for root site upload location
692
  *
 
693
  * @uses wp_upload_dir To get upload directory info
694
  * @return string Full URL to current upload location
695
  */
696
  function bp_core_avatar_url() {
697
+ global $bp;
698
+
699
+ // See if the value has already been calculated and stashed in the $bp global
700
+ if ( isset( $bp->avatar->url ) ) {
701
+ $baseurl = $bp->avatar->url;
702
+ } else {
703
+ // If this value has been set in a constant, just use that
704
+ if ( defined( 'BP_AVATAR_URL' ) ) {
705
+ $baseurl = BP_AVATAR_URL;
706
+ } else {
707
+ // Get upload directory information from current site
708
+ $upload_dir = wp_upload_dir();
709
+
710
+ // Directory does not exist and cannot be created
711
+ if ( !empty( $upload_dir['error'] ) ) {
712
+ $baseurl = '';
713
+
714
+ } else {
715
+ $baseurl = $upload_dir['baseurl'];
716
+
717
+ // If multisite, and current blog does not match root blog, make adjustments
718
+ if ( is_multisite() && bp_get_root_blog_id() != get_current_blog_id() )
719
+ $baseurl = trailingslashit( get_blog_option( bp_get_root_blog_id(), 'home' ) ) . get_blog_option( bp_get_root_blog_id(), 'upload_path' );
720
+ }
721
+ }
722
+
723
+ // Stash in $bp for later use
724
+ $bp->avatar->url = $baseurl;
725
+ }
726
+
727
+ return apply_filters( 'bp_core_avatar_url', $baseurl );
728
+ }
729
+
730
+ /**
731
+ * Utility function for fetching an avatar dimension setting
732
+ *
733
+ * @package BuddyPress
734
+ * @since 1.5
735
+ *
736
+ * @param str $type 'thumb' for thumbs, otherwise full
737
+ * @param str $h_or_w 'height' for height, otherwise width
738
+ * @return int $dim The dimension
739
+ */
740
+ function bp_core_avatar_dimension( $type = 'thumb', $h_or_w = 'height' ) {
741
+ global $bp;
742
+
743
+ $dim = isset( $bp->avatar->{$type}->{$h_or_w} ) ? (int)$bp->avatar->{$type}->{$h_or_w} : false;
744
+
745
+ return apply_filters( 'bp_core_avatar_dimension', $dim, $type, $h_or_w );
746
+ }
747
 
748
+ /**
749
+ * Get the avatar thumb width setting
750
+ *
751
+ * @package BuddyPress
752
+ * @since 1.5
753
+ *
754
+ * @return int The thumb width
755
+ */
756
+ function bp_core_avatar_thumb_width() {
757
+ return apply_filters( 'bp_core_avatar_thumb_width', bp_core_avatar_dimension( 'thumb', 'width' ) );
758
+ }
759
 
760
+ /**
761
+ * Get the avatar thumb height setting
762
+ *
763
+ * @package BuddyPress
764
+ * @since 1.5
765
+ *
766
+ * @return int The thumb height
767
+ */
768
+ function bp_core_avatar_thumb_height() {
769
+ return apply_filters( 'bp_core_avatar_thumb_height', bp_core_avatar_dimension( 'thumb', 'height' ) );
770
+ }
771
 
772
+ /**
773
+ * Get the avatar full width setting
774
+ *
775
+ * @package BuddyPress
776
+ * @since 1.5
777
+ *
778
+ * @return int The full width
779
+ */
780
+ function bp_core_avatar_full_width() {
781
+ return apply_filters( 'bp_core_avatar_full_width', bp_core_avatar_dimension( 'full', 'width' ) );
782
  }
783
 
784
+ /**
785
+ * Get the avatar full height setting
786
+ *
787
+ * @package BuddyPress
788
+ * @since 1.5
789
+ *
790
+ * @return int The full height
791
+ */
792
+ function bp_core_avatar_full_height() {
793
+ return apply_filters( 'bp_core_avatar_full_height', bp_core_avatar_dimension( 'full', 'height' ) );
794
+ }
795
+
796
+ /**
797
+ * Get the max width for original avatar uploads
798
+ *
799
+ * @package BuddyPress
800
+ * @since 1.5
801
+ *
802
+ * @return int The width
803
+ */
804
+ function bp_core_avatar_original_max_width() {
805
+ global $bp;
806
+
807
+ return apply_filters( 'bp_core_avatar_original_max_width', (int)$bp->avatar->original_max_width );
808
+ }
809
+
810
+ /**
811
+ * Get the max filesize for original avatar uploads
812
+ *
813
+ * @package BuddyPress
814
+ * @since 1.5
815
+ *
816
+ * @return int The filesize
817
+ */
818
+ function bp_core_avatar_original_max_filesize() {
819
+ global $bp;
820
+
821
+ return apply_filters( 'bp_core_avatar_original_max_filesize', (int)$bp->avatar->original_max_filesize );
822
+ }
823
+
824
+ /**
825
+ * Get the default avatar
826
+ *
827
+ * @package BuddyPress
828
+ * @since 1.5
829
+ *
830
+ * @return int The URL of the default avatar
831
+ */
832
+ function bp_core_avatar_default() {
833
+ global $bp;
834
+
835
+ return apply_filters( 'bp_core_avatar_default', $bp->avatar->full->default );
836
+ }
837
+
838
+ /**
839
+ * Get the default avatar thumb
840
+ *
841
+ * @package BuddyPress
842
+ * @since 1.5
843
+ *
844
+ * @return int The URL of the default avatar thumb
845
+ */
846
+ function bp_core_avatar_default_thumb() {
847
+ global $bp;
848
+
849
+ return apply_filters( 'bp_core_avatar_thumb', $bp->avatar->thumb->default );
850
+ }
851
+
852
+
853
  ?>
bp-core/bp-core-buddybar.php ADDED
@@ -0,0 +1,627 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Exit if accessed directly
3
+ if ( !defined( 'ABSPATH' ) ) exit;
4
+
5
+ /**
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;
13
+
14
+ $defaults = array(
15
+ 'name' => false, // Display name for the nav item
16
+ 'slug' => false, // URL slug for the nav item
17
+ 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item
18
+ 'show_for_displayed_user' => true, // When viewing another user does this nav item show up?
19
+ 'site_admin_only' => false, // Can only site admins see this nav item?
20
+ 'position' => 99, // Index of where this nav item should be positioned
21
+ 'screen_function' => false, // The name of the function to run when clicked
22
+ 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked
23
+ );
24
+
25
+ $r = wp_parse_args( $args, $defaults );
26
+ extract( $r, EXTR_SKIP );
27
+
28
+ // If we don't have the required info we need, don't create this subnav item
29
+ if ( empty( $name ) || empty( $slug ) )
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 ) )
37
+ $item_css_id = $slug;
38
+
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.
61
+ */
62
+ if ( ( -1 != $position ) && bp_is_root_component( $slug ) && !bp_displayed_user_id() )
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 );
87
+ }
88
+
89
+ /**
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;
97
+
98
+ $defaults = array(
99
+ 'parent_slug' => false, // Slug of the parent
100
+ 'screen_function' => false, // The name of the function to run when clicked
101
+ 'subnav_slug' => false // The slug of the subnav item to select when clicked
102
+ );
103
+
104
+ $r = wp_parse_args( $args, $defaults );
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
+ /**
128
+ * We can only sort nav items by their position integer at a later point in time, once all
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;
136
+
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']++;
147
+ } while ( !empty( $temp[$nav_item['position']] ) );
148
+
149
+ $temp[$nav_item['position']] = $nav_item;
150
+ }
151
+ }
152
+
153
+ ksort( $temp );
154
+ $bp->bp_nav = &$temp;
155
+ }
156
+ add_action( 'wp_head', 'bp_core_sort_nav_items' );
157
+ add_action( 'admin_head', 'bp_core_sort_nav_items' );
158
+
159
+ /**
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;
167
+
168
+ $defaults = array(
169
+ 'name' => false, // Display name for the nav item
170
+ 'slug' => false, // URL slug for the nav item
171
+ 'parent_slug' => false, // URL slug of the parent nav item
172
+ 'parent_url' => false, // URL of the parent item
173
+ 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item
174
+ 'user_has_access' => true, // Can the logged in user see this nav item?
175
+ 'site_admin_only' => false, // Can only site admins see this nav item?
176
+ 'position' => 90, // Index of where this nav item should be positioned
177
+ 'screen_function' => false, // The name of the function to run when clicked
178
+ 'link' => '' // The link for the subnav item; optional, not usually required.
179
+ );
180
+
181
+ $r = wp_parse_args( $args, $defaults );
182
+ extract( $r, EXTR_SKIP );
183
+
184
+ // If we don't have the required info we need, don't create this subnav item
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 ) )
196
+ $item_css_id = $slug;
197
+
198
+ $bp->bp_options_nav[$parent_slug][$slug] = array(
199
+ 'name' => $name,
200
+ 'link' => trailingslashit( $link ),
201
+ 'slug' => $slug,
202
+ 'css_id' => $item_css_id,
203
+ 'position' => $position,
204
+ 'user_has_access' => $user_has_access,
205
+ 'screen_function' => &$screen_function
206
+ );
207
+
208
+ /**
209
+ * The last step is to hook the screen function for the added subnav item. But this only
210
+ * needs to be done if this subnav item is the current view, and the user has access to the
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
221
+ * parent nav item in $bp->bp_nav). This condition only arises when viewing a
222
+ * user, since groups should always have an action set.
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
+ }
253
+ }
254
+ }
255
+
256
+ function bp_core_sort_subnav_items() {
257
+ global $bp;
258
+
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 {
270
+ // increase numbers here to fit new items in.
271
+ do {
272
+ $subnav_item['position']++;
273
+ } while ( !empty( $temp[$subnav_item['position']] ) );
274
+
275
+ $temp[$subnav_item['position']] = $subnav_item;
276
+ }
277
+ }
278
+ ksort( $temp );
279
+ $bp->bp_options_nav[$parent_slug] = &$temp;
280
+ unset( $temp );
281
+ }
282
+ }
283
+ add_action( 'wp_head', 'bp_core_sort_subnav_items' );
284
+ add_action( 'admin_head', 'bp_core_sort_subnav_items' );
285
+
286
+ /**
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
294
+ */
295
+ function bp_nav_item_has_subnav( $nav_item = '' ) {
296
+ global $bp;
297
+
298
+ if ( !$nav_item )
299
+ $nav_item = bp_current_component();
300
+
301
+ $has_subnav = isset( $bp->bp_options_nav[$nav_item] ) && count( $bp->bp_options_nav[$nav_item] ) > 0;
302
+
303
+ return apply_filters( 'bp_nav_item_has_subnav', $has_subnav, $nav_item );
304
+ }
305
+
306
+ /**
307
+ * Removes a navigation item from the sub navigation array used in BuddyPress themes.
308
+ *
309
+ * @package BuddyPress Core
310
+ * @param $parent_id The id of the parent navigation item.
311
+ * @param $slug The slug of the sub navigation item.
312
+ */
313
+ function bp_core_remove_nav_item( $parent_id ) {
314
+ global $bp;
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
+
331
+ unset( $bp->bp_nav[$parent_id] );
332
+ }
333
+
334
+ /**
335
+ * Removes a navigation item from the sub navigation array used in BuddyPress themes.
336
+ *
337
+ * @package BuddyPress Core
338
+ * @param $parent_id The id of the parent navigation item.
339
+ * @param $slug The slug of the sub navigation item.
340
+ */
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] );
354
+
355
+ if ( isset( $bp->bp_options_nav[$parent_id] ) && !count( $bp->bp_options_nav[$parent_id] ) )
356
+ unset($bp->bp_options_nav[$parent_id]);
357
+ }
358
+
359
+ /**
360
+ * Clear the subnav items for a specific nav item.
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;
368
+
369
+ unset( $bp->bp_options_nav[$parent_slug] );
370
+ }
371
+
372
+ /** Template functions ********************************************************/
373
+
374
+ function bp_core_admin_bar() {
375
+ global $bp;
376
+
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;
384
+
385
+ echo '<div id="wp-admin-bar"><div class="padder">';
386
+
387
+ // **** Do bp-adminbar-logo Actions ********
388
+ do_action( 'bp_adminbar_logo' );
389
+
390
+ echo '<ul class="main-nav">';
391
+
392
+ // **** Do bp-adminbar-menus Actions ********
393
+ do_action( 'bp_adminbar_menus' );
394
+
395
+ echo '</ul>';
396
+ echo "</div></div><!-- #wp-admin-bar -->\n\n";
397
+
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() )
419
+ echo '<li class="bp-signup no-arrow"><a href="' . bp_get_signup_page(false) . '">' . __( 'Sign Up', 'buddypress' ) . '</a></li>';
420
+ }
421
+
422
+
423
+ // **** "My Account" Menu ******
424
+ function bp_adminbar_account_menu() {
425
+ global $bp;
426
+
427
+ if ( !$bp->bp_nav || !is_user_logged_in() )
428
+ return false;
429
+
430
+ echo '<li id="bp-adminbar-account-menu"><a href="' . bp_loggedin_user_domain() . '">';
431
+ echo __( 'My Account', 'buddypress' ) . '</a>';
432
+ echo '<ul>';
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'] )
440
+ continue;
441
+
442
+ echo '<li' . $alt . '>';
443
+ echo '<a id="bp-admin-' . $nav_item['css_id'] . '" href="' . $nav_item['link'] . '">' . $nav_item['name'] . '</a>';
444
+
445
+ if ( isset( $bp->bp_options_nav[$nav_item['slug']] ) && is_array( $bp->bp_options_nav[$nav_item['slug']] ) ) {
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'] );
458
+
459
+ $alt = ( 0 == $sub_counter % 2 ) ? ' class="alt"' : '';
460
+ echo '<li' . $alt . '><a id="bp-admin-' . $subnav_item['css_id'] . '" href="' . $link . '">' . $name . '</a></li>';
461
+ $sub_counter++;
462
+ }
463
+ echo '</ul>';
464
+ }
465
+
466
+ echo '</li>';
467
+
468
+ $counter++;
469
+ }
470
+
471
+ $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
472
+
473
+ echo '<li' . $alt . '><a id="bp-admin-logout" class="logout" href="' . wp_logout_url( home_url() ) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';
474
+ echo '</ul>';
475
+ echo '</li>';
476
+ }
477
+
478
+ function bp_adminbar_thisblog_menu() {
479
+ if ( current_user_can( 'edit_posts' ) ) {
480
+ echo '<li id="bp-adminbar-thisblog-menu"><a href="' . admin_url() . '">';
481
+ _e( 'Dashboard', 'buddypress' );
482
+ echo '</a>';
483
+ echo '<ul>';
484
+
485
+ echo '<li class="alt"><a href="' . admin_url() . 'post-new.php">' . __( 'New Post', 'buddypress' ) . '</a></li>';
486
+ echo '<li><a href="' . admin_url() . 'edit.php">' . __( 'Manage Posts', 'buddypress' ) . '</a></li>';
487
+ echo '<li class="alt"><a href="' . admin_url() . 'edit-comments.php">' . __( 'Manage Comments', 'buddypress' ) . '</a></li>';
488
+
489
+ do_action( 'bp_adminbar_thisblog_items' );
490
+
491
+ echo '</ul>';
492
+ echo '</li>';
493
+ }
494
+ }
495
+
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>
503
+ <ul class="random-list">
504
+ <li><a href="<?php echo trailingslashit( bp_get_root_domain() . '/' . bp_get_members_root_slug() ) . '?random-member' ?>" rel="nofollow"><?php _e( 'Random Member', 'buddypress' ) ?></a></li>
505
+
506
+ <?php if ( bp_is_active( 'groups' ) ) : ?>
507
+
508
+ <li class="alt"><a href="<?php echo trailingslashit( bp_get_root_domain() . '/' . bp_get_groups_root_slug() ) . '?random-group' ?>" rel="nofollow"><?php _e( 'Random Group', 'buddypress' ) ?></a></li>
509
+
510
+ <?php endif; ?>
511
+
512
+ <?php if ( is_multisite() && bp_is_active( 'blogs' ) ) : ?>
513
+
514
+ <li><a href="<?php echo trailingslashit( bp_get_root_domain() . '/' . bp_get_blogs_root_slug() ) . '?random-blog' ?>" rel="nofollow"><?php _e( 'Random Site', 'buddypress' ) ?></a></li>
515
+
516
+ <?php endif; ?>
517
+
518
+ <?php do_action( 'bp_adminbar_random_menu' ) ?>
519
+
520
+ </ul>
521
+ </li>
522
+
523
+ <?php
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 );
542
+ if ( false === $pref )
543
+ return true;
544
+
545
+ return 'true' === $pref;
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()
555
+ * @uses is_user_logged_in()
556
+ * @uses bp_use_wp_admin_bar()
557
+ * @uses show_admin_bar()
558
+ * @uses add_action() To hook 'bp_adminbar_logo' to 'bp_adminbar_logo'
559
+ * @uses add_action() To hook 'bp_adminbar_login_menu' to 'bp_adminbar_menus'
560
+ * @uses add_action() To hook 'bp_adminbar_account_menu' to 'bp_adminbar_menus'
561
+ * @uses add_action() To hook 'bp_adminbar_thisblog_menu' to 'bp_adminbar_menus'
562
+ * @uses add_action() To hook 'bp_adminbar_random_menu' to 'bp_adminbar_menus'
563
+ * @uses add_action() To hook 'bp_core_admin_bar' to 'wp_footer'
564
+ * @uses add_action() To hook 'bp_core_admin_bar' to 'admin_footer'
565
+ */
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
+ }
598
+ }
599
+
600
+ /**
601
+ * Handle the BuddyBar CSS
602
+ */
603
+ function bp_core_load_buddybar_css() {
604
+ if ( bp_use_wp_admin_bar() || ( (int) bp_get_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() ) || ( defined( 'BP_DISABLE_ADMIN_BAR' ) && BP_DISABLE_ADMIN_BAR ) )
605
+ return;
606
+
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 ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
10
+ /**
11
+ * REQUIRES WP-SUPER-CACHE
12
+ *
13
+ * When wp-super-cache is installed this function will clear cached pages
14
+ * so that success/error messages are not cached, or time sensitive content.
15
+ *
16
+ * @package BuddyPress Core
17
+ */
18
+ function bp_core_clear_cache() {
19
+ global $cache_path, $cache_filename;
20
+
21
+ if ( function_exists( 'prune_super_cache' ) ) {
22
+ do_action( 'bp_core_clear_cache' );
23
+ return prune_super_cache( $cache_path, true );
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Add's 'bp' to global group of network wide cachable objects
29
+ *
30
+ * @package BuddyPress Core
31
+ */
32
+ function bp_core_add_global_group() {
33
+ wp_cache_init();
34
+ wp_cache_add_global_groups( array( 'bp' ) );
35
+ }
36
+ add_action( 'bp_loaded', 'bp_core_add_global_group' );
37
+
38
+ /**
39
+ * Clears all cached objects for a user, or a user is part of.
40
+ *
41
+ * @package BuddyPress Core
42
+ */
43
+ function bp_core_clear_user_object_cache( $user_id ) {
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-catchuri.php CHANGED
@@ -1,41 +1,48 @@
1
  <?php
 
 
 
2
  /*
3
  Based on contributions from: Chris Taylor - http://www.stillbreathing.co.uk/
4
  Modified for BuddyPress by: Andy Peatling - http://apeatling.wordpress.com/
5
  */
6
 
7
  /**
8
- * bp_core_set_uri_globals()
9
- *
10
  * Analyzes the URI structure and breaks it down into parts for use in code.
11
  * The idea is that BuddyPress can use complete custom friendly URI's without the
12
  * user having to add new re-write rules.
13
  *
14
  * Future custom components would then be able to use their own custom URI structure.
15
  *
 
 
 
16
  * The URI's are broken down as follows:
17
  * - http:// domain.com / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ...
18
  * - OUTSIDE ROOT: http:// domain.com / sites / buddypress / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ...
19
  *
20
  * Example:
21
  * - http://domain.com/members/andy/profile/edit/group/5/
22
- * - $bp->current_component: string 'profile'
23
  * - $bp->current_action: string 'edit'
24
  * - $bp->action_variables: array ['group', 5]
25
  *
26
- * @package BuddyPress Core
27
  */
28
  function bp_core_set_uri_globals() {
29
- global $current_component, $current_action, $action_variables;
30
- global $displayed_user_id;
31
- global $is_member_page;
32
- global $bp_unfiltered_uri;
33
- global $bp, $current_blog;
 
 
 
 
 
34
 
35
- // Only catch URI's on the root blog if we are not running BP on multiple blogs
36
- if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && bp_core_is_multisite() )
37
- if ( BP_ROOT_BLOG != (int) $current_blog->blog_id )
38
- return false;
39
 
40
  // Ajax or not?
41
  if ( strpos( $_SERVER['REQUEST_URI'], 'wp-load.php' ) )
@@ -43,12 +50,12 @@ function bp_core_set_uri_globals() {
43
  else
44
  $path = esc_url( $_SERVER['REQUEST_URI'] );
45
 
 
46
  $path = apply_filters( 'bp_uri', $path );
47
 
48
  // Take GET variables off the URL to avoid problems,
49
  // they are still registered in the global $_GET variable
50
- $noget = substr( $path, 0, strpos( $path, '?' ) );
51
- if ( $noget != '' )
52
  $path = $noget;
53
 
54
  // Fetch the current URI and explode each part separated by '/' into an array
@@ -59,7 +66,7 @@ function bp_core_set_uri_globals() {
59
  if ( empty( $bp_uri[$key] ) ) unset( $bp_uri[$key] );
60
 
61
  // Running off blog other than root
62
- if ( defined( 'BP_ENABLE_MULTIBLOG' ) || 1 != BP_ROOT_BLOG ) {
63
 
64
  // Any subdirectory names must be removed from $bp_uri.
65
  // This includes two cases: (1) when WP is installed in a subdirectory,
@@ -69,8 +76,9 @@ function bp_core_set_uri_globals() {
69
  foreach( $chunks as $key => $chunk ) {
70
  $bkey = array_search( $chunk, $bp_uri );
71
 
72
- if ( $bkey !== false )
73
  unset( $bp_uri[$bkey] );
 
74
 
75
  $bp_uri = array_values( $bp_uri );
76
  }
@@ -81,221 +89,377 @@ function bp_core_set_uri_globals() {
81
  $component_index = 0;
82
  $action_index = $component_index + 1;
83
 
84
- // If this is a WordPress page, return from the function.
85
- if ( is_page( $bp_uri[$component_index] ) )
86
- return false;
87
-
88
  // Get site path items
89
  $paths = explode( '/', bp_core_get_site_path() );
90
 
91
  // Take empties off the end of path
92
- if ( empty( $paths[count($paths) - 1] ) )
93
  array_pop( $paths );
94
 
95
  // Take empties off the start of path
96
  if ( empty( $paths[0] ) )
97
  array_shift( $paths );
98
 
99
- foreach ( (array)$bp_uri as $key => $uri_chunk )
100
- if ( in_array( $uri_chunk, $paths ))
 
101
  unset( $bp_uri[$key] );
 
 
102
 
103
  // Reset the keys by merging with an empty array
104
- $bp_uri = array_merge( array(), $bp_uri );
 
 
 
 
 
 
 
 
 
 
 
105
  $bp_unfiltered_uri = $bp_uri;
106
 
107
- // If we are under anything with a members slug, set the correct globals
108
- if ( $bp_uri[0] == BP_MEMBERS_SLUG ) {
109
- $is_member_page = true;
110
- $is_root_component = true;
 
 
 
 
 
 
 
 
 
 
 
 
111
  }
112
 
113
- // Catch a member page and set the current member ID
114
- if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) ) {
115
- if ( ( $bp_uri[0] == BP_MEMBERS_SLUG && !empty( $bp_uri[1] ) ) || in_array( 'wp-load.php', $bp_uri ) ) {
116
- // We are within a member page, set up user id globals
117
- if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
118
- $displayed_user_id = bp_core_get_userid( urldecode( $bp_uri[1] ) );
119
- else
120
- $displayed_user_id = bp_core_get_userid_from_nicename( urldecode( $bp_uri[1] ) );
 
 
 
 
 
 
121
 
122
- unset( $bp_uri[0] );
123
- unset( $bp_uri[1] );
 
124
 
125
- // Reset the keys by merging with an empty array
126
- $bp_uri = array_merge( array(), $bp_uri );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  }
128
- } else {
129
- if ( get_userdatabylogin( $bp_uri[0] ) || in_array( 'wp-load.php', $bp_uri ) ) {
130
- $is_member_page = true;
131
- $is_root_component = true;
132
 
133
- // We are within a member page, set up user id globals
134
- if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
135
- $displayed_user_id = bp_core_get_userid( urldecode( $bp_uri[0] ) );
136
- else
137
- $displayed_user_id = bp_core_get_userid_from_nicename( urldecode( $bp_uri[0] ) );
138
 
139
- unset( $bp_uri[0] );
 
 
 
140
 
141
- // Reset the keys by merging with an empty array
142
- $bp_uri = array_merge( array(), $bp_uri );
 
143
  }
144
  }
145
 
146
- if ( !isset( $is_root_component ) )
147
- $is_root_component = in_array( $bp_uri[0], $bp->root_components );
 
 
 
 
 
 
 
 
 
 
 
 
 
148
 
149
- if ( !is_subdomain_install() && !$is_root_component ) {
150
- $component_index++;
151
- $action_index++;
 
152
  }
153
 
154
- // Set the current component
155
- $current_component = $bp_uri[$component_index];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
 
157
  // Set the current action
158
- $current_action = $bp_uri[$action_index];
159
 
160
- // Set the entire URI as the action variables, we will unset the current_component and action in a second
161
- $action_variables = $bp_uri;
 
162
 
163
- // Unset the current_component and action from action_variables
164
- unset( $action_variables[$component_index] );
165
- unset( $action_variables[$action_index] );
166
 
167
  // Remove the username from action variables if this is not a VHOST install
168
- if ( !is_subdomain_install() && !$is_root_component )
169
- array_shift( $action_variables );
 
170
 
171
  // Reset the keys by merging with an empty array
172
- $action_variables = array_merge( array(), $action_variables );
173
  }
174
- add_action( 'bp_loaded', 'bp_core_set_uri_globals', 4 );
175
 
176
  /**
177
- * bp_catch_uri()
178
  *
179
- * Takes either a single page name or array of page names and
180
- * loads the first template file that can be found.
181
  *
182
- * Please don't call this function directly anymore, use: bp_core_load_template()
 
 
 
183
  *
184
  * @package BuddyPress Core
185
- * @global $bp_path BuddyPress global containing the template file names to use.
186
- * @param $pages Template file names to use.
187
- * @uses add_action() Hooks a function on to a specific action
188
  */
189
- function bp_catch_uri( $pages, $skip_blog_check = false ) {
190
- global $bp_path, $bp_skip_blog_check;
191
 
192
- $bp_skip_blog_check = $skip_blog_check;
193
-
194
- $bp_path = $pages;
195
-
196
- if ( !bp_is_blog_page() ) {
197
- remove_action( 'template_redirect', 'redirect_canonical' );
198
- }
199
- add_action( 'template_redirect', 'bp_core_do_catch_uri', 2 );
200
- }
201
 
202
- /**
203
- * bp_core_do_catch_uri()
204
- *
205
- * Loads the first template file found based on the $bp_path global.
206
- *
207
- * @package BuddyPress Core
208
- * @global $bp_path BuddyPress global containing the template file names to use.
209
- */
210
- function bp_core_do_catch_uri() {
211
- global $bp_path, $bp, $wpdb;
212
- global $current_blog, $bp_skip_blog_check;
213
- global $bp_no_status_set;
214
- global $wp_query;
215
-
216
- /* Can be a single template or an array of templates */
217
- $templates = $bp_path;
218
-
219
- /* Don't hijack any URLs on blog pages */
220
- if ( bp_is_blog_page() ) {
221
- if ( !$bp_skip_blog_check )
222
- return false;
223
- } else {
224
- $wp_query->is_home = false;
225
  }
226
 
227
- /* Make sure this is not reported as a 404 */
228
- if ( !$bp_no_status_set ) {
229
- status_header( 200 );
230
- $wp_query->is_404 = false;
231
- $wp_query->is_page = true;
232
  }
233
 
 
234
  foreach ( (array)$templates as $template )
235
  $filtered_templates[] = $template . '.php';
236
 
 
237
  if ( $located_template = apply_filters( 'bp_located_template', locate_template( (array) $filtered_templates, false ), $filtered_templates ) ) {
 
 
 
 
 
238
  load_template( apply_filters( 'bp_load_template', $located_template ) );
239
- } else {
240
- if ( $located_template = locate_template( array( '404.php' ) ) ) {
241
- status_header( 404 );
242
- load_template( $located_template );
243
- } else
244
- bp_core_redirect( $bp->root_domain );
245
  }
 
 
246
  die;
247
  }
248
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
  function bp_core_catch_no_access() {
250
- global $bp, $bp_path, $bp_unfiltered_uri, $bp_no_status_set;
251
 
252
  // If bp_core_redirect() and $bp_no_status_set is true,
253
- // we are redirecting to an accessable page, so skip this check.
254
  if ( $bp_no_status_set )
255
  return false;
256
 
257
- /* If this user has been marked as a spammer and the logged in user is not a site admin, redirect. */
258
  if ( isset( $bp->displayed_user->id ) && bp_core_is_user_spammer( $bp->displayed_user->id ) ) {
259
- if ( !is_super_admin() )
260
- bp_core_redirect( $bp->root_domain );
261
- else
 
 
262
  bp_core_add_message( __( 'This user has been marked as a spammer. Only site admins can view this profile.', 'buddypress' ), 'error' );
 
263
  }
264
 
265
- // If this user does not exist, redirect to the root domain.
266
- if ( !$bp->displayed_user->id && $bp_unfiltered_uri[0] == BP_MEMBERS_SLUG && isset($bp_unfiltered_uri[1]) )
267
- bp_core_redirect( $bp->root_domain );
 
 
 
 
 
 
 
 
 
 
 
 
 
268
 
269
- // Add .php to all options in $bp_path
270
- foreach( (array) $bp_path as $template )
271
- $filtered_templates[] = "$template.php";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
 
273
- // If the template file doesn't exist, redirect to the root domain.
274
- if ( !bp_is_blog_page() && !file_exists( apply_filters( 'bp_located_template', locate_template( $filtered_templates, false ), $filtered_templates ) ) )
275
- bp_core_redirect( $bp->root_domain );
276
 
277
- if ( !$bp_path && !bp_is_blog_page() ) {
278
- if ( is_user_logged_in() ) {
279
- wp_redirect( $bp->root_domain );
280
- } else {
281
- wp_redirect( site_url( 'wp-login.php?redirect_to=' . site_url() . $_SERVER['REQUEST_URI'] ) );
282
- }
 
 
 
 
 
 
 
 
 
 
 
283
  }
284
  }
285
- add_action( 'wp', 'bp_core_catch_no_access' );
286
 
287
  /**
288
- * bp_core_catch_profile_uri()
289
- *
290
- * If the extended profiles component is not installed we still need
291
- * to catch the /profile URI's and display whatever we have installed.
292
  *
 
 
 
293
  */
294
- function bp_core_catch_profile_uri() {
295
- global $bp;
296
 
297
- if ( !function_exists('xprofile_install') )
298
- bp_core_load_template( apply_filters( 'bp_core_template_display_profile', 'members/single/home' ) );
 
 
299
  }
 
300
 
301
  ?>
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] / ...
22
  * - OUTSIDE ROOT: http:// domain.com / sites / buddypress / members / andy / [current_component] / [current_action] / [action_variables] / [action_variables] / ...
23
  *
24
  * Example:
25
  * - http://domain.com/members/andy/profile/edit/group/5/
26
+ * - $bp->current_component: string 'xprofile'
27
  * - $bp->current_action: string 'edit'
28
  * - $bp->action_variables: array ['group', 5]
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' ) )
50
  else
51
  $path = esc_url( $_SERVER['REQUEST_URI'] );
52
 
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
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,
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
 
83
  $bp_uri = array_values( $bp_uri );
84
  }
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
 
95
  // Take empties off the end of path
96
+ if ( empty( $paths[count( $paths ) - 1] ) )
97
  array_pop( $paths );
98
 
99
  // Take empties off the start of path
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
+ }
109
 
110
  // Reset the keys by merging with an empty array
111
+ $bp_uri = array_merge( array(), $bp_uri );
112
+
113
+ // If a component is set to the front page, force its name into $bp_uri
114
+ // so that $current_component is populated
115
+ if ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) && empty( $bp_uri ) ) {
116
+ $post = get_post( get_option( 'page_on_front' ) );
117
+ if ( !empty( $post ) ) {
118
+ $bp_uri[0] = $post->post_name;
119
+ }
120
+ }
121
+
122
+ // Keep the unfiltered URI safe
123
  $bp_unfiltered_uri = $bp_uri;
124
 
125
+ // Get slugs of pages into array
126
+ foreach ( (array) $bp->pages as $page_key => $bp_page )
127
+ $key_slugs[$page_key] = trailingslashit( '/' . $bp_page->slug );
128
+
129
+ // Bail if keyslugs are empty, as BP is not setup correct
130
+ if ( empty( $key_slugs ) )
131
+ return;
132
+
133
+ // Loop through page slugs and look for exact match to path
134
+ foreach ( $key_slugs as $key => $slug ) {
135
+ if ( $slug == $path ) {
136
+ $match = $bp->pages->{$key};
137
+ $match->key = $key;
138
+ $matches[] = 1;
139
+ break;
140
+ }
141
  }
142
 
143
+ // No exact match, so look for partials
144
+ if ( empty( $match ) ) {
145
+
146
+ // Loop through each page in the $bp->pages global
147
+ foreach ( (array) $bp->pages as $page_key => $bp_page ) {
148
+
149
+ // Look for a match (check members first)
150
+ if ( in_array( $bp_page->name, (array) $bp_uri ) ) {
151
+
152
+ // Match found, now match the slug to make sure.
153
+ $uri_chunks = explode( '/', $bp_page->slug );
154
+
155
+ // Loop through uri_chunks
156
+ foreach ( (array) $uri_chunks as $key => $uri_chunk ) {
157
 
158
+ // Make sure chunk is in the correct position
159
+ if ( !empty( $bp_uri[$key] ) && ( $bp_uri[$key] == $uri_chunk ) ) {
160
+ $matches[] = 1;
161
 
162
+ // No match
163
+ } else {
164
+ $matches[] = 0;
165
+ }
166
+ }
167
+
168
+ // Have a match
169
+ if ( !in_array( 0, (array) $matches ) ) {
170
+ $match = $bp_page;
171
+ $match->key = $page_key;
172
+ break;
173
+ };
174
+
175
+ // Unset matches
176
+ unset( $matches );
177
+ }
178
+
179
+ // Unset uri chunks
180
+ unset( $uri_chunks );
181
  }
182
+ }
183
+
184
+ // URLs with BP_ENABLE_ROOT_PROFILES enabled won't be caught above
185
+ if ( empty( $matches ) && defined( 'BP_ENABLE_ROOT_PROFILES' ) && BP_ENABLE_ROOT_PROFILES ) {
186
 
187
+ // Make sure there's a user corresponding to $bp_uri[0]
188
+ if ( !empty( $bp->pages->members ) && !empty( $bp_uri[0] ) && $root_profile = get_userdatabylogin( $bp_uri[0] ) ) {
 
 
 
189
 
190
+ // Force BP to recognize that this is a members page
191
+ $matches[] = 1;
192
+ $match = $bp->pages->members;
193
+ $match->key = 'members';
194
 
195
+ // Without the 'members' URL chunk, WordPress won't know which page to load
196
+ // This filter intercepts the WP query and tells it to load the members page
197
+ add_filter( 'request', create_function( '$query_args', '$query_args["pagename"] = "' . $match->name . '"; return $query_args;' ) );
198
  }
199
  }
200
 
201
+ // Search doesn't have an associated page, so we check for it separately
202
+ if ( !empty( $bp_uri[0] ) && ( bp_get_search_slug() == $bp_uri[0] ) ) {
203
+ $matches[] = 1;
204
+ $match = new stdClass;
205
+ $match->key = 'search';
206
+ $match->slug = bp_get_search_slug();
207
+ }
208
+
209
+ // This is not a BuddyPress page, so just return.
210
+ if ( !isset( $matches ) )
211
+ return false;
212
+
213
+ // Find the offset. With $root_profile set, we fudge the offset down so later parsing works
214
+ $slug = !empty ( $match ) ? explode( '/', $match->slug ) : '';
215
+ $uri_offset = empty( $root_profile ) ? 0 : -1;
216
 
217
+ // Rejig the offset
218
+ if ( !empty( $slug ) && ( 1 < count( $slug ) ) ) {
219
+ array_pop( $slug );
220
+ $uri_offset = count( $slug );
221
  }
222
 
223
+ // Global the unfiltered offset to use in bp_core_load_template().
224
+ // To avoid PHP warnings in bp_core_load_template(), it must always be >= 0
225
+ $bp_unfiltered_uri_offset = $uri_offset >= 0 ? $uri_offset : 0;
226
+
227
+ // We have an exact match
228
+ if ( isset( $match->key ) ) {
229
+
230
+ // Set current component to matched key
231
+ $bp->current_component = $match->key;
232
+
233
+ // If members component, do more work to find the actual component
234
+ if ( 'members' == $match->key ) {
235
+
236
+ // Viewing a specific user
237
+ if ( !empty( $bp_uri[$uri_offset + 1] ) ) {
238
+
239
+ // Switch the displayed_user based on compatbility mode
240
+ if ( bp_is_username_compatibility_mode() )
241
+ $bp->displayed_user->id = (int) bp_core_get_userid( urldecode( $bp_uri[$uri_offset + 1] ) );
242
+ else
243
+ $bp->displayed_user->id = (int) bp_core_get_userid_from_nicename( urldecode( $bp_uri[$uri_offset + 1] ) );
244
+
245
+ if ( empty( $bp->displayed_user->id ) ) {
246
+ // Prevent components from loading their templates
247
+ $bp->current_component = '';
248
+
249
+ bp_do_404();
250
+ return;
251
+ }
252
+
253
+ // Bump the offset
254
+ if ( isset( $bp_uri[$uri_offset + 2] ) ) {
255
+ $bp_uri = array_merge( array(), array_slice( $bp_uri, $uri_offset + 2 ) );
256
+ $bp->current_component = $bp_uri[0];
257
+
258
+ // No component, so default will be picked later
259
+ } else {
260
+ $bp_uri = array_merge( array(), array_slice( $bp_uri, $uri_offset + 2 ) );
261
+ $bp->current_component = '';
262
+ }
263
+
264
+ // Reset the offset
265
+ $uri_offset = 0;
266
+ }
267
+ }
268
+ }
269
 
270
  // Set the current action
271
+ $bp->current_action = isset( $bp_uri[$uri_offset + 1] ) ? $bp_uri[$uri_offset + 1] : '';
272
 
273
+ // Slice the rest of the $bp_uri array and reset offset
274
+ $bp_uri = array_slice( $bp_uri, $uri_offset + 2 );
275
+ $uri_offset = 0;
276
 
277
+ // Set the entire URI as the action variables, we will unset the current_component and action in a second
278
+ $bp->action_variables = $bp_uri;
 
279
 
280
  // Remove the username from action variables if this is not a VHOST install
281
+ // @todo - move or remove this all together
282
+ if ( defined( 'VHOST' ) && ( 'no' == VHOST ) && empty( $bp->current_component ) )
283
+ array_shift( $bp_uri );
284
 
285
  // Reset the keys by merging with an empty array
286
+ $bp->action_variables = array_merge( array(), $bp->action_variables );
287
  }
 
288
 
289
  /**
290
+ * bp_core_load_template()
291
  *
292
+ * Load a specific template file with fallback support.
 
293
  *
294
+ * Example:
295
+ * bp_core_load_template( 'members/index' );
296
+ * Loads:
297
+ * wp-content/themes/[activated_theme]/members/index.php
298
  *
299
  * @package BuddyPress Core
300
+ * @param $username str Username to check.
301
+ * @return false|int The user ID of the matched user, or false.
 
302
  */
303
+ function bp_core_load_template( $templates ) {
304
+ global $post, $bp, $wpdb, $wp_query, $bp_unfiltered_uri, $bp_unfiltered_uri_offset;
305
 
306
+ // Determine if the root object WP page exists for this request (TODO: is there an API function for this?
307
+ 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] ) ) )
308
+ return false;
 
 
 
 
 
 
309
 
310
+ // Set the root object as the current wp_query-ied item
311
+ $object_id = 0;
312
+ foreach ( (array)$bp->pages as $page ) {
313
+ if ( isset( $bp_unfiltered_uri[$bp_unfiltered_uri_offset] ) && $page->name == $bp_unfiltered_uri[$bp_unfiltered_uri_offset] ) {
314
+ $object_id = $page->id;
315
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
316
  }
317
 
318
+ // Make the queried/post object an actual valid page
319
+ if ( !empty( $object_id ) ) {
320
+ $wp_query->queried_object = &get_post( $object_id );
321
+ $wp_query->queried_object_id = $object_id;
322
+ $post = $wp_query->queried_object;
323
  }
324
 
325
+ // Fetch each template and add the php suffix
326
  foreach ( (array)$templates as $template )
327
  $filtered_templates[] = $template . '.php';
328
 
329
+ // Filter the template locations so that plugins can alter where they are located
330
  if ( $located_template = apply_filters( 'bp_located_template', locate_template( (array) $filtered_templates, false ), $filtered_templates ) ) {
331
+ // Template was located, lets set this as a valid page and not a 404.
332
+ status_header( 200 );
333
+ $wp_query->is_page = true;
334
+ $wp_query->is_404 = false;
335
+
336
  load_template( apply_filters( 'bp_load_template', $located_template ) );
 
 
 
 
 
 
337
  }
338
+
339
+ // Kill any other output after this.
340
  die;
341
  }
342
 
343
+ /**
344
+ * bp_core_catch_profile_uri()
345
+ *
346
+ * If the extended profiles component is not installed we still need
347
+ * to catch the /profile URI's and display whatever we have installed.
348
+ *
349
+ */
350
+ function bp_core_catch_profile_uri() {
351
+ global $bp;
352
+
353
+ if ( !bp_is_active( 'xprofile' ) )
354
+ bp_core_load_template( apply_filters( 'bp_core_template_display_profile', 'members/single/home' ) );
355
+ }
356
+
357
+ /**
358
+ * Catches invalid access to BuddyPress pages and redirects them accordingly.
359
+ *
360
+ * @package BuddyPress Core
361
+ * @since 1.5
362
+ */
363
  function bp_core_catch_no_access() {
364
+ global $bp, $bp_no_status_set, $wp_query;
365
 
366
  // If bp_core_redirect() and $bp_no_status_set is true,
367
+ // we are redirecting to an accessible page, so skip this check.
368
  if ( $bp_no_status_set )
369
  return false;
370
 
371
+ // If the displayed user was marked as a spammer and the logged-in user is not a super admin, 404.
372
  if ( isset( $bp->displayed_user->id ) && bp_core_is_user_spammer( $bp->displayed_user->id ) ) {
373
+ if ( !$bp->loggedin_user->is_super_admin ) {
374
+ bp_do_404();
375
+ return;
376
+
377
+ } else {
378
  bp_core_add_message( __( 'This user has been marked as a spammer. Only site admins can view this profile.', 'buddypress' ), 'error' );
379
+ }
380
  }
381
 
382
+ if ( !isset( $wp_query->queried_object ) && !bp_is_blog_page() ) {
383
+ bp_do_404();
384
+ }
385
+ }
386
+ add_action( 'wp', 'bp_core_catch_no_access' );
387
+
388
+ /**
389
+ * Redirects a user to login for BP pages that require access control and adds an error message (if
390
+ * one is provided).
391
+ * If authenticated, redirects user back to requested content by default.
392
+ *
393
+ * @package BuddyPress Core
394
+ * @since 1.5
395
+ */
396
+ function bp_core_no_access( $args = '' ) {
397
+ global $bp;
398
 
399
+ $defaults = array(
400
+ 'mode' => '1', // 1 = $root, 2 = wp-login.php
401
+ 'message' => __( 'You must log in to access the page you requested.', 'buddypress' ),
402
+ 'redirect' => wp_guess_url(), // the URL you get redirected to when a user successfully logs in
403
+ 'root' => $bp->root_domain // the landing page you get redirected to when a user doesn't have access
404
+ );
405
+
406
+ $r = wp_parse_args( $args, $defaults );
407
+ extract( $r, EXTR_SKIP );
408
+
409
+ // Apply filters to these variables
410
+ $mode = apply_filters( 'bp_no_access_mode', $mode, $root, $redirect, $message );
411
+ $redirect = apply_filters( 'bp_no_access_redirect', $redirect, $root, $message, $mode );
412
+ $root = trailingslashit( apply_filters( 'bp_no_access_root', $root, $redirect, $message, $mode ) );
413
+ $message = apply_filters( 'bp_no_access_message', $message, $root, $redirect, $mode );
414
+
415
+ switch ( $mode ) {
416
+ // Option to redirect to wp-login.php
417
+ // Error message is displayed with bp_core_no_access_wp_login_error()
418
+ case 2 :
419
+ if ( $redirect ) {
420
+ bp_core_redirect( wp_login_url( $redirect ) . '&action=bpnoaccess' );
421
+ } else {
422
+ bp_core_redirect( $root );
423
+ }
424
 
425
+ break;
 
 
426
 
427
+ // Redirect to root with "redirect_to" parameter
428
+ // Error message is displayed with bp_core_add_message()
429
+ case 1 :
430
+ default :
431
+ if ( $redirect ) {
432
+ $url = add_query_arg( 'redirect_to', urlencode( $redirect ), $root );
433
+ } else {
434
+ $url = $root;
435
+ }
436
+
437
+ if ( $message ) {
438
+ bp_core_add_message( $message, 'error' );
439
+ }
440
+
441
+ bp_core_redirect( $url );
442
+
443
+ break;
444
  }
445
  }
 
446
 
447
  /**
448
+ * Adds an error message to wp-login.php.
449
+ * Hooks into the "bpnoaccess" action defined in bp_core_no_access().
 
 
450
  *
451
+ * @package BuddyPress Core
452
+ * @global $error
453
+ * @since 1.5
454
  */
455
+ function bp_core_no_access_wp_login_error() {
456
+ global $error;
457
 
458
+ $error = apply_filters( 'bp_wp_login_error', __( 'You must log in to access the page you requested.', 'buddypress' ), $_REQUEST['redirect_to'] );
459
+
460
+ // shake shake shake!
461
+ add_action( 'login_head', 'wp_shake_js', 12 );
462
  }
463
+ add_action( 'login_form_bpnoaccess', 'bp_core_no_access_wp_login_error' );
464
 
465
  ?>
bp-core/bp-core-classes.php CHANGED
@@ -1,4 +1,7 @@
1
  <?php
 
 
 
2
  /**
3
  * BP_Core_User class can be used by any component. It will fetch useful
4
  * details for any user when provided with a user_id.
@@ -13,24 +16,114 @@
13
  * @package BuddyPress Core
14
  */
15
  class BP_Core_User {
 
 
 
 
 
 
16
  var $id;
 
 
 
 
 
 
17
  var $avatar;
 
 
 
 
 
 
18
  var $avatar_thumb;
 
 
 
 
 
 
19
  var $avatar_mini;
 
 
 
 
 
 
20
  var $fullname;
 
 
 
 
 
 
21
  var $email;
22
 
 
 
 
 
 
23
  var $user_url;
 
 
 
 
 
 
24
  var $user_link;
25
 
 
 
 
 
 
 
 
26
  var $last_active;
27
 
28
  /* Extras */
 
 
 
 
 
 
29
  var $total_friends;
 
 
 
 
 
 
 
30
  var $total_blogs;
 
 
 
 
 
 
 
 
31
  var $total_groups;
32
 
 
 
 
 
 
33
  function bp_core_user( $user_id, $populate_extras = false ) {
 
 
 
 
 
 
 
 
 
 
34
  if ( $user_id ) {
35
  $this->id = $user_id;
36
  $this->populate();
@@ -41,62 +134,61 @@ class BP_Core_User {
41
  }
42
 
43
  /**
44
- * populate()
45
- *
46
  * Populate the instantiated class with data based on the User ID provided.
47
  *
48
- * @package BuddyPress Core
49
- * @global $userdata WordPress user data for the current logged in user.
50
  * @uses bp_core_get_userurl() Returns the URL with no HTML markup for a user based on their user id
51
  * @uses bp_core_get_userlink() Returns a HTML formatted link for a user with the user's full name as the link text
52
  * @uses bp_core_get_user_email() Returns the email address for the user based on user ID
53
- * @uses get_user_meta() WordPress function returns the value of passed usermeta name from usermeta table
54
  * @uses bp_core_fetch_avatar() Returns HTML formatted avatar for a user
55
  * @uses bp_profile_last_updated_date() Returns the last updated date for a user.
56
  */
57
  function populate() {
58
- if ( function_exists( 'xprofile_install' ) )
 
 
59
  $this->profile_data = $this->get_profile_data();
60
 
61
- if ( $this->profile_data ) {
62
- $this->user_url = bp_core_get_user_domain( $this->id, $this->profile_data['user_nicename'], $this->profile_data['user_login'] );
63
- $this->fullname = esc_attr( $this->profile_data[BP_XPROFILE_FULLNAME_FIELD_NAME]['field_data'] );
 
 
64
  $this->user_link = "<a href='{$this->user_url}' title='{$this->fullname}'>{$this->fullname}</a>";
65
- $this->email = esc_attr( $this->profile_data['user_email'] );
66
  } else {
67
- $this->user_url = bp_core_get_user_domain( $this->id );
68
  $this->user_link = bp_core_get_userlink( $this->id );
69
- $this->fullname = esc_attr( bp_core_get_user_displayname( $this->id ) );
70
- $this->email = esc_attr( bp_core_get_user_email( $this->id ) );
71
  }
72
 
73
- /* Cache a few things that are fetched often */
74
  wp_cache_set( 'bp_user_fullname_' . $this->id, $this->fullname, 'bp' );
75
  wp_cache_set( 'bp_user_email_' . $this->id, $this->email, 'bp' );
76
  wp_cache_set( 'bp_user_url_' . $this->id, $this->user_url, 'bp' );
77
 
78
- $this->avatar = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'full' ) );
79
  $this->avatar_thumb = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb' ) );
80
- $this->avatar_mini = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb', 'width' => 30, 'height' => 30 ) );
81
-
82
- $this->last_active = bp_core_get_last_activity( get_user_meta( $this->id, 'last_activity', true ), __( 'active %s ago', 'buddypress' ) );
83
  }
84
 
 
 
 
 
 
85
  function populate_extras() {
86
  global $bp;
87
 
88
- if ( function_exists('friends_install') )
89
  $this->total_friends = BP_Friends_Friendship::total_friend_count( $this->id );
90
 
91
- if ( function_exists('groups_install') ) {
92
  $this->total_groups = BP_Groups_Member::total_group_count( $this->id );
93
-
94
- if ( $this->total_groups ) {
95
- if ( 1 == $this->total_groups )
96
- $this->total_groups .= ' ' . __( 'group', 'buddypress' );
97
- else
98
- $this->total_groups .= ' ' . __( 'groups', 'buddypress' );
99
- }
100
  }
101
  }
102
 
@@ -104,16 +196,16 @@ class BP_Core_User {
104
  return BP_XProfile_ProfileData::get_all_for_user( $this->id );
105
  }
106
 
107
- /* Static Functions */
108
 
109
- function get_users( $type, $limit = null, $page = 1, $user_id = false, $include = false, $search_terms = false, $populate_extras = true ) {
110
  global $wpdb, $bp;
111
 
112
  $sql = array();
113
 
114
  $sql['select_main'] = "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.display_name, u.user_email";
115
 
116
- if ( 'active' == $type || 'online' == $type )
117
  $sql['select_active'] = ", um.meta_value as last_activity";
118
 
119
  if ( 'popular' == $type )
@@ -122,18 +214,33 @@ class BP_Core_User {
122
  if ( 'alphabetical' == $type )
123
  $sql['select_alpha'] = ", pd.value as fullname";
124
 
125
- $sql['from'] = "FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN " . CUSTOM_USER_META_TABLE . " um ON um.user_id = u.ID";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
 
127
- if ( $search_terms && function_exists( 'xprofile_install' ) || 'alphabetical' == $type )
128
- $sql['join_profiledata'] = "LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id";
129
 
130
  $sql['where'] = 'WHERE ' . bp_core_get_status_sql( 'u.' );
131
 
132
- if ( 'active' == $type || 'online' == $type )
133
- $sql['where_active'] = "AND um.meta_key = 'last_activity'";
134
 
135
  if ( 'popular' == $type )
136
- $sql['where_popular'] = "AND um.meta_key = 'total_friend_count'";
137
 
138
  if ( 'online' == $type )
139
  $sql['where_online'] = "AND DATE_ADD( um.meta_value, INTERVAL 5 MINUTE ) >= UTC_TIMESTAMP()";
@@ -141,6 +248,9 @@ class BP_Core_User {
141
  if ( 'alphabetical' == $type )
142
  $sql['where_alpha'] = "AND pd.field_id = 1";
143
 
 
 
 
144
  if ( $include ) {
145
  if ( is_array( $include ) )
146
  $uids = $wpdb->escape( implode( ',', (array)$include ) );
@@ -151,21 +261,31 @@ class BP_Core_User {
151
  $sql['where_users'] = "AND u.ID IN ({$uids})";
152
  }
153
 
154
- else if ( $user_id && function_exists( 'friends_install' ) ) {
155
  $friend_ids = friends_get_friend_user_ids( $user_id );
156
  $friend_ids = $wpdb->escape( implode( ',', (array)$friend_ids ) );
157
 
158
  if ( !empty( $friend_ids ) )
159
  $sql['where_friends'] = "AND u.ID IN ({$friend_ids})";
160
- else {
161
- /* User has no friends, return false since there will be no users to fetch. */
 
162
  return false;
163
- }
164
  }
165
 
166
- if ( $search_terms && function_exists( 'xprofile_install' ) ) {
167
- $search_terms = like_escape( $wpdb->escape( $search_terms ) );
168
- $sql['where_searchterms'] = "AND pd.value LIKE '%%$search_terms%%'";
 
 
 
 
 
 
 
 
 
169
  }
170
 
171
  switch ( $type ) {
@@ -173,7 +293,7 @@ class BP_Core_User {
173
  $sql[] = "ORDER BY um.meta_value DESC";
174
  break;
175
  case 'newest':
176
- $sql[] = "ORDER BY u.user_registered DESC";
177
  break;
178
  case 'alphabetical':
179
  $sql[] = "ORDER BY pd.value ASC";
@@ -189,11 +309,11 @@ class BP_Core_User {
189
  if ( $limit && $page )
190
  $sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
191
 
192
- /* Get paginated results */
193
  $paged_users_sql = apply_filters( 'bp_core_get_paged_users_sql', join( ' ', (array)$sql ), $sql );
194
  $paged_users = $wpdb->get_results( $paged_users_sql );
195
 
196
- /* Re-jig the SQL so we can get the total user count */
197
  unset( $sql['select_main'] );
198
 
199
  if ( !empty( $sql['select_active'] ) )
@@ -210,7 +330,7 @@ class BP_Core_User {
210
 
211
  array_unshift( $sql, "SELECT COUNT(DISTINCT u.ID)" );
212
 
213
- /* Get total user results */
214
  $total_users_sql = apply_filters( 'bp_core_get_total_users_sql', join( ' ', (array)$sql ), $sql );
215
  $total_users = $wpdb->get_var( $total_users_sql );
216
 
@@ -218,22 +338,39 @@ class BP_Core_User {
218
  * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
219
  * 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)
220
  */
221
- if ( $populate_extras ) {
 
 
222
  foreach ( (array)$paged_users as $user )
223
  $user_ids[] = $user->id;
224
 
225
  $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
226
 
227
- /* Add additional data to the returned results */
228
- $paged_users = BP_Core_User::get_user_extras( &$paged_users, $user_ids, $type );
229
  }
230
 
231
  return array( 'users' => $paged_users, 'total' => $total_users );
232
  }
233
 
234
- function get_users_by_letter( $letter, $limit = null, $page = 1, $populate_extras = true ) {
235
- global $wpdb, $bp;
236
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
  if ( $limit && $page )
238
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
239
 
@@ -248,11 +385,13 @@ class BP_Core_User {
248
  }
249
  }
250
 
251
- $letter = like_escape( $wpdb->escape( $letter ) );
252
  $status_sql = bp_core_get_status_sql( 'u.' );
253
 
254
- $total_users_sql = apply_filters( 'bp_core_users_by_letter_count_sql', $wpdb->prepare( "SELECT COUNT(DISTINCT u.ID) FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id LEFT JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id WHERE {$status_sql} AND pf.name = %s AND pd.value LIKE '$letter%%' ORDER BY pd.value ASC", BP_XPROFILE_FULLNAME_FIELD_NAME ), $letter );
255
- $paged_users_sql = apply_filters( 'bp_core_users_by_letter_sql', $wpdb->prepare( "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.user_email FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id LEFT JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id WHERE {$status_sql} AND pf.name = %s AND pd.value LIKE '$letter%%' ORDER BY pd.value ASC{$pag_sql}", BP_XPROFILE_FULLNAME_FIELD_NAME ), $letter, $pag_sql );
 
 
256
 
257
  $total_users = $wpdb->get_var( $total_users_sql );
258
  $paged_users = $wpdb->get_results( $paged_users_sql );
@@ -261,6 +400,7 @@ class BP_Core_User {
261
  * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
262
  * 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)
263
  */
 
264
  foreach ( (array)$paged_users as $user )
265
  $user_ids[] = $user->id;
266
 
@@ -268,22 +408,73 @@ class BP_Core_User {
268
 
269
  /* Add additional data to the returned results */
270
  if ( $populate_extras )
271
- $paged_users = BP_Core_User::get_user_extras( &$paged_users, &$user_ids );
272
 
273
  return array( 'users' => $paged_users, 'total' => $total_users );
274
  }
275
 
276
- function search_users( $search_terms, $limit = null, $page = 1, $populate_extras = true ) {
277
- global $wpdb, $bp;
 
 
 
 
 
 
 
 
 
 
 
 
278
 
 
279
  if ( $limit && $page )
280
  $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
281
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
282
  $search_terms = like_escape( $wpdb->escape( $search_terms ) );
283
- $status_sql = bp_core_get_status_sql( 'u.' );
284
 
285
- $total_users_sql = apply_filters( 'bp_core_search_users_count_sql', "SELECT COUNT(DISTINCT u.ID) as id FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE {$status_sql} AND pd.value LIKE '%%$search_terms%%' ORDER BY pd.value ASC", $search_terms );
286
- $paged_users_sql = apply_filters( 'bp_core_search_users_sql', "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.user_email FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE {$status_sql} AND pd.value LIKE '%%$search_terms%%' ORDER BY pd.value ASC{$pag_sql}", $search_terms, $pag_sql );
287
 
288
  $total_users = $wpdb->get_var( $total_users_sql );
289
  $paged_users = $wpdb->get_results( $paged_users_sql );
@@ -297,27 +488,36 @@ class BP_Core_User {
297
 
298
  $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
299
 
300
- /* Add additional data to the returned results */
301
  if ( $populate_extras )
302
- $paged_users = BP_Core_User::get_user_extras( &$paged_users, &$user_ids );
303
 
304
  return array( 'users' => $paged_users, 'total' => $total_users );
305
  }
306
 
307
- function get_user_extras( $paged_users, $user_ids, $type = false ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
308
  global $bp, $wpdb;
309
 
310
  if ( empty( $user_ids ) )
311
  return $paged_users;
312
 
313
- /* Fetch the user's full name */
314
- if ( function_exists( 'xprofile_install' ) && 'alphabetical' != $type ) {
315
- /* Ensure xprofile globals are set */
316
- if ( !defined( 'BP_XPROFILE_FULLNAME_FIELD_NAME' ) )
317
- xprofile_setup_globals();
318
-
319
- $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 ) );
320
- for ( $i = 0; $i < count( $paged_users ); $i++ ) {
321
  foreach ( (array)$names as $name ) {
322
  if ( $name->id == $paged_users[$i]->id )
323
  $paged_users[$i]->fullname = $name->fullname;
@@ -325,21 +525,21 @@ class BP_Core_User {
325
  }
326
  }
327
 
328
- /* Fetch the user's total friend count */
329
  if ( 'popular' != $type ) {
330
- $friend_count = $wpdb->get_results( "SELECT user_id as id, meta_value as total_friend_count FROM " . CUSTOM_USER_META_TABLE . " WHERE meta_key = 'total_friend_count' AND user_id IN ( {$user_ids} )" );
331
- for ( $i = 0; $i < count( $paged_users ); $i++ ) {
332
- foreach ( (array)$friend_count as $count ) {
333
- if ( $count->id == $paged_users[$i]->id )
334
- $paged_users[$i]->total_friend_count = (int)$count->total_friend_count;
335
  }
336
  }
337
  }
338
 
339
- /* Fetch whether or not the user is a friend */
340
- if ( function_exists( 'friends_install' ) ) {
341
  $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 ) );
342
- for ( $i = 0; $i < count( $paged_users ); $i++ ) {
343
  foreach ( (array)$friend_status as $status ) {
344
  if ( $status->initiator_user_id == $paged_users[$i]->id || $status->friend_user_id == $paged_users[$i]->id )
345
  $paged_users[$i]->is_friend = $status->is_confirmed;
@@ -348,8 +548,8 @@ class BP_Core_User {
348
  }
349
 
350
  if ( 'active' != $type ) {
351
- $user_activity = $wpdb->get_results( "SELECT user_id as id, meta_value as last_activity FROM " . CUSTOM_USER_META_TABLE . " WHERE meta_key = 'last_activity' AND user_id IN ( {$user_ids} )" );
352
- for ( $i = 0; $i < count( $paged_users ); $i++ ) {
353
  foreach ( (array)$user_activity as $activity ) {
354
  if ( $activity->id == $paged_users[$i]->id )
355
  $paged_users[$i]->last_activity = $activity->last_activity;
@@ -357,10 +557,10 @@ class BP_Core_User {
357
  }
358
  }
359
 
360
- /* Fetch the user's last_activity */
361
  if ( 'active' != $type ) {
362
- $user_activity = $wpdb->get_results( "SELECT user_id as id, meta_value as last_activity FROM " . CUSTOM_USER_META_TABLE . " WHERE meta_key = 'last_activity' AND user_id IN ( {$user_ids} )" );
363
- for ( $i = 0; $i < count( $paged_users ); $i++ ) {
364
  foreach ( (array)$user_activity as $activity ) {
365
  if ( $activity->id == $paged_users[$i]->id )
366
  $paged_users[$i]->last_activity = $activity->last_activity;
@@ -368,9 +568,9 @@ class BP_Core_User {
368
  }
369
  }
370
 
371
- /* Fetch the user's latest update */
372
- $user_update = $wpdb->get_results( "SELECT user_id as id, meta_value as latest_update FROM " . CUSTOM_USER_META_TABLE . " WHERE meta_key = 'bp_latest_update' AND user_id IN ( {$user_ids} )" );
373
- for ( $i = 0; $i < count( $paged_users ); $i++ ) {
374
  foreach ( (array)$user_update as $update ) {
375
  if ( $update->id == $paged_users[$i]->id )
376
  $paged_users[$i]->latest_update = $update->latest_update;
@@ -380,6 +580,14 @@ class BP_Core_User {
380
  return $paged_users;
381
  }
382
 
 
 
 
 
 
 
 
 
383
  function get_core_userdata( $user_id ) {
384
  global $wpdb;
385
 
@@ -399,46 +607,122 @@ class BP_Core_User {
399
  */
400
 
401
  class BP_Core_Notification {
 
 
 
 
 
 
402
  var $id;
 
 
 
 
 
 
403
  var $item_id;
 
 
 
 
 
 
404
  var $secondary_item_id = null;
 
 
 
 
 
 
405
  var $user_id;
 
 
 
 
 
 
406
  var $component_name;
 
 
 
 
 
 
407
  var $component_action;
 
 
 
 
 
 
408
  var $date_notified;
 
 
 
 
 
 
409
  var $is_new;
410
 
411
- function bp_core_notification( $id = false ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
412
  if ( $id ) {
413
  $this->id = $id;
414
  $this->populate();
415
  }
416
  }
417
 
 
 
 
 
 
 
418
  function populate() {
419
- global $wpdb, $bp;
420
 
421
  if ( $notification = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE id = %d", $this->id ) ) ) {
422
  $this->item_id = $notification->item_id;
423
  $this->secondary_item_id = $notification->secondary_item_id;
424
- $this->user_id = $notification->user_id;
425
- $this->component_name = $notification->component_name;
426
- $this->component_action = $notification->component_action;
427
- $this->date_notified = $notification->date_notified;
428
- $this->is_new = $notification->is_new;
429
  }
430
  }
431
 
 
 
 
 
 
 
 
432
  function save() {
433
- global $wpdb, $bp;
434
 
435
- if ( $this->id ) {
436
- // Update
437
  $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 );
438
- } else {
439
- // Save
 
440
  $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 );
441
- }
442
 
443
  if ( !$result = $wpdb->query( $sql ) )
444
  return false;
@@ -447,7 +731,7 @@ class BP_Core_Notification {
447
  return true;
448
  }
449
 
450
- /* Static functions */
451
 
452
  function check_access( $user_id, $notification_id ) {
453
  global $wpdb, $bp;
@@ -455,41 +739,96 @@ class BP_Core_Notification {
455
  return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->core->table_name_notifications} WHERE id = %d AND user_id = %d", $notification_id, $user_id ) );
456
  }
457
 
 
 
 
 
 
 
 
 
 
458
  function get_all_for_user( $user_id ) {
459
- global $wpdb, $bp;
460
 
461
  return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND is_new = 1", $user_id ) );
462
  }
463
 
 
 
 
 
 
 
 
 
 
 
464
  function delete_for_user_by_type( $user_id, $component_name, $component_action ) {
465
- global $wpdb, $bp;
466
 
467
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND component_name = %s AND component_action = %s", $user_id, $component_name, $component_action ) );
468
  }
469
 
470
- function delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id ) {
471
- global $wpdb, $bp;
 
 
 
 
 
 
 
 
 
 
 
 
472
 
473
- if ( $secondary_item_id )
474
- $secondary_item_sql = $wpdb->prepare( " AND secondary_item_id = %d", $secondary_item_id );
475
 
476
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND item_id = %d AND component_name = %s AND component_action = %s{$secondary_item_sql}", $user_id, $item_id, $component_name, $component_action ) );
477
  }
478
 
 
 
 
 
 
 
 
 
 
 
479
  function delete_from_user_by_type( $user_id, $component_name, $component_action ) {
480
- global $wpdb, $bp;
481
 
482
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE item_id = %d AND component_name = %s AND component_action = %s", $user_id, $component_name, $component_action ) );
483
  }
484
 
 
 
 
 
 
 
 
 
 
 
 
485
  function delete_all_by_type( $item_id, $component_name, $component_action, $secondary_item_id ) {
486
- global $wpdb, $bp;
487
 
488
  if ( $component_action )
489
  $component_action_sql = $wpdb->prepare( "AND component_action = %s", $component_action );
 
 
490
 
491
  if ( $secondary_item_id )
492
  $secondary_item_sql = $wpdb->prepare( "AND secondary_item_id = %d", $secondary_item_id );
 
 
493
 
494
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE item_id = %d AND component_name = %s {$component_action_sql} {$secondary_item_sql}", $item_id, $component_name ) );
495
  }
@@ -504,26 +843,109 @@ class BP_Core_Notification {
504
  * @since 1.2.6
505
  */
506
  class BP_Button {
507
-
508
  // Button properties
 
 
 
 
 
 
509
  var $id;
 
 
 
 
 
 
510
  var $component;
 
 
 
 
 
 
511
  var $must_be_logged_in;
 
 
 
 
 
 
512
  var $block_self;
513
 
514
- // Wrapper div
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
515
  var $wrapper_class;
 
 
 
 
 
 
516
  var $wrapper_id;
517
 
 
518
  // Button
 
 
 
 
 
 
519
  var $link_href;
 
 
 
 
 
 
520
  var $link_class;
 
 
 
 
 
 
521
  var $link_id;
 
 
 
 
 
 
522
  var $link_rel;
 
 
 
 
 
 
523
  var $link_title;
 
 
 
 
 
 
524
  var $link_text;
525
 
 
526
  // HTML result
 
527
  var $contents;
528
 
529
  /**
@@ -534,6 +956,7 @@ class BP_Button {
534
  * component: Which component this button is for
535
  * must_be_logged_in: Button only appears for logged in users
536
  * block_self: Button will not appear when viewing your own profile.
 
537
  * wrapper_id: The DOM ID of the button wrapper
538
  * wrapper_class: The DOM class of the button wrapper
539
  * link_href: The destination link of the button
@@ -547,13 +970,19 @@ class BP_Button {
547
  * @return bool False if not allowed
548
  */
549
  function bp_button( $args = '' ) {
 
 
 
 
550
 
 
551
  $defaults = array(
552
  'id' => '',
553
  'component' => 'core',
554
  'must_be_logged_in' => true,
555
  'block_self' => true,
556
 
 
557
  'wrapper_id' => '',
558
  'wrapper_class' => '',
559
 
@@ -573,6 +1002,7 @@ class BP_Button {
573
  $this->component = $component;
574
  $this->must_be_logged_in = (bool)$must_be_logged_in;
575
  $this->block_self = (bool)$block_self;
 
576
 
577
  // $id and $component are required
578
  if ( empty( $id ) || empty( $component ) )
@@ -591,40 +1021,51 @@ class BP_Button {
591
  return false;
592
 
593
  // Wrapper properties
594
- if ( !empty( $wrapper_id ) )
595
- $this->wrapper_id = ' id="' . $wrapper_id . '"';
596
 
597
- if ( !empty( $wrapper_class ) )
598
- $this->wrapper_class = ' class="generic-button ' . $wrapper_class . '"';
599
- else
600
- $this->wrapper_class = ' class="generic-button"';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
601
 
602
  // Link properties
603
  if ( !empty( $link_id ) )
604
- $this->link_id = ' id="' . $link_id . '"';
605
 
606
  if ( !empty( $link_href ) )
607
- $this->link_href = ' href="' . $link_href . '"';
608
 
609
  if ( !empty( $link_title ) )
610
- $this->link_title = ' title="' . $link_title . '"';
611
 
612
  if ( !empty( $link_rel ) )
613
- $this->link_rel = ' rel="' . $link_rel . '"';
614
 
615
  if ( !empty( $link_class ) )
616
- $this->link_class = ' class="' . $link_class . '"';
617
 
618
  if ( !empty( $link_text ) )
619
- $this->link_text = $link_text;
620
 
621
  // Build the button
622
- $this->contents = '<div' . $this->wrapper_class . $this->wrapper_id . '>';
623
- $this->contents .= '<a'. $this->link_href . $this->link_title . $this->link_id . $this->link_rel . $this->link_class . '>' . $this->link_text . '</a>';
624
- $this->contents .= '</div>';
625
 
626
  // Allow button to be manipulated externally
627
- $this->contents = apply_filters( 'bp_button_' . $component . '_' . $id, $this->contents, $this );
628
  }
629
 
630
  /**
@@ -649,4 +1090,165 @@ class BP_Button {
649
  }
650
  }
651
 
652
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <?php
2
+ // Exit if accessed directly
3
+ if ( !defined( 'ABSPATH' ) ) exit;
4
+
5
  /**
6
  * BP_Core_User class can be used by any component. It will fetch useful
7
  * details for any user when provided with a user_id.
16
  * @package BuddyPress Core
17
  */
18
  class BP_Core_User {
19
+
20
+ /**
21
+ * ID of the user which the object relates to.
22
+ *
23
+ * @var integer
24
+ */
25
  var $id;
26
+
27
+ /**
28
+ * The URL to the full size of the avatar for the user.
29
+ *
30
+ * @var string
31
+ */
32
  var $avatar;
33
+
34
+ /**
35
+ * The URL to the thumb size of the avatar for the user.
36
+ *
37
+ * @var string
38
+ */
39
  var $avatar_thumb;
40
+
41
+ /**
42
+ * The URL to the mini size of the avatar for the user.
43
+ *
44
+ * @var string
45
+ */
46
  var $avatar_mini;
47
+
48
+ /**
49
+ * The full name of the user
50
+ *
51
+ * @var string
52
+ */
53
  var $fullname;
54
+
55
+ /**
56
+ * The email for the user.
57
+ *
58
+ * @var string
59
+ */
60
  var $email;
61
 
62
+ /**
63
+ * The absolute url for the user's profile.
64
+ *
65
+ * @var string
66
+ */
67
  var $user_url;
68
+
69
+ /**
70
+ * The HTML for the user link, with the link text being the user's full name.
71
+ *
72
+ * @var string
73
+ */
74
  var $user_link;
75
 
76
+ /**
77
+ * Contains a formatted string when the last time the user was active.
78
+ *
79
+ * Example: "active 2 hours and 50 minutes ago"
80
+ *
81
+ * @var string
82
+ */
83
  var $last_active;
84
 
85
  /* Extras */
86
+
87
+ /**
88
+ * The total number of "Friends" the user has on site.
89
+ *
90
+ * @var integer
91
+ */
92
  var $total_friends;
93
+
94
+ /**
95
+ * The total number of blog posts posted by the user
96
+ *
97
+ * @var integer
98
+ * @deprecated No longer used
99
+ */
100
  var $total_blogs;
101
+
102
+ /**
103
+ * The total number of groups the user is a part of.
104
+ *
105
+ * Example: "1 group", "2 groups"
106
+ *
107
+ * @var string
108
+ */
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.
122
+ *
123
+ * @param integer $user_id The ID for the user
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();
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
143
+ * @uses bp_get_user_meta() BP function returns the value of passed usermeta name from usermeta table
144
  * @uses bp_core_fetch_avatar() Returns HTML formatted avatar for a user
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();
152
 
153
+ if ( !empty( $this->profile_data ) ) {
154
+ $full_name_field_name = bp_xprofile_fullname_field_name();
155
+
156
+ $this->user_url = bp_core_get_user_domain( $this->id, $this->profile_data['user_nicename'], $this->profile_data['user_login'] );
157
+ $this->fullname = esc_attr( $this->profile_data[$full_name_field_name]['field_data'] );
158
  $this->user_link = "<a href='{$this->user_url}' title='{$this->fullname}'>{$this->fullname}</a>";
159
+ $this->email = esc_attr( $this->profile_data['user_email'] );
160
  } else {
161
+ $this->user_url = bp_core_get_user_domain( $this->id );
162
  $this->user_link = bp_core_get_userlink( $this->id );
163
+ $this->fullname = esc_attr( bp_core_get_user_displayname( $this->id ) );
164
+ $this->email = esc_attr( bp_core_get_user_email( $this->id ) );
165
  }
166
 
167
+ // Cache a few things that are fetched often
168
  wp_cache_set( 'bp_user_fullname_' . $this->id, $this->fullname, 'bp' );
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;
203
 
204
  $sql = array();
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 )
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()";
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 ) );
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
286
+ if ( $meta_value ) {
287
+ $sql['where_meta'] .= $wpdb->prepare( " AND umm.meta_value = %s", $meta_value );
288
+ }
289
  }
290
 
291
  switch ( $type ) {
293
  $sql[] = "ORDER BY um.meta_value DESC";
294
  break;
295
  case 'newest':
296
+ $sql[] = "ORDER BY u.ID DESC";
297
  break;
298
  case 'alphabetical':
299
  $sql[] = "ORDER BY pd.value ASC";
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'] ) )
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
 
338
  * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
339
  * 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)
340
  */
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 );
351
  }
352
 
353
  return array( 'users' => $paged_users, 'total' => $total_users );
354
  }
355
 
 
 
356
 
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.
364
+ * @param integer $page The page number we are currently on, used in conjunction with $limit to get the start position for the limit.
365
+ * @param boolean $populate_extras Populate extra user fields?
366
+ * @param string $exclude Comma-separated IDs of users whose results aren't to be fetched.
367
+ * @return mixed False on error, otherwise associative array of results.
368
+ * @static
369
+ */
370
+ function get_users_by_letter( $letter, $limit = null, $page = 1, $populate_extras = true, $exclude = '' ) {
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
 
385
  }
386
  }
387
 
388
+ $letter = like_escape( $wpdb->escape( $letter ) );
389
  $status_sql = bp_core_get_status_sql( 'u.' );
390
 
391
+ $exclude_sql = ( !empty( $exclude ) ) ? " AND u.ID NOT IN ({$exclude})" : "";
392
+
393
+ $total_users_sql = apply_filters( 'bp_core_users_by_letter_count_sql', $wpdb->prepare( "SELECT COUNT(DISTINCT u.ID) FROM {$wpdb->users} u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id LEFT JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id WHERE {$status_sql} AND pf.name = %s {$exclude_sql} AND pd.value LIKE '$letter%%' ORDER BY pd.value ASC", bp_xprofile_fullname_field_name() ), $letter );
394
+ $paged_users_sql = apply_filters( 'bp_core_users_by_letter_sql', $wpdb->prepare( "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.user_email FROM {$wpdb->users} u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id LEFT JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id WHERE {$status_sql} AND pf.name = %s {$exclude_sql} AND pd.value LIKE '$letter%%' ORDER BY pd.value ASC{$pag_sql}", bp_xprofile_fullname_field_name() ), $letter, $pag_sql );
395
 
396
  $total_users = $wpdb->get_var( $total_users_sql );
397
  $paged_users = $wpdb->get_results( $paged_users_sql );
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
 
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
  }
415
 
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.
423
+ * @param integer $page The page we are on for pagination.
424
+ * @param boolean $populate_extras Populate extra user fields?
425
+ * @return array Associative array
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
+
438
+ $total_users_sql = apply_filters( 'bp_core_get_specific_users_count_sql', $wpdb->prepare( "SELECT COUNT(DISTINCT ID) FROM {$wpdb->users} WHERE {$status_sql} AND ID IN ( " . $wpdb->escape( $user_ids ) . " ) " ), $wpdb->escape( $user_ids ) );
439
+ $paged_users_sql = apply_filters( 'bp_core_get_specific_users_count_sql', $wpdb->prepare( "SELECT DISTINCT ID as id, user_registered, user_nicename, user_login, user_email FROM {$wpdb->users} WHERE {$status_sql} AND ID IN ( " . $wpdb->escape( $user_ids ) . " ) {$pag_sql}" ), $wpdb->escape( $user_ids ) );
440
+
441
+ $total_users = $wpdb->get_var( $total_users_sql );
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
+ }
455
+
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.
463
+ * @param integer $page The page we are on for pagination.
464
+ * @param boolean $populate_extras Populate extra user fields?
465
+ * @return array Associative array
466
+ * @static
467
+ */
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.' );
475
 
476
+ $total_users_sql = apply_filters( 'bp_core_search_users_count_sql', "SELECT COUNT(DISTINCT u.ID) as id FROM {$wpdb->users} u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE {$status_sql} AND pd.value LIKE '%%$search_terms%%' ORDER BY pd.value ASC", $search_terms );
477
+ $paged_users_sql = apply_filters( 'bp_core_search_users_sql', "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.user_email FROM {$wpdb->users} u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE {$status_sql} AND pd.value LIKE '%%$search_terms%%' ORDER BY pd.value ASC{$pag_sql}", $search_terms, $pag_sql );
478
 
479
  $total_users = $wpdb->get_var( $total_users_sql );
480
  $paged_users = $wpdb->get_results( $paged_users_sql );
488
 
489
  $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
490
 
491
+ // Add additional data to the returned results
492
  if ( $populate_extras )
493
+ $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids );
494
 
495
  return array( 'users' => $paged_users, 'total' => $total_users );
496
  }
497
 
498
+ /**
499
+ * Fetch extra user information, such as friend count and last profile update message.
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
507
+ * @param string $type the type of fields we wish to get
508
+ * @return mixed False on error, otherwise associative array of results.
509
+ * @static
510
+ */
511
+ function get_user_extras( &$paged_users, &$user_ids, $type = false ) {
512
  global $bp, $wpdb;
513
 
514
  if ( empty( $user_ids ) )
515
  return $paged_users;
516
 
517
+ // Fetch the user's full name
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;
525
  }
526
  }
527
 
528
+ // Fetch the user's total friend count
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;
548
  }
549
 
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;
557
  }
558
  }
559
 
560
+ // Fetch the user's last_activity
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;
568
  }
569
  }
570
 
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;
580
  return $paged_users;
581
  }
582
 
583
+ /**
584
+ * Get WordPress user details for a specified user.
585
+ *
586
+ * @global wpdb $wpdb WordPress database object
587
+ * @param integer $user_id User ID
588
+ * @return array Associative array
589
+ * @static
590
+ */
591
  function get_core_userdata( $user_id ) {
592
  global $wpdb;
593
 
607
  */
608
 
609
  class BP_Core_Notification {
610
+
611
+ /**
612
+ * The notification id
613
+ *
614
+ * @var integer
615
+ */
616
  var $id;
617
+
618
+ /**
619
+ * The ID to which the notification relates to within the component.
620
+ *
621
+ * @var integer
622
+ */
623
  var $item_id;
624
+
625
+ /**
626
+ * The secondary ID to which the notification relates to within the component.
627
+ *
628
+ * @var integer
629
+ */
630
  var $secondary_item_id = null;
631
+
632
+ /**
633
+ * The user ID for who the notification is for.
634
+ *
635
+ * @var integer
636
+ */
637
  var $user_id;
638
+
639
+ /**
640
+ * The name of the component that the notification is for.
641
+ *
642
+ * @var string
643
+ */
644
  var $component_name;
645
+
646
+ /**
647
+ * The action within the component which the notification is related to.
648
+ *
649
+ * @var string
650
+ */
651
  var $component_action;
652
+
653
+ /**
654
+ * The date the notification was created.
655
+ *
656
+ * @var string
657
+ */
658
  var $date_notified;
659
+
660
+ /**
661
+ * Is the notification new or has it already been read.
662
+ *
663
+ * @var boolean
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
679
+ *
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
+ */
716
  function save() {
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;
731
  return true;
732
  }
733
 
734
+ /** Static functions ******************************************************/
735
 
736
  function check_access( $user_id, $notification_id ) {
737
  global $wpdb, $bp;
739
  return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->core->table_name_notifications} WHERE id = %d AND user_id = %d", $notification_id, $user_id ) );
740
  }
741
 
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
764
+ * @param string $component_action
765
+ * @static
766
+ */
767
  function delete_for_user_by_type( $user_id, $component_name, $component_action ) {
768
+ global $bp, $wpdb;
769
 
770
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND component_name = %s AND component_action = %s", $user_id, $component_name, $component_action ) );
771
  }
772
 
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.
780
+ * @param string $component_name The name of the component that the notifications we wish to delete.
781
+ * @param string $component_action The action of the component that the notifications we wish to delete.
782
+ * @param integer $secondary_item_id (optional) The secondary item id of the notifications that we wish to use to delete.
783
+ * @static
784
+ */
785
+ function delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false ) {
786
+ global $bp, $wpdb;
787
 
788
+ $secondary_item_sql = !empty( $secondary_item_id ) ? $wpdb->prepare( " AND secondary_item_id = %d", $secondary_item_id ) : '';
 
789
 
790
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND item_id = %d AND component_name = %s AND component_action = %s{$secondary_item_sql}", $user_id, $item_id, $component_name, $component_action ) );
791
  }
792
 
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.
800
+ * @param string $component_action The action of the component the notification was sent from.
801
+ * @static
802
+ */
803
  function delete_from_user_by_type( $user_id, $component_name, $component_action ) {
804
+ global $bp, $wpdb;
805
 
806
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE item_id = %d AND component_name = %s AND component_action = %s", $user_id, $component_name, $component_action ) );
807
  }
808
 
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.
816
+ * @param string $component_action The action that the notificationsa are to be from.
817
+ * @param string $secondary_item_id Optional secondary item id that the notifications are to have.
818
+ * @static
819
+ */
820
  function delete_all_by_type( $item_id, $component_name, $component_action, $secondary_item_id ) {
821
+ global $bp, $wpdb;
822
 
823
  if ( $component_action )
824
  $component_action_sql = $wpdb->prepare( "AND component_action = %s", $component_action );
825
+ else
826
+ $component_action_sql = '';
827
 
828
  if ( $secondary_item_id )
829
  $secondary_item_sql = $wpdb->prepare( "AND secondary_item_id = %d", $secondary_item_id );
830
+ else
831
+ $secondary_item_sql = '';
832
 
833
  return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE item_id = %d AND component_name = %s {$component_action_sql} {$secondary_item_sql}", $item_id, $component_name ) );
834
  }
843
  * @since 1.2.6
844
  */
845
  class BP_Button {
 
846
  // Button properties
847
+
848
+ /**
849
+ * The button ID
850
+ *
851
+ * @var integer
852
+ */
853
  var $id;
854
+
855
+ /**
856
+ * The component name that button belongs to.
857
+ *
858
+ * @var string
859
+ */
860
  var $component;
861
+
862
+ /**
863
+ * Does the user need to be logged in to see this button?
864
+ *
865
+ * @var boolean
866
+ */
867
  var $must_be_logged_in;
868
+
869
+ /**
870
+ * True or false if the button should not be displayed while viewing your own profile.
871
+ *
872
+ * @var boolean
873
+ */
874
  var $block_self;
875
 
876
+
877
+ // Wrapper
878
+
879
+ /**
880
+ * What type of DOM element to use for a wrapper.
881
+ *
882
+ *
883
+ * @var mixed div|span|p|li, or false for no wrapper
884
+ */
885
+ var $wrapper;
886
+
887
+ /**
888
+ * The DOM class of the button wrapper
889
+ *
890
+ * @var string
891
+ */
892
  var $wrapper_class;
893
+
894
+ /**
895
+ * The DOM ID of the button wrapper
896
+ *
897
+ * @var string
898
+ */
899
  var $wrapper_id;
900
 
901
+
902
  // Button
903
+
904
+ /**
905
+ * The destination link of the button
906
+ *
907
+ * @var string
908
+ */
909
  var $link_href;
910
+
911
+ /**
912
+ * The DOM class of the button link
913
+ *
914
+ * @var string
915
+ */
916
  var $link_class;
917
+
918
+ /**
919
+ * The DOM ID of the button link
920
+ *
921
+ * @var string
922
+ */
923
  var $link_id;
924
+
925
+ /**
926
+ * The DOM rel value of the button link
927
+ *
928
+ * @var string
929
+ */
930
  var $link_rel;
931
+
932
+ /**
933
+ * Title of the button link
934
+ *
935
+ * @var string
936
+ */
937
  var $link_title;
938
+
939
+ /**
940
+ * The contents of the button link
941
+ *
942
+ * @var string
943
+ */
944
  var $link_text;
945
 
946
+
947
  // HTML result
948
+
949
  var $contents;
950
 
951
  /**
956
  * component: Which component this button is for
957
  * must_be_logged_in: Button only appears for logged in users
958
  * block_self: Button will not appear when viewing your own profile.
959
+ * wrapper: div|span|p|li|false for no wrapper
960
  * wrapper_id: The DOM ID of the button wrapper
961
  * wrapper_class: The DOM class of the button wrapper
962
  * link_href: The destination link of the button
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
979
  $defaults = array(
980
  'id' => '',
981
  'component' => 'core',
982
  'must_be_logged_in' => true,
983
  'block_self' => true,
984
 
985
+ 'wrapper' => 'div',
986
  'wrapper_id' => '',
987
  'wrapper_class' => '',
988
 
1002
  $this->component = $component;
1003
  $this->must_be_logged_in = (bool)$must_be_logged_in;
1004
  $this->block_self = (bool)$block_self;
1005
+ $this->wrapper = $wrapper;
1006
 
1007
  // $id and $component are required
1008
  if ( empty( $id ) || empty( $component ) )
1021
  return false;
1022
 
1023
  // Wrapper properties
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 . '>';
1038
+ $after = '</' . $wrapper . '>';
1039
+
1040
+ // No wrapper
1041
+ } else {
1042
+ $before = $after = '';
1043
+ }
1044
 
1045
  // Link properties
1046
  if ( !empty( $link_id ) )
1047
+ $this->link_id = ' id="' . $link_id . '"';
1048
 
1049
  if ( !empty( $link_href ) )
1050
+ $this->link_href = ' href="' . $link_href . '"';
1051
 
1052
  if ( !empty( $link_title ) )
1053
+ $this->link_title = ' title="' . $link_title . '"';
1054
 
1055
  if ( !empty( $link_rel ) )
1056
+ $this->link_rel = ' rel="' . $link_rel . '"';
1057
 
1058
  if ( !empty( $link_class ) )
1059
+ $this->link_class = ' class="' . $link_class . '"';
1060
 
1061
  if ( !empty( $link_text ) )
1062
+ $this->link_text = $link_text;
1063
 
1064
  // Build the button
1065
+ $this->contents = $before . '<a'. $this->link_href . $this->link_title . $this->link_id . $this->link_rel . $this->link_class . '>' . $this->link_text . '</a>' . $after;
 
 
1066
 
1067
  // Allow button to be manipulated externally
1068
+ $this->contents = apply_filters( 'bp_button_' . $component . '_' . $id, $this->contents, $this, $before, $after );
1069
  }
1070
 
1071
  /**
1090
  }
1091
  }
1092
 
1093
+ /**
1094
+ * BP_Embed
1095
+ *
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
+ *
1106
+ * @global unknown $wp_embed
1107
+ */
1108
+ function __construct() {
1109
+ global $wp_embed;
1110
+
1111
+ // Make sure we populate the WP_Embed handlers array.
1112
+ // These are providers that use a regex callback on the URL in question.
1113
+ // Do not confuse with oEmbed providers, which require an external ping.
1114
+ // Used in WP_Embed::shortcode()
1115
+ $this->handlers = $wp_embed->handlers;
1116
+
1117
+ if ( bp_use_embed_in_activity() ) {
1118
+ add_filter( 'bp_get_activity_content_body', array( &$this, 'autoembed' ), 8 );
1119
+ add_filter( 'bp_get_activity_content_body', array( &$this, 'run_shortcode' ), 7 );
1120
+ }
1121
+
1122
+ if ( bp_use_embed_in_activity_replies() ) {
1123
+ add_filter( 'bp_get_activity_content', array( &$this, 'autoembed' ), 8 );
1124
+ add_filter( 'bp_get_activity_content', array( &$this, 'run_shortcode' ), 7 );
1125
+ }
1126
+
1127
+ if ( bp_use_embed_in_forum_posts() ) {
1128
+ add_filter( 'bp_get_the_topic_post_content', array( &$this, 'autoembed' ), 8 );
1129
+ add_filter( 'bp_get_the_topic_post_content', array( &$this, 'run_shortcode' ), 7 );
1130
+ }
1131
+
1132
+ if ( bp_use_embed_in_private_messages() ) {
1133
+ add_filter( 'bp_get_the_thread_message_content', array( &$this, 'autoembed' ), 8 );
1134
+ add_filter( 'bp_get_the_thread_message_content', array( &$this, 'run_shortcode' ), 7 );
1135
+ }
1136
+
1137
+ do_action_ref_array( 'bp_core_setup_oembed', array( &$this ) );
1138
+ }
1139
+
1140
+ /**
1141
+ * The {@link do_shortcode()} callback function.
1142
+ *
1143
+ * Attempts to convert a URL into embed HTML. Starts by checking the URL against the regex of the registered embed handlers.
1144
+ * Next, checks the URL against the regex of registered {@link WP_oEmbed} providers if oEmbed discovery is false.
1145
+ * If none of the regex matches and it's enabled, then the URL will be passed to {@link BP_Embed::parse_oembed()} for oEmbed parsing.
1146
+ *
1147
+ * @uses wp_parse_args()
1148
+ * @uses wp_embed_defaults()
1149
+ * @uses current_user_can()
1150
+ * @uses _wp_oembed_get_object()
1151
+ * @uses WP_Embed::maybe_make_link()
1152
+ *
1153
+ * @param array $attr Shortcode attributes.
1154
+ * @param string $url The URL attempting to be embeded.
1155
+ * @return string The embed HTML on success, otherwise the original URL.
1156
+ */
1157
+ function shortcode( $attr, $url = '' ) {
1158
+ if ( empty( $url ) )
1159
+ return '';
1160
+
1161
+ $rawattr = $attr;
1162
+ $attr = wp_parse_args( $attr, wp_embed_defaults() );
1163
+
1164
+ // kses converts & into &amp; and we need to undo this
1165
+ // See http://core.trac.wordpress.org/ticket/11311
1166
+ $url = str_replace( '&amp;', '&', $url );
1167
+
1168
+ // Look for known internal handlers
1169
+ ksort( $this->handlers );
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
+ }
1178
+
1179
+ // Get object ID
1180
+ $id = apply_filters( 'embed_post_id', 0 );
1181
+
1182
+ // Is oEmbed discovery on?
1183
+ $attr['discover'] = ( apply_filters( 'bp_embed_oembed_discover', false ) && current_user_can( 'unfiltered_html' ) );
1184
+
1185
+ // Set up a new WP oEmbed object to check URL with registered oEmbed providers
1186
+ require_once( ABSPATH . WPINC . '/class-oembed.php' );
1187
+ $oembed_obj = _wp_oembed_get_object();
1188
+
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 ) )
1196
+ $is_oembed_link = true;
1197
+ }
1198
+
1199
+ // If url doesn't match a WP oEmbed provider, stop parsing
1200
+ if ( !$is_oembed_link )
1201
+ return $this->maybe_make_link( $url );
1202
+ }
1203
+
1204
+ return $this->parse_oembed( $id, $url, $attr, $rawattr );
1205
+ }
1206
+
1207
+ /**
1208
+ * Base function so BP components / plugins can parse links to be embedded.
1209
+ * View an example to add support in {@link bp_activity_embed()}.
1210
+ *
1211
+ * @uses apply_filters() Filters cache.
1212
+ * @uses do_action() To save cache.
1213
+ * @uses wp_oembed_get() Connects to oEmbed provider and returns HTML on success.
1214
+ * @uses WP_Embed::maybe_make_link() Process URL for hyperlinking on oEmbed failure.
1215
+ * @param int $id ID to do the caching for.
1216
+ * @param string $url The URL attempting to be embedded.
1217
+ * @param array $attr Shortcode attributes from {@link WP_Embed::shortcode()}.
1218
+ * @param array $rawattr Untouched shortcode attributes from {@link WP_Embed::shortcode()}.
1219
+ * @return string The embed HTML on success, otherwise the original URL.
1220
+ */
1221
+ function parse_oembed( $id, $url, $attr, $rawattr ) {
1222
+ $id = intval( $id );
1223
+
1224
+ if ( $id ) {
1225
+ // Setup the cachekey
1226
+ $cachekey = '_oembed_' . md5( $url . serialize( $attr ) );
1227
+
1228
+ // Let components / plugins grab their cache
1229
+ $cache = '';
1230
+ $cache = apply_filters( 'bp_embed_get_cache', $cache, $id, $cachekey, $url, $attr, $rawattr );
1231
+
1232
+ // Grab cache and return it if available
1233
+ if ( !empty( $cache ) ) {
1234
+ return apply_filters( 'bp_embed_oembed_html', $cache, $url, $attr, $rawattr );
1235
+
1236
+ // If no cache, ping the oEmbed provider and cache the result
1237
+ } else {
1238
+ $html = wp_oembed_get( $url, $attr );
1239
+ $cache = ( $html ) ? $html : $url;
1240
+
1241
+ // Let components / plugins save their cache
1242
+ do_action( 'bp_embed_update_cache', $cache, $cachekey, $id );
1243
+
1244
+ // If there was a result, return it
1245
+ if ( $html )
1246
+ return apply_filters( 'bp_embed_oembed_html', $html, $url, $attr, $rawattr );
1247
+ }
1248
+ }
1249
+
1250
+ // Still unknown
1251
+ return $this->maybe_make_link( $url );
1252
+ }
1253
+ }
1254
+ ?>
bp-core/bp-core-component.php ADDED
@@ -0,0 +1,358 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Exit if accessed directly
3
+ if ( !defined( 'ABSPATH' ) ) exit;
4
+
5
+ if ( !class_exists( 'BP_Component' ) ) :
6
+ /**
7
+ * BuddyPress Component Class
8
+ *
9
+ * The BuddyPress component class is responsible for simplifying the creation
10
+ * of components that share similar behaviors and routines. It is used
11
+ * internally by BuddyPress to create the bundled components, but can be
12
+ * extended to create other really neat things.
13
+ *
14
+ * @package BuddyPress
15
+ * @subpackage Component
16
+ *
17
+ * @since 1.5
18
+ */
19
+ class BP_Component {
20
+
21
+ /**
22
+ * @var string Unique name (for internal identification)
23
+ * @internal
24
+ */
25
+ var $name;
26
+
27
+ /**
28
+ * @var Unique ID (normally for custom post type)
29
+ */
30
+ var $id;
31
+
32
+ /**
33
+ * @var string Unique slug (used in query string and permalinks)
34
+ */
35
+ var $slug;
36
+
37
+ /**
38
+ * @var bool Does this component need a top-level directory?
39
+ */
40
+ var $has_directory;
41
+
42
+ /**
43
+ * @var string The path to the component's files
44
+ */
45
+ var $path;
46
+
47
+ /**
48
+ * @var WP_Query The loop for this component
49
+ */
50
+ var $query;
51
+
52
+ /**
53
+ * @var string The current ID of the queried object
54
+ */
55
+ var $current_id;
56
+
57
+ /**
58
+ * @var string Function to call for notifications
59
+ */
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
74
+ * - name: Unique name. This should be a translatable name, eg __( 'Groups', 'buddypress' )
75
+ * - path: The file path for the component's files. Used by BP_Component::includes()
76
+ * @uses bp_Component::setup_actions() Setup the hooks and actions
77
+ */
78
+ function start( $id, $name, $path ) {
79
+ // Internal identifier of component
80
+ $this->id = $id;
81
+
82
+ // Internal component name
83
+ $this->name = $name;
84
+
85
+ // Path for includes
86
+ $this->path = $path;
87
+
88
+ // Move on to the next step
89
+ $this->setup_actions();
90
+ }
91
+
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'
99
+ * @uses apply_filters() Calls 'bp_{@link bp_Component::name}_slug'
100
+ *
101
+ * @param arr $args Used to
102
+ */
103
+ function setup_globals( $args = '' ) {
104
+ global $bp;
105
+
106
+ /** Slugs *************************************************************/
107
+
108
+ $defaults = array(
109
+ 'slug' => $this->id,
110
+ 'root_slug' => '',
111
+ 'has_directory' => false,
112
+ 'notification_callback' => '',
113
+ 'search_string' => '',
114
+ 'global_tables' => ''
115
+ );
116
+ $r = wp_parse_args( $args, $defaults );
117
+
118
+ // Slug used for permalink URI chunk after root
119
+ $this->slug = apply_filters( 'bp_' . $this->id . '_slug', $r['slug'] );
120
+
121
+ // Slug used for root directory
122
+ $this->root_slug = apply_filters( 'bp_' . $this->id . '_root_slug', $r['root_slug'] );
123
+
124
+ // Does this component have a top-level directory?
125
+ $this->has_directory = apply_filters( 'bp_' . $this->id . '_has_directory', $r['has_directory'] );
126
+
127
+ // Search string
128
+ $this->search_string = apply_filters( 'bp_' . $this->id . '_search_string', $r['search_string'] );
129
+
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
+
140
+ // Register this component in the loaded components array
141
+ $bp->loaded_components[$this->slug] = $this->id;
142
+
143
+ // Call action
144
+ do_action( 'bp_' . $this->id . '_setup_globals' );
145
+ }
146
+
147
+ /**
148
+ * Include required files
149
+ *
150
+ * Please note that, by default, this method is fired on the bp_include hook, with priority
151
+ * 8. This is necessary so that core components are loaded in time to be available to
152
+ * third-party plugins. However, this load order means that third-party plugins whose main
153
+ * files are loaded at bp_include with priority 10 (as recommended), will not be loaded in
154
+ * time for their includes() method to fire automatically.
155
+ *
156
+ * For this reason, it is recommended that your plugin has its own method or function for
157
+ * requiring necessary files. If you must use this method, you will have to call it manually
158
+ * in your constructor class, ie
159
+ * $this->includes();
160
+ *
161
+ * Note that when you pass an array value like 'actions' to includes, it looks for the
162
+ * following three files (assuming your component is called 'my_component'):
163
+ * - ./actions
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'
171
+ */
172
+ function includes( $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
194
+ do_action( 'bp_' . $this->id . '_includes' );
195
+ }
196
+
197
+ /**
198
+ * Setup the actions
199
+ *
200
+ * @since 1.5
201
+ * @access private
202
+ *
203
+ * @uses add_action() To add various actions
204
+ * @uses do_action() Calls 'bp_{@link BP_Component::name}setup_actions'
205
+ */
206
+ function setup_actions() {
207
+
208
+ // Setup globals
209
+ add_action( 'bp_setup_globals', array ( $this, 'setup_globals' ), 10 );
210
+
211
+ // Include required files. Called early to ensure that BP core
212
+ // components are loaded before plugins that hook their loader functions
213
+ // to bp_include with the default priority of 10. This is for backwards
214
+ // compatibility; henceforth, plugins should register themselves by
215
+ // extending this base class.
216
+ add_action( 'bp_include', array ( $this, 'includes' ), 8 );
217
+
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
225
+ add_action( 'bp_setup_title', array ( $this, 'setup_title' ), 10 );
226
+
227
+ // Register post types
228
+ add_action( 'bp_register_post_types', array ( $this, 'register_post_types' ), 10 );
229
+
230
+ // Register taxonomies
231
+ add_action( 'bp_register_taxonomies', array ( $this, 'register_taxonomies' ), 10 );
232
+
233
+ // Add the rewrite tags
234
+ add_action( 'bp_add_rewrite_tags', array ( $this, 'add_rewrite_tags' ), 10 );
235
+
236
+ // Generate rewrite rules
237
+ add_action( 'bp_generate_rewrite_rules', array ( $this, 'generate_rewrite_rules' ), 10 );
238
+
239
+ // Additional actions can be attached here
240
+ do_action( 'bp_' . $this->id . '_setup_actions' );
241
+ }
242
+
243
+ /**
244
+ * Setup the navigation
245
+ *
246
+ * @param arr $main_nav Optional
247
+ * @param arr $sub_nav Optional
248
+ */
249
+ function setup_nav( $main_nav = '', $sub_nav = '' ) {
250
+
251
+ // No sub nav items without a main nav item
252
+ if ( !empty( $main_nav ) ) {
253
+ bp_core_new_nav_item( $main_nav );
254
+
255
+ // Sub nav items are not required
256
+ if ( !empty( $sub_nav ) ) {
257
+ foreach( $sub_nav as $nav ) {
258
+ bp_core_new_subnav_item( $nav );
259
+ }
260
+ }
261
+ }
262
+
263
+ // Call action
264
+ do_action( 'bp_' . $this->id . '_setup_nav' );
265
+ }
266
+
267
+ /**
268
+ * Setup the admin bar
269
+ *
270
+ * @global obj $wp_admin_bar
271
+ * @param array $wp_admin_menus
272
+ */
273
+ function setup_admin_bar( $wp_admin_nav = '' ) {
274
+
275
+ // Bail if this is an ajax request
276
+ if ( defined( 'DOING_AJAX' ) )
277
+ return;
278
+
279
+ // Do not proceed if BP_USE_WP_ADMIN_BAR constant is not set or is false
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
287
+ $this->admin_menu = $wp_admin_nav;
288
+
289
+ // Define the WordPress global
290
+ global $wp_admin_bar;
291
+
292
+ // Add each admin menu
293
+ foreach( $this->admin_menu as $admin_menu )
294
+ $wp_admin_bar->add_menu( $admin_menu );
295
+ }
296
+
297
+ // Call action
298
+ do_action( 'bp_' . $this->id . '_setup_admin_bar' );
299
+ }
300
+
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
+ */
308
+ function setup_title( ) {
309
+ do_action( 'bp_' . $this->id . '_setup_title' );
310
+ }
311
+
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
+ */
319
+ function register_post_types() {
320
+ do_action( 'bp_' . $this->id . '_register_post_types' );
321
+ }
322
+
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
+ */
330
+ function register_taxonomies() {
331
+ do_action( 'bp_' . $this->id . '_register_taxonomies' );
332
+ }
333
+
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
+ */
341
+ function add_rewrite_tags() {
342
+ do_action( 'bp_' . $this->id . '_add_rewrite_tags' );
343
+ }
344
+
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
+ */
352
+ function generate_rewrite_rules ( $wp_rewrite ) {
353
+ do_action( 'bp_' . $this->id . '_generate_rewrite_rules' );
354
+ }
355
+ }
356
+ endif; // BP_Component
357
+
358
+ ?>
bp-core/bp-core-cssjs.php CHANGED
@@ -1,29 +1,6 @@
1
  <?php
2
-
3
- /**
4
- * bp_core_add_admin_bar_css()
5
- *
6
- * Add the CSS needed for the admin bar on blogs (other than the root) and in the admin area.
7
- *
8
- * @package BuddyPress Core
9
- * @uses get_option() Selects a site setting from the DB.
10
- */
11
- function bp_core_add_admin_bar_css() {
12
- global $bp, $current_blog;
13
-
14
- if ( defined( 'BP_DISABLE_ADMIN_BAR' ) )
15
- return false;
16
-
17
- if ( ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG ) || is_admin() ) {
18
- $stylesheet = get_blog_option( BP_ROOT_BLOG, 'stylesheet' );
19
-
20
- if ( file_exists( WP_CONTENT_DIR . '/themes/' . $stylesheet . '/_inc/css/adminbar.css' ) )
21
- wp_enqueue_style( 'bp-admin-bar', apply_filters( 'bp_core_admin_bar_css', WP_CONTENT_URL . '/themes/' . $stylesheet . '/_inc/css/adminbar.css' ) );
22
- else
23
- wp_enqueue_style( 'bp-admin-bar', apply_filters( 'bp_core_admin_bar_css', BP_PLUGIN_URL . '/bp-themes/bp-default/_inc/css/adminbar.css' ) );
24
- }
25
- }
26
- add_action( 'init', 'bp_core_add_admin_bar_css' );
27
 
28
  /**
29
  * bp_core_admin_menu_icon_css()
@@ -33,13 +10,24 @@ add_action( 'init', 'bp_core_add_admin_bar_css' );
33
  * @package BuddyPress Core
34
  */
35
  function bp_core_admin_menu_icon_css() {
36
- global $bp;
37
- ?>
38
 
39
  <style type="text/css">
40
- ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image a { background-image: url( <?php echo BP_PLUGIN_URL . '/bp-core/images/admin_menu_icon.png' ?> ) !important; background-position: -1px -32px; }
41
- ul#adminmenu li.toplevel_page_bp-general-settings:hover .wp-menu-image a, ul#adminmenu li.toplevel_page_bp-general-settings.wp-has-current-submenu .wp-menu-image a { background-position: -1px 0; }
 
 
 
 
 
 
 
42
  ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image a img { display: none; }
 
 
 
 
 
43
  </style>
44
 
45
  <?php
@@ -47,11 +35,16 @@ function bp_core_admin_menu_icon_css() {
47
  add_action( 'admin_head', 'bp_core_admin_menu_icon_css' );
48
 
49
  function bp_core_confirmation_js() {
50
- global $current_blog;
51
 
52
- if ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG )
53
  return false;
54
- ?>
 
 
 
 
 
55
 
56
  <script type="text/javascript"> jQuery(document).ready( function() { jQuery("a.confirm").click( function() { if ( confirm( '<?php _e( 'Are you sure?', 'buddypress' ) ?>' ) ) return true; else return false; }); });</script>
57
 
@@ -82,12 +75,18 @@ function bp_core_add_jquery_cropper() {
82
  function bp_core_add_cropper_inline_js() {
83
  global $bp;
84
 
85
- $image = apply_filters( 'bp_inline_cropper_image', getimagesize( BP_AVATAR_UPLOAD_PATH . $bp->avatar_admin->image->dir ) );
86
  $aspect_ratio = 1;
87
 
 
 
 
88
  // Calculate Aspect Ratio
89
- if ( (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) && ( (int) constant( 'BP_AVATAR_FULL_WIDTH' ) != (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) ) )
90
- $aspect_ratio = (int) constant( 'BP_AVATAR_FULL_WIDTH' ) / (int) constant( 'BP_AVATAR_FULL_HEIGHT' );
 
 
 
91
  ?>
92
 
93
  <script type="text/javascript">
@@ -97,8 +96,9 @@ function bp_core_add_cropper_inline_js() {
97
  onSelect: showPreview,
98
  onSelect: updateCoords,
99
  aspectRatio: <?php echo $aspect_ratio ?>,
100
- setSelect: [ 50, 50, <?php echo $image[0] / 2 ?>, <?php echo $image[1] / 2 ?> ]
101
  });
 
102
  });
103
 
104
  function updateCoords(c) {
@@ -110,13 +110,13 @@ function bp_core_add_cropper_inline_js() {
110
 
111
  function showPreview(coords) {
112
  if ( parseInt(coords.w) > 0 ) {
113
- var rx = <?php echo (int) constant( 'BP_AVATAR_FULL_WIDTH' ) ?> / coords.w;
114
- var ry = <?php echo (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) ?> / coords.h;
115
 
116
  jQuery('#avatar-crop-preview').css({
117
  <?php if ( $image ) : ?>
118
- width: Math.round(rx * <?php echo $image[0] ?>) + 'px',
119
- height: Math.round(ry * <?php echo $image[1] ?>) + 'px',
120
  <?php endif; ?>
121
  marginLeft: '-' + Math.round(rx * coords.x) + 'px',
122
  marginTop: '-' + Math.round(ry * coords.y) + 'px'
@@ -148,7 +148,7 @@ function bp_core_add_cropper_inline_css() {
148
  .jcrop-tracker { width: 100%; height: 100%; }
149
  .custom .jcrop-vline, .custom .jcrop-hline { background: yellow; }
150
  .custom .jcrop-handle { border-color: black; background-color: #C7BB00; -moz-border-radius: 3px; -webkit-border-radius: 3px; }
151
- #avatar-crop-pane { width: <?php echo BP_AVATAR_FULL_WIDTH ?>px; height: <?php echo BP_AVATAR_FULL_HEIGHT ?>px; overflow: hidden; }
152
  #avatar-crop-submit { margin: 20px 0; }
153
  #avatar-upload-form img, #create-group-form img, #group-settings-form img { border: none !important; }
154
  </style>
@@ -173,4 +173,4 @@ function bp_core_add_ajax_url_js() {
173
  }
174
  add_action( 'wp_head', 'bp_core_add_ajax_url_js' );
175
 
176
- ?>
1
  <?php
2
+ // Exit if accessed directly
3
+ if ( !defined( 'ABSPATH' ) ) exit;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  /**
6
  * bp_core_admin_menu_icon_css()
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
35
  add_action( 'admin_head', 'bp_core_admin_menu_icon_css' );
36
 
37
  function bp_core_confirmation_js() {
38
+ global $wpdb;
39
 
40
+ if ( is_multisite() && $wpdb->blogid != bp_get_root_blog_id() )
41
  return false;
42
+
43
+ if ( !wp_script_is( 'jquery' ) )
44
+ wp_enqueue_script( 'jquery' );
45
+
46
+ if ( !wp_script_is( 'jquery', 'done' ) )
47
+ wp_print_scripts( 'jquery' ); ?>
48
 
49
  <script type="text/javascript"> jQuery(document).ready( function() { jQuery("a.confirm").click( function() { if ( confirm( '<?php _e( 'Are you sure?', 'buddypress' ) ?>' ) ) return true; else return false; }); });</script>
50
 
75
  function bp_core_add_cropper_inline_js() {
76
  global $bp;
77
 
78
+ $image = apply_filters( 'bp_inline_cropper_image', getimagesize( bp_core_avatar_upload_path() . $bp->avatar_admin->image->dir ) );
79
  $aspect_ratio = 1;
80
 
81
+ $full_height = bp_core_avatar_full_height();
82
+ $full_width = bp_core_avatar_full_width();
83
+
84
  // Calculate Aspect Ratio
85
+ if ( $full_height && ( $full_width != $full_height ) )
86
+ $aspect_ratio = $full_width / $full_height;
87
+
88
+ $width = $image[0] / 2;
89
+ $height = $image[1] / 2;
90
  ?>
91
 
92
  <script type="text/javascript">
96
  onSelect: showPreview,
97
  onSelect: updateCoords,
98
  aspectRatio: <?php echo $aspect_ratio ?>,
99
+ setSelect: [ 50, 50, <?php echo $width ?>, <?php echo $height ?> ]
100
  });
101
+ updateCoords({x: 50, y: 50, w: <?php echo $width ?>, h: <?php echo $height ?>});
102
  });
103
 
104
  function updateCoords(c) {
110
 
111
  function showPreview(coords) {
112
  if ( parseInt(coords.w) > 0 ) {
113
+ var rx = <?php echo $full_width; ?> / coords.w;
114
+ var ry = <?php echo $full_height; ?> / coords.h;
115
 
116
  jQuery('#avatar-crop-preview').css({
117
  <?php if ( $image ) : ?>
118
+ width: Math.round(rx * <?php echo $image[0]; ?>) + 'px',
119
+ height: Math.round(ry * <?php echo $image[1]; ?>) + 'px',
120
  <?php endif; ?>
121
  marginLeft: '-' + Math.round(rx * coords.x) + 'px',
122
  marginTop: '-' + Math.round(ry * coords.y) + 'px'
148
  .jcrop-tracker { width: 100%; height: 100%; }
149
  .custom .jcrop-vline, .custom .jcrop-hline { background: yellow; }
150
  .custom .jcrop-handle { border-color: black; background-color: #C7BB00; -moz-border-radius: 3px; -webkit-border-radius: 3px; }
151
+ #avatar-crop-pane { width: <?php echo bp_core_avatar_full_width() ?>px; height: <?php echo bp_core_avatar_full_height() ?>px; overflow: hidden; }
152
  #avatar-crop-submit { margin: 20px 0; }
153
  #avatar-upload-form img, #create-group-form img, #group-settings-form img { border: none !important; }
154
  </style>
173
  }
174
  add_action( 'wp_head', 'bp_core_add_ajax_url_js' );
175
 
176
+ ?>
bp-core/bp-core-filters.php CHANGED
@@ -1,38 +1,31 @@
1
  <?php
 
 
2
 
3
  /**
4
- * Load additional sign-up sanitization filters on bp_loaded. These are used
5
- * to prevent XSS in the BuddyPress sign-up process. You can unhook these to
6
- * allow for customization of your registration fields, however it is highly
7
- * recommended that you leave these in place for the safety of your network.
8
  *
9
- * @since BuddyPress (r4079)
10
- * @uses add_filter()
 
 
 
11
  */
12
- function bp_core_signup_sanitization() {
13
-
14
- // Filters on sign-up fields
15
- $fields = array (
16
- 'bp_get_signup_username_value',
17
- 'bp_get_signup_email_value',
18
- 'bp_get_signup_with_blog_value',
19
- 'bp_get_signup_blog_url_value',
20
- 'bp_get_signup_blog_title_value',
21
- 'bp_get_signup_blog_privacy_value',
22
- 'bp_get_signup_avatar_dir_value',
23
- );
24
-
25
- // Add the 'strip_tags' filter to each field
26
- foreach( $fields as $filter ) {
27
- add_filter( $filter, 'esc_html', 1 );
28
- add_filter( $filter, 'wp_filter_kses', 2 );
29
- add_filter( $filter, 'stripslashes', 3 );
30
- }
31
 
32
- // Sanitize email
33
- add_filter( 'bp_get_signup_email_value', 'sanitize_email' );
 
 
34
  }
35
- add_action( 'bp_loaded', 'bp_core_signup_sanitization' );
36
 
37
  /**
38
  * bp_core_email_from_name_filter()
@@ -44,7 +37,7 @@ add_action( 'bp_loaded', 'bp_core_signup_sanitization' );
44
  * @return The blog name for the root blog
45
  */
46
  function bp_core_email_from_name_filter() {
47
- return apply_filters( 'bp_core_email_from_name_filter', wp_specialchars_decode( get_blog_option( BP_ROOT_BLOG, 'blogname' ), ENT_QUOTES ) );
48
  }
49
  add_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
50
 
@@ -54,13 +47,12 @@ add_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
54
  * Sets the "From" address in emails sent
55
  *
56
  * @package BuddyPress Core
57
- * @global $current_site Object containing current site metadata
58
  * @return noreply@sitedomain email address
59
  */
60
  function bp_core_email_from_address_filter() {
61
  $domain = (array) explode( '/', site_url() );
62
 
63
- return apply_filters( 'bp_core_email_from_address_filter', __( 'noreply', 'buddypress' ) . '@' . $domain[2] );
64
  }
65
  add_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );
66
 
@@ -75,12 +67,12 @@ add_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );
75
  * @package BuddyPress Core
76
  */
77
  function bp_core_allow_default_theme( $themes ) {
78
- global $bp, $current_blog;
79
 
80
  if ( !is_super_admin() )
81
  return $themes;
82
 
83
- if ( $current_blog->ID == $bp->root_blog ) {
84
  $themes['bp-default'] = 1;
85
  }
86
 
@@ -133,18 +125,20 @@ add_filter( 'comments_array', 'bp_core_filter_comments', 10, 2 );
133
  * @package BuddyPress Core
134
  */
135
  function bp_core_login_redirect( $redirect_to ) {
136
- global $bp, $current_blog;
137
 
138
- if ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG )
 
139
  return $redirect_to;
140
 
141
- if ( !empty( $_REQUEST['redirect_to'] ) || strpos( $_REQUEST['redirect_to'], 'wp-admin' ) )
 
142
  return $redirect_to;
143
 
144
  if ( false === strpos( wp_get_referer(), 'wp-login.php' ) && false === strpos( wp_get_referer(), 'activate' ) && empty( $_REQUEST['nr'] ) )
145
  return wp_get_referer();
146
 
147
- return $bp->root_domain;
148
  }
149
  add_filter( 'login_redirect', 'bp_core_login_redirect' );
150
 
@@ -195,29 +189,30 @@ if ( !is_admin() && empty( $_GET['e'] ) )
195
 
196
  // Notify user of signup success.
197
  function bp_core_activation_signup_blog_notification( $domain, $path, $title, $user, $user_email, $key, $meta ) {
198
- global $current_site;
199
 
200
  // Send email with activation link.
201
  $activate_url = bp_get_activation_page() ."?key=$key";
202
- $activate_url = esc_url($activate_url);
203
 
204
- $admin_email = get_site_option( "admin_email" );
205
 
206
  if ( empty( $admin_email ) )
207
  $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
208
 
209
- $from_name = ( '' == get_site_option( "site_name" ) ) ? 'WordPress' : wp_specialchars( get_site_option( "site_name" ) );
210
- $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
211
- $message = sprintf(__("Thanks for registering! To complete the activation of your account and blog, please click the following link:\n\n%s\n\n\n\nAfter you activate, you can visit your blog here:\n\n%s", 'buddypress' ), $activate_url, esc_url("http://{$domain}{$path}" ) );
212
- $subject = '[' . $from_name . '] ' . sprintf(__('Activate %s', 'buddypress' ), esc_url('http://' . $domain . $path));
213
 
214
- /* Send the message */
215
- $to = apply_filters( 'bp_core_activation_signup_blog_notification_to', $user_email );
216
- $subject = apply_filters( 'bp_core_activation_signup_blog_notification_subject', $subject );
217
- $message = apply_filters( 'bp_core_activation_signup_blog_notification_message', $message );
218
 
219
  wp_mail( $to, $subject, $message, $message_headers );
220
 
 
 
221
  // Return false to stop the original WPMU function from continuing
222
  return false;
223
  }
@@ -225,35 +220,112 @@ if ( !is_admin() )
225
  add_filter( 'wpmu_signup_blog_notification', 'bp_core_activation_signup_blog_notification', 1, 7 );
226
 
227
  function bp_core_activation_signup_user_notification( $user, $user_email, $key, $meta ) {
228
- global $current_site;
229
 
230
- $activate_url = bp_get_activation_page() ."?key=$key";
231
  $activate_url = esc_url($activate_url);
232
- $admin_email = get_site_option( "admin_email" );
233
 
234
  if ( empty( $admin_email ) )
235
  $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
236
 
237
- /* If this is an admin generated activation, add a param to email the user login details */
238
- if ( is_admin() )
239
- $email = '&e=1';
240
 
241
- $from_name = ( '' == get_site_option( "site_name" ) ) ? 'WordPress' : wp_specialchars( get_site_option( "site_name" ) );
242
- $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
243
- $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, esc_url( "http://{$domain}{$path}" ) );
244
- $subject = '[' . $from_name . '] ' . __( 'Activate Your Account', 'buddypress' );
245
 
246
- /* Send the message */
247
- $to = apply_filters( 'bp_core_activation_signup_user_notification_to', $user_email );
248
- $subject = apply_filters( 'bp_core_activation_signup_user_notification_subject', $subject );
249
- $message = apply_filters( 'bp_core_activation_signup_user_notification_message', $message );
250
 
251
  wp_mail( $to, $subject, $message, $message_headers );
252
 
 
 
253
  // Return false to stop the original WPMU function from continuing
254
  return false;
255
  }
256
  if ( !is_admin() || ( is_admin() && empty( $_POST['noconfirmation'] ) ) )
257
  add_filter( 'wpmu_signup_user_notification', 'bp_core_activation_signup_user_notification', 1, 4 );
258
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
  ?>
1
  <?php
2
+ // Exit if accessed directly
3
+ if ( !defined( 'ABSPATH' ) ) exit;
4
 
5
  /**
6
+ * bp_core_exclude_pages()
 
 
 
7
  *
8
+ * Excludes specific pages from showing on page listings, for example the "Activation" page.
9
+ *
10
+ * @package BuddyPress Core
11
+ * @uses bp_is_active() checks if a BuddyPress component is active.
12
+ * @return array The list of page ID's to exclude
13
  */
14
+ function bp_core_exclude_pages( $pages ) {
15
+ global $bp;
16
+
17
+ if ( !empty( $bp->pages->activate ) )
18
+ $pages[] = $bp->pages->activate->id;
19
+
20
+ if ( !empty( $bp->pages->register ) )
21
+ $pages[] = $bp->pages->register->id;
 
 
 
 
 
 
 
 
 
 
 
22
 
23
+ if ( !empty( $bp->pages->forums ) && ( !bp_is_active( 'forums' ) || ( bp_is_active( 'forums' ) && bp_forums_has_directory() && !bp_forums_is_installed_correctly() ) ) )
24
+ $pages[] = $bp->pages->forums->id;
25
+
26
+ return apply_filters( 'bp_core_exclude_pages', $pages );
27
  }
28
+ add_filter( 'wp_list_pages_excludes', 'bp_core_exclude_pages' );
29
 
30
  /**
31
  * bp_core_email_from_name_filter()
37
  * @return The blog name for the root blog
38
  */
39
  function bp_core_email_from_name_filter() {
40
+ return apply_filters( 'bp_core_email_from_name_filter', wp_specialchars_decode( get_blog_option( bp_get_root_blog_id(), 'blogname' ), ENT_QUOTES ) );
41
  }
42
  add_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
43
 
47
  * Sets the "From" address in emails sent
48
  *
49
  * @package BuddyPress Core
 
50
  * @return noreply@sitedomain email address
51
  */
52
  function bp_core_email_from_address_filter() {
53
  $domain = (array) explode( '/', site_url() );
54
 
55
+ return apply_filters( 'bp_core_email_from_address_filter', 'noreply@' . $domain[2] );
56
  }
57
  add_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );
58
 
67
  * @package BuddyPress Core
68
  */
69
  function bp_core_allow_default_theme( $themes ) {
70
+ global $bp, $wpdb;
71
 
72
  if ( !is_super_admin() )
73
  return $themes;
74
 
75
+ if ( $wpdb->blogid == bp_get_root_blog_id() ) {
76
  $themes['bp-default'] = 1;
77
  }
78
 
125
  * @package BuddyPress Core
126
  */
127
  function bp_core_login_redirect( $redirect_to ) {
128
+ global $bp, $wpdb;
129
 
130
+ // Don't mess with the redirect if this is not the root blog
131
+ if ( is_multisite() && $wpdb->blogid != bp_get_root_blog_id() )
132
  return $redirect_to;
133
 
134
+ // If the redirect doesn't contain 'wp-admin', it's OK
135
+ if ( !empty( $_REQUEST['redirect_to'] ) && false === strpos( $_REQUEST['redirect_to'], 'wp-admin' ) )
136
  return $redirect_to;
137
 
138
  if ( false === strpos( wp_get_referer(), 'wp-login.php' ) && false === strpos( wp_get_referer(), 'activate' ) && empty( $_REQUEST['nr'] ) )
139
  return wp_get_referer();
140
 
141
+ return bp_get_root_domain();
142
  }
143
  add_filter( 'login_redirect', 'bp_core_login_redirect' );
144
 
189
 
190
  // Notify user of signup success.
191
  function bp_core_activation_signup_blog_notification( $domain, $path, $title, $user, $user_email, $key, $meta ) {
 
192
 
193
  // Send email with activation link.
194
  $activate_url = bp_get_activation_page() ."?key=$key";
195
+ $activate_url = esc_url( $activate_url );
196
 
197
+ $admin_email = get_site_option( 'admin_email' );
198
 
199
  if ( empty( $admin_email ) )
200
  $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
201
 
202
+ $from_name = ( '' == get_site_option( 'site_name' ) ) ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );
203
+ $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n";
204
+ $message = sprintf( __( "Thanks for registering! To complete the activation of your account and blog, please click the following link:\n\n%1\$s\n\n\n\nAfter you activate, you can visit your blog here:\n\n%2\$s", 'buddypress' ), $activate_url, esc_url( "http://{$domain}{$path}" ) );
205
+ $subject = '[' . $from_name . '] ' . sprintf(__( 'Activate %s', 'buddypress' ), esc_url( 'http://' . $domain . $path ) );
206
 
207
+ // Send the message
208
+ $to = apply_filters( 'bp_core_activation_signup_blog_notification_to', $user_email, $domain, $path, $title, $user, $user_email, $key, $meta );
209
+ $subject = apply_filters( 'bp_core_activation_signup_blog_notification_subject', $subject, $domain, $path, $title, $user, $user_email, $key, $meta );
210
+ $message = apply_filters( 'bp_core_activation_signup_blog_notification_message', $message, $domain, $path, $title, $user, $user_email, $key, $meta );
211
 
212
  wp_mail( $to, $subject, $message, $message_headers );
213
 
214
+ do_action( 'bp_core_sent_blog_signup_email', $admin_email, $subject, $message, $domain, $path, $title, $user, $user_email, $key, $meta );
215
+
216
  // Return false to stop the original WPMU function from continuing
217
  return false;
218
  }
220
  add_filter( 'wpmu_signup_blog_notification', 'bp_core_activation_signup_blog_notification', 1, 7 );
221
 
222
  function bp_core_activation_signup_user_notification( $user, $user_email, $key, $meta ) {
 
223
 
224
+ $activate_url = bp_get_activation_page() . "?key=$key";
225
  $activate_url = esc_url($activate_url);
226
+ $admin_email = get_site_option( 'admin_email' );
227
 
228
  if ( empty( $admin_email ) )
229
  $admin_email = 'support@' . $_SERVER['SERVER_NAME'];
230
 
231
+ // If this is an admin generated activation, add a param to email the
232
+ // user login details
233
+ $email = is_admin() ? '&e=1' : '';
234
 
235
+ $from_name = ( '' == get_site_option( 'site_name' ) ) ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );
236
+ $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n";
237
+ $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 );
238
+ $subject = '[' . $from_name . '] ' . __( 'Activate Your Account', 'buddypress' );
239
 
240
+ // Send the message
241
+ $to = apply_filters( 'bp_core_activation_signup_user_notification_to', $user_email, $user, $user_email, $key, $meta );
242
+ $subject = apply_filters( 'bp_core_activation_signup_user_notification_subject', $subject, $user, $user_email, $key, $meta );
243
+ $message = apply_filters( 'bp_core_activation_signup_user_notification_message', $message, $user, $user_email, $key, $meta );
244
 
245
  wp_mail( $to, $subject, $message, $message_headers );
246
 
247
+ do_action( 'bp_core_sent_user_signup_email', $admin_email, $subject, $message, $user, $user_email, $key, $meta );
248
+
249
  // Return false to stop the original WPMU function from continuing
250
  return false;
251
  }
252
  if ( !is_admin() || ( is_admin() && empty( $_POST['noconfirmation'] ) ) )
253
  add_filter( 'wpmu_signup_user_notification', 'bp_core_activation_signup_user_notification', 1, 4 );
254
 
255
+ /**
256
+ * Filter the page title for BuddyPress pages
257
+ *
258
+ * @global object $bp BuddyPress global settings
259
+ * @global unknown $post
260
+ * @global WP_Query $wp_query WordPress query object
261
+ * @param string $title Original page title
262
+ * @param string $sep How to separate the various items within the page title.
263
+ * @param string $seplocation Direction to display title
264
+ * @return string new page title
265
+ * @see wp_title()
266
+ * @since 1.5
267
+ */
268
+ function bp_modify_page_title( $title, $sep, $seplocation ) {
269
+ global $bp, $post, $wp_query;
270
+
271
+ // If this is not a BP page, just return the title produced by WP
272
+ if ( bp_is_blog_page() )
273
+ return $title;
274
+
275
+ // If this is the front page of the site, return WP's title
276
+ if ( is_front_page() || is_home() )
277
+ return $title;
278
+
279
+ $title = '';
280
+
281
+ // Displayed user
282
+ if ( !empty( $bp->displayed_user->fullname ) && !is_404() ) {
283
+ // translators: "displayed user's name | canonicalised component name"
284
+ $title = strip_tags( sprintf( __( '%1$s | %2$s', 'buddypress' ), bp_get_displayed_user_fullname(), ucwords( bp_current_component() ) ) );
285
+
286
+ // A single group
287
+ } elseif ( bp_is_active( 'groups' ) && !empty( $bp->groups->current_group ) && !empty( $bp->bp_options_nav[$bp->groups->current_group->slug] ) ) {
288
+ $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'] : '';
289
+ // translators: "group name | group nav section name"
290
+ $title = sprintf( __( '%1$s | %2$s', 'buddypress' ), $bp->bp_options_title, $subnav );
291
+
292
+ // A single item from a component other than groups
293
+ } elseif ( bp_is_single_item() ) {
294
+ // translators: "component item name | component nav section name | root component name"
295
+ $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() ) );
296
+
297
+ // An index or directory
298
+ } elseif ( bp_is_directory() ) {
299
+ if ( !bp_current_component() )
300
+ $title = sprintf( __( '%s Directory', 'buddypress' ), bp_get_name_from_root_slug( bp_members_slug() ) );
301
+ else
302
+ $title = sprintf( __( '%s Directory', 'buddypress' ), bp_get_name_from_root_slug( bp_get_root_slug() ) );
303
+
304
+ // Sign up page
305
+ } elseif ( bp_is_register_page() ) {
306
+ $title = __( 'Create an Account', 'buddypress' );
307
+
308
+ // Activation page
309
+ } elseif ( bp_is_activation_page() ) {
310
+ $title = __( 'Activate your Account', 'buddypress' );
311
+
312
+ // Group creation page
313
+ } elseif ( bp_is_group_create() ) {
314
+ $title = __( 'Create a Group', 'buddypress' );
315
+
316
+ // Blog creation page
317
+ } elseif ( bp_is_create_blog() ) {
318
+ $title = __( 'Create a Site', 'buddypress' );
319
+ }
320
+
321
+ // Some BP nav items contain item counts. Remove them
322
+ $title = preg_replace( '|<span>[0-9]+</span>|', '', $title );
323
+
324
+ return apply_filters( 'bp_modify_page_title', $title . " $sep ", $title, $sep, $seplocation );
325
+ }
326
+ add_filter( 'wp_title', 'bp_modify_page_title', 10, 3 );
327
+ add_filter( 'bp_modify_page_title', 'wptexturize' );
328
+ add_filter( 'bp_modify_page_title', 'convert_chars' );
329
+ add_filter( 'bp_modify_page_title', 'esc_html' );
330
+
331
  ?>
bp-core/bp-core-functions.php ADDED
@@ -0,0 +1,1454 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.
62
+ *
63
+ * @global object $wpdb WordPress database object
64
+ * @return string Filtered database prefix
65
+ */
66
+ function bp_core_get_table_prefix() {
67
+ global $wpdb;
68
+
69
+ return apply_filters( 'bp_core_get_table_prefix', $wpdb->base_prefix );
70
+ }
71
+
72
+ /**
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
+ }
101
+ }
102
+ }
103
+
104
+ return apply_filters( 'bp_core_get_directory_page_ids', $page_ids );
105
+ }
106
+
107
+ /**
108
+ * Stores BP pages in the meta table, depending on setup
109
+ *
110
+ * bp-pages data is stored in site_options (falls back to options on non-MS), in an array keyed by
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
+ */
118
+ function bp_core_update_directory_page_ids( $blog_page_ids ) {
119
+ bp_update_option( 'bp-pages', $blog_page_ids );
120
+ }
121
+
122
+ /**
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
+ $posts_table_name = bp_is_multiblog_mode() ? $wpdb->get_blog_prefix( bp_get_root_blog_id() ) . 'posts' : $wpdb->posts;
140
+ $page_ids_sql = implode( ',', (array)$page_ids );
141
+ $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' " ) );
142
+
143
+ foreach ( (array)$page_ids as $component_id => $page_id ) {
144
+ foreach ( (array)$page_names as $page_name ) {
145
+ if ( $page_name->ID == $page_id ) {
146
+ $pages->{$component_id}->name = $page_name->post_name;
147
+ $pages->{$component_id}->id = $page_name->ID;
148
+ $pages->{$component_id}->title = $page_name->post_title;
149
+ $slug[] = $page_name->post_name;
150
+
151
+ // Get the slug
152
+ while ( $page_name->post_parent != 0 ) {
153
+ $parent = $wpdb->get_results( $wpdb->prepare( "SELECT post_name, post_parent FROM {$posts_table_name} WHERE ID = %d", $page_name->post_parent ) );
154
+ $slug[] = $parent[0]->post_name;
155
+ $page_name->post_parent = $parent[0]->post_parent;
156
+ }
157
+
158
+ $pages->{$component_id}->slug = implode( '/', array_reverse( (array)$slug ) );
159
+ }
160
+
161
+ unset( $slug );
162
+ }
163
+ }
164
+ }
165
+
166
+ return apply_filters( 'bp_core_get_directory_pages', $pages );
167
+ }
168
+
169
+ /**
170
+ * Creates a default component slug from a WP page root_slug
171
+ *
172
+ * Since 1.5, BP components get their root_slug (the slug used immediately
173
+ * following the root domain) from the slug of a corresponding WP page.
174
+ *
175
+ * E.g. if your BP installation at example.com has its members page at
176
+ * example.com/community/people, $bp->members->root_slug will be 'community/people'.
177
+ *
178
+ * By default, this function creates a shorter version of the root_slug for
179
+ * use elsewhere in the URL, by returning the content after the final '/'
180
+ * in the root_slug ('people' in the example above).
181
+ *
182
+ * Filter on 'bp_core_component_slug_from_root_slug' to override this method
183
+ * in general, or define a specific component slug constant (e.g. BP_MEMBERS_SLUG)
184
+ * to override specific component slugs.
185
+ *
186
+ * @package BuddyPress Core
187
+ * @since 1.5
188
+ *
189
+ * @param str $root_slug The root slug, which comes from $bp->pages->[component]->slug
190
+ * @return str $slug The short slug for use in the middle of URLs
191
+ */
192
+ function bp_core_component_slug_from_root_slug( $root_slug ) {
193
+ $slug_chunks = explode( '/', $root_slug );
194
+ $slug = array_pop( $slug_chunks );
195
+
196
+ return apply_filters( 'bp_core_component_slug_from_root_slug', $slug, $root_slug );
197
+ }
198
+
199
+ function bp_core_do_network_admin() {
200
+ $do_network_admin = false;
201
+
202
+ if ( is_multisite() && !bp_is_multiblog_mode() )
203
+ $do_network_admin = true;
204
+
205
+ return apply_filters( 'bp_core_do_network_admin', $do_network_admin );
206
+ }
207
+
208
+ function bp_core_admin_hook() {
209
+ $hook = bp_core_do_network_admin() ? 'network_admin_menu' : 'admin_menu';
210
+
211
+ return apply_filters( 'bp_core_admin_hook', $hook );
212
+ }
213
+
214
+ /**
215
+ * Initializes the wp-admin area "BuddyPress" menus and sub menus.
216
+ *
217
+ * @package BuddyPress Core
218
+ * @uses is_super_admin() returns true if the current user is a site admin, false if not
219
+ */
220
+ function bp_core_admin_menu_init() {
221
+ if ( !is_super_admin() )
222
+ return false;
223
+
224
+ add_action( bp_core_admin_hook(), 'bp_core_add_admin_menu', 9 );
225
+
226
+ require ( BP_PLUGIN_DIR . '/bp-core/admin/bp-core-admin.php' );
227
+ }
228
+ add_action( 'bp_init', 'bp_core_admin_menu_init' );
229
+
230
+ /**
231
+ * Adds the "BuddyPress" admin submenu item to the Site Admin tab.
232
+ *
233
+ * @package BuddyPress Core
234
+ * @global object $bp Global BuddyPress settings object
235
+ * @uses is_super_admin() returns true if the current user is a site admin, false if not
236
+ * @uses add_submenu_page() WP function to add a submenu item
237
+ */
238
+ function bp_core_add_admin_menu() {
239
+ if ( !is_super_admin() )
240
+ return false;
241
+
242
+ // Don't add this version of the admin menu if a BP upgrade is in progress
243
+ // See bp_core_update_add_admin_menu()
244
+ if ( defined( 'BP_IS_UPGRADE' ) && BP_IS_UPGRADE )
245
+ return false;
246
+
247
+ $hooks = array();
248
+
249
+ // Add the administration tab under the "Site Admin" tab for site administrators
250
+ $hooks[] = add_menu_page( __( 'BuddyPress', 'buddypress' ), __( 'BuddyPress', 'buddypress' ), 'manage_options', 'bp-general-settings', 'bp_core_admin_component_setup', '' );
251
+ $hooks[] = add_submenu_page( 'bp-general-settings', __( 'Components', 'buddypress' ), __( 'Components', 'buddypress' ), 'manage_options', 'bp-general-settings', 'bp_core_admin_component_setup' );
252
+ $hooks[] = add_submenu_page( 'bp-general-settings', __( 'Pages', 'buddypress' ), __( 'Pages', 'buddypress' ), 'manage_options', 'bp-page-settings', 'bp_core_admin_page_setup' );
253
+ $hooks[] = add_submenu_page( 'bp-general-settings', __( 'Settings', 'buddypress' ), __( 'Settings', 'buddypress' ), 'manage_options', 'bp-settings', 'bp_core_admin_settings' );
254
+
255
+ // Add a hook for css/js
256
+ foreach( $hooks as $hook )
257
+ add_action( "admin_print_styles-$hook", 'bp_core_add_admin_menu_styles' );
258
+ }
259
+
260
+ /**
261
+ * Print admin messages to admin_notices or network_admin_notices
262
+ *
263
+ * BuddyPress combines all its messages into a single notice, to avoid a preponderance of yellow
264
+ * boxes.
265
+ *
266
+ * @package BuddyPress Core
267
+ * @since 1.5
268
+ *
269
+ * @global object $bp Global BuddyPress settings object
270
+ * @uses is_super_admin() to check current user permissions before showing the notices
271
+ * @uses bp_is_root_blog()
272
+ */
273
+ function bp_core_print_admin_notices() {
274
+ global $bp;
275
+
276
+ // Only the super admin should see messages
277
+ if ( !is_super_admin() )
278
+ return;
279
+
280
+ // On multisite installs, don't show on the Site Admin of a non-root blog, unless
281
+ // do_network_admin is overridden
282
+ if ( is_multisite() && bp_core_do_network_admin() && !bp_is_root_blog() )
283
+ return;
284
+
285
+ // Show the messages
286
+ if ( !empty( $bp->admin->notices ) ) {
287
+ ?>
288
+ <div id="message" class="updated fade">
289
+ <?php foreach( $bp->admin->notices as $notice ) : ?>
290
+ <p><?php echo $notice ?></p>
291
+ <?php endforeach ?>
292
+ </div>
293
+ <?php
294
+ }
295
+ }
296
+ add_action( 'admin_notices', 'bp_core_print_admin_notices' );
297
+ add_action( 'network_admin_notices', 'bp_core_print_admin_notices' );
298
+
299
+ /**
300
+ * Add an admin notice to the BP queue
301
+ *
302
+ * Messages added with this function are displayed in BuddyPress's general purpose admin notices
303
+ * box. It is recommended that you hook this function to admin_init, so that your messages are
304
+ * loaded in time.
305
+ *
306
+ * @package BuddyPress Core
307
+ * @since 1.5
308
+ *
309
+ * @global object $bp Global BuddyPress settings object
310
+ * @param string $notice The notice you are adding to the queue
311
+ */
312
+ function bp_core_add_admin_notice( $notice ) {
313
+ global $bp;
314
+
315
+ if ( empty( $bp->admin->notices ) ) {
316
+ $bp->admin->notices = array();
317
+ }
318
+
319
+ $bp->admin->notices[] = $notice;
320
+ }
321
+
322
+ /**
323
+ * Verify that some BP prerequisites are set up properly, and notify the admin if not
324
+ *
325
+ * On every Dashboard page, this function checks the following:
326
+ * - that pretty permalinks are enabled
327
+ * - that a BP-compatible theme is activated
328
+ * - that every BP component that needs a WP page for a directory has one
329
+ * - that no WP page has multiple BP components associated with it
330
+ * The administrator will be shown a notice for each check that fails.
331
+ *
332
+ * @package BuddyPress Core
333
+ */
334
+ function bp_core_activation_notice() {
335
+ global $wp_rewrite, $wpdb, $bp;
336
+
337
+ // Only the super admin gets warnings
338
+ if ( !is_super_admin() )
339
+ return;
340
+
341
+ // On multisite installs, don't load on a non-root blog, unless do_network_admin is
342
+ // overridden
343
+ if ( is_multisite() && bp_core_do_network_admin() && !bp_is_root_blog() )
344
+ return;
345
+
346
+ // Don't show these messages during setup or upgrade
347
+ if ( isset( $bp->maintenance_mode ) )
348
+ return;
349
+
350
+ /**
351
+ * Check to make sure that the blog setup routine has run. This can't happen during the
352
+ * wizard because of the order which the components are loaded. We check for multisite here
353
+ * on the off chance that someone has activated the blogs component and then disabled MS
354
+ */
355
+ if ( bp_is_active( 'blogs' ) ) {
356
+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$bp->blogs->table_name}" ) );
357
+
358
+ if ( !$count )
359
+ bp_blogs_record_existing_blogs();
360
+ }
361
+
362
+ /**
363
+ * Are pretty permalinks enabled?
364
+ */
365
+ if ( isset( $_POST['permalink_structure'] ) )
366
+ return false;
367
+
368
+ if ( empty( $wp_rewrite->permalink_structure ) ) {
369
+ 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' ) ) );
370
+ }
371
+
372
+ /**
373
+ * Are you using a BP-compatible theme?
374
+ */
375
+
376
+ // Get current theme info
377
+ $ct = current_theme_info();
378
+
379
+ // The best way to remove this notice is to add a "buddypress" tag to
380
+ // your active theme's CSS header.
381
+ if ( !defined( 'BP_SILENCE_THEME_NOTICE' ) && !in_array( 'buddypress', (array)$ct->tags ) ) {
382
+ 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' ) ) );
383
+ }
384
+
385
+ /**
386
+ * Check for orphaned BP components (BP component is enabled, no WP page exists)
387
+ */
388
+
389
+ $orphaned_components = array();
390
+ $wp_page_components = array();
391
+
392
+ // Only components with 'has_directory' require a WP page to function
393
+ foreach( $bp->loaded_components as $component_id => $is_active ) {
394
+ if ( !empty( $bp->{$component_id}->has_directory ) ) {
395
+ $wp_page_components[] = array(
396
+ 'id' => $component_id,
397
+ 'name' => isset( $bp->{$component_id}->name ) ? $bp->{$component_id}->name : ucwords( $bp->{$component_id}->id )
398
+ );
399
+ }
400
+ }
401
+
402
+ // Activate and Register are special cases. They are not components but they need WP pages.
403
+ // If user registration is disabled, we can skip this step.
404
+ if ( bp_get_signup_allowed() ) {
405
+ $wp_page_components[] = array(
406
+ 'id' => 'activate',
407
+ 'name' => __( 'Activate', 'buddypress' )
408
+ );
409
+
410
+ $wp_page_components[] = array(
411
+ 'id' => 'register',
412
+ 'name' => __( 'Register', 'buddypress' )
413
+ );
414
+ }
415
+
416
+ foreach( $wp_page_components as $component ) {
417
+ if ( !isset( $bp->pages->{$component['id']} ) ) {
418
+ $orphaned_components[] = $component['name'];
419
+ }
420
+ }
421
+
422
+ if ( !empty( $orphaned_components ) ) {
423
+ $admin_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) );
424
+ $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>' );
425
+
426
+ bp_core_add_admin_notice( $notice );
427
+ }
428
+
429
+ /**
430
+ * BP components cannot share a single WP page. Check for duplicate assignments, and post
431
+ * a message if found.
432
+ */
433
+ $dupe_names = array();
434
+ $page_ids = (array)bp_core_get_directory_page_ids();
435
+ $dupes = array_diff_assoc( $page_ids, array_unique( $page_ids ) );
436
+
437
+ if ( !empty( $dupes ) ) {
438
+ foreach( $dupes as $dupe_component => $dupe_id ) {
439
+ $dupe_names[] = $bp->pages->{$dupe_component}->title;
440
+ }
441
+
442
+ // Make sure that there are no duplicate duplicates :)
443
+ $dupe_names = array_unique( $dupe_names );
444
+ }
445
+
446
+ // If there are duplicates, post a message about them
447
+ if ( !empty( $dupe_names ) ) {
448
+ $admin_url = bp_get_admin_url( add_query_arg( array( 'page' => 'bp-page-settings' ), 'admin.php' ) );
449
+ $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>' );
450
+
451
+ bp_core_add_admin_notice( $notice );
452
+ }
453
+ }
454
+ add_action( 'admin_init', 'bp_core_activation_notice' );
455
+
456
+ /**
457
+ * Returns the domain for the root blog.
458
+ * eg: http://domain.com/ OR https://domain.com
459
+ *
460
+ * @package BuddyPress Core
461
+ * @uses get_blog_option() WordPress function to fetch blog meta.
462
+ * @return $domain The domain URL for the blog.
463
+ */
464
+ function bp_core_get_root_domain() {
465
+ global $wpdb;
466
+
467
+ $domain = get_home_url( bp_get_root_blog_id() );
468
+
469
+ return apply_filters( 'bp_core_get_root_domain', $domain );
470
+ }
471
+
472
+ /**
473
+ * Get the current GMT time to save into the DB
474
+ *
475
+ * @package BuddyPress Core
476
+ * @since 1.2.6
477
+ */
478
+ function bp_core_current_time( $gmt = true ) {
479
+ // Get current time in MYSQL format
480
+ $current_time = current_time( 'mysql', $gmt );
481
+
482
+ return apply_filters( 'bp_core_current_time', $current_time );
483
+ }
484
+
485
+ /**
486
+ * Adds a feedback (error/success) message to the WP cookie so it can be
487
+ * displayed after the page reloads.
488
+ *
489
+ * @package BuddyPress Core
490
+ *
491
+ * @global obj $bp
492
+ * @param str $message Feedback to give to user
493
+ * @param str $type updated|success|error|warning
494
+ */
495
+ function bp_core_add_message( $message, $type = '' ) {
496
+ global $bp;
497
+
498
+ // Success is the default
499
+ if ( empty( $type ) )
500
+ $type = 'success';
501
+
502
+ // Send the values to the cookie for page reload display
503
+ @setcookie( 'bp-message', $message, time() + 60 * 60 * 24, COOKIEPATH );
504
+ @setcookie( 'bp-message-type', $type, time() + 60 * 60 * 24, COOKIEPATH );
505
+
506
+ /***
507
+ * Send the values to the $bp global so we can still output messages
508
+ * without a page reload
509
+ */
510
+ $bp->template_message = $message;
511
+ $bp->template_message_type = $type;
512
+ }
513
+
514
+ /**
515
+ * Checks if there is a feedback message in the WP cookie, if so, adds a
516
+ * "template_notices" action so that the message can be parsed into the template
517
+ * and displayed to the user.
518
+ *
519
+ * After the message is displayed, it removes the message vars from the cookie
520
+ * so that the message is not shown to the user multiple times.
521
+ *
522
+ * @package BuddyPress Core
523
+ * @global $bp_message The message text
524
+ * @global $bp_message_type The type of message (error/success)
525
+ * @uses setcookie() Sets a cookie value for the user.
526
+ */
527
+ function bp_core_setup_message() {
528
+ global $bp;
529
+
530
+ if ( empty( $bp->template_message ) && isset( $_COOKIE['bp-message'] ) )
531
+ $bp->template_message = $_COOKIE['bp-message'];
532
+
533
+ if ( empty( $bp->template_message_type ) && isset( $_COOKIE['bp-message-type'] ) )
534
+ $bp->template_message_type = $_COOKIE['bp-message-type'];
535
+
536
+ add_action( 'template_notices', 'bp_core_render_message' );
537
+
538
+ @setcookie( 'bp-message', false, time() - 1000, COOKIEPATH );
539
+ @setcookie( 'bp-message-type', false, time() - 1000, COOKIEPATH );
540
+ }
541
+ add_action( 'bp_actions', 'bp_core_setup_message', 5 );
542
+
543
+ /**
544
+ * Renders a feedback message (either error or success message) to the theme template.
545
+ * The hook action 'template_notices' is used to call this function, it is not called directly.
546
+ *
547
+ * @package BuddyPress Core
548
+ * @global object $bp Global BuddyPress settings object
549
+ */
550
+ function bp_core_render_message() {
551
+ global $bp;
552
+
553
+ if ( isset( $bp->template_message ) && $bp->template_message ) :
554
+ $type = ( 'success' == $bp->template_message_type ) ? 'updated' : 'error'; ?>
555
+
556
+ <div id="message" class="<?php echo $type; ?>">
557
+ <p><?php echo stripslashes( esc_attr( $bp->template_message ) ); ?></p>
558
+ </div>
559
+
560
+ <?php
561
+
562
+ do_action( 'bp_core_render_message' );
563
+
564
+ endif;
565
+ }
566
+
567
+ /**
568
+ * Format numbers the BuddyPress way
569
+ *
570
+ * @param str $number
571
+ * @param bool $decimals
572
+ * @return str
573
+ */
574
+ function bp_core_number_format( $number, $decimals = false ) {
575
+ // Check we actually have a number first.
576
+ if ( empty( $number ) )
577
+ return $number;
578
+
579
+ return apply_filters( 'bp_core_number_format', number_format( $number, $decimals ), $number, $decimals );
580
+ }
581
+
582
+ /**
583
+ * Based on function created by Dunstan Orchard - http://1976design.com
584
+ *
585
+ * This function will return an English representation of the time elapsed
586
+ * since a given date.
587
+ * eg: 2 hours and 50 minutes
588
+ * eg: 4 days
589
+ * eg: 4 weeks and 6 days
590
+ *
591
+ * @package BuddyPress Core
592
+ * @param $older_date int Unix timestamp of date you want to calculate the time since for
593
+ * @param $newer_date int Unix timestamp of date to compare older date to. Default false (current time).
594
+ * @return str The time since.
595
+ */
596
+ function bp_core_time_since( $older_date, $newer_date = false ) {
597
+
598
+ // Setup the strings
599
+ $unknown_text = apply_filters( 'bp_core_time_since_unknown_text', __( 'sometime', 'buddypress' ) );
600
+ $right_now_text = apply_filters( 'bp_core_time_since_right_now_text', __( 'right now', 'buddypress' ) );
601
+ $ago_text = apply_filters( 'bp_core_time_since_ago_text', __( '%s ago', 'buddypress' ) );
602
+
603
+ // array of time period chunks
604
+ $chunks = array(
605
+ array( 60 * 60 * 24 * 365 , __( 'year', 'buddypress' ), __( 'years', 'buddypress' ) ),
606
+ array( 60 * 60 * 24 * 30 , __( 'month', 'buddypress' ), __( 'months', 'buddypress' ) ),
607
+ array( 60 * 60 * 24 * 7, __( 'week', 'buddypress' ), __( 'weeks', 'buddypress' ) ),
608
+ array( 60 * 60 * 24 , __( 'day', 'buddypress' ), __( 'days', 'buddypress' ) ),
609
+ array( 60 * 60 , __( 'hour', 'buddypress' ), __( 'hours', 'buddypress' ) ),
610
+ array( 60 , __( 'minute', 'buddypress' ), __( 'minutes', 'buddypress' ) ),
611
+ array( 1, __( 'second', 'buddypress' ), __( 'seconds', 'buddypress' ) )
612
+ );
613
+
614
+ if ( !empty( $older_date ) && !is_numeric( $older_date ) ) {
615
+ $time_chunks = explode( ':', str_replace( ' ', ':', $older_date ) );
616
+ $date_chunks = explode( '-', str_replace( ' ', '-', $older_date ) );
617
+ $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] );
618
+ }
619
+
620
+ /**
621
+ * $newer_date will equal false if we want to know the time elapsed between
622
+ * a date and the current time. $newer_date will have a value if we want to
623
+ * work out time elapsed between two known dates.
624
+ */
625
+ $newer_date = ( !$newer_date ) ? strtotime( bp_core_current_time() ) : $newer_date;
626
+
627
+ // Difference in seconds
628
+ $since = $newer_date - $older_date;
629
+
630
+ // Something went wrong with date calculation and we ended up with a negative date.
631
+ if ( 0 > $since ) {
632
+ $output = $unknown_text;
633
+
634
+ /**
635
+ * We only want to output two chunks of time here, eg:
636
+ * x years, xx months
637
+ * x days, xx hours
638
+ * so there's only two bits of calculation below:
639
+ */
640
+ } else {
641
+
642
+ // Step one: the first chunk
643
+ for ( $i = 0, $j = count( $chunks ); $i < $j; ++$i ) {
644
+ $seconds = $chunks[$i][0];
645
+
646
+ // Finding the biggest chunk (if the chunk fits, break)
647
+ if ( ( $count = floor($since / $seconds) ) != 0 ) {
648
+ break;
649
+ }
650
+ }
651
+
652
+ // If $i iterates all the way to $j, then the event happened 0 seconds ago
653
+ if ( !isset( $chunks[$i] ) ) {
654
+ $output = $right_now_text;
655
+
656
+ } else {
657
+
658
+ // Set output var
659
+ $output = ( 1 == $count ) ? '1 '. $chunks[$i][1] : $count . ' ' . $chunks[$i][2];
660
+
661
+ // Step two: the second chunk
662
+ if ( $i + 2 < $j ) {
663
+ $seconds2 = $chunks[$i + 1][0];
664
+ $name2 = $chunks[$i + 1][1];
665
+
666
+ if ( ( $count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 ) ) != 0 ) {
667
+ // Add to output var
668
+ $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];
669
+ }
670
+ }
671
+
672
+ // No output, so happened right now
673
+ if ( !(int)trim( $output ) ) {
674
+ $output = $right_now_text;
675
+ }
676
+ }
677
+ }
678
+
679
+ // Append 'ago' to the end of time-since if not 'right now'
680
+ if ( $output != $right_now_text ) {
681
+ $output = sprintf( $ago_text, $output );
682
+ }
683
+
684
+ return $output;
685
+ }
686
+
687
+ /**
688
+ * Record user activity to the database. Many functions use a "last active" feature to
689
+ * show the length of time since the user was last active.
690
+ * This function will update that time as a usermeta setting for the user every 5 minutes.
691
+ *
692
+ * @package BuddyPress Core
693
+ * @global $userdata WordPress user data for the current logged in user.
694
+ * @uses bp_update_user_meta() BP function to update user metadata in the usermeta table.
695
+ */
696
+ function bp_core_record_activity() {
697
+ global $bp;
698
+
699
+ if ( !is_user_logged_in() )
700
+ return false;
701
+
702
+ $user_id = $bp->loggedin_user->id;
703
+
704
+ if ( bp_core_is_user_spammer( $user_id ) || bp_core_is_user_deleted( $user_id ) )
705
+ return false;
706
+
707
+ $activity = bp_get_user_meta( $user_id, 'last_activity', true );
708
+
709
+ if ( !is_numeric( $activity ) )
710
+ $activity = strtotime( $activity );
711
+
712
+ // Get current time
713
+ $current_time = bp_core_current_time();
714
+
715
+ if ( empty( $activity ) || strtotime( $current_time ) >= strtotime( '+5 minutes', $activity ) )
716
+ bp_update_user_meta( $user_id, 'last_activity', $current_time );
717
+ }
718
+ add_action( 'wp_head', 'bp_core_record_activity' );
719
+
720
+ /**
721
+ * Formats last activity based on time since date given.
722
+ *
723
+ * @package BuddyPress Core
724
+ * @param last_activity_date The date of last activity.
725
+ * @param $before The text to prepend to the activity time since figure.
726
+ * @param $after The text to append to the activity time since figure.
727
+ * @uses bp_core_time_since() This function will return an English representation of the time elapsed.
728
+ */
729
+ function bp_core_get_last_activity( $last_activity_date, $string ) {
730
+ if ( !$last_activity_date || empty( $last_activity_date ) )
731
+ $last_active = __( 'not recently active', 'buddypress' );
732
+ else
733
+ $last_active = sprintf( $string, bp_core_time_since( $last_activity_date ) );
734
+
735
+ return apply_filters( 'bp_core_get_last_activity', $last_active, $last_activity_date, $string );
736
+ }
737
+
738
+ /**
739
+ * Get the path of of the current site.
740
+ *
741
+ * @package BuddyPress Core
742
+ *
743
+ * @global $bp $bp
744
+ * @global object $current_site
745
+ * @return string
746
+ */
747
+ function bp_core_get_site_path() {
748
+ global $bp, $current_site;
749
+
750
+ if ( is_multisite() )
751
+ $site_path = $current_site->path;
752
+ else {
753
+ $site_path = (array) explode( '/', home_url() );
754
+
755
+ if ( count( $site_path ) < 2 )
756
+ $site_path = '/';
757
+ else {
758
+ // Unset the first three segments (http(s)://domain.com part)
759
+ unset( $site_path[0] );
760
+ unset( $site_path[1] );
761
+ unset( $site_path[2] );
762
+
763
+ if ( !count( $site_path ) )
764
+ $site_path = '/';
765
+ else
766
+ $site_path = '/' . implode( '/', $site_path ) . '/';
767
+ }
768
+ }
769
+
770
+ return apply_filters( 'bp_core_get_site_path', $site_path );
771
+ }
772
+
773
+ /**
774
+ * Performs a status safe wp_redirect() that is compatible with bp_catch_uri()
775
+ *
776
+ * @package BuddyPress Core
777
+ * @global $bp_no_status_set Makes sure that there are no conflicts with status_header() called in bp_core_do_catch_uri()
778
+ * @uses get_themes()
779
+ * @return An array containing all of the themes.
780
+ */
781
+ function bp_core_redirect( $location, $status = 302 ) {
782
+ global $bp_no_status_set;
783
+
784
+ // Make sure we don't call status_header() in bp_core_do_catch_uri()
785
+ // as this conflicts with wp_redirect()
786
+ $bp_no_status_set = true;
787
+
788
+ wp_redirect( $location, $status );
789
+ die;
790
+ }
791
+
792
+ /**
793
+ * Returns the referrer URL without the http(s)://
794
+ *
795
+ * @package BuddyPress Core
796
+ * @return The referrer URL
797
+ */
798
+ function bp_core_referrer() {
799
+ $referer = explode( '/', wp_get_referer() );
800
+ unset( $referer[0], $referer[1], $referer[2] );
801
+ return implode( '/', $referer );
802
+ }
803
+
804
+ /**
805
+ * Adds illegal names to WP so that root components will not conflict with
806
+ * blog names on a subdirectory installation.
807
+ *
808
+ * For example, it would stop someone creating a blog with the slug "groups".
809
+ */
810
+ function bp_core_add_illegal_names() {
811
+ update_site_option( 'illegal_names', get_site_option( 'illegal_names' ), array() );
812
+ }
813
+
814
+ /**
815
+ * A javascript free implementation of the search functions in BuddyPress
816
+ *
817
+ * @package BuddyPress Core
818
+ * @global object $bp Global BuddyPress settings object
819
+ * @param string $slug The slug to redirect to for searching.
820
+ */
821
+ function bp_core_action_search_site( $slug = '' ) {
822
+ global $bp;
823
+
824
+ if ( !bp_is_current_component( bp_get_search_slug() ) )
825
+ return;
826
+
827
+ if ( empty( $_POST['search-terms'] ) ) {
828
+ bp_core_redirect( bp_get_root_domain() );
829
+ return;
830
+ }
831
+
832
+ $search_terms = stripslashes( $_POST['search-terms'] );
833
+ $search_which = !empty( $_POST['search-which'] ) ? $_POST['search-which'] : '';
834
+ $query_string = '/?s=';
835
+
836
+ if ( empty( $slug ) ) {
837
+ switch ( $search_which ) {
838
+ case 'posts':
839
+ $slug = '';
840
+ $var = '/?s=';
841
+ break;
842
+
843
+ case 'blogs':
844
+ $slug = bp_is_active( 'blogs' ) ? bp_get_blogs_root_slug() : '';
845
+ break;
846
+
847
+ case 'forums':
848
+ $slug = bp_is_active( 'forums' ) ? bp_get_forums_root_slug() : '';
849
+ $query_string = '/?fs=';
850
+ break;
851
+
852
+ case 'groups':
853
+ $slug = bp_is_active( 'groups' ) ? bp_get_groups_root_slug() : '';
854
+ break;
855
+
856
+ case 'members':
857
+ default:
858
+ $slug = bp_get_members_root_slug();
859
+ break;
860
+ }
861
+
862
+ if ( empty( $slug ) && 'posts' != $search_which ) {
863
+ bp_core_redirect( bp_get_root_domain() );
864
+ return;
865
+ }
866
+ }
867
+
868
+ bp_core_redirect( apply_filters( 'bp_core_search_site', home_url( $slug . $query_string . urlencode( $search_terms ) ), $search_terms ) );
869
+ }
870
+ add_action( 'bp_init', 'bp_core_action_search_site', 7 );
871
+
872
+ /**
873
+ * Prints the generation time in the footer of the site.
874
+ *
875
+ * @package BuddyPress Core
876
+ */
877
+ function bp_core_print_generation_time() {
878
+ ?>
879
+
880
+ <!-- Generated in <?php timer_stop(1); ?> seconds. (<?php echo get_num_queries(); ?> q) -->
881
+
882
+ <?php
883
+ }
884
+ add_action( 'wp_footer', 'bp_core_print_generation_time' );
885
+
886
+ /**
887
+ * Load the buddypress translation file for current language
888
+ *
889
+ * @package BuddyPress Core
890
+ */
891
+ function bp_core_load_buddypress_textdomain() {
892
+ $locale = apply_filters( 'buddypress_locale', get_locale() );
893
+ $mofile = sprintf( 'buddypress-%s.mo', $locale );
894
+ $mofile_global = WP_LANG_DIR . '/' . $mofile;
895
+ $mofile_local = BP_PLUGIN_DIR . '/bp-languages/' . $mofile;
896
+
897
+ if ( file_exists( $mofile_global ) )
898
+ return load_textdomain( 'buddypress', $mofile_global );
899
+ elseif ( file_exists( $mofile_local ) )
900
+ return load_textdomain( 'buddypress', $mofile_local );
901
+ else
902
+ return false;
903
+ }
904
+ add_action ( 'bp_init', 'bp_core_load_buddypress_textdomain', 2 );
905
+
906
+ function bp_core_add_ajax_hook() {
907
+ // Theme only, we already have the wp_ajax_ hook firing in wp-admin
908
+ if ( !defined( 'WP_ADMIN' ) && isset( $_REQUEST['action'] ) )
909
+ do_action( 'wp_ajax_' . $_REQUEST['action'] );
910
+ }
911
+ add_action( 'bp_init', 'bp_core_add_ajax_hook' );
912
+
913
+ /**
914
+ * Initializes {@link BP_Embed} after everything is loaded.
915
+ *
916
+ * @global object $bp BuddyPress global settings
917
+ * @package BuddyPress Core
918
+ * @since 1.5
919
+ */
920
+ function bp_embed_init() {
921
+ global $bp;
922
+
923
+ if ( empty( $bp->embed ) )
924
+ $bp->embed = new BP_Embed();
925
+ }
926
+ add_action( 'bp_init', 'bp_embed_init', 9 );
927
+
928
+ /**
929
+ * When switching from single to multisite we need to copy blog options to
930
+ * site options.
931
+ *
932
+ * @package BuddyPress Core
933
+ * @todo Does this need to be here anymore after the introduction of bp_get_option etc?
934
+ */
935
+ function bp_core_activate_site_options( $keys = array() ) {
936
+ global $bp;
937
+
938
+ if ( !empty( $keys ) && is_array( $keys ) ) {
939
+ $errors = false;
940
+
941
+ foreach ( $keys as $key => $default ) {
942
+ if ( empty( $bp->site_options[ $key ] ) ) {
943
+ $bp->site_options[ $key ] = bp_get_option( $key, $default );
944
+
945
+ if ( !bp_update_option( $key, $bp->site_options[ $key ] ) )
946
+ $errors = true;
947
+ }
948
+ }
949
+
950
+ if ( empty( $errors ) )
951
+ return true;
952
+ }
953
+
954
+ return false;
955
+ }
956
+
957
+ /**
958
+ * BuddyPress uses common options to store configuration settings. Many of these
959
+ * settings are needed at run time. Instead of fetching them all and adding many
960
+ * initial queries to each page load, let's fetch them all in one go.
961
+ *
962
+ * @package BuddyPress Core
963
+ * @todo Use settings API and audit these methods
964
+ */
965
+ function bp_core_get_root_options() {
966
+ global $wpdb;
967
+
968
+ // These options come from the root blog options table
969
+ $root_blog_options = apply_filters( 'bp_core_site_options', array(
970
+
971
+ // BuddyPress core settings
972
+ 'bp-deactivated-components' => serialize( array( ) ),
973
+ 'bp-blogs-first-install' => '0',
974
+ 'bp-disable-blog-forum-comments' => '0',
975
+ 'bp-xprofile-base-group-name' => 'Base',
976
+ 'bp-xprofile-fullname-field-name' => 'Name',
977
+ 'bp-disable-profile-sync' => '0',
978
+ 'bp-disable-avatar-uploads' => '0',
979
+ 'bp-disable-account-deletion' => '0',
980
+ 'bp-disable-blogforum-comments' => '0',
981
+ 'bb-config-location' => ABSPATH,
982
+ 'hide-loggedout-adminbar' => '0',
983
+
984
+ // Useful WordPress settings
985
+ 'registration' => '0',
986
+ 'avatar_default' => 'mysteryman'
987
+ ) );
988
+
989
+ $root_blog_option_keys = array_keys( $root_blog_options );
990
+ $blog_options_keys = "'" . join( "', '", (array) $root_blog_option_keys ) . "'";
991
+ $blog_options_query = $wpdb->prepare( "SELECT option_name AS name, option_value AS value FROM {$wpdb->options} WHERE option_name IN ( {$blog_options_keys} )" );
992
+ $root_blog_options_meta = $wpdb->get_results( $blog_options_query );
993
+
994
+ // On Multisite installations, some options must always be fetched from sitemeta
995
+ if ( is_multisite() ) {
996
+ $network_options = apply_filters( 'bp_core_network_options', array(
997
+ 'tags_blog_id' => '0',
998
+ 'registration' => '0',
999
+ 'fileupload_maxk' => '1500'
1000
+ ) );
1001
+
1002
+ $current_site = get_current_site();
1003
+ $network_option_keys = array_keys( $network_options );
1004
+ $sitemeta_options_keys = "'" . join( "', '", (array) $network_option_keys ) . "'";
1005
+ $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 );
1006
+ $network_options_meta = $wpdb->get_results( $sitemeta_options_query );
1007
+
1008
+ // Sitemeta comes second in the merge, so that network 'registration' value wins
1009
+ $root_blog_options_meta = array_merge( $root_blog_options_meta, $network_options_meta );
1010
+ }
1011
+
1012
+ // Missing some options, so do some one-time fixing
1013
+ if ( empty( $root_blog_options_meta ) || ( count( $root_blog_options_meta ) < count( $root_blog_option_keys ) ) ) {
1014
+
1015
+ // Unset the query - We'll be resetting it soon
1016
+ unset( $root_blog_options_meta );
1017
+
1018
+ // Loop through options
1019
+ foreach ( $root_blog_options as $old_meta_key => $old_meta_default ) {
1020
+ // Clear out the value from the last time around
1021
+ unset( $old_meta_value );
1022
+
1023
+ // Get old site option
1024
+ if ( is_multisite() )
1025
+ $old_meta_value = get_site_option( $old_meta_key );
1026
+
1027
+ // No site option so look in root blog
1028
+ if ( empty( $old_meta_value ) )
1029
+ $old_meta_value = bp_get_option( $old_meta_key, $old_meta_default );
1030
+
1031
+ // Update the root blog option
1032
+ bp_update_option( $old_meta_key, $old_meta_value );
1033
+
1034
+ // Update the global array
1035
+ $root_blog_options_meta[$old_meta_key] = $old_meta_value;
1036
+ }
1037
+
1038
+ // We're all matched up
1039
+ } else {
1040
+ // Loop through our results and make them usable
1041
+ foreach ( $root_blog_options_meta as $root_blog_option )
1042
+ $root_blog_options[$root_blog_option->name] = $root_blog_option->value;
1043
+
1044
+ // Copy the options no the return val
1045
+ $root_blog_options_meta = $root_blog_options;
1046
+
1047
+ // Clean up our temporary copy
1048
+ unset( $root_blog_options );
1049
+ }
1050
+
1051
+ return apply_filters( 'bp_core_get_root_options', $root_blog_options_meta );
1052
+ }
1053
+
1054
+ /**
1055
+ * This function originally let plugins add support for pages in the root of the install.
1056
+ * These root level pages are now handled by actual WordPress pages and this function is now
1057
+ * a convenience for compatibility with the new method.
1058
+ *
1059
+ * @global $bp BuddyPress global settings
1060
+ * @param $slug str The slug of the component
1061
+ */
1062
+ function bp_core_add_root_component( $slug ) {
1063
+ global $bp;
1064
+
1065
+ if ( empty( $bp->pages ) )
1066
+ $bp->pages = bp_core_get_directory_pages();
1067
+
1068
+ $match = false;
1069
+
1070
+ // Check if the slug is registered in the $bp->pages global
1071
+ foreach ( (array)$bp->pages as $key => $page ) {
1072
+ if ( $key == $slug || $page->slug == $slug )
1073
+ $match = true;
1074
+ }
1075
+
1076
+ // If there was no match, add a page for this root component
1077
+ if ( empty( $match ) ) {
1078
+ $bp->add_root[] = $slug;
1079
+ }
1080
+
1081
+ // Make sure that this component is registered as requiring a top-level directory
1082
+ if ( isset( $bp->{$slug} ) ) {
1083
+ $bp->loaded_components[$bp->{$slug}->slug] = $bp->{$slug}->id;
1084
+ $bp->{$slug}->has_directory = true;
1085
+ }
1086
+ }
1087
+
1088
+ function bp_core_create_root_component_page() {
1089
+ global $bp;
1090
+
1091
+ $new_page_ids = array();
1092
+
1093
+ foreach ( (array)$bp->add_root as $slug )
1094
+ $new_page_ids[$slug] = wp_insert_post( array( 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_title' => ucwords( $slug ), 'post_status' => 'publish', 'post_type' => 'page' ) );
1095
+
1096
+ $page_ids = array_merge( (array) $new_page_ids, (array) bp_core_get_directory_page_ids() );
1097
+ bp_core_update_directory_page_ids( $page_ids );
1098
+ }
1099
+
1100
+ /**
1101
+ * Is this the root blog ID?
1102
+ *
1103
+ * @package BuddyPress
1104
+ * @since 1.5
1105
+ *
1106
+ * @param int $blog_id Optional. Defaults to the current blog id.
1107
+ * @return bool $is_root_blog Returns true if this is bp_get_root_blog_id().
1108
+ */
1109
+ function bp_is_root_blog( $blog_id = 0 ) {
1110
+ // Assume false
1111
+ $is_root_blog = false;
1112
+
1113
+ // Use current blog if no ID is passed
1114
+ if ( empty( $blog_id ) )
1115
+ $blog_id = get_current_blog_id();
1116
+
1117
+ // Compare to root blog ID
1118
+ if ( $blog_id == bp_get_root_blog_id() )
1119
+ $is_root_blog = true;
1120
+
1121
+ return apply_filters( 'bp_is_root_blog', (bool) $is_root_blog );
1122
+ }
1123
+
1124
+ /**
1125
+ * Is this bp_get_root_blog_id()?
1126
+ *
1127
+ * @package BuddyPress
1128
+ * @since 1.5
1129
+ *
1130
+ * @param int $blog_id Optional. Defaults to the current blog id.
1131
+ * @return bool $is_root_blog Returns true if this is bp_get_root_blog_id().
1132
+ */
1133
+ function bp_get_root_blog_id( $blog_id = false ) {
1134
+
1135
+ // Define on which blog ID BuddyPress should run
1136
+ if ( !defined( 'BP_ROOT_BLOG' ) ) {
1137
+
1138
+ // Root blog is the main site on this network
1139
+ if ( is_multisite() && !bp_is_multiblog_mode() ) {
1140
+ $current_site = get_current_site();
1141
+ $root_blog_id = $current_site->blog_id;
1142
+
1143
+ // Root blog is whatever the current site is (could be any site on the network)
1144
+ } elseif ( is_multisite() && bp_is_multiblog_mode() ) {
1145
+ $root_blog_id = get_current_blog_id();
1146
+
1147
+ // Root blog is the only blog on this network
1148
+ } elseif( !is_multisite() ) {
1149
+ $root_blog_id = 1;
1150
+ }
1151
+
1152
+ define( 'BP_ROOT_BLOG', $root_blog_id );
1153
+
1154
+ // Root blog is defined
1155
+ } else {
1156
+ $root_blog_id = BP_ROOT_BLOG;
1157
+ }
1158
+
1159
+ return apply_filters( 'bp_get_root_blog_id', (int) $root_blog_id );
1160
+ }
1161
+
1162
+ /**
1163
+ * Get the meta_key for a given piece of user metadata
1164
+ *
1165
+ * BuddyPress stores a number of pieces of userdata in the WordPress central usermeta table. In
1166
+ * order to allow plugins to enable multiple instances of BuddyPress on a single WP installation,
1167
+ * BP's usermeta keys are filtered with this function, so that they can be altered on the fly.
1168
+ *
1169
+ * Plugin authors should use BP's _user_meta() functions, which bakes in bp_get_user_meta_key().
1170
+ * $last_active = bp_get_user_meta( $user_id, 'last_activity', true );
1171
+ * If you have to use WP's _user_meta() functions for some reason, you should use this function, eg
1172
+ * $last_active = get_user_meta( $user_id, bp_get_user_meta_key( 'last_activity' ), true );
1173
+ * If using the WP functions, do not not hardcode your meta keys.
1174
+ *
1175
+ * @package BuddyPress
1176
+ * @since 1.5
1177
+ *
1178
+ * @uses apply_filters() Filter bp_get_user_meta_key to modify keys individually
1179
+ * @param str $key
1180
+ * @return str $key
1181
+ */
1182
+ function bp_get_user_meta_key( $key = false ) {
1183
+ return apply_filters( 'bp_get_user_meta_key', $key );
1184
+ }
1185
+
1186
+ /**
1187
+ * Get a piece of usermeta
1188
+ *
1189
+ * This is a wrapper for get_user_meta() that allows for easy use of bp_get_user_meta_key(), thereby
1190
+ * increasing compatibility with non-standard BP setups.
1191
+ *
1192
+ * @package BuddyPress
1193
+ * @since 1.5
1194
+ *
1195
+ * @uses bp_get_user_meta_key() For a filterable version of the meta key
1196
+ * @uses get_user_meta() See get_user_meta() docs for more details on parameters
1197
+ * @param int $user_id The id of the user whose meta you're fetching
1198
+ * @param string $key The meta key to retrieve.
1199
+ * @param bool $single Whether to return a single value.
1200
+ * @return mixed Will be an array if $single is false. Will be value of meta data field if $single
1201
+ * is true.
1202
+ */
1203
+ function bp_get_user_meta( $user_id, $key, $single = false ) {
1204
+ return get_user_meta( $user_id, bp_get_user_meta_key( $key ), $single );
1205
+ }
1206
+
1207
+ /**
1208
+ * Update a piece of usermeta
1209
+ *
1210
+ * This is a wrapper for update_user_meta() that allows for easy use of bp_get_user_meta_key(),
1211
+ * thereby increasing compatibility with non-standard BP setups.
1212
+ *
1213
+ * @package BuddyPress
1214
+ * @since 1.5
1215
+ *
1216
+ * @uses bp_get_user_meta_key() For a filterable version of the meta key
1217
+ * @uses update_user_meta() See update_user_meta() docs for more details on parameters
1218
+ * @param int $user_id The id of the user whose meta you're setting
1219
+ * @param string $key The meta key to set.
1220
+ * @param mixed $value Metadata value.
1221
+ * @param mixed $prev_value Optional. Previous value to check before removing.
1222
+ * @return bool False on failure, true if success.
1223
+ */
1224
+ function bp_update_user_meta( $user_id, $key, $value, $prev_value = '' ) {
1225
+ return update_user_meta( $user_id, bp_get_user_meta_key( $key ), $value, $prev_value );
1226
+ }
1227
+
1228
+ /**
1229
+ * Delete a piece of usermeta
1230
+ *
1231
+ * This is a wrapper for delete_user_meta() that allows for easy use of bp_get_user_meta_key(),
1232
+ * thereby increasing compatibility with non-standard BP setups.
1233
+ *
1234
+ * @package BuddyPress
1235
+ * @since 1.5
1236
+ *
1237
+ * @uses bp_get_user_meta_key() For a filterable version of the meta key
1238
+ * @uses delete_user_meta() See delete_user_meta() docs for more details on parameters
1239
+ * @param int $user_id The id of the user whose meta you're deleting
1240
+ * @param string $key The meta key to delete.
1241
+ * @param mixed $value Optional. Metadata value.
1242
+ * @return bool False for failure. True for success.
1243
+ */
1244
+ function bp_delete_user_meta( $user_id, $key, $value = '' ) {
1245
+ return delete_user_meta( $user_id, bp_get_user_meta_key( $key ), $value );
1246
+ }
1247
+
1248
+ /**
1249
+ * Are we running username compatibility mode?
1250
+ *
1251
+ * @package BuddyPress
1252
+ * @since 1.5
1253
+ *
1254
+ * @uses apply_filters() Filter 'bp_is_username_compatibility_mode' to alter
1255
+ * @return bool False when compatibility mode is disabled (default); true when enabled
1256
+ */
1257
+ function bp_is_username_compatibility_mode() {
1258
+ return apply_filters( 'bp_is_username_compatibility_mode', defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) && BP_ENABLE_USERNAME_COMPATIBILITY_MODE );
1259
+ }
1260
+
1261
+ /**
1262
+ * Are we running multiblog mode?
1263
+ *
1264
+ * Note that BP_ENABLE_MULTIBLOG is different from (but dependent on) WP Multisite. "Multiblog" is
1265
+ * a BP setup that allows BP content to be viewed in the theme, and with the URL, of every blog
1266
+ * on the network. Thus, instead of having all 'boonebgorges' links go to
1267
+ * http://example.com/members/boonebgorges
1268
+ * on the root blog, each blog will have its own version of the same profile content, eg
1269
+ * http://site2.example.com/members/boonebgorges (for subdomains)
1270
+ * http://example.com/site2/members/boonebgorges (for subdirectories)
1271
+ *
1272
+ * Multiblog mode is disabled by default, meaning that all BP content must be viewed on the root
1273
+ * blog.
1274
+ *
1275
+ * @package BuddyPress
1276
+ * @since 1.5
1277
+ *
1278
+ * @uses apply_filters() Filter 'bp_is_multiblog_mode' to alter
1279
+ * @return bool False when multiblog mode is disabled (default); true when enabled
1280
+ */
1281
+ function bp_is_multiblog_mode() {
1282
+ return apply_filters( 'bp_is_multiblog_mode', is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG );
1283
+ }
1284
+
1285
+ /**
1286
+ * Should we use the WP admin bar?
1287
+ *
1288
+ * The WP Admin Bar, introduced in WP 3.1, is fully supported in BuddyPress as of BP 1.5.
1289
+ *
1290
+ * For the BP 1.5 development cycle, the BuddyBar will remain the default navigation for BP
1291
+ * installations. In the future, this behavior will be changed, so that the WP Admin Bar is the
1292
+ * default.
1293
+ *
1294
+ * @package BuddyPress
1295
+ * @since 1.5
1296
+ *
1297
+ * @uses apply_filters() Filter 'bp_use_wp_admin_bar' to alter
1298
+ * @return bool False when WP Admin Bar support is disabled (default); true when enabled
1299
+ */
1300
+ function bp_use_wp_admin_bar() {
1301
+ return apply_filters( 'bp_use_wp_admin_bar', defined( 'BP_USE_WP_ADMIN_BAR' ) && BP_USE_WP_ADMIN_BAR );
1302
+ }
1303
+
1304
+ /**
1305
+ * Are oembeds allowed in activity items?
1306
+ *
1307
+ * @return bool False when activity embed support is disabled; true when enabled (default)
1308
+ * @since 1.5
1309
+ */
1310
+ function bp_use_embed_in_activity() {
1311
+ return apply_filters( 'bp_use_oembed_in_activity', !defined( 'BP_EMBED_DISABLE_ACTIVITY' ) || !BP_EMBED_DISABLE_ACTIVITY );
1312
+ }
1313
+
1314
+ /**
1315
+ * Are oembeds allwoed in activity replies?
1316
+ *
1317
+ * @return bool False when activity replies embed support is disabled; true when enabled (default)
1318
+ * @since 1.5
1319
+ */
1320
+ function bp_use_embed_in_activity_replies() {
1321
+ return apply_filters( 'bp_use_embed_in_activity_replies', !defined( 'BP_EMBED_DISABLE_ACTIVITY_REPLIES' ) || !BP_EMBED_DISABLE_ACTIVITY_REPLIES );
1322
+ }
1323
+
1324
+ /**
1325
+ * Are oembeds allowed in forum posts?
1326
+ *
1327
+ * @return bool False when form post embed support is disabled; true when enabled (default)
1328
+ * @since 1.5
1329
+ */
1330
+ function bp_use_embed_in_forum_posts() {
1331
+ return apply_filters( 'bp_use_embed_in_forum_posts', !defined( 'BP_EMBED_DISABLE_FORUM_POSTS' ) || !BP_EMBED_DISABLE_FORUM_POSTS );
1332
+ }
1333
+
1334
+ /**
1335
+ * Are oembeds allowed in private messages?
1336
+ *
1337
+ * @return bool False when form post embed support is disabled; true when enabled (default)
1338
+ * @since 1.5
1339
+ */
1340
+ function bp_use_embed_in_private_messages() {
1341
+ return apply_filters( 'bp_use_embed_in_private_messages', !defined( 'BP_EMBED_DISABLE_PRIVATE_MESSAGES' ) || !BP_EMBED_DISABLE_PRIVATE_MESSAGES );
1342
+ }
1343
+
1344
+ /**
1345
+ * Output the correct URL based on BuddyPress and WordPress configuration
1346
+ *
1347
+ * @package BuddyPress
1348
+ * @since 1.5
1349
+ *
1350
+ * @param string $path
1351
+ * @param string $scheme
1352
+ *
1353
+ * @uses bp_get_admin_url()
1354
+ */
1355
+ function bp_admin_url( $path = '', $scheme = 'admin' ) {
1356
+ echo bp_get_admin_url( $path, $scheme );
1357
+ }
1358
+ /**
1359
+ * Return the correct URL based on BuddyPress and WordPress configuration
1360
+ *
1361
+ * @package BuddyPress
1362
+ * @since 1.5
1363
+ *
1364
+ * @param string $path
1365
+ * @param string $scheme
1366
+ *
1367
+ * @uses bp_core_do_network_admin()
1368
+ * @uses network_admin_url()
1369
+ * @uses admin_url()
1370
+ */
1371
+ function bp_get_admin_url( $path = '', $scheme = 'admin' ) {
1372
+
1373
+ // Links belong in network admin
1374
+ if ( bp_core_do_network_admin() )
1375
+ $url = network_admin_url( $path, $scheme );
1376
+
1377
+ // Links belong in site admin
1378
+ else
1379
+ $url = admin_url( $path, $scheme );
1380
+
1381
+ return $url;
1382
+ }
1383
+
1384
+ /** Global Manipulators *******************************************************/
1385
+
1386
+ /**
1387
+ * Set the $bp->is_directory global
1388
+ *
1389
+ * @global obj $bp
1390
+ * @param bool $is_directory
1391
+ * @param str $component
1392
+ */
1393
+ function bp_update_is_directory( $is_directory = false, $component = '' ) {
1394
+ global $bp;
1395
+
1396
+ if ( empty( $component ) )
1397
+ $component = bp_current_component();
1398
+
1399
+ $bp->is_directory = apply_filters( 'bp_update_is_directory', $is_directory, $component );
1400
+ }
1401
+
1402
+ /**
1403
+ * Set the $bp->is_item_admin global
1404
+ *
1405
+ * @global obj $bp
1406
+ * @param bool $is_item_admin
1407
+ * @param str $component
1408
+ */
1409
+ function bp_update_is_item_admin( $is_item_admin = false, $component = '' ) {
1410
+ global $bp;
1411
+
1412
+ if ( empty( $component ) )
1413
+ $component = bp_current_component();
1414
+
1415
+ $bp->is_item_admin = apply_filters( 'bp_update_is_item_admin', $is_item_admin, $component );
1416
+ }
1417
+
1418
+ /**
1419
+ * Set the $bp->is_item_mod global
1420
+ *
1421
+ * @global obj $bp
1422
+ * @param bool $is_item_mod
1423
+ * @param str $component
1424
+ */
1425
+ function bp_update_is_item_mod( $is_item_mod = false, $component = '' ) {
1426
+ global $bp;
1427
+
1428
+ if ( empty( $component ) )
1429
+ $component = bp_current_component();
1430
+
1431
+ $bp->is_item_mod = apply_filters( 'bp_update_is_item_mod', $is_item_mod, $component );
1432
+ }
1433
+
1434
+ /**
1435
+ * Trigger a 404
1436
+ *
1437
+ * @global object $bp Global BuddyPress settings object
1438
+ * @global WP_Query $wp_query WordPress query object
1439
+ * @param string $redirect If 'remove_canonical_direct', remove WordPress' "helpful" redirect_canonical action.
1440
+ * @since 1.5
1441
+ */
1442
+ function bp_do_404( $redirect = 'remove_canonical_direct' ) {
1443
+ global $bp, $wp_query;
1444
+
1445
+ do_action( 'bp_do_404', $redirect );
1446
+
1447
+ $wp_query->set_404();
1448
+ status_header( 404 );
1449
+ nocache_headers();
1450
+
1451
+ if ( 'remove_canonical_direct' == $redirect )
1452
+ remove_action( 'template_redirect', 'redirect_canonical' );
1453
+ }
1454
+ ?>
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 ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ );
41
+
42
+ $this->bootstrap();
43
+ }
44
+
45
+ private function bootstrap() {
46
+ global $bp;
47
+
48
+ /**
49
+ * At this point in the stack, BuddyPress core has been loaded but
50
+ * individual components (friends/activity/groups/etc...) have not.
51
+ *
52
+ * The 'bp_core_loaded' action lets you execute code ahead of the
53
+ * other components.
54
+ */
55
+ do_action( 'bp_core_loaded' );
56
+
57
+ /** Components ********************************************************/
58
+
59
+ // Set the included and optional components.
60
+ $bp->optional_components = apply_filters( 'bp_optional_components', array( 'activity', 'blogs', 'forums', 'friends', 'groups', 'messages', 'settings', 'xprofile' ) );
61
+
62
+ // Set the required components
63
+ $bp->required_components = apply_filters( 'bp_required_components', array( 'members' ) );
64
+
65
+ // Get a list of activated components
66
+ if ( $active_components = bp_get_option( 'bp-active-components' ) ) {
67
+ $bp->active_components = apply_filters( 'bp_active_components', $active_components );
68
+ $bp->deactivated_components = apply_filters( 'bp_deactivated_components', array_values( array_diff( array_values( array_merge( $bp->optional_components, $bp->required_components ) ), array_keys( $bp->active_components ) ) ) );
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 ) );
75
+
76
+ // Set globals
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 );
101
+ }
102
+
103
+ // Loop through optional components
104
+ foreach( $bp->optional_components as $component )
105
+ if ( bp_is_active( $component ) && file_exists( BP_PLUGIN_DIR . '/bp-' . $component . '/bp-' . $component . '-loader.php' ) )
106
+ include( BP_PLUGIN_DIR . '/bp-' . $component . '/bp-' . $component . '-loader.php' );
107
+
108
+ // Loop through required components
109
+ foreach( $bp->required_components as $component )
110
+ if ( file_exists( BP_PLUGIN_DIR . '/bp-' . $component . '/bp-' . $component . '-loader.php' ) )
111
+ include( BP_PLUGIN_DIR . '/bp-' . $component . '/bp-' . $component . '-loader.php' );
112
+
113
+ // Add Core to required components
114
+ $bp->required_components[] = 'core';
115
+ }
116
+
117
+ function setup_globals() {
118
+ global $bp;
119
+
120
+ /** Database **********************************************************/
121
+
122
+ // Get the base database prefix
123
+ if ( empty( $bp->table_prefix ) )
124
+ $bp->table_prefix = bp_core_get_table_prefix();
125
+
126
+ // The domain for the root of the site where the main blog resides
127
+ if ( empty( $bp->root_domain ) )
128
+ $bp->root_domain = bp_core_get_root_domain();
129
+
130
+ // Fetches all of the core BuddyPress settings in one fell swoop
131
+ if ( empty( $bp->site_options ) )
132
+ $bp->site_options = bp_core_get_root_options();
133
+
134
+ // The names of the core WordPress pages used to display BuddyPress content
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 );
175
+
176
+ // Notifications Table
177
+ $bp->core->table_name_notifications = $bp->table_prefix . 'bp_notifications';
178
+
179
+ /**
180
+ * Used to determine if user has admin rights on current content. If the
181
+ * logged in user is viewing their own profile and wants to delete
182
+ * something, is_item_admin is used. This is a generic variable so it
183
+ * can be used by other components. It can also be modified, so when
184
+ * viewing a group 'is_item_admin' would be 'true' if they are a group
185
+ * admin, and 'false' if they are not.
186
+ */
187
+ bp_update_is_item_admin( bp_user_has_access(), 'core' );
188
+
189
+ // Is the logged in user is a mod for the current item?
190
+ bp_update_is_item_mod( false, 'core' );
191
+
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;
207
+
208
+ // Add 'Profile' to the main navigation
209
+ $main_nav = array(
210
+ 'name' => __( 'Profile', 'buddypress' ),
211
+ 'slug' => $bp->core->profile->slug,
212
+ 'position' => 20,
213
+ 'screen_function' => 'bp_core_catch_profile_uri',
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(
221
+ 'name' => __( 'Public', 'buddypress' ),
222
+ 'slug' => 'public',
223
+ 'parent_url' => $profile_link,
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-notifications.php DELETED
@@ -1,95 +0,0 @@
1
- <?php
2
-
3
- function bp_core_add_notification( $item_id, $user_id, $component_name, $component_action, $secondary_item_id = false, $date_notified = false ) {
4
- global $bp;
5
-
6
- if ( !$date_notified )
7
- $date_notified = bp_core_current_time();
8
-
9
- $notification = new BP_Core_Notification;
10
- $notification->item_id = $item_id;
11
- $notification->user_id = $user_id;
12
- $notification->component_name = $component_name;
13
- $notification->component_action = $component_action;
14
- $notification->date_notified = $date_notified;
15
- $notification->is_new = 1;
16
-
17
- if ( $secondary_item_id )
18
- $notification->secondary_item_id = $secondary_item_id;
19
-
20
- if ( !$notification->save() )
21
- return false;
22
-
23
- return true;
24
- }
25
-
26
- function bp_core_delete_notification( $id ) {
27
- if ( !bp_core_check_notification_access( $bp->loggedin_user->id, $id ) )
28
- return false;
29
-
30
- return BP_Core_Notification::delete( $id );
31
- }
32
-
33
- function bp_core_get_notification( $id ) {
34
- return new BP_Core_Notification( $id );
35
- }
36
-
37
- function bp_core_get_notifications_for_user( $user_id ) {
38
- global $bp;
39
-
40
- $notifications = BP_Core_Notification::get_all_for_user( $user_id );
41
-
42
- /* Group notifications by component and component_action and provide totals */
43
- for ( $i = 0; $i < count($notifications); $i++ ) {
44
- $notification = $notifications[$i];
45
-
46
- $grouped_notifications[$notification->component_name][$notification->component_action][] = $notification;
47
- }
48
-
49
- if ( !$grouped_notifications )
50
- return false;
51
-
52
- /* Calculated a renderable outcome for each notification type */
53
- foreach ( (array)$grouped_notifications as $component_name => $action_arrays ) {
54
- if ( !$action_arrays )
55
- continue;
56
-
57
- foreach ( (array)$action_arrays as $component_action_name => $component_action_items ) {
58
- $action_item_count = count($component_action_items);
59
-
60
- if ( $action_item_count < 1 )
61
- continue;
62
-
63
- if ( function_exists( $bp->{$component_name}->format_notification_function ) ) {
64
- $renderable[] = call_user_func( $bp->{$component_name}->format_notification_function, $component_action_name, $component_action_items[0]->item_id, $component_action_items[0]->secondary_item_id, $action_item_count );
65
- }
66
- }
67
- }
68
-
69
- return $renderable;
70
- }
71
-
72
- function bp_core_delete_notifications_for_user_by_type( $user_id, $component_name, $component_action ) {
73
- return BP_Core_Notification::delete_for_user_by_type( $user_id, $component_name, $component_action );
74
- }
75
-
76
- function bp_core_delete_notifications_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false ) {
77
- return BP_Core_Notification::delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id );
78
- }
79
-
80
- function bp_core_delete_all_notifications_by_type( $item_id, $component_name, $component_action = false, $secondary_item_id = false ) {
81
- return BP_Core_Notification::delete_all_by_type( $item_id, $component_name, $component_action, $secondary_item_id );
82
- }
83
-
84
- function bp_core_delete_notifications_from_user( $user_id, $component_name, $component_action ) {
85
- return BP_Core_Notification::delete_from_user_by_type( $user_id, $component_name, $component_action );
86
- }
87
-
88
- function bp_core_check_notification_access( $user_id, $notification_id ) {
89
- if ( !BP_Core_Notification::check_access( $user_id, $notification_id ) )
90
- return false;
91
-
92
- return true;
93
- }
94
-
95
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-core/bp-core-settings.php DELETED
@@ -1,197 +0,0 @@
1
- <?php
2
-
3
- if ( !defined( 'BP_SETTINGS_SLUG' ) )
4
- define( 'BP_SETTINGS_SLUG', 'settings' );
5
-
6
- function bp_core_add_settings_nav() {
7
- global $bp;
8
-
9
- /* Set up settings as a sudo-component for identification and nav selection */
10
- $bp->settings->id = 'settings';
11
- $bp->settings->slug = BP_SETTINGS_SLUG;
12
-
13
- /* Register this in the active components array */
14
- $bp->active_components[$bp->settings->slug] = $bp->settings->id;
15
-
16
- /* Add the settings navigation item */
17
- bp_core_new_nav_item( array( 'name' => __('Settings', 'buddypress'), 'slug' => $bp->settings->slug, 'position' => 100, 'show_for_displayed_user' => false, 'screen_function' => 'bp_core_screen_general_settings', 'default_subnav_slug' => 'general' ) );
18
-
19
- $settings_link = $bp->loggedin_user->domain . $bp->settings->slug . '/';
20
-
21
- bp_core_new_subnav_item( array( 'name' => __( 'General', 'buddypress' ), 'slug' => 'general', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bp_core_screen_general_settings', 'position' => 10, 'user_has_access' => bp_is_my_profile() ) );
22
- bp_core_new_subnav_item( array( 'name' => __( 'Notifications', 'buddypress' ), 'slug' => 'notifications', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bp_core_screen_notification_settings', 'position' => 20, 'user_has_access' => bp_is_my_profile() ) );
23
-
24
- if ( !is_super_admin() && !(int) $bp->site_options['bp-disable-account-deletion'] )
25
- bp_core_new_subnav_item( array( 'name' => __( 'Delete Account', 'buddypress' ), 'slug' => 'delete-account', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bp_core_screen_delete_account', 'position' => 90, 'user_has_access' => bp_is_my_profile() ) );
26
- }
27
- add_action( 'bp_setup_nav', 'bp_core_add_settings_nav' );
28
-
29
- /**** GENERAL SETTINGS ****/
30
-
31
- function bp_core_screen_general_settings() {
32
- global $current_user, $bp_settings_updated, $pass_error;
33
-
34
- $bp_settings_updated = false;
35
- $pass_error = false;
36
-
37
- if ( isset($_POST['submit']) ) {
38
- check_admin_referer('bp_settings_general');
39
-
40
- require_once( WPINC . '/registration.php' );
41
-
42
- // Form has been submitted and nonce checks out, lets do it.
43
-
44
- if ( $_POST['email'] != '' )
45
- $current_user->user_email = wp_specialchars( trim( $_POST['email'] ) );
46
-
47
- if ( $_POST['pass1'] != '' && $_POST['pass2'] != '' ) {
48
- if ( $_POST['pass1'] == $_POST['pass2'] && !strpos( " " . $_POST['pass1'], "\\" ) )
49
- $current_user->user_pass = $_POST['pass1'];
50
- else
51
- $pass_error = true;
52
- } else if ( empty( $_POST['pass1'] ) && !empty( $_POST['pass2'] ) || !empty( $_POST['pass1'] ) && empty( $_POST['pass2'] ) ) {
53
- $pass_error = true;
54
- } else {
55
- unset( $current_user->user_pass );
56
- }
57
-
58
- if ( !$pass_error && wp_update_user( get_object_vars( $current_user ) ) )
59
- $bp_settings_updated = true;
60
- }
61
-
62
- add_action( 'bp_template_title', 'bp_core_screen_general_settings_title' );
63
- add_action( 'bp_template_content', 'bp_core_screen_general_settings_content' );
64
-
65
- bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
66
- }
67
-
68
- function bp_core_screen_general_settings_title() {
69
- _e( 'General Settings', 'buddypress' );
70
- }
71
-
72
- function bp_core_screen_general_settings_content() {
73
- global $bp, $current_user, $bp_settings_updated, $pass_error; ?>
74
-
75
- <?php if ( $bp_settings_updated && !$pass_error ) { ?>
76
- <div id="message" class="updated fade">
77
- <p><?php _e( 'Changes Saved.', 'buddypress' ) ?></p>
78
- </div>
79
- <?php } ?>
80
-
81
- <?php if ( $pass_error && !$bp_settings_updated ) { ?>
82
- <div id="message" class="error fade">
83
- <p><?php _e( 'Your passwords did not match', 'buddypress' ) ?></p>
84
- </div>
85
- <?php } ?>
86
-
87
- <form action="<?php echo $bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/general' ?>" method="post" class="standard-form" id="settings-form">
88
- <label for="email"><?php _e( 'Account Email', 'buddypress' ) ?></label>
89
- <input type="text" name="email" id="email" value="<?php echo esc_attr( $current_user->user_email ); ?>" class="settings-input" />
90
-
91
- <label for="pass1"><?php _e( 'Change Password <span>(leave blank for no change)</span>', 'buddypress' ) ?></label>
92
- <input type="password" name="pass1" id="pass1" size="16" value="" class="settings-input small" /> &nbsp;<?php _e( 'New Password', 'buddypress' ) ?><br />
93
- <input type="password" name="pass2" id="pass2" size="16" value="" class="settings-input small" /> &nbsp;<?php _e( 'Repeat New Password', 'buddypress' ) ?>
94
-
95
- <div class="submit">
96
- <input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto" />
97
- </div>
98
-
99
- <?php wp_nonce_field('bp_settings_general') ?>
100
- </form>
101
- <?php
102
- }
103
-
104
- /***** NOTIFICATION SETTINGS ******/
105
-
106
- function bp_core_screen_notification_settings() {
107
- global $current_user, $bp_settings_updated;
108
-
109
- $bp_settings_updated = false;
110
-
111
- if ( $_POST['submit'] ) {
112
- check_admin_referer('bp_settings_notifications');
113
-
114
- if ( $_POST['notifications'] ) {
115
- foreach ( (array)$_POST['notifications'] as $key => $value ) {
116
- update_user_meta( (int)$current_user->id, $key, $value );
117
- }
118
- }
119
-
120
- $bp_settings_updated = true;
121
- }
122
-
123
- add_action( 'bp_template_title', 'bp_core_screen_notification_settings_title' );
124
- add_action( 'bp_template_content', 'bp_core_screen_notification_settings_content' );
125
-
126
- bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
127
- }
128
-
129
- function bp_core_screen_notification_settings_title() {
130
- _e( 'Notification Settings', 'buddypress' );
131
- }
132
-
133
- function bp_core_screen_notification_settings_content() {
134
- global $bp, $current_user, $bp_settings_updated; ?>
135
-
136
- <?php if ( $bp_settings_updated ) { ?>
137
- <div id="message" class="updated fade">
138
- <p><?php _e( 'Changes Saved.', 'buddypress' ) ?></p>
139
- </div>
140
- <?php } ?>
141
-
142
- <form action="<?php echo $bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/notifications' ?>" method="post" id="settings-form">
143
- <h3><?php _e( 'Email Notifications', 'buddypress' ) ?></h3>
144
- <p><?php _e( 'Send a notification by email when:', 'buddypress' ) ?></p>
145
-
146
- <?php do_action( 'bp_notification_settings' ) ?>
147
-
148
- <div class="submit">
149
- <input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto" />
150
- </div>
151
-
152
- <?php wp_nonce_field('bp_settings_notifications') ?>
153
-
154
- </form>
155
- <?php
156
- }
157
-
158
- /**** DELETE ACCOUNT ****/
159
-
160
- function bp_core_screen_delete_account() {
161
- if ( isset( $_POST['delete-account-understand'] ) ) {
162
- check_admin_referer( 'delete-account' );
163
-
164
- // delete the users account
165
- if ( bp_core_delete_account() )
166
- bp_core_redirect( site_url() );
167
- }
168
-
169
- add_action( 'bp_template_title', 'bp_core_screen_delete_account_title' );
170
- add_action( 'bp_template_content', 'bp_core_screen_delete_account_content' );
171
-
172
- bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
173
- }
174
-
175
- function bp_core_screen_delete_account_title() {
176
- _e( 'Delete Account', 'buddypress' );
177
- }
178
-
179
- function bp_core_screen_delete_account_content() {
180
- global $bp, $current_user, $bp_settings_updated, $pass_error; ?>
181
-
182
- <form action="<?php echo $bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/delete-account'; ?>" name="account-delete-form" id="account-delete-form" class="standard-form" method="post">
183
-
184
- <div id="message" class="info">
185
- <p><?php _e( 'WARNING: Deleting your account will completely remove ALL content associated with it. There is no way back, please be careful with this option.', 'buddypress' ); ?></p>
186
- </div>
187
-
188
- <input type="checkbox" name="delete-account-understand" id="delete-account-understand" value="1" onclick="if(this.checked) { document.getElementById('delete-account-button').disabled = ''; } else { document.getElementById('delete-account-button').disabled = 'disabled'; }" /> <?php _e( 'I understand the consequences of deleting my account.', 'buddypress' ); ?>
189
-
190
- <div class="submit">
191
- <input type="submit" disabled="disabled" value="<?php _e( 'Delete My Account', 'buddypress' ) ?> &rarr;" id="delete-account-button" name="delete-account-button" />
192
- </div>
193
-
194
- <?php wp_nonce_field('delete-account') ?>
195
- </form>
196
- <?php
197
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-core/bp-core-template.php ADDED
@@ -0,0 +1,1661 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Exit if accessed directly
3
+ if ( !defined( 'ABSPATH' ) ) exit;
4
+
5
+ /**
6
+ * Uses the $bp->bp_options_nav global to render out the sub navigation for the current component.
7
+ * Each component adds to its sub navigation array within its own setup_nav() function.
8
+ *
9
+ * This sub navigation array is the secondary level navigation, so for profile it contains:
10
+ * [Public, Edit Profile, Change Avatar]
11
+ *
12
+ * The function will also analyze the current action for the current component to determine whether
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() {
20
+ global $bp;
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 ) {
28
+ return false;
29
+ } else {
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 = '';
50
+ }
51
+
52
+ // List type depends on our current component
53
+ $list_type = bp_is_group() ? 'groups' : 'personal';
54
+
55
+ // echo out the final list item
56
+ echo apply_filters( 'bp_get_options_nav_' . $subnav_item['css_id'], '<li id="' . $subnav_item['css_id'] . '-' . $list_type . '-li" ' . $selected . '><a id="' . $subnav_item['css_id'] . '" href="' . $subnav_item['link'] . '">' . $subnav_item['name'] . '</a></li>', $subnav_item );
57
+ }
58
+ }
59
+
60
+ function bp_get_options_title() {
61
+ global $bp;
62
+
63
+ if ( empty( $bp->bp_options_title ) )
64
+ $bp->bp_options_title = __( 'Options', 'buddypress' );
65
+
66
+ echo apply_filters( 'bp_get_options_title', esc_attr( $bp->bp_options_title ) );
67
+ }
68
+
69
+ /** Avatars *******************************************************************/
70
+
71
+ /**
72
+ * Check to see if there is an options avatar. An options avatar is an avatar for something
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;
80
+
81
+ if ( empty( $bp->bp_options_avatar ) )
82
+ return false;
83
+
84
+ return true;
85
+ }
86
+
87
+ function bp_get_options_avatar() {
88
+ global $bp;
89
+
90
+ echo apply_filters( 'bp_get_options_avatar', $bp->bp_options_avatar );
91
+ }
92
+
93
+ function bp_comment_author_avatar() {
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
+ }
101
+
102
+ function bp_post_author_avatar() {
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
+ }
110
+
111
+ function bp_avatar_admin_step() {
112
+ echo bp_get_avatar_admin_step();
113
+ }
114
+ function bp_get_avatar_admin_step() {
115
+ global $bp;
116
+
117
+ if ( isset( $bp->avatar_admin->step ) )
118
+ $step = $bp->avatar_admin->step;
119
+ else
120
+ $step = 'upload-image';
121
+
122
+ return apply_filters( 'bp_get_avatar_admin_step', $step );
123
+ }
124
+
125
+ function bp_avatar_to_crop() {
126
+ echo bp_get_avatar_to_crop();
127
+ }
128
+ function bp_get_avatar_to_crop() {
129
+ global $bp;
130
+
131
+ if ( isset( $bp->avatar_admin->image->url ) )
132
+ $url = $bp->avatar_admin->image->url;
133
+ else
134
+ $url = '';
135
+
136
+ return apply_filters( 'bp_get_avatar_to_crop', $url );
137
+ }
138
+
139
+ function bp_avatar_to_crop_src() {
140
+ echo bp_get_avatar_to_crop_src();
141
+ }
142
+ function bp_get_avatar_to_crop_src() {
143
+ global $bp;
144
+
145
+ return apply_filters( 'bp_get_avatar_to_crop_src', str_replace( WP_CONTENT_DIR, '', $bp->avatar_admin->image->dir ) );
146
+ }
147
+
148
+ function bp_avatar_cropper() {
149
+ global $bp;
150
+
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 );
160
+ }
161
+
162
+ function bp_exists( $component_name ) {
163
+ if ( function_exists( $component_name . '_install' ) )
164
+ return true;
165
+
166
+ return false;
167
+ }
168
+
169
+ function bp_format_time( $time, $just_date = false, $localize_time = true ) {
170
+ if ( !isset( $time ) || !is_numeric( $time ) )
171
+ return false;
172
+
173
+ // Get GMT offset from root blog
174
+ $root_blog_offset = false;
175
+ if ( $localize_time )
176
+ $root_blog_offset = get_blog_option( bp_get_root_blog_id(), 'gmt_offset' );
177
+
178
+ // Calculate offset time
179
+ $time_offset = $time + ( $root_blog_offset * 3600 );
180
+
181
+ // Current date (January 1, 2010)
182
+ $date = date_i18n( get_option( 'date_format' ), $time_offset );
183
+
184
+ // Should we show the time also?
185
+ if ( !$just_date ) {
186
+ // Current time (9:50pm)
187
+ $time = date_i18n( get_option( 'time_format' ), $time_offset );
188
+
189
+ // Return string formatted with date and time
190
+ $date = sprintf( __( '%1$s at %2$s', 'buddypress' ), $date, $time );
191
+ }
192
+
193
+ return apply_filters( 'bp_format_time', $date );
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
+
217
+ function bp_get_plugin_sidebar() {
218
+ locate_template( array( 'plugin-sidebar.php' ), true );
219
+ }
220
+
221
+ function bp_styles() {
222
+ do_action( 'bp_styles' );
223
+ wp_print_styles();
224
+ }
225
+
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
+
244
+ if ( bp_is_active( 'xprofile' ) )
245
+ $options['members'] = __( 'Members', 'buddypress' );
246
+
247
+ if ( bp_is_active( 'groups' ) )
248
+ $options['groups'] = __( 'Groups', 'buddypress' );
249
+
250
+ if ( bp_is_active( 'blogs' ) && is_multisite() )
251
+ $options['blogs'] = __( 'Blogs', 'buddypress' );
252
+
253
+ if ( bp_is_active( 'forums' ) && bp_forums_is_installed_correctly() && bp_forums_has_directory() )
254
+ $options['forums'] = __( 'Forums', 'buddypress' );
255
+
256
+ $options['posts'] = __( 'Posts', 'buddypress' );
257
+
258
+ // Eventually this won't be needed and a page will be built to integrate all search results.
259
+ $selection_box = '<label for="search-which" class="accessibly-hidden">' . __( 'Search these:', 'buddypress' ) . '</label>';
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>';
267
+
268
+ return apply_filters( 'bp_search_form_type_select', $selection_box );
269
+ }
270
+
271
+ /**
272
+ * Get the default text for the search box for a given component.
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 );
280
+ }
281
+ function bp_get_search_default_text( $component = '' ) {
282
+ global $bp;
283
+
284
+ if ( empty( $component ) )
285
+ $component = bp_current_component();
286
+
287
+ $default_text = __( 'Search anything...', 'buddypress' );
288
+
289
+ // Most of the time, $component will be the actual component ID
290
+ if ( !empty( $component ) ) {
291
+ if ( !empty( $bp->{$component}->search_string ) ) {
292
+ $default_text = $bp->{$component}->search_string;
293
+ } else {
294
+ // When the request comes through AJAX, we need to get the component
295
+ // name out of $bp->pages
296
+ if ( !empty( $bp->pages->{$component}->slug ) ) {
297
+ $key = $bp->pages->{$component}->slug;
298
+ if ( !empty( $bp->{$key}->search_string ) )
299
+ $default_text = $bp->{$key}->search_string;
300
+ }
301
+ }
302
+ }
303
+
304
+ return apply_filters( 'bp_get_search_default_text', $default_text, $component );
305
+ }
306
+
307
+ function bp_custom_profile_boxes() {
308
+ do_action( 'bp_custom_profile_boxes' );
309
+ }
310
+
311
+ function bp_custom_profile_sidebar_boxes() {
312
+ do_action( 'bp_custom_profile_sidebar_boxes' );
313
+ }
314
+
315
+ /**
316
+ * Creates and outputs a button.
317
+ *
318
+ * @param array $args See bp_get_button() for the list of arguments.
319
+ * @see bp_get_button()
320
+ */
321
+ function bp_button( $args = '' ) {
322
+ echo bp_get_button( $args );
323
+ }
324
+ /**
325
+ * Creates and returns a button.
326
+ *
327
+ * Args:
328
+ * component: Which component this button is for
329
+ * must_be_logged_in: Button only appears for logged in users
330
+ * block_self: Button will not appear when viewing your own profile.
331
+ * wrapper: div|span|p|li|
332
+ * wrapper_id: The DOM ID of the button wrapper
333
+ * wrapper_class: The DOM class of the button wrapper
334
+ * link_href: The destination link of the button
335
+ * link_title: Title of the button
336
+ * link_id: The DOM ID of the button
337
+ * link_class: The DOM class of the button
338
+ * link_rel: The DOM rel of the button
339
+ * link_text: The contents of the button
340
+ *
341
+ * @param array $button
342
+ * @return string
343
+ * @see bp_add_friend_button()
344
+ * @see bp_send_public_message_button()
345
+ * @see bp_send_private_message_button()
346
+ */
347
+ function bp_get_button( $args = '' ) {
348
+ $button = new BP_Button( $args );
349
+ return apply_filters( 'bp_get_button', $button->contents, $args, $button );
350
+ }
351
+
352
+
353
+ /**
354
+ * Truncates text.
355
+ *
356
+ * Cuts a string to the length of $length and replaces the last characters
357
+ * with the ending if the text is longer than length.
358
+ *
359
+ * This function is borrowed from CakePHP v2.0, under the MIT license. See
360
+ * http://book.cakephp.org/view/1469/Text#truncate-1625
361
+ *
362
+ * ### Options:
363
+ *
364
+ * - `ending` Will be used as Ending and appended to the trimmed string
365
+ * - `exact` If false, $text will not be cut mid-word
366
+ * - `html` If true, HTML tags would be handled correctly
367
+ * - `filter_shortcodes` If true, shortcodes will be stripped before truncating
368
+ *
369
+ * @package BuddyPress
370
+ *
371
+ * @param string $text String to truncate.
372
+ * @param integer $length Length of returned string, including ellipsis.
373
+ * @param array $options An array of html attributes and options.
374
+ * @return string Trimmed string.
375
+ */
376
+ function bp_create_excerpt( $text, $length = 225, $options = array() ) {
377
+ // Backward compatibility. The third argument used to be a boolean $filter_shortcodes
378
+ $filter_shortcodes_default = is_bool( $options ) ? $options : true;
379
+
380
+ $defaults = array(
381
+ 'ending' => __( ' [&hellip;]', 'buddypress' ),
382
+ 'exact' => false,
383
+ 'html' => true,
384
+ 'filter_shortcodes' => $filter_shortcodes_default
385
+ );
386
+ $r = wp_parse_args( $options, $defaults );
387
+ extract( $r );
388
+
389
+ // Save the original text, to be passed along to the filter
390
+ $original_text = $text;
391
+
392
+ // Allow plugins to modify these values globally
393
+ $length = apply_filters( 'bp_excerpt_length', $length );
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;
406
+ }
407
+
408
+ $totalLength = mb_strlen( strip_tags( $ending ) );
409
+ $openTags = array();
410
+ $truncate = '';
411
+
412
+ // Find all the tags and put them in a stack for later use
413
+ preg_match_all( '/(<\/?([\w+]+)[^>]*>)?([^<>]*)/', $text, $tags, PREG_SET_ORDER );
414
+ foreach ( $tags as $tag ) {
415
+ // Process tags that need to be closed
416
+ if ( !preg_match( '/img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param/s', $tag[2] ) ) {
417
+ if ( preg_match( '/<[\w]+[^>]*>/s', $tag[0] ) ) {
418
+ array_unshift( $openTags, $tag[2] );
419
+ } else if ( preg_match('/<\/([\w]+)[^>]*>/s', $tag[0], $closeTag ) ) {
420
+ $pos = array_search( $closeTag[1], $openTags );
421
+ if ( $pos !== false ) {
422
+ array_splice( $openTags, $pos, 1 );
423
+ }
424
+ }
425
+ }
426
+ $truncate .= $tag[1];
427
+
428
+ $contentLength = mb_strlen( preg_replace( '/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', ' ', $tag[3] ) );
429
+ if ( $contentLength + $totalLength > $length ) {
430
+ $left = $length - $totalLength;
431
+ $entitiesLength = 0;
432
+ if ( preg_match_all( '/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', $tag[3], $entities, PREG_OFFSET_CAPTURE ) ) {
433
+ foreach ( $entities[0] as $entity ) {
434
+ if ( $entity[1] + 1 - $entitiesLength <= $left ) {
435
+ $left--;
436
+ $entitiesLength += mb_strlen( $entity[0] );
437
+ } else {
438
+ break;
439
+ }
440
+ }
441
+ }
442
+
443
+ $truncate .= mb_substr( $tag[3], 0 , $left + $entitiesLength );
444
+ break;
445
+ } else {
446
+ $truncate .= $tag[3];
447
+ $totalLength += $contentLength;
448
+ }
449
+ if ( $totalLength >= $length ) {
450
+ break;
451
+ }
452
+ }
453
+ } else {
454
+ if ( mb_strlen( $text ) <= $length ) {
455
+ return $text;
456
+ } else {
457
+ $truncate = mb_substr( $text, 0, $length - mb_strlen( $ending ) );
458
+ }
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 ) {
466
+ $bits = mb_substr( $truncate, $spacepos );
467
+ preg_match_all( '/<\/([a-z]+)>/', $bits, $droppedTags, PREG_SET_ORDER );
468
+ if ( !empty( $droppedTags ) ) {
469
+ foreach ( $droppedTags as $closingTag ) {
470
+ if ( !in_array( $closingTag[1], $openTags ) ) {
471
+ array_unshift( $openTags, $closingTag[1] );
472
+ }
473
+ }
474
+ }
475
+ }
476
+ $truncate = mb_substr( $truncate, 0, $spacepos );
477
+ }
478
+ }
479
+ $truncate .= $ending;
480
+
481
+ if ( $html ) {
482
+ foreach ( $openTags as $tag ) {
483
+ $truncate .= '</' . $tag . '>';
484
+ }
485
+ }
486
+
487
+ return apply_filters( 'bp_create_excerpt', $truncate, $original_text, $length, $options );
488
+
489
+ }
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
+
501
+ function bp_blog_signup_allowed() {
502
+ echo bp_get_blog_signup_allowed();
503
+ }
504
+ function bp_get_blog_signup_allowed() {
505
+ global $bp;
506
+
507
+ if ( !is_multisite() )
508
+ return false;
509
+
510
+ $status = $bp->site_options['registration'];
511
+ if ( 'none' != $status && 'user' != $status )
512
+ return true;
513
+
514
+ return false;
515
+ }
516
+
517
+ function bp_account_was_activated() {
518
+ global $bp;
519
+
520
+ $activation_complete = !empty( $bp->activation_complete ) ? $bp->activation_complete : false;
521
+
522
+ return $activation_complete;
523
+ }
524
+
525
+ function bp_registration_needs_activation() {
526
+ return apply_filters( 'bp_registration_needs_activation', true );
527
+ }
528
+
529
+ /**
530
+ * Allow templates to pass parameters directly into the template loops via AJAX
531
+ *
532
+ * For the most part this will be filtered in a theme's functions.php for example
533
+ * in the default theme it is filtered via bp_dtheme_ajax_querystring()
534
+ *
535
+ * By using this template tag in the templates it will stop them from showing errors
536
+ * if someone copies the templates from the default theme into another WordPress theme
537
+ * without coping the functions from functions.php.
538
+ */
539
+ function bp_ajax_querystring( $object = false ) {
540
+ global $bp;
541
+
542
+ if ( !isset( $bp->ajax_querystring ) )
543
+ $bp->ajax_querystring = '';
544
+
545
+ return apply_filters( 'bp_ajax_querystring', $bp->ajax_querystring, $object );
546
+ }
547
+
548
+ /** Template Classes and _is functions ****************************************/
549
+
550
+ function bp_current_component() {
551
+ global $bp;
552
+ $current_component = !empty( $bp->current_component ) ? $bp->current_component : false;
553
+ return apply_filters( 'bp_current_component', $current_component );
554
+ }
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
+
562
+ function bp_current_item() {
563
+ global $bp;
564
+ $current_item = !empty( $bp->current_item ) ? $bp->current_item : false;
565
+ return apply_filters( 'bp_current_item', $current_item );
566
+ }
567
+
568
+ /**
569
+ * Return the value of $bp->action_variables
570
+ *
571
+ * @package BuddyPress
572
+ *
573
+ * @param mixed $action_variables The action variables array, or false if the array is empty
574
+ */
575
+ function bp_action_variables() {
576
+ global $bp;
577
+ $action_variables = !empty( $bp->action_variables ) ? $bp->action_variables : false;
578
+ return apply_filters( 'bp_action_variables', $action_variables );
579
+ }
580
+
581
+ /**
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
589
+ */
590
+ function bp_action_variable( $position = 0 ) {
591
+ $action_variables = bp_action_variables();
592
+ $action_variable = isset( $action_variables[$position] ) ? $action_variables[$position] : false;
593
+
594
+ return apply_filters( 'bp_action_variable', $action_variable, $position );
595
+ }
596
+
597
+ function bp_root_domain() {
598
+ echo bp_get_root_domain();
599
+ }
600
+ function bp_get_root_domain() {
601
+ global $bp;
602
+
603
+ if ( isset( $bp->root_domain ) && !empty( $bp->root_domain ) ) {
604
+ $domain = $bp->root_domain;
605
+ } else {
606
+ $domain = bp_core_get_root_domain();
607
+ $bp->root_domain = $domain;
608
+ }
609
+
610
+ return apply_filters( 'bp_get_root_domain', $domain );
611
+ }
612
+
613
+ /**
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 );
621
+ }
622
+ /**
623
+ * Gets the root slug for a component slug
624
+ *
625
+ * In order to maintain backward compatibility, the following procedure is used:
626
+ * 1) Use the short slug to get the canonical component name from the
627
+ * active component array
628
+ * 2) Use the component name to get the root slug out of the appropriate part of the $bp
629
+ * global
630
+ * 3) If nothing turns up, it probably means that $component is itself a root slug
631
+ *
632
+ * Example: If your groups directory is at /community/companies, this function first uses
633
+ * the short slug 'companies' (ie the current component) to look up the canonical name
634
+ * 'groups' in $bp->active_components. Then it uses 'groups' to get the root slug, from
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
+ */
644
+ function bp_get_root_slug( $component = '' ) {
645
+ global $bp;
646
+
647
+ $root_slug = '';
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] ) ) {
655
+ // Backward compatibility: in legacy plugins, the canonical component id
656
+ // was stored as an array value in $bp->active_components
657
+ $component_name = '1' == $bp->active_components[$component] ? $component : $bp->active_components[$component];
658
+
659
+ // Component has specific root slug
660
+ if ( !empty( $bp->{$component_name}->root_slug ) ) {
661
+ $root_slug = $bp->{$component_name}->root_slug;
662
+ }
663
+ }
664
+
665
+ // No specific root slug, so fall back to component slug
666
+ if ( empty( $root_slug ) )
667
+ $root_slug = $component;
668
+
669
+ return apply_filters( 'bp_get_root_slug', $root_slug, $component );
670
+ }
671
+
672
+ /**
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
+ */
680
+ function bp_get_name_from_root_slug( $root_slug = '' ) {
681
+ global $bp;
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
+ }
706
+
707
+ /**
708
+ * Output the search slug
709
+ *
710
+ * @package BuddyPress
711
+ * @since 1.5
712
+ *
713
+ * @uses bp_get_search_slug()
714
+ */
715
+ function bp_search_slug() {
716
+ echo bp_get_search_slug();
717
+ }
718
+ /**
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 );
726
+ }
727
+
728
+ /** is_() functions to determine the current page *****************************/
729
+
730
+ /**
731
+ * Checks to see whether the current page belongs to the specified component
732
+ *
733
+ * This function is designed to be generous, accepting several different kinds
734
+ * of value for the $component parameter. It checks $component_name against:
735
+ * - the component's root_slug, which matches the page slug in $bp->pages
736
+ * - the component's regular 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 ) {
744
+ global $bp;
745
+
746
+ $is_current_component = false;
747
+
748
+ // Backward compatibility: 'xprofile' should be read as 'profile'
749
+ if ( 'xprofile' == $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 ) {
756
+ $is_current_component = true;
757
+
758
+ // Since the current component is based on the visible URL slug let's
759
+ // check the component being passed and see if its root_slug matches
760
+ } elseif ( isset( $bp->{$component}->root_slug ) && $bp->{$component}->root_slug == $bp->current_component ) {
761
+ $is_current_component = true;
762
+
763
+ // Because slugs can differ from root_slugs, we should check them too
764
+ } elseif ( isset( $bp->{$component}->slug ) && $bp->{$component}->slug == $bp->current_component ) {
765
+ $is_current_component = true;
766
+
767
+ // Next, check to see whether $component is a canonical,
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
776
+ } else {
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;
785
+ break;
786
+ }
787
+ }
788
+ }
789
+
790
+ // Page template fallback check if $bp->current_component is empty
791
+ } elseif ( !is_admin() && is_page() ) {
792
+ global $wp_query;
793
+ $page = $wp_query->get_queried_object();
794
+ $custom_fields = get_post_custom_values( '_wp_page_template', $page->ID );
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 );
803
+ }
804
+
805
+ /**
806
+ * Check to see whether the current page matches a given action.
807
+ *
808
+ * Along with bp_is_current_component() and bp_is_action_variable(), this function is mostly used
809
+ * to help determine when to use a given screen function.
810
+ *
811
+ * In BP parlance, the current_action is the URL chunk that comes directly after the
812
+ * current item slug. E.g., in
813
+ * http://example.com/groups/my-group/members
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;
829
+ }
830
+
831
+ /**
832
+ * Check to see whether the current page matches a given action_variable.
833
+ *
834
+ * Along with bp_is_current_component() and bp_is_current_action(), this function is mostly used
835
+ * to help determine when to use a given screen function.
836
+ *
837
+ * In BP parlance, action_variables are an array made up of the URL chunks appearing after the
838
+ * current_action in a URL. For example,
839
+ * http://example.com/groups/my-group/admin/group-settings
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,
847
+ * the function will return true if the $action_variable is found *anywhere* in the action
848
+ * variables array.
849
+ * @return bool
850
+ */
851
+ function bp_is_action_variable( $action_variable = '', $position = false ) {
852
+ $is_action_variable = false;
853
+
854
+ if ( false !== $position ) {
855
+ // When a $position is specified, check that slot in the action_variables array
856
+ if ( $action_variable ) {
857
+ $is_action_variable = $action_variable == bp_action_variable( $position );
858
+ } else {
859
+ // If no $action_variable is provided, we are essentially checking to see
860
+ // whether the slot is empty
861
+ $is_action_variable = !bp_action_variable( $position );
862
+ }
863
+ } else {
864
+ // When no $position is specified, check the entire array
865
+ $is_action_variable = in_array( $action_variable, (array)bp_action_variables() );
866
+ }
867
+
868
+ return apply_filters( 'bp_is_action_variable', $is_action_variable, $action_variable, $position );
869
+ }
870
+
871
+ function bp_is_current_item( $item = '' ) {
872
+ if ( !empty( $item ) && $item == bp_current_item() )
873
+ return true;
874
+
875
+ return false;
876
+ }
877
+
878
+ function bp_is_single_item() {
879
+ global $bp;
880
+
881
+ if ( !empty( $bp->is_single_item ) )
882
+ return true;
883
+
884
+ return false;
885
+ }
886
+
887
+ function bp_is_item_admin() {
888
+ global $bp;
889
+
890
+ if ( !empty( $bp->is_item_admin ) )
891
+ return true;
892
+
893
+ return false;
894
+ }
895
+
896
+ function bp_is_item_mod() {
897
+ global $bp;
898
+
899
+ if ( !empty( $bp->is_item_mod ) )
900
+ return true;
901
+
902
+ return false;
903
+ }
904
+
905
+ function bp_is_directory() {
906
+ global $bp;
907
+
908
+ if ( !empty( $bp->is_directory ) )
909
+ return true;
910
+
911
+ return false;
912
+ }
913
+
914
+ /**
915
+ * Checks to see if a component's URL should be in the root, not under a
916
+ * member page:
917
+ *
918
+ * Yes: http://domain.com/groups/the-group
919
+ * No: http://domain.com/members/andy/groups/the-group
920
+ *
921
+ * @package BuddyPress Core
922
+ * @return true if root component, else false.
923
+ */
924
+ function bp_is_root_component( $component_name ) {
925
+ global $bp;
926
+
927
+ if ( !isset( $bp->active_components ) )
928
+ return false;
929
+
930
+ foreach ( (array) $bp->active_components as $key => $slug ) {
931
+ if ( $key == $component_name || $slug == $component_name )
932
+ return true;
933
+ }
934
+
935
+ return false;
936
+ }
937
+
938
+ /**
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;
950
+
951
+ if ( !$component && !empty( $bp->current_component ) )
952
+ $component = $bp->current_component;
953
+
954
+ $path = is_main_site() ? bp_core_get_site_path() : $current_blog->path;
955
+
956
+ if ( 'page' != get_option( 'show_on_front' ) || !$component || empty( $bp->pages->{$component} ) || $_SERVER['REQUEST_URI'] != $path )
957
+ return false;
958
+
959
+ return apply_filters( 'bp_is_component_front_page', ( $bp->pages->{$component}->id == get_option( 'page_on_front' ) ), $component );
960
+ }
961
+
962
+ /**
963
+ * Is this a blog page, ie a non-BP page?
964
+ *
965
+ * You can tell if a page is displaying BP content by whether the current_component has been defined
966
+ *
967
+ * @package BuddyPress
968
+ *
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
+
976
+ // Generally, we can just check to see that there's no current component. The one exception
977
+ // is single user home tabs, where $bp->current_component is unset. Thus the addition
978
+ // of the bp_is_user() check.
979
+ if ( !bp_current_component() && !bp_is_user() )
980
+ $is_blog_page = true;
981
+
982
+ return apply_filters( 'bp_is_blog_page', $is_blog_page );
983
+ }
984
+
985
+ function bp_is_page( $page ) {
986
+ if ( !bp_is_user() && bp_is_current_component( $page ) )
987
+ return true;
988
+
989
+ if ( 'home' == $page )
990
+ return is_front_page();
991
+
992
+ return false;
993
+ }
994
+
995
+ /** Components ****************************************************************/
996
+
997
+ function bp_is_active( $component ) {
998
+ global $bp;
999
+
1000
+ if ( isset( $bp->active_components[$component] ) )
1001
+ return true;
1002
+
1003
+ return false;
1004
+ }
1005
+
1006
+ function bp_is_members_component() {
1007
+ if ( bp_is_current_component( 'members' ) )
1008
+ return true;
1009
+
1010
+ return false;
1011
+ }
1012
+
1013
+ function bp_is_profile_component() {
1014
+ if ( bp_is_current_component( 'xprofile' ) )
1015
+ return true;
1016
+
1017
+ return false;
1018
+ }
1019
+
1020
+ function bp_is_activity_component() {
1021
+ if ( bp_is_current_component( 'activity' ) )
1022
+ return true;
1023
+
1024
+ return false;
1025
+ }
1026
+
1027
+ function bp_is_blogs_component() {
1028
+ if ( is_multisite() && bp_is_current_component( 'blogs' ) )
1029
+ return true;
1030
+
1031
+ return false;
1032
+ }
1033
+
1034
+ function bp_is_messages_component() {
1035
+ if ( bp_is_current_component( 'messages' ) )
1036
+ return true;
1037
+
1038
+ return false;
1039
+ }
1040
+
1041
+ function bp_is_friends_component() {
1042
+ if ( bp_is_current_component( 'friends' ) )
1043
+ return true;
1044
+
1045
+ return false;
1046
+ }
1047
+
1048
+ function bp_is_groups_component() {
1049
+ if ( bp_is_current_component( 'groups' ) )
1050
+ return true;
1051
+
1052
+ return false;
1053
+ }
1054
+
1055
+ function bp_is_forums_component() {
1056
+ if ( bp_is_current_component( 'forums' ) )
1057
+ return true;
1058
+
1059
+ return false;
1060
+ }
1061
+
1062
+ function bp_is_settings_component() {
1063
+ if ( bp_is_current_component( 'settings' ) )
1064
+ return true;
1065
+
1066
+ return false;
1067
+ }
1068
+
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;
1078
+ }
1079
+
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;
1089
+
1090
+ return apply_filters( 'bp_is_my_profile', $my_profile );
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;
1100
+ }
1101
+
1102
+ function bp_is_user_activity() {
1103
+ if ( bp_is_user() && bp_is_activity_component() )
1104
+ return true;
1105
+
1106
+ return false;
1107
+ }
1108
+
1109
+ function bp_is_user_friends_activity() {
1110
+
1111
+ if ( !bp_is_active( 'friends' ) )
1112
+ return false;
1113
+
1114
+ $slug = bp_get_friends_slug();
1115
+
1116
+ if ( empty( $slug ) )
1117
+ $slug = 'friends';
1118
+
1119
+ if ( bp_is_user_activity() && bp_is_current_action( $slug ) )
1120
+ return true;
1121
+
1122
+ return false;
1123
+ }
1124
+
1125
+ function bp_is_user_groups_activity() {
1126
+
1127
+ if ( !bp_is_active( 'groups' ) )
1128
+ return false;
1129
+
1130
+ $slug = bp_get_groups_slug();
1131
+
1132
+ if ( empty( $slug ) )
1133
+ $slug = 'groups';
1134
+
1135
+ if ( bp_is_user_activity() && bp_is_current_action( $slug ) )
1136
+ return true;
1137
+
1138
+ return false;
1139
+ }
1140
+
1141
+ function bp_is_user_profile() {
1142
+ if ( bp_is_profile_component() || bp_is_current_component( 'profile' ) )
1143
+ return true;
1144
+
1145
+ return false;
1146
+ }
1147
+
1148
+ function bp_is_user_profile_edit() {
1149
+ if ( bp_is_profile_component() && bp_is_current_action( 'edit' ) )
1150
+ return true;
1151
+
1152
+ return false;
1153
+ }
1154
+
1155
+ function bp_is_user_change_avatar() {
1156
+ if ( bp_is_profile_component() && bp_is_current_action( 'change-avatar' ) )
1157
+ return true;
1158
+
1159
+ return false;
1160
+ }
1161
+
1162
+ /**
1163
+ * Is this a user's forums page?
1164
+ *
1165
+ * @package BuddyPress
1166
+ *
1167
+ * @return bool
1168
+ */
1169
+ function bp_is_user_forums() {
1170
+ if ( bp_is_user() && bp_is_forums_component() )
1171
+ return true;
1172
+
1173
+ return false;
1174
+ }
1175
+
1176
+ /**
1177
+ * Is this a user's "Topics Started" page?
1178
+ *
1179
+ * @package BuddyPress
1180
+ * @since 1.5
1181
+ *
1182
+ * @return bool
1183
+ */
1184
+ function bp_is_user_forums_started() {
1185
+ if ( bp_is_user_forums() && bp_is_current_action( 'topics' ) )
1186
+ return true;
1187
+
1188
+ return false;
1189
+ }
1190
+
1191
+ /**
1192
+ * Is this a user's "Replied To" page?
1193
+ *
1194
+ * @package BuddyPress
1195
+ * @since 1.5
1196
+ *
1197
+ * @return bool
1198
+ */
1199
+ function bp_is_user_forums_replied_to() {
1200
+ if ( bp_is_user_forums() && bp_is_current_action( 'replies' ) )
1201
+ return true;
1202
+
1203
+ return false;
1204
+ }
1205
+
1206
+ function bp_is_user_groups() {
1207
+ if ( bp_is_user() && bp_is_groups_component() )
1208
+ return true;
1209
+
1210
+ return false;
1211
+ }
1212
+
1213
+ function bp_is_user_blogs() {
1214
+ if ( bp_is_user() && bp_is_blogs_component() )
1215
+ return true;
1216
+
1217
+ return false;
1218
+ }
1219
+
1220
+ function bp_is_user_recent_posts() {
1221
+ if ( bp_is_user_blogs() && bp_is_current_action( 'recent-posts' ) )
1222
+ return true;
1223
+
1224
+ return false;
1225
+ }
1226
+
1227
+ function bp_is_user_recent_commments() {
1228
+ if ( bp_is_user_blogs() && bp_is_current_action( 'recent-comments' ) )
1229
+ return true;
1230
+
1231
+ return false;
1232
+ }
1233
+
1234
+ function bp_is_user_friends() {
1235
+ if ( bp_is_user() && bp_is_friends_component() )
1236
+ return true;
1237
+
1238
+ return false;
1239
+ }
1240
+
1241
+ function bp_is_user_friend_requests() {
1242
+ if ( bp_is_user_friends() && bp_is_current_action( 'requests' ) )
1243
+ return true;
1244
+
1245
+ return false;
1246
+ }
1247
+
1248
+ /**
1249
+ * Is this a user's settings page?
1250
+ *
1251
+ * @package BuddyPress
1252
+ *
1253
+ * @return bool
1254
+ */
1255
+ function bp_is_user_settings() {
1256
+ if ( bp_is_user() && bp_is_settings_component() )
1257
+ return true;
1258
+
1259
+ return false;
1260
+ }
1261
+
1262
+ /**
1263
+ * Is this a user's General Settings page?
1264
+ *
1265
+ * @package BuddyPress
1266
+ * @since 1.5
1267
+ *
1268
+ * @return bool
1269
+ */
1270
+ function bp_is_user_settings_general() {
1271
+ if ( bp_is_user_settings() && bp_is_current_action( 'general' ) )
1272
+ return true;
1273
+
1274
+ return false;
1275
+ }
1276
+
1277
+ /**
1278
+ * Is this a user's Notification Settings page?
1279
+ *
1280
+ * @package BuddyPress
1281
+ * @since 1.5
1282
+ *
1283
+ * @return bool
1284
+ */
1285
+ function bp_is_user_settings_notifications() {
1286
+ if ( bp_is_user_settings() && bp_is_current_action( 'notifications' ) )
1287
+ return true;
1288
+
1289
+ return false;
1290
+ }
1291
+
1292
+ /**
1293
+ * Is this a user's Account Deletion page?
1294
+ *
1295
+ * @package BuddyPress
1296
+ * @since 1.5
1297
+ *
1298
+ * @return bool
1299
+ */
1300
+ function bp_is_user_settings_account_delete() {
1301
+ if ( bp_is_user_settings() && bp_is_current_action( 'delete-account' ) )
1302
+ return true;
1303
+
1304
+ return false;
1305
+ }
1306
+
1307
+
1308
+ /** Groups ******************************************************************/
1309
+
1310
+ function bp_is_group() {
1311
+ global $bp;
1312
+
1313
+ if ( bp_is_groups_component() && isset( $bp->groups->current_group ) && $bp->groups->current_group )
1314
+ return true;
1315
+
1316
+ return false;
1317
+ }
1318
+
1319
+ function bp_is_group_home() {
1320
+ if ( bp_is_single_item() && bp_is_groups_component() && ( !bp_current_action() || bp_is_current_action( 'home' ) ) )
1321
+ return true;
1322
+
1323
+ return false;
1324
+ }
1325
+
1326
+ function bp_is_group_create() {
1327
+ if ( bp_is_groups_component() && bp_is_current_action( 'create' ) )
1328
+ return true;
1329
+
1330
+ return false;
1331
+ }
1332
+
1333
+ function bp_is_group_admin_page() {
1334
+ if ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'admin' ) )
1335
+ return true;
1336
+
1337
+ return false;
1338
+ }
1339
+
1340
+ function bp_is_group_forum() {
1341
+ if ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'forum' ) )
1342
+ return true;
1343
+
1344
+ return false;
1345
+ }
1346
+
1347
+ function bp_is_group_activity() {
1348
+ if ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'activity' ) )
1349
+ return true;
1350
+
1351
+ return false;
1352
+ }
1353
+
1354
+ function bp_is_group_forum_topic() {
1355
+ if ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'forum' ) && bp_is_action_variable( 'topic', 0 ) )
1356
+ return true;
1357
+
1358
+ return false;
1359
+ }
1360
+
1361
+ function bp_is_group_forum_topic_edit() {
1362
+ if ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'forum' ) && bp_is_action_variable( 'topic', 0 ) && bp_is_action_variable( 'edit', 2 ) )
1363
+ return true;
1364
+
1365
+ return false;
1366
+ }
1367
+
1368
+ function bp_is_group_members() {
1369
+ if ( bp_is_single_item() && bp_is_groups_component() && bp_is_current_action( 'members' ) )
1370
+ return true;
1371
+
1372
+ return false;
1373
+ }
1374
+
1375
+ function bp_is_group_invites() {
1376
+ if ( bp_is_groups_component() && bp_is_current_action( 'send-invites' ) )
1377
+ return true;
1378
+
1379
+ return false;
1380
+ }
1381
+
1382
+ function bp_is_group_membership_request() {
1383
+ if ( bp_is_groups_component() && bp_is_current_action( 'request-membership' ) )
1384
+ return true;
1385
+
1386
+ return false;
1387
+ }
1388
+
1389
+ function bp_is_group_leave() {
1390
+
1391
+ if ( bp_is_groups_component() && bp_is_single_item() && bp_is_current_action( 'leave-group' ) )
1392
+ return true;
1393
+
1394
+ return false;
1395
+ }
1396
+
1397
+ function bp_is_group_single() {
1398
+ if ( bp_is_groups_component() && bp_is_single_item() )
1399
+ return true;
1400
+
1401
+ return false;
1402
+ }
1403
+
1404
+ function bp_is_create_blog() {
1405
+ if ( bp_is_blogs_component() && bp_is_current_action( 'create' ) )
1406
+ return true;
1407
+
1408
+ return false;
1409
+ }
1410
+
1411
+ /** Messages ******************************************************************/
1412
+
1413
+ function bp_is_user_messages() {
1414
+ if ( bp_is_user() && bp_is_messages_component() )
1415
+ return true;
1416
+
1417
+ return false;
1418
+ }
1419
+
1420
+ function bp_is_messages_inbox() {
1421
+ if ( bp_is_user_messages() && ( !bp_current_action() || bp_is_current_action( 'inbox' ) ) )
1422
+ return true;
1423
+
1424
+ return false;
1425
+ }
1426
+
1427
+ function bp_is_messages_sentbox() {
1428
+ if ( bp_is_user_messages() && bp_is_current_action( 'sentbox' ) )
1429
+ return true;
1430
+
1431
+ return false;
1432
+ }
1433
+
1434
+ function bp_is_messages_compose_screen() {
1435
+ if ( bp_is_user_messages() && bp_is_current_action( 'compose' ) )
1436
+ return true;
1437
+
1438
+ return false;
1439
+ }
1440
+
1441
+ function bp_is_notices() {
1442
+ if ( bp_is_user_messages() && bp_is_current_action( 'notices' ) )
1443
+ return true;
1444
+
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 ) ) )
1451
+ return true;
1452
+
1453
+ return false;
1454
+ }
1455
+
1456
+ /** Registration **************************************************************/
1457
+
1458
+ function bp_is_activation_page() {
1459
+ if ( bp_is_current_component( 'activate' ) )
1460
+ return true;
1461
+
1462
+ return false;
1463
+ }
1464
+
1465
+ function bp_is_register_page() {
1466
+ if ( bp_is_current_component( 'register' ) )
1467
+ return true;
1468
+
1469
+ return false;
1470
+ }
1471
+
1472
+ /**
1473
+ * Use the above is_() functions to output a body class for each scenario
1474
+ *
1475
+ * @package BuddyPress
1476
+ * @subpackage Core Template
1477
+ *
1478
+ * @param array $wp_classes The body classes coming from WP
1479
+ * @param array $custom_classes Classes that were passed to get_body_class()
1480
+ * @return array $classes The BP-adjusted body classes
1481
+ */
1482
+ function bp_the_body_class() {
1483
+ echo bp_get_the_body_class();
1484
+ }
1485
+ function bp_get_the_body_class( $wp_classes, $custom_classes = false ) {
1486
+
1487
+ $bp_classes = array();
1488
+
1489
+ /** Pages *************************************************************/
1490
+
1491
+ if ( is_front_page() )
1492
+ $bp_classes[] = 'home-page';
1493
+
1494
+ if ( bp_is_directory() )
1495
+ $bp_classes[] = 'directory';
1496
+
1497
+ if ( bp_is_single_item() )
1498
+ $bp_classes[] = 'single-item';
1499
+
1500
+ /** Components ********************************************************/
1501
+
1502
+ if ( !bp_is_blog_page() ) :
1503
+ if ( bp_is_user_profile() )
1504
+ $bp_classes[] = 'xprofile';
1505
+
1506
+ if ( bp_is_activity_component() )
1507
+ $bp_classes[] = 'activity';
1508
+
1509
+ if ( bp_is_blogs_component() )
1510
+ $bp_classes[] = 'blogs';
1511
+
1512
+ if ( bp_is_messages_component() )
1513
+ $bp_classes[] = 'messages';
1514
+
1515
+ if ( bp_is_friends_component() )
1516
+ $bp_classes[] = 'friends';
1517
+
1518
+ if ( bp_is_groups_component() )
1519
+ $bp_classes[] = 'groups';
1520
+
1521
+ if ( bp_is_settings_component() )
1522
+ $bp_classes[] = 'settings';
1523
+ endif;
1524
+
1525
+ /** User **************************************************************/
1526
+
1527
+ if ( !bp_is_directory() ) :
1528
+ if ( bp_is_user_blogs() )
1529
+ $bp_classes[] = 'my-blogs';
1530
+
1531
+ if ( bp_is_user_groups() )
1532
+ $bp_classes[] = 'my-groups';
1533
+
1534
+ if ( bp_is_user_activity() )
1535
+ $bp_classes[] = 'my-activity';
1536
+ endif;
1537
+
1538
+ if ( bp_is_my_profile() )
1539
+ $bp_classes[] = 'my-account';
1540
+
1541
+ if ( bp_is_user_profile() )
1542
+ $bp_classes[] = 'my-profile';
1543
+
1544
+ if ( bp_is_user_friends() )
1545
+ $bp_classes[] = 'my-friends';
1546
+
1547
+ if ( bp_is_user_messages() )
1548
+ $bp_classes[] = 'my-messages';
1549
+
1550
+ if ( bp_is_user_recent_commments() )
1551
+ $bp_classes[] = 'recent-comments';
1552
+
1553
+ if ( bp_is_user_recent_posts() )
1554
+ $bp_classes[] = 'recent-posts';
1555
+
1556
+ if ( bp_is_user_change_avatar() )
1557
+ $bp_classes[] = 'change-avatar';
1558
+
1559
+ if ( bp_is_user_profile_edit() )
1560
+ $bp_classes[] = 'profile-edit';
1561
+
1562
+ if ( bp_is_user_friends_activity() )
1563
+ $bp_classes[] = 'friends-activity';
1564
+
1565
+ if ( bp_is_user_groups_activity() )
1566
+ $bp_classes[] = 'groups-activity';
1567
+
1568
+ if ( is_user_logged_in() )
1569
+ $bp_classes[] = 'logged-in';
1570
+
1571
+ /** Messages **********************************************************/
1572
+
1573
+ if ( bp_is_messages_inbox() )
1574
+ $bp_classes[] = 'inbox';
1575
+
1576
+ if ( bp_is_messages_sentbox() )
1577
+ $bp_classes[] = 'sentbox';
1578
+
1579
+ if ( bp_is_messages_compose_screen() )
1580
+ $bp_classes[] = 'compose';
1581
+
1582
+ if ( bp_is_notices() )
1583
+ $bp_classes[] = 'notices';
1584
+
1585
+ if ( bp_is_user_friend_requests() )
1586
+ $bp_classes[] = 'friend-requests';
1587
+
1588
+ if ( bp_is_create_blog() )
1589
+ $bp_classes[] = 'create-blog';
1590
+
1591
+ /** Groups ************************************************************/
1592
+
1593
+ if ( bp_is_group_leave() )
1594
+ $bp_classes[] = 'leave-group';
1595
+
1596
+ if ( bp_is_group_invites() )
1597
+ $bp_classes[] = 'group-invites';
1598
+
1599
+ if ( bp_is_group_members() )
1600
+ $bp_classes[] = 'group-members';
1601
+
1602
+ if ( bp_is_group_forum_topic() )
1603
+ $bp_classes[] = 'group-forum-topic';
1604
+
1605
+ if ( bp_is_group_forum_topic_edit() )
1606
+ $bp_classes[] = 'group-forum-topic-edit';
1607
+
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';
1619
+
1620
+ if ( bp_is_single_activity() )
1621
+ $bp_classes[] = 'activity-permalink';
1622
+
1623
+ /** Registration ******************************************************/
1624
+
1625
+ if ( bp_is_register_page() )
1626
+ $bp_classes[] = 'registration';
1627
+
1628
+ if ( bp_is_activation_page() )
1629
+ $bp_classes[] = 'activation';
1630
+
1631
+ /** Current Component & Action ****************************************/
1632
+
1633
+ if ( !bp_is_blog_page() ) {
1634
+ $bp_classes[] = bp_current_component();
1635
+ $bp_classes[] = bp_current_action();
1636
+ }
1637
+
1638
+ /** Clean up***********************************************************/
1639
+
1640
+ // We don't want WordPress blog classes to appear on non-blog pages.
1641
+ if ( !bp_is_blog_page() ) {
1642
+
1643
+ // Preserve any custom classes already set
1644
+ if ( !empty( $custom_classes ) ) {
1645
+ $wp_classes = (array) $custom_classes;
1646
+ } else {
1647
+ $wp_classes = array();
1648
+ }
1649
+ }
1650
+
1651
+ // Merge WP classes with BP classes
1652
+ $classes = array_merge( (array) $bp_classes, (array) $wp_classes );
1653
+
1654
+ // Remove any duplicates
1655
+ $classes = array_unique( $classes );
1656
+
1657
+ return apply_filters( 'bp_get_the_body_class', $classes, $bp_classes, $wp_classes, $custom_classes );
1658
+ }
1659
+ add_filter( 'body_class', 'bp_get_the_body_class', 10, 2 );
1660
+
1661
+ ?>
bp-core/bp-core-templatetags.php DELETED
@@ -1,2107 +0,0 @@
1
- <?php
2
- /***
3
- * Members template loop that will allow you to loop all members or friends of a member
4
- * if you pass a user_id.
5
- */
6
-
7
- class BP_Core_Members_Template {
8
- var $current_member = -1;
9
- var $member_count;
10
- var $members;
11
- var $member;
12
-
13
- var $in_the_loop;
14
-
15
- var $pag_page;
16
- var $pag_num;
17
- var $pag_links;
18
- var $total_member_count;
19
-
20
- function bp_core_members_template( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras ) {
21
- global $bp;
22
-
23
- $this->pag_page = isset( $_REQUEST['upage'] ) ? intval( $_REQUEST['upage'] ) : $page_number;
24
- $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
25
- $this->type = $type;
26
-
27
- if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] )
28
- $this->members = BP_Core_User::get_users_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page, $populate_extras );
29
- else
30
- $this->members = bp_core_get_users( array( 'type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'include' => $include, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras ) );
31
-
32
- if ( !$max || $max >= (int)$this->members['total'] )
33
- $this->total_member_count = (int)$this->members['total'];
34
- else
35
- $this->total_member_count = (int)$max;
36
-
37
- $this->members = $this->members['users'];
38
-
39
- if ( $max ) {
40
- if ( $max >= count($this->members) ) {
41
- $this->member_count = count( $this->members );
42
- } else {
43
- $this->member_count = (int)$max;
44
- }
45
- } else {
46
- $this->member_count = count( $this->members );
47
- }
48
-
49
- if ( (int)$this->total_member_count && (int)$this->pag_num ) {
50
- $this->pag_links = paginate_links( array(
51
- 'base' => add_query_arg( 'upage', '%#%' ),
52
- 'format' => '',
53
- 'total' => ceil( (int)$this->total_member_count / (int)$this->pag_num ),
54
- 'current' => (int)$this->pag_page,
55
- 'prev_text' => '&larr;',
56
- 'next_text' => '&rarr;',
57
- 'mid_size' => 1
58
- ) );
59
- }
60
- }
61
-
62
- function has_members() {
63
- if ( $this->member_count )
64
- return true;
65
-
66
- return false;
67
- }
68
-
69
- function next_member() {
70
- $this->current_member++;
71
- $this->member = $this->members[$this->current_member];
72
-
73
- return $this->member;
74
- }
75
-
76
- function rewind_members() {
77
- $this->current_member = -1;
78
- if ( $this->member_count > 0 ) {
79
- $this->member = $this->members[0];
80
- }
81
- }
82
-
83
- function members() {
84
- if ( $this->current_member + 1 < $this->member_count ) {
85
- return true;
86
- } elseif ( $this->current_member + 1 == $this->member_count ) {
87
- do_action('loop_end');
88
- // Do some cleaning up after the loop
89
- $this->rewind_members();
90
- }
91
-
92
- $this->in_the_loop = false;
93
- return false;
94
- }
95
-
96
- function the_member() {
97
- global $member, $bp;
98
-
99
- $this->in_the_loop = true;
100
- $this->member = $this->next_member();
101
-
102
- if ( 0 == $this->current_member ) // loop has just started
103
- do_action('loop_start');
104
- }
105
- }
106
-
107
- function bp_rewind_members() {
108
- global $members_template;
109
-
110
- return $members_template->rewind_members();
111
- }
112
-
113
- function bp_has_members( $args = '' ) {
114
- global $bp, $members_template;
115
-
116
- /***
117
- * Set the defaults based on the current page. Any of these will be overridden
118
- * if arguments are directly passed into the loop. Custom plugins should always
119
- * pass their parameters directly to the loop.
120
- */
121
- $type = 'active';
122
- $user_id = false;
123
- $page = 1;
124
- $search_terms = false;
125
-
126
- // User filtering
127
- if ( !empty( $bp->displayed_user->id ) )
128
- $user_id = $bp->displayed_user->id;
129
-
130
- // Pass a filter if ?s= is set.
131
- if ( isset( $_REQUEST['s'] ) && !empty( $_REQUEST['s'] ) )
132
- $search_terms = $_REQUEST['s'];
133
-
134
- // type: active ( default ) | random | newest | popular | online | alphabetical
135
- $defaults = array(
136
- 'type' => $type,
137
- 'page' => $page,
138
- 'per_page' => 20,
139
- 'max' => false,
140
-
141
- 'include' => false, // Pass a user_id or comma separated list of user_ids to only show these users
142
-
143
- 'user_id' => $user_id, // Pass a user_id to only show friends of this user
144
- 'search_terms' => $search_terms, // Pass search_terms to filter users by their profile data
145
-
146
- 'populate_extras' => true // Fetch usermeta? Friend count, last active etc.
147
- );
148
-
149
- $r = wp_parse_args( $args, $defaults );
150
- extract( $r );
151
-
152
- if ( $max ) {
153
- if ( $per_page > $max )
154
- $per_page = $max;
155
- }
156
-
157
- // Make sure we return no members if we looking at friendship requests and there are none.
158
- if ( empty( $include ) && $bp->friends->slug == $bp->current_component && 'requests' == $bp->current_action )
159
- return false;
160
-
161
- $members_template = new BP_Core_Members_Template( $type, $page, $per_page, $max, $user_id, $search_terms, $include, (bool)$populate_extras );
162
- return apply_filters( 'bp_has_members', $members_template->has_members(), &$members_template );
163
- }
164
-
165
- function bp_the_member() {
166
- global $members_template;
167
- return $members_template->the_member();
168
- }
169
-
170
- function bp_members() {
171
- global $members_template;
172
- return $members_template->members();
173
- }
174
-
175
- function bp_members_pagination_count() {
176
- global $bp, $members_template;
177
-
178
- $start_num = intval( ( $members_template->pag_page - 1 ) * $members_template->pag_num ) + 1;
179
- $from_num = bp_core_number_format( $start_num );
180
- $to_num = bp_core_number_format( ( $start_num + ( $members_template->pag_num - 1 ) > $members_template->total_member_count ) ? $members_template->total_member_count : $start_num + ( $members_template->pag_num - 1 ) );
181
- $total = bp_core_number_format( $members_template->total_member_count );
182
-
183
- if ( 'active' == $members_template->type )
184
- echo sprintf( __( 'Viewing member %1$s to %2$s (of %3$s active members)', 'buddypress' ), $from_num, $to_num, $total );
185
- else if ( 'popular' == $members_template->type )
186
- echo sprintf( __( 'Viewing member %1$s to %2$s (of %3$s members with friends)', 'buddypress' ), $from_num, $to_num, $total );
187
- else if ( 'online' == $members_template->type )
188
- echo sprintf( __( 'Viewing member %1$s to %2$s (of %3$s members online)', 'buddypress' ), $from_num, $to_num, $total );
189
- else
190
- echo sprintf( __( 'Viewing member %1$s to %2$s (of %3$s members)', 'buddypress' ), $from_num, $to_num, $total );
191
-
192
- ?><span class="ajax-loader"></span><?php
193
- }
194
-
195
- function bp_members_pagination_links() {
196
- echo bp_get_members_pagination_links();
197
- }
198
- function bp_get_members_pagination_links() {
199
- global $members_template;
200
-
201
- return apply_filters( 'bp_get_members_pagination_links', $members_template->pag_links );
202
- }
203
-
204
- /**
205
- * bp_member_user_id()
206
- *
207
- * Echo id from bp_get_member_user_id()
208
- *
209
- * @uses bp_get_member_user_id()
210
- */
211
- function bp_member_user_id() {
212
- echo bp_get_member_user_id();
213
- }
214
- /**
215
- * bp_get_member_user_id()
216
- *
217
- * Get the id of the user in a members loop
218
- *
219
- * @global object $members_template
220
- * @return string Members id
221
- */
222
- function bp_get_member_user_id() {
223
- global $members_template;
224
-
225
- return apply_filters( 'bp_get_member_user_id', $members_template->member->id );
226
- }
227
-
228
- /**
229
- * bp_member_user_nicename()
230
- *
231
- * Echo nicename from bp_get_member_user_nicename()
232
- *
233
- * @uses bp_get_member_user_nicename()
234
- */
235
- function bp_member_user_nicename() {
236
- echo bp_get_member_user_nicename();
237
- }
238
- /**
239
- * bp_get_member_user_nicename()
240
- *
241
- * Get the nicename of the user in a members loop
242
- *
243
- * @global object $members_template
244
- * @return string Members nicename
245
- */
246
- function bp_get_member_user_nicename() {
247
- global $members_template;
248
- return apply_filters( 'bp_get_member_user_nicename', $members_template->member->user_nicename );
249
- }
250
-
251
- /**
252
- * bp_member_user_login()
253
- *
254
- * Echo login from bp_get_member_user_login()
255
- *
256
- * @uses bp_get_member_user_login()
257
- */
258
- function bp_member_user_login() {
259
- echo bp_get_member_user_login();
260
- }
261
- /**
262
- * bp_get_member_user_login()
263
- *
264
- * Get the login of the user in a members loop
265
- *
266
- * @global object $members_template
267
- * @return string Members login
268
- */
269
- function bp_get_member_user_login() {
270
- global $members_template;
271
- return apply_filters( 'bp_get_member_user_login', $members_template->member->user_login );
272
- }
273
-
274
- /**
275
- * bp_member_user_email()
276
- *
277
- * Echo email address from bp_get_member_user_email()
278
- *
279
- * @uses bp_get_member_user_email()
280
- */
281
- function bp_member_user_email() {
282
- echo bp_get_member_user_email();
283
- }
284
- /**
285
- * bp_get_member_user_email()
286
- *
287
- * Get the email address of the user in a members loop
288
- *
289
- * @global object $members_template
290
- * @return string Members email address
291
- */
292
- function bp_get_member_user_email() {
293
- global $members_template;
294
- return apply_filters( 'bp_get_member_user_email', $members_template->member->user_email );
295
- }
296
-
297
- function bp_member_is_loggedin_user() {
298
- global $bp, $members_template;
299
- return apply_filters( 'bp_member_is_loggedin_user', $bp->loggedin_user->id == $members_template->member->id ? true : false );
300
- }
301
-
302
- function bp_member_avatar( $args = '' ) {
303
- echo apply_filters( 'bp_member_avatar', bp_get_member_avatar( $args ) );
304
- }
305
- function bp_get_member_avatar( $args = '' ) {
306
- global $bp, $members_template;
307
-
308
- $defaults = array(
309
- 'type' => 'thumb',
310
- 'width' => false,
311
- 'height' => false,
312
- 'class' => 'avatar',
313
- 'id' => false,
314
- 'alt' => __( 'Member avatar', 'buddypress' )
315
- );
316
-
317
- $r = wp_parse_args( $args, $defaults );
318
- extract( $r, EXTR_SKIP );
319
-
320
- return apply_filters( 'bp_get_member_avatar', bp_core_fetch_avatar( array( 'item_id' => $members_template->member->id, 'type' => $type, 'alt' => $alt, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $members_template->member->user_email ) ) );
321
- }
322
-
323
- function bp_member_permalink() {
324
- echo bp_get_member_permalink();
325
- }
326
- function bp_get_member_permalink() {
327
- global $members_template;
328
-
329
- return apply_filters( 'bp_get_member_permalink', bp_core_get_user_domain( $members_template->member->id, $members_template->member->user_nicename, $members_template->member->user_login ) );
330
- }
331
- function bp_member_link() { echo bp_get_member_permalink(); }
332
- function bp_get_member_link() { return bp_get_member_permalink(); }
333
-
334
- function bp_member_name() {
335
- echo apply_filters( 'bp_member_name', bp_get_member_name() );
336
- }
337
- function bp_get_member_name() {
338
- global $members_template;
339
-
340
- if ( empty($members_template->member->fullname) )
341
- $members_template->member->fullname = $members_template->member->display_name;
342
-
343
- return apply_filters( 'bp_get_member_name', $members_template->member->fullname );
344
- }
345
- add_filter( 'bp_get_member_name', 'wp_filter_kses' );
346
- add_filter( 'bp_get_member_name', 'stripslashes' );
347
- add_filter( 'bp_get_member_name', 'strip_tags' );
348
-
349
- function bp_member_last_active() {
350
- echo bp_get_member_last_active();
351
- }
352
- function bp_get_member_last_active() {
353
- global $members_template;
354
-
355
- $last_activity = bp_core_get_last_activity( $members_template->member->last_activity, __( 'active %s ago', 'buddypress' ) );
356
-
357
- return apply_filters( 'bp_member_last_active', $last_activity );
358
- }
359
-
360
- function bp_member_latest_update( $args = '' ) {
361
- echo bp_get_member_latest_update( $args );
362
- }
363
- function bp_get_member_latest_update( $args = '' ) {
364
- global $members_template, $bp;
365
-
366
- $defaults = array(
367
- 'length' => 15
368
- );
369
-
370
- $r = wp_parse_args( $args, $defaults );
371
- extract( $r, EXTR_SKIP );
372
-
373
- if ( !$update = maybe_unserialize( $members_template->member->latest_update ) )
374
- return false;
375
-
376
- $update_content = apply_filters( 'bp_get_activity_latest_update', strip_tags( bp_create_excerpt( $update['content'], $length ) ) );
377
-
378
- if ( !empty( $update['id'] ) )
379
- $update_content .= ' &middot; <a href="' . $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $update['id'] . '">' . __( 'View', 'buddypress' ) . '</a>';
380
-
381
- return apply_filters( 'bp_get_member_latest_update', $update_content );
382
- }
383
-
384
- function bp_member_profile_data( $args = '' ) {
385
- echo bp_get_member_profile_data( $args );
386
- }
387
- function bp_get_member_profile_data( $args = '' ) {
388
- global $members_template;
389
-
390
- if ( !function_exists( 'xprofile_install' ) )
391
- return false;
392
-
393
- $defaults = array(
394
- 'field' => false, // Field name
395
- );
396
-
397
- $r = wp_parse_args( $args, $defaults );
398
- extract( $r, EXTR_SKIP );
399
-
400
- // Populate the user if it hasn't been already.
401
- if ( empty( $members_template->member->profile_data ) && method_exists( 'BP_XProfile_ProfileData', 'get_all_for_user' ) )
402
- $members_template->member->profile_data = BP_XProfile_ProfileData::get_all_for_user( $members_template->member->id );
403
-
404
- $data = xprofile_format_profile_field( $members_template->member->profile_data[$field]['field_type'], $members_template->member->profile_data[$field]['field_data'] );
405
-
406
- return apply_filters( 'bp_get_member_profile_data', $data );
407
- }
408
-
409
- function bp_member_registered() {
410
- echo bp_get_member_registered();
411
- }
412
- function bp_get_member_registered() {
413
- global $members_template;
414
-
415
- $registered = esc_attr( bp_core_get_last_activity( $members_template->member->user_registered, __( 'registered %s ago', 'buddypress' ) ) );
416
-
417
- return apply_filters( 'bp_member_last_active', $registered );
418
- }
419
-
420
- function bp_member_random_profile_data() {
421
- global $members_template;
422
-
423
- if ( function_exists( 'xprofile_get_random_profile_data' ) ) { ?>
424
- <?php $random_data = xprofile_get_random_profile_data( $members_template->member->id, true ); ?>
425
- <strong><?php echo wp_filter_kses( $random_data[0]->name ) ?></strong>
426
- <?php echo wp_filter_kses( $random_data[0]->value ) ?>
427
- <?php }
428
- }
429
-
430
- function bp_member_hidden_fields() {
431
- if ( isset( $_REQUEST['s'] ) ) {
432
- echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['s'] ) . '" name="search_terms" />';
433
- }
434
-
435
- if ( isset( $_REQUEST['letter'] ) ) {
436
- echo '<input type="hidden" id="selected_letter" value="' . esc_attr( $_REQUEST['letter'] ) . '" name="selected_letter" />';
437
- }
438
-
439
- if ( isset( $_REQUEST['members_search'] ) ) {
440
- echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['members_search'] ) . '" name="search_terms" />';
441
- }
442
- }
443
-
444
- function bp_directory_members_search_form() {
445
- global $bp;
446
-
447
- $search_value = __( 'Search anything...', 'buddypress' );
448
- if ( !empty( $_GET['s'] ) )
449
- $search_value = $_GET['s'];
450
-
451
- ?>
452
- <form action="" method="get" id="search-members-form">
453
- <label><input type="text" name="s" id="members_search" value="<?php echo esc_attr( $search_value ) ?>" onfocus="if (this.value == '<?php _e( 'Search anything...', 'buddypress' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search anything...', 'buddypress' ) ?>';}" /></label>
454
- <input type="submit" id="members_search_submit" name="members_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
455
- </form>
456
- <?php
457
- }
458
-
459
- function bp_total_site_member_count() {
460
- echo bp_get_total_site_member_count();
461
- }
462
- function bp_get_total_site_member_count() {
463
- return apply_filters( 'bp_get_total_site_member_count', bp_core_number_format( bp_core_get_total_member_count() ) );
464
- }
465
-
466
-
467
- /** Navigation and other misc template tags **/
468
-
469
- /**
470
- * bp_get_nav()
471
- * TEMPLATE TAG
472
- *
473
- * Uses the $bp->bp_nav global to render out the navigation within a BuddyPress install.
474
- * Each component adds to this navigation array within its own [component_name]_setup_nav() function.
475
- *
476
- * This navigation array is the top level navigation, so it contains items such as:
477
- * [Blog, Profile, Messages, Groups, Friends] ...
478
- *
479
- * The function will also analyze the current component the user is in, to determine whether
480
- * or not to highlight a particular nav item.
481
- *
482
- * @package BuddyPress Core
483
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
484
- */
485
- function bp_get_loggedin_user_nav() {
486
- global $bp, $current_blog;
487
-
488
- /* Loop through each navigation item */
489
- foreach( (array) $bp->bp_nav as $nav_item ) {
490
- /* If the current component matches the nav item id, then add a highlight CSS class. */
491
- if ( !bp_is_directory() && $bp->active_components[$bp->current_component] == $nav_item['css_id'] )
492
- $selected = ' class="current selected"';
493
- else
494
- $selected = '';
495
-
496
- /* If we are viewing another person (current_userid does not equal loggedin_user->id)
497
- then check to see if the two users are friends. if they are, add a highlight CSS class
498
- to the friends nav item if it exists. */
499
- if ( !bp_is_my_profile() && $bp->displayed_user->id ) {
500
- $selected = '';
501
-
502
- if ( function_exists('friends_install') ) {
503
- if ( $nav_item['css_id'] == $bp->friends->id ) {
504
- if ( friends_check_friendship( $bp->loggedin_user->id, $bp->displayed_user->id ) )
505
- $selected = ' class="current selected"';
506
- }
507
- }
508
- }
509
-
510
- /* echo out the final list item */
511
- echo apply_filters( 'bp_get_loggedin_user_nav_' . $nav_item['css_id'], '<li id="li-nav-' . $nav_item['css_id'] . '" ' . $selected . '><a id="my-' . $nav_item['css_id'] . '" href="' . $nav_item['link'] . '">' . $nav_item['name'] . '</a></li>', &$nav_item );
512
- }
513
-
514
- /* Always add a log out list item to the end of the navigation */
515
- if ( function_exists( 'wp_logout_url' ) ) {
516
- $logout_link = '<li><a id="wp-logout" href="' . wp_logout_url( $bp->root_domain ) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';
517
- } else {
518
- $logout_link = '<li><a id="wp-logout" href="' . site_url() . '/wp-login.php?action=logout&amp;redirect_to=' . $bp->root_domain . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';
519
- }
520
-
521
- echo apply_filters( 'bp_logout_nav_link', $logout_link );
522
- }
523
-
524
- /**
525
- * bp_get_displayed_user_nav()
526
- * TEMPLATE TAG
527
- *
528
- * Uses the $bp->bp_users_nav global to render out the user navigation when viewing another user other than
529
- * yourself.
530
- *
531
- * @package BuddyPress Core
532
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
533
- */
534
- function bp_get_displayed_user_nav() {
535
- global $bp;
536
-
537
- foreach ( (array)$bp->bp_nav as $user_nav_item ) {
538
- if ( !$user_nav_item['show_for_displayed_user'] && !bp_is_my_profile() )
539
- continue;
540
-
541
- if ( $bp->current_component == $user_nav_item['slug'] )
542
- $selected = ' class="current selected"';
543
- else
544
- $selected = '';
545
-
546
- if ( $bp->loggedin_user->domain )
547
- $link = str_replace( $bp->loggedin_user->domain, $bp->displayed_user->domain, $user_nav_item['link'] );
548
- else
549
- $link = $bp->displayed_user->domain . $user_nav_item['link'];
550
-
551
- echo apply_filters( 'bp_get_displayed_user_nav_' . $user_nav_item['css_id'], '<li id="' . $user_nav_item['css_id'] . '-personal-li" ' . $selected . '><a id="user-' . $user_nav_item['css_id'] . '" href="' . $link . '">' . $user_nav_item['name'] . '</a></li>', &$user_nav_item );
552
- }
553
- }
554
-
555
- /**
556
- * bp_get_options_nav()
557
- * TEMPLATE TAG
558
- *
559
- * Uses the $bp->bp_options_nav global to render out the sub navigation for the current component.
560
- * Each component adds to its sub navigation array within its own [component_name]_setup_nav() function.
561
- *
562
- * This sub navigation array is the secondary level navigation, so for profile it contains:
563
- * [Public, Edit Profile, Change Avatar]
564
- *
565
- * The function will also analyze the current action for the current component to determine whether
566
- * or not to highlight a particular sub nav item.
567
- *
568
- * @package BuddyPress Core
569
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
570
- * @uses bp_get_user_nav() Renders the navigation for a profile of a currently viewed user.
571
- */
572
- function bp_get_options_nav() {
573
- global $bp;
574
-
575
- if ( count( $bp->bp_options_nav[$bp->current_component] ) < 1 )
576
- return false;
577
-
578
- /* Loop through each navigation item */
579
- foreach ( (array)$bp->bp_options_nav[$bp->current_component] as $subnav_item ) {
580
- if ( !$subnav_item['user_has_access'] )
581
- continue;
582
-
583
- /* If the current action or an action variable matches the nav item id, then add a highlight CSS class. */
584
- if ( $subnav_item['slug'] == $bp->current_action ) {
585
- $selected = ' class="current selected"';
586
- } else {
587
- $selected = '';
588
- }
589
-
590
- /* echo out the final list item */
591
- echo apply_filters( 'bp_get_options_nav_' . $subnav_item['css_id'], '<li id="' . $subnav_item['css_id'] . '-personal-li" ' . $selected . '><a id="' . $subnav_item['css_id'] . '" href="' . $subnav_item['link'] . '">' . $subnav_item['name'] . '</a></li>', $subnav_item );
592
- }
593
- }
594
-
595
- function bp_get_options_title() {
596
- global $bp;
597
-
598
- if ( empty( $bp->bp_options_title ) )
599
- $bp->bp_options_title = __( 'Options', 'buddypress' );
600
-
601
- echo apply_filters( 'bp_get_options_title', esc_attr( $bp->bp_options_title ) );
602
- }
603
-
604
-
605
- /** AVATAR TEMPLATE TAGS *******************************************************/
606
-
607
- /**
608
- * bp_has_options_avatar()
609
- * TEMPLATE TAG
610
- *
611
- * Check to see if there is an options avatar. An options avatar is an avatar for something
612
- * like a group, or a friend. Basically an avatar that appears in the sub nav options bar.
613
- *
614
- * @package BuddyPress Core
615
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
616
- */
617
- function bp_has_options_avatar() {
618
- global $bp;
619
-
620
- if ( empty( $bp->bp_options_avatar ) )
621
- return false;
622
-
623
- return true;
624
- }
625
-
626
- function bp_get_options_avatar() {
627
- global $bp;
628
-
629
- echo apply_filters( 'bp_get_options_avatar', $bp->bp_options_avatar );
630
- }
631
-
632
- function bp_comment_author_avatar() {
633
- global $comment;
634
-
635
- if ( function_exists('bp_core_fetch_avatar') ) {
636
- echo apply_filters( 'bp_comment_author_avatar', bp_core_fetch_avatar( array( 'item_id' => $comment->user_id, 'type' => 'thumb' ) ) );
637
- } else if ( function_exists('get_avatar') ) {
638
- get_avatar();
639
- }
640
- }
641
-
642
- function bp_post_author_avatar() {
643
- global $post;
644
-
645
- if ( function_exists('bp_core_fetch_avatar') ) {
646
- echo apply_filters( 'bp_post_author_avatar', bp_core_fetch_avatar( array( 'item_id' => $post->post_author, 'type' => 'thumb' ) ) );
647
- } else if ( function_exists('get_avatar') ) {
648
- get_avatar();
649
- }
650
- }
651
-
652
- function bp_loggedin_user_avatar( $args = '' ) {
653
- echo bp_get_loggedin_user_avatar( $args );
654
- }
655
- function bp_get_loggedin_user_avatar( $args = '' ) {
656
- global $bp;
657
-
658
- $defaults = array(
659
- 'type' => 'thumb',
660
- 'width' => false,
661
- 'height' => false,
662
- 'html' => true
663
- );
664
-
665
- $r = wp_parse_args( $args, $defaults );
666
- extract( $r, EXTR_SKIP );
667
-
668
- return apply_filters( 'bp_get_loggedin_user_avatar', bp_core_fetch_avatar( array( 'item_id' => $bp->loggedin_user->id, 'type' => $type, 'width' => $width, 'height' => $height, 'html' => $html ) ) );
669
- }
670
-
671
- function bp_displayed_user_avatar( $args = '' ) {
672
- echo bp_get_displayed_user_avatar( $args );
673
- }
674
- function bp_get_displayed_user_avatar( $args = '' ) {
675
- global $bp;
676
-
677
- $defaults = array(
678
- 'type' => 'thumb',
679
- 'width' => false,
680
- 'height' => false,
681
- 'html' => true
682
- );
683
-
684
- $r = wp_parse_args( $args, $defaults );
685
- extract( $r, EXTR_SKIP );
686
-
687
- return apply_filters( 'bp_get_displayed_user_avatar', bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => $type, 'width' => $width, 'height' => $height, 'html' => $html ) ) );
688
- }
689
-
690
- function bp_avatar_admin_step() {
691
- echo bp_get_avatar_admin_step();
692
- }
693
- function bp_get_avatar_admin_step() {
694
- global $bp;
695
-
696
- return apply_filters( 'bp_get_avatar_admin_step', $bp->avatar_admin->step );
697
- }
698
-
699
- function bp_avatar_to_crop() {
700
- echo bp_get_avatar_to_crop();
701
- }
702
- function bp_get_avatar_to_crop() {
703
- global $bp;
704
-
705
- return apply_filters( 'bp_get_avatar_to_crop', $bp->avatar_admin->image->url );
706
- }
707
-
708
- function bp_avatar_to_crop_src() {
709
- echo bp_get_avatar_to_crop_src();
710
- }
711
- function bp_get_avatar_to_crop_src() {
712
- global $bp;
713
-
714
- return apply_filters( 'bp_get_avatar_to_crop_src', str_replace( WP_CONTENT_DIR, '', $bp->avatar_admin->image->dir ) );
715
- }
716
-
717
- function bp_avatar_cropper() {
718
- global $bp;
719
-
720
- echo '<img id="avatar-to-crop" class="avatar" src="' . $bp->avatar_admin->image . '" />';
721
- }
722
-
723
- /** OTHER TEMPLATE TAGS *******************************************************/
724
-
725
- function bp_site_name() {
726
- echo apply_filters( 'bp_site_name', get_blog_option( BP_ROOT_BLOG, 'blogname' ) );
727
- }
728
-
729
- function bp_core_get_wp_profile() {
730
- global $bp;
731
-
732
- $ud = get_userdata( $bp->displayed_user->id );
733
- ?>
734
-
735
- <div class="bp-widget wp-profile">
736
- <h4><?php _e( 'My Profile' ) ?></h4>
737
-
738
- <table class="wp-profile-fields zebra">
739
- <?php if ( $ud->display_name ) { ?>
740
- <tr id="wp_displayname">
741
- <td class="label">
742
- <?php _e( 'Name', 'buddypress' ) ?>
743
- </td>
744
- <td class="data">
745
- <?php echo $ud->display_name ?>
746
- </td>
747
- </tr>
748
- <?php } ?>
749
- <?php if ( $ud->user_description ) { ?>
750
- <tr id="wp_desc">
751
- <td class="label">
752
- <?php _e( 'About Me', 'buddypress' ) ?>
753
- </td>
754
- <td class="data">
755
- <?php echo $ud->user_description ?>
756
- </td>
757
- </tr>
758
- <?php } ?>
759
- <?php if ( $ud->user_url ) { ?>
760
- <tr id="wp_website">
761
- <td class="label">
762
- <?php _e( 'Website', 'buddypress' ) ?>
763
- </td>
764
- <td class="data">
765
- <?php echo make_clickable( $ud->user_url ) ?>
766
- </td>
767
- </tr>
768
- <?php } ?>
769
- <?php if ( $ud->jabber ) { ?>
770
- <tr id="wp_jabber">
771
- <td class="label">
772
- <?php _e( 'Jabber', 'buddypress' ) ?>
773
- </td>
774
- <td class="data">
775
- <?php echo $ud->jabber ?>
776
- </td>
777
- </tr>
778
- <?php } ?>
779
- <?php if ( $ud->aim ) { ?>
780
- <tr id="wp_aim">
781
- <td class="label">
782
- <?php _e( 'AOL Messenger', 'buddypress' ) ?>
783
- </td>
784
- <td class="data">
785
- <?php echo $ud->aim ?>
786
- </td>
787
- </tr>
788
- <?php } ?>
789
- <?php if ( $ud->yim ) { ?>
790
- <tr id="wp_yim">
791
- <td class="label">
792
- <?php _e( 'Yahoo Messenger', 'buddypress' ) ?>
793
- </td>
794
- <td class="data">
795
- <?php echo $ud->yim ?>
796
- </td>
797
- </tr>
798
- <?php } ?>
799
- </table>
800
- </div>
801
- <?php
802
- }
803
-
804
- function bp_get_profile_header() {
805
- locate_template( array( '/profile/profile-header.php' ), true );
806
- }
807
-
808
- function bp_exists( $component_name ) {
809
- if ( function_exists($component_name . '_install') )
810
- return true;
811
-
812
- return false;
813
- }
814
-
815
- function bp_format_time( $time, $just_date = false ) {
816
- if ( !$time )
817
- return false;
818
-
819
- // Get GMT offset from root blog
820
- $root_blog_offset = get_blog_option( BP_ROOT_BLOG, 'gmt_offset' );
821
-
822
- // Calculate offset time
823
- $time_offset = $time + ( $root_blog_offset * 3600 );
824
-
825
- // Current date (January 1, 2010)
826
- $date = date( 'F j, Y ', $time_offset );
827
-
828
- // Should we show the time also?
829
- if ( !$just_date ) {
830
- // Current time (9:50pm)
831
- $time = date( ' g:ia', $time_offset );
832
-
833
- // Return string formatted with date and time
834
- $date = sprintf( __( '%1$s at %2$s', 'buddypress' ), $date, $time );
835
- }
836
-
837
- return apply_filters( 'bp_format_time', $date );
838
- }
839
-
840
- function bp_word_or_name( $youtext, $nametext, $capitalize = true, $echo = true ) {
841
- global $bp;
842
-
843
- if ( $capitalize )
844
- $youtext = bp_core_ucfirst($youtext);
845
-
846
- if ( $bp->displayed_user->id == $bp->loggedin_user->id ) {
847
- if ( $echo )
848
- echo apply_filters( 'bp_word_or_name', $youtext );
849
- else
850
- return apply_filters( 'bp_word_or_name', $youtext );
851
- } else {
852
- $fullname = (array)explode( ' ', $bp->displayed_user->fullname );
853
- $nametext = sprintf( $nametext, $fullname[0] );
854
- if ( $echo )
855
- echo apply_filters( 'bp_word_or_name', $nametext );
856
- else
857
- return apply_filters( 'bp_word_or_name', $nametext );
858
- }
859
- }
860
-
861
- function bp_your_or_their( $capitalize = true, $echo = true ) {
862
- global $bp;
863
-
864
- if ( $capitalize )
865
- $yourtext = bp_core_ucfirst($yourtext);
866
-
867
- if ( $bp->displayed_user->id == $bp->loggedin_user->id ) {
868
- if ( $echo )
869
- echo apply_filters( 'bp_your_or_their', $yourtext );
870
- else
871
- return apply_filters( 'bp_your_or_their', $yourtext );
872
- } else {
873
- if ( $echo )
874
- echo apply_filters( 'bp_your_or_their', $theirtext );
875
- else
876
- return apply_filters( 'bp_your_or_their', $theirtext );
877
- }
878
- }
879
-
880
- function bp_get_plugin_sidebar() {
881
- locate_template( array( 'plugin-sidebar.php' ), true );
882
- }
883
-
884
- function bp_page_title() {
885
- echo bp_get_page_title();
886
- }
887
-
888
- function bp_get_page_title() {
889
- global $bp, $post, $wp_query, $current_blog;
890
-
891
- if ( is_front_page() || ( is_home() && bp_is_page( 'home' ) ) ) {
892
- $title = __( 'Home', 'buddypress' );
893
-
894
- } else if ( bp_is_blog_page() ) {
895
- if ( is_single() ) {
896
- $title = __( 'Blog &#124; ' . $post->post_title, 'buddypress' );
897
- } else if ( is_category() ) {
898
- $title = __( 'Blog &#124; Categories &#124; ' . ucwords( $wp_query->query_vars['category_name'] ), 'buddypress' );
899
- } else if ( is_tag() ) {
900
- $title = __( 'Blog &#124; Tags &#124; ' . ucwords( $wp_query->query_vars['tag'] ), 'buddypress' );
901
- } else if ( is_page() ){
902
- $title = $post->post_title;
903
- } else
904
- $title = __( 'Blog', 'buddypress' );
905
-
906
- } else if ( !empty( $bp->displayed_user->fullname ) ) {
907
- $title = strip_tags( $bp->displayed_user->fullname . ' &#124; ' . ucwords( $bp->current_component ) );
908
-
909
- } else if ( $bp->is_single_item ) {
910
- $title = ucwords( $bp->current_component ) . ' &#124; ' . $bp->bp_options_title . ' &#124; ' . $bp->bp_options_nav[$bp->current_component][$bp->current_action]['name'];
911
-
912
- } else if ( $bp->is_directory ) {
913
- if ( !$bp->current_component )
914
- $title = sprintf( __( '%s Directory', 'buddypress' ), ucwords( BP_MEMBERS_SLUG ) );
915
- else
916
- $title = sprintf( __( '%s Directory', 'buddypress' ), ucwords( $bp->current_component ) );
917
-
918
- } else if ( bp_is_register_page() ) {
919
- $title = __( 'Create an Account', 'buddypress' );
920
-
921
- } else if ( bp_is_activation_page() ) {
922
- $title = __( 'Activate your Account', 'buddypress' );
923
-
924
- } else if ( bp_is_group_create() ) {
925
- $title = __( 'Create a Group', 'buddypress' );
926
-
927
- } else if ( bp_is_create_blog() ) {
928
- $title = __( 'Create a Blog', 'buddypress' );
929
- }
930
-
931
- if ( defined( 'BP_ENABLE_MULTIBLOG' ) ) {
932
- $blog_title = get_blog_option( $current_blog->blog_id, 'blogname' );
933
- } else {
934
- $blog_title = get_blog_option( BP_ROOT_BLOG, 'blogname' );
935
- }
936
-
937
- return apply_filters( 'bp_page_title', $blog_title . ' &#124; ' . esc_attr( $title ), esc_attr( $title ) );
938
- }
939
-
940
- function bp_styles() {
941
- do_action( 'bp_styles' );
942
- wp_print_styles();
943
- }
944
-
945
- function bp_has_custom_signup_page() {
946
- if ( locate_template( array( 'register.php' ), false ) || locate_template( array( '/registration/register.php' ), false ) )
947
- return true;
948
-
949
- return false;
950
- }
951
-
952
- function bp_signup_page() {
953
- echo bp_get_signup_page();
954
- }
955
- function bp_get_signup_page() {
956
- global $bp;
957
-
958
- if ( bp_has_custom_signup_page() )
959
- $page = $bp->root_domain . '/' . BP_REGISTER_SLUG;
960
- else
961
- $page = $bp->root_domain . '/wp-signup.php';
962
-
963
- return apply_filters( 'bp_get_signup_page', $page );
964
- }
965
-
966
- function bp_has_custom_activation_page() {
967
- if ( locate_template( array( 'activate.php' ), false ) || locate_template( array( '/registration/activate.php' ), false ) )
968
- return true;
969
-
970
- return false;
971
- }
972
-
973
- function bp_activation_page() {
974
- echo bp_get_activation_page();
975
- }
976
- function bp_get_activation_page() {
977
- global $bp;
978
-
979
- if ( bp_has_custom_activation_page() )
980
- $page = trailingslashit( $bp->root_domain ) . BP_ACTIVATION_SLUG;
981
- else
982
- $page = trailingslashit( $bp->root_domain ) . 'wp-activate.php';
983
-
984
- return apply_filters( 'bp_get_activation_page', $page );
985
- }
986
-
987
- /**
988
- * bp_search_form_available()
989
- *
990
- * Only show the search form if there are available objects to search for.
991
- *
992
- * @global array $bp
993
- * @uses function_exists
994
- * @uses bp_core_is_multisite()
995
- * @return bool Filterable result
996
- */
997
- function bp_search_form_enabled() {
998
- global $bp;
999
-
1000
- if ( function_exists( 'xprofile_install' )
1001
- || function_exists( 'groups_install' )
1002
- || ( function_exists( 'bp_blogs_install' ) && bp_core_is_multisite() )
1003
- || ( function_exists( 'bp_forums_setup' ) && !(int)$bp->site_options['bp-disable-forum-directory'] )
1004
- ) {
1005
- $search_enabled = true;
1006
- } else {
1007
- $search_enabled = false;
1008
- }
1009
-
1010
- return apply_filters( 'bp_search_form_enabled', $search_enabled );
1011
- }
1012
-
1013
- function bp_search_form_action() {
1014
- global $bp;
1015
-
1016
- return apply_filters( 'bp_search_form_action', $bp->root_domain . '/' . BP_SEARCH_SLUG );
1017
- }
1018
-
1019
- function bp_search_form_type_select() {
1020
- global $bp;
1021
-
1022
- // Eventually this won't be needed and a page will be built to integrate all search results.
1023
- $selection_box = '<select name="search-which" id="search-which" style="width: auto">';
1024
-
1025
- if ( function_exists( 'xprofile_install' ) )
1026
- $selection_box .= '<option value="members">' . __( 'Members', 'buddypress' ) . '</option>';
1027
-
1028
- if ( function_exists( 'groups_install' ) )
1029
- $selection_box .= '<option value="groups">' . __( 'Groups', 'buddypress' ) . '</option>';
1030
-
1031
- if ( function_exists( 'bp_forums_setup' ) && !(int)$bp->site_options['bp-disable-forum-directory'] )
1032
- $selection_box .= '<option value="forums">' . __( 'Forums', 'buddypress' ) . '</option>';
1033
-
1034
- if ( function_exists( 'bp_blogs_install' ) && bp_core_is_multisite() )
1035
- $selection_box .= '<option value="blogs">' . __( 'Blogs', 'buddypress' ) . '</option>';
1036
-
1037
- $selection_box .= '</select>';
1038
-
1039
- return apply_filters( 'bp_search_form_type_select', $selection_box );
1040
- }
1041
-
1042
- function bp_search_form() {
1043
- $form = '
1044
- <form action="' . bp_search_form_action() . '" method="post" id="search-form">
1045
- <input type="text" id="search-terms" name="search-terms" value="" />
1046
- ' . bp_search_form_type_select() . '
1047
-
1048
- <input type="submit" name="search-submit" id="search-submit" value="' . __( 'Search', 'buddypress' ) . '" />
1049
- ' . wp_nonce_field( 'bp_search_form' ) . '
1050
- </form>
1051
- ';
1052
-
1053
- echo apply_filters( 'bp_search_form', $form );
1054
- }
1055
-
1056
- function bp_log_out_link() {
1057
- global $bp;
1058
- if ( function_exists('wp_logout_url') )
1059
- $logout_link = '<a href="' . wp_logout_url( $bp->root_domain ) . '">' . __( 'Log Out', 'buddypress' ) . '</a>';
1060
- else
1061
- $logout_link = '<a href="' . $bp->root_domain . '/wp-login.php?action=logout&amp;redirect_to=' . $bp->root_domain . '">' . __( 'Log Out', 'buddypress' ) . '</a>';
1062
-
1063
- echo apply_filters( 'bp_logout_link', $logout_link );
1064
- }
1065
-
1066
- function bp_custom_profile_boxes() {
1067
- do_action( 'bp_custom_profile_boxes' );
1068
- }
1069
-
1070
- function bp_custom_profile_sidebar_boxes() {
1071
- do_action( 'bp_custom_profile_sidebar_boxes' );
1072
- }
1073
-
1074
- /**
1075
- * bp_button( $button )
1076
- *
1077
- * Creates and outputs a button.
1078
- * Args: div_id | div_class | a_href | a_title | a_id | a_class | a_rel | a_text
1079
- *
1080
- * @param array $button
1081
- */
1082
- function bp_button( $button = '' ) {
1083
- echo bp_get_button( $button );
1084
- }
1085
- /**
1086
- * bp_get_button( $button )
1087
- *
1088
- * Creates and returns a button.
1089
- * Args: div_id | div_class | a_href | a_title | a_id | a_class | a_rel | a_text
1090
- *
1091
- * @param array $button
1092
- * @return string
1093
- */
1094
- function bp_get_button( $button = '' ) {
1095
- $btn = new BP_Button( $button );
1096
- return apply_filters( 'bp_get_button', $btn->contents, $button );
1097
- }
1098
-
1099
- /**
1100
- * bp_create_excerpt()
1101
- *
1102
- * Fakes an excerpt on any content. Will not truncate words.
1103
- *
1104
- * @package BuddyPress Core
1105
- * @param $text str The text to create the excerpt from
1106
- * @uses $excerpt_length The maximum length in characters of the excerpt.
1107
- * @return str The excerpt text
1108
- */
1109
- function bp_create_excerpt( $text, $excerpt_length = 55, $filter_shortcodes = true ) { // Fakes an excerpt if needed
1110
- $text = str_replace(']]>', ']]&gt;', $text);
1111
-
1112
- if ( $filter_shortcodes )
1113
- $text = preg_replace( '|\[(.+?)\](.+?\[/\\1\])?|s', '', $text );
1114
-
1115
- $words = preg_split(
1116
- "%\s*((?:<[^>]+>)+\S*)\s*|\s+%s",
1117
- $text,
1118
- $excerpt_length + 1,
1119
- PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE
1120
- );
1121
-
1122
- if (count($words) > $excerpt_length) {
1123
- array_pop($words);
1124
- array_push($words, '[...]');
1125
- $text = implode(' ', $words);
1126
- }
1127
-
1128
- return apply_filters( 'bp_create_excerpt', $text );
1129
- }
1130
- add_filter( 'bp_create_excerpt', 'wp_trim_excerpt' );
1131
- add_filter( 'bp_create_excerpt', 'stripslashes_deep' );
1132
- add_filter( 'bp_create_excerpt', 'force_balance_tags' );
1133
-
1134
- function bp_total_member_count() {
1135
- echo bp_get_total_member_count();
1136
- }
1137
- function bp_get_total_member_count() {
1138
- return apply_filters( 'bp_get_total_member_count', bp_core_get_total_member_count() );
1139
- }
1140
- add_filter( 'bp_get_total_member_count', 'bp_core_number_format' );
1141
-
1142
- /*** Signup form template tags **********************/
1143
-
1144
- function bp_signup_username_value() {
1145
- echo bp_get_signup_username_value();
1146
- }
1147
- function bp_get_signup_username_value() {
1148
- return apply_filters( 'bp_get_signup_username_value', $_POST['signup_username'] );
1149
- }
1150
-
1151
- function bp_signup_email_value() {
1152
- echo bp_get_signup_email_value();
1153
- }
1154
- function bp_get_signup_email_value() {
1155
- return apply_filters( 'bp_get_signup_email_value', $_POST['signup_email'] );
1156
- }
1157
-
1158
- function bp_signup_with_blog_value() {
1159
- echo bp_get_signup_with_blog_value();
1160
- }
1161
- function bp_get_signup_with_blog_value() {
1162
- return apply_filters( 'bp_get_signup_with_blog_value', $_POST['signup_with_blog'] );
1163
- }
1164
-
1165
- function bp_signup_blog_url_value() {
1166
- echo bp_get_signup_blog_url_value();
1167
- }
1168
- function bp_get_signup_blog_url_value() {
1169
- return apply_filters( 'bp_get_signup_blog_url_value', $_POST['signup_blog_url'] );
1170
- }
1171
-
1172
- function bp_signup_blog_title_value() {
1173
- echo bp_get_signup_blog_title_value();
1174
- }
1175
- function bp_get_signup_blog_title_value() {
1176
- return apply_filters( 'bp_get_signup_blog_title_value', $_POST['signup_blog_title'] );
1177
- }
1178
-
1179
- function bp_signup_blog_privacy_value() {
1180
- echo bp_get_signup_blog_privacy_value();
1181
- }
1182
- function bp_get_signup_blog_privacy_value() {
1183
- return apply_filters( 'bp_get_signup_blog_privacy_value', $_POST['signup_blog_privacy'] );
1184
- }
1185
-
1186
- function bp_signup_avatar_dir_value() {
1187
- echo bp_get_signup_avatar_dir_value();
1188
- }
1189
- function bp_get_signup_avatar_dir_value() {
1190
- global $bp;
1191
-
1192
- // Check if signup_avatar_dir is passed
1193
- if ( !empty( $_POST['signup_avatar_dir'] ) )
1194
- $signup_avatar_dir = $_POST['signup_avatar_dir'];
1195
-
1196
- // If not, check if global is set
1197
- elseif ( !empty( $bp->signup->avatar_dir ) )
1198
- $signup_avatar_dir = $bp->signup->avatar_dir;
1199
-
1200
- // If not, set false
1201
- else
1202
- $signup_avatar_dir = false;
1203
-
1204
- return apply_filters( 'bp_get_signup_avatar_dir_value', $bp->signup->avatar_dir );
1205
- }
1206
-
1207
- function bp_current_signup_step() {
1208
- echo bp_get_current_signup_step();
1209
- }
1210
- function bp_get_current_signup_step() {
1211
- global $bp;
1212
-
1213
- return $bp->signup->step;
1214
- }
1215
-
1216
- function bp_signup_avatar( $args = '' ) {
1217
- echo bp_get_signup_avatar( $args );
1218
- }
1219
- function bp_get_signup_avatar( $args = '' ) {
1220
- global $bp;
1221
-
1222
- $defaults = array(
1223
- 'size' => BP_AVATAR_FULL_WIDTH,
1224
- 'class' => 'avatar',
1225
- 'alt' => __( 'Your Avatar', 'buddypress' )
1226
- );
1227
-
1228
- $r = wp_parse_args( $args, $defaults );
1229
- extract( $r, EXTR_SKIP );
1230
-
1231
- // Avatar DIR is found
1232
- if ( $signup_avatar_dir = bp_get_signup_avatar_dir_value() ) {
1233
- $gravatar_img = bp_core_fetch_avatar( array(
1234
- 'item_id' => $signup_avatar_dir,
1235
- 'object' => 'signup',
1236
- 'avatar_dir' => 'avatars/signups',
1237
- 'type' => 'full',
1238
- 'width' => $size,
1239
- 'height' => $size,
1240
- 'alt' => $alt,
1241
- 'class' => $class
1242
- ) );
1243
-
1244
- // No avatar DIR was found
1245
- } else {
1246
-
1247
- // Set default gravatar type
1248
- if ( empty( $bp->grav_default->user ) )
1249
- $default_grav = 'wavatar';
1250
- else if ( 'mystery' == $bp->grav_default->user )
1251
- $default_grav = BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg';
1252
- else
1253
- $default_grav = $bp->grav_default->user;
1254
-
1255
- // Create
1256
- $gravatar_url = apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' );
1257
- $md5_lcase_email = md5( strtolower( bp_get_signup_email_value() ) );
1258
- $gravatar_img = '<img src="' . $gravatar_url . $md5_lcase_email . '?d=' . $default_grav . '&amp;s=' . $size . '" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" class="' . $class . '" />';
1259
- }
1260
-
1261
- return apply_filters( 'bp_get_signup_avatar', $gravatar_img, $args );
1262
- }
1263
-
1264
- function bp_signup_allowed() {
1265
- echo bp_get_signup_allowed();
1266
- }
1267
- function bp_get_signup_allowed() {
1268
- global $bp;
1269
-
1270
- if ( bp_core_is_multisite() ) {
1271
- if ( in_array( $bp->site_options['registration'], array( 'all', 'user' ) ) )
1272
- return true;
1273
- } else {
1274
- if ( (int)get_option( 'users_can_register') )
1275
- return true;
1276
- }
1277
- return false;
1278
- }
1279
-
1280
- function bp_blog_signup_allowed() {
1281
- echo bp_get_blog_signup_allowed();
1282
- }
1283
- function bp_get_blog_signup_allowed() {
1284
- global $bp;
1285
-
1286
- if ( !bp_core_is_multisite() )
1287
- return false;
1288
-
1289
- $status = $bp->site_options['registration'];
1290
- if ( 'none' != $status && 'user' != $status )
1291
- return true;
1292
-
1293
- return false;
1294
- }
1295
-
1296
- function bp_account_was_activated() {
1297
- global $bp;
1298
-
1299
- return $bp->activation_complete;
1300
- }
1301
-
1302
- function bp_registration_needs_activation() {
1303
- return apply_filters( 'bp_registration_needs_activation', true );
1304
- }
1305
-
1306
- function bp_mentioned_user_display_name( $user_id_or_username ) {
1307
- echo bp_get_mentioned_user_display_name( $user_id_or_username );
1308
- }
1309
- function bp_get_mentioned_user_display_name( $user_id_or_username ) {
1310
- if ( !$name = bp_core_get_user_displayname( $user_id_or_username ) )
1311
- $name = __( 'a user' );
1312
-
1313
- return apply_filters( 'bp_get_mentioned_user_display_name', $name, $user_id_or_username );
1314
- }
1315
-
1316
- function bp_get_option( $option_name ) {
1317
- global $bp;
1318
-
1319
- return apply_filters( 'bp_get_option', $bp->site_options[$option_name] );
1320
- }
1321
-
1322
- /**
1323
- * Allow templates to pass parameters directly into the template loops via AJAX
1324
- *
1325
- * For the most part this will be filtered in a theme's functions.php for example
1326
- * in the default theme it is filtered via bp_dtheme_ajax_querystring()
1327
- *
1328
- * By using this template tag in the templates it will stop them from showing errors
1329
- * if someone copies the templates from the default theme into another WordPress theme
1330
- * without coping the functions from functions.php.
1331
- */
1332
- function bp_ajax_querystring( $object = false ) {
1333
- global $bp;
1334
-
1335
- $bp->ajax_querystring = apply_filters( 'bp_ajax_querystring', $query_string, $object );
1336
- return $bp->ajax_querystring;
1337
- }
1338
-
1339
-
1340
- /*** CUSTOM LOOP TEMPLATE CLASSES *******************/
1341
-
1342
-
1343
- /* Template functions for fetching globals, without querying the DB again
1344
- also means we dont have to use the $bp variable in the template (looks messy) */
1345
-
1346
- function bp_last_activity( $user_id = false, $echo = true ) {
1347
- global $bp;
1348
-
1349
- if ( !$user_id )
1350
- $user_id = $bp->displayed_user->id;
1351
-
1352
- $last_activity = bp_core_get_last_activity( get_user_meta( $user_id, 'last_activity', true ), __('active %s ago', 'buddypress') );
1353
-
1354
- if ( $echo )
1355
- echo apply_filters( 'bp_last_activity', $last_activity );
1356
- else
1357
- return apply_filters( 'bp_last_activity', $last_activity );
1358
- }
1359
-
1360
- function bp_user_has_access() {
1361
- global $bp;
1362
-
1363
- if ( is_super_admin() || is_user_logged_in() && $bp->loggedin_user->id == $bp->displayed_user->id )
1364
- $has_access = true;
1365
- else
1366
- $has_access = false;
1367
-
1368
- return apply_filters( 'bp_user_has_access', $has_access );
1369
- }
1370
-
1371
- function bp_user_firstname() {
1372
- echo bp_get_user_firstname();
1373
- }
1374
- function bp_get_user_firstname( $name = false ) {
1375
- global $bp;
1376
-
1377
- // Try to get displayed user
1378
- if ( empty( $name ) )
1379
- $name = $bp->displayed_user->fullname;
1380
-
1381
- // Fall back on logged in user
1382
- if ( empty( $name ) )
1383
- $name = $bp->loggedin_user->fullname;
1384
-
1385
- $fullname = (array)explode( ' ', $name );
1386
-
1387
- return apply_filters( 'bp_get_user_firstname', $fullname[0], $fullname );
1388
- }
1389
-
1390
- function bp_loggedin_user_link() {
1391
- echo bp_get_loggedin_user_link();
1392
- }
1393
- function bp_get_loggedin_user_link() {
1394
- global $bp;
1395
-
1396
- return apply_filters( 'bp_get_loggedin_user_link', $bp->loggedin_user->domain );
1397
- }
1398
-
1399
- /* @todo Deprecate incorrectly named function? */
1400
- function bp_loggedinuser_link() {
1401
- global $bp;
1402
-
1403
- if ( $link = bp_core_get_userlink( $bp->loggedin_user->id ) )
1404
- echo apply_filters( 'bp_loggedin_user_link', $link );
1405
- }
1406
-
1407
- function bp_displayed_user_link() {
1408
- echo bp_get_displayed_user_link();
1409
- }
1410
- function bp_get_displayed_user_link() {
1411
- global $bp;
1412
-
1413
- return apply_filters( 'bp_get_displayed_user_link', $bp->displayed_user->domain );
1414
- }
1415
- function bp_user_link() { bp_displayed_user_link(); } // Deprecated.
1416
-
1417
- function bp_displayed_user_id() {
1418
- global $bp;
1419
- return apply_filters( 'bp_displayed_user_id', $bp->displayed_user->id );
1420
- }
1421
- function bp_current_user_id() { return bp_displayed_user_id(); }
1422
-
1423
- function bp_loggedin_user_id() {
1424
- global $bp;
1425
- return apply_filters( 'bp_loggedin_user_id', $bp->loggedin_user->id );
1426
- }
1427
-
1428
- function bp_displayed_user_domain() {
1429
- global $bp;
1430
- return apply_filters( 'bp_displayed_user_domain', $bp->displayed_user->domain );
1431
- }
1432
-
1433
- function bp_loggedin_user_domain() {
1434
- global $bp;
1435
- return apply_filters( 'bp_loggedin_user_domain', $bp->loggedin_user->domain );
1436
- }
1437
-
1438
- function bp_displayed_user_fullname() {
1439
- echo bp_get_displayed_user_fullname();
1440
- }
1441
- function bp_get_displayed_user_fullname() {
1442
- global $bp;
1443
-
1444
- return apply_filters( 'bp_displayed_user_fullname', $bp->displayed_user->fullname );
1445
- }
1446
- function bp_user_fullname() { echo bp_get_displayed_user_fullname(); }
1447
-
1448
-
1449
- function bp_loggedin_user_fullname() {
1450
- echo bp_get_loggedin_user_fullname();
1451
- }
1452
- function bp_get_loggedin_user_fullname() {
1453
- global $bp;
1454
- return apply_filters( 'bp_get_loggedin_user_fullname', $bp->loggedin_user->fullname );
1455
- }
1456
-
1457
- function bp_displayed_user_username() {
1458
- echo bp_get_displayed_user_username();
1459
- }
1460
- function bp_get_displayed_user_username() {
1461
- global $bp;
1462
- return apply_filters( 'bp_get_displayed_user_username', bp_core_get_username( $bp->displayed_user->id, $bp->displayed_user->userdata->user_nicename, $bp->displayed_user->userdata->user_login ) );
1463
- }
1464
-
1465
- function bp_loggedin_user_username() {
1466
- echo bp_get_loggedin_user_username();
1467
- }
1468
- function bp_get_loggedin_user_username() {
1469
- global $bp;
1470
- return apply_filters( 'bp_get_loggedin_user_username', bp_core_get_username( $bp->loggedin_user->id, $bp->loggedin_user->userdata->user_nicename, $bp->loggedin_user->userdata->user_login ) );
1471
- }
1472
-
1473
- function bp_current_component() {
1474
- global $bp;
1475
- return apply_filters( 'bp_current_component', $bp->current_component );
1476
- }
1477
-
1478
- function bp_current_action() {
1479
- global $bp;
1480
- return apply_filters( 'bp_current_action', $bp->current_action );
1481
- }
1482
-
1483
- function bp_current_item() {
1484
- global $bp;
1485
- return apply_filters( 'bp_current_item', $bp->current_item );
1486
- }
1487
-
1488
- function bp_action_variables() {
1489
- global $bp;
1490
- return apply_filters( 'bp_action_variables', $bp->action_variables );
1491
- }
1492
-
1493
- function bp_root_domain() {
1494
- echo bp_get_root_domain();
1495
- }
1496
- function bp_get_root_domain() {
1497
- global $bp;
1498
-
1499
- return apply_filters( 'bp_get_root_domain', $bp->root_domain );
1500
- }
1501
-
1502
- /* Template is_() functions to determine the current page */
1503
-
1504
- function bp_is_blog_page() {
1505
- global $bp, $is_member_page, $wp_query;
1506
-
1507
- if ( $wp_query->is_home && !$bp->is_directory )
1508
- return true;
1509
-
1510
- if ( !$bp->displayed_user->id && !$bp->is_single_item && !$bp->is_directory && !bp_core_is_root_component( $bp->current_component ) )
1511
- return true;
1512
-
1513
- return false;
1514
- }
1515
-
1516
- function bp_is_my_profile() {
1517
- global $bp;
1518
-
1519
- if ( is_user_logged_in() && $bp->loggedin_user->id == $bp->displayed_user->id )
1520
- $my_profile = true;
1521
- else
1522
- $my_profile = false;
1523
-
1524
- return apply_filters( 'bp_is_my_profile', $my_profile );
1525
- }
1526
- function bp_is_home() { return bp_is_my_profile(); }
1527
-
1528
- function bp_is_front_page() {
1529
- if ( 'posts' == get_option('show_on_front') && is_home() )
1530
- return true;
1531
- else if ( bp_is_activity_front_page() )
1532
- return true;
1533
- else
1534
- return is_front_page();
1535
- }
1536
-
1537
- function bp_is_activity_front_page() {
1538
- global $current_blog;
1539
-
1540
- if ( bp_core_is_main_site() )
1541
- $path = bp_core_get_site_path();
1542
- else
1543
- $path = $current_blog->path;
1544
-
1545
- return ( 'page' == get_option('show_on_front') && 'activity' == get_option('page_on_front') && $_SERVER['REQUEST_URI'] == $path );
1546
- }
1547
-
1548
- function bp_is_directory() {
1549
- global $bp;
1550
-
1551
- return $bp->is_directory;
1552
- }
1553
-
1554
- function bp_is_page($page) {
1555
- global $bp;
1556
-
1557
- if ( !$bp->displayed_user->id && $bp->current_component == $page )
1558
- return true;
1559
-
1560
- if ( 'home' == $page )
1561
- return bp_is_front_page();
1562
-
1563
- return false;
1564
- }
1565
-
1566
- function bp_is_active( $component ) {
1567
- global $bp_deactivated;
1568
-
1569
- if ( !isset( $bp_deactivated[ 'bp-' . $component . '.php' ] ) )
1570
- return true;
1571
-
1572
- return false;
1573
- }
1574
-
1575
- function bp_is_profile_component() {
1576
- global $bp;
1577
-
1578
- if ( BP_XPROFILE_SLUG == $bp->current_component )
1579
- return true;
1580
-
1581
- return false;
1582
- }
1583
-
1584
- function bp_is_activity_component() {
1585
- global $bp;
1586
-
1587
- if ( BP_ACTIVITY_SLUG == $bp->current_component )
1588
- return true;
1589
-
1590
- return false;
1591
- }
1592
-
1593
- function bp_is_blogs_component() {
1594
- global $bp;
1595
-
1596
- if ( BP_BLOGS_SLUG == $bp->current_component )
1597
- return true;
1598
-
1599
- return false;
1600
- }
1601
-
1602
- function bp_is_messages_component() {
1603
- global $bp;
1604
-
1605
- if ( BP_MESSAGES_SLUG == $bp->current_component )
1606
- return true;
1607
-
1608
- return false;
1609
- }
1610
-
1611
- function bp_is_friends_component() {
1612
- global $bp;
1613
-
1614
- if ( BP_FRIENDS_SLUG == $bp->current_component )
1615
- return true;
1616
-
1617
- return false;
1618
- }
1619
-
1620
- function bp_is_groups_component() {
1621
- global $bp;
1622
-
1623
- if ( BP_GROUPS_SLUG == $bp->current_component )
1624
- return true;
1625
-
1626
- return false;
1627
- }
1628
-
1629
- function bp_is_settings_component() {
1630
- global $bp;
1631
-
1632
- if ( BP_SETTINGS_SLUG == $bp->current_component )
1633
- return true;
1634
-
1635
- return false;
1636
- }
1637
-
1638
- function bp_is_member() {
1639
- global $bp;
1640
-
1641
- if ( $bp->displayed_user->id )
1642
- return true;
1643
-
1644
- return false;
1645
- }
1646
-
1647
- function bp_is_user_activity() {
1648
- global $bp;
1649
-
1650
- if ( BP_ACTIVITY_SLUG == $bp->current_component )
1651
- return true;
1652
-
1653
- return false;
1654
- }
1655
-
1656
- function bp_is_user_friends_activity() {
1657
- global $bp;
1658
-
1659
- if ( BP_ACTIVITY_SLUG == $bp->current_component && 'my-friends' == $bp->current_action )
1660
- return true;
1661
-
1662
- return false;
1663
- }
1664
-
1665
- function bp_is_activity_permalink() {
1666
- global $bp;
1667
-
1668
- if ( BP_ACTIVITY_SLUG == $bp->current_component && is_numeric( $bp->current_action ) )
1669
- return true;
1670
-
1671
- return false;
1672
- }
1673
-
1674
- function bp_is_user_profile() {
1675
- global $bp;
1676
-
1677
- if ( BP_XPROFILE_SLUG == $bp->current_component || $bp->core->profile->slug == $bp->current_component )
1678
- return true;
1679
-
1680
- return false;
1681
- }
1682
-
1683
- function bp_is_profile_edit() {
1684
- global $bp;
1685
-
1686
- if ( BP_XPROFILE_SLUG == $bp->current_component && 'edit' == $bp->current_action )
1687
- return true;
1688
-
1689
- return false;
1690
- }
1691
-
1692
- function bp_is_change_avatar() {
1693
- global $bp;
1694
-
1695
- if ( BP_XPROFILE_SLUG == $bp->current_component && 'change-avatar' == $bp->current_action )
1696
- return true;
1697
-
1698
- return false;
1699
- }
1700
-
1701
- function bp_is_user_groups() {
1702
- global $bp;
1703
-
1704
- if ( BP_GROUPS_SLUG == $bp->current_component )
1705
- return true;
1706
-
1707
- return false;
1708
- }
1709
-
1710
- function bp_is_group() {
1711
- global $bp;
1712
-
1713
- if ( BP_GROUPS_SLUG == $bp->current_component && $bp->groups->current_group )
1714
- return true;
1715
-
1716
- return false;
1717
- }
1718
-
1719
- function bp_is_group_home() {
1720
- global $bp;
1721
-
1722
- if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && ( !$bp->current_action || 'home' == $bp->current_action ) )
1723
- return true;
1724
-
1725
- return false;
1726
- }
1727
-
1728
- function bp_is_group_create() {
1729
- global $bp;
1730
-
1731
- if ( BP_GROUPS_SLUG == $bp->current_component && 'create' == $bp->current_action )
1732
- return true;
1733
-
1734
- return false;
1735
- }
1736
-
1737
-
1738
- function bp_is_group_admin_page() {
1739
- global $bp;
1740
-
1741
- if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'admin' == $bp->current_action )
1742
- return true;
1743
-
1744
- return false;
1745
- }
1746
-
1747
- function bp_is_group_forum() {
1748
- global $bp;
1749
-
1750
- if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'forum' == $bp->current_action )
1751
- return true;
1752
-
1753
- return false;
1754
- }
1755
-
1756
- function bp_is_group_activity() {
1757
- global $bp;
1758
-
1759
- if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'activity' == $bp->current_action )
1760
- return true;
1761
-
1762
- return false;
1763
- }
1764
-
1765
- function bp_is_group_forum_topic() {
1766
- global $bp;
1767
-
1768
- if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'forum' == $bp->current_action && 'topic' == $bp->action_variables[0] )
1769
- return true;
1770
-
1771
- return false;
1772
- }
1773
-
1774
- function bp_is_group_forum_topic_edit() {
1775
- global $bp;
1776
-
1777
- if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'forum' == $bp->current_action && 'topic' == $bp->action_variables[0] && 'edit' == $bp->action_variables[2] )
1778
- return true;
1779
-
1780
- return false;
1781
- }
1782
-
1783
- function bp_is_group_members() {
1784
- global $bp;
1785
-
1786
- if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'members' == $bp->current_action )
1787
- return true;
1788
-
1789
- return false;
1790
- }
1791
-
1792
- function bp_is_group_invites() {
1793
- global $bp;
1794
-
1795
- if ( BP_GROUPS_SLUG == $bp->current_component && 'send-invites' == $bp->current_action )
1796
- return true;
1797
-
1798
- return false;
1799
- }
1800
-
1801
- function bp_is_group_membership_request() {
1802
- global $bp;
1803
-
1804
- if ( BP_GROUPS_SLUG == $bp->current_component && 'request-membership' == $bp->current_action )
1805
- return true;
1806
-
1807
- return false;
1808
- }
1809
-
1810
- function bp_is_group_leave() {
1811
- global $bp;
1812
-
1813
- if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'leave-group' == $bp->current_action )
1814
- return true;
1815
-
1816
- return false;
1817
- }
1818
-
1819
- function bp_is_group_single() {
1820
- global $bp;
1821
-
1822
- if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item )
1823
- return true;
1824
-
1825
- return false;
1826
- }
1827
-
1828
- function bp_is_user_blogs() {
1829
- global $bp;
1830
-
1831
- if ( BP_BLOGS_SLUG == $bp->current_component )
1832
- return true;
1833
-
1834
- return false;
1835
- }
1836
-
1837
- function bp_is_user_recent_posts() {
1838
- global $bp;
1839
-
1840
- if ( BP_BLOGS_SLUG == $bp->current_component && 'recent-posts' == $bp->current_action )
1841
- return true;
1842
-
1843
- return false;
1844
- }
1845
-
1846
- function bp_is_user_recent_commments() {
1847
- global $bp;
1848
-
1849
- if ( BP_BLOGS_SLUG == $bp->current_component && 'recent-comments' == $bp->current_action )
1850
- return true;
1851
-
1852
- return false;
1853
- }
1854
-
1855
- function bp_is_create_blog() {
1856
- global $bp;
1857
-
1858
- if ( BP_BLOGS_SLUG == $bp->current_component && 'create' == $bp->current_action )
1859
- return true;
1860
-
1861
- return false;
1862
- }
1863
-
1864
- function bp_is_user_friends() {
1865
- global $bp;
1866
-
1867
- if ( BP_FRIENDS_SLUG == $bp->current_component )
1868
- return true;
1869
-
1870
- return false;
1871
- }
1872
-
1873
- function bp_is_friend_requests() {
1874
- global $bp;
1875
-
1876
- if ( BP_FRIENDS_SLUG == $bp->current_component && 'requests' == $bp->current_action )
1877
- return true;
1878
-
1879
- return false;
1880
- }
1881
-
1882
- function bp_is_user_messages() {
1883
- global $bp;
1884
-
1885
- if ( BP_MESSAGES_SLUG == $bp->current_component )
1886
- return true;
1887
-
1888
- return false;
1889
- }
1890
-
1891
- function bp_is_messages_inbox() {
1892
- global $bp;
1893
-
1894
- if ( BP_MESSAGES_SLUG == $bp->current_component && ( !$bp->current_action || 'inbox' == $bp->current_action ) )
1895
- return true;
1896
-
1897
- return false;
1898
- }
1899
-
1900
- function bp_is_messages_sentbox() {
1901
- global $bp;
1902
-
1903
- if ( BP_MESSAGES_SLUG == $bp->current_component && 'sentbox' == $bp->current_action )
1904
- return true;
1905
-
1906
- return false;
1907
- }
1908
-
1909
-
1910
- function bp_is_notices() {
1911
- global $bp;
1912
-
1913
- if ( BP_MESSAGES_SLUG == $bp->current_component && 'notices' == $bp->current_action )
1914
- return true;
1915
-
1916
- return false;
1917
- }
1918
-
1919
-
1920
- function bp_is_messages_compose_screen() {
1921
- global $bp;
1922
-
1923
- if ( BP_MESSAGES_SLUG == $bp->current_component && 'compose' == $bp->current_action )
1924
- return true;
1925
-
1926
- return false;
1927
- }
1928
-
1929
- function bp_is_single_item() {
1930
- global $bp;
1931
-
1932
- if ( $bp->is_single_item )
1933
- return true;
1934
-
1935
- return false;
1936
- }
1937
-
1938
- function bp_is_activation_page() {
1939
- global $bp;
1940
-
1941
- if ( BP_ACTIVATION_SLUG == $bp->current_component )
1942
- return true;
1943
-
1944
- return false;
1945
- }
1946
-
1947
- function bp_is_register_page() {
1948
- global $bp;
1949
-
1950
- if ( BP_REGISTER_SLUG == $bp->current_component )
1951
- return true;
1952
-
1953
- return false;
1954
- }
1955
-
1956
- /* Use the above is_() functions to output a body class for each page */
1957
-
1958
- function bp_the_body_class() {
1959
- echo bp_get_the_body_class();
1960
- }
1961
- function bp_get_the_body_class( $wp_classes, $custom_classes = false ) {
1962
- global $bp;
1963
-
1964
- if ( bp_is_front_page() )
1965
- $bp_classes[] = 'home-page';
1966
-
1967
- if ( bp_is_directory() )
1968
- $bp_classes[] = 'directory';
1969
-
1970
- if ( bp_is_user_profile() && !bp_is_blog_page() )
1971
- $bp_classes[] = 'profile';
1972
-
1973
- if ( bp_is_activity_component() && !bp_is_blog_page() || ( bp_is_activity_front_page() && bp_is_front_page() ) )
1974
- $bp_classes[] = 'activity';
1975
-
1976
- if ( bp_is_blogs_component() && !bp_is_blog_page() )
1977
- $bp_classes[] = 'blogs';
1978
-
1979
- if ( bp_is_messages_component() && !bp_is_blog_page() )
1980
- $bp_classes[] = 'messages';
1981
-
1982
- if ( bp_is_friends_component() && !bp_is_blog_page() )
1983
- $bp_classes[] = 'friends';
1984
-
1985
- if ( bp_is_groups_component() && !bp_is_blog_page() )
1986
- $bp_classes[] = 'groups';
1987
-
1988
- if ( bp_is_settings_component() && !bp_is_blog_page() )
1989
- $bp_classes[] = 'settings';
1990
-
1991
- if ( bp_is_single_item() )
1992
- $bp_classes[] = 'single-item';
1993
-
1994
- if ( bp_is_messages_inbox() )
1995
- $bp_classes[] = 'inbox';
1996
-
1997
- if ( bp_is_messages_sentbox() )
1998
- $bp_classes[] = 'sentbox';
1999
-
2000
- if ( bp_is_messages_compose_screen() )
2001
- $bp_classes[] = 'compose';
2002
-
2003
- if ( bp_is_notices() )
2004
- $bp_classes[] = 'notices';
2005
-
2006
- if ( bp_is_friend_requests() )
2007
- $bp_classes[] = 'friend-requests';
2008
-
2009
- if ( bp_is_user_friends() )
2010
- $bp_classes[] = 'my-friends';
2011
-
2012
- if ( bp_is_create_blog() )
2013
- $bp_classes[] = 'create-blog';
2014
-
2015
- if ( bp_is_user_recent_commments() )
2016
- $bp_classes[] = 'recent-comments';
2017
-
2018
- if ( bp_is_user_recent_posts() )
2019
- $bp_classes[] = 'recent-posts';
2020
-
2021
- if ( bp_is_user_blogs() && !bp_is_directory() )
2022
- $bp_classes[] = 'my-blogs';
2023
-
2024
- if ( bp_is_user_groups() && !bp_is_directory() )
2025
- $bp_classes[] = 'my-groups';
2026
-
2027
- if ( bp_is_group_leave() )
2028
- $bp_classes[] = 'leave-group';
2029
-
2030
- if ( bp_is_group_invites() )
2031
- $bp_classes[] = 'group-invites';
2032
-
2033
- if ( bp_is_group_members() )
2034
- $bp_classes[] = 'group-members';
2035
-
2036
- if ( bp_is_group_forum_topic() )
2037
- $bp_classes[] = 'group-forum-topic';
2038
-
2039
- if ( bp_is_group_forum_topic_edit() )
2040
- $bp_classes[] = 'group-forum-topic-edit';
2041
-
2042
- if ( bp_is_group_forum() )
2043
- $bp_classes[] = 'group-forum';
2044
-
2045
- if ( bp_is_group_admin_page() )
2046
- $bp_classes[] = 'group-admin';
2047
-
2048
- if ( bp_is_group_create() )
2049
- $bp_classes[] = 'group-create';
2050
-
2051
- if ( bp_is_group_home() )
2052
- $bp_classes[] = 'group-home';
2053
-
2054
- if ( bp_is_change_avatar() )
2055
- $bp_classes[] = 'change-avatar';
2056
-
2057
- if ( bp_is_profile_edit() )
2058
- $bp_classes[] = 'profile-edit';
2059
-
2060
- if ( bp_is_user_friends_activity() )
2061
- $bp_classes[] = 'friends-activity';
2062
-
2063
- if ( bp_is_user_activity() && !bp_is_directory() )
2064
- $bp_classes[] = 'my-activity';
2065
-
2066
- if ( bp_is_activity_permalink() )
2067
- $bp_classes[] = 'activity-permalink';
2068
-
2069
- if ( bp_is_register_page() )
2070
- $bp_classes[] = 'registration';
2071
-
2072
- if ( bp_is_activation_page() )
2073
- $bp_classes[] = 'activation';
2074
-
2075
- if ( is_user_logged_in() )
2076
- $bp_classes[] = 'logged-in';
2077
-
2078
- /* Add the current_component, current_action into the bp classes */
2079
- if ( !bp_is_blog_page() ) {
2080
- if ( !empty( $bp->current_component ) )
2081
- $bp_classes[] = $bp->current_component;
2082
-
2083
- if ( !empty( $bp->current_action ) )
2084
- $bp_classes[] = $bp->current_action;
2085
- }
2086
-
2087
- /* We don't want WordPress blog classes to appear on non-blog pages. */
2088
- if ( !bp_is_blog_page() || is_home() ) {
2089
- /* Preserve any custom classes already set */
2090
- if ( !empty( $custom_classes ) )
2091
- $wp_classes = (array) $custom_classes;
2092
- else
2093
- $wp_classes = array();
2094
- }
2095
-
2096
- /* Merge WP classes with BP classes */
2097
- $classes = array_merge( (array) $bp_classes, (array) $wp_classes );
2098
-
2099
- /* Remove any duplicates */
2100
- $classes = array_unique( $classes );
2101
-
2102
- return apply_filters( 'bp_get_the_body_class', $classes, $bp_classes, $wp_classes, $custom_classes );
2103
- }
2104
- add_filter( 'body_class', 'bp_get_the_body_class', 10, 2 )
2105
-
2106
-
2107
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-core/bp-core-widgets.php CHANGED
@@ -1,4 +1,6 @@
1
  <?php
 
 
2
 
3
  /* Register widgets for the core component */
4
  function bp_core_register_widgets() {
@@ -11,47 +13,69 @@ add_action( 'bp_register_widgets', 'bp_core_register_widgets' );
11
  /*** MEMBERS WIDGET *****************/
12
 
13
  class BP_Core_Members_Widget extends WP_Widget {
 
14
  function bp_core_members_widget() {
15
- parent::WP_Widget( false, $name = __( 'Members', 'buddypress' ) );
 
16
 
17
- if ( is_active_widget( false, false, $this->id_base ) )
18
- wp_enqueue_script( 'bp_core_widget_members-js', BP_PLUGIN_URL . '/bp-core/js/widget-members.js', array('jquery') );
 
 
 
 
 
 
 
 
19
  }
20
 
21
- function widget($args, $instance) {
22
  global $bp;
23
 
24
  extract( $args );
25
 
 
 
 
26
  echo $before_widget;
27
  echo $before_title
28
- . $widget_name
29
  . $after_title; ?>
30
 
31
- <?php if ( bp_has_members( 'user_id=0&type=newest&max=' . $instance['max_members'] . '&populate_extras=0' ) ) : ?>
32
  <div class="item-options" id="members-list-options">
33
- <span class="ajax-loader" id="ajax-loader-members"></span>
34
- <a href="<?php echo site_url() . '/' . BP_MEMBERS_SLUG ?>" id="newest-members" class="selected"><?php _e( 'Newest', 'buddypress' ) ?></a>
35
- | <a href="<?php echo site_url() . '/' . BP_MEMBERS_SLUG ?>" id="recently-active-members"><?php _e( 'Active', 'buddypress' ) ?></a>
36
 
37
  <?php if ( bp_is_active( 'friends' ) ) : ?>
38
 
39
- | <a href="<?php echo site_url() . '/' . BP_MEMBERS_SLUG ?>" id="popular-members"><?php _e( 'Popular', 'buddypress' ) ?></a>
40
 
41
  <?php endif; ?>
42
-
43
  </div>
44
 
45
  <ul id="members-list" class="item-list">
46
  <?php while ( bp_members() ) : bp_the_member(); ?>
47
  <li class="vcard">
48
  <div class="item-avatar">
49
- <a href="<?php bp_member_permalink() ?>"><?php bp_member_avatar() ?></a>
50
  </div>
51
 
52
  <div class="item">
53
  <div class="item-title fn"><a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_name() ?></a></div>
54
- <div class="item-meta"><span class="activity"><?php bp_member_registered() ?></span></div>
 
 
 
 
 
 
 
 
 
 
 
55
  </div>
56
  </li>
57
 
@@ -74,17 +98,40 @@ class BP_Core_Members_Widget extends WP_Widget {
74
 
75
  function update( $new_instance, $old_instance ) {
76
  $instance = $old_instance;
 
77
  $instance['max_members'] = strip_tags( $new_instance['max_members'] );
 
78
 
79
  return $instance;
80
  }
81
 
82
  function form( $instance ) {
83
- $instance = wp_parse_args( (array) $instance, array( 'max_members' => 5 ) );
 
 
 
 
 
 
 
84
  $max_members = strip_tags( $instance['max_members'] );
 
85
  ?>
86
 
87
- <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>
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  <?php
89
  }
90
  }
@@ -92,8 +139,14 @@ class BP_Core_Members_Widget extends WP_Widget {
92
  /*** WHO'S ONLINE WIDGET *****************/
93
 
94
  class BP_Core_Whos_Online_Widget extends WP_Widget {
 
95
  function bp_core_whos_online_widget() {
96
- parent::WP_Widget( false, $name = __( "Who's Online Avatars", 'buddypress' ) );
 
 
 
 
 
97
  }
98
 
99
  function widget($args, $instance) {
@@ -103,14 +156,14 @@ class BP_Core_Whos_Online_Widget extends WP_Widget {
103
 
104
  echo $before_widget;
105
  echo $before_title
106
- . $widget_name
107
  . $after_title; ?>
108
 
109
  <?php if ( bp_has_members( 'user_id=0&type=online&per_page=' . $instance['max_members'] . '&max=' . $instance['max_members'] . '&populate_extras=0' ) ) : ?>
110
  <div class="avatar-block">
111
  <?php while ( bp_members() ) : bp_the_member(); ?>
112
  <div class="item-avatar">
113
- <a href="<?php bp_member_permalink() ?>"><?php bp_member_avatar() ?></a>
114
  </div>
115
  <?php endwhile; ?>
116
  </div>
@@ -128,16 +181,25 @@ class BP_Core_Whos_Online_Widget extends WP_Widget {
128
 
129
  function update( $new_instance, $old_instance ) {
130
  $instance = $old_instance;
 
131
  $instance['max_members'] = strip_tags( $new_instance['max_members'] );
132
 
133
  return $instance;
134
  }
135
 
136
  function form( $instance ) {
137
- $instance = wp_parse_args( (array) $instance, array( 'max_members' => 15 ) );
 
 
 
 
 
 
138
  $max_members = strip_tags( $instance['max_members'] );
139
  ?>
140
 
 
 
141
  <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>
142
  <?php
143
  }
@@ -146,8 +208,14 @@ class BP_Core_Whos_Online_Widget extends WP_Widget {
146
  /*** RECENTLY ACTIVE WIDGET *****************/
147
 
148
  class BP_Core_Recently_Active_Widget extends WP_Widget {
 
149
  function bp_core_recently_active_widget() {
150
- parent::WP_Widget( false, $name = __( 'Recently Active Member Avatars', 'buddypress' ) );
 
 
 
 
 
151
  }
152
 
153
  function widget($args, $instance) {
@@ -157,14 +225,14 @@ class BP_Core_Recently_Active_Widget extends WP_Widget {
157
 
158
  echo $before_widget;
159
  echo $before_title
160
- . $widget_name
161
  . $after_title; ?>
162
 
163
  <?php if ( bp_has_members( 'user_id=0&type=active&per_page=' . $instance['max_members'] . '&max=' . $instance['max_members'] . '&populate_extras=0' ) ) : ?>
164
  <div class="avatar-block">
165
  <?php while ( bp_members() ) : bp_the_member(); ?>
166
  <div class="item-avatar">
167
- <a href="<?php bp_member_permalink() ?>"><?php bp_member_avatar() ?></a>
168
  </div>
169
  <?php endwhile; ?>
170
  </div>
@@ -182,16 +250,25 @@ class BP_Core_Recently_Active_Widget extends WP_Widget {
182
 
183
  function update( $new_instance, $old_instance ) {
184
  $instance = $old_instance;
 
185
  $instance['max_members'] = strip_tags( $new_instance['max_members'] );
186
 
187
  return $instance;
188
  }
189
 
190
  function form( $instance ) {
191
- $instance = wp_parse_args( (array) $instance, array( 'max_members' => 15 ) );
 
 
 
 
 
 
192
  $max_members = strip_tags( $instance['max_members'] );
193
  ?>
194
 
 
 
195
  <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>
196
  <?php
197
  }
@@ -233,8 +310,10 @@ function bp_core_ajax_widget_members() {
233
 
234
  <div class="item">
235
  <div class="item-title fn"><a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_name() ?></a></div>
236
- <?php if ( 'active' == $type || 'newest' == $type ) : ?>
237
  <div class="item-meta"><span class="activity"><?php bp_member_last_active() ?></span></div>
 
 
238
  <?php elseif ( bp_is_active( 'friends' ) ) : ?>
239
  <div class="item-meta"><span class="activity"><?php bp_member_total_friend_count() ?></span></div>
240
  <?php endif; ?>
1
  <?php
2
+ // Exit if accessed directly
3
+ if ( !defined( 'ABSPATH' ) ) exit;
4
 
5
  /* Register widgets for the core component */
6
  function bp_core_register_widgets() {
13
  /*** MEMBERS WIDGET *****************/
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 ) ) {
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
 
38
+ if ( !$instance['member_default'] )
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' ) ) : ?>
47
  <div class="item-options" id="members-list-options">
48
+ <a href="<?php echo site_url( bp_get_members_root_slug() ); ?>" id="newest-members" <?php if ( $instance['member_default'] == 'newest' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Newest', 'buddypress' ) ?></a>
49
+ | <a href="<?php echo site_url( bp_get_members_root_slug() ); ?>" id="recently-active-members" <?php if ( $instance['member_default'] == 'active' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Active', 'buddypress' ) ?></a>
 
50
 
51
  <?php if ( bp_is_active( 'friends' ) ) : ?>
52
 
53
+ | <a href="<?php echo site_url( bp_get_members_root_slug() ); ?>" id="popular-members" <?php if ( $instance['member_default'] == 'popular' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Popular', 'buddypress' ) ?></a>
54
 
55
  <?php endif; ?>
 
56
  </div>
57
 
58
  <ul id="members-list" class="item-list">
59
  <?php while ( bp_members() ) : bp_the_member(); ?>
60
  <li class="vcard">
61
  <div class="item-avatar">
62
+ <a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_avatar() ?></a>
63
  </div>
64
 
65
  <div class="item">
66
  <div class="item-title fn"><a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_name() ?></a></div>
67
+ <div class="item-meta">
68
+ <span class="activity">
69
+ <?php
70
+ if ( 'newest' == $instance['member_default'] )
71
+ bp_member_registered();
72
+ if ( 'active' == $instance['member_default'] )
73
+ bp_member_last_active();
74
+ if ( 'popular' == $instance['member_default'] )
75
+ bp_member_total_friend_count();
76
+ ?>
77
+ </span>
78
+ </div>
79
  </div>
80
  </li>
81
 
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>
126
+ <label for="bp-core-widget-groups-default"><?php _e('Default members to show:', 'buddypress'); ?>
127
+ <select name="<?php echo $this->get_field_name( 'member_default' ) ?>">
128
+ <option value="newest" <?php if ( $member_default == 'newest' ) : ?>selected="selected"<?php endif; ?>><?php _e( 'Newest', 'buddypress' ) ?></option>
129
+ <option value="active" <?php if ( $member_default == 'active' ) : ?>selected="selected"<?php endif; ?>><?php _e( 'Active', 'buddypress' ) ?></option>
130
+ <option value="popular" <?php if ( $member_default == 'popular' ) : ?>selected="selected"<?php endif; ?>><?php _e( 'Popular', 'buddypress' ) ?></option>
131
+ </select>
132
+ </label>
133
+ </p>
134
+
135
  <?php
136
  }
137
  }
139
  /*** WHO'S ONLINE WIDGET *****************/
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) {
156
 
157
  echo $before_widget;
158
  echo $before_title
159
+ . $instance['title']
160
  . $after_title; ?>
161
 
162
  <?php if ( bp_has_members( 'user_id=0&type=online&per_page=' . $instance['max_members'] . '&max=' . $instance['max_members'] . '&populate_extras=0' ) ) : ?>
163
  <div class="avatar-block">
164
  <?php while ( bp_members() ) : bp_the_member(); ?>
165
  <div class="item-avatar">
166
+ <a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_avatar() ?></a>
167
  </div>
168
  <?php endwhile; ?>
169
  </div>
181
 
182
  function update( $new_instance, $old_instance ) {
183
  $instance = $old_instance;
184
+ $instance['title'] = strip_tags( $new_instance['title'] );
185
  $instance['max_members'] = strip_tags( $new_instance['max_members'] );
186
 
187
  return $instance;
188
  }
189
 
190
  function form( $instance ) {
191
+ $defaults = array(
192
+ 'title' => __( "Who's Online", 'buddypress' ),
193
+ 'max_members' => 15
194
+ );
195
+ $instance = wp_parse_args( (array) $instance, $defaults );
196
+
197
+ $title = strip_tags( $instance['title'] );
198
  $max_members = strip_tags( $instance['max_members'] );
199
  ?>
200
 
201
+ <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>
202
+
203
  <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>
204
  <?php
205
  }
208
  /*** RECENTLY ACTIVE WIDGET *****************/
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) {
225
 
226
  echo $before_widget;
227
  echo $before_title
228
+ . $instance['title']
229
  . $after_title; ?>
230
 
231
  <?php if ( bp_has_members( 'user_id=0&type=active&per_page=' . $instance['max_members'] . '&max=' . $instance['max_members'] . '&populate_extras=0' ) ) : ?>
232
  <div class="avatar-block">
233
  <?php while ( bp_members() ) : bp_the_member(); ?>
234
  <div class="item-avatar">
235
+ <a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_avatar() ?></a>
236
  </div>
237
  <?php endwhile; ?>
238
  </div>
250
 
251
  function update( $new_instance, $old_instance ) {
252
  $instance = $old_instance;
253
+ $instance['title'] = strip_tags( $new_instance['title'] );
254
  $instance['max_members'] = strip_tags( $new_instance['max_members'] );
255
 
256
  return $instance;
257
  }
258
 
259
  function form( $instance ) {
260
+ $defaults = array(
261
+ 'title' => 'Recently Active Members',
262
+ 'max_members' => 15
263
+ );
264
+ $instance = wp_parse_args( (array) $instance, $defaults );
265
+
266
+ $title = strip_tags( $instance['title'] );
267
  $max_members = strip_tags( $instance['max_members'] );
268
  ?>
269
 
270
+ <p><label for="bp-core-widget-members-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>
271
+
272
  <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>
273
  <?php
274
  }
310
 
311
  <div class="item">
312
  <div class="item-title fn"><a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_name() ?></a></div>
313
+ <?php if ( 'active' == $type ) : ?>
314
  <div class="item-meta"><span class="activity"><?php bp_member_last_active() ?></span></div>
315
+ <?php elseif ( 'newest' == $type ) : ?>
316
+ <div class="item-meta"><span class="activity"><?php bp_member_registered() ?></span></div>
317
  <?php elseif ( bp_is_active( 'friends' ) ) : ?>
318
  <div class="item-meta"><span class="activity"><?php bp_member_total_friend_count() ?></span></div>
319
  <?php endif; ?>
bp-core/bp-core-wpabstraction.php CHANGED
@@ -9,120 +9,154 @@
9
  * the 3.0 WordPress version merge takes place.
10
  */
11
 
12
- if ( !bp_core_is_multisite() ) {
13
- $wpdb->base_prefix = $wpdb->prefix;
14
- $wpdb->blogid = 1;
15
- }
16
-
17
- function bp_core_is_multisite() {
18
- if ( function_exists( 'is_multisite' ) )
19
- return is_multisite();
20
-
21
- if ( !function_exists( 'wpmu_signup_blog' ) )
22
- return false;
23
-
24
- return true;
25
- }
26
 
27
  /**
28
- * bp_core_is_main_site
29
- *
30
- * Checks if current blog is root blog of site
31
- *
32
- * @since 1.2.6
33
- * @package BuddyPress
34
- *
35
- * @param int $blog_id optional blog id to test (default current blog)
36
- * @return bool True if not multisite or $blog_id is main site
37
  */
38
- function bp_core_is_main_site( $blog_id = '' ) {
39
- global $current_site, $current_blog;
40
 
41
- if ( !bp_core_is_multisite() )
42
- return true;
43
 
44
- if ( empty( $blog_id ) )
45
- $blog_id = $current_blog->blog_id;
 
 
 
46
 
47
- return $blog_id == $current_site->blog_id;
48
- }
 
 
 
49
 
50
- function bp_core_get_status_sql( $prefix = false ) {
51
- if ( !bp_core_is_multisite() )
52
- return "{$prefix}user_status = 0";
53
- else
54
- return "{$prefix}spam = 0 AND {$prefix}deleted = 0 AND {$prefix}user_status = 0";
55
- }
56
 
57
- if ( !function_exists( 'get_blog_option' ) ) {
58
- function get_blog_option( $blog_id, $option_name, $default = false ) {
59
- return get_option( $option_name, $default );
 
60
  }
61
- }
62
 
63
- if ( !function_exists( 'add_blog_option' ) ) {
64
- function add_blog_option( $blog_id, $option_name, $option_value ) {
65
- return add_option( $option_name, $option_value );
 
66
  }
67
- }
68
 
69
- if ( !function_exists( 'update_blog_option' ) ) {
70
- function update_blog_option( $blog_id, $option_name, $option_value ) {
71
- return update_option( $option_name, $option_value );
 
72
  }
73
- }
74
 
75
- if ( !function_exists( 'switch_to_blog' ) ) {
76
- function switch_to_blog() {
77
- return 1;
 
78
  }
79
- }
80
 
81
- if ( !function_exists( 'restore_current_blog' ) ) {
82
- function restore_current_blog() {
83
- return 1;
 
 
 
 
84
  }
85
  }
86
 
87
- if ( !function_exists( 'get_blogs_of_user' ) ) {
88
- function get_blogs_of_user() {
89
- return false;
90
- }
 
91
  }
92
 
93
- if ( !function_exists( 'update_blog_status' ) ) {
94
- function update_blog_status() {
95
- return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  }
97
  }
98
 
99
- if ( !function_exists( 'is_subdomain_install' ) ) {
100
- function is_subdomain_install() {
101
- if ( ( defined( 'VHOST' ) && 'yes' == VHOST ) || ( defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL ) )
102
- return true;
 
 
 
 
 
 
 
103
 
104
- return false;
105
- }
106
- }
107
 
108
- // Deprecated - 1.2.6
109
- if ( !function_exists( 'is_site_admin' ) ) {
110
- function is_site_admin( $user_id = false ) {
111
- return is_super_admin( $user_id );
 
112
  }
113
  }
114
 
115
- // Added for WordPress 3.1 support
116
- if ( !function_exists( 'get_dashboard_url' ) ) {
117
-
118
  /**
119
- * Make sure the 'network_admin_menu' hook (which is new to 3.1) fires
120
- * on our reliable friend 'admin_menu'
 
 
 
 
121
  */
122
- function bp_network_admin_menu() {
123
- do_action( 'network_admin_menu' );
 
 
 
 
 
 
 
 
 
 
124
  }
125
- add_action( 'admin_menu', 'bp_network_admin_menu' );
126
  }
127
 
128
- ?>
9
  * the 3.0 WordPress version merge takes place.
10
  */
11
 
12
+ // Exit if accessed directly
13
+ if ( !defined( 'ABSPATH' ) ) exit;
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  /**
16
+ * Only add abstraction functions if WordPress is not in multisite mode
 
 
 
 
 
 
 
 
17
  */
18
+ if ( !is_multisite() ) {
19
+ global $wpdb;
20
 
21
+ $wpdb->base_prefix = $wpdb->prefix;
22
+ $wpdb->blogid = BP_ROOT_BLOG;
23
 
24
+ if ( !function_exists( 'get_blog_option' ) ) {
25
+ function get_blog_option( $blog_id, $option_name, $default = false ) {
26
+ return get_option( $option_name, $default );
27
+ }
28
+ }
29
 
30
+ if ( !function_exists( 'update_blog_option' ) ) {
31
+ function update_blog_option( $blog_id, $option_name, $value ) {
32
+ return update_option( $option_name, $value );
33
+ }
34
+ }
35
 
36
+ if ( !function_exists( 'delete_blog_option' ) ) {
37
+ function delete_blog_option( $blog_id, $option_name ) {
38
+ return delete_option( $option_name );
39
+ }
40
+ }
 
41
 
42
+ if ( !function_exists( 'switch_to_blog' ) ) {
43
+ function switch_to_blog() {
44
+ return bp_get_root_blog_id();
45
+ }
46
  }
 
47
 
48
+ if ( !function_exists( 'restore_current_blog' ) ) {
49
+ function restore_current_blog() {
50
+ return bp_get_root_blog_id();
51
+ }
52
  }
 
53
 
54
+ if ( !function_exists( 'get_blogs_of_user' ) ) {
55
+ function get_blogs_of_user() {
56
+ return false;
57
+ }
58
  }
 
59
 
60
+ if ( !function_exists( 'update_blog_status' ) ) {
61
+ function update_blog_status() {
62
+ return true;
63
+ }
64
  }
 
65
 
66
+ if ( !function_exists( 'is_subdomain_install' ) ) {
67
+ function is_subdomain_install() {
68
+ if ( ( defined( 'VHOST' ) && 'yes' == VHOST ) || ( defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL ) )
69
+ return true;
70
+
71
+ return false;
72
+ }
73
  }
74
  }
75
 
76
+ function bp_core_get_status_sql( $prefix = false ) {
77
+ if ( !is_multisite() )
78
+ return "{$prefix}user_status = 0";
79
+ else
80
+ return "{$prefix}spam = 0 AND {$prefix}deleted = 0 AND {$prefix}user_status = 0";
81
  }
82
 
83
+ /**
84
+ * Multibyte encoding fallback functions
85
+ *
86
+ * The PHP multibyte encoding extension is not enabled by default. In cases where it is not enabled,
87
+ * these functions provide a fallback.
88
+ *
89
+ * Borrowed from MediaWiki, under the GPLv2. Thanks!
90
+ */
91
+ if ( !function_exists( 'mb_strlen' ) ) {
92
+ /**
93
+ * Fallback implementation of mb_strlen, hardcoded to UTF-8.
94
+ * @param string $str
95
+ * @param string $enc optional encoding; ignored
96
+ * @return int
97
+ */
98
+ function mb_strlen( $str, $enc = '' ) {
99
+ $counts = count_chars( $str );
100
+ $total = 0;
101
+
102
+ // Count ASCII bytes
103
+ for( $i = 0; $i < 0x80; $i++ ) {
104
+ $total += $counts[$i];
105
+ }
106
+
107
+ // Count multibyte sequence heads
108
+ for( $i = 0xc0; $i < 0xff; $i++ ) {
109
+ $total += $counts[$i];
110
+ }
111
+ return $total;
112
  }
113
  }
114
 
115
+ if ( !function_exists( 'mb_strpos' ) ) {
116
+ /**
117
+ * Fallback implementation of mb_strpos, hardcoded to UTF-8.
118
+ * @param $haystack String
119
+ * @param $needle String
120
+ * @param $offset String: optional start position
121
+ * @param $encoding String: optional encoding; ignored
122
+ * @return int
123
+ */
124
+ function mb_strpos( $haystack, $needle, $offset = 0, $encoding = '' ) {
125
+ $needle = preg_quote( $needle, '/' );
126
 
127
+ $ar = array();
128
+ preg_match( '/' . $needle . '/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset );
 
129
 
130
+ if( isset( $ar[0][1] ) ) {
131
+ return $ar[0][1];
132
+ } else {
133
+ return false;
134
+ }
135
  }
136
  }
137
 
138
+ if ( !function_exists( 'mb_strrpos' ) ) {
 
 
139
  /**
140
+ * Fallback implementation of mb_strrpos, hardcoded to UTF-8.
141
+ * @param $haystack String
142
+ * @param $needle String
143
+ * @param $offset String: optional start position
144
+ * @param $encoding String: optional encoding; ignored
145
+ * @return int
146
  */
147
+ function mb_strrpos( $haystack, $needle, $offset = 0, $encoding = '' ) {
148
+ $needle = preg_quote( $needle, '/' );
149
+
150
+ $ar = array();
151
+ preg_match_all( '/' . $needle . '/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset );
152
+
153
+ if( isset( $ar[0] ) && count( $ar[0] ) > 0 &&
154
+ isset( $ar[0][count( $ar[0] ) - 1][1] ) ) {
155
+ return $ar[0][count( $ar[0] ) - 1][1];
156
+ } else {
157
+ return false;
158
+ }
159
  }
 
160
  }
161
 
162
+ ?>
bp-core/css/admin-bar-rtl.css ADDED
@@ -0,0 +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;}
bp-core/css/admin-bar-rtl.dev.css ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #wpadminbar .quicklinks li#wp-admin-bar-my-account ul,
2
+ #wpadminbar .quicklinks li#wp-admin-bar-my-account-with-avatar ul {
3
+ left: auto;
4
+ right: 0;
5
+ }
6
+ #wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar > a img,
7
+ #wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar > a img {
8
+ margin: -2px -5px 0 23px;
9
+ }
10
+ #wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar ul,
11
+ #wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul {
12
+ left: auto;
13
+ right: 30px;
14
+ }
15
+ #wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar ul ul,
16
+ #wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul ul {
17
+ left: auto;
18
+ right: 0;
19
+ }
20
+ #wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul {
21
+ left: auto;
22
+ right: 0;
23
+ }
24
+ #wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul ul {
25
+ left: auto;
26
+ right: 0;
27
+ }
bp-core/css/admin-bar.css ADDED
@@ -0,0 +1 @@
 
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;}#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>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-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 ADDED
@@ -0,0 +1,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
+
7
+ /* Displayed User */
8
+ #wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar > a {
9
+ border-left: none;
10
+ background: url(../images/admin-bar-sprite.png?d=11122010) top left no-repeat;
11
+ }
12
+ #wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar > a img,
13
+ #wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar > a img {
14
+ width: 16px;
15
+ height: 16px;
16
+ display: inline;
17
+ border: 1px solid #999;
18
+ vertical-align: middle;
19
+ margin: -2px 23px 0 -5px;
20
+ padding: 0;
21
+ background: #eee;
22
+ float: none;
23
+ }
24
+ #wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar ul,
25
+ #wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul {
26
+ left: 30px;
27
+ }
28
+ #wpadminbar .quicklinks li#wp-admin-bar-user-admin-with-avatar ul ul,
29
+ #wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul ul {
30
+ left: 0;
31
+ }
32
+
33
+ /* Displayed Group */
34
+ #wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar > a {
35
+ border-left: none;
36
+ background: url(../images/admin-bar-sprite.png?d=11122010) top left no-repeat;
37
+ }
38
+ #wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul {
39
+ left: 0;
40
+ }
41
+ #wpadminbar .quicklinks li#wp-admin-bar-group-admin-with-avatar ul ul {
42
+ left: 0;
43
+ }
44
+ #wpadminbar .quicklinks li#wp-admin-bar-my-account a span.count,
45
+ #wpadminbar .quicklinks li#wp-admin-bar-my-account-with-avatar a span.count,
46
+ #wpadminbar .quicklinks li#wp-admin-bar-bp-notifications #ab-pending-notifications {
47
+ background: #eee;
48
+ color: #333;
49
+ text-shadow: none;
50
+ display: inline;
51
+ padding: 2px 5px;
52
+ font-size: 10px;
53
+ font-weight: bold;
54
+ -moz-border-radius: 10px;
55
+ -khtml-border-radius: 10px;
56
+ -webkit-border-radius: 10px;
57
+ border-radius: 10px;
58
+ }
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/css/admin.dev.css ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }
58
+
59
+ div.component {
60
+ width: 323px;
61
+ float: left;
62
+ margin: 15px 30px 0 0;
63
+ }
64
+ div.component div.radio {
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
+
74
+ div.component img {
75
+ margin-top: 10px;
76
+ }
77
+
78
+ div.component p {
79
+ margin-left: 4px;
80
+ }
81
+
82
+ div.component h5 {
83
+ font-size: 18px;
84
+ float: left;
85
+ margin: 0 0 0 4px;
86
+ width: 100px;
87
+ }
88
+
89
+ div.component div.radio {
90
+ font-size: 11px;
91
+ float: right;
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
+
145
+ a.button {
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;
153
+ cursor: default;
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 ADDED
@@ -0,0 +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;}
bp-core/css/buddybar-rtl.dev.css ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #wp-admin-bar {
2
+ right: 0;
3
+ left: auto;
4
+ }
5
+ #wp-admin-bar div#admin-bar-logo {
6
+ right: 10px;
7
+ left: auto;
8
+ }
9
+ #wp-admin-bar li {
10
+ text-align: right;
11
+ }
12
+ #wp-admin-bar li.no-arrow a {
13
+ padding-left: 15px;
14
+ padding-right: 0;
15
+ }
16
+ #admin-bar-logo {
17
+ float: right;
18
+ }
19
+
20
+ #wp-admin-bar ul li {/* all list items */
21
+ float: right;
22
+ background: url( _inc/images/admin-menu-arrow.gif ) 12% 53% no-repeat;
23
+ padding-left: 11px;
24
+ padding-right: 0;
25
+ }
26
+ #wp-admin-bar ul li.no-arrow {
27
+ padding-left: 0;
28
+ }
29
+ #wp-admin-bar ul li.align-right {
30
+ left: 0;
31
+ right: auto;
32
+ }
33
+
34
+ /* second-level lists */
35
+ #wp-admin-bar ul li ul {
36
+ right: -999em;
37
+ left: auto;
38
+ margin-right: 0;
39
+ }
40
+ #wp-admin-bar ul li ul li {
41
+ float: right;
42
+ }
43
+
44
+ /* third-and-above-level lists */
45
+ #wp-admin-bar ul li ul ul {
46
+ margin: -25px 184px 0 0;
47
+ }
48
+ #wp-admin-bar ul li:hover ul,
49
+ #wp-admin-bar ul li li:hover ul,
50
+ #wp-admin-bar ul li.sfhover ul,
51
+ #wp-admin-bar ul li ul li.sfhover ul {/* lists nested under hovered list items */
52
+ right: auto;
53
+ }
54
+ #wp-admin-bar ul li.align-right:hover ul {
55
+ left: 0;
56
+ right: auto;
57
+ }
58
+ #wp-admin-bar ul li:hover ul ul,
59
+ #wp-admin-bar li.sfhover ul li ul {
60
+ right: -999em;
61
+ left: auto;
62
+ }
63
+
64
+ /* Menu item css */
65
+ #wp-admin-bar img.avatar {
66
+ float: right;
67
+ margin-left: 8px;
68
+ margin-right: 0;
69
+ }
70
+ #wp-admin-bar span.activity {
71
+ margin-right: 34px;
72
+ margin-left: 0;
73
+ }
74
+ #wp-admin-bar ul li#bp-adminbar-notifications-menu a span {
75
+ margin-right: 2px;
76
+ margin-left: 0;
77
+ }
bp-core/css/buddybar.css ADDED
@@ -0,0 +1 @@
 
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-themes/bp-default/_inc/css/adminbar.css → bp-core/css/buddybar.dev.css RENAMED
@@ -1,7 +1,7 @@
1
- body {
2
- padding-top: 25px;
 
3
  }
4
-
5
  #wp-admin-bar {
6
  position: fixed;
7
  top: 0;
@@ -12,36 +12,28 @@ body {
12
  width: 100%;
13
  z-index: 1000;
14
  }
15
- #wp-admin-bar .padder {
16
- position: relative;
17
- padding: 0;
18
- width: 100%;
19
- margin: 0 auto;
20
- background: url( ../images/60pc_black.png );
21
- height: 25px;
22
- }
23
- body#bp-default #wp-admin-bar .padder {
24
- min-width: 960px;
25
- max-width: 1250px;
26
- }
27
-
28
- body#bp-default.activity-permalink #wp-admin-bar .padder {
29
- min-width: 960px;
30
- max-width: 960px;
31
- }
32
-
33
- #wp-admin-bar * { z-index: 999; }
34
-
35
  #wp-admin-bar div#admin-bar-logo {
36
  position: absolute;
37
  top: 5px;
38
  left: 10px;
39
  }
40
-
41
  #wp-admin-bar a img {
42
  border: none;
43
  }
44
-
45
  #wp-admin-bar li {
46
  list-style: none;
47
  margin: 0;
@@ -49,27 +41,25 @@ body {
49
  line-height: 100%;
50
  text-align: left;
51
  }
52
-
53
  #wp-admin-bar li a {
54
  padding: 7px 15px 7px 15px;
55
  color: #eee;
56
  text-decoration: none;
57
  font-size: 11px;
58
  }
59
- #wp-admin-bar li.alt { border: none; }
60
-
61
- #wp-admin-bar li.no-arrow a {
62
- padding-right: 15px;
63
- }
64
-
65
- #wp-admin-bar ul li ul li a span {
66
- display: none;
67
- }
68
-
69
- #wp-admin-bar li:hover, #wp-admin-bar li.hover {
70
  position: static;
71
  }
72
-
73
  #admin-bar-logo {
74
  float: left;
75
  font-weight: bold;
@@ -79,11 +69,12 @@ body {
79
  text-decoration: none;
80
  color: #fff;
81
  }
82
- body#bp-default #admin-bar-logo { padding: 2px 8px; }
83
-
84
- /*******************/
85
 
86
- #wp-admin-bar ul { /* all lists */
 
87
  margin: 0;
88
  list-style: none;
89
  line-height: 1;
@@ -92,37 +83,35 @@ body {
92
  padding: 0;
93
  }
94
 
95
- #wp-admin-bar ul li { /* all list items */
 
96
  padding: 0;
97
  float: left;
98
  position: relative;
99
  background: url( ../images/admin-menu-arrow.gif ) 88% 53% no-repeat;
100
  padding-right: 11px;
101
  }
102
- #wp-admin-bar ul li.no-arrow {
103
- background: none;
104
- padding-right: 0;
105
- }
106
-
107
- #wp-admin-bar ul li ul li {
108
- background-image: none;
109
- }
110
-
111
  #wp-admin-bar ul li.align-right {
112
  position: absolute;
113
  right: 0;
114
  }
115
-
116
  #wp-admin-bar ul li a {
117
  display: block;
118
  }
119
-
120
- #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 {
 
121
  background-color: #333;
122
  }
123
 
124
  /* second-level lists */
125
-
126
  #wp-admin-bar ul li ul {
127
  position: absolute;
128
  width: 185px;
@@ -131,7 +120,7 @@ body {
131
  background: #333;
132
  border: 1px solid #222;
133
  -moz-box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
134
- -webkit-box-shadow:0 4px 8px rgba(0, 0, 0, 0.1);
135
  -moz-border-radius: 3px;
136
  -webkit-border-radius: 3px;
137
  -moz-border-radius-topleft: 0;
@@ -139,72 +128,68 @@ body {
139
  -moz-border-radius-topright: 0;
140
  -webkit-border-top-right-radius: 0;
141
  }
142
- #wp-admin-bar ul li > ul {
143
- border-top: none;
144
- }
145
-
146
- #wp-admin-bar ul li ul a {
147
- color: #eee;
148
- }
149
-
150
  #wp-admin-bar ul li ul li {
151
  float: left;
152
  width: 174px;
153
  margin: 0;
154
  }
155
- #wp-admin-bar ul li ul li:hover a {
156
- color: #fff;
157
- }
158
-
159
  #wp-admin-bar ul li div.admin-bar-clear {
160
  clear: both;
161
  }
162
-
163
- #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 {
 
164
  background-color: #222;
165
  }
166
 
167
  /* third-and-above-level lists */
168
-
169
  #wp-admin-bar ul li ul ul {
170
  margin: -25px 0 0 184px;
171
  -moz-border-radius: 3px;
172
  -webkit-border-radius: 3px;
173
  }
174
- #wp-admin-bar ul li ul li:hover ul li a {
175
- color: #eee;
176
- }
177
- #wp-admin-bar ul li ul li ul li:hover a {
178
- color: #fff;
179
- }
180
-
181
- #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 {
 
 
182
  left: auto;
183
  }
184
-
185
  #wp-admin-bar ul li.align-right:hover ul {
186
  right: 0;
187
  }
188
-
189
- #wp-admin-bar ul li:hover ul ul, #wp-admin-bar li.sfhover ul li ul {
190
  left: -999em;
191
  }
192
 
193
  /* Menu item css */
194
-
195
  #wp-admin-bar img.avatar {
196
  float: left;
197
  margin-right: 8px;
198
  }
199
-
200
  #wp-admin-bar span.activity {
201
  display: block;
202
  margin-left: 34px;
203
  padding: 0;
204
  }
205
-
206
- #wp-admin-bar ul.author-list li a { height: 17px; }
207
-
208
  #wp-admin-bar ul li#bp-adminbar-notifications-menu a span {
209
  padding: 0 6px;
210
  margin-left: 2px;
1
+ body,
2
+ body.wp-admin {
3
+ padding-top: 25px !important;
4
  }
 
5
  #wp-admin-bar {
6
  position: fixed;
7
  top: 0;
12
  width: 100%;
13
  z-index: 1000;
14
  }
15
+ #wp-admin-bar .padder {
16
+ position: relative;
17
+ padding: 0;
18
+ width: 100%;
19
+ margin: 0 auto;
20
+ background: url( ../images/60pc_black.png );
21
+ height: 25px;
22
+ }
23
+ body#bp-default #wp-admin-bar .padder {
24
+ max-width: 1250px;
25
+ }
26
+ #wp-admin-bar * {
27
+ z-index: 999;
28
+ }
 
 
 
 
 
 
29
  #wp-admin-bar div#admin-bar-logo {
30
  position: absolute;
31
  top: 5px;
32
  left: 10px;
33
  }
 
34
  #wp-admin-bar a img {
35
  border: none;
36
  }
 
37
  #wp-admin-bar li {
38
  list-style: none;
39
  margin: 0;
41
  line-height: 100%;
42
  text-align: left;
43
  }
 
44
  #wp-admin-bar li a {
45
  padding: 7px 15px 7px 15px;
46
  color: #eee;
47
  text-decoration: none;
48
  font-size: 11px;
49
  }
50
+ #wp-admin-bar li.alt {
51
+ border: none;
52
+ }
53
+ #wp-admin-bar li.no-arrow a {
54
+ padding-right: 15px;
55
+ }
56
+ #wp-admin-bar ul li ul li a span {
57
+ display: none;
58
+ }
59
+ #wp-admin-bar li:hover,
60
+ #wp-admin-bar li.hover {
61
  position: static;
62
  }
 
63
  #admin-bar-logo {
64
  float: left;
65
  font-weight: bold;
69
  text-decoration: none;
70
  color: #fff;
71
  }
72
+ body#bp-default #admin-bar-logo {
73
+ padding: 2px 8px;
74
+ }
75
 
76
+ /* all lists */
77
+ #wp-admin-bar ul {
78
  margin: 0;
79
  list-style: none;
80
  line-height: 1;
83
  padding: 0;
84
  }
85
 
86
+ /* all list items */
87
+ #wp-admin-bar ul li {
88
  padding: 0;
89
  float: left;
90
  position: relative;
91
  background: url( ../images/admin-menu-arrow.gif ) 88% 53% no-repeat;
92
  padding-right: 11px;
93
  }
94
+ #wp-admin-bar ul li.no-arrow {
95
+ background: none;
96
+ padding-right: 0;
97
+ }
98
+ #wp-admin-bar ul li ul li {
99
+ background-image: none;
100
+ }
 
 
101
  #wp-admin-bar ul li.align-right {
102
  position: absolute;
103
  right: 0;
104
  }
 
105
  #wp-admin-bar ul li a {
106
  display: block;
107
  }
108
+ #wp-admin-bar ul.main-nav li:hover,
109
+ #wp-admin-bar ul.main-nav li.sfhover,
110
+ #wp-admin-bar ul.main-nav li ul li.sfhover {
111
  background-color: #333;
112
  }
113
 
114
  /* second-level lists */
 
115
  #wp-admin-bar ul li ul {
116
  position: absolute;
117
  width: 185px;
120
  background: #333;
121
  border: 1px solid #222;
122
  -moz-box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
123
+ -webkit-box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
124
  -moz-border-radius: 3px;
125
  -webkit-border-radius: 3px;
126
  -moz-border-radius-topleft: 0;
128
  -moz-border-radius-topright: 0;
129
  -webkit-border-top-right-radius: 0;
130
  }
131
+ #wp-admin-bar ul li > ul {
132
+ border-top: none;
133
+ }
134
+ #wp-admin-bar ul li ul a {
135
+ color: #eee;
136
+ }
 
 
137
  #wp-admin-bar ul li ul li {
138
  float: left;
139
  width: 174px;
140
  margin: 0;
141
  }
142
+ #wp-admin-bar ul li ul li:hover a {
143
+ color: #fff;
144
+ }
 
145
  #wp-admin-bar ul li div.admin-bar-clear {
146
  clear: both;
147
  }
148
+ #wp-admin-bar ul.main-nav li ul li:hover,
149
+ #wp-admin-bar ul.main-nav li ul li.sfhover,
150
+ #wp-admin-bar ul.main-nav li ul li.sfhover {
151
  background-color: #222;
152
  }
153
 
154
  /* third-and-above-level lists */
 
155
  #wp-admin-bar ul li ul ul {
156
  margin: -25px 0 0 184px;
157
  -moz-border-radius: 3px;
158
  -webkit-border-radius: 3px;
159
  }
160
+ #wp-admin-bar ul li ul li:hover ul li a {
161
+ color: #eee;
162
+ }
163
+ #wp-admin-bar ul li ul li ul li:hover a {
164
+ color: #fff;
165
+ }
166
+ #wp-admin-bar ul li:hover ul,
167
+ #wp-admin-bar ul li ul li:hover ul,
168
+ #wp-admin-bar ul li.sfhover ul,
169
+ #wp-admin-bar ul li ul li.sfhover ul {
170
  left: auto;
171
  }
 
172
  #wp-admin-bar ul li.align-right:hover ul {
173
  right: 0;
174
  }
175
+ #wp-admin-bar ul li:hover ul ul,
176
+ #wp-admin-bar li.sfhover ul li ul {
177
  left: -999em;
178
  }
179
 
180
  /* Menu item css */
 
181
  #wp-admin-bar img.avatar {
182
  float: left;
183
  margin-right: 8px;
184
  }
 
185
  #wp-admin-bar span.activity {
186
  display: block;
187
  margin-left: 34px;
188
  padding: 0;
189
  }
190
+ #wp-admin-bar ul.author-list li a {
191
+ height: 17px;
192
+ }
193
  #wp-admin-bar ul li#bp-adminbar-notifications-menu a span {
194
  padding: 0 6px;
195
  margin-left: 2px;
bp-core/css/widget-members.css DELETED
@@ -1,22 +0,0 @@
1
- .widget_bp_core_members_widget ul#members-list {
2
- margin: 15px 0 0 0;
3
- padding: 0;
4
- list-style: none;
5
- }
6
-
7
- .widget_bp_core_members_widget ul#members-list li {
8
- min-height: 60px;
9
- }
10
-
11
- .widget_bp_core_members_widget ul#members-list li img.avatar {
12
- float: left;
13
- margin: 0 10px 0 0;
14
- }
15
-
16
- .widget_bp_core_members_widget ul#members-list li span.activity {
17
- font-size: 11px;
18
- }
19
-
20
- .widget_bp_core_members_widget img#ajax-loader-members {
21
- float: right;
22
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-core/deprecated/1.5.php ADDED
@@ -0,0 +1,521 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Deprecated Functions
4
+ *
5
+ * @package BuddyPress
6
+ * @subpackage Core
7
+ * @deprecated Since 1.5
8
+ */
9
+
10
+ // Exit if accessed directly
11
+ if ( !defined( 'ABSPATH' ) ) exit;
12
+
13
+ /** Loader ********************************************************************/
14
+
15
+ function bp_setup_root_components() {
16
+ do_action( 'bp_setup_root_components' );
17
+ }
18
+ add_action( 'bp_init', 'bp_setup_root_components', 6 );
19
+
20
+ /** WP Abstraction ************************************************************/
21
+
22
+ /**
23
+ * bp_core_is_multisite()
24
+ *
25
+ * This function originally served as a wrapper when WordPress and WordPress MU were separate entities.
26
+ * Use is_multisite() instead.
27
+ *
28
+ * @deprecated 1.5
29
+ * @deprecated Use is_multisite()
30
+ */
31
+ function bp_core_is_multisite() {
32
+ _deprecated_function( __FUNCTION__, '1.5', 'is_multisite()' );
33
+ return is_multisite();
34
+ }
35
+
36
+ /**
37
+ * bp_core_is_main_site
38
+ *
39
+ * Checks if current blog is root blog of site. Deprecated in 1.5.
40
+ *
41
+ * @deprecated 1.5
42
+ * @deprecated Use is_main_site()
43
+ * @package BuddyPress
44
+ * @param int $blog_id optional blog id to test (default current blog)
45
+ * @return bool True if not multisite or $blog_id is main site
46
+ * @since 1.2.6
47
+ */
48
+ function bp_core_is_main_site( $blog_id = '' ) {
49
+ _deprecated_function( __FUNCTION__, '1.5', 'is_main_site()' );
50
+ return is_main_site( $blog_id );
51
+ }
52
+
53
+ /** Admin ******************************************************************/
54
+
55
+ /**
56
+ * In BuddyPress 1.1 - 1.2.x, this function provided a better version of add_menu_page()
57
+ * that allowed positioning of menus. Deprecated in 1.5 in favour of a WP core function.
58
+ *
59
+ * @deprecated 1.5
60
+ * @deprecated Use add_menu_page().
61
+ * @since 1.1
62
+ */
63
+ function bp_core_add_admin_menu_page( $args = '' ) {
64
+ global $_registered_pages, $admin_page_hooks, $menu;
65
+
66
+ _deprecated_function( __FUNCTION__, '1.5', 'Use add_menu_page()' );
67
+
68
+ $defaults = array(
69
+ 'access_level' => 2,
70
+ 'file' => false,
71
+ 'function' => false,
72
+ 'icon_url' => false,
73
+ 'menu_title' => '',
74
+ 'page_title' => '',
75
+ 'position' => 100
76
+ );
77
+
78
+ $r = wp_parse_args( $args, $defaults );
79
+ extract( $r, EXTR_SKIP );
80
+
81
+ $file = plugin_basename( $file );
82
+ $hookname = get_plugin_page_hookname( $file, '' );
83
+
84
+ $admin_page_hooks[$file] = sanitize_title( $menu_title );
85
+
86
+ if ( !empty( $function ) && !empty ( $hookname ) )
87
+ add_action( $hookname, $function );
88
+
89
+ if ( empty( $icon_url ) )
90
+ $icon_url = 'images/generic.png';
91
+ elseif ( is_ssl() && 0 === strpos( $icon_url, 'http://' ) )
92
+ $icon_url = 'https://' . substr( $icon_url, 7 );
93
+
94
+ do {
95
+ $position++;
96
+ } while ( !empty( $menu[$position] ) );
97
+
98
+ $menu[$position] = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url );
99
+ $_registered_pages[$hookname] = true;
100
+
101
+ return $hookname;
102
+ }
103
+ /** Activity ******************************************************************/
104
+
105
+ function bp_is_activity_permalink() {
106
+ _deprecated_function( __FUNCTION__, '1.5', 'bp_is_single_activity' );
107
+ bp_is_single_activity();
108
+ }
109
+
110
+ /** Core **********************************************************************/
111
+
112
+ function bp_core_get_wp_profile() {
113
+ _deprecated_function( __FUNCTION__, '1.5' );
114
+
115
+ global $bp;
116
+
117
+ $ud = get_userdata( $bp->displayed_user->id ); ?>
118
+
119
+ <div class="bp-widget wp-profile">
120
+ <h4><?php _e( 'My Profile' ) ?></h4>
121
+
122
+ <table class="wp-profile-fields">
123
+
124
+ <?php if ( $ud->display_name ) : ?>
125
+
126
+ <tr id="wp_displayname">
127
+ <td class="label"><?php _e( 'Name', 'buddypress' ); ?></td>
128
+ <td class="data"><?php echo $ud->display_name; ?></td>
129
+ </tr>
130
+
131
+ <?php endif; ?>
132
+
133
+ <?php if ( $ud->user_description ) : ?>
134
+
135
+ <tr id="wp_desc">
136
+ <td class="label"><?php _e( 'About Me', 'buddypress' ); ?></td>
137
+ <td class="data"><?php echo $ud->user_description; ?></td>
138
+ </tr>
139
+
140
+ <?php endif; ?>
141
+
142
+ <?php if ( $ud->user_url ) : ?>
143
+
144
+ <tr id="wp_website">
145
+ <td class="label"><?php _e( 'Website', 'buddypress' ); ?></td>
146
+ <td class="data"><?php echo make_clickable( $ud->user_url ); ?></td>
147
+ </tr>
148
+
149
+ <?php endif; ?>
150
+
151
+ <?php if ( $ud->jabber ) : ?>
152
+
153
+ <tr id="wp_jabber">
154
+ <td class="label"><?php _e( 'Jabber', 'buddypress' ); ?></td>
155
+ <td class="data"><?php echo $ud->jabber; ?></td>
156
+ </tr>
157
+
158
+ <?php endif; ?>
159
+
160
+ <?php if ( $ud->aim ) : ?>
161
+
162
+ <tr id="wp_aim">
163
+ <td class="label"><?php _e( 'AOL Messenger', 'buddypress' ); ?></td>
164
+ <td class="data"><?php echo $ud->aim; ?></td>
165
+ </tr>
166
+
167
+ <?php endif; ?>
168
+
169
+ <?php if ( $ud->yim ) : ?>
170
+
171
+ <tr id="wp_yim">
172
+ <td class="label"><?php _e( 'Yahoo Messenger', 'buddypress' ); ?></td>
173
+ <td class="data"><?php echo $ud->yim; ?></td>
174
+ </tr>
175
+
176
+ <?php endif; ?>
177
+
178
+ </table>
179
+ </div>
180
+
181
+ <?php
182
+ }
183
+
184
+ function bp_is_home() {
185
+ _deprecated_function( __FUNCTION__, '1.5', 'bp_is_my_profile' );
186
+ return bp_is_my_profile();
187
+ }
188
+
189
+ /**
190
+ * Is the user on the front page of the site?
191
+ *
192
+ * @deprecated 1.5
193
+ * @deprecated Use is_front_page()
194
+ * @return bool
195
+ */
196
+ function bp_is_front_page() {
197
+ _deprecated_function( __FUNCTION__, '1.5', "is_front_page()" );
198
+ return is_front_page();
199
+ }
200
+
201
+ /**
202
+ * Is the front page of the site set to the Activity component?
203
+ *
204
+ * @deprecated 1.5
205
+ * @deprecated Use bp_is_component_front_page( 'activity' )
206
+ * @return bool
207
+ */
208
+ function bp_is_activity_front_page() {
209
+ _deprecated_function( __FUNCTION__, '1.5', "bp_is_component_front_page( 'activity' )" );
210
+ return bp_is_component_front_page( 'activity' );
211
+ }
212
+
213
+ function bp_is_member() {
214
+ _deprecated_function( __FUNCTION__, '1.5', 'bp_is_user' );
215
+ bp_is_user();
216
+ }
217
+
218
+ function bp_loggedinuser_link() {
219
+ _deprecated_function( __FUNCTION__, '1.5', 'bp_logged_in_user_link' );
220
+ bp_loggedin_user_link();
221
+ }
222
+
223
+ /**
224
+ * Only show the search form if there are available objects to search for.
225
+ * Deprecated in 1.5; not used anymore.
226
+ *
227
+ * @return bool
228
+ */
229
+ function bp_search_form_enabled() {
230
+ _deprecated_function( __FUNCTION__, '1.5', 'No longer required.' );
231
+ return apply_filters( 'bp_search_form_enabled', true );
232
+ }
233
+
234
+ /**
235
+ * Template tag version of bp_get_page_title()
236
+ *
237
+ * @deprecated 1.5
238
+ * @deprecated Use wp_title()
239
+ * @since 1.0
240
+ */
241
+ function bp_page_title() {
242
+ echo bp_get_page_title();
243
+ }
244
+ /**
245
+ * Prior to BuddyPress 1.5, this was used to generate the page's <title> text.
246
+ * Now, just simply use wp_title().
247
+ *
248
+ * @deprecated 1.5
249
+ * @deprecated Use wp_title()
250
+ * @since 1.0
251
+ */
252
+ function bp_get_page_title() {
253
+ _deprecated_function( __FUNCTION__, '1.5', 'wp_title()' );
254
+ $title = wp_title( '|', false, 'right' ) . get_bloginfo( 'name', 'display' );
255
+
256
+ // Backpat for BP 1.2 filter
257
+ $title = apply_filters( 'bp_page_title', esc_attr( $title ), esc_attr( $title ) );
258
+
259
+ return apply_filters( 'bp_get_page_title', $title );
260
+ }
261
+
262
+ /**
263
+ * Generate a link to log out. Last used in BP 1.2-beta. You should be using wp_logout_url().
264
+ *
265
+ * @deprecated 1.5
266
+ * @deprecated Use wp_logout_url()
267
+ * @since 1.0
268
+ */
269
+ function bp_log_out_link() {
270
+ _deprecated_function( __FUNCTION__, '1.5', 'wp_logout_url()' );
271
+
272
+ $logout_link = '<a href="' . wp_logout_url( bp_get_root_domain() ) . '">' . __( 'Log Out', 'buddypress' ) . '</a>';
273
+ echo apply_filters( 'bp_logout_link', $logout_link );
274
+ }
275
+
276
+ /**
277
+ * Send an email and a BP notification on receipt of an @-mention in a group
278
+ *
279
+ * @deprecated 1.5
280
+ * @deprecated Deprecated in favor of the more general bp_activity_at_message_notification()
281
+ */
282
+ function groups_at_message_notification( $content, $poster_user_id, $group_id, $activity_id ) {
283
+ global $bp;
284
+
285
+ _deprecated_function( __FUNCTION__, '1.5', 'bp_activity_at_message_notification()' );
286
+
287
+ /* Scan for @username strings in an activity update. Notify each user. */
288
+ $pattern = '/[@]+([A-Za-z0-9-_\.@]+)/';
289
+ preg_match_all( $pattern, $content, $usernames );
290
+
291
+ /* Make sure there's only one instance of each username */
292
+ if ( !$usernames = array_unique( $usernames[1] ) )
293
+ return false;
294
+
295
+ $group = new BP_Groups_Group( $group_id );
296
+
297
+ foreach( (array)$usernames as $username ) {
298
+ if ( !$receiver_user_id = bp_core_get_userid( $username ) )
299
+ continue;
300
+
301
+ /* Check the user is a member of the group before sending the update. */
302
+ if ( !groups_is_user_member( $receiver_user_id, $group_id ) )
303
+ continue;
304
+
305
+ // Now email the user with the contents of the message (if they have enabled email notifications)
306
+ if ( 'no' != bp_get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) {
307
+ $poster_name = bp_core_get_user_displayname( $poster_user_id );
308
+
309
+ $message_link = bp_activity_get_permalink( $activity_id );
310
+ $settings_link = bp_core_get_user_domain( $receiver_user_id ) . bp_get_settings_slug() . '/notifications/';
311
+
312
+ $poster_name = stripslashes( $poster_name );
313
+ $content = bp_groups_filter_kses( stripslashes( $content ) );
314
+
315
+ // Set up and send the message
316
+ $ud = bp_core_get_core_userdata( $receiver_user_id );
317
+ $to = $ud->user_email;
318
+ $sitename = wp_specialchars_decode( get_blog_option( bp_get_root_blog_id(), 'blogname' ), ENT_QUOTES );
319
+ $subject = '[' . $sitename . '] ' . sprintf( __( '%1$s mentioned you in the group "%2$s"', 'buddypress' ), $poster_name, $group->name );
320
+
321
+ $message = sprintf( __(
322
+ '%1$s mentioned you in the group "%2$s":
323
+
324
+ "%3$s"
325
+
326
+ To view and respond to the message, log in and visit: %4$s
327
+
328
+ ---------------------
329
+ ', 'buddypress' ), $poster_name, $group->name, $content, $message_link );
330
+
331
+ $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
332
+
333
+ /* Send the message */
334
+ $to = apply_filters( 'groups_at_message_notification_to', $to );
335
+ $subject = apply_filters( 'groups_at_message_notification_subject', $subject, $group, $poster_name );
336
+ $message = apply_filters( 'groups_at_message_notification_message', $message, $group, $poster_name, $content, $message_link, $settings_link );
337
+
338
+ wp_mail( $to, $subject, $message );
339
+ }
340
+ }
341
+
342
+ do_action( 'bp_groups_sent_mention_email', $usernames, $subject, $message, $content, $poster_user_id, $group_id, $activity_id );
343
+ }
344
+
345
+ /**
346
+ * BP 1.5 simplified notification functions a bit
347
+ */
348
+ function bp_core_delete_notifications_for_user_by_type( $user_id, $component_name, $component_action ) {
349
+ _deprecated_function( __FUNCTION__, '1.5', 'bp_core_delete_notifications_by_type()' );
350
+ return BP_Core_Notification::delete_for_user_by_type( $user_id, $component_name, $component_action );
351
+ }
352
+
353
+ function bp_core_delete_notifications_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false ) {
354
+ _deprecated_function( __FUNCTION__, '1.5', 'bp_core_delete_notifications_by_item_id()' );
355
+ return BP_Core_Notification::delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id );
356
+ }
357
+
358
+ /**
359
+ * In BP 1.5, these functions were renamed for greater consistency
360
+ */
361
+ function bp_forum_directory_permalink() {
362
+ _deprecated_function( __FUNCTION__, '1.5', 'bp_forums_directory_permalink()' );
363
+ bp_forums_directory_permalink();
364
+ }
365
+ function bp_get_forum_directory_permalink() {
366
+ _deprecated_function( __FUNCTION__, '1.5', 'bp_get_forums_directory_permalink()' );
367
+ return bp_get_forums_directory_permalink();
368
+ }
369
+
370
+ /**
371
+ * Last used by core in BP 1.1. The markup was merged into DTheme's header.php template.
372
+ */
373
+ function bp_search_form() {
374
+ _deprecated_function( __FUNCTION__, '1.1', 'No longer required.' );
375
+
376
+ $form = '
377
+ <form action="' . bp_search_form_action() . '" method="post" id="search-form">
378
+ <input type="text" id="search-terms" name="search-terms" value="" />
379
+ ' . bp_search_form_type_select() . '
380
+
381
+ <input type="submit" name="search-submit" id="search-submit" value="' . __( 'Search', 'buddypress' ) . '" />
382
+ ' . wp_nonce_field( 'bp_search_form' ) . '
383
+ </form>
384
+ ';
385
+
386
+ echo apply_filters( 'bp_search_form', $form );
387
+ }
388
+
389
+ /**
390
+ * Some _is_ function had their names normalized
391
+ */
392
+ function bp_is_profile_edit() {
393
+ _deprecated_function( __FUNCTION__, '1.5', 'bp_is_user_profile_edit()' );
394
+ return bp_is_user_profile_edit();
395
+ }
396
+
397
+ function bp_is_change_avatar() {
398
+ _deprecated_function( __FUNCTION__, '1.5', 'bp_is_user_change_avatar()' );
399
+ return bp_is_user_change_avatar();
400
+ }
401
+
402
+ function bp_is_friend_requests() {
403
+ _deprecated_function( __FUNCTION__, '1.5', 'bp_is_user_friend_requests()' );
404
+ return bp_is_user_friend_requests();
405
+ }
406
+
407
+ /** Theme *********************************************************************/
408
+
409
+ /**
410
+ * Contains functions which were moved out of BP-Default's functions.php
411
+ * in BuddyPress 1.5.
412
+ *
413
+ * @since 1.5
414
+ */
415
+ function bp_dtheme_deprecated() {
416
+ if ( !function_exists( 'bp_dtheme_wp_pages_filter' ) ) :
417
+ /**
418
+ * In BuddyPress 1.2.x, this function filtered the dropdown on the
419
+ * Settings > Reading screen for selecting the page to show on front to
420
+ * include "Activity Stream." As of 1.5.x, it is no longer required.
421
+ *
422
+ * @deprecated 1.5
423
+ * @deprecated No longer required.
424
+ * @param string $page_html A list of pages as a dropdown (select list)
425
+ * @return string
426
+ * @see wp_dropdown_pages()
427
+ * @since 1.2
428
+ */
429
+ function bp_dtheme_wp_pages_filter( $page_html ) {
430
+ _deprecated_function( __FUNCTION__, '1.5', "No longer required." );
431
+ return $page_html;
432
+ }
433
+ endif;
434
+
435
+ if ( !function_exists( 'bp_dtheme_page_on_front_update' ) ) :
436
+ /**
437
+ * In BuddyPress 1.2.x, this function hijacked the saving of page on front setting to save the activity stream setting.
438
+ * As of 1.5.x, it is no longer required.
439
+ *
440
+ * @deprecated 1.5
441
+ * @deprecated No longer required.
442
+ * @param $string $oldvalue Previous value of get_option( 'page_on_front' )
443
+ * @param $string $oldvalue New value of get_option( 'page_on_front' )
444
+ * @return string
445
+ * @since 1.2
446
+ */
447
+ function bp_dtheme_page_on_front_update( $oldvalue, $newvalue ) {
448
+ _deprecated_function( __FUNCTION__, '1.5', "No longer required." );
449
+ if ( !is_admin() || !is_super_admin() )
450
+ return false;
451
+
452
+ return $oldvalue;
453
+ }
454
+ endif;
455
+
456
+ if ( !function_exists( 'bp_dtheme_page_on_front_template' ) ) :
457
+ /**
458
+ * In BuddyPress 1.2.x, this function loaded the activity stream template if the front page display settings allow.
459
+ * As of 1.5.x, it is no longer required.
460
+ *
461
+ * @deprecated 1.5
462
+ * @deprecated No longer required.
463
+ * @param string $template Absolute path to the page template
464
+ * @return string
465
+ * @since 1.2
466
+ */
467
+ function bp_dtheme_page_on_front_template( $template ) {
468
+ _deprecated_function( __FUNCTION__, '1.5', "No longer required." );
469
+ return $template;
470
+ }
471
+ endif;
472
+
473
+ if ( !function_exists( 'bp_dtheme_fix_get_posts_on_activity_front' ) ) :
474
+ /**
475
+ * In BuddyPress 1.2.x, this forced the page ID as a string to stop the get_posts query from kicking up a fuss.
476
+ * As of 1.5.x, it is no longer required.
477
+ *
478
+ * @deprecated 1.5
479
+ * @deprecated No longer required.
480
+ * @since 1.2
481
+ */
482
+ function bp_dtheme_fix_get_posts_on_activity_front() {
483
+ _deprecated_function( __FUNCTION__, '1.5', "No longer required." );
484
+ }
485
+ endif;
486
+
487
+ if ( !function_exists( 'bp_dtheme_fix_the_posts_on_activity_front' ) ) :
488
+ /**
489
+ * In BuddyPress 1.2.x, this was used as part of the code that set the activity stream to be on the front page.
490
+ * As of 1.5.x, it is no longer required.
491
+ *
492
+ * @deprecated 1.5
493
+ * @deprecated No longer required.
494
+ * @param array $posts Posts as retrieved by WP_Query
495
+ * @return array
496
+ * @since 1.2.5
497
+ */
498
+ function bp_dtheme_fix_the_posts_on_activity_front( $posts ) {
499
+ _deprecated_function( __FUNCTION__, '1.5', "No longer required." );
500
+ return $posts;
501
+ }
502
+ endif;
503
+
504
+ if ( !function_exists( 'bp_dtheme_add_blog_comments_js' ) ) :
505
+ /**
506
+ * In BuddyPress 1.2.x, this added the javascript needed for blog comment replies.
507
+ * As of 1.5.x, we recommend that you enqueue the comment-reply javascript in your theme's header.php.
508
+ *
509
+ * @deprecated 1.5
510
+ * @deprecated Enqueue the comment-reply script in your theme's header.php.
511
+ * @since 1.2
512
+ */
513
+ function bp_dtheme_add_blog_comments_js() {
514
+ _deprecated_function( __FUNCTION__, '1.5', "Enqueue the comment-reply script in your theme's header.php." );
515
+ if ( is_singular() && bp_is_blog_page() && get_option( 'thread_comments' ) )
516
+ wp_enqueue_script( 'comment-reply' );
517
+ }
518
+ endif;
519
+ }
520
+ add_action( 'after_setup_theme', 'bp_dtheme_deprecated', 15 );
521
+ ?>
bp-core/images/60pc_black.png ADDED
Binary file
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-arrow.gif ADDED
Binary file
bp-core/images/completed.gif ADDED
Binary file
bp-core/images/find.png ADDED
Binary file
bp-core/images/icons32.png ADDED
Binary file
bp-core/images/installed.gif ADDED
Binary file
bp-core/images/logo-column-header.png ADDED
Binary file
bp-core/images/logo.png ADDED
Binary file
bp-core/js/admin-bar.js DELETED
File without changes
bp-core/js/update.dev.js ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready( function($) {
2
+ var toggle = $('#site-tracking-enabled');
3
+
4
+ if ( !$(toggle).is(':checked') ) {
5
+ $('#site-tracking-page-selector').hide();
6
+ }
7
+
8
+ $(toggle).click(function(){
9
+ $('#site-tracking-page-selector').toggle('fast');
10
+ });
11
+ },jQuery );
bp-core/js/update.js ADDED
@@ -0,0 +1 @@
 
1
+ jQuery(document).ready(function(b){var a=b("#site-tracking-enabled");if(!b(a).is(":checked")){b("#site-tracking-page-selector").hide()}b(a).click(function(){b("#site-tracking-page-selector").toggle("fast")})},jQuery);
bp-core/js/widget-members.dev.js ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready( function() {
2
+ jQuery(".widget div#members-list-options a").live('click',
3
+ function() {
4
+ var link = this;
5
+ jQuery(link).addClass('loading');
6
+
7
+ jQuery(".widget div#members-list-options a").removeClass("selected");
8
+ jQuery(this).addClass('selected');
9
+
10
+ jQuery.post( ajaxurl, {
11
+ action: 'widget_members',
12
+ 'cookie': encodeURIComponent(document.cookie),
13
+ '_wpnonce': jQuery("input#_wpnonce-members").val(),
14
+ 'max-members': jQuery("input#members_widget_max").val(),
15
+ 'filter': jQuery(this).attr('id')
16
+ },
17
+ function(response)
18
+ {
19
+ jQuery(link).removeClass('loading');
20
+ member_wiget_response(response);
21
+ });
22
+
23
+ return false;
24
+ }
25
+ );
26
+ });
27
+
28
+ function member_wiget_response(response) {
29
+ response = response.substr(0, response.length-1);
30
+ response = response.split('[[SPLIT]]');
31
+
32
+ if ( response[0] != "-1" ) {
33
+ jQuery(".widget ul#members-list").fadeOut(200,
34
+ function() {
35
+ jQuery(".widget ul#members-list").html(response[1]);
36
+ jQuery(".widget ul#members-list").fadeIn(200);
37
+ }
38
+ );
39
+
40
+ } else {
41
+ jQuery(".widget ul#members-list").fadeOut(200,
42
+ function() {
43
+ var message = '<p>' + response[1] + '</p>';
44
+ jQuery(".widget ul#members-list").html(message);
45
+ jQuery(".widget ul#members-list").fadeIn(200);
46
+ }
47
+ );
48
+ }
49
+ }
bp-core/js/widget-members.js CHANGED
@@ -1,48 +1 @@
1
- jQuery(document).ready( function() {
2
- jQuery(".widget div#members-list-options a").live('click',
3
- function() {
4
- jQuery('#ajax-loader-members').toggle();
5
-
6
- jQuery(".widget div#members-list-options a").removeClass("selected");
7
- jQuery(this).addClass('selected');
8
-
9
- jQuery.post( ajaxurl, {
10
- action: 'widget_members',
11
- 'cookie': encodeURIComponent(document.cookie),
12
- '_wpnonce': jQuery("input#_wpnonce-members").val(),
13
- 'max-members': jQuery("input#members_widget_max").val(),
14
- 'filter': jQuery(this).attr('id')
15
- },
16
- function(response)
17
- {
18
- jQuery('#ajax-loader-members').toggle();
19
- member_wiget_response(response);
20
- });
21
-
22
- return false;
23
- }
24
- );
25
- });
26
-
27
- function member_wiget_response(response) {
28
- response = response.substr(0, response.length-1);
29
- response = response.split('[[SPLIT]]');
30
-
31
- if ( response[0] != "-1" ) {
32
- jQuery(".widget ul#members-list").fadeOut(200,
33
- function() {
34
- jQuery(".widget ul#members-list").html(response[1]);
35
- jQuery(".widget ul#members-list").fadeIn(200);
36
- }
37
- );
38
-
39
- } else {
40
- jQuery(".widget ul#members-list").fadeOut(200,
41
- function() {
42
- var message = '<p>' + response[1] + '</p>';
43
- jQuery(".widget ul#members-list").html(message);
44
- jQuery(".widget ul#members-list").fadeIn(200);
45
- }
46
- );
47
- }
48
- }
1
+ jQuery(document).ready(function(){jQuery(".widget div#members-list-options a").live("click",function(){var a=this;jQuery(a).addClass("loading");jQuery(".widget div#members-list-options a").removeClass("selected");jQuery(this).addClass("selected");jQuery.post(ajaxurl,{action:"widget_members",cookie:encodeURIComponent(document.cookie),_wpnonce:jQuery("input#_wpnonce-members").val(),"max-members":jQuery("input#members_widget_max").val(),filter:jQuery(this).attr("id")},function(b){jQuery(a).removeClass("loading");member_wiget_response(b)});return false})});function member_wiget_response(a){a=a.substr(0,a.length-1);a=a.split("[[SPLIT]]");if(a[0]!="-1"){jQuery(".widget ul#members-list").fadeOut(200,function(){jQuery(".widget ul#members-list").html(a[1]);jQuery(".widget ul#members-list").fadeIn(200)})}else{jQuery(".widget ul#members-list").fadeOut(200,function(){var b="<p>"+a[1]+"</p>";jQuery(".widget ul#members-list").html(b);jQuery(".widget ul#members-list").fadeIn(200)})}};
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-forums.php DELETED
@@ -1,556 +0,0 @@
1
- <?php
2
-
3
- /* Define the parent forum ID */
4
- if ( !defined( 'BP_FORUMS_PARENT_FORUM_ID' ) )
5
- define( 'BP_FORUMS_PARENT_FORUM_ID', 1 );
6
-
7
- if ( !defined( 'BP_FORUMS_SLUG' ) )
8
- define( 'BP_FORUMS_SLUG', 'forums' );
9
-
10
- if ( !defined( 'BB_PATH' ) )
11
- require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-bbpress.php' );
12
-
13
- require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-templatetags.php' );
14
- require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-filters.php' );
15
-
16
- function bp_forums_setup() {
17
- global $bp;
18
-
19
- /* For internal identification */
20
- $bp->forums->id = 'forums';
21
-
22
- $bp->forums->image_base = BP_PLUGIN_URL . '/bp-forums/images';
23
- $bp->forums->bbconfig = $bp->site_options['bb-config-location'];
24
- $bp->forums->slug = BP_FORUMS_SLUG;
25
-
26
- /* Register this in the active components array */
27
- $bp->active_components[$bp->forums->slug] = $bp->forums->id;
28
-
29
- do_action( 'bp_forums_setup' );
30
- }
31
- add_action( 'bp_setup_globals', 'bp_forums_setup' );
32
-
33
- function bp_forums_is_installed_correctly() {
34
- global $bp;
35
-
36
- if ( file_exists( $bp->forums->bbconfig ) )
37
- return true;
38
-
39
- return false;
40
- }
41
-
42
- function bp_forums_setup_root_component() {
43
- /* Register 'forums' as a root component */
44
- bp_core_add_root_component( BP_FORUMS_SLUG );
45
- }
46
- add_action( 'bp_setup_root_components', 'bp_forums_setup_root_component' );
47
-
48
- function bp_forums_directory_forums_setup() {
49
- global $bp;
50
-
51
- if ( $bp->current_component == $bp->forums->slug ) {
52
- if ( (int) $bp->site_options['bp-disable-forum-directory'] || !function_exists( 'groups_install' ) )
53
- return false;
54
-
55
- if ( !bp_forums_is_installed_correctly() ) {
56
- bp_core_add_message( __( 'The forums component has not been set up yet.', 'buddypress' ), 'error' );
57
- bp_core_redirect( $bp->root_domain );
58
- }
59
-
60
- $bp->is_directory = true;
61
-
62
- do_action( 'bbpress_init' );
63
-
64
- /* Check to see if the user has posted a new topic from the forums page. */
65
- if ( isset( $_POST['submit_topic'] ) && function_exists( 'bp_forums_new_topic' ) ) {
66
- /* Check the nonce */
67
- check_admin_referer( 'bp_forums_new_topic' );
68
-
69
- if ( $bp->groups->current_group = groups_get_group( array( 'group_id' => $_POST['topic_group_id'] ) ) ) {
70
- /* Auto join this user if they are not yet a member of this group */
71
- if ( !is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
72
- groups_join_group( $bp->groups->current_group->id, $bp->groups->current_group->id );
73
-
74
- if ( $forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' ) ) {
75
- if ( !$topic = groups_new_group_forum_topic( $_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id ) )
76
- bp_core_add_message( __( 'There was an error when creating the topic', 'buddypress'), 'error' );
77
- else
78
- bp_core_add_message( __( 'The topic was created successfully', 'buddypress') );
79
-
80
- bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic->topic_slug . '/' );
81
- } else {
82
- bp_core_add_message( __( 'Please pick the group forum where you would like to post this topic.', 'buddypress' ), 'error' );
83
- }
84
- }
85
- }
86
-
87
- do_action( 'bp_forums_directory_forums_setup' );
88
-
89
- bp_core_load_template( apply_filters( 'bp_forums_template_directory_forums_setup', 'forums/index' ) );
90
- }
91
- }
92
- add_action( 'wp', 'bp_forums_directory_forums_setup', 2 );
93
-
94
- function bp_forums_add_admin_menu() {
95
- global $bp;
96
-
97
- if ( !is_super_admin() )
98
- return false;
99
-
100
- require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-admin.php' );
101
-
102
- /* Add the administration tab under the "Site Admin" tab for site administrators */
103
- add_submenu_page( 'bp-general-settings', __( 'Forums Setup', 'buddypress' ), __( 'Forums Setup', 'buddypress' ), 'manage_options', 'bb-forums-setup', "bp_forums_bbpress_admin" );
104
- }
105
- add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', 'bp_forums_add_admin_menu' );
106
-
107
- /* Forum Functions */
108
-
109
- function bp_forums_get_forum( $forum_id ) {
110
- do_action( 'bbpress_init' );
111
- return bb_get_forum( $forum_id );
112
- }
113
-
114
- function bp_forums_new_forum( $args = '' ) {
115
- do_action( 'bbpress_init' );
116
-
117
- $defaults = array(
118
- 'forum_name' => '',
119
- 'forum_desc' => '',
120
- 'forum_parent_id' => BP_FORUMS_PARENT_FORUM_ID,
121
- 'forum_order' => false,
122
- 'forum_is_category' => 0
123
- );
124
-
125
- $r = wp_parse_args( $args, $defaults );
126
- extract( $r, EXTR_SKIP );
127
-
128
- return bb_new_forum( array( 'forum_name' => stripslashes( $forum_name ), 'forum_desc' => stripslashes( $forum_desc ), 'forum_parent' => $forum_parent_id, 'forum_order' => $forum_order, 'forum_is_category' => $forum_is_category ) );
129
- }
130
-
131
- function bp_forums_update_forum( $args = '' ) {
132
- do_action( 'bbpress_init' );
133
-
134
- $defaults = array(
135
- 'forum_id' => '',
136
- 'forum_name' => '',
137
- 'forum_desc' => '',
138
- 'forum_slug' => '',
139
- 'forum_parent_id' => BP_FORUMS_PARENT_FORUM_ID,
140
- 'forum_order' => false,
141
- 'forum_is_category' => 0
142
- );
143
-
144
- $r = wp_parse_args( $args, $defaults );
145
- extract( $r, EXTR_SKIP );
146
-
147
- 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 ) );
148
- }
149
-
150
- /* Topic Functions */
151
-
152
- function bp_forums_get_forum_topics( $args = '' ) {
153
- global $bp;
154
-
155
- do_action( 'bbpress_init' );
156
-
157
- $defaults = array(
158
- 'type' => 'newest',
159
- 'forum_id' => false,
160
- 'user_id' => false,
161
- 'page' => 1,
162
- 'per_page' => 15,
163
- 'exclude' => false,
164
- 'show_stickies' => 'all',
165
- 'filter' => false // if $type = tag then filter is the tag name, otherwise it's terms to search on.
166
- );
167
-
168
- $r = wp_parse_args( $args, $defaults );
169
- extract( $r, EXTR_SKIP );
170
-
171
- switch ( $type ) {
172
- case 'newest':
173
- $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'per_page' => $per_page, 'page' => $page, 'number' => $per_page, 'exclude' => $exclude, 'topic_title' => $filter, 'sticky' => $show_stickies ), 'get_latest_topics' );
174
- $topics =& $query->results;
175
- break;
176
-
177
- case 'popular':
178
- $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_posts', 'topic_title' => $filter, 'sticky' => $show_stickies ) );
179
- $topics =& $query->results;
180
- break;
181
-
182
- case 'unreplied':
183
- $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'post_count' => 1, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_time', 'topic_title' => $filter, 'sticky' => $show_stickies ) );
184
- $topics =& $query->results;
185
- break;
186
-
187
- case 'tags':
188
- $query = new BB_Query( 'topic', array( 'forum_id' => $forum_id, 'topic_author_id' => $user_id, 'tag' => $filter, 'per_page' => $per_page, 'page' => $page, 'order_by' => 't.topic_time', 'sticky' => $show_stickies ) );
189
- $topics =& $query->results;
190
- break;
191
- }
192
-
193
- return apply_filters( 'bp_forums_get_forum_topics', $topics, &$r );
194
- }
195
-
196
- function bp_forums_get_topic_details( $topic_id ) {
197
- do_action( 'bbpress_init' );
198
-
199
- $query = new BB_Query( 'topic', 'topic_id=' . $topic_id . '&page=1' /* Page override so bbPress doesn't use the URI */ );
200
-
201
- return $query->results[0];
202
- }
203
-
204
- function bp_forums_get_topic_id_from_slug( $topic_slug ) {
205
- do_action( 'bbpress_init' );
206
- return bb_get_id_from_slug( 'topic', $topic_slug );
207
- }
208
-
209
- function bp_forums_new_topic( $args = '' ) {
210
- global $bp;
211
-
212
- do_action( 'bbpress_init' );
213
-
214
- $defaults = array(
215
- 'topic_title' => '',
216
- 'topic_slug' => '',
217
- 'topic_text' => '',
218
- 'topic_poster' => $bp->loggedin_user->id, // accepts ids
219
- 'topic_poster_name' => $bp->loggedin_user->fullname, // accept names
220
- 'topic_last_poster' => $bp->loggedin_user->id, // accepts ids
221
- 'topic_last_poster_name' => $bp->loggedin_user->fullname, // accept names
222
- 'topic_start_time' => date( 'Y-m-d H:i:s' ),
223
- 'topic_time' => date( 'Y-m-d H:i:s' ),
224
- 'topic_open' => 1,
225
- 'topic_tags' => false, // accepts array or comma delim
226
- 'forum_id' => 0 // accepts ids or slugs
227
- );
228
-
229
- $r = wp_parse_args( $args, $defaults );
230
- extract( $r, EXTR_SKIP );
231
-
232
- $topic_title = strip_tags( $topic_title );
233
-
234
- if ( empty( $topic_title ) || !strlen( trim( $topic_title ) ) )
235
- return false;
236
-
237
- if ( empty( $topic_slug ) )
238
- $topic_slug = sanitize_title( $topic_title );
239
-
240
- 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 ) ) )
241
- return false;
242
-
243
- /* Now insert the first post. */
244
- if ( !bp_forums_insert_post( array( 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $topic_time, 'poster_id' => $topic_poster ) ) )
245
- return false;
246
-
247
- do_action( 'bp_forums_new_topic', $topic_id );
248
-
249
- return $topic_id;
250
- }
251
-
252
- function bp_forums_update_topic( $args = '' ) {
253
- global $bp;
254
-
255
- do_action( 'bbpress_init' );
256
-
257
- $defaults = array(
258
- 'topic_id' => false,
259
- 'topic_title' => '',
260
- 'topic_text' => ''
261
- );
262
-
263
- $r = wp_parse_args( $args, $defaults );
264
- extract( $r, EXTR_SKIP );
265
-
266
- if ( !$topic_id = bb_insert_topic( array( 'topic_id' => $topic_id, 'topic_title' => stripslashes( $topic_title ) ) ) )
267
- return false;
268
-
269
- if ( !$post = bb_get_first_post( $topic_id ) )
270
- return false;
271
-
272
- /* Update the first post */
273
- if ( !$post = bp_forums_insert_post( array( 'post_id' => $post->post_id, 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $post->post_time, 'poster_id' => $post->poster_id, 'poster_ip' => $post->poster_ip, 'post_status' => $post->post_status, 'post_position' => $post->post_position ) ) )
274
- return false;
275
-
276
- return bp_forums_get_topic_details( $topic_id );
277
- }
278
-
279
- function bp_forums_sticky_topic( $args = '' ) {
280
- global $bp;
281
-
282
- do_action( 'bbpress_init' );
283
-
284
- $defaults = array(
285
- 'topic_id' => false,
286
- 'mode' => 'stick' // stick/unstick
287
- );
288
-
289
- $r = wp_parse_args( $args, $defaults );
290
- extract( $r, EXTR_SKIP );
291
-
292
- if ( 'stick' == $mode )
293
- return bb_stick_topic( $topic_id );
294
- else if ( 'unstick' == $mode )
295
- return bb_unstick_topic( $topic_id );
296
-
297
- return false;
298
- }
299
-
300
- function bp_forums_openclose_topic( $args = '' ) {
301
- global $bp;
302
-
303
- do_action( 'bbpress_init' );
304
-
305
- $defaults = array(
306
- 'topic_id' => false,
307
- 'mode' => 'close' // stick/unstick
308
- );
309
-
310
- $r = wp_parse_args( $args, $defaults );
311
- extract( $r, EXTR_SKIP );
312
-
313
- if ( 'close' == $mode )
314
- return bb_close_topic( $topic_id );
315
- else if ( 'open' == $mode )
316
- return bb_open_topic( $topic_id );
317
-
318
- return false;
319
- }
320
-
321
- function bp_forums_delete_topic( $args = '' ) {
322
- global $bp;
323
-
324
- do_action( 'bbpress_init' );
325
-
326
- $defaults = array(
327
- 'topic_id' => false
328
- );
329
-
330
- $r = wp_parse_args( $args, $defaults );
331
- extract( $r, EXTR_SKIP );
332
-
333
- return bb_delete_topic( $topic_id, 1 );
334
- }
335
-
336
- function bp_forums_total_topic_count() {
337
- do_action( 'bbpress_init' );
338
-
339
- $query = new BB_Query( 'topic', array( 'page' => 1, 'per_page' => -1, 'count' => true ) );
340
- $count = $query->count;
341
- $query = null;
342
-
343
- return $count;
344
- }
345
-
346
- function bp_forums_total_topic_count_for_user( $user_id = false ) {
347
- global $bp;
348
-
349
- do_action( 'bbpress_init' );
350
-
351
- if ( !$user_id )
352
- $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
353
-
354
- $query = new BB_Query( 'topic', array( 'topic_author_id' => $user_id, 'page' => 1, 'per_page' => -1, 'count' => true ) );
355
- $count = $query->count;
356
- $query = null;
357
-
358
- return $count;
359
- }
360
-
361
- function bp_forums_get_topic_extras( $topics ) {
362
- global $bp, $wpdb, $bbdb;
363
-
364
- if ( empty( $topics ) )
365
- return $topics;
366
-
367
- /* Get the topic ids */
368
- foreach ( (array)$topics as $topic ) $topic_ids[] = $topic->topic_id;
369
- $topic_ids = $wpdb->escape( join( ',', (array)$topic_ids ) );
370
-
371
- /* Fetch the topic's last poster details */
372
- $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} )" ) );
373
- for ( $i = 0; $i < count( $topics ); $i++ ) {
374
- foreach ( (array)$poster_details as $poster ) {
375
- if ( $poster->topic_id == $topics[$i]->topic_id ) {
376
- $topics[$i]->topic_last_poster_email = $poster->user_email;
377
- $topics[$i]->topic_last_poster_nicename = $poster->user_nicename;
378
- $topics[$i]->topic_last_poster_login = $poster->user_login;
379
- $topics[$i]->topic_last_poster_displayname = $poster->display_name;
380
- }
381
- }
382
- }
383
-
384
- /* Fetch fullname for the topic's last poster */
385
- if ( function_exists( 'xprofile_install' ) ) {
386
- $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} )" ) );
387
- for ( $i = 0; $i < count( $topics ); $i++ ) {
388
- foreach ( (array)$poster_names as $name ) {
389
- if ( $name->topic_id == $topics[$i]->topic_id )
390
- $topics[$i]->topic_last_poster_displayname = $name->value;
391
- }
392
- }
393
- }
394
-
395
- return $topics;
396
- }
397
-
398
- /* Post Functions */
399
-
400
- function bp_forums_get_topic_posts( $args = '' ) {
401
- do_action( 'bbpress_init' );
402
-
403
- $defaults = array(
404
- 'topic_id' => false,
405
- 'page' => 1,
406
- 'per_page' => 15,
407
- 'order' => 'ASC'
408
- );
409
-
410
- $args = wp_parse_args( $args, $defaults );
411
-
412
- $query = new BB_Query( 'post', $args, 'get_thread' );
413
- return bp_forums_get_post_extras( $query->results );
414
- }
415
-
416
- function bp_forums_get_post( $post_id ) {
417
- do_action( 'bbpress_init' );
418
- return bb_get_post( $post_id );
419
- }
420
-
421
- function bp_forums_delete_post( $args = '' ) {
422
- global $bp;
423
-
424
- do_action( 'bbpress_init' );
425
-
426
- $defaults = array(
427
- 'post_id' => false
428
- );
429
-
430
- $r = wp_parse_args( $args, $defaults );
431
- extract( $r, EXTR_SKIP );
432
-
433
- return bb_delete_post( $post_id, 1 );
434
- }
435
-
436
- function bp_forums_insert_post( $args = '' ) {
437
- global $bp;
438
-
439
- do_action( 'bbpress_init' );
440
-
441
- $defaults = array(
442
- 'post_id' => false,
443
- 'topic_id' => false,
444
- 'post_text' => '',
445
- 'post_time' => date( 'Y-m-d H:i:s' ),
446
- 'poster_id' => $bp->loggedin_user->id, // accepts ids or names
447
- 'poster_ip' => $_SERVER['REMOTE_ADDR'],
448
- 'post_status' => 0, // use bb_delete_post() instead
449
- 'post_position' => false
450
- );
451
-
452
- $r = wp_parse_args( $args, $defaults );
453
- extract( $r, EXTR_SKIP );
454
-
455
- if ( !$post = bp_forums_get_post( $post_id ) )
456
- $post_id = false;
457
-
458
- if ( !isset( $topic_id ) )
459
- $topic_id = $post->topic_id;
460
-
461
- if ( empty( $post_text ) )
462
- $post_text = $post->post_text;
463
-
464
- if ( !isset( $post_time ) )
465
- $post_time = $post->post_time;
466
-
467
- if ( !isset( $post_position ) )
468
- $post_position = $post->post_position;
469
-
470
- $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 ) );
471
-
472
- if ( $post_id )
473
- do_action( 'bp_forums_new_post', $post_id );
474
-
475
- return $post_id;
476
- }
477
-
478
- function bp_forums_get_post_extras( $posts ) {
479
- global $bp, $wpdb;
480
-
481
- if ( empty( $posts ) )
482
- return $posts;
483
-
484
- /* Get the user ids */
485
- foreach ( (array)$posts as $post ) $user_ids[] = $post->poster_id;
486
- $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
487
-
488
- /* Fetch the poster's user_email, user_nicename and user_login */
489
- $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} )" ) );
490
-
491
- for ( $i = 0; $i < count( $posts ); $i++ ) {
492
- foreach ( (array)$poster_details as $poster ) {
493
- if ( $poster->user_id == $posts[$i]->poster_id ) {
494
- $posts[$i]->poster_email = $poster->user_email;
495
- $posts[$i]->poster_login = $poster->user_nicename;
496
- $posts[$i]->poster_nicename = $poster->user_login;
497
- $posts[$i]->poster_name = $poster->display_name;
498
- }
499
- }
500
- }
501
-
502
- /* Fetch fullname for each poster. */
503
- if ( function_exists( 'xprofile_install' ) ) {
504
- $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} )" ) );
505
- for ( $i = 0; $i < count( $posts ); $i++ ) {
506
- foreach ( (array)$poster_names as $name ) {
507
- if ( $name->user_id == $topics[$i]->user_id )
508
- $posts[$i]->poster_name = $poster->value;
509
- }
510
- }
511
- }
512
-
513
- return $posts;
514
- }
515
-
516
-
517
- function bp_forums_get_forum_topicpost_count( $forum_id ) {
518
- global $wpdb, $bbdb;
519
-
520
- do_action( 'bbpress_init' );
521
-
522
- /* Need to find a bbPress function that does this */
523
- return $wpdb->get_results( $wpdb->prepare( "SELECT topics, posts from {$bbdb->forums} WHERE forum_id = %d", $forum_id ) );
524
- }
525
-
526
-
527
- function bp_forums_filter_caps( $allcaps ) {
528
- global $bp, $wp_roles, $bb_table_prefix;
529
-
530
- $bb_cap = get_user_meta( $bp->loggedin_user->id, $bb_table_prefix . 'capabilities', true );
531
-
532
- if ( empty( $bb_cap ) )
533
- return $allcaps;
534
-
535
- $bb_cap = array_keys($bb_cap);
536
- $bb_cap = $wp_roles->get_role( $bb_cap[0] );
537
- $bb_cap = $bb_cap->capabilities;
538
-
539
- return array_merge( (array) $allcaps, (array) $bb_cap );
540
- }
541
- add_filter( 'user_has_cap', 'bp_forums_filter_caps' );
542
-
543
-
544
- /********************************************************************************
545
- * Caching
546
- *
547
- * Caching functions handle the clearing of cached objects and pages on specific
548
- * actions throughout BuddyPress.
549
- */
550
-
551
- // List actions to clear super cached pages on, if super cache is installed
552
- add_action( 'bp_forums_new_forum', 'bp_core_clear_cache' );
553
- add_action( 'bp_forums_new_topic', 'bp_core_clear_cache' );
554
- add_action( 'bp_forums_new_post', 'bp_core_clear_cache' );
555
-
556
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bp-forums/bbpress/bb-admin/admin-ajax.php CHANGED
@@ -48,12 +48,13 @@ case 'add-tag' : // $id is topic_id
48
  continue;
49
  }
50
  }
 
51
  $tag->user_id = bb_get_current_user_info( 'id' );
52
- $tag_id_val = $tag->tag_id . '_' . $tag->user_id;
53
- $tag->raw_tag = esc_attr( $tag->raw_tag );
54
  $x->add( array(
55
  'what' => 'tag',
56
- 'id' => $tag_id_val,
57
  'data' => _bb_list_tag_item( $tag, array( 'list_id' => 'tags-list', 'format' => 'list' ) )
58
  ) );
59
  }
@@ -118,8 +119,28 @@ case 'delete-post' : // $id is post_id
118
  if ( $status == $bb_post->post_status )
119
  die('1'); // We're already there
120
 
121
- if ( bb_delete_post( $id, $status ) )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  die('1');
 
123
  break;
124
  /*
125
  case 'add-post' : // Can put last_modified stuff back in later
48
  continue;
49
  }
50
  }
51
+ $tag->tag_id = $tag_id;
52
  $tag->user_id = bb_get_current_user_info( 'id' );
53
+ $tag_id_val = $tag->tag_id . '_' . $tag->user_id;
54
+ $tag->raw_tag = esc_attr( $tag_name );
55
  $x->add( array(
56
  'what' => 'tag',
57
+ 'id' => $tag_id_val,
58
  'data' => _bb_list_tag_item( $tag, array( 'list_id' => 'tags-list', 'format' => 'list' ) )
59
  ) );
60
  }
119
  if ( $status == $bb_post->post_status )
120
  die('1'); // We're already there
121
 
122
+ if ( bb_delete_post( $id, $status ) ) {
123
+ $topic = get_topic( $bb_post->topic_id );
124
+ if ( 0 == $topic->topic_posts ) {
125
+ // If we deleted the only post, send back a WP_Ajax_Response object with a URL to redirect to
126
+ if ( $ref = wp_get_referer() ) {
127
+ $ref_topic = bb_get_topic_from_uri( $ref );
128
+ if ( $ref_topic && $ref_topic->topic_id == $topic->topic_id )
129
+ $ref = add_query_arg( 'view', 'all', $ref );
130
+ if ( false === strpos( $ref, '#' ) )
131
+ $ref .= "#post-{$bb_post->post_id}";
132
+ } else {
133
+ $ref = add_query_arg( 'view', 'all', get_post_link( $topic->topic_id ) );
134
+ }
135
+ $x = new WP_Ajax_Response( array(
136
+ 'what' => 'post',
137
+ 'id' => $bb_post->post_id,
138
+ 'data' => $ref,
139
+ ) );
140
+ $x->send();
141
+ }
142
  die('1');
143
+ }
144
  break;
145
  /*
146
  case 'add-post' : // Can put last_modified stuff back in later
bp-forums/bbpress/bb-admin/admin-header.php CHANGED
@@ -8,6 +8,12 @@
8
  <?php if ( 'rtl' == bb_get_option( 'text_direction' ) ) : ?>
9
  <link rel="stylesheet" href="<?php bb_uri('bb-admin/style-rtl.css', null, BB_URI_CONTEXT_LINK_STYLESHEET_HREF + BB_URI_CONTEXT_BB_ADMIN); ?>" type="text/css" />
10
  <?php endif; do_action('bb_admin_print_scripts'); ?>
 
 
 
 
 
 
11
  <script type="text/javascript">
12
  //<![CDATA[
13
  addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
8
  <?php if ( 'rtl' == bb_get_option( 'text_direction' ) ) : ?>
9
  <link rel="stylesheet" href="<?php bb_uri('bb-admin/style-rtl.css', null, BB_URI_CONTEXT_LINK_STYLESHEET_HREF + BB_URI_CONTEXT_BB_ADMIN); ?>" type="text/css" />
10
  <?php endif; do_action('bb_admin_print_scripts'); ?>
11
+ <!--[if IE 6]>
12
+ <style type="text/css">
13
+ ul#bbAdminMenu{ margin: 15px 5px 15px -85px; } body.bb-menu-folded div#bbBody{ margin-left: 110px; }
14
+ </style>
15
+ <![endif]-->
16
+ <link rel="shortcut icon" type="image/ico" href="<?php bb_uri('bb-admin/images/favicon.ico', null, BB_URI_CONTEXT_BB_ADMIN); ?>" />
17
  <script type="text/javascript">
18
  //<![CDATA[
19
  addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
bp-forums/bbpress/bb-admin/delete-post.php CHANGED
@@ -67,7 +67,10 @@ $topic = get_topic( $bb_post->topic_id );
67
  if ( $sendto = wp_get_referer() ) {
68
  $sendto = remove_query_arg( 'message', $sendto );
69
  $sendto = add_query_arg( 'message', $message, $sendto );
70
- } elseif ( $topic->topic_posts == 0 ) {
 
 
 
71
  $sendto = get_forum_link( $topic->forum_id );
72
  } else {
73
  $the_page = bb_get_page_number( $bb_post->post_position );
67
  if ( $sendto = wp_get_referer() ) {
68
  $sendto = remove_query_arg( 'message', $sendto );
69
  $sendto = add_query_arg( 'message', $message, $sendto );
70
+ $send_to_topic = bb_get_topic_from_uri( $sendto );
71
+ if ( $send_to_topic && $topic->topic_id == $send_to_topic->topic_id )
72
+ $sendto = add_query_arg( 'view', 'all', $sendto );
73
+ } else if ( $topic->topic_posts == 0 ) {
74
  $sendto = get_forum_link( $topic->forum_id );
75
  } else {
76
  $the_page = bb_get_page_number( $bb_post->post_position );
bp-forums/bbpress/bb-admin/export.php CHANGED
@@ -243,7 +243,7 @@ function bb_export_topic_posts( $r, $topic_id ) {
243
  $r .= "\n";
244
 
245
  $page = 1;
246
- while ( $posts = get_thread( $topic_id, $page++ ) ) {
247
  foreach ( $posts as $post )
248
  $r .= bb_export_post( $post->post_id );
249
  }
@@ -297,7 +297,6 @@ add_filter( 'in_bb_export_object_topic', 'bb_export_topic_posts', 10, 2 );
297
  add_filter( 'get_forum_where', 'bb_no_where', 9999 );
298
  add_filter( 'get_forums_where', 'bb_no_where', 9999 );
299
  add_filter( 'get_latest_topics_where', 'bb_no_where', 9999 );
300
- add_filter( 'get_thread_where', 'bb_no_where', 9999 );
301
  add_filter( 'get_user_where', 'bb_no_where', 9999 );
302
  add_filter( 'cache_users_where', 'bb_no_where', 9999 );
303
 
243
  $r .= "\n";
244
 
245
  $page = 1;
246
+ while ( $posts = get_thread( $topic_id, array( 'post_status' => 'all', 'page' => $page++ ) ) ) {
247
  foreach ( $posts as $post )
248
  $r .= bb_export_post( $post->post_id );
249
  }
297
  add_filter( 'get_forum_where', 'bb_no_where', 9999 );
298
  add_filter( 'get_forums_where', 'bb_no_where', 9999 );
299
  add_filter( 'get_latest_topics_where', 'bb_no_where', 9999 );
 
300
  add_filter( 'get_user_where', 'bb_no_where', 9999 );
301
  add_filter( 'cache_users_where', 'bb_no_where', 9999 );
302
 
bp-forums/bbpress/bb-admin/images/favicon.ico ADDED
Binary file
bp-forums/bbpress/bb-admin/includes/class.bb-install.php CHANGED
@@ -899,7 +899,7 @@ class BB_Install
899
  'uri' => array(
900
  'value' => $this->guess_uri(),
901
  'label' => __( 'Site address (URL)' ),
902
- 'note' => __( 'We have attempted to guess this, it\'s usually correct, but change it here if you wish.' )
903
  ),
904
  'keymaster_user_login' => array(
905
  'value' => '',
@@ -2144,14 +2144,14 @@ class BB_Install
2144
 
2145
  if ( defined( 'BB_PLUGIN_DIR' ) && BB_PLUGIN_DIR && !file_exists( BB_PLUGIN_DIR ) ) {
2146
  // Just suppress errors as this is not critical
2147
- if ( @mkdir( BB_PLUGIN_DIR, 0750 ) ) {
2148
  $installation_log[] = '>>> ' . sprintf( __( 'Making plugin directory at %s.' ), BB_PLUGIN_DIR );
2149
  }
2150
  }
2151
 
2152
  if ( defined( 'BB_THEME_DIR' ) && BB_THEME_DIR && !file_exists( BB_THEME_DIR ) ) {
2153
  // Just suppress errors as this is not critical
2154
- if ( @mkdir( BB_THEME_DIR, 0750 ) ) {
2155
  $installation_log[] = '>>> ' . sprintf( __( 'M
899
  'uri' => array(
900
  'value' => $this->guess_uri(),
901
  'label' => __( 'Site address (URL)' ),
902
+ 'note' => __( 'We have attempted to guess this; it\'s usually correct, but change it here if you wish.' )
903
  ),
904
  'keymaster_user_login' => array(
905
  'value' => '',
2144
 
2145
  if ( defined( 'BB_PLUGIN_DIR' ) && BB_PLUGIN_DIR && !file_exists( BB_PLUGIN_DIR ) ) {
2146
  // Just suppress errors as this is not critical
2147
+ if ( @mkdir( BB_PLUGIN_DIR, 0755 ) ) {
2148
  $installation_log[] = '>>> ' . sprintf( __( 'Making plugin directory at %s.' ), BB_PLUGIN_DIR );
2149
  }
2150
  }
2151
 
2152
  if ( defined( 'BB_THEME_DIR' ) && BB_THEME_DIR && !file_exists( BB_THEME_DIR ) ) {
2153
  // Just suppress errors as this is not critical
2154
+ if ( @mkdir( BB_THEME_DIR, 0755 ) ) {
2155
  $installation_log[] = '>>> ' . sprintf( __( 'M