BuddyPress - Version 1.2.2

Version Description

Download this release

Release Info

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

Code changes from version 1.2.1 to 1.2.2

bp-activity.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
 
3
- define ( 'BP_ACTIVITY_DB_VERSION', '2060' );
4
 
5
  /* Define the slug for the component */
6
  if ( !defined( 'BP_ACTIVITY_SLUG' ) )
@@ -44,8 +44,8 @@ function bp_activity_install() {
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,
48
- mptt_right int(11) NOT NULL,
49
  KEY date_recorded (date_recorded),
50
  KEY user_id (user_id),
51
  KEY item_id (item_id),
@@ -247,7 +247,11 @@ function bp_activity_screen_single_activity_permalink() {
247
 
248
  if ( !$has_access ) {
249
  bp_core_add_message( __( 'You do not have access to this activity.', 'buddypress' ), 'error' );
250
- bp_core_redirect( $bp->loggedin_user->domain );
 
 
 
 
251
  }
252
 
253
  bp_core_load_template( apply_filters( 'bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink' ) );
@@ -311,19 +315,21 @@ function bp_activity_action_permalink_router() {
311
  /* Redirect based on the type of activity */
312
  if ( $activity->component == $bp->groups->id ) {
313
  if ( $activity->user_id )
314
- $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id;
315
  else {
316
  if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) )
317
- $redirect = bp_get_group_permalink( $group ) . $bp->activity->slug . '/' . $activity->id;
318
  }
319
  } else
320
  $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id;
321
 
 
 
322
  if ( !$redirect )
323
  bp_core_redirect( $bp->root_domain );
324
 
325
  /* Redirect to the actual activity permalink page */
326
- bp_core_redirect( apply_filters( 'bp_activity_action_permalink_url', $redirect . '/', &$activity ) );
327
  }
328
  add_action( 'wp', 'bp_activity_action_permalink_router', 3 );
329
 
@@ -714,6 +720,7 @@ function bp_activity_new_comment( $args = '' ) {
714
  global $bp;
715
 
716
  $defaults = array(
 
717
  'content' => false,
718
  'user_id' => $bp->loggedin_user->id,
719
  'activity_id' => false, // ID of the root activity item
@@ -735,6 +742,7 @@ function bp_activity_new_comment( $args = '' ) {
735
 
736
  /* Insert the activity comment */
737
  $comment_id = bp_activity_add( array(
 
738
  'action' => apply_filters( 'bp_activity_comment_action', sprintf( __( '%s posted a new activity comment:', 'buddypress' ), bp_core_get_userlink( $user_id ) ) ),
739
  'content' => apply_filters( 'bp_activity_comment_content', $content ),
740
  'component' => $bp->activity->id,
@@ -772,13 +780,14 @@ function bp_activity_get_activity_id( $args = '' ) {
772
  'item_id' => false,
773
  'secondary_item_id' => false,
774
  'action' => false,
775
- 'content' => false
 
776
  );
777
 
778
  $r = wp_parse_args( $args, $defaults );
779
  extract( $r, EXTR_SKIP );
780
 
781
- return apply_filters( 'bp_activity_get_activity_id', BP_Activity_Activity::get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content ) );
782
  }
783
 
784
  /***
1
  <?php
2
 
3
+ define ( 'BP_ACTIVITY_DB_VERSION', '2100' );
4
 
5
  /* Define the slug for the component */
6
  if ( !defined( 'BP_ACTIVITY_SLUG' ) )
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),
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' ) );
315
  /* Redirect based on the type of activity */
316
  if ( $activity->component == $bp->groups->id ) {
317
  if ( $activity->user_id )
318
+ $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id . '/';
319
  else {
320
  if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) )
321
+ $redirect = bp_get_group_permalink( $group ) . $bp->activity->slug . '/' . $activity->id . '/';
322
  }
323
  } else
324
  $redirect = bp_core_get_user_domain( $activity->user_id, $activity->user_nicename, $activity->user_login ) . $bp->activity->slug . '/' . $activity->id;
325
 
326
+ $redirect = apply_filters( 'bp_activity_permalink_redirect_url', $redirect, &$activity );
327
+
328
  if ( !$redirect )
329
  bp_core_redirect( $bp->root_domain );
330
 
331
  /* Redirect to the actual activity permalink page */
332
+ bp_core_redirect( $redirect );
333
  }
334
  add_action( 'wp', 'bp_activity_action_permalink_router', 3 );
335
 
720
  global $bp;
721
 
722
  $defaults = array(
723
+ 'id' => false,
724
  'content' => false,
725
  'user_id' => $bp->loggedin_user->id,
726
  'activity_id' => false, // ID of the root activity item
742
 
743
  /* Insert the activity comment */
744
  $comment_id = bp_activity_add( array(
745
+ 'id' => $id,
746
  'action' => apply_filters( 'bp_activity_comment_action', sprintf( __( '%s posted a new activity comment:', 'buddypress' ), bp_core_get_userlink( $user_id ) ) ),
747
  'content' => apply_filters( 'bp_activity_comment_content', $content ),
748
  'component' => $bp->activity->id,
780
  'item_id' => false,
781
  'secondary_item_id' => false,
782
  'action' => false,
783
+ 'content' => false,
784
+ 'date_recorded' => false,
785
  );
786
 
787
  $r = wp_parse_args( $args, $defaults );
788
  extract( $r, EXTR_SKIP );
789
 
790
+ return apply_filters( 'bp_activity_get_activity_id', BP_Activity_Activity::get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content, $date_recorded ) );
791
  }
792
 
793
  /***
bp-activity/bp-activity-classes.php CHANGED
@@ -198,7 +198,7 @@ Class BP_Activity_Activity {
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 ) {
202
  global $bp, $wpdb;
203
 
204
  $where_args = false;
@@ -224,6 +224,9 @@ Class BP_Activity_Activity {
224
  if ( !empty( $content ) )
225
  $where_args[] = $wpdb->prepare( "content = %s", $content );
226
 
 
 
 
227
  if ( !empty( $where_args ) )
228
  $where_sql = 'WHERE ' . join( ' AND ', $where_args );
229
  else
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;
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
bp-activity/bp-activity-templatetags.php CHANGED
@@ -540,7 +540,7 @@ function bp_activity_parent_content( $args = '' ) {
540
  }
541
 
542
  function bp_activity_is_favorite() {
543
- echo bp_get_is_activity_favorite();
544
  }
545
  function bp_get_activity_is_favorite() {
546
  global $bp, $activities_template;
540
  }
541
 
542
  function bp_activity_is_favorite() {
543
+ echo bp_get_activity_is_favorite();
544
  }
545
  function bp_get_activity_is_favorite() {
546
  global $bp, $activities_template;
bp-blogs.php CHANGED
@@ -27,30 +27,6 @@ function bp_blogs_install() {
27
  KEY blog_id (blog_id)
28
  ) {$charset_collate};";
29
 
30
- $sql[] = "CREATE TABLE {$bp->blogs->table_name_blog_posts} (
31
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
32
- user_id bigint(20) NOT NULL,
33
- blog_id bigint(20) NOT NULL,
34
- post_id bigint(20) NOT NULL,
35
- date_created datetime NOT NULL,
36
- KEY user_id (user_id),
37
- KEY blog_id (blog_id),
38
- KEY post_id (post_id)
39
- ) {$charset_collate};";
40
-
41
- $sql[] = "CREATE TABLE {$bp->blogs->table_name_blog_comments} (
42
- id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
43
- user_id bigint(20) NOT NULL,
44
- blog_id bigint(20) NOT NULL,
45
- comment_id bigint(20) NOT NULL,
46
- comment_post_id bigint(20) NOT NULL,
47
- date_created datetime NOT NULL,
48
- KEY user_id (user_id),
49
- KEY blog_id (blog_id),
50
- KEY comment_id (comment_id),
51
- KEY comment_post_id (comment_post_id)
52
- ) {$charset_collate};";
53
-
54
  $sql[] = "CREATE TABLE {$bp->blogs->table_name_blogmeta} (
55
  id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
56
  blog_id bigint(20) NOT NULL,
@@ -93,8 +69,6 @@ function bp_blogs_setup_globals() {
93
  $bp->blogs->id = 'blogs';
94
 
95
  $bp->blogs->table_name = $wpdb->base_prefix . 'bp_user_blogs';
96
- $bp->blogs->table_name_blog_posts = $wpdb->base_prefix . 'bp_user_blogs_posts';
97
- $bp->blogs->table_name_blog_comments = $wpdb->base_prefix . 'bp_user_blogs_comments';
98
  $bp->blogs->table_name_blogmeta = $wpdb->base_prefix . 'bp_user_blogs_blogmeta';
99
  $bp->blogs->format_notification_function = 'bp_blogs_format_notifications';
100
  $bp->blogs->slug = BP_BLOGS_SLUG;
@@ -182,16 +156,6 @@ function bp_blogs_screen_my_blogs() {
182
  bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'members/single/home' ) );
183
  }
184
 
185
- function bp_blogs_screen_recent_posts() {
186
- do_action( 'bp_blogs_screen_recent_posts' );
187
- bp_core_load_template( apply_filters( 'bp_blogs_template_recent_posts', 'members/single/home' ) );
188
- }
189
-
190
- function bp_blogs_screen_recent_comments() {
191
- do_action( 'bp_blogs_screen_recent_comments' );
192
- bp_core_load_template( apply_filters( 'bp_blogs_template_recent_comments', 'members/single/home' ) );
193
- }
194
-
195
  function bp_blogs_screen_create_a_blog() {
196
  global $bp;
197
 
@@ -330,7 +294,6 @@ function bp_blogs_get_blogs( $args = '' ) {
330
  return apply_filters( 'bp_blogs_get_blogs', BP_Blogs_Blog::get( $type, $per_page, $page, $user_id, $search_terms ), &$params );
331
  }
332
 
333
-
334
  function bp_blogs_record_existing_blogs() {
335
  global $bp, $wpdb;
336
 
@@ -402,7 +365,7 @@ function bp_blogs_record_post( $post_id, $post, $user_id = false ) {
402
  if ( !$user_id )
403
  $user_id = (int)$post->post_author;
404
 
405
- /* This is to stop infinate loops with Donncha's sitewide tags plugin */
406
  if ( (int)$bp->site_options['tags_blog_id'] == (int)$blog_id )
407
  return false;
408
 
@@ -410,59 +373,11 @@ function bp_blogs_record_post( $post_id, $post, $user_id = false ) {
410
  if ( $post->post_type != 'post' )
411
  return false;
412
 
413
- if ( !$is_recorded = BP_Blogs_Post::is_recorded( $post_id, $blog_id, $user_id ) ) {
414
- if ( 'publish' == $post->post_status && '' == $post->post_password ) {
415
-
416
- /* If we're on a multiblog install, record this post */
417
- if ( bp_core_is_multisite() ) {
418
- $recorded_post = new BP_Blogs_Post;
419
- $recorded_post->user_id = $user_id;
420
- $recorded_post->blog_id = $blog_id;
421
- $recorded_post->post_id = $post_id;
422
- $recorded_post->date_created = strtotime( $post->post_date );
423
-
424
- $recorded_post_id = $recorded_post->save();
425
-
426
- bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
427
- }
428
-
429
- if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
430
- /* Record this in activity streams */
431
- $post_permalink = get_permalink( $post_id );
432
-
433
- $activity_action = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
434
- $activity_content = $post->post_content;
435
-
436
- bp_blogs_record_activity( array(
437
- 'user_id' => (int)$post->post_author,
438
- 'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, &$post, $post_permalink ),
439
- 'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink ),
440
- 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ),
441
- 'type' => 'new_blog_post',
442
- 'item_id' => $blog_id,
443
- 'secondary_item_id' => $post_id,
444
- 'recorded_time' => $post->post_date_gmt
445
- ));
446
- }
447
- }
448
- } else {
449
- $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id );
450
-
451
- /* Delete the recorded post if the status is not published or it is password protected */
452
- if ( 'publish' != $post->post_status || '' != $post->post_password ) {
453
- return bp_blogs_remove_post( $post_id, $blog_id, $existing_post );
454
-
455
- /* If the post author has changed, delete the post and re-add it. */
456
- } else if ( (int)$existing_post->user_id != (int)$post->post_author ) {
457
- // Delete the existing recorded post
458
- bp_blogs_remove_post( $post_id, $blog_id, $existing_post );
459
-
460
- // Re-record the post with the new author.
461
- bp_blogs_record_post( $post_id );
462
- }
463
 
464
  if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
465
- /* Now re-record the post in the activity streams */
466
  $post_permalink = get_permalink( $post_id );
467
 
468
  $activity_action = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
@@ -477,20 +392,18 @@ function bp_blogs_record_post( $post_id, $post, $user_id = false ) {
477
  'item_id' => $blog_id,
478
  'secondary_item_id' => $post_id,
479
  'recorded_time' => $post->post_date_gmt
480
- ) );
481
  }
482
- }
 
483
 
484
- do_action( 'bp_blogs_new_blog_post', $existing_post, $is_private, $is_recorded );
485
  }
486
  add_action( 'save_post', 'bp_blogs_record_post', 10, 2 );
487
 
488
- function bp_blogs_record_comment( $comment_id, $is_approved ) {
489
  global $wpdb, $bp;
490
 
491
- if ( !$is_approved )
492
- return false;
493
-
494
  $comment = get_comment($comment_id);
495
  $comment->post = get_post( $comment->comment_post_ID );
496
 
@@ -505,20 +418,6 @@ function bp_blogs_record_comment( $comment_id, $is_approved ) {
505
  if ( !empty( $post->post_password ) )
506
  return false;
507
 
508
- /* If we're on a multiblog install, record this post */
509
- if ( bp_core_is_multisite() ) {
510
- $recorded_comment = new BP_Blogs_Comment;
511
- $recorded_comment->user_id = $user_id;
512
- $recorded_comment->blog_id = $wpdb->blogid;
513
- $recorded_comment->comment_id = $comment_id;
514
- $recorded_comment->comment_post_id = $comment->comment_post_ID;
515
- $recorded_comment->date_created = strtotime( $comment->comment_date_gmt );
516
-
517
- $recorded_commment_id = $recorded_comment->save();
518
-
519
- bp_blogs_update_blogmeta( $recorded_comment->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
520
- }
521
-
522
  if ( (int)get_blog_option( $recorded_comment->blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
523
  /* Record in activity streams */
524
  $comment_link = get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment_id;
@@ -541,6 +440,7 @@ function bp_blogs_record_comment( $comment_id, $is_approved ) {
541
  return $recorded_comment;
542
  }
543
  add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
 
544
 
545
  function bp_blogs_manage_comment( $comment_id, $comment_status ) {
546
  if ( 'spam' == $comment_status || 'hold' == $comment_status || 'delete' == $comment_status || 'trash' == $comment_status )
@@ -600,7 +500,7 @@ function bp_blogs_remove_blog_for_user( $user_id, $blog_id ) {
600
  }
601
  add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 );
602
 
603
- function bp_blogs_remove_post( $post_id, $blog_id = false, $existing_post = false ) {
604
  global $current_blog, $bp;
605
 
606
  $post_id = (int)$post_id;
@@ -608,12 +508,6 @@ function bp_blogs_remove_post( $post_id, $blog_id = false, $existing_post = fals
608
  if ( !$blog_id )
609
  $blog_id = (int)$current_blog->blog_id;
610
 
611
- if ( !$existing_post )
612
- $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id );
613
-
614
- // Delete post from the bp_blogs table
615
- BP_Blogs_Post::delete( $post_id, $blog_id );
616
-
617
  // Delete activity stream item
618
  bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog_post' ) );
619
 
@@ -624,9 +518,6 @@ add_action( 'delete_post', 'bp_blogs_remove_post' );
624
  function bp_blogs_remove_comment( $comment_id ) {
625
  global $wpdb, $bp;
626
 
627
- $recorded_comment = new BP_Blogs_Comment( false, $wpdb->blogid, $comment_id );
628
- BP_Blogs_Comment::delete( $comment_id, $wpdb->blogid );
629
-
630
  // Delete activity stream item
631
  bp_blogs_delete_activity( array( 'item_id' => $wpdb->blogid , 'secondary_item_id' => $comment_id, 'type' => 'new_blog_comment' ) );
632
 
@@ -662,8 +553,6 @@ function bp_blogs_remove_data_for_blog( $blog_id ) {
662
 
663
  /* If this is regular blog, delete all data for that blog. */
664
  BP_Blogs_Blog::delete_blog_for_all( $blog_id );
665
- BP_Blogs_Post::delete_posts_for_blog( $blog_id );
666
- BP_Blogs_Comment::delete_comments_for_blog( $blog_id );
667
 
668
  // Delete activity stream item
669
  bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->slug, 'type' => false ) );
@@ -676,25 +565,6 @@ function bp_blogs_get_blogs_for_user( $user_id, $show_hidden = false ) {
676
  return BP_Blogs_Blog::get_blogs_for_user( $user_id, $show_hidden );
677
  }
678
 
679
- /* DEPRECATED - scheduled for removal. Please use the activity stream with a 'new_blog_post' filter. */
680
- function bp_blogs_get_posts_for_user( $user_id ) {
681
- return BP_Blogs_Post::get_posts_for_user( $user_id );
682
- }
683
-
684
- /* DEPRECATED - scheduled for removal. Please use the activity stream with a 'new_blog_comment' filter. */
685
- function bp_blogs_get_comments_for_user( $user_id ) {
686
- return BP_Blogs_Comment::get_comments_for_user( $user_id );
687
- }
688
-
689
- function bp_blogs_get_latest_posts( $blog_id = null, $limit = 5 ) {
690
- global $bp;
691
-
692
- if ( !is_numeric( $limit ) )
693
- $limit = 5;
694
-
695
- return BP_Blogs_Post::get_latest_posts( $blog_id, $limit );
696
- }
697
-
698
  function bp_blogs_get_all_blogs( $limit = null, $page = null ) {
699
  return BP_Blogs_Blog::get_all( $limit, $page );
700
  }
@@ -703,18 +573,6 @@ function bp_blogs_get_random_blogs( $limit = null, $page = null ) {
703
  return BP_Blogs_Blog::get( 'random', $limit, $page );
704
  }
705
 
706
- function bp_blogs_get_all_posts( $limit = null, $page = null ) {
707
- return BP_Blogs_Post::get_all( $limit, $page );
708
- }
709
-
710
- function bp_blogs_total_post_count( $blog_id ) {
711
- return BP_Blogs_Post::total_post_count( $blog_id );
712
- }
713
-
714
- function bp_blogs_total_comment_count( $blog_id, $post_id = false ) {
715
- return BP_Blogs_Post::total_comment_count( $blog_id, $post_id );
716
- }
717
-
718
  function bp_blogs_is_blog_hidden( $blog_id ) {
719
  return BP_Blogs_Blog::is_hidden( $blog_id );
720
  }
@@ -831,10 +689,11 @@ function bp_blogs_update_blogmeta( $blog_id, $meta_key, $meta_value ) {
831
  }
832
 
833
  function bp_blogs_remove_data( $user_id ) {
 
 
 
834
  /* If this is regular blog, delete all data for that blog. */
835
  BP_Blogs_Blog::delete_blogs_for_user( $user_id );
836
- BP_Blogs_Post::delete_posts_for_user( $user_id );
837
- BP_Blogs_Comment::delete_comments_for_user( $user_id );
838
 
839
  do_action( 'bp_blogs_remove_data', $user_id );
840
  }
@@ -866,36 +725,9 @@ function bp_blogs_format_clear_blog_cache( $recorded_blog_obj ) {
866
  wp_cache_delete( 'bp_total_blogs', 'bp' );
867
  }
868
 
869
- function bp_blogs_clear_post_object_cache( $blog_id, $post_id, $user_id ) {
870
- wp_cache_delete( 'bp_user_posts_' . $user_id, 'bp' );
871
- }
872
-
873
- function bp_blogs_format_clear_post_cache( $recorded_post_obj ) {
874
- bp_blogs_clear_post_object_cache( false, false, $recorded_post_obj->user_id );
875
-
876
- /* Clear the sitewide activity cache */
877
- wp_cache_delete( 'sitewide_activity', 'bp' );
878
- }
879
-
880
- function bp_blogs_clear_comment_object_cache( $blog_id, $comment_id, $user_id ) {
881
- wp_cache_delete( 'bp_user_comments_' . $user_id, 'bp' );
882
- }
883
-
884
- function bp_blogs_format_clear_comment_cache( $recorded_comment_obj ) {
885
- bp_blogs_clear_comment_object_cache( false, false, $recorded_comment_obj->user_id );
886
-
887
- /* Clear the sitewide activity cache */
888
- wp_cache_delete( 'sitewide_activity', 'bp' );
889
- }
890
-
891
  // List actions to clear object caches on
892
  add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 );
893
- add_action( 'bp_blogs_remove_post', 'bp_blogs_clear_post_object_cache', 10, 3 );
894
- add_action( 'bp_blogs_remove_comment', 'bp_blogs_clear_comment_object_cache', 10, 3 );
895
-
896
  add_action( 'bp_blogs_new_blog', 'bp_blogs_format_clear_blog_cache', 10, 2 );
897
- add_action( 'bp_blogs_new_blog_post', 'bp_blogs_format_clear_post_cache', 10, 2 );
898
- add_action( 'bp_blogs_new_blog_comment', 'bp_blogs_format_clear_comment_cache', 10, 2 );
899
 
900
  // List actions to clear super cached pages on, if super cache is installed
901
  add_action( 'bp_blogs_remove_data_for_blog', 'bp_core_clear_cache' );
27
  KEY blog_id (blog_id)
28
  ) {$charset_collate};";
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  $sql[] = "CREATE TABLE {$bp->blogs->table_name_blogmeta} (
31
  id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
32
  blog_id bigint(20) NOT NULL,
69
  $bp->blogs->id = 'blogs';
70
 
71
  $bp->blogs->table_name = $wpdb->base_prefix . 'bp_user_blogs';
 
 
72
  $bp->blogs->table_name_blogmeta = $wpdb->base_prefix . 'bp_user_blogs_blogmeta';
73
  $bp->blogs->format_notification_function = 'bp_blogs_format_notifications';
74
  $bp->blogs->slug = BP_BLOGS_SLUG;
156
  bp_core_load_template( apply_filters( 'bp_blogs_template_my_blogs', 'members/single/home' ) );
157
  }
158
 
 
 
 
 
 
 
 
 
 
 
159
  function bp_blogs_screen_create_a_blog() {
160
  global $bp;
161
 
294
  return apply_filters( 'bp_blogs_get_blogs', BP_Blogs_Blog::get( $type, $per_page, $page, $user_id, $search_terms ), &$params );
295
  }
296
 
 
297
  function bp_blogs_record_existing_blogs() {
298
  global $bp, $wpdb;
299
 
365
  if ( !$user_id )
366
  $user_id = (int)$post->post_author;
367
 
368
+ /* This is to stop infinite loops with Donncha's sitewide tags plugin */
369
  if ( (int)$bp->site_options['tags_blog_id'] == (int)$blog_id )
370
  return false;
371
 
373
  if ( $post->post_type != 'post' )
374
  return false;
375
 
376
+ if ( 'publish' == $post->post_status && '' == $post->post_password ) {
377
+ bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
378
 
379
  if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
380
+ /* Record this in activity streams */
381
  $post_permalink = get_permalink( $post_id );
382
 
383
  $activity_action = sprintf( __( '%s wrote a new blog post: %s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
392
  'item_id' => $blog_id,
393
  'secondary_item_id' => $post_id,
394
  'recorded_time' => $post->post_date_gmt
395
+ ));
396
  }
397
+ } else
398
+ bp_blogs_remove_post( $post_id, $blog_id );
399
 
400
+ do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id );
401
  }
402
  add_action( 'save_post', 'bp_blogs_record_post', 10, 2 );
403
 
404
+ function bp_blogs_record_comment( $comment_id, $is_approved = true ) {
405
  global $wpdb, $bp;
406
 
 
 
 
407
  $comment = get_comment($comment_id);
408
  $comment->post = get_post( $comment->comment_post_ID );
409
 
418
  if ( !empty( $post->post_password ) )
419
  return false;
420
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
421
  if ( (int)get_blog_option( $recorded_comment->blog_id, 'blog_public' ) || !bp_core_is_multisite() ) {
422
  /* Record in activity streams */
423
  $comment_link = get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment_id;
440
  return $recorded_comment;
441
  }
442
  add_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
443
+ add_action( 'edit_comment', 'bp_blogs_record_comment', 10 );
444
 
445
  function bp_blogs_manage_comment( $comment_id, $comment_status ) {
446
  if ( 'spam' == $comment_status || 'hold' == $comment_status || 'delete' == $comment_status || 'trash' == $comment_status )
500
  }
501
  add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 );
502
 
503
+ function bp_blogs_remove_post( $post_id, $blog_id = false ) {
504
  global $current_blog, $bp;
505
 
506
  $post_id = (int)$post_id;
508
  if ( !$blog_id )
509
  $blog_id = (int)$current_blog->blog_id;
510
 
 
 
 
 
 
 
511
  // Delete activity stream item
512
  bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog_post' ) );
513
 
518
  function bp_blogs_remove_comment( $comment_id ) {
519
  global $wpdb, $bp;
520
 
 
 
 
521
  // Delete activity stream item
522
  bp_blogs_delete_activity( array( 'item_id' => $wpdb->blogid , 'secondary_item_id' => $comment_id, 'type' => 'new_blog_comment' ) );
523
 
553
 
554
  /* If this is regular blog, delete all data for that blog. */
555
  BP_Blogs_Blog::delete_blog_for_all( $blog_id );
 
 
556
 
557
  // Delete activity stream item
558
  bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'component' => $bp->blogs->slug, 'type' => false ) );
565
  return BP_Blogs_Blog::get_blogs_for_user( $user_id, $show_hidden );
566
  }
567
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
568
  function bp_blogs_get_all_blogs( $limit = null, $page = null ) {
569
  return BP_Blogs_Blog::get_all( $limit, $page );
570
  }
573
  return BP_Blogs_Blog::get( 'random', $limit, $page );
574
  }
575
 
 
 
 
 
 
 
 
 
 
 
 
 
576
  function bp_blogs_is_blog_hidden( $blog_id ) {
577
  return BP_Blogs_Blog::is_hidden( $blog_id );
578
  }
689
  }
690
 
691
  function bp_blogs_remove_data( $user_id ) {
692
+ if ( !bp_core_is_multisite() )
693
+ return false;
694
+
695
  /* If this is regular blog, delete all data for that blog. */
696
  BP_Blogs_Blog::delete_blogs_for_user( $user_id );
 
 
697
 
698
  do_action( 'bp_blogs_remove_data', $user_id );
699
  }
725
  wp_cache_delete( 'bp_total_blogs', 'bp' );
726
  }
727
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
728
  // List actions to clear object caches on
729
  add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 );
 
 
 
730
  add_action( 'bp_blogs_new_blog', 'bp_blogs_format_clear_blog_cache', 10, 2 );
 
 
731
 
732
  // List actions to clear super cached pages on, if super cache is installed
733
  add_action( 'bp_blogs_remove_data_for_blog', 'bp_core_clear_cache' );
bp-blogs/bp-blogs-classes.php CHANGED
@@ -278,16 +278,8 @@ Class BP_Blogs_Blog {
278
  if ( empty( $blog_ids ) )
279
  return $paged_blogs;
280
 
281
- /* Fetch lastest post for each blog. */
282
- $post_ids = $wpdb->get_results( $wpdb->prepare( "SELECT p.post_id, p.blog_id FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.blog_id IN ( {$blog_ids} ) GROUP BY p.blog_id ORDER BY p.date_created DESC" ) );
283
-
284
- for ( $i = 0; $i < count( $paged_blogs ); $i++ ) {
285
- foreach ( (array)$post_ids as $post ) {
286
- if ( $post->blog_id == $paged_blogs[$i]->blog_id ) {
287
- $paged_blogs[$i]->latest_post = $wpdb->get_row( "SELECT post_title, guid FROM {$wpdb->base_prefix}" . $post->blog_id . "_posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY id DESC LIMIT 1" );
288
- }
289
- }
290
- }
291
 
292
  /* Fetch the blog description for each blog (as it may be empty we can't fetch it in the main query). */
293
  $blog_descs = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, meta_value as description FROM {$bp->blogs->table_name_blogmeta} WHERE meta_key = 'description' AND blog_id IN ( {$blog_ids} )" ) );
@@ -315,398 +307,4 @@ Class BP_Blogs_Blog {
315
  }
316
  }
317
 
318
- /* DEPRECATED - Post DB recording is scheduled for removal. Please use the activity stream to fetch a user's posts. */
319
- Class BP_Blogs_Post {
320
- var $id;
321
- var $user_id;
322
- var $blog_id;
323
- var $post_id;
324
- var $date_created;
325
-
326
- function bp_blogs_post( $id = null, $blog_id = null, $post_id = null ) {
327
- global $bp, $wpdb;
328
-
329
- if ( $id || ( !$id && $blog_id && $post_id ) ) {
330
- $this->id = $id;
331
- $this->blog_id = $blog_id;
332
- $this->post_id = $post_id;
333
- $this->populate();
334
- }
335
- }
336
-
337
- function populate() {
338
- global $wpdb, $bp;
339
-
340
- if ( $this->id )
341
- $post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name_blog_posts} WHERE id = %d", $this->id ) );
342
- else
343
- $post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name_blog_posts} WHERE blog_id = %d AND post_id = %d", $this->blog_id, $this->post_id ) );
344
-
345
- $this->id = $post->id;
346
- $this->user_id = $post->user_id;
347
- $this->blog_id = $post->blog_id;
348
- $this->post_id = $post->post_id;
349
- $this->date_created = $post->date_created;
350
- }
351
-
352
- function save() {
353
- global $wpdb, $bp;
354
-
355
- $this->post_id = apply_filters( 'bp_blogs_post_id_before_save', $this->post_id, $this->id );
356
- $this->blog_id = apply_filters( 'bp_blogs_post_blog_id_before_save', $this->blog_id, $this->id );
357
- $this->user_id = apply_filters( 'bp_blogs_post_user_id_before_save', $this->user_id, $this->id );
358
- $this->date_created = apply_filters( 'bp_blogs_post_date_created_before_save', $this->date_created, $this->id );
359
-
360
- do_action( 'bp_blogs_post_before_save', $this );
361
-
362
- if ( $this->id ) {
363
- // Update
364
- $sql = $wpdb->prepare( "UPDATE {$bp->blogs->table_name_blog_posts} SET post_id = %d, blog_id = %d, user_id = %d, date_created = FROM_UNIXTIME(%d) WHERE id = %d", $this->post_id, $this->blog_id, $this->user_id, $this->date_created, $this->id );
365
- } else {
366
- // Save
367
- $sql = $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name_blog_posts} ( post_id, blog_id, user_id, date_created ) VALUES ( %d, %d, %d, FROM_UNIXTIME(%d) )", $this->post_id, $this->blog_id, $this->user_id, $this->date_created );
368
- }
369
-
370
- if ( !$wpdb->query($sql) )
371
- return false;
372
-
373
- do_action( 'bp_blogs_post_after_save', $this );
374
-
375
- if ( $this->id )
376
- return $this->id;
377
- else
378
- return $wpdb->insert_id;
379
- }
380
-
381
- /* Static Functions */
382
-
383
- function delete( $post_id, $blog_id ) {
384
- global $wpdb, $bp, $current_user;
385
-
386
- if ( !$bp->blogs )
387
- bp_blogs_setup_globals();
388
-
389
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_posts} WHERE blog_id = %d AND post_id = %d", $blog_id, $post_id ) );
390
- }
391
-
392
- function delete_oldest( $user_id = null ) {
393
- global $wpdb, $bp;
394
-
395
- if ( !$bp->blogs )
396
- bp_blogs_setup_globals();
397
-
398
- if ( !$user_id )
399
- $user_id = $current_user->ID;
400
-
401
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_posts} WHERE user_id = %d ORDER BY date_created ASC LIMIT 1", $user_id ) );
402
- }
403
-
404
- function delete_posts_for_user( $user_id = null ) {
405
- global $wpdb, $bp;
406
-
407
- if ( !$bp->blogs )
408
- bp_blogs_setup_globals();
409
-
410
- if ( !$user_id )
411
- $user_id = $bp->loggedin_user->id;
412
-
413
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_posts} WHERE user_id = %d", $user_id ) );
414
- }
415
-
416
- function delete_posts_for_blog( $blog_id ) {
417
- global $wpdb, $bp;
418
-
419
- if ( !$bp->blogs )
420
- bp_blogs_setup_globals();
421
-
422
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_posts} WHERE blog_id = %d", $blog_id ) );
423
- }
424
-
425
- function get_latest_posts( $blog_id = null, $limit = 5 ) {
426
- global $wpdb, $bp;
427
-
428
- if ( !$bp->blogs )
429
- bp_blogs_setup_globals();
430
-
431
- if ( $blog_id )
432
- $blog_sql = $wpdb->prepare( " AND p.blog_id = %d", $blog_id );
433
-
434
- $post_ids = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT p.post_id, p.blog_id FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.public = 1 AND b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 $blog_sql ORDER BY p.date_created DESC LIMIT $limit" ) );
435
-
436
- for ( $i = 0; $i < count($post_ids); $i++ ) {
437
- $posts[$i] = BP_Blogs_Post::fetch_post_content($post_ids[$i]);
438
- }
439
-
440
- return $posts;
441
- }
442
-
443
- function get_posts_for_user( $user_id = null ) {
444
- global $bp, $wpdb;
445
-
446
- if ( !$bp->blogs )
447
- bp_blogs_setup_globals();
448
-
449
- if ( !$user_id )
450
- $user_id = $bp->displayed_user->id;
451
-
452
- // Show a logged in user their posts on private blogs, but not anyone else.
453
- if ( !bp_is_my_profile() ) {
454
- $post_ids = $wpdb->get_results( $wpdb->prepare( "SELECT p.post_id, p.blog_id FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.public = 1 AND b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.user_id = %d ORDER BY p.date_created DESC", $user_id) );
455
- $total_post_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(p.post_id) FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.public = 1 AND b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.user_id = %d", $user_id) );
456
- } else {
457
- $post_ids = $wpdb->get_results( $wpdb->prepare( "SELECT p.post_id, p.blog_id FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.user_id = %d ORDER BY p.date_created DESC", $user_id) );
458
-
459
- $total_post_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(p.post_id) FROM {$bp->blogs->table_name_blog_posts} p LEFT JOIN {$wpdb->base_prefix}blogs b ON p.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND p.user_id = %d", $user_id) );
460
- }
461
-
462
- for ( $i = 0; $i < count($post_ids); $i++ ) {
463
- $posts[$i] = BP_Blogs_Post::fetch_post_content($post_ids[$i]);
464
- }
465
-
466
- return array( 'posts' => $posts, 'count' => $total_post_count );
467
- }
468
-
469
- function fetch_post_content( $post_object ) {
470
- // TODO: switch_to_blog() calls are expensive and this needs to be changed.
471
- switch_to_blog( $post_object->blog_id );
472
- $post = get_post($post_object->post_id);
473
- $post->blog_id = $post_object->blog_id;
474
- restore_current_blog();
475
-
476
- return $post;
477
- }
478
-
479
- function get_total_recorded_for_user( $user_id = null ) {
480
- global $bp, $wpdb;
481
-
482
- if ( !$bp->blogs )
483
- bp_blogs_setup_globals();
484
-
485
- if ( !$user_id )
486
- $user_id = $current_user->ID;
487
-
488
- return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(post_id) FROM {$bp->blogs->table_name_blog_posts} WHERE user_id = %d", $user_id ) );
489
- }
490
-
491
- function is_recorded( $post_id, $blog_id, $user_id = null ) {
492
- global $bp, $wpdb, $current_user;
493
-
494
- if ( !$bp->blogs )
495
- bp_blogs_setup_globals();
496
-
497
- if ( !$user_id )
498
- $user_id = $current_user->ID;
499
-
500
- return $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$bp->blogs->table_name_blog_posts} WHERE post_id = %d AND blog_id = %d AND user_id = %d", $post_id, $blog_id, $user_id ) );
501
- }
502
-
503
- function total_post_count( $blog_id ) {
504
- global $bp, $wpdb;
505
-
506
- if ( !$bp->blogs )
507
- bp_blogs_setup_globals();
508
-
509
- if ( !$blog_id )
510
- return false;
511
-
512
- return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(post_id) FROM {$bp->blogs->table_name_blog_posts} WHERE blog_id = %d", $blog_id ) );
513
- }
514
-
515
- function get_all() {
516
- global $bp, $wpdb;
517
-
518
- if ( !$bp->blogs )
519
- bp_blogs_setup_globals();
520
-
521
- return $wpdb->get_col( $wpdb->prepare( "SELECT post_id, blog_id FROM " . $bp->blogs->table_name_blog_posts ) );
522
- }
523
-
524
- }
525
-
526
- /* DEPRECATED - Comment DB recording is scheduled for removal. Please use the activity stream to fetch a user's comments. */
527
- Class BP_Blogs_Comment {
528
- var $id;
529
- var $user_id;
530
- var $blog_id;
531
- var $comment_id;
532
- var $comment_post_id;
533
- var $date_created;
534
-
535
- function bp_blogs_comment( $id = false, $blog_id = false, $comment_id = false ) {
536
- global $bp, $wpdb;
537
-
538
- if ( !$user_id )
539
- $user_id = $bp->displayed_user->id;
540
-
541
- if ( $id || ( !$id && $blog_id && $comment_id ) ) {
542
- $this->id = $id;
543
- $this->blog_id = $blog_id;
544
- $this->comment_id = $comment_id;
545
- $this->populate();
546
- }
547
- }
548
-
549
- function populate() {
550
- global $wpdb, $bp;
551
-
552
- if ( $this->id )
553
- $comment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name_blog_comments} WHERE id = %d", $this->id ) );
554
- else
555
- $comment = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->blogs->table_name_blog_comments} WHERE blog_id = %d AND comment_id = %d", (int)$this->blog_id, (int)$this->comment_id ) );
556
-
557
- $this->comment_id = $comment->comment_id;
558
- $this->user_id = $comment->user_id;
559
- $this->blog_id = $comment->blog_id;
560
- $this->comment_post_id = $comment->comment_post_id;
561
- $this->date_created = $comment->date_created;
562
- }
563
-
564
- function save() {
565
- global $wpdb, $bp;
566
-
567
- $this->comment_id = apply_filters( 'bp_blogs_comment_id_before_save', $this->comment_id, $this->id );
568
- $this->comment_post_id = apply_filters( 'bp_blogs_comment_post_id_before_save', $this->comment_post_id, $this->id );
569
- $this->blog_id = apply_filters( 'bp_blogs_comment_blog_id_before_save', $this->blog_id, $this->id );
570
- $this->user_id = apply_filters( 'bp_blogs_comment_user_id_before_save', $this->user_id, $this->id );
571
- $this->date_created = apply_filters( 'bp_blogs_comment_date_created_before_save', $this->date_created, $this->id );
572
-
573
- do_action( 'bp_blogs_comment_before_save', $this );
574
-
575
- if ( $this->id ) {
576
- // Update
577
- $sql = $wpdb->prepare( "UPDATE {$bp->blogs->table_name_blog_comments} SET comment_id = %d, comment_post_id = %d, blog_id = %d, user_id = %d, date_created = FROM_UNIXTIME(%d) WHERE id = %d", $this->comment_id, $this->comment_post_id, $this->blog_id, $this->user_id, $this->date_created, $this->id );
578
- } else {
579
- // Save
580
- $sql = $wpdb->prepare( "INSERT INTO {$bp->blogs->table_name_blog_comments} ( comment_id, comment_post_id, blog_id, user_id, date_created ) VALUES ( %d, %d, %d, %d, FROM_UNIXTIME(%d) )", $this->comment_id, $this->comment_post_id, $this->blog_id, $this->user_id, $this->date_created );
581
- }
582
-
583
- if ( !$wpdb->query($sql) )
584
- return false;
585
-
586
- do_action( 'bp_blogs_comment_after_save', $this );
587
-
588
- if ( $this->id )
589
- return $this->id;
590
- else
591
- return $wpdb->insert_id;
592
- }
593
-
594
- /* Static Functions */
595
-
596
- function delete( $comment_id, $blog_id ) {
597
- global $wpdb, $bp, $current_user;
598
-
599
- if ( !$bp->blogs )
600
- bp_blogs_setup_globals();
601
-
602
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_comments} WHERE comment_id = %d AND blog_id = %d", $comment_id, $blog_id ) );
603
- }
604
-
605
- function delete_oldest( $user_id = null ) {
606
- global $wpdb, $bp, $current_user;
607
-
608
- if ( !$bp->blogs )
609
- bp_blogs_setup_globals();
610
-
611
- if ( !$user_id )
612
- $user_id = $current_user->ID;
613
-
614
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_comments} WHERE user_id = %d ORDER BY date_created ASC LIMIT 1", $user_id ) );
615
- }
616
-
617
- function delete_comments_for_user( $user_id = null ) {
618
- global $wpdb, $bp;
619
-
620
- if ( !$bp->blogs )
621
- bp_blogs_setup_globals();
622
-
623
- if ( !$user_id )
624
- $user_id = $bp->loggedin_user->id;
625
-
626
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_comments} WHERE user_id = %d", $user_id ) );
627
- }
628
-
629
- function delete_comments_for_blog( $blog_id ) {
630
- global $wpdb, $bp;
631
-
632
- if ( !$bp->blogs )
633
- bp_blogs_setup_globals();
634
-
635
- return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->blogs->table_name_blog_comments} WHERE blog_id = %d", $blog_id ) );
636
- }
637
-
638
- function get_comments_for_user( $user_id = null ) {
639
- global $bp, $wpdb;
640
-
641
- if ( !$bp->blogs )
642
- bp_blogs_setup_globals();
643
-
644
- if ( !$user_id )
645
- $user_id = $bp->displayed_user->id;
646
-
647
- // Show the logged in user their comments on hidden blogs, but not to anyone else.
648
- if ( !bp_is_my_profile() ) {
649
- $comment_ids = $wpdb->get_results( $wpdb->prepare( "SELECT c.comment_id, c.blog_id FROM {$bp->blogs->table_name_blog_comments} c LEFT JOIN {$wpdb->base_prefix}blogs b ON c.blog_id = b.blog_id WHERE b.public = 1 AND b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND c.user_id = %d ORDER BY c.date_created ASC", $user_id) );
650
- $total_comment_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(c.comment_id) FROM {$bp->blogs->table_name_blog_comments} c LEFT JOIN {$wpdb->base_prefix}blogs b ON c.blog_id = b.blog_id WHERE b.public = 1 AND b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND c.user_id = %d", $user_id) );
651
- } else {
652
- $comment_ids = $wpdb->get_results( $wpdb->prepare( "SELECT c.comment_id, c.blog_id FROM {$bp->blogs->table_name_blog_comments} c LEFT JOIN {$wpdb->base_prefix}blogs b ON c.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND c.user_id = %d ORDER BY c.date_created ASC", $user_id) );
653
-
654
- $total_comment_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(c.comment_id) FROM {$bp->blogs->table_name_blog_comments} c LEFT JOIN {$wpdb->base_prefix}blogs b ON c.blog_id = b.blog_id WHERE b.deleted = 0 AND b.archived = '0' AND b.spam = 0 AND b.mature = 0 AND c.user_id = %d", $user_id) );
655
- }
656
-
657
- for ( $i = 0; $i < count($comment_ids); $i++ )
658
- $comments[$i] = BP_Blogs_Comment::fetch_comment_content($comment_ids[$i]);
659
-
660
- return array( 'comments' => $comments, 'count' => $total_comment_count );
661
- }
662
-
663
- function fetch_comment_content( $comment_object ) {
664
- switch_to_blog($comment_object->blog_id);
665
- $comment = get_comment($comment_object->comment_id);
666
- $comment->blog_id = $comment_object->blog_id;
667
- $comment->post = &get_post( $comment->comment_post_ID );
668
- restore_current_blog();
669
-
670
- return $comment;
671
- }
672
-
673
- function get_total_recorded_for_user( $user_id = null ) {
674
- global $bp, $wpdb, $current_user;
675
-
676
- if ( !$bp->blogs )
677
- bp_blogs_setup_globals();
678
-
679
- if ( !$user_id )
680
- $user_id = $current_user->ID;
681
-
682
- return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_id) FROM {$bp->blogs->table_name_blog_comments} WHERE user_id = %d", $user_id ) );
683
- }
684
-
685
- function total_comment_count( $blog_id, $post_id ) {
686
- global $bp, $wpdb;
687
-
688
- if ( !$bp->blogs )
689
- bp_blogs_setup_globals();
690
-
691
- if ( $post_id )
692
- $post_sql = $wpdb->prepare( " AND comment_post_id = %d", $post_id );
693
-
694
- return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_id) WHERE blog_id = %d{$post_sql}", $blog_id ) );
695
- }
696
-
697
-
698
- function is_recorded( $comment_id, $comment_post_id, $blog_id, $user_id = null ) {
699
- global $bp, $wpdb, $current_user;
700
-
701
- if ( !$bp->blogs )
702
- bp_blogs_setup_globals();
703
-
704
- if ( !$user_id )
705
- $user_id = $current_user->ID;
706
-
707
- return $wpdb->get_var( $wpdb->prepare( "SELECT comment_id FROM {$bp->blogs->table_name_blog_comments} WHERE comment_id = %d AND blog_id = %d AND comment_post_id = %d AND user_id = %d", $comment_id, $blog_id, $comment_post_id, $user_id ) );
708
- }
709
-
710
- }
711
-
712
  ?>
278
  if ( empty( $blog_ids ) )
279
  return $paged_blogs;
280
 
281
+ for ( $i = 0; $i < count( $paged_blogs ); $i++ )
282
+ $paged_blogs[$i]->latest_post = $wpdb->get_row( "SELECT post_title, guid FROM {$wpdb->base_prefix}" . $paged_blogs[$i]->blog_id . "_posts WHERE post_status = 'publish' AND post_type = 'post' AND id != 1 ORDER BY id DESC LIMIT 1" );
 
 
 
 
 
 
 
 
283
 
284
  /* Fetch the blog description for each blog (as it may be empty we can't fetch it in the main query). */
285
  $blog_descs = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id, meta_value as description FROM {$bp->blogs->table_name_blogmeta} WHERE meta_key = 'description' AND blog_id IN ( {$blog_ids} )" ) );
307
  }
308
  }
309
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
310
  ?>
bp-blogs/bp-blogs-templatetags.php CHANGED
@@ -144,7 +144,7 @@ function bp_has_blogs( $args = '' ) {
144
  }
145
 
146
  $blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms );
147
- return $blogs_template->has_blogs();
148
  }
149
 
150
  function bp_blogs() {
@@ -467,7 +467,7 @@ function bp_create_blog_link() {
467
  global $bp;
468
 
469
  if ( bp_is_my_profile() ) {
470
- echo apply_filters( 'bp_create_blog_link', '<a href="' . $bp->loggedin_user->domain . $bp->blogs->slug . '/create-a-blog">' . __('Create a Blog', 'buddypress') . '</a>' );
471
  }
472
  }
473
 
144
  }
145
 
146
  $blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms );
147
+ return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), &$blogs_template );
148
  }
149
 
150
  function bp_blogs() {
467
  global $bp;
468
 
469
  if ( bp_is_my_profile() ) {
470
+ echo apply_filters( 'bp_create_blog_link', '<a href="' . $bp->root_domain . '/' . $bp->blogs->slug . '/create">' . __('Create a Blog', 'buddypress') . '</a>' );
471
  }
472
  }
473
 
bp-core.php CHANGED
@@ -32,6 +32,7 @@ if ( !defined( 'CUSTOM_USER_META_TABLE' ) )
32
  /* Load the files containing functions that we globally will need. */
33
  require ( BP_PLUGIN_DIR . '/bp-core/bp-core-catchuri.php' );
34
  require ( BP_PLUGIN_DIR . '/bp-core/bp-core-classes.php' );
 
35
  require ( BP_PLUGIN_DIR . '/bp-core/bp-core-cssjs.php' );
36
  require ( BP_PLUGIN_DIR . '/bp-core/bp-core-avatars.php' );
37
  require ( BP_PLUGIN_DIR . '/bp-core/bp-core-templatetags.php' );
@@ -40,10 +41,6 @@ require ( BP_PLUGIN_DIR . '/bp-core/bp-core-widgets.php' );
40
  require ( BP_PLUGIN_DIR . '/bp-core/bp-core-notifications.php' );
41
  require ( BP_PLUGIN_DIR . '/bp-core/bp-core-signup.php' );
42
 
43
- /* Multisite includes built in account activation support. */
44
- if ( bp_core_is_multisite() )
45
- require ( BP_PLUGIN_DIR . '/bp-core/bp-core-activation.php' );
46
-
47
  /* If BP_DISABLE_ADMIN_BAR is defined, do not load the global admin bar. */
48
  if ( !defined( 'BP_DISABLE_ADMIN_BAR' ) )
49
  require ( BP_PLUGIN_DIR . '/bp-core/bp-core-adminbar.php' );
@@ -1664,37 +1661,6 @@ function bp_core_add_illegal_names() {
1664
  update_site_option( 'illegal_names', $new );
1665
  }
1666
 
1667
- /**
1668
- * bp_core_email_from_name_filter()
1669
- *
1670
- * Sets the "From" name in emails sent to the name of the site and not "WordPress"
1671
- *
1672
- * @package BuddyPress Core
1673
- * @uses get_blog_option() fetches the value for a meta_key in the wp_X_options table
1674
- * @return The blog name for the root blog
1675
- */
1676
- function bp_core_email_from_name_filter() {
1677
- return apply_filters( 'bp_core_email_from_name_filter', get_blog_option( BP_ROOT_BLOG, 'blogname' ) );
1678
- }
1679
- add_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
1680
-
1681
-
1682
- /**
1683
- * bp_core_email_from_name_filter()
1684
- *
1685
- * Sets the "From" address in emails sent
1686
- *
1687
- * @package BuddyPress Core
1688
- * @global $current_site Object containing current site metadata
1689
- * @return noreply@sitedomain email address
1690
- */
1691
- function bp_core_email_from_address_filter() {
1692
- $domain = (array) explode( '/', site_url() );
1693
-
1694
- return apply_filters( 'bp_core_email_from_address_filter', __( 'noreply', 'buddypress' ) . '@' . $domain[2] );
1695
- }
1696
- add_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );
1697
-
1698
  /**
1699
  * bp_core_delete_account()
1700
  *
@@ -1970,48 +1936,6 @@ function bp_core_update_message() {
1970
  }
1971
  add_action( 'in_plugin_update_message-buddypress/bp-loader.php', 'bp_core_update_message' );
1972
 
1973
- /**
1974
- * bp_core_filter_parent_theme()
1975
- *
1976
- * Remove social network parent theme from the theme list.
1977
- *
1978
- * @package BuddyPress Core
1979
- */
1980
- function bp_core_filter_parent_theme() {
1981
- global $wp_themes, $pagenow;
1982
-
1983
- if ( is_admin() && 'themes.php' == $pagenow )
1984
- $wp_themes = get_themes();
1985
-
1986
- unset( $wp_themes['BuddyPress Classic Parent'] );
1987
- }
1988
- add_filter( 'admin_menu', 'bp_core_filter_parent_theme' );
1989
-
1990
- /**
1991
- * bp_core_allow_default_theme()
1992
- *
1993
- * On multiblog installations you must first allow themes to be activated and show
1994
- * up on the theme selection screen. This function will let the BuddyPress bundled
1995
- * themes show up on the root blog selection screen and bypass this step. It also
1996
- * means that the themes won't show for selection on other blogs.
1997
- *
1998
- * @package BuddyPress Core
1999
- */
2000
- function bp_core_allow_default_theme( $themes ) {
2001
- global $bp, $current_blog;
2002
-
2003
- if ( !is_site_admin() )
2004
- return $themes;
2005
-
2006
- if ( $current_blog->ID == $bp->root_blog ) {
2007
- $themes['bp-default'] = 1;
2008
- $themes['bp-classic'] = 1;
2009
- }
2010
-
2011
- return $themes;
2012
- }
2013
- add_filter( 'allowed_themes', 'bp_core_allow_default_theme' );
2014
-
2015
  /**
2016
  * bp_core_activation_notice()
2017
  *
@@ -2053,67 +1977,6 @@ function bp_core_activation_notice() {
2053
  }
2054
  add_action( 'admin_notices', 'bp_core_activation_notice' );
2055
 
2056
- /**
2057
- * bp_core_filter_comments()
2058
- *
2059
- * Filter the blog post comments array and insert BuddyPress URLs for users.
2060
- *
2061
- * @package BuddyPress Core
2062
- */
2063
- function bp_core_filter_comments( $comments, $post_id ) {
2064
- global $wpdb;
2065
-
2066
- foreach( (array)$comments as $comment ) {
2067
- if ( $comment->user_id )
2068
- $user_ids[] = $comment->user_id;
2069
- }
2070
-
2071
- if ( empty( $user_ids ) )
2072
- return $comments;
2073
-
2074
- $user_ids = implode( ',', $user_ids );
2075
-
2076
- if ( !$userdata = $wpdb->get_results( $wpdb->prepare( "SELECT ID as user_id, user_login, user_nicename FROM {$wpdb->users} WHERE ID IN ({$user_ids})" ) ) )
2077
- return $comments;
2078
-
2079
- foreach( (array)$userdata as $user )
2080
- $users[$user->user_id] = bp_core_get_user_domain( $user->user_id, $user->user_nicename, $user->user_login );
2081
-
2082
- foreach( (array)$comments as $i => $comment ) {
2083
- if ( !empty( $comment->user_id ) ) {
2084
- if ( !empty( $users[$comment->user_id] ) )
2085
- $comments[$i]->comment_author_url = $users[$comment->user_id];
2086
- }
2087
- }
2088
-
2089
- return $comments;
2090
- }
2091
- add_filter( 'comments_array', 'bp_core_filter_comments', 10, 2 );
2092
-
2093
- /**
2094
- * bp_core_login_redirect()
2095
- *
2096
- * When a user logs in, always redirect them back to the previous page. NOT the admin area.
2097
- *
2098
- * @package BuddyPress Core
2099
- */
2100
- function bp_core_login_redirect( $redirect_to ) {
2101
- global $bp, $current_blog;
2102
-
2103
- if ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG )
2104
- return $redirect_to;
2105
-
2106
- if ( !empty( $_REQUEST['redirect_to'] ) && strpos( $_REQUEST['redirect_to'], 'wp-admin' ) )
2107
- return $redirect_to;
2108
-
2109
- if ( false === strpos( wp_get_referer(), 'wp-login.php' ) && false === strpos( wp_get_referer(), 'activate' ) && empty( $_REQUEST['nr'] ) )
2110
- return wp_get_referer();
2111
-
2112
- return $bp->root_domain;
2113
- }
2114
- add_filter( 'login_redirect', 'bp_core_login_redirect' );
2115
-
2116
-
2117
  /********************************************************************************
2118
  * Custom Actions
2119
  *
32
  /* Load the files containing functions that we globally will need. */
33
  require ( BP_PLUGIN_DIR . '/bp-core/bp-core-catchuri.php' );
34
  require ( BP_PLUGIN_DIR . '/bp-core/bp-core-classes.php' );
35
+ require ( BP_PLUGIN_DIR . '/bp-core/bp-core-filters.php' );
36
  require ( BP_PLUGIN_DIR . '/bp-core/bp-core-cssjs.php' );
37
  require ( BP_PLUGIN_DIR . '/bp-core/bp-core-avatars.php' );
38
  require ( BP_PLUGIN_DIR . '/bp-core/bp-core-templatetags.php' );
41
  require ( BP_PLUGIN_DIR . '/bp-core/bp-core-notifications.php' );
42
  require ( BP_PLUGIN_DIR . '/bp-core/bp-core-signup.php' );
43
 
 
 
 
 
44
  /* If BP_DISABLE_ADMIN_BAR is defined, do not load the global admin bar. */
45
  if ( !defined( 'BP_DISABLE_ADMIN_BAR' ) )
46
  require ( BP_PLUGIN_DIR . '/bp-core/bp-core-adminbar.php' );
1661
  update_site_option( 'illegal_names', $new );
1662
  }
1663
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1664
  /**
1665
  * bp_core_delete_account()
1666
  *
1936
  }
1937
  add_action( 'in_plugin_update_message-buddypress/bp-loader.php', 'bp_core_update_message' );
1938
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1939
  /**
1940
  * bp_core_activation_notice()
1941
  *
1977
  }
1978
  add_action( 'admin_notices', 'bp_core_activation_notice' );
1979
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1980
  /********************************************************************************
1981
  * Custom Actions
1982
  *
bp-core/bp-core-cssjs.php CHANGED
@@ -47,7 +47,7 @@ add_action( 'admin_head', 'bp_core_admin_menu_icon_css' );
47
  function bp_core_confirmation_js() {
48
  global $current_blog;
49
 
50
- if ( $current_blog->blog_id != BP_ROOT_BLOG )
51
  return false;
52
  ?>
53
  <script type="text/javascript"> jQuery(document).ready( function() { jQuery("a.confirm").click( function() { if ( confirm( '<?php _e( 'Are you sure?', 'buddypress' ) ?>' ) ) return true; else return false; }); });</script>
47
  function bp_core_confirmation_js() {
48
  global $current_blog;
49
 
50
+ if ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG )
51
  return false;
52
  ?>
53
  <script type="text/javascript"> jQuery(document).ready( function() { jQuery("a.confirm").click( function() { if ( confirm( '<?php _e( 'Are you sure?', 'buddypress' ) ?>' ) ) return true; else return false; }); });</script>
bp-core/{bp-core-activation.php → bp-core-filters.php} RENAMED
@@ -1,79 +1,118 @@
1
  <?php
2
 
3
- function bp_core_screen_activation() {
4
- global $bp, $wpdb;
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- if ( !bp_core_is_multisite() || BP_ACTIVATION_SLUG != $bp->current_component )
7
- return false;
 
 
 
 
 
 
 
 
 
8
 
9
- /* Check if an activation key has been passed */
10
- if ( isset( $_GET['key'] ) ) {
 
11
 
12
- require_once( ABSPATH . WPINC . '/registration.php' );
 
 
 
 
 
 
 
 
 
 
 
13
 
14
- /* Activate the signup */
15
- $signup = apply_filters( 'bp_core_activate_account', wpmu_activate_signup( $_GET['key'] ) );
16
 
17
- /* If there was errors, add a message and redirect */
18
- if ( $signup->errors ) {
19
- bp_core_add_message( __( 'There was an error activating your account, please try again.', 'buddypress' ), 'error' );
20
- bp_core_redirect( $bp->root_domain . '/' . BP_ACTIVATION_SLUG );
21
- }
22
 
23
- /* Set the password */
24
- if ( !empty( $signup['meta']['password'] ) )
25
- $wpdb->update( $wpdb->users, array( 'user_pass' => $signup['meta']['password'] ), array( 'ID' => $signup['user_id'] ), array( '%s' ), array( '%d' ) );
26
 
27
- /* Set any profile data */
28
- if ( function_exists( 'xprofile_set_field_data' ) ) {
 
 
 
 
 
 
 
29
 
30
- if ( !empty( $signup['meta']['profile_field_ids'] ) ) {
31
- $profile_field_ids = explode( ',', $signup['meta']['profile_field_ids'] );
 
 
32
 
33
- foreach( (array)$profile_field_ids as $field_id ) {
34
- $current_field = $signup['meta']["field_{$field_id}"];
35
 
36
- if ( !empty( $current_field ) )
37
- xprofile_set_field_data( $field_id, $signup['user_id'], $current_field );
38
- }
39
- }
40
 
41
- }
 
42
 
43
- /* Check for an uploaded avatar and move that to the correct user folder */
44
- $hashed_key = wp_hash( $_GET['key'] );
45
 
46
- /* Check if the avatar folder exists. If it does, move rename it, move it and delete the signup avatar dir */
47
- if ( file_exists( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key ) ) {
48
- @rename( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key, BP_AVATAR_UPLOAD_PATH . '/avatars/' . $signup['user_id'] );
 
49
  }
 
50
 
51
- /* Record the new user in the activity streams */
52
- if ( function_exists( 'bp_activity_add' ) ) {
53
- $userlink = bp_core_get_userlink( $signup['user_id'] );
54
 
55
- bp_activity_add( array(
56
- 'user_id' => $signup['user_id'],
57
- 'action' => apply_filters( 'bp_core_activity_registered_member_action', sprintf( __( '%s became a registered member', 'buddypress' ), $userlink ), $signup['user_id'] ),
58
- 'component' => 'profile',
59
- 'type' => 'new_member'
60
- ) );
61
- }
 
 
62
 
63
- do_action( 'bp_core_account_activated', &$signup, $_GET['key'] );
64
- wp_cache_delete( 'bp_total_member_count', 'bp' );
65
 
66
- bp_core_add_message( __( 'Your account is now active!', 'buddypress' ) );
 
67
 
68
- $bp->activation_complete = true;
69
- }
70
 
71
- if ( '' != locate_template( array( 'registration/activate' ), false ) )
72
- bp_core_load_template( apply_filters( 'bp_core_template_activate', 'activate' ) );
73
- else
74
- bp_core_load_template( apply_filters( 'bp_core_template_activate', 'registration/activate' ) );
75
  }
76
- add_action( 'wp', 'bp_core_screen_activation', 3 );
77
 
78
  /***
79
  * bp_core_filter_user_welcome_email()
1
  <?php
2
 
3
+ /**
4
+ * bp_core_email_from_name_filter()
5
+ *
6
+ * Sets the "From" name in emails sent to the name of the site and not "WordPress"
7
+ *
8
+ * @package BuddyPress Core
9
+ * @uses get_blog_option() fetches the value for a meta_key in the wp_X_options table
10
+ * @return The blog name for the root blog
11
+ */
12
+ function bp_core_email_from_name_filter() {
13
+ return apply_filters( 'bp_core_email_from_name_filter', get_blog_option( BP_ROOT_BLOG, 'blogname' ) );
14
+ }
15
+ add_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );
16
 
17
+ /**
18
+ * bp_core_email_from_name_filter()
19
+ *
20
+ * Sets the "From" address in emails sent
21
+ *
22
+ * @package BuddyPress Core
23
+ * @global $current_site Object containing current site metadata
24
+ * @return noreply@sitedomain email address
25
+ */
26
+ function bp_core_email_from_address_filter() {
27
+ $domain = (array) explode( '/', site_url() );
28
 
29
+ return apply_filters( 'bp_core_email_from_address_filter', __( 'noreply', 'buddypress' ) . '@' . $domain[2] );
30
+ }
31
+ add_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );
32
 
33
+ /**
34
+ * bp_core_allow_default_theme()
35
+ *
36
+ * On multiblog installations you must first allow themes to be activated and show
37
+ * up on the theme selection screen. This function will let the BuddyPress bundled
38
+ * themes show up on the root blog selection screen and bypass this step. It also
39
+ * means that the themes won't show for selection on other blogs.
40
+ *
41
+ * @package BuddyPress Core
42
+ */
43
+ function bp_core_allow_default_theme( $themes ) {
44
+ global $bp, $current_blog;
45
 
46
+ if ( !is_site_admin() )
47
+ return $themes;
48
 
49
+ if ( $current_blog->ID == $bp->root_blog ) {
50
+ $themes['bp-default'] = 1;
51
+ }
 
 
52
 
53
+ return $themes;
54
+ }
55
+ add_filter( 'allowed_themes', 'bp_core_allow_default_theme' );
56
 
57
+ /**
58
+ * bp_core_filter_comments()
59
+ *
60
+ * Filter the blog post comments array and insert BuddyPress URLs for users.
61
+ *
62
+ * @package BuddyPress Core
63
+ */
64
+ function bp_core_filter_comments( $comments, $post_id ) {
65
+ global $wpdb;
66
 
67
+ foreach( (array)$comments as $comment ) {
68
+ if ( $comment->user_id )
69
+ $user_ids[] = $comment->user_id;
70
+ }
71
 
72
+ if ( empty( $user_ids ) )
73
+ return $comments;
74
 
75
+ $user_ids = implode( ',', $user_ids );
 
 
 
76
 
77
+ if ( !$userdata = $wpdb->get_results( $wpdb->prepare( "SELECT ID as user_id, user_login, user_nicename FROM {$wpdb->users} WHERE ID IN ({$user_ids})" ) ) )
78
+ return $comments;
79
 
80
+ foreach( (array)$userdata as $user )
81
+ $users[$user->user_id] = bp_core_get_user_domain( $user->user_id, $user->user_nicename, $user->user_login );
82
 
83
+ foreach( (array)$comments as $i => $comment ) {
84
+ if ( !empty( $comment->user_id ) ) {
85
+ if ( !empty( $users[$comment->user_id] ) )
86
+ $comments[$i]->comment_author_url = $users[$comment->user_id];
87
  }
88
+ }
89
 
90
+ return $comments;
91
+ }
92
+ add_filter( 'comments_array', 'bp_core_filter_comments', 10, 2 );
93
 
94
+ /**
95
+ * bp_core_login_redirect()
96
+ *
97
+ * When a user logs in, always redirect them back to the previous page. NOT the admin area.
98
+ *
99
+ * @package BuddyPress Core
100
+ */
101
+ function bp_core_login_redirect( $redirect_to ) {
102
+ global $bp, $current_blog;
103
 
104
+ if ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG )
105
+ return $redirect_to;
106
 
107
+ if ( !empty( $_REQUEST['redirect_to'] ) || strpos( $_REQUEST['redirect_to'], 'wp-admin' ) )
108
+ return $redirect_to;
109
 
110
+ if ( false === strpos( wp_get_referer(), 'wp-login.php' ) && false === strpos( wp_get_referer(), 'activate' ) && empty( $_REQUEST['nr'] ) )
111
+ return wp_get_referer();
112
 
113
+ return $bp->root_domain;
 
 
 
114
  }
115
+ add_filter( 'login_redirect', 'bp_core_login_redirect' );
116
 
117
  /***
118
  * bp_core_filter_user_welcome_email()
bp-core/bp-core-signup.php CHANGED
@@ -1,5 +1,13 @@
1
  <?php
2
 
 
 
 
 
 
 
 
 
3
  function bp_core_screen_signup() {
4
  global $bp, $wpdb;
5
 
@@ -10,13 +18,6 @@ function bp_core_screen_signup() {
10
  if ( is_user_logged_in() )
11
  bp_core_redirect( $bp->root_domain );
12
 
13
- /***
14
- * For backwards compatibility with the old pre 1.1 two theme system, skip this screen function
15
- * if the user is using the old two theme method.
16
- */
17
- if ( file_exists( WP_CONTENT_DIR . '/bp-themes' ) )
18
- return false;
19
-
20
  /* If signups are disabled, just re-direct */
21
  if ( !bp_get_signup_allowed() )
22
  bp_core_redirect( $bp->root_domain );
@@ -32,7 +33,7 @@ function bp_core_screen_signup() {
32
  require_once( ABSPATH . WPINC . '/registration.php' );
33
 
34
  /* Check the base account details for problems */
35
- $account_details = wpmu_validate_user_signup( $_POST['signup_username'], $_POST['signup_email'] );
36
 
37
  /* If there are errors with account details, set them for display */
38
  if ( !empty( $account_details['errors']->errors['user_name'] ) )
@@ -73,7 +74,7 @@ function bp_core_screen_signup() {
73
  $active_signup = $bp->site_options['registration'];
74
 
75
  if ( 'blog' == $active_signup || 'all' == $active_signup ) {
76
- $blog_details = wpmu_validate_blog_signup( $_POST['signup_blog_url'], $_POST['signup_blog_title'] );
77
 
78
  /* If there are errors with blog details, set them for display */
79
  if ( !empty( $blog_details['errors']->errors['blogname'] ) )
@@ -125,9 +126,9 @@ function bp_core_screen_signup() {
125
 
126
  $usermeta = apply_filters( 'bp_signup_usermeta', $usermeta );
127
 
128
- /* Finally, sign up the user and/or blog*/
129
  if ( isset( $_POST['signup_with_blog'] ) && bp_core_is_multisite() )
130
- wpmu_signup_blog( $blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta );
131
  else {
132
  bp_core_signup_user( $_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta );
133
  }
@@ -158,8 +159,10 @@ function bp_core_screen_signup() {
158
  /* Hash the key to create the upload folder (added security so people don't sniff the activation key) */
159
  $bp->signup->avatar_dir = wp_hash( $bp->signup->key );
160
  }
161
- } else
162
- $bp->signup->avatar_dir = wp_hash( $bp->signup->username );
 
 
163
 
164
  /* Pass the file to the avatar upload handler */
165
  if ( bp_core_avatar_handle_upload( $_FILES, 'bp_core_signup_avatar_upload_dir' ) ) {
@@ -184,59 +187,285 @@ function bp_core_screen_signup() {
184
  bp_core_add_message( __( 'There was a problem cropping your avatar, please try uploading it again', 'buddypress' ), 'error' );
185
  else
186
  bp_core_add_message( __( 'Your new avatar was uploaded successfully', 'buddypress' ) );
 
 
 
 
187
 
188
- /* If this is a single WP install, move the avatar to the user's folder since there is no activation process to move it. */
189
- if ( !bp_core_is_multisite() ) {
190
- $user_id = bp_core_get_userid( $_POST['signup_username'] );
191
 
192
- if ( !empty( $user_id ) && file_exists( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $_POST['signup_avatar_dir'] ) ) {
193
- @rename( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $_POST['signup_avatar_dir'], BP_AVATAR_UPLOAD_PATH . '/avatars/' . $user_id );
194
- }
 
 
 
 
 
 
 
 
 
 
 
 
195
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  }
197
- bp_core_load_template( 'registration/register' );
 
 
 
 
198
  }
199
- add_action( 'wp', 'bp_core_screen_signup', 3 );
200
 
201
- function bp_core_signup_user( $user_login, $user_password, $user_email, $usermeta ) {
202
- global $bp;
203
 
204
- if ( bp_core_is_multisite() )
205
- return wpmu_signup_user( $user_login, $user_email, $usermeta );
 
 
 
 
 
 
 
 
 
206
 
207
  $errors = new WP_Error();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
 
209
- $user_id = wp_create_user( $user_login, $user_password, $user_email );
210
- if ( !$user_id ) {
211
- $errors->add('registerfail', sprintf(__('<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !'), get_option('admin_email')));
212
- return $errors;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
  }
214
 
215
- /* Set any profile data */
216
- if ( function_exists( 'xprofile_set_field_data' ) ) {
217
- if ( !empty( $usermeta['profile_field_ids'] ) ) {
218
- $profile_field_ids = explode( ',', $usermeta['profile_field_ids'] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
 
220
- foreach( (array)$profile_field_ids as $field_id ) {
221
- $current_field = $usermeta["field_{$field_id}"];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
 
223
- if ( !empty( $current_field ) )
224
- xprofile_set_field_data( $field_id, $user_id, $current_field );
 
225
  }
226
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  }
228
 
 
 
 
229
  /* Add a last active entry */
230
  update_usermeta( $user_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
231
 
232
- wp_new_user_notification( $user_id, $user_pass );
 
 
 
 
233
  wp_cache_delete( 'bp_total_member_count', 'bp' );
234
 
235
- $bp->signup->username = $user_login;
236
 
237
  return $user_id;
238
  }
239
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240
  function bp_core_map_user_registration( $user_id ) {
241
  /* Only map data when the site admin is adding users, not on registration. */
242
  if ( !is_admin() )
@@ -278,6 +507,43 @@ function bp_core_signup_avatar_upload_dir() {
278
  return apply_filters( 'bp_core_signup_avatar_upload_dir', array( 'path' => $path, 'url' => $newurl, 'subdir' => $newsubdir, 'basedir' => $newbdir, 'baseurl' => $newburl, 'error' => false ) );
279
  }
280