BuddyPress - Version 1.2.5

Version Description

Bug fixes and improved support for WordPress 3.0. Important upgrade.

=

Download this release

Release Info

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

Code changes from version 1.2.4.1 to 1.2.5

bp-activity.php CHANGED
@@ -1,1194 +1,1198 @@
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/upgrade-functions.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, $wpdb, $current_blog;
77
-
78
- /* Internal identifier */
79
- $bp->activity->id = 'activity';
80
-
81
- $bp->activity->table_name = $wpdb->base_prefix . 'bp_activity';
82
- $bp->activity->table_name_meta = $wpdb->base_prefix . 'bp_activity_meta';
83
- $bp->activity->slug = BP_ACTIVITY_SLUG;
84
- $bp->activity->format_notification_function = 'bp_activity_format_notifications';
85
-
86
- /* Register this in the active components array */
87
- $bp->active_components[$bp->activity->slug] = $bp->activity->id;
88
-
89
- do_action( 'bp_activity_setup_globals' );
90
- }
91
- add_action( 'bp_setup_globals', 'bp_activity_setup_globals' );
92
-
93
- function bp_activity_check_installed() {
94
- global $wpdb, $bp;
95
-
96
- if ( get_site_option( 'bp-activity-db-version' ) < BP_ACTIVITY_DB_VERSION )
97
- bp_activity_install();
98
- }
99
- add_action( 'admin_menu', 'bp_activity_check_installed' );
100
-
101
- function bp_activity_setup_root_component() {
102
- /* Register 'activity' as a root component (for RSS feed use) */
103
- bp_core_add_root_component( BP_ACTIVITY_SLUG );
104
- }
105
- add_action( 'bp_setup_root_components', 'bp_activity_setup_root_component' );
106
-
107
- function bp_activity_setup_nav() {
108
- global $bp;
109
-
110
- /* Add 'Activity' to the main navigation */
111
- 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 ) );
112
-
113
- $user_domain = ( !empty( $bp->displayed_user->domain ) ) ? $bp->displayed_user->domain : $bp->loggedin_user->domain;
114
- $user_login = ( !empty( $bp->displayed_user->userdata->user_login ) ) ? $bp->displayed_user->userdata->user_login : $bp->loggedin_user->userdata->user_login;
115
- $activity_link = $user_domain . $bp->activity->slug . '/';
116
-
117
- /* Add the subnav items to the activity nav item if we are using a theme that supports this */
118
- 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 ) );
119
-
120
- if ( bp_is_active( 'friends' ) )
121
- 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' ) );
122
-
123
- if ( bp_is_active( 'groups' ) )
124
- 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' ) );
125
-
126
- 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' ) );
127
- 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' ) );
128
-
129
- if ( $bp->current_component == $bp->activity->slug ) {
130
- if ( bp_is_my_profile() ) {
131
- $bp->bp_options_title = __( 'My Activity', 'buddypress' );
132
- } else {
133
- $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
134
- $bp->bp_options_title = $bp->displayed_user->fullname;
135
- }
136
- }
137
-
138
- do_action( 'bp_activity_setup_nav' );
139
- }
140
- add_action( 'bp_setup_nav', 'bp_activity_setup_nav' );
141
-
142
- function bp_activity_directory_activity_setup() {
143
- global $bp;
144
-
145
- if ( $bp->current_component == $bp->activity->slug && empty( $bp->current_action ) ) {
146
- $bp->is_directory = true;
147
-
148
- do_action( 'bp_activity_directory_activity_setup' );
149
- bp_core_load_template( apply_filters( 'bp_activity_directory_activity_setup', 'activity/index' ) );
150
- }
151
- }
152
- add_action( 'wp', 'bp_activity_directory_activity_setup', 2 );
153
-
154
-
155
- /********************************************************************************
156
- * Screen Functions
157
- *
158
- * Screen functions are the controllers of BuddyPress. They will execute when their
159
- * specific URL is caught. They will first save or manipulate data using business
160
- * functions, then pass on the user to a template file.
161
- */
162
-
163
- function bp_activity_screen_my_activity() {
164
- do_action( 'bp_activity_screen_my_activity' );
165
- bp_core_load_template( apply_filters( 'bp_activity_template_my_activity', 'members/single/home' ) );
166
- }
167
-
168
- function bp_activity_screen_friends() {
169
- global $bp;
170
-
171
- if ( !bp_is_active( 'friends' ) )
172
- return false;
173
-
174
- if ( !is_site_admin() )
175
- $bp->is_item_admin = false;
176
-
177
- do_action( 'bp_activity_screen_friends' );
178
- bp_core_load_template( apply_filters( 'bp_activity_template_friends_activity', 'members/single/home' ) );
179
- }
180
-
181
- function bp_activity_screen_groups() {
182
- global $bp;
183
-
184
- if ( !bp_is_active( 'groups' ) )
185
- return false;
186
-
187
- if ( !is_site_admin() )
188
- $bp->is_item_admin = false;
189
-
190
- do_action( 'bp_activity_screen_groups' );
191
- bp_core_load_template( apply_filters( 'bp_activity_template_groups_activity', 'members/single/home' ) );
192
- }
193
-
194
- function bp_activity_screen_favorites() {
195
- global $bp;
196
-
197
- if ( !is_site_admin() )
198
- $bp->is_item_admin = false;
199
-
200
- do_action( 'bp_activity_screen_favorites' );
201
- bp_core_load_template( apply_filters( 'bp_activity_template_favorite_activity', 'members/single/home' ) );
202
- }
203
-
204
- function bp_activity_screen_mentions() {
205
- global $bp;
206
-
207
- if ( !is_site_admin() )
208
- $bp->is_item_admin = false;
209
-
210
- do_action( 'bp_activity_screen_mentions' );
211
- bp_core_load_template( apply_filters( 'bp_activity_template_mention_activity', 'members/single/home' ) );
212
- }
213
-
214
- function bp_activity_screen_single_activity_permalink() {
215
- global $bp;
216
-
217
- if ( !$bp->displayed_user->id || $bp->current_component != $bp->activity->slug )
218
- return false;
219
-
220
- if ( empty( $bp->current_action ) || !is_numeric( $bp->current_action ) )
221
- return false;
222
-
223
- /* Get the activity details */
224
- $activity = bp_activity_get_specific( array( 'activity_ids' => $bp->current_action ) );
225
-
226
- if ( !$activity = $activity['activities'][0] )
227
- bp_core_redirect( $bp->root_domain );
228
-
229
- $has_access = true;
230
- /* Redirect based on the type of activity */
231
- if ( $activity->component == $bp->groups->id ) {
232
- if ( !function_exists( 'groups_get_group' ) )
233
- bp_core_redirect( $bp->root_domain );
234
-
235
- if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) ) {
236
- /* Check to see if the group is not public, if so, check the user has access to see this activity */
237
- if ( 'public' != $group->status ) {
238
- if ( !groups_is_user_member( $bp->loggedin_user->id, $group->id ) )
239
- $has_access = false;
240
- }
241
- }
242
- }
243
-
244
- $has_access = apply_filters( 'bp_activity_permalink_access', $has_access, &$activity );
245
-
246
- do_action( 'bp_activity_screen_single_activity_permalink', $activity, $has_access );
247
-
248
- if ( !$has_access ) {
249
- bp_core_add_message( __( 'You do not have access to this activity.', 'buddypress' ), 'error' );
250
-
251
- if ( is_user_logged_in() )
252
- bp_core_redirect( $bp->loggedin_user->domain );
253
- else
254
- bp_core_redirect( site_url( 'wp-login.php?redirect_to=' . clean_url( $bp->root_domain . '/' . $bp->activity->slug . '/p/' . $bp->current_action ) ) );
255
- }
256
-
257
- bp_core_load_template( apply_filters( 'bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink' ) );
258
- }
259
- /* This screen is not attached to a nav item, so we need to add an action for it. */
260
- add_action( 'wp', 'bp_activity_screen_single_activity_permalink', 3 );
261
-
262
- function bp_activity_screen_notification_settings() {
263
- global $bp; ?>
264
- <table class="notification-settings" id="activity-notification-settings">
265
- <tr>
266
- <th class="icon"></th>
267
- <th class="title"><?php _e( 'Activity', 'buddypress' ) ?></th>
268
- <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>
269
- <th class="no"><?php _e( 'No', 'buddypress' )?></th>
270
- </tr>
271
-
272
- <tr>
273
- <td></td>
274
- <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>
275
- <td class="yes"><input type="radio" name="notifications[notification_activity_new_mention]" value="yes" <?php if ( !get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_mention' ) || 'yes' == get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_mention' ) ) { ?>checked="checked" <?php } ?>/></td>
276
- <td class="no"><input type="radio" name="notifications[notification_activity_new_mention]" value="no" <?php if ( 'no' == get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_mention' ) ) { ?>checked="checked" <?php } ?>/></td>
277
- </tr>
278
- <tr>
279
- <td></td>
280
- <td><?php printf( __( "A member replies to an update or comment you've posted", 'buddypress' ), $current_user->user_login ) ?></td>
281
- <td class="yes"><input type="radio" name="notifications[notification_activity_new_reply]" value="yes" <?php if ( !get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_reply' ) || 'yes' == get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_reply' ) ) { ?>checked="checked" <?php } ?>/></td>
282
- <td class="no"><input type="radio" name="notifications[notification_activity_new_reply]" value="no" <?php if ( 'no' == get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_reply' ) ) { ?>checked="checked" <?php } ?>/></td>
283
- </tr>
284
-
285
- <?php do_action( 'bp_activity_screen_notification_settings' ) ?>
286
- </table>
287
- <?php
288
- }
289
- add_action( 'bp_notification_settings', 'bp_activity_screen_notification_settings', 1 );
290
-
291
- /********************************************************************************
292
- * Action Functions
293
- *
294
- * Action functions are exactly the same as screen functions, however they do not
295
- * have a template screen associated with them. Usually they will send the user
296
- * back to the default screen after execution.
297
- */
298
-
299
- function bp_activity_action_permalink_router() {
300
- global $bp;
301
-
302
- if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'p' )
303
- return false;
304
-
305
- if ( empty( $bp->action_variables[0] ) || !is_numeric( $bp->action_variables[0] ) )
306
- return false;
307
-
308
- /* Get the activity details */
309
- $activity = bp_activity_get_specific( array( 'activity_ids' => $bp->action_variables[0] ) );
310
-
311
- if ( !$activity = $activity['activities'][0] )
312
- bp_core_redirect( $bp->root_domain );
313
-
314
- $redirect = false;
315
- /* Redirect based on the type of activity */
316
- if ( $activity->component == $bp->groups->id ) {
317
- if ( $activity->user_id )
318
- $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id . '/';
319
- else {
320
- if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) )
321
- $redirect = bp_get_group_permalink( $group ) . $bp->activity->slug . '/' . $activity->id . '/';
322
- }
323
- } else
324
- $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id;
325
-
326
- $redirect = apply_filters( 'bp_activity_permalink_redirect_url', $redirect, &$activity );
327
-
328
- if ( !$redirect )
329
- bp_core_redirect( $bp->root_domain );
330
-
331
- /* Redirect to the actual activity permalink page */
332
- bp_core_redirect( $redirect );
333
- }
334
- add_action( 'wp', 'bp_activity_action_permalink_router', 3 );
335
-
336
- function bp_activity_action_delete_activity() {
337
- global $bp;
338
-
339
- if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'delete' )
340
- return false;
341
-
342
- if ( empty( $bp->action_variables[0] ) || !is_numeric( $bp->action_variables[0] ) )
343
- return false;
344
-
345
- /* Check the nonce */
346
- check_admin_referer( 'bp_activity_delete_link' );
347
-
348
- $activity_id = $bp->action_variables[0];
349
- $activity = new BP_Activity_Activity( $activity_id );
350
-
351
- /* Check access */
352
- if ( !is_site_admin() && $activity->user_id != $bp->loggedin_user->id )
353
- return false;
354
-
355
- /* Call the action before the delete so plugins can still fetch information about it */
356
- do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id );
357
-
358
- /* Now delete the activity item */
359
- if ( bp_activity_delete( array( 'id' => $activity_id, 'user_id' => $activity->user_id ) ) )
360
- bp_core_add_message( __( 'Activity deleted', 'buddypress' ) );
361
- else
362
- bp_core_add_message( __( 'There was an error when deleting that activity', 'buddypress' ), 'error' );
363
-
364
- bp_core_redirect( wp_get_referer() );
365
- }
366
- add_action( 'wp', 'bp_activity_action_delete_activity', 3 );
367
-
368
- function bp_activity_action_post_update() {
369
- global $bp;
370
-
371
- if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'post' )
372
- return false;
373
-
374
- /* Check the nonce */
375
- check_admin_referer( 'post_update', '_wpnonce_post_update' );
376
-
377
- $content = apply_filters( 'bp_activity_post_update_content', $_POST['whats-new'] );
378
- $object = apply_filters( 'bp_activity_post_update_object', $_POST['whats-new-post-object'] );
379
- $item_id = apply_filters( 'bp_activity_post_update_item_id', $_POST['whats-new-post-in'] );
380
-
381
- if ( empty( $content ) ) {
382
- bp_core_add_message( __( 'Please enter some content to post.', 'buddypress' ), 'error' );
383
- bp_core_redirect( wp_get_referer() );
384
- }
385
-
386
- if ( !(int)$item_id ) {
387
- $activity_id = bp_activity_post_update( array( 'content' => $content ) );
388
-
389
- } else if ( 'groups' == $object && function_exists( 'groups_post_update' ) ) {
390
- if ( (int)$item_id ) {
391
- $activity_id = groups_post_update( array( 'content' => $content, 'group_id' => $item_id ) );
392
- }
393
- } else
394
- $activity_id = apply_filters( 'bp_activity_custom_update', $object, $item_id, $content );
395
-
396
- if ( !empty( $activity_id ) )
397
- bp_core_add_message( __( 'Update Posted!', 'buddypress' ) );
398
- else
399
- bp_core_add_message( __( 'There was an error when posting your update, please try again.', 'buddypress' ), 'error' );
400
-
401
- bp_core_redirect( wp_get_referer() );
402
- }
403
- add_action( 'wp', 'bp_activity_action_post_update', 3 );
404
-
405
- function bp_activity_action_post_comment() {
406
- global $bp;
407
-
408
- if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'reply' )
409
- return false;
410
-
411
- /* Check the nonce */
412
- check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );
413
-
414
- $activity_id = apply_filters( 'bp_activity_post_comment_activity_id', $_POST['comment_form_id'] );
415
- $content = apply_filters( 'bp_activity_post_comment_content', $_POST['ac_input_' . $activity_id] );
416
-
417
- if ( empty( $content ) ) {
418
- bp_core_add_message( __( 'Please do not leave the comment area blank.', 'buddypress' ), 'error' );
419
- bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
420
- }
421
-
422
- $comment_id = bp_activity_new_comment( array(
423
- 'content' => $content,
424
- 'activity_id' => $activity_id,
425
- 'parent_id' => $parent_id
426
- ));
427
-
428
- if ( !empty( $comment_id ) )
429
- bp_core_add_message( __( 'Reply Posted!', 'buddypress' ) );
430
- else
431
- bp_core_add_message( __( 'There was an error posting that reply, please try again.', 'buddypress' ), 'error' );
432
-
433
- bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
434
- }
435
- add_action( 'wp', 'bp_activity_action_post_comment', 3 );
436
-
437
- function bp_activity_action_mark_favorite() {
438
- global $bp;
439
-
440
- if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'favorite' )
441
- return false;
442
-
443
- /* Check the nonce */
444
- check_admin_referer( 'mark_favorite' );
445
-
446
- if ( bp_activity_add_user_favorite( $bp->action_variables[0] ) )
447
- bp_core_add_message( __( 'Activity marked as favorite.', 'buddypress' ) );
448
- else
449
- bp_core_add_message( __( 'There was an error marking that activity as a favorite, please try again.', 'buddypress' ), 'error' );
450
-
451
- bp_core_redirect( wp_get_referer() . '#activity-' . $bp->action_variables[0] );
452
- }
453
- add_action( 'wp', 'bp_activity_action_mark_favorite', 3 );
454
-
455
- function bp_activity_action_remove_favorite() {
456
- global $bp;
457
-
458
- if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'unfavorite' )
459
- return false;
460
-
461
- /* Check the nonce */
462
- check_admin_referer( 'unmark_favorite' );
463
-
464
- if ( bp_activity_remove_user_favorite( $bp->action_variables[0] ) )
465
- bp_core_add_message( __( 'Activity removed as favorite.', 'buddypress' ) );
466
- else
467
- bp_core_add_message( __( 'There was an error removing that activity as a favorite, please try again.', 'buddypress' ), 'error' );
468
-
469
- bp_core_redirect( wp_get_referer() . '#activity-' . $bp->action_variables[0] );
470
- }
471
- add_action( 'wp', 'bp_activity_action_remove_favorite', 3 );
472
-
473
- function bp_activity_action_sitewide_feed() {
474
- global $bp, $wp_query;
475
-
476
- if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'feed' || $bp->displayed_user->id || $bp->groups->current_group )
477
- return false;
478
-
479
- $wp_query->is_404 = false;
480
- status_header( 200 );
481
-
482
- include_once( 'bp-activity/feeds/bp-activity-sitewide-feed.php' );
483
- die;
484
- }
485
- add_action( 'wp', 'bp_activity_action_sitewide_feed', 3 );
486
-
487
- function bp_activity_action_personal_feed() {
488
- global $bp, $wp_query;
489
-
490
- if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'feed' )
491
- return false;
492
-
493
- $wp_query->is_404 = false;
494
- status_header( 200 );
495
-
496
- include_once( 'bp-activity/feeds/bp-activity-personal-feed.php' );
497
- die;
498
- }
499
- add_action( 'wp', 'bp_activity_action_personal_feed', 3 );
500
-
501
- function bp_activity_action_friends_feed() {
502
- global $bp, $wp_query;
503
-
504
- if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'friends' || $bp->action_variables[0] != 'feed' )
505
- return false;
506
-
507
- $wp_query->is_404 = false;
508
- status_header( 200 );
509
-
510
- include_once( 'bp-activity/feeds/bp-activity-friends-feed.php' );
511
- die;
512
- }
513
- add_action( 'wp', 'bp_activity_action_friends_feed', 3 );
514
-
515
- function bp_activity_action_my_groups_feed() {
516
- global $bp, $wp_query;
517
-
518
- if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'groups' || $bp->action_variables[0] != 'feed' )
519
- return false;
520
-
521
- $wp_query->is_404 = false;
522
- status_header( 200 );
523
-
524
- include_once( 'bp-activity/feeds/bp-activity-mygroups-feed.php' );
525
- die;
526
- }
527
- add_action( 'wp', 'bp_activity_action_my_groups_feed', 3 );
528
-
529
- function bp_activity_action_mentions_feed() {
530
- global $bp, $wp_query;
531
-
532
- if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'mentions' || $bp->action_variables[0] != 'feed' )
533
- return false;
534
-
535
- $wp_query->is_404 = false;
536
- status_header( 200 );
537
-
538
- include_once( 'bp-activity/feeds/bp-activity-mentions-feed.php' );
539
- die;
540
- }
541
- add_action( 'wp', 'bp_activity_action_mentions_feed', 3 );
542
-
543
- function bp_activity_action_favorites_feed() {
544
- global $bp, $wp_query;
545
-
546
- if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'favorites' || $bp->action_variables[0] != 'feed' )
547
- return false;
548
-
549
- $wp_query->is_404 = false;
550
- status_header( 200 );
551
-
552
- include_once( 'bp-activity/feeds/bp-activity-favorites-feed.php' );
553
- die;
554
- }
555
- add_action( 'wp', 'bp_activity_action_favorites_feed', 3 );
556
-
557
- /********************************************************************************
558
- * Business Functions
559
- *
560
- * Business functions are where all the magic happens in BuddyPress. They will
561
- * handle the actual saving or manipulation of information. Usually they will
562
- * hand off to a database class for data access, then return
563
- * true or false on success or failure.
564
- */
565
-
566
- function bp_activity_get( $args = '' ) {
567
- $defaults = array(
568
- 'max' => false, // Maximum number of results to return
569
- 'page' => 1, // page 1 without a per_page will result in no pagination.
570
- 'per_page' => false, // results per page
571
- 'sort' => 'DESC', // sort ASC or DESC
572
- 'display_comments' => false, // false for no comments. 'stream' for within stream display, 'threaded' for below each activity item
573
-
574
- 'search_terms' => false, // Pass search terms as a string
575
- 'show_hidden' => false, // Show activity items that are hidden site-wide?
576
-
577
- /**
578
- * Pass filters as an array -- all filter items can be multiple values comma separated:
579
- * array(
580
- * 'user_id' => false, // user_id to filter on
581
- * 'object' => false, // object to filter on e.g. groups, profile, status, friends
582
- * 'action' => false, // action to filter on e.g. activity_update, profile_updated
583
- * 'primary_id' => false, // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
584
- * 'secondary_id' => false, // secondary object ID to filter on e.g. a post_id
585
- * );
586
- */
587
- 'filter' => array()
588
- );
589
-
590
- $r = wp_parse_args( $args, $defaults );
591
- extract( $r, EXTR_SKIP );
592
-
593
- /* Attempt to return a cached copy of the first page of sitewide activity. */
594
- if ( 1 == (int)$page && empty( $max ) && empty( $search_terms ) && empty( $filter ) && 'DESC' == $sort ) {
595
- if ( !$activity = wp_cache_get( 'bp_activity_sitewide_front', 'bp' ) ) {
596
- $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden );
597
- wp_cache_set( 'bp_activity_sitewide_front', $activity, 'bp' );
598
- }
599
- } else
600
- $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden );
601
-
602
- return apply_filters( 'bp_activity_get', $activity, &$r );
603
- }
604
-
605
- function bp_activity_get_specific( $args = '' ) {
606
- $defaults = array(
607
- 'activity_ids' => false, // A single activity_id or array of IDs.
608
- 'page' => 1, // page 1 without a per_page will result in no pagination.
609
- 'per_page' => false, // results per page
610
- 'max' => false, // Maximum number of results to return
611
- 'sort' => 'DESC', // sort ASC or DESC
612
- 'display_comments' => false // true or false to display threaded comments for these specific activity items
613
- );
614
-
615
- $r = wp_parse_args( $args, $defaults );
616
- extract( $r, EXTR_SKIP );
617
-
618
- return apply_filters( 'bp_activity_get_specific', BP_Activity_Activity::get_specific( $activity_ids, $max, $page, $per_page, $sort, $display_comments ) );
619
- }
620
-
621
- function bp_activity_add( $args = '' ) {
622
- global $bp, $wpdb;
623
-
624
- $defaults = array(
625
- 'id' => false, // Pass an existing activity ID to update an existing entry.
626
-
627
- 'action' => '', // The activity action - e.g. "Jon Doe posted an update"
628
- 'content' => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!"
629
-
630
- 'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent
631
- 'type' => false, // The activity type e.g. activity_update, profile_updated
632
- 'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink)
633
-
634
- '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.
635
- 'item_id' => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id
636
- 'secondary_item_id' => false, // Optional: A second ID used to further filter e.g. a comment_id
637
- 'recorded_time' => gmdate( "Y-m-d H:i:s" ), // The GMT time that this activity was recorded
638
- 'hide_sitewide' => false // Should this be hidden on the sitewide activity stream?
639
- );
640
-
641
- $params = wp_parse_args( $args, $defaults );
642
- extract( $params, EXTR_SKIP );
643
-
644
- /* Make sure we are backwards compatible */
645
- if ( empty( $component ) && !empty( $component_name ) )
646
- $component = $component_name;
647
-
648
- if ( empty( $type ) && !empty( $component_action ) )
649
- $type = $component_action;
650
-
651
- $activity = new BP_Activity_Activity( $id );
652
-
653
- $activity->user_id = $user_id;
654
- $activity->component = $component;
655
- $activity->type = $type;
656
- $activity->action = $action;
657
- $activity->content = $content;
658
- $activity->primary_link = $primary_link;
659
- $activity->item_id = $item_id;
660
- $activity->secondary_item_id = $secondary_item_id;
661
- $activity->date_recorded = $recorded_time;
662
- $activity->hide_sitewide = $hide_sitewide;
663
-
664
- if ( !$activity->save() )
665
- return false;
666
-
667
- /* If this is an activity comment, rebuild the tree */
668
- if ( 'activity_comment' == $activity->type )
669
- BP_Activity_Activity::rebuild_activity_comment_tree( $activity->item_id );
670
-
671
- wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
672
- do_action( 'bp_activity_add', $params );
673
-
674
- return $activity->id;
675
- }
676
-
677
- function bp_activity_post_update( $args = '' ) {
678
- global $bp;
679
-
680
- $defaults = array(
681
- 'content' => false,
682
- 'user_id' => $bp->loggedin_user->id
683
- );
684
-
685
- $r = wp_parse_args( $args, $defaults );
686
- extract( $r, EXTR_SKIP );
687
-
688
- if ( empty( $content ) || !strlen( trim( $content ) ) )
689
- return false;
690
-
691
- /* Record this on the user's profile */
692
- $from_user_link = bp_core_get_userlink( $user_id );
693
- $activity_action = sprintf( __( '%s posted an update:', 'buddypress' ), $from_user_link );
694
- $activity_content = $content;
695
-
696
- $primary_link = bp_core_get_userlink( $user_id, false, true );
697
-
698
- /* Now write the values */
699
- $activity_id = bp_activity_add( array(
700
- 'user_id' => $user_id,
701
- 'action' => apply_filters( 'bp_activity_new_update_action', $activity_action ),
702
- 'content' => apply_filters( 'bp_activity_new_update_content', $activity_content ),
703
- 'primary_link' => apply_filters( 'bp_activity_new_update_primary_link', $primary_link ),
704
- 'component' => $bp->activity->id,
705
- 'type' => 'activity_update'
706
- ) );
707
-
708
- /* Add this update to the "latest update" usermeta so it can be fetched anywhere. */
709
- update_usermeta( $bp->loggedin_user->id, 'bp_latest_update', array( 'id' => $activity_id, 'content' => wp_filter_kses( $content ) ) );
710
-
711
- /* Require the notifications code so email notifications can be set on the 'bp_activity_posted_update' action. */
712
- require_once( BP_PLUGIN_DIR . '/bp-activity/bp-activity-notifications.php' );
713
-
714
- do_action( 'bp_activity_posted_update', $content, $user_id, $activity_id );
715
-
716
- return $activity_id;
717
- }
718
-
719
- function bp_activity_new_comment( $args = '' ) {
720
- global $bp;
721
-
722
- $defaults = array(
723
- 'id' => false,
724
- 'content' => false,
725
- 'user_id' => $bp->loggedin_user->id,
726
- 'activity_id' => false, // ID of the root activity item
727
- 'parent_id' => false // ID of a parent comment (optional)
728
- );
729
-
730
- $params = wp_parse_args( $args, $defaults );
731
- extract( $params, EXTR_SKIP );
732
-
733
- if ( empty($content) || empty($user_id) || empty($activity_id) )
734
- return false;
735
-
736
- if ( empty($parent_id) )
737
- $parent_id = $activity_id;
738
-
739
- /* Check to see if the parent activity is hidden, and if so, hide this comment publically. */
740
- $activity = new BP_Activity_Activity( $activity_id );
741
- $is_hidden = ( (int)$activity->hide_sitewide ) ? 1 : 0;
742
-
743
- /* Insert the activity comment */
744
- $comment_id = bp_activity_add( array(
745
- 'id' => $id,
746
- 'action' => apply_filters( 'bp_activity_comment_action', sprintf( __( '%s posted a new activity comment:', 'buddypress' ), bp_core_get_userlink( $user_id ) ) ),
747
- 'content' => apply_filters( 'bp_activity_comment_content', $content ),
748
- 'component' => $bp->activity->id,
749
- 'type' => 'activity_comment',
750
- 'user_id' => $user_id,
751
- 'item_id' => $activity_id,
752
- 'secondary_item_id' => $parent_id,
753
- 'hide_sitewide' => $is_hidden
754
- ) );
755
-
756
- /* Send an email notification if settings allow */
757
- require_once( BP_PLUGIN_DIR . '/bp-activity/bp-activity-notifications.php' );
758
- bp_activity_new_comment_notification( $comment_id, $user_id, $params );
759
-
760
- /* Clear the comment cache for this activity */
761
- wp_cache_delete( 'bp_activity_comments_' . $parent_id );
762
-
763
- do_action( 'bp_activity_comment_posted', $comment_id, $params );
764
-
765
- return $comment_id;
766
- }
767
-
768
- /**
769
- * bp_activity_get_activity_id()
770
- *
771
- * Fetch the activity_id for an existing activity entry in the DB.
772
- *
773
- * @package BuddyPress Activity
774
- */
775
- function bp_activity_get_activity_id( $args = '' ) {
776
- $defaults = array(
777
- 'user_id' => false,
778
- 'component' => false,
779
- 'type' => false,
780
- 'item_id' => false,
781
- 'secondary_item_id' => false,
782
- 'action' => false,
783
- 'content' => false,
784
- 'date_recorded' => false,
785
- );
786
-
787
- $r = wp_parse_args( $args, $defaults );
788
- extract( $r, EXTR_SKIP );
789
-
790
- 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 ) );
791
- }
792
-
793
- /***
794
- * Deleting Activity
795
- *
796
- * If you're looking to hook into one action that provides the ID(s) of
797
- * the activity/activities deleted, then use:
798
- *
799
- * add_action( 'bp_activity_deleted_activities', 'my_function' );
800
- *
801
- * The action passes one parameter that is a single activity ID or an
802
- * array of activity IDs depending on the number deleted.
803
- *
804
- * If you are deleting an activity comment please use bp_activity_delete_comment();
805
- */
806
-
807
- function bp_activity_delete( $args = '' ) {
808
- global $bp;
809
-
810
- /* Pass one or more the of following variables to delete by those variables */
811
- $defaults = array(
812
- 'id' => false,
813
- 'action' => false,
814
- 'content' => false,
815
- 'component' => false,
816
- 'type' => false,
817
- 'primary_link' => false,
818
- 'user_id' => false,
819
- 'item_id' => false,
820
- 'secondary_item_id' => false,
821
- 'date_recorded' => false,
822
- 'hide_sitewide' => false
823
- );
824
-
825
- $args = wp_parse_args( $args, $defaults );
826
-
827
- if ( !$activity_ids_deleted = BP_Activity_Activity::delete( $args ) )
828
- return false;
829
-
830
- /* Check if the user's latest update has been deleted */
831
- if ( empty( $args['user_id'] ) )
832
- $user_id = $bp->loggedin_user->id;
833
- else
834
- $user_id = $args['user_id'];
835
-
836
- $latest_update = get_usermeta( $user_id, 'bp_latest_update' );
837
- if ( !empty( $latest_update ) ) {
838
- if ( in_array( (int)$latest_update['id'], (array)$activity_ids_deleted ) )
839
- delete_usermeta( $user_id, 'bp_latest_update' );
840
- }
841
-
842
- do_action( 'bp_activity_delete', $args );
843
- do_action( 'bp_activity_deleted_activities', $activity_ids_deleted );
844
-
845
- wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
846
-
847
- return true;
848
- }
849
- /* The following functions have been deprecated in place of bp_activity_delete() */
850
- function bp_activity_delete_by_item_id( $args = '' ) {
851
- global $bp;
852
-
853
- $defaults = array( 'item_id' => false, 'component' => false, 'type' => false, 'user_id' => false, 'secondary_item_id' => false );
854
- $r = wp_parse_args( $args, $defaults );
855
- extract( $r, EXTR_SKIP );
856
-
857
- return bp_activity_delete( array( 'item_id' => $item_id, 'component' => $component, 'type' => $type, 'user_id' => $user_id, 'secondary_item_id' => $secondary_item_id ) );
858
- }
859
-
860
- function bp_activity_delete_by_activity_id( $activity_id ) {
861
- return bp_activity_delete( array( 'id' => $activity_id ) );
862
- }
863
-
864
- function bp_activity_delete_by_content( $user_id, $content, $component, $type ) {
865
- return bp_activity_delete( array( 'user_id' => $user_id, 'content' => $content, 'component' => $component, 'type' => $type ) );
866
- }
867
-
868
- function bp_activity_delete_for_user_by_component( $user_id, $component ) {
869
- return bp_activity_delete( array( 'user_id' => $user_id, 'component' => $component ) );
870
- }
871
- /* End deprecation */
872
-
873
- function bp_activity_delete_comment( $activity_id, $comment_id ) {
874
- /***
875
- * You may want to hook into this filter if you want to override this function and
876
- * handle the deletion of child comments differently. Make sure you return false.
877
- */
878
- if ( !apply_filters( 'bp_activity_delete_comment_pre', true, $activity_id, $comment_id ) )
879
- return false;
880
-
881
- /* Delete any children of this comment. */
882
- bp_activity_delete_children( $activity_id, $comment_id );
883
-
884
- /* Delete the actual comment */
885
- if ( !bp_activity_delete( array( 'id' => $comment_id, 'type' => 'activity_comment' ) ) )
886
- return false;
887
-
888
- /* Recalculate the comment tree */
889
- BP_Activity_Activity::rebuild_activity_comment_tree( $activity_id );
890
-
891
- do_action( 'bp_activity_delete_comment', $activity_id, $comment_id );
892
-
893
- return true;
894
- }
895
- function bp_activity_delete_children( $activity_id, $comment_id) {
896
- /* Recursively delete all children of this comment. */
897
- if ( $children = BP_Activity_Activity::get_child_comments( $comment_id ) ) {
898
- foreach( (array)$children as $child )
899
- bp_activity_delete_children( $activity_id, $child->id );
900
- }
901
- bp_activity_delete( array( 'secondary_item_id' => $comment_id, 'type' => 'activity_comment', 'item_id' => $activity_id ) );
902
- }
903
-
904
- function bp_activity_get_permalink( $activity_id, $activity_obj = false ) {
905
- global $bp;
906
-
907
- if ( !$activity_obj )
908
- $activity_obj = new BP_Activity_Activity( $activity_id );
909
-
910
- 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 )
911
- $link = $activity_obj->primary_link;
912
- else {
913
- if ( 'activity_comment' == $activity_obj->type )
914
- $link = $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activity_obj->item_id . '/';
915
- else
916
- $link = $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activity_obj->id . '/';
917
- }
918
-
919
- return apply_filters( 'bp_activity_get_permalink', $link );
920
- }
921
-
922
- function bp_activity_hide_user_activity( $user_id ) {
923
- return BP_Activity_Activity::hide_all_for_user( $user_id );
924
- }
925
-
926
- /**
927
- * bp_activity_thumbnail_content_images()
928
- *
929
- * Take content, remove all images and replace them with one thumbnail image.
930
- *
931
- * @package BuddyPress Activity
932
- * @param $content str - The content to work with
933
- * @return $content str - The content with images stripped and replaced with a single thumb.
934
- */
935
- function bp_activity_thumbnail_content_images( $content ) {
936
- preg_match_all( '/<img[^>]*>/Ui', $content, $matches );
937
- $content = preg_replace('/<img[^>]*>/Ui', '', $content );
938
-
939
- if ( !empty( $matches ) ) {
940
- /* Get the SRC value */
941
- preg_match( '/<img.*?(src\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $src );
942
-
943
- /* Get the width and height */
944
- preg_match( '/<img.*?(height\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $height );
945
- preg_match( '/<img.*?(width\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $width );
946
-
947
- if ( !empty( $src ) ) {
948
- $src = substr( substr( str_replace( 'src=', '', $src[1] ), 0, -1 ), 1 );
949
- $height = substr( substr( str_replace( 'height=', '', $height[1] ), 0, -1 ), 1 );
950
- $width = substr( substr( str_replace( 'width=', '', $width[1] ), 0, -1 ), 1 );
951
-
952
- if ( empty( $width ) || empty( $height ) ) {
953
- $width = 100;
954
- $height = 100;
955
- }
956
-
957
- $ratio = (int)$width / (int)$height;
958
- $new_height = 100;
959
- $new_width = $new_height * $ratio;
960
-
961
- $content = '<img src="' . esc_attr( $src) . '" width="' . $new_width . '" height="' . $new_height . '" alt="' . __( 'Thumbnail', 'buddypress' ) . '" class="align-left thumbnail" />' . $content;
962
- }
963
- }
964
-
965
- return apply_filters( 'bp_activity_thumbnail_content_images', $content, $matches );
966
- }
967
-
968
- function bp_activity_set_action( $component_id, $key, $value ) {
969
- global $bp;
970
-
971
- if ( empty( $component_id ) || empty( $key ) || empty( $value ) )
972
- return false;
973
-
974
- $bp->activity->actions->{$component_id}->{$key} = apply_filters( 'bp_activity_set_action', array(
975
- 'key' => $key,
976
- 'value' => $value
977
- ), $component_id, $key, $value );
978
- }
979
-
980
- function bp_activity_get_action( $component_id, $key ) {
981
- global $bp;
982
-
983
- if ( empty( $component_id ) || empty( $key ) )
984
- return false;
985
-
986
- return apply_filters( 'bp_activity_get_action', $bp->activity->actions->{$component_id}->{$key}, $component_id, $key );
987
- }
988
-
989
- function bp_activity_get_user_favorites( $user_id ) {
990
- $my_favs = maybe_unserialize( get_usermeta( $user_id, 'bp_favorite_activities' ) );
991
- $existing_favs = bp_activity_get_specific( array( 'activity_ids' => $my_favs ) );
992
-
993
- foreach( (array)$existing_favs['activities'] as $fav )
994
- $new_favs[] = $fav->id;
995
-
996
- $new_favs = array_unique( (array)$new_favs );
997
- update_usermeta( $user_id, 'bp_favorite_activities', $new_favs );
998
-
999
- return apply_filters( 'bp_activity_get_user_favorites', $new_favs );
1000
- }
1001
-
1002
- function bp_activity_add_user_favorite( $activity_id, $user_id = false ) {
1003
- global $bp;
1004
-
1005
- if ( !$user_id )
1006
- $user_id = $bp->loggedin_user->id;
1007
-
1008
- /* Update the user's personal favorites */
1009
- $my_favs = maybe_unserialize( get_usermeta( $bp->loggedin_user->id, 'bp_favorite_activities' ) );
1010
- $my_favs[] = $activity_id;
1011
-
1012
- /* Update the total number of users who have favorited this activity */
1013
- $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' );
1014
-
1015
- if ( !empty( $fav_count ) )
1016
- $fav_count = (int)$fav_count + 1;
1017
- else
1018
- $fav_count = 1;
1019
-
1020
- update_usermeta( $bp->loggedin_user->id, 'bp_favorite_activities', $my_favs );
1021
- bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count );
1022
-
1023
- do_action( 'bp_activity_add_user_favorite', $activity_id, $user_id );
1024
-
1025
- return true;
1026
- }
1027
-
1028
- function bp_activity_remove_user_favorite( $activity_id, $user_id = false ) {
1029
- global $bp;
1030
-
1031
- if ( !$user_id )
1032
- $user_id = $bp->loggedin_user->id;
1033
-
1034
- /* Remove the fav from the user's favs */
1035
- $my_favs = maybe_unserialize( get_usermeta( $user_id, 'bp_favorite_activities' ) );
1036
- $my_favs = array_flip( (array) $my_favs );
1037
- unset( $my_favs[$activity_id] );
1038
- $my_favs = array_unique( array_flip( $my_favs ) );
1039
-
1040
- /* Update the total number of users who have favorited this activity */
1041
- $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' );
1042
-
1043
- if ( !empty( $fav_count ) ) {
1044
- $fav_count = (int)$fav_count - 1;
1045
- bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count );
1046
- }
1047
-
1048
- update_usermeta( $user_id, 'bp_favorite_activities', $my_favs );
1049
-
1050
- do_action( 'bp_activity_remove_user_favorite', $activity_id, $user_id );
1051
-
1052
- return true;
1053
- }
1054
-
1055
- function bp_activity_check_exists_by_content( $content ) {
1056
- return apply_filters( 'bp_activity_check_exists_by_content', BP_Activity_Activity::check_exists_by_content( $content ) );
1057
- }
1058
-
1059
- function bp_activity_get_last_updated() {
1060
- return apply_filters( 'bp_activity_get_last_updated', BP_Activity_Activity::get_last_updated() );
1061
- }
1062
-
1063
- function bp_activity_total_favorites_for_user( $user_id = false ) {
1064
- global $bp;
1065
-
1066
- if ( !$user_id )
1067
- $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
1068
-
1069
- return BP_Activity_Activity::total_favorite_count( $user_id );
1070
- }
1071
-
1072
- /********************************************************************************
1073
- * Activity Meta Functions
1074
- *
1075
- * Meta functions allow you to store extra data for a particular item.
1076
- */
1077
-
1078
- function bp_activity_delete_meta( $activity_id, $meta_key = false, $meta_value = false ) {
1079
- global $wpdb, $bp;
1080
-
1081
- if ( !is_numeric( $activity_id ) )
1082
- return false;
1083
-
1084
- $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
1085
-
1086
- if ( is_array( $meta_value ) || is_object( $meta_value ) )
1087
- $meta_value = serialize( $meta_value );
1088
-
1089
- $meta_value = trim( $meta_value );
1090
-
1091
- if ( !$meta_key ) {
1092
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d", $activity_id ) );
1093
- } else if ( $meta_value ) {
1094
- $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 ) );
1095
- } else {
1096
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s", $activity_id, $meta_key ) );
1097
- }
1098
-
1099
- wp_cache_delete( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, 'bp' );
1100
-
1101
- return true;
1102
- }
1103
-
1104
- function bp_activity_get_meta( $activity_id, $meta_key = '' ) {
1105
- global $wpdb, $bp;
1106
-
1107
- $activity_id = (int)$activity_id;
1108
-
1109
- if ( !$activity_id )
1110
- return false;
1111
-
1112
- if ( !empty($meta_key) ) {
1113
- $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
1114
-
1115
- if ( !$metas = wp_cache_get( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, 'bp' ) ) {
1116
- $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 ) );
1117
- wp_cache_set( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, $metas, 'bp' );
1118
- }
1119
- } else
1120
- $metas = $wpdb->get_col( $wpdb->prepare( "SELECT meta_value FROM {$bp->activity->table_name_meta} WHERE activity_id = %d", $activity_id ) );
1121
-
1122
- if ( empty($metas) )
1123
- return false;
1124
-
1125
- $metas = array_map( 'maybe_unserialize', (array)$metas );
1126
-
1127
- if ( 1 == count($metas) )
1128
- return $metas[0];
1129
- else
1130
- return $metas;
1131
- }
1132
-
1133
- function bp_activity_update_meta( $activity_id, $meta_key, $meta_value ) {
1134
- global $wpdb, $bp;
1135
-
1136
- if ( !is_numeric( $activity_id ) )
1137
- return false;
1138
-
1139
- $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
1140
-
1141
- if ( is_string( $meta_value ) )
1142
- $meta_value = stripslashes( $wpdb->escape( $meta_value ) );
1143
-
1144
- $meta_value = maybe_serialize( $meta_value );
1145
-
1146
- if ( empty( $meta_value ) ) {
1147
- return bp_activity_delete_meta( $activity_id, $meta_key );
1148
- }
1149
-
1150
- $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 ) );
1151
-
1152
- if ( !$cur ) {
1153
- $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 ) );
1154
- } else if ( $cur->meta_value != $meta_value ) {
1155
- $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 ) );
1156
- } else {
1157
- return false;
1158
- }
1159
-
1160
- wp_cache_set( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, $meta_value, 'bp' );
1161
-
1162
- return true;
1163
- }
1164
-
1165
- function bp_activity_remove_data( $user_id ) {
1166
- // Clear the user's activity from the sitewide stream and clear their activity tables
1167
- bp_activity_delete( array( 'user_id' => $user_id ) );
1168
-
1169
- // Remove any usermeta
1170
- delete_usermeta( $user_id, 'bp_latest_update' );
1171
- delete_usermeta( $user_id, 'bp_favorite_activities' );
1172
-
1173
- do_action( 'bp_activity_remove_data', $user_id );
1174
- }
1175
- add_action( 'wpmu_delete_user', 'bp_activity_remove_data' );
1176
- add_action( 'delete_user', 'bp_activity_remove_data' );
1177
- add_action( 'make_spam_user', 'bp_activity_remove_data' );
1178
-
1179
-
1180
- /********************************************************************************
1181
- * Custom Actions
1182
- *
1183
- * Functions to set up custom BuddyPress actions that all other components can
1184
- * hook in to.
1185
- */
1186
-
1187
- /* Allow core components and dependent plugins to register activity actions */
1188
- function bp_register_activity_actions() {
1189
- do_action( 'bp_register_activity_actions' );
1190
- }
1191
- add_action( 'plugins_loaded', 'bp_register_activity_actions' );
1192
-
1193
-
 
 
 
 
1194
  ?>
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/upgrade-functions.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, $wpdb, $current_blog;
77
+
78
+ /* Internal identifier */
79
+ $bp->activity->id = 'activity';
80
+
81
+ $bp->activity->table_name = $wpdb->base_prefix . 'bp_activity';
82
+ $bp->activity->table_name_meta = $wpdb->base_prefix . 'bp_activity_meta';
83
+ $bp->activity->slug = BP_ACTIVITY_SLUG;
84
+ $bp->activity->format_notification_function = 'bp_activity_format_notifications';
85
+
86
+ /* Register this in the active components array */
87
+ $bp->active_components[$bp->activity->slug] = $bp->activity->id;
88
+
89
+ do_action( 'bp_activity_setup_globals' );
90
+ }
91
+ add_action( 'bp_setup_globals', 'bp_activity_setup_globals' );
92
+
93
+ function bp_activity_check_installed() {
94
+ global $wpdb, $bp;
95
+
96
+ if ( get_site_option( 'bp-activity-db-version' ) < BP_ACTIVITY_DB_VERSION )
97
+ bp_activity_install();
98
+ }
99
+ add_action( 'admin_menu', 'bp_activity_check_installed' );
100
+
101
+ function bp_activity_setup_root_component() {
102
+ /* Register 'activity' as a root component (for RSS feed use) */
103
+ bp_core_add_root_component( BP_ACTIVITY_SLUG );
104
+ }
105
+ add_action( 'bp_setup_root_components', 'bp_activity_setup_root_component' );
106
+
107
+ function bp_activity_setup_nav() {
108
+ global $bp;
109
+
110
+ /* Add 'Activity' to the main navigation */
111
+ 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 ) );
112
+
113
+ $user_domain = ( !empty( $bp->displayed_user->domain ) ) ? $bp->displayed_user->domain : $bp->loggedin_user->domain;
114
+ $user_login = ( !empty( $bp->displayed_user->userdata->user_login ) ) ? $bp->displayed_user->userdata->user_login : $bp->loggedin_user->userdata->user_login;
115
+ $activity_link = $user_domain . $bp->activity->slug . '/';
116
+
117
+ /* Add the subnav items to the activity nav item if we are using a theme that supports this */
118
+ 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 ) );
119
+
120
+ if ( bp_is_active( 'friends' ) )
121
+ 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' ) );
122
+
123
+ if ( bp_is_active( 'groups' ) )
124
+ 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' ) );
125
+
126
+ 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' ) );
127
+ 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' ) );
128
+
129
+ if ( $bp->current_component == $bp->activity->slug ) {
130
+ if ( bp_is_my_profile() ) {
131
+ $bp->bp_options_title = __( 'My Activity', 'buddypress' );
132
+ } else {
133
+ $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
134
+ $bp->bp_options_title = $bp->displayed_user->fullname;
135
+ }
136
+ }
137
+
138
+ do_action( 'bp_activity_setup_nav' );
139
+ }
140
+ add_action( 'bp_setup_nav', 'bp_activity_setup_nav' );
141
+
142
+ function bp_activity_directory_activity_setup() {
143
+ global $bp;
144
+
145
+ if ( $bp->current_component == $bp->activity->slug && empty( $bp->current_action ) ) {
146
+ $bp->is_directory = true;
147
+
148
+ do_action( 'bp_activity_directory_activity_setup' );
149
+ bp_core_load_template( apply_filters( 'bp_activity_directory_activity_setup', 'activity/index' ) );
150
+ }
151
+ }
152
+ add_action( 'wp', 'bp_activity_directory_activity_setup', 2 );
153
+
154
+
155
+ /********************************************************************************
156
+ * Screen Functions
157
+ *
158
+ * Screen functions are the controllers of BuddyPress. They will execute when their
159
+ * specific URL is caught. They will first save or manipulate data using business
160
+ * functions, then pass on the user to a template file.
161
+ */
162
+
163
+ function bp_activity_screen_my_activity() {
164
+ do_action( 'bp_activity_screen_my_activity' );
165
+ bp_core_load_template( apply_filters( 'bp_activity_template_my_activity', 'members/single/home' ) );
166
+ }
167
+
168
+ function bp_activity_screen_friends() {
169
+ global $bp;
170
+
171
+ if ( !bp_is_active( 'friends' ) )
172
+ return false;
173
+
174
+ if ( !is_site_admin() )
175
+ $bp->is_item_admin = false;
176
+
177
+ do_action( 'bp_activity_screen_friends' );
178
+ bp_core_load_template( apply_filters( 'bp_activity_template_friends_activity', 'members/single/home' ) );
179
+ }
180
+
181
+ function bp_activity_screen_groups() {
182
+ global $bp;
183
+
184
+ if ( !bp_is_active( 'groups' ) )
185
+ return false;
186
+
187
+ if ( !is_site_admin() )
188
+ $bp->is_item_admin = false;
189
+
190
+ do_action( 'bp_activity_screen_groups' );
191
+ bp_core_load_template( apply_filters( 'bp_activity_template_groups_activity', 'members/single/home' ) );
192
+ }
193
+
194
+ function bp_activity_screen_favorites() {
195
+ global $bp;
196
+
197
+ if ( !is_site_admin() )
198
+ $bp->is_item_admin = false;
199
+
200
+ do_action( 'bp_activity_screen_favorites' );
201
+ bp_core_load_template( apply_filters( 'bp_activity_template_favorite_activity', 'members/single/home' ) );
202
+ }
203
+
204
+ function bp_activity_screen_mentions() {
205
+ global $bp;
206
+
207
+ if ( !is_site_admin() )
208
+ $bp->is_item_admin = false;
209
+
210
+ do_action( 'bp_activity_screen_mentions' );
211
+ bp_core_load_template( apply_filters( 'bp_activity_template_mention_activity', 'members/single/home' ) );
212
+ }
213
+
214
+ function bp_activity_screen_single_activity_permalink() {
215
+ global $bp;
216
+
217
+ if ( !$bp->displayed_user->id || $bp->current_component != $bp->activity->slug )
218
+ return false;
219
+
220
+ if ( empty( $bp->current_action ) || !is_numeric( $bp->current_action ) )
221
+ return false;
222
+
223
+ /* Get the activity details */
224
+ $activity = bp_activity_get_specific( array( 'activity_ids' => $bp->current_action ) );
225
+
226
+ if ( !$activity = $activity['activities'][0] )
227
+ bp_core_redirect( $bp->root_domain );
228
+
229
+ $has_access = true;
230
+ /* Redirect based on the type of activity */
231
+ if ( $activity->component == $bp->groups->id ) {
232
+ if ( !function_exists( 'groups_get_group' ) )
233
+ bp_core_redirect( $bp->root_domain );
234
+
235
+ if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) ) {
236
+ /* Check to see if the group is not public, if so, check the user has access to see this activity */
237
+ if ( 'public' != $group->status ) {
238
+ if ( !groups_is_user_member( $bp->loggedin_user->id, $group->id ) )
239
+ $has_access = false;
240
+ }
241
+ }
242
+ }
243
+
244
+ $has_access = apply_filters( 'bp_activity_permalink_access', $has_access, &$activity );
245
+
246
+ do_action( 'bp_activity_screen_single_activity_permalink', $activity, $has_access );
247
+
248
+ if ( !$has_access ) {
249
+ bp_core_add_message( __( 'You do not have access to this activity.', 'buddypress' ), 'error' );
250
+
251
+ if ( is_user_logged_in() )
252
+ bp_core_redirect( $bp->loggedin_user->domain );
253
+ else
254
+ bp_core_redirect( site_url( 'wp-login.php?redirect_to=' . clean_url( $bp->root_domain . '/' . $bp->activity->slug . '/p/' . $bp->current_action ) ) );
255
+ }
256
+
257
+ bp_core_load_template( apply_filters( 'bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink' ) );
258
+ }
259
+ /* This screen is not attached to a nav item, so we need to add an action for it. */
260
+ add_action( 'wp', 'bp_activity_screen_single_activity_permalink', 3 );
261
+
262
+ function bp_activity_screen_notification_settings() {
263
+ global $bp; ?>
264
+ <table class="notification-settings zebra" id="activity-notification-settings">
265
+ <thead>
266
+ <tr>
267
+ <th class="icon"></th>
268
+ <th class="title"><?php _e( 'Activity', 'buddypress' ) ?></th>
269
+ <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>
270
+ <th class="no"><?php _e( 'No', 'buddypress' )?></th>
271
+ </tr>
272
+ </thead>
273
+
274
+ <tbody>
275
+ <tr>
276
+ <td></td>
277
+ <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>
278
+ <td class="yes"><input type="radio" name="notifications[notification_activity_new_mention]" value="yes" <?php if ( !get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_mention' ) || 'yes' == get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_mention' ) ) { ?>checked="checked" <?php } ?>/></td>
279
+ <td class="no"><input type="radio" name="notifications[notification_activity_new_mention]" value="no" <?php if ( 'no' == get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_mention' ) ) { ?>checked="checked" <?php } ?>/></td>
280
+ </tr>
281
+ <tr>
282
+ <td></td>
283
+ <td><?php printf( __( "A member replies to an update or comment you've posted", 'buddypress' ), $current_user->user_login ) ?></td>
284
+ <td class="yes"><input type="radio" name="notifications[notification_activity_new_reply]" value="yes" <?php if ( !get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_reply' ) || 'yes' == get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_reply' ) ) { ?>checked="checked" <?php } ?>/></td>
285
+ <td class="no"><input type="radio" name="notifications[notification_activity_new_reply]" value="no" <?php if ( 'no' == get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_reply' ) ) { ?>checked="checked" <?php } ?>/></td>
286
+ </tr>
287
+
288
+ <?php do_action( 'bp_activity_screen_notification_settings' ) ?>
289
+ </tbody>
290
+ </table>
291
+ <?php
292
+ }
293
+ add_action( 'bp_notification_settings', 'bp_activity_screen_notification_settings', 1 );
294
+
295
+ /********************************************************************************
296
+ * Action Functions
297
+ *
298
+ * Action functions are exactly the same as screen functions, however they do not
299
+ * have a template screen associated with them. Usually they will send the user
300
+ * back to the default screen after execution.
301
+ */
302
+
303
+ function bp_activity_action_permalink_router() {
304
+ global $bp;
305
+
306
+ if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'p' )
307
+ return false;
308
+
309
+ if ( empty( $bp->action_variables[0] ) || !is_numeric( $bp->action_variables[0] ) )
310
+ return false;
311
+
312
+ /* Get the activity details */
313
+ $activity = bp_activity_get_specific( array( 'activity_ids' => $bp->action_variables[0] ) );
314
+
315
+ if ( !$activity = $activity['activities'][0] )
316
+ bp_core_redirect( $bp->root_domain );
317
+
318
+ $redirect = false;
319
+ /* Redirect based on the type of activity */
320
+ if ( $activity->component == $bp->groups->id ) {
321
+ if ( $activity->user_id )
322
+ $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id . '/';
323
+ else {
324
+ if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) )
325
+ $redirect = bp_get_group_permalink( $group ) . $bp->activity->slug . '/' . $activity->id . '/';
326
+ }
327
+ } else
328
+ $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id;
329
+
330
+ $redirect = apply_filters( 'bp_activity_permalink_redirect_url', $redirect, &$activity );
331
+
332
+ if ( !$redirect )
333
+ bp_core_redirect( $bp->root_domain );
334
+
335
+ /* Redirect to the actual activity permalink page */
336
+ bp_core_redirect( $redirect );
337
+ }
338
+ add_action( 'wp', 'bp_activity_action_permalink_router', 3 );
339
+
340
+ function bp_activity_action_delete_activity() {
341
+ global $bp;
342
+
343
+ if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'delete' )
344
+ return false;
345
+
346
+ if ( empty( $bp->action_variables[0] ) || !is_numeric( $bp->action_variables[0] ) )
347
+ return false;
348
+
349
+ /* Check the nonce */
350
+ check_admin_referer( 'bp_activity_delete_link' );
351
+
352
+ $activity_id = $bp->action_variables[0];
353
+ $activity = new BP_Activity_Activity( $activity_id );
354
+
355
+ /* Check access */
356
+ if ( !is_site_admin() && $activity->user_id != $bp->loggedin_user->id )
357
+ return false;
358
+
359
+ /* Call the action before the delete so plugins can still fetch information about it */
360
+ do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id );
361
+
362
+ /* Now delete the activity item */
363
+ if ( bp_activity_delete( array( 'id' => $activity_id, 'user_id' => $activity->user_id ) ) )
364
+ bp_core_add_message( __( 'Activity deleted', 'buddypress' ) );
365
+ else
366
+ bp_core_add_message( __( 'There was an error when deleting that activity', 'buddypress' ), 'error' );
367
+
368
+ bp_core_redirect( wp_get_referer() );
369
+ }
370
+ add_action( 'wp', 'bp_activity_action_delete_activity', 3 );
371
+
372
+ function bp_activity_action_post_update() {
373
+ global $bp;
374
+
375
+ if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'post' )
376
+ return false;
377
+
378
+ /* Check the nonce */
379
+ check_admin_referer( 'post_update', '_wpnonce_post_update' );
380
+
381
+ $content = apply_filters( 'bp_activity_post_update_content', $_POST['whats-new'] );
382
+ $object = apply_filters( 'bp_activity_post_update_object', $_POST['whats-new-post-object'] );
383
+ $item_id = apply_filters( 'bp_activity_post_update_item_id', $_POST['whats-new-post-in'] );
384
+
385
+ if ( empty( $content ) ) {
386
+ bp_core_add_message( __( 'Please enter some content to post.', 'buddypress' ), 'error' );
387
+ bp_core_redirect( wp_get_referer() );
388
+ }
389
+
390
+ if ( !(int)$item_id ) {
391
+ $activity_id = bp_activity_post_update( array( 'content' => $content ) );
392
+
393
+ } else if ( 'groups' == $object && function_exists( 'groups_post_update' ) ) {
394
+ if ( (int)$item_id ) {
395
+ $activity_id = groups_post_update( array( 'content' => $content, 'group_id' => $item_id ) );
396
+ }
397
+ } else
398
+ $activity_id = apply_filters( 'bp_activity_custom_update', $object, $item_id, $content );
399
+
400
+ if ( !empty( $activity_id ) )
401
+ bp_core_add_message( __( 'Update Posted!', 'buddypress' ) );
402
+ else
403
+ bp_core_add_message( __( 'There was an error when posting your update, please try again.', 'buddypress' ), 'error' );
404
+
405
+ bp_core_redirect( wp_get_referer() );
406
+ }
407
+ add_action( 'wp', 'bp_activity_action_post_update', 3 );
408
+
409
+ function bp_activity_action_post_comment() {
410
+ global $bp;
411
+
412
+ if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'reply' )
413
+ return false;
414
+
415
+ /* Check the nonce */
416
+ check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );
417
+
418
+ $activity_id = apply_filters( 'bp_activity_post_comment_activity_id', $_POST['comment_form_id'] );
419
+ $content = apply_filters( 'bp_activity_post_comment_content', $_POST['ac_input_' . $activity_id] );
420
+
421
+ if ( empty( $content ) ) {
422
+ bp_core_add_message( __( 'Please do not leave the comment area blank.', 'buddypress' ), 'error' );
423
+ bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
424
+ }
425
+
426
+ $comment_id = bp_activity_new_comment( array(
427
+ 'content' => $content,
428
+ 'activity_id' => $activity_id,
429
+ 'parent_id' => $parent_id
430
+ ));
431
+
432
+ if ( !empty( $comment_id ) )
433
+ bp_core_add_message( __( 'Reply Posted!', 'buddypress' ) );
434
+ else
435
+ bp_core_add_message( __( 'There was an error posting that reply, please try again.', 'buddypress' ), 'error' );
436
+
437
+ bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
438
+ }
439
+ add_action( 'wp', 'bp_activity_action_post_comment', 3 );
440
+
441
+ function bp_activity_action_mark_favorite() {
442
+ global $bp;
443
+
444
+ if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'favorite' )
445
+ return false;
446
+
447
+ /* Check the nonce */
448
+ check_admin_referer( 'mark_favorite' );
449
+
450
+ if ( bp_activity_add_user_favorite( $bp->action_variables[0] ) )
451
+ bp_core_add_message( __( 'Activity marked as favorite.', 'buddypress' ) );
452
+ else
453
+ bp_core_add_message( __( 'There was an error marking that activity as a favorite, please try again.', 'buddypress' ), 'error' );
454
+
455
+ bp_core_redirect( wp_get_referer() . '#activity-' . $bp->action_variables[0] );
456
+ }
457
+ add_action( 'wp', 'bp_activity_action_mark_favorite', 3 );
458
+
459
+ function bp_activity_action_remove_favorite() {
460
+ global $bp;
461
+
462
+ if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'unfavorite' )
463
+ return false;
464
+
465
+ /* Check the nonce */
466
+ check_admin_referer( 'unmark_favorite' );
467
+
468
+ if ( bp_activity_remove_user_favorite( $bp->action_variables[0] ) )
469
+ bp_core_add_message( __( 'Activity removed as favorite.', 'buddypress' ) );
470
+ else
471
+ bp_core_add_message( __( 'There was an error removing that activity as a favorite, please try again.', 'buddypress' ), 'error' );
472
+
473
+ bp_core_redirect( wp_get_referer() . '#activity-' . $bp->action_variables[0] );
474
+ }
475
+ add_action( 'wp', 'bp_activity_action_remove_favorite', 3 );
476
+
477
+ function bp_activity_action_sitewide_feed() {
478
+ global $bp, $wp_query;
479
+
480
+ if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'feed' || $bp->displayed_user->id || $bp->groups->current_group )
481
+ return false;
482
+
483
+ $wp_query->is_404 = false;
484
+ status_header( 200 );
485
+
486
+ include_once( 'bp-activity/feeds/bp-activity-sitewide-feed.php' );
487
+ die;
488
+ }
489
+ add_action( 'wp', 'bp_activity_action_sitewide_feed', 3 );
490
+
491
+ function bp_activity_action_personal_feed() {
492
+ global $bp, $wp_query;
493
+
494
+ if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'feed' )
495
+ return false;
496
+
497
+ $wp_query->is_404 = false;
498
+ status_header( 200 );
499
+
500
+ include_once( 'bp-activity/feeds/bp-activity-personal-feed.php' );
501
+ die;
502
+ }
503
+ add_action( 'wp', 'bp_activity_action_personal_feed', 3 );
504
+
505
+ function bp_activity_action_friends_feed() {
506
+ global $bp, $wp_query;
507
+
508
+ if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'friends' || $bp->action_variables[0] != 'feed' )
509
+ return false;
510
+
511
+ $wp_query->is_404 = false;
512
+ status_header( 200 );
513
+
514
+ include_once( 'bp-activity/feeds/bp-activity-friends-feed.php' );
515
+ die;
516
+ }
517
+ add_action( 'wp', 'bp_activity_action_friends_feed', 3 );
518
+
519
+ function bp_activity_action_my_groups_feed() {
520
+ global $bp, $wp_query;
521
+
522
+ if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'groups' || $bp->action_variables[0] != 'feed' )
523
+ return false;
524
+
525
+ $wp_query->is_404 = false;
526
+ status_header( 200 );
527
+
528
+ include_once( 'bp-activity/feeds/bp-activity-mygroups-feed.php' );
529
+ die;
530
+ }
531
+ add_action( 'wp', 'bp_activity_action_my_groups_feed', 3 );
532
+
533
+ function bp_activity_action_mentions_feed() {
534
+ global $bp, $wp_query;
535
+
536
+ if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'mentions' || $bp->action_variables[0] != 'feed' )
537
+ return false;
538
+
539
+ $wp_query->is_404 = false;
540
+ status_header( 200 );
541
+
542
+ include_once( 'bp-activity/feeds/bp-activity-mentions-feed.php' );
543
+ die;
544
+ }
545
+ add_action( 'wp', 'bp_activity_action_mentions_feed', 3 );
546
+
547
+ function bp_activity_action_favorites_feed() {
548
+ global $bp, $wp_query;
549
+
550
+ if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'favorites' || $bp->action_variables[0] != 'feed' )
551
+ return false;
552
+
553
+ $wp_query->is_404 = false;
554
+ status_header( 200 );
555
+
556
+ include_once( 'bp-activity/feeds/bp-activity-favorites-feed.php' );
557
+ die;
558
+ }
559
+ add_action( 'wp', 'bp_activity_action_favorites_feed', 3 );
560
+
561
+ /********************************************************************************
562
+ * Business Functions
563
+ *
564
+ * Business functions are where all the magic happens in BuddyPress. They will
565
+ * handle the actual saving or manipulation of information. Usually they will
566
+ * hand off to a database class for data access, then return
567
+ * true or false on success or failure.
568
+ */
569
+
570
+ function bp_activity_get( $args = '' ) {
571
+ $defaults = array(
572
+ 'max' => false, // Maximum number of results to return
573
+ 'page' => 1, // page 1 without a per_page will result in no pagination.
574
+ 'per_page' => false, // results per page
575
+ 'sort' => 'DESC', // sort ASC or DESC
576
+ 'display_comments' => false, // false for no comments. 'stream' for within stream display, 'threaded' for below each activity item
577
+
578
+ 'search_terms' => false, // Pass search terms as a string
579
+ 'show_hidden' => false, // Show activity items that are hidden site-wide?
580
+
581
+ /**
582
+ * Pass filters as an array -- all filter items can be multiple values comma separated:
583
+ * array(
584
+ * 'user_id' => false, // user_id to filter on
585
+ * 'object' => false, // object to filter on e.g. groups, profile, status, friends
586
+ * 'action' => false, // action to filter on e.g. activity_update, profile_updated
587
+ * 'primary_id' => false, // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
588
+ * 'secondary_id' => false, // secondary object ID to filter on e.g. a post_id
589
+ * );
590
+ */
591
+ 'filter' => array()
592
+ );
593
+
594
+ $r = wp_parse_args( $args, $defaults );
595
+ extract( $r, EXTR_SKIP );
596
+
597
+ /* Attempt to return a cached copy of the first page of sitewide activity. */
598
+ if ( 1 == (int)$page && empty( $max ) && empty( $search_terms ) && empty( $filter ) && 'DESC' == $sort ) {
599
+ if ( !$activity = wp_cache_get( 'bp_activity_sitewide_front', 'bp' ) ) {
600
+ $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden );
601
+ wp_cache_set( 'bp_activity_sitewide_front', $activity, 'bp' );
602
+ }
603
+ } else
604
+ $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden );
605
+
606
+ return apply_filters( 'bp_activity_get', $activity, &$r );
607
+ }
608
+
609
+ function bp_activity_get_specific( $args = '' ) {
610
+ $defaults = array(
611
+ 'activity_ids' => false, // A single activity_id or array of IDs.
612
+ 'page' => 1, // page 1 without a per_page will result in no pagination.
613
+ 'per_page' => false, // results per page
614
+ 'max' => false, // Maximum number of results to return
615
+ 'sort' => 'DESC', // sort ASC or DESC
616
+ 'display_comments' => false // true or false to display threaded comments for these specific activity items
617
+ );
618
+
619
+ $r = wp_parse_args( $args, $defaults );
620
+ extract( $r, EXTR_SKIP );
621
+
622
+ return apply_filters( 'bp_activity_get_specific', BP_Activity_Activity::get_specific( $activity_ids, $max, $page, $per_page, $sort, $display_comments ) );
623
+ }
624
+
625
+ function bp_activity_add( $args = '' ) {
626
+ global $bp, $wpdb;
627
+
628
+ $defaults = array(
629
+ 'id' => false, // Pass an existing activity ID to update an existing entry.
630
+
631
+ 'action' => '', // The activity action - e.g. "Jon Doe posted an update"
632
+ 'content' => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!"
633
+
634
+ 'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent
635
+ 'type' => false, // The activity type e.g. activity_update, profile_updated
636
+ 'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink)
637
+
638
+ '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.
639
+ 'item_id' => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id
640
+ 'secondary_item_id' => false, // Optional: A second ID used to further filter e.g. a comment_id
641
+ 'recorded_time' => gmdate( "Y-m-d H:i:s" ), // The GMT time that this activity was recorded
642
+ 'hide_sitewide' => false // Should this be hidden on the sitewide activity stream?
643
+ );
644
+
645
+ $params = wp_parse_args( $args, $defaults );
646
+ extract( $params, EXTR_SKIP );
647
+
648
+ /* Make sure we are backwards compatible */
649
+ if ( empty( $component ) && !empty( $component_name ) )
650
+ $component = $component_name;
651
+
652
+ if ( empty( $type ) && !empty( $component_action ) )
653
+ $type = $component_action;
654
+
655
+ $activity = new BP_Activity_Activity( $id );
656
+
657
+ $activity->user_id = $user_id;
658
+ $activity->component = $component;
659
+ $activity->type = $type;
660
+ $activity->action = $action;
661
+ $activity->content = $content;
662
+ $activity->primary_link = $primary_link;
663
+ $activity->item_id = $item_id;
664
+ $activity->secondary_item_id = $secondary_item_id;
665
+ $activity->date_recorded = $recorded_time;
666
+ $activity->hide_sitewide = $hide_sitewide;
667
+
668
+ if ( !$activity->save() )
669
+ return false;
670
+
671
+ /* If this is an activity comment, rebuild the tree */
672
+ if ( 'activity_comment' == $activity->type )
673
+ BP_Activity_Activity::rebuild_activity_comment_tree( $activity->item_id );
674
+
675
+ wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
676
+ do_action( 'bp_activity_add', $params );
677
+
678
+ return $activity->id;
679
+ }
680
+
681
+ function bp_activity_post_update( $args = '' ) {
682
+ global $bp;
683
+
684
+ $defaults = array(
685
+ 'content' => false,
686
+ 'user_id' => $bp->loggedin_user->id
687
+ );
688
+
689
+ $r = wp_parse_args( $args, $defaults );
690
+ extract( $r, EXTR_SKIP );
691
+
692
+ if ( empty( $content ) || !strlen( trim( $content ) ) )
693
+ return false;
694
+
695
+ /* Record this on the user's profile */
696
+ $from_user_link = bp_core_get_userlink( $user_id );
697
+ $activity_action = sprintf( __( '%s posted an update:', 'buddypress' ), $from_user_link );
698
+ $activity_content = $content;
699
+
700
+ $primary_link = bp_core_get_userlink( $user_id, false, true );
701
+
702
+ /* Now write the values */
703
+ $activity_id = bp_activity_add( array(
704
+ 'user_id' => $user_id,
705
+ 'action' => apply_filters( 'bp_activity_new_update_action', $activity_action ),
706
+ 'content' => apply_filters( 'bp_activity_new_update_content', $activity_content ),
707
+ 'primary_link' => apply_filters( 'bp_activity_new_update_primary_link', $primary_link ),
708
+ 'component' => $bp->activity->id,
709
+ 'type' => 'activity_update'
710
+ ) );
711
+
712
+ /* Add this update to the "latest update" usermeta so it can be fetched anywhere. */
713
+ update_usermeta( $bp->loggedin_user->id, 'bp_latest_update', array( 'id' => $activity_id, 'content' => wp_filter_kses( $content ) ) );
714
+
715
+ /* Require the notifications code so email notifications can be set on the 'bp_activity_posted_update' action. */
716
+ require_once( BP_PLUGIN_DIR . '/bp-activity/bp-activity-notifications.php' );
717
+
718
+ do_action( 'bp_activity_posted_update', $content, $user_id, $activity_id );
719
+
720
+ return $activity_id;
721
+ }
722
+
723
+ function bp_activity_new_comment( $args = '' ) {
724
+ global $bp;
725
+
726
+ $defaults = array(
727
+ 'id' => false,
728
+ 'content' => false,
729
+ 'user_id' => $bp->loggedin_user->id,
730
+ 'activity_id' => false, // ID of the root activity item
731
+ 'parent_id' => false // ID of a parent comment (optional)
732
+ );
733
+
734
+ $params = wp_parse_args( $args, $defaults );
735
+ extract( $params, EXTR_SKIP );
736
+
737
+ if ( empty($content) || empty($user_id) || empty($activity_id) )
738
+ return false;
739
+
740
+ if ( empty($parent_id) )
741
+ $parent_id = $activity_id;
742
+
743
+ /* Check to see if the parent activity is hidden, and if so, hide this comment publically. */
744
+ $activity = new BP_Activity_Activity( $activity_id );
745
+ $is_hidden = ( (int)$activity->hide_sitewide ) ? 1 : 0;
746
+
747
+ /* Insert the activity comment */
748
+ $comment_id = bp_activity_add( array(
749
+ 'id' => $id,
750
+ 'action' => apply_filters( 'bp_activity_comment_action', sprintf( __( '%s posted a new activity comment:', 'buddypress' ), bp_core_get_userlink( $user_id ) ) ),
751
+ 'content' => apply_filters( 'bp_activity_comment_content', $content ),
752
+ 'component' => $bp->activity->id,
753
+ 'type' => 'activity_comment',
754
+ 'user_id' => $user_id,
755
+ 'item_id' => $activity_id,
756
+ 'secondary_item_id' => $parent_id,
757
+ 'hide_sitewide' => $is_hidden
758
+ ) );
759
+
760
+ /* Send an email notification if settings allow */
761
+ require_once( BP_PLUGIN_DIR . '/bp-activity/bp-activity-notifications.php' );
762
+ bp_activity_new_comment_notification( $comment_id, $user_id, $params );
763
+
764
+ /* Clear the comment cache for this activity */
765
+ wp_cache_delete( 'bp_activity_comments_' . $parent_id );
766
+
767
+ do_action( 'bp_activity_comment_posted', $comment_id, $params );
768
+
769
+ return $comment_id;
770
+ }
771
+
772
+ /**
773
+ * bp_activity_get_activity_id()
774
+ *
775
+ * Fetch the activity_id for an existing activity entry in the DB.
776
+ *
777
+ * @package BuddyPress Activity
778
+ */
779
+ function bp_activity_get_activity_id( $args = '' ) {
780
+ $defaults = array(
781
+ 'user_id' => false,
782
+ 'component' => false,
783
+ 'type' => false,
784
+ 'item_id' => false,
785
+ 'secondary_item_id' => false,
786
+ 'action' => false,
787
+ 'content' => false,
788
+ 'date_recorded' => false,
789
+ );
790
+
791
+ $r = wp_parse_args( $args, $defaults );
792
+ extract( $r, EXTR_SKIP );
793
+
794
+ 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 ) );
795
+ }
796
+
797
+ /***
798
+ * Deleting Activity
799
+ *
800
+ * If you're looking to hook into one action that provides the ID(s) of
801
+ * the activity/activities deleted, then use:
802
+ *
803
+ * add_action( 'bp_activity_deleted_activities', 'my_function' );
804
+ *
805
+ * The action passes one parameter that is a single activity ID or an
806
+ * array of activity IDs depending on the number deleted.
807
+ *
808
+ * If you are deleting an activity comment please use bp_activity_delete_comment();
809
+ */
810
+
811
+ function bp_activity_delete( $args = '' ) {
812
+ global $bp;
813
+
814
+ /* Pass one or more the of following variables to delete by those variables */
815
+ $defaults = array(
816
+ 'id' => false,
817
+ 'action' => false,
818
+ 'content' => false,
819
+ 'component' => false,
820
+ 'type' => false,
821
+ 'primary_link' => false,
822
+ 'user_id' => false,
823
+ 'item_id' => false,
824
+ 'secondary_item_id' => false,
825
+ 'date_recorded' => false,
826
+ 'hide_sitewide' => false
827
+ );
828
+
829
+ $args = wp_parse_args( $args, $defaults );
830
+
831
+ if ( !$activity_ids_deleted = BP_Activity_Activity::delete( $args ) )
832
+ return false;
833
+
834
+ /* Check if the user's latest update has been deleted */
835
+ if ( empty( $args['user_id'] ) )
836
+ $user_id = $bp->loggedin_user->id;
837
+ else
838
+ $user_id = $args['user_id'];
839
+
840
+ $latest_update = get_usermeta( $user_id, 'bp_latest_update' );
841
+ if ( !empty( $latest_update ) ) {
842
+ if ( in_array( (int)$latest_update['id'], (array)$activity_ids_deleted ) )
843
+ delete_usermeta( $user_id, 'bp_latest_update' );
844
+ }
845
+
846
+ do_action( 'bp_activity_delete', $args );
847
+ do_action( 'bp_activity_deleted_activities', $activity_ids_deleted );
848
+
849
+ wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
850
+
851
+ return true;
852
+ }
853
+ /* The following functions have been deprecated in place of bp_activity_delete() */
854
+ function bp_activity_delete_by_item_id( $args = '' ) {
855
+ global $bp;
856
+
857
+ $defaults = array( 'item_id' => false, 'component' => false, 'type' => false, 'user_id' => false, 'secondary_item_id' => false );
858
+ $r = wp_parse_args( $args, $defaults );
859
+ extract( $r, EXTR_SKIP );
860
+
861
+ return bp_activity_delete( array( 'item_id' => $item_id, 'component' => $component, 'type' => $type, 'user_id' => $user_id, 'secondary_item_id' => $secondary_item_id ) );
862
+ }
863
+
864
+ function bp_activity_delete_by_activity_id( $activity_id ) {
865
+ return bp_activity_delete( array( 'id' => $activity_id ) );
866
+ }
867
+
868
+ function bp_activity_delete_by_content( $user_id, $content, $component, $type ) {
869
+ return bp_activity_delete( array( 'user_id' => $user_id, 'content' => $content, 'component' => $component, 'type' => $type ) );
870
+ }
871
+
872
+ function bp_activity_delete_for_user_by_component( $user_id, $component ) {
873
+ return bp_activity_delete( array( 'user_id' => $user_id, 'component' => $component ) );
874
+ }
875
+ /* End deprecation */
876
+
877
+ function bp_activity_delete_comment( $activity_id, $comment_id ) {
878
+ /***
879
+ * You may want to hook into this filter if you want to override this function and
880
+ * handle the deletion of child comments differently. Make sure you return false.
881
+ */
882
+ if ( !apply_filters( 'bp_activity_delete_comment_pre', true, $activity_id, $comment_id ) )
883
+ return false;
884
+
885
+ /* Delete any children of this comment. */
886
+ bp_activity_delete_children( $activity_id, $comment_id );
887
+
888
+ /* Delete the actual comment */
889
+ if ( !bp_activity_delete( array( 'id' => $comment_id, 'type' => 'activity_comment' ) ) )
890
+ return false;
891
+
892
+ /* Recalculate the comment tree */
893
+ BP_Activity_Activity::rebuild_activity_comment_tree( $activity_id );
894
+
895
+ do_action( 'bp_activity_delete_comment', $activity_id, $comment_id );
896
+
897
+ return true;
898
+ }
899
+ function bp_activity_delete_children( $activity_id, $comment_id) {
900
+ /* Recursively delete all children of this comment. */
901
+ if ( $children = BP_Activity_Activity::get_child_comments( $comment_id ) ) {
902
+ foreach( (array)$children as $child )
903
+ bp_activity_delete_children( $activity_id, $child->id );
904
+ }
905
+ bp_activity_delete( array( 'secondary_item_id' => $comment_id, 'type' => 'activity_comment', 'item_id' => $activity_id ) );
906
+ }
907
+
908
+ function bp_activity_get_permalink( $activity_id, $activity_obj = false ) {
909
+ global $bp;
910
+
911
+ if ( !$activity_obj )
912
+ $activity_obj = new BP_Activity_Activity( $activity_id );
913
+
914
+ 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 )
915
+ $link = $activity_obj->primary_link;
916
+ else {
917
+ if ( 'activity_comment' == $activity_obj->type )
918
+ $link = $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activity_obj->item_id . '/';
919
+ else
920
+ $link = $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activity_obj->id . '/';
921
+ }
922
+
923
+ return apply_filters( 'bp_activity_get_permalink', $link );
924
+ }
925
+
926
+ function bp_activity_hide_user_activity( $user_id ) {
927
+ return BP_Activity_Activity::hide_all_for_user( $user_id );
928
+ }
929
+
930
+ /**
931
+ * bp_activity_thumbnail_content_images()
932
+ *
933
+ * Take content, remove all images and replace them with one thumbnail image.
934
+ *
935
+ * @package BuddyPress Activity
936
+ * @param $content str - The content to work with
937
+ * @return $content str - The content with images stripped and replaced with a single thumb.
938
+ */
939
+ function bp_activity_thumbnail_content_images( $content ) {
940
+ preg_match_all( '/<img[^>]*>/Ui', $content, $matches );
941
+ $content = preg_replace('/<img[^>]*>/Ui', '', $content );
942
+
943
+ if ( !empty( $matches ) ) {
944
+ /* Get the SRC value */
945
+ preg_match( '/<img.*?(src\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $src );
946
+
947
+ /* Get the width and height */
948
+ preg_match( '/<img.*?(height\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $height );
949
+ preg_match( '/<img.*?(width\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $width );
950
+
951
+ if ( !empty( $src ) ) {
952
+ $src = substr( substr( str_replace( 'src=', '', $src[1] ), 0, -1 ), 1 );
953
+ $height = substr( substr( str_replace( 'height=', '', $height[1] ), 0, -1 ), 1 );
954
+ $width = substr( substr( str_replace( 'width=', '', $width[1] ), 0, -1 ), 1 );
955
+
956
+ if ( empty( $width ) || empty( $height ) ) {
957
+ $width = 100;
958
+ $height = 100;
959
+ }
960
+
961
+ $ratio = (int)$width / (int)$height;
962
+ $new_height = 100;
963
+ $new_width = $new_height * $ratio;
964
+
965
+ $content = '<img src="' . esc_attr( $src) . '" width="' . $new_width . '" height="' . $new_height . '" alt="' . __( 'Thumbnail', 'buddypress' ) . '" class="align-left thumbnail" />' . $content;
966
+ }
967
+ }
968
+
969
+ return apply_filters( 'bp_activity_thumbnail_content_images', $content, $matches );
970
+ }
971
+
972
+ function bp_activity_set_action( $component_id, $key, $value ) {
973
+ global $bp;
974
+
975
+ if ( empty( $component_id ) || empty( $key ) || empty( $value ) )
976
+ return false;
977
+
978
+ $bp->activity->actions->{$component_id}->{$key} = apply_filters( 'bp_activity_set_action', array(
979
+ 'key' => $key,
980
+ 'value' => $value
981
+ ), $component_id, $key, $value );
982
+ }
983
+
984
+ function bp_activity_get_action( $component_id, $key ) {
985
+ global $bp;
986
+
987
+ if ( empty( $component_id ) || empty( $key ) )
988
+ return false;
989
+
990
+ return apply_filters( 'bp_activity_get_action', $bp->activity->actions->{$component_id}->{$key}, $component_id, $key );
991
+ }
992
+
993
+ function bp_activity_get_user_favorites( $user_id ) {
994
+ $my_favs = maybe_unserialize( get_usermeta( $user_id, 'bp_favorite_activities' ) );
995
+ $existing_favs = bp_activity_get_specific( array( 'activity_ids' => $my_favs ) );
996
+
997
+ foreach( (array)$existing_favs['activities'] as $fav )
998
+ $new_favs[] = $fav->id;
999
+
1000
+ $new_favs = array_unique( (array)$new_favs );
1001
+ update_usermeta( $user_id, 'bp_favorite_activities', $new_favs );
1002
+
1003
+ return apply_filters( 'bp_activity_get_user_favorites', $new_favs );
1004
+ }
1005
+
1006
+ function bp_activity_add_user_favorite( $activity_id, $user_id = false ) {
1007
+ global $bp;
1008
+
1009
+ if ( !$user_id )
1010
+ $user_id = $bp->loggedin_user->id;
1011
+
1012
+ /* Update the user's personal favorites */
1013
+ $my_favs = maybe_unserialize( get_usermeta( $bp->loggedin_user->id, 'bp_favorite_activities' ) );
1014
+ $my_favs[] = $activity_id;
1015
+
1016
+ /* Update the total number of users who have favorited this activity */
1017
+ $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' );
1018
+
1019
+ if ( !empty( $fav_count ) )
1020
+ $fav_count = (int)$fav_count + 1;
1021
+ else
1022
+ $fav_count = 1;
1023
+
1024
+ update_usermeta( $bp->loggedin_user->id, 'bp_favorite_activities', $my_favs );
1025
+ bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count );
1026
+
1027
+ do_action( 'bp_activity_add_user_favorite', $activity_id, $user_id );
1028
+
1029
+ return true;
1030
+ }
1031
+
1032
+ function bp_activity_remove_user_favorite( $activity_id, $user_id = false ) {
1033
+ global $bp;
1034
+
1035
+ if ( !$user_id )
1036
+ $user_id = $bp->loggedin_user->id;
1037
+
1038
+ /* Remove the fav from the user's favs */
1039
+ $my_favs = maybe_unserialize( get_usermeta( $user_id, 'bp_favorite_activities' ) );
1040
+ $my_favs = array_flip( (array) $my_favs );
1041
+ unset( $my_favs[$activity_id] );
1042
+ $my_favs = array_unique( array_flip( $my_favs ) );
1043
+
1044
+ /* Update the total number of users who have favorited this activity */
1045
+ $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' );
1046
+
1047
+ if ( !empty( $fav_count ) ) {
1048
+ $fav_count = (int)$fav_count - 1;
1049
+ bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count );
1050
+ }
1051
+
1052
+ update_usermeta( $user_id, 'bp_favorite_activities', $my_favs );
1053
+
1054
+ do_action( 'bp_activity_remove_user_favorite', $activity_id, $user_id );
1055
+
1056
+ return true;
1057
+ }
1058
+
1059
+ function bp_activity_check_exists_by_content( $content ) {
1060
+ return apply_filters( 'bp_activity_check_exists_by_content', BP_Activity_Activity::check_exists_by_content( $content ) );
1061
+ }
1062
+
1063
+ function bp_activity_get_last_updated() {
1064
+ return apply_filters( 'bp_activity_get_last_updated', BP_Activity_Activity::get_last_updated() );
1065
+ }
1066
+
1067
+ function bp_activity_total_favorites_for_user( $user_id = false ) {
1068
+ global $bp;
1069
+
1070
+ if ( !$user_id )
1071
+ $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
1072
+
1073
+ return BP_Activity_Activity::total_favorite_count( $user_id );
1074
+ }
1075
+
1076
+ /********************************************************************************
1077
+ * Activity Meta Functions
1078
+ *
1079
+ * Meta functions allow you to store extra data for a particular item.
1080
+ */
1081
+
1082
+ function bp_activity_delete_meta( $activity_id, $meta_key = false, $meta_value = false ) {
1083
+ global $wpdb, $bp;
1084
+
1085
+ if ( !is_numeric( $activity_id ) )
1086
+ return false;
1087
+
1088
+ $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
1089
+
1090
+ if ( is_array( $meta_value ) || is_object( $meta_value ) )
1091
+ $meta_value = serialize( $meta_value );
1092
+
1093
+ $meta_value = trim( $meta_value );
1094
+
1095
+ if ( !$meta_key ) {
1096
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d", $activity_id ) );
1097
+ } else if ( $meta_value ) {
1098
+ $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 ) );
1099
+ } else {
1100
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s", $activity_id, $meta_key ) );
1101
+ }
1102
+
1103
+ wp_cache_delete( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, 'bp' );
1104
+
1105
+ return true;
1106
+ }
1107
+
1108
+ function bp_activity_get_meta( $activity_id, $meta_key = '' ) {
1109
+ global $wpdb, $bp;
1110
+
1111
+ $activity_id = (int)$activity_id;
1112
+
1113
+ if ( !$activity_id )
1114
+ return false;
1115
+
1116
+ if ( !empty($meta_key) ) {
1117
+ $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
1118
+
1119
+ if ( !$metas = wp_cache_get( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, 'bp' ) ) {
1120
+ $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 ) );
1121
+ wp_cache_set( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, $metas, 'bp' );
1122
+ }
1123
+ } else
1124
+ $metas = $wpdb->get_col( $wpdb->prepare( "SELECT meta_value FROM {$bp->activity->table_name_meta} WHERE activity_id = %d", $activity_id ) );
1125
+
1126
+ if ( empty($metas) )
1127
+ return false;
1128
+
1129
+ $metas = array_map( 'maybe_unserialize', (array)$metas );
1130
+
1131
+ if ( 1 == count($metas) )
1132
+ return $metas[0];
1133
+ else
1134
+ return $metas;
1135
+ }
1136
+
1137
+ function bp_activity_update_meta( $activity_id, $meta_key, $meta_value ) {
1138
+ global $wpdb, $bp;
1139
+
1140
+ if ( !is_numeric( $activity_id ) )
1141
+ return false;
1142
+
1143
+ $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
1144
+
1145
+ if ( is_string( $meta_value ) )
1146
+ $meta_value = stripslashes( $wpdb->escape( $meta_value ) );
1147
+
1148
+ $meta_value = maybe_serialize( $meta_value );
1149
+
1150
+ if ( empty( $meta_value ) ) {
1151
+ return bp_activity_delete_meta( $activity_id, $meta_key );
1152
+ }
1153
+
1154
+ $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 ) );
1155
+
1156
+ if ( !$cur ) {
1157
+ $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 ) );
1158
+ } else if ( $cur->meta_value != $meta_value ) {
1159
+ $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 ) );
1160
+ } else {
1161
+ return false;
1162
+ }
1163
+
1164
+ wp_cache_set( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, $meta_value, 'bp' );
1165
+
1166
+ return true;
1167
+ }
1168
+
1169
+ function bp_activity_remove_data( $user_id ) {
1170
+ // Clear the user's activity from the sitewide stream and clear their activity tables
1171
+ bp_activity_delete( array( 'user_id' => $user_id ) );
1172
+
1173
+ // Remove any usermeta
1174
+ delete_usermeta( $user_id, 'bp_latest_update' );
1175
+ delete_usermeta( $user_id, 'bp_favorite_activities' );
1176
+
1177
+ do_action( 'bp_activity_remove_data', $user_id );
1178
+ }
1179
+ add_action( 'wpmu_delete_user', 'bp_activity_remove_data' );
1180
+ add_action( 'delete_user', 'bp_activity_remove_data' );
1181
+ add_action( 'make_spam_user', 'bp_activity_remove_data' );
1182
+
1183
+
1184
+ /********************************************************************************
1185
+ * Custom Actions
1186
+ *
1187
+ * Functions to set up custom BuddyPress actions that all other components can
1188
+ * hook in to.
1189
+ */
1190
+
1191
+ /* Allow core components and dependent plugins to register activity actions */
1192
+ function bp_register_activity_actions() {
1193
+ do_action( 'bp_register_activity_actions' );
1194
+ }
1195
+ add_action( 'bp_loaded', 'bp_register_activity_actions', 8 );
1196
+
1197
+
1198
  ?>
bp-activity/bp-activity-classes.php CHANGED
@@ -1,553 +1,553 @@
1
- <?php
2
-
3
- Class BP_Activity_Activity {
4
- var $id;
5
- var $item_id;
6
- var $secondary_item_id;
7
- var $user_id;
8
- var $primary_link;
9
- var $component;
10
- var $type;
11
- var $action;
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
- }
23
- }
24
-
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;
67
-
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
75
- $q = $wpdb->prepare( "INSERT INTO {$bp->activity->table_name} ( user_id, component, type, action, content, primary_link, date_recorded, item_id, secondary_item_id, hide_sitewide ) VALUES ( %d, %s, %s, %s, %s, %s, %s, %s, %s, %d )", $this->user_id, $this->component, $this->type, $this->action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide );
76
-
77
- if ( !$wpdb->query( $q ) )
78
- return false;
79
-
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;
138
- }
139
-
140
- $activity_user_ids = implode( ',', array_unique( (array)$activity_user_ids ) );
141
- if ( !empty( $activity_user_ids ) ) {
142
- if ( $names = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, value AS user_fullname FROM {$bp->profile->table_name_data} WHERE field_id = 1 AND user_id IN ({$activity_user_ids})" ) ) ) {
143
- foreach ( (array)$names as $name )
144
- $tmp_names[$name->user_id] = $name->user_fullname;
145
-
146
- foreach ( (array)$activities as $i => $activity ) {
147
- if ( !empty( $tmp_names[$activity->user_id] ) )
148
- $activities[$i]->user_fullname = $tmp_names[$activity->user_id];
149
- }
150
-
151
- unset( $names );
152
- unset( $tmp_names );
153
- }
154
- }
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;
164
- }
165
-
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 ) {
170
- global $wpdb, $bp;
171
-
172
- if ( is_array( $activity_ids ) )
173
- $activity_ids = implode( ',', $activity_ids );
174
-
175
- $activity_ids = $wpdb->escape( $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
- $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id IN ({$activity_ids}) ORDER BY date_recorded {$sort} $pag_sql" ) );
187
- $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE id IN ({$activity_ids})" ) );
188
-
189
- if ( $display_comments )
190
- $activities = BP_Activity_Activity::append_comments( $activities );
191
-
192
- /* If $max is set, only return up to the max results */
193
- if ( !empty( $max ) ) {
194
- if ( (int)$total_activities > (int)$max )
195
- $total_activities = $max;
196
- }
197
-
198
- return array( 'activities' => $activities, 'total' => (int)$total_activities );
199
- }
200
-
201
- function get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content, $date_recorded ) {
202
- global $bp, $wpdb;
203
-
204
- $where_args = false;
205
-
206
- if ( !empty( $user_id ) )
207
- $where_args[] = $wpdb->prepare( "user_id = %d", $user_id );
208
-
209
- if ( !empty( $component ) )
210
- $where_args[] = $wpdb->prepare( "component = %s", $component );
211
-
212
- if ( !empty( $type ) )
213
- $where_args[] = $wpdb->prepare( "type = %s", $type );
214
-
215
- if ( !empty( $item_id ) )
216
- $where_args[] = $wpdb->prepare( "item_id = %s", $item_id );
217
-
218
- if ( !empty( $secondary_item_id ) )
219
- $where_args[] = $wpdb->prepare( "secondary_item_id = %s", $secondary_item_id );
220
-
221
- if ( !empty( $action ) )
222
- $where_args[] = $wpdb->prepare( "action = %s", $action );
223
-
224
- if ( !empty( $content ) )
225
- $where_args[] = $wpdb->prepare( "content = %s", $content );
226
-
227
- if ( !empty( $date_recorded ) )
228
- $where_args[] = $wpdb->prepare( "date_recorded = %s", $date_recorded );
229
-
230
- if ( !empty( $where_args ) )
231
- $where_sql = 'WHERE ' . join( ' AND ', $where_args );
232
- else
233
- return false;
234
-
235
- return $wpdb->get_var( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" );
236
- }
237
-
238
- function delete( $args ) {
239
- global $wpdb, $bp;
240
-
241
- extract( $args );
242
-
243
- $defaults = array(
244
- 'id' => false,
245
- 'action' => false,
246
- 'content' => false,
247
- 'component' => false,
248
- 'type' => false,
249
- 'primary_link' => false,
250
- 'user_id' => false,
251
- 'item_id' => false,
252
- 'secondary_item_id' => false,
253
- 'date_recorded' => false,
254
- 'hide_sitewide' => false
255
- );
256
-
257
- $where_args = false;
258
-
259
- if ( !empty( $id ) )
260
- $where_args[] = $wpdb->prepare( "id = %d", $id );
261
-
262
- if ( !empty( $user_id ) )
263
- $where_args[] = $wpdb->prepare( "user_id = %d", $user_id );
264
-
265
- if ( !empty( $action ) )
266
- $where_args[] = $wpdb->prepare( "action = %s", $action );
267
-
268
- if ( !empty( $content ) )
269
- $where_args[] = $wpdb->prepare( "content = %s", $content );
270
-
271
- if ( !empty( $component ) )
272
- $where_args[] = $wpdb->prepare( "component = %s", $component );
273
-
274
- if ( !empty( $type ) )
275
- $where_args[] = $wpdb->prepare( "type = %s", $type );
276
-
277
- if ( !empty( $primary_link ) )
278
- $where_args[] = $wpdb->prepare( "primary_link = %s", $primary_link );
279
-
280
- if ( !empty( $item_id ) )
281
- $where_args[] = $wpdb->prepare( "item_id = %s", $item_id );
282
-
283
- if ( !empty( $secondary_item_id ) )
284
- $where_args[] = $wpdb->prepare( "secondary_item_id = %s", $secondary_item_id );
285
-
286
- if ( !empty( $date_recorded ) )
287
- $where_args[] = $wpdb->prepare( "date_recorded = %s", $date_recorded );
288
-
289
- if ( !empty( $hide_sitewide ) )
290
- $where_args[] = $wpdb->prepare( "hide_sitewide = %d", $hide_sitewide );
291
-
292
- if ( !empty( $where_args ) )
293
- $where_sql = 'WHERE ' . join( ' AND ', $where_args );
294
- else
295
- return false;
296
-
297
- /* Fetch the activity IDs so we can delete any comments for this activity item */
298
- $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" ) );
299
-
300
- if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} {$where_sql}" ) ) )
301
- return false;
302
-
303
- if ( $activity_ids ) {
304
- BP_Activity_Activity::delete_activity_item_comments( $activity_ids );
305
- BP_Activity_Activity::delete_activity_meta_entries( $activity_ids );
306
-
307
- return $activity_ids;
308
- }
309
-
310
- return $activity_ids;
311
- }
312
-
313
- function delete_activity_item_comments( $activity_ids ) {
314
- global $bp, $wpdb;
315
-
316
- if ( is_array($activity_ids) )
317
- $activity_ids = implode( ',', $activity_ids );
318
-
319
- $activity_ids = $wpdb->escape( $activity_ids );
320
-
321
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND item_id IN ({$activity_ids})" ) );
322
- }
323
-
324
- function delete_activity_meta_entries( $activity_ids ) {
325
- global $bp, $wpdb;
326
-
327
- if ( is_array($activity_ids) )
328
- $activity_ids = implode( ',', $activity_ids );
329
-
330
- $activity_ids = $wpdb->escape( $activity_ids );
331
-
332
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id IN ({$activity_ids})" ) );
333
- }
334
-
335
- function append_comments( $activities ) {
336
- global $bp, $wpdb;
337
-
338
- /* Now fetch the activity comments and parse them into the correct position in the activities array. */
339
- foreach( (array)$activities as $activity ) {
340
- if ( 'activity_comment' != $activity->type && $activity->mptt_left && $activity->mptt_right )
341
- $activity_comments[$activity->id] = BP_Activity_Activity::get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right );
342
- }
343
-
344
- /* Merge the comments with the activity items */
345
- foreach( (array)$activities as $key => $activity )
346
- $activities[$key]->children = $activity_comments[$activity->id];
347
-
348
- return $activities;
349
- }
350
-
351
- function get_activity_comments( $activity_id, $left, $right ) {
352
- global $wpdb, $bp;
353
-
354
- if ( !$comments = wp_cache_get( 'bp_activity_comments_' . $activity_id ) ) {
355
- /* Select the user's fullname with the query so we don't have to fetch it for each comment */
356
- if ( function_exists( 'xprofile_install' ) ) {
357
- $fullname_select = ", pd.value as user_fullname";
358
- $fullname_from = ", {$bp->profile->table_name_data} pd ";
359
- $fullname_where = "AND pd.user_id = a.user_id AND pd.field_id = 1";
360
- }
361
-
362
- /* Retrieve all descendants of the $root node */
363
- $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 ) );
364
-
365
- /* Loop descendants and build an assoc array */
366
- foreach ( (array)$descendants as $d ) {
367
- $d->children = array();
368
-
369
- /* If we have a reference on the parent */
370
- if ( isset( $ref[ $d->secondary_item_id ] ) ) {
371
- $ref[ $d->secondary_item_id ]->children[ $d->id ] = $d;
372
- $ref[ $d->id ] =& $ref[ $d->secondary_item_id ]->children[ $d->id ];
373
-
374
- /* If we don't have a reference on the parent, put in the root level */
375
- } else {
376
- $comments[ $d->id ] = $d;
377
- $ref[ $d->id ] =& $comments[ $d->id ];
378
- }
379
- }
380
- wp_cache_set( 'bp_activity_comments_' . $activity_id, $comments, 'bp' );
381
- }
382
-
383
- return $comments;
384
- }
385
-
386
- function rebuild_activity_comment_tree( $parent_id, $left = 1 ) {
387
- global $wpdb, $bp;
388
-
389
- /* The right value of this node is the left value + 1 */
390
- $right = $left + 1;
391
-
392
- /* Get all descendants of this node */
393
- $descendants = BP_Activity_Activity::get_child_comments( $parent_id );
394
-
395
- /* Loop the descendants and recalculate the left and right values */
396
- foreach ( (array)$descendants as $descendant )
397
- $right = BP_Activity_Activity::rebuild_activity_comment_tree( $descendant->id, $right );
398
-
399
- /* We've got the left value, and now that we've processed the children of this node we also know the right value */
400
- if ( 1 == $left )
401
- $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE id = %d", $left, $right, $parent_id ) );
402
- else
403
- $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 ) );
404
-
405
- /* Return the right value of this node + 1 */
406
- return $right + 1;
407
- }
408
-
409
- function get_child_comments( $parent_id ) {
410
- global $bp, $wpdb;
411
-
412
- return $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND secondary_item_id = %d", $parent_id ) );
413
- }
414
-
415
- function get_recorded_components() {
416
- global $wpdb, $bp;
417
-
418
- return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT component FROM {$bp->activity->table_name} ORDER BY component ASC" ) );
419
- }
420
-
421
- function get_sitewide_items_for_feed( $limit = 35 ) {
422
- global $wpdb, $bp;
423
-
424
- $activities = bp_activity_get_sitewide( array( 'max' => $limit ) );
425
-
426
- for ( $i = 0; $i < count($activities); $i++ ) {
427
- $title = explode( '<span', $activities[$i]['content'] );
428
-
429
- $activity_feed[$i]['title'] = trim( strip_tags( $title[0] ) );
430
- $activity_feed[$i]['link'] = $activities[$i]['primary_link'];
431
- $activity_feed[$i]['description'] = @sprintf( $activities[$i]['content'], '' );
432
- $activity_feed[$i]['pubdate'] = $activities[$i]['date_recorded'];
433
- }
434
-
435
- return $activity_feed;
436
- }
437
-
438
- function get_filter_sql( $filter_array ) {
439
- global $wpdb;
440
-
441
- if ( !empty( $filter_array['user_id'] ) ) {
442
- $user_filter = explode( ',', $filter_array['user_id'] );
443
- $user_sql = ' ( a.user_id IN ( ' . $filter_array['user_id'] . ' ) )';
444
- $filter_sql[] = $user_sql;
445
- }
446
-
447
- if ( !empty( $filter_array['object'] ) ) {
448
- $object_filter = explode( ',', $filter_array['object'] );
449
- $object_sql = ' ( ';
450
-
451
- $counter = 1;
452
- foreach( (array) $object_filter as $object ) {
453
- $object_sql .= $wpdb->prepare( "a.component = %s", trim( $object ) );
454
-
455
- if ( $counter != count( $object_filter ) )
456
- $object_sql .= ' || ';
457
-
458
- $counter++;
459
- }
460
-
461
- $object_sql .= ' )';
462
- $filter_sql[] = $object_sql;
463
- }
464
-
465
- if ( !empty( $filter_array['action'] ) ) {
466
- $action_filter = explode( ',', $filter_array['action'] );
467
- $action_sql = ' ( ';
468
-
469
- $counter = 1;
470
- foreach( (array) $action_filter as $action ) {
471
- $action_sql .= $wpdb->prepare( "a.type = %s", trim( $action ) );
472
-
473
- if ( $counter != count( $action_filter ) )
474
- $action_sql .= ' || ';
475
-
476
- $counter++;
477
- }
478
-
479
- $action_sql .= ' )';
480
- $filter_sql[] = $action_sql;
481
- }
482
-
483
- if ( !empty( $filter_array['primary_id'] ) ) {
484
- $pid_filter = explode( ',', $filter_array['primary_id'] );
485
- $pid_sql = ' ( ';
486
-
487
- $counter = 1;
488
- foreach( (array) $pid_filter as $pid ) {
489
- $pid_sql .= $wpdb->prepare( "a.item_id = %s", trim( $pid ) );
490
-
491
- if ( $counter != count( $pid_filter ) )
492
- $pid_sql .= ' || ';
493
-
494
- $counter++;
495
- }
496
-
497
- $pid_sql .= ' )';
498
- $filter_sql[] = $pid_sql;
499
- }
500
-
501
- if ( !empty( $filter_array['secondary_id'] ) ) {
502
- $sid_filter = explode( ',', $filter_array['secondary_id'] );
503
- $sid_sql = ' ( ';
504
-
505
- $counter = 1;
506
- foreach( (array) $sid_filter as $sid ) {
507
- $sid_sql .= $wpdb->prepare( "a.secondary_item_id = %s", trim( $sid ) );
508
-
509
- if ( $counter != count( $sid_filter ) )
510
- $sid_sql .= ' || ';
511
-
512
- $counter++;
513
- }
514
-
515
- $sid_sql .= ' )';
516
- $filter_sql[] = $sid_sql;
517
- }
518
-
519
- if ( empty($filter_sql) )
520
- return false;
521
-
522
- return join( ' AND ', $filter_sql );
523
- }
524
-
525
- function get_last_updated() {
526
- global $bp, $wpdb;
527
-
528
- return $wpdb->get_var( $wpdb->prepare( "SELECT date_recorded FROM {$bp->activity->table_name} ORDER BY date_recorded ASC LIMIT 1" ) );
529
- }
530
-
531
- function total_favorite_count( $user_id ) {
532
- global $bp;
533
-
534
- if ( !$favorite_activity_entries = get_usermeta( $user_id, 'bp_favorite_activities' ) )
535
- return 0;
536
-
537
- return count( maybe_unserialize( $favorite_activity_entries ) );
538
- }
539
-
540
- function check_exists_by_content( $content ) {
541
- global $wpdb, $bp;
542
-
543
- return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE content = %s", $content ) );
544
- }
545
-
546
- function hide_all_for_user( $user_id ) {
547
- global $wpdb, $bp;
548
-
549
- return $wpdb->get_var( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET hide_sitewide = 1 WHERE user_id = %d", $user_id ) );
550
- }
551
- }
552
-
553
  ?>
1
+ <?php
2
+
3
+ Class BP_Activity_Activity {
4
+ var $id;
5
+ var $item_id;
6
+ var $secondary_item_id;
7
+ var $user_id;
8
+ var $primary_link;
9
+ var $component;
10
+ var $type;
11
+ var $action;
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
+ }
23
+ }
24
+
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;
67
+
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
75
+ $q = $wpdb->prepare( "INSERT INTO {$bp->activity->table_name} ( user_id, component, type, action, content, primary_link, date_recorded, item_id, secondary_item_id, hide_sitewide ) VALUES ( %d, %s, %s, %s, %s, %s, %s, %s, %s, %d )", $this->user_id, $this->component, $this->type, $this->action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide );
76
+
77
+ if ( !$wpdb->query( $q ) )
78
+ return false;
79
+
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;
138
+ }
139
+
140
+ $activity_user_ids = implode( ',', array_unique( (array)$activity_user_ids ) );
141
+ if ( !empty( $activity_user_ids ) ) {
142
+ if ( $names = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, value AS user_fullname FROM {$bp->profile->table_name_data} WHERE field_id = 1 AND user_id IN ({$activity_user_ids})" ) ) ) {
143
+ foreach ( (array)$names as $name )
144
+ $tmp_names[$name->user_id] = $name->user_fullname;
145
+
146
+ foreach ( (array)$activities as $i => $activity ) {
147
+ if ( !empty( $tmp_names[$activity->user_id] ) )
148
+ $activities[$i]->user_fullname = $tmp_names[$activity->user_id];
149
+ }
150
+
151
+ unset( $names );
152
+ unset( $tmp_names );
153
+ }
154
+ }
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;
164
+ }
165
+
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 ) {
170
+ global $wpdb, $bp;
171
+
172
+ if ( is_array( $activity_ids ) )
173
+ $activity_ids = implode( ',', $activity_ids );
174
+
175
+ $activity_ids = $wpdb->escape( $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
+ $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id IN ({$activity_ids}) ORDER BY date_recorded {$sort} $pag_sql" ) );
187
+ $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE id IN ({$activity_ids})" ) );
188
+
189
+ if ( $display_comments )
190
+ $activities = BP_Activity_Activity::append_comments( $activities );
191
+
192
+ /* If $max is set, only return up to the max results */
193
+ if ( !empty( $max ) ) {
194
+ if ( (int)$total_activities > (int)$max )
195
+ $total_activities = $max;
196
+ }
197
+
198
+ return array( 'activities' => $activities, 'total' => (int)$total_activities );
199
+ }
200
+
201
+ function get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content, $date_recorded ) {
202
+ global $bp, $wpdb;
203
+
204
+ $where_args = false;
205
+
206
+ if ( !empty( $user_id ) )
207
+ $where_args[] = $wpdb->prepare( "user_id = %d", $user_id );
208
+
209
+ if ( !empty( $component ) )
210
+ $where_args[] = $wpdb->prepare( "component = %s", $component );
211
+
212
+ if ( !empty( $type ) )
213
+ $where_args[] = $wpdb->prepare( "type = %s", $type );
214
+
215
+ if ( !empty( $item_id ) )
216
+ $where_args[] = $wpdb->prepare( "item_id = %s", $item_id );
217
+
218
+ if ( !empty( $secondary_item_id ) )
219
+ $where_args[] = $wpdb->prepare( "secondary_item_id = %s", $secondary_item_id );
220
+
221
+ if ( !empty( $action ) )
222
+ $where_args[] = $wpdb->prepare( "action = %s", $action );
223
+
224
+ if ( !empty( $content ) )
225
+ $where_args[] = $wpdb->prepare( "content = %s", $content );
226
+
227
+ if ( !empty( $date_recorded ) )
228
+ $where_args[] = $wpdb->prepare( "date_recorded = %s", $date_recorded );
229
+
230
+ if ( !empty( $where_args ) )
231
+ $where_sql = 'WHERE ' . join( ' AND ', $where_args );
232
+ else
233
+ return false;
234
+
235
+ return $wpdb->get_var( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" );
236
+ }
237
+
238
+ function delete( $args ) {
239
+ global $wpdb, $bp;
240
+
241
+ extract( $args );
242
+
243
+ $defaults = array(
244
+ 'id' => false,
245
+ 'action' => false,
246
+ 'content' => false,
247
+ 'component' => false,
248
+ 'type' => false,
249
+ 'primary_link' => false,
250
+ 'user_id' => false,
251
+ 'item_id' => false,
252
+ 'secondary_item_id' => false,
253
+ 'date_recorded' => false,
254
+ 'hide_sitewide' => false
255
+ );
256
+
257
+ $where_args = false;
258
+
259
+ if ( !empty( $id ) )
260
+ $where_args[] = $wpdb->prepare( "id = %d", $id );
261
+
262
+ if ( !empty( $user_id ) )
263
+ $where_args[] = $wpdb->prepare( "user_id = %d", $user_id );
264
+
265
+ if ( !empty( $action ) )
266
+ $where_args[] = $wpdb->prepare( "action = %s", $action );
267
+
268
+ if ( !empty( $content ) )
269
+ $where_args[] = $wpdb->prepare( "content = %s", $content );
270
+
271
+ if ( !empty( $component ) )
272
+ $where_args[] = $wpdb->prepare( "component = %s", $component );
273
+
274
+ if ( !empty( $type ) )
275
+ $where_args[] = $wpdb->prepare( "type = %s", $type );
276
+
277
+ if ( !empty( $primary_link ) )
278
+ $where_args[] = $wpdb->prepare( "primary_link = %s", $primary_link );
279
+
280
+ if ( !empty( $item_id ) )
281
+ $where_args[] = $wpdb->prepare( "item_id = %s", $item_id );
282
+
283
+ if ( !empty( $secondary_item_id ) )
284
+ $where_args[] = $wpdb->prepare( "secondary_item_id = %s", $secondary_item_id );
285
+
286
+ if ( !empty( $date_recorded ) )
287
+ $where_args[] = $wpdb->prepare( "date_recorded = %s", $date_recorded );
288
+
289
+ if ( !empty( $hide_sitewide ) )
290
+ $where_args[] = $wpdb->prepare( "hide_sitewide = %d", $hide_sitewide );
291
+
292
+ if ( !empty( $where_args ) )
293
+ $where_sql = 'WHERE ' . join( ' AND ', $where_args );
294
+ else
295
+ return false;
296
+
297
+ /* Fetch the activity IDs so we can delete any comments for this activity item */
298
+ $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" ) );
299
+
300
+ if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} {$where_sql}" ) ) )
301
+ return false;
302
+
303
+ if ( $activity_ids ) {
304
+ BP_Activity_Activity::delete_activity_item_comments( $activity_ids );
305
+ BP_Activity_Activity::delete_activity_meta_entries( $activity_ids );
306
+
307
+ return $activity_ids;
308
+ }
309
+
310
+ return $activity_ids;
311
+ }
312
+
313
+ function delete_activity_item_comments( $activity_ids ) {
314
+ global $bp, $wpdb;
315
+
316
+ if ( is_array($activity_ids) )
317
+ $activity_ids = implode( ',', $activity_ids );
318
+
319
+ $activity_ids = $wpdb->escape( $activity_ids );
320
+
321
+ return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND item_id IN ({$activity_ids})" ) );
322
+ }
323
+
324
+ function delete_activity_meta_entries( $activity_ids ) {
325
+ global $bp, $wpdb;
326
+
327
+ if ( is_array($activity_ids) )
328
+ $activity_ids = implode( ',', $activity_ids );
329
+
330
+ $activity_ids = $wpdb->escape( $activity_ids );
331
+
332
+ return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id IN ({$activity_ids})" ) );
333
+ }
334
+
335
+ function append_comments( $activities ) {
336
+ global $bp, $wpdb;
337
+
338
+ /* Now fetch the activity comments and parse them into the correct position in the activities array. */
339
+ foreach( (array)$activities as $activity ) {
340
+ if ( 'activity_comment' != $activity->type && $activity->mptt_left && $activity->mptt_right )
341
+ $activity_comments[$activity->id] = BP_Activity_Activity::get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right );
342
+ }
343
+
344
+ /* Merge the comments with the activity items */
345
+ foreach( (array)$activities as $key => $activity )
346
+ $activities[$key]->children = $activity_comments[$activity->id];
347
+
348
+ return $activities;
349
+ }
350
+
351
+ function get_activity_comments( $activity_id, $left, $right ) {
352
+ global $wpdb, $bp;
353
+
354
+ if ( !$comments = wp_cache_get( 'bp_activity_comments_' . $activity_id ) ) {
355
+ /* Select the user's fullname with the query so we don't have to fetch it for each comment */
356
+ if ( function_exists( 'xprofile_install' ) ) {
357
+ $fullname_select = ", pd.value as user_fullname";
358
+ $fullname_from = ", {$bp->profile->table_name_data} pd ";
359
+ $fullname_where = "AND pd.user_id = a.user_id AND pd.field_id = 1";
360
+ }
361
+
362
+ /* Retrieve all descendants of the $root node */
363
+ $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 ) );
364
+
365
+ /* Loop descendants and build an assoc array */
366
+ foreach ( (array)$descendants as $d ) {
367
+ $d->children = array();
368
+
369
+ /* If we have a reference on the parent */
370
+ if ( isset( $ref[ $d->secondary_item_id ] ) ) {
371
+ $ref[ $d->secondary_item_id ]->children[ $d->id ] = $d;
372
+ $ref[ $d->id ] =& $ref[ $d->secondary_item_id ]->children[ $d->id ];
373
+
374
+ /* If we don't have a reference on the parent, put in the root level */
375
+ } else {
376
+ $comments[ $d->id ] = $d;
377
+ $ref[ $d->id ] =& $comments[ $d->id ];
378
+ }
379
+ }
380
+ wp_cache_set( 'bp_activity_comments_' . $activity_id, $comments, 'bp' );
381
+ }
382
+
383
+ return $comments;
384
+ }
385
+
386
+ function rebuild_activity_comment_tree( $parent_id, $left = 1 ) {
387
+ global $wpdb, $bp;
388
+
389
+ /* The right value of this node is the left value + 1 */
390
+ $right = $left + 1;
391
+
392
+ /* Get all descendants of this node */
393
+ $descendants = BP_Activity_Activity::get_child_comments( $parent_id );
394
+
395
+ /* Loop the descendants and recalculate the left and right values */
396
+ foreach ( (array)$descendants as $descendant )
397
+ $right = BP_Activity_Activity::rebuild_activity_comment_tree( $descendant->id, $right );
398
+
399
+ /* We've got the left value, and now that we've processed the children of this node we also know the right value */
400
+ if ( 1 == $left )
401
+ $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE id = %d", $left, $right, $parent_id ) );
402
+ else
403
+ $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 ) );
404
+
405
+ /* Return the right value of this node + 1 */
406
+ return $right + 1;
407
+ }
408
+
409
+ function get_child_comments( $parent_id ) {
410
+ global $bp, $wpdb;
411
+
412
+ return $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND secondary_item_id = %d", $parent_id ) );
413
+ }
414
+
415
+ function get_recorded_components() {
416
+ global $wpdb, $bp;
417
+
418
+ return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT component FROM {$bp->activity->table_name} ORDER BY component ASC" ) );
419
+ }
420
+
421
+ function get_sitewide_items_for_feed( $limit = 35 ) {
422
+ global $wpdb, $bp;
423
+
424
+ $activities = bp_activity_get_sitewide( array( 'max' => $limit ) );
425
+
426
+ for ( $i = 0; $i < count($activities); $i++ ) {
427
+ $title = explode( '<span', $activities[$i]['content'] );
428
+
429
+ $activity_feed[$i]['title'] = trim( strip_tags( $title[0] ) );
430
+ $activity_feed[$i]['link'] = $activities[$i]['primary_link'];
431
+ $activity_feed[$i]['description'] = @sprintf( $activities[$i]['content'], '' );
432
+ $activity_feed[$i]['pubdate'] = $activities[$i]['date_recorded'];
433
+ }
434
+
435
+ return $activity_feed;
436
+ }
437
+
438
+ function get_filter_sql( $filter_array ) {
439
+ global $wpdb;
440
+
441
+ if ( !empty( $filter_array['user_id'] ) ) {
442
+ $user_filter = explode( ',', $filter_array['user_id'] );
443
+ $user_sql = ' ( a.user_id IN ( ' . $filter_array['user_id'] . ' ) )';
444
+ $filter_sql[] = $user_sql;
445
+ }
446
+
447
+ if ( !empty( $filter_array['object'] ) ) {
448
+ $object_filter = explode( ',', $filter_array['object'] );
449
+ $object_sql = ' ( ';
450
+
451
+ $counter = 1;
452
+ foreach( (array) $object_filter as $object ) {
453
+ $object_sql .= $wpdb->prepare( "a.component = %s", trim( $object ) );
454
+
455
+ if ( $counter != count( $object_filter ) )
456
+ $object_sql .= ' || ';
457
+
458
+ $counter++;
459
+ }
460
+
461
+ $object_sql .= ' )';
462
+ $filter_sql[] = $object_sql;
463
+ }
464
+
465
+ if ( !empty( $filter_array['action'] ) ) {
466
+ $action_filter = explode( ',', $filter_array['action'] );
467
+ $action_sql = ' ( ';
468
+
469
+ $counter = 1;
470
+ foreach( (array) $action_filter as $action ) {
471
+ $action_sql .= $wpdb->prepare( "a.type = %s", trim( $action ) );
472
+
473
+ if ( $counter != count( $action_filter ) )
474
+ $action_sql .= ' || ';
475
+
476
+ $counter++;
477
+ }
478
+
479
+ $action_sql .= ' )';
480
+ $filter_sql[] = $action_sql;
481
+ }
482
+
483
+ if ( !empty( $filter_array['primary_id'] ) ) {
484
+ $pid_filter = explode( ',', $filter_array['primary_id'] );
485
+ $pid_sql = ' ( ';
486
+
487
+ $counter = 1;
488
+ foreach( (array) $pid_filter as $pid ) {
489
+ $pid_sql .= $wpdb->prepare( "a.item_id = %s", trim( $pid ) );
490
+
491
+ if ( $counter != count( $pid_filter ) )
492
+ $pid_sql .= ' || ';
493
+
494
+ $counter++;
495
+ }
496
+
497
+ $pid_sql .= ' )';
498
+ $filter_sql[] = $pid_sql;
499
+ }
500
+
501
+ if ( !empty( $filter_array['secondary_id'] ) ) {
502
+ $sid_filter = explode( ',', $filter_array['secondary_id'] );
503
+ $sid_sql = ' ( ';
504
+
505
+ $counter = 1;
506
+ foreach( (array) $sid_filter as $sid ) {
507
+ $sid_sql .= $wpdb->prepare( "a.secondary_item_id = %s", trim( $sid ) );
508
+
509
+ if ( $counter != count( $sid_filter ) )
510
+ $sid_sql .= ' || ';
511
+
512
+ $counter++;
513
+ }
514
+
515
+ $sid_sql .= ' )';
516
+ $filter_sql[] = $sid_sql;
517
+ }
518
+
519
+ if ( empty($filter_sql) )
520
+ return false;
521
+
522
+ return join( ' AND ', $filter_sql );
523
+ }
524
+
525
+ function get_last_updated() {
526
+ global $bp, $wpdb;
527
+
528
+ return $wpdb->get_var( $wpdb->prepare( "SELECT date_recorded FROM {$bp->activity->table_name} ORDER BY date_recorded ASC LIMIT 1" ) );
529
+ }
530
+
531
+ function total_favorite_count( $user_id ) {
532
+ global $bp;
533
+
534
+ if ( !$favorite_activity_entries = get_usermeta( $user_id, 'bp_favorite_activities' ) )
535
+ return 0;
536
+
537
+ return count( maybe_unserialize( $favorite_activity_entries ) );
538
+ }
539
+
540
+ function check_exists_by_content( $content ) {
541
+ global $wpdb, $bp;
542
+
543
+ return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE content = %s", $content ) );
544
+ }
545
+
546
+ function hide_all_for_user( $user_id ) {
547
+ global $wpdb, $bp;
548
+
549
+ return $wpdb->get_var( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET hide_sitewide = 1 WHERE user_id = %d", $user_id ) );
550
+ }
551
+ }
552
+
553
  ?>
bp-activity/bp-activity-filters.php CHANGED
@@ -1,132 +1,141 @@
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 );
7
- add_filter( 'bp_get_activity_parent_content', 'bp_activity_filter_kses', 1 );
8
- add_filter( 'bp_get_activity_latest_update', 'bp_activity_filter_kses', 1 );
9
- add_filter( 'bp_get_activity_feed_item_description', 'bp_activity_filter_kses', 1 );
10
- add_filter( 'bp_activity_content_before_save', 'bp_activity_filter_kses', 1 );
11
- add_filter( 'bp_activity_action_before_save', 'bp_activity_filter_kses', 1 );
12
-
13
- add_filter( 'bp_get_activity_action', 'force_balance_tags' );
14
- add_filter( 'bp_get_activity_content_body', 'force_balance_tags' );
15
- add_filter( 'bp_get_activity_content', 'force_balance_tags' );
16
- add_filter( 'bp_get_activity_latest_update', 'force_balance_tags' );
17
- add_filter( 'bp_get_activity_feed_item_description', 'force_balance_tags' );
18
-
19
- add_filter( 'bp_get_activity_action', 'wptexturize' );
20
- add_filter( 'bp_get_activity_content_body', 'wptexturize' );
21
- add_filter( 'bp_get_activity_content', 'wptexturize' );
22
- add_filter( 'bp_get_activity_parent_content', 'wptexturize' );
23
- add_filter( 'bp_get_activity_latest_update', 'wptexturize' );
24
-
25
- add_filter( 'bp_get_activity_action', 'convert_smilies' );
26
- add_filter( 'bp_get_activity_content_body', 'convert_smilies' );
27
- add_filter( 'bp_get_activity_content', 'convert_smilies' );
28
- add_filter( 'bp_get_activity_parent_content', 'convert_smilies' );
29
- add_filter( 'bp_get_activity_latest_update', 'convert_smilies' );
30
-
31
- add_filter( 'bp_get_activity_action', 'convert_chars' );
32
- add_filter( 'bp_get_activity_content_body', 'convert_chars' );
33
- add_filter( 'bp_get_activity_content', 'convert_chars' );
34
- add_filter( 'bp_get_activity_parent_content', 'convert_chars' );
35
- add_filter( 'bp_get_activity_latest_update', 'convert_chars' );
36
-
37
- add_filter( 'bp_get_activity_action', 'wpautop' );
38
- add_filter( 'bp_get_activity_content_body', 'wpautop' );
39
- add_filter( 'bp_get_activity_content', 'wpautop' );
40
- add_filter( 'bp_get_activity_feed_item_description', 'wpautop' );
41
-
42
- add_filter( 'bp_get_activity_action', 'make_clickable' );
43
- add_filter( 'bp_get_activity_content_body', 'make_clickable' );
44
- add_filter( 'bp_get_activity_content', 'make_clickable' );
45
- add_filter( 'bp_get_activity_parent_content', 'make_clickable' );
46
- add_filter( 'bp_get_activity_latest_update', 'make_clickable' );
47
- add_filter( 'bp_get_activity_feed_item_description', 'make_clickable' );
48
-
49
- add_filter( 'bp_get_activity_action', 'stripslashes_deep' );
50
- add_filter( 'bp_get_activity_content', 'stripslashes_deep' );
51
- add_filter( 'bp_get_activity_content_body', 'stripslashes_deep' );
52
- add_filter( 'bp_get_activity_parent_content', 'stripslashes_deep' );
53
- add_filter( 'bp_get_activity_latest_update', 'stripslashes_deep' );
54
- add_filter( 'bp_get_activity_feed_item_description', 'stripslashes_deep' );
55
-
56
- add_filter( 'bp_get_activity_content', 'bp_activity_make_nofollow_filter' );
57
- add_filter( 'bp_get_activity_content_body', 'bp_activity_make_nofollow_filter' );
58
- add_filter( 'bp_get_activity_parent_content', 'bp_activity_make_nofollow_filter' );
59
- add_filter( 'bp_get_activity_latest_update', 'bp_activity_make_nofollow_filter' );
60
- add_filter( 'bp_get_activity_feed_item_description', 'bp_activity_make_nofollow_filter' );
61
-
62
- add_filter( 'bp_get_activity_parent_content', 'bp_create_excerpt' );
63
-
64
- /* Allow shortcodes in activity posts */
65
- add_filter( 'bp_get_activity_content', 'do_shortcode' );
66
- add_filter( 'bp_get_activity_content_body', 'do_shortcode' );
67
-
68
- function bp_activity_filter_kses( $content ) {
69
- global $allowedtags;
70
-
71
- $activity_allowedtags = $allowedtags;
72
- $activity_allowedtags['span'] = array();
73
- $activity_allowedtags['span']['class'] = array();
74
- $activity_allowedtags['div'] = array();
75
- $activity_allowedtags['div']['class'] = array();
76
- $activity_allowedtags['div']['id'] = array();
77
- $activity_allowedtags['a']['class'] = array();
78
- $activity_allowedtags['img'] = array();
79
- $activity_allowedtags['img']['src'] = array();
80
- $activity_allowedtags['img']['alt'] = array();
81
- $activity_allowedtags['img']['class'] = array();
82
- $activity_allowedtags['img']['width'] = array();
83
- $activity_allowedtags['img']['height'] = array();
84
- $activity_allowedtags['img']['class'] = array();
85
- $activity_allowedtags['img']['id'] = array();
86
- $activity_allowedtags['img']['title'] = array();
87
- $activity_allowedtags['code'] = array();
88
-
89
- $activity_allowedtags = apply_filters( 'bp_activity_allowed_tags', $activity_allowedtags );
90
- return wp_kses( $content, $activity_allowedtags );
91
- }
92
-
93
- function bp_activity_at_name_filter( $content ) {
94
- include_once( ABSPATH . WPINC . '/registration.php' );
95
-
96
- $pattern = '/[@]+([A-Za-z0-9-_]+)/';
97
- preg_match_all( $pattern, $content, $usernames );
98
-
99
- /* Make sure there's only one instance of each username */
100
- if ( !$usernames = array_unique( $usernames[1] ) )
101
- return $content;
102
-
103
- foreach( (array)$usernames as $username ) {
104
- if ( !$user_id = username_exists( $username ) )
105
- continue;
106
-
107
- /* Increase the number of new @ mentions for the user */
108
- $new_mention_count = (int)get_usermeta( $user_id, 'bp_new_mention_count' );
109
- update_usermeta( $user_id, 'bp_new_mention_count', $new_mention_count + 1 );
110
-
111
- $content = str_replace( "@$username", "<a href='" . bp_core_get_user_domain( bp_core_get_userid( $username ) ) . "' rel='nofollow'>@$username</a>", $content );
112
- }
113
-
114
- return $content;
115
- }
116
- add_filter( 'bp_activity_new_update_content', 'bp_activity_at_name_filter' );
117
- add_filter( 'groups_activity_new_update_content', 'bp_activity_at_name_filter' );
118
- add_filter( 'pre_comment_content', 'bp_activity_at_name_filter' );
119
- add_filter( 'group_forum_topic_text_before_save', 'bp_activity_at_name_filter' );
120
- add_filter( 'group_forum_post_text_before_save', 'bp_activity_at_name_filter' );
121
- add_filter( 'bp_activity_comment_content', 'bp_activity_at_name_filter' );
122
-
123
- function bp_activity_make_nofollow_filter( $text ) {
124
- return preg_replace_callback( '|<a (.+?)>|i', 'bp_activity_make_nofollow_filter_callback', $text );
125
- }
126
- function bp_activity_make_nofollow_filter_callback( $matches ) {
127
- $text = $matches[1];
128
- $text = str_replace( array( ' rel="nofollow"', " rel='nofollow'"), '', $text );
129
- return "<a $text rel=\"nofollow\">";
130
- }
131
-
 
 
 
 
 
 
 
 
 
132
  ?>
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 );
7
+ add_filter( 'bp_get_activity_parent_content', 'bp_activity_filter_kses', 1 );
8
+ add_filter( 'bp_get_activity_latest_update', 'bp_activity_filter_kses', 1 );
9
+ add_filter( 'bp_get_activity_latest_update_excerpt', 'bp_activity_filter_kses', 1 );
10
+ add_filter( 'bp_get_activity_feed_item_description', 'bp_activity_filter_kses', 1 );
11
+ add_filter( 'bp_activity_content_before_save', 'bp_activity_filter_kses', 1 );
12
+ add_filter( 'bp_activity_action_before_save', 'bp_activity_filter_kses', 1 );
13
+
14
+ add_filter( 'bp_get_activity_action', 'force_balance_tags' );
15
+ add_filter( 'bp_get_activity_content_body', 'force_balance_tags' );
16
+ add_filter( 'bp_get_activity_content', 'force_balance_tags' );
17
+ add_filter( 'bp_get_activity_latest_update', 'force_balance_tags' );
18
+ add_filter( 'bp_get_activity_latest_update_excerpt', 'force_balance_tags' );
19
+ add_filter( 'bp_get_activity_feed_item_description', 'force_balance_tags' );
20
+
21
+ add_filter( 'bp_get_activity_action', 'wptexturize' );
22
+ add_filter( 'bp_get_activity_content_body', 'wptexturize' );
23
+ add_filter( 'bp_get_activity_content', 'wptexturize' );
24
+ add_filter( 'bp_get_activity_parent_content', 'wptexturize' );
25
+ add_filter( 'bp_get_activity_latest_update', 'wptexturize' );
26
+ add_filter( 'bp_get_activity_latest_update_excerpt', 'wptexturize' );
27
+
28
+ add_filter( 'bp_get_activity_action', 'convert_smilies' );
29
+ add_filter( 'bp_get_activity_content_body', 'convert_smilies' );
30
+ add_filter( 'bp_get_activity_content', 'convert_smilies' );
31
+ add_filter( 'bp_get_activity_parent_content', 'convert_smilies' );
32
+ add_filter( 'bp_get_activity_latest_update', 'convert_smilies' );
33
+ add_filter( 'bp_get_activity_latest_update_excerpt', 'convert_smilies' );
34
+
35
+ add_filter( 'bp_get_activity_action', 'convert_chars' );
36
+ add_filter( 'bp_get_activity_content_body', 'convert_chars' );
37
+ add_filter( 'bp_get_activity_content', 'convert_chars' );
38
+ add_filter( 'bp_get_activity_parent_content', 'convert_chars' );
39
+ add_filter( 'bp_get_activity_latest_update', 'convert_chars' );
40
+ add_filter( 'bp_get_activity_latest_update_excerpt', 'convert_chars' );
41
+
42
+ add_filter( 'bp_get_activity_action', 'wpautop' );
43
+ add_filter( 'bp_get_activity_content_body', 'wpautop' );
44
+ add_filter( 'bp_get_activity_content', 'wpautop' );
45
+ add_filter( 'bp_get_activity_feed_item_description', 'wpautop' );
46
+
47
+ add_filter( 'bp_get_activity_action', 'make_clickable' );
48
+ add_filter( 'bp_get_activity_content_body', 'make_clickable' );
49
+ add_filter( 'bp_get_activity_content', 'make_clickable' );
50
+ add_filter( 'bp_get_activity_parent_content', 'make_clickable' );
51
+ add_filter( 'bp_get_activity_latest_update', 'make_clickable' );
52
+ add_filter( 'bp_get_activity_latest_update_excerpt', 'make_clickable' );
53
+ add_filter( 'bp_get_activity_feed_item_description', 'make_clickable' );
54
+
55
+ add_filter( 'bp_acomment_name', 'stripslashes_deep' );
56
+ add_filter( 'bp_get_activity_action', 'stripslashes_deep' );
57
+ add_filter( 'bp_get_activity_content', 'stripslashes_deep' );
58
+ add_filter( 'bp_get_activity_content_body', 'stripslashes_deep' );
59
+ add_filter( 'bp_get_activity_parent_content', 'stripslashes_deep' );
60
+ add_filter( 'bp_get_activity_latest_update', 'stripslashes_deep' );
61
+ add_filter( 'bp_get_activity_latest_update_excerpt', 'stripslashes_deep' );
62
+ add_filter( 'bp_get_activity_feed_item_description', 'stripslashes_deep' );
63
+
64
+ add_filter( 'bp_get_activity_content', 'bp_activity_make_nofollow_filter' );
65
+ add_filter( 'bp_get_activity_content_body', 'bp_activity_make_nofollow_filter' );
66
+ add_filter( 'bp_get_activity_parent_content', 'bp_activity_make_nofollow_filter' );
67
+ add_filter( 'bp_get_activity_latest_update', 'bp_activity_make_nofollow_filter' );
68
+ add_filter( 'bp_get_activity_latest_update_excerpt', 'bp_activity_make_nofollow_filter' );
69
+ add_filter( 'bp_get_activity_feed_item_description', 'bp_activity_make_nofollow_filter' );
70
+
71
+ add_filter( 'bp_get_activity_parent_content', 'bp_create_excerpt' );
72
+
73
+ /* Allow shortcodes in activity posts */
74
+ add_filter( 'bp_get_activity_content', 'do_shortcode' );
75
+ add_filter( 'bp_get_activity_content_body', 'do_shortcode' );
76
+
77
+ function bp_activity_filter_kses( $content ) {
78
+ global $allowedtags;
79
+
80
+ $activity_allowedtags = $allowedtags;
81
+ $activity_allowedtags['span'] = array();
82
+ $activity_allowedtags['span']['class'] = array();
83
+ $activity_allowedtags['div'] = array();
84
+ $activity_allowedtags['div']['class'] = array();
85
+ $activity_allowedtags['div']['id'] = array();
86
+ $activity_allowedtags['a']['class'] = array();
87
+ $activity_allowedtags['img'] = array();
88
+ $activity_allowedtags['img']['src'] = array();
89
+ $activity_allowedtags['img']['alt'] = array();
90
+ $activity_allowedtags['img']['class'] = array();
91
+ $activity_allowedtags['img']['width'] = array();
92
+ $activity_allowedtags['img']['height'] = array();
93
+ $activity_allowedtags['img']['class'] = array();
94
+ $activity_allowedtags['img']['id'] = array();
95
+ $activity_allowedtags['img']['title'] = array();
96
+ $activity_allowedtags['code'] = array();
97
+
98
+ $activity_allowedtags = apply_filters( 'bp_activity_allowed_tags', $activity_allowedtags );
99
+ return wp_kses( $content, $activity_allowedtags );
100
+ }
101
+
102
+ function bp_activity_at_name_filter( $content ) {
103
+ include_once( ABSPATH . WPINC . '/registration.php' );
104
+
105
+ $pattern = '/[@]+([A-Za-z0-9-_]+)/';
106
+ preg_match_all( $pattern, $content, $usernames );
107
+
108
+ /* Make sure there's only one instance of each username */
109
+ if ( !$usernames = array_unique( $usernames[1] ) )
110
+ return $content;
111
+
112
+ foreach( (array)$usernames as $username ) {
113
+ if ( !$user_id = username_exists( $username ) )
114
+ continue;
115
+
116
+ /* Increase the number of new @ mentions for the user */
117
+ $new_mention_count = (int)get_usermeta( $user_id, 'bp_new_mention_count' );
118
+ update_usermeta( $user_id, 'bp_new_mention_count', $new_mention_count + 1 );
119
+
120
+ $content = str_replace( "@$username", "<a href='" . bp_core_get_user_domain( bp_core_get_userid( $username ) ) . "' rel='nofollow'>@$username</a>", $content );
121
+ }
122
+
123
+ return $content;
124
+ }
125
+ add_filter( 'bp_activity_new_update_content', 'bp_activity_at_name_filter' );
126
+ add_filter( 'groups_activity_new_update_content', 'bp_activity_at_name_filter' );
127
+ add_filter( 'pre_comment_content', 'bp_activity_at_name_filter' );
128
+ add_filter( 'group_forum_topic_text_before_save', 'bp_activity_at_name_filter' );
129
+ add_filter( 'group_forum_post_text_before_save', 'bp_activity_at_name_filter' );
130
+ add_filter( 'bp_activity_comment_content', 'bp_activity_at_name_filter' );
131
+
132
+ function bp_activity_make_nofollow_filter( $text ) {
133
+ return preg_replace_callback( '|<a (.+?)>|i', 'bp_activity_make_nofollow_filter_callback', $text );
134
+ }
135
+ function bp_activity_make_nofollow_filter_callback( $matches ) {
136
+ $text = $matches[1];
137
+ $text = str_replace( array( ' rel="nofollow"', " rel='nofollow'"), '', $text );
138
+ return "<a $text rel=\"nofollow\">";
139
+ }
140
+
141
  ?>
bp-activity/bp-activity-templatetags.php CHANGED
@@ -1,954 +1,954 @@
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_usermeta( $bp->loggedin_user->id, 'bp_favorite_activities' ) );
29
-
30
- if ( !empty( $include ) ) {
31
- /* Fetch specific activity items based on ID's */
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 ) );
33
- } else {
34
- $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 ) );
35
- }
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
- } else {
50
- $this->activity_count = count($this->activities);
51
- }
52
-
53
- $this->full_name = $bp->displayed_user->fullname;
54
-
55
- /* Fetch parent content for activity comments so we do not have to query in the loop */
56
- foreach ( (array)$this->activities as $activity ) {
57
- if ( 'activity_comment' != $activity->type ) continue;
58
- $parent_ids[] = $activity->item_id;
59
- }
60
-
61
- if ( !empty( $parent_ids ) )
62
- $activity_parents = bp_activity_get_specific( array( 'activity_ids' => $parent_ids ) );
63
-
64
- if ( !empty( $activity_parents['activities'] ) ) {
65
- foreach( $activity_parents['activities'] as $parent ) $this->activity_parents[$parent->id] = $parent;
66
- unset( $activity_parents );
67
- }
68
-
69
- if ( (int) $this->total_activity_count && (int) $this->pag_num ) {
70
- $this->pag_links = paginate_links( array(
71
- 'base' => add_query_arg( 'acpage', '%#%' ),
72
- 'format' => '',
73
- 'total' => ceil( (int)$this->total_activity_count / (int)$this->pag_num ),
74
- 'current' => (int)$this->pag_page,
75
- 'prev_text' => '&larr;',
76
- 'next_text' => '&rarr;',
77
- 'mid_size' => 1
78
- ));
79
- }
80
- }
81
-
82
- function has_activities() {
83
- if ( $this->activity_count )
84
- return true;
85
-
86
- return false;
87
- }
88
-
89
- function next_activity() {
90
- $this->current_activity++;
91
- $this->activity = $this->activities[$this->current_activity];
92
-
93
- return $this->activity;
94
- }
95
-
96
- function rewind_activities() {
97
- $this->current_activity = -1;
98
- if ( $this->activity_count > 0 ) {
99
- $this->activity = $this->activities[0];
100
- }
101
- }
102
-
103
- function user_activities() {
104
- if ( $this->current_activity + 1 < $this->activity_count ) {
105
- return true;
106
- } elseif ( $this->current_activity + 1 == $this->activity_count ) {
107
- do_action('activity_loop_end');
108
- // Do some cleaning up after the loop
109
- $this->rewind_activities();
110
- }
111
-
112
- $this->in_the_loop = false;
113
- return false;
114
- }
115
-
116
- function the_activity() {
117
- global $activity;
118
-
119
- $this->in_the_loop = true;
120
- $this->activity = $this->next_activity();
121
-
122
- if ( is_array( $this->activity ) )
123
- $this->activity = (object) $this->activity;
124
-
125
- if ( $this->current_activity == 0 ) // loop has just started
126
- do_action('activity_loop_start');
127
- }
128
- }
129
-
130
- function bp_has_activities( $args = '' ) {
131
- global $bp, $activities_template;
132
-
133
- /***
134
- * Set the defaults based on the current page. Any of these will be overridden
135
- * if arguments are directly passed into the loop. Custom plugins should always
136
- * pass their parameters directly to the loop.
137
- */
138
- $user_id = false;
139
- $include = false;
140
- $show_hidden = false;
141
- $object = false;
142
- $primary_id = false;
143
-
144
- /* User filtering */
145
- if ( !empty( $bp->displayed_user->id ) )
146
- $user_id = $bp->displayed_user->id;
147
-
148
- /* Group filtering */
149
- if ( !empty( $bp->groups->current_group ) ) {
150
- $object = $bp->groups->id;
151
- $primary_id = $bp->groups->current_group->id;
152
-
153
- if ( 'public' != $bp->groups->current_group->status && groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
154
- $show_hidden = true;
155
- }
156
-
157
- /* Support for permalinks on single item pages: /groups/my-group/activity/124/ */
158
- if ( $bp->current_action == $bp->activity->slug )
159
- $include = $bp->action_variables[0];
160
-
161
- /* Note: any params used for filtering can be a single value, or multiple values comma separated. */
162
- $defaults = array(
163
- 'display_comments' => 'threaded', // false for none, stream/threaded - show comments in the stream or threaded under items
164
- 'include' => $include, // pass an activity_id or string of ID's comma separated
165
- 'sort' => 'DESC', // sort DESC or ASC
166
- 'page' => 1, // which page to load
167
- 'per_page' => 20, // number of items per page
168
- 'max' => false, // max number to return
169
- 'show_hidden' => $show_hidden, // Show activity items that are hidden site-wide?
170
-
171
- /* Scope - pre-built activity filters for a user (friends/groups/favorites/mentions) */
172
- 'scope' => $bp->current_action,
173
-
174
- /* Filtering */
175
- 'user_id' => $user_id, // user_id to filter on
176
- 'object' => $object, // object to filter on e.g. groups, profile, status, friends
177
- 'action' => false, // action to filter on e.g. activity_update, new_forum_post, profile_updated
178
- 'primary_id' => $primary_id, // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
179
- 'secondary_id' => false, // secondary object ID to filter on e.g. a post_id
180
-
181
- /* Searching */
182
- 'search_terms' => false // specify terms to search on
183
- );
184
-
185
- $r = wp_parse_args( $args, $defaults );
186
- extract( $r );
187
-
188
- /* If you have passed a "scope" then this will override any filters you have passed. */
189
- if ( 'just-me' == $scope || 'friends' == $scope || 'groups' == $scope || 'favorites' == $scope || 'mentions' == $scope ) {
190
- if ( 'just-me' == $scope )
191
- $display_comments = 'stream';
192
-
193
- if ( $user_id = ( !empty( $bp->displayed_user->id ) ) ? $bp->displayed_user->id : $bp->loggedin_user->id ) {
194
- $show_hidden = ( $user_id == $bp->loggedin_user->id && $scope != 'friends' ) ? 1 : 0;
195
-
196
- switch ( $scope ) {
197
- case 'friends':
198
- if ( function_exists( 'friends_get_friend_user_ids' ) )
199
- $friends = friends_get_friend_user_ids( $user_id );
200
- if ( empty( $friends ) )
201
- return false;
202
-
203
- $user_id = implode( ',', (array)$friends );
204
- break;
205
- case 'groups':
206
- if ( function_exists( 'groups_get_user_groups' ) ) {
207
- $groups = groups_get_user_groups( $user_id );
208
- if ( empty( $groups['groups'] ) )
209
- return false;
210
-
211
- $object = $bp->groups->id;
212
- $primary_id = implode( ',', (array)$groups['groups'] );
213
-
214
- $user_id = false;
215
- }
216
- break;
217
- case 'favorites':
218
- $favs = bp_activity_get_user_favorites( $user_id );
219
- if ( empty( $favs ) )
220
- return false;
221
-
222
- $include = implode( ',', (array)$favs );
223
- break;
224
- case 'mentions':
225
- $user_nicename = ( !empty( $bp->displayed_user->id ) ) ? $bp->displayed_user->userdata->user_nicename : $bp->loggedin_user->userdata->user_nicename;
226
- $user_login = ( !empty( $bp->displayed_user->id ) ) ? $bp->displayed_user->userdata->user_login : $bp->loggedin_user->userdata->user_login;
227
- $search_terms = '@' . bp_core_get_username( $user_id, $user_nicename, $user_login ) . '<'; // Start search at @ symbol and stop search at closing tag delimiter.
228
- $display_comments = 'stream';
229
- $user_id = false;
230
- break;
231
- }
232
- }
233
- }
234
-
235
- if ( $max ) {
236
- if ( $per_page > $max )
237
- $per_page = $max;
238
- }
239
-
240
- /* Support for basic filters in earlier BP versions. */
241
- $filter = false;
242
- if ( isset( $_GET['afilter'] ) )
243
- $filter = array( 'object' => $_GET['afilter'] );
244
- else if ( !empty( $user_id ) || !empty( $object ) || !empty( $action ) || !empty( $primary_id ) || !empty( $secondary_id ) )
245
- $filter = array( 'user_id' => $user_id, 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id );
246
-
247
- $activities_template = new BP_Activity_Template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden );
248
-
249
- return apply_filters( 'bp_has_activities', $activities_template->has_activities(), &$activities_template );
250
- }
251
-
252
- function bp_activities() {
253
- global $activities_template;
254
- return $activities_template->user_activities();
255
- }
256
-
257
- function bp_the_activity() {
258
- global $activities_template;
259
- return $activities_template->the_activity();
260
- }
261
-
262
- function bp_activity_pagination_count() {
263
- echo bp_get_activity_pagination_count();
264
- }
265
- function bp_get_activity_pagination_count() {
266
- global $bp, $activities_template;
267
-
268
- $start_num = intval( ( $activities_template->pag_page - 1 ) * $activities_template->pag_num ) + 1;
269
- $from_num = bp_core_number_format( $start_num );
270
- $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 ) );
271
- $total = bp_core_number_format( $activities_template->total_activity_count );
272
-
273
- 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>';
274
- }
275
-
276
- function bp_activity_pagination_links() {
277
- echo bp_get_activity_pagination_links();
278
- }
279
- function bp_get_activity_pagination_links() {
280
- global $activities_template;
281
-
282
- return apply_filters( 'bp_get_activity_pagination_links', $activities_template->pag_links );
283
- }
284
-
285
- function bp_activity_count() {
286
- echo bp_get_activity_count();
287
- }
288
- function bp_get_activity_count() {
289
- global $activities_template;
290
-
291
- return apply_filters( 'bp_get_activity_count', (int)$activities_template->activity_count );
292
- }
293
-
294
- function bp_activity_per_page() {
295
- echo bp_get_activity_per_page();
296
- }
297
- function bp_get_activity_per_page() {
298
- global $activities_template;
299
-
300
- return apply_filters( 'bp_get_activity_per_page', (int)$activities_template->pag_num );
301
- }
302
-
303
- function bp_activities_title() {
304
- global $bp_activity_title;
305
-
306
- echo bp_get_activities_title();
307
- }
308
- function bp_get_activities_title() {
309
- global $bp_activity_title;
310
-
311
- return apply_filters( 'bp_get_activities_title', $bp_activity_title );
312
- }
313
-
314
- function bp_activities_no_activity() {
315
- global $bp_activity_no_activity;
316
-
317
- echo bp_get_activities_no_activity();
318
- }
319
- function bp_get_activities_no_activity() {
320
- global $bp_activity_no_activity;
321
-
322
- return apply_filters( 'bp_get_activities_no_activity', $bp_activity_no_activity );
323
- }
324
-
325
- function bp_activity_id() {
326
- echo bp_get_activity_id();
327
- }
328
- function bp_get_activity_id() {
329
- global $activities_template;
330
- return apply_filters( 'bp_get_activity_id', $activities_template->activity->id );
331
- }
332
-
333
- function bp_activity_item_id() {
334
- echo bp_get_activity_item_id();
335
- }
336
- function bp_get_activity_item_id() {
337
- global $activities_template;
338
- return apply_filters( 'bp_get_activity_item_id', $activities_template->activity->item_id );
339
- }
340
-
341
- function bp_activity_secondary_item_id() {
342
- echo bp_get_activity_secondary_item_id();
343
- }
344
- function bp_get_activity_secondary_item_id() {
345
- global $activities_template;
346
- return apply_filters( 'bp_get_activity_secondary_item_id', $activities_template->activity->secondary_item_id );
347
- }
348
-
349
- function bp_activity_date_recorded() {
350
- echo bp_get_activity_date_recorded();
351
- }
352
- function bp_get_activity_date_recorded() {
353
- global $activities_template;
354
- return apply_filters( 'bp_get_activity_date_recorded', $activities_template->activity->date_recorded );
355
- }
356
-
357
- function bp_activity_object_name() {
358
- echo bp_get_activity_object_name();
359
- }
360
- function bp_get_activity_object_name() {
361
- global $activities_template;
362
- return apply_filters( 'bp_get_activity_object_name', $activities_template->activity->component );
363
- }
364
-
365
- function bp_activity_type() {
366
- echo bp_get_activity_type();
367
- }
368
- function bp_get_activity_type() {
369
- global $activities_template;
370
- return apply_filters( 'bp_get_activity_type', $activities_template->activity->type );
371
- }
372
- function bp_activity_action_name() { echo bp_activity_type(); }
373
- function bp_get_activity_action_name() { return bp_get_activity_type(); }
374
-
375
- function bp_activity_user_id() {
376
- echo bp_get_activity_user_id();
377
- }
378
- function bp_get_activity_user_id() {
379
- global $activities_template;
380
- return apply_filters( 'bp_get_activity_user_id', $activities_template->activity->user_id );
381
- }
382
-
383
- function bp_activity_user_link() {
384
- echo bp_get_activity_user_link();
385
- }
386
- function bp_get_activity_user_link() {
387
- global $activities_template;
388
-
389
- if ( empty( $activities_template->activity->user_id ) )
390
- $link = $activities_template->activity->primary_link;
391
- else
392
- $link = bp_core_get_user_domain( $activities_template->activity->user_id, $activities_template->activity->user_nicename, $activities_template->activity->user_login );
393
-
394
- return apply_filters( 'bp_get_activity_user_link', $link );
395
- }
396
-
397
- function bp_activity_avatar( $args = '' ) {
398
- echo bp_get_activity_avatar( $args );
399
- }
400
- function bp_get_activity_avatar( $args = '' ) {
401
- global $bp, $activities_template;
402
-
403
- $defaults = array(
404
- 'type' => 'thumb',
405
- 'width' => 20,
406
- 'height' => 20,
407
- 'class' => 'avatar',
408
- 'alt' => __( 'Avatar', 'buddypress' ),
409
- 'email' => false
410
- );
411
-
412
- $r = wp_parse_args( $args, $defaults );
413
- extract( $r, EXTR_SKIP );
414
-
415
- $item_id = false;
416
- if ( (int)$activities_template->activity->user_id )
417
- $item_id = $activities_template->activity->user_id;
418
- else if ( $activities_template->activity->item_id )
419
- $item_id = $activities_template->activity->item_id;
420
-
421
- $object = 'user';
422
- if ( $bp->groups->id == $activities_template->activity->component && !(int) $activities_template->activity->user_id )
423
- $object = 'group';
424
- if ( $bp->blogs->id == $activities_template->activity->component && !(int) $activities_template->activity->user_id )
425
- $object = 'blog';
426
-
427
- $object = apply_filters( 'bp_get_activity_avatar_object_' . $activities_template->activity->component, $object );
428
-
429
- /* If this is a user object pass the users' email address for Gravatar so we don't have to refetch it. */
430
- if ( 'user' == $object && empty($email) )
431
- $email = $activities_template->activity->user_email;
432
-
433
- 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 ) ) );
434
- }
435
-
436
- function bp_activity_action() {
437
- echo bp_get_activity_action();
438
- }
439
- function bp_get_activity_action() {
440
- global $activities_template;
441
-
442
- $action = $activities_template->activity->action;
443
-
444
- if ( !empty( $action ) )
445
- $action = bp_insert_activity_meta( $action );
446
-
447
- return apply_filters( 'bp_get_activity_action', $action, &$activities_template->activity );
448
- }
449
-
450
- function bp_activity_content_body() {
451
- echo bp_get_activity_content_body();
452
- }
453
- function bp_get_activity_content_body() {
454
- global $activities_template;
455
-
456
- /* Backwards compatibility if action is not being used */
457
- if ( empty( $activities_template->activity->action ) && !empty( $activities_template->activity->content ) )
458
- $activities_template->activity->content = bp_insert_activity_meta( $activities_template->activity->content );
459
-
460
- return apply_filters( 'bp_get_activity_content_body', $activities_template->activity->content, &$activities_template->activity );
461
- }
462
-
463
- function bp_activity_has_content() {
464
- global $activities_template;
465
-
466
- if ( !empty( $activities_template->activity->content ) )
467
- return true;
468
-
469
- return false;
470
- }
471
-
472
- function bp_activity_content() {
473
- echo bp_get_activity_content();
474
- }
475
- function bp_get_activity_content() {
476
- global $activities_template;
477
-
478
- /***
479
- * If you want to filter activity update content, please use
480
- * the filter 'bp_get_activity_content_body'
481
- *
482
- * This function is mainly for backwards comptibility.
483
- */
484
-
485
- $content = bp_get_activity_action() . ' ' . bp_get_activity_content_body();
486
- return apply_filters( 'bp_get_activity_content', $content );
487
- }
488
-
489
- function bp_insert_activity_meta( $content ) {
490
- global $activities_template, $bp;
491
-
492
- /* Strip any legacy time since placeholders -- TODO: Remove this in 1.3 */
493
- $content = str_replace( '<span class="time-since">%s</span>', '', $content );
494
-
495
- /* Insert the time since. */
496
- $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 );
497
-
498
- /* Insert the permalink */
499
- $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 );
500
-
501
- /* Add the delete link if the user has permission on this item */
502
- if ( ( is_user_logged_in() && $activities_template->activity->user_id == $bp->loggedin_user->id ) || $bp->is_item_admin || $bp->loggedin_user->is_site_admin )
503
- $content .= apply_filters( 'bp_activity_delete_link', ' &middot; ' . bp_get_activity_delete_link(), &$activities_template->activity );
504
-
505
- return apply_filters( 'bp_insert_activity_meta', $content );
506
- }
507
-
508
- function bp_activity_parent_content( $args = '' ) {
509
- echo bp_get_activity_parent_content($args);
510
- }
511
- function bp_get_activity_parent_content( $args = '' ) {
512
- global $bp, $activities_template;
513
-
514
- $defaults = array(
515
- 'hide_user' => false
516
- );
517
-
518
- $r = wp_parse_args( $args, $defaults );
519
- extract( $r, EXTR_SKIP );
520
-
521
- /* Get the ID of the parent activity content */
522
- if ( !$parent_id = $activities_template->activity->item_id )
523
- return false;
524
-
525
- /* Get the content of the parent */
526
- if ( empty( $activities_template->activity_parents[$parent_id] ) )
527
- return false;
528
-
529
- if ( empty( $activities_template->activity_parents[$parent_id]->content ) )
530
- $content = $activities_template->activity_parents[$parent_id]->action;
531
- else
532
- $content = $activities_template->activity_parents[$parent_id]->action . ' ' . $activities_template->activity_parents[$parent_id]->content;
533
-
534
- /* Remove the time since content for backwards compatibility */
535
- $content = str_replace( '<span class="time-since">%s</span>', '', $content );
536
-
537
- /* Remove images */
538
- $content = preg_replace( '/<img[^>]*>/Ui', '', $content );
539
-
540
- return apply_filters( 'bp_get_activity_parent_content', $content );
541
- }
542
-
543
- function bp_activity_is_favorite() {
544
- echo bp_get_activity_is_favorite();
545
- }
546
- function bp_get_activity_is_favorite() {
547
- global $bp, $activities_template;
548
-
549
- return apply_filters( 'bp_get_activity_is_favorite', in_array( $activities_template->activity->id, (array)$activities_template->my_favs ) );
550
- }
551
-
552
- function bp_activity_comments( $args = '' ) {
553
- echo bp_activity_get_comments( $args );
554
- }
555
- function bp_activity_get_comments( $args = '' ) {
556
- global $activities_template, $bp;
557
-
558
- if ( !$activities_template->activity->children )
559
- return false;
560
-
561
- $comments_html = bp_activity_recurse_comments( $activities_template->activity );
562
-
563
- return apply_filters( 'bp_activity_get_comments', $comments_html );
564
- }
565
- /* TODO: The HTML in this function is temporary and will be moved to the template in a future version. */
566
- function bp_activity_recurse_comments( $comment ) {
567
- global $activities_template, $bp;
568
-
569
- if ( !$comment->children )
570
- return false;
571
-
572
- $content .= '<ul>';
573
- foreach ( (array)$comment->children as $comment ) {
574
- if ( !$comment->user_fullname )
575
- $comment->user_fullname = $comment->display_name;
576
-
577
- $content .= '<li id="acomment-' . $comment->id . '">';
578
- $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' => 25, 'height' => 25, 'email' => $comment->user_email ) ) . '</a></div>';
579
- $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( strtotime( $comment->date_recorded ) ) );
580
-
581
- /* Reply link - the span is so that threaded reply links can be hidden when JS is off. */
582
- if ( is_user_logged_in() )
583
- $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>';
584
-
585
- /* Delete link */
586
- if ( $bp->loggedin_user->is_site_admin || $bp->loggedin_user->id == $comment->user_id )
587
- $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>';
588
-
589
- $content .= '</div>';
590
- $content .= '<div class="acomment-content">' . apply_filters( 'bp_get_activity_content', $comment->content ) . '</div>';
591
-
592
- $content .= bp_activity_recurse_comments( $comment );
593
- $content .= '</li>';
594
- }
595
- $content .= '</ul>';
596
-
597
- return apply_filters( 'bp_activity_recurse_comments', $content );
598
- }
599
-
600
- function bp_activity_comment_count() {
601
- echo bp_activity_get_comment_count();
602
- }
603
- function bp_activity_get_comment_count( $args = '' ) {
604
- global $activities_template, $bp;
605
-
606
- if ( !$activities_template->activity->children )
607
- return 0;
608
-
609
- $count = bp_activity_recurse_comment_count( $activities_template->activity );
610
-
611
- return apply_filters( 'bp_activity_get_comment_count', (int)$count );
612
- }
613
- function bp_activity_recurse_comment_count( $comment, $count = 0 ) {
614
- global $activities_template, $bp;
615
-
616
- if ( !$comment->children )
617
- return $count;
618
-
619
- foreach ( (array)$comment->children as $comment ) {
620
- $count++;
621
- $count = bp_activity_recurse_comment_count( $comment, $count );
622
- }
623
-
624
- return $count;
625
- }
626
-
627
- function bp_activity_comment_link() {
628
- echo bp_get_activity_comment_link();
629
- }
630
- function bp_get_activity_comment_link() {
631
- global $activities_template;
632
- return apply_filters( 'bp_get_activity_comment_link', '?ac=' . $activities_template->activity->id . '/#ac-form-' . $activities_template->activity->id );
633
- }
634
-
635
- function bp_activity_comment_form_nojs_display() {
636
- echo bp_get_activity_comment_form_nojs_display();
637
- }
638
- function bp_get_activity_comment_form_nojs_display() {
639
- global $activities_template;
640
- if ( $_GET['ac'] == $activities_template->activity->id . '/' )
641
- return 'style="display: block"';
642
-
643
- return false;
644
- }
645
-
646
- function bp_activity_comment_form_action() {
647
- echo bp_get_activity_comment_form_action();
648
- }
649
- function bp_get_activity_comment_form_action() {
650
- return apply_filters( 'bp_get_activity_comment_form_action', site_url( BP_ACTIVITY_SLUG . '/reply/' ) );
651
- }
652
-
653
- function bp_activity_permalink_id() {
654
- echo bp_get_activity_permalink_id();
655
- }
656
- function bp_get_activity_permalink_id() {
657
- global $bp;
658
-
659
- return apply_filters( 'bp_get_activity_permalink_id', $bp->current_action );
660
- }
661
-
662
- function bp_activity_thread_permalink() {
663
- echo bp_get_activity_thread_permalink();
664
- }
665
- function bp_get_activity_thread_permalink() {
666
- global $bp, $activities_template;
667
-
668
- $link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity );
669
-
670
- return apply_filters( 'bp_get_activity_thread_permalink', $link );
671
- }
672
-
673
- function bp_activity_favorite_link() {
674
- echo bp_get_activity_favorite_link();
675
- }
676
- function bp_get_activity_favorite_link() {
677
- global $activities_template;
678
- return apply_filters( 'bp_get_activity_favorite_link', wp_nonce_url( site_url( BP_ACTIVITY_SLUG . '/favorite/' . $activities_template->activity->id . '/' ), 'mark_favorite' ) );
679
- }
680
-
681
- function bp_activity_unfavorite_link() {
682
- echo bp_get_activity_unfavorite_link();
683
- }
684
- function bp_get_activity_unfavorite_link() {
685
- global $activities_template;
686
- return apply_filters( 'bp_get_activity_unfavorite_link', wp_nonce_url( site_url( BP_ACTIVITY_SLUG . '/unfavorite/' . $activities_template->activity->id . '/' ), 'unmark_favorite' ) );
687
- }
688
-
689
- function bp_activity_css_class() {
690
- echo bp_get_activity_css_class();
691
- }
692
- function bp_get_activity_css_class() {
693
- global $activities_template;
694
-
695
- $mini_activity_actions = apply_filters( 'bp_activity_mini_activity_types', array(
696
- 'friendship_accepted',
697
- 'friendship_created',
698
- 'new_blog',
699
- 'joined_group',
700
- 'created_group',
701
- 'new_member'
702
- ) );
703
-
704
- $class = '';
705
- if ( in_array( $activities_template->activity->type, (array)$mini_activity_actions ) || empty( $activities_template->activity->content ) )
706
- $class = ' mini';
707
-
708
- if ( bp_activity_get_comment_count() && bp_activity_can_comment() )
709
- $class .= ' has-comments';
710
-
711
- return apply_filters( 'bp_get_activity_css_class', $activities_template->activity->component . ' ' . $activities_template->activity->type . $class );
712
- }
713
-
714
- function bp_activity_delete_link() {
715
- echo bp_get_activity_delete_link();
716
- }
717
- function bp_get_activity_delete_link() {
718
- global $activities_template, $bp;
719
-
720
- 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>' );
721
- }
722
-
723
- function bp_activity_latest_update( $user_id = false ) {
724
- echo bp_get_activity_latest_update( $user_id );
725
- }
726
- function bp_get_activity_latest_update( $user_id = false ) {
727
- global $bp;
728
-
729
- if ( !$user_id )
730
- $user_id = $bp->displayed_user->id;
731
-
732
- if ( !$update = get_usermeta( $user_id, 'bp_latest_update' ) )
733
- return false;
734
-
735
- $latest_update = '&quot;' . trim( strip_tags( bp_create_excerpt( $update['content'], 40 ) ) ) . '&quot;';
736
- $latest_update .= ' &middot; <a href="' . $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $update['id'] . '/"> ' . __( 'View', 'buddypress' ) . '</a>';
737
-
738
- return apply_filters( 'bp_get_activity_latest_update', $latest_update );
739
- }
740
-
741
- function bp_activity_filter_links( $args = false ) {
742
- echo bp_get_activity_filter_links( $args );
743
- }
744
- function bp_get_activity_filter_links( $args = false ) {
745
- global $activities_template, $bp;
746
-
747
- $defaults = array(
748
- 'style' => 'list'
749
- );
750
-
751
- $r = wp_parse_args( $args, $defaults );
752
- extract( $r, EXTR_SKIP );
753
-
754
- /* Fetch the names of components that have activity recorded in the DB */
755
- $components = BP_Activity_Activity::get_recorded_components();
756
-
757
- if ( !$components )
758
- return false;
759
-
760
- foreach ( (array) $components as $component ) {
761
- /* Skip the activity comment filter */
762
- if ( 'activity' == $component )
763
- continue;
764
-
765
- if ( isset( $_GET['afilter'] ) && $component == $_GET['afilter'] )
766
- $selected = ' class="selected"';
767
- else
768
- unset($selected);
769
-
770
- $component = attribute_escape( $component );
771
-
772
- switch ( $style ) {
773
- case 'list':
774
- $tag = 'li';
775
- $before = '<li id="afilter-' . $component . '"' . $selected . '>';
776
- $after = '</li>';
777
- break;
778
- case 'paragraph':
779
- $tag = 'p';
780
- $before = '<p id="afilter-' . $component . '"' . $selected . '>';
781
- $after = '</p>';
782
- break;
783
- case 'span':
784
- $tag = 'span';
785
- $before = '<span id="afilter-' . $component . '"' . $selected . '>';
786
- $after = '</span>';
787
- break;
788
- }
789
-
790
- $link = add_query_arg( 'afilter', $component );
791
- $link = remove_query_arg( 'acpage' , $link );
792
-
793
- $link = apply_filters( 'bp_get_activity_filter_link_href', $link, $component );
794
-
795
- /* Make sure all core internal component names are translatable */
796
- $translatable_components = array( __( 'profile', 'buddypress'), __( 'friends', 'buddypress' ), __( 'groups', 'buddypress' ), __( 'status', 'buddypress' ), __( 'blogs', 'buddypress' ) );
797
-
798
- $component_links[] = $before . '<a href="' . attribute_escape( $link ) . '">' . ucwords( __( $component, 'buddypress' ) ) . '</a>' . $after;
799
- }
800
-
801
- $link = remove_query_arg( 'afilter' , $link );
802
-
803
- if ( isset( $_GET['afilter'] ) )
804
- $component_links[] = '<' . $tag . ' id="afilter-clear"><a href="' . attribute_escape( $link ) . '"">' . __( 'Clear Filter', 'buddypress' ) . '</a></' . $tag . '>';
805
-
806
- return apply_filters( 'bp_get_activity_filter_links', implode( "\n", $component_links ) );
807
- }
808
-
809
- function bp_activity_can_comment() {
810
- global $activities_template, $bp;
811
-
812
- if ( false === $activities_template->disable_blogforum_replies || (int)$activities_template->disable_blogforum_replies ) {
813
- 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() )
814
- return false;
815
- }
816
-
817
- if ( 'activity_comment' == bp_get_activity_action_name() )
818
- return false;
819
-
820
- return true;
821
- }
822
-
823
- function bp_total_favorite_count_for_user( $user_id = false ) {
824
- echo bp_get_total_favorite_count_for_user( $user_id );
825
- }
826
- function bp_get_total_favorite_count_for_user( $user_id = false ) {
827
- return apply_filters( 'bp_get_total_favorite_count_for_user', bp_activity_total_favorites_for_user( $user_id ) );
828
- }
829
-
830
- function bp_total_mention_count_for_user( $user_id = false ) {
831
- echo bp_get_total_favorite_count_for_user( $user_id );
832
- }
833
- function bp_get_total_mention_count_for_user( $user_id = false ) {
834
- return apply_filters( 'bp_get_total_mention_count_for_user', get_usermeta( $user_id, 'bp_new_mention_count' ) );
835
- }
836
-
837
- function bp_send_public_message_link() {
838
- echo bp_get_send_public_message_link();
839
- }
840
- function bp_get_send_public_message_link() {
841
- global $bp;
842
-
843
- return apply_filters( 'bp_get_send_public_message_link', $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 ) );
844
- }
845
-
846
- function bp_activity_post_form_action() {
847
- echo bp_get_activity_post_form_action();
848
- }
849
- function bp_get_activity_post_form_action() {
850
- return apply_filters( 'bp_get_activity_post_form_action', site_url( BP_ACTIVITY_SLUG . '/post/' ) );
851
- }
852
-
853
- /* RSS Feed Template Tags ***************************/
854
-
855
- function bp_sitewide_activity_feed_link() {
856
- echo bp_get_sitewide_activity_feed_link();
857
- }
858
- function bp_get_sitewide_activity_feed_link() {
859
- global $bp;
860
-
861
- return apply_filters( 'bp_get_sitewide_activity_feed_link', site_url( $bp->activity->slug . '/feed/' ) );
862
- }
863
-
864
- function bp_member_activity_feed_link() {
865
- echo bp_get_member_activity_feed_link();
866
- }
867
- function bp_activities_member_rss_link() { echo bp_get_member_activity_feed_link(); }
868
-
869
- function bp_get_member_activity_feed_link() {
870
- global $bp;
871
-
872
- if ( $bp->current_component == $bp->profile->slug || 'just-me' == $bp->current_action )
873
- $link = $bp->displayed_user->domain . $bp->activity->slug . '/feed/';
874
- else if ( 'friends' == $bp->current_action )
875
- $link = $bp->displayed_user->domain . $bp->activity->slug . '/friends/feed/';
876
- else if ( 'groups' == $bp->current_action )
877
- $link = $bp->displayed_user->domain . $bp->activity->slug . '/groups/feed/';
878
- else if ( 'favorites' == $bp->current_action )
879
- $link = $bp->displayed_user->domain . $bp->activity->slug . '/favorites/feed/';
880
- else if ( 'mentions' == $bp->current_action )
881
- $link = $bp->displayed_user->domain . $bp->activity->slug . '/mentions/feed/';
882
-
883
- return apply_filters( 'bp_get_activities_member_rss_link', $link );
884
- }
885
- function bp_get_activities_member_rss_link() { return bp_get_member_activity_feed_link(); }
886
-
887
-
888
- /* Template tags for RSS feed output */
889
-
890
- function bp_activity_feed_item_guid() {
891
- echo bp_get_activity_feed_item_guid();
892
- }
893
- function bp_get_activity_feed_item_guid() {
894
- global $activities_template;
895
-
896
- return apply_filters( 'bp_get_activity_feed_item_guid', md5( $activities_template->activity->date_recorded . '-' . $activities_template->activity->content ) );
897
- }
898
-
899
- function bp_activity_feed_item_title() {
900
- echo bp_get_activity_feed_item_title();
901
- }
902
- function bp_get_activity_feed_item_title() {
903
- global $activities_template;
904
-
905
- if ( !empty( $activities_template->activity->action ) )
906
- $content = $activities_template->activity->action;
907
- else
908
- $content = $activities_template->activity->content;
909
-
910
- $content = explode( '<span', $content );
911
- $title = trim( strip_tags( html_entity_decode( utf8_encode( $content[0] ) ) ) );
912
-
913
- if ( ':' == substr( $title, -1 ) )
914
- $title = substr( $title, 0, -1 );
915
-
916
- if ( 'activity_update' == $activities_template->activity->type )
917
- $title .= ': ' . strip_tags( bp_create_excerpt( $activities_template->activity->content, 15 ) );
918
-
919
- return apply_filters( 'bp_get_activity_feed_item_title', $title );
920
- }
921
-
922
- function bp_activity_feed_item_link() {
923
- echo bp_get_activity_feed_item_link();
924
- }
925
- function bp_get_activity_feed_item_link() {
926
- global $activities_template;
927
-
928
- return apply_filters( 'bp_get_activity_feed_item_link', $activities_template->activity->primary_link );
929
- }
930
-
931
- function bp_activity_feed_item_date() {
932
- echo bp_get_activity_feed_item_date();
933
- }
934
- function bp_get_activity_feed_item_date() {
935
- global $activities_template;
936
-
937
- return apply_filters( 'bp_get_activity_feed_item_date', $activities_template->activity->date_recorded );
938
- }
939
-
940
- function bp_activity_feed_item_description() {
941
- echo bp_get_activity_feed_item_description();
942
- }
943
- function bp_get_activity_feed_item_description() {
944
- global $activities_template;
945
-
946
- if ( empty( $activities_template->activity->action ) )
947
- $content = $activities_template->activity->content;
948
- else
949
- $content = $activities_template->activity->action . ' ' . $activities_template->activity->content;
950
-
951
- return apply_filters( 'bp_get_activity_feed_item_description', html_entity_decode( str_replace( '%s', '', $content ) ) );
952
- }
953
-
954
  ?>
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_usermeta( $bp->loggedin_user->id, 'bp_favorite_activities' ) );
29
+
30
+ if ( !empty( $include ) ) {
31
+ /* Fetch specific activity items based on ID's */
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 ) );
33
+ } else {
34
+ $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 ) );
35
+ }
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
+ } else {
50
+ $this->activity_count = count($this->activities);
51
+ }
52
+
53
+ $this->full_name = $bp->displayed_user->fullname;
54
+
55
+ /* Fetch parent content for activity comments so we do not have to query in the loop */
56
+ foreach ( (array)$this->activities as $activity ) {
57
+ if ( 'activity_comment' != $activity->type ) continue;
58
+ $parent_ids[] = $activity->item_id;
59
+ }
60
+
61
+ if ( !empty( $parent_ids ) )
62
+ $activity_parents = bp_activity_get_specific( array( 'activity_ids' => $parent_ids ) );
63
+
64
+ if ( !empty( $activity_parents['activities'] ) ) {
65
+ foreach( $activity_parents['activities'] as $parent ) $this->activity_parents[$parent->id] = $parent;
66
+ unset( $activity_parents );
67
+ }
68
+
69
+ if ( (int) $this->total_activity_count && (int) $this->pag_num ) {
70
+ $this->pag_links = paginate_links( array(
71
+ 'base' => add_query_arg( 'acpage', '%#%' ),
72
+ 'format' => '',
73
+ 'total' => ceil( (int)$this->total_activity_count / (int)$this->pag_num ),
74
+ 'current' => (int)$this->pag_page,
75
+ 'prev_text' => '&larr;',
76
+ 'next_text' => '&rarr;',
77
+ 'mid_size' => 1
78
+ ));
79
+ }
80
+ }
81
+
82
+ function has_activities() {
83
+ if ( $this->activity_count )
84
+ return true;
85
+
86
+ return false;
87
+ }
88
+
89
+ function next_activity() {
90
+ $this->current_activity++;
91
+ $this->activity = $this->activities[$this->current_activity];
92
+
93
+ return $this->activity;
94
+ }
95
+
96
+ function rewind_activities() {
97
+ $this->current_activity = -1;
98
+ if ( $this->activity_count > 0 ) {
99
+ $this->activity = $this->activities[0];
100
+ }
101
+ }
102
+
103
+ function user_activities() {
104
+ if ( $this->current_activity + 1 < $this->activity_count ) {
105
+ return true;
106
+ } elseif ( $this->current_activity + 1 == $this->activity_count ) {
107
+ do_action('activity_loop_end');
108
+ // Do some cleaning up after the loop
109
+ $this->rewind_activities();
110
+ }
111
+
112
+ $this->in_the_loop = false;
113
+ return false;
114
+ }
115
+
116
+ function the_activity() {
117
+ global $activity;
118
+
119
+ $this->in_the_loop = true;
120
+ $this->activity = $this->next_activity();
121
+
122
+ if ( is_array( $this->activity ) )
123
+ $this->activity = (object) $this->activity;
124
+
125
+ if ( $this->current_activity == 0 ) // loop has just started
126
+ do_action('activity_loop_start');
127
+ }
128
+ }
129
+
130
+ function bp_has_activities( $args = '' ) {
131
+ global $bp, $activities_template;
132
+
133
+ /***
134
+ * Set the defaults based on the current page. Any of these will be overridden
135
+ * if arguments are directly passed into the loop. Custom plugins should always
136
+ * pass their parameters directly to the loop.
137
+ */
138
+ $user_id = false;
139
+ $include = false;
140
+ $show_hidden = false;
141
+ $object = false;
142
+ $primary_id = false;
143
+
144
+ /* User filtering */
145
+ if ( !empty( $bp->displayed_user->id ) )
146
+ $user_id = $bp->displayed_user->id;
147
+
148
+ /* Group filtering */
149
+ if ( !empty( $bp->groups->current_group ) ) {
150
+ $object = $bp->groups->id;
151
+ $primary_id = $bp->groups->current_group->id;
152
+
153
+ if ( 'public' != $bp->groups->current_group->status && groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
154
+ $show_hidden = true;
155
+ }
156
+
157
+ /* Support for permalinks on single item pages: /groups/my-group/activity/124/ */
158
+ if ( $bp->current_action == $bp->activity->slug )
159
+ $include = $bp->action_variables[0];
160
+
161
+ /* Note: any params used for filtering can be a single value, or multiple values comma separated. */
162
+ $defaults = array(
163
+ 'display_comments' => 'threaded', // false for none, stream/threaded - show comments in the stream or threaded under items
164
+ 'include' => $include, // pass an activity_id or string of ID's comma separated
165
+ 'sort' => 'DESC', // sort DESC or ASC
166
+ 'page' => 1, // which page to load
167
+ 'per_page' => 20, // number of items per page
168
+ 'max' => false, // max number to return
169
+ 'show_hidden' => $show_hidden, // Show activity items that are hidden site-wide?
170
+
171
+ /* Scope - pre-built activity filters for a user (friends/groups/favorites/mentions) */
172
+ 'scope' => $bp->current_action,
173
+
174
+ /* Filtering */
175
+ 'user_id' => $user_id, // user_id to filter on
176
+ 'object' => $object, // object to filter on e.g. groups, profile, status, friends
177
+ 'action' => false, // action to filter on e.g. activity_update, new_forum_post, profile_updated
178
+ 'primary_id' => $primary_id, // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
179
+ 'secondary_id' => false, // secondary object ID to filter on e.g. a post_id
180
+
181
+ /* Searching */
182
+ 'search_terms' => false // specify terms to search on
183
+ );
184
+
185
+ $r = wp_parse_args( $args, $defaults );
186
+ extract( $r );
187
+
188
+ /* If you have passed a "scope" then this will override any filters you have passed. */
189
+ if ( 'just-me' == $scope || 'friends' == $scope || 'groups' == $scope || 'favorites' == $scope || 'mentions' == $scope ) {
190
+ if ( 'just-me' == $scope )
191
+ $display_comments = 'stream';
192
+
193
+ if ( $user_id = ( !empty( $bp->displayed_user->id ) ) ? $bp->displayed_user->id : $bp->loggedin_user->id ) {
194
+ $show_hidden = ( $user_id == $bp->loggedin_user->id && $scope != 'friends' ) ? 1 : 0;
195
+
196
+ switch ( $scope ) {
197
+ case 'friends':
198
+ if ( function_exists( 'friends_get_friend_user_ids' ) )
199
+ $friends = friends_get_friend_user_ids( $user_id );
200
+ if ( empty( $friends ) )
201
+ return false;
202
+
203
+ $user_id = implode( ',', (array)$friends );
204
+ break;
205
+ case 'groups':
206
+ if ( function_exists( 'groups_get_user_groups' ) ) {
207
+ $groups = groups_get_user_groups( $user_id );
208
+ if ( empty( $groups['groups'] ) )
209
+ return false;
210
+
211
+ $object = $bp->groups->id;
212
+ $primary_id = implode( ',', (array)$groups['groups'] );
213
+
214
+ $user_id = false;
215
+ }
216
+ break;
217
+ case 'favorites':
218
+ $favs = bp_activity_get_user_favorites( $user_id );
219
+ if ( empty( $favs ) )
220
+ return false;
221
+
222
+ $include = implode( ',', (array)$favs );
223
+ break;
224
+ case 'mentions':
225
+ $user_nicename = ( !empty( $bp->displayed_user->id ) ) ? $bp->displayed_user->userdata->user_nicename : $bp->loggedin_user->userdata->user_nicename;
226
+ $user_login = ( !empty( $bp->displayed_user->id ) ) ? $bp->displayed_user->userdata->user_login : $bp->loggedin_user->userdata->user_login;
227
+ $search_terms = '@' . bp_core_get_username( $user_id, $user_nicename, $user_login ) . '<'; // Start search at @ symbol and stop search at closing tag delimiter.
228
+ $display_comments = 'stream';
229
+ $user_id = false;
230
+ break;
231
+ }
232
+ }
233
+ }
234
+
235
+ if ( $max ) {
236
+ if ( $per_page > $max )
237
+ $per_page = $max;
238
+ }
239
+
240
+ /* Support for basic filters in earlier BP versions. */
241
+ $filter = false;
242
+ if ( isset( $_GET['afilter'] ) )
243
+ $filter = array( 'object' => $_GET['afilter'] );
244
+ else if ( !empty( $user_id ) || !empty( $object ) || !empty( $action ) || !empty( $primary_id ) || !empty( $secondary_id ) )
245
+ $filter = array( 'user_id' => $user_id, 'object' => $object, 'action' => $action, 'primary_id' => $primary_id, 'secondary_id' => $secondary_id );
246
+
247
+ $activities_template = new BP_Activity_Template( $page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden );
248
+
249
+ return apply_filters( 'bp_has_activities', $activities_template->has_activities(), &$activities_template );
250
+ }
251
+
252
+ function bp_activities() {
253
+ global $activities_template;
254
+ return $activities_template->user_activities();
255
+ }
256
+
257
+ function bp_the_activity() {
258
+ global $activities_template;
259
+ return $activities_template->the_activity();
260
+ }
261
+
262
+ function bp_activity_pagination_count() {
263
+ echo bp_get_activity_pagination_count();
264
+ }
265
+ function bp_get_activity_pagination_count() {
266
+ global $bp, $activities_template;
267
+
268
+ $start_num = intval( ( $activities_template->pag_page - 1 ) * $activities_template->pag_num ) + 1;
269
+ $from_num = bp_core_number_format( $start_num );
270
+ $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 ) );
271
+ $total = bp_core_number_format( $activities_template->total_activity_count );
272
+
273
+ 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>';
274
+ }
275
+
276
+ function bp_activity_pagination_links() {
277
+ echo bp_get_activity_pagination_links();
278
+ }
279
+ function bp_get_activity_pagination_links() {
280
+ global $activities_template;
281
+
282
+ return apply_filters( 'bp_get_activity_pagination_links', $activities_template->pag_links );
283
+ }
284
+
285
+ function bp_activity_count() {
286
+ echo bp_get_activity_count();
287
+ }
288
+ function bp_get_activity_count() {
289
+ global $activities_template;
290
+
291
+ return apply_filters( 'bp_get_activity_count', (int)$activities_template->activity_count );
292
+ }
293
+
294
+ function bp_activity_per_page() {
295
+ echo bp_get_activity_per_page();
296
+ }
297
+ function bp_get_activity_per_page() {
298
+ global $activities_template;
299
+
300
+ return apply_filters( 'bp_get_activity_per_page', (int)$activities_template->pag_num );
301
+ }
302
+
303
+ function bp_activities_title() {
304
+ global $bp_activity_title;
305
+
306
+ echo bp_get_activities_title();
307
+ }
308
+ function bp_get_activities_title() {
309
+ global $bp_activity_title;
310
+
311
+ return apply_filters( 'bp_get_activities_title', $bp_activity_title );
312
+ }
313
+
314
+ function bp_activities_no_activity() {
315
+ global $bp_activity_no_activity;
316
+
317
+ echo bp_get_activities_no_activity();
318
+ }
319
+ function bp_get_activities_no_activity() {
320
+ global $bp_activity_no_activity;
321
+
322
+ return apply_filters( 'bp_get_activities_no_activity', $bp_activity_no_activity );
323
+ }
324
+
325
+ function bp_activity_id() {
326
+ echo bp_get_activity_id();
327
+ }
328
+ function bp_get_activity_id() {
329
+ global $activities_template;
330
+ return apply_filters( 'bp_get_activity_id', $activities_template->activity->id );
331
+ }
332
+
333
+ function bp_activity_item_id() {
334
+ echo bp_get_activity_item_id();
335
+ }
336
+ function bp_get_activity_item_id() {
337
+ global $activities_template;
338
+ return apply_filters( 'bp_get_activity_item_id', $activities_template->activity->item_id );
339
+ }
340
+
341
+ function bp_activity_secondary_item_id() {
342
+ echo bp_get_activity_secondary_item_id();
343
+ }
344
+ function bp_get_activity_secondary_item_id() {
345
+ global $activities_template;
346
+ return apply_filters( 'bp_get_activity_secondary_item_id', $activities_template->activity->secondary_item_id );
347
+ }
348
+
349
+ function bp_activity_date_recorded() {
350
+ echo bp_get_activity_date_recorded();
351
+ }
352
+ function bp_get_activity_date_recorded() {
353
+ global $activities_template;
354
+ return apply_filters( 'bp_get_activity_date_recorded', $activities_template->activity->date_recorded );
355
+ }
356
+
357
+ function bp_activity_object_name() {
358
+ echo bp_get_activity_object_name();
359
+ }
360
+ function bp_get_activity_object_name() {
361
+ global $activities_template;
362
+ return apply_filters( 'bp_get_activity_object_name', $activities_template->activity->component );
363
+ }
364
+
365
+ function bp_activity_type() {
366
+ echo bp_get_activity_type();
367
+ }
368
+ function bp_get_activity_type() {
369
+ global $activities_template;
370
+ return apply_filters( 'bp_get_activity_type', $activities_template->activity->type );
371
+ }
372
+ function bp_activity_action_name() { echo bp_activity_type(); }
373
+ function bp_get_activity_action_name() { return bp_get_activity_type(); }
374
+
375
+ function bp_activity_user_id() {
376
+ echo bp_get_activity_user_id();
377
+ }
378
+ function bp_get_activity_user_id() {
379
+ global $activities_template;
380
+ return apply_filters( 'bp_get_activity_user_id', $activities_template->activity->user_id );
381
+ }
382
+
383
+ function bp_activity_user_link() {
384
+ echo bp_get_activity_user_link();
385
+ }
386
+ function bp_get_activity_user_link() {
387
+ global $activities_template;
388
+
389
+ if ( empty( $activities_template->activity->user_id ) )
390
+ $link = $activities_template->activity->primary_link;
391
+ else
392
+ $link = bp_core_get_user_domain( $activities_template->activity->user_id, $activities_template->activity->user_nicename, $activities_template->activity->user_login );
393
+
394
+ return apply_filters( 'bp_get_activity_user_link', $link );
395
+ }
396
+
397
+ function bp_activity_avatar( $args = '' ) {
398
+ echo bp_get_activity_avatar( $args );
399
+ }
400
+ function bp_get_activity_avatar( $args = '' ) {
401
+ global $bp, $activities_template;
402
+
403
+ $defaults = array(
404
+ 'type' => 'thumb',
405
+ 'width' => 20,
406
+ 'height' => 20,
407
+ 'class' => 'avatar',
408
+ 'alt' => __( 'Avatar', 'buddypress' ),
409
+ 'email' => false
410
+ );
411
+
412
+ $r = wp_parse_args( $args, $defaults );
413
+ extract( $r, EXTR_SKIP );
414
+
415
+ $item_id = false;
416
+ if ( (int)$activities_template->activity->user_id )
417
+ $item_id = $activities_template->activity->user_id;
418
+ else if ( $activities_template->activity->item_id )
419
+ $item_id = $activities_template->activity->item_id;
420
+
421
+ $object = 'user';
422
+ if ( $bp->groups->id == $activities_template->activity->component && !(int) $activities_template->activity->user_id )
423
+ $object = 'group';
424
+ if ( $bp->blogs->id == $activities_template->activity->component && !(int) $activities_template->activity->user_id )
425
+ $object = 'blog';
426
+
427
+ $object = apply_filters( 'bp_get_activity_avatar_object_' . $activities_template->activity->component, $object );
428
+
429
+ /* If this is a user object pass the users' email address for Gravatar so we don't have to refetch it. */
430
+ if ( 'user' == $object && empty($email) )
431
+ $email = $activities_template->activity->user_email;
432
+
433
+ 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 ) ) );
434
+ }
435
+
436
+ function bp_activity_action() {
437
+ echo bp_get_activity_action();
438
+ }
439
+ function bp_get_activity_action() {
440
+ global $activities_template;
441
+
442
+ $action = $activities_template->activity->action;
443
+
444
+ if ( !empty( $action ) )
445
+ $action = bp_insert_activity_meta( $action );
446
+
447
+ return apply_filters( 'bp_get_activity_action', $action, &$activities_template->activity );
448
+ }
449
+
450
+ function bp_activity_content_body() {
451
+ echo bp_get_activity_content_body();
452
+ }
453
+ function bp_get_activity_content_body() {
454
+ global $activities_template;
455
+
456
+ /* Backwards compatibility if action is not being used */
457
+ if ( empty( $activities_template->activity->action ) && !empty( $activities_template->activity->content ) )
458
+ $activities_template->activity->content = bp_insert_activity_meta( $activities_template->activity->content );
459
+
460
+ return apply_filters( 'bp_get_activity_content_body', $activities_template->activity->content, &$activities_template->activity );
461
+ }
462
+
463
+ function bp_activity_has_content() {
464
+ global $activities_template;
465
+
466
+ if ( !empty( $activities_template->activity->content ) )
467
+ return true;
468
+
469
+ return false;
470
+ }
471
+
472
+ function bp_activity_content() {
473
+ echo bp_get_activity_content();
474
+ }
475
+ function bp_get_activity_content() {
476
+ global $activities_template;
477
+
478
+ /***
479
+ * If you want to filter activity update content, please use
480
+ * the filter 'bp_get_activity_content_body'
481
+ *
482
+ * This function is mainly for backwards comptibility.
483
+ */
484
+
485
+ $content = bp_get_activity_action() . ' ' . bp_get_activity_content_body();
486
+ return apply_filters( 'bp_get_activity_content', $content );
487
+ }
488
+
489
+ function bp_insert_activity_meta( $content ) {
490
+ global $activities_template, $bp;
491
+
492
+ /* Strip any legacy time since placeholders -- TODO: Remove this in 1.3 */
493
+ $content = str_replace( '<span class="time-since">%s</span>', '', $content );
494
+
495
+ /* Insert the time since. */
496
+ $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 );
497
+
498
+ /* Insert the permalink */
499
+ $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 );
500
+
501
+ /* Add the delete link if the user has permission on this item */
502
+ if ( ( is_user_logged_in() && $activities_template->activity->user_id == $bp->loggedin_user->id ) || $bp->is_item_admin || $bp->loggedin_user->is_site_admin )
503
+ $content .= apply_filters( 'bp_activity_delete_link', ' &middot; ' . bp_get_activity_delete_link(), &$activities_template->activity );
504
+
505
+ return apply_filters( 'bp_insert_activity_meta', $content );
506
+ }
507
+
508
+ function bp_activity_parent_content( $args = '' ) {
509
+ echo bp_get_activity_parent_content($args);
510
+ }
511
+ function bp_get_activity_parent_content( $args = '' ) {
512
+ global $bp, $activities_template;
513
+
514
+ $defaults = array(
515
+ 'hide_user' => false
516
+ );
517
+
518
+ $r = wp_parse_args( $args, $defaults );
519
+ extract( $r, EXTR_SKIP );
520
+
521
+ /* Get the ID of the parent activity content */
522
+ if ( !$parent_id = $activities_template->activity->item_id )
523
+ return false;
524
+
525
+ /* Get the content of the parent */
526
+ if ( empty( $activities_template->activity_parents[$parent_id] ) )
527
+ return false;
528
+
529
+ if ( empty( $activities_template->activity_parents[$parent_id]->content ) )
530
+ $content = $activities_template->activity_parents[$parent_id]->action;
531
+ else
532
+ $content = $activities_template->activity_parents[$parent_id]->action . ' ' . $activities_template->activity_parents[$parent_id]->content;
533
+
534
+ /* Remove the time since content for backwards compatibility */
535
+ $content = str_replace( '<span class="time-since">%s</span>', '', $content );
536
+
537
+ /* Remove images */
538
+ $content = preg_replace( '/<img[^>]*>/Ui', '', $content );
539
+
540
+ return apply_filters( 'bp_get_activity_parent_content', $content );
541
+ }
542
+
543
+ function bp_activity_is_favorite() {
544
+ echo bp_get_activity_is_favorite();
545
+ }
546
+ function bp_get_activity_is_favorite() {
547
+ global $bp, $activities_template;
548
+
549
+ return apply_filters( 'bp_get_activity_is_favorite', in_array( $activities_template->activity->id, (array)$activities_template->my_favs ) );
550
+ }
551
+
552
+ function bp_activity_comments( $args = '' ) {
553
+ echo bp_activity_get_comments( $args );
554
+ }
555
+ function bp_activity_get_comments( $args = '' ) {
556
+ global $activities_template, $bp;
557
+
558
+ if ( !$activities_template->activity->children )
559
+ return false;
560
+
561
+ $comments_html = bp_activity_recurse_comments( $activities_template->activity );
562
+
563
+ return apply_filters( 'bp_activity_get_comments', $comments_html );
564
+ }
565
+ /* TODO: The HTML in this function is temporary and will be moved to the template in a future version. */
566
+ function bp_activity_recurse_comments( $comment ) {
567
+ global $activities_template, $bp;
568
+
569
+ if ( !$comment->children )
570
+ return false;
571
+
572
+ $content .= '<ul>';
573
+ foreach ( (array)$comment->children as $comment ) {
574
+ if ( !$comment->user_fullname )
575
+ $comment->user_fullname = $comment->display_name;
576
+
577
+ $content .= '<li id="acomment-' . $comment->id . '">';
578
+ $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' => 25, 'height' => 25, 'email' => $comment->user_email ) ) . '</a></div>';
579
+ $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 ) );
580
+
581
+ /* Reply link - the span is so that threaded reply links can be hidden when JS is off. */
582
+ if ( is_user_logged_in() )
583
+ $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>';
584
+
585
+ /* Delete link */
586
+ if ( $bp->loggedin_user->is_site_admin || $bp->loggedin_user->id == $comment->user_id )
587
+ $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>';
588
+
589
+ $content .= '</div>';
590
+ $content .= '<div class="acomment-content">' . apply_filters( 'bp_get_activity_content', $comment->content ) . '</div>';
591
+
592
+ $content .= bp_activity_recurse_comments( $comment );
593
+ $content .= '</li>';
594
+ }
595
+ $content .= '</ul>';
596
+
597
+ return apply_filters( 'bp_activity_recurse_comments', $content );
598
+ }
599
+
600
+ function bp_activity_comment_count() {
601
+ echo bp_activity_get_comment_count();
602
+ }
603
+ function bp_activity_get_comment_count( $args = '' ) {
604
+ global $activities_template, $bp;
605
+
606
+ if ( !$activities_template->activity->children )
607
+ return 0;
608
+
609
+ $count = bp_activity_recurse_comment_count( $activities_template->activity );
610
+
611
+ return apply_filters( 'bp_activity_get_comment_count', (int)$count );
612
+ }
613
+ function bp_activity_recurse_comment_count( $comment, $count = 0 ) {
614
+ global $activities_template, $bp;
615
+
616
+ if ( !$comment->children )
617
+ return $count;
618
+
619
+ foreach ( (array)$comment->children as $comment ) {
620
+ $count++;
621
+ $count = bp_activity_recurse_comment_count( $comment, $count );
622
+ }
623
+
624
+ return $count;
625
+ }
626
+
627
+ function bp_activity_comment_link() {
628
+ echo bp_get_activity_comment_link();
629
+ }
630
+ function bp_get_activity_comment_link() {
631
+ global $activities_template;
632
+ return apply_filters( 'bp_get_activity_comment_link', '?ac=' . $activities_template->activity->id . '/#ac-form-' . $activities_template->activity->id );
633
+ }
634
+
635
+ function bp_activity_comment_form_nojs_display() {
636
+ echo bp_get_activity_comment_form_nojs_display();
637
+ }
638
+ function bp_get_activity_comment_form_nojs_display() {
639
+ global $activities_template;
640
+ if ( $_GET['ac'] == $activities_template->activity->id . '/' )
641
+ return 'style="display: block"';
642
+
643
+ return false;
644
+ }
645
+
646
+ function bp_activity_comment_form_action() {
647
+ echo bp_get_activity_comment_form_action();
648
+ }
649
+ function bp_get_activity_comment_form_action() {
650
+ return apply_filters( 'bp_get_activity_comment_form_action', site_url( BP_ACTIVITY_SLUG . '/reply/' ) );
651
+ }
652
+
653
+ function bp_activity_permalink_id() {
654
+ echo bp_get_activity_permalink_id();
655
+ }
656
+ function bp_get_activity_permalink_id() {
657
+ global $bp;
658
+
659
+ return apply_filters( 'bp_get_activity_permalink_id', $bp->current_action );
660
+ }
661
+
662
+ function bp_activity_thread_permalink() {
663
+ echo bp_get_activity_thread_permalink();
664
+ }
665
+ function bp_get_activity_thread_permalink() {
666
+ global $bp, $activities_template;
667
+
668
+ $link = bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity );
669
+
670
+ return apply_filters( 'bp_get_activity_thread_permalink', $link );
671
+ }
672
+
673
+ function bp_activity_favorite_link() {
674
+ echo bp_get_activity_favorite_link();
675
+ }
676
+ function bp_get_activity_favorite_link() {
677
+ global $activities_template;
678
+ return apply_filters( 'bp_get_activity_favorite_link', wp_nonce_url( site_url( BP_ACTIVITY_SLUG . '/favorite/' . $activities_template->activity->id . '/' ), 'mark_favorite' ) );
679
+ }
680
+
681
+ function bp_activity_unfavorite_link() {
682
+ echo bp_get_activity_unfavorite_link();
683
+ }
684
+ function bp_get_activity_unfavorite_link() {
685
+ global $activities_template;
686
+ return apply_filters( 'bp_get_activity_unfavorite_link', wp_nonce_url( site_url( BP_ACTIVITY_SLUG . '/unfavorite/' . $activities_template->activity->id . '/' ), 'unmark_favorite' ) );
687
+ }
688
+
689
+ function bp_activity_css_class() {
690
+ echo bp_get_activity_css_class();
691
+ }
692
+ function bp_get_activity_css_class() {
693
+ global $activities_template;
694
+
695
+ $mini_activity_actions = apply_filters( 'bp_activity_mini_activity_types', array(
696
+ 'friendship_accepted',
697
+ 'friendship_created',
698
+ 'new_blog',
699
+ 'joined_group',
700
+ 'created_group',
701
+ 'new_member'
702
+ ) );
703
+
704
+ $class = '';
705
+ if ( in_array( $activities_template->activity->type, (array)$mini_activity_actions ) || empty( $activities_template->activity->content ) )
706
+ $class = ' mini';
707
+
708
+ if ( bp_activity_get_comment_count() && bp_activity_can_comment() )
709
+ $class .= ' has-comments';
710
+
711
+ return apply_filters( 'bp_get_activity_css_class', $activities_template->activity->component . ' ' . $activities_template->activity->type . $class );
712
+ }
713
+
714
+ function bp_activity_delete_link() {
715
+ echo bp_get_activity_delete_link();
716
+ }
717
+ function bp_get_activity_delete_link() {
718
+ global $activities_template, $bp;
719
+
720
+ 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>' );
721
+ }
722
+
723
+ function bp_activity_latest_update( $user_id = false ) {
724
+ echo bp_get_activity_latest_update( $user_id );
725
+ }
726
+ function bp_get_activity_latest_update( $user_id = false ) {
727
+ global $bp;
728
+
729
+ if ( !$user_id )
730
+ $user_id = $bp->displayed_user->id;
731
+
732
+ if ( !$update = get_usermeta( $user_id, 'bp_latest_update' ) )
733
+ return false;
734
+
735
+ $latest_update = '&quot;' . apply_filters( 'bp_get_activity_latest_update_excerpt', trim( strip_tags( bp_create_excerpt( $update['content'], 40 ) ) ) ) . '&quot;';
736
+ $latest_update .= ' &middot; <a href="' . $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $update['id'] . '/"> ' . __( 'View', 'buddypress' ) . '</a>';
737
+
738
+ return apply_filters( 'bp_get_activity_latest_update', $latest_update );
739
+ }
740
+
741
+ function bp_activity_filter_links( $args = false ) {
742
+ echo bp_get_activity_filter_links( $args );
743
+ }
744
+ function bp_get_activity_filter_links( $args = false ) {
745
+ global $activities_template, $bp;
746
+
747
+ $defaults = array(
748
+ 'style' => 'list'
749
+ );
750
+
751
+ $r = wp_parse_args( $args, $defaults );
752
+ extract( $r, EXTR_SKIP );
753
+
754
+ /* Fetch the names of components that have activity recorded in the DB */
755
+ $components = BP_Activity_Activity::get_recorded_components();
756
+
757
+ if ( !$components )
758
+ return false;
759
+
760
+ foreach ( (array) $components as $component ) {
761
+ /* Skip the activity comment filter */
762
+ if ( 'activity' == $component )
763
+ continue;
764
+
765
+ if ( isset( $_GET['afilter'] ) && $component == $_GET['afilter'] )
766
+ $selected = ' class="selected"';
767
+ else
768
+ unset($selected);
769
+
770
+ $component = attribute_escape( $component );
771
+
772
+ switch ( $style ) {
773
+ case 'list':
774
+ $tag = 'li';
775
+ $before = '<li id="afilter-' . $component . '"' . $selected . '>';
776
+ $after = '</li>';
777
+ break;
778
+ case 'paragraph':
779
+ $tag = 'p';
780
+ $before = '<p id="afilter-' . $component . '"' . $selected . '>';
781
+ $after = '</p>';
782
+ break;
783
+ case 'span':
784
+ $tag = 'span';
785
+ $before = '<span id="afilter-' . $component . '"' . $selected . '>';
786
+ $after = '</span>';
787
+ break;
788
+ }
789
+
790
+ $link = add_query_arg( 'afilter', $component );
791
+ $link = remove_query_arg( 'acpage' , $link );
792
+
793
+ $link = apply_filters( 'bp_get_activity_filter_link_href', $link, $component );
794
+
795
+ /* Make sure all core internal component names are translatable */
796
+ $translatable_components = array( __( 'profile', 'buddypress'), __( 'friends', 'buddypress' ), __( 'groups', 'buddypress' ), __( 'status', 'buddypress' ), __( 'blogs', 'buddypress' ) );
797
+
798
+ $component_links[] = $before . '<a href="' . attribute_escape( $link ) . '">' . ucwords( __( $component, 'buddypress' ) ) . '</a>' . $after;
799
+ }
800
+
801
+ $link = remove_query_arg( 'afilter' , $link );
802
+
803
+ if ( isset( $_GET['afilter'] ) )
804
+ $component_links[] = '<' . $tag . ' id="afilter-clear"><a href="' . attribute_escape( $link ) . '"">' . __( 'Clear Filter', 'buddypress' ) . '</a></' . $tag . '>';
805
+
806
+ return apply_filters( 'bp_get_activity_filter_links', implode( "\n", $component_links ) );
807
+ }
808
+
809
+ function bp_activity_can_comment() {
810
+ global $activities_template, $bp;
811
+
812
+ if ( false === $activities_template->disable_blogforum_replies || (int)$activities_template->disable_blogforum_replies ) {
813
+ 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() )
814
+ return false;
815
+ }
816
+
817
+ if ( 'activity_comment' == bp_get_activity_action_name() )
818
+ return false;
819
+
820
+ return true;
821
+ }
822
+
823
+ function bp_total_favorite_count_for_user( $user_id = false ) {
824
+ echo bp_get_total_favorite_count_for_user( $user_id );
825
+ }
826
+ function bp_get_total_favorite_count_for_user( $user_id = false ) {
827
+ return apply_filters( 'bp_get_total_favorite_count_for_user', bp_activity_total_favorites_for_user( $user_id ) );
828
+ }
829
+
830
+ function bp_total_mention_count_for_user( $user_id = false ) {
831
+ echo bp_get_total_favorite_count_for_user( $user_id );
832
+ }
833
+ function bp_get_total_mention_count_for_user( $user_id = false ) {
834
+ return apply_filters( 'bp_get_total_mention_count_for_user', get_usermeta( $user_id, 'bp_new_mention_count' ) );
835
+ }
836
+
837
+ function bp_send_public_message_link() {
838
+ echo bp_get_send_public_message_link();
839
+ }
840
+ function bp_get_send_public_message_link() {
841
+ global $bp;
842
+
843
+ return apply_filters( 'bp_get_send_public_message_link', $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 ) );
844
+ }
845
+
846
+ function bp_activity_post_form_action() {
847
+ echo bp_get_activity_post_form_action();
848
+ }
849
+ function bp_get_activity_post_form_action() {
850
+ return apply_filters( 'bp_get_activity_post_form_action', site_url( BP_ACTIVITY_SLUG . '/post/' ) );
851
+ }
852
+
853
+ /* RSS Feed Template Tags ***************************/
854
+
855
+ function bp_sitewide_activity_feed_link() {
856
+ echo bp_get_sitewide_activity_feed_link();
857
+ }
858
+ function bp_get_sitewide_activity_feed_link() {
859
+ global $bp;
860
+
861
+ return apply_filters( 'bp_get_sitewide_activity_feed_link', site_url( $bp->activity->slug . '/feed/' ) );
862
+ }
863
+
864
+ function bp_member_activity_feed_link() {
865
+ echo bp_get_member_activity_feed_link();
866
+ }
867
+ function bp_activities_member_rss_link() { echo bp_get_member_activity_feed_link(); }
868
+
869
+ function bp_get_member_activity_feed_link() {
870
+ global $bp;
871
+
872
+ if ( $bp->current_component == $bp->profile->slug || 'just-me' == $bp->current_action )
873
+ $link = $bp->displayed_user->domain . $bp->activity->slug . '/feed/';
874
+ else if ( 'friends' == $bp->current_action )
875
+ $link = $bp->displayed_user->domain . $bp->activity->slug . '/friends/feed/';
876
+ else if ( 'groups' == $bp->current_action )
877
+ $link = $bp->displayed_user->domain . $bp->activity->slug . '/groups/feed/';
878
+ else if ( 'favorites' == $bp->current_action )
879
+ $link = $bp->displayed_user->domain . $bp->activity->slug . '/favorites/feed/';
880
+ else if ( 'mentions' == $bp->current_action )
881
+ $link = $bp->displayed_user->domain . $bp->activity->slug . '/mentions/feed/';
882
+
883
+ return apply_filters( 'bp_get_activities_member_rss_link', $link );
884
+ }
885
+ function bp_get_activities_member_rss_link() { return bp_get_member_activity_feed_link(); }
886
+
887
+
888
+ /* Template tags for RSS feed output */
889
+
890
+ function bp_activity_feed_item_guid() {
891
+ echo bp_get_activity_feed_item_guid();
892
+ }
893
+ function bp_get_activity_feed_item_guid() {
894
+ global $activities_template;
895
+
896
+ return apply_filters( 'bp_get_activity_feed_item_guid', md5( $activities_template->activity->date_recorded . '-' . $activities_template->activity->content ) );
897
+ }
898
+
899
+ function bp_activity_feed_item_title() {
900
+ echo bp_get_activity_feed_item_title();
901
+ }
902
+ function bp_get_activity_feed_item_title() {
903
+ global $activities_template;
904
+
905
+ if ( !empty( $activities_template->activity->action ) )
906
+ $content = $activities_template->activity->action;
907
+ else
908
+ $content = $activities_template->activity->content;
909
+
910
+ $content = explode( '<span', $content );
911
+ $title = trim( strip_tags( html_entity_decode( utf8_encode( $content[0] ) ) ) );
912
+
913
+ if ( ':' == substr( $title, -1 ) )
914
+ $title = substr( $title, 0, -1 );
915
+
916
+ if ( 'activity_update' == $activities_template->activity->type )
917
+ $title .= ': ' . strip_tags( bp_create_excerpt( $activities_template->activity->content, 15 ) );
918
+
919
+ return apply_filters( 'bp_get_activity_feed_item_title', $title );
920
+ }
921
+
922
+ function bp_activity_feed_item_link() {
923
+ echo bp_get_activity_feed_item_link();
924
+ }
925
+ function bp_get_activity_feed_item_link() {
926
+ global $activities_template;
927
+
928
+ return apply_filters( 'bp_get_activity_feed_item_link', $activities_template->activity->primary_link );
929
+ }
930
+
931
+ function bp_activity_feed_item_date() {
932
+ echo bp_get_activity_feed_item_date();
933
+ }
934
+ function bp_get_activity_feed_item_date() {
935
+ global $activities_template;
936
+
937
+ return apply_filters( 'bp_get_activity_feed_item_date', $activities_template->activity->date_recorded );
938
+ }
939
+
940
+ function bp_activity_feed_item_description() {
941
+ echo bp_get_activity_feed_item_description();
942
+ }
943
+ function bp_get_activity_feed_item_description() {
944
+ global $activities_template;
945
+
946
+ if ( empty( $activities_template->activity->action ) )
947
+ $content = $activities_template->activity->content;
948
+ else
949
+ $content = $activities_template->activity->action . ' ' . $activities_template->activity->content;
950
+
951
+ return apply_filters( 'bp_get_activity_feed_item_description', html_entity_decode( str_replace( '%s', '', $content ) ) );
952
+ }
953
+
954
  ?>
bp-activity/feeds/bp-activity-favorites-feed.php CHANGED
@@ -14,7 +14,7 @@ header('Status: 200 OK');
14
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
15
  xmlns:dc="http://purl.org/dc/elements/1.1/"
16
  xmlns:atom="http://www.w3.org/2005/Atom"
17
- <?php do_action('bp_activity_mentions_feed'); ?>
18
  >
19
 
20
  <channel>
14
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
15
  xmlns:dc="http://purl.org/dc/elements/1.1/"
16
  xmlns:atom="http://www.w3.org/2005/Atom"
17
+ <?php do_action('bp_activity_favorites_feed'); ?>
18
  >
19
 
20
  <channel>
bp-activity/feeds/bp-activity-friends-feed.php CHANGED
@@ -1,59 +1,59 @@
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
- ?>
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/"
14
- xmlns:wfw="http://wellformedweb.org/CommentAPI/"
15
- xmlns:dc="http://purl.org/dc/elements/1.1/"
16
- xmlns:atom="http://www.w3.org/2005/Atom"
17
- <?php do_action('bp_activity_friends_feed'); ?>
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>
53
- <?php do_action('bp_activity_personal_feed_item'); ?>
54
- </item>
55
- <?php endwhile; ?>
56
-
57
- <?php endif; ?>
58
- </channel>
59
- </rss>
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
+ ?>
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/"
14
+ xmlns:wfw="http://wellformedweb.org/CommentAPI/"
15
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
16
+ xmlns:atom="http://www.w3.org/2005/Atom"
17
+ <?php do_action('bp_activity_friends_feed'); ?>
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>
53
+ <?php do_action('bp_activity_personal_feed_item'); ?>
54
+ </item>
55
+ <?php endwhile; ?>
56
+
57
+ <?php endif; ?>
58
+ </channel>
59
+ </rss>
bp-activity/feeds/bp-activity-personal-feed.php CHANGED
@@ -1,58 +1,58 @@
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
- ?>
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/"
14
- xmlns:wfw="http://wellformedweb.org/CommentAPI/"
15
- xmlns:dc="http://purl.org/dc/elements/1.1/"
16
- xmlns:atom="http://www.w3.org/2005/Atom"
17
- <?php do_action('bp_activity_personal_feed'); ?>
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>
27
- <language><?php echo get_option('rss_language'); ?></language>
28
- <?php do_action('bp_activity_personal_feed_head'); ?>
29
-
30
- <?php if ( bp_has_activities( 'user_id=' . $bp->displayed_user->id . '&max=50&display_comments=stream' ) ) : ?>
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
-
38
- <description>
39
- <![CDATA[
40
- <?php bp_activity_feed_item_description() ?>
41
-
42
- <?php if ( bp_activity_can_comment() ) : ?>
43
- <p><?php printf( __( 'Comments: %s', 'buddypress' ), bp_activity_get_comment_count() ); ?></p>
44
- <?php endif; ?>
45
-
46
- <?php if ( 'activity_comment' == bp_get_activity_action_name() ) : ?>
47
- <br /><strong><?php _e( 'In reply to', 'buddypress' ) ?></strong> -
48
- <?php bp_activity_parent_content() ?>
49
- <?php endif; ?>
50
- ]]>
51
- </description>
52
- <?php do_action('bp_activity_personal_feed_item'); ?>
53
- </item>
54
- <?php endwhile; ?>
55
-
56
- <?php endif; ?>
57
- </channel>
58
- </rss>
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
+ ?>
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/"
14
+ xmlns:wfw="http://wellformedweb.org/CommentAPI/"
15
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
16
+ xmlns:atom="http://www.w3.org/2005/Atom"
17
+ <?php do_action('bp_activity_personal_feed'); ?>
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>
27
+ <language><?php echo get_option('rss_language'); ?></language>
28
+ <?php do_action('bp_activity_personal_feed_head'); ?>
29
+
30
+ <?php if ( bp_has_activities( 'user_id=' . $bp->displayed_user->id . '&max=50&display_comments=stream' ) ) : ?>
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
+
38
+ <description>
39
+ <![CDATA[
40
+ <?php bp_activity_feed_item_description() ?>
41
+
42
+ <?php if ( bp_activity_can_comment() ) : ?>
43
+ <p><?php printf( __( 'Comments: %s', 'buddypress' ), bp_activity_get_comment_count() ); ?></p>
44
+ <?php endif; ?>
45
+
46
+ <?php if ( 'activity_comment' == bp_get_activity_action_name() ) : ?>
47
+ <br /><strong><?php _e( 'In reply to', 'buddypress' ) ?></strong> -
48
+ <?php bp_activity_parent_content() ?>
49
+ <?php endif; ?>
50
+ ]]>
51
+ </description>
52
+ <?php do_action('bp_activity_personal_feed_item'); ?>
53
+ </item>
54
+ <?php endwhile; ?>
55
+
56
+ <?php endif; ?>
57
+ </channel>
58
+ </rss>
bp-activity/feeds/bp-activity-sitewide-feed.php CHANGED
@@ -1,54 +1,54 @@
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
- ?>
11
- <?php echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
12
-
13
- <rss version="2.0"
14
- xmlns:content="http://purl.org/rss/1.0/modules/content/"
15
- xmlns:wfw="http://wellformedweb.org/CommentAPI/"
16
- xmlns:dc="http://purl.org/dc/elements/1.1/"
17
- xmlns:atom="http://www.w3.org/2005/Atom"
18
- <?php do_action('bp_activity_sitewide_feed'); ?>
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>
28
- <language><?php echo get_option('rss_language'); ?></language>
29
- <?php do_action('bp_activity_sitewide_feed_head'); ?>
30
-
31
- <?php if ( bp_has_activities( 'type=sitewide&max=50&display_comments=threaded' ) ) : ?>
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
-
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
- </description>
48
- <?php do_action('bp_activity_personal_feed_item'); ?>
49
- </item>
50
- <?php endwhile; ?>
51
-
52
- <?php endif; ?>
53
- </channel>
54
- </rss>
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
+ ?>
11
+ <?php echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
12
+
13
+ <rss version="2.0"
14
+ xmlns:content="http://purl.org/rss/1.0/modules/content/"
15
+ xmlns:wfw="http://wellformedweb.org/CommentAPI/"
16
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
17
+ xmlns:atom="http://www.w3.org/2005/Atom"
18
+ <?php do_action('bp_activity_sitewide_feed'); ?>
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>
28
+ <language><?php echo get_option('rss_language'); ?></language>
29
+ <?php do_action('bp_activity_sitewide_feed_head'); ?>
30
+
31
+ <?php if ( bp_has_activities( 'type=sitewide&max=50&display_comments=threaded' ) ) : ?>
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
+
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
+ </description>
48
+ <?php do_action('bp_activity_personal_feed_item'); ?>
49
+ </item>
50
+ <?php endwhile; ?>
51
+
52
+ <?php endif; ?>
53
+ </channel>
54
+ </rss>
bp-blogs.php CHANGED
@@ -1,750 +1,800 @@
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/upgrade-functions.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_site_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( '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->table_name = $wpdb->base_prefix . 'bp_user_blogs';
72
- $bp->blogs->table_name_blogmeta = $wpdb->base_prefix . 'bp_user_blogs_blogmeta';
73
- $bp->blogs->format_notification_function = 'bp_blogs_format_notifications';
74
- $bp->blogs->slug = BP_BLOGS_SLUG;
75
-
76
- /* Register this in the active components array */
77
- $bp->active_components[$bp->blogs->slug] = $bp->blogs->id;
78
-
79
- do_action( 'bp_blogs_setup_globals' );
80
- }
81
- add_action( 'bp_setup_globals', 'bp_blogs_setup_globals' );
82
-
83
- function bp_blogs_setup_root_component() {
84
- /* Register 'blogs' as a root component */
85
- bp_core_add_root_component( BP_BLOGS_SLUG );
86
- }
87
- add_action( 'bp_setup_root_components', 'bp_blogs_setup_root_component' );
88
-
89
- /**
90
- * bp_blogs_setup_nav()
91
- *
92
- * Adds "Blog" to the navigation arrays for the current and logged in user.
93
- *
94
- * @package BuddyPress Blogs
95
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
96
- * @uses bp_is_my_profile() Checks to see if the current user being viewed is the logged in user
97
- */
98
- function bp_blogs_setup_nav() {
99
- global $bp;
100
-
101
- /* Blog/post/comment menus should not appear on single WordPress setups. Although comments
102
- and posts made by users will still show on their activity stream .*/
103
- if ( !bp_core_is_multisite() )
104
- return false;
105
-
106
- /* Add 'Blogs' to the main navigation */
107
- 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 ) );
108
-
109
- $blogs_link = $bp->loggedin_user->domain . $bp->blogs->slug . '/';
110
-
111
- /* Set up the component options navigation for Blog */
112
- if ( 'blogs' == $bp->current_component ) {
113
- if ( bp_is_my_profile() ) {
114
- if ( function_exists('xprofile_setup_nav') ) {
115
- $bp->bp_options_title = __('My Blogs', 'buddypress');
116
- }
117
- } else {
118
- /* If we are not viewing the logged in user, set up the current users avatar and name */
119
- $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
120
- $bp->bp_options_title = $bp->displayed_user->fullname;
121
- }
122
- }
123
-
124
- do_action( 'bp_blogs_setup_nav' );
125
- }
126
- add_action( 'bp_setup_nav', 'bp_blogs_setup_nav' );
127
-
128
- function bp_blogs_directory_blogs_setup() {
129
- global $bp;
130
-
131
- if ( bp_core_is_multisite() && $bp->current_component == $bp->blogs->slug && empty( $bp->current_action ) ) {
132
- $bp->is_directory = true;
133
-
134
- do_action( 'bp_blogs_directory_blogs_setup' );
135
- bp_core_load_template( apply_filters( 'bp_blogs_template_directory_blogs_setup', 'blogs/index' ) );
136
- }
137
- }
138
- add_action( 'wp', 'bp_blogs_directory_blogs_setup', 2 );
139
-
140
-
141
- /********************************************************************************
142
- * Screen Functions
143
- *
144
- * Screen functions are the controllers of BuddyPress. They will execute when their
145
- * specific URL is caught. They will first save or manipulate data using business
146
- * functions, then pass on the user to a template file.
147
- */
148
-
149
- function bp_blogs_screen_my_blogs() {
150
- global $bp;
151
-
152
- if ( !bp_core_is_multisite() )
153
- return false;
154
-
155
- do_action( 'bp_blogs_screen_my_blogs' );
156
- bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'members/single/home' ) );
157
- }
158
-
159
- function bp_blogs_screen_create_a_blog() {
160
- global $bp;
161
-
162
- if ( !bp_core_is_multisite() || $bp->current_component != $bp->blogs->slug || 'create' != $bp->current_action )
163
- return false;
164
-
165
- if ( !is_user_logged_in() || !bp_blog_signup_enabled() )
166
- return false;
167
-
168
- do_action( 'bp_blogs_screen_create_a_blog' );
169
- bp_core_load_template( apply_filters( 'bp_blogs_template_create_a_blog', 'blogs/create' ) );
170
- }
171
- /* The create screen is not attached to a nav item, so we need to attach it to an action */
172
- add_action( 'wp', 'bp_blogs_screen_create_a_blog', 3 );
173
-
174
-
175
- /********************************************************************************
176
- * Activity & Notification Functions
177
- *
178
- * These functions handle the recording, deleting and formatting of activity and
179
- * notifications for the user and for this specific component.
180
- */
181
-
182
- function bp_blogs_register_activity_actions() {
183
- global $bp;
184
-
185
- if ( !function_exists( 'bp_activity_set_action' ) )
186
- return false;
187
-
188
- bp_activity_set_action( $bp->blogs->id, 'new_blog', __( 'New blog created', 'buddypress' ) );
189
- bp_activity_set_action( $bp->blogs->id, 'new_blog_post', __( 'New blog post published', 'buddypress' ) );
190
- bp_activity_set_action( $bp->blogs->id, 'new_blog_comment', __( 'New blog post comment posted', 'buddypress' ) );
191
-
192
- do_action( 'bp_blogs_register_activity_actions' );
193
- }
194
- add_action( 'bp_register_activity_actions', 'bp_blogs_register_activity_actions' );
195
-
196
- function bp_blogs_record_activity( $args = '' ) {
197
- global $bp;
198
-
199
- if ( !function_exists( 'bp_activity_add' ) )
200
- return false;
201
-
202
- /* Because blog, comment, and blog post code execution happens before anything else
203
- we may need to manually instantiate the activity component globals */
204
- if ( !$bp->activity && function_exists('bp_activity_setup_globals') )
205
- bp_activity_setup_globals();
206
-
207
- $defaults = array(
208
- 'user_id' => $bp->loggedin_user->id,
209
- 'action' => '',
210
- 'content' => '',
211
- 'primary_link' => '',
212
- 'component' => $bp->blogs->id,
213
- 'type' => false,
214
- 'item_id' => false,
215
- 'secondary_item_id' => false,
216
- 'recorded_time' => gmdate( "Y-m-d H:i:s" ),
217
- 'hide_sitewide' => false
218
- );
219
-
220
- $r = wp_parse_args( $args, $defaults );
221
- extract( $r, EXTR_SKIP );
222
-
223
- /* Remove large images and replace them with just one image thumbnail */
224
- if ( function_exists( 'bp_activity_thumbnail_content_images' ) && !empty( $content ) )
225
- $content = bp_activity_thumbnail_content_images( $content );
226
-
227
- if ( !empty( $action ) )
228
- $action = apply_filters( 'bp_blogs_record_activity_action', $action );
229
-
230
- if ( !empty( $content ) )
231
- $content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $content ) );
232
-
233
- /* Check for an existing entry and update if one exists. */
234
- $id = bp_activity_get_activity_id( array(
235
- 'user_id' => $user_id,
236
- 'component' => $component,
237
- 'type' => $type,
238
- 'item_id' => $item_id,
239
- 'secondary_item_id' => $secondary_item_id
240
- ) );
241
-
242
- 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 ) );
243
- }
244
-
245
- function bp_blogs_delete_activity( $args = true ) {
246
- global $bp;
247
-
248
- if ( function_exists('bp_activity_delete_by_item_id') ) {
249
- $defaults = array(
250
- 'item_id' => false,
251
- 'component' => $bp->blogs->id,
252
- 'type' => false,
253
- 'user_id' => false,
254
- 'secondary_item_id' => false
255
- );
256
-
257
- $params = wp_parse_args( $args, $defaults );
258
- extract( $params, EXTR_SKIP );
259
-
260
- bp_activity_delete_by_item_id( array(
261
- 'item_id' => $item_id,
262
- 'component' => $component,
263
- 'type' => $type,
264
- 'user_id' => $user_id,
265
- 'secondary_item_id' => $secondary_item_id
266
- ) );
267
- }
268
- }
269
-
270
- /********************************************************************************
271
- * Business Functions
272
- *
273
- * Business functions are where all the magic happens in BuddyPress. They will
274
- * handle the actual saving or manipulation of information. Usually they will
275
- * hand off to a database class for data access, then return
276
- * true or false on success or failure.
277
- */
278
-
279
- function bp_blogs_get_blogs( $args = '' ) {
280
- global $bp;
281
-
282
- $defaults = array(
283
- 'type' => 'active', // active, alphabetical, newest, or random.
284
- 'user_id' => false, // Pass a user_id to limit to only blogs that this user has privilages higher than subscriber on.
285
- 'search_terms' => false, // Limit to blogs that match these search terms
286
-
287
- 'per_page' => 20, // The number of results to return per page
288
- 'page' => 1, // The page to return if limiting per page
289
- );
290
-
291
- $params = wp_parse_args( $args, $defaults );
292
- extract( $params, EXTR_SKIP );
293
-
294
- return apply_filters( 'bp_blogs_get_blogs', BP_Blogs_Blog::get( $type, $per_page, $page, $user_id, $search_terms ), &$params );
295
- }
296
-
297
- function bp_blogs_record_existing_blogs() {
298
- global $bp, $wpdb;
299
-
300
- /* Truncate user blogs table and re-record. */
301
- $wpdb->query( "TRUNCATE TABLE {$bp->blogs->table_name}" );
302
-
303
- $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$wpdb->base_prefix}blogs WHERE mature = 0 AND spam = 0 AND deleted = 0" ) );
304
-
305
- if ( $blog_ids ) {
306
- foreach( (array)$blog_ids as $blog_id ) {
307
- $users = get_users_of_blog( $blog_id );
308
-
309
- if ( $users ) {
310
- foreach ( (array)$users as $user ) {
311
- $role = unserialize( $user->meta_value );
312
-
313
- if ( !isset( $role['subscriber'] ) )
314
- bp_blogs_record_blog( $blog_id, $user->user_id, true );
315
- }
316
- }
317
- }
318
- }
319
- }
320
-
321
- function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) {
322
- global $bp;
323
-
324
- if ( !$user_id )
325
- $user_id = $bp->loggedin_user->id;
326
-
327
- $name = get_blog_option( $blog_id, 'blogname' );
328
- $description = get_blog_option( $blog_id, 'blogdescription' );
329
-
330
- if ( empty( $name ) )
331
- return false;
332
-
333
- $recorded_blog = new BP_Blogs_Blog;
334
- $recorded_blog->user_id = $user_id;
335
- $recorded_blog->blog_id = $blog_id;
336
-
337
- $recorded_blog_id = $recorded_blog->save();
338
-
339
- bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'name', $name );
340
- bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description );
341
- bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
342
-
343
- /* Only record this activity if the blog is public */
344
- if ( (int)$_POST['blog_public'] && !$no_activity ) {
345
- /* Record this in activity streams */
346
- bp_blogs_record_activity( array(
347
- 'user_id' => $recorded_blog->user_id,
348
- '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_blog_option( $recorded_blog->blog_id, 'siteurl' ) . '">' . attribute_escape( $name ) . '</a>' ), &$recorded_blog, $name, $description ),
349
- 'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', get_blog_option( $recorded_blog->blog_id, 'siteurl' ), $recorded_blog->blog_id ),
350
- 'type' => 'new_blog',
351
- 'item_id' => $recorded_blog->blog_id
352
- ) );
353
- }
354
-
355
- do_action( 'bp_blogs_new_blog', &$recorded_blog, $is_private, $is_recorded );
356
- }
357
- add_action( 'wpmu_new_blog', 'bp_blogs_record_blog', 10, 2 );
358
-
359
- function bp_blogs_record_post( $post_id, $post, $user_id = false ) {
360
- global $bp, $wpdb;
361
-
362
- $post_id = (int)$post_id;
363
- $blog_id = (int)$wpdb->blogid;
364
-
365
- if ( !$user_id )
366
- $user_id = (int)$post->post_author;
367
-
368
- /* This is to stop infinite loops with Donncha's sitewide tags plugin */
369
- if ( (int)$bp->site_options['tags_blog_id'] == (int)$blog_id )
370
- return false;
371
-
372
- /* Don't record this if it's not a post */
373
- if ( $post->post_type != 'post' )
374
- return false;
375
-
376
- if ( 'publish' == $post->post_status && '' == $post->post_password ) {
377
- if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
378
- /* Record this in activity streams */
379
- $post_permalink = get_permalink( $post_id );
380
-
381
- $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>' );
382
- $activity_content = $post->post_content;
383
-
384
- bp_blogs_record_activity( array(
385
- 'user_id' => (int)$post->post_author,
386
- 'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, &$post, $post_permalink ),
387
- 'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink ),
388
- 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
389
- 'type' => 'new_blog_post',
390
- 'item_id' => $blog_id,
391
- 'secondary_item_id' => $post_id,
392
- 'recorded_time' => $post->post_date_gmt
393
- ));
394
- }
395
- } else
396
- bp_blogs_remove_post( $post_id, $blog_id );
397
-
398
- bp_blogs_update_blogmeta( $blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
399
-
400
- do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
401
- }
402
- add_action( 'save_post', 'bp_blogs_record_post', 10, 2 );
403
-
404
- function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
405
- global $wpdb, $bp;
406
-
407
- $comment = get_comment($comment_id);
408
-
409
- if ( !$is_approved )
410
- return false;
411
-
412
- $comment->post = get_post( $comment->comment_post_ID );
413
-
414
- /* Get the user_id from the author email. */
415
- $user = get_user_by_email( $comment->comment_author_email );
416
- $user_id = (int)$user->ID;
417
-
418
- if ( !$user_id )
419
- return false;
420
-
421
- /* If this is a password protected post, don't record the comment */
422
- if ( !empty( $post->post_password ) )
423
- return false;
424
-
425
- if ( (int)get_blog_option( $recorded_comment->blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
426
- /* Record in activity streams */
427
- $comment_link = htmlspecialchars( get_comment_link( $comment->comment_ID ) );
428
- $activity_action = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $comment_link . '">' . $comment->post->post_title . '</a>' );
429
- $activity_content = $comment->comment_content;
430
-
431
- /* Record this in activity streams */
432
- bp_blogs_record_activity( array(
433
- 'user_id' => $user_id,
434
- 'action' => apply_filters( 'bp_blogs_activity_new_comment_action', $activity_action, &$comment, &$recorded_comment, $comment_link ),
435
- 'content' => apply_filters( 'bp_blogs_activity_new_comment_content', $activity_content, &$comment, &$recorded_comment, $comment_link ),
436
- 'primary_link' => apply_filters( 'bp_blogs_activity_new_comment_primary_link', $comment_link, &$comment, &$recorded_comment ),
437
- 'type' => 'new_blog_comment',
438
- 'item_id' => $wpdb->blogid,
439
- 'secondary_item_id' => $comment_id,
440
- 'recorded_time' => $comment->comment_date_gmt
441
- ) );
442
-
443
- bp_blogs_update_blogmeta( $blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
444
- }
445
-
446
- return $recorded_comment;
447
- }
448
- add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
449
- add_action( 'edit_comment', 'bp_blogs_record_comment', 10 );
450
-
451
- function bp_blogs_manage_comment( $comment_id, $comment_status ) {
452
- if ( 'spam' == $comment_status || 'hold' == $comment_status || 'delete' == $comment_status || 'trash' == $comment_status )
453
- return bp_blogs_remove_comment( $comment_id );
454
-
455
- return bp_blogs_record_comment( $comment_id, true );
456
- }
457
- add_action( 'wp_set_comment_status', 'bp_blogs_manage_comment', 10, 2 );
458
-
459
- function bp_blogs_add_user_to_blog( $user_id, $role, $blog_id = false ) {
460
- global $current_blog;
461
-
462
- if ( empty( $blog_id ) )
463
- $blog_id = $current_blog->blog_id;
464
-
465
- if ( $role != 'subscriber' )
466
- bp_blogs_record_blog( $blog_id, $user_id, true );
467
- }
468
- add_action( 'add_user_to_blog', 'bp_blogs_add_user_to_blog', 10, 3 );
469
-
470
- function bp_blogs_remove_user_from_blog( $user_id, $blog_id = false ) {
471
- global $current_blog;
472
-
473
- if ( empty( $blog_id ) )
474
- $blog_id = $current_blog->blog_id;
475
-
476
- bp_blogs_remove_blog_for_user( $user_id, $blog_id );
477
- }
478
- add_action( 'remove_user_from_blog', 'bp_blogs_remove_user_from_blog', 10, 2 );
479
-
480
- function bp_blogs_remove_blog( $blog_id ) {
481
- global $bp;
482
-
483
- $blog_id = (int)$blog_id;
484
-
485
- BP_Blogs_Blog::delete_blog_for_all( $blog_id );
486
-
487
- // Delete activity stream item
488
- bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog' ) );
489
-
490
- do_action( 'bp_blogs_remove_blog', $blog_id );
491
- }
492
- add_action( 'delete_blog', 'bp_blogs_remove_blog' );
493
-
494
- function bp_blogs_remove_blog_for_user( $user_id, $blog_id ) {
495
- global $current_user;
496
-
497
- $blog_id = (int)$blog_id;
498
- $user_id = (int)$user_id;
499
-
500
- BP_Blogs_Blog::delete_blog_for_user( $blog_id, $user_id );
501
-
502
- // Delete activity stream item
503
- bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog' ) );
504
-
505
- do_action( 'bp_blogs_remove_blog_for_user', $blog_id, $user_id );
506
- }
507
- add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 );
508
-
509
- function bp_blogs_remove_post( $post_id, $blog_id = false ) {
510
- global $current_blog, $bp;
511
-
512
- $post_id = (int)$post_id;
513
-
514
- if ( !$blog_id )
515
- $blog_id = (int)$current_blog->blog_id;
516
-
517
- // Delete activity stream item
518
- bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog_post' ) );
519
-
520
- do_action( 'bp_blogs_remove_post', $blog_id, $post_id, $post->user_id );
521
- }
522
- add_action( 'delete_post', 'bp_blogs_remove_post' );
523
-
524
- function bp_blogs_remove_comment( $comment_id ) {
525
- global $wpdb, $bp;
526
-
527
- // Delete activity stream item
528
- bp_blogs_delete_activity( array( 'item_id' => $wpdb->blogid , 'secondary_item_id' => $comment_id, 'type' => 'new_blog_comment' ) );
529
-
530
- do_action( 'bp_blogs_remove_comment', $blog_id, $comment_id, $bp->loggedin_user->id );
531
- }
532
- add_action( 'delete_comment', 'bp_blogs_remove_comment' );
533
-
534
- function bp_blogs_total_blogs() {
535
- if ( !$count = wp_cache_get( 'bp_total_blogs', 'bp' ) ) {
536
- $blogs = BP_Blogs_Blog::get_all();
537
- $count = $blogs['total'];
538
- wp_cache_set( 'bp_total_blogs', $count, 'bp' );
539
- }
540
- return $count;
541
- }
542
-
543
- function bp_blogs_total_blogs_for_user( $user_id = false ) {
544
- global $bp;
545
-
546
- if ( !$user_id )
547
- $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
548
-
549
- if ( !$count = wp_cache_get( 'bp_total_blogs_for_user_' . $user_id, 'bp' ) ) {
550
- $count = BP_Blogs_Blog::total_blog_count_for_user( $user_id );
551
- wp_cache_set( 'bp_total_blogs_for_user_' . $user_id, $count, 'bp' );
552
- }
553
-
554
- return $count;
555
- }
556
-
557
- function bp_blogs_remove_data_for_blog( $blog_id ) {
558
- global $bp;
559
-
560
- /* If this is regular blog, delete all data for that blog. */
561
- BP_Blogs_Blog::delete_blog_for_all( $blog_id );
562
-
563
- // Delete activity stream item
564
- bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->slug, 'type' => false ) );
565
-
566
- do_action( 'bp_blogs_remove_data_for_blog', $blog_id );
567
- }
568
- add_action( 'delete_blog', 'bp_blogs_remove_data_for_blog', 1 );
569
-
570
- function bp_blogs_get_blogs_for_user( $user_id, $show_hidden = false ) {
571
- return BP_Blogs_Blog::get_blogs_for_user( $user_id, $show_hidden );
572
- }
573
-
574
- function bp_blogs_get_all_blogs( $limit = null, $page = null ) {
575
- return BP_Blogs_Blog::get_all( $limit, $page );
576
- }
577
-
578
- function bp_blogs_get_random_blogs( $limit = null, $page = null ) {
579
- return BP_Blogs_Blog::get( 'random', $limit, $page );
580
- }
581
-
582
- function bp_blogs_is_blog_hidden( $blog_id ) {
583
- return BP_Blogs_Blog::is_hidden( $blog_id );
584
- }
585
-
586
- function bp_blogs_redirect_to_random_blog() {
587
- global $bp, $wpdb;
588
-
589
- if ( $bp->current_component == $bp->blogs->slug && isset( $_GET['random-blog'] ) ) {
590
- $blog = bp_blogs_get_random_blogs( 1, 1 );
591
-
592
- bp_core_redirect( get_blog_option( $blog['blogs'][0]->blog_id, 'siteurl') );
593
- }
594
- }
595
- add_action( 'wp', 'bp_blogs_redirect_to_random_blog', 6 );
596
-
597
-
598
- //
599
- // Blog meta functions
600
- // These functions are used to store specific blogmeta in one global table, rather than in each
601
- // blog's options table. Significantly speeds up global blog queries.
602
- // By default each blog's name, description and last updated time are stored and synced here.
603
- //
604
-
605
- function bp_blogs_delete_blogmeta( $blog_id, $meta_key = false, $meta_value = false ) {
606
- global $wpdb, $bp;
607
-
608
- if ( !is_numeric( $blog_id ) || !bp_core_is_multisite() )
609
- return false;
610
-
611
- $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
612
-
613
- if ( is_array($meta_value) || is_object($meta_value) )
614
- $meta_value = serialize($meta_value);
615
-
616
- $meta_value = trim( $meta_value );
617
-
618
- if ( !$meta_key ) {
619
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d", $blog_id ) );
620
- } else if ( $meta_value ) {
621
- $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 ) );
622
- } else {
623
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key ) );
624
- }
625
-
626
- wp_cache_delete( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, 'bp' );
627
-
628
- return true;
629
- }
630
-
631
- function bp_blogs_get_blogmeta( $blog_id, $meta_key = '') {
632
- global $wpdb, $bp;
633
-
634
- $blog_id = (int) $blog_id;
635
-
636
- if ( !$blog_id || !bp_core_is_multisite() )
637
- return false;
638
-
639
- if ( !empty($meta_key) ) {
640
- $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
641
-
642
- if ( !$metas = wp_cache_get( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, 'bp' ) ) {
643
- $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 ) );
644
- wp_cache_set( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, $metas, 'bp' );
645
- }
646
- } else {
647
- $metas = $wpdb->get_col( $wpdb->prepare("SELECT meta_value FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d", $blog_id) );
648
- }
649
-
650
- if ( empty($metas) ) {
651
- if ( empty($meta_key) )
652
- return array();
653
- else
654
- return '';
655
- }
656
-
657
- $metas = array_map('maybe_unserialize', (array)$metas);
658
-
659
- if ( 1 == count($metas) )
660
- return $metas[0];
661
- else
662
- return $metas;
663
- }
664
-
665
- function bp_blogs_update_blogmeta( $blog_id, $meta_key, $meta_value ) {
666
- global $wpdb, $bp;
667
-
668
- if ( !is_numeric( $blog_id ) || !bp_core_is_multisite() )
669
- return false;
670
-
671
- $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
672
-
673
- if ( is_string($meta_value) )
674
- $meta_value = stripslashes($wpdb->escape($meta_value));
675
-
676
- $meta_value = maybe_serialize($meta_value);
677
-
678
- if (empty($meta_value)) {
679
- return bp_blogs_delete_blogmeta( $blog_id, $meta_key );
680
- }
681
-
682
- $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 ) );
683
-
684
- if ( !$cur ) {
685
- $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 ) );
686
- } else if ( $cur->meta_value != $meta_value ) {
687
- $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 ) );
688
- } else {
689
- return false;
690
- }
691
-
692
- wp_cache_set( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, $metas, 'bp' );
693
-
694
- return true;
695
- }
696
-
697
- function bp_blogs_remove_data( $user_id ) {
698
- if ( !bp_core_is_multisite() )
699
- return false;
700
-
701
- /* If this is regular blog, delete all data for that blog. */
702
- BP_Blogs_Blog::delete_blogs_for_user( $user_id );
703
-
704
- do_action( 'bp_blogs_remove_data', $user_id );
705
- }
706
- add_action( 'wpmu_delete_user', 'bp_blogs_remove_data' );
707
- add_action( 'delete_user', 'bp_blogs_remove_data' );
708
- add_action( 'make_spam_user', 'bp_blogs_remove_data' );
709
-
710
-
711
- /********************************************************************************
712
- * Caching
713
- *
714
- * Caching functions handle the clearing of cached objects and pages on specific
715
- * actions throughout BuddyPress.
716
- */
717
-
718
- function bp_blogs_clear_blog_object_cache( $blog_id, $user_id ) {
719
- wp_cache_delete( 'bp_blogs_of_user_' . $user_id, 'bp' );
720
- wp_cache_delete( 'bp_blogs_for_user_' . $user_id, 'bp' );
721
- wp_cache_delete( 'bp_total_blogs_for_user_' . $user_id, 'bp' );
722
-
723
- /* Clear the sitewide activity cache */
724
- wp_cache_delete( 'sitewide_activity', 'bp' );
725
- }
726
-
727
- function bp_blogs_format_clear_blog_cache( $recorded_blog_obj ) {
728
- bp_blogs_clear_blog_object_cache( false, $recorded_blog_obj->user_id );
729
-
730
- /* Clear the sitewide activity cache */
731
- wp_cache_delete( 'sitewide_activity', 'bp' );
732
- wp_cache_delete( 'bp_total_blogs', 'bp' );
733
- }
734
-
735
- // List actions to clear object caches on
736
- add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 );
737
- add_action( 'bp_blogs_new_blog', 'bp_blogs_format_clear_blog_cache', 10, 2 );
738
-
739
- // List actions to clear super cached pages on, if super cache is installed
740
- add_action( 'bp_blogs_remove_data_for_blog', 'bp_core_clear_cache' );
741
- add_action( 'bp_blogs_remove_comment', 'bp_core_clear_cache' );
742
- add_action( 'bp_blogs_remove_post', 'bp_core_clear_cache' );
743
- add_action( 'bp_blogs_remove_blog_for_user', 'bp_core_clear_cache' );
744
- add_action( 'bp_blogs_remove_blog', 'bp_core_clear_cache' );
745
- add_action( 'bp_blogs_new_blog_comment', 'bp_core_clear_cache' );
746
- add_action( 'bp_blogs_new_blog_post', 'bp_core_clear_cache' );
747
- add_action( 'bp_blogs_new_blog', 'bp_core_clear_cache' );
748
- add_action( 'bp_blogs_remove_data', 'bp_core_clear_cache' );
749
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
750
  ?>
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/upgrade-functions.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_site_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( '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->table_name = $wpdb->base_prefix . 'bp_user_blogs';
72
+ $bp->blogs->table_name_blogmeta = $wpdb->base_prefix . 'bp_user_blogs_blogmeta';
73
+ $bp->blogs->format_notification_function = 'bp_blogs_format_notifications';
74
+ $bp->blogs->slug = BP_BLOGS_SLUG;
75
+
76
+ /* Register this in the active components array */
77
+ $bp->active_components[$bp->blogs->slug] = $bp->blogs->id;
78
+
79
+ do_action( 'bp_blogs_setup_globals' );
80
+ }
81
+ add_action( 'bp_setup_globals', 'bp_blogs_setup_globals' );
82
+
83
+ function bp_blogs_setup_root_component() {
84
+ /* Register 'blogs' as a root component */
85
+ bp_core_add_root_component( BP_BLOGS_SLUG );
86
+ }
87
+ add_action( 'bp_setup_root_components', 'bp_blogs_setup_root_component' );
88
+
89
+ /**
90
+ * bp_blogs_setup_nav()
91
+ *
92
+ * Adds "Blog" to the navigation arrays for the current and logged in user.
93
+ *
94
+ * @package BuddyPress Blogs
95
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
96
+ * @uses bp_is_my_profile() Checks to see if the current user being viewed is the logged in user
97
+ */
98
+ function bp_blogs_setup_nav() {
99
+ global $bp;
100
+
101
+ /* Blog/post/comment menus should not appear on single WordPress setups. Although comments
102
+ and posts made by users will still show on their activity stream .*/
103
+ if ( !bp_core_is_multisite() )
104
+ return false;
105
+
106
+ /* Add 'Blogs' to the main navigation */
107
+ 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 ) );
108
+
109
+ $blogs_link = $bp->loggedin_user->domain . $bp->blogs->slug . '/';
110
+
111
+ /* Set up the component options navigation for Blog */
112
+ if ( 'blogs' == $bp->current_component ) {
113
+ if ( bp_is_my_profile() ) {
114
+ if ( function_exists('xprofile_setup_nav') ) {
115
+ $bp->bp_options_title = __('My Blogs', 'buddypress');
116
+ }
117
+ } else {
118
+ /* If we are not viewing the logged in user, set up the current users avatar and name */
119
+ $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
120
+ $bp->bp_options_title = $bp->displayed_user->fullname;
121
+ }
122
+ }
123
+
124
+ do_action( 'bp_blogs_setup_nav' );
125
+ }
126
+ add_action( 'bp_setup_nav', 'bp_blogs_setup_nav' );
127
+
128
+ function bp_blogs_directory_blogs_setup() {
129
+ global $bp;
130
+
131
+ if ( bp_core_is_multisite() && $bp->current_component == $bp->blogs->slug && empty( $bp->current_action ) ) {
132
+ $bp->is_directory = true;
133
+
134
+ do_action( 'bp_blogs_directory_blogs_setup' );
135
+ bp_core_load_template( apply_filters( 'bp_blogs_template_directory_blogs_setup', 'blogs/index' ) );
136
+ }
137
+ }
138
+ add_action( 'wp', 'bp_blogs_directory_blogs_setup', 2 );
139
+
140
+
141
+ /********************************************************************************
142
+ * Screen Functions
143
+ *
144
+ * Screen functions are the controllers of BuddyPress. They will execute when their
145
+ * specific URL is caught. They will first save or manipulate data using business
146
+ * functions, then pass on the user to a template file.
147
+ */
148
+
149
+ function bp_blogs_screen_my_blogs() {
150
+ global $bp;
151
+
152
+ if ( !bp_core_is_multisite() )
153
+ return false;
154
+
155
+ do_action( 'bp_blogs_screen_my_blogs' );
156
+ bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'members/single/home' ) );
157
+ }
158
+
159
+ function bp_blogs_screen_create_a_blog() {
160
+ global $bp;
161
+
162
+ if ( !bp_core_is_multisite() || $bp->current_component != $bp->blogs->slug || 'create' != $bp->current_action )
163
+ return false;
164
+
165
+ if ( !is_user_logged_in() || !bp_blog_signup_enabled() )
166
+ return false;
167
+
168
+ do_action( 'bp_blogs_screen_create_a_blog' );
169
+ bp_core_load_template( apply_filters( 'bp_blogs_template_create_a_blog', 'blogs/create' ) );
170
+ }
171
+ /* The create screen is not attached to a nav item, so we need to attach it to an action */
172
+ add_action( 'wp', 'bp_blogs_screen_create_a_blog', 3 );
173
+
174
+
175
+ /********************************************************************************
176
+ * Activity & Notification Functions
177
+ *
178
+ * These functions handle the recording, deleting and formatting of activity and
179
+ * notifications for the user and for this specific component.
180
+ */
181
+
182
+ function bp_blogs_register_activity_actions() {
183
+ global $bp;
184
+
185
+ if ( !function_exists( 'bp_activity_set_action' ) )
186
+ return false;
187
+
188
+ bp_activity_set_action( $bp->blogs->id, 'new_blog', __( 'New blog created', 'buddypress' ) );
189
+ bp_activity_set_action( $bp->blogs->id, 'new_blog_post', __( 'New blog post published', 'buddypress' ) );
190
+ bp_activity_set_action( $bp->blogs->id, 'new_blog_comment', __( 'New blog post comment posted', 'buddypress' ) );
191
+
192
+ do_action( 'bp_blogs_register_activity_actions' );
193
+ }
194
+ add_action( 'bp_register_activity_actions', 'bp_blogs_register_activity_actions' );
195
+
196
+ function bp_blogs_record_activity( $args = '' ) {
197
+ global $bp;
198
+
199
+ if ( !function_exists( 'bp_activity_add' ) )
200
+ return false;
201
+
202
+ /* Because blog, comment, and blog post code execution happens before anything else
203
+ we may need to manually instantiate the activity component globals */
204
+ if ( !$bp->activity && function_exists('bp_activity_setup_globals') )
205
+ bp_activity_setup_globals();
206
+
207
+ $defaults = array(
208
+ 'user_id' => $bp->loggedin_user->id,
209
+ 'action' => '',
210
+ 'content' => '',
211
+ 'primary_link' => '',
212
+ 'component' => $bp->blogs->id,
213
+ 'type' => false,
214
+ 'item_id' => false,
215
+ 'secondary_item_id' => false,
216
+ 'recorded_time' => gmdate( "Y-m-d H:i:s" ),
217
+ 'hide_sitewide' => false
218
+ );
219
+
220
+ $r = wp_parse_args( $args, $defaults );
221
+ extract( $r, EXTR_SKIP );
222
+
223
+ /* Remove large images and replace them with just one image thumbnail */
224
+ if ( function_exists( 'bp_activity_thumbnail_content_images' ) && !empty( $content ) )
225
+ $content = bp_activity_thumbnail_content_images( $content );
226
+
227
+ if ( !empty( $action ) )
228
+ $action = apply_filters( 'bp_blogs_record_activity_action', $action );
229
+
230
+ if ( !empty( $content ) )
231
+ $content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $content ) );
232
+
233
+ /* Check for an existing entry and update if one exists. */
234
+ $id = bp_activity_get_activity_id( array(
235
+ 'user_id' => $user_id,
236
+ 'component' => $component,
237
+ 'type' => $type,
238
+ 'item_id' => $item_id,
239
+ 'secondary_item_id' => $secondary_item_id
240
+ ) );
241
+
242
+ 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 ) );
243
+ }
244
+
245
+ function bp_blogs_delete_activity( $args = true ) {
246
+ global $bp;
247
+
248
+ if ( function_exists('bp_activity_delete_by_item_id') ) {
249
+ $defaults = array(
250
+ 'item_id' => false,
251
+ 'component' => $bp->blogs->id,
252
+ 'type' => false,
253
+ 'user_id' => false,
254
+ 'secondary_item_id' => false
255
+ );
256
+
257
+ $params = wp_parse_args( $args, $defaults );
258
+ extract( $params, EXTR_SKIP );
259
+
260
+ bp_activity_delete_by_item_id( array(
261
+ 'item_id' => $item_id,
262
+ 'component' => $component,
263
+ 'type' => $type,
264
+ 'user_id' => $user_id,
265
+ 'secondary_item_id' => $secondary_item_id
266
+ ) );
267
+ }
268
+ }
269
+
270
+ /********************************************************************************
271
+ * Business Functions
272
+ *
273
+ * Business functions are where all the magic happens in BuddyPress. They will
274
+ * handle the actual saving or manipulation of information. Usually they will
275
+ * hand off to a database class for data access, then return
276
+ * true or false on success or failure.
277
+ */
278
+
279
+ function bp_blogs_get_blogs( $args = '' ) {
280
+ global $bp;
281
+
282
+ $defaults = array(
283
+ 'type' => 'active', // active, alphabetical, newest, or random.
284
+ 'user_id' => false, // Pass a user_id to limit to only blogs that this user has privilages higher than subscriber on.
285
+ 'search_terms' => false, // Limit to blogs that match these search terms
286
+
287
+ 'per_page' => 20, // The number of results to return per page
288
+ 'page' => 1, // The page to return if limiting per page
289
+ );
290
+
291
+ $params = wp_parse_args( $args, $defaults );
292
+ extract( $params, EXTR_SKIP );
293
+
294
+ return apply_filters( 'bp_blogs_get_blogs', BP_Blogs_Blog::get( $type, $per_page, $page, $user_id, $search_terms ), &$params );
295
+ }
296
+
297
+ function bp_blogs_record_existing_blogs() {
298
+ global $bp, $wpdb;
299
+
300
+ /* Truncate user blogs table and re-record. */
301
+ $wpdb->query( "TRUNCATE TABLE {$bp->blogs->table_name}" );
302
+
303
+ $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$wpdb->base_prefix}blogs WHERE mature = 0 AND spam = 0 AND deleted = 0" ) );
304
+
305
+ if ( $blog_ids ) {
306
+ foreach( (array)$blog_ids as $blog_id ) {
307
+ $users = get_users_of_blog( $blog_id );
308
+
309
+ if ( $users ) {
310
+ foreach ( (array)$users as $user ) {
311
+ $role = unserialize( $user->meta_value );
312
+
313
+ if ( !isset( $role['subscriber'] ) )
314
+ bp_blogs_record_blog( $blog_id, $user->user_id, true );
315
+ }
316
+ }
317
+ }
318
+ }
319
+ }
320
+
321
+ function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) {
322
+ global $bp;
323
+
324
+ if ( !$user_id )
325
+ $user_id = $bp->loggedin_user->id;
326
+
327
+ $name = get_blog_option( $blog_id, 'blogname' );
328
+ $description = get_blog_option( $blog_id, 'blogdescription' );
329
+
330
+ if ( empty( $name ) )
331
+ return false;
332
+
333
+ $recorded_blog = new BP_Blogs_Blog;
334
+ $recorded_blog->user_id = $user_id;
335
+ $recorded_blog->blog_id = $blog_id;
336
+
337
+ $recorded_blog_id = $recorded_blog->save();
338
+
339
+ bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'name', $name );
340
+ bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description );
341
+ bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
342
+
343
+ /* Only record this activity if the blog is public */
344
+ if ( (int)$_POST['blog_public'] && !$no_activity ) {
345
+ /* Record this in activity streams */
346
+ bp_blogs_record_activity( array(
347
+ 'user_id' => $recorded_blog->user_id,
348
+ '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_blog_option( $recorded_blog->blog_id, 'siteurl' ) . '">' . attribute_escape( $name ) . '</a>' ), &$recorded_blog, $name, $description ),
349
+ 'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', get_blog_option( $recorded_blog->blog_id, 'siteurl' ), $recorded_blog->blog_id ),
350
+ 'type' => 'new_blog',
351
+ 'item_id' => $recorded_blog->blog_id
352
+ ) );
353
+ }
354
+
355
+ do_action( 'bp_blogs_new_blog', &$recorded_blog, $is_private, $is_recorded );
356
+ }
357
+ add_action( 'wpmu_new_blog', 'bp_blogs_record_blog', 10, 2 );
358
+
359
+ /**
360
+ * bp_blogs_update_option_blogname()
361
+ *
362
+ * Updates blogname in BuddyPress blogmeta table
363
+ *
364
+ * @global object $wpdb DB Layer
365
+ * @param string $oldvalue Value before save (not used)
366
+ * @param string $newvalue Value to change meta to
367
+ */
368
+ function bp_blogs_update_option_blogname( $oldvalue, $newvalue ) {
369
+ global $wpdb;
370
+ bp_blogs_update_blogmeta( $wpdb->blogid, 'name', $newvalue );
371
+ }
372
+ add_action( 'update_option_blogname', 'bp_blogs_update_option_blogname', 10, 2 );
373
+
374
+ /**
375
+ * bp_blogs_update_option_blogdescription()
376
+ *
377
+ * Updates blogdescription in BuddyPress blogmeta table
378
+ *
379
+ * @global object $wpdb DB Layer
380
+ * @param string $oldvalue Value before save (not used)
381
+ * @param string $newvalue Value to change meta to
382
+ */
383
+ function bp_blogs_update_option_blogdescription( $oldvalue, $newvalue ) {
384
+ global $wpdb;
385
+ bp_blogs_update_blogmeta( $wpdb->blogid, 'description', $newvalue );
386
+ }
387
+ add_action( 'update_option_blogdescription', 'bp_blogs_update_option_blogdescription', 10, 2 );
388
+
389
+ function bp_blogs_record_post( $post_id, $post, $user_id = false ) {
390
+ global $bp, $wpdb;
391
+
392
+ $post_id = (int)$post_id;
393
+ $blog_id = (int)$wpdb->blogid;
394
+
395
+ if ( !$user_id )
396
+ $user_id = (int)$post->post_author;
397
+
398
+ /* This is to stop infinite loops with Donncha's sitewide tags plugin */
399
+ if ( (int)$bp->site_options['tags_blog_id'] == (int)$blog_id )
400
+ return false;
401
+
402
+ /* Don't record this if it's not a post */
403
+ if ( $post->post_type != 'post' )
404
+ return false;
405
+
406
+ if ( 'publish' == $post->post_status && '' == $post->post_password ) {
407
+ if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
408
+ /* Record this in activity streams */
409
+ $post_permalink = get_permalink( $post_id );
410
+
411
+ $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>' );
412
+ $activity_content = $post->post_content;
413
+
414
+ bp_blogs_record_activity( array(
415
+ 'user_id' => (int)$post->post_author,
416
+ 'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, &$post, $post_permalink ),
417
+ 'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink ),
418
+ 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
419
+ 'type' => 'new_blog_post',
420
+ 'item_id' => $blog_id,
421
+ 'secondary_item_id' => $post_id,
422
+ 'recorded_time' => $post->post_date_gmt
423
+ ));
424
+ }
425
+ } else
426
+ bp_blogs_remove_post( $post_id, $blog_id );
427
+
428
+ bp_blogs_update_blogmeta( $blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
429
+
430
+ do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
431
+ }
432
+ add_action( 'save_post', 'bp_blogs_record_post', 10, 2 );
433
+
434
+ /**
435
+ * bp_blogs_record_comment()
436
+ *
437
+ * Record blog comment activity. Checks if blog is public and post is not
438
+ * password protected.
439
+ *
440
+ * @global object $wpdb
441
+ * @global $bp $bp
442
+ * @param <type> $comment_id
443
+ * @param <type> $is_approved
444
+ * @return <type>
445
+ */
446
+ function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
447
+ global $wpdb, $bp;
448
+
449
+ // Get the users comment
450
+ $recorded_comment = get_comment( $comment_id );
451
+
452
+ // Don't record activity if the comment hasn't been approved
453
+ if ( !$is_approved || true != $recorded_comment->comment_approved )
454
+ return false;
455
+
456
+ // Get blog and post data
457
+ $blog_id = (int)$wpdb->blogid;
458
+ $recorded_comment->post = get_post( $recorded_comment->comment_post_ID );
459
+
460
+ // Get the user_id from the comment author email.
461
+ $user = get_user_by_email( $recorded_comment->comment_author_email );
462
+ $user_id = (int)$user->ID;
463
+
464
+ // If there's no registered user id, don't record activity
465
+ if ( !$user_id )
466
+ return false;
467
+
468
+ // If this is a password protected post, don't record the comment
469
+ if ( !empty( $recorded_comment->post->post_password ) )
470
+ return false;
471
+
472
+ // If blog is public allow activity to be posted
473
+ if ( get_blog_option( $blog_id, 'blog_public' ) ) {
474
+
475
+ // Prepare to record in activity streams
476
+ $comment_link = htmlspecialchars( get_comment_link( $recorded_comment->comment_ID ) );
477
+ $activity_action = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $comment_link . '">' . $recorded_comment->post->post_title . '</a>' );
478
+ $activity_content = $recorded_comment->comment_content;
479
+
480
+ // Record in activity streams
481
+ bp_blogs_record_activity( array(
482
+ 'user_id' => $user_id,
483
+ 'action' => apply_filters( 'bp_blogs_activity_new_comment_action', $activity_action, &$recorded_comment, $comment_link ),
484
+ 'content' => apply_filters( 'bp_blogs_activity_new_comment_content', $activity_content, &$recorded_comment, $comment_link ),
485
+ 'primary_link' => apply_filters( 'bp_blogs_activity_new_comment_primary_link', $comment_link, &$recorded_comment ),
486
+ 'type' => 'new_blog_comment',
487
+ 'item_id' => $blog_id,
488
+ 'secondary_item_id' => $comment_id,
489
+ 'recorded_time' => $recorded_comment->comment_date_gmt
490
+ ) );
491
+
492
+ // Update the blogs last active date
493
+ bp_blogs_update_blogmeta( $blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
494
+ }
495
+
496
+ return $recorded_comment;
497
+ }
498
+ add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
499
+ add_action( 'edit_comment', 'bp_blogs_record_comment', 10 );
500
+
501
+ function bp_blogs_manage_comment( $comment_id, $comment_status ) {
502
+ if ( 'spam' == $comment_status || 'hold' == $comment_status || 'delete' == $comment_status || 'trash' == $comment_status )
503
+ return bp_blogs_remove_comment( $comment_id );
504
+
505
+ return bp_blogs_record_comment( $comment_id, true );
506
+ }
507
+ add_action( 'wp_set_comment_status', 'bp_blogs_manage_comment', 10, 2 );
508
+
509
+ function bp_blogs_add_user_to_blog( $user_id, $role, $blog_id = false ) {
510
+ global $current_blog;
511
+
512
+ if ( empty( $blog_id ) )
513
+ $blog_id = $current_blog->blog_id;
514
+
515
+ if ( $role != 'subscriber' )
516
+ bp_blogs_record_blog( $blog_id, $user_id, true );
517
+ }
518
+ add_action( 'add_user_to_blog', 'bp_blogs_add_user_to_blog', 10, 3 );
519
+
520
+ function bp_blogs_remove_user_from_blog( $user_id, $blog_id = false ) {
521
+ global $current_blog;
522
+
523
+ if ( empty( $blog_id ) )
524
+ $blog_id = $current_blog->blog_id;
525
+
526
+ bp_blogs_remove_blog_for_user( $user_id, $blog_id );
527
+ }
528
+ add_action( 'remove_user_from_blog', 'bp_blogs_remove_user_from_blog', 10, 2 );
529
+
530
+ function bp_blogs_remove_blog( $blog_id ) {
531
+ global $bp;
532
+
533
+ $blog_id = (int)$blog_id;
534
+
535
+ BP_Blogs_Blog::delete_blog_for_all( $blog_id );
536
+
537
+ // Delete activity stream item
538
+ bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog' ) );
539
+
540
+ do_action( 'bp_blogs_remove_blog', $blog_id );
541
+ }
542
+ add_action( 'delete_blog', 'bp_blogs_remove_blog' );
543
+
544
+ function bp_blogs_remove_blog_for_user( $user_id, $blog_id ) {
545
+ global $current_user;
546
+
547
+ $blog_id = (int)$blog_id;
548
+ $user_id = (int)$user_id;
549
+
550
+ BP_Blogs_Blog::delete_blog_for_user( $blog_id, $user_id );
551
+
552
+ // Delete activity stream item
553
+ bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog' ) );
554
+
555
+ do_action( 'bp_blogs_remove_blog_for_user', $blog_id, $user_id );
556
+ }
557
+ add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 );
558
+
559
+ function bp_blogs_remove_post( $post_id, $blog_id = false ) {
560
+ global $current_blog, $bp;
561
+
562
+ $post_id = (int)$post_id;
563
+
564
+ if ( !$blog_id )
565
+ $blog_id = (int)$current_blog->blog_id;
566
+
567
+ // Delete activity stream item
568
+ bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog_post' ) );
569
+
570
+ do_action( 'bp_blogs_remove_post', $blog_id, $post_id, $post->user_id );
571
+ }
572
+ add_action( 'delete_post', 'bp_blogs_remove_post' );
573
+
574
+ function bp_blogs_remove_comment( $comment_id ) {
575
+ global $wpdb, $bp;
576
+
577
+ // Delete activity stream item
578
+ bp_blogs_delete_activity( array( 'item_id' => $wpdb->blogid , 'secondary_item_id' => $comment_id, 'type' => 'new_blog_comment' ) );
579
+
580
+ do_action( 'bp_blogs_remove_comment', $blog_id, $comment_id, $bp->loggedin_user->id );
581
+ }
582
+ add_action( 'delete_comment', 'bp_blogs_remove_comment' );
583
+
584
+ function bp_blogs_total_blogs() {
585
+ if ( !$count = wp_cache_get( 'bp_total_blogs', 'bp' ) ) {
586
+ $blogs = BP_Blogs_Blog::get_all();
587
+ $count = $blogs['total'];
588
+ wp_cache_set( 'bp_total_blogs', $count, 'bp' );
589
+ }
590
+ return $count;
591
+ }
592
+
593
+ function bp_blogs_total_blogs_for_user( $user_id = false ) {
594
+ global $bp;
595
+
596
+ if ( !$user_id )
597
+ $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
598
+
599
+ if ( !$count = wp_cache_get( 'bp_total_blogs_for_user_' . $user_id, 'bp' ) ) {
600
+ $count = BP_Blogs_Blog::total_blog_count_for_user( $user_id );
601
+ wp_cache_set( 'bp_total_blogs_for_user_' . $user_id, $count, 'bp' );
602
+ }
603
+
604
+ return $count;
605
+ }
606
+
607
+ function bp_blogs_remove_data_for_blog( $blog_id ) {
608
+ global $bp;
609
+
610
+ /* If this is regular blog, delete all data for that blog. */
611
+ BP_Blogs_Blog::delete_blog_for_all( $blog_id );
612
+
613
+ // Delete activity stream item
614
+ bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->slug, 'type' => false ) );
615
+
616
+ do_action( 'bp_blogs_remove_data_for_blog', $blog_id );
617
+ }
618
+ add_action( 'delete_blog', 'bp_blogs_remove_data_for_blog', 1 );
619
+
620
+ function bp_blogs_get_blogs_for_user( $user_id, $show_hidden = false ) {
621
+ return BP_Blogs_Blog::get_blogs_for_user( $user_id, $show_hidden );
622
+ }
623
+
624
+ function bp_blogs_get_all_blogs( $limit = null, $page = null ) {
625
+ return BP_Blogs_Blog::get_all( $limit, $page );
626
+ }
627
+
628
+ function bp_blogs_get_random_blogs( $limit = null, $page = null ) {
629
+ return BP_Blogs_Blog::get( 'random', $limit, $page );
630
+ }
631
+
632
+ function bp_blogs_is_blog_hidden( $blog_id ) {
633
+ return BP_Blogs_Blog::is_hidden( $blog_id );
634
+ }
635
+
636
+ function bp_blogs_redirect_to_random_blog() {
637
+ global $bp, $wpdb;
638
+
639
+ if ( $bp->current_component == $bp->blogs->slug && isset( $_GET['random-blog'] ) ) {
640
+ $blog = bp_blogs_get_random_blogs( 1, 1 );
641
+
642
+ bp_core_redirect( get_blog_option( $blog['blogs'][0]->blog_id, 'siteurl') );
643
+ }
644
+ }
645
+ add_action( 'wp', 'bp_blogs_redirect_to_random_blog', 6 );
646
+
647
+
648
+ //
649
+ // Blog meta functions
650
+ // These functions are used to store specific blogmeta in one global table, rather than in each
651
+ // blog's options table. Significantly speeds up global blog queries.
652
+ // By default each blog's name, description and last updated time are stored and synced here.
653
+ //
654
+
655
+ function bp_blogs_delete_blogmeta( $blog_id, $meta_key = false, $meta_value = false ) {
656
+ global $wpdb, $bp;
657
+
658
+ if ( !is_numeric( $blog_id ) || !bp_core_is_multisite() )
659
+ return false;
660
+
661
+ $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
662
+
663
+ if ( is_array($meta_value) || is_object($meta_value) )
664
+ $meta_value = serialize($meta_value);
665
+
666
+ $meta_value = trim( $meta_value );
667
+
668
+ if ( !$meta_key ) {
669
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d", $blog_id ) );
670
+ } else if ( $meta_value ) {
671
+ $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 ) );
672
+ } else {
673
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d AND meta_key = %s", $blog_id, $meta_key ) );
674
+ }
675
+
676
+ wp_cache_delete( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, 'bp' );
677
+
678
+ return true;
679
+ }
680
+
681
+ function bp_blogs_get_blogmeta( $blog_id, $meta_key = '') {
682
+ global $wpdb, $bp;
683
+
684
+ $blog_id = (int) $blog_id;
685
+
686
+ if ( !$blog_id || !bp_core_is_multisite() )
687
+ return false;
688
+
689
+ if ( !empty($meta_key) ) {
690
+ $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
691
+
692
+ if ( !$metas = wp_cache_get( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, 'bp' ) ) {
693
+ $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 ) );
694
+ wp_cache_set( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, $metas, 'bp' );
695
+ }
696
+ } else {
697
+ $metas = $wpdb->get_col( $wpdb->prepare("SELECT meta_value FROM {$bp->blogs->table_name_blogmeta} WHERE blog_id = %d", $blog_id) );
698
+ }
699
+
700
+ if ( empty($metas) ) {
701
+ if ( empty($meta_key) )
702
+ return array();
703
+ else
704
+ return '';
705
+ }
706
+
707
+ $metas = array_map('maybe_unserialize', (array)$metas);
708
+
709
+ if ( 1 == count($metas) )
710
+ return $metas[0];
711
+ else
712
+ return $metas;
713
+ }
714
+
715
+ function bp_blogs_update_blogmeta( $blog_id, $meta_key, $meta_value ) {
716
+ global $wpdb, $bp;
717
+
718
+ if ( !is_numeric( $blog_id ) || !bp_core_is_multisite() )
719
+ return false;
720
+
721
+ $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
722
+
723
+ if ( is_string($meta_value) )
724
+ $meta_value = stripslashes($wpdb->escape($meta_value));
725
+
726
+ $meta_value = maybe_serialize($meta_value);
727
+
728
+ if (empty($meta_value)) {
729
+ return bp_blogs_delete_blogmeta( $blog_id, $meta_key );
730
+ }
731
+
732
+ $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 ) );
733
+
734
+ if ( !$cur ) {
735
+ $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 ) );
736
+ } else if ( $cur->meta_value != $meta_value ) {
737
+ $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 ) );
738
+ } else {
739
+ return false;
740
+ }
741
+
742
+ wp_cache_set( 'bp_blogs_blogmeta_' . $blog_id . '_' . $meta_key, $metas, 'bp' );
743
+
744
+ return true;
745
+ }
746
+
747
+ function bp_blogs_remove_data( $user_id ) {
748
+ if ( !bp_core_is_multisite() )
749
+ return false;
750
+
751
+ /* If this is regular blog, delete all data for that blog. */
752
+ BP_Blogs_Blog::delete_blogs_for_user( $user_id );
753
+
754
+ do_action( 'bp_blogs_remove_data', $user_id );
755
+ }
756
+ add_action( 'wpmu_delete_user', 'bp_blogs_remove_data' );
757
+ add_action( 'delete_user', 'bp_blogs_remove_data' );
758
+ add_action( 'make_spam_user', 'bp_blogs_remove_data' );
759
+
760
+
761
+ /********************************************************************************
762
+ * Caching
763
+ *
764
+ * Caching functions handle the clearing of cached objects and pages on specific
765
+ * actions throughout BuddyPress.
766
+ */
767
+
768
+ function bp_blogs_clear_blog_object_cache( $blog_id, $user_id ) {
769
+ wp_cache_delete( 'bp_blogs_of_user_' . $user_id, 'bp' );
770
+ wp_cache_delete( 'bp_blogs_for_user_' . $user_id, 'bp' );
771
+ wp_cache_delete( 'bp_total_blogs_for_user_' . $user_id, 'bp' );
772
+
773
+ /* Clear the sitewide activity cache */
774
+ wp_cache_delete( 'sitewide_activity', 'bp' );
775
+ }
776
+
777
+ function bp_blogs_format_clear_blog_cache( $recorded_blog_obj ) {
778
+ bp_blogs_clear_blog_object_cache( false, $recorded_blog_obj->user_id );
779
+
780
+ /* Clear the sitewide activity cache */
781
+ wp_cache_delete( 'sitewide_activity', 'bp' );
782
+ wp_cache_delete( 'bp_total_blogs', 'bp' );
783
+ }
784
+
785
+ // List actions to clear object caches on
786
+ add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 );
787
+ add_action( 'bp_blogs_new_blog', 'bp_blogs_format_clear_blog_cache', 10, 2 );
788
+
789
+ // List actions to clear super cached pages on, if super cache is installed
790
+ add_action( 'bp_blogs_remove_data_for_blog', 'bp_core_clear_cache' );
791
+ add_action( 'bp_blogs_remove_comment', 'bp_core_clear_cache' );
792
+ add_action( 'bp_blogs_remove_post', 'bp_core_clear_cache' );
793
+ add_action( 'bp_blogs_remove_blog_for_user', 'bp_core_clear_cache' );
794
+ add_action( 'bp_blogs_remove_blog', 'bp_core_clear_cache' );
795
+ add_action( 'bp_blogs_new_blog_comment', 'bp_core_clear_cache' );
796
+ add_action( 'bp_blogs_new_blog_post', 'bp_core_clear_cache' );
797
+ add_action( 'bp_blogs_new_blog', 'bp_core_clear_cache' );
798
+ add_action( 'bp_blogs_remove_data', 'bp_core_clear_cache' );
799
+
800
  ?>
bp-blogs/bp-blogs-classes.php CHANGED
@@ -1,310 +1,311 @@
1
- <?php
2
-
3
- Class BP_Blogs_Blog {
4
- var $id;
5
- var $user_id;
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;
16
- $this->populate();
17
- }
18
- }
19
-
20
- function populate() {
21
- global $wpdb, $bp;
22
-
23
- $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name} WHERE id = %d", $this->id ) );
24
-
25
- $this->user_id = $blog->user_id;
26
- $this->blog_id = $blog->blog_id;
27
- }
28
-
29
- function save() {
30
- global $wpdb, $bp;
31
-
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 )
39
- return false;
40
-
41
- // Don't save if this blog has already been recorded for the user.
42
- if ( !$this->id && $this->exists() )
43
- return false;
44
-
45
- if ( $this->id ) {
46
- // Update
47
- $sql = $wpdb->prepare( "UPDATE {$bp->blogs->table_name} SET user_id = %d, blog_id = %d WHERE id = %d", $this->user_id, $this->blog_id, $this->id );
48
- } else {
49
- // Save
50
- $sql = $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name} ( user_id, blog_id ) VALUES ( %d, %d )", $this->user_id, $this->blog_id );
51
- }
52
-
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;
60
- else
61
- return $wpdb->insert_id;
62
- }
63
-
64
- function exists() {
65
- global $bp, $wpdb;
66
-
67
- return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $this->user_id, $this->blog_id ) );
68
- }
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_site_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:
89
- $order_sql = "ORDER BY bm.meta_value DESC";
90
- break;
91
- case 'alphabetical':
92
- $order_sql = "ORDER BY bm2.meta_value ASC";
93
- break;
94
- case 'newest':
95
- $order_sql = "ORDER BY wb.registered DESC";
96
- break;
97
- case 'random':
98
- $order_sql = "ORDER BY RAND()";
99
- break;
100
- }
101
-
102
- if ( !empty( $search_terms ) ) {
103
- $filter = like_escape( $wpdb->escape( $search_terms ) );
104
- $paged_blogs = $wpdb->get_results( "SELECT b.blog_id, b.user_id as admin_user_id, u.user_email as admin_user_email, wb.domain, wb.path, bm.meta_value as last_activity, bm2.meta_value as name FROM {$bp->blogs->table_name} b, {$bp->blogs->table_name_blogmeta} bm, {$bp->blogs->table_name_blogmeta} bm2, {$wpdb->base_prefix}blogs wb, {$wpdb->users} u WHERE b.blog_id = wb.blog_id AND b.user_id = u.ID AND b.blog_id = bm.blog_id AND b.blog_id = bm2.blog_id AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$hidden_sql} AND bm.meta_key = 'last_activity' AND bm2.meta_key = 'name' AND bm2.meta_value LIKE '%%$filter%%' {$user_sql} GROUP BY b.blog_id {$order_sql} {$pag_sql}" );
105
- $total_blogs = $wpdb->get_var( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm, {$bp->blogs->table_name_blogmeta} bm2 WHERE b.blog_id = wb.blog_id AND bm.blog_id = b.blog_id AND bm2.blog_id = b.blog_id AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$hidden_sql} AND bm.meta_key = 'name' AND bm2.meta_key = 'description' AND ( bm.meta_value LIKE '%%$filter%%' || bm2.meta_value LIKE '%%$filter%%' ) {$user_sql}" );
106
- } else {
107
- $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT b.blog_id, b.user_id as admin_user_id, u.user_email as admin_user_email, wb.domain, wb.path, bm.meta_value as last_activity, bm2.meta_value as name FROM {$bp->blogs->table_name} b, {$bp->blogs->table_name_blogmeta} bm, {$bp->blogs->table_name_blogmeta} bm2, {$wpdb->base_prefix}blogs wb, {$wpdb->users} u WHERE b.blog_id = wb.blog_id AND b.user_id = u.ID AND b.blog_id = bm.blog_id AND b.blog_id = bm2.blog_id {$user_sql} AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$hidden_sql} AND bm.meta_key = 'last_activity' AND bm2.meta_key = 'name' GROUP BY b.blog_id {$order_sql} {$pag_sql}" ) );
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
- }
117
-
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
-
138
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $user_id, $blog_id ) );
139
- }
140
-
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
-
162
- // Show logged in users their hidden blogs.
163
- if ( !bp_is_my_profile() && !$show_hidden )
164
- $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.id, bm1.meta_value as name, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND bm1.meta_key = 'name' AND wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ORDER BY b.id", $user_id ) );
165
- else
166
- $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.id, bm1.meta_value as name, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND bm1.meta_key = 'name' AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ORDER BY b.id", $user_id ) );
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->id] = new stdClass;
172
- $user_blogs[$blog->id]->id = $blog->id;
173
- $user_blogs[$blog->id]->siteurl = ( is_ssl() ) ? 'https://' . $blog->domain . $blog->path : 'http://' . $blog->domain . $blog->path;
174
- $user_blogs[$blog->id]->name = $blog->name;
175
- }
176
-
177
- return array( 'blogs' => $user_blogs, 'count' => $total_blog_count );
178
- }
179
-
180
- function get_blog_ids_for_user( $user_id = false ) {
181
- global $bp, $wpdb;
182
-
183
- if ( !$bp->blogs )
184
- bp_blogs_setup_globals();
185
-
186
- if ( !$user_id )
187
- $user_id = $bp->displayed_user->id;
188
-
189
- return $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) );
190
- }
191
-
192
- function is_recorded( $blog_id ) {
193
- global $bp, $wpdb;
194
-
195
- if ( !$bp->blogs )
196
- bp_blogs_setup_globals();
197
-
198
- return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE blog_id = %d", $blog_id ) );
199
- }
200
-
201
- function total_blog_count_for_user( $user_id = null ) {
202
- global $bp, $wpdb;
203
-
204
- if ( !$bp->blogs )
205
- bp_blogs_setup_globals();
206
-
207
- if ( !$user_id )
208
- $user_id = $bp->displayed_user->id;
209
-
210
- // If the user is logged in return the blog count including their hidden blogs.
211
- if ( ( is_user_logged_in() && $user_id == $bp->loggedin_user->id ) || is_site_admin() )
212
- return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id) );
213
- else
214
- return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id) );
215
- }
216
-
217
- function search_blogs( $filter, $limit = null, $page = null ) {
218
- global $wpdb, $bp;
219
-
220
- if ( !$bp->blogs )
221
- bp_blogs_setup_globals();
222
-
223
- $filter = like_escape( $wpdb->escape( $filter ) );
224
-
225
- if ( !is_site_admin() )
226
- $hidden_sql = "AND wb.public = 1";
227
-
228
- if ( $limit && $page )
229
- $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
230
-
231
- $paged_blogs = $wpdb->get_results( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND bm.meta_value LIKE '%%$filter%%' ) {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY meta_value ASC{$pag_sql}" );
232
- $total_blogs = $wpdb->get_var( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND bm.meta_value LIKE '%%$filter%%' ) {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY meta_value ASC" );
233
-
234
- return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
235
- }
236
-
237
- function get_all( $limit = null, $page = null ) {
238
- global $bp, $wpdb;
239
-
240
- if ( !$bp->blogs )
241
- bp_blogs_setup_globals();
242
-
243
- if ( !is_site_admin() )
244
- $hidden_sql = "AND wb.public = 1";
245
-
246
- if ( $limit && $page )
247
- $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
248
-
249
- $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}" ) );
250
- $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}" ) );
251
-
252
- return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
253
- }
254
-
255
- function get_by_letter( $letter, $limit = null, $page = null ) {
256
- global $bp, $wpdb;
257
-
258
- if ( !$bp->blogs )
259
- bp_blogs_setup_globals();
260
-
261
- $letter = like_escape( $wpdb->escape( $letter ) );
262
-
263
- if ( !is_site_admin() )
264
- $hidden_sql = "AND wb.public = 1";
265
-
266
- if ( $limit && $page )
267
- $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
268
-
269
- $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE bm.meta_key = 'name' AND bm.meta_value LIKE '$letter%%' {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY bm.meta_value ASC{$pag_sql}" ) );
270
- $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE bm.meta_key = 'name' AND bm.meta_value LIKE '$letter%%' {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY bm.meta_value ASC" ) );
271
-
272
- return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
273
- }
274
-
275
- function get_blog_extras( $paged_blogs, $blog_ids, $type = false ) {
276
- global $bp, $wpdb;
277
-
278
- if ( empty( $blog_ids ) )
279
- return $paged_blogs;
280
-
281
- for ( $i = 0; $i < count( $paged_blogs ); $i++ )
282
- $paged_blogs[$i]->latest_post = $wpdb->get_row( "SELECT post_title, guid FROM {$wpdb->base_prefix}" . $paged_blogs[$i]->blog_id . "_posts WHERE post_status = 'publish' AND post_type = 'post' AND id != 1 ORDER BY id DESC LIMIT 1" );
283
-
284
- /* Fetch the blog description for each blog (as it may be empty we can't fetch it in the main query). */
285
- $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} )" ) );
286
-
287
- for ( $i = 0; $i < count( $paged_blogs ); $i++ ) {
288
- foreach ( (array)$blog_descs as $desc ) {
289
- if ( $desc->blog_id == $paged_blogs[$i]->blog_id )
290
- $paged_blogs[$i]->description = $desc->description;
291
- }
292
- }
293
-
294
- return $paged_blogs;
295
- }
296
-
297
- function is_hidden( $blog_id ) {
298
- global $wpdb;
299
-
300
- if ( !$bp->blogs )
301
- bp_blogs_setup_globals();
302
-
303
- if ( !(int)$wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT public FROM {$wpdb->base_prefix}blogs WHERE blog_id = %d", $blog_id ) ) )
304
- return true;
305
-
306
- return false;
307
- }
308
- }
309
-
 
310
  ?>
1
+ <?php
2
+
3
+ Class BP_Blogs_Blog {
4
+ var $id;
5
+ var $user_id;
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;
16
+ $this->populate();
17
+ }
18
+ }
19
+
20
+ function populate() {
21
+ global $wpdb, $bp;
22
+
23
+ $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name} WHERE id = %d", $this->id ) );
24
+
25
+ $this->user_id = $blog->user_id;
26
+ $this->blog_id = $blog->blog_id;
27
+ }
28
+
29
+ function save() {
30
+ global $wpdb, $bp;
31
+
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 )
39
+ return false;
40
+
41
+ // Don't save if this blog has already been recorded for the user.
42
+ if ( !$this->id && $this->exists() )
43
+ return false;
44
+
45
+ if ( $this->id ) {
46
+ // Update
47
+ $sql = $wpdb->prepare( "UPDATE {$bp->blogs->table_name} SET user_id = %d, blog_id = %d WHERE id = %d", $this->user_id, $this->blog_id, $this->id );
48
+ } else {
49
+ // Save
50
+ $sql = $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name} ( user_id, blog_id ) VALUES ( %d, %d )", $this->user_id, $this->blog_id );
51
+ }
52
+
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;
60
+ else
61
+ return $wpdb->insert_id;
62
+ }
63
+
64
+ function exists() {
65
+ global $bp, $wpdb;
66
+
67
+ return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $this->user_id, $this->blog_id ) );
68
+ }
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_site_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:
89
+ $order_sql = "ORDER BY bm.meta_value DESC";
90
+ break;
91
+ case 'alphabetical':
92
+ $order_sql = "ORDER BY bm2.meta_value ASC";
93
+ break;
94
+ case 'newest':
95
+ $order_sql = "ORDER BY wb.registered DESC";
96
+ break;
97
+ case 'random':
98
+ $order_sql = "ORDER BY RAND()";
99
+ break;
100
+ }
101
+
102
+ if ( !empty( $search_terms ) ) {
103
+ $filter = like_escape( $wpdb->escape( $search_terms ) );
104
+ $paged_blogs = $wpdb->get_results( "SELECT b.blog_id, b.user_id as admin_user_id, u.user_email as admin_user_email, wb.domain, wb.path, bm.meta_value as last_activity, bm2.meta_value as name FROM {$bp->blogs->table_name} b, {$bp->blogs->table_name_blogmeta} bm, {$bp->blogs->table_name_blogmeta} bm2, {$wpdb->base_prefix}blogs wb, {$wpdb->users} u WHERE b.blog_id = wb.blog_id AND b.user_id = u.ID AND b.blog_id = bm.blog_id AND b.blog_id = bm2.blog_id AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$hidden_sql} AND bm.meta_key = 'last_activity' AND bm2.meta_key = 'name' AND bm2.meta_value LIKE '%%$filter%%' {$user_sql} GROUP BY b.blog_id {$order_sql} {$pag_sql}" );
105
+ $total_blogs = $wpdb->get_var( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm, {$bp->blogs->table_name_blogmeta} bm2 WHERE b.blog_id = wb.blog_id AND bm.blog_id = b.blog_id AND bm2.blog_id = b.blog_id AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$hidden_sql} AND bm.meta_key = 'name' AND bm2.meta_key = 'description' AND ( bm.meta_value LIKE '%%$filter%%' || bm2.meta_value LIKE '%%$filter%%' ) {$user_sql}" );
106
+ } else {
107
+ $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT b.blog_id, b.user_id as admin_user_id, u.user_email as admin_user_email, wb.domain, wb.path, bm.meta_value as last_activity, bm2.meta_value as name FROM {$bp->blogs->table_name} b, {$bp->blogs->table_name_blogmeta} bm, {$bp->blogs->table_name_blogmeta} bm2, {$wpdb->base_prefix}blogs wb, {$wpdb->users} u WHERE b.blog_id = wb.blog_id AND b.user_id = u.ID AND b.blog_id = bm.blog_id AND b.blog_id = bm2.blog_id {$user_sql} AND wb.archived = '0' AND wb.spam = 0 AND wb.mature = 0 AND wb.deleted = 0 {$hidden_sql} AND bm.meta_key = 'last_activity' AND bm2.meta_key = 'name' GROUP BY b.blog_id {$order_sql} {$pag_sql}" ) );
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
+ }
117
+
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
+
138
+ return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $user_id, $blog_id ) );
139
+ }
140
+
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
+
162
+ // Show logged in users their hidden blogs.
163
+ if ( !bp_is_my_profile() && !$show_hidden )
164
+ $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id, b.id, bm1.meta_value as name, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND bm1.meta_key = 'name' AND wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ORDER BY b.blog_id", $user_id ) );
165
+ else
166
+ $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id, b.id, bm1.meta_value as name, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND bm1.meta_key = 'name' AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ORDER BY b.blog_id", $user_id ) );
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;
173
+ $user_blogs[$blog->blog_id]->blog_id = $blog->blog_id;
174
+ $user_blogs[$blog->blog_id]->siteurl = ( is_ssl() ) ? 'https://' . $blog->domain . $blog->path : 'http://' . $blog->domain . $blog->path;
175
+ $user_blogs[$blog->blog_id]->name = $blog->name;
176
+ }
177
+
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
+
190
+ return $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id ) );
191
+ }
192
+
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
+
211
+ // If the user is logged in return the blog count including their hidden blogs.
212
+ if ( ( is_user_logged_in() && $user_id == $bp->loggedin_user->id ) || is_site_admin() )
213
+ return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id) );
214
+ else
215
+ return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id) );
216
+ }
217
+
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_site_admin() )
227
+ $hidden_sql = "AND wb.public = 1";
228
+
229
+ if ( $limit && $page )
230
+ $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
231
+
232
+ $paged_blogs = $wpdb->get_results( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND bm.meta_value LIKE '%%$filter%%' ) {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY meta_value ASC{$pag_sql}" );
233
+ $total_blogs = $wpdb->get_var( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE ( ( bm.meta_key = 'name' OR bm.meta_key = 'description' ) AND bm.meta_value LIKE '%%$filter%%' ) {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY meta_value ASC" );
234
+
235
+ return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
236
+ }
237
+
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_site_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}" ) );
252
+
253
+ return array( 'blogs' => $paged_blogs, 'total' => $total_blogs );
254
+ }
255
+
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_site_admin() )
265
+ $hidden_sql = "AND wb.public = 1";
266
+
267
+ if ( $limit && $page )
268
+ $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
269
+
270
+ $paged_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT bm.blog_id FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE bm.meta_key = 'name' AND bm.meta_value LIKE '$letter%%' {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY bm.meta_value ASC{$pag_sql}" ) );
271
+ $total_blogs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT bm.blog_id) FROM {$bp->blogs->table_name_blogmeta} bm LEFT JOIN {$wpdb->base_prefix}blogs wb ON bm.blog_id = wb.blog_id WHERE bm.meta_key = 'name' AND bm.meta_value LIKE '$letter%%' {$hidden_sql} AND wb.mature = 0 AND wb.spam = 0 AND wb.archived = '0' AND wb.deleted = 0 ORDER BY bm.meta_value ASC" ) );
272
+
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
+ $paged_blogs[$i]->latest_post = $wpdb->get_row( "SELECT post_title, guid FROM {$wpdb->base_prefix}" . $paged_blogs[$i]->blog_id . "_posts WHERE post_status = 'publish' AND post_type = 'post' AND id != 1 ORDER BY id DESC LIMIT 1" );
284
+
285
+ /* Fetch the blog description for each blog (as it may be empty we can't fetch it in the main query). */
286
+ $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} )" ) );
287
+
288
+ for ( $i = 0; $i < count( $paged_blogs ); $i++ ) {
289
+ foreach ( (array)$blog_descs as $desc ) {
290
+ if ( $desc->blog_id == $paged_blogs[$i]->blog_id )
291
+ $paged_blogs[$i]->description = $desc->description;
292
+ }
293
+ }
294
+
295
+ return $paged_blogs;
296
+ }
297
+
298
+ function is_hidden( $blog_id ) {
299
+ global $wpdb;
300
+
301
+ if ( !$bp->blogs )
302
+ bp_blogs_setup_globals();
303
+
304
+ if ( !(int)$wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT public FROM {$wpdb->base_prefix}blogs WHERE blog_id = %d", $blog_id ) ) )
305
+ return true;
306
+
307
+ return false;
308
+ }
309
+ }
310
+
311
  ?>
bp-blogs/bp-blogs-templatetags.php CHANGED
@@ -1,502 +1,502 @@
1
- <?php
2
-
3
- /**********************************************************************
4
- * Blog listing template class.
5
- */
6
-
7
- class BP_Blogs_Template {
8
- var $current_blog = -1;
9
- var $blog_count;
10
- var $blogs;
11
- var $blog;
12
-
13
- var $in_the_loop;
14
-
15
- var $pag_page;
16
- var $pag_num;
17
- var $pag_links;
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;
24
- $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
25
-
26
- if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] )
27
- $this->blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page );
28
- else
29
- $this->blogs = bp_blogs_get_blogs( array( 'type' => $type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms ) );
30
-
31
- if ( !$max || $max >= (int)$this->blogs['total'] )
32
- $this->total_blog_count = (int)$this->blogs['total'];
33
- else
34
- $this->total_blog_count = (int)$max;
35
-
36
- $this->blogs = $this->blogs['blogs'];
37
-
38
- if ( $max ) {
39
- if ( $max >= count($this->blogs) )
40
- $this->blog_count = count($this->blogs);
41
- else
42
- $this->blog_count = (int)$max;
43
- } else {
44
- $this->blog_count = count($this->blogs);
45
- }
46
-
47
- $this->pag_links = paginate_links( array(
48
- 'base' => add_query_arg( 'bpage', '%#%' ),
49
- 'format' => '',
50
- 'total' => ceil( (int) $this->total_blog_count / (int) $this->pag_num ),
51
- 'current' => (int) $this->pag_page,
52
- 'prev_text' => '&larr;',
53
- 'next_text' => '&rarr;',
54
- 'mid_size' => 1
55
- ));
56
- }
57
-
58
- function has_blogs() {
59
- if ( $this->blog_count )
60
- return true;
61
-
62
- return false;
63
- }
64
-
65
- function next_blog() {
66
- $this->current_blog++;
67
- $this->blog = $this->blogs[$this->current_blog];
68
-
69
- return $this->blog;
70
- }
71
-
72
- function rewind_blogs() {
73
- $this->current_blog = -1;
74
- if ( $this->blog_count > 0 ) {
75
- $this->blog = $this->blogs[0];
76
- }
77
- }
78
-
79
- function blogs() {
80
- if ( $this->current_blog + 1 < $this->blog_count ) {
81
- return true;
82
- } elseif ( $this->current_blog + 1 == $this->blog_count ) {
83
- do_action('loop_end');
84
- // Do some cleaning up after the loop
85
- $this->rewind_blogs();
86
- }
87
-
88
- $this->in_the_loop = false;
89
- return false;
90
- }
91
-
92
- function the_blog() {
93
- global $blog;
94
-
95
- $this->in_the_loop = true;
96
- $this->blog = $this->next_blog();
97
-
98
- if ( 0 == $this->current_blog ) // loop has just started
99
- do_action('loop_start');
100
- }
101
- }
102
-
103
- function bp_rewind_blogs() {
104
- global $blogs_template;
105
-
106
- $blogs_template->rewind_blogs();
107
- }
108
-
109
- function bp_has_blogs( $args = '' ) {
110
- global $bp, $blogs_template;
111
-
112
- /***
113
- * Set the defaults based on the current page. Any of these will be overridden
114
- * if arguments are directly passed into the loop. Custom plugins should always
115
- * pass their parameters directly to the loop.
116
- */
117
- $type = 'active';
118
- $user_id = false;
119
- $search_terms = false;
120
-
121
- /* User filtering */
122
- if ( !empty( $bp->displayed_user->id ) )
123
- $user_id = $bp->displayed_user->id;
124
-
125
- if ( !empty( $_REQUEST['s'] ) )
126
- $search_terms = $_REQUEST['s'];
127
-
128
- $defaults = array(
129
- 'type' => $type,
130
- 'page' => 1,
131
- 'per_page' => 20,
132
- 'max' => false,
133
-
134
- 'user_id' => $user_id, // Pass a user_id to limit to only blogs this user has higher than subscriber access to
135
- 'search_terms' => $search_terms // Pass search terms to filter on the blog title or description.
136
- );
137
-
138
- $r = wp_parse_args( $args, $defaults );
139
- extract( $r );
140
-
141
- if ( $max ) {
142
- if ( $per_page > $max )
143
- $per_page = $max;
144
- }
145
-
146
- $blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms );
147
- return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), &$blogs_template );
148
- }
149
-
150
- function bp_blogs() {
151
- global $blogs_template;
152
-
153
- return $blogs_template->blogs();
154
- }
155
-
156
- function bp_the_blog() {
157
- global $blogs_template;
158
-
159
- return $blogs_template->the_blog();
160
- }
161
-
162
- function bp_blogs_pagination_count() {
163
- global $bp, $blogs_template;
164
-
165
- $start_num = intval( ( $blogs_template->pag_page - 1 ) * $blogs_template->pag_num ) + 1;
166
- $from_num = bp_core_number_format( $start_num );
167
- $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 ) );
168
- $total = bp_core_number_format( $blogs_template->total_blog_count );
169
-
170
- echo sprintf( __( 'Viewing blog %1$s to %2$s (of %3$s blogs)', 'buddypress' ), $from_num, $to_num, $total ); ?> &nbsp;
171
- <span class="ajax-loader"></span><?php
172
- }
173
-
174
- function bp_blogs_pagination_links() {
175
- echo bp_get_blogs_pagination_links();
176
- }
177
- function bp_get_blogs_pagination_links() {
178
- global $blogs_template;
179
-
180
- return apply_filters( 'bp_get_blogs_pagination_links', $blogs_template->pag_links );
181
- }
182
-
183
- function bp_blog_avatar( $args = '' ) {
184
- echo bp_get_blog_avatar( $args );
185
- }
186
- function bp_get_blog_avatar( $args = '' ) {
187
- global $blogs_template, $bp;
188
-
189
- $defaults = array(
190
- 'type' => 'full',
191
- 'width' => false,
192
- 'height' => false,
193
- 'class' => 'avatar',
194
- 'id' => false,
195
- 'alt' => __( 'Blog avatar', 'buddypress' ),
196
- 'no_grav' => true
197
- );
198
-
199
- $r = wp_parse_args( $args, $defaults );
200
- extract( $r, EXTR_SKIP );
201
-
202
- /***
203
- * In future BuddyPress versions you will be able to set the avatar for a blog.
204
- * Right now you can use a filter with the ID of the blog to change it if you wish.
205
- * By default it will return the avatar for the primary blog admin.
206
- */
207
- 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 ) ) );
208
- }
209
-
210
- function bp_blog_permalink() {
211
- echo bp_get_blog_permalink();
212
- }
213
- function bp_get_blog_permalink() {
214
- global $blogs_template;
215
-
216
- if ( empty( $blogs_template->blog->domain ) )
217
- $permalink = $bp->root_domain . $blogs_template->blog->path;
218
- else {
219
- $protocol = 'http://';
220
- if ( is_ssl() )
221
- $protocol = 'https://';
222
-
223
- $permalink = $protocol . $blogs_template->blog->domain . $blogs_template->blog->path;
224
- }
225
-
226
- return apply_filters( 'bp_get_blog_permalink', $permalink );
227
- }
228
-
229
- function bp_blog_name() {
230
- echo bp_get_blog_name();
231
- }
232
- function bp_get_blog_name() {
233
- global $blogs_template;
234
-
235
- return apply_filters( 'bp_get_blog_name', $blogs_template->blog->name );
236
- }
237
-
238
- function bp_blog_description() {
239
- echo apply_filters( 'bp_blog_description', bp_get_blog_description() );
240
- }
241
- function bp_get_blog_description() {
242
- global $blogs_template;
243
-
244
- return apply_filters( 'bp_get_blog_description', $blogs_template->blog->description );
245
- }
246
-
247
- function bp_blog_last_active() {
248
- echo bp_get_blog_last_active();
249
- }
250
- function bp_get_blog_last_active() {
251
- global $blogs_template;
252
-
253
- return apply_filters( 'bp_blog_last_active', bp_core_get_last_activity( $blogs_template->blog->last_activity, __( 'active %s ago', 'buddypress' ) ) );
254
- }
255
-
256
- function bp_blog_latest_post() {
257
- echo bp_get_blog_latest_post();
258
- }
259
- function bp_get_blog_latest_post() {
260
- global $blogs_template;
261
-
262
- if ( null == $blogs_template->blog->latest_post )
263
- return false;
264
-
265
- return apply_filters( 'bp_get_blog_latest_post', sprintf( __( 'Latest Post: %s', 'buddypress' ), '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $blogs_template->blog->latest_post->post_title ) . '</a>' ) );
266
- }
267
-
268
- function bp_blog_hidden_fields() {
269
- if ( isset( $_REQUEST['s'] ) ) {
270
- echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['s'] ). '" name="search_terms" />';
271
- }
272
-
273
- if ( isset( $_REQUEST['letter'] ) ) {
274
- echo '<input type="hidden" id="selected_letter" value="' . attribute_escape( $_REQUEST['letter'] ) . '" name="selected_letter" />';
275
- }
276
-
277
- if ( isset( $_REQUEST['blogs_search'] ) ) {
278
- echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['blogs_search'] ) . '" name="search_terms" />';
279
- }
280
- }
281
-
282
- function bp_total_blog_count() {
283
- echo bp_get_total_blog_count();
284
- }
285
- function bp_get_total_blog_count() {
286
- return apply_filters( 'bp_get_total_blog_count', bp_blogs_total_blogs() );
287
- }
288
- add_filter( 'bp_get_total_blog_count', 'bp_core_number_format' );
289
-
290
- function bp_total_blog_count_for_user( $user_id = false ) {
291
- echo bp_get_total_blog_count_for_user( $user_id );
292
- }
293
- function bp_get_total_blog_count_for_user( $user_id = false ) {
294
- return apply_filters( 'bp_get_total_blog_count_for_user', bp_blogs_total_blogs_for_user( $user_id ) );
295
- }
296
- add_filter( 'bp_get_total_blog_count_for_user', 'bp_core_number_format' );
297
-
298
-
299
- /* Blog registration template tags */
300
-
301
- function bp_blog_signup_enabled() {
302
- global $bp;
303
-
304
- $active_signup = $bp->site_options['registration'];
305
-
306
- if ( !$active_signup )
307
- $active_signup = 'all';
308
-
309
- $active_signup = apply_filters( 'wpmu_active_signup', $active_signup ); // return "all", "none", "blog" or "user"
310
-
311
- if ( 'none' == $active_signup || 'user' == $active_signup )
312
- return false;
313
-
314
- return true;
315
- }
316
-
317
- function bp_show_blog_signup_form($blogname = '', $blog_title = '', $errors = '') {
318
- global $current_user, $current_site;
319
- global $bp;
320
-
321
- require_once( ABSPATH . WPINC . '/registration.php' );
322
-
323
- if ( isset($_POST['submit']) ) {
324
- bp_blogs_validate_blog_signup();
325
- } else {
326
- if ( ! is_wp_error($errors) ) {
327
- $errors = new WP_Error();
328
- }
329
-
330
- // allow definition of default variables
331
- $filtered_results = apply_filters('signup_another_blog_init', array('blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors ));
332
- $blogname = $filtered_results['blogname'];
333
- $blog_title = $filtered_results['blog_title'];
334
- $errors = $filtered_results['errors'];
335
-
336
- if ( $errors->get_error_code() ) {
337
- echo "<p>" . __('There was a problem, please correct the form below and try again.', 'buddypress') . "</p>";
338
- }
339
- ?>
340
- <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>
341
-
342
- <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>
343
-
344
- <form class="standard-form" id="setupform" method="post" action="">
345
-
346
- <input type="hidden" name="stage" value="gimmeanotherblog" />
347
- <?php do_action( "signup_hidden_fields" ); ?>
348
-
349
- <?php bp_blogs_signup_blog($blogname, $blog_title, $errors); ?>
350
- <p>
351
- <input id="submit" type="submit" name="submit" class="submit" value="<?php _e('Create Blog &rarr;', 'buddypress') ?>" />
352
- </p>
353
-
354
- <?php wp_nonce_field( 'bp_blog_signup_form' ) ?>
355
- </form>
356
- <?php
357
- }
358
- }
359
-
360
- function bp_blogs_signup_blog( $blogname = '', $blog_title = '', $errors = '' ) {
361
- global $current_site;
362
-
363
- // Blog name
364
- if( 'no' == constant( "VHOST" ) )
365
- echo '<label for="blogname">' . __('Blog Name:', 'buddypress') . '</label>';
366
- else
367
- echo '<label for="blogname">' . __('Blog Domain:', 'buddypress') . '</label>';
368
-
369
- if ( $errmsg = $errors->get_error_message('blogname') ) { ?>
370
- <p class="error"><?php echo $errmsg ?></p>
371
- <?php }
372
-
373
- if( 'no' == constant( "VHOST" ) ) {
374
- echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span> <input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /><br />';
375
- } else {
376
- echo '<input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /> <span class="suffix_address">.' . $current_site->domain . $current_site->path . '</span><br />';
377
- }
378
- if ( !is_user_logged_in() ) {
379
- print '(<strong>' . __( 'Your address will be ' , 'buddypress');
380
- if( 'no' == constant( "VHOST" ) ) {
381
- print $current_site->domain . $current_site->path . __( 'blogname' , 'buddypress');
382
- } else {
383
- print __( 'domain.' , 'buddypress') . $current_site->domain . $current_site->path;
384
- }
385
- echo '.</strong> ' . __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed so choose carefully!)' , 'buddypress') . '</p>';
386
- }
387
-
388
- // Blog Title
389
- ?>
390
- <label for="blog_title"><?php _e('Blog Title:', 'buddypress') ?></label>
391
- <?php if ( $errmsg = $errors->get_error_message('blog_title') ) { ?>
392
- <p class="error"><?php echo $errmsg ?></p>
393
- <?php }
394
- echo '<input name="blog_title" type="text" id="blog_title" value="'.wp_specialchars($blog_title, 1).'" /></p>';
395
- ?>
396
-
397
- <p>
398
- <label for="blog_public_on"><?php _e('Privacy:', 'buddypress') ?></label>
399
- <?php _e('I would like my blog to appear in search engines like Google and Technorati, and in public listings around this site.', 'buddypress'); ?>
400
-
401
-
402
- <label class="checkbox" for="blog_public_on">
403
- <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 } ?> />
404
- <strong><?php _e( 'Yes' , 'buddypress'); ?></strong>
405
- </label>
406
- <label class="checkbox" for="blog_public_off">
407
- <input type="radio" id="blog_public_off" name="blog_public" value="0" <?php if( isset( $_POST['blog_public'] ) && '0' == $_POST['blog_public'] ) { ?>checked="checked"<?php } ?> />
408
- <strong><?php _e( 'No' , 'buddypress'); ?></strong>
409
- </label>
410
- </p>
411
-
412
- <?php
413
- do_action('signup_blogform', $errors);
414
- }
415
-
416
- function bp_blogs_validate_blog_signup() {
417
- global $wpdb, $current_user, $blogname, $blog_title, $errors, $domain, $path;
418
-
419
- if ( !check_admin_referer( 'bp_blog_signup_form' ) )
420
- return false;
421
-
422
- $current_user = wp_get_current_user();
423
-
424
- if( !is_user_logged_in() )
425
- die();
426
-
427
- $result = bp_blogs_validate_blog_form();
428
- extract($result);
429
-
430
- if ( $errors->get_error_code() ) {
431
- unset($_POST['submit']);
432
- bp_show_blog_signup_form( $blogname, $blog_title, $errors );
433
- return false;
434
- }
435
-
436
- $public = (int) $_POST['blog_public'];
437
-
438
- $meta = apply_filters( 'signup_create_blog_meta', array( 'lang_id' => 1, 'public' => $public ) ); // depreciated
439
- $meta = apply_filters( 'add_signup_meta', $meta );
440
-
441
- /* If this is a VHOST install, remove the username from the domain as we are setting this blog
442
- up inside a user domain, not the root domain. */
443
-
444
- wpmu_create_blog( $domain, $path, $blog_title, $current_user->id, $meta, $wpdb->siteid );
445
- bp_blogs_confirm_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta);
446
- return true;
447
- }
448
-
449
- function bp_blogs_validate_blog_form() {
450
- $user = '';
451
- if ( is_user_logged_in() )
452
- $user = wp_get_current_user();
453
-
454
- return wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title'], $user);
455
- }
456
-
457
- function bp_blogs_confirm_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = '' ) {
458
- ?>
459
- <p><?php _e('Congratulations! You have successfully registered a new blog.', 'buddypress') ?></p>
460
- <p>
461
- <?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) ?>
462
- </p>
463
- <?php
464
- do_action('signup_finished');
465
- }
466
-
467
- function bp_create_blog_link() {
468
- global $bp;
469
-
470
- if ( bp_is_my_profile() ) {
471
- echo apply_filters( 'bp_create_blog_link', '<a href="' . $bp->root_domain . '/' . $bp->blogs->slug . '/create">' . __('Create a Blog', 'buddypress') . '</a>' );
472
- }
473
- }
474
-
475
- function bp_blogs_blog_tabs() {
476
- global $bp, $groups_template;
477
-
478
- // Don't show these tabs on a user's own profile
479
- if ( bp_is_my_profile() )
480
- return false;
481
-
482
- $current_tab = $bp->current_action
483
- ?>
484
- <ul class="content-header-nav">
485
- <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>
486
- <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>
487
- <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>
488
- </ul>
489
- <?php
490
- do_action( 'bp_blogs_blog_tabs', $current_tab );
491
- }
492
-
493
- function bp_directory_blogs_search_form() {
494
- global $bp; ?>
495
- <form action="" method="get" id="search-blogs-form">
496
- <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>
497
- <input type="submit" id="blogs_search_submit" name="blogs_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
498
- </form>
499
- <?php
500
- }
501
-
502
  ?>
1
+ <?php
2
+
3
+ /**********************************************************************
4
+ * Blog listing template class.
5
+ */
6
+
7
+ class BP_Blogs_Template {
8
+ var $current_blog = -1;
9
+ var $blog_count;
10
+ var $blogs;
11
+ var $blog;
12
+
13
+ var $in_the_loop;
14
+
15
+ var $pag_page;
16
+ var $pag_num;
17
+ var $pag_links;
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;
24
+ $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
25
+
26
+ if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] )
27
+ $this->blogs = BP_Blogs_Blog::get_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page );
28
+ else
29
+ $this->blogs = bp_blogs_get_blogs( array( 'type' => $type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms ) );
30
+
31
+ if ( !$max || $max >= (int)$this->blogs['total'] )
32
+ $this->total_blog_count = (int)$this->blogs['total'];
33
+ else
34
+ $this->total_blog_count = (int)$max;
35
+
36
+ $this->blogs = $this->blogs['blogs'];
37
+
38
+ if ( $max ) {
39
+ if ( $max >= count($this->blogs) )
40
+ $this->blog_count = count($this->blogs);
41
+ else
42
+ $this->blog_count = (int)$max;
43
+ } else {
44
+ $this->blog_count = count($this->blogs);
45
+ }
46
+
47
+ $this->pag_links = paginate_links( array(
48
+ 'base' => add_query_arg( 'bpage', '%#%' ),
49
+ 'format' => '',
50
+ 'total' => ceil( (int) $this->total_blog_count / (int) $this->pag_num ),
51
+ 'current' => (int) $this->pag_page,
52
+ 'prev_text' => '&larr;',
53
+ 'next_text' => '&rarr;',
54
+ 'mid_size' => 1
55
+ ));
56
+ }
57
+
58
+ function has_blogs() {
59
+ if ( $this->blog_count )
60
+ return true;
61
+
62
+ return false;
63
+ }
64
+
65
+ function next_blog() {
66
+ $this->current_blog++;
67
+ $this->blog = $this->blogs[$this->current_blog];
68
+
69
+ return $this->blog;
70
+ }
71
+
72
+ function rewind_blogs() {
73
+ $this->current_blog = -1;
74
+ if ( $this->blog_count > 0 ) {
75
+ $this->blog = $this->blogs[0];
76
+ }
77
+ }
78
+
79
+ function blogs() {
80
+ if ( $this->current_blog + 1 < $this->blog_count ) {
81
+ return true;
82
+ } elseif ( $this->current_blog + 1 == $this->blog_count ) {
83
+ do_action('loop_end');
84
+ // Do some cleaning up after the loop
85
+ $this->rewind_blogs();
86
+ }
87
+
88
+ $this->in_the_loop = false;
89
+ return false;
90
+ }
91
+
92
+ function the_blog() {
93
+ global $blog;
94
+
95
+ $this->in_the_loop = true;
96
+ $this->blog = $this->next_blog();
97
+
98
+ if ( 0 == $this->current_blog ) // loop has just started
99
+ do_action('loop_start');
100
+ }
101
+ }
102
+
103
+ function bp_rewind_blogs() {
104
+ global $blogs_template;
105
+
106
+ $blogs_template->rewind_blogs();
107
+ }
108
+
109
+ function bp_has_blogs( $args = '' ) {
110
+ global $bp, $blogs_template;
111
+
112
+ /***
113
+ * Set the defaults based on the current page. Any of these will be overridden
114
+ * if arguments are directly passed into the loop. Custom plugins should always
115
+ * pass their parameters directly to the loop.
116
+ */
117
+ $type = 'active';
118
+ $user_id = false;
119
+ $search_terms = false;
120
+
121
+ /* User filtering */
122
+ if ( !empty( $bp->displayed_user->id ) )
123
+ $user_id = $bp->displayed_user->id;
124
+
125
+ if ( !empty( $_REQUEST['s'] ) )
126
+ $search_terms = $_REQUEST['s'];
127
+
128
+ $defaults = array(
129
+ 'type' => $type,
130
+ 'page' => 1,
131
+ 'per_page' => 20,
132
+ 'max' => false,
133
+
134
+ 'user_id' => $user_id, // Pass a user_id to limit to only blogs this user has higher than subscriber access to
135
+ 'search_terms' => $search_terms // Pass search terms to filter on the blog title or description.
136
+ );
137
+
138
+ $r = wp_parse_args( $args, $defaults );
139
+ extract( $r );
140
+
141
+ if ( $max ) {
142
+ if ( $per_page > $max )
143
+ $per_page = $max;
144
+ }
145
+
146
+ $blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms );
147
+ return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), &$blogs_template );
148
+ }
149
+
150
+ function bp_blogs() {
151
+ global $blogs_template;
152
+
153
+ return $blogs_template->blogs();
154
+ }
155
+
156
+ function bp_the_blog() {
157
+ global $blogs_template;
158
+
159
+ return $blogs_template->the_blog();
160
+ }
161
+
162
+ function bp_blogs_pagination_count() {
163
+ global $bp, $blogs_template;
164
+
165
+ $start_num = intval( ( $blogs_template->pag_page - 1 ) * $blogs_template->pag_num ) + 1;
166
+ $from_num = bp_core_number_format( $start_num );
167
+ $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 ) );
168
+ $total = bp_core_number_format( $blogs_template->total_blog_count );
169
+
170
+ echo sprintf( __( 'Viewing blog %1$s to %2$s (of %3$s blogs)', 'buddypress' ), $from_num, $to_num, $total ); ?> &nbsp;
171
+ <span class="ajax-loader"></span><?php
172
+ }
173
+
174
+ function bp_blogs_pagination_links() {
175
+ echo bp_get_blogs_pagination_links();
176
+ }
177
+ function bp_get_blogs_pagination_links() {
178
+ global $blogs_template;
179
+
180
+ return apply_filters( 'bp_get_blogs_pagination_links', $blogs_template->pag_links );
181
+ }
182
+
183
+ function bp_blog_avatar( $args = '' ) {
184
+ echo bp_get_blog_avatar( $args );
185
+ }
186
+ function bp_get_blog_avatar( $args = '' ) {
187
+ global $blogs_template, $bp;
188
+
189
+ $defaults = array(
190
+ 'type' => 'full',
191
+ 'width' => false,
192
+ 'height' => false,
193
+ 'class' => 'avatar',
194
+ 'id' => false,
195
+ 'alt' => __( 'Blog avatar', 'buddypress' ),
196
+ 'no_grav' => true
197
+ );
198
+
199
+ $r = wp_parse_args( $args, $defaults );
200
+ extract( $r, EXTR_SKIP );
201
+
202
+ /***
203
+ * In future BuddyPress versions you will be able to set the avatar for a blog.
204
+ * Right now you can use a filter with the ID of the blog to change it if you wish.
205
+ * By default it will return the avatar for the primary blog admin.
206
+ */
207
+ 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 ) ) );
208
+ }
209
+
210
+ function bp_blog_permalink() {
211
+ echo bp_get_blog_permalink();
212
+ }
213
+ function bp_get_blog_permalink() {
214
+ global $blogs_template;
215
+
216
+ if ( empty( $blogs_template->blog->domain ) )
217
+ $permalink = $bp->root_domain . $blogs_template->blog->path;
218
+ else {
219
+ $protocol = 'http://';
220
+ if ( is_ssl() )
221
+ $protocol = 'https://';
222
+
223
+ $permalink = $protocol . $blogs_template->blog->domain . $blogs_template->blog->path;
224
+ }
225
+
226
+ return apply_filters( 'bp_get_blog_permalink', $permalink );
227
+ }
228
+
229
+ function bp_blog_name() {
230
+ echo bp_get_blog_name();
231
+ }
232
+ function bp_get_blog_name() {
233
+ global $blogs_template;
234
+
235
+ return apply_filters( 'bp_get_blog_name', $blogs_template->blog->name );
236
+ }
237
+
238
+ function bp_blog_description() {
239
+ echo apply_filters( 'bp_blog_description', bp_get_blog_description() );
240
+ }
241
+ function bp_get_blog_description() {
242
+ global $blogs_template;
243
+
244
+ return apply_filters( 'bp_get_blog_description', $blogs_template->blog->description );
245
+ }
246
+
247
+ function bp_blog_last_active() {
248
+ echo bp_get_blog_last_active();
249
+ }
250
+ function bp_get_blog_last_active() {
251
+ global $blogs_template;
252
+
253
+ return apply_filters( 'bp_blog_last_active', bp_core_get_last_activity( $blogs_template->blog->last_activity, __( 'active %s ago', 'buddypress' ) ) );
254
+ }
255
+
256
+ function bp_blog_latest_post() {
257
+ echo bp_get_blog_latest_post();
258
+ }
259
+ function bp_get_blog_latest_post() {
260
+ global $blogs_template;
261
+
262
+ if ( null == $blogs_template->blog->latest_post )
263
+ return false;
264
+
265
+ return apply_filters( 'bp_get_blog_latest_post', sprintf( __( 'Latest Post: %s', 'buddypress' ), '<a href="' . $blogs_template->blog->latest_post->guid . '">' . apply_filters( 'the_title', $blogs_template->blog->latest_post->post_title ) . '</a>' ) );
266
+ }
267
+
268
+ function bp_blog_hidden_fields() {
269
+ if ( isset( $_REQUEST['s'] ) ) {
270
+ echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['s'] ). '" name="search_terms" />';
271
+ }
272
+
273
+ if ( isset( $_REQUEST['letter'] ) ) {
274
+ echo '<input type="hidden" id="selected_letter" value="' . attribute_escape( $_REQUEST['letter'] ) . '" name="selected_letter" />';
275
+ }
276
+
277
+ if ( isset( $_REQUEST['blogs_search'] ) ) {
278
+ echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['blogs_search'] ) . '" name="search_terms" />';
279
+ }
280
+ }
281
+
282
+ function bp_total_blog_count() {
283
+ echo bp_get_total_blog_count();
284
+ }
285
+ function bp_get_total_blog_count() {
286
+ return apply_filters( 'bp_get_total_blog_count', bp_blogs_total_blogs() );
287
+ }
288
+ add_filter( 'bp_get_total_blog_count', 'bp_core_number_format' );
289
+
290
+ function bp_total_blog_count_for_user( $user_id = false ) {
291
+ echo bp_get_total_blog_count_for_user( $user_id );
292
+ }
293
+ function bp_get_total_blog_count_for_user( $user_id = false ) {
294
+ return apply_filters( 'bp_get_total_blog_count_for_user', bp_blogs_total_blogs_for_user( $user_id ) );
295
+ }
296
+ add_filter( 'bp_get_total_blog_count_for_user', 'bp_core_number_format' );
297
+
298
+
299
+ /* Blog registration template tags */
300
+
301
+ function bp_blog_signup_enabled() {
302
+ global $bp;
303
+
304
+ $active_signup = $bp->site_options['registration'];
305
+
306
+ if ( !$active_signup )
307
+ $active_signup = 'all';
308
+
309
+ $active_signup = apply_filters( 'wpmu_active_signup', $active_signup ); // return "all", "none", "blog" or "user"
310
+
311
+ if ( 'none' == $active_signup || 'user' == $active_signup )
312
+ return false;
313
+
314
+ return true;
315
+ }
316
+
317
+ function bp_show_blog_signup_form($blogname = '', $blog_title = '', $errors = '') {
318
+ global $current_user, $current_site;
319
+ global $bp;
320
+
321
+ require_once( ABSPATH . WPINC . '/registration.php' );
322
+
323
+ if ( isset($_POST['submit']) ) {
324
+ bp_blogs_validate_blog_signup();
325
+ } else {
326
+ if ( ! is_wp_error($errors) ) {
327
+ $errors = new WP_Error();
328
+ }
329
+
330
+ // allow definition of default variables
331
+ $filtered_results = apply_filters('signup_another_blog_init', array('blogname' => $blogname, 'blog_title' => $blog_title, 'errors' => $errors ));
332
+ $blogname = $filtered_results['blogname'];
333
+ $blog_title = $filtered_results['blog_title'];
334
+ $errors = $filtered_results['errors'];
335
+
336
+ if ( $errors->get_error_code() ) {
337
+ echo "<p>" . __('There was a problem, please correct the form below and try again.', 'buddypress') . "</p>";
338
+ }
339
+ ?>
340
+ <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>
341
+
342
+ <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>
343
+
344
+ <form class="standard-form" id="setupform" method="post" action="">
345
+
346
+ <input type="hidden" name="stage" value="gimmeanotherblog" />
347
+ <?php do_action( "signup_hidden_fields" ); ?>
348
+
349
+ <?php bp_blogs_signup_blog($blogname, $blog_title, $errors); ?>
350
+ <p>
351
+ <input id="submit" type="submit" name="submit" class="submit" value="<?php _e('Create Blog &rarr;', 'buddypress') ?>" />
352
+ </p>
353
+
354
+ <?php wp_nonce_field( 'bp_blog_signup_form' ) ?>
355
+ </form>
356
+ <?php
357
+ }
358
+ }
359
+
360
+ function bp_blogs_signup_blog( $blogname = '', $blog_title = '', $errors = '' ) {
361
+ global $current_site;
362
+
363
+ // Blog name
364
+ if( 'no' == constant( "VHOST" ) )
365
+ echo '<label for="blogname">' . __('Blog Name:', 'buddypress') . '</label>';
366
+ else
367
+ echo '<label for="blogname">' . __('Blog Domain:', 'buddypress') . '</label>';
368
+
369
+ if ( $errmsg = $errors->get_error_message('blogname') ) { ?>
370
+ <p class="error"><?php echo $errmsg ?></p>
371
+ <?php }
372
+
373
+ if( 'no' == constant( "VHOST" ) ) {
374
+ echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span> <input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /><br />';
375
+ } else {
376
+ echo '<input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /> <span class="suffix_address">.' . $current_site->domain . $current_site->path . '</span><br />';
377
+ }
378
+ if ( !is_user_logged_in() ) {
379
+ print '(<strong>' . __( 'Your address will be ' , 'buddypress');
380
+ if( 'no' == constant( "VHOST" ) ) {
381
+ print $current_site->domain . $current_site->path . __( 'blogname' , 'buddypress');
382
+ } else {
383
+ print __( 'domain.' , 'buddypress') . $current_site->domain . $current_site->path;
384
+ }
385
+ echo '.</strong> ' . __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed so choose carefully!)' , 'buddypress') . '</p>';
386
+ }
387
+
388
+ // Blog Title
389
+ ?>
390
+ <label for="blog_title"><?php _e('Blog Title:', 'buddypress') ?></label>
391
+ <?php if ( $errmsg = $errors->get_error_message('blog_title') ) { ?>
392
+ <p class="error"><?php echo $errmsg ?></p>
393
+ <?php }
394
+ echo '<input name="blog_title" type="text" id="blog_title" value="'.wp_specialchars($blog_title, 1).'" /></p>';
395
+ ?>
396
+
397
+ <p>
398
+ <label for="blog_public_on"><?php _e('Privacy:', 'buddypress') ?></label>
399
+ <?php _e('I would like my blog to appear in search engines like Google and Technorati, and in public listings around this site.', 'buddypress'); ?>
400
+
401
+
402
+ <label class="checkbox" for="blog_public_on">
403
+ <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 } ?> />
404
+ <strong><?php _e( 'Yes' , 'buddypress'); ?></strong>
405
+ </label>
406
+ <label class="checkbox" for="blog_public_off">
407
+ <input type="radio" id="blog_public_off" name="blog_public" value="0" <?php if( isset( $_POST['blog_public'] ) && '0' == $_POST['blog_public'] ) { ?>checked="checked"<?php } ?> />
408
+ <strong><?php _e( 'No' , 'buddypress'); ?></strong>
409
+ </label>
410
+ </p>
411
+
412
+ <?php
413
+ do_action('signup_blogform', $errors);
414
+ }
415
+
416
+ function bp_blogs_validate_blog_signup() {
417
+ global $wpdb, $current_user, $blogname, $blog_title, $errors, $domain, $path;
418
+
419
+ if ( !check_admin_referer( 'bp_blog_signup_form' ) )
420
+ return false;
421
+
422
+ $current_user = wp_get_current_user();
423
+
424
+ if( !is_user_logged_in() )
425
+ die();
426
+
427
+ $result = bp_blogs_validate_blog_form();
428
+ extract($result);
429
+
430
+ if ( $errors->get_error_code() ) {
431
+ unset($_POST['submit']);
432
+ bp_show_blog_signup_form( $blogname, $blog_title, $errors );
433
+ return false;
434
+ }
435
+
436
+ $public = (int) $_POST['blog_public'];
437
+
438
+ $meta = apply_filters( 'signup_create_blog_meta', array( 'lang_id' => 1, 'public' => $public ) ); // depreciated
439
+ $meta = apply_filters( 'add_signup_meta', $meta );
440
+
441
+ /* If this is a VHOST install, remove the username from the domain as we are setting this blog
442
+ up inside a user domain, not the root domain. */
443
+
444
+ wpmu_create_blog( $domain, $path, $blog_title, $current_user->id, $meta, $wpdb->siteid );
445
+ bp_blogs_confirm_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta);
446
+ return true;
447
+ }
448
+
449
+ function bp_blogs_validate_blog_form() {
450
+ $user = '';
451
+ if ( is_user_logged_in() )
452
+ $user = wp_get_current_user();
453
+
454
+ return wpmu_validate_blog_signup($_POST['blogname'], $_POST['blog_title'], $user);
455
+ }
456
+
457
+ function bp_blogs_confirm_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = '' ) {
458
+ ?>
459
+ <p><?php _e('Congratulations! You have successfully registered a new blog.', 'buddypress') ?></p>
460
+ <p>
461
+ <?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) ?>
462
+ </p>
463
+ <?php
464
+ do_action('signup_finished');
465
+ }
466
+
467
+ function bp_create_blog_link() {
468
+ global $bp;
469
+
470
+ if ( bp_is_my_profile() ) {
471
+ echo apply_filters( 'bp_create_blog_link', '<a href="' . $bp->root_domain . '/' . $bp->blogs->slug . '/create">' . __('Create a Blog', 'buddypress') . '</a>' );
472
+ }
473
+ }
474
+
475
+ function bp_blogs_blog_tabs() {
476
+ global $bp, $groups_template;
477
+
478
+ // Don't show these tabs on a user's own profile
479
+ if ( bp_is_my_profile() )
480
+ return false;
481
+
482
+ $current_tab = $bp->current_action
483
+ ?>
484
+ <ul class="content-header-nav">
485
+ <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>
486
+ <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>
487
+ <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>
488
+ </ul>
489
+ <?php
490
+ do_action( 'bp_blogs_blog_tabs', $current_tab );
491
+ }
492
+
493
+ function bp_directory_blogs_search_form() {
494
+ global $bp; ?>
495
+ <form action="" method="get" id="search-blogs-form">
496
+ <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>
497
+ <input type="submit" id="blogs_search_submit" name="blogs_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
498
+ </form>
499
+ <?php
500
+ }
501
+
502
  ?>
bp-blogs/bp-blogs-widgets.php CHANGED
@@ -1,87 +1,84 @@
1
- <?php
2
-
3
- /***
4
- * The recent blogs widget is actually just the activity feed filtered on "new_blog_post".
5
- * Why not make some of your own widgets using a filtered activity stream?
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) {
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
32
- if ( empty( $instance['max_posts'] ) || !$instance['max_posts'] )
33
- $instance['max_posts'] = 10; ?>
34
-
35
- <?php if ( bp_has_activities( 'action=new_blog_post&max=' . $instance['max_posts'] . '&per_page=' . $instance['max_posts'] ) ) : ?>
36
-
37
- <ul id="blog-post-list" class="activity-list item-list">
38
-
39
- <?php while ( bp_activities() ) : bp_the_activity(); ?>
40
-
41
- <li>
42
- <div class="activity-content" style="margin: 0">
43
-
44
- <div class="activity-header">
45
- <?php bp_activity_action() ?>
46
- </div>
47
-
48
- <?php if ( bp_get_activity_content_body() ) : ?>
49
- <div class="activity-inner">
50
- <?php bp_activity_content_body() ?>
51
- </div>
52
- <?php endif; ?>
53
-
54
- </div>
55
- </li>
56
-
57
- <?php endwhile; ?>
58
-
59
- </ul>
60
-
61
- <?php else : ?>
62
- <div id="message" class="info">
63
- <p><?php _e( 'Sorry, there were no blog posts found. Why not write one?', 'buddypress' ) ?></p>
64
- </div>
65
- <?php endif; ?>
66
-
67
- <?php echo $after_widget; ?>
68
- <?php
69
- }
70
-
71
- function update( $new_instance, $old_instance ) {
72
- $instance = $old_instance;
73
- $instance['max_posts'] = strip_tags( $new_instance['max_posts'] );
74
-
75
- return $instance;
76
- }
77
-
78
- function form( $instance ) {
79
- $instance = wp_parse_args( (array) $instance, array( 'max_posts' => 10 ) );
80
- $max_posts = strip_tags( $instance['max_posts'] );
81
- ?>
82
-
83
- <p><label for="bp-blogs-widget-posts-max"><?php _e('Max posts to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_posts' ); ?>" name="<?php echo $this->get_field_name( 'max_posts' ); ?>" type="text" value="<?php echo attribute_escape( $max_posts ); ?>" style="width: 30%" /></label></p>
84
- <?php
85
- }
86
- }
87
  ?>
1
+ <?php
2
+
3
+ /***
4
+ * The recent blogs widget is actually just the activity feed filtered on "new_blog_post".
5
+ * Why not make some of your own widgets using a filtered activity stream?
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) {
22
+ global $bp;
23
+
24
+ extract( $args );
25
+
26
+ echo $before_widget;
27
+ echo $before_title . $widget_name . $after_title;
28
+
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
+
36
+ <?php while ( bp_activities() ) : bp_the_activity(); ?>
37
+
38
+ <li>
39
+ <div class="activity-content" style="margin: 0">
40
+
41
+ <div class="activity-header">
42
+ <?php bp_activity_action() ?>
43
+ </div>
44
+
45
+ <?php if ( bp_get_activity_content_body() ) : ?>
46
+ <div class="activity-inner">
47
+ <?php bp_activity_content_body() ?>
48
+ </div>
49
+ <?php endif; ?>
50
+
51
+ </div>
52
+ </li>
53
+
54
+ <?php endwhile; ?>
55
+
56
+ </ul>
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
+
64
+ <?php echo $after_widget; ?>
65
+ <?php
66
+ }
67
+
68
+ function update( $new_instance, $old_instance ) {
69
+ $instance = $old_instance;
70
+ $instance['max_posts'] = strip_tags( $new_instance['max_posts'] );
71
+
72
+ return $instance;
73
+ }
74
+
75
+ function form( $instance ) {
76
+ $instance = wp_parse_args( (array) $instance, array( 'max_posts' => 10 ) );
77
+ $max_posts = strip_tags( $instance['max_posts'] );
78
+ ?>
79
+
80
+ <p><label for="bp-blogs-widget-posts-max"><?php _e('Max posts to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_posts' ); ?>" name="<?php echo $this->get_field_name( 'max_posts' ); ?>" type="text" value="<?php echo attribute_escape( $max_posts ); ?>" style="width: 30%" /></label></p>
81
+ <?php
82
+ }
83
+ }
 
 
 
84
  ?>
bp-core.php CHANGED
@@ -1,2107 +1,2144 @@
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, $wpdb;
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
- /* The domain for the root of the site where the main blog resides */
95
- $bp->root_domain = bp_core_get_root_domain();
96
-
97
- /* The user ID of the user who is currently logged in. */
98
- $bp->loggedin_user->id = $current_user->ID;
99
-
100
- /* The domain for the user currently logged in. eg: http://domain.com/members/andy */
101
- $bp->loggedin_user->domain = bp_core_get_user_domain( $bp->loggedin_user->id );
102
-
103
- /* The core userdata of the user who is currently logged in. */
104
- $bp->loggedin_user->userdata = bp_core_get_core_userdata( $bp->loggedin_user->id );
105
-
106
- /* is_site_admin() hits the DB on single WP installs, so we need to get this separately so we can call it in a loop. */
107
- $bp->loggedin_user->is_site_admin = is_site_admin();
108
-
109
- /* The user id of the user currently being viewed, set in /bp-core/bp-core-catchuri.php */
110
- $bp->displayed_user->id = $displayed_user_id;
111
-
112
- /* The domain for the user currently being displayed */
113
- $bp->displayed_user->domain = bp_core_get_user_domain( $bp->displayed_user->id );
114
-
115
- /* The core userdata of the user who is currently being displayed */
116
- $bp->displayed_user->userdata = bp_core_get_core_userdata( $bp->displayed_user->id );
117
-
118
- /* The component being used eg: http://domain.com/members/andy/ [profile] */
119
- $bp->current_component = $current_component; // type: string
120
-
121
- /* The current action for the component eg: http://domain.com/members/andy/profile/ [edit] */
122
- $bp->current_action = $current_action; // type: string
123
-
124
- /* The action variables for the current action eg: http://domain.com/members/andy/profile/edit/ [group] / [6] */
125
- $bp->action_variables = $action_variables; // type: array
126
-
127
- /* 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.*/
128
- $bp->current_item = ''; // type: string
129
-
130
- /* Used for overriding the 2nd level navigation menu so it can be used to display custom navigation for an item (for example a group) */
131
- $bp->is_single_item = false;
132
-
133
- /* The default component to use if none are set and someone visits: http://domain.com/members/andy */
134
- if ( !defined( 'BP_DEFAULT_COMPONENT' ) ) {
135
- if ( defined( 'BP_ACTIVITY_SLUG' ) )
136
- $bp->default_component = BP_ACTIVITY_SLUG;
137
- else
138
- $bp->default_component = 'profile';
139
- } else {
140
- $bp->default_component = BP_DEFAULT_COMPONENT;
141
- }
142
-
143
- /* Fetches all of the core database based BuddyPress settings in one foul swoop */
144
- $bp->site_options = bp_core_get_site_options();
145
-
146
- /* Sets up the array container for the component navigation rendered by bp_get_nav() */
147
- $bp->bp_nav = array();
148
-
149
- /* Sets up the array container for the component options navigation rendered by bp_get_options_nav() */
150
- $bp->bp_options_nav = array();
151
-
152
- /* Contains an array of all the active components. The key is the slug, value the internal ID of the component */
153
- $bp->active_components = array();
154
-
155
- /* Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar */
156
- $bp->grav_default->user = apply_filters( 'bp_user_gravatar_default', $bp->site_options['user-avatar-default'] );
157
- $bp->grav_default->group = apply_filters( 'bp_group_gravatar_default', 'identicon' );
158
- $bp->grav_default->blog = apply_filters( 'bp_blog_gravatar_default', 'identicon' );
159
-
160
- /* Fetch the full name for the logged in and current user */
161
- $bp->loggedin_user->fullname = bp_core_get_user_displayname( $bp->loggedin_user->id );
162
- $bp->displayed_user->fullname = bp_core_get_user_displayname( $bp->displayed_user->id );
163
-
164
- /* Used to determine if user has admin rights on current content. If the logged in user is viewing
165
- their own profile and wants to delete something, is_item_admin is used. This is a
166
- generic variable so it can be used by other components. It can also be modified, so when viewing a group
167
- 'is_item_admin' would be 1 if they are a group admin, 0 if they are not. */
168
- $bp->is_item_admin = bp_user_has_access();
169
-
170
- /* Used to determine if the logged in user is a moderator for the current content. */
171
- $bp->is_item_mod = false;
172
-
173
- $bp->core->table_name_notifications = $wpdb->base_prefix . 'bp_notifications';
174
-
175
- if ( !$bp->current_component && $bp->displayed_user->id )
176
- $bp->current_component = $bp->default_component;
177
-
178
- do_action( 'bp_core_setup_globals' );
179
- }
180
- add_action( 'bp_setup_globals', 'bp_core_setup_globals' );
181
-
182
- /**
183
- * bp_core_setup_root_uris()
184
- *
185
- * Adds the core URIs that should run in the root of the installation.
186
- *
187
- * For example: http://example.org/search/ or http://example.org/members/
188
- *
189
- * @package BuddyPress Core
190
- * @uses bp_core_add_root_component() Adds a slug to the root components global variable.
191
- */
192
- function bp_core_setup_root_uris() {
193
- /* Add core root components */
194
- bp_core_add_root_component( BP_MEMBERS_SLUG );
195
- bp_core_add_root_component( BP_REGISTER_SLUG );
196
- bp_core_add_root_component( BP_ACTIVATION_SLUG );
197
- bp_core_add_root_component( BP_SEARCH_SLUG );
198
- }
199
- add_action( 'plugins_loaded', 'bp_core_setup_root_uris', 2 );
200
-
201
-
202
- /**
203
- * bp_core_install()
204
- *
205
- * Installs the core DB tables for BuddyPress.
206
- *
207
- * @package BuddyPress Core
208
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
209
- * @global $wpdb WordPress DB access object.
210
- * @uses dbDelta() Performs a table creation, or upgrade based on what already exists in the DB.
211
- * @uses bp_core_add_illegal_names() Adds illegal blog names to the WP settings
212
- */
213
- function bp_core_install() {
214
- global $wpdb, $bp;
215
-
216
- if ( !empty($wpdb->charset) )
217
- $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
218
-
219
- $sql[] = "CREATE TABLE {$bp->core->table_name_notifications} (
220
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
221
- user_id bigint(20) NOT NULL,
222
- item_id bigint(20) NOT NULL,
223
- secondary_item_id bigint(20),
224
- component_name varchar(75) NOT NULL,
225
- component_action varchar(75) NOT NULL,
226
- date_notified datetime NOT NULL,
227
- is_new bool NOT NULL DEFAULT 0,
228
- KEY item_id (item_id),
229
- KEY secondary_item_id (secondary_item_id),
230
- KEY user_id (user_id),
231
- KEY is_new (is_new),
232
- KEY component_name (component_name),
233
- KEY component_action (component_action),
234
- KEY useritem (user_id,is_new)
235
- ) {$charset_collate};";
236
-
237
- require_once( ABSPATH . 'wp-admin/upgrade-functions.php' );
238
- dbDelta( $sql );
239
-
240
- /* Add names of root components to the banned blog list to avoid conflicts */
241
- if ( bp_core_is_multisite() )
242
- bp_core_add_illegal_names();
243
-
244
- update_site_option( 'bp-core-db-version', BP_CORE_DB_VERSION );
245
- }
246
-
247
- /**
248
- * bp_core_check_installed()
249
- *
250
- * Checks to make sure the database tables are set up for the core component.
251
- *
252
- * @package BuddyPress Core
253
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
254
- * @global $wpdb WordPress DB access object.
255
- * @global $current_user WordPress global variable containing current logged in user information
256
- * @uses is_site_admin() returns true if the current user is a site admin, false if not
257
- * @uses get_site_option() fetches the value for a meta_key in the wp_sitemeta table
258
- * @uses bp_core_install() runs the installation of DB tables for the core component
259
- */
260
- function bp_core_check_installed() {
261
- global $wpdb, $bp;
262
-
263
- if ( !is_site_admin() )
264
- return false;
265
-
266
- require ( BP_PLUGIN_DIR . '/bp-core/bp-core-admin.php' );
267
-
268
- /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
269
- if ( get_site_option( 'bp-core-db-version' ) < BP_CORE_DB_VERSION )
270
- bp_core_install();
271
- }
272
- add_action( 'admin_menu', 'bp_core_check_installed' );
273
-
274
- /**
275
- * bp_core_add_admin_menu()
276
- *
277
- * Adds the "BuddyPress" admin submenu item to the Site Admin tab.
278
- *
279
- * @package BuddyPress Core
280
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
281
- * @global $wpdb WordPress DB access object.
282
- * @uses is_site_admin() returns true if the current user is a site admin, false if not
283
- * @uses add_submenu_page() WP function to add a submenu item
284
- */
285
- function bp_core_add_admin_menu() {
286
- if ( !is_site_admin() )
287
- return false;
288
-
289
- /* Add the administration tab under the "Site Admin" tab for site administrators */
290
- bp_core_add_admin_menu_page( array(
291
- 'menu_title' => __( 'BuddyPress', 'buddypress' ),
292
- 'page_title' => __( 'BuddyPress', 'buddypress' ),
293
- 'access_level' => 10, 'file' => 'bp-general-settings',
294
- 'function' => 'bp_core_admin_settings',
295
- 'position' => 2
296
- ) );
297
-
298
- add_submenu_page( 'bp-general-settings', __( 'General Settings', 'buddypress'), __( 'General Settings', 'buddypress' ), 'manage_options', 'bp-general-settings', 'bp_core_admin_settings' );
299
- add_submenu_page( 'bp-general-settings', __( 'Component Setup', 'buddypress'), __( 'Component Setup', 'buddypress' ), 'manage_options', 'bp-component-setup', 'bp_core_admin_component_setup' );
300
- }
301
- add_action( 'admin_menu', 'bp_core_add_admin_menu' );
302
-
303
- /**
304
- * bp_core_is_root_component()
305
- *
306
- * Checks to see if a component's URL should be in the root, not under a member page:
307
- * eg: http://domain.com/groups/the-group NOT http://domain.com/members/andy/groups/the-group
308
- *
309
- * @package BuddyPress Core
310
- * @return true if root component, else false.
311
- */
312
- function bp_core_is_root_component( $component_name ) {
313
- global $bp;
314
-
315
- return in_array( $component_name, $bp->root_components );
316
- }
317
-
318
- /**
319
- * bp_core_setup_nav()
320
- *
321
- * Sets up the profile navigation item if the Xprofile component is not installed.
322
- *
323
- * @package BuddyPress Core
324
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
325
- * @uses bp_core_new_nav_item() Adds a navigation item to the top level buddypress navigation
326
- * @uses bp_core_new_subnav_item() Adds a sub navigation item to a nav item
327
- * @uses bp_is_my_profile() Returns true if the current user being viewed is equal the logged in user
328
- * @uses bp_core_fetch_avatar() Returns the either the thumb or full avatar URL for the user_id passed
329
- */
330
- function bp_core_setup_nav() {
331
- global $bp;
332
-
333
- /***
334
- * If the extended profiles component is disabled, we need to revert to using the
335
- * built in WordPress profile information
336
- */
337
- if ( !function_exists( 'xprofile_install' ) ) {
338
- /* Fallback values if xprofile is disabled */
339
- $bp->core->profile->slug = 'profile';
340
- $bp->active_components[$bp->core->profile->slug] = $bp->core->profile->slug;
341
-
342
- /* Add 'Profile' to the main navigation */
343
- bp_core_new_nav_item( array(
344
- 'name' => __('Profile', 'buddypress'),
345
- 'slug' => $bp->core->profile->slug,
346
- 'position' => 20,
347
- 'screen_function' => 'bp_core_catch_profile_uri',
348
- 'default_subnav_slug' => 'public'
349
- ) );
350
-
351
- $profile_link = $bp->loggedin_user->domain . '/profile/';
352
-
353
- /* Add the subnav items to the profile */
354
- bp_core_new_subnav_item( array(
355
- 'name' => __( 'Public', 'buddypress' ),
356
- 'slug' => 'public',
357
- 'parent_url' => $profile_link,
358
- 'parent_slug' => $bp->core->profile->slug,
359
- 'screen_function' => 'bp_core_catch_profile_uri'
360
- ) );
361
-
362
-
363
- if ( 'profile' == $bp->current_component ) {
364
- if ( bp_is_my_profile() ) {
365
- $bp->bp_options_title = __('My Profile', 'buddypress');
366
- } else {
367
- $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
368
- $bp->bp_options_title = $bp->displayed_user->fullname;
369
- }
370
- }
371
- }
372
- }
373
- add_action( 'bp_setup_nav', 'bp_core_setup_nav' );
374
-
375
- /********************************************************************************
376
- * Action Functions
377
- *
378
- * Action functions are exactly the same as screen functions, however they do not
379
- * have a template screen associated with them. Usually they will send the user
380
- * back to the default screen after execution.
381
- */
382
-
383
- /**
384
- * bp_core_action_directory_members()
385
- *
386
- * Listens to the $bp component and action variables to determine if the user is viewing the members
387
- * directory page. If they are, it will set up the directory and load the members directory template.
388
- *
389
- * @package BuddyPress Core
390
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
391
- * @uses wp_enqueue_script() Loads a JS script into the header of the page.
392
- * @uses bp_core_load_template() Loads a specific template file.
393
- */
394
- function bp_core_action_directory_members() {
395
- global $bp;
396
-
397
- if ( is_null( $bp->displayed_user->id ) && $bp->current_component == BP_MEMBERS_SLUG ) {
398
- $bp->is_directory = true;
399
-
400
- do_action( 'bp_core_action_directory_members' );
401
- bp_core_load_template( apply_filters( 'bp_core_template_directory_members', 'members/index' ) );
402
- }
403
- }
404
- add_action( 'wp', 'bp_core_action_directory_members', 2 );
405
-
406
- /**
407
- * bp_core_action_set_spammer_status()
408
- *
409
- * When a site admin selects "Mark as Spammer/Not Spammer" from the admin menu
410
- * this action will fire and mark or unmark the user and their blogs as spam.
411
- * Must be a site admin for this function to run.
412
- *
413
- * @package BuddyPress Core
414
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
415
- */
416
- function bp_core_action_set_spammer_status() {
417
- global $bp, $wpdb, $wp_version;
418
-
419
- if ( !is_site_admin() || bp_is_my_profile() || !$bp->displayed_user->id )
420
- return false;
421
-
422
- if ( 'admin' == $bp->current_component && ( 'mark-spammer' == $bp->current_action || 'unmark-spammer' == $bp->current_action ) ) {
423
- /* Check the nonce */
424
- check_admin_referer( 'mark-unmark-spammer' );
425
-
426
- /* Get the functions file */
427
- if ( bp_core_is_multisite() ) {
428
- if ( $wp_version >= '3.0' )
429
- require_once( ABSPATH . '/wp-admin/includes/ms.php' );
430
- else
431
- require_once( ABSPATH . '/wp-admin/includes/mu.php' );
432
- }
433
-
434
- if ( 'mark-spammer' == $bp->current_action )
435
- $is_spam = 1;
436
- else
437
- $is_spam = 0;
438
-
439
- /* Get the blogs for the user */
440
- $blogs = get_blogs_of_user( $bp->displayed_user->id, true );
441
-
442
- foreach ( (array) $blogs as $key => $details ) {
443
- /* Do not mark the main or current root blog as spam */
444
- if ( 1 == $details->userblog_id || BP_ROOT_BLOG == $details->userblog_id )
445
- continue;
446
-
447
- /* Update the blog status */
448
- update_blog_status( $details->userblog_id, 'spam', $is_spam );
449
-
450
- /* Fire the standard WPMU hook */
451
- do_action( 'make_spam_blog', $details->userblog_id );
452
- }
453
-
454
- /* Finally, mark this user as a spammer */
455
- if ( bp_core_is_multisite() )
456
- $wpdb->update( $wpdb->users, array( 'spam' => $is_spam ), array( 'ID' => $bp->displayed_user->id ) );
457
-
458
- $wpdb->update( $wpdb->users, array( 'user_status' => $is_spam ), array( 'ID' => $bp->displayed_user->id ) );
459
-
460
- if ( $is_spam )
461
- bp_core_add_message( __( 'User marked as spammer. Spam users are visible only to site admins.', 'buddypress' ) );
462
- else
463
- bp_core_add_message( __( 'User removed as spammer.', 'buddypress' ) );
464
-
465
- /* Hide this user's activity */
466
- if ( $is_spam && function_exists( 'bp_activity_hide_user_activity' ) )
467
- bp_activity_hide_user_activity( $bp->displayed_user->id );
468
-
469
- do_action( 'bp_core_action_set_spammer_status', $bp->displayed_user->id, $is_spam );
470
-
471
- bp_core_redirect( wp_get_referer() );
472
- }
473
- }
474
- add_action( 'wp', 'bp_core_action_set_spammer_status', 3 );
475
-
476
- /**
477
- * bp_core_action_delete_user()
478
- *
479
- * Allows a site admin to delete a user from the adminbar menu.
480
- *
481
- * @package BuddyPress Core
482
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
483
- */
484
- function bp_core_action_delete_user() {
485
- global $bp;
486
-
487
- if ( !is_site_admin() || bp_is_my_profile() || !$bp->displayed_user->id )
488
- return false;
489
-
490
- if ( 'admin' == $bp->current_component && 'delete-user' == $bp->current_action ) {
491
- /* Check the nonce */
492
- check_admin_referer( 'delete-user' );
493
-
494
- $errors = false;
495
-
496
- if ( bp_core_delete_account( $bp->displayed_user->id ) ) {
497
- bp_core_add_message( sprintf( __( '%s has been deleted from the system.', 'buddypress' ), $bp->displayed_user->fullname ) );
498
- } else {
499
- bp_core_add_message( sprintf( __( 'There was an error deleting %s from the system. Please try again.', 'buddypress' ), $bp->displayed_user->fullname ), 'error' );
500
- $errors = true;
501
- }
502
-
503
- do_action( 'bp_core_action_delete_user', $errors );
504
-
505
- if ( $errors )
506
- bp_core_redirect( $bp->displayed_user->domain );
507
- else
508
- bp_core_redirect( $bp->loggedin_user->domain );
509
- }
510
- }
511
- add_action( 'wp', 'bp_core_action_delete_user', 3 );
512
-
513
-
514
- /********************************************************************************
515
- * Business Functions
516
- *
517
- * Business functions are where all the magic happens in BuddyPress. They will
518
- * handle the actual saving or manipulation of information. Usually they will
519
- * hand off to a database class for data access, then return
520
- * true or false on success or failure.
521
- */
522
-
523
- /**
524
- * bp_core_get_users()
525
- *
526
- * Return an array of users IDs based on the parameters passed.
527
- *
528
- * @package BuddyPress Core
529
- */
530
- function bp_core_get_users( $args = '' ) {
531
- global $bp;
532
-
533
- $defaults = array(
534
- 'type' => 'active', // active, newest, alphabetical, random or popular
535
- 'user_id' => false, // Pass a user_id to limit to only friend connections for this user
536
- 'search_terms' => false, // Limit to users that match these search terms
537
-
538
- 'include' => false, // Pass comma separated list of user_ids to limit to only these users
539
- 'per_page' => 20, // The number of results to return per page
540
- 'page' => 1, // The page to return if limiting per page
541
- 'populate_extras' => true, // Fetch the last active, where the user is a friend, total friend count, latest update
542
- );
543
-
544
- $params = wp_parse_args( $args, $defaults );
545
- extract( $params, EXTR_SKIP );
546
-
547
- return apply_filters( 'bp_core_get_users', BP_Core_User::get_users( $type, $per_page, $page, $user_id, $include, $search_terms, $populate_extras ), &$params );
548
- }
549
-
550
- /**
551
- * bp_core_get_user_domain()
552
- *
553
- * Returns the domain for the passed user:
554
- * e.g. http://domain.com/members/andy/
555
- *
556
- * @package BuddyPress Core
557
- * @global $current_user WordPress global variable containing current logged in user information
558
- * @param user_id The ID of the user.
559
- * @uses get_usermeta() WordPress function to get the usermeta for a user.
560
- */
561
- function bp_core_get_user_domain( $user_id, $user_nicename = false, $user_login = false ) {
562
- global $bp;
563
-
564
- if ( !$user_id ) return;
565
-
566
- if ( !$domain = wp_cache_get( 'bp_user_domain_' . $user_id, 'bp' ) ) {
567
- $username = bp_core_get_username( $user_id, $user_nicename, $user_login );
568
-
569
- /* If we are using a members slug, include it. */
570
- if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) )
571
- $domain = $bp->root_domain . '/' . BP_MEMBERS_SLUG . '/' . $username . '/';
572
- else
573
- $domain = $bp->root_domain . '/' . $username . '/';
574
-
575
- /* Cache the link */
576
- if ( !empty( $domain ) )
577
- wp_cache_set( 'bp_user_domain_' . $user_id, $domain, 'bp' );
578
- }
579
-
580
- return apply_filters( 'bp_core_get_user_domain', $domain );
581
- }
582
-
583
- /**
584
- * bp_core_get_core_userdata()
585
- *
586
- * Fetch everything in the wp_users table for a user, without any usermeta.
587
- *
588
- * @package BuddyPress Core
589
- * @param user_id The ID of the user.
590
- * @uses BP_Core_User::get_core_userdata() Performs the query.
591
- */
592
- function bp_core_get_core_userdata( $user_id ) {
593
- if ( empty( $user_id ) )
594
- return false;
595
-
596
- if ( !$userdata = wp_cache_get( 'bp_core_userdata_' . $user_id, 'bp' ) ) {
597
- $userdata = BP_Core_User::get_core_userdata( $user_id );
598
- wp_cache_set( 'bp_core_userdata_' . $user_id, $userdata, 'bp' );
599
- }
600
- return apply_filters( 'bp_core_get_core_userdata', $userdata );
601
- }
602
-
603
- /**
604
- * bp_core_get_root_domain()
605
- *
606
- * Returns the domain for the root blog.
607
- * eg: http://domain.com/ OR https://domain.com
608
- *
609
- * @package BuddyPress Core
610
- * @uses get_blog_option() WordPress function to fetch blog meta.
611
- * @return $domain The domain URL for the blog.
612
- */
613
- function bp_core_get_root_domain() {
614
- global $current_blog;
615
-
616
- if ( defined( 'BP_ENABLE_MULTIBLOG' ) )
617
- $domain = get_blog_option( $current_blog->blog_id, 'home' );
618
- else
619
- $domain = get_blog_option( BP_ROOT_BLOG, 'home' );
620
-
621
- return apply_filters( 'bp_core_get_root_domain', $domain );
622
- }
623
-
624
- /**
625
- * bp_core_get_displayed_userid()
626
- *
627
- * Returns the user id for the user that is currently being displayed.
628
- * eg: http://andy.domain.com/ or http://domain.com/andy/
629
- *
630
- * @package BuddyPress Core
631
- * @global $current_blog WordPress global containing information and settings for the current blog being viewed.
632
- * @uses bp_core_get_userid_from_user_login() Returns the user id for the username passed
633
- * @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.
634
- */
635
- function bp_core_get_displayed_userid( $user_login ) {
636
- return apply_filters( 'bp_core_get_displayed_userid', bp_core_get_userid( $user_login ) );
637
- }
638
-
639
- /**
640
- * bp_core_new_nav_item()
641
- *
642
- * Adds a navigation item to the main navigation array used in BuddyPress themes.
643
- *
644
- * @package BuddyPress Core
645
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
646
- */
647
- function bp_core_new_nav_item( $args = '' ) {
648
- global $bp;
649
-
650
- $defaults = array(
651
- 'name' => false, // Display name for the nav item
652
- 'slug' => false, // URL slug for the nav item
653
- 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item
654
- 'show_for_displayed_user' => true, // When viewing another user does this nav item show up?
655
- 'site_admin_only' => false, // Can only site admins see this nav item?
656
- 'position' => 99, // Index of where this nav item should be positioned
657
- 'screen_function' => false, // The name of the function to run when clicked
658
- 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked
659
- );
660
-
661
- $r = wp_parse_args( $args, $defaults );
662
- extract( $r, EXTR_SKIP );
663
-
664
- /* If we don't have the required info we need, don't create this subnav item */
665
- if ( empty($name) || empty($slug) )
666
- return false;
667
-
668
- /* If this is for site admins only and the user is not one, don't create the subnav item */
669
- if ( $site_admin_only && !is_site_admin() )
670
- return false;
671
-
672
- if ( empty( $item_css_id ) )
673
- $item_css_id = $slug;
674
-
675
- $bp->bp_nav[$slug] = array(
676
- 'name' => $name,
677
- 'slug' => $slug,
678
- 'link' => $bp->loggedin_user->domain . $slug . '/',
679
- 'css_id' => $item_css_id,
680
- 'show_for_displayed_user' => $show_for_displayed_user,
681
- 'position' => $position
682
- );
683
-
684
- /***
685
- * If this nav item is hidden for the displayed user, and
686
- * the logged in user is not the displayed user
687
- * looking at their own profile, don't create the nav item.
688
- */
689
- if ( !$show_for_displayed_user && !bp_user_has_access() )
690
- return false;
691
-
692
- /***
693
- * If we are not viewing a user, and this is a root component, don't attach the
694
- * default subnav function so we can display a directory or something else.
695
- */
696
- if ( bp_core_is_root_component( $slug ) && !$bp->displayed_user->id )
697
- return;
698
-
699
- if ( $bp->current_component == $slug && !$bp->current_action ) {
700
- if ( !is_object( $screen_function[0] ) )
701
- add_action( 'wp', $screen_function, 3 );
702
- else
703
- add_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );
704
-
705
- if ( $default_subnav_slug )
706
- $bp->current_action = $default_subnav_slug;
707
- }
708
- }
709
-
710
- /**
711
- * bp_core_new_nav_default()
712
- *
713
- * Modify the default subnav item to load when a top level nav item is clicked.
714
- *
715
- * @package BuddyPress Core
716
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
717
- */
718
- function bp_core_new_nav_default( $args = '' ) {
719
- global $bp;
720
-
721
- $defaults = array(
722
- 'parent_slug' => false, // Slug of the parent
723
- 'screen_function' => false, // The name of the function to run when clicked
724
- 'subnav_slug' => false // The slug of the subnav item to select when clicked
725
- );
726
-
727
- $r = wp_parse_args( $args, $defaults );
728
- extract( $r, EXTR_SKIP );
729
-
730
- if ( $bp->current_component == $parent_slug && !$bp->current_action ) {
731
- if ( !is_object( $screen_function[0] ) )
732
- add_action( 'wp', $screen_function, 3 );
733
- else
734
- add_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );
735
-
736
- if ( $subnav_slug )
737
- $bp->current_action = $subnav_slug;
738
- }
739
- }
740
-
741
- /**
742
- * bp_core_sort_nav_items()
743
- *
744
- * We can only sort nav items by their position integer at a later point in time, once all
745
- * plugins have registered their navigation items.
746
- *
747
- * @package BuddyPress Core
748
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
749
- */
750
- function bp_core_sort_nav_items() {
751
- global $bp;
752
-
753
- if ( empty( $bp->bp_nav ) || !is_array( $bp->bp_nav ) )
754
- return false;
755
-
756
- foreach ( (array)$bp->bp_nav as $slug => $nav_item ) {
757
- if ( empty( $temp[$nav_item['position']]) )
758
- $temp[$nav_item['position']] = $nav_item;
759
- else {
760
- // increase numbers here to fit new items in.
761
- do {
762
- $nav_item['position']++;
763
- } while ( !empty( $temp[$nav_item['position']] ) );
764
-
765
- $temp[$nav_item['position']] = $nav_item;
766
- }
767
- }
768
-
769
- ksort( $temp );
770
- $bp->bp_nav = &$temp;
771
- }
772
- add_action( 'wp_head', 'bp_core_sort_nav_items' );
773
- add_action( 'admin_head', 'bp_core_sort_nav_items' );
774
-
775
- /**
776
- * bp_core_new_subnav_item()
777
- *
778
- * Adds a navigation item to the sub navigation array used in BuddyPress themes.
779
- *
780
- * @package BuddyPress Core
781
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
782
- */
783
- function bp_core_new_subnav_item( $args = '' ) {
784
- global $bp;
785
-
786
- $defaults = array(
787
- 'name' => false, // Display name for the nav item
788
- 'slug' => false, // URL slug for the nav item
789
- 'parent_slug' => false, // URL slug of the parent nav item
790
- 'parent_url' => false, // URL of the parent item
791
- 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item
792
- 'user_has_access' => true, // Can the logged in user see this nav item?
793
- 'site_admin_only' => false, // Can only site admins see this nav item?
794
- 'position' => 90, // Index of where this nav item should be positioned
795
- 'screen_function' => false // The name of the function to run when clicked
796
- );
797
-
798
- $r = wp_parse_args( $args, $defaults );
799
- extract( $r, EXTR_SKIP );
800
-
801
- /* If we don't have the required info we need, don't create this subnav item */
802
- if ( empty($name) || empty($slug) || empty($parent_slug) || empty($parent_url) || empty($screen_function) )
803
- return false;
804
-
805
- /* If this is for site admins only and the user is not one, don't create the subnav item */
806
- if ( $site_admin_only && !is_site_admin() )
807
- return false;
808
-
809
- if ( empty( $item_css_id ) )
810
- $item_css_id = $slug;
811
-
812
- $bp->bp_options_nav[$parent_slug][$slug] = array(
813
- 'name' => $name,
814
- 'link' => $parent_url . $slug . '/',
815
- 'slug' => $slug,
816
- 'css_id' => $item_css_id,
817
- 'position' => $position,
818
- 'user_has_access' => $user_has_access
819
- );
820
-
821
- if ( ( $bp->current_action == $slug && $bp->current_component == $parent_slug ) && $user_has_access ) {
822
- if ( !is_object( $screen_function[0] ) )
823
- add_action( 'wp', $screen_function, 3 );
824
- else
825
- add_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );
826
- }
827
- }
828
-
829
- function bp_core_sort_subnav_items() {
830
- global $bp;
831
-
832
- if ( empty( $bp->bp_options_nav ) || !is_array( $bp->bp_options_nav ) )
833
- return false;
834
-
835
- foreach ( (array)$bp->bp_options_nav as $parent_slug => $subnav_items ) {
836
- if ( !is_array( $subnav_items ) )
837
- continue;
838
-
839
- foreach ( (array)$subnav_items as $subnav_item ) {
840
- if ( empty( $temp[$subnav_item['position']]) )
841
- $temp[$subnav_item['position']] = $subnav_item;
842
- else {
843
- // increase numbers here to fit new items in.
844
- do {
845
- $subnav_item['position']++;
846
- } while ( !empty( $temp[$subnav_item['position']] ) );
847
-
848
- $temp[$subnav_item['position']] = $subnav_item;
849
- }
850
- }
851
- ksort( $temp );
852
- $bp->bp_options_nav[$parent_slug] = &$temp;
853
- unset($temp);
854
- }
855
- }
856
- add_action( 'wp_head', 'bp_core_sort_subnav_items' );
857
- add_action( 'admin_head', 'bp_core_sort_subnav_items' );
858
-
859
- /**
860
- * bp_core_remove_nav_item()
861
- *
862
- * Removes a navigation item from the sub navigation array used in BuddyPress themes.
863
- *
864
- * @package BuddyPress Core
865
- * @param $parent_id The id of the parent navigation item.
866
- * @param $slug The slug of the sub navigation item.
867
- */
868
- function bp_core_remove_nav_item( $parent_id ) {
869
- global $bp;
870
-
871
- /* Unset subnav items for this nav item */
872
- if ( is_array( $bp->bp_options_nav[$parent_id] ) ) {
873
- foreach( (array)$bp->bp_options_nav[$parent_id] as $subnav_item ) {
874
- bp_core_remove_subnav_item( $parent_id, $subnav_item['slug'] );
875
- }
876
- }
877
-
878
- unset( $bp->bp_nav[$parent_id] );
879
- }
880
-
881
- /**
882
- * bp_core_remove_subnav_item()
883
- *
884
- * Removes a navigation item from the sub navigation array used in BuddyPress themes.
885
- *
886
- * @package BuddyPress Core
887
- * @param $parent_id The id of the parent navigation item.
888
- * @param $slug The slug of the sub navigation item.
889
- */
890
- function bp_core_remove_subnav_item( $parent_id, $slug ) {
891
- global $bp;
892
-
893
- $function = $bp->bp_options_nav[$parent_id][$slug]['screen_function'];
894
-
895
- if ( $function ) {
896
- if ( !is_object( $screen_function[0] ) )
897
- remove_action( 'wp', $screen_function, 3 );
898
- else
899
- remove_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );
900
- }
901
-
902
- unset( $bp->bp_options_nav[$parent_id][$slug] );
903
-
904
- if ( !count( $bp->bp_options_nav[$parent_id] ) )
905
- unset($bp->bp_options_nav[$parent_id]);
906
- }
907
-
908
- /**
909
- * bp_core_reset_subnav_items()
910
- *
911
- * Clear the subnav items for a specific nav item.
912
- *
913
- * @package BuddyPress Core
914
- * @param $parent_id The id of the parent navigation item.
915
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
916
- */
917
- function bp_core_reset_subnav_items($parent_slug) {
918
- global $bp;
919
-
920
- unset($bp->bp_options_nav[$parent_slug]);
921
- }
922
-
923
- /**
924
- * bp_core_load_template()
925
- *
926
- * Uses the bp_catch_uri function to load a specific template file with fallback support.
927
- *
928
- * Example:
929
- * bp_core_load_template( 'profile/edit-profile' );
930
- * Loads:
931
- * wp-content/themes/[activated_theme]/profile/edit-profile.php
932
- *
933
- * @package BuddyPress Core
934
- * @param $username str Username to check.
935
- * @global $wpdb WordPress DB access object.
936
- * @return false on no match
937
- * @return int the user ID of the matched user.
938
- */
939
- function bp_core_load_template( $template, $skip_blog_check = false ) {
940
- return bp_catch_uri( $template, $skip_blog_check );
941
- }
942
-
943
- /**
944
- * bp_core_add_root_component()
945
- *
946
- * Adds a component to the $bp->root_components global.
947
- * Any component that runs in the "root" of an install should be added.
948
- * The "root" as in, it can or always runs outside of the /members/username/ path.
949
- *
950
- * Example of a root component:
951
- * Groups: http://domain.com/groups/group-name
952
- * http://community.domain.com/groups/group-name
953
- * http://domain.com/wpmu/groups/group-name
954
- *
955
- * Example of a component that is NOT a root component:
956
- * Friends: http://domain.com/members/andy/friends
957
- * http://community.domain.com/members/andy/friends
958
- * http://domain.com/wpmu/members/andy/friends
959
- *
960
- * @package BuddyPress Core
961
- * @param $slug str The slug of the component
962
- * @global $bp BuddyPress global settings
963
- */
964
- function bp_core_add_root_component( $slug ) {
965
- global $bp;
966
-
967
- $bp->root_components[] = $slug;
968
- }
969
-
970
- /**
971
- * bp_core_get_random_member()
972
- *
973
- * Returns the user_id for a user based on their username.
974
- *
975
- * @package BuddyPress Core
976
- * @param $username str Username to check.
977
- * @global $wpdb WordPress DB access object.
978
- * @return false on no match
979
- * @return int the user ID of the matched user.
980
- */
981
- function bp_core_get_random_member() {
982
- global $bp, $wpdb;
983
-
984
- if ( isset( $_GET['random-member'] ) ) {
985
- $user = bp_core_get_users( array( 'type' => 'random', 'per_page' => 1 ) );
986
- bp_core_redirect( bp_core_get_user_domain( $user['users'][0]->id ) );
987
- }
988
- }
989
- add_action( 'wp', 'bp_core_get_random_member' );
990
-
991
- /**
992
- * bp_core_get_userid()
993
- *
994
- * Returns the user_id for a user based on their username.
995
- *
996
- * @package BuddyPress Core
997
- * @param $username str Username to check.
998
- * @global $wpdb WordPress DB access object.
999
- * @return false on no match
1000
- * @return int the user ID of the matched user.
1001
- */
1002
- function bp_core_get_userid( $username ) {
1003
- global $wpdb;
1004
-
1005
- if ( empty( $username ) )
1006
- return false;
1007
-
1008
- return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ) );
1009
- }
1010
-
1011
- /**
1012
- * bp_core_get_userid_from_nicename()
1013
- *
1014
- * Returns the user_id for a user based on their user_nicename.
1015
- *
1016
- * @package BuddyPress Core
1017
- * @param $username str Username to check.
1018
- * @global $wpdb WordPress DB access object.
1019
- * @return false on no match
1020
- * @return int the user ID of the matched user.
1021
- */
1022
- function bp_core_get_userid_from_nicename( $user_nicename ) {
1023
- global $wpdb;
1024
-
1025
- if ( empty( $user_nicename ) )
1026
- return false;
1027
-
1028
- 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 ) ) );
1029
- }
1030
-
1031
- /**
1032
- * bp_core_get_username()
1033
- *
1034
- * Returns the username for a user based on their user id.
1035
- *
1036
- * @package BuddyPress Core
1037
- * @param $uid int User ID to check.
1038
- * @global $userdata WordPress user data for the current logged in user.
1039
- * @uses get_userdata() WordPress function to fetch the userdata for a user ID
1040
- * @return false on no match
1041
- * @return str the username of the matched user.
1042
- */
1043
- function bp_core_get_username( $user_id, $user_nicename = false, $user_login = false ) {
1044
- global $bp;
1045
-
1046
- if ( !$username = wp_cache_get( 'bp_user_username_' . $user_id, 'bp' ) ) {
1047
- if ( empty( $user_nicename ) && empty( $user_login ) ) {
1048
- $ud = false;
1049
-
1050
- if ( $bp->loggedin_user->id == $user_id )
1051
- $ud = &$bp->loggedin_user->userdata;
1052
-
1053
- if ( $bp->displayed_user->id == $user_id )
1054
- $ud = &$bp->displayed_user->userdata;
1055
-
1056
- if ( empty( $ud ) ) {
1057
- if ( !$ud = bp_core_get_core_userdata( $user_id ) )
1058
- return false;
1059
- }
1060
-
1061
- $user_nicename = $ud->user_nicename;
1062
- $user_login = $ud->user_login;
1063
- }
1064
-
1065
- if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
1066
- $username = $user_login;
1067
- else
1068
- $username = $user_nicename;
1069
- }
1070
-
1071
- /* Add this to cache */
1072
- if ( !empty( $username ) )
1073
- wp_cache_set( 'bp_user_username_' . $user_id, $username, 'bp' );
1074
-
1075
- return apply_filters( 'bp_core_get_username', $username );
1076
- }
1077
-
1078
- /**
1079
- * bp_core_get_user_email()
1080
- *
1081
- * Returns the email address for the user based on user ID
1082
- *
1083
- * @package BuddyPress Core
1084
- * @param $uid int User ID to check.
1085
- * @uses get_userdata() WordPress function to fetch the userdata for a user ID
1086
- * @return false on no match
1087
- * @return str The email for the matched user.
1088
- */
1089
- function bp_core_get_user_email( $uid ) {
1090
- if ( !$email = wp_cache_get( 'bp_user_email_' . $uid, 'bp' ) ) {
1091
- $ud = bp_core_get_core_userdata($uid);
1092
- $email = $ud->user_email;
1093
- wp_cache_set( 'bp_user_email_' . $uid, $email, 'bp' );
1094
- }
1095
-
1096
- return apply_filters( 'bp_core_get_user_email', $email );
1097
- }
1098
-
1099
- /**
1100
- * bp_core_get_userlink()
1101
- *
1102
- * Returns a HTML formatted link for a user with the user's full name as the link text.
1103
- * eg: <a href="http://andy.domain.com/">Andy Peatling</a>
1104
- * Optional parameters will return just the name, or just the URL, or disable "You" text when
1105
- * user matches the logged in user.
1106
- *
1107
- * [NOTES: This function needs to be cleaned up or split into separate functions]
1108
- *
1109
- * @package BuddyPress Core
1110
- * @param $uid int User ID to check.
1111
- * @param $no_anchor bool Disable URL and HTML and just return full name. Default false.
1112
- * @param $just_link bool Disable full name and HTML and just return the URL text. Default false.
1113
- * @param $no_you bool Disable replacing full name with "You" when logged in user is equal to the current user. Default false.
1114
- * @global $userdata WordPress user data for the current logged in user.
1115
- * @uses get_userdata() WordPress function to fetch the userdata for a user ID
1116
- * @uses bp_fetch_user_fullname() Returns the full name for a user based on user ID.
1117
- * @uses bp_core_get_userurl() Returns the URL for the user with no anchor tag based on user ID
1118
- * @return false on no match
1119
- * @return str The link text based on passed parameters.
1120
- */
1121
- function bp_core_get_userlink( $user_id, $no_anchor = false, $just_link = false ) {
1122
- $display_name = bp_core_get_user_displayname( $user_id );
1123
-
1124
- if ( empty( $display_name ) )
1125
- return false;
1126
-
1127
- if ( $no_anchor )
1128
- return $display_name;
1129
-
1130
- if ( !$url = bp_core_get_user_domain($user_id) )
1131
- return false;
1132
-
1133
- if ( $just_link )
1134
- return $url;
1135
-
1136
- return apply_filters( 'bp_core_get_userlink', '<a href="' . $url . '" title="' . $display_name . '">' . $display_name . '</a>', $user_id );
1137
- }
1138
-
1139
-
1140
- /**
1141
- * bp_core_get_user_displayname()
1142
- *
1143
- * Fetch the display name for a user. This will use the "Name" field in xprofile if it is installed.
1144
- * Otherwise, it will fall back to the normal WP display_name, or user_nicename, depending on what has been set.
1145
- *
1146
- * @package BuddyPress Core
1147
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
1148
- * @uses wp_cache_get() Will try and fetch the value from the cache, rather than querying the DB again.
1149
- * @uses get_userdata() Fetches the WP userdata for a specific user.
1150
- * @uses xprofile_set_field_data() Will update the field data for a user based on field name and user id.
1151
- * @uses wp_cache_set() Adds a value to the cache.
1152
- * @return str The display name for the user in question.
1153
- */
1154
- function bp_core_get_user_displayname( $user_id_or_username ) {
1155
- global $bp;
1156
-
1157
- if ( !$user_id_or_username )
1158
- return false;
1159
-
1160
- if ( !is_numeric( $user_id_or_username ) )
1161
- $user_id = bp_core_get_userid( $user_id_or_username );
1162
- else
1163
- $user_id = $user_id_or_username;
1164
-
1165
- if ( !$user_id )
1166
- return false;
1167
-
1168
- if ( !$fullname = wp_cache_get( 'bp_user_fullname_' . $user_id, 'bp' ) ) {
1169
- if ( function_exists('xprofile_install') ) {
1170
- $fullname = xprofile_get_field_data( 1, $user_id );
1171
-
1172
- if ( empty($fullname) ) {
1173
- $ud = bp_core_get_core_userdata( $user_id );
1174
-
1175
- if ( !empty( $ud->display_name ) )
1176
- $fullname = $ud->display_name;
1177
- else
1178
- $fullname = $ud->user_nicename;
1179
-
1180
- xprofile_set_field_data( 1, $user_id, $fullname );
1181
- }
1182
- } else {
1183
- $ud = bp_core_get_core_userdata($user_id);
1184
-
1185
- if ( !empty( $ud->display_name ) )
1186
- $fullname = $ud->display_name;
1187
- else
1188
- $fullname = $ud->user_nicename;
1189
- }
1190
-
1191
- if ( !empty( $fullname ) )
1192
- wp_cache_set( 'bp_user_fullname_' . $user_id, $fullname, 'bp' );
1193
- }
1194
-
1195
- return apply_filters( 'bp_core_get_user_displayname', $fullname, $user_id );
1196
- }
1197
- add_filter( 'bp_core_get_user_displayname', 'strip_tags', 1 );
1198
- add_filter( 'bp_core_get_user_displayname', 'trim' );
1199
- add_filter( 'bp_core_get_user_displayname', 'stripslashes' );
1200
-
1201
-
1202
- /**
1203
- * bp_core_get_userlink_by_email()
1204
- *
1205
- * Returns the user link for the user based on user email address
1206
- *
1207
- * @package BuddyPress Core
1208
- * @param $email str The email address for the user.
1209
- * @uses bp_core_get_userlink() BuddyPress function to get a userlink by user ID.
1210
- * @uses get_user_by_email() WordPress function to get userdata via an email address
1211
- * @return str The link to the users home base. False on no match.
1212
- */
1213
- function bp_core_get_userlink_by_email( $email ) {
1214
- $user = get_user_by_email( $email );
1215
- return apply_filters( 'bp_core_get_userlink_by_email', bp_core_get_userlink( $user->ID, false, false, true ) );
1216
- }
1217
-
1218
- /**
1219
- * bp_core_get_userlink_by_username()
1220
- *
1221
- * Returns the user link for the user based on user's username
1222
- *
1223
- * @package BuddyPress Core
1224
- * @param $username str The username for the user.
1225
- * @uses bp_core_get_userlink() BuddyPress function to get a userlink by user ID.
1226
- * @return str The link to the users home base. False on no match.
1227
- */
1228
- function bp_core_get_userlink_by_username( $username ) {
1229
- global $wpdb;
1230
-
1231
- $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) );
1232
- return apply_filters( 'bp_core_get_userlink_by_username', bp_core_get_userlink( $user_id, false, false, true ) );
1233
- }
1234
-
1235
- /**
1236
- * bp_core_get_total_member_count()
1237
- *
1238
- * Returns the total number of members for the installation.
1239
- *
1240
- * @package BuddyPress Core
1241
- * @return int The total number of members.
1242
- */
1243
- function bp_core_get_total_member_count() {
1244
- global $wpdb, $bp;
1245
-
1246
- if ( !$count = wp_cache_get( 'bp_total_member_count', 'bp' ) ) {
1247
- $status_sql = bp_core_get_status_sql();
1248
- $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM " . CUSTOM_USER_TABLE . " WHERE {$status_sql}" ) );
1249
- wp_cache_set( 'bp_total_member_count', $count, 'bp' );
1250
- }
1251
-
1252
- return apply_filters( 'bp_core_get_total_member_count', $count );
1253
- }
1254
-
1255
- /**
1256
- * bp_core_is_user_spammer()
1257
- *
1258
- * Checks if the user has been marked as a spammer.
1259
- *
1260
- * @package BuddyPress Core
1261
- * @param $user_id int The id for the user.
1262
- * @return int 1 if spammer, 0 if not.
1263
- */
1264
- function bp_core_is_user_spammer( $user_id ) {
1265
- global $wpdb;
1266
-
1267
- if ( bp_core_is_multisite() )
1268
- $is_spammer = (int) $wpdb->get_var( $wpdb->prepare( "SELECT spam FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) );
1269
- else
1270
- $is_spammer = (int) $wpdb->get_var( $wpdb->prepare( "SELECT user_status FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) );
1271
-
1272
- return apply_filters( 'bp_core_is_user_spammer', $is_spammer );
1273
- }
1274
-
1275
- /**
1276
- * bp_core_is_user_deleted()
1277
- *
1278
- * Checks if the user has been marked as deleted.
1279
- *
1280
- * @package BuddyPress Core
1281
- * @param $user_id int The id for the user.
1282
- * @return int 1 if deleted, 0 if not.
1283
- */
1284
- function bp_core_is_user_deleted( $user_id ) {
1285
- global $wpdb;
1286
-
1287
- 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 ) ) );
1288
- }
1289
-
1290
- /**
1291
- * bp_core_format_time()
1292
- */
1293
- function bp_core_format_time( $time, $just_date = false ) {
1294
- if ( !$time )
1295
- return false;
1296
-
1297
- $date = date( "F j, Y ", $time );
1298
-
1299
- if ( !$just_date ) {
1300
- $date .= __('at', 'buddypress') . date( ' g:iA', $time );
1301
- }
1302
-
1303
- return $date;
1304
- }
1305
-
1306
- /**
1307
- * bp_core_add_message()
1308
- *
1309
- * Adds a feedback (error/success) message to the WP cookie so it can be displayed after the page reloads.
1310
- *
1311
- * @package BuddyPress Core
1312
- */
1313
- function bp_core_add_message( $message, $type = false ) {
1314
- global $bp;
1315
-
1316
- if ( !$type )
1317
- $type = 'success';
1318
-
1319
- /* Send the values to the cookie for page reload display */
1320
- @setcookie( 'bp-message', $message, time()+60*60*24, COOKIEPATH );
1321
- @setcookie( 'bp-message-type', $type, time()+60*60*24, COOKIEPATH );
1322
-
1323
- /***
1324
- * Send the values to the $bp global so we can still output messages
1325
- * without a page reload
1326
- */
1327
- $bp->template_message = $message;
1328
- $bp->template_message_type = $type;
1329
- }
1330
-
1331
- /**
1332
- * bp_core_setup_message()
1333
- *
1334
- * Checks if there is a feedback message in the WP cookie, if so, adds a "template_notices" action
1335
- * so that the message can be parsed into the template and displayed to the user.
1336
- *
1337
- * After the message is displayed, it removes the message vars from the cookie so that the message
1338
- * is not shown to the user multiple times.
1339
- *
1340
- * @package BuddyPress Core
1341
- * @global $bp_message The message text
1342
- * @global $bp_message_type The type of message (error/success)
1343
- * @uses setcookie() Sets a cookie value for the user.
1344
- */
1345
- function bp_core_setup_message() {
1346
- global $bp;
1347
-
1348
- if ( empty( $bp->template_message ) )
1349
- $bp->template_message = $_COOKIE['bp-message'];
1350
-
1351
- if ( empty( $bp->template_message_type ) )
1352
- $bp->template_message_type = $_COOKIE['bp-message-type'];
1353
-
1354
- add_action( 'template_notices', 'bp_core_render_message' );
1355
-
1356
- @setcookie( 'bp-message', false, time() - 1000, COOKIEPATH );
1357
- @setcookie( 'bp-message-type', false, time() - 1000, COOKIEPATH );
1358
- }
1359
- add_action( 'wp', 'bp_core_setup_message', 2 );
1360
-
1361
- /**
1362
- * bp_core_render_message()
1363
- *
1364
- * Renders a feedback message (either error or success message) to the theme template.
1365
- * The hook action 'template_notices' is used to call this function, it is not called directly.
1366
- *
1367
- * @package BuddyPress Core
1368
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
1369
- */
1370
- function bp_core_render_message() {
1371
- global $bp;
1372
-
1373
- if ( $bp->template_message ) {
1374
- $type = ( 'success' == $bp->template_message_type ) ? 'updated' : 'error';
1375
- ?>
1376
- <div id="message" class="<?php echo $type; ?>">
1377
- <p><?php echo stripslashes( attribute_escape( $bp->template_message ) ); ?></p>
1378
- </div>
1379
- <?php
1380
- do_action( 'bp_core_render_message' );
1381
- }
1382
- }
1383
-
1384
- /**
1385
- * bp_core_time_since()
1386
- *
1387
- * Based on function created by Dunstan Orchard - http://1976design.com
1388
- *
1389
- * This function will return an English representation of the time elapsed
1390
- * since a given date.
1391
- * eg: 2 hours and 50 minutes
1392
- * eg: 4 days
1393
- * eg: 4 weeks and 6 days
1394
- *
1395
- * @package BuddyPress Core
1396
- * @param $older_date int Unix timestamp of date you want to calculate the time since for
1397
- * @param $newer_date int Unix timestamp of date to compare older date to. Default false (current time).
1398
- * @return str The time since.
1399
- */
1400
- function bp_core_time_since( $older_date, $newer_date = false ) {
1401
- // array of time period chunks
1402
-
1403
- $chunks = array(
1404
- array( 60 * 60 * 24 * 365 , __( 'year', 'buddypress' ), __( 'years', 'buddypress' ) ),
1405
- array( 60 * 60 * 24 * 30 , __( 'month', 'buddypress' ), __( 'months', 'buddypress' ) ),
1406
- array( 60 * 60 * 24 * 7, __( 'week', 'buddypress' ), __( 'weeks', 'buddypress' ) ),
1407
- array( 60 * 60 * 24 , __( 'day', 'buddypress' ), __( 'days', 'buddypress' ) ),
1408
- array( 60 * 60 , __( 'hour', 'buddypress' ), __( 'hours', 'buddypress' ) ),
1409
- array( 60 , __( 'minute', 'buddypress' ), __( 'minutes', 'buddypress' ) ),
1410
- array( 1, __( 'second', 'buddypress' ), __( 'seconds', 'buddypress' ) )
1411
- );
1412
-
1413
- if ( !is_numeric( $older_date ) ) {
1414
- $time_chunks = explode( ':', str_replace( ' ', ':', $older_date ) );
1415
- $date_chunks = explode( '-', str_replace( ' ', '-', $older_date ) );
1416
-
1417
- $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] );
1418
- }
1419
-
1420
- /* $newer_date will equal false if we want to know the time elapsed between a date and the current time */
1421
- /* $newer_date will have a value if we want to work out time elapsed between two known dates */
1422
- $newer_date = ( !$newer_date ) ? gmmktime( gmdate( 'H' ), gmdate( 'i' ), gmdate( 's' ), gmdate( 'n' ), gmdate( 'j' ), gmdate( 'Y' ) ) : $newer_date;
1423
-
1424
- /* Difference in seconds */
1425
- $since = $newer_date - $older_date;
1426
-
1427
- /* Something went wrong with date calculation and we ended up with a negative date. */
1428
- if ( 0 > $since )
1429
- return __( 'sometime', 'buddypress' );
1430
-
1431
- /**
1432
- * We only want to output two chunks of time here, eg:
1433
- * x years, xx months
1434
- * x days, xx hours
1435
- * so there's only two bits of calculation below:
1436
- */
1437
-
1438
- /* Step one: the first chunk */
1439
- for ( $i = 0, $j = count($chunks); $i < $j; $i++) {
1440
- $seconds = $chunks[$i][0];
1441
-
1442
- /* Finding the biggest chunk (if the chunk fits, break) */
1443
- if ( ( $count = floor($since / $seconds) ) != 0 )
1444
- break;
1445
- }
1446
-
1447
- /* Set output var */
1448
- $output = ( 1 == $count ) ? '1 '. $chunks[$i][1] : $count . ' ' . $chunks[$i][2];
1449
-
1450
- /* Step two: the second chunk */
1451
- if ( $i + 2 < $j ) {
1452
- $seconds2 = $chunks[$i + 1][0];
1453
- $name2 = $chunks[$i + 1][1];
1454
-
1455
- if ( ( $count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 ) ) != 0 ) {
1456
- /* Add to output var */
1457
- $output .= ( 1 == $count2 ) ? _c( ',|Separator in time since', 'buddypress' ) . ' 1 '. $chunks[$i + 1][1] : _c( ',|Separator in time since', 'buddypress' ) . ' ' . $count2 . ' ' . $chunks[$i + 1][2];
1458
- }
1459
- }
1460
-
1461
- if ( !(int)trim($output) )
1462
- $output = '0 ' . __( 'seconds', 'buddypress' );
1463
-
1464
- return $output;
1465
- }
1466
-
1467
-
1468
- /**
1469
- * bp_core_record_activity()
1470
- *
1471
- * Record user activity to the database. Many functions use a "last active" feature to
1472
- * show the length of time since the user was last active.
1473
- * This function will update that time as a usermeta setting for the user every 5 minutes.
1474
- *
1475
- * @package BuddyPress Core
1476
- * @global $userdata WordPress user data for the current logged in user.
1477
- * @uses update_usermeta() WordPress function to update user metadata in the usermeta table.
1478
- */
1479
- function bp_core_record_activity() {
1480
- global $bp;
1481
-
1482
- if ( !is_user_logged_in() )
1483
- return false;
1484
-
1485
- $activity = get_usermeta( $bp->loggedin_user->id, 'last_activity' );
1486
-
1487
- if ( !is_numeric( $activity ) )
1488
- $activity = strtotime( $activity );
1489
-
1490
- if ( '' == $activity || strtotime( gmdate( "Y-m-d H:i:s" ) ) >= strtotime( '+5 minutes', $activity ) )
1491
- update_usermeta( $bp->loggedin_user->id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
1492
- }
1493
- add_action( 'wp_head', 'bp_core_record_activity' );
1494
-
1495
-
1496
- /**
1497
- * bp_core_get_last_activity()
1498
- *
1499
- * Formats last activity based on time since date given.
1500
- *
1501
- * @package BuddyPress Core
1502
- * @param last_activity_date The date of last activity.
1503
- * @param $before The text to prepend to the activity time since figure.
1504
- * @param $after The text to append to the activity time since figure.
1505
- * @uses bp_core_time_since() This function will return an English representation of the time elapsed.
1506
- */
1507
- function bp_core_get_last_activity( $last_activity_date, $string ) {
1508
- if ( !$last_activity_date || empty( $last_activity_date ) ) {
1509
- $last_active = __( 'not recently active', 'buddypress' );
1510
- } else {
1511
- $last_active = sprintf( $string, bp_core_time_since( $last_activity_date ) );
1512
- }
1513
-
1514
- return apply_filters( 'bp_core_get_last_activity', $last_active, $last_activity_date, $string );
1515
- }
1516
-
1517
- function bp_core_number_format( $number, $decimals = false ) {
1518
- /* Check we actually have a number first. */
1519
- if ( empty( $number ) )
1520
- return $number;
1521
-
1522
- return apply_filters( 'bp_core_number_format', number_format( $number, $decimals ), $number, $decimals );
1523
- }
1524
-
1525
- /**
1526
- * bp_core_get_all_posts_for_user()
1527
- *
1528
- * Fetch every post that is authored by the given user for the current blog.
1529
- *
1530
- * @package BuddyPress Core
1531
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
1532
- * @global $wpdb WordPress user data for the current logged in user.
1533
- * @return array of post ids.
1534
- */
1535
- function bp_core_get_all_posts_for_user( $user_id = null ) {
1536
- global $bp, $wpdb;
1537
-
1538
- if ( !$user_id )
1539
- $user_id = $bp->displayed_user->id;
1540
-
1541
- 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 ) ) );
1542
- }
1543
-
1544
- /**
1545
- * bp_core_get_site_path()
1546
- *
1547
- * Get the path of of the current site.
1548
- *
1549
- * @package BuddyPress Core
1550
- * @global $comment WordPress comment global for the current comment.
1551
- * @uses bp_core_get_userlink_by_email() Fetches a userlink via email address.
1552
- */
1553
- function bp_core_get_site_path() {
1554
- global $bp, $current_site;
1555
-
1556
- if ( bp_core_is_multisite() )
1557
- $site_path = $current_site->path;
1558
- else {
1559
- $site_path = (array) explode( '/', site_url() );
1560
-
1561
- if ( count( $site_path ) < 2 )
1562
- $site_path = '/';
1563
- else {
1564
- /* Unset the first three segments (http(s)://domain.com part) */
1565
- unset( $site_path[0] );
1566
- unset( $site_path[1] );
1567
- unset( $site_path[2] );
1568
-
1569
- if ( !count( $site_path ) )
1570
- $site_path = '/';
1571
- else
1572
- $site_path = '/' . implode( '/', $site_path ) . '/';
1573
- }
1574
- }
1575
-
1576
- return apply_filters( 'bp_core_get_site_path', $site_path );
1577
- }
1578
- /**
1579
- * bp_core_get_site_options()
1580
- *
1581
- * BuddyPress uses site options to store configuration settings. Many of these settings are needed
1582
- * at run time. Instead of fetching them all and adding many initial queries to each page load, let's fetch
1583
- * them all in one go.
1584
- *
1585
- * @package BuddyPress Core
1586
- */
1587
- function bp_core_get_site_options() {
1588
- global $bp, $wpdb;
1589
-
1590
- $options = apply_filters( 'bp_core_site_options', array(
1591
- 'bp-deactivated-components',
1592
- 'bp-blogs-first-install',
1593
- 'bp-disable-blog-forum-comments',
1594
- 'bp-xprofile-base-group-name',
1595
- 'bp-xprofile-fullname-field-name',
1596
- 'bp-disable-profile-sync',
1597
- 'bp-disable-avatar-uploads',
1598
- 'bp-disable-account-deletion',
1599
- 'bp-disable-forum-directory',
1600
- 'bp-disable-blogforum-comments',
1601
- 'bb-config-location',
1602
- 'hide-loggedout-adminbar',
1603
-
1604
- /* Useful WordPress settings used often */
1605
- 'user-avatar-default',
1606
- 'tags_blog_id',
1607
- 'registration',
1608
- 'fileupload_maxk'
1609
- ) );
1610
-
1611
- $meta_keys = "'" . implode( "','", (array)$options ) ."'";
1612
-
1613
- if ( bp_core_is_multisite() )
1614
- $meta = $wpdb->get_results( "SELECT meta_key AS name, meta_value AS value FROM {$wpdb->sitemeta} WHERE meta_key IN ({$meta_keys})" );
1615
- else
1616
- $meta = $wpdb->get_results( "SELECT option_name AS name, option_value AS value FROM {$wpdb->options} WHERE option_name IN ({$meta_keys})" );
1617
-
1618
- $site_options = array();
1619
- if ( !empty( $meta ) ) {
1620
- foreach( (array)$meta as $meta_item )
1621
- $site_options[$meta_item->name] = $meta_item->value;
1622
- }
1623
-
1624
- return apply_filters( 'bp_core_get_site_options', $site_options );
1625
- }
1626
-
1627
- /**
1628
- * bp_core_redirect()
1629
- *
1630
- * Performs a status safe wp_redirect() that is compatible with bp_catch_uri()
1631
- *
1632
- * @package BuddyPress Core
1633
- * @global $bp_no_status_set Makes sure that there are no conflicts with status_header() called in bp_core_do_catch_uri()
1634
- * @uses get_themes()
1635
- * @return An array containing all of the themes.
1636
- */
1637
- function bp_core_redirect( $location, $status = 302 ) {
1638
- global $bp_no_status_set;
1639
-
1640
- // Make sure we don't call status_header() in bp_core_do_catch_uri()
1641
- // as this conflicts with wp_redirect()
1642
- $bp_no_status_set = true;
1643
-
1644
- wp_redirect( $location, $status );
1645
- die;
1646
- }
1647
-
1648
- /**
1649
- * bp_core_referrer()
1650
- *
1651
- * Returns the referrer URL without the http(s)://
1652
- *
1653
- * @package BuddyPress Core
1654
- * @return The referrer URL
1655
- */
1656
- function bp_core_referrer() {
1657
- $referer = explode( '/', wp_get_referer() );
1658
- unset( $referer[0], $referer[1], $referer[2] );
1659
- return implode( '/', $referer );
1660
- }
1661
-
1662
- /**
1663
- * bp_core_add_illegal_names()
1664
- *
1665
- * Adds illegal names to WP so that root components will not conflict with
1666
- * blog names on a subdirectory installation.
1667
- *
1668
- * For example, it would stop someone creating a blog with the slug "groups".
1669
- *
1670
- * @package BuddyPress Core
1671
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
1672
- */
1673
- function bp_core_add_illegal_names() {
1674
- global $bp;
1675
-
1676
- $current = maybe_unserialize( get_site_option( 'illegal_names' ) );
1677
- $bp_illegal_names = $bp->root_components;
1678
-
1679
- if ( is_array( $current ) ) {
1680
- foreach( (array)$bp_illegal_names as $bp_illegal_name ) {
1681
- if ( !in_array( $bp_illegal_name, $current ) )
1682
- $current[] = $bp_illegal_name;
1683
- }
1684
- $new = $current;
1685
- } else {
1686
- $bp_illegal_names[] = $current;
1687
- $new = $bp_illegal_names;
1688
- }
1689
-
1690
- update_site_option( 'illegal_names', $new );
1691
- }
1692
-
1693
- /**
1694
- * bp_core_delete_account()
1695
- *
1696
- * Allows a user to completely remove their account from the system
1697
- *
1698
- * @package BuddyPress Core
1699
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
1700
- * @uses is_site_admin() Checks to see if the user is a site administrator.
1701
- * @uses wpmu_delete_user() Deletes a user from the system on multisite installs.
1702
- * @uses wp_delete_user() Deletes a user from the system on singlesite installs.
1703
- * @uses get_site_option Checks if account deletion is allowed
1704
- */
1705
- function bp_core_delete_account( $user_id = false ) {
1706
- global $bp, $wpdb, $wp_version;
1707
-
1708
- if ( !$user_id )
1709
- $user_id = $bp->loggedin_user->id;
1710
-
1711
- /* Make sure account deletion is not disabled */
1712
- if ( (int)get_site_option( 'bp-disable-account-deletion' ) )
1713
- return false;
1714
-
1715
- /* Specifically handle multi-site environment */
1716
- if ( bp_core_is_multisite() ) {
1717
- /* Site admins cannot be deleted */
1718
- if ( is_site_admin( bp_core_get_username( $user_id ) ) )
1719
- return false;
1720
-
1721
- if ( $wp_version >= '3.0' )
1722
- require_once( ABSPATH . '/wp-admin/includes/ms.php' );
1723
- else
1724
- require_once( ABSPATH . '/wp-admin/includes/mu.php' );
1725
-
1726
- require_once( ABSPATH . '/wp-admin/includes/user.php' );
1727
-
1728
- return wpmu_delete_user( $user_id );
1729
- }
1730
-
1731
- /* Single site user deletion */
1732
- require_once( ABSPATH . '/wp-admin/includes/user.php' );
1733
- return wp_delete_user( $user_id );
1734
- }
1735
-
1736
-
1737
- /**
1738
- * bp_core_search_site()
1739
- *
1740
- * A javascript free implementation of the search functions in BuddyPress
1741
- *
1742
- * @package BuddyPress Core
1743
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
1744
- * @param $slug The slug to redirect to for searching.
1745
- */
1746
- function bp_core_action_search_site( $slug = false ) {
1747
- global $bp;
1748
-
1749
- if ( $bp->current_component == BP_SEARCH_SLUG ) {
1750
- $search_terms = $_POST['search-terms'];
1751
- $search_which = $_POST['search-which'];
1752
-
1753
- if ( !$slug || empty( $slug ) ) {
1754
- switch ( $search_which ) {
1755
- case 'members': default:
1756
- $slug = BP_MEMBERS_SLUG;
1757
- $var = '/?s=';
1758
- break;
1759
- case 'groups':
1760
- $slug = BP_GROUPS_SLUG;
1761
- $var = '/?s=';
1762
- break;
1763
- case 'forums':
1764
- $slug = BP_FORUMS_SLUG;
1765
- $var = '/?fs=';
1766
- break;
1767
- case 'blogs':
1768
- $slug = BP_BLOGS_SLUG;
1769
- $var = '/?s=';
1770
- break;
1771
- }
1772
- }
1773
-
1774
- $search_url = apply_filters( 'bp_core_search_site', site_url( $slug . $var . urlencode($search_terms) ), $search_terms );
1775
-
1776
- bp_core_redirect( $search_url );
1777
- }
1778
- }
1779
- add_action( 'init', 'bp_core_action_search_site', 5 );
1780
-
1781
-
1782
- /**
1783
- * bp_core_ucfirst()
1784
- *
1785
- * Localization safe ucfirst() support.
1786
- *
1787
- * @package BuddyPress Core
1788
- */
1789
- function bp_core_ucfirst( $str ) {
1790
- if ( function_exists( 'mb_strtoupper' ) && function_exists( 'mb_substr' ) ) {
1791
- $fc = mb_strtoupper( mb_substr( $str, 0, 1 ) );
1792
- return $fc.mb_substr( $str, 1 );
1793
- } else {
1794
- return ucfirst( $str );
1795
- }
1796
- }
1797
-
1798
-
1799
- /**
1800
- * bp_core_strip_username_spaces()
1801
- *
1802
- * Strips spaces from usernames that are created using add_user() and wp_insert_user()
1803
- *
1804
- * @package BuddyPress Core
1805
- */
1806
- function bp_core_strip_username_spaces( $username ) {
1807
- return str_replace( ' ', '-', $username );
1808
- }
1809
- add_action( 'pre_user_login', 'bp_core_strip_username_spaces' );
1810
-
1811
-
1812
- /**
1813
- * bp_core_clear_cache()
1814
- * REQUIRES WP-SUPER-CACHE
1815
- *
1816
- * When wp-super-cache is installed this function will clear cached pages
1817
- * so that success/error messages are not cached, or time sensitive content.
1818
- *
1819
- * @package BuddyPress Core
1820
- */
1821
- function bp_core_clear_cache() {
1822
- global $cache_path, $cache_filename;
1823
-
1824
- if ( function_exists( 'prune_super_cache' ) ) {
1825
- do_action( 'bp_core_clear_cache' );
1826
-
1827
- return prune_super_cache( $cache_path, true );
1828
- }
1829
- }
1830
-
1831
- /**
1832
- * bp_core_print_generation_time()
1833
- *
1834
- * Prints the generation time in the footer of the site.
1835
- *
1836
- * @package BuddyPress Core
1837
- */
1838
- function bp_core_print_generation_time() {
1839
- global $wpdb;
1840
- ?>
1841
-
1842
- <!-- Generated in <?php timer_stop(1); ?> seconds. -->
1843
-
1844
- <?php
1845
- }
1846
- add_action( 'wp_footer', 'bp_core_print_generation_time' );
1847
-
1848
- /**
1849
- * bp_core_add_admin_menu_page()
1850
- *
1851
- * A better version of add_admin_menu_page() that allows positioning of menus.
1852
- *
1853
- * @package BuddyPress Core
1854
- */
1855
- function bp_core_add_admin_menu_page( $args = '' ) {
1856
- global $menu, $admin_page_hooks, $_registered_pages;
1857
-
1858
- $defaults = array(
1859
- 'page_title' => '',
1860
- 'menu_title' => '',
1861
- 'access_level' => 2,
1862
- 'file' => false,
1863
- 'function' => false,
1864
- 'icon_url' => false,
1865
- 'position' => 100
1866
- );
1867
-
1868
- $r = wp_parse_args( $args, $defaults );
1869
- extract( $r, EXTR_SKIP );
1870
-
1871
- $file = plugin_basename( $file );
1872
-
1873
- $admin_page_hooks[$file] = sanitize_title( $menu_title );
1874
-
1875
- $hookname = get_plugin_page_hookname( $file, '' );
1876
- if (!empty ( $function ) && !empty ( $hookname ))
1877
- add_action( $hookname, $function );
1878
-
1879
- if ( empty($icon_url) )
1880
- $icon_url = 'images/generic.png';
1881
- elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') )
1882
- $icon_url = 'https://' . substr($icon_url, 7);
1883
-
1884
- do {
1885
- $position++;
1886
- } while ( !empty( $menu[$position] ) );
1887
-
1888
- $menu[$position] = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url );
1889
-
1890
- $_registered_pages[$hookname] = true;
1891
-
1892
- return $hookname;
1893
- }
1894
-
1895
- /**
1896
- * bp_core_boot_spammer()
1897
- *
1898
- * When a user logs in, check if they have been marked as a spammer. If yes then simply
1899
- * redirect them to the home page and stop them from logging in.
1900
- *
1901
- * @package BuddyPress Core
1902
- * @param $auth_obj The WP authorization object
1903
- * @param $username The username of the user logging in.
1904
- * @uses get_userdatabylogin() Get the userdata object for a user based on their username
1905
- * @uses bp_core_redirect() Safe redirect to a page
1906
- * @return $auth_obj If the user is not a spammer, return the authorization object
1907
- */
1908
- function bp_core_boot_spammer( $auth_obj, $username ) {
1909
- global $bp;
1910
-
1911
- $user = get_userdatabylogin( $username );
1912
-
1913
- if ( ( bp_core_is_multisite() && (int)$user->spam ) || 1 == (int)$user->user_status )
1914
- bp_core_redirect( $bp->root_domain );
1915
- else
1916
- return $auth_obj;
1917
- }
1918
- add_filter( 'authenticate', 'bp_core_boot_spammer', 11, 2 );
1919
-
1920
- /**
1921
- * bp_core_remove_data()
1922
- *
1923
- * Deletes usermeta for the user when the user is deleted.
1924
- *
1925
- * @package BuddyPress Core
1926
- * @param $user_id The user id for the user to delete usermeta for
1927
- * @uses delete_usermeta() deletes a row from the wp_usermeta table based on meta_key
1928
- */
1929
- function bp_core_remove_data( $user_id ) {
1930
- /* Remove usermeta */
1931
- delete_usermeta( $user_id, 'last_activity' );
1932
-
1933
- /* Flush the cache to remove the user from all cached objects */
1934
- wp_cache_flush();
1935
- }
1936
- add_action( 'wpmu_delete_user', 'bp_core_remove_data' );
1937
- add_action( 'delete_user', 'bp_core_remove_data' );
1938
- add_action( 'make_spam_user', 'bp_core_remove_data' );
1939
-
1940
- /**
1941
- * bp_load_buddypress_textdomain()
1942
- *
1943
- * Load the buddypress translation file for current language
1944
- *
1945
- * @package BuddyPress Core
1946
- */
1947
- function bp_core_load_buddypress_textdomain() {
1948
- $locale = apply_filters( 'buddypress_locale', get_locale() );
1949
- $mofile = BP_PLUGIN_DIR . "/bp-languages/buddypress-$locale.mo";
1950
-
1951
- if ( file_exists( $mofile ) )
1952
- load_textdomain( 'buddypress', $mofile );
1953
- }
1954
- add_action ( 'plugins_loaded', 'bp_core_load_buddypress_textdomain', 5 );
1955
-
1956
- function bp_core_add_ajax_hook() {
1957
- /* Theme only, we already have the wp_ajax_ hook firing in wp-admin */
1958
- if ( !defined( 'WP_ADMIN' ) )
1959
- do_action( 'wp_ajax_' . $_REQUEST['action'] );
1960
- }
1961
- add_action( 'init', 'bp_core_add_ajax_hook' );
1962
-
1963
- /**
1964
- * bp_core_update_message()
1965
- *
1966
- * Add an extra update message to the update plugin notification.
1967
- *
1968
- * @package BuddyPress Core
1969
- */
1970
- function bp_core_update_message() {
1971
- 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>';
1972
- }
1973
- add_action( 'in_plugin_update_message-buddypress/bp-loader.php', 'bp_core_update_message' );
1974
-
1975
- /**
1976
- * bp_core_activation_notice()
1977
- *
1978
- * When BuddyPress is activated we must make sure that mod_rewrite is enabled.
1979
- * We must also make sure a BuddyPress compatible theme is enabled. This function
1980
- * will show helpful messages to the administrator.
1981
- *
1982
- * @package BuddyPress Core
1983
- */
1984
- function bp_core_activation_notice() {
1985
- global $wp_rewrite, $current_blog, $bp;
1986
-
1987
- if ( isset( $_POST['permalink_structure'] ) )
1988
- return false;
1989
-
1990
- if ( !is_site_admin() )
1991
- return false;
1992
-
1993
- if ( !empty( $current_blog ) ) {
1994
- if ( $current_blog->blog_id != BP_ROOT_BLOG )
1995
- return false;
1996
- }
1997
-
1998
- if ( empty( $wp_rewrite->permalink_structure ) ) { ?>
1999
- <div id="message" class="updated fade">
2000
- <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>
2001
- </div><?php
2002
- } else {
2003
- /* Get current theme info */
2004
- $ct = current_theme_info();
2005
-
2006
- /* The best way to remove this notice is to add a "buddypress" tag to your active theme's CSS header. */
2007
- if ( !defined( 'BP_SILENCE_THEME_NOTICE' ) && !in_array( 'buddypress', (array)$ct->tags ) ) { ?>
2008
- <div id="message" class="updated fade">
2009
- <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>
2010
- </div><?php
2011
- }
2012
- }
2013
- }
2014
- add_action( 'admin_notices', 'bp_core_activation_notice' );
2015
-
2016
- /**
2017
- * bp_core_activate_site_options()
2018
- *
2019
- * When switching from single to multisite we need to copy blog options to
2020
- * site options.
2021
- *
2022
- * @package BuddyPress Core
2023
- */
2024
- function bp_core_activate_site_options( $keys = array() ) {
2025
- global $bp;
2026
-
2027
- if ( !empty( $keys ) && is_array( $keys ) ) {
2028
- $errors = false;
2029
-
2030
- foreach ( $keys as $key => $default ) {
2031
- if ( empty( $bp->site_options[ $key ] ) ) {
2032
- $bp->site_options[ $key ] = get_blog_option( BP_ROOT_BLOG, $key, $default );
2033
-
2034
- if ( !update_site_option( $key, $bp->site_options[ $key ] ) )
2035
- $errors = true;
2036
- }
2037
- }
2038
-
2039
- if ( empty( $errors ) )
2040
- return true;
2041
- }
2042
-
2043
- return false;
2044
- }
2045
-
2046
- /********************************************************************************
2047
- * Custom Actions
2048
- *
2049
- * Functions to set up custom BuddyPress actions that all other components can
2050
- * hook in to.
2051
- */
2052
-
2053
- /* Allow core components and dependent plugins to set globals */
2054
- function bp_setup_globals() {
2055
- do_action( 'bp_setup_globals' );
2056
- }
2057
- add_action( 'plugins_loaded', 'bp_setup_globals', 5 );
2058
-
2059
- /* Allow core components and dependent plugins to set root components */
2060
- function bp_setup_root_components() {
2061
- do_action( 'bp_setup_root_components' );
2062
- }
2063
- add_action( 'plugins_loaded', 'bp_setup_root_components', 2 );
2064
-
2065
- /* Allow core components and dependent plugins to set their nav */
2066
- function bp_setup_nav() {
2067
- do_action( 'bp_setup_nav' );
2068
- }
2069
- add_action( 'plugins_loaded', 'bp_setup_nav' );
2070
-
2071
- /* Allow core components and dependent plugins to register widgets */
2072
- function bp_setup_widgets() {
2073
- do_action( 'bp_register_widgets' );
2074
- }
2075
- add_action( 'plugins_loaded', 'bp_setup_widgets' );
2076
-
2077
-
2078
- /********************************************************************************
2079
- * Caching
2080
- *
2081
- * Caching functions handle the clearing of cached objects and pages on specific
2082
- * actions throughout BuddyPress.
2083
- */
2084
-
2085
- /**
2086
- * bp_core_clear_user_object_cache()
2087
- *
2088
- * Clears all cached objects for a user, or a user is part of.
2089
- *
2090
- * @package BuddyPress Core
2091
- */
2092
- function bp_core_clear_user_object_cache( $user_id ) {
2093
- wp_cache_delete( 'bp_user_' . $user_id, 'bp' );
2094
- wp_cache_delete( 'bp_core_avatar_v1_u' . $user_id, 'bp' );
2095
- wp_cache_delete( 'bp_core_avatar_v2_u' . $user_id, 'bp' );
2096
- wp_cache_delete( 'online_users' );
2097
- wp_cache_delete( 'newest_users' );
2098
- }
2099
-
2100
- // List actions to clear super cached pages on, if super cache is installed
2101
- add_action( 'wp_login', 'bp_core_clear_cache' );
2102
- add_action( 'bp_core_render_notice', 'bp_core_clear_cache' );
2103
-
2104
- // Remove the catch non existent blogs hook so WPMU doesn't think BuddyPress pages are non existing blogs
2105
- remove_action( 'plugins_loaded', 'catch_nonexistant_blogs' );
2106
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2107
  ?>
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, $wpdb;
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
+ /* The domain for the root of the site where the main blog resides */
95
+ $bp->root_domain = bp_core_get_root_domain();
96
+
97
+ /* The user ID of the user who is currently logged in. */
98
+ $bp->loggedin_user->id = $current_user->ID;
99
+
100
+ /* The domain for the user currently logged in. eg: http://domain.com/members/andy */
101
+ $bp->loggedin_user->domain = bp_core_get_user_domain( $bp->loggedin_user->id );
102
+
103
+ /* The core userdata of the user who is currently logged in. */
104
+ $bp->loggedin_user->userdata = bp_core_get_core_userdata( $bp->loggedin_user->id );
105
+
106
+ /* is_site_admin() hits the DB on single WP installs, so we need to get this separately so we can call it in a loop. */
107
+ $bp->loggedin_user->is_site_admin = is_site_admin();
108
+
109
+ /* The user id of the user currently being viewed, set in /bp-core/bp-core-catchuri.php */
110
+ $bp->displayed_user->id = $displayed_user_id;
111
+
112
+ /* The domain for the user currently being displayed */
113
+ $bp->displayed_user->domain = bp_core_get_user_domain( $bp->displayed_user->id );
114
+
115
+ /* The core userdata of the user who is currently being displayed */
116
+ $bp->displayed_user->userdata = bp_core_get_core_userdata( $bp->displayed_user->id );
117
+
118
+ /* The component being used eg: http://domain.com/members/andy/ [profile] */
119
+ $bp->current_component = $current_component; // type: string
120
+
121
+ /* The current action for the component eg: http://domain.com/members/andy/profile/ [edit] */
122
+ $bp->current_action = $current_action; // type: string
123
+
124
+ /* The action variables for the current action eg: http://domain.com/members/andy/profile/edit/ [group] / [6] */
125
+ $bp->action_variables = $action_variables; // type: array
126
+
127
+ /* 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.*/
128
+ $bp->current_item = ''; // type: string
129
+
130
+ /* Used for overriding the 2nd level navigation menu so it can be used to display custom navigation for an item (for example a group) */
131
+ $bp->is_single_item = false;
132
+
133
+ /* The default component to use if none are set and someone visits: http://domain.com/members/andy */
134
+ if ( !defined( 'BP_DEFAULT_COMPONENT' ) ) {
135
+ if ( defined( 'BP_ACTIVITY_SLUG' ) )
136
+ $bp->default_component = BP_ACTIVITY_SLUG;
137
+ else
138
+ $bp->default_component = 'profile';
139
+ } else {
140
+ $bp->default_component = BP_DEFAULT_COMPONENT;
141
+ }
142
+
143
+ /* Fetches all of the core database based BuddyPress settings in one foul swoop */
144
+ $bp->site_options = bp_core_get_site_options();
145
+
146
+ /* Sets up the array container for the component navigation rendered by bp_get_nav() */
147
+ $bp->bp_nav = array();
148
+
149
+ /* Sets up the array container for the component options navigation rendered by bp_get_options_nav() */
150
+ $bp->bp_options_nav = array();
151
+
152
+ /* Contains an array of all the active components. The key is the slug, value the internal ID of the component */
153
+ $bp->active_components = array();
154
+
155
+ /* Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar */
156
+ $bp->grav_default->user = apply_filters( 'bp_user_gravatar_default', $bp->site_options['user-avatar-default'] );
157
+ $bp->grav_default->group = apply_filters( 'bp_group_gravatar_default', 'identicon' );
158
+ $bp->grav_default->blog = apply_filters( 'bp_blog_gravatar_default', 'identicon' );
159
+
160
+ /* Fetch the full name for the logged in and current user */
161
+ $bp->loggedin_user->fullname = bp_core_get_user_displayname( $bp->loggedin_user->id );
162
+ $bp->displayed_user->fullname = bp_core_get_user_displayname( $bp->displayed_user->id );
163
+
164
+ /* Used to determine if user has admin rights on current content. If the logged in user is viewing
165
+ their own profile and wants to delete something, is_item_admin is used. This is a
166
+ generic variable so it can be used by other components. It can also be modified, so when viewing a group
167
+ 'is_item_admin' would be 1 if they are a group admin, 0 if they are not. */
168
+ $bp->is_item_admin = bp_user_has_access();
169
+
170
+ /* Used to determine if the logged in user is a moderator for the current content. */
171
+ $bp->is_item_mod = false;
172
+
173
+ $bp->core->table_name_notifications = $wpdb->base_prefix . 'bp_notifications';
174
+
175
+ if ( !$bp->current_component && $bp->displayed_user->id )
176
+ $bp->current_component = $bp->default_component;
177
+
178
+ do_action( 'bp_core_setup_globals' );
179
+ }
180
+ add_action( 'bp_setup_globals', 'bp_core_setup_globals' );
181
+
182
+ /**
183
+ * bp_core_setup_root_uris()
184
+ *
185
+ * Adds the core URIs that should run in the root of the installation.
186
+ *
187
+ * For example: http://example.org/search/ or http://example.org/members/
188
+ *
189
+ * @package BuddyPress Core
190
+ * @uses bp_core_add_root_component() Adds a slug to the root components global variable.
191
+ */
192
+ function bp_core_setup_root_uris() {
193
+ // Add core root components
194
+ bp_core_add_root_component( BP_MEMBERS_SLUG );
195
+ bp_core_add_root_component( BP_REGISTER_SLUG );
196
+ bp_core_add_root_component( BP_ACTIVATION_SLUG );
197
+ bp_core_add_root_component( BP_SEARCH_SLUG );
198
+ }
199
+ add_action( 'bp_setup_root_components', 'bp_core_setup_root_uris' );
200
+
201
+
202
+ /**
203
+ * bp_core_install()
204
+ *
205
+ * Installs the core DB tables for BuddyPress.
206
+ *
207
+ * @package BuddyPress Core
208
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
209
+ * @global $wpdb WordPress DB access object.
210
+ * @uses dbDelta() Performs a table creation, or upgrade based on what already exists in the DB.
211
+ * @uses bp_core_add_illegal_names() Adds illegal blog names to the WP settings
212
+ */
213
+ function bp_core_install() {
214
+ global $wpdb, $bp;
215
+
216
+ if ( !empty($wpdb->charset) )
217
+ $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
218
+
219
+ $sql[] = "CREATE TABLE {$bp->core->table_name_notifications} (
220
+ id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
221
+ user_id bigint(20) NOT NULL,
222
+ item_id bigint(20) NOT NULL,
223
+ secondary_item_id bigint(20),
224
+ component_name varchar(75) NOT NULL,
225
+ component_action varchar(75) NOT NULL,
226
+ date_notified datetime NOT NULL,
227
+ is_new bool NOT NULL DEFAULT 0,
228
+ KEY item_id (item_id),
229
+ KEY secondary_item_id (secondary_item_id),
230
+ KEY user_id (user_id),
231
+ KEY is_new (is_new),
232
+ KEY component_name (component_name),
233
+ KEY component_action (component_action),
234
+ KEY useritem (user_id,is_new)
235
+ ) {$charset_collate};";
236
+
237
+ require_once( ABSPATH . 'wp-admin/upgrade-functions.php' );
238
+ dbDelta( $sql );
239
+
240
+ /* Add names of root components to the banned blog list to avoid conflicts */
241
+ if ( bp_core_is_multisite() )
242
+ bp_core_add_illegal_names();
243
+
244
+ update_site_option( 'bp-core-db-version', BP_CORE_DB_VERSION );
245
+ }
246
+
247
+ /**
248
+ * bp_core_check_installed()
249
+ *
250
+ * Checks to make sure the database tables are set up for the core component.
251
+ *
252
+ * @package BuddyPress Core
253
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
254
+ * @global $wpdb WordPress DB access object.
255
+ * @global $current_user WordPress global variable containing current logged in user information
256
+ * @uses is_site_admin() returns true if the current user is a site admin, false if not
257
+ * @uses get_site_option() fetches the value for a meta_key in the wp_sitemeta table
258
+ * @uses bp_core_install() runs the installation of DB tables for the core component
259
+ */
260
+ function bp_core_check_installed() {
261
+ global $wpdb, $bp;
262
+
263
+ if ( !is_site_admin() )
264
+ return false;
265
+
266
+ require ( BP_PLUGIN_DIR . '/bp-core/bp-core-admin.php' );
267
+
268
+ /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
269
+ if ( get_site_option( 'bp-core-db-version' ) < BP_CORE_DB_VERSION )
270
+ bp_core_install();
271
+ }
272
+ add_action( 'admin_menu', 'bp_core_check_installed' );
273
+
274
+ /**
275
+ * bp_core_add_admin_menu()
276
+ *
277
+ * Adds the "BuddyPress" admin submenu item to the Site Admin tab.
278
+ *
279
+ * @package BuddyPress Core
280
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
281
+ * @global $wpdb WordPress DB access object.
282
+ * @uses is_site_admin() returns true if the current user is a site admin, false if not
283
+ * @uses add_submenu_page() WP function to add a submenu item
284
+ */
285
+ function bp_core_add_admin_menu() {
286
+ if ( !is_site_admin() )
287
+ return false;
288
+
289
+ /* Add the administration tab under the "Site Admin" tab for site administrators */
290
+ bp_core_add_admin_menu_page( array(
291
+ 'menu_title' => __( 'BuddyPress', 'buddypress' ),
292
+ 'page_title' => __( 'BuddyPress', 'buddypress' ),
293
+ 'access_level' => 10, 'file' => 'bp-general-settings',
294
+ 'function' => 'bp_core_admin_settings',
295
+ 'position' => 2
296
+ ) );
297
+
298
+ add_submenu_page( 'bp-general-settings', __( 'General Settings', 'buddypress'), __( 'General Settings', 'buddypress' ), 'manage_options', 'bp-general-settings', 'bp_core_admin_settings' );
299
+ add_submenu_page( 'bp-general-settings', __( 'Component Setup', 'buddypress'), __( 'Component Setup', 'buddypress' ), 'manage_options', 'bp-component-setup', 'bp_core_admin_component_setup' );
300
+ }
301
+ add_action( 'admin_menu', 'bp_core_add_admin_menu' );
302
+
303
+ /**
304
+ * bp_core_is_root_component()
305
+ *
306
+ * Checks to see if a component's URL should be in the root, not under a member page:
307
+ * eg: http://domain.com/groups/the-group NOT http://domain.com/members/andy/groups/the-group
308
+ *
309
+ * @package BuddyPress Core
310
+ * @return true if root component, else false.
311
+ */
312
+ function bp_core_is_root_component( $component_name ) {
313
+ global $bp;
314
+
315
+ return in_array( $component_name, $bp->root_components );
316
+ }
317
+
318
+ /**
319
+ * bp_core_setup_nav()
320
+ *
321
+ * Sets up the profile navigation item if the Xprofile component is not installed.
322
+ *
323
+ * @package BuddyPress Core
324
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
325
+ * @uses bp_core_new_nav_item() Adds a navigation item to the top level buddypress navigation
326
+ * @uses bp_core_new_subnav_item() Adds a sub navigation item to a nav item
327
+ * @uses bp_is_my_profile() Returns true if the current user being viewed is equal the logged in user
328
+ * @uses bp_core_fetch_avatar() Returns the either the thumb or full avatar URL for the user_id passed
329
+ */
330
+ function bp_core_setup_nav() {
331
+ global $bp;
332
+
333
+ /***
334
+ * If the extended profiles component is disabled, we need to revert to using the
335
+ * built in WordPress profile information
336
+ */
337
+ if ( !function_exists( 'xprofile_install' ) ) {
338
+ /* Fallback values if xprofile is disabled */
339
+ $bp->core->profile->slug = 'profile';
340
+ $bp->active_components[$bp->core->profile->slug] = $bp->core->profile->slug;
341
+
342
+ /* Add 'Profile' to the main navigation */
343
+ bp_core_new_nav_item( array(
344
+ 'name' => __('Profile', 'buddypress'),
345
+ 'slug' => $bp->core->profile->slug,
346
+ 'position' => 20,
347
+ 'screen_function' => 'bp_core_catch_profile_uri',
348
+ 'default_subnav_slug' => 'public'
349
+ ) );
350
+
351
+ $profile_link = $bp->loggedin_user->domain . '/profile/';
352
+
353
+ /* Add the subnav items to the profile */
354
+ bp_core_new_subnav_item( array(
355
+ 'name' => __( 'Public', 'buddypress' ),
356
+ 'slug' => 'public',
357
+ 'parent_url' => $profile_link,
358
+ 'parent_slug' => $bp->core->profile->slug,
359
+ 'screen_function' => 'bp_core_catch_profile_uri'
360
+ ) );
361
+
362
+
363
+ if ( 'profile' == $bp->current_component ) {
364
+ if ( bp_is_my_profile() ) {
365
+ $bp->bp_options_title = __('My Profile', 'buddypress');
366
+ } else {
367
+ $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
368
+ $bp->bp_options_title = $bp->displayed_user->fullname;
369
+ }
370
+ }
371
+ }
372
+ }
373
+ add_action( 'bp_setup_nav', 'bp_core_setup_nav' );
374
+
375
+ /********************************************************************************
376
+ * Action Functions
377
+ *
378
+ * Action functions are exactly the same as screen functions, however they do not
379
+ * have a template screen associated with them. Usually they will send the user
380
+ * back to the default screen after execution.
381
+ */
382
+
383
+ /**
384
+ * bp_core_action_directory_members()
385
+ *
386
+ * Listens to the $bp component and action variables to determine if the user is viewing the members
387
+ * directory page. If they are, it will set up the directory and load the members directory template.
388
+ *
389
+ * @package BuddyPress Core
390
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
391
+ * @uses wp_enqueue_script() Loads a JS script into the header of the page.
392
+ * @uses bp_core_load_template() Loads a specific template file.
393
+ */
394
+ function bp_core_action_directory_members() {
395
+ global $bp;
396
+
397
+ if ( is_null( $bp->displayed_user->id ) && $bp->current_component == BP_MEMBERS_SLUG ) {
398
+ $bp->is_directory = true;
399
+
400
+ do_action( 'bp_core_action_directory_members' );
401
+ bp_core_load_template( apply_filters( 'bp_core_template_directory_members', 'members/index' ) );
402
+ }
403
+ }
404
+ add_action( 'wp', 'bp_core_action_directory_members', 2 );
405
+
406
+ /**
407
+ * bp_core_action_set_spammer_status()
408
+ *
409
+ * When a site admin selects "Mark as Spammer/Not Spammer" from the admin menu
410
+ * this action will fire and mark or unmark the user and their blogs as spam.
411
+ * Must be a site admin for this function to run.
412
+ *
413
+ * @package BuddyPress Core
414
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
415
+ */
416
+ function bp_core_action_set_spammer_status() {
417
+ global $bp, $wpdb, $wp_version;
418
+
419
+ if ( !is_site_admin() || bp_is_my_profile() || !$bp->displayed_user->id )
420
+ return false;
421
+
422
+ if ( 'admin' == $bp->current_component && ( 'mark-spammer' == $bp->current_action || 'unmark-spammer' == $bp->current_action ) ) {
423
+ /* Check the nonce */
424
+ check_admin_referer( 'mark-unmark-spammer' );
425
+
426
+ /* Get the functions file */
427
+ if ( bp_core_is_multisite() ) {
428
+ if ( $wp_version >= '3.0' )
429
+ require_once( ABSPATH . '/wp-admin/includes/ms.php' );
430
+ else
431
+ require_once( ABSPATH . '/wp-admin/includes/mu.php' );
432
+ }
433
+
434
+ if ( 'mark-spammer' == $bp->current_action )
435
+ $is_spam = 1;
436
+ else
437
+ $is_spam = 0;
438
+
439
+ /* Get the blogs for the user */
440
+ $blogs = get_blogs_of_user( $bp->displayed_user->id, true );
441
+
442
+ foreach ( (array) $blogs as $key => $details ) {
443
+ /* Do not mark the main or current root blog as spam */
444
+ if ( 1 == $details->userblog_id || BP_ROOT_BLOG == $details->userblog_id )
445
+ continue;
446
+
447
+ /* Update the blog status */
448
+ update_blog_status( $details->userblog_id, 'spam', $is_spam );
449
+
450
+ /* Fire the standard WPMU hook */
451
+ do_action( 'make_spam_blog', $details->userblog_id );
452
+ }
453
+
454
+ /* Finally, mark this user as a spammer */
455
+ if ( bp_core_is_multisite() )
456
+ $wpdb->update( $wpdb->users, array( 'spam' => $is_spam ), array( 'ID' => $bp->displayed_user->id ) );
457
+
458
+ $wpdb->update( $wpdb->users, array( 'user_status' => $is_spam ), array( 'ID' => $bp->displayed_user->id ) );
459
+
460
+ if ( $is_spam )
461
+ bp_core_add_message( __( 'User marked as spammer. Spam users are visible only to site admins.', 'buddypress' ) );
462
+ else
463
+ bp_core_add_message( __( 'User removed as spammer.', 'buddypress' ) );
464
+
465
+ /* Hide this user's activity */
466
+ if ( $is_spam && function_exists( 'bp_activity_hide_user_activity' ) )
467
+ bp_activity_hide_user_activity( $bp->displayed_user->id );
468
+
469
+ do_action( 'bp_core_action_set_spammer_status', $bp->displayed_user->id, $is_spam );
470
+
471
+ bp_core_redirect( wp_get_referer() );
472
+ }
473
+ }
474
+ add_action( 'wp', 'bp_core_action_set_spammer_status', 3 );
475
+
476
+ /**
477
+ * bp_core_action_delete_user()
478
+ *
479
+ * Allows a site admin to delete a user from the adminbar menu.
480
+ *
481
+ * @package BuddyPress Core
482
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
483
+ */
484
+ function bp_core_action_delete_user() {
485
+ global $bp;
486
+
487
+ if ( !is_site_admin() || bp_is_my_profile() || !$bp->displayed_user->id )
488
+ return false;
489
+
490
+ if ( 'admin' == $bp->current_component && 'delete-user' == $bp->current_action ) {
491
+ /* Check the nonce */
492
+ check_admin_referer( 'delete-user' );
493
+
494
+ $errors = false;
495
+
496
+ if ( bp_core_delete_account( $bp->displayed_user->id ) ) {
497
+ bp_core_add_message( sprintf( __( '%s has been deleted from the system.', 'buddypress' ), $bp->displayed_user->fullname ) );
498
+ } else {
499
+ bp_core_add_message( sprintf( __( 'There was an error deleting %s from the system. Please try again.', 'buddypress' ), $bp->displayed_user->fullname ), 'error' );
500
+ $errors = true;
501
+ }
502
+
503
+ do_action( 'bp_core_action_delete_user', $errors );
504
+
505
+ if ( $errors )
506
+ bp_core_redirect( $bp->displayed_user->domain );
507
+ else
508
+ bp_core_redirect( $bp->loggedin_user->domain );
509
+ }
510
+ }
511
+ add_action( 'wp', 'bp_core_action_delete_user', 3 );
512
+
513
+
514
+ /********************************************************************************
515
+ * Business Functions
516
+ *
517
+ * Business functions are where all the magic happens in BuddyPress. They will
518
+ * handle the actual saving or manipulation of information. Usually they will
519
+ * hand off to a database class for data access, then return
520
+ * true or false on success or failure.
521
+ */
522
+
523
+ /**
524
+ * bp_core_get_users()
525
+ *
526
+ * Return an array of users IDs based on the parameters passed.
527
+ *
528
+ * @package BuddyPress Core
529
+ */
530
+ function bp_core_get_users( $args = '' ) {
531
+ global $bp;
532
+
533
+ $defaults = array(
534
+ 'type' => 'active', // active, newest, alphabetical, random or popular
535
+ 'user_id' => false, // Pass a user_id to limit to only friend connections for this user
536
+ 'search_terms' => false, // Limit to users that match these search terms
537
+
538
+ 'include' => false, // Pass comma separated list of user_ids to limit to only these users
539
+ 'per_page' => 20, // The number of results to return per page
540
+ 'page' => 1, // The page to return if limiting per page
541
+ 'populate_extras' => true, // Fetch the last active, where the user is a friend, total friend count, latest update
542
+ );
543
+
544
+ $params = wp_parse_args( $args, $defaults );
545
+ extract( $params, EXTR_SKIP );
546
+
547
+ return apply_filters( 'bp_core_get_users', BP_Core_User::get_users( $type, $per_page, $page, $user_id, $include, $search_terms, $populate_extras ), &$params );
548
+ }
549
+
550
+ /**
551
+ * bp_core_get_user_domain()
552
+ *
553
+ * Returns the domain for the passed user:
554
+ * e.g. http://domain.com/members/andy/
555
+ *
556
+ * @package BuddyPress Core
557
+ * @global $current_user WordPress global variable containing current logged in user information
558
+ * @param user_id The ID of the user.
559
+ * @uses get_usermeta() WordPress function to get the usermeta for a user.
560
+ */
561
+ function bp_core_get_user_domain( $user_id, $user_nicename = false, $user_login = false ) {
562
+ global $bp;
563
+
564
+ if ( !$user_id ) return;
565
+
566
+ if ( !$domain = wp_cache_get( 'bp_user_domain_' . $user_id, 'bp' ) ) {
567
+ $username = bp_core_get_username( $user_id, $user_nicename, $user_login );
568
+
569
+ /* If we are using a members slug, include it. */
570
+ if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) )
571
+ $domain = $bp->root_domain . '/' . BP_MEMBERS_SLUG . '/' . $username . '/';
572
+ else
573
+ $domain = $bp->root_domain . '/' . $username . '/';
574
+
575
+ /* Cache the link */
576
+ if ( !empty( $domain ) )
577
+ wp_cache_set( 'bp_user_domain_' . $user_id, $domain, 'bp' );
578
+ }
579
+
580
+ return apply_filters( 'bp_core_get_user_domain', $domain );
581
+ }
582
+
583
+ /**
584
+ * bp_core_get_core_userdata()
585
+ *
586
+ * Fetch everything in the wp_users table for a user, without any usermeta.
587
+ *
588
+ * @package BuddyPress Core
589
+ * @param user_id The ID of the user.
590
+ * @uses BP_Core_User::get_core_userdata() Performs the query.
591
+ */
592
+ function bp_core_get_core_userdata( $user_id ) {
593
+ if ( empty( $user_id ) )
594
+ return false;
595
+
596
+ if ( !$userdata = wp_cache_get( 'bp_core_userdata_' . $user_id, 'bp' ) ) {
597
+ $userdata = BP_Core_User::get_core_userdata( $user_id );
598
+ wp_cache_set( 'bp_core_userdata_' . $user_id, $userdata, 'bp' );
599
+ }
600
+ return apply_filters( 'bp_core_get_core_userdata', $userdata );
601
+ }
602
+
603
+ /**
604
+ * bp_core_get_root_domain()
605
+ *
606
+ * Returns the domain for the root blog.
607
+ * eg: http://domain.com/ OR https://domain.com
608
+ *
609
+ * @package BuddyPress Core
610
+ * @uses get_blog_option() WordPress function to fetch blog meta.
611
+ * @return $domain The domain URL for the blog.
612
+ */
613
+ function bp_core_get_root_domain() {
614
+ global $current_blog;
615
+
616
+ if ( defined( 'BP_ENABLE_MULTIBLOG' ) )
617
+ $domain = get_blog_option( $current_blog->blog_id, 'home' );
618
+ else
619
+ $domain = get_blog_option( BP_ROOT_BLOG, 'home' );
620
+
621
+ return apply_filters( 'bp_core_get_root_domain', $domain );
622
+ }
623
+
624
+ /**
625
+ * bp_core_get_displayed_userid()
626
+ *
627
+ * Returns the user id for the user that is currently being displayed.
628
+ * eg: http://andy.domain.com/ or http://domain.com/andy/
629
+ *
630
+ * @package BuddyPress Core
631
+ * @global $current_blog WordPress global containing information and settings for the current blog being viewed.
632
+ * @uses bp_core_get_userid_from_user_login() Returns the user id for the username passed
633
+ * @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.
634
+ */
635
+ function bp_core_get_displayed_userid( $user_login ) {
636
+ return apply_filters( 'bp_core_get_displayed_userid', bp_core_get_userid( $user_login ) );
637
+ }
638
+
639
+ /**
640
+ * bp_core_new_nav_item()
641
+ *
642
+ * Adds a navigation item to the main navigation array used in BuddyPress themes.
643
+ *
644
+ * @package BuddyPress Core
645
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
646
+ */
647
+ function bp_core_new_nav_item( $args = '' ) {
648
+ global $bp;
649
+
650
+ $defaults = array(
651
+ 'name' => false, // Display name for the nav item
652
+ 'slug' => false, // URL slug for the nav item
653
+ 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item
654
+ 'show_for_displayed_user' => true, // When viewing another user does this nav item show up?
655
+ 'site_admin_only' => false, // Can only site admins see this nav item?
656
+ 'position' => 99, // Index of where this nav item should be positioned
657
+ 'screen_function' => false, // The name of the function to run when clicked
658
+ 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked
659
+ );
660
+
661
+ $r = wp_parse_args( $args, $defaults );
662
+ extract( $r, EXTR_SKIP );
663
+
664
+ /* If we don't have the required info we need, don't create this subnav item */
665
+ if ( empty($name) || empty($slug) )
666
+ return false;
667
+
668
+ /* If this is for site admins only and the user is not one, don't create the subnav item */
669
+ if ( $site_admin_only && !is_site_admin() )
670
+ return false;
671
+
672
+ if ( empty( $item_css_id ) )
673
+ $item_css_id = $slug;
674
+
675
+ $bp->bp_nav[$slug] = array(
676
+ 'name' => $name,
677
+ 'slug' => $slug,
678
+ 'link' => $bp->loggedin_user->domain . $slug . '/',
679
+ 'css_id' => $item_css_id,
680
+ 'show_for_displayed_user' => $show_for_displayed_user,
681
+ 'position' => $position
682
+ );
683
+
684
+ /***
685
+ * If this nav item is hidden for the displayed user, and
686
+ * the logged in user is not the displayed user
687
+ * looking at their own profile, don't create the nav item.
688
+ */
689
+ if ( !$show_for_displayed_user && !bp_user_has_access() )
690
+ return false;
691
+
692
+ /***
693
+ * If we are not viewing a user, and this is a root component, don't attach the
694
+ * default subnav function so we can display a directory or something else.
695
+ */
696
+ if ( bp_core_is_root_component( $slug ) && !$bp->displayed_user->id )
697
+ return;
698
+
699
+ if ( $bp->current_component == $slug && !$bp->current_action ) {
700
+ if ( !is_object( $screen_function[0] ) )
701
+ add_action( 'wp', $screen_function, 3 );
702
+ else
703
+ add_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );
704
+
705
+ if ( $default_subnav_slug )
706
+ $bp->current_action = $default_subnav_slug;
707
+ }
708
+ }
709
+
710
+ /**
711
+ * bp_core_new_nav_default()
712
+ *
713
+ * Modify the default subnav item to load when a top level nav item is clicked.
714
+ *
715
+ * @package BuddyPress Core
716
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
717
+ */
718
+ function bp_core_new_nav_default( $args = '' ) {
719
+ global $bp;
720
+
721
+ $defaults = array(
722
+ 'parent_slug' => false, // Slug of the parent
723
+ 'screen_function' => false, // The name of the function to run when clicked
724
+ 'subnav_slug' => false // The slug of the subnav item to select when clicked
725
+ );
726
+
727
+ $r = wp_parse_args( $args, $defaults );
728
+ extract( $r, EXTR_SKIP );
729
+
730
+ if ( $bp->current_component == $parent_slug && !$bp->current_action ) {
731
+ if ( !is_object( $screen_function[0] ) )
732
+ add_action( 'wp', $screen_function, 3 );
733
+ else
734
+ add_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );
735
+
736
+ if ( $subnav_slug )
737
+ $bp->current_action = $subnav_slug;
738
+ }
739
+ }
740
+
741
+ /**
742
+ * bp_core_sort_nav_items()
743
+ *
744
+ * We can only sort nav items by their position integer at a later point in time, once all
745
+ * plugins have registered their navigation items.
746
+ *
747
+ * @package BuddyPress Core
748
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
749
+ */
750
+ function bp_core_sort_nav_items() {
751
+ global $bp;
752
+
753
+ if ( empty( $bp->bp_nav ) || !is_array( $bp->bp_nav ) )
754
+ return false;
755
+
756
+ foreach ( (array)$bp->bp_nav as $slug => $nav_item ) {
757
+ if ( empty( $temp[$nav_item['position']]) )
758
+ $temp[$nav_item['position']] = $nav_item;
759
+ else {
760
+ // increase numbers here to fit new items in.
761
+ do {
762
+ $nav_item['position']++;
763
+ } while ( !empty( $temp[$nav_item['position']] ) );
764
+
765
+ $temp[$nav_item['position']] = $nav_item;
766
+ }
767
+ }
768
+
769
+ ksort( $temp );
770
+ $bp->bp_nav = &$temp;
771
+ }
772
+ add_action( 'wp_head', 'bp_core_sort_nav_items' );
773
+ add_action( 'admin_head', 'bp_core_sort_nav_items' );
774
+
775
+ /**
776
+ * bp_core_new_subnav_item()
777
+ *
778
+ * Adds a navigation item to the sub navigation array used in BuddyPress themes.
779
+ *
780
+ * @package BuddyPress Core
781
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
782
+ */
783
+ function bp_core_new_subnav_item( $args = '' ) {
784
+ global $bp;
785
+
786
+ $defaults = array(
787
+ 'name' => false, // Display name for the nav item
788
+ 'slug' => false, // URL slug for the nav item
789
+ 'parent_slug' => false, // URL slug of the parent nav item
790
+ 'parent_url' => false, // URL of the parent item
791
+ 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item
792
+ 'user_has_access' => true, // Can the logged in user see this nav item?
793
+ 'site_admin_only' => false, // Can only site admins see this nav item?
794
+ 'position' => 90, // Index of where this nav item should be positioned
795
+ 'screen_function' => false // The name of the function to run when clicked
796
+ );
797
+
798
+ $r = wp_parse_args( $args, $defaults );
799
+ extract( $r, EXTR_SKIP );
800
+
801
+ /* If we don't have the required info we need, don't create this subnav item */
802
+ if ( empty($name) || empty($slug) || empty($parent_slug) || empty($parent_url) || empty($screen_function) )
803
+ return false;
804
+
805
+ /* If this is for site admins only and the user is not one, don't create the subnav item */
806
+ if ( $site_admin_only && !is_site_admin() )
807
+ return false;
808
+
809
+ if ( empty( $item_css_id ) )
810
+ $item_css_id = $slug;
811
+
812
+ $bp->bp_options_nav[$parent_slug][$slug] = array(
813
+ 'name' => $name,
814
+ 'link' => $parent_url . $slug . '/',
815
+ 'slug' => $slug,
816
+ 'css_id' => $item_css_id,
817
+ 'position' => $position,
818
+ 'user_has_access' => $user_has_access,
819
+ 'screen_function' => $screen_function
820
+ );
821
+
822
+ if ( ( $bp->current_action == $slug && $bp->current_component == $parent_slug ) && $user_has_access ) {
823
+ if ( !is_object( $screen_function[0] ) )
824
+ add_action( 'wp', $screen_function, 3 );
825
+ else
826
+ add_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );
827
+ }
828
+ }
829
+
830
+ function bp_core_sort_subnav_items() {
831
+ global $bp;
832
+
833
+ if ( empty( $bp->bp_options_nav ) || !is_array( $bp->bp_options_nav ) )
834
+ return false;
835
+
836
+ foreach ( (array)$bp->bp_options_nav as $parent_slug => $subnav_items ) {
837
+ if ( !is_array( $subnav_items ) )
838
+ continue;
839
+
840
+ foreach ( (array)$subnav_items as $subnav_item ) {
841
+ if ( empty( $temp[$subnav_item['position']]) )
842
+ $temp[$subnav_item['position']] = $subnav_item;
843
+ else {
844
+ // increase numbers here to fit new items in.
845
+ do {
846
+ $subnav_item['position']++;
847
+ } while ( !empty( $temp[$subnav_item['position']] ) );
848
+
849
+ $temp[$subnav_item['position']] = $subnav_item;
850
+ }
851
+ }
852
+ ksort( $temp );
853
+ $bp->bp_options_nav[$parent_slug] = &$temp;
854
+ unset($temp);
855
+ }
856
+ }
857
+ add_action( 'wp_head', 'bp_core_sort_subnav_items' );
858
+ add_action( 'admin_head', 'bp_core_sort_subnav_items' );
859
+
860
+ /**
861
+ * bp_core_remove_nav_item()
862
+ *
863
+ * Removes a navigation item from the sub navigation array used in BuddyPress themes.
864
+ *
865
+ * @package BuddyPress Core
866
+ * @param $parent_id The id of the parent navigation item.
867
+ * @param $slug The slug of the sub navigation item.
868
+ */
869
+ function bp_core_remove_nav_item( $parent_id ) {
870
+ global $bp;
871
+
872
+ /* Unset subnav items for this nav item */
873
+ if ( is_array( $bp->bp_options_nav[$parent_id] ) ) {
874
+ foreach( (array)$bp->bp_options_nav[$parent_id] as $subnav_item ) {
875
+ bp_core_remove_subnav_item( $parent_id, $subnav_item['slug'] );
876
+ }
877
+ }
878
+
879
+ unset( $bp->bp_nav[$parent_id] );
880
+ }
881
+
882
+ /**
883
+ * bp_core_remove_subnav_item()
884
+ *
885
+ * Removes a navigation item from the sub navigation array used in BuddyPress themes.
886
+ *
887
+ * @package BuddyPress Core
888
+ * @param $parent_id The id of the parent navigation item.
889
+ * @param $slug The slug of the sub navigation item.
890
+ */
891
+ function bp_core_remove_subnav_item( $parent_id, $slug ) {
892
+ global $bp;
893
+
894
+ $screen_function = $bp->bp_options_nav[$parent_id][$slug]['screen_function'];
895
+
896
+ if ( $screen_function ) {
897
+ if ( !is_object( $screen_function[0] ) )
898
+ remove_action( 'wp', $screen_function, 3 );
899
+ else
900
+ remove_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 );
901
+ }
902
+
903
+ unset( $bp->bp_options_nav[$parent_id][$slug] );
904
+
905
+ if ( !count( $bp->bp_options_nav[$parent_id] ) )
906
+ unset($bp->bp_options_nav[$parent_id]);
907
+ }
908
+
909
+ /**
910
+ * bp_core_reset_subnav_items()
911
+ *
912
+ * Clear the subnav items for a specific nav item.
913
+ *
914
+ * @package BuddyPress Core
915
+ * @param $parent_id The id of the parent navigation item.
916
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
917
+ */
918
+ function bp_core_reset_subnav_items($parent_slug) {
919
+ global $bp;
920
+
921
+ unset($bp->bp_options_nav[$parent_slug]);
922
+ }
923
+
924
+ /**
925
+ * bp_core_load_template()
926
+ *
927
+ * Uses the bp_catch_uri function to load a specific template file with fallback support.
928
+ *
929
+ * Example:
930
+ * bp_core_load_template( 'profile/edit-profile' );
931
+ * Loads:
932
+ * wp-content/themes/[activated_theme]/profile/edit-profile.php
933
+ *
934
+ * @package BuddyPress Core
935
+ * @param $username str Username to check.
936
+ * @global $wpdb WordPress DB access object.
937
+ * @return false on no match
938
+ * @return int the user ID of the matched user.
939
+ */
940
+ function bp_core_load_template( $template, $skip_blog_check = false ) {
941
+ return bp_catch_uri( $template, $skip_blog_check );
942
+ }
943
+
944
+ /**
945
+ * bp_core_add_root_component()
946
+ *
947
+ * Adds a component to the $bp->root_components global.
948
+ * Any component that runs in the "root" of an install should be added.
949
+ * The "root" as in, it can or always runs outside of the /members/username/ path.
950
+ *
951
+ * Example of a root component:
952
+ * Groups: http://domain.com/groups/group-name
953
+ * http://community.domain.com/groups/group-name
954
+ * http://domain.com/wpmu/groups/group-name
955
+ *
956
+ * Example of a component that is NOT a root component:
957
+ * Friends: http://domain.com/members/andy/friends
958
+ * http://community.domain.com/members/andy/friends
959
+ * http://domain.com/wpmu/members/andy/friends
960
+ *
961
+ * @package BuddyPress Core
962
+ * @param $slug str The slug of the component
963
+ * @global $bp BuddyPress global settings
964
+ */
965
+ function bp_core_add_root_component( $slug ) {
966
+ global $bp;
967
+
968
+ $bp->root_components[] = $slug;
969
+ }
970
+
971
+ /**
972
+ * bp_core_get_random_member()
973
+ *
974
+ * Returns the user_id for a user based on their username.
975
+ *
976
+ * @package BuddyPress Core
977
+ * @param $username str Username to check.
978
+ * @global $wpdb WordPress DB access object.
979
+ * @return false on no match
980
+ * @return int the user ID of the matched user.
981
+ */
982
+ function bp_core_get_random_member() {
983
+ global $bp, $wpdb;
984
+
985
+ if ( isset( $_GET['random-member'] ) ) {
986
+ $user = bp_core_get_users( array( 'type' => 'random', 'per_page' => 1 ) );
987
+ bp_core_redirect( bp_core_get_user_domain( $user['users'][0]->id ) );
988
+ }
989
+ }
990
+ add_action( 'wp', 'bp_core_get_random_member' );
991
+
992
+ /**
993
+ * bp_core_get_userid()
994
+ *
995
+ * Returns the user_id for a user based on their username.
996
+ *
997
+ * @package BuddyPress Core
998
+ * @param $username str Username to check.
999
+ * @global $wpdb WordPress DB access object.
1000
+ * @return false on no match
1001
+ * @return int the user ID of the matched user.
1002
+ */
1003
+ function bp_core_get_userid( $username ) {
1004
+ global $wpdb;
1005
+
1006
+ if ( empty( $username ) )
1007
+ return false;
1008
+
1009
+ return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ) );
1010
+ }
1011
+
1012
+ /**
1013
+ * bp_core_get_userid_from_nicename()
1014
+ *
1015
+ * Returns the user_id for a user based on their user_nicename.
1016
+ *
1017
+ * @package BuddyPress Core
1018
+ * @param $username str Username to check.
1019
+ * @global $wpdb WordPress DB access object.
1020
+ * @return false on no match
1021
+ * @return int the user ID of the matched user.
1022
+ */
1023
+ function bp_core_get_userid_from_nicename( $user_nicename ) {
1024
+ global $wpdb;
1025
+
1026
+ if ( empty( $user_nicename ) )
1027
+ return false;
1028
+
1029
+ 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 ) ) );
1030
+ }
1031
+
1032
+ /**
1033
+ * bp_core_get_username()
1034
+ *
1035
+ * Returns the username for a user based on their user id.
1036
+ *
1037
+ * @package BuddyPress Core
1038
+ * @param $uid int User ID to check.
1039
+ * @global $userdata WordPress user data for the current logged in user.
1040
+ * @uses get_userdata() WordPress function to fetch the userdata for a user ID
1041
+ * @return false on no match
1042
+ * @return str the username of the matched user.
1043
+ */
1044
+ function bp_core_get_username( $user_id, $user_nicename = false, $user_login = false ) {
1045
+ global $bp;
1046
+
1047
+ if ( !$username = wp_cache_get( 'bp_user_username_' . $user_id, 'bp' ) ) {
1048
+ if ( empty( $user_nicename ) && empty( $user_login ) ) {
1049
+ $ud = false;
1050
+
1051
+ if ( $bp->loggedin_user->id == $user_id )
1052
+ $ud = &$bp->loggedin_user->userdata;
1053
+
1054
+ if ( $bp->displayed_user->id == $user_id )
1055
+ $ud = &$bp->displayed_user->userdata;
1056
+
1057
+ if ( empty( $ud ) ) {
1058
+ if ( !$ud = bp_core_get_core_userdata( $user_id ) )
1059
+ return false;
1060
+ }
1061
+
1062
+ $user_nicename = $ud->user_nicename;
1063
+ $user_login = $ud->user_login;
1064
+ }
1065
+
1066
+ if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
1067
+ $username = $user_login;
1068
+ else
1069
+ $username = $user_nicename;
1070
+ }
1071
+
1072
+ /* Add this to cache */
1073
+ if ( !empty( $username ) )
1074
+ wp_cache_set( 'bp_user_username_' . $user_id, $username, 'bp' );
1075
+
1076
+ return apply_filters( 'bp_core_get_username', $username );
1077
+ }
1078
+
1079
+ /**
1080
+ * bp_core_get_user_email()
1081
+ *
1082
+ * Returns the email address for the user based on user ID
1083
+ *
1084
+ * @package BuddyPress Core
1085
+ * @param $uid int User ID to check.
1086
+ * @uses get_userdata() WordPress function to fetch the userdata for a user ID
1087
+ * @return false on no match
1088
+ * @return str The email for the matched user.
1089
+ */
1090
+ function bp_core_get_user_email( $uid ) {
1091
+ if ( !$email = wp_cache_get( 'bp_user_email_' . $uid, 'bp' ) ) {
1092
+ $ud = bp_core_get_core_userdata($uid);
1093
+ $email = $ud->user_email;
1094
+ wp_cache_set( 'bp_user_email_' . $uid, $email, 'bp' );
1095
+ }
1096
+
1097
+ return apply_filters( 'bp_core_get_user_email', $email );
1098
+ }
1099
+
1100
+ /**
1101
+ * bp_core_get_userlink()
1102
+ *
1103
+ * Returns a HTML formatted link for a user with the user's full name as the link text.
1104
+ * eg: <a href="http://andy.domain.com/">Andy Peatling</a>
1105
+ * Optional parameters will return just the name, or just the URL, or disable "You" text when
1106
+ * user matches the logged in user.
1107
+ *
1108
+ * [NOTES: This function needs to be cleaned up or split into separate functions]
1109
+ *
1110
+ * @package BuddyPress Core
1111
+ * @param $uid int User ID to check.
1112
+ * @param $no_anchor bool Disable URL and HTML and just return full name. Default false.
1113
+ * @param $just_link bool Disable full name and HTML and just return the URL text. Default false.
1114
+ * @param $no_you bool Disable replacing full name with "You" when logged in user is equal to the current user. Default false.
1115
+ * @global $userdata WordPress user data for the current logged in user.
1116
+ * @uses get_userdata() WordPress function to fetch the userdata for a user ID
1117
+ * @uses bp_fetch_user_fullname() Returns the full name for a user based on user ID.
1118
+ * @uses bp_core_get_userurl() Returns the URL for the user with no anchor tag based on user ID
1119
+ * @return false on no match
1120
+ * @return str The link text based on passed parameters.
1121
+ */
1122
+ function bp_core_get_userlink( $user_id, $no_anchor = false, $just_link = false ) {
1123
+ $display_name = bp_core_get_user_displayname( $user_id );
1124
+
1125
+ if ( empty( $display_name ) )
1126
+ return false;
1127
+
1128
+ if ( $no_anchor )
1129
+ return $display_name;
1130
+
1131
+ if ( !$url = bp_core_get_user_domain($user_id) )
1132
+ return false;
1133
+
1134
+ if ( $just_link )
1135
+ return $url;
1136
+
1137
+ return apply_filters( 'bp_core_get_userlink', '<a href="' . $url . '" title="' . $display_name . '">' . $display_name . '</a>', $user_id );
1138
+ }
1139
+
1140
+
1141
+ /**
1142
+ * bp_core_get_user_displayname()
1143
+ *
1144
+ * Fetch the display name for a user. This will use the "Name" field in xprofile if it is installed.
1145
+ * Otherwise, it will fall back to the normal WP display_name, or user_nicename, depending on what has been set.
1146
+ *
1147
+ * @package BuddyPress Core
1148
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
1149
+ * @uses wp_cache_get() Will try and fetch the value from the cache, rather than querying the DB again.
1150
+ * @uses get_userdata() Fetches the WP userdata for a specific user.
1151
+ * @uses xprofile_set_field_data() Will update the field data for a user based on field name and user id.
1152
+ * @uses wp_cache_set() Adds a value to the cache.
1153
+ * @return str The display name for the user in question.
1154
+ */
1155
+ function bp_core_get_user_displayname( $user_id_or_username ) {
1156
+ global $bp;
1157
+
1158
+ if ( !$user_id_or_username )
1159
+ return false;
1160
+
1161
+ if ( !is_numeric( $user_id_or_username ) )
1162
+ $user_id = bp_core_get_userid( $user_id_or_username );
1163
+ else
1164
+ $user_id = $user_id_or_username;
1165
+
1166
+ if ( !$user_id )
1167
+ return false;
1168
+
1169
+ if ( !$fullname = wp_cache_get( 'bp_user_fullname_' . $user_id, 'bp' ) ) {
1170
+ if ( function_exists('xprofile_install') ) {
1171
+ $fullname = xprofile_get_field_data( 1, $user_id );
1172
+
1173
+ if ( empty($fullname) ) {
1174
+ $ud = bp_core_get_core_userdata( $user_id );
1175
+
1176
+ if ( !empty( $ud->display_name ) )
1177
+ $fullname = $ud->display_name;
1178
+ else
1179
+ $fullname = $ud->user_nicename;
1180
+
1181
+ xprofile_set_field_data( 1, $user_id, $fullname );
1182
+ }
1183
+ } else {
1184
+ $ud = bp_core_get_core_userdata($user_id);
1185
+
1186
+ if ( !empty( $ud->display_name ) )
1187
+ $fullname = $ud->display_name;
1188
+ else
1189
+ $fullname = $ud->user_nicename;
1190
+ }
1191
+
1192
+ if ( !empty( $fullname ) )
1193
+ wp_cache_set( 'bp_user_fullname_' . $user_id, $fullname, 'bp' );
1194
+ }
1195
+
1196
+ return apply_filters( 'bp_core_get_user_displayname', $fullname, $user_id );
1197
+ }
1198
+ add_filter( 'bp_core_get_user_displayname', 'strip_tags', 1 );
1199
+ add_filter( 'bp_core_get_user_displayname', 'trim' );
1200
+ add_filter( 'bp_core_get_user_displayname', 'stripslashes' );
1201
+
1202
+
1203
+ /**
1204
+ * bp_core_get_userlink_by_email()
1205
+ *
1206
+ * Returns the user link for the user based on user email address
1207
+ *
1208
+ * @package BuddyPress Core
1209
+ * @param $email str The email address for the user.
1210
+ * @uses bp_core_get_userlink() BuddyPress function to get a userlink by user ID.
1211
+ * @uses get_user_by_email() WordPress function to get userdata via an email address
1212
+ * @return str The link to the users home base. False on no match.
1213
+ */
1214
+ function bp_core_get_userlink_by_email( $email ) {
1215
+ $user = get_user_by_email( $email );
1216
+ return apply_filters( 'bp_core_get_userlink_by_email', bp_core_get_userlink( $user->ID, false, false, true ) );
1217
+ }
1218
+
1219
+ /**
1220
+ * bp_core_get_userlink_by_username()
1221
+ *
1222
+ * Returns the user link for the user based on user's username
1223
+ *
1224
+ * @package BuddyPress Core
1225
+ * @param $username str The username for the user.
1226
+ * @uses bp_core_get_userlink() BuddyPress function to get a userlink by user ID.
1227
+ * @return str The link to the users home base. False on no match.
1228
+ */
1229
+ function bp_core_get_userlink_by_username( $username ) {
1230
+ global $wpdb;
1231
+
1232
+ $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) );
1233
+ return apply_filters( 'bp_core_get_userlink_by_username', bp_core_get_userlink( $user_id, false, false, true ) );
1234
+ }
1235
+
1236
+ /**
1237
+ * bp_core_get_total_member_count()
1238
+ *
1239
+ * Returns the total number of members for the installation.
1240
+ *
1241
+ * @package BuddyPress Core
1242
+ * @return int The total number of members.
1243
+ */
1244
+ function bp_core_get_total_member_count() {
1245
+ global $wpdb, $bp;
1246
+
1247
+ if ( !$count = wp_cache_get( 'bp_total_member_count', 'bp' ) ) {
1248
+ $status_sql = bp_core_get_status_sql();
1249
+ $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM " . CUSTOM_USER_TABLE . " WHERE {$status_sql}" ) );
1250
+ wp_cache_set( 'bp_total_member_count', $count, 'bp' );
1251
+ }
1252
+
1253
+ return apply_filters( 'bp_core_get_total_member_count', $count );
1254
+ }
1255
+
1256
+ /**
1257
+ * bp_core_is_user_spammer()
1258
+ *
1259
+ * Checks if the user has been marked as a spammer.
1260
+ *
1261
+ * @package BuddyPress Core
1262
+ * @param $user_id int The id for the user.
1263
+ * @return int 1 if spammer, 0 if not.
1264
+ */
1265
+ function bp_core_is_user_spammer( $user_id ) {
1266
+ global $wpdb;
1267
+
1268
+ if ( bp_core_is_multisite() )
1269
+ $is_spammer = (int) $wpdb->get_var( $wpdb->prepare( "SELECT spam FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) );
1270
+ else
1271
+ $is_spammer = (int) $wpdb->get_var( $wpdb->prepare( "SELECT user_status FROM " . CUSTOM_USER_TABLE . " WHERE ID = %d", $user_id ) );
1272
+
1273
+ return apply_filters( 'bp_core_is_user_spammer', $is_spammer );
1274
+ }
1275
+
1276
+ /**
1277
+ * bp_core_is_user_deleted()
1278
+ *
1279
+ * Checks if the user has been marked as deleted.
1280
+ *
1281
+ * @package BuddyPress Core
1282
+ * @param $user_id int The id for the user.
1283
+ * @return int 1 if deleted, 0 if not.
1284
+ */
1285
+ function bp_core_is_user_deleted( $user_id ) {
1286
+ global $wpdb;
1287
+
1288
+ 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 ) ) );
1289
+ }
1290
+
1291
+ /**
1292
+ * bp_core_format_time()
1293
+ */
1294
+ function bp_core_format_time( $time, $just_date = false ) {
1295
+ if ( !$time )
1296
+ return false;
1297
+
1298
+ $date = date( "F j, Y ", $time );
1299
+
1300
+ if ( !$just_date ) {
1301
+ $date .= __('at', 'buddypress') . date( ' g:iA', $time );
1302
+ }
1303
+
1304
+ return $date;
1305
+ }
1306
+
1307
+ /**
1308
+ * bp_core_add_message()
1309
+ *
1310
+ * Adds a feedback (error/success) message to the WP cookie so it can be displayed after the page reloads.
1311
+ *
1312
+ * @package BuddyPress Core
1313
+ */
1314
+ function bp_core_add_message( $message, $type = false ) {
1315
+ global $bp;
1316
+
1317
+ if ( !$type )
1318
+ $type = 'success';
1319
+
1320
+ /* Send the values to the cookie for page reload display */
1321
+ @setcookie( 'bp-message', $message, time()+60*60*24, COOKIEPATH );
1322
+ @setcookie( 'bp-message-type', $type, time()+60*60*24, COOKIEPATH );
1323
+
1324
+ /***
1325
+ * Send the values to the $bp global so we can still output messages
1326
+ * without a page reload
1327
+ */
1328
+ $bp->template_message = $message;
1329
+ $bp->template_message_type = $type;
1330
+ }
1331
+
1332
+ /**
1333
+ * bp_core_setup_message()
1334
+ *
1335
+ * Checks if there is a feedback message in the WP cookie, if so, adds a "template_notices" action
1336
+ * so that the message can be parsed into the template and displayed to the user.
1337
+ *
1338
+ * After the message is displayed, it removes the message vars from the cookie so that the message
1339
+ * is not shown to the user multiple times.
1340
+ *
1341
+ * @package BuddyPress Core
1342
+ * @global $bp_message The message text
1343
+ * @global $bp_message_type The type of message (error/success)
1344
+ * @uses setcookie() Sets a cookie value for the user.
1345
+ */
1346
+ function bp_core_setup_message() {
1347
+ global $bp;
1348
+
1349
+ if ( empty( $bp->template_message ) )
1350
+ $bp->template_message = $_COOKIE['bp-message'];
1351
+
1352
+ if ( empty( $bp->template_message_type ) )
1353
+ $bp->template_message_type = $_COOKIE['bp-message-type'];
1354
+
1355
+ add_action( 'template_notices', 'bp_core_render_message' );
1356
+
1357
+ @setcookie( 'bp-message', false, time() - 1000, COOKIEPATH );
1358
+ @setcookie( 'bp-message-type', false, time() - 1000, COOKIEPATH );
1359
+ }
1360
+ add_action( 'wp', 'bp_core_setup_message', 2 );
1361
+
1362
+ /**
1363
+ * bp_core_render_message()
1364
+ *
1365
+ * Renders a feedback message (either error or success message) to the theme template.
1366
+ * The hook action 'template_notices' is used to call this function, it is not called directly.
1367
+ *
1368
+ * @package BuddyPress Core
1369
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
1370
+ */
1371
+ function bp_core_render_message() {
1372
+ global $bp;
1373
+
1374
+ if ( $bp->template_message ) {
1375
+ $type = ( 'success' == $bp->template_message_type ) ? 'updated' : 'error';
1376
+ ?>
1377
+ <div id="message" class="<?php echo $type; ?>">
1378
+ <p><?php echo stripslashes( attribute_escape( $bp->template_message ) ); ?></p>
1379
+ </div>
1380
+ <?php
1381
+ do_action( 'bp_core_render_message' );
1382
+ }
1383
+ }
1384
+
1385
+ /**
1386
+ * bp_core_time_since()
1387
+ *
1388
+ * Based on function created by Dunstan Orchard - http://1976design.com
1389
+ *
1390
+ * This function will return an English representation of the time elapsed
1391
+ * since a given date.
1392
+ * eg: 2 hours and 50 minutes
1393
+ * eg: 4 days
1394
+ * eg: 4 weeks and 6 days
1395
+ *
1396
+ * @package BuddyPress Core
1397
+ * @param $older_date int Unix timestamp of date you want to calculate the time since for
1398
+ * @param $newer_date int Unix timestamp of date to compare older date to. Default false (current time).
1399
+ * @return str The time since.
1400
+ */
1401
+ function bp_core_time_since( $older_date, $newer_date = false ) {
1402
+ // array of time period chunks
1403
+
1404
+ $chunks = array(
1405
+ array( 60 * 60 * 24 * 365 , __( 'year', 'buddypress' ), __( 'years', 'buddypress' ) ),
1406
+ array( 60 * 60 * 24 * 30 , __( 'month', 'buddypress' ), __( 'months', 'buddypress' ) ),
1407
+ array( 60 * 60 * 24 * 7, __( 'week', 'buddypress' ), __( 'weeks', 'buddypress' ) ),
1408
+ array( 60 * 60 * 24 , __( 'day', 'buddypress' ), __( 'days', 'buddypress' ) ),
1409
+ array( 60 * 60 , __( 'hour', 'buddypress' ), __( 'hours', 'buddypress' ) ),
1410
+ array( 60 , __( 'minute', 'buddypress' ), __( 'minutes', 'buddypress' ) ),
1411
+ array( 1, __( 'second', 'buddypress' ), __( 'seconds', 'buddypress' ) )
1412
+ );
1413
+
1414
+ if ( !is_numeric( $older_date ) ) {
1415
+ $time_chunks = explode( ':', str_replace( ' ', ':', $older_date ) );
1416
+ $date_chunks = explode( '-', str_replace( ' ', '-', $older_date ) );
1417
+
1418
+ $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] );
1419
+ }
1420
+
1421
+ /* $newer_date will equal false if we want to know the time elapsed between a date and the current time */
1422
+ /* $newer_date will have a value if we want to work out time elapsed between two known dates */
1423
+ $newer_date = ( !$newer_date ) ? gmmktime( gmdate( 'H' ), gmdate( 'i' ), gmdate( 's' ), gmdate( 'n' ), gmdate( 'j' ), gmdate( 'Y' ) ) : $newer_date;
1424
+
1425
+ /* Difference in seconds */
1426
+ $since = $newer_date - $older_date;
1427
+
1428
+ /* Something went wrong with date calculation and we ended up with a negative date. */
1429
+ if ( 0 > $since )
1430
+ return __( 'sometime', 'buddypress' );
1431
+
1432
+ /**
1433
+ * We only want to output two chunks of time here, eg:
1434
+ * x years, xx months
1435
+ * x days, xx hours
1436
+ * so there's only two bits of calculation below:
1437
+ */
1438
+
1439
+ /* Step one: the first chunk */
1440
+ for ( $i = 0, $j = count($chunks); $i < $j; $i++) {
1441
+ $seconds = $chunks[$i][0];
1442
+
1443
+ /* Finding the biggest chunk (if the chunk fits, break) */
1444
+ if ( ( $count = floor($since / $seconds) ) != 0 )
1445
+ break;
1446
+ }
1447
+
1448
+ /* Set output var */
1449
+ $output = ( 1 == $count ) ? '1 '. $chunks[$i][1] : $count . ' ' . $chunks[$i][2];
1450
+
1451
+ /* Step two: the second chunk */
1452
+ if ( $i + 2 < $j ) {
1453
+ $seconds2 = $chunks[$i + 1][0];
1454
+ $name2 = $chunks[$i + 1][1];
1455
+
1456
+ if ( ( $count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 ) ) != 0 ) {
1457
+ /* Add to output var */
1458
+ $output .= ( 1 == $count2 ) ? _c( ',|Separator in time since', 'buddypress' ) . ' 1 '. $chunks[$i + 1][1] : _c( ',|Separator in time since', 'buddypress' ) . ' ' . $count2 . ' ' . $chunks[$i + 1][2];
1459
+ }
1460
+ }
1461
+
1462
+ if ( !(int)trim($output) )
1463
+ $output = '0 ' . __( 'seconds', 'buddypress' );
1464
+
1465
+ return $output;
1466
+ }
1467
+
1468
+
1469
+ /**
1470
+ * bp_core_record_activity()
1471
+ *
1472
+ * Record user activity to the database. Many functions use a "last active" feature to
1473
+ * show the length of time since the user was last active.
1474
+ * This function will update that time as a usermeta setting for the user every 5 minutes.
1475
+ *
1476
+ * @package BuddyPress Core
1477
+ * @global $userdata WordPress user data for the current logged in user.
1478
+ * @uses update_usermeta() WordPress function to update user metadata in the usermeta table.
1479
+ */
1480
+ function bp_core_record_activity() {
1481
+ global $bp;
1482
+
1483
+ if ( !is_user_logged_in() )
1484
+ return false;
1485
+
1486
+ $activity = get_usermeta( $bp->loggedin_user->id, 'last_activity' );
1487
+
1488
+ if ( !is_numeric( $activity ) )
1489
+ $activity = strtotime( $activity );
1490
+
1491
+ if ( '' == $activity || strtotime( gmdate( "Y-m-d H:i:s" ) ) >= strtotime( '+5 minutes', $activity ) )
1492
+ update_usermeta( $bp->loggedin_user->id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
1493
+ }
1494
+ add_action( 'wp_head', 'bp_core_record_activity' );
1495
+
1496
+
1497
+ /**
1498
+ * bp_core_get_last_activity()
1499
+ *
1500
+ * Formats last activity based on time since date given.
1501
+ *
1502
+ * @package BuddyPress Core
1503
+ * @param last_activity_date The date of last activity.
1504
+ * @param $before The text to prepend to the activity time since figure.
1505
+ * @param $after The text to append to the activity time since figure.
1506
+ * @uses bp_core_time_since() This function will return an English representation of the time elapsed.
1507
+ */
1508
+ function bp_core_get_last_activity( $last_activity_date, $string ) {
1509
+ if ( !$last_activity_date || empty( $last_activity_date ) ) {
1510
+ $last_active = __( 'not recently active', 'buddypress' );
1511
+ } else {
1512
+ $last_active = sprintf( $string, bp_core_time_since( $last_activity_date ) );
1513
+ }
1514
+
1515
+ return apply_filters( 'bp_core_get_last_activity', $last_active, $last_activity_date, $string );
1516
+ }
1517
+
1518
+ function bp_core_number_format( $number, $decimals = false ) {
1519
+ /* Check we actually have a number first. */
1520
+ if ( empty( $number ) )
1521
+ return $number;
1522
+
1523
+ return apply_filters( 'bp_core_number_format', number_format( $number, $decimals ), $number, $decimals );
1524
+ }
1525
+
1526
+ /**
1527
+ * bp_core_get_all_posts_for_user()
1528
+ *
1529
+ * Fetch every post that is authored by the given user for the current blog.
1530
+ *
1531
+ * @package BuddyPress Core
1532
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
1533
+ * @global $wpdb WordPress user data for the current logged in user.
1534
+ * @return array of post ids.
1535
+ */
1536
+ function bp_core_get_all_posts_for_user( $user_id = null ) {
1537
+ global $bp, $wpdb;
1538
+
1539
+ if ( !$user_id )
1540
+ $user_id = $bp->displayed_user->id;
1541
+
1542
+ 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 ) ) );
1543
+ }
1544
+
1545
+ /**
1546
+ * bp_core_get_site_path()
1547
+ *
1548
+ * Get the path of of the current site.
1549
+ *
1550
+ * @package BuddyPress Core
1551
+ * @global $comment WordPress comment global for the current comment.
1552
+ * @uses bp_core_get_userlink_by_email() Fetches a userlink via email address.
1553
+ */
1554
+ function bp_core_get_site_path() {
1555
+ global $bp, $current_site;
1556
+
1557
+ if ( bp_core_is_multisite() )
1558
+ $site_path = $current_site->path;
1559
+ else {
1560
+ $site_path = (array) explode( '/', site_url() );
1561
+
1562
+ if ( count( $site_path ) < 2 )
1563
+ $site_path = '/';
1564
+ else {
1565
+ /* Unset the first three segments (http(s)://domain.com part) */
1566
+ unset( $site_path[0] );
1567
+ unset( $site_path[1] );
1568
+ unset( $site_path[2] );
1569
+
1570
+ if ( !count( $site_path ) )
1571
+ $site_path = '/';
1572
+ else
1573
+ $site_path = '/' . implode( '/', $site_path ) . '/';
1574
+ }
1575
+ }
1576
+
1577
+ return apply_filters( 'bp_core_get_site_path', $site_path );
1578
+ }
1579
+ /**
1580
+ * bp_core_get_site_options()
1581
+ *
1582
+ * BuddyPress uses site options to store configuration settings. Many of these settings are needed
1583
+ * at run time. Instead of fetching them all and adding many initial queries to each page load, let's fetch
1584
+ * them all in one go.
1585
+ *
1586
+ * @package BuddyPress Core
1587
+ */
1588
+ function bp_core_get_site_options() {
1589
+ global $bp, $wpdb;
1590
+
1591
+ $options = apply_filters( 'bp_core_site_options', array(
1592
+ 'bp-deactivated-components',
1593
+ 'bp-blogs-first-install',
1594
+ 'bp-disable-blog-forum-comments',
1595
+ 'bp-xprofile-base-group-name',
1596
+ 'bp-xprofile-fullname-field-name',
1597
+ 'bp-disable-profile-sync',
1598
+ 'bp-disable-avatar-uploads',
1599
+ 'bp-disable-account-deletion',
1600
+ 'bp-disable-forum-directory',
1601
+ 'bp-disable-blogforum-comments',
1602
+ 'bb-config-location',
1603
+ 'hide-loggedout-adminbar',
1604
+
1605
+ /* Useful WordPress settings used often */
1606
+ 'user-avatar-default',
1607
+ 'tags_blog_id',
1608
+ 'registration',
1609
+ 'fileupload_maxk'
1610
+ ) );
1611
+
1612
+ $meta_keys = "'" . implode( "','", (array)$options ) ."'";
1613
+
1614
+ if ( bp_core_is_multisite() )
1615
+ $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}" );
1616
+ else
1617
+ $meta = $wpdb->get_results( "SELECT option_name AS name, option_value AS value FROM {$wpdb->options} WHERE option_name IN ({$meta_keys})" );
1618
+
1619
+ $site_options = array();
1620
+ if ( !empty( $meta ) ) {
1621
+ foreach( (array)$meta as $meta_item )
1622
+ $site_options[$meta_item->name] = $meta_item->value;
1623
+ }
1624
+
1625
+ return apply_filters( 'bp_core_get_site_options', $site_options );
1626
+ }
1627
+
1628
+ /**
1629
+ * bp_core_redirect()
1630
+ *
1631
+ * Performs a status safe wp_redirect() that is compatible with bp_catch_uri()
1632
+ *
1633
+ * @package BuddyPress Core
1634
+ * @global $bp_no_status_set Makes sure that there are no conflicts with status_header() called in bp_core_do_catch_uri()
1635
+ * @uses get_themes()
1636
+ * @return An array containing all of the themes.
1637
+ */
1638
+ function bp_core_redirect( $location, $status = 302 ) {
1639
+ global $bp_no_status_set;
1640
+
1641
+ // Make sure we don't call status_header() in bp_core_do_catch_uri()
1642
+ // as this conflicts with wp_redirect()
1643
+ $bp_no_status_set = true;
1644
+
1645
+ wp_redirect( $location, $status );
1646
+ die;
1647
+ }
1648
+
1649
+ /**
1650
+ * bp_core_referrer()
1651
+ *
1652
+ * Returns the referrer URL without the http(s)://
1653
+ *
1654
+ * @package BuddyPress Core
1655
+ * @return The referrer URL
1656
+ */
1657
+ function bp_core_referrer() {
1658
+ $referer = explode( '/', wp_get_referer() );
1659
+ unset( $referer[0], $referer[1], $referer[2] );
1660
+ return implode( '/', $referer );
1661
+ }
1662
+
1663
+ /**
1664
+ * bp_core_add_illegal_names()
1665
+ *
1666
+ * Adds illegal names to WP so that root components will not conflict with
1667
+ * blog names on a subdirectory installation.
1668
+ *
1669
+ * For example, it would stop someone creating a blog with the slug "groups".
1670
+ *
1671
+ * @package BuddyPress Core
1672
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
1673
+ */
1674
+ function bp_core_add_illegal_names() {
1675
+ global $bp;
1676
+
1677
+ $current = maybe_unserialize( get_site_option( 'illegal_names' ) );
1678
+ $bp_illegal_names = $bp->root_components;
1679
+
1680
+ if ( is_array( $current ) ) {
1681
+ foreach( (array)$bp_illegal_names as $bp_illegal_name ) {
1682
+ if ( !in_array( $bp_illegal_name, $current ) )
1683
+ $current[] = $bp_illegal_name;
1684
+ }
1685
+ $new = $current;
1686
+ } else {
1687
+ $bp_illegal_names[] = $current;
1688
+ $new = $bp_illegal_names;
1689
+ }
1690
+
1691
+ update_site_option( 'illegal_names', $new );
1692
+ }
1693
+
1694
+ /**
1695
+ * bp_core_delete_account()
1696
+ *
1697
+ * Allows a user to completely remove their account from the system
1698
+ *
1699
+ * @package BuddyPress Core
1700
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
1701
+ * @uses is_site_admin() Checks to see if the user is a site administrator.
1702
+ * @uses wpmu_delete_user() Deletes a user from the system on multisite installs.
1703
+ * @uses wp_delete_user() Deletes a user from the system on singlesite installs.
1704
+ * @uses get_site_option Checks if account deletion is allowed
1705
+ */
1706
+ function bp_core_delete_account( $user_id = false ) {
1707
+ global $bp, $wpdb, $wp_version;
1708
+
1709
+ if ( !$user_id )
1710
+ $user_id = $bp->loggedin_user->id;
1711
+
1712
+ /* Make sure account deletion is not disabled */
1713
+ if ( (int)get_site_option( 'bp-disable-account-deletion' ) )
1714
+ return false;
1715
+
1716
+ /* Site admins cannot be deleted */
1717
+ if ( is_site_admin( bp_core_get_username( $user_id ) ) )
1718
+ return false;
1719
+
1720
+ /* Specifically handle multi-site environment */
1721
+ if ( bp_core_is_multisite() ) {
1722
+ if ( $wp_version >= '3.0' )
1723
+ require_once( ABSPATH . '/wp-admin/includes/ms.php' );
1724
+ else
1725
+ require_once( ABSPATH . '/wp-admin/includes/mu.php' );
1726
+
1727
+ require_once( ABSPATH . '/wp-admin/includes/user.php' );
1728
+
1729
+ return wpmu_delete_user( $user_id );
1730
+
1731
+ /* Single site user deletion */
1732
+ } else {
1733
+ require_once( ABSPATH . '/wp-admin/includes/user.php' );
1734
+ return wp_delete_user( $user_id );
1735
+ }
1736
+ }
1737
+
1738
+
1739
+ /**
1740
+ * bp_core_search_site()
1741
+ *
1742
+ * A javascript free implementation of the search functions in BuddyPress
1743
+ *
1744
+ * @package BuddyPress Core
1745
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
1746
+ * @param $slug The slug to redirect to for searching.
1747
+ */
1748
+ function bp_core_action_search_site( $slug = false ) {
1749
+ global $bp;
1750
+
1751
+ if ( $bp->current_component == BP_SEARCH_SLUG ) {
1752
+ $search_terms = $_POST['search-terms'];
1753
+ $search_which = $_POST['search-which'];
1754
+
1755
+ if ( !$slug || empty( $slug ) ) {
1756
+ switch ( $search_which ) {
1757
+ case 'members': default:
1758
+ $slug = BP_MEMBERS_SLUG;
1759
+ $var = '/?s=';
1760
+ break;
1761
+ case 'groups':
1762
+ $slug = BP_GROUPS_SLUG;
1763
+ $var = '/?s=';
1764
+ break;
1765
+ case 'forums':
1766
+ $slug = BP_FORUMS_SLUG;
1767
+ $var = '/?fs=';
1768
+ break;
1769
+ case 'blogs':
1770
+ $slug = BP_BLOGS_SLUG;
1771
+ $var = '/?s=';
1772
+ break;
1773
+ }
1774
+ }
1775
+
1776
+ $search_url = apply_filters( 'bp_core_search_site', site_url( $slug . $var . urlencode($search_terms) ), $search_terms );
1777
+
1778
+ bp_core_redirect( $search_url );
1779
+ }
1780
+ }
1781
+ add_action( 'init', 'bp_core_action_search_site', 5 );
1782
+
1783
+
1784
+ /**
1785
+ * bp_core_ucfirst()
1786
+ *
1787
+ * Localization safe ucfirst() support.
1788
+ *
1789
+ * @package BuddyPress Core
1790
+ */
1791
+ function bp_core_ucfirst( $str ) {
1792
+ if ( function_exists( 'mb_strtoupper' ) && function_exists( 'mb_substr' ) ) {
1793
+ $fc = mb_strtoupper( mb_substr( $str, 0, 1 ) );
1794
+ return $fc.mb_substr( $str, 1 );
1795
+ } else {
1796
+ return ucfirst( $str );
1797
+ }
1798
+ }
1799
+
1800
+
1801
+ /**
1802
+ * bp_core_strip_username_spaces()
1803
+ *
1804
+ * Strips spaces from usernames that are created using add_user() and wp_insert_user()
1805
+ *
1806
+ * @package BuddyPress Core
1807
+ */
1808
+ function bp_core_strip_username_spaces( $username ) {
1809
+ return str_replace( ' ', '-', $username );
1810
+ }
1811
+ add_action( 'pre_user_login', 'bp_core_strip_username_spaces' );
1812
+
1813
+
1814
+ /**
1815
+ * bp_core_clear_cache()
1816
+ * REQUIRES WP-SUPER-CACHE
1817
+ *
1818
+ * When wp-super-cache is installed this function will clear cached pages
1819
+ * so that success/error messages are not cached, or time sensitive content.
1820
+ *
1821
+ * @package BuddyPress Core
1822
+ */
1823
+ function bp_core_clear_cache() {
1824
+ global $cache_path, $cache_filename;
1825
+
1826
+ if ( function_exists( 'prune_super_cache' ) ) {
1827
+ do_action( 'bp_core_clear_cache' );
1828
+
1829
+ return prune_super_cache( $cache_path, true );
1830
+ }
1831
+ }
1832
+
1833
+ /**
1834
+ * bp_core_print_generation_time()
1835
+ *
1836
+ * Prints the generation time in the footer of the site.
1837
+ *
1838
+ * @package BuddyPress Core
1839
+ */
1840
+ function bp_core_print_generation_time() {
1841
+ global $wpdb;
1842
+ ?>
1843
+
1844
+ <!-- Generated in <?php timer_stop(1); ?> seconds. -->
1845
+
1846
+ <?php
1847
+ }
1848
+ add_action( 'wp_footer', 'bp_core_print_generation_time' );
1849
+
1850
+ /**
1851
+ * bp_core_add_admin_menu_page()
1852
+ *
1853
+ * A better version of add_admin_menu_page() that allows positioning of menus.
1854
+ *
1855
+ * @package BuddyPress Core
1856
+ */
1857
+ function bp_core_add_admin_menu_page( $args = '' ) {
1858
+ global $menu, $admin_page_hooks, $_registered_pages;
1859
+
1860
+ $defaults = array(
1861
+ 'page_title' => '',
1862
+ 'menu_title' => '',
1863
+ 'access_level' => 2,
1864
+ 'file' => false,
1865
+ 'function' => false,
1866
+ 'icon_url' => false,
1867
+ 'position' => 100
1868
+ );
1869
+
1870
+ $r = wp_parse_args( $args, $defaults );
1871
+ extract( $r, EXTR_SKIP );
1872
+
1873
+ $file = plugin_basename( $file );
1874
+
1875
+ $admin_page_hooks[$file] = sanitize_title( $menu_title );
1876
+
1877
+ $hookname = get_plugin_page_hookname( $file, '' );
1878
+ if (!empty ( $function ) && !empty ( $hookname ))
1879
+ add_action( $hookname, $function );
1880
+
1881
+ if ( empty($icon_url) )
1882
+ $icon_url = 'images/generic.png';
1883
+ elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') )
1884
+ $icon_url = 'https://' . substr($icon_url, 7);
1885
+
1886
+ do {
1887
+ $position++;
1888
+ } while ( !empty( $menu[$position] ) );
1889
+
1890
+ $menu[$position] = array ( $menu_title, $access_level, $file, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url );
1891
+
1892
+ $_registered_pages[$hookname] = true;
1893
+
1894
+ return $hookname;
1895
+ }
1896
+
1897
+ /**
1898
+ * bp_core_boot_spammer()
1899
+ *
1900
+ * When a user logs in, check if they have been marked as a spammer. If yes then simply
1901
+ * redirect them to the home page and stop them from logging in.
1902
+ *
1903
+ * @package BuddyPress Core
1904
+ * @param $auth_obj The WP authorization object
1905
+ * @param $username The username of the user logging in.
1906
+ * @uses get_userdatabylogin() Get the userdata object for a user based on their username
1907
+ * @uses bp_core_redirect() Safe redirect to a page
1908
+ * @return $auth_obj If the user is not a spammer, return the authorization object
1909
+ */
1910
+ function bp_core_boot_spammer( $auth_obj, $username ) {
1911
+ global $bp;
1912
+
1913
+ $user = get_userdatabylogin( $username );
1914
+
1915
+ if ( ( bp_core_is_multisite() && (int)$user->spam ) || 1 == (int)$user->user_status )
1916
+ bp_core_redirect( $bp->root_domain );
1917
+ else
1918
+ return $auth_obj;
1919
+ }
1920
+ add_filter( 'authenticate', 'bp_core_boot_spammer', 11, 2 );
1921
+
1922
+ /**
1923
+ * bp_core_remove_data()
1924
+ *
1925
+ * Deletes usermeta for the user when the user is deleted.
1926
+ *
1927
+ * @package BuddyPress Core
1928
+ * @param $user_id The user id for the user to delete usermeta for
1929
+ * @uses delete_usermeta() deletes a row from the wp_usermeta table based on meta_key
1930
+ */
1931
+ function bp_core_remove_data( $user_id ) {
1932
+ /* Remove usermeta */
1933
+ delete_usermeta( $user_id, 'last_activity' );
1934
+
1935
+ /* Flush the cache to remove the user from all cached objects */
1936
+ wp_cache_flush();
1937
+ }
1938
+ add_action( 'wpmu_delete_user', 'bp_core_remove_data' );
1939
+ add_action( 'delete_user', 'bp_core_remove_data' );
1940
+ add_action( 'make_spam_user', 'bp_core_remove_data' );
1941
+
1942
+ /**
1943
+ * bp_load_buddypress_textdomain()
1944
+ *
1945
+ * Load the buddypress translation file for current language
1946
+ *
1947
+ * @package BuddyPress Core
1948
+ */
1949
+ function bp_core_load_buddypress_textdomain() {
1950
+ $locale = apply_filters( 'buddypress_locale', get_locale() );
1951
+ $mofile = BP_PLUGIN_DIR . "/bp-languages/buddypress-$locale.mo";
1952
+
1953
+ if ( file_exists( $mofile ) )
1954
+ load_textdomain( 'buddypress', $mofile );
1955
+ }
1956
+ add_action ( 'bp_loaded', 'bp_core_load_buddypress_textdomain', 2 );
1957
+
1958
+ function bp_core_add_ajax_hook() {
1959
+ /* Theme only, we already have the wp_ajax_ hook firing in wp-admin */
1960
+ if ( !defined( 'WP_ADMIN' ) )
1961
+ do_action( 'wp_ajax_' . $_REQUEST['action'] );
1962
+ }
1963
+ add_action( 'init', 'bp_core_add_ajax_hook' );
1964
+
1965
+ /**
1966
+ * bp_core_update_message()
1967
+ *
1968
+ * Add an extra update message to the update plugin notification.
1969
+ *
1970
+ * @package BuddyPress Core
1971
+ */
1972
+ function bp_core_update_message() {
1973
+ 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>';
1974
+ }
1975
+ add_action( 'in_plugin_update_message-buddypress/bp-loader.php', 'bp_core_update_message' );
1976
+
1977
+ /**
1978
+ * bp_core_activation_notice()
1979
+ *
1980
+ * When BuddyPress is activated we must make sure that mod_rewrite is enabled.
1981
+ * We must also make sure a BuddyPress compatible theme is enabled. This function
1982
+ * will show helpful messages to the administrator.
1983
+ *
1984
+ * @package BuddyPress Core
1985
+ */
1986
+ function bp_core_activation_notice() {
1987
+ global $wp_rewrite, $current_blog, $bp;
1988
+
1989
+ if ( isset( $_POST['permalink_structure'] ) )
1990
+ return false;
1991
+
1992
+ if ( !is_site_admin() )
1993
+ return false;
1994
+
1995
+ if ( !empty( $current_blog ) ) {
1996
+ if ( $current_blog->blog_id != BP_ROOT_BLOG )
1997
+ return false;
1998
+ }
1999
+
2000
+ if ( empty( $wp_rewrite->permalink_structure ) ) { ?>
2001
+ <div id="message" class="updated fade">
2002
+ <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>
2003
+ </div><?php
2004
+ } else {
2005
+ /* Get current theme info */
2006
+ $ct = current_theme_info();
2007
+
2008
+ /* The best way to remove this notice is to add a "buddypress" tag to your active theme's CSS header. */
2009
+ if ( !defined( 'BP_SILENCE_THEME_NOTICE' ) && !in_array( 'buddypress', (array)$ct->tags ) ) { ?>
2010
+ <div id="message" class="updated fade">
2011
+ <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>
2012
+ </div><?php
2013
+ }
2014
+ }
2015
+ }
2016
+ add_action( 'admin_notices', 'bp_core_activation_notice' );
2017
+
2018
+ /**
2019
+ * bp_core_activate_site_options()
2020
+ *
2021
+ * When switching from single to multisite we need to copy blog options to
2022
+ * site options.
2023
+ *
2024
+ * @package BuddyPress Core
2025
+ */
2026
+ function bp_core_activate_site_options( $keys = array() ) {
2027
+ global $bp;
2028
+
2029
+ if ( !empty( $keys ) && is_array( $keys ) ) {
2030
+ $errors = false;
2031
+
2032
+ foreach ( $keys as $key => $default ) {
2033
+ if ( empty( $bp->site_options[ $key ] ) ) {
2034
+ $bp->site_options[ $key ] = get_blog_option( BP_ROOT_BLOG, $key, $default );
2035
+
2036
+ if ( !update_site_option( $key, $bp->site_options[ $key ] ) )
2037
+ $errors = true;
2038
+ }
2039
+ }
2040
+
2041
+ if ( empty( $errors ) )
2042
+ return true;
2043
+ }
2044
+
2045
+ return false;
2046
+ }
2047
+
2048
+ /********************************************************************************
2049
+ * Custom Actions
2050
+ *
2051
+ * Functions to set up custom BuddyPress actions that all other components can
2052
+ * hook in to.
2053
+ */
2054
+
2055
+ /**
2056
+ * bp_include()
2057
+ *
2058
+ * Allow plugins to include their files ahead of core filters
2059
+ */
2060
+ function bp_include() {
2061
+ do_action( 'bp_include' );
2062
+ }
2063
+ add_action( 'bp_loaded', 'bp_include', 2 );
2064
+
2065
+ /**
2066
+ * bp_setup_root_components()
2067
+ *
2068
+ * Allow core components and dependent plugins to set root components
2069
+ */
2070
+ function bp_setup_root_components() {
2071
+ do_action( 'bp_setup_root_components' );
2072
+ }
2073
+ add_action( 'bp_loaded', 'bp_setup_root_components', 2 );
2074
+
2075
+ /**
2076
+ * bp_setup_globals()
2077
+ *
2078
+ * Allow core components and dependent plugins to set globals
2079
+ */
2080
+ function bp_setup_globals() {
2081
+ do_action( 'bp_setup_globals' );
2082
+ }
2083
+ add_action( 'bp_loaded', 'bp_setup_globals', 6 );
2084
+
2085
+ /**
2086
+ * bp_setup_nav()
2087
+ *
2088
+ * Allow core components and dependent plugins to set their nav
2089
+ */
2090
+ function bp_setup_nav() {
2091
+ do_action( 'bp_setup_nav' );
2092
+ }
2093
+ add_action( 'bp_loaded', 'bp_setup_nav', 8 );
2094
+
2095
+ /**
2096
+ * bp_setup_widgets()
2097
+ *
2098
+ * Allow core components and dependent plugins to register widgets
2099
+ */
2100
+ function bp_setup_widgets() {
2101
+ do_action( 'bp_register_widgets' );
2102
+ }
2103
+ add_action( 'bp_loaded', 'bp_setup_widgets', 8 );
2104
+
2105
+ /**
2106
+ * bp_init()
2107
+ *
2108
+ * Allow components to initialize themselves cleanly
2109
+ */
2110
+ function bp_init() {
2111
+ do_action( 'bp_init' );
2112
+ }
2113
+ add_action( 'bp_loaded', 'bp_init' );
2114
+
2115
+ /********************************************************************************
2116
+ * Caching
2117
+ *
2118
+ * Caching functions handle the clearing of cached objects and pages on specific
2119
+ * actions throughout BuddyPress.
2120
+ */
2121
+
2122
+ /**
2123
+ * bp_core_clear_user_object_cache()
2124
+ *
2125
+ * Clears all cached objects for a user, or a user is part of.
2126
+ *
2127
+ * @package BuddyPress Core
2128
+ */
2129
+ function bp_core_clear_user_object_cache( $user_id ) {
2130
+ wp_cache_delete( 'bp_user_' . $user_id, 'bp' );
2131
+ wp_cache_delete( 'bp_core_avatar_v1_u' . $user_id, 'bp' );
2132
+ wp_cache_delete( 'bp_core_avatar_v2_u' . $user_id, 'bp' );
2133
+ wp_cache_delete( 'online_users' );
2134
+ wp_cache_delete( 'newest_users' );
2135
+ }
2136
+
2137
+ // List actions to clear super cached pages on, if super cache is installed
2138
+ add_action( 'wp_login', 'bp_core_clear_cache' );
2139
+ add_action( 'bp_core_render_notice', 'bp_core_clear_cache' );
2140
+
2141
+ // Remove the catch non existent blogs hook so WPMU doesn't think BuddyPress pages are non existing blogs
2142
+ remove_action( 'plugins_loaded', 'catch_nonexistant_blogs' );
2143
+
2144
  ?>
bp-core/bp-core-admin.php CHANGED
@@ -1,251 +1,251 @@
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"><?php _e( 'Base profile group name', 'buddypress' ) ?>:</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"><?php _e( 'Full Name field name', 'buddypress' ) ?>:</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"><?php _e( 'Disable BuddyPress to WordPress profile syncing?', 'buddypress' ) ?>:</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"><?php _e( 'Hide admin bar for logged out users?', 'buddypress' ) ?>:</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"><?php _e( 'Disable avatar uploads? (Gravatars will still work)', 'buddypress' ) ?>:</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"><?php _e( 'Disable user account deletion?', 'buddypress' ) ?>:</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"><?php _e( 'Disable global forum directory?', 'buddypress' ) ?>:</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"><?php _e( 'Disable activity stream commenting on blog and forum posts?', 'buddypress' ) ?>:</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"><?php _e( 'Default User Avatar', 'buddypress' ) ?></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( $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( $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( $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( $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
  ?>
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"><?php _e( 'Base profile group name', 'buddypress' ) ?>:</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"><?php _e( 'Full Name field name', 'buddypress' ) ?>:</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"><?php _e( 'Disable BuddyPress to WordPress profile syncing?', 'buddypress' ) ?>:</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"><?php _e( 'Hide admin bar for logged out users?', 'buddypress' ) ?>:</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"><?php _e( 'Disable avatar uploads? (Gravatars will still work)', 'buddypress' ) ?>:</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"><?php _e( 'Disable user account deletion?', 'buddypress' ) ?>:</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"><?php _e( 'Disable global forum directory?', 'buddypress' ) ?>:</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"><?php _e( 'Disable activity stream commenting on blog and forum posts?', 'buddypress' ) ?>:</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"><?php _e( 'Default User Avatar', 'buddypress' ) ?></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,258 +1,258 @@
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
-
53
- // **** "My Account" Menu ******
54
- function bp_adminbar_account_menu() {
55
- global $bp;
56
-
57
- if ( !$bp->bp_nav || !is_user_logged_in() )
58
- return false;
59
-
60
- echo '<li id="bp-adminbar-account-menu"><a href="' . bp_loggedin_user_domain() . '">';
61
-
62
- echo __( 'My Account', 'buddypress' ) . '</a>';
63
- echo '<ul>';
64
-
65
- /* Loop through each navigation item */
66
- $counter = 0;
67
- foreach( (array)$bp->bp_nav as $nav_item ) {
68
- $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
69
-
70
- echo '<li' . $alt . '>';
71
- echo '<a id="bp-admin-' . $nav_item['css_id'] . '" href="' . $nav_item['link'] . '">' . $nav_item['name'] . '</a>';
72
-
73
- if ( is_array( $bp->bp_options_nav[$nav_item['slug']] ) ) {
74
- echo '<ul>';
75
- $sub_counter = 0;
76
-
77
- foreach( (array)$bp->bp_options_nav[$nav_item['slug']] as $subnav_item ) {
78
- $link = str_replace( $bp->displayed_user->domain, $bp->loggedin_user->domain, $subnav_item['link'] );
79
- $name = str_replace( $bp->displayed_user->userdata->user_login, $bp->loggedin_user->userdata->user_login, $subnav_item['name'] );
80
- $alt = ( 0 == $sub_counter % 2 ) ? ' class="alt"' : '';
81
- echo '<li' . $alt . '><a id="bp-admin-' . $subnav_item['css_id'] . '" href="' . $link . '">' . $name . '</a></li>';
82
- $sub_counter++;
83
- }
84
- echo '</ul>';
85
- }
86
-
87
- echo '</li>';
88
-
89
- $counter++;
90
- }
91
-
92
- $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
93
-
94
- echo '<li' . $alt . '><a id="bp-admin-logout" class="logout" href="' . wp_logout_url( site_url() ) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';
95
- echo '</ul>';
96
- echo '</li>';
97
- }
98
-
99
- // *** "My Blogs" Menu ********
100
- function bp_adminbar_blogs_menu() {
101
- global $bp;
102
-
103
- if ( !is_user_logged_in() || !function_exists('bp_blogs_install') )
104
- return false;
105
-
106
- if ( !$blogs = wp_cache_get( 'bp_blogs_of_user_' . $bp->loggedin_user->id . '_inc_hidden', 'bp' ) ) {
107
- $blogs = bp_blogs_get_blogs_for_user( $bp->loggedin_user->id, true );
108
- wp_cache_set( 'bp_blogs_of_user_' . $bp->loggedin_user->id . '_inc_hidden', $blogs, 'bp' );
109
- }
110
-
111
- echo '<li id="bp-adminbar-blogs-menu"><a href="' . $bp->loggedin_user->domain . $bp->blogs->slug . '/my-blogs">';
112
-
113
- _e( 'My Blogs', 'buddypress' );
114
-
115
- echo '</a>';
116
- echo '<ul>';
117
-
118
- if ( is_array( $blogs['blogs'] ) && (int)$blogs['count'] ) {
119
- $counter = 0;
120
- foreach ( (array)$blogs['blogs'] as $blog ) {
121
- $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
122
- $site_url = esc_attr( $blog->siteurl );
123
-
124
- echo '<li' . $alt . '>';
125
- echo '<a href="' . $site_url . '">' . esc_html( $blog->name ) . '</a>';
126
-
127
- echo '<ul>';
128
- echo '<li class="alt"><a href="' . $site_url . 'wp-admin/">' . __( 'Dashboard', 'buddypress' ) . '</a></li>';
129
- echo '<li><a href="' . $site_url . 'wp-admin/post-new.php">' . __( 'New Post', 'buddypress' ) . '</a></li>';
130
- echo '<li class="alt"><a href="' . $site_url . 'wp-admin/edit.php">' . __( 'Manage Posts', 'buddypress' ) . '</a></li>';
131
- echo '<li><a href="' . $site_url . 'wp-admin/edit-comments.php">' . __( 'Manage Comments', 'buddypress' ) . '</a></li>';
132
- echo '</ul>';
133
-
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
- // **** "Notifications" Menu *********
152
- function bp_adminbar_notifications_menu() {
153
- global $bp;
154
-
155
- if ( !is_user_logged_in() )
156
- return false;
157
-
158
- echo '<li id="bp-adminbar-notifications-menu"><a href="' . $bp->loggedin_user->domain . '">';
159
- _e( 'Notifications', 'buddypress' );
160
-
161
- if ( $notifications = bp_core_get_notifications_for_user( $bp->loggedin_user->id ) ) { ?>
162
- <span><?php echo count($notifications) ?></span>
163
- <?php
164
- }
165
-
166
- echo '</a>';
167
- echo '<ul>';
168
-
169
- if ( $notifications ) { ?>
170
- <?php $counter = 0; ?>
171
- <?php for ( $i = 0; $i < count($notifications); $i++ ) { ?>
172
- <?php $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : ''; ?>
173
- <li<?php echo $alt ?>><?php echo $notifications[$i] ?></li>
174
- <?php $counter++; ?>
175
- <?php } ?>
176
- <?php } else { ?>
177
- <li><a href="<?php echo $bp->loggedin_user->domain ?>"><?php _e( 'No new notifications.', 'buddypress' ); ?></a></li>
178
- <?php
179
- }
180
-
181
- echo '</ul>';
182
- echo '</li>';
183
- }
184
-
185
- // **** "Blog Authors" Menu (visible when not logged in) ********
186
- function bp_adminbar_authors_menu() {
187
- global $bp, $current_blog, $wpdb;
188
-
189
- if ( $current_blog->blog_id == BP_ROOT_BLOG || !function_exists( 'bp_blogs_install' ) )
190
- return false;
191
-
192
- $blog_prefix = $wpdb->get_blog_prefix( $current_blog->id );
193
- $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" );
194
-
195
- if ( !empty( $authors ) ) {
196
- /* This is a blog, render a menu with links to all authors */
197
- echo '<li id="bp-adminbar-authors-menu"><a href="/">';
198
- _e('Blog Authors', 'buddypress');
199
- echo '</a>';
200
-
201
- echo '<ul class="author-list">';
202
- foreach( (array)$authors as $author ) {
203
- $caps = maybe_unserialize( $author->caps );
204
- if ( isset( $caps['subscriber'] ) || isset( $caps['contributor'] ) ) continue;
205
-
206
- echo '<li>';
207
- echo '<a href="' . bp_core_get_user_domain( $author->user_id, $author->user_nicename, $author->user_login ) . '">';
208
- echo bp_core_fetch_avatar( array( 'item_id' => $author->user_id, 'email' => $author->user_email, 'width' => 15, 'height' => 15 ) ) ;
209
- echo ' ' . $author->display_name . '</a>';
210
- echo '<div class="admin-bar-clear"></div>';
211
- echo '</li>';
212
- }
213
- echo '</ul>';
214
- echo '</li>';
215
- }
216
- }
217
-
218
- // **** "Random" Menu (visible when not logged in) ********
219
- function bp_adminbar_random_menu() {
220
- global $bp; ?>
221
- <li class="align-right" id="bp-adminbar-visitrandom-menu">
222
- <a href="#"><?php _e( 'Visit', 'buddypress' ) ?></a>
223
- <ul class="random-list">
224
- <li><a href="<?php echo $bp->root_domain . '/' . BP_MEMBERS_SLUG . '/?random-member' ?>"><?php _e( 'Random Member', 'buddypress' ) ?></a></li>
225
-
226
- <?php if ( function_exists('groups_install') ) : ?>
227
- <li class="alt"><a href="<?php echo $bp->root_domain . '/' . $bp->groups->slug . '/?random-group' ?>"><?php _e( 'Random Group', 'buddypress' ) ?></a></li>
228
- <?php endif; ?>
229
-
230
- <?php if ( function_exists('bp_blogs_install') && bp_core_is_multisite() ) : ?>
231
- <li><a href="<?php echo $bp->root_domain . '/' . $bp->blogs->slug . '/?random-blog' ?>"><?php _e( 'Random Blog', 'buddypress' ) ?></a></li>
232
-
233
- <?php endif; ?>
234
-
235
- <?php do_action( 'bp_adminbar_random_menu' ) ?>
236
- </ul>
237
- </li>
238
- <?php
239
- }
240
-
241
- add_action( 'bp_adminbar_logo', 'bp_adminbar_logo' );
242
- add_action( 'bp_adminbar_menus', 'bp_adminbar_login_menu', 2 );
243
- add_action( 'bp_adminbar_menus', 'bp_adminbar_account_menu', 4 );
244
-
245
- if ( bp_core_is_multisite() )
246
- add_action( 'bp_adminbar_menus', 'bp_adminbar_blogs_menu', 6 );
247
-
248
- add_action( 'bp_adminbar_menus', 'bp_adminbar_notifications_menu', 8 );
249
-
250
- if ( bp_core_is_multisite() )
251
- add_action( 'bp_adminbar_menus', 'bp_adminbar_authors_menu', 12 );
252
-
253
- add_action( 'bp_adminbar_menus', 'bp_adminbar_random_menu', 100 );
254
-
255
- add_action( 'wp_footer', 'bp_core_admin_bar', 8 );
256
- add_action( 'admin_footer', 'bp_core_admin_bar' );
257
-
258
  ?>
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
+
53
+ // **** "My Account" Menu ******
54
+ function bp_adminbar_account_menu() {
55
+ global $bp;
56
+
57
+ if ( !$bp->bp_nav || !is_user_logged_in() )
58
+ return false;
59
+
60
+ echo '<li id="bp-adminbar-account-menu"><a href="' . bp_loggedin_user_domain() . '">';
61
+
62
+ echo __( 'My Account', 'buddypress' ) . '</a>';
63
+ echo '<ul>';
64
+
65
+ /* Loop through each navigation item */
66
+ $counter = 0;
67
+ foreach( (array)$bp->bp_nav as $nav_item ) {
68
+ $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
69
+
70
+ echo '<li' . $alt . '>';
71
+ echo '<a id="bp-admin-' . $nav_item['css_id'] . '" href="' . $nav_item['link'] . '">' . $nav_item['name'] . '</a>';
72
+
73
+ if ( is_array( $bp->bp_options_nav[$nav_item['slug']] ) ) {
74
+ echo '<ul>';
75
+ $sub_counter = 0;
76
+
77
+ foreach( (array)$bp->bp_options_nav[$nav_item['slug']] as $subnav_item ) {
78
+ $link = str_replace( $bp->displayed_user->domain, $bp->loggedin_user->domain, $subnav_item['link'] );
79
+ $name = str_replace( $bp->displayed_user->userdata->user_login, $bp->loggedin_user->userdata->user_login, $subnav_item['name'] );
80
+ $alt = ( 0 == $sub_counter % 2 ) ? ' class="alt"' : '';
81
+ echo '<li' . $alt . '><a id="bp-admin-' . $subnav_item['css_id'] . '" href="' . $link . '">' . $name . '</a></li>';
82
+ $sub_counter++;
83
+ }
84
+ echo '</ul>';
85
+ }
86
+
87
+ echo '</li>';
88
+
89
+ $counter++;
90
+ }
91
+
92
+ $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
93
+
94
+ echo '<li' . $alt . '><a id="bp-admin-logout" class="logout" href="' . wp_logout_url( site_url() ) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';
95
+ echo '</ul>';
96
+ echo '</li>';
97
+ }
98
+
99
+ // *** "My Blogs" Menu ********
100
+ function bp_adminbar_blogs_menu() {
101
+ global $bp;
102
+
103
+ if ( !is_user_logged_in() || !function_exists('bp_blogs_install') )
104
+ return false;
105
+
106
+ if ( !$blogs = wp_cache_get( 'bp_blogs_of_user_' . $bp->loggedin_user->id . '_inc_hidden', 'bp' ) ) {
107
+ $blogs = bp_blogs_get_blogs_for_user( $bp->loggedin_user->id, true );
108
+ wp_cache_set( 'bp_blogs_of_user_' . $bp->loggedin_user->id . '_inc_hidden', $blogs, 'bp' );
109
+ }
110
+
111
+ echo '<li id="bp-adminbar-blogs-menu"><a href="' . $bp->loggedin_user->domain . $bp->blogs->slug . '/my-blogs">';
112
+
113
+ _e( 'My Blogs', 'buddypress' );
114
+
115
+ echo '</a>';
116
+ echo '<ul>';
117
+
118
+ if ( is_array( $blogs['blogs'] ) && (int)$blogs['count'] ) {
119
+ $counter = 0;
120
+ foreach ( (array)$blogs['blogs'] as $blog ) {
121
+ $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
122
+ $site_url = esc_attr( $blog->siteurl );
123
+
124
+ echo '<li' . $alt . '>';
125
+ echo '<a href="' . $site_url . '">' . esc_html( $blog->name ) . '</a>';
126
+
127
+ echo '<ul>';
128
+ echo '<li class="alt"><a href="' . $site_url . 'wp-admin/">' . __( 'Dashboard', 'buddypress' ) . '</a></li>';
129
+ echo '<li><a href="' . $site_url . 'wp-admin/post-new.php">' . __( 'New Post', 'buddypress' ) . '</a></li>';
130
+ echo '<li class="alt"><a href="' . $site_url . 'wp-admin/edit.php">' . __( 'Manage Posts', 'buddypress' ) . '</a></li>';
131
+ echo '<li><a href="' . $site_url . 'wp-admin/edit-comments.php">' . __( 'Manage Comments', 'buddypress' ) . '</a></li>';
132
+ echo '</ul>';
133
+
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
+ // **** "Notifications" Menu *********
152
+ function bp_adminbar_notifications_menu() {
153
+ global $bp;
154
+
155
+ if ( !is_user_logged_in() )
156
+ return false;
157
+
158
+ echo '<li id="bp-adminbar-notifications-menu"><a href="' . $bp->loggedin_user->domain . '">';
159
+ _e( 'Notifications', 'buddypress' );
160
+
161
+ if ( $notifications = bp_core_get_notifications_for_user( $bp->loggedin_user->id ) ) { ?>
162
+ <span><?php echo count($notifications) ?></span>
163
+ <?php
164
+ }
165
+
166
+ echo '</a>';
167
+ echo '<ul>';
168
+
169
+ if ( $notifications ) { ?>
170
+ <?php $counter = 0; ?>
171
+ <?php for ( $i = 0; $i < count($notifications); $i++ ) { ?>
172
+ <?php $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : ''; ?>
173
+ <li<?php echo $alt ?>><?php echo $notifications[$i] ?></li>
174
+ <?php $counter++; ?>
175
+ <?php } ?>
176
+ <?php } else { ?>
177
+ <li><a href="<?php echo $bp->loggedin_user->domain ?>"><?php _e( 'No new notifications.', 'buddypress' ); ?></a></li>
178
+ <?php
179
+ }
180
+
181
+ echo '</ul>';
182
+ echo '</li>';
183
+ }
184
+
185
+ // **** "Blog Authors" Menu (visible when not logged in) ********
186
+ function bp_adminbar_authors_menu() {
187
+ global $bp, $current_blog, $wpdb;
188
+
189
+ if ( $current_blog->blog_id == BP_ROOT_BLOG || !function_exists( 'bp_blogs_install' ) )
190
+ return false;
191
+
192
+ $blog_prefix = $wpdb->get_blog_prefix( $current_blog->id );
193
+ $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" );
194
+
195
+ if ( !empty( $authors ) ) {
196
+ /* This is a blog, render a menu with links to all authors */
197
+ echo '<li id="bp-adminbar-authors-menu"><a href="/">';
198
+ _e('Blog Authors', 'buddypress');
199
+ echo '</a>';
200
+
201
+ echo '<ul class="author-list">';
202
+ foreach( (array)$authors as $author ) {
203
+ $caps = maybe_unserialize( $author->caps );
204
+ if ( isset( $caps['subscriber'] ) || isset( $caps['contributor'] ) ) continue;
205
+
206
+ echo '<li>';
207
+ echo '<a href="' . bp_core_get_user_domain( $author->user_id, $author->user_nicename, $author->user_login ) . '">';
208
+ echo bp_core_fetch_avatar( array( 'item_id' => $author->user_id, 'email' => $author->user_email, 'width' => 15, 'height' => 15 ) ) ;
209
+ echo ' ' . $author->display_name . '</a>';
210
+ echo '<div class="admin-bar-clear"></div>';
211
+ echo '</li>';
212
+ }
213
+ echo '</ul>';
214
+ echo '</li>';
215
+ }
216
+ }
217
+
218
+ // **** "Random" Menu (visible when not logged in) ********
219
+ function bp_adminbar_random_menu() {
220
+ global $bp; ?>
221
+ <li class="align-right" id="bp-adminbar-visitrandom-menu">
222
+ <a href="#"><?php _e( 'Visit', 'buddypress' ) ?></a>
223
+ <ul class="random-list">
224
+ <li><a href="<?php echo $bp->root_domain . '/' . BP_MEMBERS_SLUG . '/?random-member' ?>"><?php _e( 'Random Member', 'buddypress' ) ?></a></li>
225
+
226
+ <?php if ( function_exists('groups_install') ) : ?>
227
+ <li class="alt"><a href="<?php echo $bp->root_domain . '/' . $bp->groups->slug . '/?random-group' ?>"><?php _e( 'Random Group', 'buddypress' ) ?></a></li>
228
+ <?php endif; ?>
229
+
230
+ <?php if ( function_exists('bp_blogs_install') && bp_core_is_multisite() ) : ?>
231
+ <li><a href="<?php echo $bp->root_domain . '/' . $bp->blogs->slug . '/?random-blog' ?>"><?php _e( 'Random Blog', 'buddypress' ) ?></a></li>
232
+
233
+ <?php endif; ?>
234
+
235
+ <?php do_action( 'bp_adminbar_random_menu' ) ?>
236
+ </ul>
237
+ </li>
238
+ <?php
239
+ }
240
+
241
+ add_action( 'bp_adminbar_logo', 'bp_adminbar_logo' );
242
+ add_action( 'bp_adminbar_menus', 'bp_adminbar_login_menu', 2 );
243
+ add_action( 'bp_adminbar_menus', 'bp_adminbar_account_menu', 4 );
244
+
245
+ if ( bp_core_is_multisite() )
246
+ add_action( 'bp_adminbar_menus', 'bp_adminbar_blogs_menu', 6 );
247
+
248
+ add_action( 'bp_adminbar_menus', 'bp_adminbar_notifications_menu', 8 );
249
+
250
+ if ( bp_core_is_multisite() )
251
+ add_action( 'bp_adminbar_menus', 'bp_adminbar_authors_menu', 12 );
252
+
253
+ add_action( 'bp_adminbar_menus', 'bp_adminbar_random_menu', 100 );
254
+
255
+ add_action( 'wp_footer', 'bp_core_admin_bar', 8 );
256
+ add_action( 'admin_footer', 'bp_core_admin_bar' );
257
+
258
  ?>
bp-core/bp-core-avatars.php CHANGED
@@ -1,427 +1,570 @@
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
-
22
- if ( !defined( 'BP_AVATAR_THUMB_HEIGHT' ) )
23
- define( 'BP_AVATAR_THUMB_HEIGHT', 50 );
24
-
25
- if ( !defined( 'BP_AVATAR_FULL_WIDTH' ) )
26
- define( 'BP_AVATAR_FULL_WIDTH', 150 );
27
-
28
- if ( !defined( 'BP_AVATAR_FULL_HEIGHT' ) )
29
- define( 'BP_AVATAR_FULL_HEIGHT', 150 );
30
-
31
- if ( !defined( 'BP_AVATAR_ORIGINAL_MAX_WIDTH' ) )
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
- }
40
-
41
- if ( !defined( 'BP_AVATAR_DEFAULT' ) )
42
- define( 'BP_AVATAR_DEFAULT', BP_PLUGIN_URL . '/bp-xprofile/images/none.gif' );
43
-
44
- if ( !defined( 'BP_AVATAR_DEFAULT_THUMB' ) )
45
- define( 'BP_AVATAR_DEFAULT_THUMB', BP_PLUGIN_URL . '/bp-xprofile/images/none-thumbnail.gif' );
46
- }
47
- add_action( 'bp_init', 'bp_core_set_avatar_constants' );
48
-
49
- function bp_core_fetch_avatar( $args = '' ) {
50
- global $bp, $current_blog;
51
-
52
- $defaults = array(
53
- 'item_id' => false,
54
- 'object' => 'user', // user OR group OR blog OR custom type (if you use filters)
55
- 'type' => 'thumb',
56
- 'avatar_dir' => false,
57
- 'width' => false,
58
- 'height' => false,
59
- 'class' => 'avatar',
60
- 'css_id' => false,
61
- 'alt' => __( 'Avatar Image', 'buddypress' ),
62
- 'email' => false, // Pass the user email (for gravatar) to prevent querying the DB for it
63
- 'no_grav' => false // If there is no avatar found, return false instead of a grav?
64
- );
65
-
66
- $params = wp_parse_args( $args, $defaults );
67
- extract( $params, EXTR_SKIP );
68
-
69
- if ( !$item_id ) {
70
- if ( 'user' == $object )
71
- $item_id = $bp->displayed_user->id;
72
- else if ( 'group' == $object )
73
- $item_id = $bp->groups->current_group->id;
74
- else if ( 'blog' == $object )
75
- $item_id = $current_blog->id;
76
-
77
- $item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object );
78
-
79
- if ( !$item_id ) return false;
80
- }
81
-
82
- if ( !$avatar_dir ) {
83
- if ( 'user' == $object )
84
- $avatar_dir = 'avatars';
85
- else if ( 'group' == $object )
86
- $avatar_dir = 'group-avatars';
87
- else if ( 'blog' == $object )
88
- $avatar_dir = 'blog-avatars';
89
-
90
- $avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object );
91
-
92
- if ( !$avatar_dir ) return false;
93
- }
94
-
95
- /* Add an identifying class to each item */
96
- $class .= ' ' . $object . '-' . $item_id . '-avatar';
97
-
98
- if ( !empty($css_id) )
99
- $css_id = " id='{$css_id}'";
100
-
101
- if ( $width )
102
- $html_width = " width='{$width}'";
103
- else
104
- $html_width = ( 'thumb' == $type ) ? ' width="' . BP_AVATAR_THUMB_WIDTH . '"' : ' width="' . BP_AVATAR_FULL_WIDTH . '"';
105
-
106
- if ( $height )
107
- $html_height = " height='{$height}'";
108
- else
109
- $html_height = ( 'thumb' == $type ) ? ' height="' . BP_AVATAR_THUMB_HEIGHT . '"' : ' height="' . BP_AVATAR_FULL_HEIGHT . '"';
110
-
111
- $avatar_folder_url = apply_filters( 'bp_core_avatar_folder_url', BP_AVATAR_URL . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
112
- $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', BP_AVATAR_UPLOAD_PATH . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
113
-
114
- /****
115
- * Look for uploaded avatar first. Use it if it exists.
116
- * Set the file names to search for, to select the full size
117
- * or thumbnail image.
118
- */
119
- $avatar_name = ( 'full' == $type ) ? '-bpfull' : '-bpthumb';
120
- $legacy_user_avatar_name = ( 'full' == $type ) ? '-avatar2' : '-avatar1';
121
- $legacy_group_avatar_name = ( 'full' == $type ) ? '-groupavatar-full' : '-groupavatar-thumb';
122
-
123
- if ( file_exists( $avatar_folder_dir ) ) {
124
- if ( $av_dir = opendir( $avatar_folder_dir ) ) {
125
- while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
126
- if ( preg_match( "/{$avatar_name}/", $avatar_file ) || preg_match( "/{$legacy_user_avatar_name}/", $avatar_file ) || preg_match( "/{$legacy_group_avatar_name}/", $avatar_file ) )
127
- $avatar_url = $avatar_folder_url . '/' . $avatar_file;
128
- }
129
- }
130
- closedir($av_dir);
131
-
132
- if ( $avatar_url )
133
- 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 );
134
- }
135
-
136
- /* If no avatars have been uploaded for this item, display a gravatar */
137
- if ( !$no_grav ) {
138
- if ( empty( $bp->grav_default->{$object} ) )
139
- $default_grav = 'wavatar';
140
- else if ( 'mystery' == $bp->grav_default->{$object} )
141
- $default_grav = apply_filters( 'bp_core_mysteryman_src', BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg' );
142
- else
143
- $default_grav = $bp->grav_default->{$object};
144
-
145
- if ( $width ) $grav_size = $width;
146
- else if ( 'full' == $type ) $grav_size = BP_AVATAR_FULL_WIDTH;
147
- else if ( 'thumb' == $type ) $grav_size = BP_AVATAR_THUMB_WIDTH;
148
-
149
- if ( empty( $email ) ) {
150
- if ( 'user' == $object ) {
151
- $email = bp_core_get_user_email( $item_id );
152
- } else if ( 'group' == $object || 'blog' == $object ) {
153
- $email = "{$item_id}-{$object}@{$bp->root_domain}";
154
- }
155
- }
156
-
157
- if ( is_ssl() )
158
- $host = 'https://secure.gravatar.com/avatar/';
159
- else
160
- $host = 'http://www.gravatar.com/avatar/';
161
-
162
- $email = apply_filters( 'bp_core_gravatar_email', $email, $item_id, $object );
163
- $gravatar = apply_filters( 'bp_gravatar_url', $host ) . md5( $email ) . '?d=' . $default_grav . '&amp;s=' . $grav_size;
164
-
165
- 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 );
166
- } else {
167
- 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 );
168
- }
169
- }
170
-
171
- function bp_core_delete_existing_avatar( $args = '' ) {
172
- global $bp;
173
-
174
- $defaults = array(
175
- 'item_id' => false,
176
- 'object' => 'user', // user OR group OR blog OR custom type (if you use filters)
177
- 'avatar_dir' => false
178
- );
179
-
180
- $args = wp_parse_args( $args, $defaults );
181
- extract( $args, EXTR_SKIP );
182
-
183
- if ( !$item_id ) {
184
- if ( 'user' == $object )
185
- $item_id = $bp->displayed_user->id;
186
- else if ( 'group' == $object )
187
- $item_id = $bp->groups->current_group->id;
188
- else if ( 'blog' == $object )
189
- $item_id = $current_blog->id;
190
-
191
- $item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object );
192
-
193
- if ( !$item_id ) return false;
194
- }
195
-
196
- if ( !$avatar_dir ) {
197
- if ( 'user' == $object )
198
- $avatar_dir = 'avatars';
199
- else if ( 'group' == $object )
200
- $avatar_dir = 'group-avatars';
201
- else if ( 'blog' == $object )
202
- $avatar_dir = 'blog-avatars';
203
-
204
- $avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object );
205
-
206
- if ( !$avatar_dir ) return false;
207
- }
208
-
209
- $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', BP_AVATAR_UPLOAD_PATH . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
210
-
211
- if ( !file_exists( $avatar_folder_dir ) )
212
- return false;
213
-
214
- if ( $av_dir = opendir( $avatar_folder_dir ) ) {
215
- while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
216
- if ( ( preg_match( "/-bpfull/", $avatar_file ) || preg_match( "/-bpthumb/", $avatar_file ) ) && '.' != $avatar_file && '..' != $avatar_file )
217
- @unlink( $avatar_folder_dir . '/' . $avatar_file );
218
- }
219
- }
220
- closedir($av_dir);
221
-
222
- @rmdir( $avatar_folder_dir );
223
-
224
- do_action( 'bp_core_delete_existing_avatar', $args );
225
-
226
- return true;
227
- }
228
-
229
- function bp_core_avatar_handle_upload( $file, $upload_dir_filter ) {
230
- global $bp;
231
-
232
- /***
233
- * You may want to hook into this filter if you want to override this function.
234
- * Make sure you return false.
235
- */
236
- if ( !apply_filters( 'bp_core_pre_avatar_handle_upload', true, $file, $upload_dir_filter ) )
237
- return true;
238
-
239
- require_once( ABSPATH . '/wp-admin/includes/image.php' );
240
- require_once( ABSPATH . '/wp-admin/includes/file.php' );
241
-
242
- $uploadErrors = array(
243
- 0 => __("There is no error, the file uploaded with success", 'buddypress'),
244
- 1 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE),
245
- 2 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE),
246
- 3 => __("The uploaded file was only partially uploaded", 'buddypress'),
247
- 4 => __("No file was uploaded", 'buddypress'),
248
- 6 => __("Missing a temporary folder", 'buddypress')
249
- );
250
-
251
- if ( !bp_core_check_avatar_upload( $file ) ) {
252
- bp_core_add_message( sprintf( __( 'Your upload failed, please try again. Error was: %s', 'buddypress' ), $uploadErrors[$file['file']['error']] ), 'error' );
253
- return false;
254
- }
255
-
256
- if ( !bp_core_check_avatar_size( $file ) ) {
257
- 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' );
258
- return false;
259
- }
260
-
261
- if ( !bp_core_check_avatar_type( $file ) ) {
262
- bp_core_add_message( __( 'Please upload only JPG, GIF or PNG photos.', 'buddypress' ), 'error' );
263
- return false;
264
- }
265
-
266
- /* Filter the upload location */
267
- add_filter( 'upload_dir', $upload_dir_filter, 10, 0 );
268
-
269
- $bp->avatar_admin->original = wp_handle_upload( $file['file'], array( 'action'=> 'bp_avatar_upload' ) );
270
-
271
- /* Move the file to the correct upload location. */
272
- if ( !empty( $bp->avatar_admin->original['error'] ) ) {
273
- bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $bp->avatar_admin->original['error'] ), 'error' );
274
- return false;
275
- }
276
-
277
- /* Get image size */
278
- $size = @getimagesize( $bp->avatar_admin->original['file'] );
279
-
280
- /* Check image size and shrink if too large */
281
- if ( $size[0] > BP_AVATAR_ORIGINAL_MAX_WIDTH ) {
282
- $thumb = wp_create_thumbnail( $bp->avatar_admin->original['file'], BP_AVATAR_ORIGINAL_MAX_WIDTH );
283
-
284
- /* Check for thumbnail creation errors */
285
- if ( is_wp_error( $thumb ) ) {
286
- bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $thumb->get_error_message() ), 'error' );
287
- return false;
288
- }
289
-
290
- /* Thumbnail is good so proceed */
291
- $bp->avatar_admin->resized = $thumb;
292
- }
293
-
294
- /* We only want to handle one image after resize. */
295
- if ( empty( $bp->avatar_admin->resized ) )
296
- $bp->avatar_admin->image->dir = str_replace( BP_AVATAR_UPLOAD_PATH, '', $bp->avatar_admin->original['file'] );
297
- else {
298
- $bp->avatar_admin->image->dir = str_replace( BP_AVATAR_UPLOAD_PATH, '', $bp->avatar_admin->resized );
299
- @unlink( $bp->avatar_admin->original['file'] );
300
- }
301
-
302
- /* Set the url value for the image */
303
- $bp->avatar_admin->image->url = BP_AVATAR_URL . $bp->avatar_admin->image->dir;
304
-
305
- return true;
306
- }
307
-
308
- function bp_core_avatar_handle_crop( $args = '' ) {
309
- global $bp;
310
-
311
- $defaults = array(
312
- 'object' => 'user',
313
- 'avatar_dir' => 'avatars',
314
- 'item_id' => false,
315
- 'original_file' => false,
316
- 'crop_w' => BP_AVATAR_FULL_WIDTH,
317
- 'crop_h' => BP_AVATAR_FULL_HEIGHT,
318
- 'crop_x' => 0,
319
- 'crop_y' => 0
320
- );
321
-
322
- $r = wp_parse_args( $args, $defaults );
323
-
324
- /***
325
- * You may want to hook into this filter if you want to override this function.
326
- * Make sure you return false.
327
- */
328
- if ( !apply_filters( 'bp_core_pre_avatar_handle_crop', true, $r ) )
329
- return true;
330
-
331
- extract( $r, EXTR_SKIP );
332
-
333
- if ( !$original_file )
334
- return false;
335
-
336
- $original_file = BP_AVATAR_UPLOAD_PATH . $original_file;
337
-
338
- if ( !file_exists( $original_file ) )
339
- return false;
340
-
341
- if ( !$item_id )
342
- $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', dirname( $original_file ), $item_id, $object, $avatar_dir );
343
- else
344
- $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', BP_AVATAR_UPLOAD_PATH . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
345
-
346
- if ( !file_exists( $avatar_folder_dir ) )
347
- return false;
348
-
349
- require_once( ABSPATH . '/wp-admin/includes/image.php' );
350
- require_once( ABSPATH . '/wp-admin/includes/file.php' );
351
-
352
- /* Delete the existing avatar files for the object */
353
- bp_core_delete_existing_avatar( array( 'object' => $object, 'avatar_path' => $avatar_folder_dir ) );
354
-
355
- /* Make sure we at least have a width and height for cropping */
356
- if ( !(int)$crop_w )
357
- $crop_w = BP_AVATAR_FULL_WIDTH;
358
-
359
- if ( !(int)$crop_h )
360
- $crop_h = BP_AVATAR_FULL_HEIGHT;
361
-
362
- /* Set the full and thumb filenames */
363
- $full_filename = wp_hash( $original_file . time() ) . '-bpfull.jpg';
364
- $thumb_filename = wp_hash( $original_file . time() ) . '-bpthumb.jpg';
365
-
366
- /* Crop the image */
367
- $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 );
368
- $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 );
369
-
370
- /* Remove the original */
371
- @unlink( $original_file );
372
-
373
- return true;
374
- }
375
-
376
- // Override internal "get_avatar()" function to use our own where possible
377
- function bp_core_fetch_avatar_filter( $avatar, $user, $size, $default, $alt ) {
378
- global $authordata;
379
-
380
- if ( is_object( $user ) )
381
- $id = $user->user_id;
382
- else if ( is_numeric( $user ) )
383
- $id = $user;
384
- else
385
- $id = $authordata->ID;
386
-
387
- if ( empty( $id ) )
388
- return $avatar;
389
-
390
- $bp_avatar = bp_core_fetch_avatar( array( 'item_id' => $id, 'width' => $size, 'height' => $size, 'alt' => $alt ) );
391
-
392
- return ( !$bp_avatar ) ? $avatar : $bp_avatar;
393
- }
394
- add_filter( 'get_avatar', 'bp_core_fetch_avatar_filter', 10, 5 );
395
-
396
- function bp_core_check_avatar_upload($file) {
397
- if ( $file['error'] )
398
- return false;
399
-
400
- return true;
401
- }
402
-
403
- function bp_core_check_avatar_size($file) {
404
- if ( $file['file']['size'] > BP_AVATAR_ORIGINAL_MAX_FILESIZE )
405
- return false;
406
-
407
- return true;
408
- }
409
-
410
- function bp_core_check_avatar_type($file) {
411
- if ( ( strlen($file['file']['type']) && !preg_match('/(jpe?g|gif|png)$/', $file['file']['type'] ) ) && !preg_match( '/(jpe?g|gif|png)$/', $file['file']['name'] ) )
412
- return false;
413
-
414
- return true;
415
- }
416
-
417
- function bp_core_avatar_upload_path() {
418
- $upload_dir = wp_upload_dir();
419
- return apply_filters( 'bp_core_avatar_upload_path', $upload_dir['basedir'] );
420
- }
421
-
422
- function bp_core_avatar_url() {
423
- $upload_dir = wp_upload_dir();
424
- return apply_filters( 'bp_core_avatar_url', $upload_dir['baseurl'] );
425
- }
426
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
427
  ?>
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
+
22
+ if ( !defined( 'BP_AVATAR_THUMB_HEIGHT' ) )
23
+ define( 'BP_AVATAR_THUMB_HEIGHT', 50 );
24
+
25
+ if ( !defined( 'BP_AVATAR_FULL_WIDTH' ) )
26
+ define( 'BP_AVATAR_FULL_WIDTH', 150 );
27
+
28
+ if ( !defined( 'BP_AVATAR_FULL_HEIGHT' ) )
29
+ define( 'BP_AVATAR_FULL_HEIGHT', 150 );
30
+
31
+ if ( !defined( 'BP_AVATAR_ORIGINAL_MAX_WIDTH' ) )
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
+ }
40
+
41
+ if ( !defined( 'BP_AVATAR_DEFAULT' ) )
42
+ define( 'BP_AVATAR_DEFAULT', BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg' );
43
+
44
+ if ( !defined( 'BP_AVATAR_DEFAULT_THUMB' ) )
45
+ define( 'BP_AVATAR_DEFAULT_THUMB', BP_PLUGIN_URL . '/bp-core/images/mystery-man-50.jpg' );
46
+ }
47
+ add_action( 'bp_loaded', 'bp_core_set_avatar_constants', 8 );
48
+
49
+ /**
50
+ * bp_core_fetch_avatar()
51
+ *
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
+ */
60
+ 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
86
+ $params = wp_parse_args( $args, $defaults );
87
+ extract( $params, EXTR_SKIP );
88
+
89
+ // Set item_id if not passed
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}'";
123
+
124
+ // Set avatar width
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
150
+ if ( file_exists( $avatar_folder_dir ) ) {
151
+
152
+ // Open directory
153
+ if ( $av_dir = opendir( $avatar_folder_dir ) ) {
154
+
155
+ // Stash files in an array once to check for one that matches
156
+ $avatar_files = array();
157
+ while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
158
+ // Only add files to the array (skip directories)
159
+ if ( 2 < strlen( $avatar_file ) )
160
+ $avatar_files[] = $avatar_file;
161
+ }
162
+
163
+ // Check for array
164
+ if ( 0 < count( $avatar_files ) ) {
165
+
166
+ // Check for current avatar
167
+ foreach( $avatar_files as $key => $value ) {
168
+ if ( strpos ( $value, $avatar_size )!== false )
169
+ $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
170
+ }
171
+
172
+ // Legacy avatar check
173
+ if ( !isset( $avatar_url ) ) {
174
+ foreach( $avatar_files as $key => $value ) {
175
+ if ( strpos ( $value, $legacy_user_avatar_name )!== false )
176
+ $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
177
+ }
178
+
179
+ // Legacy group avatar check
180
+ if ( !isset( $avatar_url ) ) {
181
+ foreach( $avatar_files as $key => $value ) {
182
+ if ( strpos ( $value, $legacy_group_avatar_name )!== false )
183
+ $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key];
184
+ }
185
+ }
186
+ }
187
+ }
188
+ }
189
+
190
+ // Close the avatar directory
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 {
202
+ return apply_filters( 'bp_core_fetch_avatar_url', $avatar_url );
203
+ }
204
+ }
205
+ }
206
+
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
+
228
+ // Set gravatar object
229
+ if ( empty( $email ) ) {
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
+
237
+ // Set host based on if using ssl
238
+ if ( is_ssl() )
239
+ $host = 'https://secure.gravatar.com/avatar/';
240
+ else
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
+
269
+ $args = wp_parse_args( $args, $defaults );
270
+ extract( $args, EXTR_SKIP );
271
+
272
+ if ( !$item_id ) {
273
+ if ( 'user' == $object )
274
+ $item_id = $bp->displayed_user->id;
275
+ else if ( 'group' == $object )
276
+ $item_id = $bp->groups->current_group->id;
277
+ else if ( 'blog' == $object )
278
+ $item_id = $current_blog->id;
279
+
280
+ $item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object );
281
+
282
+ if ( !$item_id ) return false;
283
+ }
284
+
285
+ if ( !$avatar_dir ) {
286
+ if ( 'user' == $object )
287
+ $avatar_dir = 'avatars';
288
+ else if ( 'group' == $object )
289
+ $avatar_dir = 'group-avatars';
290
+ else if ( 'blog' == $object )
291
+ $avatar_dir = 'blog-avatars';
292
+
293
+ $avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object );
294
+
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;
302
+
303
+ if ( $av_dir = opendir( $avatar_folder_dir ) ) {
304
+ while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
305
+ if ( ( preg_match( "/-bpfull/", $avatar_file ) || preg_match( "/-bpthumb/", $avatar_file ) ) && '.' != $avatar_file && '..' != $avatar_file )
306
+ @unlink( $avatar_folder_dir . '/' . $avatar_file );
307
+ }
308
+ }
309
+ closedir($av_dir);
310
+
311
+ @rmdir( $avatar_folder_dir );
312
+
313
+ do_action( 'bp_core_delete_existing_avatar', $args );
314
+
315
+ return true;
316
+ }
317
+
318
+ function bp_core_avatar_handle_upload( $file, $upload_dir_filter ) {
319
+ global $bp;
320
+
321
+ /***
322
+ * You may want to hook into this filter if you want to override this function.
323
+ * Make sure you return false.
324
+ */
325
+ if ( !apply_filters( 'bp_core_pre_avatar_handle_upload', true, $file, $upload_dir_filter ) )
326
+ return true;
327
+
328
+ require_once( ABSPATH . '/wp-admin/includes/image.php' );
329
+ require_once( ABSPATH . '/wp-admin/includes/file.php' );
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')
338
+ );
339
+
340
+ if ( !bp_core_check_avatar_upload( $file ) ) {
341
+ bp_core_add_message( sprintf( __( 'Your upload failed, please try again. Error was: %s', 'buddypress' ), $uploadErrors[$file['file']['error']] ), 'error' );
342
+ return false;
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
+
350
+ if ( !bp_core_check_avatar_type( $file ) ) {
351
+ bp_core_add_message( __( 'Please upload only JPG, GIF or PNG photos.', 'buddypress' ), 'error' );
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 );
412
+
413
+ /***
414
+ * You may want to hook into this filter if you want to override this function.
415
+ * Make sure you return false.
416
+ */
417
+ if ( !apply_filters( 'bp_core_pre_avatar_handle_crop', true, $r ) )
418
+ return true;
419
+
420
+ extract( $r, EXTR_SKIP );
421
+
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;
429
+
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;
437
+
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;
463
+ }
464
+
465
+ /**
466
+ * bp_core_fetch_avatar_filter()
467
+ *
468
+ * Attempts to filter get_avatar function and let BuddyPress have a go
469
+ * at finding an avatar that may have been uploaded locally.
470
+ *
471
+ * @global array $authordata
472
+ * @param string $avatar The result of get_avatar from before-filter
473
+ * @param int|string|object $user A user ID, email address, or comment object
474
+ * @param int $size Size of the avatar image (thumb/full)
475
+ * @param string $default URL to a default image to use if no avatar is available
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
+
481
+ // If passed an object, assume $user->user_id
482
+ if ( is_object( $user ) )
483
+ $id = $user->user_id;
484
+
485
+ // If passed a number, assume it was a $user_id
486
+ else if ( is_numeric( $user ) )
487
+ $id = $user;
488
+
489
+ // If passed a string and that string returns a user, get the $id
490
+ else if ( is_string( $user ) && ( $user_by_email = get_user_by_email( $user ) ) )
491
+ $id = $user_by_email->ID;
492
+
493
+ // If somehow $id hasn't been assigned, return the result of get_avatar
494
+ if ( empty( $id ) )
495
+ return !empty( $avatar ) ? $avatar : $default;
496
+
497
+ // Let BuddyPress handle the fetching of the avatar
498
+ $bp_avatar = bp_core_fetch_avatar( array( 'item_id' => $id, 'width' => $size, 'height' => $size, 'alt' => $alt ) );
499
+
500
+ // If BuddyPress found an avatar, use it. If not, use the result of get_avatar
501
+ return ( !$bp_avatar ) ? $avatar : $bp_avatar;
502
+ }
503
+ add_filter( 'get_avatar', 'bp_core_fetch_avatar_filter', 10, 5 );
504
+
505
+ function bp_core_check_avatar_upload($file) {
506
+ if ( $file['error'] )
507
+ return false;
508
+
509
+ return true;
510
+ }
511
+
512
+ function bp_core_check_avatar_size($file) {
513
+ if ( $file['file']['size'] > BP_AVATAR_ORIGINAL_MAX_FILESIZE )
514
+ return false;
515
+
516
+ return true;
517
+ }
518
+
519
+ function bp_core_check_avatar_type($file) {
520
+ if ( ( strlen($file['file']['type']) && !preg_match('/(jpe?g|gif|png)$/', $file['file']['type'] ) ) && !preg_match( '/(jpe?g|gif|png)$/', $file['file']['name'] ) )
521
+ return false;
522
+
523
+ return true;
524
+ }
525
+
526
+ /**
527
+ * bp_core_avatar_upload_path()
528
+ *
529
+ * Returns the absolute upload path for the WP installation
530
+ *
531
+ * @global object $current_blog Current blog information
532
+ * @uses wp_upload_dir To get upload directory info
533
+ * @return string Absolute path to WP upload directory
534
+ */
535
+ function bp_core_avatar_upload_path() {
536
+ global $current_blog;
537
+
538
+ // Get upload directory information from current site
539
+ $upload_dir = wp_upload_dir();
540
+
541
+ // If multisite, and current blog does not match root blog, make adjustments
542
+ if ( bp_core_is_multisite() && BP_ROOT_BLOG != $current_blog->blog_id )
543
+ $upload_dir['basedir'] = str_replace( $current_blog->blog_id, BP_ROOT_BLOG, BLOGUPLOADDIR );
544
+
545
+ return apply_filters( 'bp_core_avatar_upload_path', $upload_dir['basedir'] );
546
+ }
547
+
548
+ /**
549
+ * bp_core_avatar_url()
550
+ *
551
+ * Returns the raw base URL for root site upload location
552
+ *
553
+ * @global object $current_blog Current blog information
554
+ * @uses wp_upload_dir To get upload directory info
555
+ * @return string Full URL to current upload location
556
+ */
557
+ function bp_core_avatar_url() {
558
+ global $current_blog;
559
+
560
+ // Get upload directory information from current site
561
+ $upload_dir = wp_upload_dir();
562
+
563
+ // If multisite, and current blog does not match root blog, make adjustments
564
+ if ( bp_core_is_multisite() && BP_ROOT_BLOG != $current_blog->blog_id )
565
+ $upload_dir['baseurl'] = str_replace( get_blog_option( $current_blog->blog_id, 'home' ) , get_blog_option( BP_ROOT_BLOG, 'home' ), $upload_dir['baseurl'] );
566
+
567
+ return apply_filters( 'bp_core_avatar_url', $upload_dir['baseurl'] );
568
+ }
569
+
570
  ?>
bp-core/bp-core-catchuri.php CHANGED
@@ -1,286 +1,286 @@
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
- if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && bp_core_is_multisite() ) {
36
- /* Only catch URI's on the root blog if we are not running BP on multiple blogs */
37
- if ( BP_ROOT_BLOG != (int) $current_blog->blog_id )
38
- return false;
39
- }
40
-
41
- if ( strpos( $_SERVER['REQUEST_URI'], 'wp-load.php' ) )
42
- $path = bp_core_referrer();
43
- else
44
- $path = clean_url( $_SERVER['REQUEST_URI'] );
45
-
46
- $path = apply_filters( 'bp_uri', $path );
47
-
48
- // Firstly, 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 != '' ) $path = $noget;
52
-
53
- /* Fetch the current URI and explode each part separated by '/' into an array */
54
- $bp_uri = explode( "/", $path );
55
-
56
- /* Loop and remove empties */
57
- foreach ( (array)$bp_uri as $key => $uri_chunk )
58
- if ( empty( $bp_uri[$key] ) ) unset( $bp_uri[$key] );
59
-
60
- if ( defined( 'BP_ENABLE_MULTIBLOG' ) || 1 != BP_ROOT_BLOG ) {
61
- /* If we are running BuddyPress on any blog, not just a root blog, we need to first
62
- shift off the blog name if we are running a subdirectory install of WPMU. */
63
- if ( $current_blog->path != '/' )
64
- array_shift( $bp_uri );
65
- }
66
-
67
- /* Set the indexes, these are incresed by one if we are not on a VHOST install */
68
- $component_index = 0;
69
- $action_index = $component_index + 1;
70
-
71
- // If this is a WordPress page, return from the function.
72
- if ( is_page( $bp_uri[$component_index] ) )
73
- return false;
74
-
75
- /* Get site path items */
76
- $paths = explode( '/', bp_core_get_site_path() );
77
-
78
- /* Take empties off the end of path */
79
- if ( empty( $paths[count($paths) - 1] ) )
80
- array_pop( $paths );
81
-
82
- /* Take empties off the start of path */
83
- if ( empty( $paths[0] ) )
84
- array_shift( $paths );
85
-
86
- foreach ( (array)$bp_uri as $key => $uri_chunk ) {
87
- if ( in_array( $uri_chunk, $paths )) {
88
- unset( $bp_uri[$key] );
89
- }
90
- }
91
-
92
- /* Reset the keys by merging with an empty array */
93
- $bp_uri = array_merge( array(), $bp_uri );
94
- $bp_unfiltered_uri = $bp_uri;
95
-
96
- /* If we are under anything with a members slug, set the correct globals */
97
- if ( $bp_uri[0] == BP_MEMBERS_SLUG ) {
98
- $is_member_page = true;
99
- $is_root_component = true;
100
- }
101
-
102
- /* Catch a member page and set the current member ID */
103
- if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) ) {
104
- if ( ( $bp_uri[0] == BP_MEMBERS_SLUG && !empty( $bp_uri[1] ) ) || in_array( 'wp-load.php', $bp_uri ) ) {
105
- // We are within a member page, set up user id globals
106
- if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
107
- $displayed_user_id = bp_core_get_userid( $bp_uri[1] );
108
- else
109
- $displayed_user_id = bp_core_get_userid_from_nicename( $bp_uri[1] );
110
-
111
- unset($bp_uri[0]);
112
- unset($bp_uri[1]);
113
-
114
- /* Reset the keys by merging with an empty array */
115
- $bp_uri = array_merge( array(), $bp_uri );
116
- }
117
- } else {
118
- if ( get_userdatabylogin( $bp_uri[0] ) || in_array( 'wp-load.php', $bp_uri ) ) {
119
- $is_member_page = true;
120
- $is_root_component = true;
121
-
122
- // We are within a member page, set up user id globals
123
- if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
124
- $displayed_user_id = bp_core_get_userid( $bp_uri[0] );
125
- else
126
- $displayed_user_id = bp_core_get_userid_from_nicename( $bp_uri[0] );
127
-
128
- unset($bp_uri[0]);
129
-
130
- /* Reset the keys by merging with an empty array */
131
- $bp_uri = array_merge( array(), $bp_uri );
132
- }
133
- }
134
-
135
- if ( !isset($is_root_component) )
136
- $is_root_component = in_array( $bp_uri[0], $bp->root_components );
137
-
138
- if ( 'no' == VHOST && !$is_root_component ) {
139
- $component_index++;
140
- $action_index++;
141
- }
142
-
143
- /* Set the current component */
144
- $current_component = $bp_uri[$component_index];
145
-
146
- /* Set the current action */
147
- $current_action = $bp_uri[$action_index];
148
-
149
- /* Set the entire URI as the action variables, we will unset the current_component and action in a second */
150
- $action_variables = $bp_uri;
151
-
152
- /* Unset the current_component and action from action_variables */
153
- unset($action_variables[$component_index]);
154
- unset($action_variables[$action_index]);
155
-
156
- /* Remove the username from action variables if this is not a VHOST install */
157
- if ( 'no' == VHOST && !$is_root_component )
158
- array_shift($action_variables);
159
-
160
- /* Reset the keys by merging with an empty array */
161
- $action_variables = array_merge( array(), $action_variables );
162
- }
163
- add_action( 'plugins_loaded', 'bp_core_set_uri_globals', 3 );
164
-
165
- /**
166
- * bp_catch_uri()
167
- *
168
- * Takes either a single page name or array of page names and
169
- * loads the first template file that can be found.
170
- *
171
- * Please don't call this function directly anymore, use: bp_core_load_template()
172
- *
173
- * @package BuddyPress Core
174
- * @global $bp_path BuddyPress global containing the template file names to use.
175
- * @param $pages Template file names to use.
176
- * @uses add_action() Hooks a function on to a specific action
177
- */
178
- function bp_catch_uri( $pages, $skip_blog_check = false ) {
179
- global $bp_path, $bp_skip_blog_check;
180
-
181
- $bp_skip_blog_check = $skip_blog_check;
182
-
183
- $bp_path = $pages;
184
-
185
- if ( !bp_is_blog_page() ) {
186
- remove_action( 'template_redirect', 'redirect_canonical' );
187
- }
188
- add_action( 'template_redirect', 'bp_core_do_catch_uri', 2 );
189
- }
190
-
191
- /**
192
- * bp_core_do_catch_uri()
193
- *
194
- * Loads the first template file found based on the $bp_path global.
195
- *
196
- * @package BuddyPress Core
197
- * @global $bp_path BuddyPress global containing the template file names to use.
198
- */
199
- function bp_core_do_catch_uri() {
200
- global $bp_path, $bp, $wpdb;
201
- global $current_blog, $bp_skip_blog_check;
202
- global $bp_no_status_set;
203
- global $wp_query;
204
-
205
- /* Can be a single template or an array of templates */
206
- $templates = $bp_path;
207
-
208
- /* Don't hijack any URLs on blog pages */
209
- if ( bp_is_blog_page() ) {
210
- if ( !$bp_skip_blog_check )
211
- return false;
212
- } else {
213
- $wp_query->is_home = false;
214
- }
215
-
216
- /* Make sure this is not reported as a 404 */
217
- if ( !$bp_no_status_set ) {
218
- status_header( 200 );
219
- $wp_query->is_404 = false;
220
- $wp_query->is_page = true;
221
- }
222
-
223
- foreach ( (array)$templates as $template )
224
- $filtered_templates[] = $template . '.php';
225
-
226
- if ( $located_template = apply_filters( 'bp_located_template', locate_template( (array) $filtered_templates, false ), $filtered_templates ) ) {
227
- load_template( apply_filters( 'bp_load_template', $located_template ) );
228
- } else {
229
- if ( $located_template = locate_template( array( '404.php' ) ) ) {
230
- status_header( 404 );
231
- load_template( $located_template );
232
- } else
233
- bp_core_redirect( $bp->root_domain );
234
- }
235
- die;
236
- }
237
-
238
- function bp_core_catch_no_access() {
239
- global $bp, $bp_path, $bp_unfiltered_uri, $bp_no_status_set;
240
-
241
- // If bp_core_redirect() and $bp_no_status_set is true,
242
- // we are redirecting to an accessable page, so skip this check.
243
- if ( $bp_no_status_set )
244
- return false;
245
-
246
- /* If this user has been marked as a spammer and the logged in user is not a site admin, redirect. */
247
- if ( isset( $bp->displayed_user->id ) && bp_core_is_user_spammer( $bp->displayed_user->id ) ) {
248
- if ( !is_site_admin() )
249
- bp_core_redirect( $bp->root_domain );
250
- else
251
- bp_core_add_message( __( 'This user has been marked as a spammer. Only site admins can view this profile.', 'buddypress' ), 'error' );
252
- }
253
-
254
- // If this user does not exist, redirect to the root domain.
255
- if ( !$bp->displayed_user->id && $bp_unfiltered_uri[0] == BP_MEMBERS_SLUG && isset($bp_unfiltered_uri[1]) )
256
- bp_core_redirect( $bp->root_domain );
257
-
258
- // If the template file doesn't exist, redirect to the root domain.
259
- if ( !bp_is_blog_page() && !file_exists( apply_filters( 'bp_located_template', locate_template( array( $bp_path . '.php' ), false ), array( $bp_path . '.php' ) ) ) )
260
- bp_core_redirect( $bp->root_domain );
261
-
262
- if ( !$bp_path && !bp_is_blog_page() ) {
263
- if ( is_user_logged_in() ) {
264
- wp_redirect( $bp->root_domain );
265
- } else {
266
- wp_redirect( site_url( 'wp-login.php?redirect_to=' . site_url() . $_SERVER['REQUEST_URI'] ) );
267
- }
268
- }
269
- }
270
- add_action( 'wp', 'bp_core_catch_no_access' );
271
-
272
- /**
273
- * bp_core_catch_profile_uri()
274
- *
275
- * If the extended profiles component is not installed we still need
276
- * to catch the /profile URI's and display whatever we have installed.
277
- *
278
- */
279
- function bp_core_catch_profile_uri() {
280
- global $bp;
281
-
282
- if ( !function_exists('xprofile_install') )
283
- bp_core_load_template( apply_filters( 'bp_core_template_display_profile', 'members/single/home' ) );
284
- }
285
-
286
  ?>
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
+ if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && bp_core_is_multisite() ) {
36
+ /* Only catch URI's on the root blog if we are not running BP on multiple blogs */
37
+ if ( BP_ROOT_BLOG != (int) $current_blog->blog_id )
38
+ return false;
39
+ }
40
+
41
+ if ( strpos( $_SERVER['REQUEST_URI'], 'wp-load.php' ) )
42
+ $path = bp_core_referrer();
43
+ else
44
+ $path = clean_url( $_SERVER['REQUEST_URI'] );
45
+
46
+ $path = apply_filters( 'bp_uri', $path );
47
+
48
+ // Firstly, 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 != '' ) $path = $noget;
52
+
53
+ /* Fetch the current URI and explode each part separated by '/' into an array */
54
+ $bp_uri = explode( "/", $path );
55
+
56
+ /* Loop and remove empties */
57
+ foreach ( (array)$bp_uri as $key => $uri_chunk )
58
+ if ( empty( $bp_uri[$key] ) ) unset( $bp_uri[$key] );
59
+
60
+ if ( defined( 'BP_ENABLE_MULTIBLOG' ) || 1 != BP_ROOT_BLOG ) {
61
+ /* If we are running BuddyPress on any blog, not just a root blog, we need to first
62
+ shift off the blog name if we are running a subdirectory install of WPMU. */
63
+ if ( $current_blog->path != '/' )
64
+ array_shift( $bp_uri );
65
+ }
66
+
67
+ /* Set the indexes, these are incresed by one if we are not on a VHOST install */
68
+ $component_index = 0;
69
+ $action_index = $component_index + 1;
70
+
71
+ // If this is a WordPress page, return from the function.
72
+ if ( is_page( $bp_uri[$component_index] ) )
73
+ return false;
74
+
75
+ /* Get site path items */
76
+ $paths = explode( '/', bp_core_get_site_path() );
77
+
78
+ /* Take empties off the end of path */
79
+ if ( empty( $paths[count($paths) - 1] ) )
80
+ array_pop( $paths );
81
+
82
+ /* Take empties off the start of path */
83
+ if ( empty( $paths[0] ) )
84
+ array_shift( $paths );
85
+
86
+ foreach ( (array)$bp_uri as $key => $uri_chunk ) {
87
+ if ( in_array( $uri_chunk, $paths )) {
88
+ unset( $bp_uri[$key] );
89
+ }
90
+ }
91
+
92
+ /* Reset the keys by merging with an empty array */
93
+ $bp_uri = array_merge( array(), $bp_uri );
94
+ $bp_unfiltered_uri = $bp_uri;
95
+
96
+ /* If we are under anything with a members slug, set the correct globals */
97
+ if ( $bp_uri[0] == BP_MEMBERS_SLUG ) {
98
+ $is_member_page = true;
99
+ $is_root_component = true;
100
+ }
101
+
102
+ /* Catch a member page and set the current member ID */
103
+ if ( !defined( 'BP_ENABLE_ROOT_PROFILES' ) ) {
104
+ if ( ( $bp_uri[0] == BP_MEMBERS_SLUG && !empty( $bp_uri[1] ) ) || in_array( 'wp-load.php', $bp_uri ) ) {
105
+ // We are within a member page, set up user id globals
106
+ if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
107
+ $displayed_user_id = bp_core_get_userid( $bp_uri[1] );
108
+ else
109
+ $displayed_user_id = bp_core_get_userid_from_nicename( $bp_uri[1] );
110
+
111
+ unset($bp_uri[0]);
112
+ unset($bp_uri[1]);
113
+
114
+ /* Reset the keys by merging with an empty array */
115
+ $bp_uri = array_merge( array(), $bp_uri );
116
+ }
117
+ } else {
118
+ if ( get_userdatabylogin( $bp_uri[0] ) || in_array( 'wp-load.php', $bp_uri ) ) {
119
+ $is_member_page = true;
120
+ $is_root_component = true;
121
+
122
+ // We are within a member page, set up user id globals
123
+ if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) )
124
+ $displayed_user_id = bp_core_get_userid( $bp_uri[0] );
125
+ else
126
+ $displayed_user_id = bp_core_get_userid_from_nicename( $bp_uri[0] );
127
+
128
+ unset($bp_uri[0]);
129
+
130
+ /* Reset the keys by merging with an empty array */
131
+ $bp_uri = array_merge( array(), $bp_uri );
132
+ }
133
+ }
134
+
135
+ if ( !isset($is_root_component) )
136
+ $is_root_component = in_array( $bp_uri[0], $bp->root_components );
137
+
138
+ if ( 'no' == VHOST && !$is_root_component ) {
139
+ $component_index++;
140
+ $action_index++;
141
+ }
142
+
143
+ /* Set the current component */
144
+ $current_component = $bp_uri[$component_index];
145
+
146
+ /* Set the current action */
147
+ $current_action = $bp_uri[$action_index];
148
+
149
+ /* Set the entire URI as the action variables, we will unset the current_component and action in a second */
150
+ $action_variables = $bp_uri;
151
+
152
+ /* Unset the current_component and action from action_variables */
153
+ unset($action_variables[$component_index]);
154
+ unset($action_variables[$action_index]);
155
+
156
+ /* Remove the username from action variables if this is not a VHOST install */
157
+ if ( 'no' == VHOST && !$is_root_component )
158
+ array_shift($action_variables);
159
+
160
+ /* Reset the keys by merging with an empty array */
161
+ $action_variables = array_merge( array(), $action_variables );
162
+ }
163
+ add_action( 'bp_loaded', 'bp_core_set_uri_globals', 4 );
164
+
165
+ /**
166
+ * bp_catch_uri()
167
+ *
168
+ * Takes either a single page name or array of page names and
169
+ * loads the first template file that can be found.
170
+ *
171
+ * Please don't call this function directly anymore, use: bp_core_load_template()
172
+ *
173
+ * @package BuddyPress Core
174
+ * @global $bp_path BuddyPress global containing the template file names to use.
175
+ * @param $pages Template file names to use.
176
+ * @uses add_action() Hooks a function on to a specific action
177
+ */
178
+ function bp_catch_uri( $pages, $skip_blog_check = false ) {
179
+ global $bp_path, $bp_skip_blog_check;
180
+
181
+ $bp_skip_blog_check = $skip_blog_check;
182
+
183
+ $bp_path = $pages;
184
+
185
+ if ( !bp_is_blog_page() ) {
186
+ remove_action( 'template_redirect', 'redirect_canonical' );
187
+ }
188
+ add_action( 'template_redirect', 'bp_core_do_catch_uri', 2 );
189
+ }
190
+
191
+ /**
192
+ * bp_core_do_catch_uri()
193
+ *
194
+ * Loads the first template file found based on the $bp_path global.
195
+ *
196
+ * @package BuddyPress Core
197
+ * @global $bp_path BuddyPress global containing the template file names to use.
198
+ */
199
+ function bp_core_do_catch_uri() {
200
+ global $bp_path, $bp, $wpdb;
201
+ global $current_blog, $bp_skip_blog_check;
202
+ global $bp_no_status_set;
203
+ global $wp_query;
204
+
205
+ /* Can be a single template or an array of templates */
206
+ $templates = $bp_path;
207
+
208
+ /* Don't hijack any URLs on blog pages */
209
+ if ( bp_is_blog_page() ) {
210
+ if ( !$bp_skip_blog_check )
211
+ return false;
212
+ } else {
213
+ $wp_query->is_home = false;
214
+ }
215
+
216
+ /* Make sure this is not reported as a 404 */
217
+ if ( !$bp_no_status_set ) {
218
+ status_header( 200 );
219
+ $wp_query->is_404 = false;
220
+ $wp_query->is_page = true;
221
+ }
222
+
223
+ foreach ( (array)$templates as $template )
224
+ $filtered_templates[] = $template . '.php';
225
+
226
+ if ( $located_template = apply_filters( 'bp_located_template', locate_template( (array) $filtered_templates, false ), $filtered_templates ) ) {
227
+ load_template( apply_filters( 'bp_load_template', $located_template ) );
228
+ } else {
229
+ if ( $located_template = locate_template( array( '404.php' ) ) ) {
230
+ status_header( 404 );
231
+ load_template( $located_template );
232
+ } else
233
+ bp_core_redirect( $bp->root_domain );
234
+ }
235
+ die;
236
+ }
237
+
238
+ function bp_core_catch_no_access() {
239
+ global $bp, $bp_path, $bp_unfiltered_uri, $bp_no_status_set;
240
+
241
+ // If bp_core_redirect() and $bp_no_status_set is true,
242
+ // we are redirecting to an accessable page, so skip this check.
243
+ if ( $bp_no_status_set )
244
+ return false;
245
+
246
+ /* If this user has been marked as a spammer and the logged in user is not a site admin, redirect. */
247
+ if ( isset( $bp->displayed_user->id ) && bp_core_is_user_spammer( $bp->displayed_user->id ) ) {
248
+ if ( !is_site_admin() )
249
+ bp_core_redirect( $bp->root_domain );
250
+ else
251
+ bp_core_add_message( __( 'This user has been marked as a spammer. Only site admins can view this profile.', 'buddypress' ), 'error' );
252
+ }
253
+
254
+ // If this user does not exist, redirect to the root domain.
255
+ if ( !$bp->displayed_user->id && $bp_unfiltered_uri[0] == BP_MEMBERS_SLUG && isset($bp_unfiltered_uri[1]) )
256
+ bp_core_redirect( $bp->root_domain );
257
+
258
+ // If the template file doesn't exist, redirect to the root domain.
259
+ if ( !bp_is_blog_page() && !file_exists( apply_filters( 'bp_located_template', locate_template( array( $bp_path . '.php' ), false ), array( $bp_path . '.php' ) ) ) )
260
+ bp_core_redirect( $bp->root_domain );
261
+
262
+ if ( !$bp_path && !bp_is_blog_page() ) {
263
+ if ( is_user_logged_in() ) {
264
+ wp_redirect( $bp->root_domain );
265
+ } else {
266
+ wp_redirect( site_url( 'wp-login.php?redirect_to=' . site_url() . $_SERVER['REQUEST_URI'] ) );
267
+ }
268
+ }
269
+ }
270
+ add_action( 'wp', 'bp_core_catch_no_access' );
271
+
272
+ /**
273
+ * bp_core_catch_profile_uri()
274
+ *
275
+ * If the extended profiles component is not installed we still need
276
+ * to catch the /profile URI's and display whatever we have installed.
277
+ *
278
+ */
279
+ function bp_core_catch_profile_uri() {
280
+ global $bp;
281
+
282
+ if ( !function_exists('xprofile_install') )
283
+ bp_core_load_template( apply_filters( 'bp_core_template_display_profile', 'members/single/home' ) );
284
+ }
285
+
286
  ?>
bp-core/bp-core-classes.php CHANGED
@@ -1,489 +1,489 @@
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.
5
- *
6
- * Example:
7
- * $user = new BP_Core_User( $user_id );
8
- * $user_avatar = $user->avatar;
9
- * $user_email = $user->email;
10
- * $user_status = $user->status;
11
- * etc.
12
- *
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();
37
-
38
- if ( $populate_extras )
39
- $this->populate_extras();
40
- }
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_usermeta() 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 = attribute_escape( $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 = attribute_escape( $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 = attribute_escape( bp_core_get_user_displayname( $this->id ) );
70
- $this->email = attribute_escape( 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_usermeta( $this->id, 'last_activity' ), __( '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
-
103
- function get_profile_data() {
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 )
120
- $sql['select_popular'] = ", um.meta_value as total_friend_count";
121
-
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()";
140
-
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 ) );
147
- else
148
- $uids = $wpdb->escape( $include );
149
-
150
- if ( !empty( $uids ) )
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 ) {
172
- case 'active': case 'online': default:
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";
180
- break;
181
- case 'random':
182
- $sql[] = "ORDER BY rand()";
183
- break;
184
- case 'popular':
185
- $sql[] = "ORDER BY CONVERT(um.meta_value, SIGNED) DESC";
186
- break;
187
- }
188
-
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 = $wpdb->get_results( join( ' ', (array)$sql ) );
194
-
195
- /* Re-jig the SQL so we can get the total user count */
196
- unset( $sql['select_main'] );
197
-
198
- if ( !empty( $sql['select_active'] ) )
199
- unset( $sql['select_active'] );
200
-
201
- if ( !empty( $sql['select_popular'] ) )
202
- unset( $sql['select_popular'] );
203
-
204
- if ( !empty( $sql['select_alpha'] ) )
205
- unset( $sql['select_alpha'] );
206
-
207
- if ( !empty( $sql['pagination'] ) )
208
- unset( $sql['pagination'] );
209
-
210
- array_unshift( $sql, "SELECT COUNT(DISTINCT u.ID)" );
211
-
212
- /* Get total user results */
213
- $total_users = $wpdb->get_var( join( ' ', (array)$sql ) );
214
-
215
- /***
216
- * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
217
- * 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)
218
- */
219
- if ( $populate_extras ) {
220
- foreach ( (array)$paged_users as $user )
221
- $user_ids[] = $user->id;
222
-
223
- $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
224
-
225
- /* Add additional data to the returned results */
226
- $paged_users = BP_Core_User::get_user_extras( &$paged_users, $user_ids, $type );
227
- }
228
-
229
- return array( 'users' => $paged_users, 'total' => $total_users );
230
- }
231
-
232
- function get_users_by_letter( $letter, $limit = null, $page = 1, $populate_extras = true ) {
233
- global $wpdb, $bp;
234
-
235
- if ( $limit && $page )
236
- $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
237
-
238
- if ( strlen($letter) > 1 || is_numeric($letter) || !$letter )
239
- return false;
240
-
241
- $letter = like_escape( $wpdb->escape( $letter ) );
242
- $status_sql = bp_core_get_status_sql( 'u.' );
243
-
244
- $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 );
245
- $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 );
246
-
247
- $total_users = $wpdb->get_var( $total_users_sql );
248
- $paged_users = $wpdb->get_results( $paged_users_sql );
249
-
250
- /***
251
- * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
252
- * 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)
253
- */
254
- foreach ( (array)$paged_users as $user )
255
- $user_ids[] = $user->id;
256
-
257
- $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
258
-
259
- /* Add additional data to the returned results */
260
- if ( $populate_extras )
261
- $paged_users = BP_Core_User::get_user_extras( &$paged_users, &$user_ids );
262
-
263
- return array( 'users' => $paged_users, 'total' => $total_users );
264
- }
265
-
266
- function search_users( $search_terms, $limit = null, $page = 1, $populate_extras = true ) {
267
- global $wpdb, $bp;
268
-
269
- if ( $limit && $page )
270
- $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
271
-
272
- $search_terms = like_escape( $wpdb->escape( $search_terms ) );
273
- $status_sql = bp_core_get_status_sql( 'u.' );
274
-
275
- $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 );
276
- $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 );
277
-
278
- $total_users = $wpdb->get_var( $total_users_sql );
279
- $paged_users = $wpdb->get_results( $paged_users_sql );
280
-
281
- /***
282
- * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
283
- * 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)
284
- */
285
- foreach ( (array)$paged_users as $user )
286
- $user_ids[] = $user->id;
287
-
288
- $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
289
-
290
- /* Add additional data to the returned results */
291
- if ( $populate_extras )
292
- $paged_users = BP_Core_User::get_user_extras( &$paged_users, &$user_ids );
293
-
294
- return array( 'users' => $paged_users, 'total' => $total_users );
295
- }
296
-
297
- function get_user_extras( $paged_users, $user_ids, $type = false ) {
298
- global $bp, $wpdb;
299
-
300
- if ( empty( $user_ids ) )
301
- return $paged_users;
302
-
303
- /* Fetch the user's full name */
304
- if ( function_exists( 'xprofile_install' ) && 'alphabetical' != $type ) {
305
- /* Ensure xprofile globals are set */
306
- if ( !defined( 'BP_XPROFILE_FULLNAME_FIELD_NAME' ) )
307
- xprofile_setup_globals();
308
-
309
- $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 ) );
310
- for ( $i = 0; $i < count( $paged_users ); $i++ ) {
311
- foreach ( (array)$names as $name ) {
312
- if ( $name->id == $paged_users[$i]->id )
313
- $paged_users[$i]->fullname = $name->fullname;
314
- }
315
- }
316
- }
317
-
318
- /* Fetch the user's total friend count */
319
- if ( 'popular' != $type ) {
320
- $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} )" );
321
- for ( $i = 0; $i < count( $paged_users ); $i++ ) {
322
- foreach ( (array)$friend_count as $count ) {
323
- if ( $count->id == $paged_users[$i]->id )
324
- $paged_users[$i]->total_friend_count = (int)$count->total_friend_count;
325
- }
326
- }
327
- }
328
-
329
- /* Fetch whether or not the user is a friend */
330
- if ( function_exists( 'friends_install' ) ) {
331
- $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 ) );
332
- for ( $i = 0; $i < count( $paged_users ); $i++ ) {
333
- foreach ( (array)$friend_status as $status ) {
334
- if ( $status->initiator_user_id == $paged_users[$i]->id || $status->friend_user_id == $paged_users[$i]->id )
335
- $paged_users[$i]->is_friend = $status->is_confirmed;
336
- }
337
- }
338
- }
339
-
340
- if ( 'active' != $type ) {
341
- $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} )" );
342
- for ( $i = 0; $i < count( $paged_users ); $i++ ) {
343
- foreach ( (array)$user_activity as $activity ) {
344
- if ( $activity->id == $paged_users[$i]->id )
345
- $paged_users[$i]->last_activity = $activity->last_activity;
346
- }
347
- }
348
- }
349
-
350
- /* Fetch the user's last_activity */
351
- if ( 'active' != $type ) {
352
- $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} )" );
353
- for ( $i = 0; $i < count( $paged_users ); $i++ ) {
354
- foreach ( (array)$user_activity as $activity ) {
355
- if ( $activity->id == $paged_users[$i]->id )
356
- $paged_users[$i]->last_activity = $activity->last_activity;
357
- }
358
- }
359
- }
360
-
361
- /* Fetch the user's latest update */
362
- $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} )" );
363
- for ( $i = 0; $i < count( $paged_users ); $i++ ) {
364
- foreach ( (array)$user_update as $update ) {
365
- if ( $update->id == $paged_users[$i]->id )
366
- $paged_users[$i]->latest_update = $update->latest_update;
367
- }
368
- }
369
-
370
- return $paged_users;
371
- }
372
-
373
- function get_core_userdata( $user_id ) {
374
- global $wpdb;
375
-
376
- if ( !$user = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->users WHERE ID = %d LIMIT 1", $user_id ) ) )
377
- return false;
378
-
379
- return $user;
380
- }
381
- }
382
-
383
-
384
- /**
385
- * BP_Core_Notification class can be used by any component.
386
- * It will handle the fetching, saving and deleting of a user notification.
387
- *
388
- * @package BuddyPress Core
389
- */
390
-
391
- class BP_Core_Notification {
392
- var $id;
393
- var $item_id;
394
- var $secondary_item_id = null;
395
- var $user_id;
396
- var $component_name;
397
- var $component_action;
398
- var $date_notified;
399
- var $is_new;
400
-
401
- function bp_core_notification( $id = false ) {
402
- if ( $id ) {
403
- $this->id = $id;
404
- $this->populate();
405
- }
406
- }
407
-
408
- function populate() {
409
- global $wpdb, $bp;
410
-
411
- if ( $notification = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE id = %d", $this->id ) ) ) {
412
- $this->item_id = $notification->item_id;
413
- $this->secondary_item_id = $notification->secondary_item_id;
414
- $this->user_id = $notification->user_id;
415
- $this->component_name = $notification->component_name;
416
- $this->component_action = $notification->component_action;
417
- $this->date_notified = $notification->date_notified;
418
- $this->is_new = $notification->is_new;
419
- }
420
- }
421
-
422
- function save() {
423
- global $wpdb, $bp;
424
-
425
- if ( $this->id ) {
426
- // Update
427
- $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 = FROM_UNIXTIME(%d), 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 );
428
- } else {
429
- // Save
430
- $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, FROM_UNIXTIME(%d), %d )", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new );
431
- }
432
-
433
- if ( !$result = $wpdb->query( $sql ) )
434
- return false;
435
-
436
- $this->id = $wpdb->insert_id;
437
- return true;
438
- }
439
-
440
- /* Static functions */
441
-
442
- function check_access( $user_id, $notification_id ) {
443
- global $wpdb, $bp;
444
-
445
- 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 ) );
446
- }
447
-
448
- function get_all_for_user( $user_id ) {
449
- global $wpdb, $bp;
450
-
451
- return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND is_new = 1", $user_id ) );
452
- }
453
-
454
- function delete_for_user_by_type( $user_id, $component_name, $component_action ) {
455
- global $wpdb, $bp;
456
-
457
- 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 ) );
458
- }
459
-
460
- function delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id ) {
461
- global $wpdb, $bp;
462
-
463
- if ( $secondary_item_id )
464
- $secondary_item_sql = $wpdb->prepare( " AND secondary_item_id = %d", $secondary_item_id );
465
-
466
- 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 ) );
467
- }
468
-
469
- function delete_from_user_by_type( $user_id, $component_name, $component_action ) {
470
- global $wpdb, $bp;
471
-
472
- 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 ) );
473
- }
474
-
475
- function delete_all_by_type( $item_id, $component_name, $component_action, $secondary_item_id ) {
476
- global $wpdb, $bp;
477
-
478
- if ( $component_action )
479
- $component_action_sql = $wpdb->prepare( "AND component_action = %s", $component_action );
480
-
481
- if ( $secondary_item_id )
482
- $secondary_item_sql = $wpdb->prepare( "AND secondary_item_id = %d", $secondary_item_id );
483
-
484
- 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 ) );
485
- }
486
- }
487
-
488
-
489
  ?>
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.
5
+ *
6
+ * Example:
7
+ * $user = new BP_Core_User( $user_id );
8
+ * $user_avatar = $user->avatar;
9
+ * $user_email = $user->email;
10
+ * $user_status = $user->status;
11
+ * etc.
12
+ *
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();
37
+
38
+ if ( $populate_extras )
39
+ $this->populate_extras();
40
+ }
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_usermeta() 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 = attribute_escape( $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 = attribute_escape( $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 = attribute_escape( bp_core_get_user_displayname( $this->id ) );
70
+ $this->email = attribute_escape( 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_usermeta( $this->id, 'last_activity' ), __( '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
+
103
+ function get_profile_data() {
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 )
120
+ $sql['select_popular'] = ", um.meta_value as total_friend_count";
121
+
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()";
140
+
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 ) );
147
+ else
148
+ $uids = $wpdb->escape( $include );
149
+
150
+ if ( !empty( $uids ) )
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 ) {
172
+ case 'active': case 'online': default:
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";
180
+ break;
181
+ case 'random':
182
+ $sql[] = "ORDER BY rand()";
183
+ break;
184
+ case 'popular':
185
+ $sql[] = "ORDER BY CONVERT(um.meta_value, SIGNED) DESC";
186
+ break;
187
+ }
188
+
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 = $wpdb->get_results( join( ' ', (array)$sql ) );
194
+
195
+ /* Re-jig the SQL so we can get the total user count */
196
+ unset( $sql['select_main'] );
197
+
198
+ if ( !empty( $sql['select_active'] ) )
199
+ unset( $sql['select_active'] );
200
+
201
+ if ( !empty( $sql['select_popular'] ) )
202
+ unset( $sql['select_popular'] );
203
+
204
+ if ( !empty( $sql['select_alpha'] ) )
205
+ unset( $sql['select_alpha'] );
206
+
207
+ if ( !empty( $sql['pagination'] ) )
208
+ unset( $sql['pagination'] );
209
+
210
+ array_unshift( $sql, "SELECT COUNT(DISTINCT u.ID)" );
211
+
212
+ /* Get total user results */
213
+ $total_users = $wpdb->get_var( join( ' ', (array)$sql ) );
214
+
215
+ /***
216
+ * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
217
+ * 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)
218
+ */
219
+ if ( $populate_extras ) {
220
+ foreach ( (array)$paged_users as $user )
221
+ $user_ids[] = $user->id;
222
+
223
+ $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
224
+
225
+ /* Add additional data to the returned results */
226
+ $paged_users = BP_Core_User::get_user_extras( &$paged_users, $user_ids, $type );
227
+ }
228
+
229
+ return array( 'users' => $paged_users, 'total' => $total_users );
230
+ }
231
+
232
+ function get_users_by_letter( $letter, $limit = null, $page = 1, $populate_extras = true ) {
233
+ global $wpdb, $bp;
234
+
235
+ if ( $limit && $page )
236
+ $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
237
+
238
+ if ( strlen($letter) > 1 || is_numeric($letter) || !$letter )
239
+ return false;
240
+
241
+ $letter = like_escape( $wpdb->escape( $letter ) );
242
+ $status_sql = bp_core_get_status_sql( 'u.' );
243
+
244
+ $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 );
245
+ $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 );
246
+
247
+ $total_users = $wpdb->get_var( $total_users_sql );
248
+ $paged_users = $wpdb->get_results( $paged_users_sql );
249
+
250
+ /***
251
+ * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
252
+ * 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)
253
+ */
254
+ foreach ( (array)$paged_users as $user )
255
+ $user_ids[] = $user->id;
256
+
257
+ $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
258
+
259
+ /* Add additional data to the returned results */
260
+ if ( $populate_extras )
261
+ $paged_users = BP_Core_User::get_user_extras( &$paged_users, &$user_ids );
262
+
263
+ return array( 'users' => $paged_users, 'total' => $total_users );
264
+ }
265
+
266
+ function search_users( $search_terms, $limit = null, $page = 1, $populate_extras = true ) {
267
+ global $wpdb, $bp;
268
+
269
+ if ( $limit && $page )
270
+ $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
271
+
272
+ $search_terms = like_escape( $wpdb->escape( $search_terms ) );
273
+ $status_sql = bp_core_get_status_sql( 'u.' );
274
+
275
+ $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 );
276
+ $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 );
277
+
278
+ $total_users = $wpdb->get_var( $total_users_sql );
279
+ $paged_users = $wpdb->get_results( $paged_users_sql );
280
+
281
+ /***
282
+ * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list.
283
+ * 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)
284
+ */
285
+ foreach ( (array)$paged_users as $user )
286
+ $user_ids[] = $user->id;
287
+
288
+ $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
289
+
290
+ /* Add additional data to the returned results */
291
+ if ( $populate_extras )
292
+ $paged_users = BP_Core_User::get_user_extras( &$paged_users, &$user_ids );
293
+
294
+ return array( 'users' => $paged_users, 'total' => $total_users );
295
+ }
296
+
297
+ function get_user_extras( $paged_users, $user_ids, $type = false ) {
298
+ global $bp, $wpdb;
299
+
300
+ if ( empty( $user_ids ) )
301
+ return $paged_users;
302
+
303
+ /* Fetch the user's full name */
304
+ if ( function_exists( 'xprofile_install' ) && 'alphabetical' != $type ) {
305
+ /* Ensure xprofile globals are set */
306
+ if ( !defined( 'BP_XPROFILE_FULLNAME_FIELD_NAME' ) )
307
+ xprofile_setup_globals();
308
+
309
+ $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 ) );
310
+ for ( $i = 0; $i < count( $paged_users ); $i++ ) {
311
+ foreach ( (array)$names as $name ) {
312
+ if ( $name->id == $paged_users[$i]->id )
313
+ $paged_users[$i]->fullname = $name->fullname;
314
+ }
315
+ }
316
+ }
317
+
318
+ /* Fetch the user's total friend count */
319
+ if ( 'popular' != $type ) {
320
+ $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} )" );
321
+ for ( $i = 0; $i < count( $paged_users ); $i++ ) {
322
+ foreach ( (array)$friend_count as $count ) {
323
+ if ( $count->id == $paged_users[$i]->id )
324
+ $paged_users[$i]->total_friend_count = (int)$count->total_friend_count;
325
+ }
326
+ }
327
+ }
328
+
329
+ /* Fetch whether or not the user is a friend */
330
+ if ( function_exists( 'friends_install' ) ) {
331
+ $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 ) );
332
+ for ( $i = 0; $i < count( $paged_users ); $i++ ) {
333
+ foreach ( (array)$friend_status as $status ) {
334
+ if ( $status->initiator_user_id == $paged_users[$i]->id || $status->friend_user_id == $paged_users[$i]->id )
335
+ $paged_users[$i]->is_friend = $status->is_confirmed;
336
+ }
337
+ }
338
+ }
339
+
340
+ if ( 'active' != $type ) {
341
+ $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} )" );
342
+ for ( $i = 0; $i < count( $paged_users ); $i++ ) {
343
+ foreach ( (array)$user_activity as $activity ) {
344
+ if ( $activity->id == $paged_users[$i]->id )
345
+ $paged_users[$i]->last_activity = $activity->last_activity;
346
+ }
347
+ }
348
+ }
349
+
350
+ /* Fetch the user's last_activity */
351
+ if ( 'active' != $type ) {
352
+ $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} )" );
353
+ for ( $i = 0; $i < count( $paged_users ); $i++ ) {
354
+ foreach ( (array)$user_activity as $activity ) {
355
+ if ( $activity->id == $paged_users[$i]->id )
356
+ $paged_users[$i]->last_activity = $activity->last_activity;
357
+ }
358
+ }
359
+ }
360
+
361
+ /* Fetch the user's latest update */
362
+ $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} )" );
363
+ for ( $i = 0; $i < count( $paged_users ); $i++ ) {
364
+ foreach ( (array)$user_update as $update ) {
365
+ if ( $update->id == $paged_users[$i]->id )
366
+ $paged_users[$i]->latest_update = $update->latest_update;
367
+ }
368
+ }
369
+
370
+ return $paged_users;
371
+ }
372
+
373
+ function get_core_userdata( $user_id ) {
374
+ global $wpdb;
375
+
376
+ if ( !$user = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->users WHERE ID = %d LIMIT 1", $user_id ) ) )
377
+ return false;
378
+
379
+ return $user;
380
+ }
381
+ }
382
+
383
+
384
+ /**
385
+ * BP_Core_Notification class can be used by any component.
386
+ * It will handle the fetching, saving and deleting of a user notification.
387
+ *
388
+ * @package BuddyPress Core
389
+ */
390
+
391
+ class BP_Core_Notification {
392
+ var $id;
393
+ var $item_id;
394
+ var $secondary_item_id = null;
395
+ var $user_id;
396
+ var $component_name;
397
+ var $component_action;
398
+ var $date_notified;
399
+ var $is_new;
400
+
401
+ function bp_core_notification( $id = false ) {
402
+ if ( $id ) {
403
+ $this->id = $id;
404
+ $this->populate();
405
+ }
406
+ }
407
+
408
+ function populate() {
409
+ global $wpdb, $bp;
410
+
411
+ if ( $notification = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE id = %d", $this->id ) ) ) {
412
+ $this->item_id = $notification->item_id;
413
+ $this->secondary_item_id = $notification->secondary_item_id;
414
+ $this->user_id = $notification->user_id;
415
+ $this->component_name = $notification->component_name;
416
+ $this->component_action = $notification->component_action;
417
+ $this->date_notified = $notification->date_notified;
418
+ $this->is_new = $notification->is_new;
419
+ }
420
+ }
421
+
422
+ function save() {
423
+ global $wpdb, $bp;
424
+
425
+ if ( $this->id ) {
426
+ // Update
427
+ $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 = FROM_UNIXTIME(%d), 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 );
428
+ } else {
429
+ // Save
430
+ $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, FROM_UNIXTIME(%d), %d )", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new );
431
+ }
432
+
433
+ if ( !$result = $wpdb->query( $sql ) )
434
+ return false;
435
+
436
+ $this->id = $wpdb->insert_id;
437
+ return true;
438
+ }
439
+
440
+ /* Static functions */
441
+
442
+ function check_access( $user_id, $notification_id ) {
443
+ global $wpdb, $bp;
444
+
445
+ 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 ) );
446
+ }
447
+
448
+ function get_all_for_user( $user_id ) {
449
+ global $wpdb, $bp;
450
+
451
+ return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND is_new = 1", $user_id ) );
452
+ }
453
+
454
+ function delete_for_user_by_type( $user_id, $component_name, $component_action ) {
455
+ global $wpdb, $bp;
456
+
457
+ 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 ) );
458
+ }
459
+
460
+ function delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id ) {
461
+ global $wpdb, $bp;
462
+
463
+ if ( $secondary_item_id )
464
+ $secondary_item_sql = $wpdb->prepare( " AND secondary_item_id = %d", $secondary_item_id );
465
+
466
+ 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 ) );
467
+ }
468
+
469
+ function delete_from_user_by_type( $user_id, $component_name, $component_action ) {
470
+ global $wpdb, $bp;
471
+
472
+ 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 ) );
473
+ }
474
+
475
+ function delete_all_by_type( $item_id, $component_name, $component_action, $secondary_item_id ) {
476
+ global $wpdb, $bp;
477
+
478
+ if ( $component_action )
479
+ $component_action_sql = $wpdb->prepare( "AND component_action = %s", $component_action );
480
+
481
+ if ( $secondary_item_id )
482
+ $secondary_item_sql = $wpdb->prepare( "AND secondary_item_id = %d", $secondary_item_id );
483
+
484
+ 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 ) );
485
+ }
486
+ }
487
+
488
+
489
  ?>
bp-core/bp-core-cssjs.php CHANGED
@@ -1,183 +1,183 @@
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()
30
- *
31
- * Add a hover-able icon to the "BuddyPress" wp-admin area menu.
32
- *
33
- * @package BuddyPress Core
34
- */
35
- function bp_core_admin_menu_icon_css() {
36
- global $bp;
37
- ?>
38
- <style type="text/css">
39
- 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; }
40
- ul#adminmenu li.toplevel_page_bp-general-settings:hover .wp-menu-image a { background-position: -1px 0; }
41
- ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image a img { display: none; }
42
- </style>
43
- <?php
44
- }
45
- add_action( 'admin_head', 'bp_core_admin_menu_icon_css' );
46
-
47
- function bp_core_confirmation_js() {
48
- global $current_blog;
49
-
50
- if ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG )
51
- return false;
52
- ?>
53
- <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>
54
- <?php
55
- }
56
- add_action( 'wp_head', 'bp_core_confirmation_js', 100 );
57
-
58
- /**
59
- * bp_core_add_jquery_cropper()
60
- *
61
- * Makes sure the jQuery jCrop library is loaded.
62
- *
63
- * @package BuddyPress Core
64
- */
65
- function bp_core_add_jquery_cropper() {
66
- wp_enqueue_script( 'jcrop', array( 'jquery' ) );
67
- add_action( 'wp_head', 'bp_core_add_cropper_inline_js' );
68
- add_action( 'wp_head', 'bp_core_add_cropper_inline_css' );
69
- }
70
-
71
- /**
72
- * bp_core_add_cropper_inline_js()
73
- *
74
- * Adds the inline JS needed for the cropper to work on a per-page basis.
75
- *
76
- * @package BuddyPress Core
77
- */
78
- function bp_core_add_cropper_inline_js() {
79
- global $bp;
80
-
81
- $image = apply_filters( 'bp_inline_cropper_image', getimagesize( BP_AVATAR_UPLOAD_PATH . $bp->avatar_admin->image->dir ) );
82
- $aspect_ratio = 1;
83
-
84
- /* Calculate Aspect Ratio */
85
- if ( (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) && ( (int) constant( 'BP_AVATAR_FULL_WIDTH' ) != (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) ) )
86
- $aspect_ratio = (int) constant( 'BP_AVATAR_FULL_WIDTH' ) / (int) constant( 'BP_AVATAR_FULL_HEIGHT' );
87
- ?>
88
- <script type="text/javascript">
89
- jQuery(window).load( function(){
90
- jQuery('#avatar-to-crop').Jcrop({
91
- onChange: showPreview,
92
- onSelect: showPreview,
93
- onSelect: updateCoords,
94
- aspectRatio: <?php echo $aspect_ratio ?>,
95
- setSelect: [ 50, 50, <?php echo $image[0] / 2 ?>, <?php echo $image[1] / 2 ?> ]
96
- });
97
- });
98
-
99
- function updateCoords(c) {
100
- jQuery('#x').val(c.x);
101
- jQuery('#y').val(c.y);
102
- jQuery('#w').val(c.w);
103
- jQuery('#h').val(c.h);
104
- };
105
-
106
- function showPreview(coords) {
107
- if ( parseInt(coords.w) > 0 ) {
108
- var rx = <?php echo (int) constant( 'BP_AVATAR_FULL_WIDTH' ) ?> / coords.w;
109
- var ry = <?php echo (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) ?> / coords.h;
110
-
111
- jQuery('#avatar-crop-preview').css({
112
- <?php if ( $image ) : ?>
113
- width: Math.round(rx * <?php echo $image[0] ?>) + 'px',
114
- height: Math.round(ry * <?php echo $image[1] ?>) + 'px',
115
- <?php endif; ?>
116
- marginLeft: '-' + Math.round(rx * coords.x) + 'px',
117
- marginTop: '-' + Math.round(ry * coords.y) + 'px'
118
- });
119
- }
120
- }
121
- </script>
122
- <?php
123
- }
124
-
125
- /**
126
- * bp_core_add_cropper_inline_css()
127
- *
128
- * Adds the inline CSS needed for the cropper to work on a per-page basis.
129
- *
130
- * @package BuddyPress Core
131
- */
132
- function bp_core_add_cropper_inline_css() {
133
- global $bp;
134
- ?>
135
- <style type="text/css">
136
- .jcrop-holder { float: left; margin: 0 20px 20px 0; text-align: left; }
137
- .jcrop-vline, .jcrop-hline { font-size: 0; position: absolute; background: white top left repeat url( <?php echo BP_PLUGIN_URL ?>/bp-core/images/Jcrop.gif ); }
138
- .jcrop-vline { height: 100%; width: 1px !important; }
139
- .jcrop-hline { width: 100%; height: 1px !important; }
140
- .jcrop-handle { font-size: 1px; width: 7px !important; height: 7px !important; border: 1px #eee solid; background-color: #333; *width: 9px; *height: 9px; }
141
- .jcrop-tracker { width: 100%; height: 100%; }
142
- .custom .jcrop-vline, .custom .jcrop-hline { background: yellow; }
143
- .custom .jcrop-handle { border-color: black; background-color: #C7BB00; -moz-border-radius: 3px; -webkit-border-radius: 3px; }
144
- #avatar-crop-pane { width: <?php echo BP_AVATAR_FULL_WIDTH ?>px; height: <?php echo BP_AVATAR_FULL_HEIGHT ?>px; overflow: hidden; }
145
- #avatar-crop-submit { margin: 20px 0; }
146
- #avatar-upload-form img, #create-group-form img, #group-settings-form img { border: none !important; }
147
- </style>
148
- <?php
149
- }
150
-
151
- /**
152
- * bp_core_add_ajax_url_js()
153
- *
154
- * Adds AJAX target URL so themes can access the WordPress AJAX functionality.
155
- *
156
- * @package BuddyPress Core
157
- */
158
- function bp_core_add_ajax_url_js() {
159
- global $bp;
160
-
161
- echo
162
- '<script type="text/javascript">var ajaxurl = "' . site_url( 'wp-load.php' ) . '";</script>
163
- ';
164
- }
165
- add_action( 'wp_head', 'bp_core_add_ajax_url_js' );
166
-
167
- /**
168
- * bp_core_override_adminbar_css()
169
- *
170
- * Overrides the theme's admin bar CSS to hide the adminbar if disabled.
171
- *
172
- * @package BuddyPress Core
173
- */
174
- function bp_core_override_adminbar_css() {
175
- global $bp;
176
-
177
- if ( defined( 'BP_DISABLE_ADMIN_BAR' ) || ( (int)get_site_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() ) ) {
178
- ?>
179
- <style type="text/css">body { padding-top: 0 !important; } #wp-admin-bar { display: none; }</style>
180
- <?php }
181
- }
182
- add_action( 'wp_footer', 'bp_core_override_adminbar_css' );
183
  ?>
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()
30
+ *
31
+ * Add a hover-able icon to the "BuddyPress" wp-admin area menu.
32
+ *
33
+ * @package BuddyPress Core
34
+ */
35
+ function bp_core_admin_menu_icon_css() {
36
+ global $bp;
37
+ ?>
38
+ <style type="text/css">
39
+ 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; }
40
+ 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; }
41
+ ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image a img { display: none; }
42
+ </style>
43
+ <?php
44
+ }
45
+ add_action( 'admin_head', 'bp_core_admin_menu_icon_css' );
46
+
47
+ function bp_core_confirmation_js() {
48
+ global $current_blog;
49
+
50
+ if ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG )
51
+ return false;
52
+ ?>
53
+ <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>
54
+ <?php
55
+ }
56
+ add_action( 'wp_head', 'bp_core_confirmation_js', 100 );
57
+
58
+ /**
59
+ * bp_core_add_jquery_cropper()
60
+ *
61
+ * Makes sure the jQuery jCrop library is loaded.
62
+ *
63
+ * @package BuddyPress Core
64
+ */
65
+ function bp_core_add_jquery_cropper() {
66
+ wp_enqueue_script( 'jcrop', array( 'jquery' ) );
67
+ add_action( 'wp_head', 'bp_core_add_cropper_inline_js' );
68
+ add_action( 'wp_head', 'bp_core_add_cropper_inline_css' );
69
+ }
70
+
71
+ /**
72
+ * bp_core_add_cropper_inline_js()
73
+ *
74
+ * Adds the inline JS needed for the cropper to work on a per-page basis.
75
+ *
76
+ * @package BuddyPress Core
77
+ */
78
+ function bp_core_add_cropper_inline_js() {
79
+ global $bp;
80
+
81
+ $image = apply_filters( 'bp_inline_cropper_image', getimagesize( BP_AVATAR_UPLOAD_PATH . $bp->avatar_admin->image->dir ) );
82
+ $aspect_ratio = 1;
83
+
84
+ /* Calculate Aspect Ratio */
85
+ if ( (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) && ( (int) constant( 'BP_AVATAR_FULL_WIDTH' ) != (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) ) )
86
+ $aspect_ratio = (int) constant( 'BP_AVATAR_FULL_WIDTH' ) / (int) constant( 'BP_AVATAR_FULL_HEIGHT' );
87
+ ?>
88
+ <script type="text/javascript">
89
+ jQuery(window).load( function(){
90
+ jQuery('#avatar-to-crop').Jcrop({
91
+ onChange: showPreview,
92
+ onSelect: showPreview,
93
+ onSelect: updateCoords,
94
+ aspectRatio: <?php echo $aspect_ratio ?>,
95
+ setSelect: [ 50, 50, <?php echo $image[0] / 2 ?>, <?php echo $image[1] / 2 ?> ]
96
+ });
97
+ });
98
+
99
+ function updateCoords(c) {
100
+ jQuery('#x').val(c.x);
101
+ jQuery('#y').val(c.y);
102
+ jQuery('#w').val(c.w);
103
+ jQuery('#h').val(c.h);
104
+ };
105
+
106
+ function showPreview(coords) {
107
+ if ( parseInt(coords.w) > 0 ) {
108
+ var rx = <?php echo (int) constant( 'BP_AVATAR_FULL_WIDTH' ) ?> / coords.w;
109
+ var ry = <?php echo (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) ?> / coords.h;
110
+
111
+ jQuery('#avatar-crop-preview').css({
112
+ <?php if ( $image ) : ?>
113
+ width: Math.round(rx * <?php echo $image[0] ?>) + 'px',
114
+ height: Math.round(ry * <?php echo $image[1] ?>) + 'px',
115
+ <?php endif; ?>
116
+ marginLeft: '-' + Math.round(rx * coords.x) + 'px',
117
+ marginTop: '-' + Math.round(ry * coords.y) + 'px'
118
+ });
119
+ }
120
+ }
121
+ </script>
122
+ <?php
123
+ }
124
+
125
+ /**
126
+ * bp_core_add_cropper_inline_css()
127
+ *
128
+ * Adds the inline CSS needed for the cropper to work on a per-page basis.
129
+ *
130
+ * @package BuddyPress Core
131
+ */
132
+ function bp_core_add_cropper_inline_css() {
133
+ global $bp;
134
+ ?>
135
+ <style type="text/css">
136
+ .jcrop-holder { float: left; margin: 0 20px 20px 0; text-align: left; }
137
+ .jcrop-vline, .jcrop-hline { font-size: 0; position: absolute; background: white top left repeat url( <?php echo BP_PLUGIN_URL ?>/bp-core/images/Jcrop.gif ); }
138
+ .jcrop-vline { height: 100%; width: 1px !important; }
139
+ .jcrop-hline { width: 100%; height: 1px !important; }
140
+ .jcrop-handle { font-size: 1px; width: 7px !important; height: 7px !important; border: 1px #eee solid; background-color: #333; *width: 9px; *height: 9px; }
141
+ .jcrop-tracker { width: 100%; height: 100%; }
142
+ .custom .jcrop-vline, .custom .jcrop-hline { background: yellow; }
143
+ .custom .jcrop-handle { border-color: black; background-color: #C7BB00; -moz-border-radius: 3px; -webkit-border-radius: 3px; }
144
+ #avatar-crop-pane { width: <?php echo BP_AVATAR_FULL_WIDTH ?>px; height: <?php echo BP_AVATAR_FULL_HEIGHT ?>px; overflow: hidden; }
145
+ #avatar-crop-submit { margin: 20px 0; }
146
+ #avatar-upload-form img, #create-group-form img, #group-settings-form img { border: none !important; }
147
+ </style>
148
+ <?php
149
+ }
150
+
151
+ /**
152
+ * bp_core_add_ajax_url_js()
153
+ *
154
+ * Adds AJAX target URL so themes can access the WordPress AJAX functionality.
155
+ *
156
+ * @package BuddyPress Core
157
+ */
158
+ function bp_core_add_ajax_url_js() {
159
+ global $bp;
160
+
161
+ echo
162
+ '<script type="text/javascript">var ajaxurl = "' . site_url( 'wp-load.php' ) . '";</script>
163
+ ';
164
+ }
165
+ add_action( 'wp_head', 'bp_core_add_ajax_url_js' );
166
+
167
+ /**
168
+ * bp_core_override_adminbar_css()
169
+ *
170
+ * Overrides the theme's admin bar CSS to hide the adminbar if disabled.
171
+ *
172
+ * @package BuddyPress Core
173
+ */
174
+ function bp_core_override_adminbar_css() {
175
+ global $bp;
176
+
177
+ if ( defined( 'BP_DISABLE_ADMIN_BAR' ) || ( (int)get_site_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() ) ) {
178
+ ?>
179
+ <style type="text/css">body { padding-top: 0 !important; } #wp-admin-bar { display: none; }</style>
180
+ <?php }
181
+ }
182
+ add_action( 'wp_footer', 'bp_core_override_adminbar_css' );
183
  ?>
bp-core/bp-core-notifications.php CHANGED
@@ -1,95 +1,95 @@
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 = 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
  ?>
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 = 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 CHANGED
@@ -1,198 +1,198 @@
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_site_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( 'wp', 'bp_core_add_settings_nav', 2 );
28
- add_action( 'admin_menu', 'bp_core_add_settings_nav', 2 );
29
-
30
- /**** GENERAL SETTINGS ****/
31
-
32
- function bp_core_screen_general_settings() {
33
- global $current_user, $bp_settings_updated, $pass_error;
34
-
35
- $bp_settings_updated = false;
36
- $pass_error = false;
37
-
38
- if ( isset($_POST['submit']) ) {
39
- check_admin_referer('bp_settings_general');
40
-
41
- require_once( WPINC . '/registration.php' );
42
-
43
- // Form has been submitted and nonce checks out, lets do it.
44
-
45
- if ( $_POST['email'] != '' )
46
- $current_user->user_email = wp_specialchars( trim( $_POST['email'] ) );
47
-
48
- if ( $_POST['pass1'] != '' && $_POST['pass2'] != '' ) {
49
- if ( $_POST['pass1'] == $_POST['pass2'] && !strpos( " " . $_POST['pass1'], "\\" ) )
50
- $current_user->user_pass = $_POST['pass1'];
51
- else
52
- $pass_error = true;
53
- } else if ( empty( $_POST['pass1'] ) && !empty( $_POST['pass2'] ) || !empty( $_POST['pass1'] ) && empty( $_POST['pass2'] ) ) {
54
- $pass_error = true;
55
- } else {
56
- unset( $current_user->user_pass );
57
- }
58
-
59
- if ( !$pass_error && wp_update_user( get_object_vars( $current_user ) ) )
60
- $bp_settings_updated = true;
61
- }
62
-
63
- add_action( 'bp_template_title', 'bp_core_screen_general_settings_title' );
64
- add_action( 'bp_template_content', 'bp_core_screen_general_settings_content' );
65
-
66
- bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
67
- }
68
-
69
- function bp_core_screen_general_settings_title() {
70
- _e( 'General Settings', 'buddypress' );
71
- }
72
-
73
- function bp_core_screen_general_settings_content() {
74
- global $bp, $current_user, $bp_settings_updated, $pass_error; ?>
75
-
76
- <?php if ( $bp_settings_updated && !$pass_error ) { ?>
77
- <div id="message" class="updated fade">
78
- <p><?php _e( 'Changes Saved.', 'buddypress' ) ?></p>
79
- </div>
80
- <?php } ?>
81
-
82
- <?php if ( $pass_error && !$bp_settings_updated ) { ?>
83
- <div id="message" class="error fade">
84
- <p><?php _e( 'Your passwords did not match', 'buddypress' ) ?></p>
85
- </div>
86
- <?php } ?>
87
-
88
- <form action="<?php echo $bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/general' ?>" method="post" class="standard-form" id="settings-form">
89
- <label for="email"><?php _e( 'Account Email', 'buddypress' ) ?></label>
90
- <input type="text" name="email" id="email" value="<?php echo attribute_escape( $current_user->user_email ); ?>" class="settings-input" />
91
-
92
- <label for="pass1"><?php _e( 'Change Password <span>(leave blank for no change)</span>', 'buddypress' ) ?></label>
93
- <input type="password" name="pass1" id="pass1" size="16" value="" class="settings-input small" /> &nbsp;<?php _e( 'New Password', 'buddypress' ) ?><br />
94
- <input type="password" name="pass2" id="pass2" size="16" value="" class="settings-input small" /> &nbsp;<?php _e( 'Repeat New Password', 'buddypress' ) ?>
95
-
96
- <div class="submit">
97
- <input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto" />
98
- </div>
99
-
100
- <?php wp_nonce_field('bp_settings_general') ?>
101
- </form>
102
- <?php
103
- }
104
-
105
- /***** NOTIFICATION SETTINGS ******/
106
-
107
- function bp_core_screen_notification_settings() {
108
- global $current_user, $bp_settings_updated;
109
-
110
- $bp_settings_updated = false;
111
-
112
- if ( $_POST['submit'] ) {
113
- check_admin_referer('bp_settings_notifications');
114
-
115
- if ( $_POST['notifications'] ) {
116
- foreach ( (array)$_POST['notifications'] as $key => $value ) {
117
- update_usermeta( (int)$current_user->id, $key, $value );
118
- }
119
- }
120
-
121
- $bp_settings_updated = true;
122
- }
123
-
124
- add_action( 'bp_template_title', 'bp_core_screen_notification_settings_title' );
125
- add_action( 'bp_template_content', 'bp_core_screen_notification_settings_content' );
126
-
127
- bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
128
- }
129
-
130
- function bp_core_screen_notification_settings_title() {
131
- _e( 'Notification Settings', 'buddypress' );
132
- }
133
-
134
- function bp_core_screen_notification_settings_content() {
135
- global $bp, $current_user, $bp_settings_updated; ?>
136
-
137
- <?php if ( $bp_settings_updated ) { ?>
138
- <div id="message" class="updated fade">
139
- <p><?php _e( 'Changes Saved.', 'buddypress' ) ?></p>
140
- </div>
141
- <?php } ?>
142
-
143
- <form action="<?php echo $bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/notifications' ?>" method="post" id="settings-form">
144
- <h3><?php _e( 'Email Notifications', 'buddypress' ) ?></h3>
145
- <p><?php _e( 'Send a notification by email when:', 'buddypress' ) ?></p>
146
-
147
- <?php do_action( 'bp_notification_settings' ) ?>
148
-
149
- <div class="submit">
150
- <input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto" />
151
- </div>
152
-
153
- <?php wp_nonce_field('bp_settings_notifications') ?>
154
-
155
- </form>
156
- <?php
157
- }
158
-
159
- /**** DELETE ACCOUNT ****/
160
-
161
- function bp_core_screen_delete_account() {
162
- if ( isset( $_POST['delete-account-understand'] ) ) {
163
- check_admin_referer( 'delete-account' );
164
-
165
- // delete the users account
166
- if ( bp_core_delete_account() )
167
- bp_core_redirect( site_url() );
168
- }
169
-
170
- add_action( 'bp_template_title', 'bp_core_screen_delete_account_title' );
171
- add_action( 'bp_template_content', 'bp_core_screen_delete_account_content' );
172
-
173
- bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
174
- }
175
-
176
- function bp_core_screen_delete_account_title() {
177
- _e( 'Delete Account', 'buddypress' );
178
- }
179
-
180
- function bp_core_screen_delete_account_content() {
181
- global $bp, $current_user, $bp_settings_updated, $pass_error; ?>
182
-
183
- <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">
184
-
185
- <div id="message" class="info">
186
- <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>
187
- </div>
188
-
189
- <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' ); ?>
190
-
191
- <div class="submit">
192
- <input type="submit" disabled="disabled" value="<?php _e( 'Delete My Account', 'buddypress' ) ?> &rarr;" id="delete-account-button" name="delete-account-button" />
193
- </div>
194
-
195
- <?php wp_nonce_field('delete-account') ?>
196
- </form>
197
- <?php
198
- }
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_site_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( 'wp', 'bp_core_add_settings_nav', 2 );
28
+ add_action( 'admin_menu', 'bp_core_add_settings_nav', 2 );
29
+
30
+ /**** GENERAL SETTINGS ****/
31
+
32
+ function bp_core_screen_general_settings() {
33
+ global $current_user, $bp_settings_updated, $pass_error;
34
+
35
+ $bp_settings_updated = false;
36
+ $pass_error = false;
37
+
38
+ if ( isset($_POST['submit']) ) {
39
+ check_admin_referer('bp_settings_general');
40
+
41
+ require_once( WPINC . '/registration.php' );
42
+
43
+ // Form has been submitted and nonce checks out, lets do it.
44
+
45
+ if ( $_POST['email'] != '' )
46
+ $current_user->user_email = wp_specialchars( trim( $_POST['email'] ) );
47
+
48
+ if ( $_POST['pass1'] != '' && $_POST['pass2'] != '' ) {
49
+ if ( $_POST['pass1'] == $_POST['pass2'] && !strpos( " " . $_POST['pass1'], "\\" ) )
50
+ $current_user->user_pass = $_POST['pass1'];
51
+ else
52
+ $pass_error = true;
53
+ } else if ( empty( $_POST['pass1'] ) && !empty( $_POST['pass2'] ) || !empty( $_POST['pass1'] ) && empty( $_POST['pass2'] ) ) {
54
+ $pass_error = true;
55
+ } else {
56
+ unset( $current_user->user_pass );
57
+ }
58
+
59
+ if ( !$pass_error && wp_update_user( get_object_vars( $current_user ) ) )
60
+ $bp_settings_updated = true;
61
+ }
62
+
63
+ add_action( 'bp_template_title', 'bp_core_screen_general_settings_title' );
64
+ add_action( 'bp_template_content', 'bp_core_screen_general_settings_content' );
65
+
66
+ bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
67
+ }
68
+
69
+ function bp_core_screen_general_settings_title() {
70
+ _e( 'General Settings', 'buddypress' );
71
+ }
72
+
73
+ function bp_core_screen_general_settings_content() {
74
+ global $bp, $current_user, $bp_settings_updated, $pass_error; ?>
75
+
76
+ <?php if ( $bp_settings_updated && !$pass_error ) { ?>
77
+ <div id="message" class="updated fade">
78
+ <p><?php _e( 'Changes Saved.', 'buddypress' ) ?></p>
79
+ </div>
80
+ <?php } ?>
81
+
82
+ <?php if ( $pass_error && !$bp_settings_updated ) { ?>
83
+ <div id="message" class="error fade">
84
+ <p><?php _e( 'Your passwords did not match', 'buddypress' ) ?></p>
85
+ </div>
86
+ <?php } ?>
87
+
88
+ <form action="<?php echo $bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/general' ?>" method="post" class="standard-form" id="settings-form">
89
+ <label for="email"><?php _e( 'Account Email', 'buddypress' ) ?></label>
90
+ <input type="text" name="email" id="email" value="<?php echo attribute_escape( $current_user->user_email ); ?>" class="settings-input" />
91
+
92
+ <label for="pass1"><?php _e( 'Change Password <span>(leave blank for no change)</span>', 'buddypress' ) ?></label>
93
+ <input type="password" name="pass1" id="pass1" size="16" value="" class="settings-input small" /> &nbsp;<?php _e( 'New Password', 'buddypress' ) ?><br />
94
+ <input type="password" name="pass2" id="pass2" size="16" value="" class="settings-input small" /> &nbsp;<?php _e( 'Repeat New Password', 'buddypress' ) ?>
95
+
96
+ <div class="submit">
97
+ <input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto" />
98
+ </div>
99
+
100
+ <?php wp_nonce_field('bp_settings_general') ?>
101
+ </form>
102
+ <?php
103
+ }
104
+
105
+ /***** NOTIFICATION SETTINGS ******/
106
+
107
+ function bp_core_screen_notification_settings() {
108
+ global $current_user, $bp_settings_updated;
109
+
110
+ $bp_settings_updated = false;
111
+
112
+ if ( $_POST['submit'] ) {
113
+ check_admin_referer('bp_settings_notifications');
114
+
115
+ if ( $_POST['notifications'] ) {
116
+ foreach ( (array)$_POST['notifications'] as $key => $value ) {
117
+ update_usermeta( (int)$current_user->id, $key, $value );
118
+ }
119
+ }
120
+
121
+ $bp_settings_updated = true;
122
+ }
123
+
124
+ add_action( 'bp_template_title', 'bp_core_screen_notification_settings_title' );
125
+ add_action( 'bp_template_content', 'bp_core_screen_notification_settings_content' );
126
+
127
+ bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
128
+ }
129
+
130
+ function bp_core_screen_notification_settings_title() {
131
+ _e( 'Notification Settings', 'buddypress' );
132
+ }
133
+
134
+ function bp_core_screen_notification_settings_content() {
135
+ global $bp, $current_user, $bp_settings_updated; ?>
136
+
137
+ <?php if ( $bp_settings_updated ) { ?>
138
+ <div id="message" class="updated fade">
139
+ <p><?php _e( 'Changes Saved.', 'buddypress' ) ?></p>
140
+ </div>
141
+ <?php } ?>
142
+
143
+ <form action="<?php echo $bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/notifications' ?>" method="post" id="settings-form">
144
+ <h3><?php _e( 'Email Notifications', 'buddypress' ) ?></h3>
145
+ <p><?php _e( 'Send a notification by email when:', 'buddypress' ) ?></p>
146
+
147
+ <?php do_action( 'bp_notification_settings' ) ?>
148
+
149
+ <div class="submit">
150
+ <input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto" />
151
+ </div>
152
+
153
+ <?php wp_nonce_field('bp_settings_notifications') ?>
154
+
155
+ </form>
156
+ <?php
157
+ }
158
+
159
+ /**** DELETE ACCOUNT ****/
160
+
161
+ function bp_core_screen_delete_account() {
162
+ if ( isset( $_POST['delete-account-understand'] ) ) {
163
+ check_admin_referer( 'delete-account' );
164
+
165
+ // delete the users account
166
+ if ( bp_core_delete_account() )
167
+ bp_core_redirect( site_url() );
168
+ }
169
+
170
+ add_action( 'bp_template_title', 'bp_core_screen_delete_account_title' );
171
+ add_action( 'bp_template_content', 'bp_core_screen_delete_account_content' );
172
+
173
+ bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
174
+ }
175
+
176
+ function bp_core_screen_delete_account_title() {
177
+ _e( 'Delete Account', 'buddypress' );
178
+ }
179
+
180
+ function bp_core_screen_delete_account_content() {
181
+ global $bp, $current_user, $bp_settings_updated, $pass_error; ?>
182
+
183
+ <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">
184
+
185
+ <div id="message" class="info">
186
+ <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>
187
+ </div>
188
+
189
+ <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' ); ?>
190
+
191
+ <div class="submit">
192
+ <input type="submit" disabled="disabled" value="<?php _e( 'Delete My Account', 'buddypress' ) ?> &rarr;" id="delete-account-button" name="delete-account-button" />
193
+ </div>
194
+
195
+ <?php wp_nonce_field('delete-account') ?>
196
+ </form>
197
+ <?php
198
+ }
bp-core/bp-core-signup.php CHANGED
@@ -1,579 +1,625 @@
1
- <?php
2
-
3
- /********************************************************************************
4
- * Screen Functions
5
- *
6
- * Screen functions are the controllers of BuddyPress. They will execute when their
7
- * specific URL is caught. They will first save or manipulate data using business
8
- * functions, then pass on the user to a template file.
9
- */
10
-
11
- function bp_core_screen_signup() {
12
- global $bp, $wpdb;
13
-
14
- if ( $bp->current_component != BP_REGISTER_SLUG )
15
- return false;
16
-
17
- /* If the user is logged in, redirect away from here */
18
- if ( is_user_logged_in() )
19
- bp_core_redirect( $bp->root_domain );
20
-
21
- /* If signups are disabled, just re-direct */
22
- if ( !bp_get_signup_allowed() )
23
- bp_core_redirect( $bp->root_domain );
24
-
25
- $bp->signup->step = 'request-details';
26
-
27
- /* If the signup page is submitted, validate and save */
28
- if ( isset( $_POST['signup_submit'] ) ) {
29
-
30
- /* Check the nonce */
31
- check_admin_referer( 'bp_new_signup' );
32
-
33
- require_once( ABSPATH . WPINC . '/registration.php' );
34
-
35
- /* Check the base account details for problems */
36
- $account_details = bp_core_validate_user_signup( $_POST['signup_username'], $_POST['signup_email'] );
37
-
38
- /* If there are errors with account details, set them for display */
39
- if ( !empty( $account_details['errors']->errors['user_name'] ) )
40
- $bp->signup->errors['signup_username'] = $account_details['errors']->errors['user_name'][0];
41
-
42
- if ( !empty( $account_details['errors']->errors['user_email'] ) )
43
- $bp->signup->errors['signup_email'] = $account_details['errors']->errors['user_email'][0];
44
-
45
- /* Check that both password fields are filled in */
46
- if ( empty( $_POST['signup_password'] ) || empty( $_POST['signup_password_confirm'] ) )
47
- $bp->signup->errors['signup_password'] = __( 'Please make sure you enter your password twice', 'buddypress' );
48
-
49
- /* Check that the passwords match */
50
- if ( ( !empty( $_POST['signup_password'] ) && !empty( $_POST['signup_password_confirm'] ) ) && $_POST['signup_password'] != $_POST['signup_password_confirm'] )
51
- $bp->signup->errors['signup_password'] = __( 'The passwords you entered do not match.', 'buddypress' );
52
-
53
- $bp->signup->username = $_POST['signup_username'];
54
- $bp->signup->email = $_POST['signup_email'];
55
-
56
- /* Now we've checked account details, we can check profile information */
57
- if ( function_exists( 'xprofile_check_is_required_field' ) ) {
58
-
59
- /* Make sure hidden field is passed and populated */
60
- if ( isset( $_POST['signup_profile_field_ids'] ) && !empty( $_POST['signup_profile_field_ids'] ) ) {
61
-
62
- /* Let's compact any profile field info into an array */
63
- $profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] );
64
-
65
- /* Loop through the posted fields formatting any datebox values then validate the field */
66
- foreach ( (array) $profile_field_ids as $field_id ) {
67
- if ( !isset( $_POST['field_' . $field_id] ) ) {
68
- if ( isset( $_POST['field_' . $field_id . '_day'] ) )
69
- $_POST['field_' . $field_id] = strtotime( $_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year'] );
70
- }
71
-
72
- /* Create errors for required fields without values */
73
- if ( xprofile_check_is_required_field( $field_id ) && empty( $_POST['field_' . $field_id] ) )
74
- $bp->signup->errors['field_' . $field_id] = __( 'This is a required field', 'buddypress' );
75
- }
76
-
77
- /* This situation doesn't naturally occur so bounce to website root */
78
- } else {
79
- bp_core_redirect( $bp->root_domain );
80
- }
81
- }
82
-
83
- /* Finally, let's check the blog details, if the user wants a blog and blog creation is enabled */
84
- if ( isset( $_POST['signup_with_blog'] ) ) {
85
- $active_signup = $bp->site_options['registration'];
86
-
87
- if ( 'blog' == $active_signup || 'all' == $active_signup ) {
88
- $blog_details = bp_core_validate_blog_signup( $_POST['signup_blog_url'], $_POST['signup_blog_title'] );
89
-
90
- /* If there are errors with blog details, set them for display */
91
- if ( !empty( $blog_details['errors']->errors['blogname'] ) )
92
- $bp->signup->errors['signup_blog_url'] = $blog_details['errors']->errors['blogname'][0];
93
-
94
- if ( !empty( $blog_details['errors']->errors['blog_title'] ) )
95
- $bp->signup->errors['signup_blog_title'] = $blog_details['errors']->errors['blog_title'][0];
96
- }
97
- }
98
-
99
- do_action( 'bp_signup_validate' );
100
-
101
- /* Add any errors to the action for the field in the template for display. */
102
- if ( !empty( $bp->signup->errors ) ) {
103
- foreach ( (array)$bp->signup->errors as $fieldname => $error_message )
104
- add_action( 'bp_' . $fieldname . '_errors', create_function( '', 'echo "<div class=\"error\">' . $error_message . '</div>";' ) );
105
- } else {
106
- $bp->signup->step = 'save-details';
107
-
108
- /* No errors! Let's register those deets. */
109
- $active_signup = $bp->site_options['registration'];
110
-
111
- if ( 'none' != $active_signup ) {
112
-
113
- /* Let's compact any profile field info into usermeta */
114
- $profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] );
115
-
116
- /* Loop through the posted fields formatting any datebox values then add to usermeta */
117
- foreach ( (array) $profile_field_ids as $field_id ) {
118
- if ( !isset( $_POST['field_' . $field_id] ) ) {
119
- if ( isset( $_POST['field_' . $field_id . '_day'] ) )
120
- $_POST['field_' . $field_id] = strtotime( $_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year'] );
121
- }
122
-
123
- if ( !empty( $_POST['field_' . $field_id] ) )
124
- $usermeta['field_' . $field_id] = $_POST['field_' . $field_id];
125
- }
126
-
127
- /* Store the profile field ID's in usermeta */
128
- $usermeta['profile_field_ids'] = $_POST['signup_profile_field_ids'];
129
-
130
- /* Hash and store the password */
131
- $usermeta['password'] = wp_hash_password( $_POST['signup_password'] );
132
-
133
- /* If the user decided to create a blog, save those details to usermeta */
134
- if ( 'blog' == $active_signup || 'all' == $active_signup ) {
135
- $usermeta['public'] = ( 'public' == $_POST['signup_blog_privacy'] ) ? true : false;
136
- }
137
-
138
- $usermeta = apply_filters( 'bp_signup_usermeta', $usermeta );
139
-
140
- /* Finally, sign up the user and/or blog */
141
- if ( isset( $_POST['signup_with_blog'] ) && bp_core_is_multisite() )
142
- bp_core_signup_blog( $blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta );
143
- else {
144
- bp_core_signup_user( $_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta );
145
- }
146
-
147
- $bp->signup->step = 'completed-confirmation';
148
- }
149
-
150
- do_action( 'bp_complete_signup' );
151
- }
152
-
153
- }
154
-
155
- $bp->avatar_admin->step = 'upload-image';
156
-
157
- /* If user has uploaded a new avatar */
158
- if ( !empty( $_FILES ) ) {
159
-
160
- /* Check the nonce */
161
- check_admin_referer( 'bp_avatar_upload' );
162
-
163
- $bp->signup->step = 'completed-confirmation';
164
-
165
- if ( bp_core_is_multisite() ) {
166
- /* Get the activation key */
167
- if ( !$bp->signup->key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $_POST[ 'signup_username' ], $_POST[ 'signup_email' ] ) ) ) {
168
- bp_core_add_message( __( 'There was a problem uploading your avatar, please try uploading it again', 'buddypress' ) );
169
- } else {
170
- /* Hash the key to create the upload folder (added security so people don't sniff the activation key) */
171
- $bp->signup->avatar_dir = wp_hash( $bp->signup->key );
172
- }
173
- } else {
174
- $user_id = bp_core_get_userid( $_POST['signup_username'] );
175
- $bp->signup->avatar_dir = wp_hash( $user_id );
176
- }
177
-
178
- /* Pass the file to the avatar upload handler */
179
- if ( bp_core_avatar_handle_upload( $_FILES, 'bp_core_signup_avatar_upload_dir' ) ) {
180
- $bp->avatar_admin->step = 'crop-image';
181
-
182
- /* Make sure we include the jQuery jCrop file for image cropping */
183
- add_action( 'wp', 'bp_core_add_jquery_cropper' );
184
- }
185
- }
186
-
187
- /* If the image cropping is done, crop the image and save a full/thumb version */
188
- if ( isset( $_POST['avatar-crop-submit'] ) ) {
189
-
190
- /* Check the nonce */
191
- check_admin_referer( 'bp_avatar_cropstore' );
192
-
193
- /* Reset the avatar step so we can show the upload form again if needed */
194
- $bp->signup->step = 'completed-confirmation';
195
- $bp->avatar_admin->step = 'upload-image';
196
-
197
- if ( !bp_core_avatar_handle_crop( array( 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h'] ) ) )
198
- bp_core_add_message( __( 'There was a problem cropping your avatar, please try uploading it again', 'buddypress' ), 'error' );
199
- else
200
- bp_core_add_message( __( 'Your new avatar was uploaded successfully', 'buddypress' ) );
201
- }
202
- bp_core_load_template( 'registration/register' );
203
- }
204
- add_action( 'wp', 'bp_core_screen_signup', 3 );
205
-
206
- function bp_core_screen_activation() {
207
- global $bp, $wpdb;
208
-
209
- if ( BP_ACTIVATION_SLUG != $bp->current_component )
210
- return false;
211
-
212
- /* Check if an activation key has been passed */
213
- if ( isset( $_GET['key'] ) ) {
214
-
215
- require_once( ABSPATH . WPINC . '/registration.php' );
216
-
217
- /* Activate the signup */
218
- $user = apply_filters( 'bp_core_activate_account', bp_core_activate_signup( $_GET['key'] ) );
219
-
220
- /* If there was errors, add a message and redirect */
221
- if ( $user->errors ) {
222
- bp_core_add_message( __( 'There was an error activating your account, please try again.', 'buddypress' ), 'error' );
223
- bp_core_redirect( $bp->root_domain . '/' . BP_ACTIVATION_SLUG );
224
- }
225
-
226
- /* Check for an uploaded avatar and move that to the correct user folder */
227
- if ( bp_core_is_multisite() )
228
- $hashed_key = wp_hash( $_GET['key'] );
229
- else
230
- $hashed_key = wp_hash( $user );
231
-
232
- /* Check if the avatar folder exists. If it does, move rename it, move it and delete the signup avatar dir */
233
- if ( file_exists( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key ) )
234
- @rename( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key, BP_AVATAR_UPLOAD_PATH . '/avatars/' . $user );
235
-
236
- bp_core_add_message( __( 'Your account is now active!', 'buddypress' ) );
237
-
238
- $bp->activation_complete = true;
239
- }
240
-
241
- if ( '' != locate_template( array( 'registration/activate' ), false ) )
242
- bp_core_load_template( apply_filters( 'bp_core_template_activate', 'activate' ) );
243
- else
244
- bp_core_load_template( apply_filters( 'bp_core_template_activate', 'registration/activate' ) );
245
- }
246
- add_action( 'wp', 'bp_core_screen_activation', 3 );
247
-
248
-
249
- /********************************************************************************
250
- * Business Functions
251
- *
252
- * Business functions are where all the magic happens in BuddyPress. They will
253
- * handle the actual saving or manipulation of information. Usually they will
254
- * hand off to a database class for data access, then return
255
- * true or false on success or failure.
256
- */
257
-
258
- function bp_core_validate_user_signup( $user_name, $user_email ) {
259
- global $wpdb;
260
-
261
- $errors = new WP_Error();
262
- $user_email = sanitize_email( $user_email );
263
-
264
- if ( empty( $user_name ) )
265
- $errors->add( 'user_name', __( 'Please enter a username', 'buddypress' ) );
266
-
267
- $maybe = array();
268
- preg_match( "/[a-z0-9]+/", $user_name, $maybe );
269
-
270
- $db_illegal_names = get_site_option( 'illegal_names' );
271
- $filtered_illegal_names = apply_filters( 'bp_core_illegal_usernames', array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', BP_GROUPS_SLUG, BP_MEMBERS_SLUG, BP_FORUMS_SLUG, BP_BLOGS_SLUG, BP_REGISTER_SLUG, BP_ACTIVATION_SLUG ) );
272
-
273
- /* Safely merge our illegal names into existing site_option */
274
- $common_names = array_intersect( (array)$db_illegal_names, (array)$filtered_illegal_names );
275
- $diff_names = array_diff( (array)$db_illegal_names, (array)$filtered_illegal_names );
276
- $illegal_names = array_merge( (array)$diff_names, (array)$common_names );
277
-
278
- update_site_option( 'illegal_names', $illegal_names );
279
-
280
- if ( !validate_username( $user_name ) || in_array( $user_name, (array)$illegal_names ) || $user_name != $maybe[0] )
281
- $errors->add( 'user_name', __( 'Only lowercase letters and numbers allowed', 'buddypress' ) );
282
-
283
- if( strlen( $user_name ) < 4 )
284
- $errors->add( 'user_name', __( 'Username must be at least 4 characters', 'buddypress' ) );
285
-
286
- if ( strpos( ' ' . $user_name, '_' ) != false )
287
- $errors->add( 'user_name', __( 'Sorry, usernames may not contain the character "_"!', 'buddypress' ) );
288
-
289
- /* Is the user_name all numeric? */
290
- $match = array();
291
- preg_match( '/[0-9]*/', $user_name, $match );
292
-
293
- if ( $match[0] == $user_name )
294
- $errors->add( 'user_name', __( 'Sorry, usernames must have letters too!', 'buddypress' ) );
295
-
296
- if ( !is_email( $user_email ) )
297
- $errors->add( 'user_email', __( 'Please check your email address.', 'buddypress' ) );
298
-
299
- $limited_email_domains = get_site_option( 'limited_email_domains', 'buddypress' );
300
-
301
- if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
302
- $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
303
-
304
- if ( in_array( $emaildomain, (array)$limited_email_domains ) == false )
305
- $errors->add( 'user_email', __( 'Sorry, that email address is not allowed!', 'buddypress' ) );
306
- }
307
-
308
- /* Check if the username has been used already. */
309
- if ( username_exists( $user_name ) )
310
- $errors->add( 'user_name', __( 'Sorry, that username already exists!', 'buddypress' ) );
311
-
312
- /* Check if the email address has been used already. */
313
- if ( email_exists( $user_email ) )
314
- $errors->add( 'user_email', __( 'Sorry, that email address is already used!', 'buddypress' ) );
315
-
316
- $result = array( 'user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors );
317
-
318
- /* Apply WPMU legacy filter */
319
- $result = apply_filters( 'wpmu_validate_user_signup', $result );
320
-
321
- return apply_filters( 'bp_core_validate_user_signup', $result );
322
- }
323
-
324
- function bp_core_validate_blog_signup( $blog_url, $blog_title ) {
325
- if ( !bp_core_is_multisite() || !function_exists( 'wpmu_validate_blog_signup' ) )
326
- return false;
327
-
328
- return apply_filters( 'bp_core_validate_blog_signup', wpmu_validate_blog_signup( $blog_url, $blog_title ) );
329
- }
330
-
331
- function bp_core_signup_user( $user_login, $user_password, $user_email, $usermeta ) {
332
- global $bp, $wpdb;
333
-
334
- /* Multisite installs have their own install procedure */
335
- if ( bp_core_is_multisite() ) {
336
- wpmu_signup_user( $user_login, $user_email, $usermeta );
337
-
338
- } else {
339
- $errors = new WP_Error();
340
-
341
- $user_id = wp_insert_user( array(
342
- 'user_login' => $user_login,
343
- 'user_pass' => $user_password,
344
- 'display_name' => sanitize_title( $user_login ),
345
- 'user_email' => $user_email
346
- ) );
347
-
348
- if ( !$user_id ) {
349
- $errors->add( 'registerfail', sprintf( __('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'buddypress' ), get_option( 'admin_email' ) ) );
350
- return $errors;
351
- }
352
-
353
- /* Update the user status to '2' which we will use as 'not activated' (0 = active, 1 = spam, 2 = not active) */
354
- $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_status = 2 WHERE ID = %d", $user_id ) );
355
-
356
- /* Set any profile data */
357
- if ( function_exists( 'xprofile_set_field_data' ) ) {
358
- if ( !empty( $usermeta['profile_field_ids'] ) ) {
359
- $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] );
360
-
361
- foreach( (array)$profile_field_ids as $field_id ) {
362
- $current_field = $usermeta["field_{$field_id}"];
363
-
364
- if ( !empty( $current_field ) )
365
- xprofile_set_field_data( $field_id, $user_id, $current_field );
366
- }
367
- }
368
- }
369
- }
370
- $bp->signup->username = $user_login;
371
-
372
- /***
373
- * Now generate an activation key and send an email to the user so they can activate their account
374
- * and validate their email address. Multisite installs send their own email, so this is only for single blog installs.
375
- *
376
- * To disable sending activation emails you can user the filter 'bp_core_signup_send_activation_key' and return false.
377
- */
378
- if ( apply_filters( 'bp_core_signup_send_activation_key', true ) ) {
379
- if ( !bp_core_is_multisite() ) {
380
- $activation_key = wp_hash( $user_id );
381
- update_usermeta( $user_id, 'activation_key', $activation_key );
382
- bp_core_signup_send_validation_email( $user_id, $user_email, $activation_key );
383
- }
384
- }
385
-
386
- do_action( 'bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta );
387
-
388
- return $user_id;
389
- }
390
-
391
- function bp_core_signup_blog( $blog_domain, $blog_path, $blog_title, $user_name, $user_email, $usermeta ) {
392
- if ( !bp_core_is_multisite() || !function_exists( 'wpmu_signup_blog' ) )
393
- return false;
394
-
395
- return apply_filters( 'bp_core_signup_blog', wpmu_signup_blog( $blog_domain, $blog_path, $blog_title, $user_name, $user_email, $usermeta ) );
396
- }
397
-
398
- function bp_core_activate_signup( $key ) {
399
- global $bp, $wpdb;
400
-
401
- $user = false;
402
-
403
- /* Multisite installs have their own activation routine */
404
- if ( bp_core_is_multisite() ) {
405
- $user = wpmu_activate_signup( $key );
406
-
407
- /* If there was errors, add a message and redirect */
408
- if ( $user->errors ) {
409
- bp_core_add_message( __( 'There was an error activating your account, please try again.', 'buddypress' ), 'error' );
410
- bp_core_redirect( $bp->root_domain . '/' . BP_ACTIVATION_SLUG );
411
- }
412
-
413
- $user_id = $user['user_id'];
414
-
415
- /* Set any profile data */
416
- if ( function_exists( 'xprofile_set_field_data' ) ) {
417
- if ( !empty( $user['meta']['profile_field_ids'] ) ) {
418
- $profile_field_ids = explode( ',', $user['meta']['profile_field_ids'] );
419
-
420
- foreach( (array)$profile_field_ids as $field_id ) {
421
- $current_field = $user['meta']["field_{$field_id}"];
422
-
423
- if ( !empty( $current_field ) )
424
- xprofile_set_field_data( $field_id, $user_id, $current_field );
425
- }
426
- }
427
- }
428
-
429
- } else {
430
- /* Get the user_id based on the $key */
431
- $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_value = %s", $key ) );
432
-
433
- if ( empty( $user_id ) )
434
- return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) );
435
-
436
- /* Change the user's status so they become active */
437
- if ( !$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_status = 0 WHERE ID = %d", $user_id ) ) )
438
- return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) );
439
-
440
- /* Notify the site admin of a new user registration */
441
- wp_new_user_notification( $user_id );
442
-
443
- /* Remove the activation key meta */
444
- delete_usermeta( $user_id, 'activation_key' );
445
- }
446
-
447
- /* Update the user_url and display_name */
448
- wp_update_user( array( 'ID' => $user_id, 'user_url' => bp_core_get_user_domain( $user_id, sanitize_title( $user_login ), $user_login ), 'display_name' => bp_core_get_user_displayname( $user_id ) ) );
449
-
450
- /* Add a last active entry */
451
- update_usermeta( $user_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
452
-
453
- /* Set the password on multisite installs */
454
- if ( bp_core_is_multisite() && !empty( $user['meta']['password'] ) )
455
- $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_pass = %s WHERE ID = %d", $user['meta']['password'], $user_id ) );
456
-
457
- /* Delete the total member cache */
458
- wp_cache_delete( 'bp_total_member_count', 'bp' );
459
-
460
- do_action( 'bp_core_activated_user', $user_id, $key, $user );
461
-
462
- return $user_id;
463
- }
464
-
465
- function bp_core_new_user_activity( $user ) {
466
- if ( empty( $user ) || !function_exists( 'bp_activity_add' ) )
467
- return false;
468
-
469
- if ( is_array( $user ) )
470
- $user_id = $user['user_id'];
471
- else
472
- $user_id = $user;
473
-
474
- if ( empty( $user_id ) )
475
- return false;
476
-
477
- $userlink = bp_core_get_userlink( $user_id );
478
-
479
- bp_activity_add( array(
480
- 'user_id' => $user_id,
481
- 'action' => apply_filters( 'bp_core_activity_registered_member_action', sprintf( __( '%s became a registered member', 'buddypress' ), $userlink ), $user_id ),
482
- 'component' => 'profile',
483
- 'type' => 'new_member'
484
- ) );
485
- }
486
- add_action( 'bp_core_activated_user', 'bp_core_new_user_activity' );
487
-
488
- function bp_core_map_user_registration( $user_id ) {
489
- /* Only map data when the site admin is adding users, not on registration. */
490
- if ( !is_admin() )
491
- return false;
492
-
493
- /* Add a last active entry */
494
- update_usermeta( $user_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
495
-
496
- /* Add the user's fullname to Xprofile */
497
- if ( function_exists( 'xprofile_set_field_data' ) ) {
498
- $firstname = get_usermeta( $user_id, 'first_name' );
499
- $lastname = ' ' . get_usermeta( $user_id, 'last_name' );
500
- $name = $firstname . $lastname;
501
-
502
- if ( empty( $name ) || ' ' == $name )
503
- $name = get_usermeta( $user_id, 'nickname' );
504
-
505
- xprofile_set_field_data( 1, $user_id, $name );
506
- }
507
- }
508
- add_action( 'user_register', 'bp_core_map_user_registration' );
509
-
510
- function bp_core_signup_avatar_upload_dir() {
511
- global $bp;
512
-
513
- if ( !$bp->signup->avatar_dir )
514
- return false;
515
-
516
- $path = BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $bp->signup->avatar_dir;
517
- $newbdir = $path;
518
-
519
- if ( !file_exists( $path ) )
520
- @wp_mkdir_p( $path );
521
-
522
- $newurl = BP_AVATAR_URL . '/avatars/signups/' . $bp->signup->avatar_dir;
523
- $newburl = $newurl;
524
- $newsubdir = '/avatars/signups/' . $bp->signup->avatar_dir;
525
-
526
- return apply_filters( 'bp_core_signup_avatar_upload_dir', array( 'path' => $path, 'url' => $newurl, 'subdir' => $newsubdir, 'basedir' => $newbdir, 'baseurl' => $newburl, 'error' => false ) );
527
- }
528
-
529
- function bp_core_signup_send_validation_email( $user_id, $user_email, $key ) {
530
- $activate_url = bp_get_activation_page() ."?key=$key";
531
- $activate_url = clean_url( $activate_url );
532
- $admin_email = get_site_option( "admin_email" );
533
-
534
- if ( empty( $admin_email ) )
535
- $admin_email = 'noreply@' . $_SERVER['SERVER_NAME'];
536
-
537
- $from_name = ( '' == get_option( 'blogname' ) ) ? 'BuddyPress' : wp_specialchars( get_option( 'blogname' ) );
538
- $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n";
539
- $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 );
540
- $subject = '[' . $from_name . '] ' . __( 'Activate Your Account', 'buddypress' );
541
-
542
- /* Send the message */
543
- $to = apply_filters( 'bp_core_activation_signup_user_notification_to', $user_email );
544
- $subject = apply_filters( 'bp_core_activation_signup_user_notification_subject', $subject );
545
- $message = apply_filters( 'bp_core_activation_signup_user_notification_message', $message );
546
-
547
- wp_mail( $to, $subject, $message, $message_headers );
548
- }
549
-
550
- /* Stop user accounts logging in that have not been activated (user_status = 2) */
551
- function bp_core_signup_disable_inactive( $auth_obj, $username ) {
552
- global $bp, $wpdb;
553
-
554
- if ( !$user_id = bp_core_get_userid( $username ) )
555
- return $auth_obj;
556
-
557
- $user_status = (int) $wpdb->get_var( $wpdb->prepare( "SELECT user_status FROM $wpdb->users WHERE ID = %d", $user_id ) );
558
-
559
- if ( 2 == $user_status )
560
- bp_core_redirect( $bp->root_domain );
561
- else
562
- return $auth_obj;
563
- }
564
- add_filter( 'authenticate', 'bp_core_signup_disable_inactive', 11, 2 );
565
-
566
- /* Kill the wp-signup.php if custom registration signup templates are present */
567
- function bp_core_wpsignup_redirect() {
568
- if ( false === strpos( $_SERVER['SCRIPT_NAME'], 'wp-signup.php') && $_GET['action'] != 'register' )
569
- return false;
570
-
571
- if ( locate_template( array( 'registration/register.php' ), false ) || locate_template( array( 'register.php' ), false ) )
572
- bp_core_redirect( bp_get_root_domain() . '/' . BP_REGISTER_SLUG . '/' );
573
- }
574
- if ( bp_core_is_multisite() )
575
- add_action( 'wp', 'bp_core_wpsignup_redirect' );
576
- else
577
- add_action( 'init', 'bp_core_wpsignup_redirect' );
578
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
579
  ?>
1
+ <?php
2
+
3
+ /********************************************************************************
4
+ * Screen Functions
5
+ *
6
+ * Screen functions are the controllers of BuddyPress. They will execute when their
7
+ * specific URL is caught. They will first save or manipulate data using business
8
+ * functions, then pass on the user to a template file.
9
+ */
10
+
11
+ function bp_core_screen_signup() {
12
+ global $bp, $wpdb;
13
+
14
+ if ( $bp->current_component != BP_REGISTER_SLUG )
15
+ return false;
16
+
17
+ /* If the user is logged in, redirect away from here */
18
+ if ( is_user_logged_in() )
19
+ bp_core_redirect( $bp->root_domain );
20
+
21
+ /* If signups are disabled, just re-direct */
22
+ if ( !bp_get_signup_allowed() )
23
+ bp_core_redirect( $bp->root_domain );
24
+
25
+ $bp->signup->step = 'request-details';
26
+
27
+ /* If the signup page is submitted, validate and save */
28
+ if ( isset( $_POST['signup_submit'] ) ) {
29
+
30
+ /* Check the nonce */
31
+ check_admin_referer( 'bp_new_signup' );
32
+
33
+ require_once( ABSPATH . WPINC . '/registration.php' );
34
+
35
+ /* Check the base account details for problems */
36
+ $account_details = bp_core_validate_user_signup( $_POST['signup_username'], $_POST['signup_email'] );
37
+
38
+ /* If there are errors with account details, set them for display */
39
+ if ( !empty( $account_details['errors']->errors['user_name'] ) )
40
+ $bp->signup->errors['signup_username'] = $account_details['errors']->errors['user_name'][0];
41
+
42
+ if ( !empty( $account_details['errors']->errors['user_email'] ) )
43
+ $bp->signup->errors['signup_email'] = $account_details['errors']->errors['user_email'][0];
44
+
45
+ /* Check that both password fields are filled in */
46
+ if ( empty( $_POST['signup_password'] ) || empty( $_POST['signup_password_confirm'] ) )
47
+ $bp->signup->errors['signup_password'] = __( 'Please make sure you enter your password twice', 'buddypress' );
48
+
49
+ /* Check that the passwords match */
50
+ if ( ( !empty( $_POST['signup_password'] ) && !empty( $_POST['signup_password_confirm'] ) ) && $_POST['signup_password'] != $_POST['signup_password_confirm'] )
51
+ $bp->signup->errors['signup_password'] = __( 'The passwords you entered do not match.', 'buddypress' );
52
+
53
+ $bp->signup->username = $_POST['signup_username'];
54
+ $bp->signup->email = $_POST['signup_email'];
55
+
56
+ /* Now we've checked account details, we can check profile information */
57
+ if ( function_exists( 'xprofile_check_is_required_field' ) ) {
58
+
59
+ /* Make sure hidden field is passed and populated */
60
+ if ( isset( $_POST['signup_profile_field_ids'] ) && !empty( $_POST['signup_profile_field_ids'] ) ) {
61
+
62
+ /* Let's compact any profile field info into an array */
63
+ $profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] );
64
+
65
+ /* Loop through the posted fields formatting any datebox values then validate the field */
66
+ foreach ( (array) $profile_field_ids as $field_id ) {
67
+ if ( !isset( $_POST['field_' . $field_id] ) ) {
68
+ if ( isset( $_POST['field_' . $field_id . '_day'] ) )
69
+ $_POST['field_' . $field_id] = strtotime( $_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year'] );
70
+ }
71
+
72
+ /* Create errors for required fields without values */
73
+ if ( xprofile_check_is_required_field( $field_id ) && empty( $_POST['field_' . $field_id] ) )
74
+ $bp->signup->errors['field_' . $field_id] = __( 'This is a required field', 'buddypress' );
75
+ }
76
+
77
+ /* This situation doesn't naturally occur so bounce to website root */
78
+ } else {
79
+ bp_core_redirect( $bp->root_domain );
80
+ }
81
+ }
82
+
83
+ /* Finally, let's check the blog details, if the user wants a blog and blog creation is enabled */
84
+ if ( isset( $_POST['signup_with_blog'] ) ) {
85
+ $active_signup = $bp->site_options['registration'];
86
+
87
+ if ( 'blog' == $active_signup || 'all' == $active_signup ) {
88
+ $blog_details = bp_core_validate_blog_signup( $_POST['signup_blog_url'], $_POST['signup_blog_title'] );
89
+
90
+ /* If there are errors with blog details, set them for display */
91
+ if ( !empty( $blog_details['errors']->errors['blogname'] ) )
92
+ $bp->signup->errors['signup_blog_url'] = $blog_details['errors']->errors['blogname'][0];
93
+
94
+ if ( !empty( $blog_details['errors']->errors['blog_title'] ) )
95
+ $bp->signup->errors['signup_blog_title'] = $blog_details['errors']->errors['blog_title'][0];
96
+ }
97
+ }
98
+
99
+ do_action( 'bp_signup_validate' );
100
+
101
+ /* Add any errors to the action for the field in the template for display. */
102
+ if ( !empty( $bp->signup->errors ) ) {
103
+ foreach ( (array)$bp->signup->errors as $fieldname => $error_message )
104
+ add_action( 'bp_' . $fieldname . '_errors', create_function( '', 'echo "<div class=\"error\">' . $error_message . '</div>";' ) );
105
+ } else {
106
+ $bp->signup->step = 'save-details';
107
+
108
+ /* No errors! Let's register those deets. */
109
+ $active_signup = $bp->site_options['registration'];
110
+
111
+ if ( 'none' != $active_signup ) {
112
+
113
+ /* Let's compact any profile field info into usermeta */
114
+ $profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] );
115
+
116
+ /* Loop through the posted fields formatting any datebox values then add to usermeta */
117
+ foreach ( (array) $profile_field_ids as $field_id ) {
118
+ if ( !isset( $_POST['field_' . $field_id] ) ) {
119
+ if ( isset( $_POST['field_' . $field_id . '_day'] ) )
120
+ $_POST['field_' . $field_id] = strtotime( $_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year'] );
121
+ }
122
+
123
+ if ( !empty( $_POST['field_' . $field_id] ) )
124
+ $usermeta['field_' . $field_id] = $_POST['field_' . $field_id];
125
+ }
126
+
127
+ /* Store the profile field ID's in usermeta */
128
+ $usermeta['profile_field_ids'] = $_POST['signup_profile_field_ids'];
129
+
130
+ /* Hash and store the password */
131
+ $usermeta['password'] = wp_hash_password( $_POST['signup_password'] );
132
+
133
+ /* If the user decided to create a blog, save those details to usermeta */
134
+ if ( 'blog' == $active_signup || 'all' == $active_signup ) {
135
+ $usermeta['public'] = ( 'public' == $_POST['signup_blog_privacy'] ) ? true : false;
136
+ }
137
+
138
+ $usermeta = apply_filters( 'bp_signup_usermeta', $usermeta );
139
+
140
+ /* Finally, sign up the user and/or blog */
141
+ if ( isset( $_POST['signup_with_blog'] ) && bp_core_is_multisite() )
142
+ bp_core_signup_blog( $blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta );
143
+ else {
144
+ bp_core_signup_user( $_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta );
145
+ }
146
+
147
+ $bp->signup->step = 'completed-confirmation';
148
+ }
149
+
150
+ do_action( 'bp_complete_signup' );
151
+ }
152
+
153
+ }
154
+
155
+ $bp->avatar_admin->step = 'upload-image';
156
+
157
+ /* If user has uploaded a new avatar */
158
+ if ( !empty( $_FILES ) ) {
159
+
160
+ /* Check the nonce */
161
+ check_admin_referer( 'bp_avatar_upload' );
162
+
163
+ $bp->signup->step = 'completed-confirmation';
164
+
165
+ if ( bp_core_is_multisite() ) {
166
+ /* Get the activation key */
167
+ if ( !$bp->signup->key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $_POST[ 'signup_username' ], $_POST[ 'signup_email' ] ) ) ) {
168
+ bp_core_add_message( __( 'There was a problem uploading your avatar, please try uploading it again', 'buddypress' ) );
169
+ } else {
170
+ /* Hash the key to create the upload folder (added security so people don't sniff the activation key) */
171
+ $bp->signup->avatar_dir = wp_hash( $bp->signup->key );
172
+ }
173
+ } else {
174
+ $user_id = bp_core_get_userid( $_POST['signup_username'] );
175
+ $bp->signup->avatar_dir = wp_hash( $user_id );
176
+ }
177
+
178
+ /* Pass the file to the avatar upload handler */
179
+ if ( bp_core_avatar_handle_upload( $_FILES, 'bp_core_signup_avatar_upload_dir' ) ) {
180
+ $bp->avatar_admin->step = 'crop-image';
181
+
182
+ /* Make sure we include the jQuery jCrop file for image cropping */
183
+ add_action( 'wp', 'bp_core_add_jquery_cropper' );
184
+ }
185
+ }
186
+
187
+ /* If the image cropping is done, crop the image and save a full/thumb version */
188
+ if ( isset( $_POST['avatar-crop-submit'] ) ) {
189
+
190
+ /* Check the nonce */
191
+ check_admin_referer( 'bp_avatar_cropstore' );
192
+
193
+ /* Reset the avatar step so we can show the upload form again if needed */
194
+ $bp->signup->step = 'completed-confirmation';
195
+ $bp->avatar_admin->step = 'upload-image';
196
+
197
+ if ( !bp_core_avatar_handle_crop( array( 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h'] ) ) )
198
+ bp_core_add_message( __( 'There was a problem cropping your avatar, please try uploading it again', 'buddypress' ), 'error' );
199
+ else
200
+ bp_core_add_message( __( 'Your new avatar was uploaded successfully', 'buddypress' ) );
201
+ }
202
+ bp_core_load_template( 'registration/register' );
203
+ }
204
+ add_action( 'wp', 'bp_core_screen_signup', 3 );
205
+
206
+ function bp_core_screen_activation() {
207
+ global $bp, $wpdb;
208
+
209
+ if ( BP_ACTIVATION_SLUG != $bp->current_component )
210
+ return false;
211
+
212
+ /* Check if an activation key has been passed */
213
+ if ( isset( $_GET['key'] ) ) {
214
+
215
+ require_once( ABSPATH . WPINC . '/registration.php' );
216
+
217
+ /* Activate the signup */
218
+ $user = apply_filters( 'bp_core_activate_account', bp_core_activate_signup( $_GET['key'] ) );
219
+
220
+ /* If there was errors, add a message and redirect */
221
+ if ( $user->errors ) {
222
+ bp_core_add_message( __( 'There was an error activating your account, please try again.', 'buddypress' ), 'error' );
223
+ bp_core_redirect( $bp->root_domain . '/' . BP_ACTIVATION_SLUG );
224
+ }
225
+
226
+ /* Check for an uploaded avatar and move that to the correct user folder */
227
+ if ( bp_core_is_multisite() )
228
+ $hashed_key = wp_hash( $_GET['key'] );
229
+ else
230
+ $hashed_key = wp_hash( $user );
231
+
232
+ /* Check if the avatar folder exists. If it does, move rename it, move it and delete the signup avatar dir */
233
+ if ( file_exists( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key ) )
234
+ @rename( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key, BP_AVATAR_UPLOAD_PATH . '/avatars/' . $user );
235
+
236
+ bp_core_add_message( __( 'Your account is now active!', 'buddypress' ) );
237
+
238
+ $bp->activation_complete = true;
239
+ }
240
+
241
+ if ( '' != locate_template( array( 'registration/activate' ), false ) )
242
+ bp_core_load_template( apply_filters( 'bp_core_template_activate', 'activate' ) );
243
+ else
244
+ bp_core_load_template( apply_filters( 'bp_core_template_activate', 'registration/activate' ) );
245
+ }
246
+ add_action( 'wp', 'bp_core_screen_activation', 3 );
247
+
248
+
249
+ /********************************************************************************
250
+ * Business Functions
251
+ *
252
+ * Business functions are where all the magic happens in BuddyPress. They will
253
+ * handle the actual saving or manipulation of information. Usually they will
254
+ * hand off to a database class for data access, then return
255
+ * true or false on success or failure.
256
+ */
257
+
258
+ /**
259
+ * bp_core_flush_illegal_names()
260
+ *
261
+ * Flush illegal names by getting and setting 'illegal_names' site option
262
+ */
263
+ function bp_core_flush_illegal_names() {
264
+ $illegal_names = get_site_option( 'illegal_names' );
265
+ update_site_option( 'illegal_names', $illegal_names );
266
+ }
267
+
268
+ /**
269
+ * bp_core_illegal_names()
270
+ *
271
+ * Filter the illegal_names site option and make sure it includes a few
272
+ * specific BuddyPress and Multi-site slugs
273
+ *
274
+ * @param array|string $value Illegal names from field
275
+ * @param array|string $oldvalue The value as it is currently
276
+ * @return array Merged and unique array of illegal names
277
+ */
278
+ function bp_core_illegal_names( $value = '', $oldvalue = '' ) {
279
+
280
+ // Make sure $value is array
281
+ if ( empty( $value ) )
282
+ $db_illegal_names = array();
283
+ if ( is_array( $value ) )
284
+ $db_illegal_names = $value;
285
+ elseif ( is_string( $value ) )
286
+ $db_illegal_names = implode( ' ', $names );
287
+
288
+ // Add our slugs to the array and allow them to be filtered
289
+ $filtered_illegal_names = apply_filters( 'bp_core_illegal_usernames', array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', BP_GROUPS_SLUG, BP_MEMBERS_SLUG, BP_FORUMS_SLUG, BP_BLOGS_SLUG, BP_ACTIVITY_SLUG, BP_XPROFILE_SLUG, BP_FRIENDS_SLUG, BP_SEARCH_SLUG, BP_SETTINGS_SLUG, BP_REGISTER_SLUG, BP_ACTIVATION_SLUG ) );
290
+
291
+ // Merge the arrays together
292
+ $merged_names = array_merge( (array)$filtered_illegal_names, (array)$db_illegal_names );
293
+
294
+ // Remove duplicates
295
+ $illegal_names = array_unique( (array)$merged_names );
296
+
297
+ return apply_filters( 'bp_core_illegal_names', $illegal_names );
298
+ }
299
+ add_filter( 'pre_update_site_option_illegal_names', 'bp_core_illegal_names', 10, 2 );
300
+
301
+ /**
302
+ * bp_core_validate_user_signup()
303
+ *
304
+ * Validate a user name and email address when creating a new user.
305
+ *
306
+ * @global object $wpdb DB Layer
307
+ * @param string $user_name Username to validate
308
+ * @param string $user_email Email address to validate
309
+ * @return array Results of user validation including errors, if any
310
+ */
311
+ function bp_core_validate_user_signup( $user_name, $user_email ) {
312
+ global $wpdb;
313
+
314
+ $errors = new WP_Error();
315
+ $user_email = sanitize_email( $user_email );
316
+
317
+ if ( empty( $user_name ) )
318
+ $errors->add( 'user_name', __( 'Please enter a username', 'buddypress' ) );
319
+
320
+ $maybe = array();
321
+ preg_match( "/[a-z0-9]+/", $user_name, $maybe );
322
+
323
+ // Make sure illegal names include BuddyPress slugs and values
324
+ bp_core_flush_illegal_names();
325
+
326
+ if ( !validate_username( $user_name ) || in_array( $user_name, (array)$illegal_names ) || $user_name != $maybe[0] )
327
+ $errors->add( 'user_name', __( 'Only lowercase letters and numbers allowed', 'buddypress' ) );
328
+
329
+ if( strlen( $user_name ) < 4 )
330
+ $errors->add( 'user_name', __( 'Username must be at least 4 characters', 'buddypress' ) );
331
+
332
+ if ( strpos( ' ' . $user_name, '_' ) != false )
333
+ $errors->add( 'user_name', __( 'Sorry, usernames may not contain the character "_"!', 'buddypress' ) );
334
+
335
+ /* Is the user_name all numeric? */
336
+ $match = array();
337
+ preg_match( '/[0-9]*/', $user_name, $match );
338
+
339
+ if ( $match[0] == $user_name )
340
+ $errors->add( 'user_name', __( 'Sorry, usernames must have letters too!', 'buddypress' ) );
341
+
342
+ if ( !is_email( $user_email ) )
343
+ $errors->add( 'user_email', __( 'Please check your email address.', 'buddypress' ) );
344
+
345
+ $limited_email_domains = get_site_option( 'limited_email_domains', 'buddypress' );
346
+
347
+ if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) {
348
+ $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) );
349
+
350
+ if ( in_array( $emaildomain, (array)$limited_email_domains ) == false )
351
+ $errors->add( 'user_email', __( 'Sorry, that email address is not allowed!', 'buddypress' ) );
352
+ }
353
+
354
+ /* Check if the username has been used already. */
355
+ if ( username_exists( $user_name ) )
356
+ $errors->add( 'user_name', __( 'Sorry, that username already exists!', 'buddypress' ) );
357
+
358
+ /* Check if the email address has been used already. */
359
+ if ( email_exists( $user_email ) )
360
+ $errors->add( 'user_email', __( 'Sorry, that email address is already used!', 'buddypress' ) );
361
+
362
+ $result = array( 'user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors );
363
+
364
+ /* Apply WPMU legacy filter */
365
+ $result = apply_filters( 'wpmu_validate_user_signup', $result );
366
+
367
+ return apply_filters( 'bp_core_validate_user_signup', $result );
368
+ }
369
+
370
+ function bp_core_validate_blog_signup( $blog_url, $blog_title ) {
371
+ if ( !bp_core_is_multisite() || !function_exists( 'wpmu_validate_blog_signup' ) )
372
+ return false;
373
+
374
+ return apply_filters( 'bp_core_validate_blog_signup', wpmu_validate_blog_signup( $blog_url, $blog_title ) );
375
+ }
376
+
377
+ function bp_core_signup_user( $user_login, $user_password, $user_email, $usermeta ) {
378
+ global $bp, $wpdb;
379
+
380
+ /* Multisite installs have their own install procedure */
381
+ if ( bp_core_is_multisite() ) {
382
+ wpmu_signup_user( $user_login, $user_email, $usermeta );
383
+
384
+ } else {
385
+ $errors = new WP_Error();
386
+
387
+ $user_id = wp_insert_user( array(
388
+ 'user_login' => $user_login,
389
+ 'user_pass' => $user_password,
390
+ 'display_name' => sanitize_title( $user_login ),
391
+ 'user_email' => $user_email
392
+ ) );
393
+
394
+ if ( !$user_id ) {
395
+ $errors->add( 'registerfail', sprintf( __('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'buddypress' ), get_option( 'admin_email' ) ) );
396
+ return $errors;
397
+ }
398
+
399
+ /* Update the user status to '2' which we will use as 'not activated' (0 = active, 1 = spam, 2 = not active) */
400
+ $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_status = 2 WHERE ID = %d", $user_id ) );
401
+
402
+ /* Set any profile data */
403
+ if ( function_exists( 'xprofile_set_field_data' ) ) {
404
+ if ( !empty( $usermeta['profile_field_ids'] ) ) {
405
+ $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] );
406
+
407
+ foreach( (array)$profile_field_ids as $field_id ) {
408
+ $current_field = $usermeta["field_{$field_id}"];
409
+
410
+ if ( !empty( $current_field ) )
411
+ xprofile_set_field_data( $field_id, $user_id, $current_field );
412
+ }
413
+ }
414
+ }
415
+ }
416
+ $bp->signup->username = $user_login;
417
+
418
+ /***
419
+ * Now generate an activation key and send an email to the user so they can activate their account
420
+ * and validate their email address. Multisite installs send their own email, so this is only for single blog installs.
421
+ *
422
+ * To disable sending activation emails you can user the filter 'bp_core_signup_send_activation_key' and return false.
423
+ */
424
+ if ( apply_filters( 'bp_core_signup_send_activation_key', true ) ) {
425
+ if ( !bp_core_is_multisite() ) {
426
+ $activation_key = wp_hash( $user_id );
427
+ update_usermeta( $user_id, 'activation_key', $activation_key );
428
+ bp_core_signup_send_validation_email( $user_id, $user_email, $activation_key );
429
+ }
430
+ }
431
+
432
+ do_action( 'bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta );
433
+
434
+ return $user_id;
435
+ }
436
+
437
+ function bp_core_signup_blog( $blog_domain, $blog_path, $blog_title, $user_name, $user_email, $usermeta ) {
438
+ if ( !bp_core_is_multisite() || !function_exists( 'wpmu_signup_blog' ) )
439
+ return false;
440
+
441
+ return apply_filters( 'bp_core_signup_blog', wpmu_signup_blog( $blog_domain, $blog_path, $blog_title, $user_name, $user_email, $usermeta ) );
442
+ }
443
+
444
+ function bp_core_activate_signup( $key ) {
445
+ global $bp, $wpdb;
446
+
447
+ $user = false;
448
+
449
+ /* Multisite installs have their own activation routine */
450
+ if ( bp_core_is_multisite() ) {
451
+ $user = wpmu_activate_signup( $key );
452
+
453
+ /* If there was errors, add a message and redirect */
454
+ if ( $user->errors ) {
455
+ bp_core_add_message( __( 'There was an error activating your account, please try again.', 'buddypress' ), 'error' );
456
+ bp_core_redirect( $bp->root_domain . '/' . BP_ACTIVATION_SLUG );
457
+ }
458
+
459
+ $user_id = $user['user_id'];
460
+
461
+ /* Set any profile data */
462
+ if ( function_exists( 'xprofile_set_field_data' ) ) {
463
+ if ( !empty( $user['meta']['profile_field_ids'] ) ) {
464
+ $profile_field_ids = explode( ',', $user['meta']['profile_field_ids'] );
465
+
466
+ foreach( (array)$profile_field_ids as $field_id ) {
467
+ $current_field = $user['meta']["field_{$field_id}"];
468
+
469
+ if ( !empty( $current_field ) )
470
+ xprofile_set_field_data( $field_id, $user_id, $current_field );
471
+ }
472
+ }
473
+ }
474
+
475
+ } else {
476
+ /* Get the user_id based on the $key */
477
+ $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM $wpdb->usermeta WHERE meta_value = %s", $key ) );
478
+
479
+ if ( empty( $user_id ) )
480
+ return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) );
481
+
482
+ /* Change the user's status so they become active */
483
+ if ( !$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_status = 0 WHERE ID = %d", $user_id ) ) )
484
+ return new WP_Error( 'invalid_key', __( 'Invalid activation key', 'buddypress' ) );
485
+
486
+ /* Notify the site admin of a new user registration */
487
+ wp_new_user_notification( $user_id );
488
+
489
+ /* Remove the activation key meta */
490
+ delete_usermeta( $user_id, 'activation_key' );
491
+ }
492
+
493
+ /* Update the user_url and display_name */
494
+ wp_update_user( array( 'ID' => $user_id, 'user_url' => bp_core_get_user_domain( $user_id, sanitize_title( $user_login ), $user_login ), 'display_name' => bp_core_get_user_displayname( $user_id ) ) );
495
+
496
+ /* Add a last active entry */
497
+ update_usermeta( $user_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
498
+
499
+ /* Set the password on multisite installs */
500
+ if ( bp_core_is_multisite() && !empty( $user['meta']['password'] ) )
501
+ $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_pass = %s WHERE ID = %d", $user['meta']['password'], $user_id ) );
502
+
503
+ /* Delete the total member cache */
504
+ wp_cache_delete( 'bp_total_member_count', 'bp' );
505
+
506
+ do_action( 'bp_core_activated_user', $user_id, $key, $user );
507
+
508
+ return $user_id;
509
+ }
510
+
511
+ function bp_core_new_user_activity( $user ) {
512
+ if ( empty( $user ) || !function_exists( 'bp_activity_add' ) )
513
+ return false;
514
+
515
+ if ( is_array( $user ) )
516
+ $user_id = $user['user_id'];
517
+ else
518
+ $user_id = $user;
519
+
520
+ if ( empty( $user_id ) )
521
+ return false;
522
+
523
+ $userlink = bp_core_get_userlink( $user_id );
524
+
525
+ bp_activity_add( array(
526
+ 'user_id' => $user_id,
527
+ 'action' => apply_filters( 'bp_core_activity_registered_member_action', sprintf( __( '%s became a registered member', 'buddypress' ), $userlink ), $user_id ),
528
+ 'component' => 'profile',
529
+ 'type' => 'new_member'
530
+ ) );
531
+ }
532
+ add_action( 'bp_core_activated_user', 'bp_core_new_user_activity' );
533
+
534
+ function bp_core_map_user_registration( $user_id ) {
535
+ /* Only map data when the site admin is adding users, not on registration. */
536
+ if ( !is_admin() )
537
+ return false;
538
+
539
+ /* Add a last active entry */
540
+ update_usermeta( $user_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
541
+
542
+ /* Add the user's fullname to Xprofile */
543
+ if ( function_exists( 'xprofile_set_field_data' ) ) {
544
+ $firstname = get_usermeta( $user_id, 'first_name' );
545
+ $lastname = ' ' . get_usermeta( $user_id, 'last_name' );
546
+ $name = $firstname . $lastname;
547
+
548
+ if ( empty( $name ) || ' ' == $name )
549
+ $name = get_usermeta( $user_id, 'nickname' );
550
+
551
+ xprofile_set_field_data( 1, $user_id, $name );
552
+ }
553
+ }
554
+ add_action( 'user_register', 'bp_core_map_user_registration' );
555
+
556
+ function bp_core_signup_avatar_upload_dir() {
557
+ global $bp;
558
+
559
+ if ( !$bp->signup->avatar_dir )
560
+ return false;
561
+
562
+ $path = BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $bp->signup->avatar_dir;
563
+ $newbdir = $path;
564
+
565
+ if ( !file_exists( $path ) )
566
+ @wp_mkdir_p( $path );
567
+
568
+ $newurl = BP_AVATAR_URL . '/avatars/signups/' . $bp->signup->avatar_dir;
569
+ $newburl = $newurl;
570
+ $newsubdir = '/avatars/signups/' . $bp->signup->avatar_dir;
571
+
572
+ return apply_filters( 'bp_core_signup_avatar_upload_dir', array( 'path' => $path, 'url' => $newurl, 'subdir' => $newsubdir, 'basedir' => $newbdir, 'baseurl' => $newburl, 'error' => false ) );
573
+ }
574
+
575
+ function bp_core_signup_send_validation_email( $user_id, $user_email, $key ) {
576
+ $activate_url = bp_get_activation_page() ."?key=$key";
577
+ $activate_url = clean_url( $activate_url );
578
+ $admin_email = get_site_option( "admin_email" );
579
+
580
+ if ( empty( $admin_email ) )
581
+ $admin_email = 'noreply@' . $_SERVER['SERVER_NAME'];
582
+
583
+ $from_name = ( '' == get_option( 'blogname' ) ) ? 'BuddyPress' : wp_specialchars( get_option( 'blogname' ) );
584
+ $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n";
585
+ $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 );
586
+ $subject = '[' . $from_name . '] ' . __( 'Activate Your Account', 'buddypress' );
587
+
588
+ /* Send the message */
589
+ $to = apply_filters( 'bp_core_activation_signup_user_notification_to', $user_email );
590
+ $subject = apply_filters( 'bp_core_activation_signup_user_notification_subject', $subject );
591
+ $message = apply_filters( 'bp_core_activation_signup_user_notification_message', $message );
592
+
593
+ wp_mail( $to, $subject, $message, $message_headers );
594
+ }
595
+
596
+ /* Stop user accounts logging in that have not been activated (user_status = 2) */
597
+ function bp_core_signup_disable_inactive( $auth_obj, $username ) {
598
+ global $bp, $wpdb;
599
+
600
+ if ( !$user_id = bp_core_get_userid( $username ) )
601
+ return $auth_obj;
602
+
603
+ $user_status = (int) $wpdb->get_var( $wpdb->prepare( "SELECT user_status FROM $wpdb->users WHERE ID = %d", $user_id ) );
604
+
605
+ if ( 2 == $user_status )
606
+ bp_core_redirect( $bp->root_domain );
607
+ else
608
+ return $auth_obj;
609
+ }
610
+ add_filter( 'authenticate', 'bp_core_signup_disable_inactive', 11, 2 );
611
+
612
+ /* Kill the wp-signup.php if custom registration signup templates are present */
613
+ function bp_core_wpsignup_redirect() {
614
+ if ( false === strpos( $_SERVER['SCRIPT_NAME'], 'wp-signup.php') && $_GET['action'] != 'register' )
615
+ return false;
616
+
617
+ if ( locate_template( array( 'registration/register.php' ), false ) || locate_template( array( 'register.php' ), false ) )
618
+ bp_core_redirect( bp_get_root_domain() . '/' . BP_REGISTER_SLUG . '/' );
619
+ }
620
+ if ( bp_core_is_multisite() )
621
+ add_action( 'wp', 'bp_core_wpsignup_redirect' );
622
+ else
623
+ add_action( 'init', 'bp_core_wpsignup_redirect' );
624
+
625
  ?>
bp-core/bp-core-templatetags.php CHANGED
@@ -1,1960 +1,2082 @@
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
-
33
- if ( !$max || $max >= (int)$this->members['total'] )
34
- $this->total_member_count = (int)$this->members['total'];
35
- else
36
- $this->total_member_count = (int)$max;
37
-
38
- $this->members = $this->members['users'];
39
-
40
- if ( $max ) {
41
- if ( $max >= count($this->members) )
42
- $this->member_count = count($this->members);
43
- else
44
- $this->member_count = (int)$max;
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 ( $_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
- function bp_member_user_id() {
205
- echo bp_get_member_user_id();
206
- }
207
- function bp_get_member_user_id() {
208
- global $members_template;
209
-
210
- return apply_filters( 'bp_get_member_user_id', $members_template->member->id );
211
- }
212
-
213
- function bp_member_avatar( $args = '' ) {
214
- echo apply_filters( 'bp_member_avatar', bp_get_member_avatar( $args ) );
215
- }
216
- function bp_get_member_avatar( $args = '' ) {
217
- global $bp, $members_template;
218
-
219
- $defaults = array(
220
- 'type' => 'thumb',
221
- 'width' => false,
222
- 'height' => false,
223
- 'class' => 'avatar',
224
- 'id' => false,
225
- 'alt' => __( 'Member avatar', 'buddypress' )
226
- );
227
-
228
- $r = wp_parse_args( $args, $defaults );
229
- extract( $r, EXTR_SKIP );
230
-
231
- 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 ) ) );
232
- }
233
-
234
- function bp_member_permalink() {
235
- echo bp_get_member_permalink();
236
- }
237
- function bp_get_member_permalink() {
238
- global $members_template;
239
-
240
- 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 ) );
241
- }
242
- function bp_member_link() { echo bp_get_member_permalink(); }
243
- function bp_get_member_link() { return bp_get_member_permalink(); }
244
-
245
- function bp_member_name() {
246
- echo apply_filters( 'bp_member_name', bp_get_member_name() );
247
- }
248
- function bp_get_member_name() {
249
- global $members_template;
250
-
251
- if ( empty($members_template->member->fullname) )
252
- $members_template->member->fullname = $members_template->member->display_name;
253
-
254
- return apply_filters( 'bp_get_member_name', $members_template->member->fullname );
255
- }
256
- add_filter( 'bp_get_member_name', 'wp_filter_kses' );
257
- add_filter( 'bp_get_member_name', 'stripslashes' );
258
- add_filter( 'bp_get_member_name', 'strip_tags' );
259
-
260
- function bp_member_last_active() {
261
- echo bp_get_member_last_active();
262
- }
263
- function bp_get_member_last_active() {
264
- global $members_template;
265
-
266
- $last_activity = bp_core_get_last_activity( $members_template->member->last_activity, __( 'active %s ago', 'buddypress' ) );
267
-
268
- return apply_filters( 'bp_member_last_active', $last_activity );
269
- }
270
-
271
- function bp_member_latest_update( $args = '' ) {
272
- echo bp_get_member_latest_update( $args );
273
- }
274
- function bp_get_member_latest_update( $args = '' ) {
275
- global $members_template, $bp;
276
-
277
- $defaults = array(
278
- 'length' => 15
279
- );
280
-
281
- $r = wp_parse_args( $args, $defaults );
282
- extract( $r, EXTR_SKIP );
283
-
284
- if ( !$update = maybe_unserialize( $members_template->member->latest_update ) )
285
- return false;
286
-
287
- $update_content = apply_filters( 'bp_get_activity_latest_update', strip_tags( bp_create_excerpt( $update['content'], $length ) ) );
288
-
289
- if ( !empty( $update['id'] ) )
290
- $update_content .= ' &middot; <a href="' . $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $update['id'] . '">' . __( 'View', 'buddypress' ) . '</a>';
291
-
292
- return apply_filters( 'bp_get_member_latest_update', $update_content );
293
- }
294
-
295
- function bp_member_profile_data( $args = '' ) {
296
- echo bp_get_member_profile_data( $args );
297
- }
298
- function bp_get_member_profile_data( $args = '' ) {
299
- global $members_template;
300
-
301
- if ( !function_exists( 'xprofile_install' ) )
302
- return false;
303
-
304
- $defaults = array(
305
- 'field' => false, // Field name
306
- );
307
-
308
- $r = wp_parse_args( $args, $defaults );
309
- extract( $r, EXTR_SKIP );
310
-
311
- // Populate the user if it hasn't been already.
312
- if ( empty( $members_template->member->profile_data ) && method_exists( 'BP_XProfile_ProfileData', 'get_all_for_user' ) )
313
- $members_template->member->profile_data = BP_XProfile_ProfileData::get_all_for_user( $members_template->member->id );
314
-
315
- $data = xprofile_format_profile_field( $members_template->member->profile_data[$field]['field_type'], $members_template->member->profile_data[$field]['field_data'] );
316
-
317
- return apply_filters( 'bp_get_member_profile_data', $data );
318
- }
319
-
320
- function bp_member_registered() {
321
- echo bp_get_member_registered();
322
- }
323
- function bp_get_member_registered() {
324
- global $members_template;
325
-
326
- $registered = attribute_escape( bp_core_get_last_activity( $members_template->member->user_registered, __( 'registered %s ago', 'buddypress' ) ) );
327
-
328
- return apply_filters( 'bp_member_last_active', $registered );
329
- }
330
-
331
- function bp_member_add_friend_button() {
332
- global $members_template;
333
-
334
- if ( function_exists( 'bp_add_friend_button' ) ) {
335
- if ( null === $members_template->member->is_friend )
336
- $friend_status = 'not_friends';
337
- else
338
- $friend_status = ( 0 == $members_template->member->is_friend ) ? 'pending' : 'is_friend';
339
-
340
- echo bp_add_friend_button( $members_template->member->id, $friend_status );
341
- }
342
- }
343
-
344
- function bp_member_total_friend_count() {
345
- global $members_template;
346
-
347
- echo bp_get_member_total_friend_count();
348
- }
349
- function bp_get_member_total_friend_count() {
350
- global $members_template;
351
-
352
- if ( 1 == (int) $members_template->member->total_friend_count )
353
- return apply_filters( 'bp_get_member_total_friend_count', sprintf( __( '%d friend', 'buddypress' ), (int) $members_template->member->total_friend_count ) );
354
- else
355
- return apply_filters( 'bp_get_member_total_friend_count', sprintf( __( '%d friends', 'buddypress' ), (int) $members_template->member->total_friend_count ) );
356
- }
357
-
358
- function bp_member_random_profile_data() {
359
- global $members_template;
360
-
361
- if ( function_exists( 'xprofile_get_random_profile_data' ) ) { ?>
362
- <?php $random_data = xprofile_get_random_profile_data( $members_template->member->id, true ); ?>
363
- <strong><?php echo wp_filter_kses( $random_data[0]->name ) ?></strong>
364
- <?php echo wp_filter_kses( $random_data[0]->value ) ?>
365
- <?php }
366
- }
367
-
368
- function bp_member_hidden_fields() {
369
- if ( isset( $_REQUEST['s'] ) ) {
370
- echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['s'] ) . '" name="search_terms" />';
371
- }
372
-
373
- if ( isset( $_REQUEST['letter'] ) ) {
374
- echo '<input type="hidden" id="selected_letter" value="' . attribute_escape( $_REQUEST['letter'] ) . '" name="selected_letter" />';
375
- }
376
-
377
- if ( isset( $_REQUEST['members_search'] ) ) {
378
- echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['members_search'] ) . '" name="search_terms" />';
379
- }
380
- }
381
-
382
- function bp_directory_members_search_form() {
383
- global $bp;
384
-
385
- $search_value = __( 'Search anything...', 'buddypress' );
386
- if ( !empty( $_GET['s'] ) )
387
- $search_value = $_GET['s'];
388
-
389
- ?>
390
- <form action="" method="get" id="search-members-form">
391
- <label><input type="text" name="s" id="members_search" value="<?php echo attribute_escape( $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>
392
- <input type="submit" id="members_search_submit" name="members_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
393
- </form>
394
- <?php
395
- }
396
-
397
- function bp_total_site_member_count() {
398
- echo bp_get_total_site_member_count();
399
- }
400
- function bp_get_total_site_member_count() {
401
- return apply_filters( 'bp_get_total_site_member_count', bp_core_number_format( bp_core_get_total_member_count() ) );
402
- }
403
-
404
-
405
- /** Navigation and other misc template tags **/
406
-
407
- /**
408
- * bp_get_nav()
409
- * TEMPLATE TAG
410
- *
411
- * Uses the $bp->bp_nav global to render out the navigation within a BuddyPress install.
412
- * Each component adds to this navigation array within its own [component_name]_setup_nav() function.
413
- *
414
- * This navigation array is the top level navigation, so it contains items such as:
415
- * [Blog, Profile, Messages, Groups, Friends] ...
416
- *
417
- * The function will also analyze the current component the user is in, to determine whether
418
- * or not to highlight a particular nav item.
419
- *
420
- * @package BuddyPress Core
421
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
422
- */
423
- function bp_get_loggedin_user_nav() {
424
- global $bp, $current_blog;
425
-
426
- /* Loop through each navigation item */
427
- foreach( (array) $bp->bp_nav as $nav_item ) {
428
- /* If the current component matches the nav item id, then add a highlight CSS class. */
429
- if ( !bp_is_directory && $bp->active_components[$bp->current_component] == $nav_item['css_id'] )
430
- $selected = ' class="current selected"';
431
- else
432
- $selected = '';
433
-
434
- /* If we are viewing another person (current_userid does not equal loggedin_user->id)
435
- then check to see if the two users are friends. if they are, add a highlight CSS class
436
- to the friends nav item if it exists. */
437
- if ( !bp_is_my_profile() && $bp->displayed_user->id ) {
438
- $selected = '';
439
-
440
- if ( function_exists('friends_install') ) {
441
- if ( $nav_item['css_id'] == $bp->friends->id ) {
442
- if ( friends_check_friendship( $bp->loggedin_user->id, $bp->displayed_user->id ) )
443
- $selected = ' class="current selected"';
444
- }
445
- }
446
- }
447
-
448
- /* echo out the final list item */
449
- 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 );
450
- }
451
-
452
- /* Always add a log out list item to the end of the navigation */
453
- if ( function_exists( 'wp_logout_url' ) ) {
454
- $logout_link = '<li><a id="wp-logout" href="' . wp_logout_url( $bp->root_domain ) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';
455
- } else {
456
- $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>';
457
- }
458
-
459
- echo apply_filters( 'bp_logout_nav_link', $logout_link );
460
- }
461
-
462
- /**
463
- * bp_get_displayed_user_nav()
464
- * TEMPLATE TAG
465
- *
466
- * Uses the $bp->bp_users_nav global to render out the user navigation when viewing another user other than
467
- * yourself.
468
- *
469
- * @package BuddyPress Core
470
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
471
- */
472
- function bp_get_displayed_user_nav() {
473
- global $bp;
474
-
475
- foreach ( (array)$bp->bp_nav as $user_nav_item ) {
476
- if ( !$user_nav_item['show_for_displayed_user'] && !bp_is_my_profile() )
477
- continue;
478
-
479
- if ( $bp->current_component == $user_nav_item['slug'] )
480
- $selected = ' class="current selected"';
481
- else
482
- $selected = '';
483
-
484
- if ( $bp->loggedin_user->domain )
485
- $link = str_replace( $bp->loggedin_user->domain, $bp->displayed_user->domain, $user_nav_item['link'] );
486
- else
487
- $link = $bp->displayed_user->domain . $user_nav_item['link'];
488
-
489
- 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 );
490
- }
491
- }
492
-
493
- /**
494
- * bp_get_options_nav()
495
- * TEMPLATE TAG
496
- *
497
- * Uses the $bp->bp_options_nav global to render out the sub navigation for the current component.
498
- * Each component adds to its sub navigation array within its own [component_name]_setup_nav() function.
499
- *
500
- * This sub navigation array is the secondary level navigation, so for profile it contains:
501
- * [Public, Edit Profile, Change Avatar]
502
- *
503
- * The function will also analyze the current action for the current component to determine whether
504
- * or not to highlight a particular sub nav item.
505
- *
506
- * @package BuddyPress Core
507
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
508
- * @uses bp_get_user_nav() Renders the navigation for a profile of a currently viewed user.
509
- */
510
- function bp_get_options_nav() {
511
- global $bp;
512
-
513
- if ( count( $bp->bp_options_nav[$bp->current_component] ) < 1 )
514
- return false;
515
-
516
- /* Loop through each navigation item */
517
- foreach ( (array)$bp->bp_options_nav[$bp->current_component] as $subnav_item ) {
518
- if ( !$subnav_item['user_has_access'] )
519
- continue;
520
-
521
- /* If the current action or an action variable matches the nav item id, then add a highlight CSS class. */
522
- if ( $subnav_item['slug'] == $bp->current_action ) {
523
- $selected = ' class="current selected"';
524
- } else {
525
- $selected = '';
526
- }
527
-
528
- /* echo out the final list item */
529
- 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 );
530
- }
531
- }
532
-
533
- function bp_get_options_title() {
534
- global $bp;
535
-
536
- if ( empty( $bp->bp_options_title ) )
537
- $bp->bp_options_title = __( 'Options', 'buddypress' );
538
-
539
- echo apply_filters( 'bp_get_options_title', attribute_escape( $bp->bp_options_title ) );
540
- }
541
-
542
-
543
- /** AVATAR TEMPLATE TAGS *******************************************************/
544
-
545
- /**
546
- * bp_has_options_avatar()
547
- * TEMPLATE TAG
548
- *
549
- * Check to see if there is an options avatar. An options avatar is an avatar for something
550
- * like a group, or a friend. Basically an avatar that appears in the sub nav options bar.
551
- *
552
- * @package BuddyPress Core
553
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
554
- */
555
- function bp_has_options_avatar() {
556
- global $bp;
557
-
558
- if ( empty( $bp->bp_options_avatar ) )
559
- return false;
560
-
561
- return true;
562
- }
563
-
564
- function bp_get_options_avatar() {
565
- global $bp;
566
-
567
- echo apply_filters( 'bp_get_options_avatar', $bp->bp_options_avatar );
568
- }
569
-
570
- function bp_comment_author_avatar() {
571
- global $comment;
572
-
573
- if ( function_exists('bp_core_fetch_avatar') ) {
574
- echo apply_filters( 'bp_comment_author_avatar', bp_core_fetch_avatar( array( 'item_id' => $comment->user_id, 'type' => 'thumb' ) ) );
575
- } else if ( function_exists('get_avatar') ) {
576
- get_avatar();
577
- }
578
- }
579
-
580
- function bp_post_author_avatar() {
581
- global $post;
582
-
583
- if ( function_exists('bp_core_fetch_avatar') ) {
584
- echo apply_filters( 'bp_post_author_avatar', bp_core_fetch_avatar( array( 'item_id' => $post->post_author, 'type' => 'thumb' ) ) );
585
- } else if ( function_exists('get_avatar') ) {
586
- get_avatar();
587
- }
588
- }
589
-
590
- function bp_loggedin_user_avatar( $args = '' ) {
591
- echo bp_get_loggedin_user_avatar( $args );
592
- }
593
- function bp_get_loggedin_user_avatar( $args = '' ) {
594
- global $bp;
595
-
596
- $defaults = array(
597
- 'type' => 'thumb',
598
- 'width' => false,
599
- 'height' => false
600
- );
601
-
602
- $r = wp_parse_args( $args, $defaults );
603
- extract( $r, EXTR_SKIP );
604
-
605
- 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 ) ) );
606
- }
607
-
608
- function bp_displayed_user_avatar( $args = '' ) {
609
- echo bp_get_displayed_user_avatar( $args );
610
- }
611
- function bp_get_displayed_user_avatar( $args = '' ) {
612
- global $bp;
613
-
614
- $defaults = array(
615
- 'type' => 'thumb',
616
- 'width' => false,
617
- 'height' => false
618
- );
619
-
620
- $r = wp_parse_args( $args, $defaults );
621
- extract( $r, EXTR_SKIP );
622
-
623
- 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 ) ) );
624
- }
625
-
626
- function bp_avatar_admin_step() {
627
- echo bp_get_avatar_admin_step();
628
- }
629
- function bp_get_avatar_admin_step() {
630
- global $bp;
631
-
632
- return apply_filters( 'bp_get_avatar_admin_step', $bp->avatar_admin->step );
633
- }
634
-
635
- function bp_avatar_to_crop() {
636
- echo bp_get_avatar_to_crop();
637
- }
638
- function bp_get_avatar_to_crop() {
639
- global $bp;
640
-
641
- return apply_filters( 'bp_get_avatar_to_crop', $bp->avatar_admin->image->url );
642
- }
643
-
644
- function bp_avatar_to_crop_src() {
645
- echo bp_get_avatar_to_crop_src();
646
- }
647
- function bp_get_avatar_to_crop_src() {
648
- global $bp;
649
-
650
- return apply_filters( 'bp_get_avatar_to_crop_src', str_replace( WP_CONTENT_DIR, '', $bp->avatar_admin->image->dir ) );
651
- }
652
-
653
- function bp_avatar_cropper() {
654
- global $bp;
655
-
656
- echo '<img id="avatar-to-crop" class="avatar" src="' . $bp->avatar_admin->image . '" />';
657
- }
658
-
659
- /** OTHER TEMPLATE TAGS *******************************************************/
660
-
661
- function bp_site_name() {
662
- echo apply_filters( 'bp_site_name', get_blog_option( BP_ROOT_BLOG, 'blogname' ) );
663
- }
664
-
665
- function bp_core_get_wp_profile() {
666
- global $bp;
667
-
668
- $ud = get_userdata( $bp->displayed_user->id );
669
- ?>
670
-
671
- <div class="bp-widget wp-profile">
672
- <h4><?php _e( 'My Profile' ) ?></h4>
673
-
674
- <table class="wp-profile-fields">
675
- <?php if ( $ud->display_name ) { ?>
676
- <tr id="wp_displayname">
677
- <td class="label">
678
- <?php _e( 'Name', 'buddypress' ) ?>
679
- </td>
680
- <td class="data">
681
- <?php echo $ud->display_name ?>
682
- </td>
683
- </tr>
684
- <?php } ?>
685
- <?php if ( $ud->user_description ) { ?>
686
- <tr id="wp_desc">
687
- <td class="label">
688
- <?php _e( 'About Me', 'buddypress' ) ?>
689
- </td>
690
- <td class="data">
691
- <?php echo $ud->user_description ?>
692
- </td>
693
- </tr>
694
- <?php } ?>
695
- <?php if ( $ud->user_url ) { ?>
696
- <tr id="wp_website">
697
- <td class="label">
698
- <?php _e( 'Website', 'buddypress' ) ?>
699
- </td>
700
- <td class="data">
701
- <?php echo make_clickable( $ud->user_url ) ?>
702
- </td>
703
- </tr>
704
- <?php } ?>
705
- <?php if ( $ud->jabber ) { ?>
706
- <tr id="wp_jabber">
707
- <td class="label">
708
- <?php _e( 'Jabber', 'buddypress' ) ?>
709
- </td>
710
- <td class="data">
711
- <?php echo $ud->jabber ?>
712
- </td>
713
- </tr>
714
- <?php } ?>
715
- <?php if ( $ud->aim ) { ?>
716
- <tr id="wp_aim">
717
- <td class="label">
718
- <?php _e( 'AOL Messenger', 'buddypress' ) ?>
719
- </td>
720
- <td class="data">
721
- <?php echo $ud->aim ?>
722
- </td>
723
- </tr>
724
- <?php } ?>
725
- <?php if ( $ud->yim ) { ?>
726
- <tr id="wp_yim">
727
- <td class="label">
728
- <?php _e( 'Yahoo Messenger', 'buddypress' ) ?>
729
- </td>
730
- <td class="data">
731
- <?php echo $ud->yim ?>
732
- </td>
733
- </tr>
734
- <?php } ?>
735
- </table>
736
- </div>
737
- <?php
738
- }
739
-
740
- function bp_get_profile_header() {
741
- locate_template( array( '/profile/profile-header.php' ), true );
742
- }
743
-
744
- function bp_exists( $component_name ) {
745
- if ( function_exists($component_name . '_install') )
746
- return true;
747
-
748
- return false;
749
- }
750
-
751
- function bp_format_time( $time, $just_date = false ) {
752
- $date = date( get_option('date_format'), $time );
753
-
754
- if ( !$just_date ) {
755
- $date .= ' ' . __( 'at', 'buddypress' ) . date( ' ' . get_option('time_format'), $time );
756
- }
757
-
758
- return apply_filters( 'bp_format_time', $date );
759
- }
760
-
761
- function bp_word_or_name( $youtext, $nametext, $capitalize = true, $echo = true ) {
762
- global $bp;
763
-
764
- if ( $capitalize )
765
- $youtext = bp_core_ucfirst($youtext);
766
-
767
- if ( $bp->displayed_user->id == $bp->loggedin_user->id ) {
768
- if ( $echo )
769
- echo apply_filters( 'bp_word_or_name', $youtext );
770
- else
771
- return apply_filters( 'bp_word_or_name', $youtext );
772
- } else {
773
- $fullname = (array)explode( ' ', $bp->displayed_user->fullname );
774
- $nametext = sprintf( $nametext, $fullname[0] );
775
- if ( $echo )
776
- echo apply_filters( 'bp_word_or_name', $nametext );
777
- else
778
- return apply_filters( 'bp_word_or_name', $nametext );
779
- }
780
- }
781
-
782
- function bp_your_or_their( $capitalize = true, $echo = true ) {
783
- global $bp;
784
-
785
- if ( $capitalize )
786
- $yourtext = bp_core_ucfirst($yourtext);
787
-
788
- if ( $bp->displayed_user->id == $bp->loggedin_user->id ) {
789
- if ( $echo )
790
- echo apply_filters( 'bp_your_or_their', $yourtext );
791
- else
792
- return apply_filters( 'bp_your_or_their', $yourtext );
793
- } else {
794
- if ( $echo )
795
- echo apply_filters( 'bp_your_or_their', $theirtext );
796
- else
797
- return apply_filters( 'bp_your_or_their', $theirtext );
798
- }
799
- }
800
-
801
- function bp_get_plugin_sidebar() {
802
- locate_template( array( 'plugin-sidebar.php' ), true );
803
- }
804
-
805
- function bp_page_title() {
806
- echo bp_get_page_title();
807
- }
808
-
809
- function bp_get_page_title() {
810
- global $bp, $post, $wp_query, $current_blog;
811
-
812
- if ( is_front_page() || !bp_current_component() || ( is_home() && bp_is_page( 'home' ) ) ) {
813
- $title = __( 'Home', 'buddypress' );
814
-
815
- } else if ( bp_is_blog_page() ) {
816
- if ( is_single() ) {
817
- $title = __( 'Blog &#124; ' . $post->post_title, 'buddypress' );
818
- } else if ( is_category() ) {
819
- $title = __( 'Blog &#124; Categories &#124; ' . ucwords( $wp_query->query_vars['category_name'] ), 'buddypress' );
820
- } else if ( is_tag() ) {
821
- $title = __( 'Blog &#124; Tags &#124; ' . ucwords( $wp_query->query_vars['tag'] ), 'buddypress' );
822
- } else if ( is_page() ){
823
- $title = $post->post_title;
824
- } else
825
- $title = __( 'Blog', 'buddypress' );
826
-
827
- } else if ( !empty( $bp->displayed_user->fullname ) ) {
828
- $title = strip_tags( $bp->displayed_user->fullname . ' &#124; ' . ucwords( $bp->current_component ) );
829
-
830
- } else if ( $bp->is_single_item ) {
831
- $title = ucwords( $bp->current_component ) . ' &#124; ' . $bp->bp_options_title . ' &#124; ' . $bp->bp_options_nav[$bp->current_component][$bp->current_action]['name'];
832
-
833
- } else if ( $bp->is_directory ) {
834
- if ( !$bp->current_component )
835
- $title = sprintf( __( '%s Directory', 'buddypress' ), ucwords( BP_MEMBERS_SLUG ) );
836
- else
837
- $title = sprintf( __( '%s Directory', 'buddypress' ), ucwords( $bp->current_component ) );
838
-
839
- } else if ( bp_is_register_page() ) {
840
- $title = __( 'Create an Account', 'buddypress' );
841
-
842
- } else if ( bp_is_activation_page() ) {
843
- $title = __( 'Activate your Account', 'buddypress' );
844
-
845
- } else if ( bp_is_group_create() ) {
846
- $title = __( 'Create a Group', 'buddypress' );
847
-
848
- } else if ( bp_is_create_blog() ) {
849
- $title = __( 'Create a Blog', 'buddypress' );
850
- }
851
-
852
- if ( defined( 'BP_ENABLE_MULTIBLOG' ) ) {
853
- $blog_title = get_blog_option( $current_blog->blog_id, 'blogname' );
854
- } else {
855
- $blog_title = get_blog_option( BP_ROOT_BLOG, 'blogname' );
856
- }
857
-
858
- return apply_filters( 'bp_page_title', $blog_title . ' &#124; ' . esc_attr( $title ), esc_attr( $title ) );
859
- }
860
-
861
- function bp_styles() {
862
- do_action( 'bp_styles' );
863
- wp_print_styles();
864
- }
865
-
866
- function bp_has_custom_signup_page() {
867
- if ( locate_template( array( 'register.php' ), false ) || locate_template( array( '/registration/register.php' ), false ) )
868
- return true;
869
-
870
- return false;
871
- }
872
-
873
- function bp_signup_page() {
874
- echo bp_get_signup_page();
875
- }
876
- function bp_get_signup_page() {
877
- global $bp;
878
-
879
- if ( bp_has_custom_signup_page() )
880
- $page = $bp->root_domain . '/' . BP_REGISTER_SLUG;
881
- else
882
- $page = $bp->root_domain . '/wp-signup.php';
883
-
884
- return apply_filters( 'bp_get_signup_page', $page );
885
- }
886
-
887
- function bp_has_custom_activation_page() {
888
- if ( locate_template( array( 'activate.php' ), false ) || locate_template( array( '/registration/activate.php' ), false ) )
889
- return true;
890
-
891
- return false;
892
- }
893
-
894
- function bp_activation_page() {
895
- echo bp_get_activation_page();
896
- }
897
- function bp_get_activation_page() {
898
- global $bp;
899
-
900
- if ( bp_has_custom_activation_page() )
901
- $page = $bp->root_domain . '/' . BP_ACTIVATION_SLUG;
902
- else
903
- $page = $bp->root_domain . '/wp-activate.php';
904
-
905
- return apply_filters( 'bp_get_activation_page', $page );
906
- }
907
-
908
- function bp_search_form_action() {
909
- global $bp;
910
-
911
- return apply_filters( 'bp_search_form_action', $bp->root_domain . '/' . BP_SEARCH_SLUG );
912
- }
913
-
914
- function bp_search_form_type_select() {
915
- // Eventually this won't be needed and a page will be built to integrate all search results.
916
- $selection_box = '<select name="search-which" id="search-which" style="width: auto">';
917
-
918
- if ( function_exists( 'xprofile_install' ) ) {
919
- $selection_box .= '<option value="members">' . __( 'Members', 'buddypress' ) . '</option>';
920
- }
921
-
922
- if ( function_exists( 'groups_install' ) ) {
923
- $selection_box .= '<option value="groups">' . __( 'Groups', 'buddypress' ) . '</option>';
924
- }
925
-
926
- if ( function_exists( 'bp_forums_setup' ) && !(int) $bp->site_options['bp-disable-forum-directory'] ) {
927
- $selection_box .= '<option value="forums">' . __( 'Forums', 'buddypress' ) . '</option>';
928
- }
929
-
930
- if ( function_exists( 'bp_blogs_install' ) && bp_core_is_multisite() ) {
931
- $selection_box .= '<option value="blogs">' . __( 'Blogs', 'buddypress' ) . '</option>';
932
- }
933
-
934
- $selection_box .= '</select>';
935
-
936
- return apply_filters( 'bp_search_form_type_select', $selection_box );
937
- }
938
-
939
- function bp_search_form() {
940
- $form = '
941
- <form action="' . bp_search_form_action() . '" method="post" id="search-form">
942
- <input type="text" id="search-terms" name="search-terms" value="" />
943
- ' . bp_search_form_type_select() . '
944
-
945
- <input type="submit" name="search-submit" id="search-submit" value="' . __( 'Search', 'buddypress' ) . '" />
946
- ' . wp_nonce_field( 'bp_search_form' ) . '
947
- </form>
948
- ';
949
-
950
- echo apply_filters( 'bp_search_form', $form );
951
- }
952
-
953
- function bp_log_out_link() {
954
- global $bp;
955
- if ( function_exists('wp_logout_url') )
956
- $logout_link = '<a href="' . wp_logout_url( $bp->root_domain ) . '">' . __( 'Log Out', 'buddypress' ) . '</a>';
957
- else
958
- $logout_link = '<a href="' . $bp->root_domain . '/wp-login.php?action=logout&amp;redirect_to=' . $bp->root_domain . '">' . __( 'Log Out', 'buddypress' ) . '</a>';
959
-
960
- echo apply_filters( 'bp_logout_link', $logout_link );
961
- }
962
-
963
- function bp_custom_profile_boxes() {
964
- do_action( 'bp_custom_profile_boxes' );
965
- }
966
-
967
- function bp_custom_profile_sidebar_boxes() {
968
- do_action( 'bp_custom_profile_sidebar_boxes' );
969
- }
970
-
971
- /**
972
- * bp_create_excerpt()
973
- *
974
- * Fakes an excerpt on any content. Will not truncate words.
975
- *
976
- * @package BuddyPress Core
977
- * @param $text str The text to create the excerpt from
978
- * @uses $excerpt_length The maximum length in characters of the excerpt.
979
- * @return str The excerpt text
980
- */
981
- function bp_create_excerpt( $text, $excerpt_length = 55, $filter_shortcodes = true ) { // Fakes an excerpt if needed
982
- $text = str_replace(']]>', ']]&gt;', $text);
983
-
984
- if ( $filter_shortcodes )
985
- $text = preg_replace( '|\[(.+?)\](.+?\[/\\1\])?|s', '', $text );
986
-
987
- $words = preg_split(
988
- "%\s*((?:<[^>]+>)+\S*)\s*|\s+%s",
989
- $text,
990
- $excerpt_length + 1,
991
- PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE
992
- );
993
-
994
- if (count($words) > $excerpt_length) {
995
- array_pop($words);
996
- array_push($words, '[...]');
997
- $text = implode(' ', $words);
998
- }
999
-
1000
- return apply_filters( 'bp_create_excerpt', $text );
1001
- }
1002
- add_filter( 'bp_create_excerpt', 'wp_trim_excerpt' );
1003
- add_filter( 'bp_create_excerpt', 'stripslashes_deep' );
1004
- add_filter( 'bp_create_excerpt', 'force_balance_tags' );
1005
-
1006
- /**
1007
- * bp_is_serialized()
1008
- *
1009
- * Checks to see if the data passed has been serialized.
1010
- *
1011
- * @package BuddyPress Core
1012
- * @param $data str The data that will be checked
1013
- * @return bool false if the data is not serialized
1014
- * @return bool true if the data is serialized
1015
- */
1016
- function bp_is_serialized( $data ) {
1017
- if ( '' == trim($data) )
1018
- return false;
1019
-
1020
- if ( preg_match( "/^(i|s|a|o|d)(.*);/si", $data ) )
1021
- return true;
1022
-
1023
- return false;
1024
- }
1025
-
1026
- function bp_total_member_count() {
1027
- echo bp_get_total_member_count();
1028
- }
1029
- function bp_get_total_member_count() {
1030
- return apply_filters( 'bp_get_total_member_count', bp_core_get_total_member_count() );
1031
- }
1032
- add_filter( 'bp_get_total_member_count', 'bp_core_number_format' );
1033
-
1034
- /*** Signup form template tags **********************/
1035
-
1036
- function bp_signup_username_value() {
1037
- echo bp_get_signup_username_value();
1038
- }
1039
- function bp_get_signup_username_value() {
1040
- return apply_filters( 'bp_get_signup_username_value', $_POST['signup_username'] );
1041
- }
1042
-
1043
- function bp_signup_email_value() {
1044
- echo bp_get_signup_email_value();
1045
- }
1046
- function bp_get_signup_email_value() {
1047
- return apply_filters( 'bp_get_signup_email_value', $_POST['signup_email'] );
1048
- }
1049
-
1050
- function bp_signup_with_blog_value() {
1051
- echo bp_get_signup_with_blog_value();
1052
- }
1053
- function bp_get_signup_with_blog_value() {
1054
- return apply_filters( 'bp_get_signup_with_blog_value', $_POST['signup_with_blog'] );
1055
- }
1056
-
1057
- function bp_signup_blog_url_value() {
1058
- echo bp_get_signup_blog_url_value();
1059
- }
1060
- function bp_get_signup_blog_url_value() {
1061
- return apply_filters( 'bp_get_signup_blog_url_value', $_POST['signup_blog_url'] );
1062
- }
1063
-
1064
- function bp_signup_blog_title_value() {
1065
- echo bp_get_signup_blog_title_value();
1066
- }
1067
- function bp_get_signup_blog_title_value() {
1068
- return apply_filters( 'bp_get_signup_blog_title_value', $_POST['signup_blog_title'] );
1069
- }
1070
-
1071
- function bp_signup_blog_privacy_value() {
1072
- echo bp_get_signup_blog_privacy_value();
1073
- }
1074
- function bp_get_signup_blog_privacy_value() {
1075
- return apply_filters( 'bp_get_signup_blog_privacy_value', $_POST['signup_blog_privacy'] );
1076
- }
1077
-
1078
- function bp_signup_avatar_dir_value() {
1079
- echo bp_get_signup_avatar_dir_value();
1080
- }
1081
- function bp_get_signup_avatar_dir_value() {
1082
- global $bp;
1083
-
1084
- return apply_filters( 'bp_get_signup_avatar_dir_value', $bp->signup->avatar_dir );
1085
- }
1086
-
1087
- function bp_current_signup_step() {
1088
- echo bp_get_current_signup_step();
1089
- }
1090
- function bp_get_current_signup_step() {
1091
- global $bp;
1092
-
1093
- return $bp->signup->step;
1094
- }
1095
-
1096
- function bp_signup_avatar( $args = '' ) {
1097
- echo bp_get_signup_avatar( $args );
1098
- }
1099
- function bp_get_signup_avatar( $args = '' ) {
1100
- global $bp;
1101
-
1102
- $defaults = array(
1103
- 'size' => BP_AVATAR_FULL_WIDTH,
1104
- 'class' => 'avatar',
1105
- 'alt' => __( 'Your Avatar', 'buddypress' )
1106
- );
1107
-
1108
- $r = wp_parse_args( $args, $defaults );
1109
- extract( $r, EXTR_SKIP );
1110
-
1111
- $signup_avatar_dir = ( !empty( $_POST['signup_avatar_dir'] ) ) ? $_POST['signup_avatar_dir'] : $bp->signup->avatar_dir;
1112
-
1113
- if ( empty( $signup_avatar_dir ) ) {
1114
- if ( empty( $bp->grav_default->user ) ) {
1115
- $default_grav = 'wavatar';
1116
- } else if ( 'mystery' == $bp->grav_default->user ) {
1117
- $default_grav = BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg';
1118
- } else {
1119
- $default_grav = $bp->grav_default->user;
1120
- }
1121
-
1122
- $gravatar_url = apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' );
1123
- return apply_filters( 'bp_get_signup_avatar', '<img src="' . $gravatar_url . md5( $_POST['signup_email'] ) . '?d=' . $default_grav . '&amp;s=' . $size ) . '" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" class="' . $class . '" />';
1124
- } else {
1125
- return apply_filters( 'bp_get_signup_avatar', bp_core_fetch_avatar( array( 'item_id' => $signup_avatar_dir, 'object' => 'signup', 'avatar_dir' => 'avatars/signups', 'type' => 'full', 'width' => $size, 'height' => $size, 'alt' => $alt, 'class' => $class ) ) );
1126
- }
1127
- }
1128
-
1129
- function bp_signup_allowed() {
1130
- echo bp_get_signup_allowed();
1131
- }
1132
- function bp_get_signup_allowed() {
1133
- global $bp;
1134
-
1135
- if ( bp_core_is_multisite() ) {
1136
- if ( in_array( $bp->site_options['registration'], array( 'all', 'user' ) ) )
1137
- return true;
1138
- } else {
1139
- if ( (int)get_option( 'users_can_register') )
1140
- return true;
1141
- }
1142
- return false;
1143
- }
1144
-
1145
- function bp_blog_signup_allowed() {
1146
- echo bp_get_blog_signup_allowed();
1147
- }
1148
- function bp_get_blog_signup_allowed() {
1149
- global $bp;
1150
-
1151
- if ( !bp_core_is_multisite() )
1152
- return false;
1153
-
1154
- $status = $bp->site_options['registration'];
1155
- if ( 'none' != $status && 'user' != $status )
1156
- return true;
1157
-
1158
- return false;
1159
- }
1160
-
1161
- function bp_account_was_activated() {
1162
- global $bp;
1163
-
1164
- return $bp->activation_complete;
1165
- }
1166
-
1167
- function bp_registration_needs_activation() {
1168
- return apply_filters( 'bp_registration_needs_activation', true );
1169
- }
1170
-
1171
- function bp_mentioned_user_display_name( $user_id_or_username ) {
1172
- echo bp_get_mentioned_user_display_name( $user_id_or_username );
1173
- }
1174
- function bp_get_mentioned_user_display_name( $user_id_or_username ) {
1175
- if ( !$name = bp_core_get_user_displayname( $user_id_or_username ) )
1176
- $name = __( 'a user' );
1177
-
1178
- return apply_filters( 'bp_get_mentioned_user_display_name', $name, $user_id_or_username );
1179
- }
1180
-
1181
- function bp_get_option( $option_name ) {
1182
- global $bp;
1183
-
1184
- return apply_filters( 'bp_get_option', $bp->site_options[$option_name] );
1185
- }
1186
-
1187
- /**
1188
- * Allow templates to pass parameters directly into the template loops via AJAX
1189
- *
1190
- * For the most part this will be filtered in a theme's functions.php for example
1191
- * in the default theme it is filtered via bp_dtheme_ajax_querystring()
1192
- *
1193
- * By using this template tag in the templates it will stop them from showing errors
1194
- * if someone copies the templates from the default theme into another WordPress theme
1195
- * without coping the functions from functions.php.
1196
- */
1197
- function bp_ajax_querystring( $object = false ) {
1198
- global $bp;
1199
-
1200
- $bp->ajax_querystring = apply_filters( 'bp_ajax_querystring', $query_string, $object );
1201
- return $bp->ajax_querystring;
1202
- }
1203
-
1204
-
1205
- /*** CUSTOM LOOP TEMPLATE CLASSES *******************/
1206
-
1207
-
1208
- /* Template functions for fetching globals, without querying the DB again
1209
- also means we dont have to use the $bp variable in the template (looks messy) */
1210
-
1211
- function bp_last_activity( $user_id = false, $echo = true ) {
1212
- global $bp;
1213
-
1214
- if ( !$user_id )
1215
- $user_id = $bp->displayed_user->id;
1216
-
1217
- $last_activity = bp_core_get_last_activity( get_usermeta( $user_id, 'last_activity' ), __('active %s ago', 'buddypress') );
1218
-
1219
- if ( $echo )
1220
- echo apply_filters( 'bp_last_activity', $last_activity );
1221
- else
1222
- return apply_filters( 'bp_last_activity', $last_activity );
1223
- }
1224
-
1225
- function bp_user_has_access() {
1226
- global $bp;
1227
-
1228
- if ( is_site_admin() || is_user_logged_in() && $bp->loggedin_user->id == $bp->displayed_user->id )
1229
- $has_access = true;
1230
- else
1231
- $has_access = false;
1232
-
1233
- return apply_filters( 'bp_user_has_access', $has_access );
1234
- }
1235
-
1236
- function bp_user_firstname() {
1237
- echo bp_get_user_firstname();
1238
- }
1239
- function bp_get_user_firstname( $name = false ) {
1240
- global $bp;
1241
-
1242
- if ( !$name )
1243
- $name = $bp->loggedin_user->fullname;
1244
-
1245
- $fullname = (array)explode( ' ', $name );
1246
-
1247
- return apply_filters( 'bp_get_user_firstname', $fullname[0], $fullname );
1248
- }
1249
-
1250
- function bp_loggedin_user_link() {
1251
- echo bp_get_loggedin_user_link();
1252
- }
1253
- function bp_get_loggedin_user_link() {
1254
- global $bp;
1255
-
1256
- return apply_filters( 'bp_get_loggedin_user_link', $bp->loggedin_user->domain );
1257
- }
1258
-
1259
- /* @todo Deprecate incorrectly named function? */
1260
- function bp_loggedinuser_link() {
1261
- global $bp;
1262
-
1263
- if ( $link = bp_core_get_userlink( $bp->loggedin_user->id ) )
1264
- echo apply_filters( 'bp_loggedin_user_link', $link );
1265
- }
1266
-
1267
- function bp_displayed_user_link() {
1268
- echo bp_get_loggedin_user_link();
1269
- }
1270
- function bp_user_link() { bp_displayed_user_link(); }
1271
- function bp_get_displayed_user_link() {
1272
- global $bp;
1273
-
1274
- return apply_filters( 'bp_get_displayed_user_link', $bp->displayed_user->domain );
1275
- }
1276
-
1277
- function bp_displayed_user_id() {
1278
- global $bp;
1279
- return apply_filters( 'bp_displayed_user_id', $bp->displayed_user->id );
1280
- }
1281
- function bp_current_user_id() { return bp_displayed_user_id(); }
1282
-
1283
- function bp_loggedin_user_id() {
1284
- global $bp;
1285
- return apply_filters( 'bp_loggedin_user_id', $bp->loggedin_user->id );
1286
- }
1287
-
1288
- function bp_displayed_user_domain() {
1289
- global $bp;
1290
- return apply_filters( 'bp_displayed_user_domain', $bp->displayed_user->domain );
1291
- }
1292
-
1293
- function bp_loggedin_user_domain() {
1294
- global $bp;
1295
- return apply_filters( 'bp_loggedin_user_domain', $bp->loggedin_user->domain );
1296
- }
1297
-
1298
- function bp_displayed_user_fullname() {
1299
- echo bp_get_displayed_user_fullname();
1300
- }
1301
- function bp_get_displayed_user_fullname() {
1302
- global $bp;
1303
-
1304
- return apply_filters( 'bp_displayed_user_fullname', $bp->displayed_user->fullname );
1305
- }
1306
- function bp_user_fullname() { echo bp_get_displayed_user_fullname(); }
1307
-
1308
-
1309
- function bp_loggedin_user_fullname() {
1310
- echo bp_get_loggedin_user_fullname();
1311
- }
1312
- function bp_get_loggedin_user_fullname() {
1313
- global $bp;
1314
- return apply_filters( 'bp_get_loggedin_user_fullname', $bp->loggedin_user->fullname );
1315
- }
1316
-
1317
- function bp_displayed_user_username() {
1318
- echo bp_get_displayed_user_username();
1319
- }
1320
- function bp_get_displayed_user_username() {
1321
- global $bp;
1322
- 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 ) );
1323
- }
1324
-
1325
- function bp_loggedin_user_username() {
1326
- echo bp_get_loggedin_user_username();
1327
- }
1328
- function bp_get_loggedin_user_username() {
1329
- global $bp;
1330
- 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 ) );
1331
- }
1332
-
1333
- function bp_current_component() {
1334
- global $bp;
1335
- return apply_filters( 'bp_current_component', $bp->current_component );
1336
- }
1337
-
1338
- function bp_current_action() {
1339
- global $bp;
1340
- return apply_filters( 'bp_current_action', $bp->current_action );
1341
- }
1342
-
1343
- function bp_current_item() {
1344
- global $bp;
1345
- return apply_filters( 'bp_current_item', $bp->current_item );
1346
- }
1347
-
1348
- function bp_action_variables() {
1349
- global $bp;
1350
- return apply_filters( 'bp_action_variables', $bp->action_variables );
1351
- }
1352
-
1353
- function bp_root_domain() {
1354
- echo bp_get_root_domain();
1355
- }
1356
- function bp_get_root_domain() {
1357
- global $bp;
1358
-
1359
- return apply_filters( 'bp_get_root_domain', $bp->root_domain );
1360
- }
1361
-
1362
- /* Template is_() functions to determine the current page */
1363
-
1364
- function bp_is_blog_page() {
1365
- global $bp, $is_member_page, $wp_query;
1366
-
1367
- if ( $wp_query->is_home && !$bp->is_directory )
1368
- return true;
1369
-
1370
- if ( !$bp->displayed_user->id && !$bp->is_single_item && !$bp->is_directory && !bp_core_is_root_component( $bp->current_component ) )
1371
- return true;
1372
-
1373
- return false;
1374
- }
1375
-
1376
- function bp_is_my_profile() {
1377
- global $bp;
1378
-
1379
- if ( is_user_logged_in() && $bp->loggedin_user->id == $bp->displayed_user->id )
1380
- $my_profile = true;
1381
- else
1382
- $my_profile = false;
1383
-
1384
- return apply_filters( 'bp_is_my_profile', $my_profile );
1385
- }
1386
- function bp_is_home() { return bp_is_my_profile(); }
1387
-
1388
- function bp_is_front_page() {
1389
- if ( 'posts' == get_option('show_on_front') && is_home() )
1390
- return true;
1391
- else if ( bp_is_activity_front_page() )
1392
- return true;
1393
- else
1394
- return is_front_page();
1395
- }
1396
-
1397
- function bp_is_activity_front_page() {
1398
- return ( 'page' == get_option('show_on_front') && 'activity' == get_option('page_on_front') && $_SERVER['REQUEST_URI'] == bp_core_get_site_path() );
1399
- }
1400
-
1401
- function bp_is_directory() {
1402
- global $bp;
1403
-
1404
- return $bp->is_directory;
1405
- }
1406
-
1407
- function bp_is_page($page) {
1408
- global $bp;
1409
-
1410
- if ( !$bp->displayed_user->id && $bp->current_component == $page )
1411
- return true;
1412
-
1413
- if ( 'home' == $page )
1414
- return bp_is_front_page();
1415
-
1416
- return false;
1417
- }
1418
-
1419
- function bp_is_active( $component ) {
1420
- global $bp_deactivated;
1421
-
1422
- if ( !isset( $bp_deactivated[ 'bp-' . $component . '.php' ] ) )
1423
- return true;
1424
-
1425
- return false;
1426
- }
1427
-
1428
- function bp_is_profile_component() {
1429
- global $bp;
1430
-
1431
- if ( BP_XPROFILE_SLUG == $bp->current_component )
1432
- return true;
1433
-
1434
- return false;
1435
- }
1436
-
1437
- function bp_is_activity_component() {
1438
- global $bp;
1439
-
1440
- if ( BP_ACTIVITY_SLUG == $bp->current_component )
1441
- return true;
1442
-
1443
- return false;
1444
- }
1445
-
1446
- function bp_is_blogs_component() {
1447
- global $bp;
1448
-
1449
- if ( BP_BLOGS_SLUG == $bp->current_component )
1450
- return true;
1451
-
1452
- return false;
1453
- }
1454
-
1455
- function bp_is_messages_component() {
1456
- global $bp;
1457
-
1458
- if ( BP_MESSAGES_SLUG == $bp->current_component )
1459
- return true;
1460
-
1461
- return false;
1462
- }
1463
-
1464
- function bp_is_friends_component() {
1465
- global $bp;
1466
-
1467
- if ( BP_FRIENDS_SLUG == $bp->current_component )
1468
- return true;
1469
-
1470
- return false;
1471
- }
1472
-
1473
- function bp_is_groups_component() {
1474
- global $bp;
1475
-
1476
- if ( BP_GROUPS_SLUG == $bp->current_component )
1477
- return true;
1478
-
1479
- return false;
1480
- }
1481
-
1482
- function bp_is_settings_component() {
1483
- global $bp;
1484
-
1485
- if ( BP_SETTINGS_SLUG == $bp->current_component )
1486
- return true;
1487
-
1488
- return false;
1489
- }
1490
-
1491
- function bp_is_member() {
1492
- global $bp;
1493
-
1494
- if ( $bp->displayed_user->id )
1495
- return true;
1496
-
1497
- return false;
1498
- }
1499
-
1500
- function bp_is_user_activity() {
1501
- global $bp;
1502
-
1503
- if ( BP_ACTIVITY_SLUG == $bp->current_component )
1504
- return true;
1505
-
1506
- return false;
1507
- }
1508
-
1509
- function bp_is_user_friends_activity() {
1510
- global $bp;
1511
-
1512
- if ( BP_ACTIVITY_SLUG == $bp->current_component && 'my-friends' == $bp->current_action )
1513
- return true;
1514
-
1515
- return false;
1516
- }
1517
-
1518
- function bp_is_activity_permalink() {
1519
- global $bp;
1520
-
1521
- if ( BP_ACTIVITY_SLUG == $bp->current_component && is_numeric( $bp->current_action ) )
1522
- return true;
1523
-
1524
- return false;
1525
- }
1526
-
1527
- function bp_is_user_profile() {
1528
- global $bp;
1529
-
1530
- if ( BP_XPROFILE_SLUG == $bp->current_component || $bp->core->profile->slug == $bp->current_component )
1531
- return true;
1532
-
1533
- return false;
1534
- }
1535
-
1536
- function bp_is_profile_edit() {
1537
- global $bp;
1538
-
1539
- if ( BP_XPROFILE_SLUG == $bp->current_component && 'edit' == $bp->current_action )
1540
- return true;
1541
-
1542
- return false;
1543
- }
1544
-
1545
- function bp_is_change_avatar() {
1546
- global $bp;
1547
-
1548
- if ( BP_XPROFILE_SLUG == $bp->current_component && 'change-avatar' == $bp->current_action )
1549
- return true;
1550
-
1551
- return false;
1552
- }
1553
-
1554
- function bp_is_user_groups() {
1555
- global $bp;
1556
-
1557
- if ( BP_GROUPS_SLUG == $bp->current_component )
1558
- return true;
1559
-
1560
- return false;
1561
- }
1562
-
1563
- function bp_is_group() {
1564
- global $bp;
1565
-
1566
- if ( BP_GROUPS_SLUG == $bp->current_component && $bp->groups->current_group )
1567
- return true;
1568
-
1569
- return false;
1570
- }
1571
-
1572
- function bp_is_group_home() {
1573
- global $bp;
1574
-
1575
- if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && ( !$bp->current_action || 'home' == $bp->current_action ) )
1576
- return true;
1577
-
1578
- return false;
1579
- }
1580
-
1581
- function bp_is_group_create() {
1582
- global $bp;
1583
-
1584
- if ( BP_GROUPS_SLUG == $bp->current_component && 'create' == $bp->current_action )
1585
- return true;
1586
-
1587
- return false;
1588
- }
1589
-
1590
-
1591
- function bp_is_group_admin_page() {
1592
- global $bp;
1593
-
1594
- if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'admin' == $bp->current_action )
1595
- return true;
1596
-
1597
- return false;
1598
- }
1599
-
1600
- function bp_is_group_forum() {
1601
- global $bp;
1602
-
1603
- if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'forum' == $bp->current_action )
1604
- return true;
1605
-
1606
- return false;
1607
- }
1608
-
1609
- function bp_is_group_activity() {
1610
- global $bp;
1611
-
1612
- if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'activity' == $bp->current_action )
1613
- return true;
1614
-
1615
- return false;
1616
- }
1617
-
1618
- function bp_is_group_forum_topic() {
1619
- global $bp;
1620
-
1621
- if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'forum' == $bp->current_action && 'topic' == $bp->action_variables[0] )
1622
- return true;
1623
-
1624
- return false;
1625
- }
1626
-
1627
- function bp_is_group_forum_topic_edit() {
1628
- global $bp;
1629
-
1630
- 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] )
1631
- return true;
1632
-
1633
- return false;
1634
- }
1635
-
1636
- function bp_is_group_members() {
1637
- global $bp;
1638
-
1639
- if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'members' == $bp->current_action )
1640
- return true;
1641
-
1642
- return false;
1643
- }
1644
-
1645
- function bp_is_group_invites() {
1646
- global $bp;
1647
-
1648
- if ( BP_GROUPS_SLUG == $bp->current_component && 'send-invites' == $bp->current_action )
1649
- return true;
1650
-
1651
- return false;
1652
- }
1653
-
1654
- function bp_is_group_membership_request() {
1655
- global $bp;
1656
-
1657
- if ( BP_GROUPS_SLUG == $bp->current_component && 'request-membership' == $bp->current_action )
1658
- return true;
1659
-
1660
- return false;
1661
- }
1662
-
1663
- function bp_is_group_leave() {
1664
- global $bp;
1665
-
1666
- if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'leave-group' == $bp->current_action )
1667
- return true;
1668
-
1669
- return false;
1670
- }
1671
-
1672
- function bp_is_group_single() {
1673
- global $bp;
1674
-
1675
- if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item )
1676
- return true;
1677
-
1678
- return false;
1679
- }
1680
-
1681
- function bp_is_user_blogs() {
1682
- global $bp;
1683
-
1684
- if ( BP_BLOGS_SLUG == $bp->current_component )
1685
- return true;
1686
-
1687
- return false;
1688
- }
1689
-
1690
- function bp_is_user_recent_posts() {
1691
- global $bp;
1692
-
1693
- if ( BP_BLOGS_SLUG == $bp->current_component && 'recent-posts' == $bp->current_action )
1694
- return true;
1695
-
1696
- return false;
1697
- }
1698
-
1699
- function bp_is_user_recent_commments() {
1700
- global $bp;
1701
-
1702
- if ( BP_BLOGS_SLUG == $bp->current_component && 'recent-comments' == $bp->current_action )
1703
- return true;
1704
-
1705
- return false;
1706
- }
1707
-
1708
- function bp_is_create_blog() {
1709
- global $bp;
1710
-
1711
- if ( BP_BLOGS_SLUG == $bp->current_component && 'create' == $bp->current_action )
1712
- return true;
1713
-
1714
- return false;
1715
- }
1716
-
1717
- function bp_is_user_friends() {
1718
- global $bp;
1719
-
1720
- if ( BP_FRIENDS_SLUG == $bp->current_component )
1721
- return true;
1722
-
1723
- return false;
1724
- }
1725
-
1726
- function bp_is_friend_requests() {
1727
- global $bp;
1728
-
1729
- if ( BP_FRIENDS_SLUG == $bp->current_component && 'requests' == $bp->current_action )
1730
- return true;
1731
-
1732
- return false;
1733
- }
1734
-
1735
- function bp_is_user_messages() {
1736
- global $bp;
1737
-
1738
- if ( BP_MESSAGES_SLUG == $bp->current_component )
1739
- return true;
1740
-
1741
- return false;
1742
- }
1743
-
1744
- function bp_is_messages_inbox() {
1745
- global $bp;
1746
-
1747
- if ( BP_MESSAGES_SLUG == $bp->current_component && ( !$bp->current_action || 'inbox' == $bp->current_action ) )
1748
- return true;
1749
-
1750
- return false;
1751
- }
1752
-
1753
- function bp_is_messages_sentbox() {
1754
- global $bp;
1755
-
1756
- if ( BP_MESSAGES_SLUG == $bp->current_component && 'sentbox' == $bp->current_action )
1757
- return true;
1758
-
1759
- return false;
1760
- }
1761
-
1762
-
1763
- function bp_is_notices() {
1764
- global $bp;
1765
-
1766
- if ( BP_MESSAGES_SLUG == $bp->current_component && 'notices' == $bp->current_action )
1767
- return true;
1768
-
1769
- return false;
1770
- }
1771
-
1772
-
1773
- function bp_is_messages_compose_screen() {
1774
- global $bp;
1775
-
1776
- if ( BP_MESSAGES_SLUG == $bp->current_component && 'compose' == $bp->current_action )
1777
- return true;
1778
-
1779
- return false;
1780
- }
1781
-
1782
- function bp_is_single_item() {
1783
- global $bp;
1784
-
1785
- if ( $bp->is_single_item )
1786
- return true;
1787
-
1788
- return false;
1789
- }
1790
-
1791
- function bp_is_activation_page() {
1792
- global $bp;
1793
-
1794
- if ( BP_ACTIVATION_SLUG == $bp->current_component )
1795
- return true;
1796
-
1797
- return false;
1798
- }
1799
-
1800
- function bp_is_register_page() {
1801
- global $bp;
1802
-
1803
- if ( BP_REGISTER_SLUG == $bp->current_component )
1804
- return true;
1805
-
1806
- return false;
1807
- }
1808
-
1809
- /* Use the above is_() functions to output a body class for each page */
1810
-
1811
- function bp_the_body_class() {
1812
- echo bp_get_the_body_class();
1813
- }
1814
- function bp_get_the_body_class( $wp_classes, $custom_classes = false ) {
1815
- global $bp;
1816
-
1817
- if ( bp_is_front_page() )
1818
- $bp_classes[] = 'home-page';
1819
-
1820
- if ( bp_is_directory() )
1821
- $bp_classes[] = 'directory';
1822
-
1823
- if ( bp_is_user_profile() && !bp_is_blog_page() )
1824
- $bp_classes[] = 'profile';
1825
-
1826
- if ( bp_is_activity_component() && !bp_is_blog_page() || ( bp_is_activity_front_page() && bp_is_front_page() ) )
1827
- $bp_classes[] = 'activity';
1828
-
1829
- if ( bp_is_blogs_component() && !bp_is_blog_page() )
1830
- $bp_classes[] = 'blogs';
1831
-
1832
- if ( bp_is_messages_component() && !bp_is_blog_page() )
1833
- $bp_classes[] = 'messages';
1834
-
1835
- if ( bp_is_friends_component() && !bp_is_blog_page() )
1836
- $bp_classes[] = 'friends';
1837
-
1838
- if ( bp_is_groups_component() && !bp_is_blog_page() )
1839
- $bp_classes[] = 'groups';
1840
-
1841
- if ( bp_is_settings_component() && !bp_is_blog_page() )
1842
- $bp_classes[] = 'settings';
1843
-
1844
- if ( bp_is_single_item() )
1845
- $bp_classes[] = 'single-item';
1846
-
1847
- if ( bp_is_messages_inbox() )
1848
- $bp_classes[] = 'inbox';
1849
-
1850
- if ( bp_is_messages_sentbox() )
1851
- $bp_classes[] = 'sentbox';
1852
-
1853
- if ( bp_is_messages_compose_screen() )
1854
- $bp_classes[] = 'compose';
1855
-
1856
- if ( bp_is_notices() )
1857
- $bp_classes[] = 'notices';
1858
-
1859
- if ( bp_is_friend_requests() )
1860
- $bp_classes[] = 'friend-requests';
1861
-
1862
- if ( bp_is_user_friends() )
1863
- $bp_classes[] = 'my-friends';
1864
-
1865
- if ( bp_is_create_blog() )
1866
- $bp_classes[] = 'create-blog';
1867
-
1868
- if ( bp_is_user_recent_commments() )
1869
- $bp_classes[] = 'recent-comments';
1870
-
1871
- if ( bp_is_user_recent_posts() )
1872
- $bp_classes[] = 'recent-posts';
1873
-
1874
- if ( bp_is_user_blogs() && !bp_is_directory() )
1875
- $bp_classes[] = 'my-blogs';
1876
-
1877
- if ( bp_is_user_groups() && !bp_is_directory() )
1878
- $bp_classes[] = 'my-groups';
1879
-
1880
- if ( bp_is_group_leave() )
1881
- $bp_classes[] = 'leave-group';
1882
-
1883
- if ( bp_is_group_invites() )
1884
- $bp_classes[] = 'group-invites';
1885
-
1886
- if ( bp_is_group_members() )
1887
- $bp_classes[] = 'group-members';
1888
-
1889
- if ( bp_is_group_forum_topic() )
1890
- $bp_classes[] = 'group-forum-topic';
1891
-
1892
- if ( bp_is_group_forum_topic_edit() )
1893
- $bp_classes[] = 'group-forum-topic-edit';
1894
-
1895
- if ( bp_is_group_forum() )
1896
- $bp_classes[] = 'group-forum';
1897
-
1898
- if ( bp_is_group_admin_page() )
1899
- $bp_classes[] = 'group-admin';
1900
-
1901
- if ( bp_is_group_create() )
1902
- $bp_classes[] = 'group-create';
1903
-
1904
- if ( bp_is_group_home() )
1905
- $bp_classes[] = 'group-home';
1906
-
1907
- if ( bp_is_change_avatar() )
1908
- $bp_classes[] = 'change-avatar';
1909
-
1910
- if ( bp_is_profile_edit() )
1911
- $bp_classes[] = 'profile-edit';
1912
-
1913
- if ( bp_is_user_friends_activity() )
1914
- $bp_classes[] = 'friends-activity';
1915
-
1916
- if ( bp_is_user_activity() && !bp_is_directory() )
1917
- $bp_classes[] = 'my-activity';
1918
-
1919
- if ( bp_is_activity_permalink() )
1920
- $bp_classes[] = 'activity-permalink';
1921
-
1922
- if ( bp_is_register_page() )
1923
- $bp_classes[] = 'registration';
1924
-
1925
- if ( bp_is_activation_page() )
1926
- $bp_classes[] = 'activation';
1927
-
1928
- if ( is_user_logged_in() )
1929
- $bp_classes[] = 'logged-in';
1930
-
1931
- /* Add the current_component, current_action into the bp classes */
1932
- if ( !bp_is_blog_page() ) {
1933
- if ( !empty( $bp->current_component ) )
1934
- $bp_classes[] = $bp->current_component;
1935
-
1936
- if ( !empty( $bp->current_action ) )
1937
- $bp_classes[] = $bp->current_action;
1938
- }
1939
-
1940
- /* We don't want WordPress blog classes to appear on non-blog pages. */
1941
- if ( !bp_is_blog_page() || is_home() ) {
1942
- /* Preserve any custom classes already set */
1943
- if ( !empty( $custom_classes ) )
1944
- $wp_classes = (array) $custom_classes;
1945
- else
1946
- $wp_classes = array();
1947
- }
1948
-
1949
- /* Merge WP classes with BP classes */
1950
- $classes = array_merge( (array) $bp_classes, (array) $wp_classes );
1951
-
1952
- /* Remove any duplicates */
1953
- $classes = array_unique( $classes );
1954
-
1955
- return apply_filters( 'bp_get_the_body_class', $classes, $bp_classes, $wp_classes, $custom_classes );
1956
- }
1957
- add_filter( 'body_class', 'bp_get_the_body_class', 10, 2 )
1958
-
1959
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1960
  ?>
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
+
33
+ if ( !$max || $max >= (int)$this->members['total'] )
34
+ $this->total_member_count = (int)$this->members['total'];
35
+ else
36
+ $this->total_member_count = (int)$max;
37
+
38
+ $this->members = $this->members['users'];
39
+
40
+ if ( $max ) {
41
+ if ( $max >= count($this->members) )
42
+ $this->member_count = count($this->members);
43
+ else
44
+ $this->member_count = (int)$max;
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 = attribute_escape( 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_add_friend_button() {
421
+ global $members_template;
422
+
423
+ if ( function_exists( 'bp_add_friend_button' ) ) {
424
+ if ( null === $members_template->member->is_friend )
425
+ $friend_status = 'not_friends';
426
+ else
427
+ $friend_status = ( 0 == $members_template->member->is_friend ) ? 'pending' : 'is_friend';
428
+
429
+ echo bp_add_friend_button( $members_template->member->id, $friend_status );
430
+ }
431
+ }
432
+
433
+ function bp_member_total_friend_count() {
434
+ global $members_template;
435
+
436
+ echo bp_get_member_total_friend_count();
437
+ }
438
+ function bp_get_member_total_friend_count() {
439
+ global $members_template;
440
+
441
+ if ( 1 == (int) $members_template->member->total_friend_count )
442
+ return apply_filters( 'bp_get_member_total_friend_count', sprintf( __( '%d friend', 'buddypress' ), (int) $members_template->member->total_friend_count ) );
443
+ else
444
+ return apply_filters( 'bp_get_member_total_friend_count', sprintf( __( '%d friends', 'buddypress' ), (int) $members_template->member->total_friend_count ) );
445
+ }
446
+
447
+ function bp_member_random_profile_data() {
448
+ global $members_template;
449
+
450
+ if ( function_exists( 'xprofile_get_random_profile_data' ) ) { ?>
451
+ <?php $random_data = xprofile_get_random_profile_data( $members_template->member->id, true ); ?>
452
+ <strong><?php echo wp_filter_kses( $random_data[0]->name ) ?></strong>
453
+ <?php echo wp_filter_kses( $random_data[0]->value ) ?>
454
+ <?php }
455
+ }
456
+
457
+ function bp_member_hidden_fields() {
458
+ if ( isset( $_REQUEST['s'] ) ) {
459
+ echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['s'] ) . '" name="search_terms" />';
460
+ }
461
+
462
+ if ( isset( $_REQUEST['letter'] ) ) {
463
+ echo '<input type="hidden" id="selected_letter" value="' . attribute_escape( $_REQUEST['letter'] ) . '" name="selected_letter" />';
464
+ }
465
+
466
+ if ( isset( $_REQUEST['members_search'] ) ) {
467
+ echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['members_search'] ) . '" name="search_terms" />';
468
+ }
469
+ }
470
+
471
+ function bp_directory_members_search_form() {
472
+ global $bp;
473
+
474
+ $search_value = __( 'Search anything...', 'buddypress' );
475
+ if ( !empty( $_GET['s'] ) )
476
+ $search_value = $_GET['s'];
477
+
478
+ ?>
479
+ <form action="" method="get" id="search-members-form">
480
+ <label><input type="text" name="s" id="members_search" value="<?php echo attribute_escape( $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>
481
+ <input type="submit" id="members_search_submit" name="members_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
482
+ </form>
483
+ <?php
484
+ }
485
+
486
+ function bp_total_site_member_count() {
487
+ echo bp_get_total_site_member_count();
488
+ }
489
+ function bp_get_total_site_member_count() {
490
+ return apply_filters( 'bp_get_total_site_member_count', bp_core_number_format( bp_core_get_total_member_count() ) );
491
+ }
492
+
493
+
494
+ /** Navigation and other misc template tags **/
495
+
496
+ /**
497
+ * bp_get_nav()
498
+ * TEMPLATE TAG
499
+ *
500
+ * Uses the $bp->bp_nav global to render out the navigation within a BuddyPress install.
501
+ * Each component adds to this navigation array within its own [component_name]_setup_nav() function.
502
+ *
503
+ * This navigation array is the top level navigation, so it contains items such as:
504
+ * [Blog, Profile, Messages, Groups, Friends] ...
505
+ *
506
+ * The function will also analyze the current component the user is in, to determine whether
507
+ * or not to highlight a particular nav item.
508
+ *
509
+ * @package BuddyPress Core
510
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
511
+ */
512
+ function bp_get_loggedin_user_nav() {
513
+ global $bp, $current_blog;
514
+
515
+ /* Loop through each navigation item */
516
+ foreach( (array) $bp->bp_nav as $nav_item ) {
517
+ /* If the current component matches the nav item id, then add a highlight CSS class. */
518
+ if ( !bp_is_directory && $bp->active_components[$bp->current_component] == $nav_item['css_id'] )
519
+ $selected = ' class="current selected"';
520
+ else
521
+ $selected = '';
522
+
523
+ /* If we are viewing another person (current_userid does not equal loggedin_user->id)
524
+ then check to see if the two users are friends. if they are, add a highlight CSS class
525
+ to the friends nav item if it exists. */
526
+ if ( !bp_is_my_profile() && $bp->displayed_user->id ) {
527
+ $selected = '';
528
+
529
+ if ( function_exists('friends_install') ) {
530
+ if ( $nav_item['css_id'] == $bp->friends->id ) {
531
+ if ( friends_check_friendship( $bp->loggedin_user->id, $bp->displayed_user->id ) )
532
+ $selected = ' class="current selected"';
533
+ }
534
+ }
535
+ }
536
+
537
+ /* echo out the final list item */
538
+ 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 );
539
+ }
540
+
541
+ /* Always add a log out list item to the end of the navigation */
542
+ if ( function_exists( 'wp_logout_url' ) ) {
543
+ $logout_link = '<li><a id="wp-logout" href="' . wp_logout_url( $bp->root_domain ) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';
544
+ } else {
545
+ $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>';
546
+ }
547
+
548
+ echo apply_filters( 'bp_logout_nav_link', $logout_link );
549
+ }
550
+
551
+ /**
552
+ * bp_get_displayed_user_nav()
553
+ * TEMPLATE TAG
554
+ *
555
+ * Uses the $bp->bp_users_nav global to render out the user navigation when viewing another user other than
556
+ * yourself.
557
+ *
558
+ * @package BuddyPress Core
559
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
560
+ */
561
+ function bp_get_displayed_user_nav() {
562
+ global $bp;
563
+
564
+ foreach ( (array)$bp->bp_nav as $user_nav_item ) {
565
+ if ( !$user_nav_item['show_for_displayed_user'] && !bp_is_my_profile() )
566
+ continue;
567
+
568
+ if ( $bp->current_component == $user_nav_item['slug'] )
569
+ $selected = ' class="current selected"';
570
+ else
571
+ $selected = '';
572
+
573
+ if ( $bp->loggedin_user->domain )
574
+ $link = str_replace( $bp->loggedin_user->domain, $bp->displayed_user->domain, $user_nav_item['link'] );
575
+ else
576
+ $link = $bp->displayed_user->domain . $user_nav_item['link'];
577
+
578
+ 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 );
579
+ }
580
+ }
581
+
582
+ /**
583
+ * bp_get_options_nav()
584
+ * TEMPLATE TAG
585
+ *
586
+ * Uses the $bp->bp_options_nav global to render out the sub navigation for the current component.
587
+ * Each component adds to its sub navigation array within its own [component_name]_setup_nav() function.
588
+ *
589
+ * This sub navigation array is the secondary level navigation, so for profile it contains:
590
+ * [Public, Edit Profile, Change Avatar]
591
+ *
592
+ * The function will also analyze the current action for the current component to determine whether
593
+ * or not to highlight a particular sub nav item.
594
+ *
595
+ * @package BuddyPress Core
596
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
597
+ * @uses bp_get_user_nav() Renders the navigation for a profile of a currently viewed user.
598
+ */
599
+ function bp_get_options_nav() {
600
+ global $bp;
601
+
602
+ if ( count( $bp->bp_options_nav[$bp->current_component] ) < 1 )
603
+ return false;
604
+
605
+ /* Loop through each navigation item */
606
+ foreach ( (array)$bp->bp_options_nav[$bp->current_component] as $subnav_item ) {
607
+ if ( !$subnav_item['user_has_access'] )
608
+ continue;
609
+
610
+ /* If the current action or an action variable matches the nav item id, then add a highlight CSS class. */
611
+ if ( $subnav_item['slug'] == $bp->current_action ) {
612
+ $selected = ' class="current selected"';
613
+ } else {
614
+ $selected = '';
615
+ }
616
+
617
+ /* echo out the final list item */
618
+ 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 );
619
+ }
620
+ }
621
+
622
+ function bp_get_options_title() {
623
+ global $bp;
624
+
625
+ if ( empty( $bp->bp_options_title ) )
626
+ $bp->bp_options_title = __( 'Options', 'buddypress' );
627
+
628
+ echo apply_filters( 'bp_get_options_title', attribute_escape( $bp->bp_options_title ) );
629
+ }
630
+
631
+
632
+ /** AVATAR TEMPLATE TAGS *******************************************************/
633
+
634
+ /**
635
+ * bp_has_options_avatar()
636
+ * TEMPLATE TAG
637
+ *
638
+ * Check to see if there is an options avatar. An options avatar is an avatar for something
639
+ * like a group, or a friend. Basically an avatar that appears in the sub nav options bar.
640
+ *
641
+ * @package BuddyPress Core
642
+ * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
643
+ */
644
+ function bp_has_options_avatar() {
645
+ global $bp;
646
+
647
+ if ( empty( $bp->bp_options_avatar ) )
648
+ return false;
649
+
650
+ return true;
651
+ }
652
+
653
+ function bp_get_options_avatar() {
654
+ global $bp;
655
+
656
+ echo apply_filters( 'bp_get_options_avatar', $bp->bp_options_avatar );
657
+ }
658
+
659
+ function bp_comment_author_avatar() {
660
+ global $comment;
661
+
662
+ if ( function_exists('bp_core_fetch_avatar') ) {
663
+ echo apply_filters( 'bp_comment_author_avatar', bp_core_fetch_avatar( array( 'item_id' => $comment->user_id, 'type' => 'thumb' ) ) );
664
+ } else if ( function_exists('get_avatar') ) {
665
+ get_avatar();
666
+ }
667
+ }
668
+
669
+ function bp_post_author_avatar() {
670
+ global $post;
671
+
672
+ if ( function_exists('bp_core_fetch_avatar') ) {
673
+ echo apply_filters( 'bp_post_author_avatar', bp_core_fetch_avatar( array( 'item_id' => $post->post_author, 'type' => 'thumb' ) ) );
674
+ } else if ( function_exists('get_avatar') ) {
675
+ get_avatar();
676
+ }
677
+ }
678
+
679
+ function bp_loggedin_user_avatar( $args = '' ) {
680
+ echo bp_get_loggedin_user_avatar( $args );
681
+ }
682
+ function bp_get_loggedin_user_avatar( $args = '' ) {
683
+ global $bp;
684
+
685
+ $defaults = array(
686
+ 'type' => 'thumb',
687
+ 'width' => false,
688
+ 'height' => false,
689
+ 'html' => true
690
+ );
691
+
692
+ $r = wp_parse_args( $args, $defaults );
693
+ extract( $r, EXTR_SKIP );
694
+
695
+ 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 ) ) );
696
+ }
697
+
698
+ function bp_displayed_user_avatar( $args = '' ) {
699
+ echo bp_get_displayed_user_avatar( $args );
700
+ }
701
+ function bp_get_displayed_user_avatar( $args = '' ) {
702
+ global $bp;
703
+
704
+ $defaults = array(
705
+ 'type' => 'thumb',
706
+ 'width' => false,
707
+ 'height' => false,
708
+ 'html' => true
709
+ );
710
+
711
+ $r = wp_parse_args( $args, $defaults );
712
+ extract( $r, EXTR_SKIP );
713
+
714
+ 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 ) ) );
715
+ }
716
+
717
+ function bp_avatar_admin_step() {
718
+ echo bp_get_avatar_admin_step();
719
+ }
720
+ function bp_get_avatar_admin_step() {
721
+ global $bp;
722
+
723
+ return apply_filters( 'bp_get_avatar_admin_step', $bp->avatar_admin->step );
724
+ }
725
+
726
+ function bp_avatar_to_crop() {
727
+ echo bp_get_avatar_to_crop();
728
+ }
729
+ function bp_get_avatar_to_crop() {
730
+ global $bp;
731
+
732
+ return apply_filters( 'bp_get_avatar_to_crop', $bp->avatar_admin->image->url );
733
+ }
734
+
735
+ function bp_avatar_to_crop_src() {
736
+ echo bp_get_avatar_to_crop_src();
737
+ }
738
+ function bp_get_avatar_to_crop_src() {
739
+ global $bp;
740
+
741
+ return apply_filters( 'bp_get_avatar_to_crop_src', str_replace( WP_CONTENT_DIR, '', $bp->avatar_admin->image->dir ) );
742
+ }
743
+
744
+ function bp_avatar_cropper() {
745
+ global $bp;
746
+
747
+ echo '<img id="avatar-to-crop" class="avatar" src="' . $bp->avatar_admin->image . '" />';
748
+ }
749
+
750
+ /** OTHER TEMPLATE TAGS *******************************************************/
751
+
752
+ function bp_site_name() {
753
+ echo apply_filters( 'bp_site_name', get_blog_option( BP_ROOT_BLOG, 'blogname' ) );
754
+ }
755
+
756
+ function bp_core_get_wp_profile() {
757
+ global $bp;
758
+
759
+ $ud = get_userdata( $bp->displayed_user->id );
760
+ ?>
761
+
762
+ <div class="bp-widget wp-profile">
763
+ <h4><?php _e( 'My Profile' ) ?></h4>
764
+
765
+ <table class="wp-profile-fields zebra">
766
+ <?php if ( $ud->display_name ) { ?>
767
+ <tr id="wp_displayname">
768
+ <td class="label">
769
+ <?php _e( 'Name', 'buddypress' ) ?>
770
+ </td>
771
+ <td class="data">
772
+ <?php echo $ud->display_name ?>
773
+ </td>
774
+ </tr>
775
+ <?php } ?>
776
+ <?php if ( $ud->user_description ) { ?>
777
+ <tr id="wp_desc">
778
+ <td class="label">
779
+ <?php _e( 'About Me', 'buddypress' ) ?>
780
+ </td>
781
+ <td class="data">
782
+ <?php echo $ud->user_description ?>
783
+ </td>
784
+ </tr>
785
+ <?php } ?>
786
+ <?php if ( $ud->user_url ) { ?>
787
+ <tr id="wp_website">
788
+ <td class="label">
789
+ <?php _e( 'Website', 'buddypress' ) ?>
790
+ </td>
791
+ <td class="data">
792
+ <?php echo make_clickable( $ud->user_url ) ?>
793
+ </td>
794
+ </tr>
795
+ <?php } ?>
796
+ <?php if ( $ud->jabber ) { ?>
797
+ <tr id="wp_jabber">
798
+ <td class="label">
799
+ <?php _e( 'Jabber', 'buddypress' ) ?>
800
+ </td>
801
+ <td class="data">
802
+ <?php echo $ud->jabber ?>
803
+ </td>
804
+ </tr>
805
+ <?php } ?>
806
+ <?php if ( $ud->aim ) { ?>
807
+ <tr id="wp_aim">
808
+ <td class="label">
809
+ <?php _e( 'AOL Messenger', 'buddypress' ) ?>
810
+ </td>
811
+ <td class="data">
812
+ <?php echo $ud->aim ?>
813
+ </td>
814
+ </tr>
815
+ <?php } ?>
816
+ <?php if ( $ud->yim ) { ?>
817
+ <tr id="wp_yim">
818
+ <td class="label">
819
+ <?php _e( 'Yahoo Messenger', 'buddypress' ) ?>
820
+ </td>
821
+ <td class="data">
822
+ <?php echo $ud->yim ?>
823
+ </td>
824
+ </tr>
825
+ <?php } ?>
826
+ </table>
827
+ </div>
828
+ <?php
829
+ }
830
+
831
+ function bp_get_profile_header() {
832
+ locate_template( array( '/profile/profile-header.php' ), true );
833
+ }
834
+
835
+ function bp_exists( $component_name ) {
836
+ if ( function_exists($component_name . '_install') )
837
+ return true;
838
+
839
+ return false;
840
+ }
841
+
842
+ function bp_format_time( $time, $just_date = false ) {
843
+ $date = date( get_option('date_format'), $time );
844
+
845
+ if ( !$just_date ) {
846
+ $date .= ' ' . __( 'at', 'buddypress' ) . date( ' ' . get_option('time_format'), $time );
847
+ }
848
+
849
+ return apply_filters( 'bp_format_time', $date );
850
+ }
851
+
852
+ function bp_word_or_name( $youtext, $nametext, $capitalize = true, $echo = true ) {
853
+ global $bp;
854
+
855
+ if ( $capitalize )
856
+ $youtext = bp_core_ucfirst($youtext);
857
+
858
+ if ( $bp->displayed_user->id == $bp->loggedin_user->id ) {
859
+ if ( $echo )
860
+ echo apply_filters( 'bp_word_or_name', $youtext );
861
+ else
862
+ return apply_filters( 'bp_word_or_name', $youtext );
863
+ } else {
864
+ $fullname = (array)explode( ' ', $bp->displayed_user->fullname );
865
+ $nametext = sprintf( $nametext, $fullname[0] );
866
+ if ( $echo )
867
+ echo apply_filters( 'bp_word_or_name', $nametext );
868
+ else
869
+ return apply_filters( 'bp_word_or_name', $nametext );
870
+ }
871
+ }
872
+
873
+ function bp_your_or_their( $capitalize = true, $echo = true ) {
874
+ global $bp;
875
+
876
+ if ( $capitalize )
877
+ $yourtext = bp_core_ucfirst($yourtext);
878
+
879
+ if ( $bp->displayed_user->id == $bp->loggedin_user->id ) {
880
+ if ( $echo )
881
+ echo apply_filters( 'bp_your_or_their', $yourtext );
882
+ else
883
+ return apply_filters( 'bp_your_or_their', $yourtext );
884
+ } else {
885
+ if ( $echo )
886
+ echo apply_filters( 'bp_your_or_their', $theirtext );
887
+ else
888
+ return apply_filters( 'bp_your_or_their', $theirtext );
889
+ }
890
+ }
891
+
892
+ function bp_get_plugin_sidebar() {
893
+ locate_template( array( 'plugin-sidebar.php' ), true );
894
+ }
895
+
896
+ function bp_page_title() {
897
+ echo bp_get_page_title();
898
+ }
899
+
900
+ function bp_get_page_title() {
901
+ global $bp, $post, $wp_query, $current_blog;
902
+
903
+ if ( is_front_page() || !bp_current_component() || ( is_home() && bp_is_page( 'home' ) ) ) {
904
+ $title = __( 'Home', 'buddypress' );
905
+
906
+ } else if ( bp_is_blog_page() ) {
907
+ if ( is_single() ) {
908
+ $title = __( 'Blog &#124; ' . $post->post_title, 'buddypress' );
909
+ } else if ( is_category() ) {
910
+ $title = __( 'Blog &#124; Categories &#124; ' . ucwords( $wp_query->query_vars['category_name'] ), 'buddypress' );
911
+ } else if ( is_tag() ) {
912
+ $title = __( 'Blog &#124; Tags &#124; ' . ucwords( $wp_query->query_vars['tag'] ), 'buddypress' );
913
+ } else if ( is_page() ){
914
+ $title = $post->post_title;
915
+ } else
916
+ $title = __( 'Blog', 'buddypress' );
917
+
918
+ } else if ( !empty( $bp->displayed_user->fullname ) ) {
919
+ $title = strip_tags( $bp->displayed_user->fullname . ' &#124; ' . ucwords( $bp->current_component ) );
920
+
921
+ } else if ( $bp->is_single_item ) {
922
+ $title = ucwords( $bp->current_component ) . ' &#124; ' . $bp->bp_options_title . ' &#124; ' . $bp->bp_options_nav[$bp->current_component][$bp->current_action]['name'];
923
+
924
+ } else if ( $bp->is_directory ) {
925
+ if ( !$bp->current_component )
926
+ $title = sprintf( __( '%s Directory', 'buddypress' ), ucwords( BP_MEMBERS_SLUG ) );
927
+ else
928
+ $title = sprintf( __( '%s Directory', 'buddypress' ), ucwords( $bp->current_component ) );
929
+
930
+ } else if ( bp_is_register_page() ) {
931
+ $title = __( 'Create an Account', 'buddypress' );
932
+
933
+ } else if ( bp_is_activation_page() ) {
934
+ $title = __( 'Activate your Account', 'buddypress' );
935
+
936
+ } else if ( bp_is_group_create() ) {
937
+ $title = __( 'Create a Group', 'buddypress' );
938
+
939
+ } else if ( bp_is_create_blog() ) {
940
+ $title = __( 'Create a Blog', 'buddypress' );
941
+ }
942
+
943
+ if ( defined( 'BP_ENABLE_MULTIBLOG' ) ) {
944
+ $blog_title = get_blog_option( $current_blog->blog_id, 'blogname' );
945
+ } else {
946
+ $blog_title = get_blog_option( BP_ROOT_BLOG, 'blogname' );
947
+ }
948
+
949
+ return apply_filters( 'bp_page_title', $blog_title . ' &#124; ' . esc_attr( $title ), esc_attr( $title ) );
950
+ }
951
+
952
+ function bp_styles() {
953
+ do_action( 'bp_styles' );
954
+ wp_print_styles();
955
+ }
956
+
957
+ function bp_has_custom_signup_page() {
958
+ if ( locate_template( array( 'register.php' ), false ) || locate_template( array( '/registration/register.php' ), false ) )
959
+ return true;
960
+
961
+ return false;
962
+ }
963
+
964
+ function bp_signup_page() {
965
+ echo bp_get_signup_page();
966
+ }
967
+ function bp_get_signup_page() {
968
+ global $bp;
969
+
970
+ if ( bp_has_custom_signup_page() )
971
+ $page = $bp->root_domain . '/' . BP_REGISTER_SLUG;
972
+ else
973
+ $page = $bp->root_domain . '/wp-signup.php';
974
+
975
+ return apply_filters( 'bp_get_signup_page', $page );
976
+ }
977
+
978
+ function bp_has_custom_activation_page() {
979
+ if ( locate_template( array( 'activate.php' ), false ) || locate_template( array( '/registration/activate.php' ), false ) )
980
+ return true;
981
+
982
+ return false;
983
+ }
984
+
985
+ function bp_activation_page() {
986
+ echo bp_get_activation_page();
987
+ }
988
+ function bp_get_activation_page() {
989
+ global $bp;
990
+
991
+ if ( bp_has_custom_activation_page() )
992
+ $page = $bp->root_domain . '/' . BP_ACTIVATION_SLUG;
993
+ else
994
+ $page = $bp->root_domain . '/wp-activate.php';
995
+
996
+ return apply_filters( 'bp_get_activation_page', $page );
997
+ }
998
+
999
+ /**
1000
+ * bp_search_form_available()
1001
+ *
1002
+ * Only show the search form if there are available objects to search for.
1003
+ *
1004
+ * @global array $bp
1005
+ * @uses function_exists
1006
+ * @uses bp_core_is_multisite()
1007
+ * @return bool Filterable result
1008
+ */
1009
+ function bp_search_form_enabled() {
1010
+ global $bp;
1011
+
1012
+ if ( function_exists( 'xprofile_install' )
1013
+ || function_exists( 'groups_install' )
1014
+ || ( function_exists( 'bp_blogs_install' ) && bp_core_is_multisite() )
1015
+ || ( function_exists( 'bp_forums_setup' ) && !(int)$bp->site_options['bp-disable-forum-directory'] )
1016
+ ) {
1017
+ $search_enabled = true;
1018
+ } else {
1019
+ $search_enabled = false;
1020
+ }
1021
+
1022
+ return apply_filters( 'bp_search_form_enabled', $search_enabled );
1023
+ }
1024
+
1025
+ function bp_search_form_action() {
1026
+ global $bp;
1027
+
1028
+ return apply_filters( 'bp_search_form_action', $bp->root_domain . '/' . BP_SEARCH_SLUG );
1029
+ }
1030
+
1031
+ function bp_search_form_type_select() {
1032
+ global $bp;
1033
+
1034
+ // Eventually this won't be needed and a page will be built to integrate all search results.
1035
+ $selection_box = '<select name="search-which" id="search-which" style="width: auto">';
1036
+
1037
+ if ( function_exists( 'xprofile_install' ) )
1038
+ $selection_box .= '<option value="members">' . __( 'Members', 'buddypress' ) . '</option>';
1039
+
1040
+ if ( function_exists( 'groups_install' ) )
1041
+ $selection_box .= '<option value="groups">' . __( 'Groups', 'buddypress' ) . '</option>';
1042
+
1043
+ if ( function_exists( 'bp_forums_setup' ) && !(int)$bp->site_options['bp-disable-forum-directory'] )
1044
+ $selection_box .= '<option value="forums">' . __( 'Forums', 'buddypress' ) . '</option>';
1045
+
1046
+ if ( function_exists( 'bp_blogs_install' ) && bp_core_is_multisite() )
1047
+ $selection_box .= '<option value="blogs">' . __( 'Blogs', 'buddypress' ) . '</option>';
1048
+
1049
+ $selection_box .= '</select>';
1050
+
1051
+ return apply_filters( 'bp_search_form_type_select', $selection_box );
1052
+ }
1053
+
1054
+ function bp_search_form() {
1055
+ $form = '
1056
+ <form action="' . bp_search_form_action() . '" method="post" id="search-form">
1057
+ <input type="text" id="search-terms" name="search-terms" value="" />
1058
+ ' . bp_search_form_type_select() . '
1059
+
1060
+ <input type="submit" name="search-submit" id="search-submit" value="' . __( 'Search', 'buddypress' ) . '" />
1061
+ ' . wp_nonce_field( 'bp_search_form' ) . '
1062
+ </form>
1063
+ ';
1064
+
1065
+ echo apply_filters( 'bp_search_form', $form );
1066
+ }
1067
+
1068
+ function bp_log_out_link() {
1069
+ global $bp;
1070
+ if ( function_exists('wp_logout_url') )
1071
+ $logout_link = '<a href="' . wp_logout_url( $bp->root_domain ) . '">' . __( 'Log Out', 'buddypress' ) . '</a>';
1072
+ else
1073
+ $logout_link = '<a href="' . $bp->root_domain . '/wp-login.php?action=logout&amp;redirect_to=' . $bp->root_domain . '">' . __( 'Log Out', 'buddypress' ) . '</a>';
1074
+
1075
+ echo apply_filters( 'bp_logout_link', $logout_link );
1076
+ }
1077
+
1078
+ function bp_custom_profile_boxes() {
1079
+ do_action( 'bp_custom_profile_boxes' );
1080
+ }
1081
+
1082
+ function bp_custom_profile_sidebar_boxes() {
1083
+ do_action( 'bp_custom_profile_sidebar_boxes' );
1084
+ }
1085
+
1086
+ /**
1087
+ * bp_create_excerpt()
1088
+ *
1089
+ * Fakes an excerpt on any content. Will not truncate words.
1090
+ *
1091
+ * @package BuddyPress Core
1092
+ * @param $text str The text to create the excerpt from
1093
+ * @uses $excerpt_length The maximum length in characters of the excerpt.
1094
+ * @return str The excerpt text
1095
+ */
1096
+ function bp_create_excerpt( $text, $excerpt_length = 55, $filter_shortcodes = true ) { // Fakes an excerpt if needed
1097
+ $text = str_replace(']]>', ']]&gt;', $text);
1098
+
1099
+ if ( $filter_shortcodes )
1100
+ $text = preg_replace( '|\[(.+?)\](.+?\[/\\1\])?|s', '', $text );
1101
+
1102
+ $words = preg_split(
1103
+ "%\s*((?:<[^>]+>)+\S*)\s*|\s+%s",
1104
+ $text,
1105
+ $excerpt_length + 1,
1106
+ PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE
1107
+ );
1108
+
1109
+ if (count($words) > $excerpt_length) {
1110
+ array_pop($words);
1111
+ array_push($words, '[...]');
1112
+ $text = implode(' ', $words);
1113
+ }
1114
+
1115
+ return apply_filters( 'bp_create_excerpt', $text );
1116
+ }
1117
+ add_filter( 'bp_create_excerpt', 'wp_trim_excerpt' );
1118
+ add_filter( 'bp_create_excerpt', 'stripslashes_deep' );
1119
+ add_filter( 'bp_create_excerpt', 'force_balance_tags' );
1120
+
1121
+ /**
1122
+ * bp_is_serialized()
1123
+ *
1124
+ * Checks to see if the data passed has been serialized.
1125
+ *
1126
+ * @package BuddyPress Core
1127
+ * @param $data str The data that will be checked
1128
+ * @return bool false if the data is not serialized
1129
+ * @return bool true if the data is serialized
1130
+ */
1131
+ function bp_is_serialized( $data ) {
1132
+ if ( '' == trim($data) )
1133
+ return false;
1134
+
1135
+ if ( preg_match( "/^(i|s|a|o|d)(.*);/si", $data ) )
1136
+ return true;
1137
+
1138
+ return false;
1139
+ }
1140
+
1141
+ function bp_total_member_count() {
1142
+ echo bp_get_total_member_count();
1143
+ }
1144
+ function bp_get_total_member_count() {
1145
+ return apply_filters( 'bp_get_total_member_count', bp_core_get_total_member_count() );
1146
+ }
1147
+ add_filter( 'bp_get_total_member_count', 'bp_core_number_format' );
1148
+
1149
+ /*** Signup form template tags **********************/
1150
+
1151
+ function bp_signup_username_value() {
1152
+ echo bp_get_signup_username_value();
1153
+ }
1154
+ function bp_get_signup_username_value() {
1155
+ return apply_filters( 'bp_get_signup_username_value', $_POST['signup_username'] );
1156
+ }
1157
+
1158
+ function bp_signup_email_value() {
1159
+ echo bp_get_signup_email_value();
1160
+ }
1161
+ function bp_get_signup_email_value() {
1162
+ return apply_filters( 'bp_get_signup_email_value', $_POST['signup_email'] );
1163
+ }
1164
+
1165
+ function bp_signup_with_blog_value() {
1166
+ echo bp_get_signup_with_blog_value();
1167
+ }
1168
+ function bp_get_signup_with_blog_value() {
1169
+ return apply_filters( 'bp_get_signup_with_blog_value', $_POST['signup_with_blog'] );
1170
+ }
1171
+
1172
+ function bp_signup_blog_url_value() {
1173
+ echo bp_get_signup_blog_url_value();
1174
+ }
1175
+ function bp_get_signup_blog_url_value() {
1176
+ return apply_filters( 'bp_get_signup_blog_url_value', $_POST['signup_blog_url'] );
1177
+ }
1178
+
1179
+ function bp_signup_blog_title_value() {
1180
+ echo bp_get_signup_blog_title_value();
1181
+ }
1182
+ function bp_get_signup_blog_title_value() {
1183
+ return apply_filters( 'bp_get_signup_blog_title_value', $_POST['signup_blog_title'] );
1184
+ }
1185
+
1186
+ function bp_signup_blog_privacy_value() {
1187
+ echo bp_get_signup_blog_privacy_value();
1188
+ }
1189
+ function bp_get_signup_blog_privacy_value() {
1190
+ return apply_filters( 'bp_get_signup_blog_privacy_value', $_POST['signup_blog_privacy'] );
1191
+ }
1192
+
1193
+ function bp_signup_avatar_dir_value() {
1194
+ echo bp_get_signup_avatar_dir_value();
1195
+ }
1196
+ function bp_get_signup_avatar_dir_value() {
1197
+ global $bp;
1198
+
1199
+ return apply_filters( 'bp_get_signup_avatar_dir_value', $bp->signup->avatar_dir );
1200
+ }
1201
+
1202
+ function bp_current_signup_step() {
1203
+ echo bp_get_current_signup_step();
1204
+ }
1205
+ function bp_get_current_signup_step() {
1206
+ global $bp;
1207
+
1208
+ return $bp->signup->step;
1209
+ }
1210
+
1211
+ function bp_signup_avatar( $args = '' ) {
1212
+ echo bp_get_signup_avatar( $args );
1213
+ }
1214
+ function bp_get_signup_avatar( $args = '' ) {
1215
+ global $bp;
1216
+
1217
+ $defaults = array(
1218
+ 'size' => BP_AVATAR_FULL_WIDTH,
1219
+ 'class' => 'avatar',
1220
+ 'alt' => __( 'Your Avatar', 'buddypress' )
1221
+ );
1222
+
1223
+ $r = wp_parse_args( $args, $defaults );
1224
+ extract( $r, EXTR_SKIP );
1225
+
1226
+ $signup_avatar_dir = ( !empty( $_POST['signup_avatar_dir'] ) ) ? $_POST['signup_avatar_dir'] : $bp->signup->avatar_dir;
1227
+
1228
+ if ( empty( $signup_avatar_dir ) ) {
1229
+ if ( empty( $bp->grav_default->user ) ) {
1230
+ $default_grav = 'wavatar';
1231
+ } else if ( 'mystery' == $bp->grav_default->user ) {
1232
+ $default_grav = BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg';
1233
+ } else {
1234
+ $default_grav = $bp->grav_default->user;
1235
+ }
1236
+
1237
+ $gravatar_url = apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' );
1238
+ $gravatar_img = '<img src="' . $gravatar_url . md5( strtolower( $_POST['signup_email'] ) ) . '?d=' . $default_grav . '&amp;s=' . $size . '" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" class="' . $class . '" />';
1239
+ } else {
1240
+ $gravatar_img = bp_core_fetch_avatar( array( 'item_id' => $signup_avatar_dir, 'object' => 'signup', 'avatar_dir' => 'avatars/signups', 'type' => 'full', 'width' => $size, 'height' => $size, 'alt' => $alt, 'class' => $class ) );
1241
+ }
1242
+
1243
+ return apply_filters( 'bp_get_signup_avatar', $gravatar_img );
1244
+ }
1245
+
1246
+ function bp_signup_allowed() {
1247
+ echo bp_get_signup_allowed();
1248
+ }
1249
+ function bp_get_signup_allowed() {
1250
+ global $bp;
1251
+
1252
+ if ( bp_core_is_multisite() ) {
1253
+ if ( in_array( $bp->site_options['registration'], array( 'all', 'user' ) ) )
1254
+ return true;
1255
+ } else {
1256
+ if ( (int)get_option( 'users_can_register') )
1257
+ return true;
1258
+ }
1259
+ return false;
1260
+ }
1261
+
1262
+ function bp_blog_signup_allowed() {
1263
+ echo bp_get_blog_signup_allowed();
1264
+ }
1265
+ function bp_get_blog_signup_allowed() {
1266
+ global $bp;
1267
+
1268
+ if ( !bp_core_is_multisite() )
1269
+ return false;
1270
+
1271
+ $status = $bp->site_options['registration'];
1272
+ if ( 'none' != $status && 'user' != $status )
1273
+ return true;
1274
+
1275
+ return false;
1276
+ }
1277
+
1278
+ function bp_account_was_activated() {
1279
+ global $bp;
1280
+
1281
+ return $bp->activation_complete;
1282
+ }
1283
+
1284
+ function bp_registration_needs_activation() {
1285
+ return apply_filters( 'bp_registration_needs_activation', true );
1286
+ }
1287
+
1288
+ function bp_mentioned_user_display_name( $user_id_or_username ) {
1289
+ echo bp_get_mentioned_user_display_name( $user_id_or_username );
1290
+ }
1291
+ function bp_get_mentioned_user_display_name( $user_id_or_username ) {
1292
+ if ( !$name = bp_core_get_user_displayname( $user_id_or_username ) )
1293
+ $name = __( 'a user' );
1294
+
1295
+ return apply_filters( 'bp_get_mentioned_user_display_name', $name, $user_id_or_username );
1296
+ }
1297
+
1298
+ function bp_get_option( $option_name ) {
1299
+ global $bp;
1300
+
1301
+ return apply_filters( 'bp_get_option', $bp->site_options[$option_name] );
1302
+ }
1303
+
1304
+ /**
1305
+ * Allow templates to pass parameters directly into the template loops via AJAX
1306
+ *
1307
+ * For the most part this will be filtered in a theme's functions.php for example
1308
+ * in the default theme it is filtered via bp_dtheme_ajax_querystring()
1309
+ *
1310
+ * By using this template tag in the templates it will stop them from showing errors
1311
+ * if someone copies the templates from the default theme into another WordPress theme
1312
+ * without coping the functions from functions.php.
1313
+ */
1314
+ function bp_ajax_querystring( $object = false ) {
1315
+ global $bp;
1316
+
1317
+ $bp->ajax_querystring = apply_filters( 'bp_ajax_querystring', $query_string, $object );
1318
+ return $bp->ajax_querystring;
1319
+ }
1320
+
1321
+
1322
+ /*** CUSTOM LOOP TEMPLATE CLASSES *******************/
1323
+
1324
+
1325
+ /* Template functions for fetching globals, without querying the DB again
1326
+ also means we dont have to use the $bp variable in the template (looks messy) */
1327
+
1328
+ function bp_last_activity( $user_id = false, $echo = true ) {
1329
+ global $bp;
1330
+
1331
+ if ( !$user_id )
1332
+ $user_id = $bp->displayed_user->id;
1333
+
1334
+ $last_activity = bp_core_get_last_activity( get_usermeta( $user_id, 'last_activity' ), __('active %s ago', 'buddypress') );
1335
+
1336
+ if ( $echo )
1337
+ echo apply_filters( 'bp_last_activity', $last_activity );
1338
+ else
1339
+ return apply_filters( 'bp_last_activity', $last_activity );
1340
+ }
1341
+
1342
+ function bp_user_has_access() {
1343
+ global $bp;
1344
+
1345
+ if ( is_site_admin() || is_user_logged_in() && $bp->loggedin_user->id == $bp->displayed_user->id )
1346
+ $has_access = true;
1347
+ else
1348
+ $has_access = false;
1349
+
1350
+ return apply_filters( 'bp_user_has_access', $has_access );
1351
+ }
1352
+
1353
+ function bp_user_firstname() {
1354
+ echo bp_get_user_firstname();
1355
+ }
1356
+ function bp_get_user_firstname( $name = false ) {
1357
+ global $bp;
1358
+
1359
+ // Try to get displayed user
1360
+ if ( empty( $name ) )
1361
+ $name = $bp->displayed_user->fullname;
1362
+
1363
+ // Fall back on logged in user
1364
+ if ( empty( $name ) )
1365
+ $name = $bp->loggedin_user->fullname;
1366
+
1367
+ $fullname = (array)explode( ' ', $name );
1368
+
1369
+ return apply_filters( 'bp_get_user_firstname', $fullname[0], $fullname );
1370
+ }
1371
+
1372
+ function bp_loggedin_user_link() {
1373
+ echo bp_get_loggedin_user_link();
1374
+ }
1375
+ function bp_get_loggedin_user_link() {
1376
+ global $bp;
1377
+
1378
+ return apply_filters( 'bp_get_loggedin_user_link', $bp->loggedin_user->domain );
1379
+ }
1380
+
1381
+ /* @todo Deprecate incorrectly named function? */
1382
+ function bp_loggedinuser_link() {
1383
+ global $bp;
1384
+
1385
+ if ( $link = bp_core_get_userlink( $bp->loggedin_user->id ) )
1386
+ echo apply_filters( 'bp_loggedin_user_link', $link );
1387
+ }
1388
+
1389
+ function bp_displayed_user_link() {
1390
+ echo bp_get_displayed_user_link();
1391
+ }
1392
+ function bp_get_displayed_user_link() {
1393
+ global $bp;
1394
+
1395
+ return apply_filters( 'bp_get_displayed_user_link', $bp->displayed_user->domain );
1396
+ }
1397
+ function bp_user_link() { bp_displayed_user_link(); } // Deprecated.
1398
+
1399
+ function bp_displayed_user_id() {
1400
+ global $bp;
1401
+ return apply_filters( 'bp_displayed_user_id', $bp->displayed_user->id );
1402
+ }
1403
+ function bp_current_user_id() { return bp_displayed_user_id(); }
1404
+
1405
+ function bp_loggedin_user_id() {
1406
+ global $bp;
1407
+ return apply_filters( 'bp_loggedin_user_id', $bp->loggedin_user->id );
1408
+ }
1409
+
1410
+ function bp_displayed_user_domain() {
1411
+ global $bp;
1412
+ return apply_filters( 'bp_displayed_user_domain', $bp->displayed_user->domain );
1413
+ }
1414
+
1415
+ function bp_loggedin_user_domain() {
1416
+ global $bp;
1417
+ return apply_filters( 'bp_loggedin_user_domain', $bp->loggedin_user->domain );
1418
+ }
1419
+
1420
+ function bp_displayed_user_fullname() {
1421
+ echo bp_get_displayed_user_fullname();
1422
+ }
1423
+ function bp_get_displayed_user_fullname() {
1424
+ global $bp;
1425
+
1426
+ return apply_filters( 'bp_displayed_user_fullname', $bp->displayed_user->fullname );
1427
+ }
1428
+ function bp_user_fullname() { echo bp_get_displayed_user_fullname(); }
1429
+
1430
+
1431
+ function bp_loggedin_user_fullname() {
1432
+ echo bp_get_loggedin_user_fullname();
1433
+ }
1434
+ function bp_get_loggedin_user_fullname() {
1435
+ global $bp;
1436
+ return apply_filters( 'bp_get_loggedin_user_fullname', $bp->loggedin_user->fullname );
1437
+ }
1438
+
1439
+ function bp_displayed_user_username() {
1440
+ echo bp_get_displayed_user_username();
1441
+ }
1442
+ function bp_get_displayed_user_username() {
1443
+ global $bp;
1444
+ 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 ) );
1445
+ }
1446
+
1447
+ function bp_loggedin_user_username() {
1448
+ echo bp_get_loggedin_user_username();
1449
+ }
1450
+ function bp_get_loggedin_user_username() {
1451
+ global $bp;
1452
+ 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 ) );
1453
+ }
1454
+
1455
+ function bp_current_component() {
1456
+ global $bp;
1457
+ return apply_filters( 'bp_current_component', $bp->current_component );
1458
+ }
1459
+
1460
+ function bp_current_action() {
1461
+ global $bp;
1462
+ return apply_filters( 'bp_current_action', $bp->current_action );
1463
+ }
1464
+
1465
+ function bp_current_item() {
1466
+ global $bp;
1467
+ return apply_filters( 'bp_current_item', $bp->current_item );
1468
+ }
1469
+
1470
+ function bp_action_variables() {
1471
+ global $bp;
1472
+ return apply_filters( 'bp_action_variables', $bp->action_variables );
1473
+ }
1474
+
1475
+ function bp_root_domain() {
1476
+ echo bp_get_root_domain();
1477
+ }
1478
+ function bp_get_root_domain() {
1479
+ global $bp;
1480
+
1481
+ return apply_filters( 'bp_get_root_domain', $bp->root_domain );
1482
+ }
1483
+
1484
+ /* Template is_() functions to determine the current page */
1485
+
1486
+ function bp_is_blog_page() {
1487
+ global $bp, $is_member_page, $wp_query;
1488
+
1489
+ if ( $wp_query->is_home && !$bp->is_directory )
1490
+ return true;
1491
+
1492
+ if ( !$bp->displayed_user->id && !$bp->is_single_item && !$bp->is_directory && !bp_core_is_root_component( $bp->current_component ) )
1493
+ return true;
1494
+
1495
+ return false;
1496
+ }
1497
+
1498
+ function bp_is_my_profile() {
1499
+ global $bp;
1500
+
1501
+ if ( is_user_logged_in() && $bp->loggedin_user->id == $bp->displayed_user->id )
1502
+ $my_profile = true;
1503
+ else
1504
+ $my_profile = false;
1505
+
1506
+ return apply_filters( 'bp_is_my_profile', $my_profile );
1507
+ }
1508
+ function bp_is_home() { return bp_is_my_profile(); }
1509
+
1510
+ function bp_is_front_page() {
1511
+ if ( 'posts' == get_option('show_on_front') && is_home() )
1512
+ return true;
1513
+ else if ( bp_is_activity_front_page() )
1514
+ return true;
1515
+ else
1516
+ return is_front_page();
1517
+ }
1518
+
1519
+ function bp_is_activity_front_page() {
1520
+ return ( 'page' == get_option('show_on_front') && 'activity' == get_option('page_on_front') && $_SERVER['REQUEST_URI'] == bp_core_get_site_path() );
1521
+ }
1522
+
1523
+ function bp_is_directory() {
1524
+ global $bp;
1525
+
1526
+ return $bp->is_directory;
1527
+ }
1528
+
1529
+ function bp_is_page($page) {
1530
+ global $bp;
1531
+
1532
+ if ( !$bp->displayed_user->id && $bp->current_component == $page )
1533
+ return true;
1534
+
1535
+ if ( 'home' == $page )
1536
+ return bp_is_front_page();
1537
+
1538
+ return false;
1539
+ }
1540
+
1541
+ function bp_is_active( $component ) {
1542
+ global $bp_deactivated;
1543
+
1544
+ if ( !isset( $bp_deactivated[ 'bp-' . $component . '.php' ] ) )
1545
+ return true;
1546
+
1547
+ return false;
1548
+ }
1549
+
1550
+ function bp_is_profile_component() {
1551
+ global $bp;
1552
+
1553
+ if ( BP_XPROFILE_SLUG == $bp->current_component )
1554
+ return true;
1555
+
1556
+ return false;
1557
+ }
1558
+
1559
+ function bp_is_activity_component() {
1560
+ global $bp;
1561
+
1562
+ if ( BP_ACTIVITY_SLUG == $bp->current_component )
1563
+ return true;
1564
+
1565
+ return false;
1566
+ }
1567
+
1568
+ function bp_is_blogs_component() {
1569
+ global $bp;
1570
+
1571
+ if ( BP_BLOGS_SLUG == $bp->current_component )
1572
+ return true;
1573
+
1574
+ return false;
1575
+ }
1576
+
1577
+ function bp_is_messages_component() {
1578
+ global $bp;
1579
+
1580
+ if ( BP_MESSAGES_SLUG == $bp->current_component )
1581
+ return true;
1582
+
1583
+ return false;
1584
+ }
1585
+
1586
+ function bp_is_friends_component() {
1587
+ global $bp;
1588
+
1589
+ if ( BP_FRIENDS_SLUG == $bp->current_component )
1590
+ return true;
1591
+
1592
+ return false;
1593
+ }
1594
+
1595
+ function bp_is_groups_component() {
1596
+ global $bp;
1597
+
1598
+ if ( BP_GROUPS_SLUG == $bp->current_component )
1599
+ return true;
1600
+
1601
+ return false;
1602
+ }
1603
+
1604
+ function bp_is_settings_component() {
1605
+ global $bp;
1606
+
1607
+ if ( BP_SETTINGS_SLUG == $bp->current_component )
1608
+ return true;
1609
+
1610
+ return false;
1611
+ }
1612
+
1613
+ function bp_is_member() {
1614
+ global $bp;
1615
+
1616
+ if ( $bp->displayed_user->id )
1617
+ return true;
1618
+
1619
+ return false;
1620
+ }
1621
+
1622
+ function bp_is_user_activity() {
1623
+ global $bp;
1624
+
1625
+ if ( BP_ACTIVITY_SLUG == $bp->current_component )
1626
+ return true;
1627
+
1628
+ return false;
1629
+ }
1630
+
1631
+ function bp_is_user_friends_activity() {
1632
+ global $bp;
1633
+
1634
+ if ( BP_ACTIVITY_SLUG == $bp->current_component && 'my-friends' == $bp->current_action )
1635
+ return true;
1636
+
1637
+ return false;
1638
+ }
1639
+
1640
+ function bp_is_activity_permalink() {
1641
+ global $bp;
1642
+
1643
+ if ( BP_ACTIVITY_SLUG == $bp->current_component && is_numeric( $bp->current_action ) )
1644
+ return true;
1645
+
1646
+ return false;
1647
+ }
1648
+
1649
+ function bp_is_user_profile() {
1650
+ global $bp;
1651
+
1652
+ if ( BP_XPROFILE_SLUG == $bp->current_component || $bp->core->profile->slug == $bp->current_component )
1653
+ return true;
1654
+
1655
+ return false;
1656
+ }
1657
+
1658
+ function bp_is_profile_edit() {
1659
+ global $bp;
1660
+
1661
+ if ( BP_XPROFILE_SLUG == $bp->current_component && 'edit' == $bp->current_action )
1662
+ return true;
1663
+
1664
+ return false;
1665
+ }
1666
+
1667
+ function bp_is_change_avatar() {
1668
+ global $bp;
1669
+
1670
+ if ( BP_XPROFILE_SLUG == $bp->current_component && 'change-avatar' == $bp->current_action )
1671
+ return true;
1672
+
1673
+ return false;
1674
+ }
1675
+
1676
+ function bp_is_user_groups() {
1677
+ global $bp;
1678
+
1679
+ if ( BP_GROUPS_SLUG == $bp->current_component )
1680
+ return true;
1681
+
1682
+ return false;
1683
+ }
1684
+
1685
+ function bp_is_group() {
1686
+ global $bp;
1687
+
1688
+ if ( BP_GROUPS_SLUG == $bp->current_component && $bp->groups->current_group )
1689
+ return true;
1690
+
1691
+ return false;
1692
+ }
1693
+
1694
+ function bp_is_group_home() {
1695
+ global $bp;
1696
+
1697
+ if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && ( !$bp->current_action || 'home' == $bp->current_action ) )
1698
+ return true;
1699
+
1700
+ return false;
1701
+ }
1702
+
1703
+ function bp_is_group_create() {
1704
+ global $bp;
1705
+
1706
+ if ( BP_GROUPS_SLUG == $bp->current_component && 'create' == $bp->current_action )
1707
+ return true;
1708
+
1709
+ return false;
1710
+ }
1711
+
1712
+
1713
+ function bp_is_group_admin_page() {
1714
+ global $bp;
1715
+
1716
+ if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'admin' == $bp->current_action )
1717
+ return true;
1718
+
1719
+ return false;
1720
+ }
1721
+
1722
+ function bp_is_group_forum() {
1723
+ global $bp;
1724
+
1725
+ if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'forum' == $bp->current_action )
1726
+ return true;
1727
+
1728
+ return false;
1729
+ }
1730
+
1731
+ function bp_is_group_activity() {
1732
+ global $bp;
1733
+
1734
+ if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'activity' == $bp->current_action )
1735
+ return true;
1736
+
1737
+ return false;
1738
+ }
1739
+
1740
+ function bp_is_group_forum_topic() {
1741
+ global $bp;
1742
+
1743
+ if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'forum' == $bp->current_action && 'topic' == $bp->action_variables[0] )
1744
+ return true;
1745
+
1746
+ return false;
1747
+ }
1748
+
1749
+ function bp_is_group_forum_topic_edit() {
1750
+ global $bp;
1751
+
1752
+ 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] )
1753
+ return true;
1754
+
1755
+ return false;
1756
+ }
1757
+
1758
+ function bp_is_group_members() {
1759
+ global $bp;
1760
+
1761
+ if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'members' == $bp->current_action )
1762
+ return true;
1763
+
1764
+ return false;
1765
+ }
1766
+
1767
+ function bp_is_group_invites() {
1768
+ global $bp;
1769
+
1770
+ if ( BP_GROUPS_SLUG == $bp->current_component && 'send-invites' == $bp->current_action )
1771
+ return true;
1772
+
1773
+ return false;
1774
+ }
1775
+
1776
+ function bp_is_group_membership_request() {
1777
+ global $bp;
1778
+
1779
+ if ( BP_GROUPS_SLUG == $bp->current_component && 'request-membership' == $bp->current_action )
1780
+ return true;
1781
+
1782
+ return false;
1783
+ }
1784
+
1785
+ function bp_is_group_leave() {
1786
+ global $bp;
1787
+
1788
+ if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item && 'leave-group' == $bp->current_action )
1789
+ return true;
1790
+
1791
+ return false;
1792
+ }
1793
+
1794
+ function bp_is_group_single() {
1795
+ global $bp;
1796
+
1797
+ if ( BP_GROUPS_SLUG == $bp->current_component && $bp->is_single_item )
1798
+ return true;
1799
+
1800
+ return false;
1801
+ }
1802
+
1803
+ function bp_is_user_blogs() {
1804
+ global $bp;
1805
+
1806
+ if ( BP_BLOGS_SLUG == $bp->current_component )
1807
+ return true;
1808
+
1809
+ return false;
1810
+ }
1811
+
1812
+ function bp_is_user_recent_posts() {
1813
+ global $bp;
1814
+
1815
+ if ( BP_BLOGS_SLUG == $bp->current_component && 'recent-posts' == $bp->current_action )
1816
+ return true;
1817
+
1818
+ return false;
1819
+ }
1820
+
1821
+ function bp_is_user_recent_commments() {
1822
+ global $bp;
1823
+
1824
+ if ( BP_BLOGS_SLUG == $bp->current_component && 'recent-comments' == $bp->current_action )
1825
+ return true;
1826
+
1827
+ return false;
1828
+ }
1829
+
1830
+ function bp_is_create_blog() {
1831
+ global $bp;
1832
+
1833
+ if ( BP_BLOGS_SLUG == $bp->current_component && 'create' == $bp->current_action )
1834
+ return true;
1835
+
1836
+ return false;
1837
+ }
1838
+
1839
+ function bp_is_user_friends() {
1840
+ global $bp;
1841
+
1842
+ if ( BP_FRIENDS_SLUG == $bp->current_component )
1843
+ return true;
1844
+
1845
+ return false;
1846
+ }
1847
+
1848
+ function bp_is_friend_requests() {
1849
+ global $bp;
1850
+
1851
+ if ( BP_FRIENDS_SLUG == $bp->current_component && 'requests' == $bp->current_action )
1852
+ return true;
1853
+
1854
+ return false;
1855
+ }
1856
+
1857
+ function bp_is_user_messages() {
1858
+ global $bp;
1859
+
1860
+ if ( BP_MESSAGES_SLUG == $bp->current_component )
1861
+ return true;
1862
+
1863
+ return false;
1864
+ }
1865
+
1866
+ function bp_is_messages_inbox() {
1867
+ global $bp;
1868
+
1869
+ if ( BP_MESSAGES_SLUG == $bp->current_component && ( !$bp->current_action || 'inbox' == $bp->current_action ) )
1870
+ return true;
1871
+
1872
+ return false;
1873
+ }
1874
+
1875
+ function bp_is_messages_sentbox() {
1876
+ global $bp;
1877
+
1878
+ if ( BP_MESSAGES_SLUG == $bp->current_component && 'sentbox' == $bp->current_action )
1879
+ return true;
1880
+
1881
+ return false;
1882
+ }
1883
+
1884
+
1885
+ function bp_is_notices() {
1886
+ global $bp;
1887
+
1888
+ if ( BP_MESSAGES_SLUG == $bp->current_component && 'notices' == $bp->current_action )
1889
+ return true;
1890
+
1891
+ return false;
1892
+ }
1893
+
1894
+
1895
+ function bp_is_messages_compose_screen() {
1896
+ global $bp;
1897
+
1898
+ if ( BP_MESSAGES_SLUG == $bp->current_component && 'compose' == $bp->current_action )
1899
+ return true;
1900
+
1901
+ return false;
1902
+ }
1903
+
1904
+ function bp_is_single_item() {
1905
+ global $bp;
1906
+
1907
+ if ( $bp->is_single_item )
1908
+ return true;
1909
+
1910
+ return false;
1911
+ }
1912
+
1913
+ function bp_is_activation_page() {
1914
+ global $bp;
1915
+
1916
+ if ( BP_ACTIVATION_SLUG == $bp->current_component )
1917
+ return true;
1918
+
1919
+ return false;
1920
+ }
1921
+
1922
+ function bp_is_register_page() {
1923
+ global $bp;
1924
+
1925
+ if ( BP_REGISTER_SLUG == $bp->current_component )
1926
+ return true;
1927
+
1928
+ return false;
1929
+ }
1930
+
1931
+ /* Use the above is_() functions to output a body class for each page */
1932
+
1933
+ function bp_the_body_class() {
1934
+ echo bp_get_the_body_class();
1935
+ }
1936
+ function bp_get_the_body_class( $wp_classes, $custom_classes = false ) {
1937
+ global $bp;
1938
+
1939
+ if ( bp_is_front_page() )
1940
+ $bp_classes[] = 'home-page';
1941
+
1942
+ if ( bp_is_directory() )
1943
+ $bp_classes[] = 'directory';
1944
+
1945
+ if ( bp_is_user_profile() && !bp_is_blog_page() )
1946
+ $bp_classes[] = 'profile';
1947
+
1948
+ if ( bp_is_activity_component() && !bp_is_blog_page() || ( bp_is_activity_front_page() && bp_is_front_page() ) )
1949
+ $bp_classes[] = 'activity';
1950
+
1951
+ if ( bp_is_blogs_component() && !bp_is_blog_page() )
1952
+ $bp_classes[] = 'blogs';
1953
+
1954
+ if ( bp_is_messages_component() && !bp_is_blog_page() )
1955
+ $bp_classes[] = 'messages';
1956
+
1957
+ if ( bp_is_friends_component() && !bp_is_blog_page() )
1958
+ $bp_classes[] = 'friends';
1959
+
1960
+ if ( bp_is_groups_component() && !bp_is_blog_page() )
1961
+ $bp_classes[] = 'groups';
1962
+
1963
+ if ( bp_is_settings_component() && !bp_is_blog_page() )
1964
+ $bp_classes[] = 'settings';
1965
+
1966
+ if ( bp_is_single_item() )
1967
+ $bp_classes[] = 'single-item';
1968
+
1969
+ if ( bp_is_messages_inbox() )
1970
+ $bp_classes[] = 'inbox';
1971
+
1972
+ if ( bp_is_messages_sentbox() )
1973
+ $bp_classes[] = 'sentbox';
1974
+
1975
+ if ( bp_is_messages_compose_screen() )
1976
+ $bp_classes[] = 'compose';
1977
+
1978
+ if ( bp_is_notices() )
1979
+ $bp_classes[] = 'notices';
1980
+
1981
+ if ( bp_is_friend_requests() )
1982
+ $bp_classes[] = 'friend-requests';
1983
+
1984
+ if ( bp_is_user_friends() )
1985
+ $bp_classes[] = 'my-friends';
1986
+
1987
+ if ( bp_is_create_blog() )
1988
+ $bp_classes[] = 'create-blog';
1989
+
1990
+ if ( bp_is_user_recent_commments() )
1991
+ $bp_classes[] = 'recent-comments';
1992
+
1993
+ if ( bp_is_user_recent_posts() )
1994
+ $bp_classes[] = 'recent-posts';
1995
+
1996
+ if ( bp_is_user_blogs() && !bp_is_directory() )
1997
+ $bp_classes[] = 'my-blogs';
1998
+
1999
+ if ( bp_is_user_groups() && !bp_is_directory() )
2000
+ $bp_classes[] = 'my-groups';
2001
+
2002
+ if ( bp_is_group_leave() )
2003
+ $bp_classes[] = 'leave-group';
2004
+
2005
+ if ( bp_is_group_invites() )
2006
+ $bp_classes[] = 'group-invites';
2007
+
2008
+ if ( bp_is_group_members() )
2009
+ $bp_classes[] = 'group-members';
2010
+
2011
+ if ( bp_is_group_forum_topic() )
2012
+ $bp_classes[] = 'group-forum-topic';
2013
+
2014
+ if ( bp_is_group_forum_topic_edit() )
2015
+ $bp_classes[] = 'group-forum-topic-edit';
2016
+
2017
+ if ( bp_is_group_forum() )
2018
+ $bp_classes[] = 'group-forum';
2019
+
2020
+ if ( bp_is_group_admin_page() )
2021
+ $bp_classes[] = 'group-admin';
2022
+
2023
+ if ( bp_is_group_create() )
2024
+ $bp_classes[] = 'group-create';
2025
+
2026
+ if ( bp_is_group_home() )
2027
+ $bp_classes[] = 'group-home';
2028
+
2029
+ if ( bp_is_change_avatar() )
2030
+ $bp_classes[] = 'change-avatar';
2031
+
2032
+ if ( bp_is_profile_edit() )
2033
+ $bp_classes[] = 'profile-edit';
2034
+
2035
+ if ( bp_is_user_friends_activity() )
2036
+ $bp_classes[] = 'friends-activity';
2037
+
2038
+ if ( bp_is_user_activity() && !bp_is_directory() )
2039
+ $bp_classes[] = 'my-activity';
2040
+
2041
+ if ( bp_is_activity_permalink() )
2042
+ $bp_classes[] = 'activity-permalink';
2043
+
2044
+ if ( bp_is_register_page() )
2045
+ $bp_classes[] = 'registration';
2046
+
2047
+ if ( bp_is_activation_page() )
2048
+ $bp_classes[] = 'activation';
2049
+
2050
+ if ( is_user_logged_in() )
2051
+ $bp_classes[] = 'logged-in';
2052
+
2053
+ /* Add the current_component, current_action into the bp classes */
2054
+ if ( !bp_is_blog_page() ) {
2055
+ if ( !empty( $bp->current_component ) )
2056
+ $bp_classes[] = $bp->current_component;
2057
+
2058
+ if ( !empty( $bp->current_action ) )
2059
+ $bp_classes[] = $bp->current_action;
2060
+ }
2061
+
2062
+ /* We don't want WordPress blog classes to appear on non-blog pages. */
2063
+ if ( !bp_is_blog_page() || is_home() ) {
2064
+ /* Preserve any custom classes already set */
2065
+ if ( !empty( $custom_classes ) )
2066
+ $wp_classes = (array) $custom_classes;
2067
+ else
2068
+ $wp_classes = array();
2069
+ }
2070
+
2071
+ /* Merge WP classes with BP classes */
2072
+ $classes = array_merge( (array) $bp_classes, (array) $wp_classes );
2073
+
2074
+ /* Remove any duplicates */
2075
+ $classes = array_unique( $classes );
2076
+
2077
+ return apply_filters( 'bp_get_the_body_class', $classes, $bp_classes, $wp_classes, $custom_classes );
2078
+ }
2079
+ add_filter( 'body_class', 'bp_get_the_body_class', 10, 2 )
2080
+
2081
+
2082
  ?>
bp-core/bp-core-widgets.php CHANGED
@@ -1,243 +1,243 @@
1
- <?php
2
-
3
- /* Register widgets for the core component */
4
- function bp_core_register_widgets() {
5
- add_action('widgets_init', create_function('', 'return register_widget("BP_Core_Members_Widget");') );
6
- add_action('widgets_init', create_function('', 'return register_widget("BP_Core_Whos_Online_Widget");') );
7
- add_action('widgets_init', create_function('', 'return register_widget("BP_Core_Recently_Active_Widget");') );
8
- }
9
- add_action( 'bp_register_widgets', 'bp_core_register_widgets' );
10
-
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
- <a href="<?php echo site_url() . '/' . BP_MEMBERS_SLUG ?>" id="popular-members"><?php _e( 'Popular', 'buddypress' ) ?></a>
37
- </div>
38
-
39
- <ul id="members-list" class="item-list">
40
- <?php while ( bp_members() ) : bp_the_member(); ?>
41
- <li class="vcard">
42
- <div class="item-avatar">
43
- <a href="<?php bp_member_permalink() ?>"><?php bp_member_avatar() ?></a>
44
- </div>
45
-
46
- <div class="item">
47
- <div class="item-title fn"><a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_name() ?></a></div>
48
- <div class="item-meta"><span class="activity"><?php bp_member_registered() ?></span></div>
49
- </div>
50
- </li>
51
-
52
- <?php endwhile; ?>
53
- </ul>
54
- <?php wp_nonce_field( 'bp_core_widget_members', '_wpnonce-members' ); ?>
55
- <input type="hidden" name="members_widget_max" id="members_widget_max" value="<?php echo attribute_escape( $instance['max_members'] ); ?>" />
56
-
57
- <?php else: ?>
58
-
59
- <div class="widget-error">
60
- <?php _e('No one has signed up yet!', 'buddypress') ?>
61
- </div>
62
-
63
- <?php endif; ?>
64
-
65
- <?php echo $after_widget; ?>
66
- <?php
67
- }
68
-
69
- function update( $new_instance, $old_instance ) {
70
- $instance = $old_instance;
71
- $instance['max_members'] = strip_tags( $new_instance['max_members'] );
72
-
73
- return $instance;
74
- }
75
-
76
- function form( $instance ) {
77
- $instance = wp_parse_args( (array) $instance, array( 'max_members' => 5 ) );
78
- $max_members = strip_tags( $instance['max_members'] );
79
- ?>
80
-
81
- <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 attribute_escape( $max_members ); ?>" style="width: 30%" /></label></p>
82
- <?php
83
- }
84
- }
85
-
86
- /*** WHO'S ONLINE WIDGET *****************/
87
-
88
- class BP_Core_Whos_Online_Widget extends WP_Widget {
89
- function bp_core_whos_online_widget() {
90
- parent::WP_Widget( false, $name = __( "Who's Online Avatars", 'buddypress' ) );
91
- }
92
-
93
- function widget($args, $instance) {
94
- global $bp;
95
-
96
- extract( $args );
97
-
98
- echo $before_widget;
99
- echo $before_title
100
- . $widget_name
101
- . $after_title; ?>
102
-
103
- <?php if ( bp_has_members( 'user_id=0&type=online&per_page=' . $instance['max_members'] . '&max=' . $instance['max_members'] . '&populate_extras=0' ) ) : ?>
104
- <div class="avatar-block">
105
- <?php while ( bp_members() ) : bp_the_member(); ?>
106
- <div class="item-avatar">
107
- <a href="<?php bp_member_permalink() ?>"><?php bp_member_avatar() ?></a>
108
- </div>
109
- <?php endwhile; ?>
110
- </div>
111
- <?php else: ?>
112
-
113
- <div class="widget-error">
114
- <?php _e( 'There are no users currently online', 'buddypress' ) ?>
115
- </div>
116
-
117
- <?php endif; ?>
118
-
119
- <?php echo $after_widget; ?>
120
- <?php
121
- }
122
-
123
- function update( $new_instance, $old_instance ) {
124
- $instance = $old_instance;
125
- $instance['max_members'] = strip_tags( $new_instance['max_members'] );
126
-
127
- return $instance;
128
- }
129
-
130
- function form( $instance ) {
131
- $instance = wp_parse_args( (array) $instance, array( 'max_members' => 15 ) );
132
- $max_members = strip_tags( $instance['max_members'] );
133
- ?>
134
-
135
- <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 attribute_escape( $max_members ); ?>" style="width: 30%" /></label></p>
136
- <?php
137
- }
138
- }
139
-
140
- /*** RECENTLY ACTIVE WIDGET *****************/
141
-
142
- class BP_Core_Recently_Active_Widget extends WP_Widget {
143
- function bp_core_recently_active_widget() {
144
- parent::WP_Widget( false, $name = __( 'Recently Active Member Avatars', 'buddypress' ) );
145
- }
146
-
147
- function widget($args, $instance) {
148
- global $bp;
149
-
150
- extract( $args );
151
-
152
- echo $before_widget;
153
- echo $before_title
154
- . $widget_name
155
- . $after_title; ?>
156
-
157
- <?php if ( bp_has_members( 'user_id=0&type=active&per_page=' . $instance['max_members'] . '&max=' . $instance['max_members'] . '&populate_extras=0' ) ) : ?>
158
- <div class="avatar-block">
159
- <?php while ( bp_members() ) : bp_the_member(); ?>
160
- <div class="item-avatar">
161
- <a href="<?php bp_member_permalink() ?>"><?php bp_member_avatar() ?></a>
162
- </div>
163
- <?php endwhile; ?>
164
- </div>
165
- <?php else: ?>
166
-
167
- <div class="widget-error">
168
- <?php _e( 'There are no recently active members', 'buddypress' ) ?>
169
- </div>
170
-
171
- <?php endif; ?>
172
-
173
- <?php echo $after_widget; ?>
174
- <?php
175
- }
176
-
177
- function update( $new_instance, $old_instance ) {
178
- $instance = $old_instance;
179
- $instance['max_members'] = strip_tags( $new_instance['max_members'] );
180
-
181
- return $instance;
182
- }
183
-
184
- function form( $instance ) {
185
- $instance = wp_parse_args( (array) $instance, array( 'max_members' => 15 ) );
186
- $max_members = strip_tags( $instance['max_members'] );
187
- ?>
188
-
189
- <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 attribute_escape( $max_members ); ?>" style="width: 30%" /></label></p>
190
- <?php
191
- }
192
- }
193
-
194
- /** Widget AJAX ******************/
195
-
196
- function bp_core_ajax_widget_members() {
197
- global $bp;
198
-
199
- check_ajax_referer( 'bp_core_widget_members' );
200
-
201
- switch ( $_POST['filter'] ) {
202
- case 'newest-members':
203
- $type = 'newest';
204
- break;
205
- case 'recently-active-members':
206
- $type = 'active';
207
- break;
208
- case 'popular-members':
209
- $type = 'popular';
210
- break;
211
- }
212
-
213
- if ( bp_has_members( 'user_id=0&type=' . $type . '&per_page=' . $_POST['max-members'] . '&max=' . $_POST['max-members'] . '&populate_extras=0' ) ) : ?>
214
- <?php echo '0[[SPLIT]]'; // return valid result. TODO: remove this. ?>
215
- <div class="avatar-block">
216
- <?php while ( bp_members() ) : bp_the_member(); ?>
217
- <li class="vcard">
218
- <div class="item-avatar">
219
- <a href="<?php bp_member_permalink() ?>"><?php bp_member_avatar() ?></a>
220
- </div>
221
-
222
- <div class="item">
223
- <div class="item-title fn"><a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_name() ?></a></div>
224
- <?php if ( 'active' == $type || 'newest' == $type ) : ?>
225
- <div class="item-meta"><span class="activity"><?php bp_member_last_active() ?></span></div>
226
- <?php else : ?>
227
- <div class="item-meta"><span class="activity"><?php bp_member_total_friend_count() ?></span></div>
228
- <?php endif; ?>
229
- </div>
230
- </li>
231
-
232
- <?php endwhile; ?>
233
- </div>
234
-
235
- <?php else: ?>
236
- <?php echo "-1[[SPLIT]]<li>"; ?>
237
- <?php _e( 'There were no members found, please try another filter.', 'buddypress' ) ?>
238
- <?php echo "</li>"; ?>
239
- <?php endif;
240
- }
241
- add_action( 'wp_ajax_widget_members', 'bp_core_ajax_widget_members' );
242
-
243
  ?>
1
+ <?php
2
+
3
+ /* Register widgets for the core component */
4
+ function bp_core_register_widgets() {
5
+ add_action('widgets_init', create_function('', 'return register_widget("BP_Core_Members_Widget");') );
6
+ add_action('widgets_init', create_function('', 'return register_widget("BP_Core_Whos_Online_Widget");') );
7
+ add_action('widgets_init', create_function('', 'return register_widget("BP_Core_Recently_Active_Widget");') );
8
+ }
9
+ add_action( 'bp_register_widgets', 'bp_core_register_widgets' );
10
+
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
+ <a href="<?php echo site_url() . '/' . BP_MEMBERS_SLUG ?>" id="popular-members"><?php _e( 'Popular', 'buddypress' ) ?></a>
37
+ </div>
38
+
39
+ <ul id="members-list" class="item-list">
40
+ <?php while ( bp_members() ) : bp_the_member(); ?>
41
+ <li class="vcard">
42
+ <div class="item-avatar">
43
+ <a href="<?php bp_member_permalink() ?>"><?php bp_member_avatar() ?></a>
44
+ </div>
45
+
46
+ <div class="item">
47
+ <div class="item-title fn"><a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_name() ?></a></div>
48
+ <div class="item-meta"><span class="activity"><?php bp_member_registered() ?></span></div>
49
+ </div>
50
+ </li>
51
+
52
+ <?php endwhile; ?>
53
+ </ul>
54
+ <?php wp_nonce_field( 'bp_core_widget_members', '_wpnonce-members' ); ?>
55
+ <input type="hidden" name="members_widget_max" id="members_widget_max" value="<?php echo attribute_escape( $instance['max_members'] ); ?>" />
56
+
57
+ <?php else: ?>
58
+
59
+ <div class="widget-error">
60
+ <?php _e('No one has signed up yet!', 'buddypress') ?>
61
+ </div>
62
+
63
+ <?php endif; ?>
64
+
65
+ <?php echo $after_widget; ?>
66
+ <?php
67
+ }
68
+
69
+ function update( $new_instance, $old_instance ) {
70
+ $instance = $old_instance;
71
+ $instance['max_members'] = strip_tags( $new_instance['max_members'] );
72
+
73
+ return $instance;
74
+ }
75
+
76
+ function form( $instance ) {
77
+ $instance = wp_parse_args( (array) $instance, array( 'max_members' => 5 ) );
78
+ $max_members = strip_tags( $instance['max_members'] );
79
+ ?>
80
+
81
+ <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 attribute_escape( $max_members ); ?>" style="width: 30%" /></label></p>
82
+ <?php
83
+ }
84
+ }
85
+
86
+ /*** WHO'S ONLINE WIDGET *****************/
87
+
88
+ class BP_Core_Whos_Online_Widget extends WP_Widget {
89
+ function bp_core_whos_online_widget() {
90
+ parent::WP_Widget( false, $name = __( "Who's Online Avatars", 'buddypress' ) );
91
+ }
92
+
93
+ function widget($args, $instance) {
94
+ global $bp;
95
+
96
+ extract( $args );
97
+
98
+ echo $before_widget;
99
+ echo $before_title
100
+ . $widget_name
101
+ . $after_title; ?>
102
+
103
+ <?php if ( bp_has_members( 'user_id=0&type=online&per_page=' . $instance['max_members'] . '&max=' . $instance['max_members'] . '&populate_extras=0' ) ) : ?>
104
+ <div class="avatar-block">
105
+ <?php while ( bp_members() ) : bp_the_member(); ?>
106
+ <div class="item-avatar">
107
+ <a href="<?php bp_member_permalink() ?>"><?php bp_member_avatar() ?></a>
108
+ </div>
109
+ <?php endwhile; ?>
110
+ </div>
111
+ <?php else: ?>
112
+
113
+ <div class="widget-error">
114
+ <?php _e( 'There are no users currently online', 'buddypress' ) ?>
115
+ </div>
116
+
117
+ <?php endif; ?>
118
+
119
+ <?php echo $after_widget; ?>
120
+ <?php
121
+ }
122
+
123
+ function update( $new_instance, $old_instance ) {
124
+ $instance = $old_instance;
125
+ $instance['max_members'] = strip_tags( $new_instance['max_members'] );
126
+
127
+ return $instance;
128
+ }
129
+
130
+ function form( $instance ) {
131
+ $instance = wp_parse_args( (array) $instance, array( 'max_members' => 15 ) );
132
+ $max_members = strip_tags( $instance['max_members'] );
133
+ ?>
134
+
135
+ <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 attribute_escape( $max_members ); ?>" style="width: 30%" /></label></p>
136
+ <?php
137
+ }
138
+ }
139
+
140
+ /*** RECENTLY ACTIVE WIDGET *****************/
141
+
142
+ class BP_Core_Recently_Active_Widget extends WP_Widget {
143
+ function bp_core_recently_active_widget() {
144
+ parent::WP_Widget( false, $name = __( 'Recently Active Member Avatars', 'buddypress' ) );
145
+ }
146
+
147
+ function widget($args, $instance) {
148
+ global $bp;
149
+
150
+ extract( $args );
151
+
152
+ echo $before_widget;
153
+ echo $before_title
154
+ . $widget_name
155
+ . $after_title; ?>
156
+
157
+ <?php if ( bp_has_members( 'user_id=0&type=active&per_page=' . $instance['max_members'] . '&max=' . $instance['max_members'] . '&populate_extras=0' ) ) : ?>
158
+ <div class="avatar-block">
159
+ <?php while ( bp_members() ) : bp_the_member(); ?>
160
+ <div class="item-avatar">
161
+ <a href="<?php bp_member_permalink() ?>"><?php bp_member_avatar() ?></a>
162
+ </div>
163
+ <?php endwhile; ?>
164
+ </div>
165
+ <?php else: ?>
166
+
167
+ <div class="widget-error">
168
+ <?php _e( 'There are no recently active members', 'buddypress' ) ?>
169
+ </div>
170
+
171
+ <?php endif; ?>
172
+
173
+ <?php echo $after_widget; ?>
174
+ <?php
175
+ }
176
+
177
+ function update( $new_instance, $old_instance ) {
178
+ $instance = $old_instance;
179
+ $instance['max_members'] = strip_tags( $new_instance['max_members'] );
180
+
181
+ return $instance;
182
+ }
183
+
184
+ function form( $instance ) {
185
+ $instance = wp_parse_args( (array) $instance, array( 'max_members' => 15 ) );
186
+ $max_members = strip_tags( $instance['max_members'] );
187
+ ?>
188
+
189
+ <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 attribute_escape( $max_members ); ?>" style="width: 30%" /></label></p>
190
+ <?php
191
+ }
192
+ }
193
+
194
+ /** Widget AJAX ******************/
195
+
196
+ function bp_core_ajax_widget_members() {
197
+ global $bp;
198
+
199
+ check_ajax_referer( 'bp_core_widget_members' );
200
+
201
+ switch ( $_POST['filter'] ) {
202
+ case 'newest-members':
203
+ $type = 'newest';
204
+ break;
205
+ case 'recently-active-members':
206
+ $type = 'active';
207
+ break;
208
+ case 'popular-members':
209
+ $type = 'popular';
210
+ break;
211
+ }
212
+
213
+ if ( bp_has_members( 'user_id=0&type=' . $type . '&per_page=' . $_POST['max-members'] . '&max=' . $_POST['max-members'] . '&populate_extras=0' ) ) : ?>
214
+ <?php echo '0[[SPLIT]]'; // return valid result. TODO: remove this. ?>
215
+ <div class="avatar-block">
216
+ <?php while ( bp_members() ) : bp_the_member(); ?>
217
+ <li class="vcard">
218
+ <div class="item-avatar">
219
+ <a href="<?php bp_member_permalink() ?>"><?php bp_member_avatar() ?></a>
220
+ </div>
221
+
222
+ <div class="item">
223
+ <div class="item-title fn"><a href="<?php bp_member_permalink() ?>" title="<?php bp_member_name() ?>"><?php bp_member_name() ?></a></div>
224
+ <?php if ( 'active' == $type || 'newest' == $type ) : ?>
225
+ <div class="item-meta"><span class="activity"><?php bp_member_last_active() ?></span></div>
226
+ <?php else : ?>
227
+ <div class="item-meta"><span class="activity"><?php bp_member_total_friend_count() ?></span></div>
228
+ <?php endif; ?>
229
+ </div>
230
+ </li>
231
+
232
+ <?php endwhile; ?>
233
+ </div>
234
+
235
+ <?php else: ?>
236
+ <?php echo "-1[[SPLIT]]<li>"; ?>
237
+ <?php _e( 'There were no members found, please try another filter.', 'buddypress' ) ?>
238
+ <?php echo "</li>"; ?>
239
+ <?php endif;
240
+ }
241
+ add_action( 'wp_ajax_widget_members', 'bp_core_ajax_widget_members' );
242
+
243
  ?>
bp-core/images/admin_menu_icon.png CHANGED
Binary file
bp-core/images/mystery-man-50.jpg ADDED
Binary file
bp-forums.php CHANGED
@@ -1,535 +1,554 @@
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_site_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
- }
82
- }
83
- }
84
-
85
- do_action( 'bp_forums_directory_forums_setup' );
86
-
87
- bp_core_load_template( apply_filters( 'bp_forums_template_directory_forums_setup', 'forums/index' ) );
88
- }
89
- }
90
- add_action( 'wp', 'bp_forums_directory_forums_setup', 2 );
91
-
92
- function bp_forums_add_admin_menu() {
93
- global $bp;
94
-
95
- if ( !is_site_admin() )
96
- return false;
97
-
98
- require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-admin.php' );
99
-
100
- /* Add the administration tab under the "Site Admin" tab for site administrators */
101
- add_submenu_page( 'bp-general-settings', __( 'Forums Setup', 'buddypress' ), __( 'Forums Setup', 'buddypress' ), 'manage_options', 'bb-forums-setup', "bp_forums_bbpress_admin" );
102
- }
103
- add_action( 'admin_menu', 'bp_forums_add_admin_menu' );
104
-
105
- /* Forum Functions */
106
-
107
- function bp_forums_get_forum( $forum_id ) {
108
- do_action( 'bbpress_init' );
109
- return bb_get_forum( $forum_id );
110
- }
111
-
112
- function bp_forums_new_forum( $args = '' ) {
113
- do_action( 'bbpress_init' );
114
-
115
- $defaults = array(
116
- 'forum_name' => '',
117
- 'forum_desc' => '',
118
- 'forum_parent_id' => BP_FORUMS_PARENT_FORUM_ID,
119
- 'forum_order' => false,
120
- 'forum_is_category' => 0
121
- );
122
-
123
- $r = wp_parse_args( $args, $defaults );
124
- extract( $r, EXTR_SKIP );
125
-
126
- 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 ) );
127
- }
128
-
129
- /* Topic Functions */
130
-
131
- function bp_forums_get_forum_topics( $args = '' ) {
132
- global $bp;
133
-
134
- do_action( 'bbpress_init' );
135
-
136
- $defaults = array(
137
- 'type' => 'newest',
138
- 'forum_id' => false,
139
- 'user_id' => false,
140
- 'page' => 1,
141
- 'per_page' => 15,
142
- 'exclude' => false,
143
- 'show_stickies' => 'all',
144
- 'filter' => false // if $type = tag then filter is the tag name, otherwise it's terms to search on.
145
- );
146
-
147
- $r = wp_parse_args( $args, $defaults );
148
- extract( $r, EXTR_SKIP );
149
-
150
- switch ( $type ) {
151
- case 'newest':
152
- $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' );
153
- $topics =& $query->results;
154
- break;
155
-
156
- case 'popular':
157
- $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 ) );
158
- $topics =& $query->results;
159
- break;
160
-
161
- case 'unreplied':
162
- $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 ) );
163
- $topics =& $query->results;
164
- break;
165
-
166
- case 'tags':
167
- $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 ) );
168
- $topics =& $query->results;
169
- break;
170
- }
171
-
172
- return apply_filters( 'bp_forums_get_forum_topics', $topics, &$r );
173
- }
174
-
175
- function bp_forums_get_topic_details( $topic_id ) {
176
- do_action( 'bbpress_init' );
177
-
178
- $query = new BB_Query( 'topic', 'topic_id=' . $topic_id . '&page=1' /* Page override so bbPress doesn't use the URI */ );
179
-
180
- return $query->results[0];
181
- }
182
-
183
- function bp_forums_get_topic_id_from_slug( $topic_slug ) {
184
- do_action( 'bbpress_init' );
185
- return bb_get_id_from_slug( 'topic', $topic_slug );
186
- }
187
-
188
- function bp_forums_new_topic( $args = '' ) {
189
- global $bp;
190
-
191
- do_action( 'bbpress_init' );
192
-
193
- $defaults = array(
194
- 'topic_title' => '',
195
- 'topic_slug' => '',
196
- 'topic_text' => '',
197
- 'topic_poster' => $bp->loggedin_user->id, // accepts ids
198
- 'topic_poster_name' => $bp->loggedin_user->fullname, // accept names
199
- 'topic_last_poster' => $bp->loggedin_user->id, // accepts ids
200
- 'topic_last_poster_name' => $bp->loggedin_user->fullname, // accept names
201
- 'topic_start_time' => date( 'Y-m-d H:i:s' ),
202
- 'topic_time' => date( 'Y-m-d H:i:s' ),
203
- 'topic_open' => 1,
204
- 'topic_tags' => false, // accepts array or comma delim
205
- 'forum_id' => 0 // accepts ids or slugs
206
- );
207
-
208
- $r = wp_parse_args( $args, $defaults );
209
- extract( $r, EXTR_SKIP );
210
-
211
- $topic_title = strip_tags( $topic_title );
212
-
213
- if ( empty( $topic_title ) || !strlen( trim( $topic_title ) ) )
214
- return false;
215
-
216
- if ( empty( $topic_slug ) )
217
- $topic_slug = sanitize_title( $topic_title );
218
-
219
- 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 ) ) )
220
- return false;
221
-
222
- /* Now insert the first post. */
223
- if ( !bp_forums_insert_post( array( 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $topic_time, 'poster_id' => $topic_poster ) ) )
224
- return false;
225
-
226
- do_action( 'bp_forums_new_topic', $topic_id );
227
-
228
- return $topic_id;
229
- }
230
-
231
- function bp_forums_update_topic( $args = '' ) {
232
- global $bp;
233
-
234
- do_action( 'bbpress_init' );
235
-
236
- $defaults = array(
237
- 'topic_id' => false,
238
- 'topic_title' => '',
239
- 'topic_text' => ''
240
- );
241
-
242
- $r = wp_parse_args( $args, $defaults );
243
- extract( $r, EXTR_SKIP );
244
-
245
- if ( !$topic_id = bb_insert_topic( array( 'topic_id' => $topic_id, 'topic_title' => stripslashes( $topic_title ) ) ) )
246
- return false;
247
-
248
- if ( !$post = bb_get_first_post( $topic_id ) )
249
- return false;
250
-
251
- /* Update the first post */
252
- 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 ) ) )
253
- return false;
254
-
255
- return bp_forums_get_topic_details( $topic_id );
256
- }
257
-
258
- function bp_forums_sticky_topic( $args = '' ) {
259
- global $bp;
260
-
261
- do_action( 'bbpress_init' );
262
-
263
- $defaults = array(
264
- 'topic_id' => false,
265
- 'mode' => 'stick' // stick/unstick
266
- );
267
-
268
- $r = wp_parse_args( $args, $defaults );
269
- extract( $r, EXTR_SKIP );
270
-
271
- if ( 'stick' == $mode )
272
- return bb_stick_topic( $topic_id );
273
- else if ( 'unstick' == $mode )
274
- return bb_unstick_topic( $topic_id );
275
-
276
- return false;
277
- }
278
-
279
- function bp_forums_openclose_topic( $args = '' ) {
280
- global $bp;
281
-
282
- do_action( 'bbpress_init' );
283
-
284
- $defaults = array(
285
- 'topic_id' => false,
286
- 'mode' => 'close' // stick/unstick
287
- );
288
-
289
- $r = wp_parse_args( $args, $defaults );
290
- extract( $r, EXTR_SKIP );
291
-
292
- if ( 'close' == $mode )
293
- return bb_close_topic( $topic_id );
294
- else if ( 'open' == $mode )
295
- return bb_open_topic( $topic_id );
296
-
297
- return false;
298
- }
299
-
300
- function bp_forums_delete_topic( $args = '' ) {
301
- global $bp;
302
-
303
- do_action( 'bbpress_init' );
304
-
305
- $defaults = array(
306
- 'topic_id' => false
307
- );
308
-
309
- $r = wp_parse_args( $args, $defaults );
310
- extract( $r, EXTR_SKIP );
311
-
312
- return bb_delete_topic( $topic_id, 1 );
313
- }
314
-
315
- function bp_forums_total_topic_count() {
316
- do_action( 'bbpress_init' );
317
-
318
- $query = new BB_Query( 'topic', array( 'page' => 1, 'per_page' => -1, 'count' => true ) );
319
- $count = $query->count;
320
- $query = null;
321
-
322
- return $count;
323
- }
324
-
325
- function bp_forums_total_topic_count_for_user( $user_id = false ) {
326
- global $bp;
327
-
328
- do_action( 'bbpress_init' );
329
-
330
- if ( !$user_id )
331
- $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
332
-
333
- $query = new BB_Query( 'topic', array( 'topic_author_id' => $user_id, 'page' => 1, 'per_page' => -1, 'count' => true ) );
334
- $count = $query->count;
335
- $query = null;
336
-
337
- return $count;
338
- }
339
-
340
- function bp_forums_get_topic_extras( $topics ) {
341
- global $bp, $wpdb, $bbdb;
342
-
343
- if ( empty( $topics ) )
344
- return $topics;
345
-
346
- /* Get the topic ids */
347
- foreach ( (array)$topics as $topic ) $topic_ids[] = $topic->topic_id;
348
- $topic_ids = $wpdb->escape( join( ',', (array)$topic_ids ) );
349
-
350
- /* Fetch the topic's last poster details */
351
- $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} )" ) );
352
- for ( $i = 0; $i < count( $topics ); $i++ ) {
353
- foreach ( (array)$poster_details as $poster ) {
354
- if ( $poster->topic_id == $topics[$i]->topic_id ) {
355
- $topics[$i]->topic_last_poster_email = $poster->user_email;
356
- $topics[$i]->topic_last_poster_nicename = $poster->user_nicename;
357
- $topics[$i]->topic_last_poster_login = $poster->user_login;
358
- $topics[$i]->topic_last_poster_displayname = $poster->display_name;
359
- }
360
- }
361
- }
362
-
363
- /* Fetch fullname for the topic's last poster */
364
- if ( function_exists( 'xprofile_install' ) ) {
365
- $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} )" ) );
366
- for ( $i = 0; $i < count( $topics ); $i++ ) {
367
- foreach ( (array)$poster_names as $name ) {
368
- if ( $name->topic_id == $topics[$i]->topic_id )
369
- $topics[$i]->topic_last_poster_displayname = $name->value;
370
- }
371
- }
372
- }
373
-
374
- return $topics;
375
- }
376
-
377
- /* Post Functions */
378
-
379
- function bp_forums_get_topic_posts( $args = '' ) {
380
- do_action( 'bbpress_init' );
381
-
382
- $defaults = array(
383
- 'topic_id' => false,
384
- 'page' => 1,
385
- 'per_page' => 15,
386
- 'order' => 'ASC'
387
- );
388
-
389
- $args = wp_parse_args( $args, $defaults );
390
-
391
- $query = new BB_Query( 'post', $args, 'get_thread' );
392
- return bp_forums_get_post_extras( $query->results );
393
- }
394
-
395
- function bp_forums_get_post( $post_id ) {
396
- do_action( 'bbpress_init' );
397
- return bb_get_post( $post_id );
398
- }
399
-
400
- function bp_forums_delete_post( $args = '' ) {
401
- global $bp;
402
-
403
- do_action( 'bbpress_init' );
404
-
405
- $defaults = array(
406
- 'post_id' => false
407
- );
408
-
409
- $r = wp_parse_args( $args, $defaults );
410
- extract( $r, EXTR_SKIP );
411
-
412
- return bb_delete_post( $post_id, 1 );
413
- }
414
-
415
- function bp_forums_insert_post( $args = '' ) {
416
- global $bp;
417
-
418
- do_action( 'bbpress_init' );
419
-
420
- $defaults = array(
421
- 'post_id' => false,
422
- 'topic_id' => false,
423
- 'post_text' => '',
424
- 'post_time' => date( 'Y-m-d H:i:s' ),
425
- 'poster_id' => $bp->loggedin_user->id, // accepts ids or names
426
- 'poster_ip' => $_SERVER['REMOTE_ADDR'],
427
- 'post_status' => 0, // use bb_delete_post() instead
428
- 'post_position' => false
429
- );
430
-
431
- $r = wp_parse_args( $args, $defaults );
432
- extract( $r, EXTR_SKIP );
433
-
434
- if ( !$post = bp_forums_get_post( $post_id ) )
435
- $post_id = false;
436
-
437
- if ( !isset( $topic_id ) )
438
- $topic_id = $post->topic_id;
439
-
440
- if ( empty( $post_text ) )
441
- $post_text = $post->post_text;
442
-
443
- if ( !isset( $post_time ) )
444
- $post_time = $post->post_time;
445
-
446
- if ( !isset( $post_position ) )
447
- $post_position = $post->post_position;
448
-
449
- $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 ) );
450
-
451
- if ( $post_id )
452
- do_action( 'bp_forums_new_post', $post_id );
453
-
454
- return $post_id;
455
- }
456
-
457
- function bp_forums_get_post_extras( $posts ) {
458
- global $bp, $wpdb;
459
-
460
- if ( empty( $posts ) )
461
- return $posts;
462
-
463
- /* Get the user ids */
464
- foreach ( (array)$posts as $post ) $user_ids[] = $post->poster_id;
465
- $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
466
-
467
- /* Fetch the poster's user_email, user_nicename and user_login */
468
- $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} )" ) );
469
-
470
- for ( $i = 0; $i < count( $posts ); $i++ ) {
471
- foreach ( (array)$poster_details as $poster ) {
472
- if ( $poster->user_id == $posts[$i]->poster_id ) {
473
- $posts[$i]->poster_email = $poster->user_email;
474
- $posts[$i]->poster_login = $poster->user_nicename;
475
- $posts[$i]->poster_nicename = $poster->user_login;
476
- $posts[$i]->poster_name = $poster->display_name;
477
- }
478
- }
479
- }
480
-
481
- /* Fetch fullname for each poster. */
482
- if ( function_exists( 'xprofile_install' ) ) {
483
- $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} )" ) );
484
- for ( $i = 0; $i < count( $posts ); $i++ ) {
485
- foreach ( (array)$poster_names as $name ) {
486
- if ( $name->user_id == $topics[$i]->user_id )
487
- $posts[$i]->poster_name = $poster->value;
488
- }
489
- }
490
- }
491
-
492
- return $posts;
493
- }
494
-
495
-
496
- function bp_forums_get_forum_topicpost_count( $forum_id ) {
497
- global $wpdb, $bbdb;
498
-
499
- do_action( 'bbpress_init' );
500
-
501
- /* Need to find a bbPress function that does this */
502
- return $wpdb->get_results( $wpdb->prepare( "SELECT topics, posts from {$bbdb->forums} WHERE forum_id = %d", $forum_id ) );
503
- }
504
-
505
-
506
- function bp_forums_filter_caps( $allcaps ) {
507
- global $bp, $wp_roles, $bb_table_prefix;
508
-
509
- $bb_cap = get_usermeta( $bp->loggedin_user->id, $bb_table_prefix . 'capabilities' );
510
-
511
- if ( empty( $bb_cap ) )
512
- return $allcaps;
513
-
514
- $bb_cap = array_keys($bb_cap);
515
- $bb_cap = $wp_roles->get_role( $bb_cap[0] );
516
- $bb_cap = $bb_cap->capabilities;
517
-
518
- return array_merge( (array) $allcaps, (array) $bb_cap );
519
- }
520
- add_filter( 'user_has_cap', 'bp_forums_filter_caps' );
521
-
522
-
523
- /********************************************************************************
524
- * Caching
525
- *
526
- * Caching functions handle the clearing of cached objects and pages on specific
527
- * actions throughout BuddyPress.
528
- */
529
-
530
- // List actions to clear super cached pages on, if super cache is installed
531
- add_action( 'bp_forums_new_forum', 'bp_core_clear_cache' );
532
- add_action( 'bp_forums_new_topic', 'bp_core_clear_cache' );
533
- add_action( 'bp_forums_new_post', 'bp_core_clear_cache' );
534
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
535
  ?>
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_site_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
+ }
82
+ }
83
+ }
84
+
85
+ do_action( 'bp_forums_directory_forums_setup' );
86
+
87
+ bp_core_load_template( apply_filters( 'bp_forums_template_directory_forums_setup', 'forums/index' ) );
88
+ }
89
+ }
90
+ add_action( 'wp', 'bp_forums_directory_forums_setup', 2 );
91
+
92
+ function bp_forums_add_admin_menu() {
93
+ global $bp;
94
+
95
+ if ( !is_site_admin() )
96
+ return false;
97
+
98
+ require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-admin.php' );
99
+
100
+ /* Add the administration tab under the "Site Admin" tab for site administrators */
101
+ add_submenu_page( 'bp-general-settings', __( 'Forums Setup', 'buddypress' ), __( 'Forums Setup', 'buddypress' ), 'manage_options', 'bb-forums-setup', "bp_forums_bbpress_admin" );
102
+ }
103
+ add_action( 'admin_menu', 'bp_forums_add_admin_menu' );
104
+
105
+ /* Forum Functions */
106
+
107
+ function bp_forums_get_forum( $forum_id ) {
108
+ do_action( 'bbpress_init' );
109
+ return bb_get_forum( $forum_id );
110
+ }
111
+
112
+ function bp_forums_new_forum( $args = '' ) {
113
+ do_action( 'bbpress_init' );
114
+
115
+ $defaults = array(
116
+ 'forum_name' => '',
117
+ 'forum_desc' => '',
118
+ 'forum_parent_id' => BP_FORUMS_PARENT_FORUM_ID,
119
+ 'forum_order' => false,
120
+ 'forum_is_category' => 0
121
+ );
122
+
123
+ $r = wp_parse_args( $args, $defaults );
124
+ extract( $r, EXTR_SKIP );
125
+
126
+ 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 ) );
127
+ }
128
+
129
+ function bp_forums_update_forum( $args = '' ) {
130
+ do_action( 'bbpress_init' );
131
+
132
+ $defaults = array(
133
+ 'forum_id' => '',
134
+ 'forum_name' => '',
135
+ 'forum_desc' => '',
136
+ 'forum_slug' => '',
137
+ 'forum_parent_id' => BP_FORUMS_PARENT_FORUM_ID,
138
+ 'forum_order' => false,
139
+ 'forum_is_category' => 0
140
+ );
141
+
142
+ $r = wp_parse_args( $args, $defaults );
143
+ extract( $r, EXTR_SKIP );
144
+
145
+ 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 ) );
146
+ }
147
+
148
+ /* Topic Functions */
149
+
150
+ function bp_forums_get_forum_topics( $args = '' ) {
151
+ global $bp;
152
+
153
+ do_action( 'bbpress_init' );
154
+
155
+ $defaults = array(
156
+ 'type' => 'newest',
157
+ 'forum_id' => false,
158
+ 'user_id' => false,
159
+ 'page' => 1,
160
+ 'per_page' => 15,
161
+ 'exclude' => false,
162
+ 'show_stickies' => 'all',
163
+ 'filter' => false // if $type = tag then filter is the tag name, otherwise it's terms to search on.
164
+ );
165
+
166
+ $r = wp_parse_args( $args, $defaults );
167
+ extract( $r, EXTR_SKIP );
168
+
169
+ switch ( $type ) {
170
+ case 'newest':
171
+ $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' );
172
+ $topics =& $query->results;
173
+ break;
174
+
175
+ case 'popular':
176
+ $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 ) );
177
+ $topics =& $query->results;
178
+ break;
179
+
180
+ case 'unreplied':
181
+ $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 ) );
182
+ $topics =& $query->results;
183
+ break;
184
+
185
+ case 'tags':
186
+ $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 ) );
187
+ $topics =& $query->results;
188
+ break;
189
+ }
190
+
191
+ return apply_filters( 'bp_forums_get_forum_topics', $topics, &$r );
192
+ }
193
+
194
+ function bp_forums_get_topic_details( $topic_id ) {
195
+ do_action( 'bbpress_init' );
196
+
197
+ $query = new BB_Query( 'topic', 'topic_id=' . $topic_id . '&page=1' /* Page override so bbPress doesn't use the URI */ );
198
+
199
+ return $query->results[0];
200
+ }
201
+
202
+ function bp_forums_get_topic_id_from_slug( $topic_slug ) {
203
+ do_action( 'bbpress_init' );
204
+ return bb_get_id_from_slug( 'topic', $topic_slug );
205
+ }
206
+
207
+ function bp_forums_new_topic( $args = '' ) {
208
+ global $bp;
209
+
210
+ do_action( 'bbpress_init' );
211
+
212
+ $defaults = array(
213
+ 'topic_title' => '',
214
+ 'topic_slug' => '',
215
+ 'topic_text' => '',
216
+ 'topic_poster' => $bp->loggedin_user->id, // accepts ids
217
+ 'topic_poster_name' => $bp->loggedin_user->fullname, // accept names
218
+ 'topic_last_poster' => $bp->loggedin_user->id, // accepts ids
219
+ 'topic_last_poster_name' => $bp->loggedin_user->fullname, // accept names
220
+ 'topic_start_time' => date( 'Y-m-d H:i:s' ),
221
+ 'topic_time' => date( 'Y-m-d H:i:s' ),
222
+ 'topic_open' => 1,
223
+ 'topic_tags' => false, // accepts array or comma delim
224
+ 'forum_id' => 0 // accepts ids or slugs
225
+ );
226
+
227
+ $r = wp_parse_args( $args, $defaults );
228
+ extract( $r, EXTR_SKIP );
229
+
230
+ $topic_title = strip_tags( $topic_title );
231
+
232
+ if ( empty( $topic_title ) || !strlen( trim( $topic_title ) ) )
233
+ return false;
234
+
235
+ if ( empty( $topic_slug ) )
236
+ $topic_slug = sanitize_title( $topic_title );
237
+
238
+ 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 ) ) )
239
+ return false;
240
+
241
+ /* Now insert the first post. */
242
+ if ( !bp_forums_insert_post( array( 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $topic_time, 'poster_id' => $topic_poster ) ) )
243
+ return false;
244
+
245
+ do_action( 'bp_forums_new_topic', $topic_id );
246
+
247
+ return $topic_id;
248
+ }
249
+
250
+ function bp_forums_update_topic( $args = '' ) {
251
+ global $bp;
252
+
253
+ do_action( 'bbpress_init' );
254
+
255
+ $defaults = array(
256
+ 'topic_id' => false,
257
+ 'topic_title' => '',
258
+ 'topic_text' => ''
259
+ );
260
+
261
+ $r = wp_parse_args( $args, $defaults );
262
+ extract( $r, EXTR_SKIP );
263
+
264
+ if ( !$topic_id = bb_insert_topic( array( 'topic_id' => $topic_id, 'topic_title' => stripslashes( $topic_title ) ) ) )
265
+ return false;
266
+
267
+ if ( !$post = bb_get_first_post( $topic_id ) )
268
+ return false;
269
+
270
+ /* Update the first post */
271
+ 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 ) ) )
272
+ return false;
273
+
274
+ return bp_forums_get_topic_details( $topic_id );
275
+ }
276
+
277
+ function bp_forums_sticky_topic( $args = '' ) {
278
+ global $bp;
279
+
280
+ do_action( 'bbpress_init' );
281
+
282
+ $defaults = array(
283
+ 'topic_id' => false,
284
+ 'mode' => 'stick' // stick/unstick
285
+ );
286
+
287
+ $r = wp_parse_args( $args, $defaults );
288
+ extract( $r, EXTR_SKIP );
289
+
290
+ if ( 'stick' == $mode )
291
+ return bb_stick_topic( $topic_id );
292
+ else if ( 'unstick' == $mode )
293
+ return bb_unstick_topic( $topic_id );
294
+
295
+ return false;
296
+ }
297
+
298
+ function bp_forums_openclose_topic( $args = '' ) {
299
+ global $bp;
300
+
301
+ do_action( 'bbpress_init' );
302
+
303
+ $defaults = array(
304
+ 'topic_id' => false,
305
+ 'mode' => 'close' // stick/unstick
306
+ );
307
+
308
+ $r = wp_parse_args( $args, $defaults );
309
+ extract( $r, EXTR_SKIP );
310
+
311
+ if ( 'close' == $mode )
312
+ return bb_close_topic( $topic_id );
313
+ else if ( 'open' == $mode )
314
+ return bb_open_topic( $topic_id );
315
+
316
+ return false;
317
+ }
318
+
319
+ function bp_forums_delete_topic( $args = '' ) {
320
+ global $bp;
321
+
322
+ do_action( 'bbpress_init' );
323
+
324
+ $defaults = array(
325
+ 'topic_id' => false
326
+ );
327
+
328
+ $r = wp_parse_args( $args, $defaults );
329
+ extract( $r, EXTR_SKIP );
330
+
331
+ return bb_delete_topic( $topic_id, 1 );
332
+ }
333
+
334
+ function bp_forums_total_topic_count() {
335
+ do_action( 'bbpress_init' );
336
+
337
+ $query = new BB_Query( 'topic', array( 'page' => 1, 'per_page' => -1, 'count' => true ) );
338
+ $count = $query->count;
339
+ $query = null;
340
+
341
+ return $count;
342
+ }
343
+
344
+ function bp_forums_total_topic_count_for_user( $user_id = false ) {
345
+ global $bp;
346
+
347
+ do_action( 'bbpress_init' );
348
+
349
+ if ( !$user_id )
350
+ $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
351
+
352
+ $query = new BB_Query( 'topic', array( 'topic_author_id' => $user_id, 'page' => 1, 'per_page' => -1, 'count' => true ) );
353
+ $count = $query->count;
354
+ $query = null;
355
+
356
+ return $count;
357
+ }
358
+
359
+ function bp_forums_get_topic_extras( $topics ) {
360
+ global $bp, $wpdb, $bbdb;
361
+
362
+ if ( empty( $topics ) )
363
+ return $topics;
364
+
365
+ /* Get the topic ids */
366
+ foreach ( (array)$topics as $topic ) $topic_ids[] = $topic->topic_id;
367
+ $topic_ids = $wpdb->escape( join( ',', (array)$topic_ids ) );
368
+
369
+ /* Fetch the topic's last poster details */
370
+ $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} )" ) );
371
+ for ( $i = 0; $i < count( $topics ); $i++ ) {
372
+ foreach ( (array)$poster_details as $poster ) {
373
+ if ( $poster->topic_id == $topics[$i]->topic_id ) {
374
+ $topics[$i]->topic_last_poster_email = $poster->user_email;
375
+ $topics[$i]->topic_last_poster_nicename = $poster->user_nicename;
376
+ $topics[$i]->topic_last_poster_login = $poster->user_login;
377
+ $topics[$i]->topic_last_poster_displayname = $poster->display_name;
378
+ }
379
+ }
380
+ }
381
+
382
+ /* Fetch fullname for the topic's last poster */
383
+ if ( function_exists( 'xprofile_install' ) ) {
384
+ $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} )" ) );
385
+ for ( $i = 0; $i < count( $topics ); $i++ ) {
386
+ foreach ( (array)$poster_names as $name ) {
387
+ if ( $name->topic_id == $topics[$i]->topic_id )
388
+ $topics[$i]->topic_last_poster_displayname = $name->value;
389
+ }
390
+ }
391
+ }
392
+
393
+ return $topics;
394
+ }
395
+
396
+ /* Post Functions */
397
+
398
+ function bp_forums_get_topic_posts( $args = '' ) {
399
+ do_action( 'bbpress_init' );
400
+
401
+ $defaults = array(
402
+ 'topic_id' => false,
403
+ 'page' => 1,
404
+ 'per_page' => 15,
405
+ 'order' => 'ASC'
406
+ );
407
+
408
+ $args = wp_parse_args( $args, $defaults );
409
+
410
+ $query = new BB_Query( 'post', $args, 'get_thread' );
411
+ return bp_forums_get_post_extras( $query->results );
412
+ }
413
+
414
+ function bp_forums_get_post( $post_id ) {
415
+ do_action( 'bbpress_init' );
416
+ return bb_get_post( $post_id );
417
+ }
418
+
419
+ function bp_forums_delete_post( $args = '' ) {
420
+ global $bp;
421
+
422
+ do_action( 'bbpress_init' );
423
+
424
+ $defaults = array(
425
+ 'post_id' => false
426
+ );
427
+
428
+ $r = wp_parse_args( $args, $defaults );
429
+ extract( $r, EXTR_SKIP );
430
+
431
+ return bb_delete_post( $post_id, 1 );
432
+ }
433
+
434
+ function bp_forums_insert_post( $args = '' ) {
435
+ global $bp;
436
+
437
+ do_action( 'bbpress_init' );
438
+
439
+ $defaults = array(
440
+ 'post_id' => false,
441
+ 'topic_id' => false,
442
+ 'post_text' => '',
443
+ 'post_time' => date( 'Y-m-d H:i:s' ),
444
+ 'poster_id' => $bp->loggedin_user->id, // accepts ids or names
445
+ 'poster_ip' => $_SERVER['REMOTE_ADDR'],
446
+ 'post_status' => 0, // use bb_delete_post() instead
447
+ 'post_position' => false
448
+ );
449
+
450
+ $r = wp_parse_args( $args, $defaults );
451
+ extract( $r, EXTR_SKIP );
452
+
453
+ if ( !$post = bp_forums_get_post( $post_id ) )
454
+ $post_id = false;
455
+
456
+ if ( !isset( $topic_id ) )
457
+ $topic_id = $post->topic_id;
458
+
459
+ if ( empty( $post_text ) )
460
+ $post_text = $post->post_text;
461
+
462
+ if ( !isset( $post_time ) )
463
+ $post_time = $post->post_time;
464
+
465
+ if ( !isset( $post_position ) )
466
+ $post_position = $post->post_position;
467
+
468
+ $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 ) );
469
+
470
+ if ( $post_id )
471
+ do_action( 'bp_forums_new_post', $post_id );
472
+
473
+ return $post_id;
474
+ }
475
+
476
+ function bp_forums_get_post_extras( $posts ) {
477
+ global $bp, $wpdb;
478
+
479
+ if ( empty( $posts ) )
480
+ return $posts;
481
+
482
+ /* Get the user ids */
483
+ foreach ( (array)$posts as $post ) $user_ids[] = $post->poster_id;
484
+ $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
485
+
486
+ /* Fetch the poster's user_email, user_nicename and user_login */
487
+ $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} )" ) );
488
+
489
+ for ( $i = 0; $i < count( $posts ); $i++ ) {
490
+ foreach ( (array)$poster_details as $poster ) {
491
+ if ( $poster->user_id == $posts[$i]->poster_id ) {
492
+ $posts[$i]->poster_email = $poster->user_email;
493
+ $posts[$i]->poster_login = $poster->user_nicename;
494
+ $posts[$i]->poster_nicename = $poster->user_login;
495
+ $posts[$i]->poster_name = $poster->display_name;
496
+ }
497
+ }
498
+ }
499
+
500
+ /* Fetch fullname for each poster. */
501
+ if ( function_exists( 'xprofile_install' ) ) {
502
+ $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} )" ) );
503
+ for ( $i = 0; $i < count( $posts ); $i++ ) {
504
+ foreach ( (array)$poster_names as $name ) {
505
+ if ( $name->user_id == $topics[$i]->user_id )
506
+ $posts[$i]->poster_name = $poster->value;
507
+ }
508
+ }
509
+ }
510
+
511
+ return $posts;
512
+ }
513
+
514
+
515
+ function bp_forums_get_forum_topicpost_count( $forum_id ) {
516
+ global $wpdb, $bbdb;
517
+
518
+ do_action( 'bbpress_init' );
519
+
520
+ /* Need to find a bbPress function that does this */
521
+ return $wpdb->get_results( $wpdb->prepare( "SELECT topics, posts from {$bbdb->forums} WHERE forum_id = %d", $forum_id ) );
522
+ }
523
+
524
+
525
+ function bp_forums_filter_caps( $allcaps ) {
526
+ global $bp, $wp_roles, $bb_table_prefix;
527
+
528
+ $bb_cap = get_usermeta( $bp->loggedin_user->id, $bb_table_prefix . 'capabilities' );
529
+
530
+ if ( empty( $bb_cap ) )
531
+ return $allcaps;
532
+
533
+ $bb_cap = array_keys($bb_cap);
534
+ $bb_cap = $wp_roles->get_role( $bb_cap[0] );
535
+ $bb_cap = $bb_cap->capabilities;
536
+
537
+ return array_merge( (array) $allcaps, (array) $bb_cap );
538
+ }
539
+ add_filter( 'user_has_cap', 'bp_forums_filter_caps' );
540
+
541
+
542
+ /********************************************************************************
543
+ * Caching
544
+ *
545
+ * Caching functions handle the clearing of cached objects and pages on specific
546
+ * actions throughout BuddyPress.
547
+ */
548
+
549
+ // List actions to clear super cached pages on, if super cache is installed
550
+ add_action( 'bp_forums_new_forum', 'bp_core_clear_cache' );
551
+ add_action( 'bp_forums_new_topic', 'bp_core_clear_cache' );
552
+ add_action( 'bp_forums_new_post', 'bp_core_clear_cache' );
553
+
554
  ?>
bp-forums/bb-config.php CHANGED
@@ -1,11 +1,11 @@
1
- <?php
2
- /***
3
- * *** IMPORTANT ****
4
- * This file will stop people from accessing your bbPress installation directly.
5
- * It is very important from a security standpoint that this file is not moved.
6
- * Your actual bb-config.php file will be installed in the root of your WordPress
7
- * installation once you have set up the forums component in BuddyPress.
8
- */
9
-
10
- header("HTTP/1.0 403 Forbidden"); die;
11
  ?>
1
+ <?php
2
+ /***
3
+ * *** IMPORTANT ****
4
+ * This file will stop people from accessing your bbPress installation directly.
5
+ * It is very important from a security standpoint that this file is not moved.
6
+ * Your actual bb-config.php file will be installed in the root of your WordPress
7
+ * installation once you have set up the forums component in BuddyPress.
8
+ */
9
+
10
+ header("HTTP/1.0 403 Forbidden"); die;
11
  ?>
bp-forums/bp-forums-admin.php CHANGED
@@ -1,258 +1,258 @@
1
- <?php
2
-
3
- function bp_forums_bbpress_admin() {
4
- global $bp;
5
- ?>
6
- <div class="wrap">
7
-
8
- <h2><?php _e( 'Forums Setup', 'buddypress' ) ?></h2>
9
-
10
- <?php if ( isset( $_POST['submit'] ) ) : ?>
11
- <div id="message" class="updated fade">
12
- <p><?php _e( 'Settings Saved.', 'buddypress' ) ?></p>
13
- </div>
14
- <?php endif; ?>
15
-
16
- <?php
17
-
18
- if ( isset( $_REQUEST['reinstall'] ) || !bp_forums_is_installed_correctly() ) {
19
- update_site_option( 'bb-config-location', false );
20
- bp_forums_bbpress_install_wizard();
21
- } else { ?>
22
- <p><?php printf( __( 'bbPress forum integration in BuddyPress has been set up correctly. If you are having problems you can <a href="%s" title="Reinstall bbPress">re-install</a>', 'buddypress' ), site_url( 'wp-admin/admin.php?page=bb-forums-setup&reinstall=1' ) ); ?>
23
- <p><?php _e( 'NOTE: The forums directory will only work if your bbPress tables are in the same database as your WordPress tables. If you are not using an existing bbPress install you can ignore this message.', 'buddypress' ) ?></p>
24
- <?php
25
- }
26
- ?>
27
- </div>
28
- <?php
29
- }
30
-
31
- function bp_forums_bbpress_install_wizard() {
32
- $post_url = site_url( 'wp-admin/admin.php?page=bb-forums-setup' );
33
-
34
- switch( $_REQUEST['step'] ) {
35
- case 'existing':
36
- if ( 1 == (int)$_REQUEST['doinstall'] ) {
37
- if ( !bp_forums_configure_existing_install() ) {
38
- _e( 'The bb-config.php file was not found at that location, please try again.', 'buddypress' );
39
- } else {
40
- ?>
41
- <h3><?php _e( 'Forums were set up correctly using your existing bbPress install!', 'buddypress' ) ?></h3>
42
- <p><?php _e( 'BuddyPress will now use its internal copy of bbPress to run the forums on your site. If you wish, you can remove your old bbPress installation files, as long as you keep the bb-config.php file in the same location.', 'buddypress' ) ?></p><?php
43
- }
44
- } else {
45
- ?>
46
- <form action="" method="post">
47
- <h3><?php _e( 'Existing bbPress Installation', 'buddypress' ) ?></h3>
48
- <p><?php _e( "BuddyPress can make use of your existing bbPress install. Just provide the location of your <code>bb-config.php</code> file, and BuddyPress will do the rest.", 'buddypress' ) ?></p>
49
- <p><label><code>bb-config.php</code> file location:</label><br /><input style="width: 50%" type="text" name="bbconfigloc" id="bbconfigloc" value="<?php echo str_replace( 'buddypress', '', $_SERVER['DOCUMENT_ROOT'] ) ?>" /></p>
50
- <p><input type="submit" class="button-primary" value="<?php _e( 'Complete Installation', 'buddypress' ) ?>" /></p>
51
- <input type="hidden" name="step" value="existing" />
52
- <input type="hidden" name="doinstall" value="1" />
53
- <?php wp_nonce_field( 'bp_forums_existing_install_init' ) ?>
54
- </form>
55
- <?php
56
- }
57
- break;
58
-
59
- case 'new':
60
- if ( 1 == (int)$_REQUEST['doinstall'] ) {
61
- $result = bp_forums_bbpress_install();
62
-
63
- switch ( $result ) {
64
- case 1:
65
- _e( 'All done! Configuration settings have been saved to the file <code>bb-config.php</code> in the root of your WordPress install.', 'buddypress' );
66
- break;
67
- default:
68
- // Just write the contents to screen
69
- _e( 'A configuration file could not be created. No problem, but you will need to save the text shown below into a file named <code>bb-config.php</code> in the root directory of your WordPress installation before you can start using the forum functionality.', 'buddypress' );
70
- ?><code style="display:block; margin-top: 30px;"><pre><?php echo htmlspecialchars( $result ) ?></pre></code><?php
71
- break;
72
- }
73
- } else {
74
- ?>
75
- <h3><?php _e( 'New bbPress Installation', 'buddypress' ) ?></h3>
76
- <p><?php _e( "You've decided to set up a new installation of bbPress for forum management in BuddyPress. This is very simple and is usually just a one click
77
- process. When you're ready, hit the link below.", 'buddypress' ) ?></p>
78
- <p><a class="button-primary" href="<?php echo wp_nonce_url( $post_url . '&step=new&doinstall=1', 'bp_forums_new_install_init' ) ?>"><?php _e( 'Complete Installation', 'buddypress' ) ?></a></p>
79
- <?php
80
- }
81
- break;
82
-
83
- default:
84
- if ( !file_exists( BP_PLUGIN_DIR . '/bp-forums/bbpress/' ) ) { ?>
85
- <div id="message" class="error">
86
- <p><?php printf( __( 'bbPress files were not found. To install the forums component you must download a copy of bbPress and make sure it is in the folder: "%s"', 'buddypress' ), 'wp-content/plugins/buddypress/bp-forums/bbpress/' ) ?></p>
87
- </div>
88
- <?php } else { ?>
89
-
90
- <p><?php _e( 'Forums in BuddyPress make use of a bbPress installation to function. You can choose to either let BuddyPress set up a new bbPress install, or use an already existing bbPress install. Please choose one of the options below.', 'buddypress' ) ?></p>
91
-
92
- <a class="button" href="<?php echo $post_url . '&step=new' ?>"><?php _e( 'Set up a new bbPress installation', 'buddypress' ) ?></a> &nbsp;
93
- <a class="button" href="<?php echo $post_url . '&step=existing' ?>"><?php _e( 'Use an existing bbPress installation', 'buddypress' ) ?></a>
94
-
95
- <?php }
96
- break;
97
- }
98
- }
99
-
100
- function bp_forums_configure_existing_install() {
101
- global $wpdb, $bbdb;
102
-
103
- check_admin_referer( 'bp_forums_existing_install_init' );
104
-
105
- /* Sanitize $_REQUEST['bbconfigloc'] */
106
- $_REQUEST['bbconfigloc'] = apply_filters( 'bp_forums_bbconfig_location', $_REQUEST['bbconfigloc'] );
107
-
108
- if ( false === strpos( $_REQUEST['bbconfigloc'], 'bb-config.php' ) ) {
109
- if ( '/' != substr( $_REQUEST['bbconfigloc'], -1, 1 ) )
110
- $_REQUEST['bbconfigloc'] .= '/';
111
-
112
- $_REQUEST['bbconfigloc'] .= 'bb-config.php';
113
- }
114
-
115
- if ( !file_exists( $_REQUEST['bbconfigloc'] ) )
116
- return false;
117
-
118
- update_site_option( 'bb-config-location', $_REQUEST['bbconfigloc'] );
119
-
120
- return true;
121
- }
122
-
123
- function bp_forums_bbpress_install() {
124
- global $wpdb, $bbdb;
125
-
126
- check_admin_referer( 'bp_forums_new_install_init' );
127
-
128
- /* Create the bb-config.php file */
129
- $initial_write = bp_forums_bbpress_write(
130
- BP_PLUGIN_DIR . '/bp-forums/bbpress/bb-config-sample.php',
131
- ABSPATH . 'bb-config.php',
132
- array(
133
- "define( 'BBDB_NAME'," => array( "'bbpress'", "'" . DB_NAME . "'" ),
134
- "define( 'BBDB_USER'," => array( "'username'", "'" . DB_USER . "'" ),
135
- "define( 'BBDB_PASSWO" => array( "'password'", "'" . DB_PASSWORD . "'" ),
136
- "define( 'BBDB_HOST'," => array( "'localhost'", "'" . DB_HOST . "'" ),
137
- "define( 'BBDB_CHARSE" => array( "'utf8'", "'" . DB_CHARSET . "'" ),
138
- "define( 'BBDB_COLLAT" => array( "''", "'" . DB_COLLATE . "'" ),
139
- "define( 'BB_AUTH_KEY" => array( "'put your unique phrase here'", "'" . addslashes( AUTH_KEY ) . "'" ),
140
- "define( 'BB_SECURE_A" => array( "'put your unique phrase here'", "'" . addslashes( SECURE_AUTH_KEY ) . "'" ),
141
- "define( 'BB_LOGGED_I" => array( "'put your unique phrase here'", "'" . addslashes( LOGGED_IN_KEY ) . "'" ),
142
- "define( 'BB_NONCE_KE" => array( "'put your unique phrase here'", "'" . addslashes( NONCE_KEY ) . "'" ),
143
- "\$bb_table_prefix = '" => array( "'bb_'", "'" . $wpdb->base_prefix . "bb_'" ),
144
- "define( 'BB_LANG', '" => array( "''", "'" . WPLANG . "'" )
145
- )
146
- );
147
-
148
- /* Add the custom user and usermeta entries to the config file */
149
- if ( $initial_write == 1 ) {
150
- $file = file_get_contents( ABSPATH . 'bb-config.php' );
151
- } else {
152
- $file = &$initial_write;
153
- }
154
-
155
- $file = substr( $file, 0, -2 );
156
- $file .= "\n" . '$bb->custom_user_table = "' . $wpdb->users . '";';
157
- $file .= "\n" . '$bb->custom_user_meta_table = "' . $wpdb->usermeta . '";';
158
- $file .= "\n\n" . '$bb->uri = "' . BP_PLUGIN_URL . '/bp-forums/bbpress/";';
159
- $file .= "\n" . '$bb->name = "' . get_blog_option( BP_ROOT_BLOG, 'name' ) . ' ' . __( 'Forums', 'buddypress' ) . '";';
160
-
161
- if ( bp_core_is_multisite() )
162
- $file .= "\n" . '$bb->wordpress_mu_primary_blog_id = ' . BP_ROOT_BLOG . ';';
163
-
164
- if ( defined( 'AUTH_SALT' ) )
165
- $file .= "\n\n" . 'define(\'BB_AUTH_SALT\', "' . addslashes( AUTH_SALT ) . '");';
166
-
167
- if ( defined( 'LOGGED_IN_SALT' ) )
168
- $file .= "\n" . 'define(\'BB_LOGGED_IN_SALT\', "' . addslashes( LOGGED_IN_SALT ) . '");';
169
-
170
- if ( defined( 'SECURE_AUTH_SALT' ) )
171
- $file .= "\n" . 'define(\'BB_SECURE_AUTH_SALT\', "' . addslashes( SECURE_AUTH_SALT ) . '");';
172
-
173
- $file .= "\n\n" . 'define(\'WP_AUTH_COOKIE_VERSION\', 2);';
174
- $file .= "\n\n" . '?>';
175
-
176
- if ( $initial_write == 1 ) {
177
- $file_handle = fopen( ABSPATH . 'bb-config.php', 'w' );
178
- fwrite( $file_handle, $file );
179
- fclose( $file_handle );
180
- } else {
181
- $initial_write = $file;
182
- }
183
-
184
- update_site_option( 'bb-config-location', ABSPATH . 'bb-config.php' );
185
- return $initial_write;
186
- }
187
-
188
- function bp_forums_bbpress_write( $file_source, $file_target, $alterations ) {
189
- if ( !$file_source || !file_exists( $file_source ) || !is_file( $file_source ) ) {
190
- return -1;
191
- }
192
-
193
- if ( !$file_target ) {
194
- $file_target = $file_source;
195
- }
196
-
197
- if ( !$alterations || !is_array( $alterations ) ) {
198
- return -2;
199
- }
200
-
201
- // Get the existing lines in the file
202
- $lines = file( $file_source );
203
-
204
- // Initialise an array to store the modified lines
205
- $modified_lines = array();
206
-
207
- // Loop through the lines and modify them
208
- foreach ( (array)$lines as $line ) {
209
- if ( isset( $alterations[substr( $line, 0, 20 )] ) ) {
210
- $alteration = $alterations[substr( $line, 0, 20 )];
211
- $modified_lines[] = str_replace( $alteration[0], $alteration[1], $line );
212
- } else {
213
- $modified_lines[] = $line;
214
- }
215
- }
216
-
217
- $writable = true;
218
- if ( file_exists( $file_target ) ) {
219
- if ( !is_writable( $file_target ) ) {
220
- $writable = false;
221
- }
222
- } else {
223
- $dir_target = dirname( $file_target );
224
-
225
- if ( file_exists( $dir_target ) ) {
226
- if ( !is_writable( $dir_target ) || !is_dir( $dir_target ) ) {
227
- $writable = false;
228
- }
229
- } else {
230
- $writable = false;
231
- }
232
- }
233
-
234
- if ( !$writable )
235
- return trim( join( null, $modified_lines ) );
236
-
237
- // Open the file for writing - rewrites the whole file
238
- $file_handle = fopen( $file_target, 'w' );
239
-
240
- // Write lines one by one to avoid OS specific newline hassles
241
- foreach ( (array)$modified_lines as $modified_line ) {
242
- if ( false !== strpos( $modified_line, '?>' ) ) {
243
- $modified_line = '?>';
244
- }
245
- fwrite( $file_handle, $modified_line );
246
- if ( $modified_line == '?>' ) {
247
- break;
248
- }
249
- }
250
-
251
- // Close the config file
252
- fclose( $file_handle );
253
-
254
- @chmod( $file_target, 0666 );
255
-
256
- return 1;
257
- }
258
  ?>
1
+ <?php
2
+
3
+ function bp_forums_bbpress_admin() {
4
+ global $bp;
5
+ ?>
6
+ <div class="wrap">
7
+
8
+ <h2><?php _e( 'Forums Setup', 'buddypress' ) ?></h2>
9
+
10
+ <?php if ( isset( $_POST['submit'] ) ) : ?>
11
+ <div id="message" class="updated fade">
12
+ <p><?php _e( 'Settings Saved.', 'buddypress' ) ?></p>
13
+ </div>
14
+ <?php endif; ?>
15
+
16
+ <?php
17
+
18
+ if ( isset( $_REQUEST['reinstall'] ) || !bp_forums_is_installed_correctly() ) {
19
+ update_site_option( 'bb-config-location', false );
20
+ bp_forums_bbpress_install_wizard();
21
+ } else { ?>
22
+ <p><?php printf( __( 'bbPress forum integration in BuddyPress has been set up correctly. If you are having problems you can <a href="%s" title="Reinstall bbPress">re-install</a>', 'buddypress' ), site_url( 'wp-admin/admin.php?page=bb-forums-setup&reinstall=1' ) ); ?>
23
+ <p><?php _e( 'NOTE: The forums directory will only work if your bbPress tables are in the same database as your WordPress tables. If you are not using an existing bbPress install you can ignore this message.', 'buddypress' ) ?></p>
24
+ <?php
25
+ }
26
+ ?>
27
+ </div>
28
+ <?php
29
+ }
30
+
31
+ function bp_forums_bbpress_install_wizard() {
32
+ $post_url = site_url( 'wp-admin/admin.php?page=bb-forums-setup' );
33
+
34
+ switch( $_REQUEST['step'] ) {
35
+ case 'existing':
36
+ if ( 1 == (int)$_REQUEST['doinstall'] ) {
37
+ if ( !bp_forums_configure_existing_install() ) {
38
+ _e( 'The bb-config.php file was not found at that location, please try again.', 'buddypress' );
39
+ } else {
40
+ ?>
41
+ <h3><?php _e( 'Forums were set up correctly using your existing bbPress install!', 'buddypress' ) ?></h3>
42
+ <p><?php _e( 'BuddyPress will now use its internal copy of bbPress to run the forums on your site. If you wish, you can remove your old bbPress installation files, as long as you keep the bb-config.php file in the same location.', 'buddypress' ) ?></p><?php
43
+ }
44
+ } else {
45
+ ?>
46
+ <form action="" method="post">
47
+ <h3><?php _e( 'Existing bbPress Installation', 'buddypress' ) ?></h3>
48
+ <p><?php _e( "BuddyPress can make use of your existing bbPress install. Just provide the location of your <code>bb-config.php</code> file, and BuddyPress will do the rest.", 'buddypress' ) ?></p>
49
+ <p><label><code>bb-config.php</code> file location:</label><br /><input style="width: 50%" type="text" name="bbconfigloc" id="bbconfigloc" value="<?php echo str_replace( 'buddypress', '', $_SERVER['DOCUMENT_ROOT'] ) ?>" /></p>
50
+ <p><input type="submit" class="button-primary" value="<?php _e( 'Complete Installation', 'buddypress' ) ?>" /></p>
51
+ <input type="hidden" name="step" value="existing" />
52
+ <input type="hidden" name="doinstall" value="1" />
53
+ <?php wp_nonce_field( 'bp_forums_existing_install_init' ) ?>
54
+ </form>
55
+ <?php
56
+ }
57
+ break;
58
+
59
+ case 'new':
60
+ if ( 1 == (int)$_REQUEST['doinstall'] ) {
61
+ $result = bp_forums_bbpress_install();
62
+
63
+ switch ( $result ) {
64
+ case 1:
65
+ _e( 'All done! Configuration settings have been saved to the file <code>bb-config.php</code> in the root of your WordPress install.', 'buddypress' );
66
+ break;
67
+ default:
68
+ // Just write the contents to screen
69
+ _e( 'A configuration file could not be created. No problem, but you will need to save the text shown below into a file named <code>bb-config.php</code> in the root directory of your WordPress installation before you can start using the forum functionality.', 'buddypress' );
70
+ ?><code style="display:block; margin-top: 30px;"><pre><?php echo htmlspecialchars( $result ) ?></pre></code><?php
71
+ break;
72
+ }
73
+ } else {
74
+ ?>
75
+ <h3><?php _e( 'New bbPress Installation', 'buddypress' ) ?></h3>
76
+ <p><?php _e( "You've decided to set up a new installation of bbPress for forum management in BuddyPress. This is very simple and is usually just a one click
77
+ process. When you're ready, hit the link below.", 'buddypress' ) ?></p>
78
+ <p><a class="button-primary" href="<?php echo wp_nonce_url( $post_url . '&step=new&doinstall=1', 'bp_forums_new_install_init' ) ?>"><?php _e( 'Complete Installation', 'buddypress' ) ?></a></p>
79
+ <?php
80
+ }
81
+ break;
82
+
83
+ default:
84
+ if ( !file_exists( BP_PLUGIN_DIR . '/bp-forums/bbpress/' ) ) { ?>
85
+ <div id="message" class="error">
86
+ <p><?php printf( __( 'bbPress files were not found. To install the forums component you must download a copy of bbPress and make sure it is in the folder: "%s"', 'buddypress' ), 'wp-content/plugins/buddypress/bp-forums/bbpress/' ) ?></p>
87
+ </div>
88
+ <?php } else { ?>
89
+
90
+ <p><?php _e( 'Forums in BuddyPress make use of a bbPress installation to function. You can choose to either let BuddyPress set up a new bbPress install, or use an already existing bbPress install. Please choose one of the options below.', 'buddypress' ) ?></p>
91
+
92
+ <a class="button" href="<?php echo $post_url . '&step=new' ?>"><?php _e( 'Set up a new bbPress installation', 'buddypress' ) ?></a> &nbsp;
93
+ <a class="button" href="<?php echo $post_url . '&step=existing' ?>"><?php _e( 'Use an existing bbPress installation', 'buddypress' ) ?></a>
94
+
95
+ <?php }
96
+ break;
97
+ }
98
+ }
99
+
100
+ function bp_forums_configure_existing_install() {
101
+ global $wpdb, $bbdb;
102
+
103
+ check_admin_referer( 'bp_forums_existing_install_init' );
104
+
105
+ /* Sanitize $_REQUEST['bbconfigloc'] */
106
+ $_REQUEST['bbconfigloc'] = apply_filters( 'bp_forums_bbconfig_location', $_REQUEST['bbconfigloc'] );
107
+
108
+ if ( false === strpos( $_REQUEST['bbconfigloc'], 'bb-config.php' ) ) {
109
+ if ( '/' != substr( $_REQUEST['bbconfigloc'], -1, 1 ) )
110
+ $_REQUEST['bbconfigloc'] .= '/';
111
+
112
+ $_REQUEST['bbconfigloc'] .= 'bb-config.php';
113
+ }
114
+
115
+ if ( !file_exists( $_REQUEST['bbconfigloc'] ) )
116
+ return false;
117
+
118
+ update_site_option( 'bb-config-location', $_REQUEST['bbconfigloc'] );
119
+
120
+ return true;
121
+ }
122
+
123
+ function bp_forums_bbpress_install() {
124
+ global $wpdb, $bbdb;
125
+
126
+ check_admin_referer( 'bp_forums_new_install_init' );
127
+
128
+ /* Create the bb-config.php file */
129
+ $initial_write = bp_forums_bbpress_write(
130
+ BP_PLUGIN_DIR . '/bp-forums/bbpress/bb-config-sample.php',
131
+ ABSPATH . 'bb-config.php',
132
+ array(
133
+ "define( 'BBDB_NAME'," => array( "'bbpress'", "'" . DB_NAME . "'" ),
134
+ "define( 'BBDB_USER'," => array( "'username'", "'" . DB_USER . "'" ),
135
+ "define( 'BBDB_PASSWO" => array( "'password'", "'" . DB_PASSWORD . "'" ),
136
+ "define( 'BBDB_HOST'," => array( "'localhost'", "'" . DB_HOST . "'" ),
137
+ "define( 'BBDB_CHARSE" => array( "'utf8'", "'" . DB_CHARSET . "'" ),
138
+ "define( 'BBDB_COLLAT" => array( "''", "'" . DB_COLLATE . "'" ),
139
+ "define( 'BB_AUTH_KEY" => array( "'put your unique phrase here'", "'" . addslashes( AUTH_KEY ) . "'" ),
140
+ "define( 'BB_SECURE_A" => array( "'put your unique phrase here'", "'" . addslashes( SECURE_AUTH_KEY ) . "'" ),
141
+ "define( 'BB_LOGGED_I" => array( "'put your unique phrase here'", "'" . addslashes( LOGGED_IN_KEY ) . "'" ),
142
+ "define( 'BB_NONCE_KE" => array( "'put your unique phrase here'", "'" . addslashes( NONCE_KEY ) . "'" ),
143
+ "\$bb_table_prefix = '" => array( "'bb_'", "'" . $wpdb->base_prefix . "bb_'" ),
144
+ "define( 'BB_LANG', '" => array( "''", "'" . WPLANG . "'" )
145
+ )
146
+ );
147
+
148
+ /* Add the custom user and usermeta entries to the config file */
149
+ if ( $initial_write == 1 ) {
150
+ $file = file_get_contents( ABSPATH . 'bb-config.php' );
151
+ } else {
152
+ $file = &$initial_write;
153
+ }
154
+
155
+ $file = substr( $file, 0, -2 );
156
+ $file .= "\n" . '$bb->custom_user_table = \'' . $wpdb->users . '\';';
157
+ $file .= "\n" . '$bb->custom_user_meta_table = \'' . $wpdb->usermeta . '\';';
158
+ $file .= "\n\n" . '$bb->uri = \'' . BP_PLUGIN_URL . '/bp-forums/bbpress/\';';
159
+ $file .= "\n" . '$bb->name = \'' . get_blog_option( BP_ROOT_BLOG, 'name' ) . ' ' . __( 'Forums', 'buddypress' ) . '\';';
160
+
161
+ if ( bp_core_is_multisite() )
162
+ $file .= "\n" . '$bb->wordpress_mu_primary_blog_id = ' . BP_ROOT_BLOG . ';';
163
+
164
+ if ( defined( 'AUTH_SALT' ) )
165
+ $file .= "\n\n" . 'define(\'BB_AUTH_SALT\', \'' . addslashes( AUTH_SALT ) . '\');';
166
+
167
+ if ( defined( 'LOGGED_IN_SALT' ) )
168
+ $file .= "\n" . 'define(\'BB_LOGGED_IN_SALT\', \'' . addslashes( LOGGED_IN_SALT ) . '\');';
169
+
170
+ if ( defined( 'SECURE_AUTH_SALT' ) )
171
+ $file .= "\n" . 'define(\'BB_SECURE_AUTH_SALT\', \'' . addslashes( SECURE_AUTH_SALT ) . '\');';
172
+
173
+ $file .= "\n\n" . 'define(\'WP_AUTH_COOKIE_VERSION\', 2);';
174
+ $file .= "\n\n" . '?>';
175
+
176
+ if ( $initial_write == 1 ) {
177
+ $file_handle = fopen( ABSPATH . 'bb-config.php', 'w' );
178
+ fwrite( $file_handle, $file );
179
+ fclose( $file_handle );
180
+ } else {
181
+ $initial_write = $file;
182
+ }
183
+
184
+ update_site_option( 'bb-config-location', ABSPATH . 'bb-config.php' );
185
+ return $initial_write;
186
+ }
187
+
188
+ function bp_forums_bbpress_write( $file_source, $file_target, $alterations ) {
189
+ if ( !$file_source || !file_exists( $file_source ) || !is_file( $file_source ) ) {
190
+ return -1;
191
+ }
192
+
193
+ if ( !$file_target ) {
194
+ $file_target = $file_source;
195
+ }
196
+
197
+ if ( !$alterations || !is_array( $alterations ) ) {
198
+ return -2;
199
+ }
200
+
201
+ // Get the existing lines in the file
202
+ $lines = file( $file_source );
203
+
204
+ // Initialise an array to store the modified lines
205
+ $modified_lines = array();
206
+
207
+ // Loop through the lines and modify them
208
+ foreach ( (array)$lines as $line ) {
209
+ if ( isset( $alterations[substr( $line, 0, 20 )] ) ) {
210
+ $alteration = $alterations[substr( $line, 0, 20 )];
211
+ $modified_lines[] = str_replace( $alteration[0], $alteration[1], $line );
212
+ } else {
213
+ $modified_lines[] = $line;
214
+ }
215
+ }
216
+
217
+ $writable = true;
218
+ if ( file_exists( $file_target ) ) {
219
+ if ( !is_writable( $file_target ) ) {
220
+ $writable = false;
221
+ }
222
+ } else {
223
+ $dir_target = dirname( $file_target );
224
+
225
+ if ( file_exists( $dir_target ) ) {
226
+ if ( !is_writable( $dir_target ) || !is_dir( $dir_target ) ) {
227
+ $writable = false;
228
+ }
229
+ } else {
230
+ $writable = false;
231
+ }
232
+ }
233
+
234
+ if ( !$writable )
235
+ return trim( join( null, $modified_lines ) );
236
+
237
+ // Open the file for writing - rewrites the whole file
238
+ $file_handle = fopen( $file_target, 'w' );
239
+
240
+ // Write lines one by one to avoid OS specific newline hassles
241
+ foreach ( (array)$modified_lines as $modified_line ) {
242
+ if ( false !== strpos( $modified_line, '?>' ) ) {
243
+ $modified_line = '?>';
244
+ }
245
+ fwrite( $file_handle, $modified_line );
246
+ if ( $modified_line == '?>' ) {
247
+ break;
248
+ }
249
+ }
250
+
251
+ // Close the config file
252
+ fclose( $file_handle );
253
+
254
+ @chmod( $file_target, 0666 );
255
+
256
+ return 1;
257
+ }
258
  ?>
bp-forums/bp-forums-bbpress.php CHANGED
@@ -1,175 +1,175 @@
1
- <?php
2
-
3
- function bp_forums_load_bbpress() {
4
- global $bp, $wpdb, $wp_roles, $current_user, $wp_users_object;
5
- global $bb, $bbdb, $bb_table_prefix, $bb_current_user;
6
- global $bb_roles, $wp_taxonomy_object;
7
-
8
- /* Return if we've already run this function. */
9
- if ( is_object( $bbdb ) && is_object( $bb_roles ) )
10
- return;
11
-
12
- if ( !bp_forums_is_installed_correctly() )
13
- return false;
14
-
15
- define( 'BB_PATH', BP_PLUGIN_DIR . '/bp-forums/bbpress/' );
16
- define( 'BACKPRESS_PATH', BP_PLUGIN_DIR . '/bp-forums/bbpress/bb-includes/backpress/' );
17
- define( 'BB_URL', BP_PLUGIN_URL . '/bp-forums/bbpress/' );
18
- define( 'BB_INC', 'bb-includes/' );
19
-
20
- require_once( BB_PATH . BB_INC . 'class.bb-query.php' );
21
- require_once( BB_PATH . BB_INC . 'class.bb-walker.php' );
22
-
23
- require_once( BB_PATH . BB_INC . 'functions.bb-core.php' );
24
- require_once( BB_PATH . BB_INC . 'functions.bb-forums.php' );
25
- require_once( BB_PATH . BB_INC . 'functions.bb-topics.php' );
26
- require_once( BB_PATH . BB_INC . 'functions.bb-posts.php' );
27
- require_once( BB_PATH . BB_INC . 'functions.bb-topic-tags.php' );
28
- require_once( BB_PATH . BB_INC . 'functions.bb-capabilities.php' );
29
- require_once( BB_PATH . BB_INC . 'functions.bb-meta.php' );
30
- require_once( BB_PATH . BB_INC . 'functions.bb-pluggable.php' );
31
- require_once( BB_PATH . BB_INC . 'functions.bb-formatting.php' );
32
- require_once( BB_PATH . BB_INC . 'functions.bb-template.php' );
33
-
34
- require_once( BACKPRESS_PATH . 'class.wp-taxonomy.php' );
35
- require_once( BB_PATH . BB_INC . 'class.bb-taxonomy.php' );
36
-
37
- $bb = new stdClass();
38
- require_once( $bp->forums->bbconfig );
39
-
40
- // Setup the global database connection
41
- $bbdb = new BPDB ( BBDB_USER, BBDB_PASSWORD, BBDB_NAME, BBDB_HOST );
42
-
43
- /* Set the table names */
44
- $bbdb->forums = $bb_table_prefix . 'forums';
45
- $bbdb->meta = $bb_table_prefix . 'meta';
46
- $bbdb->posts = $bb_table_prefix . 'posts';
47
- $bbdb->terms = $bb_table_prefix . 'terms';
48
- $bbdb->term_relationships = $bb_table_prefix . 'term_relationships';
49
- $bbdb->term_taxonomy = $bb_table_prefix . 'term_taxonomy';
50
- $bbdb->topics = $bb_table_prefix . 'topics';
51
-
52
- if ( isset( $bb->custom_user_table ) )
53
- $bbdb->users = $bb->custom_user_table;
54
- else
55
- $bbdb->users = $wpdb->users;
56
-
57
- if ( isset( $bb->custom_user_meta_table ) )
58
- $bbdb->usermeta = $bb->custom_user_meta_table;
59
- else
60
- $bbdb->usermeta = $wpdb->usermeta;
61
-
62
- $bbdb->prefix = $bb_table_prefix;
63
-
64
- define( 'BB_INSTALLING', false );
65
-
66
- /* This must be loaded before functionss.bb-admin.php otherwise we get a function conflict. */
67
- if ( !$tables_installed = (boolean) $bbdb->get_results( 'DESCRIBE `' . $bbdb->forums . '`;', ARRAY_A ) )
68
- require_once( ABSPATH . 'wp-admin/upgrade-functions.php' );
69
-
70
- require_once( BB_PATH . 'bb-admin/includes/functions.bb-admin.php' );
71
-
72
- if ( is_object( $wp_roles ) ) {
73
- $bb_roles =& $wp_roles;
74
- bb_init_roles( $bb_roles );
75
- }
76
-
77
- do_action( 'bb_got_roles' );
78
- do_action( 'bb_init' );
79
- do_action( 'init_roles' );
80
-
81
- $bb_current_user = $current_user;
82
- $wp_users_object = new BP_Forums_BB_Auth;
83
-
84
- if ( !isset( $wp_taxonomy_object ) )
85
- $wp_taxonomy_object = new BB_Taxonomy( $bbdb );
86
-
87
- $wp_taxonomy_object->register_taxonomy( 'bb_topic_tag', 'bb_topic' );
88
-
89
- // Set a site id if there isn't one already
90
- if ( !isset( $bb->site_id ) )
91
- $bb->site_id = BP_ROOT_BLOG;
92
-
93
- /* Check if the tables are installed, if not, install them */
94
- if ( !$tables_installed ) {
95
- require_once( BB_PATH . 'bb-admin/includes/defaults.bb-schema.php' );
96
-
97
- /* Backticks and "IF NOT EXISTS" break the dbDelta function. */
98
- dbDelta( str_replace( ' IF NOT EXISTS', '', str_replace( '`', '', $bb_queries ) ) );
99
-
100
- require_once( BB_PATH . 'bb-admin/includes/functions.bb-upgrade.php' );
101
- bb_update_db_version();
102
-
103
- /* Set the site admins as the keymasters */
104
- $site_admins = get_site_option( 'site_admins', array('admin') );
105
- foreach ( (array)$site_admins as $site_admin )
106
- update_usermeta( bp_core_get_userid( $site_admin ), $bb_table_prefix . 'capabilities', array( 'keymaster' => true ) );
107
-
108
- // Create the first forum.
109
- bb_new_forum( array( 'forum_name' => 'Default Forum' ) );
110
-
111
- // Set the site URI
112
- bb_update_option( 'uri', BB_URL );
113
- }
114
-
115
- register_shutdown_function( create_function( '', 'do_action("bb_shutdown");' ) );
116
- }
117
- add_action( 'bbpress_init', 'bp_forums_load_bbpress' );
118
-
119
- /* WP to bbP wrapper functions */
120
- function bb_get_current_user() { global $current_user; return $current_user; }
121
- function bb_get_user( $user_id ) { return get_userdata( $user_id ); }
122
- function bb_cache_users( $users ) {}
123
-
124
- /**
125
- * bbPress needs this class for its usermeta manipulation.
126
- */
127
- class BP_Forums_BB_Auth {
128
- function update_meta( $args = '' ) {
129
- $defaults = array( 'id' => 0, 'meta_key' => null, 'meta_value' => null, 'meta_table' => 'usermeta', 'meta_field' => 'user_id', 'cache_group' => 'users' );
130
- $args = wp_parse_args( $args, $defaults );
131
- extract( $args, EXTR_SKIP );
132
-
133
- return update_usermeta( $id, $meta_key, $meta_value );
134
- }
135
- }
136
-
137
- /**
138
- * bbPress needs the DB class to be BPDB, but we want to use WPDB, so we can
139
- * extend it and use this.
140
- */
141
- class BPDB extends WPDB {
142
- function escape_deep( $data ) {
143
- if ( is_array( $data ) ) {
144
- foreach ( (array) $data as $k => $v ) {
145
- if ( is_array( $v ) ) {
146
- $data[$k] = $this->_escape( $v );
147
- } else {
148
- $data[$k] = $this->_real_escape( $v );
149
- }
150
- }
151
- } else {
152
- $data = $this->_real_escape( $data );
153
- }
154
-
155
- return $data;
156
- }
157
- }
158
-
159
- /* BBPress needs this function to convert vars */
160
- function backpress_convert_object( &$object, $output ) {
161
- if ( is_array( $object ) ) {
162
- foreach ( array_keys( $object ) as $key )
163
- backpress_convert_object( $object[$key], $output );
164
- } else {
165
- switch ( $output ) {
166
- case OBJECT : break;
167
- case ARRAY_A : $object = get_object_vars($object); break;
168
- case ARRAY_N : $object = array_values(get_object_vars($object)); break;
169
- }
170
- }
171
- }
172
-
173
-
174
-
175
  ?>
1
+ <?php
2
+
3
+ function bp_forums_load_bbpress() {
4
+ global $bp, $wpdb, $wp_roles, $current_user, $wp_users_object;
5
+ global $bb, $bbdb, $bb_table_prefix, $bb_current_user;
6
+ global $bb_roles, $wp_taxonomy_object;
7
+
8
+ /* Return if we've already run this function. */
9
+ if ( is_object( $bbdb ) && is_object( $bb_roles ) )
10
+ return;
11
+
12
+ if ( !bp_forums_is_installed_correctly() )
13
+ return false;
14
+
15
+ define( 'BB_PATH', BP_PLUGIN_DIR . '/bp-forums/bbpress/' );
16
+ define( 'BACKPRESS_PATH', BP_PLUGIN_DIR . '/bp-forums/bbpress/bb-includes/backpress/' );
17
+ define( 'BB_URL', BP_PLUGIN_URL . '/bp-forums/bbpress/' );
18
+ define( 'BB_INC', 'bb-includes/' );
19
+
20
+ require_once( BB_PATH . BB_INC . 'class.bb-query.php' );
21
+ require_once( BB_PATH . BB_INC . 'class.bb-walker.php' );
22
+
23
+ require_once( BB_PATH . BB_INC . 'functions.bb-core.php' );
24
+ require_once( BB_PATH . BB_INC . 'functions.bb-forums.php' );
25
+ require_once( BB_PATH . BB_INC . 'functions.bb-topics.php' );
26
+ require_once( BB_PATH . BB_INC . 'functions.bb-posts.php' );
27
+ require_once( BB_PATH . BB_INC . 'functions.bb-topic-tags.php' );
28
+ require_once( BB_PATH . BB_INC . 'functions.bb-capabilities.php' );
29
+ require_once( BB_PATH . BB_INC . 'functions.bb-meta.php' );
30
+ require_once( BB_PATH . BB_INC . 'functions.bb-pluggable.php' );
31
+ require_once( BB_PATH . BB_INC . 'functions.bb-formatting.php' );
32
+ require_once( BB_PATH . BB_INC . 'functions.bb-template.php' );
33
+
34
+ require_once( BACKPRESS_PATH . 'class.wp-taxonomy.php' );
35
+ require_once( BB_PATH . BB_INC . 'class.bb-taxonomy.php' );
36
+
37
+ $bb = new stdClass();
38
+ require_once( $bp->forums->bbconfig );
39
+
40
+ // Setup the global database connection
41
+ $bbdb = new BPDB ( BBDB_USER, BBDB_PASSWORD, BBDB_NAME, BBDB_HOST );
42
+
43
+ /* Set the table names */
44
+ $bbdb->forums = $bb_table_prefix . 'forums';
45
+ $bbdb->meta = $bb_table_prefix . 'meta';
46
+ $bbdb->posts = $bb_table_prefix . 'posts';
47
+ $bbdb->terms = $bb_table_prefix . 'terms';
48
+ $bbdb->term_relationships = $bb_table_prefix . 'term_relationships';
49
+ $bbdb->term_taxonomy = $bb_table_prefix . 'term_taxonomy';
50
+ $bbdb->topics = $bb_table_prefix . 'topics';
51
+
52
+ if ( isset( $bb->custom_user_table ) )
53
+ $bbdb->users = $bb->custom_user_table;
54
+ else
55
+ $bbdb->users = $wpdb->users;
56
+
57
+ if ( isset( $bb->custom_user_meta_table ) )
58
+ $bbdb->usermeta = $bb->custom_user_meta_table;
59
+ else
60
+ $bbdb->usermeta = $wpdb->usermeta;
61
+
62
+ $bbdb->prefix = $bb_table_prefix;
63
+
64
+ define( 'BB_INSTALLING', false );
65
+
66
+ /* This must be loaded before functionss.bb-admin.php otherwise we get a function conflict. */
67
+ if ( !$tables_installed = (boolean) $bbdb->get_results( 'DESCRIBE `' . $bbdb->forums . '`;', ARRAY_A ) )
68
+ require_once( ABSPATH . 'wp-admin/upgrade-functions.php' );
69
+
70
+ require_once( BB_PATH . 'bb-admin/includes/functions.bb-admin.php' );
71
+
72
+ if ( is_object( $wp_roles ) ) {
73
+ $bb_roles =& $wp_roles;
74
+ bb_init_roles( $bb_roles );
75
+ }
76
+
77
+ do_action( 'bb_got_roles' );
78
+ do_action( 'bb_init' );
79
+ do_action( 'init_roles' );
80
+
81
+ $bb_current_user = $current_user;
82
+ $wp_users_object = new BP_Forums_BB_Auth;
83
+
84
+ if ( !isset( $wp_taxonomy_object ) )
85
+ $wp_taxonomy_object = new BB_Taxonomy( $bbdb );
86
+
87
+ $wp_taxonomy_object->register_taxonomy( 'bb_topic_tag', 'bb_topic' );
88
+
89
+ // Set a site id if there isn't one already
90
+ if ( !isset( $bb->site_id ) )
91
+ $bb->site_id = BP_ROOT_BLOG;
92
+
93
+ /* Check if the tables are installed, if not, install them */
94
+ if ( !$tables_installed ) {
95
+ require_once( BB_PATH . 'bb-admin/includes/defaults.bb-schema.php' );
96
+
97
+ /* Backticks and "IF NOT EXISTS" break the dbDelta function. */
98
+ dbDelta( str_replace( ' IF NOT EXISTS', '', str_replace( '`', '', $bb_queries ) ) );
99
+
100
+ require_once( BB_PATH . 'bb-admin/includes/functions.bb-upgrade.php' );
101
+ bb_update_db_version();
102
+
103
+ /* Set the site admins as the keymasters */
104
+ $site_admins = get_site_option( 'site_admins', array('admin') );
105
+ foreach ( (array)$site_admins as $site_admin )
106
+ update_usermeta( bp_core_get_userid( $site_admin ), $bb_table_prefix . 'capabilities', array( 'keymaster' => true ) );
107
+
108
+ // Create the first forum.
109
+ bb_new_forum( array( 'forum_name' => 'Default Forum' ) );
110
+
111
+ // Set the site URI
112
+ bb_update_option( 'uri', BB_URL );
113
+ }
114
+
115
+ register_shutdown_function( create_function( '', 'do_action("bb_shutdown");' ) );
116
+ }
117
+ add_action( 'bbpress_init', 'bp_forums_load_bbpress' );
118
+
119
+ /* WP to bbP wrapper functions */
120
+ function bb_get_current_user() { global $current_user; return $current_user; }
121
+ function bb_get_user( $user_id ) { return get_userdata( $user_id ); }
122
+ function bb_cache_users( $users ) {}
123
+
124
+ /**
125
+ * bbPress needs this class for its usermeta manipulation.
126
+ */
127
+ class BP_Forums_BB_Auth {
128
+ function update_meta( $args = '' ) {
129
+ $defaults = array( 'id' => 0, 'meta_key' => null, 'meta_value' => null, 'meta_table' => 'usermeta', 'meta_field' => 'user_id', 'cache_group' => 'users' );
130
+ $args = wp_parse_args( $args, $defaults );
131
+ extract( $args, EXTR_SKIP );
132
+
133
+ return update_usermeta( $id, $meta_key, $meta_value );
134
+ }
135
+ }
136
+
137
+ /**
138
+ * bbPress needs the DB class to be BPDB, but we want to use WPDB, so we can
139
+ * extend it and use this.
140
+ */
141
+ class BPDB extends WPDB {
142
+ function escape_deep( $data ) {
143
+ if ( is_array( $data ) ) {
144
+ foreach ( (array) $data as $k => $v ) {
145
+ if ( is_array( $v ) ) {
146
+ $data[$k] = $this->_escape( $v );
147
+ } else {
148
+ $data[$k] = $this->_real_escape( $v );
149
+ }
150
+ }
151
+ } else {
152
+ $data = $this->_real_escape( $data );
153
+ }
154
+
155
+ return $data;
156
+ }
157
+ }
158
+
159
+ /* BBPress needs this function to convert vars */
160
+ function backpress_convert_object( &$object, $output ) {
161
+ if ( is_array( $object ) ) {
162
+ foreach ( array_keys( $object ) as $key )
163
+ backpress_convert_object( $object[$key], $output );
164
+ } else {
165
+ switch ( $output ) {
166
+ case OBJECT : break;
167
+ case ARRAY_A : $object = get_object_vars($object); break;
168
+ case ARRAY_N : $object = array_values(get_object_vars($object)); break;
169
+ }
170
+ }
171
+ }
172
+
173
+
174
+
175
  ?>
bp-forums/bp-forums-filters.php CHANGED
@@ -1,90 +1,91 @@
1
- <?php
2
-
3
- /* Apply WordPress defined filters */
4
- add_filter( 'bp_forums_bbconfig_location', 'wp_filter_kses', 1 );
5
- add_filter( 'bp_forums_bbconfig_location', 'attribute_escape', 1 );
6
-
7
- add_filter( 'bp_get_the_topic_title', 'wp_filter_kses', 1 );
8
- add_filter( 'bp_get_the_topic_latest_post_excerpt', 'bp_forums_filter_kses', 1 );
9
- add_filter( 'bp_get_the_topic_post_content', 'bp_forums_filter_kses', 1 );
10
-
11
- add_filter( 'bp_get_the_topic_title', 'force_balance_tags' );
12
- add_filter( 'bp_get_the_topic_latest_post_excerpt', 'force_balance_tags' );
13
- add_filter( 'bp_get_the_topic_post_content', 'force_balance_tags' );
14
-
15
- add_filter( 'bp_get_the_topic_title', 'wptexturize' );
16
- add_filter( 'bp_get_the_topic_poster_name', 'wptexturize' );
17
- add_filter( 'bp_get_the_topic_last_poster_name', 'wptexturize' );
18
- add_filter( 'bp_get_the_topic_post_content', 'wptexturize' );
19
- add_filter( 'bp_get_the_topic_post_poster_name', 'wptexturize' );
20
-
21
- add_filter( 'bp_get_the_topic_title', 'convert_smilies' );
22
- add_filter( 'bp_get_the_topic_latest_post_excerpt', 'convert_smilies' );
23
- add_filter( 'bp_get_the_topic_post_content', 'convert_smilies' );
24
-
25
- add_filter( 'bp_get_the_topic_title', 'convert_chars' );
26
- add_filter( 'bp_get_the_topic_latest_post_excerpt', 'convert_chars' );
27
- add_filter( 'bp_get_the_topic_post_content', 'convert_chars' );
28
-
29
- add_filter( 'bp_get_the_topic_post_content', 'wpautop' );
30
- add_filter( 'bp_get_the_topic_latest_post_excerpt', 'wpautop' );
31
-
32
- add_filter( 'bp_get_the_topic_post_content', 'stripslashes_deep' );
33
- add_filter( 'bp_get_the_topic_title', 'stripslashes_deep' );
34
- add_filter( 'bp_get_the_topic_latest_post_excerpt', 'stripslashes_deep' );
35
- add_filter( 'bp_get_the_topic_poster_name', 'stripslashes_deep' );
36
- add_filter( 'bp_get_the_topic_last_poster_name', 'stripslashes_deep' );
37
-
38
- add_filter( 'bp_get_the_topic_post_content', 'make_clickable' );
39
-
40
- add_filter( 'bp_get_forum_topic_count_for_user', 'bp_core_number_format' );
41
- add_filter( 'bp_get_forum_topic_count', 'bp_core_number_format' );
42
-
43
- add_filter( 'bp_get_the_topic_title', 'bp_forums_make_nofollow_filter' );
44
- add_filter( 'bp_get_the_topic_latest_post_excerpt', 'bp_forums_make_nofollow_filter' );
45
- add_filter( 'bp_get_the_topic_post_content', 'bp_forums_make_nofollow_filter' );
46
-
47
- function bp_forums_filter_kses( $content ) {
48
- global $allowedtags;
49
-
50
- $forums_allowedtags = $allowedtags;
51
- $forums_allowedtags['span'] = array();
52
- $forums_allowedtags['span']['class'] = array();
53
- $forums_allowedtags['div'] = array();
54
- $forums_allowedtags['div']['class'] = array();
55
- $forums_allowedtags['div']['id'] = array();
56
- $forums_allowedtags['a']['class'] = array();
57
- $forums_allowedtags['img'] = array();
58
- $forums_allowedtags['br'] = array();
59
- $forums_allowedtags['p'] = array();
60
- $forums_allowedtags['img']['src'] = array();
61
- $forums_allowedtags['img']['alt'] = array();
62
- $forums_allowedtags['img']['class'] = array();
63
- $forums_allowedtags['img']['width'] = array();
64
- $forums_allowedtags['img']['height'] = array();
65
- $forums_allowedtags['img']['class'] = array();
66
- $forums_allowedtags['img']['id'] = array();
67
- $forums_allowedtags['code'] = array();
68
- $forums_allowedtags['blockquote'] = array();
69
-
70
- $forums_allowedtags = apply_filters( 'bp_forums_allowed_tags', $forums_allowedtags );
71
- return wp_kses( $content, $forums_allowedtags );
72
- }
73
-
74
- function bp_forums_filter_tag_link( $link, $tag, $page, $context ) {
75
- global $bp;
76
-
77
- return apply_filters( 'bp_forums_filter_tag_link', $bp->root_domain . '/' . $bp->forums->slug . '/tag/' . $tag . '/' );
78
- }
79
- add_filter( 'bb_get_tag_link', 'bp_forums_filter_tag_link', 10, 4);
80
-
81
- function bp_forums_make_nofollow_filter( $text ) {
82
- return preg_replace_callback( '|<a (.+?)>|i', 'bp_forums_make_nofollow_filter_callback', $text );
83
- }
84
- function bp_forums_make_nofollow_filter_callback( $matches ) {
85
- $text = $matches[1];
86
- $text = str_replace( array( ' rel="nofollow"', " rel='nofollow'"), '', $text );
87
- return "<a $text rel=\"nofollow\">";
88
- }
89
-
 
90
  ?>
1
+ <?php
2
+
3
+ /* Apply WordPress defined filters */
4
+ add_filter( 'bp_forums_bbconfig_location', 'wp_filter_kses', 1 );
5
+ add_filter( 'bp_forums_bbconfig_location', 'attribute_escape', 1 );
6
+
7
+ add_filter( 'bp_get_the_topic_title', 'wp_filter_kses', 1 );
8
+ add_filter( 'bp_get_the_topic_latest_post_excerpt', 'bp_forums_filter_kses', 1 );
9
+ add_filter( 'bp_get_the_topic_post_content', 'bp_forums_filter_kses', 1 );
10
+
11
+ add_filter( 'bp_get_the_topic_title', 'force_balance_tags' );
12
+ add_filter( 'bp_get_the_topic_latest_post_excerpt', 'force_balance_tags' );
13
+ add_filter( 'bp_get_the_topic_post_content', 'force_balance_tags' );
14
+
15
+ add_filter( 'bp_get_the_topic_title', 'wptexturize' );
16
+ add_filter( 'bp_get_the_topic_poster_name', 'wptexturize' );
17
+ add_filter( 'bp_get_the_topic_last_poster_name', 'wptexturize' );
18
+ add_filter( 'bp_get_the_topic_post_content', 'wptexturize' );
19
+ add_filter( 'bp_get_the_topic_post_poster_name', 'wptexturize' );
20
+
21
+ add_filter( 'bp_get_the_topic_title', 'convert_smilies' );
22
+ add_filter( 'bp_get_the_topic_latest_post_excerpt', 'convert_smilies' );
23
+ add_filter( 'bp_get_the_topic_post_content', 'convert_smilies' );
24
+
25
+ add_filter( 'bp_get_the_topic_title', 'convert_chars' );
26
+ add_filter( 'bp_get_the_topic_latest_post_excerpt', 'convert_chars' );
27
+ add_filter( 'bp_get_the_topic_post_content', 'convert_chars' );
28
+
29
+ add_filter( 'bp_get_the_topic_post_content', 'wpautop' );
30
+ add_filter( 'bp_get_the_topic_latest_post_excerpt', 'wpautop' );
31
+
32
+ add_filter( 'bp_get_the_topic_post_content', 'stripslashes_deep' );
33
+ add_filter( 'bp_get_the_topic_title', 'stripslashes_deep' );
34
+ add_filter( 'bp_get_the_topic_latest_post_excerpt', 'stripslashes_deep' );
35
+ add_filter( 'bp_get_the_topic_poster_name', 'stripslashes_deep' );
36
+ add_filter( 'bp_get_the_topic_last_poster_name', 'stripslashes_deep' );
37
+ add_filter( 'bp_get_the_topic_object_name', 'stripslashes_deep' );
38
+
39
+ add_filter( 'bp_get_the_topic_post_content', 'make_clickable' );
40
+
41
+ add_filter( 'bp_get_forum_topic_count_for_user', 'bp_core_number_format' );
42
+ add_filter( 'bp_get_forum_topic_count', 'bp_core_number_format' );
43
+
44
+ add_filter( 'bp_get_the_topic_title', 'bp_forums_make_nofollow_filter' );
45
+ add_filter( 'bp_get_the_topic_latest_post_excerpt', 'bp_forums_make_nofollow_filter' );
46
+ add_filter( 'bp_get_the_topic_post_content', 'bp_forums_make_nofollow_filter' );
47
+
48
+ function bp_forums_filter_kses( $content ) {
49
+ global $allowedtags;
50
+
51
+ $forums_allowedtags = $allowedtags;
52
+ $forums_allowedtags['span'] = array();
53
+ $forums_allowedtags['span']['class'] = array();
54
+ $forums_allowedtags['div'] = array();
55
+ $forums_allowedtags['div']['class'] = array();
56
+ $forums_allowedtags['div']['id'] = array();
57
+ $forums_allowedtags['a']['class'] = array();
58
+ $forums_allowedtags['img'] = array();
59
+ $forums_allowedtags['br'] = array();
60
+ $forums_allowedtags['p'] = array();
61
+ $forums_allowedtags['img']['src'] = array();
62
+ $forums_allowedtags['img']['alt'] = array();
63
+ $forums_allowedtags['img']['class'] = array();
64
+ $forums_allowedtags['img']['width'] = array();
65
+ $forums_allowedtags['img']['height'] = array();
66
+ $forums_allowedtags['img']['class'] = array();
67
+ $forums_allowedtags['img']['id'] = array();
68
+ $forums_allowedtags['code'] = array();
69
+ $forums_allowedtags['blockquote'] = array();
70
+
71
+ $forums_allowedtags = apply_filters( 'bp_forums_allowed_tags', $forums_allowedtags );
72
+ return wp_kses( $content, $forums_allowedtags );
73
+ }
74
+
75
+ function bp_forums_filter_tag_link( $link, $tag, $page, $context ) {
76
+ global $bp;
77
+
78
+ return apply_filters( 'bp_forums_filter_tag_link', $bp->root_domain . '/' . $bp->forums->slug . '/tag/' . $tag . '/' );
79
+ }
80
+ add_filter( 'bb_get_tag_link', 'bp_forums_filter_tag_link', 10, 4);
81
+
82
+ function bp_forums_make_nofollow_filter( $text ) {
83
+ return preg_replace_callback( '|<a (.+?)>|i', 'bp_forums_make_nofollow_filter_callback', $text );
84
+ }
85
+ function bp_forums_make_nofollow_filter_callback( $matches ) {
86
+ $text = $matches[1];
87
+ $text = str_replace( array( ' rel="nofollow"', " rel='nofollow'"), '', $text );
88
+ return "<a $text rel=\"nofollow\">";
89
+ }
90
+
91
  ?>
bp-forums/bp-forums-templatetags.php CHANGED
@@ -1,1090 +1,1090 @@
1
- <?php
2
-
3
- class BP_Forums_Template_Forum {
4
- var $current_topic = -1;
5
- var $topic_count;
6
- var $topics;
7
- var $topic;
8
-
9
- var $forum_id;
10
-
11
- var $in_the_loop;
12
-
13
- var $pag_page;
14
- var $pag_num;
15
- var $pag_links;
16
- var $total_topic_count;
17
-
18
- var $single_topic = false;
19
-
20
- var $sort_by;
21
- var $order;
22
-
23
- function BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms ) {
24
- global $bp;
25
-
26
- $this->pag_page = isset( $_REQUEST['p'] ) ? intval( $_REQUEST['p'] ) : $page;
27
- $this->pag_num = isset( $_REQUEST['n'] ) ? intval( $_REQUEST['n'] ) : $per_page;
28
- $this->type = $type;
29
- $this->search_terms = $search_terms;
30
- $this->forum_id = $forum_id;
31
-
32
- switch ( $type ) {
33
- case 'newest': default:
34
- $this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'forum_id' => $forum_id, 'filter' => $search_terms, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies ) );
35
- break;
36
-
37
- case 'popular':
38
- $this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'type' => 'popular', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies ) );
39
- break;
40
-
41
- case 'unreplied':
42
- $this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'type' => 'unreplied', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies ) );
43
- break;
44
-
45
- case 'tags':
46
- $this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'type' => 'tags', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies ) );
47
- break;
48
- }
49
-
50
- $this->topics = apply_filters( 'bp_forums_template_topics', $this->topics, $type, $forum_id, $per_page, $max, $no_stickies );
51
-
52
- if ( !(int)$this->topics ) {
53
- $this->topic_count = 0;
54
- $this->total_topic_count = 0;
55
- } else {
56
- if ( $forum_id ) {
57
- $topic_count = bp_forums_get_forum( $forum_id );
58
- $topic_count = (int)$topic_count->topics;
59
- } else if ( function_exists( 'groups_total_public_forum_topic_count' ) ) {
60
- $topic_count = (int)groups_total_public_forum_topic_count( $type );
61
- } else {
62
- $topic_count = count( $this->topics );
63
- }
64
-
65
- if ( !$max || $max >= $topic_count )
66
- $this->total_topic_count = $topic_count;
67
- else
68
- $this->total_topic_count = (int)$max;
69
-
70
- if ( $max ) {
71
- if ( $max >= count($this->topics) )
72
- $this->topic_count = count( $this->topics );
73
- else
74
- $this->topic_count = (int)$max;
75
- } else {
76
- $this->topic_count = count( $this->topics );
77
- }
78
- }
79
-
80
- $this->topic_count = apply_filters( 'bp_forums_template_topic_count', $this->topic_count, &$topics, $type, $forum_id, $per_page, $max, $no_stickies );
81
- $this->total_topic_count = apply_filters( 'bp_forums_template_total_topic_count', $this->total_topic_count, $this->topic_count, &$topics, $type, $forum_id, $per_page, $max, $no_stickies );
82
-
83
- if ( !$no_stickies) {
84
- /* Place stickies at the top - not sure why bbPress doesn't do this? */
85
- foreach( (array)$this->topics as $topic ) {
86
- if ( 1 == (int)$topic->topic_sticky )
87
- $stickies[] = $topic;
88
- else
89
- $standard[] = $topic;
90
- }
91
- $this->topics = array_merge( (array)$stickies, (array)$standard );
92
- }
93
-
94
- /* Fetch extra information for topics, so we don't have to query inside the loop */
95
- $this->topics = bp_forums_get_topic_extras( &$this->topics );
96
-
97
- $this->pag_links = paginate_links( array(
98
- 'base' => add_query_arg( array( 'p' => '%#%', 'n' => $this->pag_num ) ),
99
- 'format' => '',
100
- 'total' => ceil($this->total_topic_count / $this->pag_num),
101
- 'current' => $this->pag_page,
102
- 'prev_text' => '&larr;',
103
- 'next_text' => '&rarr;',
104
- 'mid_size' => 1
105
- ));
106
- }
107
-
108
- function has_topics() {
109
- if ( $this->topic_count )
110
- return true;
111
-
112
- return false;
113
- }
114
-
115
- function next_topic() {
116
- $this->current_topic++;
117
- $this->topic = $this->topics[$this->current_topic];
118
-
119
- return $this->topic;
120
- }
121
-
122
- function rewind_topics() {
123
- $this->current_topic = -1;
124
- if ( $this->topic_count > 0 ) {
125
- $this->topic = $this->topics[0];
126
- }
127
- }
128
-
129
- function user_topics() {
130
- if ( $this->current_topic + 1 < $this->topic_count ) {
131
- return true;
132
- } elseif ( $this->current_topic + 1 == $this->topic_count ) {
133
- do_action('loop_end');
134
- // Do some cleaning up after the loop
135
- $this->rewind_topics();
136
- }
137
-
138
- $this->in_the_loop = false;
139
- return false;
140
- }
141
-
142
- function the_topic() {
143
- global $topic;
144
-
145
- $this->in_the_loop = true;
146
- $this->topic = $this->next_topic();
147
- $this->topic = (object)$this->topic;
148
-
149
- if ( $this->current_topic == 0 ) // loop has just started
150
- do_action('loop_start');
151
- }
152
- }
153
-
154
- function bp_has_forum_topics( $args = '' ) {
155
- global $forum_template, $bp;
156
-
157
- /***
158
- * Set the defaults based on the current page. Any of these will be overridden
159
- * if arguments are directly passed into the loop. Custom plugins should always
160
- * pass their parameters directly to the loop.
161
- */
162
- $type = 'newest';
163
- $user_id = false;
164
- $forum_id = false;
165
- $search_terms = false;
166
- $no_stickies = 'all';
167
-
168
- /* User filtering */
169
- if ( !empty( $bp->displayed_user->id ) )
170
- $user_id = $bp->displayed_user->id;
171
-
172
- /* If we're in a single group, set this group's forum_id */
173
- if ( !$forum_id && $bp->groups->current_group ) {
174
- $bp->groups->current_group->forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' );
175
-
176
- /* If it turns out there is no forum for this group, return false so we don't fetch all global topics */
177
- if ( !$bp->groups->current_group->forum_id )
178
- return false;
179
-
180
- $forum_id = $bp->groups->current_group->forum_id;
181
- }
182
-
183
- /* If $_GET['fs'] is set, let's auto populate the search_terms var */
184
- if ( $bp->is_directory && !empty( $_GET['fs'] ) )
185
- $search_terms = $_GET['fs'];
186
-
187
- /* Show stickies on a group forum */
188
- if ( $bp->groups->current_group )
189
- $no_stickies = null;
190
-
191
- $defaults = array(
192
- 'type' => $type,
193
- 'forum_id' => $forum_id,
194
- 'user_id' => $user_id,
195
- 'page' => 1,
196
- 'per_page' => 20,
197
- 'max' => false,
198
- 'no_stickies' => $no_stickies,
199
- 'search_terms' => $search_terms
200
- );
201
-
202
- $r = wp_parse_args( $args, $defaults );
203
- extract( $r );
204
-
205
- /* If we're viewing a tag URL in the directory, let's override the type and set it to tags and the filter to the tag name */
206
- if ( 'tag' == $bp->current_action && !empty( $bp->action_variables[0] ) ) {
207
- $search_terms = $bp->action_variables[0];
208
- $type = 'tags';
209
- }
210
-
211
- $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms );
212
- return apply_filters( 'bp_has_topics', $forum_template->has_topics(), &$forum_template );
213
- }
214
-
215
- function bp_forum_topics() {
216
- global $forum_template;
217
- return $forum_template->user_topics();
218
- }
219
-
220
- function bp_the_forum_topic() {
221
- global $forum_template;
222
- return $forum_template->the_topic();
223
- }
224
-
225
- function bp_the_topic_id() {
226
- echo bp_get_the_topic_id();
227
- }
228
- function bp_get_the_topic_id() {
229
- global $forum_template;
230
-
231
- return apply_filters( 'bp_get_the_topic_id', $forum_template->topic->topic_id );
232
- }
233
-
234
- function bp_the_topic_title() {
235
- echo bp_get_the_topic_title();
236
- }
237
- function bp_get_the_topic_title() {
238
- global $forum_template;
239
-
240
- return apply_filters( 'bp_get_the_topic_title', stripslashes( $forum_template->topic->topic_title ) );
241
- }
242
-
243
- function bp_the_topic_slug() {
244
- echo bp_get_the_topic_slug();
245
- }
246
- function bp_get_the_topic_slug() {
247
- global $forum_template;
248
-
249
- return apply_filters( 'bp_get_the_topic_slug', $forum_template->topic->topic_slug );
250
- }
251
-
252
- function bp_the_topic_text() {
253
- echo bp_get_the_topic_text();
254
- }
255
- function bp_get_the_topic_text() {
256
- global $forum_template;
257
-
258
- $post = bb_get_first_post( (int)$forum_template->topic->topic_id, false );
259
- return apply_filters( 'bp_get_the_topic_text', attribute_escape( $post->post_text ) );
260
- }
261
-
262
- function bp_the_topic_poster_id() {
263
- echo bp_get_the_topic_poster_id();
264
- }
265
- function bp_get_the_topic_poster_id() {
266
- global $forum_template;
267
-
268
- return apply_filters( 'bp_get_the_topic_poster_id', $forum_template->topic->topic_poster );
269
- }
270
-
271
- function bp_the_topic_poster_avatar( $args = '' ) {
272
- echo bp_get_the_topic_poster_avatar( $args );
273
- }
274
- function bp_get_the_topic_poster_avatar( $args = '' ) {
275
- global $forum_template;
276
-
277
- $defaults = array(
278
- 'type' => 'thumb',
279
- 'width' => false,
280
- 'height' => false,
281
- );
282
-
283
- $r = wp_parse_args( $args, $defaults );
284
- extract( $r, EXTR_SKIP );
285
-
286
- return apply_filters( 'bp_get_the_topic_poster_avatar', bp_core_fetch_avatar( array( 'item_id' => $forum_template->topic->topic_poster, 'type' => $type, 'width' => $width, 'height' => $height ) ) );
287
- }
288
-
289
- function bp_the_topic_poster_name() {
290
- echo bp_get_the_topic_poster_name();
291
- }
292
- function bp_get_the_topic_poster_name() {
293
- global $forum_template;
294
-
295
- $poster_id = ( empty( $forum_template->topic->poster_id ) ) ? $forum_template->topic->topic_poster : $forum_template->topic->poster_id;
296
-
297
- if ( !$name = bp_core_get_userlink( $poster_id ) )
298
- return __( 'Deleted User', 'buddypress' );
299
-
300
- return apply_filters( 'bp_get_the_topic_poster_name', $name );
301
- }
302
-
303
- function bp_the_topic_object_id() {
304
- echo bp_get_the_topic_object_id();
305
- }
306
- function bp_get_the_topic_object_id() {
307
- global $forum_template;
308
-
309
- return apply_filters( 'bp_get_the_topic_object_id', $forum_template->topic->object_id );
310
- }
311
-
312
- function bp_the_topic_object_name() {
313
- echo bp_get_the_topic_object_name();
314
- }
315
- function bp_get_the_topic_object_name() {
316
- global $forum_template;
317
-
318
- return apply_filters( 'bp_get_the_topic_object_name', $forum_template->topic->object_name );
319
- }
320
-
321
- function bp_the_topic_object_slug() {
322
- echo bp_get_the_topic_object_slug();
323
- }
324
- function bp_get_the_topic_object_slug() {
325
- global $forum_template;
326
-
327
- return apply_filters( 'bp_get_the_topic_object_slug', $forum_template->topic->object_slug );
328
- }
329
-
330
- function bp_the_topic_object_permalink() {
331
- echo bp_get_the_topic_object_permalink();
332
- }
333
- function bp_get_the_topic_object_permalink() {
334
- global $bp, $forum_template;
335
-
336
- /* Currently this will only work with group forums, extended support in the future */
337
- return apply_filters( 'bp_get_the_topic_object_permalink', $bp->root_domain . '/' . BP_GROUPS_SLUG . '/' . $forum_template->topic->object_slug . '/forum/' );
338
- }
339
-
340
- function bp_the_topic_last_poster_name() {
341
- echo bp_get_the_topic_last_poster_name();
342
- }
343
- function bp_get_the_topic_last_poster_name() {
344
- global $forum_template;
345
-
346
- if ( !$domain = bp_core_get_user_domain( $forum_template->topic->topic_last_poster, $forum_template->topic->topic_last_poster_nicename, $forum_template->topic->topic_last_poster_login ) )
347
- return __( 'Deleted User', 'buddypress' );
348
-
349
- return apply_filters( 'bp_get_the_topic_last_poster_name', '<a href="' . $domain . '">' . $forum_template->topic->topic_last_poster_displayname . '</a>' );
350
- }
351
-
352
- function bp_the_topic_object_avatar( $args = '' ) {
353
- echo bp_get_the_topic_object_avatar( $args );
354
- }
355
- function bp_get_the_topic_object_avatar( $args = '' ) {
356
- global $forum_template;
357
-
358
- $defaults = array(
359
- 'type' => 'thumb',
360
- 'width' => false,
361
- 'height' => false,
362
- );
363
-
364
- $r = wp_parse_args( $args, $defaults );
365
- extract( $r, EXTR_SKIP );
366
-
367
- return apply_filters( 'bp_get_the_topic_object_avatar', bp_core_fetch_avatar( array( 'item_id' => $forum_template->topic->object_id, 'type' => $type, 'object' => 'group', 'width' => $width, 'height' => $height ) ) );
368
- }
369
-
370
- function bp_the_topic_last_poster_avatar( $args = '' ) {
371
- echo bp_get_the_topic_last_poster_avatar( $args );
372
- }
373
- function bp_get_the_topic_last_poster_avatar( $args = '' ) {
374
- global $forum_template;
375
-
376
- $defaults = array(
377
- 'type' => 'thumb',
378
- 'width' => false,
379
- 'height' => false,
380
- );
381
-
382
- $r = wp_parse_args( $args, $defaults );
383
- extract( $r, EXTR_SKIP );
384
-
385
- return apply_filters( 'bp_get_the_topic_last_poster_avatar', bp_core_fetch_avatar( array( 'email' => $forum_template->topic->topic_last_poster_email, 'item_id' => $forum_template->topic->topic_last_poster, 'type' => $type, 'width' => $width, 'height' => $height ) ) );
386
- }
387
-
388
- function bp_the_topic_start_time() {
389
- echo bp_get_the_topic_start_time();
390
- }
391
- function bp_get_the_topic_start_time() {
392
- global $forum_template;
393
-
394
- return apply_filters( 'bp_get_the_topic_start_time', $forum_template->topic->topic_start_time );
395
- }
396
-
397
- function bp_the_topic_time() {
398
- echo bp_get_the_topic_time();
399
- }
400
- function bp_get_the_topic_time() {
401
- global $forum_template;
402
-
403
- return apply_filters( 'bp_get_the_topic_time', $forum_template->topic->topic_time );
404
- }
405
-
406
- function bp_the_topic_forum_id() {
407
- echo bp_get_the_topic_forum_id();
408
- }
409
- function bp_get_the_topic_forum_id() {
410
- global $forum_template;
411
-
412
- return apply_filters( 'bp_get_the_topic_forum_id', $forum_template->topic->topic_forum_id );
413
- }
414
-
415
- function bp_the_topic_status() {
416
- echo bp_get_the_topic_status();
417
- }
418
- function bp_get_the_topic_status() {
419
- global $forum_template;
420
-
421
- return apply_filters( 'bp_get_the_topic_status', $forum_template->topic->topic_status );
422
- }
423
-
424
- function bp_the_topic_is_topic_open() {
425
- echo bp_get_the_topic_is_topic_open();
426
- }
427
- function bp_get_the_topic_is_topic_open() {
428
- global $forum_template;
429
-
430
- return apply_filters( 'bp_get_the_topic_is_topic_open', $forum_template->topic->topic_open );
431
- }
432
-
433
- function bp_the_topic_last_post_id() {
434
- echo bp_get_the_topic_last_post_id();
435
- }
436
- function bp_get_the_topic_last_post_id() {
437
- global $forum_template;
438
-
439
- return apply_filters( 'bp_get_the_topic_last_post_id', $forum_template->topic->topic_last_post_id );
440
- }
441
-
442
- function bp_the_topic_is_sticky() {
443
- echo bp_get_the_topic_is_sticky();
444
- }
445
- function bp_get_the_topic_is_sticky() {
446
- global $forum_template;
447
-
448
- return apply_filters( 'bp_get_the_topic_is_sticky', $forum_template->topic->topic_sticky );
449
- }
450
-
451
- function bp_the_topic_total_post_count() {
452
- echo bp_get_the_topic_total_post_count();
453
- }
454
- function bp_get_the_topic_total_post_count() {
455
- global $forum_template;
456
-
457
- if ( $forum_template->topic->topic_posts == 1 )
458
- return apply_filters( 'bp_get_the_topic_total_post_count', sprintf( __( '%d post', 'buddypress' ), $forum_template->topic->topic_posts ) );
459
- else
460
- return apply_filters( 'bp_get_the_topic_total_post_count', sprintf( __( '%d posts', 'buddypress' ), $forum_template->topic->topic_posts ) );
461
- }
462
-
463
- function bp_the_topic_total_posts() {
464
- echo bp_get_the_topic_total_posts();
465
- }
466
- function bp_get_the_topic_total_posts() {
467
- global $forum_template;
468
-
469
- return apply_filters( 'bp_get_the_topic_total_posts', $forum_template->topic->topic_posts );
470
- }
471
-
472
- function bp_the_topic_tag_count() {
473
- echo bp_get_the_topic_tag_count();
474
- }
475
- function bp_get_the_topic_tag_count() {
476
- global $forum_template;
477
-
478
- return apply_filters( 'bp_get_the_topic_tag_count', $forum_template->topic->tag_count );
479
- }
480
-
481
- function bp_the_topic_permalink() {
482
- echo bp_get_the_topic_permalink();
483
- }
484
- function bp_get_the_topic_permalink() {
485
- global $forum_template, $bp;
486
-
487
- if ( $forum_template->topic->object_slug )
488
- $permalink = $bp->root_domain . '/' . BP_GROUPS_SLUG . '/' . $forum_template->topic->object_slug . '/';
489
- else if ( $bp->is_single_item )
490
- $permalink = $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_item . '/';
491
- else
492
- $permalink = $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_action . '/';
493
-
494
- return apply_filters( 'bp_get_the_topic_permalink', $permalink . 'forum/topic/' . $forum_template->topic->topic_slug . '/' );
495
- }
496
-
497
- function bp_the_topic_time_since_created() {
498
- echo bp_get_the_topic_time_since_created();
499
- }
500
- function bp_get_the_topic_time_since_created() {
501
- global $forum_template;
502
-
503
- return apply_filters( 'bp_get_the_topic_time_since_created', bp_core_time_since( strtotime( $forum_template->topic->topic_start_time ) ) );
504
- }
505
-
506
- function bp_the_topic_latest_post_excerpt( $args = '' ) {
507
- echo bp_get_the_topic_latest_post_excerpt( $args );
508
- }
509
- function bp_get_the_topic_latest_post_excerpt( $args = '' ) {
510
- global $forum_template;
511
-
512
- $defaults = array(
513
- 'length' => 10
514
- );
515
-
516
- $r = wp_parse_args( $args, $defaults );
517
- extract( $r, EXTR_SKIP );
518
-
519
- $post = bp_forums_get_post( $forum_template->topic->topic_last_post_id );
520
- $post = bp_create_excerpt( $post->post_text, $length );
521
- return apply_filters( 'bp_get_the_topic_latest_post_excerpt', $post );
522
- }
523
-
524
- function bp_the_topic_time_since_last_post() {
525
- global $forum_template;
526
-
527
- echo bp_get_the_topic_time_since_last_post();
528
- }
529
- function bp_get_the_topic_time_since_last_post() {
530
- global $forum_template;
531
-
532
- return apply_filters( 'bp_get_the_topic_time_since_last_post', bp_core_time_since( strtotime( $forum_template->topic->topic_time ) ) );
533
- }
534
-
535
- function bp_the_topic_is_mine() {
536
- echo bp_get_the_topic_is_mine();
537
- }
538
- function bp_get_the_topic_is_mine() {
539
- global $bp, $forum_template;
540
-
541
- return $bp->loggedin_user->id == $forum_template->topic->topic_poster;
542
- }
543
-
544
- function bp_the_topic_admin_links( $args = '' ) {
545
- echo bp_get_the_topic_admin_links( $args );
546
- }
547
- function bp_get_the_topic_admin_links( $args = '' ) {
548
- global $bp, $forum_template;
549
-
550
- $defaults = array(
551
- 'seperator' => '|'
552
- );
553
-
554
- $r = wp_parse_args( $args, $defaults );
555
- extract( $r, EXTR_SKIP );
556
-
557
- $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'edit', 'bp_forums_edit_topic' ) . '">' . __( 'Edit Topic', 'buddypress' ) . '</a>';
558
-
559
- if ( $bp->is_item_admin || $bp->is_item_mod || is_site_admin() ) {
560
- if ( 0 == (int)$forum_template->topic->topic_sticky )
561
- $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'stick', 'bp_forums_stick_topic' ) . '">' . __( 'Sticky Topic', 'buddypress' ) . '</a>';
562
- else
563
- $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'unstick', 'bp_forums_unstick_topic' ) . '">' . __( 'Un-stick Topic', 'buddypress' ) . '</a>';
564
-
565
- if ( 0 == (int)$forum_template->topic->topic_open )
566
- $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'open', 'bp_forums_open_topic' ) . '">' . __( 'Open Topic', 'buddypress' ) . '</a>';
567
- else
568
- $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'close', 'bp_forums_close_topic' ) . '">' . __( 'Close Topic', 'buddypress' ) . '</a>';
569
-
570
- $links[] = '<a class="confirm" id="topic-delete-link" href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'delete', 'bp_forums_delete_topic' ) . '">' . __( 'Delete Topic', 'buddypress' ) . '</a>';
571
- }
572
-
573
- return implode( ' ' . $seperator . ' ', (array) $links );
574
- }
575
-
576
- function bp_the_topic_css_class() {
577
- echo bp_get_the_topic_css_class();
578
- }
579
-
580
- function bp_get_the_topic_css_class() {
581
- global $forum_template;
582
-
583
- $class = false;
584
-
585
- if ( $forum_template->current_topic % 2 == 1 )
586
- $class .= 'alt';
587
-
588
- if ( 1 == (int)$forum_template->topic->topic_sticky )
589
- $class .= ' sticky';
590
-
591
- if ( 0 == (int)$forum_template->topic->topic_open )
592
- $class .= ' closed';
593
-
594
- return apply_filters( 'bp_get_the_topic_css_class', trim( $class ) );
595
- }
596
-
597
- function bp_my_forum_topics_link() {
598
- echo bp_get_my_forum_topics_link();
599
- }
600
- function bp_get_my_forum_topics_link() {
601
- global $bp;
602
-
603
- return apply_filters( 'bp_get_my_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/personal/' );
604
- }
605
-
606
- function bp_unreplied_forum_topics_link() {
607
- echo bp_get_unreplied_forum_topics_link();
608
- }
609
- function bp_get_unreplied_forum_topics_link() {
610
- global $bp;
611
-
612
- return apply_filters( 'bp_get_unreplied_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/unreplied/' );
613
- }
614
-
615
-
616
- function bp_popular_forum_topics_link() {
617
- echo bp_get_popular_forum_topics_link();
618
- }
619
- function bp_get_popular_forum_topics_link() {
620
- global $bp;
621
-
622
- return apply_filters( 'bp_get_popular_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/popular/' );
623
- }
624
-
625
- function bp_newest_forum_topics_link() {
626
- echo bp_get_newest_forum_topics_link();
627
- }
628
- function bp_get_newest_forum_topics_link() {
629
- global $bp;
630
-
631
- return apply_filters( 'bp_get_newest_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/' );
632
- }
633
-
634
- function bp_forum_topic_type() {
635
- echo bp_get_forum_topic_type();
636
- }
637
- function bp_get_forum_topic_type() {
638
- global $bp;
639
-
640
- if ( !$bp->is_directory || !$bp->current_action )
641
- return 'newest';
642
-
643
-
644
- return apply_filters( 'bp_get_forum_topic_type', $bp->current_action );
645
- }
646
-
647
- function bp_forums_tag_name() {
648
- echo bp_get_forums_tag_name();
649
- }
650
- function bp_get_forums_tag_name() {
651
- global $bp;
652
-
653
- if ( $bp->is_directory && $bp->forums->slug == $bp->current_component )
654
- return apply_filters( 'bp_get_forums_tag_name', $bp->action_variables[0] );
655
- }
656
-
657
- function bp_forum_pagination() {
658
- echo bp_get_forum_pagination();
659
- }
660
- function bp_get_forum_pagination() {
661
- global $forum_template;
662
-
663
- return apply_filters( 'bp_get_forum_pagination', $forum_template->pag_links );
664
- }
665
-
666
- function bp_forum_pagination_count() {
667
- global $bp, $forum_template;
668
-
669
- $start_num = intval( ( $forum_template->pag_page - 1 ) * $forum_template->pag_num ) + 1;
670
- $from_num = bp_core_number_format( $start_num );
671
- $to_num = bp_core_number_format( ( $start_num + ( $forum_template->pag_num - 1 ) > $forum_template->total_topic_count ) ? $forum_template->total_topic_count : $start_num + ( $forum_template->pag_num - 1 ) );
672
- $total = bp_core_number_format( $forum_template->total_topic_count );
673
-
674
- $pag_filter = false;
675
- if ( 'tags' == $forum_template->type && !empty( $forum_template->search_terms ) )
676
- $pag_filter = sprintf( __( ' matching tag "%s"', 'buddypress' ), $forum_template->search_terms );
677
-
678
- echo apply_filters( 'bp_forum_pagination_count', sprintf( __( 'Viewing topic %1$s to %2$s (%3$s total topics%4$s)', 'buddypress' ), $from_num, $to_num, $total, $pag_filter ) );
679
- ?>
680
- <span class="ajax-loader"></span>
681
- <?php
682
- }
683
-
684
- function bp_is_edit_topic() {
685
- global $bp;
686
-
687
- if ( in_array( 'post', (array)$bp->action_variables ) && in_array( 'edit', (array)$bp->action_variables ) )
688
- return false;
689
-
690
- return true;
691
- }
692
-
693
-
694
- class BP_Forums_Template_Topic {
695
- var $current_post = -1;
696
- var $post_count;
697
- var $posts;
698
- var $post;
699
-
700
- var $forum_id;
701
- var $topic_id;
702
- var $topic;
703
-
704
- var $in_the_loop;
705
-
706
- var $pag_page;
707
- var $pag_num;
708
- var $pag_links;
709
- var $total_post_count;
710
-
711
- var $single_post = false;
712
-
713
- var $sort_by;
714
- var $order;
715
-
716
- function BP_Forums_Template_Topic( $topic_id, $per_page, $max ) {
717
- global $bp, $current_user, $forum_template;
718
-
719
- $this->pag_page = isset( $_REQUEST['topic_page'] ) ? intval( $_REQUEST['topic_page'] ) : 1;
720
- $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
721
-
722
- $this->topic_id = $topic_id;
723
- $forum_template->topic = (object) bp_forums_get_topic_details( $this->topic_id );
724
- $this->forum_id = $forum_template->topic->forum_id;
725
-
726
- $this->posts = bp_forums_get_topic_posts( array( 'topic_id' => $this->topic_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num ) );
727
-
728
- if ( !$this->posts ) {
729
- $this->post_count = 0;
730
- $this->total_post_count = 0;
731
- } else {
732
- if ( !$max || $max >= (int) $forum_template->topic->topic_posts )
733
- $this->total_post_count = (int) $forum_template->topic->topic_posts;
734
- else
735
- $this->total_post_count = (int)$max;
736
-
737
- if ( $max ) {
738
- if ( $max >= count($this->posts) )
739
- $this->post_count = count( $this->posts );
740
- else
741
- $this->post_count = (int)$max;
742
- } else {
743
- $this->post_count = count( $this->posts );
744
- }
745
- }
746
-
747
- $this->pag_links = paginate_links( array(
748
- 'base' => add_query_arg( array( 'topic_page' => '%#%', 'num' => $this->pag_num ) ),
749
- 'format' => '',
750
- 'total' => ceil($this->total_post_count / $this->pag_num),
751
- 'current' => $this->pag_page,
752
- 'prev_text' => '&larr;',
753
- 'next_text' => '&rarr;',
754
- 'mid_size' => 1
755
- ));
756
- $this->pag->total_pages = ceil($this->total_post_count / $this->pag_num);
757
- }
758
-
759
- function has_posts() {
760
- if ( $this->post_count )
761
- return true;
762
-
763
- return false;
764
- }
765
-
766
- function next_post() {
767
- $this->current_post++;
768
- $this->post = $this->posts[$this->current_post];
769
-
770
- return $this->post;
771
- }
772
-
773
- function rewind_posts() {
774
- $this->current_post = -1;
775
- if ( $this->post_count > 0 ) {
776
- $this->post = $this->posts[0];
777
- }
778
- }
779
-
780
- function user_posts() {
781
- if ( $this->current_post + 1 < $this->post_count ) {
782
- return true;
783
- } elseif ( $this->current_post + 1 == $this->post_count ) {
784
- do_action('loop_end');
785
- // Do some cleaning up after the loop
786
- $this->rewind_posts();
787
- }
788
-
789
- $this->in_the_loop = false;
790
- return false;
791
- }
792
-
793
- function the_post() {
794
- global $post;
795
-
796
- $this->in_the_loop = true;
797
- $this->post = $this->next_post();
798
- $this->post = (object)$this->post;
799
-
800
- if ( $this->current_post == 0 ) // loop has just started
801
- do_action('loop_start');
802
- }
803
- }
804
-
805
- function bp_has_forum_topic_posts( $args = '' ) {
806
- global $topic_template, $bp;
807
-
808
- $defaults = array(
809
- 'topic_id' => false,
810
- 'per_page' => 15,
811
- 'max' => false
812
- );
813
-
814
- $r = wp_parse_args( $args, $defaults );
815
- extract( $r, EXTR_SKIP );
816
-
817
- if ( !$topic_id && $bp->current_component == $bp->groups->slug && 'forum' == $bp->current_action && 'topic' == $bp->action_variables[0] )
818
- $topic_id = bp_forums_get_topic_id_from_slug( $bp->action_variables[1] );
819
-
820
- if ( is_numeric( $topic_id ) ) {
821
- $topic_template = new BP_Forums_Template_Topic( $topic_id, $per_page, $max );
822
-
823
- // Current topic forum_id needs to match current_group forum_id
824
- if ( $bp->current_component == $bp->groups->slug && $topic_template->forum_id != groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' ) )
825
- return false;
826
-
827
- } else {
828
- return false;
829
- }
830
-
831
- return apply_filters( 'bp_has_topic_posts', $topic_template->has_posts(), &$topic_template );
832
- }
833
-
834
- function bp_forum_topic_posts() {
835
- global $topic_template;
836
- return $topic_template->user_posts();
837
- }
838
-
839
- function bp_the_forum_topic_post() {
840
- global $topic_template;
841
- return $topic_template->the_post();
842
- }
843
-
844
- function bp_the_topic_post_id() {
845
- echo bp_get_the_topic_post_id();
846
- }
847
- function bp_get_the_topic_post_id() {
848
- global $topic_template;
849
-
850
- return apply_filters( 'bp_get_the_topic_post_id', $topic_template->post->post_id );
851
- }
852
-
853
- function bp_the_topic_post_content() {
854
- echo bp_get_the_topic_post_content();
855
- }
856
- function bp_get_the_topic_post_content() {
857
- global $topic_template;
858
-
859
- return apply_filters( 'bp_get_the_topic_post_content', stripslashes( $topic_template->post->post_text ) );
860
- }
861
-
862
- function bp_the_topic_post_css_class() {
863
- echo bp_get_the_topic_post_css_class();
864
- }
865
-
866
- function bp_get_the_topic_post_css_class() {
867
- global $topic_template;
868
-
869
- $class = false;
870
-
871
- if ( $topic_template->current_post % 2 == 1 )
872
- $class .= 'alt';
873
-
874
- if ( 1 == (int)$topic_template->post->post_status )
875
- $class .= ' deleted';
876
-
877
- if ( 0 == (int)$topic_template->post->post_status )
878
- $class .= ' open';
879
-
880
- return apply_filters( 'bp_get_the_topic_post_css_class', trim( $class ) );
881
- }
882
-
883
- function bp_the_topic_post_poster_avatar( $args = '' ) {
884
- echo bp_get_the_topic_post_poster_avatar( $args );
885
- }
886
- function bp_get_the_topic_post_poster_avatar( $args = '' ) {
887
- global $topic_template;
888
-
889
- $defaults = array(
890
- 'type' => 'thumb',
891
- 'width' => 20,
892
- 'height' => 20,
893
- );
894
-
895
- $r = wp_parse_args( $args, $defaults );
896
- extract( $r, EXTR_SKIP );
897
-
898
- return apply_filters( 'bp_get_the_topic_post_poster_avatar', bp_core_fetch_avatar( array( 'item_id' => $topic_template->post->poster_id, 'type' => $type, 'width' => $width, 'height' => $height ) ) );
899
- }
900
-
901
- function bp_the_topic_post_poster_name() {
902
- echo bp_get_the_topic_post_poster_name();
903
- }
904
- function bp_get_the_topic_post_poster_name() {
905
- global $topic_template;
906
-
907
- if ( !$link = bp_core_get_user_domain( $topic_template->post->poster_id, $topic_template->post->poster_nicename, $topic_template->post->poster_login ) )
908
- return __( 'Deleted User', 'buddypress' );
909
-
910
- return apply_filters( 'bp_get_the_topic_post_poster_name', '<a href="' . $link . '" title="' . $topic_template->post->poster_name . '">' . $topic_template->post->poster_name . '</a>' );
911
- }
912
-
913
- function bp_the_topic_post_poster_link() {
914
- echo bp_get_the_topic_post_poster_link();
915
- }
916
- function bp_get_the_topic_post_poster_link() {
917
- global $topic_template;
918
-
919
- return apply_filters( 'bp_the_topic_post_poster_link', bp_core_get_user_domain( $topic_template->post->poster_id, $topic_template->post->poster_nicename, $topic_template->post->poster_login ) );
920
- }
921
-
922
- function bp_the_topic_post_time_since() {
923
- echo bp_get_the_topic_post_time_since();
924
- }
925
- function bp_get_the_topic_post_time_since() {
926
- global $topic_template;
927
-
928
- return apply_filters( 'bp_get_the_topic_post_time_since', bp_core_time_since( strtotime( $topic_template->post->post_time ) ) );
929
- }
930
-
931
- function bp_the_topic_post_is_mine() {
932
- echo bp_the_topic_post_is_mine();
933
- }
934
- function bp_get_the_topic_post_is_mine() {
935
- global $bp, $topic_template;
936
-
937
- return $bp->loggedin_user->id == $topic_template->post->poster_id;
938
- }
939
-
940
- function bp_the_topic_post_admin_links( $args = '' ) {
941
- echo bp_get_the_topic_post_admin_links( $args );
942
- }
943
- function bp_get_the_topic_post_admin_links( $args = '' ) {
944
- global $topic_template;
945
-
946
- /* Never show for the first post in a topic. */
947
- if ( 0 == $topic_template->current_post && $topic_template->pag_page == 1 )
948
- return;
949
-
950
- $defaults = array(
951
- 'seperator' => '|'
952
- );
953
-
954
- $r = wp_parse_args( $args, $defaults );
955
- extract( $r, EXTR_SKIP );
956
-
957
- if ( $_SERVER['QUERY_STRING'] )
958
- $query_vars = '?' . $_SERVER['QUERY_STRING'];
959
-
960
- $links = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . $topic_template->post->id . 'edit/post/' . $topic_template->post->post_id . '/' . $query_vars, 'bp_forums_edit_post' ) . '">' . __( 'Edit', 'buddypress' ) . '</a> ' . $seperator . ' ';
961
- $links .= '<a class="confirm" id="post-delete-link" href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'delete/post/' . $topic_template->post->post_id, 'bp_forums_delete_post' ) . '">' . __( 'Delete', 'buddypress' ) . '</a> | ';
962
-
963
- return $links;
964
- }
965
-
966
- function bp_the_topic_post_edit_text() {
967
- echo bp_get_the_topic_post_edit_text();
968
- }
969
- function bp_get_the_topic_post_edit_text() {
970
- global $bp;
971
-
972
- $post = bp_forums_get_post( $bp->action_variables[4] );
973
- return apply_filters( 'bp_get_the_topic_post_edit_text', attribute_escape( $post->post_text ) );
974
- }
975
-
976
- function bp_the_topic_pagination() {
977
- echo bp_get_the_topic_pagination();
978
- }
979
- function bp_get_the_topic_pagination() {
980
- global $topic_template;
981
-
982
- return apply_filters( 'bp_get_the_topic_pagination', $topic_template->pag_links );
983
- }
984
-
985
- function bp_the_topic_pagination_count() {
986
- global $bp, $topic_template;
987
-
988
- $start_num = intval( ( $topic_template->pag_page - 1 ) * $topic_template->pag_num ) + 1;
989
- $from_num = bp_core_number_format( $start_num );
990
- $to_num = bp_core_number_format( ( $start_num + ( $topic_template->pag_num - 1 ) > $topic_template->total_post_count ) ? $topic_template->total_post_count : $start_num + ( $topic_template->pag_num - 1 ) );
991
- $total = bp_core_number_format( $topic_template->total_post_count );
992
-
993
- echo apply_filters( 'bp_the_topic_pagination_count', sprintf( __( 'Viewing post %1$s to %2$s (%3$s total posts)', 'buddypress' ), $from_num, $to_num, $total ) );
994
- ?>
995
- <span class="ajax-loader"></span>
996
- <?php
997
- }
998
-
999
- function bp_the_topic_is_last_page() {
1000
- echo bp_get_the_topic_is_last_page();
1001
- }
1002
- function bp_get_the_topic_is_last_page() {
1003
- global $topic_template;
1004
-
1005
- return apply_filters( 'bp_get_the_topic_is_last_page', $topic_template->pag_page == $topic_template->pag->total_pages );
1006
- }
1007
-
1008
- function bp_directory_forums_search_form() {
1009
- global $bp;
1010
-
1011
- $search_value = __( 'Search anything...', 'buddypress' );
1012
- if ( !empty( $_REQUEST['fs'] ) )
1013
- $search_value = $_REQUEST['fs'];
1014
-
1015
- ?>
1016
- <form action="" method="get" id="search-forums-form">
1017
- <label><input type="text" name="s" id="forums_search" value="<?php echo attribute_escape($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>
1018
- <input type="submit" id="forums_search_submit" name="forums_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
1019
- </form>
1020
- <?php
1021
- }
1022
- function bp_forum_permalink() {
1023
- echo bp_get_forum_permalink();
1024
- }
1025
- function bp_get_forum_permalink() {
1026
- global $bp;
1027
-
1028
- if ( $bp->is_single_item )
1029
- $permalink = $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_item . '/';
1030
- else
1031
- $permalink = $bp->root_domain . $bp->current_component . '/' . $bp->current_action . '/';
1032
-
1033
- return apply_filters( 'bp_get_forum_permalink', $permalink . 'forum' );
1034
- }
1035
-
1036
- function bp_forum_directory_permalink() {
1037
- echo bp_get_forum_directory_permalink();
1038
- }
1039
- function bp_get_forum_directory_permalink() {
1040
- global $bp;
1041
-
1042
- return apply_filters( 'bp_get_forum_directory_permalink', $bp->root_domain . '/' . $bp->forums->slug );
1043
- }
1044
-
1045
- function bp_forums_tag_heat_map( $args = '' ) {
1046
- $defaults = array(
1047
- 'smallest' => '10',
1048
- 'largest' => '42',
1049
- 'sizing' => 'px',
1050
- 'limit' => '50'
1051
- );
1052
-
1053
- $r = wp_parse_args( $args, $defaults );
1054
- extract( $r, EXTR_SKIP );
1055
-
1056
- bb_tag_heat_map( $smallest, $largest, $sizing, $limit );
1057
- }
1058
-
1059
- function bp_forum_action() {
1060
- echo bp_get_forum_action();
1061
- }
1062
- function bp_get_forum_action() {
1063
- global $topic_template;
1064
-
1065
- return apply_filters( 'bp_get_forum_action', $bp->root_domain . attribute_escape( $_SERVER['REQUEST_URI'] ) );
1066
- }
1067
-
1068
- function bp_forum_topic_action() {
1069
- echo bp_get_forum_topic_action();
1070
- }
1071
- function bp_get_forum_topic_action() {
1072
- global $bp;
1073
-
1074
- return apply_filters( 'bp_get_forum_topic_action', $bp->root_domain . attribute_escape( $_SERVER['REQUEST_URI'] ) );
1075
- }
1076
-
1077
- function bp_forum_topic_count_for_user( $user_id = false ) {
1078
- echo bp_get_forum_topic_count_for_user( $user_id );
1079
- }
1080
- function bp_get_forum_topic_count_for_user( $user_id = false ) {
1081
- return apply_filters( 'bp_get_forum_topic_count_for_user', bp_forums_total_topic_count_for_user( $user_id ) );
1082
- }
1083
-
1084
- function bp_forum_topic_count( $user_id = false ) {
1085
- echo bp_get_forum_topic_count( $user_id );
1086
- }
1087
- function bp_get_forum_topic_count( $user_id = false ) {
1088
- return apply_filters( 'bp_get_forum_topic_count', bp_forums_total_topic_count( $user_id ) );
1089
- }
1090
  ?>
1
+ <?php
2
+
3
+ class BP_Forums_Template_Forum {
4
+ var $current_topic = -1;
5
+ var $topic_count;
6
+ var $topics;
7
+ var $topic;
8
+
9
+ var $forum_id;
10
+
11
+ var $in_the_loop;
12
+
13
+ var $pag_page;
14
+ var $pag_num;
15
+ var $pag_links;
16
+ var $total_topic_count;
17
+
18
+ var $single_topic = false;
19
+
20
+ var $sort_by;
21
+ var $order;
22
+
23
+ function BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms ) {
24
+ global $bp;
25
+
26
+ $this->pag_page = isset( $_REQUEST['p'] ) ? intval( $_REQUEST['p'] ) : $page;
27
+ $this->pag_num = isset( $_REQUEST['n'] ) ? intval( $_REQUEST['n'] ) : $per_page;
28
+ $this->type = $type;
29
+ $this->search_terms = $search_terms;
30
+ $this->forum_id = $forum_id;
31
+
32
+ switch ( $type ) {
33
+ case 'newest': default:
34
+ $this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'forum_id' => $forum_id, 'filter' => $search_terms, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies ) );
35
+ break;
36
+
37
+ case 'popular':
38
+ $this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'type' => 'popular', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies ) );
39
+ break;
40
+
41
+ case 'unreplied':
42
+ $this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'type' => 'unreplied', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies ) );
43
+ break;
44
+
45
+ case 'tags':
46
+ $this->topics = bp_forums_get_forum_topics( array( 'user_id' => $user_id, 'type' => 'tags', 'filter' => $search_terms, 'forum_id' => $forum_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'show_stickies' => $no_stickies ) );
47
+ break;
48
+ }
49
+
50
+ $this->topics = apply_filters( 'bp_forums_template_topics', $this->topics, $type, $forum_id, $per_page, $max, $no_stickies );
51
+
52
+ if ( !(int)$this->topics ) {
53
+ $this->topic_count = 0;
54
+ $this->total_topic_count = 0;
55
+ } else {
56
+ if ( $forum_id ) {
57
+ $topic_count = bp_forums_get_forum( $forum_id );
58
+ $topic_count = (int)$topic_count->topics;
59
+ } else if ( function_exists( 'groups_total_public_forum_topic_count' ) ) {
60
+ $topic_count = (int)groups_total_public_forum_topic_count( $type );
61
+ } else {
62
+ $topic_count = count( $this->topics );
63
+ }
64
+
65
+ if ( !$max || $max >= $topic_count )
66
+ $this->total_topic_count = $topic_count;
67
+ else
68
+ $this->total_topic_count = (int)$max;
69
+
70
+ if ( $max ) {
71
+ if ( $max >= count($this->topics) )
72
+ $this->topic_count = count( $this->topics );
73
+ else
74
+ $this->topic_count = (int)$max;
75
+ } else {
76
+ $this->topic_count = count( $this->topics );
77
+ }
78
+ }
79
+
80
+ $this->topic_count = apply_filters( 'bp_forums_template_topic_count', $this->topic_count, &$topics, $type, $forum_id, $per_page, $max, $no_stickies );
81
+ $this->total_topic_count = apply_filters( 'bp_forums_template_total_topic_count', $this->total_topic_count, $this->topic_count, &$topics, $type, $forum_id, $per_page, $max, $no_stickies );
82
+
83
+ if ( !$no_stickies) {
84
+ /* Place stickies at the top - not sure why bbPress doesn't do this? */
85
+ foreach( (array)$this->topics as $topic ) {
86
+ if ( 1 == (int)$topic->topic_sticky )
87
+ $stickies[] = $topic;
88
+ else
89
+ $standard[] = $topic;
90
+ }
91
+ $this->topics = array_merge( (array)$stickies, (array)$standard );
92
+ }
93
+
94
+ /* Fetch extra information for topics, so we don't have to query inside the loop */
95
+ $this->topics = bp_forums_get_topic_extras( &$this->topics );
96
+
97
+ $this->pag_links = paginate_links( array(
98
+ 'base' => add_query_arg( array( 'p' => '%#%', 'n' => $this->pag_num ) ),
99
+ 'format' => '',
100
+ 'total' => ceil($this->total_topic_count / $this->pag_num),
101
+ 'current' => $this->pag_page,
102
+ 'prev_text' => '&larr;',
103
+ 'next_text' => '&rarr;',
104
+ 'mid_size' => 1
105
+ ));
106
+ }
107
+
108
+ function has_topics() {
109
+ if ( $this->topic_count )
110
+ return true;
111
+
112
+ return false;
113
+ }
114
+
115
+ function next_topic() {
116
+ $this->current_topic++;
117
+ $this->topic = $this->topics[$this->current_topic];
118
+
119
+ return $this->topic;
120
+ }
121
+
122
+ function rewind_topics() {
123
+ $this->current_topic = -1;
124
+ if ( $this->topic_count > 0 ) {
125
+ $this->topic = $this->topics[0];
126
+ }
127
+ }
128
+
129
+ function user_topics() {
130
+ if ( $this->current_topic + 1 < $this->topic_count ) {
131
+ return true;
132
+ } elseif ( $this->current_topic + 1 == $this->topic_count ) {
133
+ do_action('loop_end');
134
+ // Do some cleaning up after the loop
135
+ $this->rewind_topics();
136
+ }
137
+
138
+ $this->in_the_loop = false;
139
+ return false;
140
+ }
141
+
142
+ function the_topic() {
143
+ global $topic;
144
+
145
+ $this->in_the_loop = true;
146
+ $this->topic = $this->next_topic();
147
+ $this->topic = (object)$this->topic;
148
+
149
+ if ( $this->current_topic == 0 ) // loop has just started
150
+ do_action('loop_start');
151
+ }
152
+ }
153
+
154
+ function bp_has_forum_topics( $args = '' ) {
155
+ global $forum_template, $bp;
156
+
157
+ /***
158
+ * Set the defaults based on the current page. Any of these will be overridden
159
+ * if arguments are directly passed into the loop. Custom plugins should always
160
+ * pass their parameters directly to the loop.
161
+ */
162
+ $type = 'newest';
163
+ $user_id = false;
164
+ $forum_id = false;
165
+ $search_terms = false;
166
+ $no_stickies = 'all';
167
+
168
+ /* User filtering */
169
+ if ( !empty( $bp->displayed_user->id ) )
170
+ $user_id = $bp->displayed_user->id;
171
+
172
+ /* If we're in a single group, set this group's forum_id */
173
+ if ( !$forum_id && $bp->groups->current_group ) {
174
+ $bp->groups->current_group->forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' );
175
+
176
+ /* If it turns out there is no forum for this group, return false so we don't fetch all global topics */
177
+ if ( !$bp->groups->current_group->forum_id )
178
+ return false;
179
+
180
+ $forum_id = $bp->groups->current_group->forum_id;
181
+ }
182
+
183
+ /* If $_GET['fs'] is set, let's auto populate the search_terms var */
184
+ if ( $bp->is_directory && !empty( $_GET['fs'] ) )
185
+ $search_terms = $_GET['fs'];
186
+
187
+ /* Show stickies on a group forum */
188
+ if ( $bp->groups->current_group )
189
+ $no_stickies = null;
190
+
191
+ $defaults = array(
192
+ 'type' => $type,
193
+ 'forum_id' => $forum_id,
194
+ 'user_id' => $user_id,
195
+ 'page' => 1,
196
+ 'per_page' => 20,
197
+ 'max' => false,
198
+ 'no_stickies' => $no_stickies,
199
+ 'search_terms' => $search_terms
200
+ );
201
+
202
+ $r = wp_parse_args( $args, $defaults );
203
+ extract( $r );
204
+
205
+ /* If we're viewing a tag URL in the directory, let's override the type and set it to tags and the filter to the tag name */
206
+ if ( 'tag' == $bp->current_action && !empty( $bp->action_variables[0] ) ) {
207
+ $search_terms = $bp->action_variables[0];
208
+ $type = 'tags';
209
+ }
210
+
211
+ $forum_template = new BP_Forums_Template_Forum( $type, $forum_id, $user_id, $page, $per_page, $max, $no_stickies, $search_terms );
212
+ return apply_filters( 'bp_has_topics', $forum_template->has_topics(), &$forum_template );
213
+ }
214
+
215
+ function bp_forum_topics() {
216
+ global $forum_template;
217
+ return $forum_template->user_topics();
218
+ }
219
+
220
+ function bp_the_forum_topic() {
221
+ global $forum_template;
222
+ return $forum_template->the_topic();
223
+ }
224
+
225
+ function bp_the_topic_id() {
226
+ echo bp_get_the_topic_id();
227
+ }
228
+ function bp_get_the_topic_id() {
229
+ global $forum_template;
230
+
231
+ return apply_filters( 'bp_get_the_topic_id', $forum_template->topic->topic_id );
232
+ }
233
+
234
+ function bp_the_topic_title() {
235
+ echo bp_get_the_topic_title();
236
+ }
237
+ function bp_get_the_topic_title() {
238
+ global $forum_template;
239
+
240
+ return apply_filters( 'bp_get_the_topic_title', stripslashes( $forum_template->topic->topic_title ) );
241
+ }
242
+
243
+ function bp_the_topic_slug() {
244
+ echo bp_get_the_topic_slug();
245
+ }
246
+ function bp_get_the_topic_slug() {
247
+ global $forum_template;
248
+
249
+ return apply_filters( 'bp_get_the_topic_slug', $forum_template->topic->topic_slug );
250
+ }
251
+
252
+ function bp_the_topic_text() {
253
+ echo bp_get_the_topic_text();
254
+ }
255
+ function bp_get_the_topic_text() {
256
+ global $forum_template;
257
+
258
+ $post = bb_get_first_post( (int)$forum_template->topic->topic_id, false );
259
+ return apply_filters( 'bp_get_the_topic_text', attribute_escape( $post->post_text ) );
260
+ }
261
+
262
+ function bp_the_topic_poster_id() {
263
+ echo bp_get_the_topic_poster_id();
264
+ }
265
+ function bp_get_the_topic_poster_id() {
266
+ global $forum_template;
267
+
268
+ return apply_filters( 'bp_get_the_topic_poster_id', $forum_template->topic->topic_poster );
269
+ }
270
+
271
+ function bp_the_topic_poster_avatar( $args = '' ) {
272
+ echo bp_get_the_topic_poster_avatar( $args );
273
+ }
274
+ function bp_get_the_topic_poster_avatar( $args = '' ) {
275
+ global $forum_template;
276
+
277
+ $defaults = array(
278
+ 'type' => 'thumb',
279
+ 'width' => false,
280
+ 'height' => false,
281
+ );
282
+
283
+ $r = wp_parse_args( $args, $defaults );
284
+ extract( $r, EXTR_SKIP );
285
+
286
+ return apply_filters( 'bp_get_the_topic_poster_avatar', bp_core_fetch_avatar( array( 'item_id' => $forum_template->topic->topic_poster, 'type' => $type, 'width' => $width, 'height' => $height ) ) );
287
+ }
288
+
289
+ function bp_the_topic_poster_name() {
290
+ echo bp_get_the_topic_poster_name();
291
+ }
292
+ function bp_get_the_topic_poster_name() {
293
+ global $forum_template;
294
+
295
+ $poster_id = ( empty( $forum_template->topic->poster_id ) ) ? $forum_template->topic->topic_poster : $forum_template->topic->poster_id;
296
+
297
+ if ( !$name = bp_core_get_userlink( $poster_id ) )
298
+ return __( 'Deleted User', 'buddypress' );
299
+
300
+ return apply_filters( 'bp_get_the_topic_poster_name', $name );
301
+ }
302
+
303
+ function bp_the_topic_object_id() {
304
+ echo bp_get_the_topic_object_id();
305
+ }
306
+ function bp_get_the_topic_object_id() {
307
+ global $forum_template;
308
+
309
+ return apply_filters( 'bp_get_the_topic_object_id', $forum_template->topic->object_id );
310
+ }
311
+
312
+ function bp_the_topic_object_name() {
313
+ echo bp_get_the_topic_object_name();
314
+ }
315
+ function bp_get_the_topic_object_name() {
316
+ global $forum_template;
317
+
318
+ return apply_filters( 'bp_get_the_topic_object_name', $forum_template->topic->object_name );
319
+ }
320
+
321
+ function bp_the_topic_object_slug() {
322
+ echo bp_get_the_topic_object_slug();
323
+ }
324
+ function bp_get_the_topic_object_slug() {
325
+ global $forum_template;
326
+
327
+ return apply_filters( 'bp_get_the_topic_object_slug', $forum_template->topic->object_slug );
328
+ }
329
+
330
+ function bp_the_topic_object_permalink() {
331
+ echo bp_get_the_topic_object_permalink();
332
+ }
333
+ function bp_get_the_topic_object_permalink() {
334
+ global $bp, $forum_template;
335
+
336
+ /* Currently this will only work with group forums, extended support in the future */
337
+ return apply_filters( 'bp_get_the_topic_object_permalink', $bp->root_domain . '/' . BP_GROUPS_SLUG . '/' . $forum_template->topic->object_slug . '/forum/' );
338
+ }
339
+
340
+ function bp_the_topic_last_poster_name() {
341
+ echo bp_get_the_topic_last_poster_name();
342
+ }
343
+ function bp_get_the_topic_last_poster_name() {
344
+ global $forum_template;
345
+
346
+ if ( !$domain = bp_core_get_user_domain( $forum_template->topic->topic_last_poster, $forum_template->topic->topic_last_poster_nicename, $forum_template->topic->topic_last_poster_login ) )
347
+ return __( 'Deleted User', 'buddypress' );
348
+
349
+ return apply_filters( 'bp_get_the_topic_last_poster_name', '<a href="' . $domain . '">' . $forum_template->topic->topic_last_poster_displayname . '</a>' );
350
+ }
351
+
352
+ function bp_the_topic_object_avatar( $args = '' ) {
353
+ echo bp_get_the_topic_object_avatar( $args );
354
+ }
355
+ function bp_get_the_topic_object_avatar( $args = '' ) {
356
+ global $forum_template;
357
+
358
+ $defaults = array(
359
+ 'type' => 'thumb',
360
+ 'width' => false,
361
+ 'height' => false,
362
+ );
363
+
364
+ $r = wp_parse_args( $args, $defaults );
365
+ extract( $r, EXTR_SKIP );
366
+
367
+ return apply_filters( 'bp_get_the_topic_object_avatar', bp_core_fetch_avatar( array( 'item_id' => $forum_template->topic->object_id, 'type' => $type, 'object' => 'group', 'width' => $width, 'height' => $height ) ) );
368
+ }
369
+
370
+ function bp_the_topic_last_poster_avatar( $args = '' ) {
371
+ echo bp_get_the_topic_last_poster_avatar( $args );
372
+ }
373
+ function bp_get_the_topic_last_poster_avatar( $args = '' ) {
374
+ global $forum_template;
375
+
376
+ $defaults = array(
377
+ 'type' => 'thumb',
378
+ 'width' => false,
379
+ 'height' => false,
380
+ );
381
+
382
+ $r = wp_parse_args( $args, $defaults );
383
+ extract( $r, EXTR_SKIP );
384
+
385
+ return apply_filters( 'bp_get_the_topic_last_poster_avatar', bp_core_fetch_avatar( array( 'email' => $forum_template->topic->topic_last_poster_email, 'item_id' => $forum_template->topic->topic_last_poster, 'type' => $type, 'width' => $width, 'height' => $height ) ) );
386
+ }
387
+
388
+ function bp_the_topic_start_time() {
389
+ echo bp_get_the_topic_start_time();
390
+ }
391
+ function bp_get_the_topic_start_time() {
392
+ global $forum_template;
393
+
394
+ return apply_filters( 'bp_get_the_topic_start_time', $forum_template->topic->topic_start_time );
395
+ }
396
+
397
+ function bp_the_topic_time() {
398
+ echo bp_get_the_topic_time();
399
+ }
400
+ function bp_get_the_topic_time() {
401
+ global $forum_template;
402
+
403
+ return apply_filters( 'bp_get_the_topic_time', $forum_template->topic->topic_time );
404
+ }
405
+
406
+ function bp_the_topic_forum_id() {
407
+ echo bp_get_the_topic_forum_id();
408
+ }
409
+ function bp_get_the_topic_forum_id() {
410
+ global $forum_template;
411
+
412
+ return apply_filters( 'bp_get_the_topic_forum_id', $forum_template->topic->topic_forum_id );
413
+ }
414
+
415
+ function bp_the_topic_status() {
416
+ echo bp_get_the_topic_status();
417
+ }
418
+ function bp_get_the_topic_status() {
419
+ global $forum_template;
420
+
421
+ return apply_filters( 'bp_get_the_topic_status', $forum_template->topic->topic_status );
422
+ }
423
+
424
+ function bp_the_topic_is_topic_open() {
425
+ echo bp_get_the_topic_is_topic_open();
426
+ }
427
+ function bp_get_the_topic_is_topic_open() {
428
+ global $forum_template;
429
+
430
+ return apply_filters( 'bp_get_the_topic_is_topic_open', $forum_template->topic->topic_open );
431
+ }
432
+
433
+ function bp_the_topic_last_post_id() {
434
+ echo bp_get_the_topic_last_post_id();
435
+ }
436
+ function bp_get_the_topic_last_post_id() {
437
+ global $forum_template;
438
+
439
+ return apply_filters( 'bp_get_the_topic_last_post_id', $forum_template->topic->topic_last_post_id );
440
+ }
441
+
442
+ function bp_the_topic_is_sticky() {
443
+ echo bp_get_the_topic_is_sticky();
444
+ }
445
+ function bp_get_the_topic_is_sticky() {
446
+ global $forum_template;
447
+
448
+ return apply_filters( 'bp_get_the_topic_is_sticky', $forum_template->topic->topic_sticky );
449
+ }
450
+
451
+ function bp_the_topic_total_post_count() {
452
+ echo bp_get_the_topic_total_post_count();
453
+ }
454
+ function bp_get_the_topic_total_post_count() {
455
+ global $forum_template;
456
+
457
+ if ( $forum_template->topic->topic_posts == 1 )
458
+ return apply_filters( 'bp_get_the_topic_total_post_count', sprintf( __( '%d post', 'buddypress' ), $forum_template->topic->topic_posts ) );
459
+ else
460
+ return apply_filters( 'bp_get_the_topic_total_post_count', sprintf( __( '%d posts', 'buddypress' ), $forum_template->topic->topic_posts ) );
461
+ }
462
+
463
+ function bp_the_topic_total_posts() {
464
+ echo bp_get_the_topic_total_posts();
465
+ }
466
+ function bp_get_the_topic_total_posts() {
467
+ global $forum_template;
468
+
469
+ return apply_filters( 'bp_get_the_topic_total_posts', $forum_template->topic->topic_posts );
470
+ }
471
+
472
+ function bp_the_topic_tag_count() {
473
+ echo bp_get_the_topic_tag_count();
474
+ }
475
+ function bp_get_the_topic_tag_count() {
476
+ global $forum_template;
477
+
478
+ return apply_filters( 'bp_get_the_topic_tag_count', $forum_template->topic->tag_count );
479
+ }
480
+
481
+ function bp_the_topic_permalink() {
482
+ echo bp_get_the_topic_permalink();
483
+ }
484
+ function bp_get_the_topic_permalink() {
485
+ global $forum_template, $bp;
486
+
487
+ if ( $forum_template->topic->object_slug )
488
+ $permalink = $bp->root_domain . '/' . BP_GROUPS_SLUG . '/' . $forum_template->topic->object_slug . '/';
489
+ else if ( $bp->is_single_item )
490
+ $permalink = $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_item . '/';
491
+ else
492
+ $permalink = $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_action . '/';
493
+
494
+ return apply_filters( 'bp_get_the_topic_permalink', $permalink . 'forum/topic/' . $forum_template->topic->topic_slug . '/' );
495
+ }
496
+
497
+ function bp_the_topic_time_since_created() {
498
+ echo bp_get_the_topic_time_since_created();
499
+ }
500
+ function bp_get_the_topic_time_since_created() {
501
+ global $forum_template;
502
+
503
+ return apply_filters( 'bp_get_the_topic_time_since_created', bp_core_time_since( strtotime( $forum_template->topic->topic_start_time ) ) );
504
+ }
505
+
506
+ function bp_the_topic_latest_post_excerpt( $args = '' ) {
507
+ echo bp_get_the_topic_latest_post_excerpt( $args );
508
+ }
509
+ function bp_get_the_topic_latest_post_excerpt( $args = '' ) {
510
+ global $forum_template;
511
+
512
+ $defaults = array(
513
+ 'length' => 10
514
+ );
515
+
516
+ $r = wp_parse_args( $args, $defaults );
517
+ extract( $r, EXTR_SKIP );
518
+
519
+ $post = bp_forums_get_post( $forum_template->topic->topic_last_post_id );
520
+ $post = bp_create_excerpt( $post->post_text, $length );
521
+ return apply_filters( 'bp_get_the_topic_latest_post_excerpt', $post );
522
+ }
523
+
524
+ function bp_the_topic_time_since_last_post() {
525
+ global $forum_template;
526
+
527
+ echo bp_get_the_topic_time_since_last_post();
528
+ }
529
+ function bp_get_the_topic_time_since_last_post() {
530
+ global $forum_template;
531
+
532
+ return apply_filters( 'bp_get_the_topic_time_since_last_post', bp_core_time_since( strtotime( $forum_template->topic->topic_time ) ) );
533
+ }
534
+
535
+ function bp_the_topic_is_mine() {
536
+ echo bp_get_the_topic_is_mine();
537
+ }
538
+ function bp_get_the_topic_is_mine() {
539
+ global $bp, $forum_template;
540
+
541
+ return $bp->loggedin_user->id == $forum_template->topic->topic_poster;
542
+ }
543
+
544
+ function bp_the_topic_admin_links( $args = '' ) {
545
+ echo bp_get_the_topic_admin_links( $args );
546
+ }
547
+ function bp_get_the_topic_admin_links( $args = '' ) {
548
+ global $bp, $forum_template;
549
+
550
+ $defaults = array(
551
+ 'seperator' => '|'
552
+ );
553
+
554
+ $r = wp_parse_args( $args, $defaults );
555
+ extract( $r, EXTR_SKIP );
556
+
557
+ $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'edit', 'bp_forums_edit_topic' ) . '">' . __( 'Edit Topic', 'buddypress' ) . '</a>';
558
+
559
+ if ( $bp->is_item_admin || $bp->is_item_mod || is_site_admin() ) {
560
+ if ( 0 == (int)$forum_template->topic->topic_sticky )
561
+ $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'stick', 'bp_forums_stick_topic' ) . '">' . __( 'Sticky Topic', 'buddypress' ) . '</a>';
562
+ else
563
+ $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'unstick', 'bp_forums_unstick_topic' ) . '">' . __( 'Un-stick Topic', 'buddypress' ) . '</a>';
564
+
565
+ if ( 0 == (int)$forum_template->topic->topic_open )
566
+ $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'open', 'bp_forums_open_topic' ) . '">' . __( 'Open Topic', 'buddypress' ) . '</a>';
567
+ else
568
+ $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'close', 'bp_forums_close_topic' ) . '">' . __( 'Close Topic', 'buddypress' ) . '</a>';
569
+
570
+ $links[] = '<a class="confirm" id="topic-delete-link" href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'delete', 'bp_forums_delete_topic' ) . '">' . __( 'Delete Topic', 'buddypress' ) . '</a>';
571
+ }
572
+
573
+ return implode( ' ' . $seperator . ' ', (array) $links );
574
+ }
575
+
576
+ function bp_the_topic_css_class() {
577
+ echo bp_get_the_topic_css_class();
578
+ }
579
+
580
+ function bp_get_the_topic_css_class() {
581
+ global $forum_template;
582
+
583
+ $class = false;
584
+
585
+ if ( $forum_template->current_topic % 2 == 1 )
586
+ $class .= 'alt';
587
+
588
+ if ( 1 == (int)$forum_template->topic->topic_sticky )
589
+ $class .= ' sticky';
590
+
591
+ if ( 0 == (int)$forum_template->topic->topic_open )
592
+ $class .= ' closed';
593
+
594
+ return apply_filters( 'bp_get_the_topic_css_class', trim( $class ) );
595
+ }
596
+
597
+ function bp_my_forum_topics_link() {
598
+ echo bp_get_my_forum_topics_link();
599
+ }
600
+ function bp_get_my_forum_topics_link() {
601
+ global $bp;
602
+
603
+ return apply_filters( 'bp_get_my_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/personal/' );
604
+ }
605
+
606
+ function bp_unreplied_forum_topics_link() {
607
+ echo bp_get_unreplied_forum_topics_link();
608
+ }
609
+ function bp_get_unreplied_forum_topics_link() {
610
+ global $bp;
611
+
612
+ return apply_filters( 'bp_get_unreplied_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/unreplied/' );
613
+ }
614
+
615
+
616
+ function bp_popular_forum_topics_link() {
617
+ echo bp_get_popular_forum_topics_link();
618
+ }
619
+ function bp_get_popular_forum_topics_link() {
620
+ global $bp;
621
+
622
+ return apply_filters( 'bp_get_popular_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/popular/' );
623
+ }
624
+
625
+ function bp_newest_forum_topics_link() {
626
+ echo bp_get_newest_forum_topics_link();
627
+ }
628
+ function bp_get_newest_forum_topics_link() {
629
+ global $bp;
630
+
631
+ return apply_filters( 'bp_get_newest_forum_topics_link', $bp->root_domain . '/' . $bp->forums->slug . '/' );
632
+ }
633
+
634
+ function bp_forum_topic_type() {
635
+ echo bp_get_forum_topic_type();
636
+ }
637
+ function bp_get_forum_topic_type() {
638
+ global $bp;
639
+
640
+ if ( !$bp->is_directory || !$bp->current_action )
641
+ return 'newest';
642
+
643
+
644
+ return apply_filters( 'bp_get_forum_topic_type', $bp->current_action );
645
+ }
646
+
647
+ function bp_forums_tag_name() {
648
+ echo bp_get_forums_tag_name();
649
+ }
650
+ function bp_get_forums_tag_name() {
651
+ global $bp;
652
+
653
+ if ( $bp->is_directory && $bp->forums->slug == $bp->current_component )
654
+ return apply_filters( 'bp_get_forums_tag_name', $bp->action_variables[0] );
655
+ }
656
+
657
+ function bp_forum_pagination() {
658
+ echo bp_get_forum_pagination();
659
+ }
660
+ function bp_get_forum_pagination() {
661
+ global $forum_template;
662
+
663
+ return apply_filters( 'bp_get_forum_pagination', $forum_template->pag_links );
664
+ }
665
+
666
+ function bp_forum_pagination_count() {
667
+ global $bp, $forum_template;
668
+
669
+ $start_num = intval( ( $forum_template->pag_page - 1 ) * $forum_template->pag_num ) + 1;
670
+ $from_num = bp_core_number_format( $start_num );
671
+ $to_num = bp_core_number_format( ( $start_num + ( $forum_template->pag_num - 1 ) > $forum_template->total_topic_count ) ? $forum_template->total_topic_count : $start_num + ( $forum_template->pag_num - 1 ) );
672
+ $total = bp_core_number_format( $forum_template->total_topic_count );
673
+
674
+ $pag_filter = false;
675
+ if ( 'tags' == $forum_template->type && !empty( $forum_template->search_terms ) )
676
+ $pag_filter = sprintf( __( ' matching tag "%s"', 'buddypress' ), $forum_template->search_terms );
677
+
678
+ echo apply_filters( 'bp_forum_pagination_count', sprintf( __( 'Viewing topic %1$s to %2$s (%3$s total topics%4$s)', 'buddypress' ), $from_num, $to_num, $total, $pag_filter ) );
679
+ ?>
680
+ <span class="ajax-loader"></span>
681
+ <?php
682
+ }
683
+
684
+ function bp_is_edit_topic() {
685
+ global $bp;
686
+
687
+ if ( in_array( 'post', (array)$bp->action_variables ) && in_array( 'edit', (array)$bp->action_variables ) )
688
+ return false;
689
+
690
+ return true;
691
+ }
692
+
693
+
694
+ class BP_Forums_Template_Topic {
695
+ var $current_post = -1;
696
+ var $post_count;
697
+ var $posts;
698
+ var $post;
699
+
700
+ var $forum_id;
701
+ var $topic_id;
702
+ var $topic;
703
+
704
+ var $in_the_loop;
705
+
706
+ var $pag_page;
707
+ var $pag_num;
708
+ var $pag_links;
709
+ var $total_post_count;
710
+
711
+ var $single_post = false;
712
+
713
+ var $sort_by;
714
+ var $order;
715
+
716
+ function BP_Forums_Template_Topic( $topic_id, $per_page, $max ) {
717
+ global $bp, $current_user, $forum_template;
718
+
719
+ $this->pag_page = isset( $_REQUEST['topic_page'] ) ? intval( $_REQUEST['topic_page'] ) : 1;
720
+ $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
721
+
722
+ $this->topic_id = $topic_id;
723
+ $forum_template->topic = (object) bp_forums_get_topic_details( $this->topic_id );
724
+ $this->forum_id = $forum_template->topic->forum_id;
725
+
726
+ $this->posts = bp_forums_get_topic_posts( array( 'topic_id' => $this->topic_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num ) );
727
+
728
+ if ( !$this->posts ) {
729
+ $this->post_count = 0;
730
+ $this->total_post_count = 0;
731
+ } else {
732
+ if ( !$max || $max >= (int) $forum_template->topic->topic_posts )
733
+ $this->total_post_count = (int) $forum_template->topic->topic_posts;
734
+ else
735
+ $this->total_post_count = (int)$max;
736
+
737
+ if ( $max ) {
738
+ if ( $max >= count($this->posts) )
739
+ $this->post_count = count( $this->posts );
740
+ else
741
+ $this->post_count = (int)$max;
742
+ } else {
743
+ $this->post_count = count( $this->posts );
744
+ }
745
+ }
746
+
747
+ $this->pag_links = paginate_links( array(
748
+ 'base' => add_query_arg( array( 'topic_page' => '%#%', 'num' => $this->pag_num ) ),
749
+ 'format' => '',
750
+ 'total' => ceil($this->total_post_count / $this->pag_num),
751
+ 'current' => $this->pag_page,
752
+ 'prev_text' => '&larr;',
753
+ 'next_text' => '&rarr;',
754
+ 'mid_size' => 1
755
+ ));
756
+ $this->pag->total_pages = ceil($this->total_post_count / $this->pag_num);
757
+ }
758
+
759
+ function has_posts() {
760
+ if ( $this->post_count )
761
+ return true;
762
+
763
+ return false;
764
+ }
765
+
766
+ function next_post() {
767
+ $this->current_post++;
768
+ $this->post = $this->posts[$this->current_post];
769
+
770
+ return $this->post;
771
+ }
772
+
773
+ function rewind_posts() {
774
+ $this->current_post = -1;
775
+ if ( $this->post_count > 0 ) {
776
+ $this->post = $this->posts[0];
777
+ }
778
+ }
779
+
780
+ function user_posts() {
781
+ if ( $this->current_post + 1 < $this->post_count ) {
782
+ return true;
783
+ } elseif ( $this->current_post + 1 == $this->post_count ) {
784
+ do_action('loop_end');
785
+ // Do some cleaning up after the loop
786
+ $this->rewind_posts();
787
+ }
788
+
789
+ $this->in_the_loop = false;
790
+ return false;
791
+ }
792
+
793
+ function the_post() {
794
+ global $post;
795
+
796
+ $this->in_the_loop = true;
797
+ $this->post = $this->next_post();
798
+ $this->post = (object)$this->post;
799
+
800
+ if ( $this->current_post == 0 ) // loop has just started
801
+ do_action('loop_start');
802
+ }
803
+ }
804
+
805
+ function bp_has_forum_topic_posts( $args = '' ) {
806
+ global $topic_template, $bp;
807
+
808
+ $defaults = array(
809
+ 'topic_id' => false,
810
+ 'per_page' => 15,
811
+ 'max' => false
812
+ );
813
+
814
+ $r = wp_parse_args( $args, $defaults );
815
+ extract( $r, EXTR_SKIP );
816
+
817
+ if ( !$topic_id && $bp->current_component == $bp->groups->slug && 'forum' == $bp->current_action && 'topic' == $bp->action_variables[0] )
818
+ $topic_id = bp_forums_get_topic_id_from_slug( $bp->action_variables[1] );
819
+
820
+ if ( is_numeric( $topic_id ) ) {
821
+ $topic_template = new BP_Forums_Template_Topic( $topic_id, $per_page, $max );
822
+
823
+ // Current topic forum_id needs to match current_group forum_id
824
+ if ( $bp->current_component == $bp->groups->slug && $topic_template->forum_id != groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' ) )
825
+ return false;
826
+
827
+ } else {
828
+ return false;
829
+ }
830
+
831
+ return apply_filters( 'bp_has_topic_posts', $topic_template->has_posts(), &$topic_template );
832
+ }
833
+
834
+ function bp_forum_topic_posts() {
835
+ global $topic_template;
836
+ return $topic_template->user_posts();
837
+ }
838
+
839
+ function bp_the_forum_topic_post() {
840
+ global $topic_template;
841
+ return $topic_template->the_post();
842
+ }
843
+
844
+ function bp_the_topic_post_id() {
845
+ echo bp_get_the_topic_post_id();
846
+ }
847
+ function bp_get_the_topic_post_id() {
848
+ global $topic_template;
849
+
850
+ return apply_filters( 'bp_get_the_topic_post_id', $topic_template->post->post_id );
851
+ }
852
+
853
+ function bp_the_topic_post_content() {
854
+ echo bp_get_the_topic_post_content();
855
+ }
856
+ function bp_get_the_topic_post_content() {
857
+ global $topic_template;
858
+
859
+ return apply_filters( 'bp_get_the_topic_post_content', stripslashes( $topic_template->post->post_text ) );
860
+ }
861
+
862
+ function bp_the_topic_post_css_class() {
863
+ echo bp_get_the_topic_post_css_class();
864
+ }
865
+
866
+ function bp_get_the_topic_post_css_class() {
867
+ global $topic_template;
868
+
869
+ $class = false;
870
+
871
+ if ( $topic_template->current_post % 2 == 1 )
872
+ $class .= 'alt';
873
+
874
+ if ( 1 == (int)$topic_template->post->post_status )
875
+ $class .= ' deleted';
876
+
877
+ if ( 0 == (int)$topic_template->post->post_status )
878
+ $class .= ' open';
879
+
880
+ return apply_filters( 'bp_get_the_topic_post_css_class', trim( $class ) );
881
+ }
882
+
883
+ function bp_the_topic_post_poster_avatar( $args = '' ) {
884
+ echo bp_get_the_topic_post_poster_avatar( $args );
885
+ }
886
+ function bp_get_the_topic_post_poster_avatar( $args = '' ) {
887
+ global $topic_template;
888
+
889
+ $defaults = array(
890
+ 'type' => 'thumb',
891
+ 'width' => 20,
892
+ 'height' => 20,
893
+ );
894
+
895
+ $r = wp_parse_args( $args, $defaults );
896
+ extract( $r, EXTR_SKIP );
897
+
898
+ return apply_filters( 'bp_get_the_topic_post_poster_avatar', bp_core_fetch_avatar( array( 'item_id' => $topic_template->post->poster_id, 'type' => $type, 'width' => $width, 'height' => $height ) ) );
899
+ }
900
+
901
+ function bp_the_topic_post_poster_name() {
902
+ echo bp_get_the_topic_post_poster_name();
903
+ }
904
+ function bp_get_the_topic_post_poster_name() {
905
+ global $topic_template;
906
+
907
+ if ( !$link = bp_core_get_user_domain( $topic_template->post->poster_id, $topic_template->post->poster_nicename, $topic_template->post->poster_login ) )
908
+ return __( 'Deleted User', 'buddypress' );
909
+
910
+ return apply_filters( 'bp_get_the_topic_post_poster_name', '<a href="' . $link . '" title="' . $topic_template->post->poster_name . '">' . $topic_template->post->poster_name . '</a>' );
911
+ }
912
+
913
+ function bp_the_topic_post_poster_link() {
914
+ echo bp_get_the_topic_post_poster_link();
915
+ }
916
+ function bp_get_the_topic_post_poster_link() {
917
+ global $topic_template;
918
+
919
+ return apply_filters( 'bp_the_topic_post_poster_link', bp_core_get_user_domain( $topic_template->post->poster_id, $topic_template->post->poster_nicename, $topic_template->post->poster_login ) );
920
+ }
921
+
922
+ function bp_the_topic_post_time_since() {
923
+ echo bp_get_the_topic_post_time_since();
924
+ }
925
+ function bp_get_the_topic_post_time_since() {
926
+ global $topic_template;
927
+
928
+ return apply_filters( 'bp_get_the_topic_post_time_since', bp_core_time_since( strtotime( $topic_template->post->post_time ) ) );
929
+ }
930
+
931
+ function bp_the_topic_post_is_mine() {
932
+ echo bp_the_topic_post_is_mine();
933
+ }
934
+ function bp_get_the_topic_post_is_mine() {
935
+ global $bp, $topic_template;
936
+
937
+ return $bp->loggedin_user->id == $topic_template->post->poster_id;
938
+ }
939
+
940
+ function bp_the_topic_post_admin_links( $args = '' ) {
941
+ echo bp_get_the_topic_post_admin_links( $args );
942
+ }
943
+ function bp_get_the_topic_post_admin_links( $args = '' ) {
944
+ global $topic_template;
945
+
946
+ /* Never show for the first post in a topic. */
947
+ if ( 0 == $topic_template->current_post && $topic_template->pag_page == 1 )
948
+ return;
949
+
950
+ $defaults = array(
951
+ 'seperator' => '|'
952
+ );
953
+
954
+ $r = wp_parse_args( $args, $defaults );
955
+ extract( $r, EXTR_SKIP );
956
+
957
+ if ( $_SERVER['QUERY_STRING'] )
958
+ $query_vars = '?' . $_SERVER['QUERY_STRING'];
959
+
960
+ $links = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'edit/post/' . $topic_template->post->post_id . '/' . $query_vars, 'bp_forums_edit_post' ) . '">' . __( 'Edit', 'buddypress' ) . '</a> ' . $seperator . ' ';
961
+ $links .= '<a class="confirm" id="post-delete-link" href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'delete/post/' . $topic_template->post->post_id, 'bp_forums_delete_post' ) . '">' . __( 'Delete', 'buddypress' ) . '</a> | ';
962
+
963
+ return $links;
964
+ }
965
+
966
+ function bp_the_topic_post_edit_text() {
967
+ echo bp_get_the_topic_post_edit_text();
968
+ }
969
+ function bp_get_the_topic_post_edit_text() {
970
+ global $bp;
971
+
972
+ $post = bp_forums_get_post( $bp->action_variables[4] );
973
+ return apply_filters( 'bp_get_the_topic_post_edit_text', attribute_escape( $post->post_text ) );
974
+ }
975
+
976
+ function bp_the_topic_pagination() {
977
+ echo bp_get_the_topic_pagination();
978
+ }
979
+ function bp_get_the_topic_pagination() {
980
+ global $topic_template;
981
+
982
+ return apply_filters( 'bp_get_the_topic_pagination', $topic_template->pag_links );
983
+ }
984
+
985
+ function bp_the_topic_pagination_count() {
986
+ global $bp, $topic_template;
987
+
988
+ $start_num = intval( ( $topic_template->pag_page - 1 ) * $topic_template->pag_num ) + 1;
989
+ $from_num = bp_core_number_format( $start_num );
990
+ $to_num = bp_core_number_format( ( $start_num + ( $topic_template->pag_num - 1 ) > $topic_template->total_post_count ) ? $topic_template->total_post_count : $start_num + ( $topic_template->pag_num - 1 ) );
991
+ $total = bp_core_number_format( $topic_template->total_post_count );
992
+
993
+ echo apply_filters( 'bp_the_topic_pagination_count', sprintf( __( 'Viewing post %1$s to %2$s (%3$s total posts)', 'buddypress' ), $from_num, $to_num, $total ) );
994
+ ?>
995
+ <span class="ajax-loader"></span>
996
+ <?php
997
+ }
998
+
999
+ function bp_the_topic_is_last_page() {
1000
+ echo bp_get_the_topic_is_last_page();
1001
+ }
1002
+ function bp_get_the_topic_is_last_page() {
1003
+ global $topic_template;
1004
+
1005
+ return apply_filters( 'bp_get_the_topic_is_last_page', $topic_template->pag_page == $topic_template->pag->total_pages );
1006
+ }
1007
+
1008
+ function bp_directory_forums_search_form() {
1009
+ global $bp;
1010
+
1011
+ $search_value = __( 'Search anything...', 'buddypress' );
1012
+ if ( !empty( $_REQUEST['fs'] ) )
1013
+ $search_value = $_REQUEST['fs'];
1014
+
1015
+ ?>
1016
+ <form action="" method="get" id="search-forums-form">
1017
+ <label><input type="text" name="s" id="forums_search" value="<?php echo attribute_escape($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>
1018
+ <input type="submit" id="forums_search_submit" name="forums_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
1019
+ </form>
1020
+ <?php
1021
+ }
1022
+ function bp_forum_permalink() {
1023
+ echo bp_get_forum_permalink();
1024
+ }
1025
+ function bp_get_forum_permalink() {
1026
+ global $bp;
1027
+
1028
+ if ( $bp->is_single_item )
1029
+ $permalink = $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_item . '/';
1030
+ else
1031
+ $permalink = $bp->root_domain . $bp->current_component . '/' . $bp->current_action . '/';
1032
+
1033
+ return apply_filters( 'bp_get_forum_permalink', $permalink . 'forum' );
1034
+ }
1035
+
1036
+ function bp_forum_directory_permalink() {
1037
+ echo bp_get_forum_directory_permalink();
1038
+ }
1039
+ function bp_get_forum_directory_permalink() {
1040
+ global $bp;
1041
+
1042
+ return apply_filters( 'bp_get_forum_directory_permalink', $bp->root_domain . '/' . $bp->forums->slug );
1043
+ }
1044
+
1045
+ function bp_forums_tag_heat_map( $args = '' ) {
1046
+ $defaults = array(
1047
+ 'smallest' => '10',
1048
+ 'largest' => '42',
1049
+ 'sizing' => 'px',
1050
+ 'limit' => '50'
1051
+ );
1052
+
1053
+ $r = wp_parse_args( $args, $defaults );
1054
+ extract( $r, EXTR_SKIP );
1055
+
1056
+ bb_tag_heat_map( $smallest, $largest, $sizing, $limit );
1057
+ }
1058
+
1059
+ function bp_forum_action() {
1060
+ echo bp_get_forum_action();
1061
+ }
1062
+ function bp_get_forum_action() {
1063
+ global $topic_template;
1064
+
1065
+ return apply_filters( 'bp_get_forum_action', $bp->root_domain . attribute_escape( $_SERVER['REQUEST_URI'] ) );
1066
+ }
1067
+
1068
+ function bp_forum_topic_action() {
1069
+ echo bp_get_forum_topic_action();
1070
+ }
1071
+ function bp_get_forum_topic_action() {
1072
+ global $bp;
1073
+
1074
+ return apply_filters( 'bp_get_forum_topic_action', $bp->root_domain . attribute_escape( $_SERVER['REQUEST_URI'] ) );
1075
+ }
1076
+
1077
+ function bp_forum_topic_count_for_user( $user_id = false ) {
1078
+ echo bp_get_forum_topic_count_for_user( $user_id );
1079
+ }
1080
+ function bp_get_forum_topic_count_for_user( $user_id = false ) {
1081
+ return apply_filters( 'bp_get_forum_topic_count_for_user', bp_forums_total_topic_count_for_user( $user_id ) );
1082
+ }
1083
+
1084
+ function bp_forum_topic_count( $user_id = false ) {
1085
+ echo bp_get_forum_topic_count( $user_id );
1086
+ }
1087
+ function bp_get_forum_topic_count( $user_id = false ) {
1088
+ return apply_filters( 'bp_get_forum_topic_count', bp_forums_total_topic_count( $user_id ) );
1089
+ }
1090
  ?>
bp-friends.php CHANGED
@@ -1,651 +1,656 @@
1
- <?php
2
-
3
- define ( 'BP_FRIENDS_DB_VERSION', '1800' );
4
-
5
- /* Define the slug for the component */
6
- if ( !defined( 'BP_FRIENDS_SLUG' ) )
7
- define ( 'BP_FRIENDS_SLUG', 'friends' );
8
-
9
- require ( BP_PLUGIN_DIR . '/bp-friends/bp-friends-classes.php' );
10
- require ( BP_PLUGIN_DIR . '/bp-friends/bp-friends-templatetags.php' );
11
-
12
- function friends_install() {
13
- global $wpdb, $bp;
14
-
15
- if ( !empty($wpdb->charset) )
16
- $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
17
-
18
- $sql[] = "CREATE TABLE {$bp->friends->table_name} (
19
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
20
- initiator_user_id bigint(20) NOT NULL,
21
- friend_user_id bigint(20) NOT NULL,
22
- is_confirmed bool DEFAULT 0,
23
- is_limited bool DEFAULT 0,
24
- date_created datetime NOT NULL,
25
- KEY initiator_user_id (initiator_user_id),
26
- KEY friend_user_id (friend_user_id)
27
- ) {$charset_collate};";
28
-
29
- require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
30
- dbDelta($sql);
31
-
32
- update_site_option( 'bp-friends-db-version', BP_FRIENDS_DB_VERSION );
33
- }
34
-
35
- function friends_setup_globals() {
36
- global $bp, $wpdb;
37
-
38
- /* For internal identification */
39
- $bp->friends->id = 'friends';
40
-
41
- $bp->friends->table_name = $wpdb->base_prefix . 'bp_friends';
42
- $bp->friends->format_notification_function = 'friends_format_notifications';
43
- $bp->friends->slug = BP_FRIENDS_SLUG;
44
-
45
- /* Register this in the active components array */
46
- $bp->active_components[$bp->friends->slug] = $bp->friends->id;
47
-
48
- do_action( 'friends_setup_globals' );
49
- }
50
- add_action( 'bp_setup_globals', 'friends_setup_globals' );
51
-
52
- function friends_check_installed() {
53
- global $wpdb, $bp;
54
-
55
- if ( !is_site_admin() )
56
- return false;
57
-
58
- /* Need to check db tables exist, activate hook no-worky in mu-plugins folder. */
59
- if ( get_site_option( 'bp-friends-db-version' ) < BP_FRIENDS_DB_VERSION )
60
- friends_install();
61
- }
62
- add_action( 'admin_menu', 'friends_check_installed' );
63
-
64
- function friends_setup_nav() {
65
- global $bp;
66
-
67
- /* Add 'Friends' to the main navigation */
68
- bp_core_new_nav_item( array( 'name' => sprintf( __( 'Friends <span>(%d)</span>', 'buddypress' ), friends_get_total_friend_count() ), 'slug' => $bp->friends->slug, 'position' => 60, 'screen_function' => 'friends_screen_my_friends', 'default_subnav_slug' => 'my-friends', 'item_css_id' => $bp->friends->id ) );
69
-
70
- $friends_link = $bp->loggedin_user->domain . $bp->friends->slug . '/';
71
-
72
- /* Add the subnav items to the friends nav item */
73
- bp_core_new_subnav_item( array( 'name' => __( 'My Friends', 'buddypress' ), 'slug' => 'my-friends', 'parent_url' => $friends_link, 'parent_slug' => $bp->friends->slug, 'screen_function' => 'friends_screen_my_friends', 'position' => 10, 'item_css_id' => 'friends-my-friends' ) );
74
- bp_core_new_subnav_item( array( 'name' => __( 'Requests', 'buddypress' ), 'slug' => 'requests', 'parent_url' => $friends_link, 'parent_slug' => $bp->friends->slug, 'screen_function' => 'friends_screen_requests', 'position' => 20, 'user_has_access' => bp_is_my_profile() ) );
75
-
76
- if ( $bp->current_component == $bp->friends->slug ) {
77
- if ( bp_is_my_profile() ) {
78
- $bp->bp_options_title = __( 'My Friends', 'buddypress' );
79
- } else {
80
- $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
81
- $bp->bp_options_title = $bp->displayed_user->fullname;
82
- }
83
- }
84
-
85
- do_action( 'friends_setup_nav' );
86
- }
87
- add_action( 'bp_setup_nav', 'friends_setup_nav' );
88
-
89
- /********************************************************************************
90
- * Screen Functions
91
- *
92
- * Screen functions are the controllers of BuddyPress. They will execute when their
93
- * specific URL is caught. They will first save or manipulate data using business
94
- * functions, then pass on the user to a template file.
95
- */
96
-
97
- function friends_screen_my_friends() {
98
- global $bp;
99
-
100
- // Delete any friendship acceptance notifications for the user when viewing a profile
101
- bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->friends->id, 'friendship_accepted' );
102
-
103
- do_action( 'friends_screen_my_friends' );
104
-
105
- bp_core_load_template( apply_filters( 'friends_template_my_friends', 'members/single/home' ) );
106
- }
107
-
108
- function friends_screen_requests() {
109
- global $bp;
110
-
111
- if ( isset($bp->action_variables) && 'accept' == $bp->action_variables[0] && is_numeric($bp->action_variables[1]) ) {
112
- /* Check the nonce */
113
- check_admin_referer( 'friends_accept_friendship' );
114
-
115
- if ( friends_accept_friendship( $bp->action_variables[1] ) ) {
116
- bp_core_add_message( __( 'Friendship accepted', 'buddypress' ) );
117
- } else {
118
- bp_core_add_message( __( 'Friendship could not be accepted', 'buddypress' ), 'error' );
119
- }
120
- bp_core_redirect( $bp->loggedin_user->domain . $bp->current_component . '/' . $bp->current_action );
121
-
122
- } else if ( isset($bp->action_variables) && 'reject' == $bp->action_variables[0] && is_numeric($bp->action_variables[1]) ) {
123
- /* Check the nonce */
124
- check_admin_referer( 'friends_reject_friendship' );
125
-
126
- if ( friends_reject_friendship( $bp->action_variables[1] ) ) {
127
- bp_core_add_message( __( 'Friendship rejected', 'buddypress' ) );
128
- } else {
129
- bp_core_add_message( __( 'Friendship could not be rejected', 'buddypress' ), 'error' );
130
- }
131
- bp_core_redirect( $bp->loggedin_user->domain . $bp->current_component . '/' . $bp->current_action );
132
- }
133
-
134
- do_action( 'friends_screen_requests' );
135
-
136
- if ( isset( $_GET['new'] ) )
137
- bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->friends->id, 'friendship_request' );
138
-
139
- bp_core_load_template( apply_filters( 'friends_template_requests', 'members/single/home' ) );
140
- }
141
-
142
- function friends_screen_notification_settings() {
143
- global $current_user; ?>
144
- <table class="notification-settings" id="friends-notification-settings">
145
- <tr>
146
- <th class="icon"></th>
147
- <th class="title"><?php _e( 'Friends', 'buddypress' ) ?></th>
148
- <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>
149
- <th class="no"><?php _e( 'No', 'buddypress' )?></th>
150
- </tr>
151
- <tr>
152
- <td></td>
153
- <td><?php _e( 'A member sends you a friendship request', 'buddypress' ) ?></td>
154
- <td class="yes"><input type="radio" name="notifications[notification_friends_friendship_request]" value="yes" <?php if ( !get_usermeta( $current_user->id,'notification_friends_friendship_request') || 'yes' == get_usermeta( $current_user->id,'notification_friends_friendship_request') ) { ?>checked="checked" <?php } ?>/></td>
155
- <td class="no"><input type="radio" name="notifications[notification_friends_friendship_request]" value="no" <?php if ( get_usermeta( $current_user->id,'notification_friends_friendship_request') == 'no' ) { ?>checked="checked" <?php } ?>/></td>
156
- </tr>
157
- <tr>
158
- <td></td>
159
- <td><?php _e( 'A member accepts your friendship request', 'buddypress' ) ?></td>
160
- <td class="yes"><input type="radio" name="notifications[notification_friends_friendship_accepted]" value="yes" <?php if ( !get_usermeta( $current_user->id,'notification_friends_friendship_accepted') || 'yes' == get_usermeta( $current_user->id,'notification_friends_friendship_accepted') ) { ?>checked="checked" <?php } ?>/></td>
161
- <td class="no"><input type="radio" name="notifications[notification_friends_friendship_accepted]" value="no" <?php if ( 'no' == get_usermeta( $current_user->id,'notification_friends_friendship_accepted') ) { ?>checked="checked" <?php } ?>/></td>
162
- </tr>
163
-
164
- <?php do_action( 'friends_screen_notification_settings' ); ?>
165
- </table>
166
- <?php
167
- }
168
- add_action( 'bp_notification_settings', 'friends_screen_notification_settings' );
169
-
170
-
171
- /********************************************************************************
172
- * Action Functions
173
- *
174
- * Action functions are exactly the same as screen functions, however they do not
175
- * have a template screen associated with them. Usually they will send the user
176
- * back to the default screen after execution.
177
- */
178
-
179
- function friends_action_add_friend() {
180
- global $bp;
181
-
182
- if ( $bp->current_component != $bp->friends->slug || $bp->current_action != 'add-friend' )
183
- return false;
184
-
185
- $potential_friend_id = $bp->action_variables[0];
186
-
187
- if ( !is_numeric( $potential_friend_id ) || !isset( $potential_friend_id ) )
188
- return false;
189
-
190
- if ( $potential_friend_id == $bp->loggedin_user->id )
191
- return false;
192
-
193
- $friendship_status = BP_Friends_Friendship::check_is_friend( $bp->loggedin_user->id, $potential_friend_id );
194
-
195
- if ( 'not_friends' == $friendship_status ) {
196
-
197
- if ( !check_admin_referer( 'friends_add_friend' ) )
198
- return false;
199
-
200
- if ( !friends_add_friend( $bp->loggedin_user->id, $potential_friend_id ) ) {
201
- bp_core_add_message( __( 'Friendship could not be requested.', 'buddypress' ), 'error' );
202
- } else {
203
- bp_core_add_message( __( 'Friendship requested', 'buddypress' ) );
204
- }
205
- } else if ( 'is_friend' == $friendship_status ) {
206
- bp_core_add_message( __( 'You are already friends with this user', 'buddypress' ), 'error' );
207
- } else {
208
- bp_core_add_message( __( 'You already have a pending friendship request with this user', 'buddypress' ), 'error' );
209
- }
210
-
211
- bp_core_redirect( wp_get_referer() );
212
-
213
- return false;
214
- }
215
- add_action( 'init', 'friends_action_add_friend' );
216
-
217
- function friends_action_remove_friend() {
218
- global $bp;
219
-
220
- if ( $bp->current_component != $bp->friends->slug || $bp->current_action != 'remove-friend' )
221
- return false;
222
-
223
- $potential_friend_id = $bp->action_variables[0];
224
-
225
- if ( !is_numeric( $potential_friend_id ) || !isset( $potential_friend_id ) )
226
- return false;
227
-
228
- if ( $potential_friend_id == $bp->loggedin_user->id )
229
- return false;
230
-
231
- $friendship_status = BP_Friends_Friendship::check_is_friend( $bp->loggedin_user->id, $potential_friend_id );
232
-
233
- if ( 'is_friend' == $friendship_status ) {
234
-
235
- if ( !check_admin_referer( 'friends_remove_friend' ) )
236
- return false;
237
-
238
- if ( !friends_remove_friend( $bp->loggedin_user->id, $potential_friend_id ) ) {
239
- bp_core_add_message( __( 'Friendship could not be canceled.', 'buddypress' ), 'error' );
240
- } else {
241
- bp_core_add_message( __( 'Friendship canceled', 'buddypress' ) );
242
- }
243
- } else if ( 'is_friends' == $friendship_status ) {
244
- bp_core_add_message( __( 'You are not yet friends with this user', 'buddypress' ), 'error' );
245
- } else {
246
- bp_core_add_message( __( 'You have a pending friendship request with this user', 'buddypress' ), 'error' );
247
- }
248
-
249
- bp_core_redirect( wp_get_referer() );
250
-
251
- return false;
252
- }
253
- add_action( 'init', 'friends_action_remove_friend' );
254
-
255
-
256
- /********************************************************************************
257
- * Activity & Notification Functions
258
- *
259
- * These functions handle the recording, deleting and formatting of activity and
260
- * notifications for the user and for this specific component.
261
- */
262
-
263
- function friends_record_activity( $args = '' ) {
264
- global $bp;
265
-
266
- if ( !function_exists( 'bp_activity_add' ) )
267
- return false;
268
-
269
- $defaults = array(
270
- 'user_id' => $bp->loggedin_user->id,
271
- 'action' => '',
272
- 'content' => '',
273
- 'primary_link' => '',
274
- 'component' => $bp->friends->id,
275
- 'type' => false,
276
- 'item_id' => false,
277
- 'secondary_item_id' => false,
278
- 'recorded_time' => gmdate( "Y-m-d H:i:s" ),
279
- 'hide_sitewide' => false
280
- );
281
-
282
- $r = wp_parse_args( $args, $defaults );
283
- extract( $r, EXTR_SKIP );
284
-
285
- return bp_activity_add( array( '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 ) );
286
- }
287
-
288
- function friends_delete_activity( $args ) {
289
- if ( function_exists('bp_activity_delete_by_item_id') ) {
290
- extract( (array)$args );
291
- bp_activity_delete_by_item_id( array( 'item_id' => $item_id, 'component' => $bp->friends->id, 'type' => $type, 'user_id' => $user_id, 'secondary_item_id' => $secondary_item_id ) );
292
- }
293
- }
294
-
295
- function friends_register_activity_actions() {
296
- global $bp;
297
-
298
- if ( !function_exists( 'bp_activity_set_action' ) )
299
- return false;
300
-
301
- bp_activity_set_action( $bp->friends->id, 'friends_register_activity_action', __( 'New friendship created', 'buddypress' ) );
302
-
303
- do_action( 'friends_register_activity_actions' );
304
- }
305
- add_action( 'bp_register_activity_actions', 'friends_register_activity_actions' );
306
-
307
- function friends_format_notifications( $action, $item_id, $secondary_item_id, $total_items ) {
308
- global $bp;
309
-
310
- switch ( $action ) {
311
- case 'friendship_accepted':
312
- if ( (int)$total_items > 1 ) {
313
- return apply_filters( 'bp_friends_multiple_friendship_accepted_notification', '<a href="' . $bp->loggedin_user->domain . $bp->friends->slug . '/my-friends/newest" title="' . __( 'My Friends', 'buddypress' ) . '">' . sprintf( __('%d friends accepted your friendship requests', 'buddypress' ), (int)$total_items ) . '</a>', (int)$total_items );
314
- } else {
315
- $user_fullname = bp_core_get_user_displayname( $item_id );
316
- $user_url = bp_core_get_user_domain( $item_id );
317
- return apply_filters( 'bp_friends_single_friendship_accepted_notification', '<a href="' . $user_url . '?new" title="' . $user_fullname .'\'s profile">' . sprintf( __( '%s accepted your friendship request', 'buddypress' ), $user_fullname ) . '</a>', $user_fullname );
318
- }
319
- break;
320
-
321
- case 'friendship_request':
322
- if ( (int)$total_items > 1 ) {
323
- return apply_filters( 'bp_friends_multiple_friendship_request_notification', '<a href="' . $bp->loggedin_user->domain . $bp->friends->slug . '/requests/?new" title="' . __( 'Friendship requests', 'buddypress' ) . '">' . sprintf( __('You have %d pending friendship requests', 'buddypress' ), (int)$total_items ) . '</a>', $total_items );
324
- } else {
325
- $user_fullname = bp_core_get_user_displayname( $item_id );
326
- $user_url = bp_core_get_user_domain( $item_id );
327
- return apply_filters( 'bp_friends_single_friendship_request_notification', '<a href="' . $bp->loggedin_user->domain . $bp->friends->slug . '/requests/?new" title="' . __( 'Friendship requests', 'buddypress' ) . '">' . sprintf( __('You have a friendship request from %s', 'buddypress' ), $user_fullname ) . '</a>', $user_fullname );
328
- }
329
- break;
330
- }
331
-
332
- do_action( 'friends_format_notifications', $action, $item_id, $secondary_item_id, $total_items );
333
-
334
- return false;
335
- }
336
-
337
-
338
- /********************************************************************************
339
- * Business Functions
340
- *
341
- * Business functions are where all the magic happens in BuddyPress. They will
342
- * handle the actual saving or manipulation of information. Usually they will
343
- * hand off to a database class for data access, then return
344
- * true or false on success or failure.
345
- */
346
-
347
- function friends_add_friend( $initiator_userid, $friend_userid, $force_accept = false ) {
348
- global $bp;
349
-
350
- $friendship = new BP_Friends_Friendship;
351
-
352
- if ( (int)$friendship->is_confirmed )
353
- return true;
354
-
355
- $friendship->initiator_user_id = $initiator_userid;
356
- $friendship->friend_user_id = $friend_userid;
357
- $friendship->is_confirmed = 0;
358
- $friendship->is_limited = 0;
359
- $friendship->date_created = time();
360
-
361
- if ( $force_accept )
362
- $friendship->is_confirmed = 1;
363
-
364
- if ( $friendship->save() ) {
365
-
366
- if ( !$force_accept ) {
367
- // Add the on screen notification
368
- bp_core_add_notification( $friendship->initiator_user_id, $friendship->friend_user_id, $bp->friends->id, 'friendship_request' );
369
-
370
- // Send the email notification
371
- require_once( BP_PLUGIN_DIR . '/bp-friends/bp-friends-notifications.php' );
372
- friends_notification_new_request( $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id );
373
-
374
- do_action( 'friends_friendship_requested', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id );
375
- } else {
376
- do_action( 'friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id );
377
- }
378
-
379
- return true;
380
- }
381
-
382
- return false;
383
- }
384
-
385
- function friends_remove_friend( $initiator_userid, $friend_userid ) {
386
- global $bp;
387
-
388
- $friendship_id = BP_Friends_Friendship::get_friendship_id( $initiator_userid, $friend_userid );
389
- $friendship = new BP_Friends_Friendship( $friendship_id );
390
-
391
- // Remove the activity stream item for the user who canceled the friendship
392
- friends_delete_activity( array( 'item_id' => $friendship_id, 'type' => 'friendship_accepted', 'user_id' => $bp->displayed_user->id ) );
393
-
394
- do_action( 'friends_friendship_deleted', $friendship_id, $initiator_userid, $friend_userid );
395
-
396
- if ( $friendship->delete() ) {
397
- friends_update_friend_totals( $initiator_userid, $friend_userid, 'remove' );
398
-
399
- return true;
400
- }
401
-
402
- return false;
403
- }
404
-
405
- function friends_accept_friendship( $friendship_id ) {
406
- global $bp;
407
-
408
- $friendship = new BP_Friends_Friendship( $friendship_id, true, false );
409
-
410
- if ( !$friendship->is_confirmed && BP_Friends_Friendship::accept( $friendship_id ) ) {
411
- friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id );
412
-
413
- /* Remove the friend request notice */
414
- bp_core_delete_notifications_for_user_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_request' );
415
-
416
- /* Add a friend accepted notice for the initiating user */