BuddyPress - Version 1.2.6

Version Description

Bug fixes and improved WordPress 3.0 support. Important upgrade.

=

Download this release

Release Info

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

Code changes from version 1.2.5.2 to 1.2.6

Files changed (83) hide show
  1. bp-activity.php +1214 -1197
  2. bp-activity/bp-activity-classes.php +552 -552
  3. bp-activity/bp-activity-filters.php +144 -141
  4. bp-activity/bp-activity-notifications.php +17 -14
  5. bp-activity/bp-activity-templatetags.php +1073 -953
  6. bp-activity/feeds/bp-activity-friends-feed.php +59 -59
  7. bp-activity/feeds/bp-activity-personal-feed.php +58 -58
  8. bp-activity/feeds/bp-activity-sitewide-feed.php +54 -54
  9. bp-blogs.php +820 -803
  10. bp-blogs/bp-blogs-classes.php +312 -310
  11. bp-blogs/bp-blogs-templatetags.php +544 -504
  12. bp-blogs/bp-blogs-widgets.php +83 -83
  13. bp-core.php +2174 -2143
  14. bp-core/bp-core-admin.php +250 -250
  15. bp-core/bp-core-adminbar.php +257 -257
  16. bp-core/bp-core-avatars.php +574 -569
  17. bp-core/bp-core-catchuri.php +300 -289
  18. bp-core/bp-core-classes.php +652 -489
  19. bp-core/bp-core-cssjs.php +176 -183
  20. bp-core/bp-core-filters.php +7 -7
  21. bp-core/bp-core-notifications.php +94 -94
  22. bp-core/bp-core-settings.php +197 -198
  23. bp-core/bp-core-signup.php +624 -624
  24. bp-core/bp-core-templatetags.php +2081 -2081
  25. bp-core/bp-core-widgets.php +254 -242
  26. bp-core/bp-core-wpabstraction.php +33 -18
  27. bp-forums.php +555 -555
  28. bp-forums/bb-config.php +10 -10
  29. bp-forums/bp-forums-admin.php +257 -257
  30. bp-forums/bp-forums-bbpress.php +174 -174
  31. bp-forums/bp-forums-filters.php +113 -91
  32. bp-forums/bp-forums-templatetags.php +1104 -1089
  33. bp-friends.php +659 -655
  34. bp-friends/bp-friends-classes.php +333 -333
  35. bp-friends/bp-friends-notifications.php +81 -79
  36. bp-friends/bp-friends-templatetags.php +349 -229
  37. bp-groups.php +2696 -2638
  38. bp-groups/bp-groups-classes.php +1256 -1192
  39. bp-groups/bp-groups-filters.php +107 -107
  40. bp-groups/bp-groups-notifications.php +303 -299
  41. bp-groups/bp-groups-templatetags.php +2273 -2156
  42. bp-groups/bp-groups-widgets.php +142 -142
  43. bp-languages/buddypress.pot +666 -616
  44. bp-loader.php +100 -100
  45. bp-messages.php +599 -592
  46. bp-messages/bp-messages-classes.php +461 -461
  47. bp-messages/bp-messages-cssjs.php +43 -43
  48. bp-messages/bp-messages-filters.php +60 -62
  49. bp-messages/bp-messages-notifications.php +47 -46
  50. bp-messages/bp-messages-templatetags.php +785 -744
  51. bp-themes/bp-default/_inc/ajax.php +13 -13
  52. bp-themes/bp-default/_inc/css/default.css +25 -18
  53. bp-themes/bp-default/_inc/global.js +8 -8
  54. bp-themes/bp-default/_inc/images/rss.png +0 -0
  55. bp-themes/bp-default/activity/entry.php +1 -1
  56. bp-themes/bp-default/activity/index.php +1 -1
  57. bp-themes/bp-default/activity/post-form.php +1 -1
  58. bp-themes/bp-default/blogs/blogs-loop.php +19 -7
  59. bp-themes/bp-default/comments.php +15 -6
  60. bp-themes/bp-default/forums/forums-loop.php +22 -4
  61. bp-themes/bp-default/functions.php +147 -36
  62. bp-themes/bp-default/groups/create.php +1 -1
  63. bp-themes/bp-default/groups/groups-loop.php +26 -7
  64. bp-themes/bp-default/groups/single/activity.php +1 -1
  65. bp-themes/bp-default/groups/single/admin.php +28 -22
  66. bp-themes/bp-default/groups/single/forum.php +1 -1
  67. bp-themes/bp-default/groups/single/forum/topic.php +1 -1
  68. bp-themes/bp-default/groups/single/group-header.php +4 -6
  69. bp-themes/bp-default/members/members-loop.php +24 -7
  70. bp-themes/bp-default/members/single/member-header.php +3 -15
  71. bp-themes/bp-default/members/single/messages/compose.php +1 -1
  72. bp-themes/bp-default/registration/register.php +1 -1
  73. bp-themes/bp-default/searchform.php +0 -0
  74. bp-themes/bp-default/sidebar.php +2 -2
  75. bp-themes/bp-default/single.php +1 -1
  76. bp-themes/bp-default/style.css +1 -1
  77. bp-xprofile.php +1024 -1023
  78. bp-xprofile/bp-xprofile-admin.php +301 -301
  79. bp-xprofile/bp-xprofile-classes.php +912 -902
  80. bp-xprofile/bp-xprofile-cssjs.php +15 -15
  81. bp-xprofile/bp-xprofile-filters.php +147 -113
  82. bp-xprofile/bp-xprofile-templatetags.php +700 -696
  83. readme.txt +4 -4
bp-activity.php CHANGED
@@ -1,1198 +1,1215 @@
1
- <?php
2
-
3
- define ( 'BP_ACTIVITY_DB_VERSION', '2100' );
4
-
5
- /* Define the slug for the component */
6
- if ( !defined( 'BP_ACTIVITY_SLUG' ) )
7
- define ( 'BP_ACTIVITY_SLUG', 'activity' );
8
-
9
- require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-classes.php' );
10
- require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-templatetags.php' );
11
- require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-filters.php' );
12
-
13
- function bp_activity_install() {
14
- global $wpdb, $bp;
15
-
16
- if ( !empty($wpdb->charset) )
17
- $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
18
-
19
- /* Rename the old user activity cached table if needed. */
20
- if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$wpdb->base_prefix}bp_activity_user_activity_cached%'" ) )
21
- $wpdb->query( "RENAME TABLE {$wpdb->base_prefix}bp_activity_user_activity_cached TO {$bp->activity->table_name}" );
22
-
23
- /* Rename fields from pre BP 1.2 */
24
- if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$bp->activity->table_name}%'" ) ) {
25
- if ( $wpdb->get_var( "SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_action'" ) )
26
- $wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE component_action type varchar(75) NOT NULL" );
27
-
28
- if ( $wpdb->get_var( "SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_name'" ) )
29
- $wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE component_name component varchar(75) NOT NULL" );
30
- }
31
-
32
- /**
33
- * Build the tables
34
- */
35
- $sql[] = "CREATE TABLE {$bp->activity->table_name} (
36
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
37
- user_id bigint(20) NOT NULL,
38
- component varchar(75) NOT NULL,
39
- type varchar(75) NOT NULL,
40
- action text NOT NULL,
41
- content longtext NOT NULL,
42
- primary_link varchar(150) NOT NULL,
43
- item_id varchar(75) NOT NULL,
44
- secondary_item_id varchar(75) DEFAULT NULL,
45
- date_recorded datetime NOT NULL,
46
- hide_sitewide bool DEFAULT 0,
47
- mptt_left int(11) NOT NULL DEFAULT 0,
48
- mptt_right int(11) NOT NULL DEFAULT 0,
49
- KEY date_recorded (date_recorded),
50
- KEY user_id (user_id),
51
- KEY item_id (item_id),
52
- KEY secondary_item_id (secondary_item_id),
53
- KEY component (component),
54
- KEY type (type),
55
- KEY mptt_left (mptt_left),
56
- KEY mptt_right (mptt_right),
57
- KEY hide_sitewide (hide_sitewide)
58
- ) {$charset_collate};";
59
-
60
- $sql[] = "CREATE TABLE {$bp->activity->table_name_meta} (
61
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
62
- activity_id bigint(20) NOT NULL,
63
- meta_key varchar(255) DEFAULT NULL,
64
- meta_value longtext DEFAULT NULL,
65
- KEY activity_id (activity_id),
66
- KEY meta_key (meta_key)
67
- ) {$charset_collate};";
68
-
69
- require_once( ABSPATH . 'wp-admin/upgrade-functions.php' );
70
- dbDelta($sql);
71
-
72
- update_site_option( 'bp-activity-db-version', BP_ACTIVITY_DB_VERSION );
73
- }
74
-
75
- function bp_activity_setup_globals() {
76
- global $bp, $wpdb, $current_blog;
77
-
78
- /* Internal identifier */
79
- $bp->activity->id = 'activity';
80
-
81
- $bp->activity->table_name = $wpdb->base_prefix . 'bp_activity';
82
- $bp->activity->table_name_meta = $wpdb->base_prefix . 'bp_activity_meta';
83
- $bp->activity->slug = BP_ACTIVITY_SLUG;
84
- $bp->activity->format_notification_function = 'bp_activity_format_notifications';
85
-
86
- /* Register this in the active components array */
87
- $bp->active_components[$bp->activity->slug] = $bp->activity->id;
88
-
89
- do_action( 'bp_activity_setup_globals' );
90
- }
91
- add_action( 'bp_setup_globals', 'bp_activity_setup_globals' );
92
-
93
- function bp_activity_check_installed() {
94
- global $wpdb, $bp;
95
-
96
- if ( get_site_option( 'bp-activity-db-version' ) < BP_ACTIVITY_DB_VERSION )
97
- bp_activity_install();
98
- }
99
- add_action( 'admin_menu', 'bp_activity_check_installed' );
100
-
101
- function bp_activity_setup_root_component() {
102
- /* Register 'activity' as a root component (for RSS feed use) */
103
- bp_core_add_root_component( BP_ACTIVITY_SLUG );
104
- }
105
- add_action( 'bp_setup_root_components', 'bp_activity_setup_root_component' );
106
-
107
- function bp_activity_setup_nav() {
108
- global $bp;
109
-
110
- /* Add 'Activity' to the main navigation */
111
- bp_core_new_nav_item( array( 'name' => __( 'Activity', 'buddypress' ), 'slug' => $bp->activity->slug, 'position' => 10, 'screen_function' => 'bp_activity_screen_my_activity', 'default_subnav_slug' => 'just-me', 'item_css_id' => $bp->activity->id ) );
112
-
113
- $user_domain = ( !empty( $bp->displayed_user->domain ) ) ? $bp->displayed_user->domain : $bp->loggedin_user->domain;
114
- $user_login = ( !empty( $bp->displayed_user->userdata->user_login ) ) ? $bp->displayed_user->userdata->user_login : $bp->loggedin_user->userdata->user_login;
115
- $activity_link = $user_domain . $bp->activity->slug . '/';
116
-
117
- /* Add the subnav items to the activity nav item if we are using a theme that supports this */
118
- bp_core_new_subnav_item( array( 'name' => __( 'Personal', 'buddypress' ), 'slug' => 'just-me', 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_my_activity', 'position' => 10 ) );
119
-
120
- if ( bp_is_active( 'friends' ) )
121
- bp_core_new_subnav_item( array( 'name' => __( 'Friends', 'buddypress' ), 'slug' => BP_FRIENDS_SLUG, 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_friends', 'position' => 20, 'item_css_id' => 'activity-friends' ) );
122
-
123
- if ( bp_is_active( 'groups' ) )
124
- bp_core_new_subnav_item( array( 'name' => __( 'Groups', 'buddypress' ), 'slug' => BP_GROUPS_SLUG, 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_groups', 'position' => 30, 'item_css_id' => 'activity-groups' ) );
125
-
126
- bp_core_new_subnav_item( array( 'name' => __( 'Favorites', 'buddypress' ), 'slug' => 'favorites', 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_favorites', 'position' => 40, 'item_css_id' => 'activity-favs' ) );
127
- bp_core_new_subnav_item( array( 'name' => sprintf( __( '@%s Mentions', 'buddypress' ), $user_login ), 'slug' => 'mentions', 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_mentions', 'position' => 50, 'item_css_id' => 'activity-mentions' ) );
128
-
129
- if ( $bp->current_component == $bp->activity->slug ) {
130
- if ( bp_is_my_profile() ) {
131
- $bp->bp_options_title = __( 'My Activity', 'buddypress' );
132
- } else {
133
- $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
134
- $bp->bp_options_title = $bp->displayed_user->fullname;
135
- }
136
- }
137
-
138
- do_action( 'bp_activity_setup_nav' );
139
- }
140
- add_action( 'bp_setup_nav', 'bp_activity_setup_nav' );
141
-
142
- function bp_activity_directory_activity_setup() {
143
- global $bp;
144
-
145
- if ( $bp->current_component == $bp->activity->slug && empty( $bp->current_action ) ) {
146
- $bp->is_directory = true;
147
-
148
- do_action( 'bp_activity_directory_activity_setup' );
149
- bp_core_load_template( apply_filters( 'bp_activity_directory_activity_setup', 'activity/index' ) );
150
- }
151
- }
152
- add_action( 'wp', 'bp_activity_directory_activity_setup', 2 );
153
-
154
-
155
- /********************************************************************************
156
- * Screen Functions
157
- *
158
- * Screen functions are the controllers of BuddyPress. They will execute when their
159
- * specific URL is caught. They will first save or manipulate data using business
160
- * functions, then pass on the user to a template file.
161
- */
162
-
163
- function bp_activity_screen_my_activity() {
164
- do_action( 'bp_activity_screen_my_activity' );
165
- bp_core_load_template( apply_filters( 'bp_activity_template_my_activity', 'members/single/home' ) );
166
- }
167
-
168
- function bp_activity_screen_friends() {
169
- global $bp;
170
-
171
- if ( !bp_is_active( 'friends' ) )
172
- return false;
173
-
174
- if ( !is_site_admin() )
175
- $bp->is_item_admin = false;
176
-
177
- do_action( 'bp_activity_screen_friends' );
178
- bp_core_load_template( apply_filters( 'bp_activity_template_friends_activity', 'members/single/home' ) );
179
- }
180
-
181
- function bp_activity_screen_groups() {
182
- global $bp;
183
-
184
- if ( !bp_is_active( 'groups' ) )
185
- return false;
186
-
187
- if ( !is_site_admin() )
188
- $bp->is_item_admin = false;
189
-
190
- do_action( 'bp_activity_screen_groups' );
191
- bp_core_load_template( apply_filters( 'bp_activity_template_groups_activity', 'members/single/home' ) );
192
- }
193
-
194
- function bp_activity_screen_favorites() {
195
- global $bp;
196
-
197
- if ( !is_site_admin() )
198
- $bp->is_item_admin = false;
199
-
200
- do_action( 'bp_activity_screen_favorites' );
201
- bp_core_load_template( apply_filters( 'bp_activity_template_favorite_activity', 'members/single/home' ) );
202
- }
203
-
204
- function bp_activity_screen_mentions() {
205
- global $bp;
206
-
207
- if ( !is_site_admin() )
208
- $bp->is_item_admin = false;
209
-
210
- do_action( 'bp_activity_screen_mentions' );
211
- bp_core_load_template( apply_filters( 'bp_activity_template_mention_activity', 'members/single/home' ) );
212
- }
213
-
214
- function bp_activity_screen_single_activity_permalink() {
215
- global $bp;
216
-
217
- if ( !$bp->displayed_user->id || $bp->current_component != $bp->activity->slug )
218
- return false;
219
-
220
- if ( empty( $bp->current_action ) || !is_numeric( $bp->current_action ) )
221
- return false;
222
-
223
- /* Get the activity details */
224
- $activity = bp_activity_get_specific( array( 'activity_ids' => $bp->current_action ) );
225
-
226
- if ( !$activity = $activity['activities'][0] )
227
- bp_core_redirect( $bp->root_domain );
228
-
229
- $has_access = true;
230
- /* Redirect based on the type of activity */
231
- if ( $activity->component == $bp->groups->id ) {
232
- if ( !function_exists( 'groups_get_group' ) )
233
- bp_core_redirect( $bp->root_domain );
234
-
235
- if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) ) {
236
- /* Check to see if the group is not public, if so, check the user has access to see this activity */
237
- if ( 'public' != $group->status ) {
238
- if ( !groups_is_user_member( $bp->loggedin_user->id, $group->id ) )
239
- $has_access = false;
240
- }
241
- }
242
- }
243
-
244
- $has_access = apply_filters( 'bp_activity_permalink_access', $has_access, &$activity );
245
-
246
- do_action( 'bp_activity_screen_single_activity_permalink', $activity, $has_access );
247
-
248
- if ( !$has_access ) {
249
- bp_core_add_message( __( 'You do not have access to this activity.', 'buddypress' ), 'error' );
250
-
251
- if ( is_user_logged_in() )
252
- bp_core_redirect( $bp->loggedin_user->domain );
253
- else
254
- bp_core_redirect( site_url( 'wp-login.php?redirect_to=' . clean_url( $bp->root_domain . '/' . $bp->activity->slug . '/p/' . $bp->current_action ) ) );
255
- }
256
-
257
- bp_core_load_template( apply_filters( 'bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink' ) );
258
- }
259
- /* This screen is not attached to a nav item, so we need to add an action for it. */
260
- add_action( 'wp', 'bp_activity_screen_single_activity_permalink', 3 );
261
-
262
- function bp_activity_screen_notification_settings() {
263
- global $bp; ?>
264
- <table class="notification-settings zebra" id="activity-notification-settings">
265
- <thead>
266
- <tr>
267
- <th class="icon"></th>
268
- <th class="title"><?php _e( 'Activity', 'buddypress' ) ?></th>
269
- <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>
270
- <th class="no"><?php _e( 'No', 'buddypress' )?></th>
271
- </tr>
272
- </thead>
273
-
274
- <tbody>
275
- <tr>
276
- <td></td>
277
- <td><?php printf( __( 'A member mentions you in an update using "@%s"', 'buddypress' ), bp_core_get_username( $bp->loggedin_user->id, $bp->loggedin_user->userdata->user_nicename, $bp->loggedin_user->userdata->user_login ) ) ?></td>
278
- <td class="yes"><input type="radio" name="notifications[notification_activity_new_mention]" value="yes" <?php if ( !get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_mention' ) || 'yes' == get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_mention' ) ) { ?>checked="checked" <?php } ?>/></td>
279
- <td class="no"><input type="radio" name="notifications[notification_activity_new_mention]" value="no" <?php if ( 'no' == get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_mention' ) ) { ?>checked="checked" <?php } ?>/></td>
280
- </tr>
281
- <tr>
282
- <td></td>
283
- <td><?php printf( __( "A member replies to an update or comment you've posted", 'buddypress' ), $current_user->user_login ) ?></td>
284
- <td class="yes"><input type="radio" name="notifications[notification_activity_new_reply]" value="yes" <?php if ( !get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_reply' ) || 'yes' == get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_reply' ) ) { ?>checked="checked" <?php } ?>/></td>
285
- <td class="no"><input type="radio" name="notifications[notification_activity_new_reply]" value="no" <?php if ( 'no' == get_usermeta( $bp->loggedin_user->id, 'notification_activity_new_reply' ) ) { ?>checked="checked" <?php } ?>/></td>
286
- </tr>
287
-
288
- <?php do_action( 'bp_activity_screen_notification_settings' ) ?>
289
- </tbody>
290
- </table>
291
- <?php
292
- }
293
- add_action( 'bp_notification_settings', 'bp_activity_screen_notification_settings', 1 );
294
-
295
- /********************************************************************************
296
- * Action Functions
297
- *
298
- * Action functions are exactly the same as screen functions, however they do not
299
- * have a template screen associated with them. Usually they will send the user
300
- * back to the default screen after execution.
301
- */
302
-
303
- function bp_activity_action_permalink_router() {
304
- global $bp;
305
-
306
- if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'p' )
307
- return false;
308
-
309
- if ( empty( $bp->action_variables[0] ) || !is_numeric( $bp->action_variables[0] ) )
310
- return false;
311
-
312
- /* Get the activity details */
313
- $activity = bp_activity_get_specific( array( 'activity_ids' => $bp->action_variables[0] ) );
314
-
315
- if ( !$activity = $activity['activities'][0] )
316
- bp_core_redirect( $bp->root_domain );
317
-
318
- $redirect = false;
319
- /* Redirect based on the type of activity */
320
- if ( $activity->component == $bp->groups->id ) {
321
- if ( $activity->user_id )
322
- $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id . '/';
323
- else {
324
- if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) )
325
- $redirect = bp_get_group_permalink( $group ) . $bp->activity->slug . '/' . $activity->id . '/';
326
- }
327
- } else
328
- $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id;
329
-
330
- $redirect = apply_filters( 'bp_activity_permalink_redirect_url', $redirect, &$activity );
331
-
332
- if ( !$redirect )
333
- bp_core_redirect( $bp->root_domain );
334
-
335
- /* Redirect to the actual activity permalink page */
336
- bp_core_redirect( $redirect );
337
- }
338
- add_action( 'wp', 'bp_activity_action_permalink_router', 3 );
339
-
340
- function bp_activity_action_delete_activity() {
341
- global $bp;
342
-
343
- if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'delete' )
344
- return false;
345
-
346
- if ( empty( $bp->action_variables[0] ) || !is_numeric( $bp->action_variables[0] ) )
347
- return false;
348
-
349
- /* Check the nonce */
350
- check_admin_referer( 'bp_activity_delete_link' );
351
-
352
- $activity_id = $bp->action_variables[0];
353
- $activity = new BP_Activity_Activity( $activity_id );
354
-
355
- /* Check access */
356
- if ( !is_site_admin() && $activity->user_id != $bp->loggedin_user->id )
357
- return false;
358
-
359
- /* Call the action before the delete so plugins can still fetch information about it */
360
- do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id );
361
-
362
- /* Now delete the activity item */
363
- if ( bp_activity_delete( array( 'id' => $activity_id, 'user_id' => $activity->user_id ) ) )
364
- bp_core_add_message( __( 'Activity deleted', 'buddypress' ) );
365
- else
366
- bp_core_add_message( __( 'There was an error when deleting that activity', 'buddypress' ), 'error' );
367
-
368
- bp_core_redirect( wp_get_referer() );
369
- }
370
- add_action( 'wp', 'bp_activity_action_delete_activity', 3 );
371
-
372
- function bp_activity_action_post_update() {
373
- global $bp;
374
-
375
- if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'post' )
376
- return false;
377
-
378
- /* Check the nonce */
379
- check_admin_referer( 'post_update', '_wpnonce_post_update' );
380
-
381
- $content = apply_filters( 'bp_activity_post_update_content', $_POST['whats-new'] );
382
- $object = apply_filters( 'bp_activity_post_update_object', $_POST['whats-new-post-object'] );
383
- $item_id = apply_filters( 'bp_activity_post_update_item_id', $_POST['whats-new-post-in'] );
384
-
385
- if ( empty( $content ) ) {
386
- bp_core_add_message( __( 'Please enter some content to post.', 'buddypress' ), 'error' );
387
- bp_core_redirect( wp_get_referer() );
388
- }
389
-
390
- if ( !(int)$item_id ) {
391
- $activity_id = bp_activity_post_update( array( 'content' => $content ) );
392
-
393
- } else if ( 'groups' == $object && function_exists( 'groups_post_update' ) ) {
394
- if ( (int)$item_id ) {
395
- $activity_id = groups_post_update( array( 'content' => $content, 'group_id' => $item_id ) );
396
- }
397
- } else
398
- $activity_id = apply_filters( 'bp_activity_custom_update', $object, $item_id, $content );
399
-
400
- if ( !empty( $activity_id ) )
401
- bp_core_add_message( __( 'Update Posted!', 'buddypress' ) );
402
- else
403
- bp_core_add_message( __( 'There was an error when posting your update, please try again.', 'buddypress' ), 'error' );
404
-
405
- bp_core_redirect( wp_get_referer() );
406
- }
407
- add_action( 'wp', 'bp_activity_action_post_update', 3 );
408
-
409
- function bp_activity_action_post_comment() {
410
- global $bp;
411
-
412
- if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'reply' )
413
- return false;
414
-
415
- /* Check the nonce */
416
- check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );
417
-
418
- $activity_id = apply_filters( 'bp_activity_post_comment_activity_id', $_POST['comment_form_id'] );
419
- $content = apply_filters( 'bp_activity_post_comment_content', $_POST['ac_input_' . $activity_id] );
420
-
421
- if ( empty( $content ) ) {
422
- bp_core_add_message( __( 'Please do not leave the comment area blank.', 'buddypress' ), 'error' );
423
- bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
424
- }
425
-
426
- $comment_id = bp_activity_new_comment( array(
427
- 'content' => $content,
428
- 'activity_id' => $activity_id,
429
- 'parent_id' => $parent_id
430
- ));
431
-
432
- if ( !empty( $comment_id ) )
433
- bp_core_add_message( __( 'Reply Posted!', 'buddypress' ) );
434
- else
435
- bp_core_add_message( __( 'There was an error posting that reply, please try again.', 'buddypress' ), 'error' );
436
-
437
- bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
438
- }
439
- add_action( 'wp', 'bp_activity_action_post_comment', 3 );
440
-
441
- function bp_activity_action_mark_favorite() {
442
- global $bp;
443
-
444
- if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'favorite' )
445
- return false;
446
-
447
- /* Check the nonce */
448
- check_admin_referer( 'mark_favorite' );
449
-
450
- if ( bp_activity_add_user_favorite( $bp->action_variables[0] ) )
451
- bp_core_add_message( __( 'Activity marked as favorite.', 'buddypress' ) );
452
- else
453
- bp_core_add_message( __( 'There was an error marking that activity as a favorite, please try again.', 'buddypress' ), 'error' );
454
-
455
- bp_core_redirect( wp_get_referer() . '#activity-' . $bp->action_variables[0] );
456
- }
457
- add_action( 'wp', 'bp_activity_action_mark_favorite', 3 );
458
-
459
- function bp_activity_action_remove_favorite() {
460
- global $bp;
461
-
462
- if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'unfavorite' )
463
- return false;
464
-
465
- /* Check the nonce */
466
- check_admin_referer( 'unmark_favorite' );
467
-
468
- if ( bp_activity_remove_user_favorite( $bp->action_variables[0] ) )
469
- bp_core_add_message( __( 'Activity removed as favorite.', 'buddypress' ) );
470
- else
471
- bp_core_add_message( __( 'There was an error removing that activity as a favorite, please try again.', 'buddypress' ), 'error' );
472
-
473
- bp_core_redirect( wp_get_referer() . '#activity-' . $bp->action_variables[0] );
474
- }
475
- add_action( 'wp', 'bp_activity_action_remove_favorite', 3 );
476
-
477
- function bp_activity_action_sitewide_feed() {
478
- global $bp, $wp_query;
479
-
480
- if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'feed' || $bp->displayed_user->id || $bp->groups->current_group )
481
- return false;
482
-
483
- $wp_query->is_404 = false;
484
- status_header( 200 );
485
-
486
- include_once( 'bp-activity/feeds/bp-activity-sitewide-feed.php' );
487
- die;
488
- }
489
- add_action( 'wp', 'bp_activity_action_sitewide_feed', 3 );
490
-
491
- function bp_activity_action_personal_feed() {
492
- global $bp, $wp_query;
493
-
494
- if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'feed' )
495
- return false;
496
-
497
- $wp_query->is_404 = false;
498
- status_header( 200 );
499
-
500
- include_once( 'bp-activity/feeds/bp-activity-personal-feed.php' );
501
- die;
502
- }
503
- add_action( 'wp', 'bp_activity_action_personal_feed', 3 );
504
-
505
- function bp_activity_action_friends_feed() {
506
- global $bp, $wp_query;
507
-
508
- if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'friends' || $bp->action_variables[0] != 'feed' )
509
- return false;
510
-
511
- $wp_query->is_404 = false;
512
- status_header( 200 );
513
-
514
- include_once( 'bp-activity/feeds/bp-activity-friends-feed.php' );
515
- die;
516
- }
517
- add_action( 'wp', 'bp_activity_action_friends_feed', 3 );
518
-
519
- function bp_activity_action_my_groups_feed() {
520
- global $bp, $wp_query;
521
-
522
- if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'groups' || $bp->action_variables[0] != 'feed' )
523
- return false;
524
-
525
- $wp_query->is_404 = false;
526
- status_header( 200 );
527
-
528
- include_once( 'bp-activity/feeds/bp-activity-mygroups-feed.php' );
529
- die;
530
- }
531
- add_action( 'wp', 'bp_activity_action_my_groups_feed', 3 );
532
-
533
- function bp_activity_action_mentions_feed() {
534
- global $bp, $wp_query;
535
-
536
- if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'mentions' || $bp->action_variables[0] != 'feed' )
537
- return false;
538
-
539
- $wp_query->is_404 = false;
540
- status_header( 200 );
541
-
542
- include_once( 'bp-activity/feeds/bp-activity-mentions-feed.php' );
543
- die;
544
- }
545
- add_action( 'wp', 'bp_activity_action_mentions_feed', 3 );
546
-
547
- function bp_activity_action_favorites_feed() {
548
- global $bp, $wp_query;
549
-
550
- if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'favorites' || $bp->action_variables[0] != 'feed' )
551
- return false;
552
-
553
- $wp_query->is_404 = false;
554
- status_header( 200 );
555
-
556
- include_once( 'bp-activity/feeds/bp-activity-favorites-feed.php' );
557
- die;
558
- }
559
- add_action( 'wp', 'bp_activity_action_favorites_feed', 3 );
560
-
561
- /********************************************************************************
562
- * Business Functions
563
- *
564
- * Business functions are where all the magic happens in BuddyPress. They will
565
- * handle the actual saving or manipulation of information. Usually they will
566
- * hand off to a database class for data access, then return
567
- * true or false on success or failure.
568
- */
569
-
570
- function bp_activity_get( $args = '' ) {
571
- $defaults = array(
572
- 'max' => false, // Maximum number of results to return
573
- 'page' => 1, // page 1 without a per_page will result in no pagination.
574
- 'per_page' => false, // results per page
575
- 'sort' => 'DESC', // sort ASC or DESC
576
- 'display_comments' => false, // false for no comments. 'stream' for within stream display, 'threaded' for below each activity item
577
-
578
- 'search_terms' => false, // Pass search terms as a string
579
- 'show_hidden' => false, // Show activity items that are hidden site-wide?
580
-
581
- /**
582
- * Pass filters as an array -- all filter items can be multiple values comma separated:
583
- * array(
584
- * 'user_id' => false, // user_id to filter on
585
- * 'object' => false, // object to filter on e.g. groups, profile, status, friends
586
- * 'action' => false, // action to filter on e.g. activity_update, profile_updated
587
- * 'primary_id' => false, // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
588
- * 'secondary_id' => false, // secondary object ID to filter on e.g. a post_id
589
- * );
590
- */
591
- 'filter' => array()
592
- );
593
-
594
- $r = wp_parse_args( $args, $defaults );
595
- extract( $r, EXTR_SKIP );
596
-
597
- /* Attempt to return a cached copy of the first page of sitewide activity. */
598
- if ( 1 == (int)$page && empty( $max ) && empty( $search_terms ) && empty( $filter ) && 'DESC' == $sort ) {
599
- if ( !$activity = wp_cache_get( 'bp_activity_sitewide_front', 'bp' ) ) {
600
- $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden );
601
- wp_cache_set( 'bp_activity_sitewide_front', $activity, 'bp' );
602
- }
603
- } else
604
- $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden );
605
-
606
- return apply_filters( 'bp_activity_get', $activity, &$r );
607
- }
608
-
609
- function bp_activity_get_specific( $args = '' ) {
610
- $defaults = array(
611
- 'activity_ids' => false, // A single activity_id or array of IDs.
612
- 'page' => 1, // page 1 without a per_page will result in no pagination.
613
- 'per_page' => false, // results per page
614
- 'max' => false, // Maximum number of results to return
615
- 'sort' => 'DESC', // sort ASC or DESC
616
- 'display_comments' => false // true or false to display threaded comments for these specific activity items
617
- );
618
-
619
- $r = wp_parse_args( $args, $defaults );
620
- extract( $r, EXTR_SKIP );
621
-
622
- return apply_filters( 'bp_activity_get_specific', BP_Activity_Activity::get_specific( $activity_ids, $max, $page, $per_page, $sort, $display_comments ) );
623
- }
624
-
625
- function bp_activity_add( $args = '' ) {
626
- global $bp, $wpdb;
627
-
628
- $defaults = array(
629
- 'id' => false, // Pass an existing activity ID to update an existing entry.
630
-
631
- 'action' => '', // The activity action - e.g. "Jon Doe posted an update"
632
- 'content' => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!"
633
-
634
- 'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent
635
- 'type' => false, // The activity type e.g. activity_update, profile_updated
636
- 'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink)
637
-
638
- 'user_id' => $bp->loggedin_user->id, // Optional: The user to record the activity for, can be false if this activity is not for a user.
639
- 'item_id' => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id
640
- 'secondary_item_id' => false, // Optional: A second ID used to further filter e.g. a comment_id
641
- 'recorded_time' => gmdate( "Y-m-d H:i:s" ), // The GMT time that this activity was recorded
642
- 'hide_sitewide' => false // Should this be hidden on the sitewide activity stream?
643
- );
644
-
645
- $params = wp_parse_args( $args, $defaults );
646
- extract( $params, EXTR_SKIP );
647
-
648
- /* Make sure we are backwards compatible */
649
- if ( empty( $component ) && !empty( $component_name ) )
650
- $component = $component_name;
651
-
652
- if ( empty( $type ) && !empty( $component_action ) )
653
- $type = $component_action;
654
-
655
- $activity = new BP_Activity_Activity( $id );
656
-
657
- $activity->user_id = $user_id;
658
- $activity->component = $component;
659
- $activity->type = $type;
660
- $activity->action = $action;
661
- $activity->content = $content;
662
- $activity->primary_link = $primary_link;
663
- $activity->item_id = $item_id;
664
- $activity->secondary_item_id = $secondary_item_id;
665
- $activity->date_recorded = $recorded_time;
666
- $activity->hide_sitewide = $hide_sitewide;
667
-
668
- if ( !$activity->save() )
669
- return false;
670
-
671
- /* If this is an activity comment, rebuild the tree */
672
- if ( 'activity_comment' == $activity->type )
673
- BP_Activity_Activity::rebuild_activity_comment_tree( $activity->item_id );
674
-
675
- wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
676
- do_action( 'bp_activity_add', $params );
677
-
678
- return $activity->id;
679
- }
680
-
681
- function bp_activity_post_update( $args = '' ) {
682
- global $bp;
683
-
684
- $defaults = array(
685
- 'content' => false,
686
- 'user_id' => $bp->loggedin_user->id
687
- );
688
-
689
- $r = wp_parse_args( $args, $defaults );
690
- extract( $r, EXTR_SKIP );
691
-
692
- if ( empty( $content ) || !strlen( trim( $content ) ) )
693
- return false;
694
-
695
- /* Record this on the user's profile */
696
- $from_user_link = bp_core_get_userlink( $user_id );
697
- $activity_action = sprintf( __( '%s posted an update:', 'buddypress' ), $from_user_link );
698
- $activity_content = $content;
699
-
700
- $primary_link = bp_core_get_userlink( $user_id, false, true );
701
-
702
- /* Now write the values */
703
- $activity_id = bp_activity_add( array(
704
- 'user_id' => $user_id,
705
- 'action' => apply_filters( 'bp_activity_new_update_action', $activity_action ),
706
- 'content' => apply_filters( 'bp_activity_new_update_content', $activity_content ),
707
- 'primary_link' => apply_filters( 'bp_activity_new_update_primary_link', $primary_link ),
708
- 'component' => $bp->activity->id,
709
- 'type' => 'activity_update'
710
- ) );
711
-
712
- /* Add this update to the "latest update" usermeta so it can be fetched anywhere. */
713
- update_usermeta( $bp->loggedin_user->id, 'bp_latest_update', array( 'id' => $activity_id, 'content' => wp_filter_kses( $content ) ) );
714
-
715
- /* Require the notifications code so email notifications can be set on the 'bp_activity_posted_update' action. */
716
- require_once( BP_PLUGIN_DIR . '/bp-activity/bp-activity-notifications.php' );
717
-
718
- do_action( 'bp_activity_posted_update', $content, $user_id, $activity_id );
719
-
720
- return $activity_id;
721
- }
722
-
723
- function bp_activity_new_comment( $args = '' ) {
724
- global $bp;
725
-
726
- $defaults = array(
727
- 'id' => false,
728
- 'content' => false,
729
- 'user_id' => $bp->loggedin_user->id,
730
- 'activity_id' => false, // ID of the root activity item
731
- 'parent_id' => false // ID of a parent comment (optional)
732
- );
733
-
734
- $params = wp_parse_args( $args, $defaults );
735
- extract( $params, EXTR_SKIP );
736
-
737
- if ( empty($content) || empty($user_id) || empty($activity_id) )
738
- return false;
739
-
740
- if ( empty($parent_id) )
741
- $parent_id = $activity_id;
742
-
743
- /* Check to see if the parent activity is hidden, and if so, hide this comment publically. */
744
- $activity = new BP_Activity_Activity( $activity_id );
745
- $is_hidden = ( (int)$activity->hide_sitewide ) ? 1 : 0;
746
-
747
- /* Insert the activity comment */
748
- $comment_id = bp_activity_add( array(
749
- 'id' => $id,
750
- 'action' => apply_filters( 'bp_activity_comment_action', sprintf( __( '%s posted a new activity comment:', 'buddypress' ), bp_core_get_userlink( $user_id ) ) ),
751
- 'content' => apply_filters( 'bp_activity_comment_content', $content ),
752
- 'component' => $bp->activity->id,
753
- 'type' => 'activity_comment',
754
- 'user_id' => $user_id,
755
- 'item_id' => $activity_id,
756
- 'secondary_item_id' => $parent_id,
757
- 'hide_sitewide' => $is_hidden
758
- ) );
759
-
760
- /* Send an email notification if settings allow */
761
- require_once( BP_PLUGIN_DIR . '/bp-activity/bp-activity-notifications.php' );
762
- bp_activity_new_comment_notification( $comment_id, $user_id, $params );
763
-
764
- /* Clear the comment cache for this activity */
765
- wp_cache_delete( 'bp_activity_comments_' . $parent_id );
766
-
767
- do_action( 'bp_activity_comment_posted', $comment_id, $params );
768
-
769
- return $comment_id;
770
- }
771
-
772
- /**
773
- * bp_activity_get_activity_id()
774
- *
775
- * Fetch the activity_id for an existing activity entry in the DB.
776
- *
777
- * @package BuddyPress Activity
778
- */
779
- function bp_activity_get_activity_id( $args = '' ) {
780
- $defaults = array(
781
- 'user_id' => false,
782
- 'component' => false,
783
- 'type' => false,
784
- 'item_id' => false,
785
- 'secondary_item_id' => false,
786
- 'action' => false,
787
- 'content' => false,
788
- 'date_recorded' => false,
789
- );
790
-
791
- $r = wp_parse_args( $args, $defaults );
792
- extract( $r, EXTR_SKIP );
793
-
794
- return apply_filters( 'bp_activity_get_activity_id', BP_Activity_Activity::get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content, $date_recorded ) );
795
- }
796
-
797
- /***
798
- * Deleting Activity
799
- *
800
- * If you're looking to hook into one action that provides the ID(s) of
801
- * the activity/activities deleted, then use:
802
- *
803
- * add_action( 'bp_activity_deleted_activities', 'my_function' );
804
- *
805
- * The action passes one parameter that is a single activity ID or an
806
- * array of activity IDs depending on the number deleted.
807
- *
808
- * If you are deleting an activity comment please use bp_activity_delete_comment();
809
- */
810
-
811
- function bp_activity_delete( $args = '' ) {
812
- global $bp;
813
-
814
- /* Pass one or more the of following variables to delete by those variables */
815
- $defaults = array(
816
- 'id' => false,
817
- 'action' => false,
818
- 'content' => false,
819
- 'component' => false,
820
- 'type' => false,
821
- 'primary_link' => false,
822
- 'user_id' => false,
823
- 'item_id' => false,
824
- 'secondary_item_id' => false,
825
- 'date_recorded' => false,
826
- 'hide_sitewide' => false
827
- );
828
-
829
- $args = wp_parse_args( $args, $defaults );
830
-
831
- if ( !$activity_ids_deleted = BP_Activity_Activity::delete( $args ) )
832
- return false;
833
-
834
- /* Check if the user's latest update has been deleted */
835
- if ( empty( $args['user_id'] ) )
836
- $user_id = $bp->loggedin_user->id;
837
- else
838
- $user_id = $args['user_id'];
839
-
840
- $latest_update = get_usermeta( $user_id, 'bp_latest_update' );
841
- if ( !empty( $latest_update ) ) {
842
- if ( in_array( (int)$latest_update['id'], (array)$activity_ids_deleted ) )
843
- delete_usermeta( $user_id, 'bp_latest_update' );
844
- }
845
-
846
- do_action( 'bp_activity_delete', $args );
847
- do_action( 'bp_activity_deleted_activities', $activity_ids_deleted );
848
-
849
- wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
850
-
851
- return true;
852
- }
853
- /* The following functions have been deprecated in place of bp_activity_delete() */
854
- function bp_activity_delete_by_item_id( $args = '' ) {
855
- global $bp;
856
-
857
- $defaults = array( 'item_id' => false, 'component' => false, 'type' => false, 'user_id' => false, 'secondary_item_id' => false );
858
- $r = wp_parse_args( $args, $defaults );
859
- extract( $r, EXTR_SKIP );
860
-
861
- return bp_activity_delete( array( 'item_id' => $item_id, 'component' => $component, 'type' => $type, 'user_id' => $user_id, 'secondary_item_id' => $secondary_item_id ) );
862
- }
863
-
864
- function bp_activity_delete_by_activity_id( $activity_id ) {
865
- return bp_activity_delete( array( 'id' => $activity_id ) );
866
- }
867
-
868
- function bp_activity_delete_by_content( $user_id, $content, $component, $type ) {
869
- return bp_activity_delete( array( 'user_id' => $user_id, 'content' => $content, 'component' => $component, 'type' => $type ) );
870
- }
871
-
872
- function bp_activity_delete_for_user_by_component( $user_id, $component ) {
873
- return bp_activity_delete( array( 'user_id' => $user_id, 'component' => $component ) );
874
- }
875
- /* End deprecation */
876
-
877
- function bp_activity_delete_comment( $activity_id, $comment_id ) {
878
- /***
879
- * You may want to hook into this filter if you want to override this function and
880
- * handle the deletion of child comments differently. Make sure you return false.
881
- */
882
- if ( !apply_filters( 'bp_activity_delete_comment_pre', true, $activity_id, $comment_id ) )
883
- return false;
884
-
885
- /* Delete any children of this comment. */
886
- bp_activity_delete_children( $activity_id, $comment_id );
887
-
888
- /* Delete the actual comment */
889
- if ( !bp_activity_delete( array( 'id' => $comment_id, 'type' => 'activity_comment' ) ) )
890
- return false;
891
-
892
- /* Recalculate the comment tree */
893
- BP_Activity_Activity::rebuild_activity_comment_tree( $activity_id );
894
-
895
- do_action( 'bp_activity_delete_comment', $activity_id, $comment_id );
896
-
897
- return true;
898
- }
899
- function bp_activity_delete_children( $activity_id, $comment_id) {
900
- /* Recursively delete all children of this comment. */
901
- if ( $children = BP_Activity_Activity::get_child_comments( $comment_id ) ) {
902
- foreach( (array)$children as $child )
903
- bp_activity_delete_children( $activity_id, $child->id );
904
- }
905
- bp_activity_delete( array( 'secondary_item_id' => $comment_id, 'type' => 'activity_comment', 'item_id' => $activity_id ) );
906
- }
907
-
908
- function bp_activity_get_permalink( $activity_id, $activity_obj = false ) {
909
- global $bp;
910
-
911
- if ( !$activity_obj )
912
- $activity_obj = new BP_Activity_Activity( $activity_id );
913
-
914
- if ( 'new_blog_post' == $activity_obj->type || 'new_blog_comment' == $activity_obj->type || 'new_forum_topic' == $activity_obj->type || 'new_forum_post' == $activity_obj->type )
915
- $link = $activity_obj->primary_link;
916
- else {
917
- if ( 'activity_comment' == $activity_obj->type )
918
- $link = $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activity_obj->item_id . '/';
919
- else
920
- $link = $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activity_obj->id . '/';
921
- }
922
-
923
- return apply_filters( 'bp_activity_get_permalink', $link );
924
- }
925
-
926
- function bp_activity_hide_user_activity( $user_id ) {
927
- return BP_Activity_Activity::hide_all_for_user( $user_id );
928
- }
929
-
930
- /**
931
- * bp_activity_thumbnail_content_images()
932
- *
933
- * Take content, remove all images and replace them with one thumbnail image.
934
- *
935
- * @package BuddyPress Activity
936
- * @param $content str - The content to work with
937
- * @return $content str - The content with images stripped and replaced with a single thumb.
938
- */
939
- function bp_activity_thumbnail_content_images( $content ) {
940
- preg_match_all( '/<img[^>]*>/Ui', $content, $matches );
941
- $content = preg_replace('/<img[^>]*>/Ui', '', $content );
942
-
943
- if ( !empty( $matches ) ) {
944
- /* Get the SRC value */
945
- preg_match( '/<img.*?(src\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $src );
946
-
947
- /* Get the width and height */
948
- preg_match( '/<img.*?(height\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $height );
949
- preg_match( '/<img.*?(width\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $width );
950
-
951
- if ( !empty( $src ) ) {
952
- $src = substr( substr( str_replace( 'src=', '', $src[1] ), 0, -1 ), 1 );
953
- $height = substr( substr( str_replace( 'height=', '', $height[1] ), 0, -1 ), 1 );
954
- $width = substr( substr( str_replace( 'width=', '', $width[1] ), 0, -1 ), 1 );
955
-
956
- if ( empty( $width ) || empty( $height ) ) {
957
- $width = 100;
958
- $height = 100;
959
- }
960
-
961
- $ratio = (int)$width / (int)$height;
962
- $new_height = 100;
963
- $new_width = $new_height * $ratio;
964
-
965
- $content = '<img src="' . esc_attr( $src) . '" width="' . $new_width . '" height="' . $new_height . '" alt="' . __( 'Thumbnail', 'buddypress' ) . '" class="align-left thumbnail" />' . $content;
966
- }
967
- }
968
-
969
- return apply_filters( 'bp_activity_thumbnail_content_images', $content, $matches );
970
- }
971
-
972
- function bp_activity_set_action( $component_id, $key, $value ) {
973
- global $bp;
974
-
975
- if ( empty( $component_id ) || empty( $key ) || empty( $value ) )
976
- return false;
977
-
978
- $bp->activity->actions->{$component_id}->{$key} = apply_filters( 'bp_activity_set_action', array(
979
- 'key' => $key,
980
- 'value' => $value
981
- ), $component_id, $key, $value );
982
- }
983
-
984
- function bp_activity_get_action( $component_id, $key ) {
985
- global $bp;
986
-
987
- if ( empty( $component_id ) || empty( $key ) )
988
- return false;
989
-
990
- return apply_filters( 'bp_activity_get_action', $bp->activity->actions->{$component_id}->{$key}, $component_id, $key );
991
- }
992
-
993
- function bp_activity_get_user_favorites( $user_id ) {
994
- $my_favs = maybe_unserialize( get_usermeta( $user_id, 'bp_favorite_activities' ) );
995
- $existing_favs = bp_activity_get_specific( array( 'activity_ids' => $my_favs ) );
996
-
997
- foreach( (array)$existing_favs['activities'] as $fav )
998
- $new_favs[] = $fav->id;
999
-
1000
- $new_favs = array_unique( (array)$new_favs );
1001
- update_usermeta( $user_id, 'bp_favorite_activities', $new_favs );
1002
-
1003
- return apply_filters( 'bp_activity_get_user_favorites', $new_favs );
1004
- }
1005
-
1006
- function bp_activity_add_user_favorite( $activity_id, $user_id = false ) {
1007
- global $bp;
1008
-
1009
- if ( !$user_id )
1010
- $user_id = $bp->loggedin_user->id;
1011
-
1012
- /* Update the user's personal favorites */
1013
- $my_favs = maybe_unserialize( get_usermeta( $bp->loggedin_user->id, 'bp_favorite_activities' ) );
1014
- $my_favs[] = $activity_id;
1015
-
1016
- /* Update the total number of users who have favorited this activity */
1017
- $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' );
1018
-
1019
- if ( !empty( $fav_count ) )
1020
- $fav_count = (int)$fav_count + 1;
1021
- else
1022
- $fav_count = 1;
1023
-
1024
- update_usermeta( $bp->loggedin_user->id, 'bp_favorite_activities', $my_favs );
1025
- bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count );
1026
-
1027
- do_action( 'bp_activity_add_user_favorite', $activity_id, $user_id );
1028
-
1029
- return true;
1030
- }
1031
-
1032
- function bp_activity_remove_user_favorite( $activity_id, $user_id = false ) {
1033
- global $bp;
1034
-
1035
- if ( !$user_id )
1036
- $user_id = $bp->loggedin_user->id;
1037
-
1038
- /* Remove the fav from the user's favs */
1039
- $my_favs = maybe_unserialize( get_usermeta( $user_id, 'bp_favorite_activities' ) );
1040
- $my_favs = array_flip( (array) $my_favs );
1041
- unset( $my_favs[$activity_id] );
1042
- $my_favs = array_unique( array_flip( $my_favs ) );
1043
-
1044
- /* Update the total number of users who have favorited this activity */
1045
- $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' );
1046
-
1047
- if ( !empty( $fav_count ) ) {
1048
- $fav_count = (int)$fav_count - 1;
1049
- bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count );
1050
- }
1051
-
1052
- update_usermeta( $user_id, 'bp_favorite_activities', $my_favs );
1053
-
1054
- do_action( 'bp_activity_remove_user_favorite', $activity_id, $user_id );
1055
-
1056
- return true;
1057
- }
1058
-
1059
- function bp_activity_check_exists_by_content( $content ) {
1060
- return apply_filters( 'bp_activity_check_exists_by_content', BP_Activity_Activity::check_exists_by_content( $content ) );
1061
- }
1062
-
1063
- function bp_activity_get_last_updated() {
1064
- return apply_filters( 'bp_activity_get_last_updated', BP_Activity_Activity::get_last_updated() );
1065
- }
1066
-
1067
- function bp_activity_total_favorites_for_user( $user_id = false ) {
1068
- global $bp;
1069
-
1070
- if ( !$user_id )
1071
- $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
1072
-
1073
- return BP_Activity_Activity::total_favorite_count( $user_id );
1074
- }
1075
-
1076
- /********************************************************************************
1077
- * Activity Meta Functions
1078
- *
1079
- * Meta functions allow you to store extra data for a particular item.
1080
- */
1081
-
1082
- function bp_activity_delete_meta( $activity_id, $meta_key = false, $meta_value = false ) {
1083
- global $wpdb, $bp;
1084
-
1085
- if ( !is_numeric( $activity_id ) )
1086
- return false;
1087
-
1088
- $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
1089
-
1090
- if ( is_array( $meta_value ) || is_object( $meta_value ) )
1091
- $meta_value = serialize( $meta_value );
1092
-
1093
- $meta_value = trim( $meta_value );
1094
-
1095
- if ( !$meta_key ) {
1096
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d", $activity_id ) );
1097
- } else if ( $meta_value ) {
1098
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s AND meta_value = %s", $activity_id, $meta_key, $meta_value ) );
1099
- } else {
1100
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s", $activity_id, $meta_key ) );
1101
- }
1102
-
1103
- wp_cache_delete( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, 'bp' );
1104
-
1105
- return true;
1106
- }
1107
-
1108
- function bp_activity_get_meta( $activity_id, $meta_key = '' ) {
1109
- global $wpdb, $bp;
1110
-
1111
- $activity_id = (int)$activity_id;
1112
-
1113
- if ( !$activity_id )
1114
- return false;
1115
-
1116
- if ( !empty($meta_key) ) {
1117
- $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
1118
-
1119
- if ( !$metas = wp_cache_get( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, 'bp' ) ) {
1120
- $metas = $wpdb->get_col( $wpdb->prepare("SELECT meta_value FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s", $activity_id, $meta_key ) );
1121
- wp_cache_set( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, $metas, 'bp' );
1122
- }
1123
- } else
1124
- $metas = $wpdb->get_col( $wpdb->prepare( "SELECT meta_value FROM {$bp->activity->table_name_meta} WHERE activity_id = %d", $activity_id ) );
1125
-
1126
- if ( empty($metas) )
1127
- return false;
1128
-
1129
- $metas = array_map( 'maybe_unserialize', (array)$metas );
1130
-
1131
- if ( 1 == count($metas) )
1132
- return $metas[0];
1133
- else
1134
- return $metas;
1135
- }
1136
-
1137
- function bp_activity_update_meta( $activity_id, $meta_key, $meta_value ) {
1138
- global $wpdb, $bp;
1139
-
1140
- if ( !is_numeric( $activity_id ) )
1141
- return false;
1142
-
1143
- $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
1144
-
1145
- if ( is_string( $meta_value ) )
1146
- $meta_value = stripslashes( $wpdb->escape( $meta_value ) );
1147
-
1148
- $meta_value = maybe_serialize( $meta_value );
1149
-
1150
- if ( empty( $meta_value ) ) {
1151
- return bp_activity_delete_meta( $activity_id, $meta_key );
1152
- }
1153
-
1154
- $cur = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s", $activity_id, $meta_key ) );
1155
-
1156
- if ( !$cur ) {
1157
- $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->activity->table_name_meta} ( activity_id, meta_key, meta_value ) VALUES ( %d, %s, %s )", $activity_id, $meta_key, $meta_value ) );
1158
- } else if ( $cur->meta_value != $meta_value ) {
1159
- $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name_meta} SET meta_value = %s WHERE activity_id = %d AND meta_key = %s", $meta_value, $activity_id, $meta_key ) );
1160
- } else {
1161
- return false;
1162
- }
1163
-
1164
- wp_cache_set( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, $meta_value, 'bp' );
1165
-
1166
- return true;
1167
- }
1168
-
1169
- function bp_activity_remove_data( $user_id ) {
1170
- // Clear the user's activity from the sitewide stream and clear their activity tables
1171
- bp_activity_delete( array( 'user_id' => $user_id ) );
1172
-
1173
- // Remove any usermeta
1174
- delete_usermeta( $user_id, 'bp_latest_update' );
1175
- delete_usermeta( $user_id, 'bp_favorite_activities' );
1176
-
1177
- do_action( 'bp_activity_remove_data', $user_id );
1178
- }
1179
- add_action( 'wpmu_delete_user', 'bp_activity_remove_data' );
1180
- add_action( 'delete_user', 'bp_activity_remove_data' );
1181
- add_action( 'make_spam_user', 'bp_activity_remove_data' );
1182
-
1183
-
1184
- /********************************************************************************
1185
- * Custom Actions
1186
- *
1187
- * Functions to set up custom BuddyPress actions that all other components can
1188
- * hook in to.
1189
- */
1190
-
1191
- /* Allow core components and dependent plugins to register activity actions */
1192
- function bp_register_activity_actions() {
1193
- do_action( 'bp_register_activity_actions' );
1194
- }
1195
- add_action( 'bp_loaded', 'bp_register_activity_actions', 8 );
1196
-
1197
-
1198
?>
1
+ <?php
2
+
3
+ define ( 'BP_ACTIVITY_DB_VERSION', '2100' );
4
+
5
+ /* Define the slug for the component */
6
+ if ( !defined( 'BP_ACTIVITY_SLUG' ) )
7
+ define ( 'BP_ACTIVITY_SLUG', 'activity' );
8
+
9
+ require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-classes.php' );
10
+ require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-templatetags.php' );
11
+ require ( BP_PLUGIN_DIR . '/bp-activity/bp-activity-filters.php' );
12
+
13
+ function bp_activity_install() {
14
+ global $wpdb, $bp;
15
+
16
+ if ( !empty($wpdb->charset) )
17
+ $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
18
+
19
+ /* Rename the old user activity cached table if needed. */
20
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$wpdb->base_prefix}bp_activity_user_activity_cached%'" ) )
21
+ $wpdb->query( "RENAME TABLE {$wpdb->base_prefix}bp_activity_user_activity_cached TO {$bp->activity->table_name}" );
22
+
23
+ /* Rename fields from pre BP 1.2 */
24
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$bp->activity->table_name}%'" ) ) {
25
+ if ( $wpdb->get_var( "SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_action'" ) )
26
+ $wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE component_action type varchar(75) NOT NULL" );
27
+
28
+ if ( $wpdb->get_var( "SHOW COLUMNS FROM {$bp->activity->table_name} LIKE 'component_name'" ) )
29
+ $wpdb->query( "ALTER TABLE {$bp->activity->table_name} CHANGE component_name component varchar(75) NOT NULL" );
30
+ }
31
+
32
+ /**
33
+ * Build the tables
34
+ */
35
+ $sql[] = "CREATE TABLE {$bp->activity->table_name} (
36
+ id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
37
+ user_id bigint(20) NOT NULL,
38
+ component varchar(75) NOT NULL,
39
+ type varchar(75) NOT NULL,
40
+ action text NOT NULL,
41
+ content longtext NOT NULL,
42
+ primary_link varchar(150) NOT NULL,
43
+ item_id varchar(75) NOT NULL,
44
+ secondary_item_id varchar(75) DEFAULT NULL,
45
+ date_recorded datetime NOT NULL,
46
+ hide_sitewide bool DEFAULT 0,
47
+ mptt_left int(11) NOT NULL DEFAULT 0,
48
+ mptt_right int(11) NOT NULL DEFAULT 0,
49
+ KEY date_recorded (date_recorded),
50
+ KEY user_id (user_id),
51
+ KEY item_id (item_id),
52
+ KEY secondary_item_id (secondary_item_id),
53
+ KEY component (component),
54
+ KEY type (type),
55
+ KEY mptt_left (mptt_left),
56
+ KEY mptt_right (mptt_right),
57
+ KEY hide_sitewide (hide_sitewide)
58
+ ) {$charset_collate};";
59
+
60
+ $sql[] = "CREATE TABLE {$bp->activity->table_name_meta} (
61
+ id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
62
+ activity_id bigint(20) NOT NULL,
63
+ meta_key varchar(255) DEFAULT NULL,
64
+ meta_value longtext DEFAULT NULL,
65
+ KEY activity_id (activity_id),
66
+ KEY meta_key (meta_key)
67
+ ) {$charset_collate};";
68
+
69
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
70
+ dbDelta($sql);
71
+
72
+ update_site_option( 'bp-activity-db-version', BP_ACTIVITY_DB_VERSION );
73
+ }
74
+
75
+ function bp_activity_setup_globals() {
76
+ global $bp, $current_blog;
77
+
78
+ /* Internal identifier */
79
+ $bp->activity->id = 'activity';
80
+
81
+ $bp->activity->slug = BP_ACTIVITY_SLUG;
82
+
83
+ $bp->activity->table_name = $bp->table_prefix . 'bp_activity';
84
+ $bp->activity->table_name_meta = $bp->table_prefix . 'bp_activity_meta';
85
+
86
+ $bp->activity->format_notification_function = 'bp_activity_format_notifications';
87
+
88
+ /* Register this in the active components array */
89
+ $bp->active_components[$bp->activity->slug] = $bp->activity->id;
90
+
91
+ do_action( 'bp_activity_setup_globals' );
92
+ }
93
+ add_action( 'bp_setup_globals', 'bp_activity_setup_globals' );
94
+
95
+ function bp_activity_check_installed() {
96
+ global $bp;
97
+
98
+ if ( get_site_option( 'bp-activity-db-version' ) < BP_ACTIVITY_DB_VERSION )
99
+ bp_activity_install();
100
+ }
101
+ add_action( 'admin_menu', 'bp_activity_check_installed' );
102
+
103
+ function bp_activity_setup_root_component() {
104
+ /* Register 'activity' as a root component (for RSS feed use) */
105
+ bp_core_add_root_component( BP_ACTIVITY_SLUG );
106
+ }
107
+ add_action( 'bp_setup_root_components', 'bp_activity_setup_root_component' );
108
+
109
+ function bp_activity_setup_nav() {
110
+ global $bp;
111
+
112
+ /* Add 'Activity' to the main navigation */
113
+ bp_core_new_nav_item( array( 'name' => __( 'Activity', 'buddypress' ), 'slug' => $bp->activity->slug, 'position' => 10, 'screen_function' => 'bp_activity_screen_my_activity', 'default_subnav_slug' => 'just-me', 'item_css_id' => $bp->activity->id ) );
114
+
115
+ $user_domain = ( !empty( $bp->displayed_user->domain ) ) ? $bp->displayed_user->domain : $bp->loggedin_user->domain;
116
+ $user_login = ( !empty( $bp->displayed_user->userdata->user_login ) ) ? $bp->displayed_user->userdata->user_login : $bp->loggedin_user->userdata->user_login;
117
+ $activity_link = $user_domain . $bp->activity->slug . '/';
118
+
119
+ /* Add the subnav items to the activity nav item if we are using a theme that supports this */
120
+ bp_core_new_subnav_item( array( 'name' => __( 'Personal', 'buddypress' ), 'slug' => 'just-me', 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_my_activity', 'position' => 10 ) );
121
+
122
+ if ( bp_is_active( 'friends' ) )
123
+ bp_core_new_subnav_item( array( 'name' => __( 'Friends', 'buddypress' ), 'slug' => BP_FRIENDS_SLUG, 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_friends', 'position' => 20, 'item_css_id' => 'activity-friends' ) );
124
+
125
+ if ( bp_is_active( 'groups' ) )
126
+ bp_core_new_subnav_item( array( 'name' => __( 'Groups', 'buddypress' ), 'slug' => BP_GROUPS_SLUG, 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_groups', 'position' => 30, 'item_css_id' => 'activity-groups' ) );
127
+
128
+ bp_core_new_subnav_item( array( 'name' => __( 'Favorites', 'buddypress' ), 'slug' => 'favorites', 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_favorites', 'position' => 40, 'item_css_id' => 'activity-favs' ) );
129
+ bp_core_new_subnav_item( array( 'name' => sprintf( __( '@%s Mentions', 'buddypress' ), $user_login ), 'slug' => 'mentions', 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->slug, 'screen_function' => 'bp_activity_screen_mentions', 'position' => 50, 'item_css_id' => 'activity-mentions' ) );
130
+
131
+ if ( $bp->current_component == $bp->activity->slug ) {
132
+ if ( bp_is_my_profile() ) {
133
+ $bp->bp_options_title = __( 'My Activity', 'buddypress' );
134
+ } else {
135
+ $bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => 'thumb' ) );
136
+ $bp->bp_options_title = $bp->displayed_user->fullname;
137
+ }
138
+ }
139
+
140
+ do_action( 'bp_activity_setup_nav' );
141
+ }
142
+ add_action( 'bp_setup_nav', 'bp_activity_setup_nav' );
143
+
144
+ function bp_activity_directory_activity_setup() {
145
+ global $bp;
146
+
147
+ if ( $bp->current_component == $bp->activity->slug && empty( $bp->current_action ) ) {
148
+ $bp->is_directory = true;
149
+
150
+ do_action( 'bp_activity_directory_activity_setup' );
151
+ bp_core_load_template( apply_filters( 'bp_activity_directory_activity_setup', 'activity/index' ) );
152
+ }
153
+ }
154
+ add_action( 'wp', 'bp_activity_directory_activity_setup', 2 );
155
+
156
+
157
+ /********************************************************************************
158
+ * Screen Functions
159
+ *
160
+ * Screen functions are the controllers of BuddyPress. They will execute when their
161
+ * specific URL is caught. They will first save or manipulate data using business
162
+ * functions, then pass on the user to a template file.
163
+ */
164
+
165
+ function bp_activity_screen_my_activity() {
166
+ do_action( 'bp_activity_screen_my_activity' );
167
+ bp_core_load_template( apply_filters( 'bp_activity_template_my_activity', 'members/single/home' ) );
168
+ }
169
+
170
+ function bp_activity_screen_friends() {
171
+ global $bp;
172
+
173
+ if ( !bp_is_active( 'friends' ) )
174
+ return false;
175
+
176
+ if ( !is_super_admin() )
177
+ $bp->is_item_admin = false;
178
+
179
+ do_action( 'bp_activity_screen_friends' );
180
+ bp_core_load_template( apply_filters( 'bp_activity_template_friends_activity', 'members/single/home' ) );
181
+ }
182
+
183
+ function bp_activity_screen_groups() {
184
+ global $bp;
185
+
186
+ if ( !bp_is_active( 'groups' ) )
187
+ return false;
188
+
189
+ if ( !is_super_admin() )
190
+ $bp->is_item_admin = false;
191
+
192
+ do_action( 'bp_activity_screen_groups' );
193
+ bp_core_load_template( apply_filters( 'bp_activity_template_groups_activity', 'members/single/home' ) );
194
+ }
195
+
196
+ function bp_activity_screen_favorites() {
197
+ global $bp;
198
+
199
+ if ( !is_super_admin() )
200
+ $bp->is_item_admin = false;
201
+
202
+ do_action( 'bp_activity_screen_favorites' );
203
+ bp_core_load_template( apply_filters( 'bp_activity_template_favorite_activity', 'members/single/home' ) );
204
+ }
205
+
206
+ function bp_activity_screen_mentions() {
207
+ global $bp;
208
+
209
+ if ( !is_super_admin() )
210
+ $bp->is_item_admin = false;
211
+
212
+ do_action( 'bp_activity_screen_mentions' );
213
+ bp_core_load_template( apply_filters( 'bp_activity_template_mention_activity', 'members/single/home' ) );
214
+ }
215
+
216
+ function bp_activity_screen_single_activity_permalink() {
217
+ global $bp;
218
+
219
+ if ( !$bp->displayed_user->id || $bp->current_component != $bp->activity->slug )
220
+ return false;
221
+
222
+ if ( empty( $bp->current_action ) || !is_numeric( $bp->current_action ) )
223
+ return false;
224
+
225
+ /* Get the activity details */
226
+ $activity = bp_activity_get_specific( array( 'activity_ids' => $bp->current_action ) );
227
+
228
+ if ( !$activity = $activity['activities'][0] )
229
+ bp_core_redirect( $bp->root_domain );
230
+
231
+ $has_access = true;
232
+ /* Redirect based on the type of activity */
233
+ if ( $activity->component == $bp->groups->id ) {
234
+ if ( !function_exists( 'groups_get_group' ) )
235
+ bp_core_redirect( $bp->root_domain );
236
+
237
+ if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) ) {
238
+ /* Check to see if the group is not public, if so, check the user has access to see this activity */
239
+ if ( 'public' != $group->status ) {
240
+ if ( !groups_is_user_member( $bp->loggedin_user->id, $group->id ) )
241
+ $has_access = false;
242
+ }
243
+ }
244
+ }
245
+
246
+ $has_access = apply_filters( 'bp_activity_permalink_access', $has_access, &$activity );
247
+
248
+ do_action( 'bp_activity_screen_single_activity_permalink', $activity, $has_access );
249
+
250
+ if ( !$has_access ) {
251
+ bp_core_add_message( __( 'You do not have access to this activity.', 'buddypress' ), 'error' );
252
+
253
+ if ( is_user_logged_in() )
254
+ bp_core_redirect( $bp->loggedin_user->domain );
255
+ else
256
+ bp_core_redirect( site_url( 'wp-login.php?redirect_to=' . esc_url( $bp->root_domain . '/' . $bp->activity->slug . '/p/' . $bp->current_action ) ) );
257
+ }
258
+
259
+ bp_core_load_template( apply_filters( 'bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink' ) );
260
+ }
261
+ /* This screen is not attached to a nav item, so we need to add an action for it. */
262
+ add_action( 'wp', 'bp_activity_screen_single_activity_permalink', 3 );
263
+
264
+ function bp_activity_screen_notification_settings() {
265
+ global $bp; ?>
266
+ <table class="notification-settings zebra" id="activity-notification-settings">
267
+ <thead>
268
+ <tr>
269
+ <th class="icon"></th>
270
+ <th class="title"><?php _e( 'Activity', 'buddypress' ) ?></th>
271
+ <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>
272
+ <th class="no"><?php _e( 'No', 'buddypress' )?></th>
273
+ </tr>
274
+ </thead>
275
+
276
+ <tbody>
277
+ <tr>
278
+ <td></td>
279
+ <td><?php printf( __( 'A member mentions you in an update using "@%s"', 'buddypress' ), bp_core_get_username( $bp->loggedin_user->id, $bp->loggedin_user->userdata->user_nicename, $bp->loggedin_user->userdata->user_login ) ) ?></td>
280
+ <td class="yes"><input type="radio" name="notifications[notification_activity_new_mention]" value="yes" <?php if ( !get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_mention', true ) || 'yes' == get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_mention', true ) ) { ?>checked="checked" <?php } ?>/></td>
281
+ <td class="no"><input type="radio" name="notifications[notification_activity_new_mention]" value="no" <?php if ( 'no' == get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_mention', true ) ) { ?>checked="checked" <?php } ?>/></td>
282
+ </tr>
283
+ <tr>
284
+ <td></td>
285
+ <td><?php printf( __( "A member replies to an update or comment you've posted", 'buddypress' ), $current_user->user_login ) ?></td>
286
+ <td class="yes"><input type="radio" name="notifications[notification_activity_new_reply]" value="yes" <?php if ( !get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_reply', true ) || 'yes' == get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_reply', true ) ) { ?>checked="checked" <?php } ?>/></td>
287
+ <td class="no"><input type="radio" name="notifications[notification_activity_new_reply]" value="no" <?php if ( 'no' == get_user_meta( $bp->loggedin_user->id, 'notification_activity_new_reply', true ) ) { ?>checked="checked" <?php } ?>/></td>
288
+ </tr>
289
+
290
+ <?php do_action( 'bp_activity_screen_notification_settings' ) ?>
291
+ </tbody>
292
+ </table>
293
+ <?php
294
+ }
295
+ add_action( 'bp_notification_settings', 'bp_activity_screen_notification_settings', 1 );
296
+
297
+ /********************************************************************************
298
+ * Action Functions
299
+ *
300
+ * Action functions are exactly the same as screen functions, however they do not
301
+ * have a template screen associated with them. Usually they will send the user
302
+ * back to the default screen after execution.
303
+ */
304
+
305
+ function bp_activity_action_permalink_router() {
306
+ global $bp;
307
+
308
+ if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'p' )
309
+ return false;
310
+
311
+ if ( empty( $bp->action_variables[0] ) || !is_numeric( $bp->action_variables[0] ) )
312
+ return false;
313
+
314
+ /* Get the activity details */
315
+ $activity = bp_activity_get_specific( array( 'activity_ids' => $bp->action_variables[0] ) );
316
+
317
+ if ( !$activity = $activity['activities'][0] )
318
+ bp_core_redirect( $bp->root_domain );
319
+
320
+ $redirect = false;
321
+ /* Redirect based on the type of activity */
322
+ if ( $activity->component == $bp->groups->id ) {
323
+ if ( $activity->user_id )
324
+ $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id . '/';
325
+ else {
326
+ if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) )
327
+ $redirect = bp_get_group_permalink( $group ) . $bp->activity->slug . '/' . $activity->id . '/';
328
+ }
329
+ } else
330
+ $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id;
331
+
332
+ $redirect = apply_filters( 'bp_activity_permalink_redirect_url', $redirect, &$activity );
333
+
334
+ if ( !$redirect )
335
+ bp_core_redirect( $bp->root_domain );
336
+
337
+ /* Redirect to the actual activity permalink page */
338
+ bp_core_redirect( $redirect );
339
+ }
340
+ add_action( 'wp', 'bp_activity_action_permalink_router', 3 );
341
+
342
+ function bp_activity_action_delete_activity() {
343
+ global $bp;
344
+
345
+ if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'delete' )
346
+ return false;
347
+
348
+ if ( empty( $bp->action_variables[0] ) || !is_numeric( $bp->action_variables[0] ) )
349
+ return false;
350
+
351
+ /* Check the nonce */
352
+ check_admin_referer( 'bp_activity_delete_link' );
353
+
354
+ $activity_id = $bp->action_variables[0];
355
+ $activity = new BP_Activity_Activity( $activity_id );
356
+
357
+ /* Check access */
358
+ if ( !is_super_admin() && $activity->user_id != $bp->loggedin_user->id )
359
+ return false;
360
+
361
+ /* Call the action before the delete so plugins can still fetch information about it */
362
+ do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id );
363
+
364
+ /* Now delete the activity item */
365
+ if ( bp_activity_delete( array( 'id' => $activity_id, 'user_id' => $activity->user_id ) ) )
366
+ bp_core_add_message( __( 'Activity deleted', 'buddypress' ) );
367
+ else
368
+ bp_core_add_message( __( 'There was an error when deleting that activity', 'buddypress' ), 'error' );
369
+
370
+ bp_core_redirect( wp_get_referer() );
371
+ }
372
+ add_action( 'wp', 'bp_activity_action_delete_activity', 3 );
373
+
374
+ function bp_activity_action_post_update() {
375
+ global $bp;
376
+
377
+ if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'post' )
378
+ return false;
379
+
380
+ /* Check the nonce */
381
+ check_admin_referer( 'post_update', '_wpnonce_post_update' );
382
+
383
+ $content = apply_filters( 'bp_activity_post_update_content', $_POST['whats-new'] );
384
+ $object = apply_filters( 'bp_activity_post_update_object', $_POST['whats-new-post-object'] );
385
+ $item_id = apply_filters( 'bp_activity_post_update_item_id', $_POST['whats-new-post-in'] );
386
+
387
+ if ( empty( $content ) ) {
388
+ bp_core_add_message( __( 'Please enter some content to post.', 'buddypress' ), 'error' );
389
+ bp_core_redirect( wp_get_referer() );
390
+ }
391
+
392
+ if ( !(int)$item_id ) {
393
+ $activity_id = bp_activity_post_update( array( 'content' => $content ) );
394
+
395
+ } else if ( 'groups' == $object && function_exists( 'groups_post_update' ) ) {
396
+ if ( (int)$item_id ) {
397
+ $activity_id = groups_post_update( array( 'content' => $content, 'group_id' => $item_id ) );
398
+ }
399
+ } else
400
+ $activity_id = apply_filters( 'bp_activity_custom_update', $object, $item_id, $content );
401
+
402
+ if ( !empty( $activity_id ) )
403
+ bp_core_add_message( __( 'Update Posted!', 'buddypress' ) );
404
+ else
405
+ bp_core_add_message( __( 'There was an error when posting your update, please try again.', 'buddypress' ), 'error' );
406
+
407
+ bp_core_redirect( wp_get_referer() );
408
+ }
409
+ add_action( 'wp', 'bp_activity_action_post_update', 3 );
410
+
411
+ function bp_activity_action_post_comment() {
412
+ global $bp;
413
+
414
+ if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'reply' )
415
+ return false;
416
+
417
+ /* Check the nonce */
418
+ check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );
419
+
420
+ $activity_id = apply_filters( 'bp_activity_post_comment_activity_id', $_POST['comment_form_id'] );
421
+ $content = apply_filters( 'bp_activity_post_comment_content', $_POST['ac_input_' . $activity_id] );
422
+
423
+ if ( empty( $content ) ) {
424
+ bp_core_add_message( __( 'Please do not leave the comment area blank.', 'buddypress' ), 'error' );
425
+ bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
426
+ }
427
+
428
+ $comment_id = bp_activity_new_comment( array(
429
+ 'content' => $content,
430
+ 'activity_id' => $activity_id,
431
+ 'parent_id' => $parent_id
432
+ ));
433
+
434
+ if ( !empty( $comment_id ) )
435
+ bp_core_add_message( __( 'Reply Posted!', 'buddypress' ) );
436
+ else
437
+ bp_core_add_message( __( 'There was an error posting that reply, please try again.', 'buddypress' ), 'error' );
438
+
439
+ bp_core_redirect( wp_get_referer() . '#ac-form-' . $activity_id );
440
+ }
441
+ add_action( 'wp', 'bp_activity_action_post_comment', 3 );
442
+
443
+ function bp_activity_action_mark_favorite() {
444
+ global $bp;
445
+
446
+ if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'favorite' )
447
+ return false;
448
+
449
+ /* Check the nonce */
450
+ check_admin_referer( 'mark_favorite' );
451
+
452
+ if ( bp_activity_add_user_favorite( $bp->action_variables[0] ) )
453
+ bp_core_add_message( __( 'Activity marked as favorite.', 'buddypress' ) );
454
+ else
455
+ bp_core_add_message( __( 'There was an error marking that activity as a favorite, please try again.', 'buddypress' ), 'error' );
456
+
457
+ bp_core_redirect( wp_get_referer() . '#activity-' . $bp->action_variables[0] );
458
+ }
459
+ add_action( 'wp', 'bp_activity_action_mark_favorite', 3 );
460
+
461
+ function bp_activity_action_remove_favorite() {
462
+ global $bp;
463
+
464
+ if ( !is_user_logged_in() || $bp->current_component != $bp->activity->slug || $bp->current_action != 'unfavorite' )
465
+ return false;
466
+
467
+ /* Check the nonce */
468
+ check_admin_referer( 'unmark_favorite' );
469
+
470
+ if ( bp_activity_remove_user_favorite( $bp->action_variables[0] ) )
471
+ bp_core_add_message( __( 'Activity removed as favorite.', 'buddypress' ) );
472
+ else
473
+ bp_core_add_message( __( 'There was an error removing that activity as a favorite, please try again.', 'buddypress' ), 'error' );
474
+
475
+ bp_core_redirect( wp_get_referer() . '#activity-' . $bp->action_variables[0] );
476
+ }
477
+ add_action( 'wp', 'bp_activity_action_remove_favorite', 3 );
478
+
479
+ function bp_activity_action_sitewide_feed() {
480
+ global $bp, $wp_query;
481
+
482
+ if ( $bp->current_component != $bp->activity->slug || $bp->current_action != 'feed' || $bp->displayed_user->id || $bp->groups->current_group )
483
+ return false;
484
+
485
+ $wp_query->is_404 = false;
486
+ status_header( 200 );
487
+
488
+ include_once( 'bp-activity/feeds/bp-activity-sitewide-feed.php' );
489
+ die;
490
+ }
491
+ add_action( 'wp', 'bp_activity_action_sitewide_feed', 3 );
492
+
493
+ function bp_activity_action_personal_feed() {
494
+ global $bp, $wp_query;
495
+
496
+ if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'feed' )
497
+ return false;
498
+
499
+ $wp_query->is_404 = false;
500
+ status_header( 200 );
501
+
502
+ include_once( 'bp-activity/feeds/bp-activity-personal-feed.php' );
503
+ die;
504
+ }
505
+ add_action( 'wp', 'bp_activity_action_personal_feed', 3 );
506
+
507
+ function bp_activity_action_friends_feed() {
508
+ global $bp, $wp_query;
509
+
510
+ if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'friends' || $bp->action_variables[0] != 'feed' )
511
+ return false;
512
+
513
+ $wp_query->is_404 = false;
514
+ status_header( 200 );
515
+
516
+ include_once( 'bp-activity/feeds/bp-activity-friends-feed.php' );
517
+ die;
518
+ }
519
+ add_action( 'wp', 'bp_activity_action_friends_feed', 3 );
520
+
521
+ function bp_activity_action_my_groups_feed() {
522
+ global $bp, $wp_query;
523
+
524
+ if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'groups' || $bp->action_variables[0] != 'feed' )
525
+ return false;
526
+
527
+ $wp_query->is_404 = false;
528
+ status_header( 200 );
529
+
530
+ include_once( 'bp-activity/feeds/bp-activity-mygroups-feed.php' );
531
+ die;
532
+ }
533
+ add_action( 'wp', 'bp_activity_action_my_groups_feed', 3 );
534
+
535
+ function bp_activity_action_mentions_feed() {
536
+ global $bp, $wp_query;
537
+
538
+ if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'mentions' || $bp->action_variables[0] != 'feed' )
539
+ return false;
540
+
541
+ $wp_query->is_404 = false;
542
+ status_header( 200 );
543
+
544
+ include_once( 'bp-activity/feeds/bp-activity-mentions-feed.php' );
545
+ die;
546
+ }
547
+ add_action( 'wp', 'bp_activity_action_mentions_feed', 3 );
548
+
549
+ function bp_activity_action_favorites_feed() {
550
+ global $bp, $wp_query;
551
+
552
+ if ( $bp->current_component != $bp->activity->slug || !$bp->displayed_user->id || $bp->current_action != 'favorites' || $bp->action_variables[0] != 'feed' )
553
+ return false;
554
+
555
+ $wp_query->is_404 = false;
556
+ status_header( 200 );
557
+
558
+ include_once( 'bp-activity/feeds/bp-activity-favorites-feed.php' );
559
+ die;
560
+ }
561
+ add_action( 'wp', 'bp_activity_action_favorites_feed', 3 );
562
+
563
+ /********************************************************************************
564
+ * Business Functions
565
+ *
566
+ * Business functions are where all the magic happens in BuddyPress. They will
567
+ * handle the actual saving or manipulation of information. Usually they will
568
+ * hand off to a database class for data access, then return
569
+ * true or false on success or failure.
570
+ */
571
+
572
+ function bp_activity_get( $args = '' ) {
573
+ $defaults = array(
574
+ 'max' => false, // Maximum number of results to return
575
+ 'page' => 1, // page 1 without a per_page will result in no pagination.
576
+ 'per_page' => false, // results per page
577
+ 'sort' => 'DESC', // sort ASC or DESC
578
+ 'display_comments' => false, // false for no comments. 'stream' for within stream display, 'threaded' for below each activity item
579
+
580
+ 'search_terms' => false, // Pass search terms as a string
581
+ 'show_hidden' => false, // Show activity items that are hidden site-wide?
582
+
583
+ /**
584
+ * Pass filters as an array -- all filter items can be multiple values comma separated:
585
+ * array(
586
+ * 'user_id' => false, // user_id to filter on
587
+ * 'object' => false, // object to filter on e.g. groups, profile, status, friends
588
+ * 'action' => false, // action to filter on e.g. activity_update, profile_updated
589
+ * 'primary_id' => false, // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
590
+ * 'secondary_id' => false, // secondary object ID to filter on e.g. a post_id
591
+ * );
592
+ */
593
+ 'filter' => array()
594
+ );
595
+
596
+ $r = wp_parse_args( $args, $defaults );
597
+ extract( $r, EXTR_SKIP );
598
+
599
+ /* Attempt to return a cached copy of the first page of sitewide activity. */
600
+ if ( 1 == (int)$page && empty( $max ) && empty( $search_terms ) && empty( $filter ) && 'DESC' == $sort ) {
601
+ if ( !$activity = wp_cache_get( 'bp_activity_sitewide_front', 'bp' ) ) {
602
+ $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden );
603
+ wp_cache_set( 'bp_activity_sitewide_front', $activity, 'bp' );
604
+ }
605
+ } else
606
+ $activity = BP_Activity_Activity::get( $max, $page, $per_page, $sort, $search_terms, $filter, $display_comments, $show_hidden );
607
+
608
+ return apply_filters( 'bp_activity_get', $activity, &$r );
609
+ }
610
+
611
+ function bp_activity_get_specific( $args = '' ) {
612
+ $defaults = array(
613
+ 'activity_ids' => false, // A single activity_id or array of IDs.
614
+ 'page' => 1, // page 1 without a per_page will result in no pagination.
615
+ 'per_page' => false, // results per page
616
+ 'max' => false, // Maximum number of results to return
617
+ 'sort' => 'DESC', // sort ASC or DESC
618
+ 'display_comments' => false // true or false to display threaded comments for these specific activity items
619
+ );
620
+
621
+ $r = wp_parse_args( $args, $defaults );
622
+ extract( $r, EXTR_SKIP );
623
+
624
+ return apply_filters( 'bp_activity_get_specific', BP_Activity_Activity::get_specific( $activity_ids, $max, $page, $per_page, $sort, $display_comments ) );
625
+ }
626
+
627
+ function bp_activity_add( $args = '' ) {
628
+ global $bp;
629
+
630
+ $defaults = array(
631
+ 'id' => false, // Pass an existing activity ID to update an existing entry.
632
+
633
+ 'action' => '', // The activity action - e.g. "Jon Doe posted an update"
634
+ 'content' => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!"
635
+
636
+ 'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent
637
+ 'type' => false, // The activity type e.g. activity_update, profile_updated
638
+ 'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink)
639
+
640
+ '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.
641
+ 'item_id' => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id
642
+ 'secondary_item_id' => false, // Optional: A second ID used to further filter e.g. a comment_id
643
+ 'recorded_time' => bp_core_current_time(), // The GMT time that this activity was recorded
644
+ 'hide_sitewide' => false // Should this be hidden on the sitewide activity stream?
645
+ );
646
+
647
+ $params = wp_parse_args( $args, $defaults );
648
+ extract( $params, EXTR_SKIP );
649
+
650
+ /* Make sure we are backwards compatible */
651
+ if ( empty( $component ) && !empty( $component_name ) )
652
+ $component = $component_name;
653
+
654
+ if ( empty( $type ) && !empty( $component_action ) )
655
+ $type = $component_action;
656
+
657
+ $activity = new BP_Activity_Activity( $id );
658
+
659
+ $activity->user_id = $user_id;
660
+ $activity->component = $component;
661
+ $activity->type = $type;
662
+ $activity->action = $action;
663
+ $activity->content = $content;
664
+ $activity->primary_link = $primary_link;
665
+ $activity->item_id = $item_id;
666
+ $activity->secondary_item_id = $secondary_item_id;
667
+ $activity->date_recorded = $recorded_time;
668
+ $activity->hide_sitewide = $hide_sitewide;
669
+
670
+ if ( !$activity->save() )
671
+ return false;
672
+
673
+ /* If this is an activity comment, rebuild the tree */
674
+ if ( 'activity_comment' == $activity->type )
675
+ BP_Activity_Activity::rebuild_activity_comment_tree( $activity->item_id );
676
+
677
+ wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
678
+ do_action( 'bp_activity_add', $params );
679
+
680
+ return $activity->id;
681
+ }
682
+
683
+ function bp_activity_post_update( $args = '' ) {
684
+ global $bp;
685
+
686
+ $defaults = array(
687
+ 'content' => false,
688
+ 'user_id' => $bp->loggedin_user->id
689
+ );
690
+
691
+ $r = wp_parse_args( $args, $defaults );
692
+ extract( $r, EXTR_SKIP );
693
+
694
+ if ( empty( $content ) || !strlen( trim( $content ) ) )
695
+ return false;
696
+
697
+ /* Record this on the user's profile */
698
+ $from_user_link = bp_core_get_userlink( $user_id );
699
+ $activity_action = sprintf( __( '%s posted an update:', 'buddypress' ), $from_user_link );
700
+ $activity_content = $content;
701
+
702
+ $primary_link = bp_core_get_userlink( $user_id, false, true );
703
+
704
+ /* Now write the values */
705
+ $activity_id = bp_activity_add( array(
706
+ 'user_id' => $user_id,
707
+ 'action' => apply_filters( 'bp_activity_new_update_action', $activity_action ),
708
+ 'content' => apply_filters( 'bp_activity_new_update_content', $activity_content ),
709
+ 'primary_link' => apply_filters( 'bp_activity_new_update_primary_link', $primary_link ),
710
+ 'component' => $bp->activity->id,
711
+ 'type' => 'activity_update'
712
+ ) );
713
+
714
+ /* Add this update to the "latest update" usermeta so it can be fetched anywhere. */
715
+ update_user_meta( $bp->loggedin_user->id, 'bp_latest_update', array( 'id' => $activity_id, 'content' => wp_filter_kses( $content ) ) );
716
+
717
+ /* Require the notifications code so email notifications can be set on the 'bp_activity_posted_update' action. */
718
+ require_once( BP_PLUGIN_DIR . '/bp-activity/bp-activity-notifications.php' );
719
+
720
+ do_action( 'bp_activity_posted_update', $content, $user_id, $activity_id );
721
+
722
+ return $activity_id;
723
+ }
724
+
725
+ function bp_activity_new_comment( $args = '' ) {
726
+ global $bp;
727
+
728
+ $defaults = array(
729
+ 'id' => false,
730
+ 'content' => false,
731
+ 'user_id' => $bp->loggedin_user->id,
732
+ 'activity_id' => false, // ID of the root activity item
733
+ 'parent_id' => false // ID of a parent comment (optional)
734
+ );
735
+
736
+ $params = wp_parse_args( $args, $defaults );
737
+ extract( $params, EXTR_SKIP );
738
+
739
+ if ( empty($content) || empty($user_id) || empty($activity_id) )
740
+ return false;
741
+
742
+ if ( empty($parent_id) )
743
+ $parent_id = $activity_id;
744
+
745
+ /* Check to see if the parent activity is hidden, and if so, hide this comment publically. */
746
+ $activity = new BP_Activity_Activity( $activity_id );
747
+ $is_hidden = ( (int)$activity->hide_sitewide ) ? 1 : 0;
748
+
749
+ /* Insert the activity comment */
750
+ $comment_id = bp_activity_add( array(
751
+ 'id' => $id,
752
+ 'action' => apply_filters( 'bp_activity_comment_action', sprintf( __( '%s posted a new activity comment:', 'buddypress' ), bp_core_get_userlink( $user_id ) ) ),
753
+ 'content' => apply_filters( 'bp_activity_comment_content', $content ),
754
+ 'component' => $bp->activity->id,
755
+ 'type' => 'activity_comment',
756
+ 'user_id' => $user_id,
757
+ 'item_id' => $activity_id,
758
+ 'secondary_item_id' => $parent_id,
759
+ 'hide_sitewide' => $is_hidden
760
+ ) );
761
+
762
+ /* Send an email notification if settings allow */
763
+ require_once( BP_PLUGIN_DIR . '/bp-activity/bp-activity-notifications.php' );
764
+ bp_activity_new_comment_notification( $comment_id, $user_id, $params );
765
+
766
+ /* Clear the comment cache for this activity */
767
+ wp_cache_delete( 'bp_activity_comments_' . $parent_id );
768
+
769
+ do_action( 'bp_activity_comment_posted', $comment_id, $params );
770
+
771
+ return $comment_id;
772
+ }
773
+
774
+ /**
775
+ * bp_activity_get_activity_id()
776
+ *
777
+ * Fetch the activity_id for an existing activity entry in the DB.
778
+ *
779
+ * @package BuddyPress Activity
780
+ */
781
+ function bp_activity_get_activity_id( $args = '' ) {
782
+ $defaults = array(
783
+ 'user_id' => false,
784
+ 'component' => false,
785
+ 'type' => false,
786
+ 'item_id' => false,
787
+ 'secondary_item_id' => false,
788
+ 'action' => false,
789
+ 'content' => false,
790
+ 'date_recorded' => false,
791
+ );
792
+
793
+ $r = wp_parse_args( $args, $defaults );
794
+ extract( $r, EXTR_SKIP );
795
+
796
+ 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 ) );
797
+ }
798
+
799
+ /***
800
+ * Deleting Activity
801
+ *
802
+ * If you're looking to hook into one action that provides the ID(s) of
803
+ * the activity/activities deleted, then use:
804
+ *
805
+ * add_action( 'bp_activity_deleted_activities', 'my_function' );
806
+ *
807
+ * The action passes one parameter that is a single activity ID or an
808
+ * array of activity IDs depending on the number deleted.
809
+ *
810
+ * If you are deleting an activity comment please use bp_activity_delete_comment();
811
+ */
812
+
813
+ function bp_activity_delete( $args = '' ) {
814
+ global $bp;
815
+
816
+ /* Pass one or more the of following variables to delete by those variables */
817
+ $defaults = array(
818
+ 'id' => false,
819
+ 'action' => false,
820
+ 'content' => false,
821
+ 'component' => false,
822
+ 'type' => false,
823
+ 'primary_link' => false,
824
+ 'user_id' => false,
825
+ 'item_id' => false,
826
+ 'secondary_item_id' => false,
827
+ 'date_recorded' => false,
828
+ 'hide_sitewide' => false
829
+ );
830
+
831
+ $args = wp_parse_args( $args, $defaults );
832
+
833
+ if ( !$activity_ids_deleted = BP_Activity_Activity::delete( $args ) )
834
+ return false;
835
+
836
+ /* Check if the user's latest update has been deleted */
837
+ if ( empty( $args['user_id'] ) )
838
+ $user_id = $bp->loggedin_user->id;
839
+ else
840
+ $user_id = $args['user_id'];
841
+
842
+ $latest_update = get_user_meta( $user_id, 'bp_latest_update', true );
843
+ if ( !empty( $latest_update ) ) {
844
+ if ( in_array( (int)$latest_update['id'], (array)$activity_ids_deleted ) )
845
+ delete_user_meta( $user_id, 'bp_latest_update' );
846
+ }
847
+
848
+ do_action( 'bp_activity_delete', $args );
849
+ do_action( 'bp_activity_deleted_activities', $activity_ids_deleted );
850
+
851
+ wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
852
+
853
+ return true;
854
+ }
855
+ /* The following functions have been deprecated in place of bp_activity_delete() */
856
+ function bp_activity_delete_by_item_id( $args = '' ) {
857
+ global $bp;
858
+
859
+ $defaults = array( 'item_id' => false, 'component' => false, 'type' => false, 'user_id' => false, 'secondary_item_id' => false );
860
+ $r = wp_parse_args( $args, $defaults );
861
+ extract( $r, EXTR_SKIP );
862
+
863
+ return bp_activity_delete( array( 'item_id' => $item_id, 'component' => $component, 'type' => $type, 'user_id' => $user_id, 'secondary_item_id' => $secondary_item_id ) );
864
+ }
865
+
866
+ function bp_activity_delete_by_activity_id( $activity_id ) {
867
+ return bp_activity_delete( array( 'id' => $activity_id ) );
868
+ }
869
+
870
+ function bp_activity_delete_by_content( $user_id, $content, $component, $type ) {
871
+ return bp_activity_delete( array( 'user_id' => $user_id, 'content' => $content, 'component' => $component, 'type' => $type ) );
872
+ }
873
+
874
+ function bp_activity_delete_for_user_by_component( $user_id, $component ) {
875
+ return bp_activity_delete( array( 'user_id' => $user_id, 'component' => $component ) );
876
+ }
877
+ /* End deprecation */
878
+
879
+ function bp_activity_delete_comment( $activity_id, $comment_id ) {
880
+ /***
881
+ * You may want to hook into this filter if you want to override this function and
882
+ * handle the deletion of child comments differently. Make sure you return false.
883
+ */
884
+ if ( !apply_filters( 'bp_activity_delete_comment_pre', true, $activity_id, $comment_id ) )
885
+ return false;
886
+
887
+ /* Delete any children of this comment. */
888
+ bp_activity_delete_children( $activity_id, $comment_id );
889
+
890
+ /* Delete the actual comment */
891
+ if ( !bp_activity_delete( array( 'id' => $comment_id, 'type' => 'activity_comment' ) ) )
892
+ return false;
893
+
894
+ /* Recalculate the comment tree */
895
+ BP_Activity_Activity::rebuild_activity_comment_tree( $activity_id );
896
+
897
+ do_action( 'bp_activity_delete_comment', $activity_id, $comment_id );
898
+
899
+ return true;
900
+ }
901
+ function bp_activity_delete_children( $activity_id, $comment_id) {
902
+ /* Recursively delete all children of this comment. */
903
+ if ( $children = BP_Activity_Activity::get_child_comments( $comment_id ) ) {
904
+ foreach( (array)$children as $child )
905
+ bp_activity_delete_children( $activity_id, $child->id );
906
+ }
907
+ bp_activity_delete( array( 'secondary_item_id' => $comment_id, 'type' => 'activity_comment', 'item_id' => $activity_id ) );
908
+ }
909
+
910
+ function bp_activity_get_permalink( $activity_id, $activity_obj = false ) {
911
+ global $bp;
912
+
913
+ if ( !$activity_obj )
914
+ $activity_obj = new BP_Activity_Activity( $activity_id );
915
+
916
+ 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 )
917
+ $link = $activity_obj->primary_link;
918
+ else {
919
+ if ( 'activity_comment' == $activity_obj->type )
920
+ $link = $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activity_obj->item_id . '/';
921
+ else
922
+ $link = $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activity_obj->id . '/';
923
+ }
924
+
925
+ return apply_filters( 'bp_activity_get_permalink', $link );
926
+ }
927
+
928
+ function bp_activity_hide_user_activity( $user_id ) {
929
+ return BP_Activity_Activity::hide_all_for_user( $user_id );
930
+ }
931
+
932
+ /**
933
+ * bp_activity_thumbnail_content_images()
934
+ *
935
+ * Take content, remove all images and replace them with one thumbnail image.
936
+ *
937
+ * @package BuddyPress Activity
938
+ * @param $content str - The content to work with
939
+ * @return $content str - The content with images stripped and replaced with a single thumb.
940
+ */
941
+ function bp_activity_thumbnail_content_images( $content ) {
942
+ preg_match_all( '/<img[^>]*>/Ui', $content, $matches );
943
+ $content = preg_replace('/<img[^>]*>/Ui', '', $content );
944
+
945
+ if ( !empty( $matches ) ) {
946
+ /* Get the SRC value */
947
+ preg_match( '/<img.*?(src\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $src );
948
+
949
+ /* Get the width and height */
950
+ preg_match( '/<img.*?(height\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $height );
951
+ preg_match( '/<img.*?(width\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $width );
952
+
953
+ if ( !empty( $src ) ) {
954
+ $src = substr( substr( str_replace( 'src=', '', $src[1] ), 0, -1 ), 1 );
955
+ $height = substr( substr( str_replace( 'height=', '', $height[1] ), 0, -1 ), 1 );
956
+ $width = substr( substr( str_replace( 'width=', '', $width[1] ), 0, -1 ), 1 );
957
+
958
+ if ( empty( $width ) || empty( $height ) ) {
959
+ $width = 100;
960
+ $height = 100;
961
+ }
962
+
963
+ $ratio = (int)$width / (int)$height;
964
+ $new_height = 100;
965
+ $new_width = $new_height * $ratio;
966
+
967
+ $content = '<img src="' . esc_attr( $src) . '" width="' . $new_width . '" height="' . $new_height . '" alt="' . __( 'Thumbnail', 'buddypress' ) . '" class="align-left thumbnail" />' . $content;
968
+ }
969
+ }
970
+
971
+ return apply_filters( 'bp_activity_thumbnail_content_images', $content, $matches );
972
+ }
973
+
974
+ function bp_activity_set_action( $component_id, $key, $value ) {
975
+ global $bp;
976
+
977
+ if ( empty( $component_id ) || empty( $key ) || empty( $value ) )
978
+ return false;
979
+
980
+ $bp->activity->actions->{$component_id}->{$key} = apply_filters( 'bp_activity_set_action', array(
981
+ 'key' => $key,
982
+ 'value' => $value
983
+ ), $component_id, $key, $value );
984
+ }
985
+
986
+ function bp_activity_get_action( $component_id, $key ) {
987
+ global $bp;
988
+
989
+ if ( empty( $component_id ) || empty( $key ) )
990
+ return false;
991
+
992
+ return apply_filters( 'bp_activity_get_action', $bp->activity->actions->{$component_id}->{$key}, $component_id, $key );
993
+ }
994
+
995
+ function bp_activity_get_user_favorites( $user_id ) {
996
+ $my_favs = maybe_unserialize( get_user_meta( $user_id, 'bp_favorite_activities', true ) );
997
+ $existing_favs = bp_activity_get_specific( array( 'activity_ids' => $my_favs ) );
998
+
999
+ foreach( (array)$existing_favs['activities'] as $fav )
1000
+ $new_favs[] = $fav->id;
1001
+
1002
+ $new_favs = array_unique( (array)$new_favs );
1003
+ update_user_meta( $user_id, 'bp_favorite_activities', $new_favs );
1004
+
1005
+ return apply_filters( 'bp_activity_get_user_favorites', $new_favs );
1006
+ }
1007
+
1008
+ function bp_activity_add_user_favorite( $activity_id, $user_id = false ) {
1009
+ global $bp;
1010
+
1011
+ if ( !$user_id )
1012
+ $user_id = $bp->loggedin_user->id;
1013
+
1014
+ /* Update the user's personal favorites */
1015
+ $my_favs = maybe_unserialize( get_user_meta( $bp->loggedin_user->id, 'bp_favorite_activities', true ) );
1016
+ $my_favs[] = $activity_id;
1017
+
1018
+ /* Update the total number of users who have favorited this activity */
1019
+ $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' );
1020
+
1021
+ if ( !empty( $fav_count ) )
1022
+ $fav_count = (int)$fav_count + 1;
1023
+ else
1024
+ $fav_count = 1;
1025
+
1026
+ update_user_meta( $bp->loggedin_user->id, 'bp_favorite_activities', $my_favs );
1027
+ bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count );
1028
+
1029
+ do_action( 'bp_activity_add_user_favorite', $activity_id, $user_id );
1030
+
1031
+ return true;
1032
+ }
1033
+
1034
+ function bp_activity_remove_user_favorite( $activity_id, $user_id = false ) {
1035
+ global $bp;
1036
+
1037
+ if ( !$user_id )
1038
+ $user_id = $bp->loggedin_user->id;
1039
+
1040
+ /* Remove the fav from the user's favs */
1041
+ $my_favs = maybe_unserialize( get_user_meta( $user_id, 'bp_favorite_activities', true ) );
1042
+ $my_favs = array_flip( (array) $my_favs );
1043
+ unset( $my_favs[$activity_id] );
1044
+ $my_favs = array_unique( array_flip( $my_favs ) );
1045
+
1046
+ /* Update the total number of users who have favorited this activity */
1047
+ $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' );
1048
+
1049
+ if ( !empty( $fav_count ) ) {
1050
+ $fav_count = (int)$fav_count - 1;
1051
+ bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count );
1052
+ }
1053
+
1054
+ update_user_meta( $user_id, 'bp_favorite_activities', $my_favs );
1055
+
1056
+ do_action( 'bp_activity_remove_user_favorite', $activity_id, $user_id );
1057
+
1058
+ return true;
1059
+ }
1060
+
1061
+ function bp_activity_check_exists_by_content( $content ) {
1062
+ return apply_filters( 'bp_activity_check_exists_by_content', BP_Activity_Activity::check_exists_by_content( $content ) );
1063
+ }
1064
+
1065
+ function bp_activity_get_last_updated() {
1066
+ return apply_filters( 'bp_activity_get_last_updated', BP_Activity_Activity::get_last_updated() );
1067
+ }
1068
+
1069
+ function bp_activity_total_favorites_for_user( $user_id = false ) {
1070
+ global $bp;
1071
+
1072
+ if ( !$user_id )
1073
+ $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id;
1074
+
1075
+ return BP_Activity_Activity::total_favorite_count( $user_id );
1076
+ }
1077
+
1078
+ /********************************************************************************
1079
+ * Activity Meta Functions
1080
+ *
1081
+ * Meta functions allow you to store extra data for a particular item.
1082
+ */
1083
+
1084
+ function bp_activity_delete_meta( $activity_id, $meta_key = false, $meta_value = false ) {
1085
+ global $wpdb, $bp;
1086
+
1087
+ if ( !is_numeric( $activity_id ) )
1088
+ return false;
1089
+
1090
+ $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
1091
+
1092
+ if ( is_array( $meta_value ) || is_object( $meta_value ) )
1093
+ $meta_value = serialize( $meta_value );
1094
+
1095
+ $meta_value = trim( $meta_value );
1096
+
1097
+ if ( !$meta_key ) {
1098
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d", $activity_id ) );
1099
+ } else if ( $meta_value ) {
1100
+ $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 ) );
1101
+ } else {
1102
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id = %d AND meta_key = %s", $activity_id, $meta_key ) );
1103
+ }
1104
+
1105
+ wp_cache_delete( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, 'bp' );
1106
+
1107
+ return true;
1108
+ }
1109
+
1110
+ function bp_activity_get_meta( $activity_id, $meta_key = '' ) {
1111
+ global $wpdb, $bp;
1112
+
1113
+ $activity_id = (int)$activity_id;
1114
+
1115
+ if ( !$activity_id )
1116
+ return false;
1117
+
1118
+ if ( !empty($meta_key) ) {
1119
+ $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
1120
+
1121
+ if ( !$metas = wp_cache_get( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, 'bp' ) ) {
1122
+ $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 ) );
1123
+ wp_cache_set( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, $metas, 'bp' );
1124
+ }
1125
+ } else
1126
+ $metas = $wpdb->get_col( $wpdb->prepare( "SELECT meta_value FROM {$bp->activity->table_name_meta} WHERE activity_id = %d", $activity_id ) );
1127
+
1128
+ if ( empty($metas) )
1129
+ return false;
1130
+
1131
+ $metas = array_map( 'maybe_unserialize', (array)$metas );
1132
+
1133
+ if ( 1 == count($metas) )
1134
+ return $metas[0];
1135
+ else
1136
+ return $metas;
1137
+ }
1138
+
1139
+ function bp_activity_update_meta( $activity_id, $meta_key, $meta_value ) {
1140
+ global $wpdb, $bp;
1141
+
1142
+ if ( !is_numeric( $activity_id ) )
1143
+ return false;
1144
+
1145
+ $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
1146
+
1147
+ if ( is_string( $meta_value ) )
1148
+ $meta_value = stripslashes( $wpdb->escape( $meta_value ) );
1149
+
1150
+ $meta_value = maybe_serialize( $meta_value );
1151
+
1152
+ if ( empty( $meta_value ) ) {
1153
+ return bp_activity_delete_meta( $activity_id, $meta_key );
1154
+ }
1155
+
1156
+ $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 ) );
1157
+
1158
+ if ( !$cur ) {
1159
+ $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 ) );
1160
+ } else if ( $cur->meta_value != $meta_value ) {
1161
+ $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 ) );
1162
+ } else {
1163
+ return false;
1164
+ }
1165
+
1166
+ wp_cache_set( 'bp_activity_meta_' . $meta_key . '_' . $activity_id, $meta_value, 'bp' );
1167
+
1168
+ return true;
1169
+ }
1170
+
1171
+ function bp_activity_remove_data( $user_id ) {
1172
+ // Clear the user's activity from the sitewide stream and clear their activity tables
1173
+ bp_activity_delete( array( 'user_id' => $user_id ) );
1174
+
1175
+ // Remove any usermeta
1176
+ delete_user_meta( $user_id, 'bp_latest_update' );
1177
+ delete_user_meta( $user_id, 'bp_favorite_activities' );
1178
+
1179
+ do_action( 'bp_activity_remove_data', $user_id );
1180
+ }
1181
+ add_action( 'wpmu_delete_user', 'bp_activity_remove_data' );
1182
+ add_action( 'delete_user', 'bp_activity_remove_data' );
1183
+ add_action( 'make_spam_user', 'bp_activity_remove_data' );
1184
+
1185
+ /**
1186
+ * updates_register_activity_actions()
1187
+ *
1188
+ * Register the activity stream actions for updates
1189
+ *
1190
+ * @global array $bp
1191
+ */
1192
+ function updates_register_activity_actions() {
1193
+ global $bp;
1194
+
1195
+ bp_activity_set_action( $bp->activity->id, 'activity_update', __( 'Posted an update', 'buddypress' ) );
1196
+
1197
+ do_action( 'updates_register_activity_actions' );
1198
+ }
1199
+ add_action( 'bp_register_activity_actions', 'updates_register_activity_actions' );
1200
+
1201
+ /********************************************************************************
1202
+ * Custom Actions
1203
+ *
1204
+ * Functions to set up custom BuddyPress actions that all other components can
1205
+ * hook in to.
1206
+ */
1207
+
1208
+ /* Allow core components and dependent plugins to register activity actions */
1209
+ function bp_register_activity_actions() {
1210
+ do_action( 'bp_register_activity_actions' );
1211
+ }
1212
+ add_action( 'bp_loaded', 'bp_register_activity_actions', 8 );
1213
+
1214
+
1215
?>
bp-activity/bp-activity-classes.php CHANGED
@@ -1,553 +1,553 @@
1
- <?php
2
-
3
- Class BP_Activity_Activity {
4
- var $id;
5
- var $item_id;
6
- var $secondary_item_id;
7
- var $user_id;
8
- var $primary_link;
9
- var $component;
10
- var $type;
11
- var $action;
12
- var $content;
13
- var $date_recorded;
14
- var $hide_sitewide = false;
15
-
16
- function bp_activity_activity( $id = false ) {
17
- global $bp;
18
-
19
- if ( $id ) {
20
- $this->id = $id;
21
- $this->populate();
22
- }
23
- }
24
-
25
- function populate() {
26
- global $wpdb, $bp;
27
-
28
- $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id = %d", $this->id ) );
29
- if ( $row ) {
30
- $this->id = $row->id;
31
- $this->item_id = $row->item_id;
32
- $this->secondary_item_id = $row->secondary_item_id;
33
- $this->user_id = $row->user_id;
34
- $this->primary_link = $row->primary_link;
35
- $this->component = $row->component;
36
- $this->type = $row->type;
37
- $this->action = $row->action;
38
- $this->content = $row->content;
39
- $this->date_recorded = $row->date_recorded;
40
- $this->hide_sitewide = $row->hide_sitewide;
41
- $this->mptt_left = $row->mptt_left;
42
- $this->mptt_right = $row->mptt_right;
43
- }
44
- }
45
-
46
- function save() {
47
- global $wpdb, $bp, $current_user;
48
-
49
- do_action( 'bp_activity_before_save', &$this );
50
-
51
- $this->id = apply_filters( 'bp_activity_id_before_save', $this->id, &$this );
52
- $this->item_id = apply_filters( 'bp_activity_item_id_before_save', $this->item_id, &$this );
53
- $this->secondary_item_id = apply_filters( 'bp_activity_secondary_item_id_before_save', $this->secondary_item_id, &$this );
54
- $this->user_id = apply_filters( 'bp_activity_user_id_before_save', $this->user_id, &$this );
55
- $this->primary_link = apply_filters( 'bp_activity_primary_link_before_save', $this->primary_link, &$this );
56
- $this->component = apply_filters( 'bp_activity_component_before_save', $this->component, &$this );
57
- $this->type = apply_filters( 'bp_activity_type_before_save', $this->type, &$this );
58
- $this->action = apply_filters( 'bp_activity_action_before_save', $this->action, &$this );
59
- $this->content = apply_filters( 'bp_activity_content_before_save', $this->content, &$this );
60
- $this->date_recorded = apply_filters( 'bp_activity_date_recorded_before_save', $this->date_recorded, &$this );
61
- $this->hide_sitewide = apply_filters( 'bp_activity_hide_sitewide_before_save', $this->hide_sitewide, &$this );
62
- $this->mptt_left = apply_filters( 'bp_activity_mptt_left_before_save', $this->mptt_left, &$this );
63
- $this->mptt_right = apply_filters( 'bp_activity_mptt_right_before_save', $this->mptt_right, &$this );
64
-
65
- if ( !$this->component || !$this->type )
66
- return false;
67
-
68
- if ( !$this->primary_link )
69
- $this->primary_link = $bp->loggedin_user->domain;
70
-
71
- /* If we have an existing ID, update the activity item, otherwise insert it. */
72
- if ( $this->id )
73
- $q = $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET user_id = %d, component = %s, type = %s, action = %s, content = %s, primary_link = %s, date_recorded = %s, item_id = %s, secondary_item_id = %s, hide_sitewide = %d WHERE id = %d", $this->user_id, $this->component, $this->type, $this->action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide, $this->id );
74
- else
75
- $q = $wpdb->prepare( "INSERT INTO {$bp->activity->table_name} ( user_id, component, type, action, content, primary_link, date_recorded, item_id, secondary_item_id, hide_sitewide ) VALUES ( %d, %s, %s, %s, %s, %s, %s, %s, %s, %d )", $this->user_id, $this->component, $this->type, $this->action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide );
76
-
77
- if ( !$wpdb->query( $q ) )
78
- return false;
79
-
80
- if ( empty( $this->id ) )
81
- $this->id = $wpdb->insert_id;
82
-
83
- do_action( 'bp_activity_after_save', &$this );
84
- return true;
85
- }
86
-
87
- /* Static Functions */
88
-
89
- function get( $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $search_terms = false, $filter = false, $display_comments = false, $show_hidden = false ) {
90
- global $wpdb, $bp;
91
-
92
- /* Select conditions */
93
- $select_sql = "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name";
94
-
95
- $from_sql = " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID";
96
-
97
- /* Where conditions */
98
- $where_conditions = array();
99
-
100
- /* Searching */
101
- if ( $search_terms ) {
102
- $search_terms = $wpdb->escape( $search_terms );
103
- $where_conditions['search_sql'] = "a.content LIKE '%%" . like_escape( $search_terms ) . "%%'";
104
- }
105
-
106
- /* Filtering */
107
- if ( $filter && $filter_sql = BP_Activity_Activity::get_filter_sql( $filter ) )
108
- $where_conditions['filter_sql'] = $filter_sql;
109
-
110
- /* Sorting */
111
- if ( $sort != 'ASC' && $sort != 'DESC' )
112
- $sort = 'DESC';
113
-
114
- /* Hide Hidden Items? */
115
- if ( !$show_hidden )
116
- $where_conditions['hidden_sql'] = "a.hide_sitewide = 0";
117
-
118
- /* Alter the query based on whether we want to show activity item comments in the stream like normal comments or threaded below the activity */
119
- if ( !$display_comments || 'threaded' == $display_comments ) {
120
- $where_conditions[] = "a.type != 'activity_comment'";
121
- }
122
-
123
- $where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
124
-
125
- if ( $per_page && $page ) {
126
- $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page ), intval( $per_page ) );
127
- $activities = $wpdb->get_results( $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}" ) );
128
- } else
129
- $activities = $wpdb->get_results( $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}" ) );
130
-
131
- $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(a.id) FROM {$bp->activity->table_name} a {$where_sql} ORDER BY a.date_recorded {$sort}" ) );
132
-
133
- /* Get the fullnames of users so we don't have to query in the loop */
134
- if ( function_exists( 'xprofile_install' ) && $activities ) {
135
- foreach ( (array)$activities as $activity ) {
136
- if ( (int)$activity->user_id )
137
- $activity_user_ids[] = $activity->user_id;
138
- }
139
-
140
- $activity_user_ids = implode( ',', array_unique( (array)$activity_user_ids ) );
141
- if ( !empty( $activity_user_ids ) ) {
142
- if ( $names = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, value AS user_fullname FROM {$bp->profile->table_name_data} WHERE field_id = 1 AND user_id IN ({$activity_user_ids})" ) ) ) {
143
- foreach ( (array)$names as $name )
144
- $tmp_names[$name->user_id] = $name->user_fullname;
145
-
146
- foreach ( (array)$activities as $i => $activity ) {
147
- if ( !empty( $tmp_names[$activity->user_id] ) )
148
- $activities[$i]->user_fullname = $tmp_names[$activity->user_id];
149
- }
150
-
151
- unset( $names );
152
- unset( $tmp_names );
153
- }
154
- }
155
- }
156
-
157
- if ( $activities && $display_comments )
158
- $activities = BP_Activity_Activity::append_comments( &$activities );
159
-
160
- /* If $max is set, only return up to the max results */
161
- if ( !empty( $max ) ) {
162
- if ( (int)$total_activities > (int)$max )
163
- $total_activities = $max;
164
- }
165
-
166
- return array( 'activities' => $activities, 'total' => (int)$total_activities );
167
- }
168
-
169
- function get_specific( $activity_ids, $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $display_comments = false ) {
170
- global $wpdb, $bp;
171
-
172
- if ( is_array( $activity_ids ) )
173
- $activity_ids = implode( ',', $activity_ids );
174
-
175
- $activity_ids = $wpdb->escape( $activity_ids );
176
-
177
- if ( empty( $activity_ids ) )
178
- return false;
179
-
180
- if ( $per_page && $page )
181
- $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page ), intval( $per_page ) );
182
-
183
- if ( $sort != 'ASC' && $sort != 'DESC' )
184
- $sort = 'DESC';
185
-
186
- $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE id IN ({$activity_ids}) ORDER BY date_recorded {$sort} $pag_sql" ) );
187
- $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE id IN ({$activity_ids})" ) );
188
-
189
- if ( $display_comments )
190
- $activities = BP_Activity_Activity::append_comments( $activities );
191
-
192
- /* If $max is set, only return up to the max results */
193
- if ( !empty( $max ) ) {
194
- if ( (int)$total_activities > (int)$max )
195
- $total_activities = $max;
196
- }
197
-
198
- return array( 'activities' => $activities, 'total' => (int)$total_activities );
199
- }
200
-
201
- function get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content, $date_recorded ) {
202
- global $bp, $wpdb;
203
-
204
- $where_args = false;
205
-
206
- if ( !empty( $user_id ) )
207
- $where_args[] = $wpdb->prepare( "user_id = %d", $user_id );
208
-
209
- if ( !empty( $component ) )
210
- $where_args[] = $wpdb->prepare( "component = %s", $component );
211
-
212
- if ( !empty( $type ) )
213
- $where_args[] = $wpdb->prepare( "type = %s", $type );
214
-
215
- if ( !empty( $item_id ) )
216
- $where_args[] = $wpdb->prepare( "item_id = %s", $item_id );
217
-
218
- if ( !empty( $secondary_item_id ) )
219
- $where_args[] = $wpdb->prepare( "secondary_item_id = %s", $secondary_item_id );
220
-
221
- if ( !empty( $action ) )
222
- $where_args[] = $wpdb->prepare( "action = %s", $action );
223
-
224
- if ( !empty( $content ) )
225
- $where_args[] = $wpdb->prepare( "content = %s", $content );
226
-
227
- if ( !empty( $date_recorded ) )
228
- $where_args[] = $wpdb->prepare( "date_recorded = %s", $date_recorded );
229
-
230
- if ( !empty( $where_args ) )
231
- $where_sql = 'WHERE ' . join( ' AND ', $where_args );
232
- else
233
- return false;
234
-
235
- return $wpdb->get_var( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" );
236
- }
237
-
238
- function delete( $args ) {
239
- global $wpdb, $bp;
240
-
241
- extract( $args );
242
-
243
- $defaults = array(
244
- 'id' => false,
245
- 'action' => false,
246
- 'content' => false,
247
- 'component' => false,
248
- 'type' => false,
249
- 'primary_link' => false,
250
- 'user_id' => false,
251
- 'item_id' => false,
252
- 'secondary_item_id' => false,
253
- 'date_recorded' => false,
254
- 'hide_sitewide' => false
255
- );
256
-
257
- $where_args = false;
258
-
259
- if ( !empty( $id ) )
260
- $where_args[] = $wpdb->prepare( "id = %d", $id );
261
-
262
- if ( !empty( $user_id ) )
263
- $where_args[] = $wpdb->prepare( "user_id = %d", $user_id );
264
-
265
- if ( !empty( $action ) )
266
- $where_args[] = $wpdb->prepare( "action = %s", $action );
267
-
268
- if ( !empty( $content ) )
269
- $where_args[] = $wpdb->prepare( "content = %s", $content );
270
-
271
- if ( !empty( $component ) )
272
- $where_args[] = $wpdb->prepare( "component = %s", $component );
273
-
274
- if ( !empty( $type ) )
275
- $where_args[] = $wpdb->prepare( "type = %s", $type );
276
-
277
- if ( !empty( $primary_link ) )
278
- $where_args[] = $wpdb->prepare( "primary_link = %s", $primary_link );
279
-
280
- if ( !empty( $item_id ) )
281
- $where_args[] = $wpdb->prepare( "item_id = %s", $item_id );
282
-
283
- if ( !empty( $secondary_item_id ) )
284
- $where_args[] = $wpdb->prepare( "secondary_item_id = %s", $secondary_item_id );
285
-
286
- if ( !empty( $date_recorded ) )
287
- $where_args[] = $wpdb->prepare( "date_recorded = %s", $date_recorded );
288
-
289
- if ( !empty( $hide_sitewide ) )
290
- $where_args[] = $wpdb->prepare( "hide_sitewide = %d", $hide_sitewide );
291
-
292
- if ( !empty( $where_args ) )
293
- $where_sql = 'WHERE ' . join( ' AND ', $where_args );
294
- else
295
- return false;
296
-
297
- /* Fetch the activity IDs so we can delete any comments for this activity item */
298
- $activity_ids = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} {$where_sql}" ) );
299
-
300
- if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} {$where_sql}" ) ) )
301
- return false;
302
-
303
- if ( $activity_ids ) {
304
- BP_Activity_Activity::delete_activity_item_comments( $activity_ids );
305
- BP_Activity_Activity::delete_activity_meta_entries( $activity_ids );
306
-
307
- return $activity_ids;
308
- }
309
-
310
- return $activity_ids;
311
- }
312
-
313
- function delete_activity_item_comments( $activity_ids ) {
314
- global $bp, $wpdb;
315
-
316
- if ( is_array($activity_ids) )
317
- $activity_ids = implode( ',', $activity_ids );
318
-
319
- $activity_ids = $wpdb->escape( $activity_ids );
320
-
321
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND item_id IN ({$activity_ids})" ) );
322
- }
323
-
324
- function delete_activity_meta_entries( $activity_ids ) {
325
- global $bp, $wpdb;
326
-
327
- if ( is_array($activity_ids) )
328
- $activity_ids = implode( ',', $activity_ids );
329
-
330
- $activity_ids = $wpdb->escape( $activity_ids );
331
-
332
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name_meta} WHERE activity_id IN ({$activity_ids})" ) );
333
- }
334
-
335
- function append_comments( $activities ) {
336
- global $bp, $wpdb;
337
-
338
- /* Now fetch the activity comments and parse them into the correct position in the activities array. */
339
- foreach( (array)$activities as $activity ) {
340
- if ( 'activity_comment' != $activity->type && $activity->mptt_left && $activity->mptt_right )
341
- $activity_comments[$activity->id] = BP_Activity_Activity::get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right );
342
- }
343
-
344
- /* Merge the comments with the activity items */
345
- foreach( (array)$activities as $key => $activity )
346
- $activities[$key]->children = $activity_comments[$activity->id];
347
-
348
- return $activities;
349
- }
350
-
351
- function get_activity_comments( $activity_id, $left, $right ) {
352
- global $wpdb, $bp;
353
-
354
- if ( !$comments = wp_cache_get( 'bp_activity_comments_' . $activity_id ) ) {
355
- /* Select the user's fullname with the query so we don't have to fetch it for each comment */
356
- if ( function_exists( 'xprofile_install' ) ) {
357
- $fullname_select = ", pd.value as user_fullname";
358
- $fullname_from = ", {$bp->profile->table_name_data} pd ";
359
- $fullname_where = "AND pd.user_id = a.user_id AND pd.field_id = 1";
360
- }
361
-
362
- /* Retrieve all descendants of the $root node */
363
- $descendants = $wpdb->get_results( $wpdb->prepare( "SELECT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name{$fullname_select} FROM {$bp->activity->table_name} a, {$wpdb->users} u{$fullname_from} WHERE u.ID = a.user_id {$fullname_where} AND a.type = 'activity_comment' AND a.item_id = %d AND a.mptt_left BETWEEN %d AND %d ORDER BY a.date_recorded ASC", $activity_id, $left, $right ) );
364
-
365
- /* Loop descendants and build an assoc array */
366
- foreach ( (array)$descendants as $d ) {
367
- $d->children = array();
368
-
369
- /* If we have a reference on the parent */
370
- if ( isset( $ref[ $d->secondary_item_id ] ) ) {
371
- $ref[ $d->secondary_item_id ]->children[ $d->id ] = $d;
372
- $ref[ $d->id ] =& $ref[ $d->secondary_item_id ]->children[ $d->id ];
373
-
374
- /* If we don't have a reference on the parent, put in the root level */
375
- } else {
376
- $comments[ $d->id ] = $d;
377
- $ref[ $d->id ] =& $comments[ $d->id ];
378
- }
379
- }
380
- wp_cache_set( 'bp_activity_comments_' . $activity_id, $comments, 'bp' );
381
- }
382
-
383
- return $comments;
384
- }
385
-
386
- function rebuild_activity_comment_tree( $parent_id, $left = 1 ) {
387
- global $wpdb, $bp;
388
-
389
- /* The right value of this node is the left value + 1 */
390
- $right = $left + 1;
391
-
392
- /* Get all descendants of this node */
393
- $descendants = BP_Activity_Activity::get_child_comments( $parent_id );
394
-
395
- /* Loop the descendants and recalculate the left and right values */
396
- foreach ( (array)$descendants as $descendant )
397
- $right = BP_Activity_Activity::rebuild_activity_comment_tree( $descendant->id, $right );
398
-
399
- /* We've got the left value, and now that we've processed the children of this node we also know the right value */
400
- if ( 1 == $left )
401
- $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE id = %d", $left, $right, $parent_id ) );
402
- else
403
- $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d W