BuddyPress - Version 1.2.4

Version Description

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
Comparing to
See all releases

Code changes from version 1.2.3 to 1.2.4

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->type;
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