BuddyPress - Version 1.2.4.1

Version Description

= 1.2.4 = Bug fixes and improved upgrade support to WordPress 3.0. Important upgrade.

Download this release

Release Info

Developer apeatling
Plugin Icon 128x128 BuddyPress
Version 1.2.4.1
Comparing to
See all releases

Code changes from version 1.2.4 to 1.2.4.1

bp-activity.php CHANGED
@@ -1,1194 +1,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" 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" 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
  ?>
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,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_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_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
  ?>
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( 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
  ?>
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,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)$bp->site_options['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, $current_site;
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 AND site_id = %d" ), $current_site->id );
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
+ 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
  ?>
bp-blogs/bp-blogs-classes.php CHANGED
@@ -1,310 +1,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.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.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
  ?>
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,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
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
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
  ?>
bp-core.php CHANGED
@@ -1,2107 +1,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( '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( '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
  ?>
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( $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
  ?>
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,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-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-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
  ?>
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( '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
  ?>
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 { 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,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
- 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
+ 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
  ?>
bp-core/bp-core-templatetags.php CHANGED
@@ -1,1960 +1,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 ( $_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 ( $_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
  ?>
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-forums.php CHANGED
@@ -1,535 +1,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
- /* 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
+ /* 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
  ?>
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,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
-
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
+
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
  ?>
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() . $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
  ?>
bp-friends.php CHANGED
@@ -1,651 +1,651 @@
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 */
417
- bp_core_add_notification( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_accepted' );
418
-
419
- $initiator_link = bp_core_get_userlink( $friendship->initiator_user_id );
420
- $friend_link = bp_core_get_userlink( $friendship->friend_user_id );
421
-
422
- /* Record in activity streams for the initiator */
423
- friends_record_activity( array(
424
- 'user_id' => $friendship->initiator_user_id,
425
- 'type' => 'friendship_created',
426
- 'action' => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%s and %s are now friends', 'buddypress' ), $initiator_link, $friend_link ), &$friendship ),
427
- 'item_id' => $friendship_id
428
- ) );
429
-
430
- /* Record in activity streams for the friend */
431
- friends_record_activity( array(
432
- 'user_id' => $friendship->friend_user_id,
433
- 'type' => 'friendship_created',
434
- 'action' => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%s and %s are now friends', 'buddypress' ), $friend_link, $initiator_link ), &$friendship ),
435
- 'item_id' => $friendship_id,
436
- 'hide_sitewide' => true /* We've already got the first entry site wide */
437
- ) );
438
-
439
- /* Send the email notification */
440
- require_once( BP_PLUGIN_DIR . '/bp-friends/bp-friends-notifications.php' );
441
- friends_notification_accepted_request( $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id );
442
-
443
- do_action( 'friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id );
444
- return true;
445
- }
446
-
447
- return false;
448
- }
449
-
450
- function friends_reject_friendship( $friendship_id ) {
451
- $friendship = new BP_Friends_Friendship( $friendship_id, true, false );
452
-
453
- if ( !$friendship->is_confirmed && BP_Friends_Friendship::reject( $friendship_id ) ) {
454
- // Remove the friend request notice
455
- bp_core_delete_notifications_for_user_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_request' );
456
-
457
- do_action( 'friends_friendship_rejected', $friendship_id, &$friendship );
458
- return true;
459
- }
460
-
461
- return false;
462
- }
463
-
464
- function friends_check_friendship( $user_id, $possible_friend_id ) {
465
- global $bp;
466
-
467
- if ( 'is_friend' == BP_Friends_Friendship::check_is_friend( $user_id, $possible_friend_id ) )
468
- return true;
469
-
470
- return false;
471
- }
472
-
473
- function friends_check_friendship_status( $user_id, $possible_friend_id ) {
474
- /* Returns - 'is_friend', 'not_friends', 'pending' */
475
- return BP_Friends_Friendship::check_is_friend( $user_id, $possible_friend_id );
476
- }
477
-
478
- function friends_get_total_friend_count( $user_id = false ) {
479
- global $bp;
480
-
481
- if ( !$user_id )
482
- $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
483
-
484
- if ( !$count = wp_cache_get( 'bp_total_friend_count_' . $user_id, 'bp' ) ) {
485
- $count = get_usermeta( $user_id, 'total_friend_count' );
486
- if ( empty( $count ) ) $count = 0;
487
- wp_cache_set( 'bp_total_friend_count_' . $user_id, $count, 'bp' );
488
- }
489
-
490
- return apply_filters( 'friends_get_total_friend_count', $count );
491
- }
492
-
493
- function friends_check_user_has_friends( $user_id ) {
494
- $friend_count = friends_get_total_friend_count( $user_id );
495
-
496
- if ( empty( $friend_count ) )
497
- return false;
498
-
499
- if ( !(int)$friend_count )
500
- return false;
501
-
502
- return true;
503
- }
504
-
505
- function friends_get_friendship_id( $initiator_user_id, $friend_user_id ) {
506
- return BP_Friends_Friendship::get_friendship_id( $initiator_user_id, $friend_user_id );
507
- }
508
-
509
- function friends_get_friend_user_ids( $user_id, $friend_requests_only = false, $assoc_arr = false, $filter = false ) {
510
- return BP_Friends_Friendship::get_friend_user_ids( $user_id, $friend_requests_only, $assoc_arr, $filter );
511
- }
512
-
513
- function friends_search_friends( $search_terms, $user_id, $pag_num = 10, $pag_page = 1 ) {
514
- return BP_Friends_Friendship::search_friends( $search_terms, $user_id, $pag_num, $pag_page );
515
- }
516
-
517
- function friends_get_friendship_request_user_ids( $user_id ) {
518
- return BP_Friends_Friendship::get_friendship_request_user_ids( $user_id );
519
- }
520
-
521
- function friends_get_recently_active( $user_id, $per_page = false, $page = false, $filter = false ) {
522
- return apply_filters( 'friends_get_recently_active', BP_Core_User::get_users( 'active', $per_page, $page, $user_id, $filter ) );
523
- }
524
-
525
- function friends_get_alphabetically( $user_id, $per_page = false, $page = false, $filter = false ) {
526
- return apply_filters( 'friends_get_alphabetically', BP_Core_User::get_users( 'alphabetical', $per_page, $page, $user_id, $filter ) );
527
- }
528
-
529
- function friends_get_newest( $user_id, $per_page = false, $page = false, $filter = false ) {
530
- return apply_filters( 'friends_get_newest', BP_Core_User::get_users( 'newest', $per_page, $page, $user_id, $filter ) );
531
- }
532
-
533
- function friends_get_bulk_last_active( $friend_ids ) {
534
- return BP_Friends_Friendship::get_bulk_last_active( $friend_ids );
535
- }
536
-
537
- function friends_get_friends_invite_list( $user_id = false ) {
538
- global $bp;
539
-
540
- if ( !$user_id )
541
- $user_id = $bp->loggedin_user->id;
542
-
543
- if ( bp_has_members( 'user_id=' . $user_id . '&type=alphabetical&per_page=0' ) ) {
544
- while ( bp_members() ) : bp_the_member();
545
- $friends[] = array(
546
- 'id' => bp_get_member_user_id(),
547
- 'full_name' => bp_get_member_name()
548
- );
549
- endwhile;
550
- }
551
-
552
- if ( empty($friends) )
553
- return false;
554
-
555
- return $friends;
556
- }
557
-
558
- function friends_count_invitable_friends( $user_id, $group_id ) {
559
- return BP_Friends_Friendship::get_invitable_friend_count( $user_id, $group_id );
560
- }
561
-
562
- function friends_get_friend_count_for_user( $user_id ) {
563
- return BP_Friends_Friendship::total_friend_count( $user_id );
564
- }
565
-
566
- function friends_search_users( $search_terms, $user_id, $pag_num = false, $pag_page = false ) {
567
- global $bp;
568
-
569
- $user_ids = BP_Friends_Friendship::search_users( $search_terms, $user_id, $pag_num, $pag_page );
570
-
571
- if ( !$user_ids )
572
- return false;
573
-
574
- for ( $i = 0; $i < count($user_ids); $i++ ) {
575
- $users[] = new BP_Core_User($user_ids[$i]);
576
- }
577
-
578
- return array( 'users' => $users, 'count' => BP_Friends_Friendship::search_users_count($search_terms) );
579
- }
580
-
581
- function friends_is_friendship_confirmed( $friendship_id ) {
582
- $friendship = new BP_Friends_Friendship( $friendship_id );
583
- return $friendship->is_confirmed;
584
- }
585
-
586
- function friends_update_friend_totals( $initiator_user_id, $friend_user_id, $status = 'add' ) {
587
- if ( 'add' == $status ) {
588
- update_usermeta( $initiator_user_id, 'total_friend_count', (int)get_usermeta( $initiator_user_id, 'total_friend_count' ) + 1 );
589
- update_usermeta( $friend_user_id, 'total_friend_count', (int)get_usermeta( $friend_user_id, 'total_friend_count' ) + 1 );
590
- } else {
591
- update_usermeta( $initiator_user_id, 'total_friend_count', (int)get_usermeta( $initiator_user_id, 'total_friend_count' ) - 1 );
592
- update_usermeta( $friend_user_id, 'total_friend_count', (int)get_usermeta( $friend_user_id, 'total_friend_count' ) - 1 );
593
- }
594
- }
595
-
596
- function friends_remove_data( $user_id ) {
597
- BP_Friends_Friendship::delete_all_for_user($user_id);
598
-
599
- /* Remove usermeta */
600
- delete_usermeta( $user_id, 'total_friend_count' );
601
-
602
- /* Remove friendship requests FROM user */
603
- bp_core_delete_notifications_from_user( $user_id, $bp->friends->id, 'friendship_request' );
604
-
605
- do_action( 'friends_remove_data', $user_id );
606
- }
607
- add_action( 'wpmu_delete_user', 'friends_remove_data' );
608
- add_action( 'delete_user', 'friends_remove_data' );
609
- add_action( 'make_spam_user', 'friends_remove_data' );
610
-
611
-
612
- /********************************************************************************
613
- * Caching
614
- *
615
- * Caching functions handle the clearing of cached objects and pages on specific
616
- * actions throughout BuddyPress.
617
- */
618
-
619
- function friends_clear_friend_object_cache( $friendship_id ) {
620
- if ( !$friendship = new BP_Friends_Friendship( $friendship_id ) )
621
- return false;
622
-
623
- wp_cache_delete( 'friends_friend_ids_' . $friendship->initiator_user_id, 'bp' );
624
- wp_cache_delete( 'friends_friend_ids_' . $friendship->friend_user_id, 'bp' );
625
- wp_cache_delete( 'bp_total_friend_count_' . $friendship->initiator_user_id, 'bp' );
626
- wp_cache_delete( 'bp_total_friend_count_' . $friendship->friend_user_id, 'bp' );
627
- wp_cache_delete( 'popular_users', 'bp' );
628
-
629
- /* Clear the sitewide activity cache */
630
- wp_cache_delete( 'sitewide_activity', 'bp' );
631
- }
632
-
633
- function friends_clear_friend_notifications() {
634
- global $bp;
635
-
636
- if ( isset( $_GET['new'] ) )
637
- bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->friends->id, 'friendship_accepted' );
638
- }
639
- add_action( 'bp_activity_screen_my_activity', 'friends_clear_friend_notifications' );
640
-
641
- // List actions to clear object caches on
642
- add_action( 'friends_friendship_accepted', 'friends_clear_friend_object_cache' );
643
- add_action( 'friends_friendship_deleted', 'friends_clear_friend_object_cache' );
644
-
645
- // List actions to clear super cached pages on, if super cache is installed
646
- add_action( 'friends_friendship_rejected', 'bp_core_clear_cache' );
647
- add_action( 'friends_friendship_accepted', 'bp_core_clear_cache' );
648
- add_action( 'friends_friendship_deleted', 'bp_core_clear_cache' );
649
- add_action( 'friends_friendship_requested', 'bp_core_clear_cache' );
650
-
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