Changeset 3300
- Timestamp:
- 10/24/2010 09:22:29 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 99 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity.php
r2863 r3300 5 5 6 6 function bp_activity_setup_globals() { 7 global $bp, $ wpdb, $current_blog;7 global $bp, $current_blog; 8 8 9 9 if ( !defined( 'BP_ACTIVITY_SLUG' ) ) 10 10 define ( 'BP_ACTIVITY_SLUG', $bp->pages->activity->slug ); 11 11 12 / * For internal identification */12 // For internal identification 13 13 $bp->activity->id = 'activity'; 14 14 $bp->activity->name = $bp->pages->activity->name; 15 15 $bp->activity->slug = BP_ACTIVITY_SLUG; 16 16 17 $bp->activity->table_name = $wpdb->base_prefix . 'bp_activity'; 18 $bp->activity->table_name_meta = $wpdb->base_prefix . 'bp_activity_meta'; 17 $bp->activity->table_name = $bp->table_prefix . 'bp_activity'; 18 $bp->activity->table_name_meta = $bp->table_prefix . 'bp_activity_meta'; 19 19 20 $bp->activity->format_notification_function = 'bp_activity_format_notifications'; 20 21 21 / * Register this in the active components array */22 // Register this in the active components array 22 23 $bp->active_components[$bp->activity->slug] = $bp->activity->id; 23 24 … … 43 44 44 45 if ( bp_is_active( 'groups' ) ) 45 bp_core_new_subnav_item( array( 'name' => __( 'Groups', 'buddypress' ), 'slug' => $bp->groups->name, 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->name, 'screen_function' => 'bp_activity_screen_groups', 'position' => 30, 'item_css_id' => 'activity-groups' ) );46 bp_core_new_subnav_item( array( 'name' => __( 'Groups', 'buddypress' ), 'slug' => BP_GROUPS_SLUG, 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->name, 'screen_function' => 'bp_activity_screen_groups', 'position' => 30, 'item_css_id' => 'activity-groups' ) ); 46 47 47 48 bp_core_new_subnav_item( array( 'name' => __( 'Favorites', 'buddypress' ), 'slug' => 'favorites', 'parent_url' => $activity_link, 'parent_slug' => $bp->activity->name, 'screen_function' => 'bp_activity_screen_favorites', 'position' => 40, 'item_css_id' => 'activity-favs' ) ); … … 93 94 return false; 94 95 95 if ( !is_s ite_admin() )96 if ( !is_super_admin() ) 96 97 $bp->is_item_admin = false; 97 98 … … 106 107 return false; 107 108 108 if ( !is_s ite_admin() )109 if ( !is_super_admin() ) 109 110 $bp->is_item_admin = false; 110 111 … … 116 117 global $bp; 117 118 118 if ( !is_s ite_admin() )119 if ( !is_super_admin() ) 119 120 $bp->is_item_admin = false; 120 121 … … 126 127 global $bp; 127 128 128 if ( !is_s ite_admin() )129 if ( !is_super_admin() ) 129 130 $bp->is_item_admin = false; 130 131 … … 173 174 bp_core_redirect( $bp->loggedin_user->domain ); 174 175 else 175 bp_core_redirect( site_url( 'wp-login.php?redirect_to=' . clean_url( $bp->root_domain . '/' . $bp->activity->slug . '/p/' . $bp->current_action ) ) );176 bp_core_redirect( site_url( 'wp-login.php?redirect_to=' . esc_url( $bp->root_domain . '/' . $bp->activity->slug . '/p/' . $bp->current_action ) ) ); 176 177 } 177 178 … … 183 184 function bp_activity_screen_notification_settings() { 184 185 global $bp; ?> 185 <table class="notification-settings" id="activity-notification-settings"> 186 <tr> 187 <th class="icon"></th> 188 <th class="title"><?php _e( 'Activity', 'buddypress' ) ?></th> 189 <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th> 190 <th class="no"><?php _e( 'No', 'buddypress' )?></th> 191 </tr> 192 193 <tr> 194 <td></td> 195 <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> 196 <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> 197 <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> 198 </tr> 199 <tr> 200 <td></td> 201 <td><?php printf( __( "A member replies to an update or comment you've posted", 'buddypress' ), $current_user->user_login ) ?></td> 202 <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> 203 <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> 204 </tr> 205 206 <?php do_action( 'bp_activity_screen_notification_settings' ) ?> 186 <table class="notification-settings zebra" id="activity-notification-settings"> 187 <thead> 188 <tr> 189 <th class="icon"></th> 190 <th class="title"><?php _e( 'Activity', 'buddypress' ) ?></th> 191 <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th> 192 <th class="no"><?php _e( 'No', 'buddypress' )?></th> 193 </tr> 194 </thead> 195 196 <tbody> 197 <tr> 198 <td></td> 199 <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> 200 <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> 201 <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> 202 </tr> 203 <tr> 204 <td></td> 205 <td><?php printf( __( "A member replies to an update or comment you've posted", 'buddypress' ), $current_user->user_login ) ?></td> 206 <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> 207 <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> 208 </tr> 209 210 <?php do_action( 'bp_activity_screen_notification_settings' ) ?> 211 </tbody> 207 212 </table> 208 213 <?php … … 271 276 272 277 /* Check access */ 273 if ( !is_s ite_admin() && $activity->user_id != $bp->loggedin_user->id )278 if ( !is_super_admin() && $activity->user_id != $bp->loggedin_user->id ) 274 279 return false; 275 280 … … 541 546 542 547 function bp_activity_add( $args = '' ) { 543 global $bp , $wpdb;548 global $bp; 544 549 545 550 $defaults = array( 546 'id' => false, // Pass an existing activity ID to update an existing entry.547 548 'action' => '', // The activity action - e.g. "Jon Doe posted an update"549 'content' => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!"550 551 'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent552 'type' => false, // The activity type e.g. activity_update, profile_updated553 'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink)554 555 '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.556 'item_id' => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id551 'id' => false, // Pass an existing activity ID to update an existing entry. 552 553 'action' => '', // The activity action - e.g. "Jon Doe posted an update" 554 'content' => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!" 555 556 'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent 557 'type' => false, // The activity type e.g. activity_update, profile_updated 558 'primary_link' => '', // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink) 559 560 '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. 561 'item_id' => false, // Optional: The ID of the specific item being recorded, e.g. a blog_id 557 562 'secondary_item_id' => false, // Optional: A second ID used to further filter e.g. a comment_id 558 'recorded_time' => gmdate( "Y-m-d H:i:s"), // The GMT time that this activity was recorded559 'hide_sitewide' => false // Should this be hidden on the sitewide activity stream?563 'recorded_time' => bp_core_current_time(), // The GMT time that this activity was recorded 564 'hide_sitewide' => false // Should this be hidden on the sitewide activity stream? 560 565 ); 561 566 … … 628 633 629 634 /* Add this update to the "latest update" usermeta so it can be fetched anywhere. */ 630 update_user meta( $bp->loggedin_user->id, 'bp_latest_update', array( 'id' => $activity_id, 'content' => wp_filter_kses( $content ) ) );635 update_user_meta( $bp->loggedin_user->id, 'bp_latest_update', array( 'id' => $activity_id, 'content' => wp_filter_kses( $content ) ) ); 631 636 632 637 /* Require the notifications code so email notifications can be set on the 'bp_activity_posted_update' action. */ … … 755 760 $user_id = $args['user_id']; 756 761 757 $latest_update = get_user meta( $user_id, 'bp_latest_update');762 $latest_update = get_user_meta( $user_id, 'bp_latest_update', true ); 758 763 if ( !empty( $latest_update ) ) { 759 764 if ( in_array( (int)$latest_update['id'], (array)$activity_ids_deleted ) ) 760 delete_user meta( $user_id, 'bp_latest_update' );765 delete_user_meta( $user_id, 'bp_latest_update' ); 761 766 } 762 767 … … 909 914 910 915 function bp_activity_get_user_favorites( $user_id ) { 911 $my_favs = maybe_unserialize( get_user meta( $user_id, 'bp_favorite_activities') );916 $my_favs = maybe_unserialize( get_user_meta( $user_id, 'bp_favorite_activities', true ) ); 912 917 $existing_favs = bp_activity_get_specific( array( 'activity_ids' => $my_favs ) ); 913 918 … … 916 921 917 922 $new_favs = array_unique( (array)$new_favs ); 918 update_user meta( $user_id, 'bp_favorite_activities', $new_favs );923 update_user_meta( $user_id, 'bp_favorite_activities', $new_favs ); 919 924 920 925 return apply_filters( 'bp_activity_get_user_favorites', $new_favs ); … … 928 933 929 934 /* Update the user's personal favorites */ 930 $my_favs = maybe_unserialize( get_user meta( $bp->loggedin_user->id, 'bp_favorite_activities') );935 $my_favs = maybe_unserialize( get_user_meta( $bp->loggedin_user->id, 'bp_favorite_activities', true ) ); 931 936 $my_favs[] = $activity_id; 932 937 … … 939 944 $fav_count = 1; 940 945 941 update_user meta( $bp->loggedin_user->id, 'bp_favorite_activities', $my_favs );946 update_user_meta( $bp->loggedin_user->id, 'bp_favorite_activities', $my_favs ); 942 947 bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count ); 943 948 … … 954 959 955 960 /* Remove the fav from the user's favs */ 956 $my_favs = maybe_unserialize( get_user meta( $user_id, 'bp_favorite_activities') );961 $my_favs = maybe_unserialize( get_user_meta( $user_id, 'bp_favorite_activities', true ) ); 957 962 $my_favs = array_flip( (array) $my_favs ); 958 963 unset( $my_favs[$activity_id] ); … … 967 972 } 968 973 969 update_user meta( $user_id, 'bp_favorite_activities', $my_favs );974 update_user_meta( $user_id, 'bp_favorite_activities', $my_favs ); 970 975 971 976 do_action( 'bp_activity_remove_user_favorite', $activity_id, $user_id ); … … 1089 1094 1090 1095 // Remove any usermeta 1091 delete_user meta( $user_id, 'bp_latest_update' );1092 delete_user meta( $user_id, 'bp_favorite_activities' );1096 delete_user_meta( $user_id, 'bp_latest_update' ); 1097 delete_user_meta( $user_id, 'bp_favorite_activities' ); 1093 1098 1094 1099 do_action( 'bp_activity_remove_data', $user_id ); … … 1098 1103 add_action( 'make_spam_user', 'bp_activity_remove_data' ); 1099 1104 1105 /** 1106 * updates_register_activity_actions() 1107 * 1108 * Register the activity stream actions for updates 1109 * 1110 * @global array $bp 1111 */ 1112 function updates_register_activity_actions() { 1113 global $bp; 1114 1115 bp_activity_set_action( $bp->activity->id, 'activity_update', __( 'Posted an update', 'buddypress' ) ); 1116 1117 do_action( 'updates_register_activity_actions' ); 1118 } 1119 add_action( 'bp_register_activity_actions', 'updates_register_activity_actions' ); 1100 1120 1101 1121 /******************************************************************************** … … 1110 1130 do_action( 'bp_register_activity_actions' ); 1111 1131 } 1112 add_action( ' plugins_loaded', 'bp_register_activity_actions');1132 add_action( 'bp_loaded', 'bp_register_activity_actions', 8 ); 1113 1133 1114 1134 -
trunk/bp-activity/bp-activity-classes.php
r3236 r3300 98 98 $where_conditions = array(); 99 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 100 106 /* Filtering */ 101 107 if ( $filter && $filter_sql = BP_Activity_Activity::get_filter_sql( $filter ) ) … … 117 123 $where_sql = 'WHERE ' . join( ' AND ', $where_conditions ); 118 124 119 /* Searching */120 if ( $search_terms ) {121 $search_terms = $wpdb->escape( $search_terms );122 123 if ( !empty( $filter['user_id'] ) )124 $where_sql .= ' OR ';125 else if ( !empty( $where_conditions ) )126 $where_sql .= ' AND ';127 128 $where_sql .= "a.content LIKE '%%" . like_escape( $search_terms ) . "%%'";129 }130 131 125 if ( $per_page && $page ) { 132 126 $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page ), intval( $per_page ) ); 133 127 $activities = $wpdb->get_results( apply_filters( 'bp_activity_get_user_join_filter', $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}", $select_sql, $from_sql, $where_sql, $sort, $pag_sql ) ) ); 134 } else 128 } else { 135 129 $activities = $wpdb->get_results( apply_filters( 'bp_activity_get_user_join_filter', $wpdb->prepare( "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort}", $select_sql, $from_sql, $where_sql, $sort ) ) ); 130 } 136 131 137 132 $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}" ) ); … … 532 527 global $bp, $wpdb; 533 528 534 return $wpdb->get_var( $wpdb->prepare( "SELECT date_recorded FROM {$bp->activity->table_name} ORDER BY date_recorded ASC LIMIT 1" ) );529 return $wpdb->get_var( $wpdb->prepare( "SELECT date_recorded FROM {$bp->activity->table_name} ORDER BY date_recorded DESC LIMIT 1" ) ); 535 530 } 536 531 … … 538 533 global $bp; 539 534 540 if ( !$favorite_activity_entries = get_user meta( $user_id, 'bp_favorite_activities') )535 if ( !$favorite_activity_entries = get_user_meta( $user_id, 'bp_favorite_activities', true ) ) 541 536 return 0; 542 537 -
trunk/bp-activity/bp-activity-notifications.php
r3232 r3300 5 5 6 6 /* Scan for @username strings in an activity update. Notify each user. */ 7 $pattern = '/[@]+([A-Za-z0-9-_ ]+)/';7 $pattern = '/[@]+([A-Za-z0-9-_\.]+)/'; 8 8 preg_match_all( $pattern, $content, $usernames ); 9 9 … … 13 13 14 14 foreach( (array)$usernames as $username ) { 15 if ( !$receiver_user_id = bp_core_get_userid( $username) )15 if ( !$receiver_user_id = bp_core_get_userid( $username ) ) 16 16 continue; 17 17 18 18 // Now email the user with the contents of the message (if they have enabled email notifications) 19 if ( 'no' != get_user meta( $receiver_user_id, 'notification_activity_new_mention') ) {19 if ( 'no' != get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) { 20 20 $poster_name = bp_core_get_user_displayname( $poster_user_id ); 21 21 … … 27 27 28 28 // Set up and send the message 29 $ud = bp_core_get_core_userdata( $receiver_user_id ); 30 $to = $ud->user_email; 31 $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s mentioned you in an update', 'buddypress' ), $poster_name ); 29 $ud = bp_core_get_core_userdata( $receiver_user_id ); 30 $to = $ud->user_email; 31 $sitename = wp_specialchars_decode( get_blog_option( BP_ROOT_BLOG, 'blogname' ), ENT_QUOTES ); 32 $subject = '[' . $sitename . '] ' . sprintf( __( '%s mentioned you in an update', 'buddypress' ), $poster_name ); 32 33 33 34 $message = sprintf( __( … … 61 62 $original_activity = new BP_Activity_Activity( $activity_id ); 62 63 63 if ( $original_activity->user_id != $commenter_id && 'no' != get_user meta( $original_activity->user_id, 'notification_activity_new_reply') ) {64 if ( $original_activity->user_id != $commenter_id && 'no' != get_user_meta( $original_activity->user_id, 'notification_activity_new_reply', true ) ) { 64 65 $poster_name = bp_core_get_user_displayname( $commenter_id ); 65 66 $thread_link = bp_activity_get_permalink( $activity_id ); … … 70 71 71 72 // Set up and send the message 72 $ud = bp_core_get_core_userdata( $original_activity->user_id ); 73 $to = $ud->user_email; 74 $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s replied to one of your updates', 'buddypress' ), $poster_name ); 73 $ud = bp_core_get_core_userdata( $original_activity->user_id ); 74 $to = $ud->user_email; 75 $sitename = wp_specialchars_decode( get_blog_option( BP_ROOT_BLOG, 'blogname' ), ENT_QUOTES ); 76 $subject = '[' . $sitename . '] ' . sprintf( __( '%s replied to one of your updates', 'buddypress' ), $poster_name ); 75 77 76 78 $message = sprintf( __( … … 103 105 $parent_comment = new BP_Activity_Activity( $parent_id ); 104 106 105 if ( $parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id && 'no' != get_user meta( $parent_comment->user_id, 'notification_activity_new_reply') ) {107 if ( $parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id && 'no' != get_user_meta( $parent_comment->user_id, 'notification_activity_new_reply', true ) ) { 106 108 $poster_name = bp_core_get_user_displayname( $commenter_id ); 107 109 $thread_link = bp_activity_get_permalink( $activity_id ); … … 109 111 110 112 // Set up and send the message 111 $ud = bp_core_get_core_userdata( $parent_comment->user_id ); 112 $to = $ud->user_email; 113 $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s replied to one of your comments', 'buddypress' ), $poster_name ); 113 $ud = bp_core_get_core_userdata( $parent_comment->user_id ); 114 $to = $ud->user_email; 115 $sitename = wp_specialchars_decode( get_blog_option( BP_ROOT_BLOG, 'blogname' ), ENT_QUOTES ); 116 $subject = '[' . $sitename . '] ' . sprintf( __( '%s replied to one of your comments', 'buddypress' ), $poster_name ); 114 117 115 118 $poster_name = stripslashes( $poster_name ); -
trunk/bp-activity/bp-activity-templatetags.php
r3263 r3300 26 26 27 27 // Get an array of the logged in user's favorite activities 28 $this->my_favs = maybe_unserialize( get_user meta( $bp->loggedin_user->id, 'bp_favorite_activities') );28 $this->my_favs = maybe_unserialize( get_user_meta( $bp->loggedin_user->id, 'bp_favorite_activities', true ) ); 29 29 30 30 // Fetch specific activity items based on ID's 31 31 if ( !empty( $include ) ) 32 32 $this->activities = bp_activity_get_specific( array( 'activity_ids' => explode( ',', $include ), 'max' => $max, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'sort' => $sort, 'display_comments' => $display_comments ) ); 33 // Fetch all activity items 33 34 else 34 35 $this->activities = bp_activity_get( array( 'display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter, 'show_hidden' => $show_hidden ) ); … … 155 156 $primary_id = $bp->groups->current_group->id; 156 157 157 if ( 'public' != $bp->groups->current_group->status && groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id) )158 if ( 'public' != $bp->groups->current_group->status && ( groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) || $bp->loggedin_user->is_super_admin ) ) 158 159 $show_hidden = true; 159 160 } … … 201 202 // are we displaying user specific activity? 202 203 if ( is_numeric( $user_id ) ) { 203 $show_hidden = ( $user_id == $bp->loggedin_user->id ) ? 1 : 0;204 $show_hidden = ( $user_id == $bp->loggedin_user->id && $scope != 'friends' ) ? 1 : 0; 204 205 205 206 switch ( $scope ) { … … 275 276 global $bp, $activities_template; 276 277 277 $from_num = bp_core_number_format( intval( ( $activities_template->pag_page - 1 ) * $activities_template->pag_num ) + 1 ); 278 $to_num = bp_core_number_format( ( $from_num + ( $activities_template->pag_num - 1 ) > $activities_template->total_activity_count ) ? $activities_template->total_activity_count : $from_num + ( $activities_template->pag_num - 1 ) ); 278 $start_num = intval( ( $activities_template->pag_page - 1 ) * $activities_template->pag_num ) + 1; 279 $from_num = bp_core_number_format( $start_num ); 280 $to_num = bp_core_number_format( ( $start_num + ( $activities_template->pag_num - 1 ) > $activities_template->total_activity_count ) ? $activities_template->total_activity_count : $start_num + ( $activities_template->pag_num - 1 ) ); 279 281 $total = bp_core_number_format( $activities_template->total_activity_count ); 280 282 281 return sprintf( __( 'Viewing item % s to %s (of %s items)', 'buddypress' ), $from_num, $to_num, $total ) . ' <span class="ajax-loader"></span>';283 return sprintf( __( 'Viewing item %1$s to %2$s (of %3$s items)', 'buddypress' ), $from_num, $to_num, $total ) . ' <span class="ajax-loader"></span>'; 282 284 } 283 285 … … 403 405 } 404 406 407 /** 408 * bp_activity_avatar( $args ) 409 * 410 * Output the avatar of the user that performed the action 411 * 412 * @param array $args 413 */ 405 414 function bp_activity_avatar( $args = '' ) { 406 415 echo bp_get_activity_avatar( $args ); 407 416 } 417 /** 418 * bp_get_activity_avatar( $args ) 419 * 420 * Return the avatar of the user that performed the action 421 * 422 * @global array $bp 423 * @global object $activities_template 424 * @param array $args optional 425 * @return string 426 */ 408 427 function bp_get_activity_avatar( $args = '' ) { 409 428 global $bp, $activities_template; 410 429 411 430 $defaults = array( 412 'type' => 'thumb',413 'width' => 20,431 'type' => 'thumb', 432 'width' => 20, 414 433 'height' => 20, 415 'class' => 'avatar',416 'alt' => __( 'Avatar', 'buddypress' ),417 'email' => false434 'class' => 'avatar', 435 'alt' => __( 'Avatar', 'buddypress' ), 436 'email' => false 418 437 ); 419 438 … … 421 440 extract( $r, EXTR_SKIP ); 422 441 423 $item_id = false; 424 if ( (int)$activities_template->activity->user_id ) 425 $item_id = $activities_template->activity->user_id; 426 else if ( $activities_template->activity->item_id ) 427 $item_id = $activities_template->activity->item_id; 428 429 $object = 'user'; 430 if ( $bp->groups->id == $activities_template->activity->component && !(int) $activities_template->activity->user_id ) 431 $object = 'group'; 432 if ( $bp->blogs->id == $activities_template->activity->component && !(int) $activities_template->activity->user_id ) 433 $object = 'blog'; 434 435 $object = apply_filters( 'bp_get_activity_avatar_object_' . $activities_template->activity->component, $object ); 436 437 /* If this is a user object pass the users' email address for Gravatar so we don't have to refetch it. */ 438 if ( 'user' == $object && empty($email) ) 442 // Primary activity avatar is always a user, but can be modified via a filter 443 $object = apply_filters( 'bp_get_activity_avatar_object_' . $activities_template->activity->component, 'user' ); 444 $item_id = apply_filters( 'bp_get_activity_avatar_item_id', $activities_template->activity->user_id ); 445 446 // If this is a user object pass the users' email address for Gravatar so we don't have to refetch it. 447 if ( 'user' == $object && empty( $email ) ) 439 448 $email = $activities_template->activity->user_email; 440 449 441 450 return apply_filters( 'bp_get_activity_avatar', bp_core_fetch_avatar( array( 'item_id' => $item_id, 'object' => $object, 'type' => $type, 'alt' => $alt, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $email ) ) ); 451 } 452 453 /** 454 * bp_activity_secondary_avatar( $args ) 455 * 456 * Output the avatar of the object that action was performed on 457 * 458 * @param array $args optional 459 */ 460 function bp_activity_secondary_avatar( $args = '' ) { 461 echo bp_get_activity_secondary_avatar( $args ); 462 } 463 /** 464 * bp_get_activity_secondary_avatar( $args ) 465 * 466 * Return the avatar of the object that action was performed on 467 * 468 * @global array $bp 469 * @global object $activities_template 470 * @param array $args optional 471 * @return string 472 */ 473 function bp_get_activity_secondary_avatar( $args = '' ) { 474 global $bp, $activities_template; 475 476 $defaults = array( 477 'type' => 'thumb', 478 'width' => 20, 479 'height' => 20, 480 'class' => 'avatar', 481 'alt' => __( 'Avatar', 'buddypress' ), 482 'email' => false 483 ); 484 485 $r = wp_parse_args( $args, $defaults ); 486 extract( $r, EXTR_SKIP ); 487 488 // Set item_id and object (default to user) 489 switch ( $activities_template->activity->component ) { 490 case 'groups' : 491 $object = 'group'; 492 $item_id = $activities_template->activity->item_id; 493 break; 494 case 'blogs' : 495 $object = 'blog'; 496 $item_id = $activities_template->activity->item_id; 497 break; 498 case 'friends' : 499 $object = 'user'; 500 $item_id = $activities_template->activity->secondary_item_id; 501 break; 502 default : 503 $object = 'user'; 504 $item_id = $activities_template->activity->user_id; 505 $email = $activities_template->activity->user_email; 506 break; 507 } 508 509 // Allow object and item_id to be filtered 510 $object = apply_filters( 'bp_get_activity_secondary_avatar_object_' . $activities_template->activity->component, $object ); 511 $item_id = apply_filters( 'bp_get_activity_secondary_avatar_item_id', $item_id ); 512 513 // If we have no item_id or object, there is no avatar to display 514 if ( empty( $item_id ) || empty( $object ) ) 515 return false; 516 517 return apply_filters( 'bp_get_activity_secondary_avatar', bp_core_fetch_avatar( array( 'item_id' => $item_id, 'object' => $object, 'type' => $type, 'alt' => $alt, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $email ) ) ); 442 518 } 443 519 … … 449 525 450 526 $action = $activities_template->activity->action; 527 528 $action = apply_filters( 'bp_get_activity_action_pre_meta', $action, &$activities_template->activity ); 451 529 452 530 if ( !empty( $action ) ) … … 498 576 global $activities_template, $bp; 499 577 500 $meta = '<span class="activity-actions">'; 578 /* Strip any legacy time since placeholders -- TODO: Remove this in 1.3 */ 579 $content = str_replace( '<span class="time-since">%s</span>', '', $content ); 501 580 502 581 /* Insert the time since. */ 503 $ meta .=apply_filters( 'bp_activity_time_since', '<span class="time-since">' . sprintf( __( ' %s ago', 'buddypress' ), bp_core_time_since( $activities_template->activity->date_recorded ) ) . '</span>', &$activities_template->activity );582 $content .= ' ' . apply_filters( 'bp_activity_time_since', '<span class="time-since">' . sprintf( __( ' %s ago', 'buddypress' ), bp_core_time_since( $activities_template->activity->date_recorded ) ) . '</span>', &$activities_template->activity ); 504 583 505 584 /* Insert the permalink */ 506 $ meta.= apply_filters( 'bp_activity_permalink', ' · <a href="' . bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ) . '" class="view" title="' . __( 'View Thread / Permalink', 'buddypress' ) . '">' . __( 'View', 'buddypress' ) . '</a>', &$activities_template->activity );585 $content .= apply_filters( 'bp_activity_permalink', ' · <a href="' . bp_activity_get_permalink( $activities_template->activity->id, $activities_template->activity ) . '" class="view" title="' . __( 'View Thread / Permalink', 'buddypress' ) . '">' . __( 'View', 'buddypress' ) . '</a>', &$activities_template->activity ); 507 586 508 587 /* Add the delete link if the user has permission on this item */ 509 if ( ( is_user_logged_in() && $activities_template->activity->user_id == $bp->loggedin_user->id ) || $bp->is_item_admin || $bp->loggedin_user->is_site_admin ) 510 $meta .= apply_filters( 'bp_activity_delete_link', ' · ' . bp_get_activity_delete_link(), &$activities_template->activity ); 511 512 $meta .= '</span>'; 513 514 return apply_filters( 'bp_insert_activity_meta', $content . ' ' . $meta, $content, $meta ); 588 if ( ( is_user_logged_in() && $activities_template->activity->user_id == $bp->loggedin_user->id ) || $bp->is_item_admin || $bp->loggedin_user->is_super_admin ) 589 $content .= apply_filters( 'bp_activity_delete_link', ' · ' . bp_get_activity_delete_link(), &$activities_template->activity ); 590 591 return apply_filters( 'bp_insert_activity_meta', $content ); 515 592 } 516 593 … … 585 662 586 663 $content .= '<li id="acomment-' . $comment->id . '">'; 587 $content .= '<div class="acomment-avatar"><a href="' . bp_core_get_user_domain( $comment->user_id, $comment->user_nicename, $comment->user_login ) . '">' . bp_core_fetch_avatar( array( 'item_id' => $comment->user_id, 'width' => 2 5, 'height' => 25, 'email' => $comment->user_email ) ) . '</a></div>';588 $content .= '<div class="acomment-meta"><a href="' . bp_core_get_user_domain( $comment->user_id, $comment->user_nicename, $comment->user_login ) . '">' . apply_filters( 'bp_ get_member_name', $comment->user_fullname ) . '</a> · ' . sprintf( __( '%s ago', 'buddypress' ), bp_core_time_since( strtotime( $comment->date_recorded )) );664 $content .= '<div class="acomment-avatar"><a href="' . bp_core_get_user_domain( $comment->user_id, $comment->user_nicename, $comment->user_login ) . '">' . bp_core_fetch_avatar( array( 'item_id' => $comment->user_id, 'width' => 20, 'height' => 20, 'email' => $comment->user_email ) ) . '</a></div>'; 665 $content .= '<div class="acomment-meta"><a href="' . bp_core_get_user_domain( $comment->user_id, $comment->user_nicename, $comment->user_login ) . '">' . apply_filters( 'bp_acomment_name', $comment->user_fullname, $comment ) . '</a> · ' . sprintf( __( '%s ago', 'buddypress' ), bp_core_time_since( $comment->date_recorded ) ); 589 666 590 667 /* Reply link - the span is so that threaded reply links can be hidden when JS is off. */ … … 593 670 594 671 /* Delete link */ 595 if ( $bp->loggedin_user->is_s ite_admin || $bp->loggedin_user->id == $comment->user_id )672 if ( $bp->loggedin_user->is_super_admin || $bp->loggedin_user->id == $comment->user_id ) 596 673 $content .= ' · <a href="' . wp_nonce_url( $bp->root_domain . '/' . $bp->activity->slug . '/delete/?cid=' . $comment->id, 'bp_activity_delete_link' ) . '" class="delete acomment-delete">' . __( 'Delete', 'buddypress' ) . '</a>'; 597 674 … … 739 816 $user_id = $bp->displayed_user->id; 740 817 741 if ( !$update = get_user meta( $user_id, 'bp_latest_update') )818 if ( !$update = get_user_meta( $user_id, 'bp_latest_update', true ) ) 742 819 return false; 743 820 744 $latest_update = '"' . trim( strip_tags( bp_create_excerpt( $update['content'], 40) ) ) . '"';821 $latest_update = '"' . apply_filters( 'bp_get_activity_latest_update_excerpt', trim( strip_tags( bp_create_excerpt( $update['content'], 40 ) ) ) ) . '"'; 745 822 $latest_update .= ' · <a href="' . $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $update['id'] . '/"> ' . __( 'View', 'buddypress' ) . '</a>'; 746 823 … … 777 854 unset($selected); 778 855 779 $component = attribute_escape( $component );856 $component = esc_attr( $component ); 780 857 781 858 switch ( $style ) { … … 805 882 $translatable_components = array( __( 'profile', 'buddypress'), __( 'friends', 'buddypress' ), __( 'groups', 'buddypress' ), __( 'status', 'buddypress' ), __( 'blogs', 'buddypress' ) ); 806 883 807 $component_links[] = $before . '<a href="' . attribute_escape( $link ) . '">' . ucwords( __( $component, 'buddypress' ) ) . '</a>' . $after;884 $component_links[] = $before . '<a href="' . esc_attr( $link ) . '">' . ucwords( __( $component, 'buddypress' ) ) . '</a>' . $after; 808 885 } 809 886 … … 811 888 812 889 if ( isset( $_GET['afilter'] ) ) 813 $component_links[] = '<' . $tag . ' id="afilter-clear"><a href="' . attribute_escape( $link ) . '"">' . __( 'Clear Filter', 'buddypress' ) . '</a></' . $tag . '>';890 $component_links[] = '<' . $tag . ' id="afilter-clear"><a href="' . esc_attr( $link ) . '"">' . __( 'Clear Filter', 'buddypress' ) . '</a></' . $tag . '>'; 814 891 815 892 return apply_filters( 'bp_get_activity_filter_links', implode( "\n", $component_links ) ); … … 841 918 } 842 919 function bp_get_total_mention_count_for_user( $user_id = false ) { 843 return apply_filters( 'bp_get_total_mention_count_for_user', get_user meta( $user_id, 'bp_new_mention_count') );920 return apply_filters( 'bp_get_total_mention_count_for_user', get_user_meta( $user_id, 'bp_new_mention_count', true ) ); 844 921 } 845 922 -
trunk/bp-activity/feeds/bp-activity-favorites-feed.php
r2600 r3300 15 15 xmlns:dc="http://purl.org/dc/elements/1.1/" 16 16 xmlns:atom="http://www.w3.org/2005/Atom" 17 <?php do_action('bp_activity_ mentions_feed'); ?>17 <?php do_action('bp_activity_favorites_feed'); ?> 18 18 > 19 19 -
trunk/bp-blogs.php
r3232 r3300 10 10 global $bp, $wpdb; 11 11 12 if ( !defined( 'BP_BLOGS_SLUG' ) ) 13 define ( 'BP_BLOGS_SLUG', $bp->pages->blogs->slug ); 14 12 15 /* For internal identification */ 13 16 $bp->blogs->id = 'blogs'; … … 45 48 46 49 /* Add 'Blogs' to the main navigation */ 47 bp_core_new_nav_item( array( 'name' => sprintf( __( 'Blogs <span>(%d)</span>', 'buddypress' ), bp_blogs_total_blogs_for_user() ), 'slug' => $bp->blogs-> name, 'position' => 30, 'screen_function' => 'bp_blogs_screen_my_blogs', 'default_subnav_slug' => 'my-blogs', 'item_css_id' => $bp->blogs->id ) );48 49 $blogs_link = $bp->loggedin_user->domain . $bp->blogs-> name. '/';50 bp_core_new_nav_item( array( 'name' => sprintf( __( 'Blogs <span>(%d)</span>', 'buddypress' ), bp_blogs_total_blogs_for_user() ), 'slug' => $bp->blogs->slug, 'position' => 30, 'screen_function' => 'bp_blogs_screen_my_blogs', 'default_subnav_slug' => 'my-blogs', 'item_css_id' => $bp->blogs->id ) ); 51 52 $blogs_link = $bp->loggedin_user->domain . $bp->blogs->slug . '/'; 50 53 51 54 /* Set up the component options navigation for Blog */ … … 97 100 } 98 101 99 function bp_blogs_screen_recent_posts() {100 do_action( 'bp_blogs_screen_recent_posts' );101 bp_core_load_template( apply_filters( 'bp_blogs_template_recent_posts', 'members/single/home' ) );102 }103 104 function bp_blogs_screen_recent_comments() {105 do_action( 'bp_blogs_screen_recent_comments' );106 bp_core_load_template( apply_filters( 'bp_blogs_template_recent_comments', 'members/single/home' ) );107 }108 109 102 function bp_blogs_screen_create_a_blog() { 110 103 global $bp; … … 164 157 'item_id' => false, 165 158 'secondary_item_id' => false, 166 'recorded_time' => gmdate( "Y-m-d H:i:s"),159 'recorded_time' => bp_core_current_time(), 167 160 'hide_sitewide' => false 168 161 ); … … 179 172 180 173 if ( !empty( $content ) ) 181 $content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $content ) );174 $content = apply_filters( 'bp_blogs_record_activity_content', bp_create_excerpt( $content ), $content ); 182 175 183 176 /* Check for an existing entry and update if one exists. */ … … 245 238 } 246 239 247 248 240 function bp_blogs_record_existing_blogs() { 249 241 global $bp, $wpdb; … … 270 262 } 271 263 264 /** 265 * Makes BuddyPress aware of a new site so that it can track its activity. 266 * 267 * @global object $bp BuddyPress global settings 268 * @param int $blog_id 269 * @param int $user_id 270 * @param $bool $no_activity ; optional. 271 * @since 1.0 272 * @uses BP_Blogs_Blog 273 */ 272 274 function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) { 273 275 global $bp; … … 290 292 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'name', $name ); 291 293 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description ); 292 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s") );293 294 / * Only record this activity if the blog is public */294 bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'last_activity', bp_core_current_time() ); 295 296 // Only record this activity if the blog is public 295 297 if ( (int)$_POST['blog_public'] && !$no_activity ) { 296 / * Record this in activity streams */298 // Record this in activity streams 297 299 bp_blogs_record_activity( array( 298 'user_id' => $recorded_blog->user_id,299 'action' => apply_filters( 'bp_blogs_activity_created_blog_action', sprintf( __( '%1$s created the blog %2$s', 'buddypress'), bp_core_get_userlink( $recorded_blog->user_id ), '<a href="' . get_blog_option( $recorded_blog->blog_id, 'siteurl' ) . '">' . attribute_escape( $name ) . '</a>' ), &$recorded_blog, $name, $description ),300 'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', get_ blog_option( $recorded_blog->blog_id, 'siteurl'), $recorded_blog->blog_id ),301 'type' => 'new_blog',302 'item_id' => $recorded_blog->blog_id300 'user_id' => $recorded_blog->user_id, 301 'action' => apply_filters( 'bp_blogs_activity_created_blog_action', sprintf( __( '%s created the blog %s', 'buddypress'), bp_core_get_userlink( $recorded_blog->user_id ), '<a href="' . get_site_url( $recorded_blog->blog_id ) . '">' . esc_attr( $name ) . '</a>' ), &$recorded_blog, $name, $description ), 302 'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', get_site_url( $recorded_blog->blog_id ), $recorded_blog->blog_id ), 303 'type' => 'new_blog', 304 'item_id' => $recorded_blog->blog_id 303 305 ) ); 304 306 } … … 307 309 } 308 310 add_action( 'wpmu_new_blog', 'bp_blogs_record_blog', 10, 2 ); 311 312 /** 313 * bp_blogs_update_option_blogname() 314 * 315 * Updates blogname in BuddyPress blogmeta table 316 * 317 * @global object $wpdb DB Layer 318 * @param string $oldvalue Value before save (not used) 319 * @param string $newvalue Value to change meta to 320 */ 321 function bp_blogs_update_option_blogname( $oldvalue, $newvalue ) { 322 global $wpdb; 323 bp_blogs_update_blogmeta( $wpdb->blogid, 'name', $newvalue ); 324 } 325 add_action( 'update_option_blogname', 'bp_blogs_update_option_blogname', 10, 2 ); 326 327 /** 328 * bp_blogs_update_option_blogdescription() 329 * 330 * Updates blogdescription in BuddyPress blogmeta table 331 * 332 * @global object $wpdb DB Layer 333 * @param string $oldvalue Value before save (not used) 334 * @param string $newvalue Value to change meta to 335 */ 336 function bp_blogs_update_option_blogdescription( $oldvalue, $newvalue ) { 337 global $wpdb; 338 bp_blogs_update_blogmeta( $wpdb->blogid, 'description', $newvalue ); 339 } 340 add_action( 'update_option_blogdescription', 'bp_blogs_update_option_blogdescription', 10, 2 ); 309 341 310 342 function bp_blogs_record_post( $post_id, $post, $user_id = false ) { … … 317 349 $user_id = (int)$post->post_author; 318 350 319 /* This is to stop infin ate loops with Donncha's sitewide tags plugin */351 /* This is to stop infinite loops with Donncha's sitewide tags plugin */ 320 352 if ( (int)$bp->site_options['tags_blog_id'] == (int)$blog_id ) 321 353 return false; … … 325 357 return false; 326 358 327 if ( !$is_recorded = BP_Blogs_Post::is_recorded( $post_id, $blog_id, $user_id ) ) { 328 if ( 'publish' == $post->post_status && '' == $post->post_password ) { 329 330 /* If we're on a multiblog install, record this post */ 331 if ( bp_core_is_multisite() ) { 332 $recorded_post = new BP_Blogs_Post; 333 $recorded_post->user_id = $user_id; 334 $recorded_post->blog_id = $blog_id; 335 $recorded_post->post_id = $post_id; 336 $recorded_post->date_created = strtotime( $post->post_date ); 337 338 $recorded_post_id = $recorded_post->save(); 339 340 bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) ); 341 } 342 343 if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) { 344 /* Record this in activity streams */ 345 $post_permalink = get_permalink( $post_id ); 346 347 $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>' ); 348 $activity_content = $post->post_content; 349 350 bp_blogs_record_activity( array( 351 'user_id' => (int)$post->post_author, 352 'action' => apply_filters( 'bp_blogs_activity_new_post_action', $activity_action, &$post, $post_permalink ), 353 'content' => apply_filters( 'bp_blogs_activity_new_post_content', $activity_content, &$post, $post_permalink ), 354 'primary_link' => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink, $post_id ), 355 'type' => 'new_blog_post', 356 'item_id' => $blog_id, 357 'secondary_item_id' => $post_id, 358 'recorded_time' => $post->post_date_gmt 359 )); 360 } 361 } 362 } else { 363 $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id ); 364 365 /* Delete the recorded post if the status is not published or it is password protected */ 366 if ( 'publish' != $post->post_status || '' != $post->post_password ) { 367 return bp_blogs_remove_post( $post_id, $blog_id, $existing_post ); 368 369 /* If the post author has changed, delete the post and re-add it. */ 370 } else if ( (int)$existing_post->user_id != (int)$post->post_author ) { 371 // Delete the existing recorded post 372 bp_blogs_remove_post( $post_id, $blog_id, $existing_post ); 373 374 // Re-record the post with the new author. 375 bp_blogs_record_post( $post_id ); 376 } 377 378 bp_blogs_update_blogmeta( $recorded_post->blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) ); 379 359 if ( 'publish' == $post->post_status && '' == $post->post_password ) { 380 360 if ( (int)get_blog_option( $blog_id, 'blog_public' ) || !bp_core_is_multisite() ) { 381 /* Now re-record the post in theactivity streams */361 /* Record this in activity streams */ 382 362 $post_permalink = get_permalink( $post_id ); 383 363 384 $activity_action = sprintf( __( '% 1$s wrote a new blog post: %2$s', 'buddypress' ), bp_core_get_userlink( (int)$post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );364 $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>' ); 385 365 $activity_content = $post->post_content; 386 366 … … 394 374 'secondary_item_id' => $post_id, 395 375 'recorded_time' => $post->post_date_gmt 396 ) 376 )); 397 377 } 398 } 399 400 bp_blogs_update_blogmeta( $blog_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) ); 401 402 do_action( 'bp_blogs_new_blog_post', $existing_post, $is_private, $is_recorded ); 378 } else 379 bp_blogs_remove_post( $post_id, $blog_id ); 380 381 bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() ); 382 383 do_action( 'bp_blogs_new_blog_post', $post_id, $post, $user_id ); 403 384 } 404 385 add_action( 'save_post', 'bp_blogs_record_post', 10, 2 ); 405 386 387 /** 388 * bp_blogs_record_comment() 389 * 390 * Record blog comment activity. Checks if blog is public and post is not 391 * password protected. 392 * 393 * @global object $wpdb 394 * @global $bp $bp 395 * @param int $comment_id 396 * @param bool $is_approved 397 * @return mixed 398 */ 406 399 function bp_blogs_record_comment( $comment_id, $is_approved = true ) { 407 400 global $wpdb, $bp; … … 436 429 // If blog is public allow activity to be posted 437 430 if ( get_blog_option( $blog_id, 'blog_public' ) ) { 431 438 432 // Get activity related links 439 433 $post_permalink = get_permalink( $recorded_comment->comment_post_ID ); … … 441 435 442 436 // Prepare to record in activity streams 443 $activity_action 444 $activity_content 437 $activity_action = sprintf( __( '%s commented on the blog post %s', 'buddypress' ), bp_core_get_userlink( $user_id ), '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>' ); 438 $activity_content = $recorded_comment->comment_content; 445 439 446 440 // Record in activity streams … … 523 517 add_action( 'remove_user_from_blog', 'bp_blogs_remove_blog_for_user', 10, 2 ); 524 518 525 function bp_blogs_remove_post( $post_id, $blog_id = false , $existing_post = false) {519 function bp_blogs_remove_post( $post_id, $blog_id = false ) { 526 520 global $current_blog, $bp; 527 521 … … 531 525 $blog_id = (int)$current_blog->blog_id; 532 526 533 if ( !$existing_post )534 $existing_post = new BP_Blogs_Post( null, $blog_id, $post_id );535 536 // Delete post from the bp_blogs table537 BP_Blogs_Post::delete( $post_id, $blog_id );538 539 527 // Delete activity stream item 540 528 bp_blogs_delete_activity( array( 'item_id' => $blog_id, 'secondary_item_id' => $post_id, 'component' => $bp->blogs->slug, 'type' => 'new_blog_post' ) ); … … 546 534 function bp_blogs_remove_comment( $comment_id ) { 547 535 global $wpdb, $bp; 548 549 $recorded_comment = new BP_Blogs_Comment( false, $wpdb->blogid, $comment_id );550 BP_Blogs_Comment::delete( $comment_id, $wpdb->blogid );551 536 552 537 // Delete activity stream item … … 585 570 /* If this is regular blog, delete all data for that blog. */ 586 571 BP_Blogs_Blog::delete_blog_for_all( $blog_id ); 587 BP_Blogs_Post::delete_posts_for_blog( $blog_id );588 BP_Blogs_Comment::delete_comments_for_blog( $blog_id );589 572 590 573 // Delete activity stream item … … 599 582 } 600 583 601 /* DEPRECATED - scheduled for removal. Please use the activity stream with a 'new_blog_post' filter. */602 function bp_blogs_get_posts_for_user( $user_id ) {603 return BP_Blogs_Post::get_posts_for_user( $user_id );604 }605 606 /* DEPRECATED - scheduled for removal. Please use the activity stream with a 'new_blog_comment' filter. */607 function bp_blogs_get_comments_for_user( $user_id ) {608 return BP_Blogs_Comment::get_comments_for_user( $user_id );609 }610 611 function bp_blogs_get_latest_posts( $blog_id = null, $limit = 5 ) {612 global $bp;613 614 if ( !is_numeric( $limit ) )615 $limit = 5;616 617 return BP_Blogs_Post::get_latest_posts( $blog_id, $limit );618 }619 620 584 function bp_blogs_get_all_blogs( $limit = null, $page = null ) { 621 585 return BP_Blogs_Blog::get_all( $limit, $page ); … … 626 590 } 627 591 628 function bp_blogs_get_all_posts( $limit = null, $page = null ) {629 return BP_Blogs_Post::get_all( $limit, $page );630 }631 632 function bp_blogs_total_post_count( $blog_id ) {633 return BP_Blogs_Post::total_post_count( $blog_id );634 }635 636 function bp_blogs_total_comment_count( $blog_id, $post_id = false ) {637 return BP_Blogs_Post::total_comment_count( $blog_id, $post_id );638 }639 640 592 function bp_blogs_is_blog_hidden( $blog_id ) { 641 593 return BP_Blogs_Blog::is_hidden( $blog_id ); … … 648 600 $blog = bp_blogs_get_random_blogs( 1, 1 ); 649 601 650 bp_core_redirect( get_ blog_option( $blog['blogs'][0]->blog_id, 'siteurl') );602 bp_core_redirect( get_site_url( $blog['blogs'][0]->blog_id ) ); 651 603 } 652 604 } … … 664 616 global $wpdb, $bp; 665 617 666 if ( !is_numeric( $blog_id ) )618 if ( !is_numeric( $blog_id ) || !bp_core_is_multisite() ) 667 619 return false; 668 620 … … 692 644 $blog_id = (int) $blog_id; 693 645 694 if ( !$blog_id )646 if ( !$blog_id || !bp_core_is_multisite() ) 695 647 return false; 696 648 … … 724 676 global $wpdb, $bp; 725 677 726 if ( !is_numeric( $blog_id ) )678 if ( !is_numeric( $blog_id ) || !bp_core_is_multisite() ) 727 679 return false; 728 680 … … 754 706 755 707 function bp_blogs_remove_data( $user_id ) { 708 if ( !bp_core_is_multisite() ) 709 return false; 710 756 711 /* If this is regular blog, delete all data for that blog. */ 757 712 BP_Blogs_Blog::delete_blogs_for_user( $user_id ); 758 BP_Blogs_Post::delete_posts_for_user( $user_id );759 BP_Blogs_Comment::delete_comments_for_user( $user_id );760 713 761 714 do_action( 'bp_blogs_remove_data', $user_id ); 762 715 } 763 add_action( 'wpmu_delete_user', 'bp_blogs_remove_data', 1 ); 764 add_action( 'delete_user', 'bp_blogs_remove_data', 1 ); 716 add_action( 'wpmu_delete_user', 'bp_blogs_remove_data' ); 717 add_action( 'delete_user', 'bp_blogs_remove_data' ); 718 add_action( 'make_spam_user', 'bp_blogs_remove_data' ); 765 719 766 720 … … 789 743 } 790 744 791 function bp_blogs_clear_post_object_cache( $blog_id, $post_id, $user_id ) {792 wp_cache_delete( 'bp_user_posts_' . $user_id, 'bp' );793 }794 795 function bp_blogs_format_clear_post_cache( $recorded_post_obj ) {796 bp_blogs_clear_post_object_cache( false, false, $recorded_post_obj->user_id );797 798 /* Clear the sitewide activity cache */799 wp_cache_delete( 'sitewide_activity', 'bp' );800 }801 802 function bp_blogs_clear_comment_object_cache( $blog_id, $comment_id, $user_id ) {803 wp_cache_delete( 'bp_user_comments_' . $user_id, 'bp' );804 }805 806 function bp_blogs_format_clear_comment_cache( $recorded_comment_obj ) {807 bp_blogs_clear_comment_object_cache( false, false, $recorded_comment_obj->user_id );808 809 /* Clear the sitewide activity cache */810 wp_cache_delete( 'sitewide_activity', 'bp' );811 }812 813 745 // List actions to clear object caches on 814 746 add_action( 'bp_blogs_remove_blog_for_user', 'bp_blogs_clear_blog_object_cache', 10, 2 ); 815 add_action( 'bp_blogs_remove_post', 'bp_blogs_clear_post_object_cache', 10, 3 );816 add_action( 'bp_blogs_remove_comment', 'bp_blogs_clear_comment_object_cache', 10, 3 );817 818 747 add_action( 'bp_blogs_new_blog', 'bp_blogs_format_clear_blog_cache', 10, 2 ); 819 add_action( 'bp_blogs_new_blog_post', 'bp_blogs_format_clear_post_cache', 10, 2 );820 add_action( 'bp_blogs_new_blog_comment', 'bp_blogs_format_clear_comment_cache', 10, 2 );821 748 822 749 // List actions to clear super cached pages on, if super cache is installed -
trunk/bp-blogs/bp-blogs-classes.php
r3232 r3300 76 76 bp_blogs_setup_globals(); 77 77 78 if ( !is_user_logged_in() || ( !is_s ite_admin() && ( $user_id != $bp->loggedin_user->id ) ) )78 if ( !is_user_logged_in() || ( !is_super_admin() && ( $user_id != $bp->loggedin_user->id ) ) ) 79 79 $hidden_sql = "AND wb.public = 1"; 80 80 … … 162 162 // Show logged in users their hidden blogs. 163 163 if ( !bp_is_my_profile() && !$show_hidden ) 164 $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b. id, bm1.meta_value as name, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND bm1.meta_key = 'name' AND wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ORDER BY b.id", $user_id ) );164 $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id, b.id, bm1.meta_value as name, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND bm1.meta_key = 'name' AND wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ORDER BY b.blog_id", $user_id ) ); 165 165 else 166 $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b. id, bm1.meta_value as name, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND bm1.meta_key = 'name' AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ORDER BY b.id", $user_id ) );166 $blogs = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT b.blog_id, b.id, bm1.meta_value as name, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND bm1.meta_key = 'name' AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ORDER BY b.blog_id", $user_id ) ); 167 167 168 168 $total_blog_count = BP_Blogs_Blog::total_blog_count_for_user( $user_id ); 169 169 170 170 foreach ( (array)$blogs as $blog ) { 171 $user_blogs[$blog->id] = new stdClass; 172 $user_blogs[$blog->id]->id = $blog->id; 173 $user_blogs[$blog->id]->siteurl = ( is_ssl() ) ? 'https://' . $blog->domain . $blog->path : 'http://' . $blog->domain . $blog->path; 174 $user_blogs[$blog->id]->name = $blog->name; 171 $user_blogs[$blog->blog_id] = new stdClass; 172 $user_blogs[$blog->blog_id]->id = $blog->id; 173 $user_blogs[$blog->blog_id]->blog_id = $blog->blog_id; 174 $user_blogs[$blog->blog_id]->siteurl = ( is_ssl() ) ? 'https://' . $blog->domain . $blog->path : 'http://' . $blog->domain . $blog->path; 175 $user_blogs[$blog->blog_id]->name = $blog->name; 175 176 } 176 177 … … 209 210 210 211 // If the user is logged in return the blog count including their hidden blogs. 211 if ( ( is_user_logged_in() && $user_id == $bp->loggedin_user->id ) || is_s ite_admin() )212 if ( ( is_user_logged_in() && $user_id == $bp->loggedin_user->id ) || is_super_admin() ) 212 213 return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id) ); 213 214 else … … 223 224 $filter = like_escape( $wpdb->escape( $filter ) ); 224 225 225 if ( !is_s ite_admin() )226 if ( !is_super_admin() ) 226 227 $hidden_sql = "AND wb.public = 1"; 227 228 … … 241 242 bp_blogs_setup_globals(); 242 243 243 if ( !is_s ite_admin() )244 if ( !is_super_admin() ) 244 245 $hidden_sql = "AND wb.public = 1"; 245 246 … … 261 262 $letter = like_escape( $wpdb->escape( $letter ) ); 262 263 263 if ( !is_s ite_admin() )264 if ( !is_super_admin() ) 264 265 $hidden_sql = "AND wb.public = 1"; 265 266 … … 279 280 return $paged_blogs; 280 281 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 282 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 } 283 $blog_prefix = $wpdb->get_blog_prefix( $paged_blogs[$i]->blog_id ); 284 $paged_blogs[$i]->latest_post = $wpdb->get_row( "SELECT post_title, guid FROM {$blog_prefix}posts WHERE post_status = 'publish' AND post_type = 'post' AND id != 1 ORDER BY id DESC LIMIT 1" ); 290 285 } 291 286 … … 316 311 } 317 312 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 else343 $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 // Update364 $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 // Save367 $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 else378 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 else555 $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 // Update577 $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 // Save580 $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 else591 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 313 ?> -
trunk/bp-blogs/bp-blogs-templatetags.php
r3263 r3300 22 22 23 23 $this->pag_page = isset( $_REQUEST['bpage'] ) ? intval( $_REQUEST['bpage'] ) : $page; 24 $this->pag_num 24 $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page; 25 25 26 26 if ( isset( $_REQUEST['letter'] ) && '' != $_REQUEST['letter'] ) … … 37 37 38 38 if ( $max ) { 39 if ( $max >= count( $this->blogs) ) {39 if ( $max >= count($this->blogs) ) { 40 40 $this->blog_count = count( $this->blogs ); 41 41 } else { … … 148 148 149 149 $blogs_template = new BP_Blogs_Template( $type, $page, $per_page, $max, $user_id, $search_terms ); 150 return $blogs_template->has_blogs();150 return apply_filters( 'bp_has_blogs', $blogs_template->has_blogs(), &$blogs_template ); 151 151 } 152 152 … … 166 166 global $bp, $blogs_template; 167 167 168 $from_num = bp_core_number_format( intval( ( $blogs_template->pag_page - 1 ) * $blogs_template->pag_num ) + 1 ); 169 $to_num = bp_core_number_format( ( $from_num + ( $blogs_template->pag_num - 1 ) > $blogs_template->total_blog_count ) ? $blogs_template->total_blog_count : $from_num + ( $blogs_template->pag_num - 1 ) ); 168 $start_num = intval( ( $blogs_template->pag_page - 1 ) * $blogs_template->pag_num ) + 1; 169 $from_num = bp_core_number_format( $start_num ); 170 $to_num = bp_core_number_format( ( $start_num + ( $blogs_template->pag_num - 1 ) > $blogs_template->total_blog_count ) ? $blogs_template->total_blog_count : $start_num + ( $blogs_template->pag_num - 1 ) ); 170 171 $total = bp_core_number_format( $blogs_template->total_blog_count ); 171 172 172 echo sprintf( __( 'Viewing blog % s to %s (of %s blogs)', 'buddypress' ), $from_num, $to_num, $total ); ?> 173 echo sprintf( __( 'Viewing blog %1$s to %2$s (of %3$s blogs)', 'buddypress' ), $from_num, $to_num, $total ); ?> 173 174 <span class="ajax-loader"></span><?php 174 175 } … … 270 271 function bp_blog_hidden_fields() { 271 272 if ( isset( $_REQUEST['s'] ) ) { 272 echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['s'] ). '" name="search_terms" />';273 echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['s'] ). '" name="search_terms" />'; 273 274 } 274 275 275 276 if ( isset( $_REQUEST['letter'] ) ) { 276 echo '<input type="hidden" id="selected_letter" value="' . attribute_escape( $_REQUEST['letter'] ) . '" name="selected_letter" />';277 echo '<input type="hidden" id="selected_letter" value="' . esc_attr( $_REQUEST['letter'] ) . '" name="selected_letter" />'; 277 278 } 278 279 279 280 if ( isset( $_REQUEST['blogs_search'] ) ) { 280 echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['blogs_search'] ) . '" name="search_terms" />';281 echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['blogs_search'] ) . '" name="search_terms" />'; 281 282 } 282 283 } … … 347 348 348 349 <input type="hidden" name="stage" value="gimmeanotherblog" /> 349 <?php do_action( "signup_hidden_fields"); ?>350 <?php do_action( 'signup_hidden_fields' ); ?> 350 351 351 352 <?php bp_blogs_signup_blog($blogname, $blog_title, $errors); ?> … … 364 365 365 366 // Blog name 366 if( 'no' == constant( "VHOST") )367 if( !is_subdomain_install() ) 367 368 echo '<label for="blogname">' . __('Blog Name:', 'buddypress') . '</label>'; 368 369 else … … 373 374 <?php } 374 375 375 if ( 'no' == constant( "VHOST" ) ) {376 if ( !is_subdomain_install() ) 376 377 echo '<span class="prefix_address">' . $current_site->domain . $current_site->path . '</span> <input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /><br />'; 377 } else {378 else 378 379 echo '<input name="blogname" type="text" id="blogname" value="'.$blogname.'" maxlength="50" /> <span class="suffix_address">.' . $current_site->domain . $current_site->path . '</span><br />'; 379 } 380 380 381 if ( !is_user_logged_in() ) { 381 382 print '(<strong>' . __( 'Your address will be ' , 'buddypress'); 382 if( 'no' == constant( "VHOST" ) ) { 383 384 if ( !is_subdomain_install() ) { 383 385 print $current_site->domain . $current_site->path . __( 'blogname' , 'buddypress'); 384 386 } else { 385 387 print __( 'domain.' , 'buddypress') . $current_site->domain . $current_site->path; 386 388 } 389 387 390 echo '.</strong> ' . __( 'Must be at least 4 characters, letters and numbers only. It cannot be changed so choose carefully!)' , 'buddypress') . '</p>'; 388 391 } … … 476 479 477 480 function bp_blogs_blog_tabs() { 478 global $bp ;481 global $bp, $groups_template; 479 482 480 483 // Don't show these tabs on a user's own profile -
trunk/bp-blogs/bp-blogs-widgets.php
r2698 r3300 22 22 global $bp; 23 23 24 24 extract( $args ); 25 25 26 26 echo $before_widget; 27 echo $before_title 28 . $widget_name 29 . $after_title; ?> 27 echo $before_title . $widget_name . $after_title; 30 28 31 <?php32 29 if ( empty( $instance['max_posts'] ) || !$instance['max_posts'] ) 33 30 $instance['max_posts'] = 10; ?> … … 81 78 ?> 82 79 83 <p><label for="bp-blogs-widget-posts-max"><?php _e('Max posts to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_posts' ); ?>" name="<?php echo $this->get_field_name( 'max_posts' ); ?>" type="text" value="<?php echo attribute_escape( $max_posts ); ?>" style="width: 30%" /></label></p>80 <p><label for="bp-blogs-widget-posts-max"><?php _e('Max posts to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_posts' ); ?>" name="<?php echo $this->get_field_name( 'max_posts' ); ?>" type="text" value="<?php echo esc_attr( $max_posts ); ?>" style="width: 30%" /></label></p> 84 81 <?php 85 82 } -
trunk/bp-core.php
r3242 r3300 30 30 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-catchuri.php' ); 31 31 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-classes.php' ); 32 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-filters.php' ); 32 33 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-cssjs.php' ); 33 34 require ( BP_PLUGIN_DIR . '/bp-core/bp-core-avatars.php' ); … … 65 66 */ 66 67 function bp_core_setup_globals() { 67 global $bp , $wpdb;68 global $bp; 68 69 global $current_user, $current_component, $current_action, $current_blog; 69 70 global $displayed_user_id, $bp_pages; … … 72 73 $current_user = wp_get_current_user(); 73 74 75 /* Get the base database prefix */ 76 $bp->table_prefix = bp_core_get_table_prefix(); 77 74 78 /* The domain for the root of the site where the main blog resides */ 75 79 $bp->root_domain = bp_core_get_root_domain(); 76 77 /* Contains an array of all the active components. The key is the slug, value the internal ID of the component */78 $bp->active_components = array();79 80 80 81 /* The names of the core WordPress pages used to display BuddyPress content */ … … 95 96 $bp->loggedin_user->userdata = bp_core_get_core_userdata( $bp->loggedin_user->id ); 96 97 97 /* is_site_admin() hits the DB on single WP installs, so we need to get this separately so we can call it in a loop. */ 98 $bp->loggedin_user->is_site_admin = is_site_admin(); 98 /* is_super_admin() hits the DB on single WP installs, so we need to get this separately so we can call it in a loop. */ 99 $bp->loggedin_user->is_super_admin = is_super_admin(); 100 $bp->loggedin_user->is_site_admin = $bp->loggedin_user->is_super_admin; // deprecated 1.2.6 99 101 100 102 /* The user id of the user currently being viewed, set in /bp-core/bp-core-catchuri.php */ … … 141 143 $bp->bp_options_nav = array(); 142 144 145 /* Contains an array of all the active components. The key is the slug, value the internal ID of the component */ 146 $bp->active_components = array(); 147 143 148 /* Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar */ 144 $bp->grav_default->user = apply_filters( 'bp_user_gravatar_default', $bp->site_options['user-avatar-default'] );149 $bp->grav_default->user = apply_filters( 'bp_user_gravatar_default', $bp->site_options['user-avatar-default'] ); 145 150 $bp->grav_default->group = apply_filters( 'bp_group_gravatar_default', 'identicon' ); 146 $bp->grav_default->blog = apply_filters( 'bp_blog_gravatar_default', 'identicon' );151 $bp->grav_default->blog = apply_filters( 'bp_blog_gravatar_default', 'identicon' ); 147 152 148 153 /* Fetch the full name for the logged in and current user */ 149 $bp->loggedin_user->fullname = bp_core_get_user_displayname( $bp->loggedin_user->id );154 $bp->loggedin_user->fullname = bp_core_get_user_displayname( $bp->loggedin_user->id ); 150 155 $bp->displayed_user->fullname = bp_core_get_user_displayname( $bp->displayed_user->id ); 151 156 … … 154 159 generic variable so it can be used by other components. It can also be modified, so when viewing a group 155 160 'is_item_admin' would be 1 if they are a group admin, 0 if they are not. */ 156 $bp->is_item_admin = bp_ is_my_profile();161 $bp->is_item_admin = bp_user_has_access(); 157 162 158 163 /* Used to determine if the logged in user is a moderator for the current content. */ 159 164 $bp->is_item_mod = false; 160 165 161 $bp->core->table_name_notifications = $ wpdb->base_prefix . 'bp_notifications';166 $bp->core->table_name_notifications = $bp->table_prefix . 'bp_notifications'; 162 167 163 168 if ( !$bp->current_component && $bp->displayed_user->id ) … … 169 174 170 175 /** 176 * bp_core_get_table_prefix() 177 * 178 * Allow filtering of database prefix. Intended for use in multinetwork installations. 179 * 180 * @global object $wpdb WordPress database object 181 * @return string Filtered database prefix 182 */ 183 function bp_core_get_table_prefix() { 184 global $wpdb; 185 186 return apply_filters( 'bp_core_get_table_prefix', $wpdb->base_prefix ); 187 } 188 189 /** 171 190 * bp_core_define_slugs() 172 191 * … … 188 207 if ( !defined( 'BP_ACTIVATION_SLUG' ) ) 189 208 define( 'BP_ACTIVATION_SLUG', $bp->pages->activate->slug ); 209 210 if ( !defined( 'BP_SEARCH_SLUG' ) ) 211 define( 'BP_SEARCH_SLUG', 'search' ); 190 212 } 191 213 add_action( 'bp_setup_globals', 'bp_core_define_slugs' ); … … 231 253 } 232 254 233 234 255 /** 235 256 * bp_core_admin_menu_init() … … 238 259 * 239 260 * @package BuddyPress Core 240 * @uses is_s ite_admin() returns true if the current user is a site admin, false if not261 * @uses is_super_admin() returns true if the current user is a site admin, false if not 241 262 */ 242 263 function bp_core_admin_menu_init() { 243 if ( !is_s ite_admin() )264 if ( !is_super_admin() ) 244 265 return false; 245 266 … … 255 276 * @package BuddyPress Core 256 277 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 257 * @global $wpdb WordPress DB access object. 258 * @uses is_site_admin() returns true if the current user is a site admin, false if not 278 * @uses is_super_admin() returns true if the current user is a site admin, false if not 259 279 * @uses add_submenu_page() WP function to add a submenu item 260 280 */ 261 281 function bp_core_add_admin_menu() { 262 if ( !is_s ite_admin() )282 if ( !is_super_admin() ) 263 283 return false; 264 284 … … 280 300 add_action( 'admin_menu', 'bp_core_add_admin_menu' ); 281 301 302 /** 303 * bp_core_is_root_component() 304 * 305 * Checks to see if a component's URL should be in the root, not under a member page: 306 * eg: http://domain.com/groups/the-group NOT http://domain.com/members/andy/groups/the-group 307 * 308 * @package BuddyPress Core 309 * @return true if root component, else false. 310 */ 311 function bp_core_is_root_component( $component_name ) { 312 global $bp; 313 314 foreach ( (array) $bp->pages as $key => $page ) { 315 if ( $key == $component_name || $page->slug == $component_name ) 316 return true; 317 } 318 319 return false; 320 } 282 321 283 322 /** … … 380 419 */ 381 420 function bp_core_action_set_spammer_status() { 382 global $bp, $wpdb ;383 384 if ( !is_s ite_admin() || bp_is_my_profile() || !$bp->displayed_user->id )421 global $bp, $wpdb, $wp_version; 422 423 if ( !is_super_admin() || bp_is_my_profile() || !$bp->displayed_user->id ) 385 424 return false; 386 425 … … 390 429 391 430 /* Get the functions file */ 392 if ( file_exists( ABSPATH . 'wp-admin/includes/mu.php' ) &&bp_core_is_multisite() )393 require ( ABSPATH . 'wp-admin/includes/mu.php' );431 if ( bp_core_is_multisite() ) 432 require_once( ABSPATH . 'wp-admin/includes/ms.php' ); 394 433 395 434 if ( 'mark-spammer' == $bp->current_action ) … … 446 485 global $bp; 447 486 448 if ( !is_s ite_admin() || bp_is_my_profile() || !$bp->displayed_user->id )487 if ( !is_super_admin() || bp_is_my_profile() || !$bp->displayed_user->id ) 449 488 return false; 450 489 … … 462 501 } 463 502 464 do_action( 'bp_core_action_ set_spammer_status', $errors );503 do_action( 'bp_core_action_delete_user', $errors ); 465 504 466 505 if ( $errors ) … … 472 511 add_action( 'wp', 'bp_core_action_delete_user', 3 ); 473 512 513 474 514 /******************************************************************************** 475 515 * Business Functions … … 496 536 'search_terms' => false, // Limit to users that match these search terms 497 537 538 'include' => false, // Pass comma separated list of user_ids to limit to only these users 498 539 'per_page' => 20, // The number of results to return per page 499 540 'page' => 1, // The page to return if limiting per page … … 504 545 extract( $params, EXTR_SKIP ); 505 546 506 return apply_filters( 'bp_core_get_users', BP_Core_User::get_users( $type, $per_page, $page, $user_id, $ search_terms, $populate_extras ), &$params );547 return apply_filters( 'bp_core_get_users', BP_Core_User::get_users( $type, $per_page, $page, $user_id, $include, $search_terms, $populate_extras ), &$params ); 507 548 } 508 549 … … 516 557 * @global $current_user WordPress global variable containing current logged in user information 517 558 * @param user_id The ID of the user. 518 * @uses get_user meta() WordPress function to get the usermeta for a user.559 * @uses get_user_meta() WordPress function to get the usermeta for a user. 519 560 */ 520 561 function bp_core_get_user_domain( $user_id, $user_nicename = false, $user_login = false ) { … … 574 615 575 616 if ( defined( 'BP_ENABLE_MULTIBLOG' ) ) 576 $domain = get_blog_option( $current_blog->blog_id, ' siteurl' );617 $domain = get_blog_option( $current_blog->blog_id, 'home' ); 577 618 else 578 $domain = get_blog_option( BP_ROOT_BLOG, ' siteurl' );619 $domain = get_blog_option( BP_ROOT_BLOG, 'home' ); 579 620 580 621 return apply_filters( 'bp_core_get_root_domain', $domain ); … … 626 667 627 668 /* If this is for site admins only and the user is not one, don't create the subnav item */ 628 if ( $site_admin_only && !is_s ite_admin() )669 if ( $site_admin_only && !is_super_admin() ) 629 670 return false; 630 671 … … 647 688 * looking at their own profile, don't create the nav item. 648 689 */ 649 if ( !$show_for_displayed_user && !bp_ is_my_profile() )690 if ( !$show_for_displayed_user && !bp_user_has_access() ) 650 691 return false; 651 692 … … 654 695 * default subnav function so we can display a directory or something else. 655 696 */ 656 if ( !$bp->displayed_user->id )697 if ( bp_core_is_root_component( $slug ) && !$bp->displayed_user->id ) 657 698 return; 658 699 … … 773 814 774 815 /* If this is for site admins only and the user is not one, don't create the subnav item */ 775 if ( $site_admin_only && !is_s ite_admin() )816 if ( $site_admin_only && !is_super_admin() ) 776 817 return false; 777 818 … … 868 909 global $bp; 869 910 870 if ( $function = $bp->bp_options_nav[$parent_id][$slug]['screen_function'] ) { 871 if ( !is_object( $function[0] ) ) 872 remove_action( 'wp', $function, 3 ); 911 $screen_function = $bp->bp_options_nav[$parent_id][$slug]['screen_function']; 912 913 if ( $screen_function ) { 914 if ( !is_object( $screen_function[0] ) ) 915 remove_action( 'wp', $screen_function, 3 ); 873 916 else 874 remove_action( 'wp', array( &$ function[0], $function[1] ), 3 );917 remove_action( 'wp', array( &$screen_function[0], $screen_function[1] ), 3 ); 875 918 } 876 919 … … 898 941 /** 899 942 * bp_core_get_random_member() 943 * 944 * Returns the user_id for a user based on their username. 945 * 946 * @package BuddyPress Core 947 * @param $username str Username to check. 948 * @return false on no match 949 * @return int the user ID of the matched user. 950 */ 951 function bp_core_get_random_member() { 952 global $bp; 953 954 if ( isset( $_GET['random-member'] ) ) { 955 $user = bp_core_get_users( array( 'type' => 'random', 'per_page' => 1 ) ); 956 bp_core_redirect( bp_core_get_user_domain( $user['users'][0]->id ) ); 957 } 958 } 959 add_action( 'wp', 'bp_core_get_random_member' ); 960 961 /** 962 * bp_core_get_userid() 900 963 * 901 964 * Returns the user_id for a user based on their username. … … 907 970 * @return int the user ID of the matched user. 908 971 */ 909 function bp_core_get_random_member() {910 global $bp, $wpdb;911 912 if ( isset( $_GET['random-member'] ) ) {913 $user = bp_core_get_users( array( 'type' => 'random', 'per_page' => 1 ) );914 bp_core_redirect( bp_core_get_user_domain( $user['users'][0]->id ) );915 }916 }917 add_action( 'wp', 'bp_core_get_random_member' );918 919 /**920 * bp_core_get_userid()921 *922 * Returns the user_id for a user based on their username.923 *924 * @package BuddyPress Core925 * @param $username str Username to check.926 * @global $wpdb WordPress DB access object.927 * @return false on no match928 * @return int the user ID of the matched user.929 */930 972 function bp_core_get_userid( $username ) { 931 973 global $wpdb; 932 974 933 if ( !empty( $username ) ) 934 return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ) ); 975 if ( empty( $username ) ) 976 return false; 977 978 return apply_filters( 'bp_core_get_userid', $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . CUSTOM_USER_TABLE . " WHERE user_login = %s", $username ) ) ); 935 979 } 936 980 … … 1119 1163 } 1120 1164 1121 return apply_filters( 'bp_core_get_user_displayname', $fullname );1165 return apply_filters( 'bp_core_get_user_displayname', $fullname, $user_id ); 1122 1166 } 1123 1167 add_filter( 'bp_core_get_user_displayname', 'strip_tags', 1 ); … … 1215 1259 1216 1260 /** 1217 * bp_core_format_time() 1218 */ 1219 function bp_core_format_time( $time, $just_date = false ) { 1220 if ( !$time ) 1221 return false; 1222 1223 $date = date( "F j, Y ", $time ); 1224 1225 if ( !$just_date ) { 1226 $date .= __('at', 'buddypress') . date( ' g:iA', $time ); 1227 } 1228 1229 return $date; 1261 * bp_core_current_time() 1262 * 1263 * Get the current GMT time to save into the DB 1264 * 1265 * @package BuddyPress Core 1266 * @since 1.2.6 1267 */ 1268 function bp_core_current_time( $gmt = true ) { 1269 // Get current time in MYSQL format 1270 $current_time = current_time( 'mysql', $gmt ); 1271 1272 return apply_filters( 'bp_core_current_time', $current_time ); 1230 1273 } 1231 1274 … … 1283 1326 @setcookie( 'bp-message-type', false, time() - 1000, COOKIEPATH ); 1284 1327 } 1285 add_action( 'bp_init', 'bp_core_setup_message' ); 1286 1328 add_action( 'wp', 'bp_core_setup_message', 2 ); 1287 1329 1288 1330 /** … … 1302 1344 ?> 1303 1345 <div id="message" class="<?php echo $type; ?>"> 1304 <p><?php echo stripslashes( attribute_escape( $bp->template_message ) ); ?></p>1346 <p><?php echo stripslashes( esc_attr( $bp->template_message ) ); ?></p> 1305 1347 </div> 1306 1348 <?php … … 1326 1368 */ 1327 1369 function bp_core_time_since( $older_date, $newer_date = false ) { 1370 1328 1371 // array of time period chunks 1329 1372 $chunks = array( 1330 array( 60 * 60 * 24 * 365 , __( 'year', 'buddypress' ), __( 'years', 'buddypress' ) ),1331 array( 60 * 60 * 24 * 30 , __( 'month', 'buddypress' ), __( 'months', 'buddypress' ) ),1332 array( 60 * 60 * 24 * 7, __( 'week', 'buddypress' ), __( 'weeks', 'buddypress' ) ),1333 array( 60 * 60 * 24 , __( 'day', 'buddypress' ), __( 'days', 'buddypress' ) ),1334 array( 60 * 60 , __( 'hour', 'buddypress' ), __( 'hours', 'buddypress' ) ),1335 array( 60 , __( 'minute', 'buddypress' ), __( 'minutes', 'buddypress' ) ),1336 array( 1, __( 'second', 'buddypress' ), __( 'seconds', 'buddypress' ) )1373 array( 60 * 60 * 24 * 365 , __( 'year', 'buddypress' ), __( 'years', 'buddypress' ) ), 1374 array( 60 * 60 * 24 * 30 , __( 'month', 'buddypress' ), __( 'months', 'buddypress' ) ), 1375 array( 60 * 60 * 24 * 7, __( 'week', 'buddypress' ), __( 'weeks', 'buddypress' ) ), 1376 array( 60 * 60 * 24 , __( 'day', 'buddypress' ), __( 'days', 'buddypress' ) ), 1377 array( 60 * 60 , __( 'hour', 'buddypress' ), __( 'hours', 'buddypress' ) ), 1378 array( 60 , __( 'minute', 'buddypress' ), __( 'minutes', 'buddypress' ) ), 1379 array( 1, __( 'second', 'buddypress' ), __( 'seconds', 'buddypress' ) ) 1337 1380 ); 1338 1381 … … 1346 1389 /* $newer_date will equal false if we want to know the time elapsed between a date and the current time */ 1347 1390 /* $newer_date will have a value if we want to work out time elapsed between two known dates */ 1348 $newer_date = ( !$newer_date ) ? gmmktime( gmdate( 'H' ), gmdate( 'i' ), gmdate( 's' ), gmdate( 'n' ), gmdate( 'j' ), gmdate( 'Y') ) : $newer_date;1391 $newer_date = ( !$newer_date ) ? strtotime( bp_core_current_time() ) : $newer_date; 1349 1392 1350 1393 /* Difference in seconds */ … … 1381 1424 if ( ( $count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 ) ) != 0 ) { 1382 1425 /* Add to output var */ 1383 $output .= ( 1 == $count2 ) ? _ c( ',|Separator in time since', 'buddypress' ) . ' 1 '. $chunks[$i + 1][1] : _c( ',|Separator in time since', 'buddypress' ) . ' ' . $count2 . ' ' . $chunks[$i + 1][2];1426 $output .= ( 1 == $count2 ) ? _x( ',', 'Separator in time since', 'buddypress' ) . ' 1 '. $chunks[$i + 1][1] : _x( ',', 'Separator in time since', 'buddypress' ) . ' ' . $count2 . ' ' . $chunks[$i + 1][2]; 1384 1427 } 1385 1428 } … … 1401 1444 * @package BuddyPress Core 1402 1445 * @global $userdata WordPress user data for the current logged in user. 1403 * @uses update_user meta() WordPress function to update user metadata in the usermeta table.1446 * @uses update_user_meta() WordPress function to update user metadata in the usermeta table. 1404 1447 */ 1405 1448 function bp_core_record_activity() { … … 1409 1452 return false; 1410 1453 1411 $activity = get_user meta( $bp->loggedin_user->id, 'last_activity');1454 $activity = get_user_meta( $bp->loggedin_user->id, 'last_activity', true ); 1412 1455 1413 1456 if ( !is_numeric( $activity ) ) 1414 1457 $activity = strtotime( $activity ); 1415 1458 1416 if ( '' == $activity || strtotime( gmdate( "Y-m-d H:i:s" ) ) >= strtotime( '+5 minutes', $activity ) ) 1417 update_usermeta( $bp->loggedin_user->id, 'last_activity', gmdate( "Y-m-d H:i:s" ) ); 1459 // Get current time 1460 $current_time = bp_core_current_time(); 1461 1462 if ( '' == $activity || strtotime( $current_time ) >= strtotime( '+5 minutes', $activity ) ) 1463 update_user_meta( $bp->loggedin_user->id, 'last_activity', $current_time ); 1418 1464 } 1419 1465 add_action( 'wp_head', 'bp_core_record_activity' ); … … 1446 1492 return $number; 1447 1493 1448 return apply_filters( 'bp_core_ bp_core_number_format', number_format( $number, $decimals ), $number, $decimals );1494 return apply_filters( 'bp_core_number_format', number_format( $number, $decimals ), $number, $decimals ); 1449 1495 } 1450 1496 … … 1474 1520 * 1475 1521 * @package BuddyPress Core 1476 * @global $comment WordPress comment global for the current comment. 1477 * @uses bp_core_get_userlink_by_email() Fetches a userlink via email address. 1522 * 1523 * @global $bp $bp 1524 * @global object $current_site 1525 * @return string 1478 1526 */ 1479 1527 function bp_core_get_site_path() { … … 1493 1541 unset( $site_path[2] ); 1494 1542 1495 $site_path = '/' . implode( '/', $site_path ) . '/'; 1543 if ( !count( $site_path ) ) 1544 $site_path = '/'; 1545 else 1546 $site_path = '/' . implode( '/', $site_path ) . '/'; 1496 1547 } 1497 1548 } … … 1536 1587 1537 1588 if ( bp_core_is_multisite() ) 1538 $meta = $wpdb->get_results( "SELECT meta_key AS name, meta_value AS value FROM {$wpdb->sitemeta} WHERE meta_key IN ({$meta_keys}) " );1589 $meta = $wpdb->get_results( "SELECT meta_key AS name, meta_value AS value FROM {$wpdb->sitemeta} WHERE meta_key IN ({$meta_keys}) AND site_id = {$wpdb->siteid}" ); 1539 1590 else 1540 1591 $meta = $wpdb->get_results( "SELECT option_name AS name, option_value AS value FROM {$wpdb->options} WHERE option_name IN ({$meta_keys})" ); … … 1563 1614 1564 1615 // Make sure we don't call status_header() in bp_core_do_catch_uri() 1565 1616 // as this conflicts with wp_redirect() 1566 1617 $bp_no_status_set = true; 1567 1618 … … 1616 1667 1617 1668 /** 1618 * bp_core_email_from_name_filter()1619 *1620 * Sets the "From" name in emails sent to the name of the site and not "WordPress"1621 *1622 * @package BuddyPress Core1623 * @uses get_blog_option() fetches the value for a meta_key in the wp_X_options table1624 * @return The blog name for the root blog1625 */1626 function bp_core_email_from_name_filter() {1627 return apply_filters( 'bp_core_email_from_name_filter', get_blog_option( BP_ROOT_BLOG, 'blogname' ) );1628 }1629 add_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' );1630 1631 1632 /**1633 * bp_core_email_from_name_filter()1634 *1635 * Sets the "From" address in emails sent1636 *1637 * @package BuddyPress Core1638 * @global $current_site Object containing current site metadata1639 * @return noreply@sitedomain email address1640 */1641 function bp_core_email_from_address_filter() {1642 $domain = (array) explode( '/', site_url() );1643 1644 return apply_filters( 'bp_core_email_from_address_filter', __( 'noreply', 'buddypress' ) . '@' . $domain[2] );1645 }1646 add_filter( 'wp_mail_from', 'bp_core_email_from_address_filter' );1647 1648 /**1649 1669 * bp_core_delete_account() 1650 1670 * … … 1653 1673 * @package BuddyPress Core 1654 1674 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() 1655 * @uses is_s ite_admin() Checks to see if the user is a site administrator.1675 * @uses is_super_admin() Checks to see if the user is a site administrator. 1656 1676 * @uses wpmu_delete_user() Deletes a user from the system on multisite installs. 1657 1677 * @uses wp_delete_user() Deletes a user from the system on singlesite installs. … … 1744 1764 function bp_core_ucfirst( $str ) { 1745 1765 if ( function_exists( 'mb_strtoupper' ) && function_exists( 'mb_substr' ) ) { 1746 1747 1766 $fc = mb_strtoupper( mb_substr( $str, 0, 1 ) ); 1767 return $fc.mb_substr( $str, 1 ); 1748 1768 } else { 1749 1769 return ucfirst( $str ); … … 1792 1812 */ 1793 1813 function bp_core_print_generation_time() { 1794 global $wpdb; 1795 ?> 1814 ?> 1796 1815 1797 1816 <!-- Generated in <?php timer_stop(1); ?> seconds. (<?php echo get_num_queries(); ?> q) --> … … 1866 1885 $user = get_userdatabylogin( $username ); 1867 1886 1868 if ( ( int)$user->spam)1887 if ( ( bp_core_is_multisite() && (int)$user->spam ) || 1 == (int)$user->user_status ) 1869 1888 bp_core_redirect( $bp->root_domain ); 1870 1889 else … … 1880 1899 * @package BuddyPress Core 1881 1900 * @param $user_id The user id for the user to delete usermeta for 1882 * @uses delete_user meta() deletes a row from the wp_usermeta table based on meta_key1901 * @uses delete_user_meta() deletes a row from the wp_usermeta table based on meta_key 1883 1902 */ 1884 1903 function bp_core_remove_data( $user_id ) { 1885 1904 /* Remove usermeta */ 1886 delete_user meta( $user_id, 'last_activity' );1905 delete_user_meta( $user_id, 'last_activity' ); 1887 1906 1888 1907 /* Flush the cache to remove the user from all cached objects */ 1889 1908 wp_cache_flush(); 1890 1909 } 1891 add_action( 'wpmu_delete_user', 'bp_core_remove_data' , 1);1892 add_action( 'delete_user', 'bp_core_remove_data' , 1);1893 add_action( 'make_spam_user', 'bp_core_remove_data' , 1);1910 add_action( 'wpmu_delete_user', 'bp_core_remove_data' ); 1911 add_action( 'delete_user', 'bp_core_remove_data' ); 1912 add_action( 'make_spam_user', 'bp_core_remove_data' ); 1894 1913 1895 1914 /** … … 1907 1926 load_textdomain( 'buddypress', $mofile ); 1908 1927 } 1909 add_action ( ' plugins_loaded', 'bp_core_load_buddypress_textdomain', 5);1928 add_action ( 'bp_loaded', 'bp_core_load_buddypress_textdomain', 2 ); 1910 1929 1911 1930 function bp_core_add_ajax_hook() { … … 1929 1948 1930 1949 /** 1931 * bp_core_filter_parent_theme()1932 *1933 * Remove social network parent theme from the theme list.1934 *1935 * @package BuddyPress Core1936 */1937 function bp_core_filter_parent_theme() {1938 global $wp_themes, $pagenow;1939 1940 if ( is_admin() && 'themes.php' == $pagenow )1941 $wp_themes = get_themes();1942 1943 unset( $wp_themes['BuddyPress Classic Parent'] );1944 }1945 add_filter( 'admin_menu', 'bp_core_filter_parent_theme' );1946 1947 /**1948 * bp_core_allow_default_theme()1949 *1950 * On multiblog installations you must first allow themes to be activated and show1951 * up on the theme selection screen. This function will let the BuddyPress bundled1952 * themes show up on the root blog selection screen and bypass this step. It also1953 * means that the themes won't show for selection on other blogs.1954 *1955 * @package BuddyPress Core1956 */1957 function bp_core_allow_default_theme( $themes ) {1958 global $bp, $current_blog;1959 1960 if ( !is_site_admin() )1961 return $themes;1962 1963 if ( $current_blog->ID == $bp->root_blog ) {1964 $themes['bp-default'] = 1;1965 $themes['bp-classic'] = 1;1966 }1967 1968 return $themes;1969 }1970 add_filter( 'allowed_themes', 'bp_core_allow_default_theme' );1971 1972 /**1973 1950 * bp_core_activation_notice() 1974 1951 * … … 1985 1962 return false; 1986 1963 1987 if ( !is_s ite_admin() )1964 if ( !is_super_admin() ) 1988 1965 return false; 1989 1966 … … 2011 1988 add_action( 'admin_notices', 'bp_core_activation_notice' ); 2012 1989 2013 2014 /** 2015 * bp_core_filter_comments() 2016 * 2017 * Filter the blog post comments array and insert BuddyPress URLs for users. 2018 * 2019 * @package BuddyPress Core 2020 */ 2021 function bp_core_filter_comments( $comments, $post_id ) { 2022 global $wpdb; 2023 2024 foreach( (array)$comments as $comment ) { 2025 if ( $comment->user_id ) 2026 $user_ids[] = $comment->user_id; 2027 } 2028 2029 if ( empty( $user_ids ) ) 2030 return $comments; 2031 2032 $user_ids = implode( ',', $user_ids ); 2033 2034 if ( !$userdata = $wpdb->get_results( $wpdb->prepare( "SELECT ID as user_id, user_login, user_nicename FROM {$wpdb->users} WHERE ID IN ({$user_ids})" ) ) ) 2035 return $comments; 2036 2037 foreach( (array)$userdata as $user ) 2038 $users[$user->user_id] = bp_core_get_user_domain( $user->user_id, $user->user_nicename, $user->user_login ); 2039 2040 foreach( (array)$comments as $i => $comment ) { 2041 if ( !empty( $comment->user_id ) ) { 2042 if ( !empty( $users[$comment->user_id] ) ) 2043 $comments[$i]->comment_author_url = $users[$comment->user_id]; 1990 /** 1991 * bp_core_activate_site_options() 1992 * 1993 * When switching from single to multisite we need to copy blog options to 1994 * site options. 1995 * 1996 * @package BuddyPress Core 1997 */ 1998 function bp_core_activate_site_options( $keys = array() ) { 1999 global $bp; 2000 2001 if ( !empty( $keys ) && is_array( $keys ) ) { 2002 $errors = false; 2003 2004 foreach ( $keys as $key => $default ) { 2005 if ( empty( $bp->site_options[ $key ] ) ) { 2006 $bp->site_options[ $key ] = get_blog_option( BP_ROOT_BLOG, $key, $default ); 2007 2008 if ( !update_site_option( $key, $bp->site_options[ $key ] ) ) 2009 $errors = true; 2010 } 2044 2011 } 2045 } 2046 2047 return $comments; 2048 } 2049 add_filter( 'comments_array', 'bp_core_filter_comments', 10, 2 ); 2050 2051 2052 /** 2053 * bp_core_login_redirect() 2054 * 2055 * When a user logs in, always redirect them back to the previous page. NOT the admin area. 2056 * 2057 * @package BuddyPress Core 2058 */ 2059 function bp_core_login_redirect( $redirect_to ) { 2060 global $bp, $current_blog; 2061 2062 if ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG ) 2063 return $redirect_to; 2064 2065 if ( !empty( $_REQUEST['redirect_to'] ) || strpos( $_REQUEST['redirect_to'], 'wp-admin' ) ) 2066 return $redirect_to; 2067 2068 if ( false === strpos( wp_get_referer(), 'wp-login.php' ) && false === strpos( wp_get_referer(), 'activate' ) && empty( $_REQUEST['nr'] ) ) 2069 return wp_get_referer(); 2070 2071 return $bp->root_domain; 2072 } 2073 add_filter( 'login_redirect', 'bp_core_login_redirect' ); 2074 2012 2013 if ( empty( $errors ) ) 2014 return true; 2015 } 2016 2017 return false; 2018 } 2075 2019 2076 2020 /******************************************************************************** … … 2080 2024 * hook in to. 2081 2025 */ 2082 2083 /* Allow core components and dependent plugins to set globals */ 2026 2027 /** 2028 * bp_include() 2029 * 2030 * Allow plugins to include their files ahead of core filters 2031 */ 2032 function bp_include() { 2033 do_action( 'bp_include' ); 2034 } 2035 add_action( 'bp_loaded', 'bp_include', 2 ); 2036 2037 /** 2038 * bp_setup_root_components() 2039 * 2040 * Allow core components and dependent plugins to set root components 2041 */ 2042 function bp_setup_root_components() { 2043 do_action( 'bp_setup_root_components' ); 2044 } 2045 add_action( 'bp_loaded', 'bp_setup_root_components', 2 ); 2046 2047 /** 2048 * bp_setup_globals() 2049 * 2050 * Allow core components and dependent plugins to set globals 2051 */ 2084 2052 function bp_setup_globals() { 2085 2053 do_action( 'bp_setup_globals' ); 2086 2054 } 2087 add_action( 'plugins_loaded', 'bp_setup_globals', 5 ); 2088 2089 /* Allow core components and dependent plugins to set root components */ 2090 function bp_setup_root_components() { 2091 do_action( 'bp_setup_root_components' ); 2092 } 2093 add_action( 'plugins_loaded', 'bp_setup_root_components', 2 ); 2094 2095 /* Allow core components and dependent plugins to set their nav */ 2055 add_action( 'bp_loaded', 'bp_setup_globals', 6 ); 2056 2057 /** 2058 * bp_setup_nav() 2059 * 2060 * Allow core components and dependent plugins to set their nav 2061 */ 2096 2062 function bp_setup_nav() { 2097 2063 do_action( 'bp_setup_nav' ); … … 2099 2065 add_action( 'bp_loaded', 'bp_setup_nav', 8 ); 2100 2066 2101 /* Allow core components and dependent plugins to register widgets */ 2067 /** 2068 * bp_setup_widgets() 2069 * 2070 * Allow core components and dependent plugins to register widgets 2071 */ 2102 2072 function bp_setup_widgets() { 2103 2073 do_action( 'bp_register_widgets' ); 2104 2074 } 2105 add_action( 'plugins_loaded', 'bp_setup_widgets' ); 2075 add_action( 'bp_loaded', 'bp_setup_widgets', 8 ); 2076 2077 /** 2078 * bp_init() 2079 * 2080 * Allow components to initialize themselves cleanly 2081 */ 2082 function bp_init() { 2083 do_action( 'bp_init' ); 2084 } 2085 add_action( 'bp_loaded', 'bp_init' ); 2106 2086 2107 2087 … … 2112 2092 * actions throughout BuddyPress. 2113 2093 */ 2094 2095 /** 2096 * bp_core_add_global_group() 2097 * 2098 * Add's 'bp' to global group of network wide cachable objects 2099 * 2100 * @package BuddyPress Core 2101 */ 2102 function bp_core_add_global_group() { 2103 wp_cache_init(); 2104 2105 if ( function_exists( 'wp_cache_add_global_groups' ) ) 2106 wp_cache_add_global_groups( array( 'bp' ) ); 2107 } 2108 add_action( 'init', 'bp_core_add_global_group' ); 2114 2109 2115 2110 /** … … 2184 2179 update_site_option( 'bp-pages', $page_ids ); 2185 2180 } 2186 2187 function bp_core_is_root_component( $component_name ) {2188 global $bp;2189 2190 foreach ( (array) $bp->pages as $key => $page ) {2191 if ( $key == $component_name || $page->slug == $component_name )2192 return true;2193 }2194 2195 return false;2196 }2197 2198 2181 ?> -
trunk/bp-core/bp-core-adminbar.php
r3232 r3300 109 109 } 110 110 111 echo '<li id="bp-adminbar-blogs-menu"><a href="' . $bp->loggedin_user->domain . $bp->blogs->slug . '/ my-blogs">';111 echo '<li id="bp-adminbar-blogs-menu"><a href="' . $bp->loggedin_user->domain . $bp->blogs->slug . '/">'; 112 112 113 113 _e( 'My Blogs', 'buddypress' ); -
trunk/bp-core/bp-core-avatars.php
r3232 r3300 479 479 function bp_core_fetch_avatar_filter( $avatar, $user, $size, $default, $alt ) { 480 480 global $pagenow; 481 481 482 482 // Do not filter if inside WordPress options page 483 483 if ( 'options-discussion.php' == $pagenow ) 484 484 return $avatar; 485 485 486 486 // If passed an object, assume $user->user_id 487 487 if ( is_object( $user ) ) -
trunk/bp-core/bp-core-catchuri.php
r3234 r3300 43 43 } 44 44 45 // Ajax or not? 45 46 if ( strpos( $_SERVER['REQUEST_URI'], 'wp-load.php' ) ) 46 47 $path = bp_core_referrer(); 47 48 else 48 $path = clean_url( $_SERVER['REQUEST_URI'] );49 $path = esc_url( $_SERVER['REQUEST_URI'] ); 49 50 50 51 $path = apply_filters( 'bp_uri', $path ); 51 52 52 // Firstly, take GET variables off the URL to avoid problems,53 // they are still registered in the global $_GET variable */53 // Take GET variables off the URL to avoid problems, 54 // they are still registered in the global $_GET variable 54 55 $noget = substr( $path, 0, strpos( $path, '?' ) ); 55 if ( $noget != '' ) $path = $noget; 56 57 /* Fetch the current URI and explode each part separated by '/' into an array */ 56 if ( $noget != '' ) 57 $path = $noget; 58 59 // Fetch the current URI and explode each part separated by '/' into an array 58 60 $bp_uri = explode( "/", $path ); 59 61 60 / * Loop and remove empties */62 // Loop and remove empties 61 63 foreach ( (array)$bp_uri as $key => $uri_chunk ) 62 64 if ( empty( $bp_uri[$key] ) ) unset( $bp_uri[$key] ); 63 65 64 if ( defined( 'BP_ENABLE_MULTIBLOG' ) || 1 != BP_ROOT_BLOG ) { 65 /* If we are running BuddyPress on any blog, not just a root blog, we need to first 66 shift off the blog name if we are running a subdirectory install of WPMU. */ 67 if ( $current_blog->path != '/' ) 68 array_shift( $bp_uri ); 69 } 70 71 /* Set the indexes, these are incresed by one if we are not on a VHOST install */ 72 $component_index = 0; 73 $action_index = $component_index + 1; 74 75 /* Get site path items */ 66 // Running off blog other than root 67 if ( defined( 'BP_ENABLE_MULTIBLOG' ) || 1 != BP_ROOT_BLOG ) { 68 69 // Any subdirectory names must be removed from $bp_uri. 70 // This includes two cases: (1) when WP is installed in a subdirectory, 71 // and (2) when BP is running on secondary blog of a subdirectory 72 // multisite installation. Phew! 73 if ( $chunks = explode( '/', $current_blog->path ) ) { 74 foreach( $chunks as $key => $chunk ) { 75 $bkey = array_search( $chunk, $bp_uri ); 76 77 if ( $bkey !== false ) 78 unset( $bp_uri[$bkey] ); 79 80 $bp_uri = array_values( $bp_uri ); 81 } 82 } 83 } 84 85 // Set the indexes, these are incresed by one if we are not on a VHOST install 86 $component_index = 0; 87 $action_index = $component_index + 1; 88 89 // Get site path items 76 90 $paths = explode( '/', bp_core_get_site_path() ); 77 91 78 / * Take empties off the end of path */92 // Take empties off the end of path 79 93 if ( empty( $paths[count($paths) - 1] ) ) 80 94 array_pop( $paths ); 81 95 82 / * Take empties off the start of path */96 // Take empties off the start of path 83 97 if ( empty( $paths[0] ) ) 84 98 array_shift( $paths ); … … 90 104 } 91 105 92 / * Reset the keys by merging with an empty array */93 $bp_uri 94 $bp_unfiltered_uri = $bp_uri;95 96 / * Find a match within registered BuddyPress controlled WP pages (check members first) */106 // Reset the keys by merging with an empty array 107 $bp_uri = array_merge( array(), $bp_uri ); 108 $bp_unfiltered_uri = $bp_uri; 109 110 // Find a match within registered BuddyPress controlled WP pages (check members first) 97 111 foreach ( (array)$bp_pages as $page_key => $bp_page ) { 98 112 if ( in_array( $bp_page->name, (array)$bp_uri ) ) { 99 / * Match found, now match the slug to make sure. */113 // Match found, now match the slug to make sure. 100 114 $uri_chunks = explode( '/', $bp_page->slug ); 101 115 … … 120 134 } 121 135 122 / * This is not a BuddyPress page, so just return. */136 // This is not a BuddyPress page, so just return. 123 137 if ( in_array( 0, (array) $matches ) ) 124 138 return false; 125 139 126 / * Find the offset */140 // Find the offset 127 141 $uri_offset = 0; 128 142 $slug = explode( '/', $match->slug ); … … 133 147 } 134 148 135 / * Global the unfiltered offset to use in bp_core_load_template() */149 // Global the unfiltered offset to use in bp_core_load_template() 136 150 $bp_unfiltered_uri_offset = $uri_offset; 137 151 138 / * This is a members page so lets check if we have a displayed member */152 // This is a members page so lets check if we have a displayed member 139 153 if ( 'members' == $match->key ) { 140 154 if ( !empty( $bp_uri[$uri_offset + 1] ) ) { … … 146 160 $uri_offset = $uri_offset + 2; 147 161 148 / * Remove everything from the URI up to the offset and take it from there. */162 // Remove everything from the URI up to the offset and take it from there. 149 163 for ( $i = 0; $i < $uri_offset; $i++ ) 150 164 unset( $bp_uri[$i] ); … … 154 168 } 155 169 156 / * Reset the keys by merging with an empty array */170 // Reset the keys by merging with an empty array 157 171 $bp_uri = array_merge( array(), $bp_uri ); 158 172 159 / * Set the current component */173 // Set the current component 160 174 if ( empty( $current_component ) ) { 161 175 for ( $i = 0; $i <= $uri_offset; $i++ ) { … … 170 184 $i = 1; 171 185 172 / * Set the current action */186 // Set the current action 173 187 $current_action = $bp_uri[$i]; 174 188 175 / * Unset the current_component and action from action_variables */189 // Unset the current_component and action from action_variables 176 190 for ( $j = 0; $j <= $i; $j++ ) 177 191 unset( $bp_uri[$j] ); 178 192 179 / * Set the entire URI as the action variables, we will unset the current_component and action in a second */193 // Set the entire URI as the action variables, we will unset the current_component and action in a second 180 194 $action_variables = $bp_uri; 181 195 182 / * Remove the username from action variables if this is not a VHOST install */196 // Remove the username from action variables if this is not a VHOST install 183 197 if ( 'no' == VHOST && !$is_root_component ) 184 198 array_shift($bp_uri); 185 199 186 / * Reset the keys by merging with an empty array */200 // Reset the keys by merging with an empty array 187 201 $action_variables = array_merge( array(), $action_variables ); 188 189 //var_dump($current_component, $current_action, $bp_uri);190 202 } 191 add_action( ' plugins_loaded', 'bp_core_set_uri_globals', 3);203 add_action( 'bp_loaded', 'bp_core_set_uri_globals', 4 ); 192 204 193 205 /** -
trunk/bp-core/bp-core-classes.php
r3267 r3300 51 51 * @uses bp_core_get_userlink() Returns a HTML formatted link for a user with the user's full name as the link text 52 52 * @uses bp_core_get_user_email() Returns the email address for the user based on user ID 53 * @uses get_user meta() WordPress function returns the value of passed usermeta name from usermeta table53 * @uses get_user_meta() WordPress function returns the value of passed usermeta name from usermeta table 54 54 * @uses bp_core_fetch_avatar() Returns HTML formatted avatar for a user 55 55 * @uses bp_profile_last_updated_date() Returns the last updated date for a user. … … 61 61 if ( $this->profile_data ) { 62 62 $this->user_url = bp_core_get_user_domain( $this->id, $this->profile_data['user_nicename'], $this->profile_data['user_login'] ); 63 $this->fullname = attribute_escape( $this->profile_data[BP_XPROFILE_FULLNAME_FIELD_NAME]['field_data'] );63 $this->fullname = esc_attr( $this->profile_data[BP_XPROFILE_FULLNAME_FIELD_NAME]['field_data'] ); 64 64 $this->user_link = "<a href='{$this->user_url}' title='{$this->fullname}'>{$this->fullname}</a>"; 65 $this->email = attribute_escape( $this->profile_data['user_email'] );65 $this->email = esc_attr( $this->profile_data['user_email'] ); 66 66 } else { 67 67 $this->user_url = bp_core_get_user_domain( $this->id ); 68 68 $this->user_link = bp_core_get_userlink( $this->id ); 69 $this->fullname = attribute_escape( bp_core_get_user_displayname( $this->id ) );70 $this->email = attribute_escape( bp_core_get_user_email( $this->id ) );69 $this->fullname = esc_attr( bp_core_get_user_displayname( $this->id ) ); 70 $this->email = esc_attr( bp_core_get_user_email( $this->id ) ); 71 71 } 72 72 … … 80 80 $this->avatar_mini = bp_core_fetch_avatar( array( 'item_id' => $this->id, 'type' => 'thumb', 'width' => 30, 'height' => 30 ) ); 81 81 82 $this->last_active = bp_core_get_last_activity( get_user meta( $this->id, 'last_activity'), __( 'active %s ago', 'buddypress' ) );82 $this->last_active = bp_core_get_last_activity( get_user_meta( $this->id, 'last_activity', true ), __( 'active %s ago', 'buddypress' ) ); 83 83 } 84 84 … … 107 107 /* Static Functions */ 108 108 109 function get_users( $type, $limit = null, $page = 1, $user_id = false, $ search_terms = false, $populate_extras = true ) {109 function get_users( $type, $limit = null, $page = 1, $user_id = false, $include = false, $search_terms = false, $populate_extras = true ) { 110 110 global $wpdb, $bp; 111 111 112 112 $sql = array(); 113 113 114 $sql['select_main'] = "SELECT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.display_name, u.user_email";114 $sql['select_main'] = "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.display_name, u.user_email"; 115 115 116 116 if ( 'active' == $type || 'online' == $type ) … … 125 125 $sql['from'] = "FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN " . CUSTOM_USER_META_TABLE . " um ON um.user_id = u.ID"; 126 126 127 if ( $search_terms && function_exists( 'xprofile_install' ) || 'alphabetical' == $type ) 128 $sql['join_profiledata'] = "LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id"; 129 127 130 $sql['where'] = 'WHERE ' . bp_core_get_status_sql( 'u.' ); 128 131 … … 134 137 135 138 if ( 'online' == $type ) 136 $sql['where_online'] = "AND DATE_ADD( um.meta_value, INTERVAL 5 MINUTE ) >= NOW()";139 $sql['where_online'] = "AND DATE_ADD( um.meta_value, INTERVAL 5 MINUTE ) >= UTC_TIMESTAMP()"; 137 140 138 141 if ( 'alphabetical' == $type ) 139 142 $sql['where_alpha'] = "AND pd.field_id = 1"; 140 143 141 if ( $user_id && function_exists( 'friends_install' ) ) { 144 if ( $include ) { 145 if ( is_array( $include ) ) 146 $uids = $wpdb->escape( implode( ',', (array)$include ) ); 147 else 148 $uids = $wpdb->escape( $include ); 149 150 if ( !empty( $uids ) ) 151 $sql['where_users'] = "AND u.ID IN ({$uids})"; 152 } 153 154 else if ( $user_id && function_exists( 'friends_install' ) ) { 142 155 $friend_ids = friends_get_friend_user_ids( $user_id ); 143 156 $friend_ids = $wpdb->escape( implode( ',', (array)$friend_ids ) ); … … 151 164 } 152 165 153 if ( $search_terms ) {166 if ( $search_terms && function_exists( 'xprofile_install' ) ) { 154 167 $search_terms = like_escape( $wpdb->escape( $search_terms ) ); 155 $sql['where_searchterms'] = "AND u.display_name LIKE '%%$search_terms%%'";168 $sql['where_searchterms'] = "AND pd.value LIKE '%%$search_terms%%'"; 156 169 } 157 170 … … 164 177 break; 165 178 case 'alphabetical': 166 $sql[] = "ORDER BY u.display_name ASC";179 $sql[] = "ORDER BY pd.value ASC"; 167 180 break; 168 181 case 'random': … … 178 191 179 192 /* Get paginated results */ 180 $paged_users = $wpdb->get_results( join( ' ', (array)$sql ) ); 193 $paged_users_sql = apply_filters( 'bp_core_get_paged_users_sql', join( ' ', (array)$sql ), $sql ); 194 $paged_users = $wpdb->get_results( $paged_users_sql ); 181 195 182 196 /* Re-jig the SQL so we can get the total user count */ … … 198 212 199 213 /* Get total user results */ 200 $total_users = $wpdb->get_var( join( ' ', (array)$sql ) ); 214 $total_users_sql = apply_filters( 'bp_core_get_total_users_sql', join( ' ', (array)$sql ), $sql ); 215 $total_users = $wpdb->get_var( $total_users_sql ); 201 216 202 217 /*** … … 223 238 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 224 239 225 if ( strlen($letter) > 1 || is_numeric($letter) || !$letter ) 226 return false; 240 // Multibyte compliance 241 if ( function_exists( 'mb_strlen' ) ) { 242 if ( mb_strlen( $letter, 'UTF-8' ) > 1 || is_numeric( $letter ) || !$letter ) { 243 return false; 244 } 245 } else { 246 if ( strlen( $letter ) > 1 || is_numeric( $letter ) || !$letter ) { 247 return false; 248 } 249 } 227 250 228 251 $letter = like_escape( $wpdb->escape( $letter ) ); … … 318 341 /* Fetch the user's full name */ 319 342 if ( bp_is_active( 'xprofile' ) && 'alphabetical' != $type ) { 343 /* Ensure xprofile globals are set */ 344 if ( !defined( 'BP_XPROFILE_FULLNAME_FIELD_NAME' ) ) 345 xprofile_setup_globals(); 346 320 347 $names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id as id, pd.value as fullname FROM {$bp->profile->table_name_fields} pf, {$bp->profile->table_name_data} pd WHERE pf.id = pd.field_id AND pf.name = %s AND pd.user_id IN ( {$user_ids} )", BP_XPROFILE_FULLNAME_FIELD_NAME ) ); 321 348 for ( $i = 0; $i < count( $paged_users ); $i++ ) { … … 436 463 if ( $this->id ) { 437 464 // Update 438 $sql = $wpdb->prepare( "UPDATE {$bp->core->table_name_notifications} SET item_id = %d, secondary_item_id = %d, user_id = %d, component_name = %s, component_action = %d, date_notified = FROM_UNIXTIME(%d), is_new = %d ) WHERE id = %d", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new, $this->id );465 $sql = $wpdb->prepare( "UPDATE {$bp->core->table_name_notifications} SET item_id = %d, secondary_item_id = %d, user_id = %d, component_name = %s, component_action = %d, date_notified = %s, is_new = %d ) WHERE id = %d", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new, $this->id ); 439 466 } else { 440 467 // Save 441 $sql = $wpdb->prepare( "INSERT INTO {$bp->core->table_name_notifications} ( item_id, secondary_item_id, user_id, component_name, component_action, date_notified, is_new ) VALUES ( %d, %d, %d, %s, %s, FROM_UNIXTIME(%d), %d )", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new );468 $sql = $wpdb->prepare( "INSERT INTO {$bp->core->table_name_notifications} ( item_id, secondary_item_id, user_id, component_name, component_action, date_notified, is_new ) VALUES ( %d, %d, %d, %s, %s, %s, %d )", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new ); 442 469 } 443 470 -
trunk/bp-core/bp-core-cssjs.php
r3280 r3300 39 39 <style type="text/css"> 40 40 ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image a { background-image: url( <?php echo BP_PLUGIN_URL . '/bp-core/images/admin_menu_icon.png' ?> ) !important; background-position: -1px -32px; } 41 ul#adminmenu li.toplevel_page_bp-general-settings:hover .wp-menu-image a { background-position: -1px 0; }41 ul#adminmenu li.toplevel_page_bp-general-settings:hover .wp-menu-image a, ul#adminmenu li.toplevel_page_bp-general-settings.wp-has-current-submenu .wp-menu-image a { background-position: -1px 0; } 42 42 ul#adminmenu li.toplevel_page_bp-general-settings .wp-menu-image a img { display: none; } 43 43 </style> … … 50 50 global $current_blog; 51 51 52 if ( $current_blog->blog_id != BP_ROOT_BLOG )52 if ( bp_core_is_multisite() && $current_blog->blog_id != BP_ROOT_BLOG ) 53 53 return false; 54 54 ?> … … 83 83 global $bp; 84 84 85 $image = apply_filters( 'bp_inline_cropper_image', getimagesize( $bp->avatar_admin->image->dir ) );85 $image = apply_filters( 'bp_inline_cropper_image', getimagesize( BP_AVATAR_UPLOAD_PATH . $bp->avatar_admin->image->dir ) ); 86 86 $aspect_ratio = 1; 87 87 88 / * Calculate Aspect Ratio */88 // Calculate Aspect Ratio 89 89 if ( (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) && ( (int) constant( 'BP_AVATAR_FULL_WIDTH' ) != (int) constant( 'BP_AVATAR_FULL_HEIGHT' ) ) ) 90 90 $aspect_ratio = (int) constant( 'BP_AVATAR_FULL_WIDTH' ) / (int) constant( 'BP_AVATAR_FULL_HEIGHT' ); -
trunk/bp-core/bp-core-filters.php
r2941 r3300 33 33 */ 34 34 function bp_core_email_from_name_filter() { 35 return apply_filters( 'bp_core_email_from_name_filter', get_blog_option( BP_ROOT_BLOG, 'blogname') );35 return apply_filters( 'bp_core_email_from_name_filter', wp_specialchars_decode( get_blog_option( BP_ROOT_BLOG, 'blogname' ), ENT_QUOTES ) ); 36 36 } 37 37 add_filter( 'wp_mail_from_name', 'bp_core_email_from_name_filter' ); … … 66 66 global $bp, $current_blog; 67 67 68 if ( !is_s ite_admin() )68 if ( !is_super_admin() ) 69 69 return $themes; 70 70 … … 142 142 * Replace the generated password in the welcome email. 143 143 * This will not filter when the site admin registers a user. 144 * 145 * @uses locate_template To see if custom registration files exist 146 * @param string $welcome_email Complete email passed through WordPress 147 * @return string Filtered $welcome_email with 'PASSWORD' replaced by [User Set] 144 148 */ 145 149 function bp_core_filter_user_welcome_email( $welcome_email ) { … … 148 152 return $welcome_email; 149 153 154 // [User Set] Replaces 'PASSWORD' in welcome email; Represents value set by user 150 155 return str_replace( 'PASSWORD', __( '[User Set]', 'buddypress' ), $welcome_email ); 151 156 } … … 158 163 * Replace the generated password in the welcome email. 159 164 * This will not filter when the site admin registers a user. 165 * 166 * @uses locate_template To see if custom registration files exist 167 * @param string $welcome_email Complete email passed through WordPress 168 * @param integer $blog_id ID of the blog user is joining 169 * @param integer $user_id ID of the user joining 170 * @param string $password Password of user 171 * @return string Filtered $welcome_email with $password replaced by [User Set] 160 172 */ 161 173 function bp_core_filter_blog_welcome_email( $welcome_email, $blog_id, $user_id, $password ) { … … 164 176 return $welcome_email; 165 177 178 // [User Set] Replaces $password in welcome email; Represents value set by user 166 179 return str_replace( $password, __( '[User Set]', 'buddypress' ), $welcome_email ); 167 180 } … … 175 188 // Send email with activation link. 176 189 $activate_url = bp_get_activation_page() ."?key=$key"; 177 $activate_url = clean_url($activate_url);190 $activate_url = esc_url($activate_url); 178 191 179 192 $admin_email = get_site_option( "admin_email" ); … … 184 197 $from_name = ( '' == get_site_option( "site_name" ) ) ? 'WordPress' : wp_specialchars( get_site_option( "site_name" ) ); 185 198 $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; 186 $message = sprintf(__("Thanks for registering! To complete the activation of your account and blog, please click the following link:\n\n%1$s\n\n\n\nAfter you activate, you can visit your blog here:\n\n%2$s", 'buddypress' ), $activate_url, clean_url("http://{$domain}{$path}" ) );187 $subject = '[' . $from_name . '] ' . sprintf(__('Activate %s', 'buddypress' ), clean_url('http://' . $domain . $path));199 $message = sprintf(__("Thanks for registering! To complete the activation of your account and blog, please click the following link:\n\n%1$s\n\n\n\nAfter you activate, you can visit your blog here:\n\n%2$s", 'buddypress' ), $activate_url, esc_url("http://{$domain}{$path}" ) ); 200 $subject = '[' . $from_name . '] ' . sprintf(__('Activate %s', 'buddypress' ), esc_url('http://' . $domain . $path)); 188 201 189 202 /* Send the message */ … … 204 217 205 218 $activate_url = bp_get_activation_page() ."?key=$key"; 206 $activate_url = clean_url($activate_url);219 $activate_url = esc_url($activate_url); 207 220 $admin_email = get_site_option( "admin_email" ); 208 221 … … 216 229 $from_name = ( '' == get_site_option( "site_name" ) ) ? 'WordPress' : wp_specialchars( get_site_option( "site_name" ) ); 217 230 $message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n"; 218 $message = sprintf( __( "Thanks for registering! To complete the activation of your account please click the following link:\n\n%s\n\n", 'buddypress' ), $activate_url . $email, clean_url("http://{$domain}{$path}" ) );231 $message = sprintf( __( "Thanks for registering! To complete the activation of your account please click the following link:\n\n%s\n\n", 'buddypress' ), $activate_url . $email, esc_url( "http://{$domain}{$path}" ) ); 219 232 $subject = '[' . $from_name . '] ' . __( 'Activate Your Account', 'buddypress' ); 220 233 -
trunk/bp-core/bp-core-notifications.php
r2576 r3300 5 5 6 6 if ( !$date_notified ) 7 $date_notified = time();7 $date_notified = bp_core_current_time(); 8 8 9 9 $notification = new BP_Core_Notification; -
trunk/bp-core/bp-core-settings.php
r2717 r3300 22 22 bp_core_new_subnav_item( array( 'name' => __( 'Notifications', 'buddypress' ), 'slug' => 'notifications', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bp_core_screen_notification_settings', 'position' => 20, 'user_has_access' => bp_is_my_profile() ) ); 23 23 24 if ( !is_s ite_admin() && !(int) $bp->site_options['bp-disable-account-deletion'] )24 if ( !is_super_admin() && !(int) $bp->site_options['bp-disable-account-deletion'] ) 25 25 bp_core_new_subnav_item( array( 'name' => __( 'Delete Account', 'buddypress' ), 'slug' => 'delete-account', 'parent_url' => $settings_link, 'parent_slug' => $bp->settings->slug, 'screen_function' => 'bp_core_screen_delete_account', 'position' => 90, 'user_has_access' => bp_is_my_profile() ) ); 26 26 } 27 add_action( 'wp', 'bp_core_add_settings_nav', 2 ); 28 add_action( 'admin_menu', 'bp_core_add_settings_nav', 2 ); 27 add_action( 'bp_setup_nav', 'bp_core_add_settings_nav' ); 29 28 30 29 /**** GENERAL SETTINGS ****/ … … 88 87 <form action="<?php echo $bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/general' ?>" method="post" class="standard-form" id="settings-form"> 89 88 <label for="email"><?php _e( 'Account Email', 'buddypress' ) ?></label> 90 <input type="text" name="email" id="email" value="<?php echo attribute_escape( $current_user->user_email ); ?>" class="settings-input" />89 <input type="text" name="email" id="email" value="<?php echo esc_attr( $current_user->user_email ); ?>" class="settings-input" /> 91 90 92 91 <label for="pass1"><?php _e( 'Change Password <span>(leave blank for no change)</span>', 'buddypress' ) ?></label> … … 95 94 96 95 <div class="submit"> 97 <input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto" /></p>96 <input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto" /> 98 97 </div> 99 98 … … 115 114 if ( $_POST['notifications'] ) { 116 115 foreach ( (array)$_POST['notifications'] as $key => $value ) { 117 update_user meta( (int)$current_user->id, $key, $value );116 update_user_meta( (int)$current_user->id, $key, $value ); 118 117 } 119 118 } … … 148 147 149 148 <div class="submit"> 150 <input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto" /></p>149 <input type="submit" name="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?>" id="submit" class="auto" /> 151 150 </div> 152 151 … … 190 189 191 190 <div class="submit"> 192 <input type="submit" disabled="disabled" value="<?php _e( 'Delete My Account', 'buddypress' ) ?> →" id="delete-account-button" name="delete-account-button" /> </p>191 <input type="submit" disabled="disabled" value="<?php _e( 'Delete My Account', 'buddypress' ) ?> →" id="delete-account-button" name="delete-account-button" /> 193 192 </div> 194 193 -
trunk/bp-core/bp-core-signup.php
r3277 r3300 181 181 182 182 /* Make sure we include the jQuery jCrop file for image cropping */ 183 add_action( 'wp ', 'bp_core_add_jquery_cropper' );183 add_action( 'wp_print_scripts', 'bp_core_add_jquery_cropper' ); 184 184 } 185 185 } -
trunk/bp-core/bp-core-templatetags.php
r3286 r3300 30 30 $this->members = BP_Core_User::get_specific_users( $include, $this->pag_num, $this->pag_page, $populate_extras ); 31 31 else 32 $this->members = bp_core_get_users( array( 'type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, ' search_terms' => $search_terms, 'populate_extras' => $populate_extras ) );32 $this->members = bp_core_get_users( array( 'type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'include' => $include, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras ) ); 33 33 34 34 if ( !$max || $max >= (int)$this->members['total'] ) … … 126 126 $search_terms = false; 127 127 128 / * User filtering */128 // User filtering 129 129 if ( !empty( $bp->displayed_user->id ) ) 130 130 $user_id = $bp->displayed_user->id; 131 131 132 / * Pass a filter if ?s= is set. */133 if ( $_REQUEST['s'])132 // Pass a filter if ?s= is set. 133 if ( isset( $_REQUEST['s'] ) && !empty( $_REQUEST['s'] ) ) 134 134 $search_terms = $_REQUEST['s']; 135 135 … … 157 157 } 158 158 159 / * Make sure we return no members if we looking at friendship requests and there are none. */159 // Make sure we return no members if we looking at friendship requests and there are none. 160 160 if ( empty( $include ) && $bp->friends->slug == $bp->current_component && 'requests' == $bp->current_action ) 161 161 return false; 162 162 163 163 $members_template = new BP_Core_Members_Template( $type, $page, $per_page, $max, $user_id, $search_terms, $include, (bool)$populate_extras ); 164 165 return $members_template->has_members(); 164 return apply_filters( 'bp_has_members', $members_template->has_members(), &$members_template ); 166 165 } 167 166 … … 182 181 global $bp, $members_template; 183 182 184 $from_num = bp_core_number_format( intval( ( $members_template->pag_page - 1 ) * $members_template->pag_num ) + 1 ); 185 $to_num = bp_core_number_format( ( $from_num + ( $members_template->pag_num - 1 ) > $members_template->total_member_count ) ? $members_template->total_member_count : $from_num + ( $members_template->pag_num - 1) ); 183 $start_num = intval( ( $members_template->pag_page - 1 ) * $members_template->pag_num ) + 1; 184 $from_num = bp_core_number_format( $start_num ); 185 $to_num = bp_core_number_format( ( $start_num + ( $members_template->pag_num - 1 ) > $members_template->total_member_count ) ? $members_template->total_member_count : $start_num + ( $members_template->pag_num - 1 ) ); 186 186 $total = bp_core_number_format( $members_template->total_member_count ); 187 187 … … 195 195 $pag = sprintf( __( 'Viewing member %1$s to %2$s (of %3$s members)', 'buddypress' ), $from_num, $to_num, $total ); 196 196 197 return apply_filters( 'bp_members_pagination_count', $pag );197 return apply_filters( 'bp_members_pagination_count', $pag . '<span class="ajax-loader"></span>' ); 198 198 } 199 199 … … 207 207 } 208 208 209 /** 210 * bp_member_user_id() 211 * 212 * Echo id from bp_get_member_user_id() 213 * 214 * @uses bp_get_member_user_id() 215 */ 209 216 function bp_member_user_id() { 210 217 echo bp_get_member_user_id(); 211 218 } 219 /** 220 * bp_get_member_user_id() 221 * 222 * Get the id of the user in a members loop 223 * 224 * @global object $members_template 225 * @return string Members id 226 */ 212 227 function bp_get_member_user_id() { 213 228 global $members_template; … … 215 230 return apply_filters( 'bp_get_member_user_id', $members_template->member->id ); 216 231 } 232 233 /** 234 * bp_member_user_nicename() 235 * 236 * Echo nicename from bp_get_member_user_nicename() 237 * 238 * @uses bp_get_member_user_nicename() 239 */ 240 function bp_member_user_nicename() { 241 echo bp_get_member_user_nicename(); 242 } 243 /** 244 * bp_get_member_user_nicename() 245 * 246 * Get the nicename of the user in a members loop 247 * 248 * @global object $members_template 249 * @return string Members nicename 250 */ 251 function bp_get_member_user_nicename() { 252 global $members_template; 253 return apply_filters( 'bp_get_member_user_nicename', $members_template->member->user_nicename ); 254 } 255 256 /** 257 * bp_member_user_login() 258 * 259 * Echo login from bp_get_member_user_login() 260 * 261 * @uses bp_get_member_user_login() 262 */ 263 function bp_member_user_login() { 264 echo bp_get_member_user_login(); 265 } 266 /** 267 * bp_get_member_user_login() 268 * 269 * Get the login of the user in a members loop 270 * 271 * @global object $members_template 272 * @return string Members login 273 */ 274 function bp_get_member_user_login() { 275 global $members_template; 276 return apply_filters( 'bp_get_member_user_login', $members_template->member->user_login ); 277 } 278 279 /** 280 * bp_member_user_email() 281 * 282 * Echo email address from bp_get_member_user_email() 283 * 284 * @uses bp_get_member_user_email() 285 */ 286 function bp_member_user_email() { 287 echo bp_get_member_user_email(); 288 } 289 /** 290 * bp_get_member_user_email() 291 * 292 * Get the email address of the user in a members loop 293 * 294 * @global object $members_template 295 * @return string Members email address 296 */ 297 function bp_get_member_user_email() { 298 global $members_template; 299 return apply_filters( 'bp_get_member_user_email', $members_template->member->user_email ); 300 } 301 302 function bp_member_is_loggedin_user() { 303 global $bp, $members_template; 304 return apply_filters( 'bp_member_is_loggedin_user', $bp->loggedin_user->id == $members_template->member->id ? true : false ); 305 } 217 306 218 307 function bp_member_avatar( $args = '' ) { … … 315 404 316 405 // Populate the user if it hasn't been already. 317 if ( empty( $members_template->member->profile_data ) )318 $members_template->member = new BP_Core_User( $members_template->member->id );406 if ( empty( $members_template->member->profile_data ) && method_exists( 'BP_XProfile_ProfileData', 'get_all_for_user' ) ) 407 $members_template->member->profile_data = BP_XProfile_ProfileData::get_all_for_user( $members_template->member->id ); 319 408 320 409 $data = xprofile_format_profile_field( $members_template->member->profile_data[$field]['field_type'], $members_template->member->profile_data[$field]['field_data'] ); … … 329 418 global $members_template; 330 419 331 $registered = attribute_escape( bp_core_get_last_activity( $members_template->member->user_registered, __( 'registered %s ago', 'buddypress' ) ) );420 $registered = esc_attr( bp_core_get_last_activity( $members_template->member->user_registered, __( 'registered %s ago', 'buddypress' ) ) ); 332 421 333 422 return apply_filters( 'bp_member_last_active', $registered ); … … 346 435 function bp_member_hidden_fields() { 347 436 if ( isset( $_REQUEST['s'] ) ) { 348 echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['s'] ) . '" name="search_terms" />';437 echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['s'] ) . '" name="search_terms" />'; 349 438 } 350 439 351 440 if ( isset( $_REQUEST['letter'] ) ) { 352 echo '<input type="hidden" id="selected_letter" value="' . attribute_escape( $_REQUEST['letter'] ) . '" name="selected_letter" />';441 echo '<input type="hidden" id="selected_letter" value="' . esc_attr( $_REQUEST['letter'] ) . '" name="selected_letter" />'; 353 442 } 354 443 355 444 if ( isset( $_REQUEST['members_search'] ) ) { 356 echo '<input type="hidden" id="search_terms" value="' . attribute_escape( $_REQUEST['members_search'] ) . '" name="search_terms" />';445 echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['members_search'] ) . '" name="search_terms" />'; 357 446 } 358 447 } … … 367 456 ?> 368 457 <form action="" method="get" id="search-members-form"> 369 <label><input type="text" name="s" id="members_search" value="<?php echo attribute_escape( $search_value ) ?>" onfocus="if (this.value == '<?php _e( 'Search anything...', 'buddypress' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search anything...', 'buddypress' ) ?>';}" /></label>458 <label><input type="text" name="s" id="members_search" value="<?php echo esc_attr( $search_value ) ?>" onfocus="if (this.value == '<?php _e( 'Search anything...', 'buddypress' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search anything...', 'buddypress' ) ?>';}" /></label> 370 459 <input type="submit" id="members_search_submit" name="members_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" /> 371 460 </form> … … 517 606 $bp->bp_options_title = __( 'Options', 'buddypress' ); 518 607 519 echo apply_filters( 'bp_get_options_title', attribute_escape( $bp->bp_options_title ) );608 echo apply_filters( 'bp_get_options_title', esc_attr( $bp->bp_options_title ) ); 520 609 } 521 610 … … 575 664 576 665 $defaults = array( 577 'type' => 'thumb', 578 'width' => false, 579 'height' => false 666 'type' => 'thumb', 667 'width' => false, 668 'height' => false, 669 'html' => true 580 670 ); 581 671 … … 583 673 extract( $r, EXTR_SKIP ); 584 674 585 return apply_filters( 'bp_get_loggedin_user_avatar', bp_core_fetch_avatar( array( 'item_id' => $bp->loggedin_user->id, 'type' => $type, 'width' => $width, 'height' => $height ) ) );675 return apply_filters( 'bp_get_loggedin_user_avatar', bp_core_fetch_avatar( array( 'item_id' => $bp->loggedin_user->id, 'type' => $type, 'width' => $width, 'height' => $height, 'html' => $html ) ) ); 586 676 } 587 677 … … 593 683 594 684 $defaults = array( 595 'type' => 'thumb', 596 'width' => false, 597 'height' => false 685 'type' => 'thumb', 686 'width' => false, 687 'height' => false, 688 'html' => true 598 689 ); 599 690 … … 601 692 extract( $r, EXTR_SKIP ); 602 693 603 return apply_filters( 'bp_get_displayed_user_avatar', bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => $type, 'width' => $width, 'height' => $height ) ) );694 return apply_filters( 'bp_get_displayed_user_avatar', bp_core_fetch_avatar( array( 'item_id' => $bp->displayed_user->id, 'type' => $type, 'width' => $width, 'height' => $height, 'html' => $html ) ) ); 604 695 } 605 696 … … 641 732 } 642 733 643 function bp_is_my_profile() {644 global $bp;645 646 if ( is_user_logged_in() && $bp->loggedin_user->id == $bp->displayed_user->id )647 return true;648 649 return false;650 }651 function bp_is_home() { return bp_is_my_profile(); }652 653 function bp_get_loggedin_user_link() {654 global $bp;655 656 return $bp->loggedin_user->domain;657 }658 659 function bp_get_displayed_user_link() {660 global $bp;661 662 return $bp->displayed_user->domain;663 }664 665 function bp_last_activity( $user_id = false, $echo = true ) {666 global $bp;667 668 if ( !$user_id )669 $user_id = $bp->displayed_user->id;670 671 $last_activity = bp_core_get_last_activity( get_usermeta( $user_id, 'last_activity' ), __('active %s ago', 'buddypress') );672 673 if ( $echo )674 echo apply_filters( 'bp_last_activity', $last_activity );675 else676 return apply_filters( 'bp_last_activity', $last_activity );677 }678 679 function bp_user_firstname() {680 echo bp_get_user_firstname();681 }682 function bp_get_user_firstname( $name = false ) {683 global $bp;684 685 if ( !$name )686 $name = $bp->loggedin_user->fullname;687 688 $fullname = (array)explode( ' ', $name );689 690 return apply_filters( 'bp_get_user_firstname', $fullname[0], $fullname );691 }692 693 function bp_user_link() {694 global $bp;695 696 echo apply_filters( 'bp_the_avatar_thumbnail', $bp->displayed_user->domain );697 }698 699 734 function bp_core_get_wp_profile() { 700 735 global $bp; … … 706 741 <h4><?php _e( 'My Profile' ) ?></h4> 707 742 708 <table class="wp-profile-fields ">743 <table class="wp-profile-fields zebra"> 709 744 <?php if ( $ud->display_name ) { ?> 710 745 <tr id="wp_displayname"> … … 784 819 785 820 function bp_format_time( $time, $just_date = false ) { 786 $date = date( get_option('date_format'), $time ); 787 821 if ( !$time ) 822 return false; 823 824 // Get GMT offset from root blog 825 $root_blog_offset = get_blog_option( BP_ROOT_BLOG, 'gmt_offset' ); 826 827 // Calculate offset time 828 $time_offset = $time + ( $root_blog_offset * 3600 ); 829 830 // Current date (January 1, 2010) 831 $date = date( 'F j, Y ', $time_offset ); 832 833 // Should we show the time also? 788 834 if ( !$just_date ) { 789 $date .= ' ' . __( 'at', 'buddypress' ) . date( ' ' . get_option('time_format'), $time ); 835 // Current time (9:50pm) 836 $time = date( ' g:ia', $time_offset ); 837 838 // Return string formatted with date and time 839 $date = sprintf( __( '%1$s at %2$s', 'buddypress' ), $date, $time ); 790 840 } 791 841 … … 833 883 } 834 884 835 function bp_loggedinuser_link() {836 global $bp;837 838 if ( $link = bp_core_get_userlink( $bp->loggedin_user->id ) ) {839 echo apply_filters( 'bp_loggedinuser_link', $link );840 }841 }842 843 885 function bp_get_plugin_sidebar() { 844 886 locate_template( array( 'plugin-sidebar.php' ), true ); 845 887 } 846 888 847 function bp_is_blog_page() {848 global $bp, $is_member_page, $wp_query;849 850 if ( $wp_query->is_home && !$bp->is_directory )851 return true;852 853 if ( !$bp->displayed_user->id && !$bp->is_single_item && !$bp->is_directory && !bp_core_is_root_component( $bp->current_component ) )854 return true;855 856 return false;857 }858 859 889 function bp_page_title() { 860 890 echo bp_get_page_title(); … … 864 894 global $bp, $post, $wp_query, $current_blog; 865 895 866 if ( is_front_page() || !bp_current_component() ||( is_home() && bp_is_page( 'home' ) ) ) {896 if ( is_front_page() || ( is_home() && bp_is_page( 'home' ) ) ) { 867 897 $title = __( 'Home', 'buddypress' ); 868 898 … … 886 916 887 917 } else if ( $bp->is_directory ) { 888 $title = get_the_title(); 918 if ( !$bp->current_component ) 919 $title = sprintf( __( '%s Directory', 'buddypress' ), ucwords( BP_MEMBERS_SLUG ) ); 920 else 921 $title = sprintf( __( '%s Directory', 'buddypress' ), ucwords( $bp->current_component ) ); 889 922 890 923 } else if ( bp_is_register_page() ) { 891 892 924 $title = __( 'Create an Account', 'buddypress' ); 893 925 894 926 } else if ( bp_is_activation_page() ) { 895 927 $title = __( 'Activate your Account', 'buddypress' ); 928 929 } else if ( bp_is_group_create() ) { 930 $title = __( 'Create a Group', 'buddypress' ); 931 932 } else if ( bp_is_create_blog() ) { 933 $title = __( 'Create a Blog', 'buddypress' ); 896 934 } 897 935 … … 952 990 } 953 991 992 /** 993 * bp_search_form_available() 994 * 995 * Only show the search form if there are available objects to search for. 996 * 997 * @global array $bp 998 * @uses function_exists 999 * @uses bp_core_is_multisite() 1000 * @return bool Filterable result 1001 */ 1002 function bp_search_form_enabled() { 1003 global $bp; 1004 1005 if ( function_exists( 'xprofile_install' ) 1006 || function_exists( 'groups_install' ) 1007 || ( function_exists( 'bp_blogs_install' ) && bp_core_is_multisite() ) 1008 || ( function_exists( 'bp_forums_setup' ) && !(int)$bp->site_options['bp-disable-forum-directory'] ) 1009 ) { 1010 $search_enabled = true; 1011 } else { 1012 $search_enabled = false; 1013 } 1014 1015 return apply_filters( 'bp_search_form_enabled', $search_enabled ); 1016 } 1017 954 1018 function bp_search_form_action() { 955 1019 global $bp; … … 959 1023 960 1024 function bp_search_form_type_select() { 1025 global $bp; 1026 961 1027 // Eventually this won't be needed and a page will be built to integrate all search results. 962 1028 $selection_box = '<select name="search-which" id="search-which" style="width: auto">'; … … 1013 1079 function bp_custom_profile_sidebar_boxes() { 1014 1080 do_action( 'bp_custom_profile_sidebar_boxes' ); 1015 }1016 1017 function bp_is_directory() {1018 global $bp;1019 1020 return $bp->is_directory;1021 1081 } 1022 1082 … … 1225 1285 1226 1286 function bp_registration_needs_activation() { 1227 return apply_filters( 'bp_registration_needs_activation', bp_core_is_multisite());1287 return apply_filters( 'bp_registration_needs_activation', true ); 1228 1288 } 1229 1289 … … 1268 1328 also means we dont have to use the $bp variable in the template (looks messy) */ 1269 1329 1330 function bp_last_activity( $user_id = false, $echo = true ) { 1331 global $bp; 1332 1333 if ( !$user_id ) 1334 $user_id = $bp->displayed_user->id; 1335 1336 $last_activity = bp_core_get_last_activity( get_user_meta( $user_id, 'last_activity', true ), __('active %s ago', 'buddypress') ); 1337 1338 if ( $echo ) 1339 echo apply_filters( 'bp_last_activity', $last_activity ); 1340 else 1341 return apply_filters( 'bp_last_activity', $last_activity ); 1342 } 1343 1344 function bp_user_has_access() { 1345 global $bp; 1346 1347 if ( is_super_admin() || is_user_logged_in() && $bp->loggedin_user->id == $bp->displayed_user->id ) 1348 $has_access = true; 1349 else 1350 $has_access = false; 1351 1352 return apply_filters( 'bp_user_has_access', $has_access ); 1353 } 1354 1355 function bp_user_firstname() { 1356 echo bp_get_user_firstname(); 1357 } 1358 function bp_get_user_firstname( $name = false ) { 1359 global $bp; 1360 1361 // Try to get displayed user 1362 if ( empty( $name ) ) 1363 $name = $bp->displayed_user->fullname; 1364 1365 // Fall back on logged in user 1366 if ( empty( $name ) ) 1367 $name = $bp->loggedin_user->fullname; 1368 1369 $fullname = (array)explode( ' ', $name ); 1370 1371 return apply_filters( 'bp_get_user_firstname', $fullname[0], $fullname ); 1372 } 1373 1374 function bp_loggedin_user_link() { 1375 echo bp_get_loggedin_user_link(); 1376 } 1377 function bp_get_loggedin_user_link() { 1378 global $bp; 1379 1380 return apply_filters( 'bp_get_loggedin_user_link', $bp->loggedin_user->domain ); 1381 } 1382 1383 /* @todo Deprecate incorrectly named function? */ 1384 function bp_loggedinuser_link() { 1385 global $bp; 1386 1387 if ( $link = bp_core_get_userlink( $bp->loggedin_user->id ) ) 1388 echo apply_filters( 'bp_loggedin_user_link', $link ); 1389 } 1390 1391 function bp_displayed_user_link() { 1392 echo bp_get_displayed_user_link(); 1393 } 1394 function bp_get_displayed_user_link() { 1395 global $bp; 1396 1397 return apply_filters( 'bp_get_displayed_user_link', $bp->displayed_user->domain ); 1398 } 1399 function bp_user_link() { bp_displayed_user_link(); } // Deprecated. 1400 1270 1401 function bp_displayed_user_id() { 1271 1402 global $bp; … … 1350 1481 global $bp; 1351 1482 1352 return $bp->root_domain;1483 return apply_filters( 'bp_get_root_domain', $bp->root_domain ); 1353 1484 } 1354 1485 1355 1486 /* Template is_() functions to determine the current page */ 1487 1488 function bp_is_blog_page() { 1489 global $bp, $is_member_page, $wp_query; 1490 1491 if ( $wp_query->is_home && !$bp->is_directory ) 1492 return true; 1493 1494 if ( !$bp->displayed_user->id && !$bp->is_single_item && !$bp->is_directory && !bp_core_is_root_component( $bp->current_component ) ) 1495 return true; 1496 1497 return false; 1498 } 1499 1500 function bp_is_my_profile() { 1501 global $bp; 1502 1503 if ( is_user_logged_in() && $bp->loggedin_user->id == $bp->displayed_user->id ) 1504 $my_profile = true; 1505 else 1506 $my_profile = false; 1507 1508 return apply_filters( 'bp_is_my_profile', $my_profile ); 1509 } 1510 function bp_is_home() { return bp_is_my_profile(); } 1356 1511 1357 1512 function bp_is_front_page() { … … 1365 1520 1366 1521 function bp_is_activity_front_page() { 1367 return ( 'page' == get_option('show_on_front') && 'activity' == get_option('page_on_front') && $_SERVER['REQUEST_URI'] == bp_core_get_site_path() ); 1522 global $current_blog; 1523 1524 if ( bp_core_is_main_site() ) 1525 $path = bp_core_get_site_path(); 1526 else 1527 $path = $current_blog->path; 1528 1529 return ( 'page' == get_option('show_on_front') && 'activity' == get_option('page_on_front') && $_SERVER['REQUEST_URI'] == $path ); 1530 } 1531 1532 function bp_is_directory() { 1533 global $bp; 1534 1535 return $bp->is_directory; 1368 1536 } 1369 1537 -
trunk/bp-core/bp-core-widgets.php
r3263 r3300 59 59 </ul> 60 60 <?php wp_nonce_field( 'bp_core_widget_members', '_wpnonce-members' ); ?> 61 <input type="hidden" name="members_widget_max" id="members_widget_max" value="<?php echo attribute_escape( $instance['max_members'] ); ?>" />61 <input type="hidden" name="members_widget_max" id="members_widget_max" value="<?php echo esc_attr( $instance['max_members'] ); ?>" /> 62 62 63 63 <?php else: ?> … … 85 85 ?> 86 86 87 <p><label for="bp-core-widget-members-max"><?php _e('Max Members to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="text" value="<?php echo attribute_escape( $max_members ); ?>" style="width: 30%" /></label></p>87 <p><label for="bp-core-widget-members-max"><?php _e('Max Members to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="text" value="<?php echo esc_attr( $max_members ); ?>" style="width: 30%" /></label></p> 88 88 <?php 89 89 } … … 139 139 ?> 140 140 141 <p><label for="bp-core-widget-members-max"><?php _e('Max Members to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="text" value="<?php echo attribute_escape( $max_members ); ?>" style="width: 30%" /></label></p>141 <p><label for="bp-core-widget-members-max"><?php _e('Max Members to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="text" value="<?php echo esc_attr( $max_members ); ?>" style="width: 30%" /></label></p> 142 142 <?php 143 143 } … … 154 154 global $bp; 155 155 156 156 extract( $args ); 157 157 158 158 echo $before_widget; … … 193 193 ?> 194 194 195 <p><label for="bp-core-widget-members-max"><?php _e('Max Members to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="text" value="<?php echo attribute_escape( $max_members ); ?>" style="width: 30%" /></label></p>195 <p><label for="bp-core-widget-members-max"><?php _e('Max Members to show:', 'buddypress'); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="text" value="<?php echo esc_attr( $max_members ); ?>" style="width: 30%" /></label></p> 196 196 <?php 197 197 } … … 209 209 $type = 'newest'; 210 210 break; 211 211 212 case 'recently-active-members': 212 213 $type = 'active'; 213 214 break; 215 214 216 case 'popular-members': 215 217 if ( bp_is_active( 'friends' ) ) -
trunk/bp-core/bp-core-wpabstraction.php
r3284 r3300 23 23 24 24 return true; 25 } 26 27 /** 28 * bp_core_is_main_site 29 * 30 * Checks if current blog is root blog of site 31 * 32 * @since 1.2.6 33 * @package BuddyPress 34 * 35 * @param int $blog_id optional blog id to test (default current blog) 36 * @return bool True if not multisite or $blog_id is main site 37 */ 38 function bp_core_is_main_site( $blog_id = '' ) { 39 global $current_site, $current_blog; 40 41 if ( !bp_core_is_multisite() ) 42 return true; 43 44 if ( empty( $blog_id ) ) 45 $blog_id = $current_blog->blog_id; 46 47 return $blog_id == $current_site->blog_id; 25 48 } 26 49 … … 74 97 } 75 98 76 if ( !function_exists( 'wpmu_validate_user_signup' ) ) { 77 function wpmu_validate_user_signup( $user_name, $user_email ) { 78 global $wpdb; 99 if ( !function_exists( 'is_subdomain_install' ) ) { 100 function is_subdomain_install() { 101 if ( ( defined( 'VHOST' ) && 'yes' == VHOST ) || ( defined( 'SUBDOMAIN_INSTALL' ) && SUBDOMAIN_INSTALL ) ) 102 return true; 79 103 80 $errors = new WP_Error(); 81 82 $user_email = sanitize_email( $user_email ); 83 84 if ( empty( $user_name ) ) 85 $errors->add('user_name', __("Please enter a username")); 86 87 $maybe = array(); 88 preg_match( "/[a-z0-9]+/", $user_name, $maybe ); 89 90 $illegal_names = get_site_option( "illegal_names" ); 91 if( is_array( $illegal_names ) == false ) { 92 $illegal_names = array( "www", "web", "root", "admin", "main", "invite", "administrator" ); 93 add_site_option( "illegal_names", $illegal_names ); 94 } 95 96 if ( !validate_username( $user_name ) || in_array( $user_name, $illegal_names ) == true || $user_name != $maybe[0] ) { 97 $errors->add('user_name', __("Only lowercase letters and numbers allowed")); 98 } 99 100 if( strlen( $user_name ) < 4 ) { 101 $errors->add('user_name', __("Username must be at least 4 characters")); 102 } 103 104 if ( strpos( " " . $user_name, "_" ) != false ) 105 $errors->add('user_name', __("Sorry, usernames may not contain the character '_'!")); 106 107 // all numeric? 108 $match = array(); 109 preg_match( '/[0-9]*/', $user_name, $match ); 110 if ( $match[0] == $user_name ) 111 $errors->add('user_name', __("Sorry, usernames must have letters too!")); 112 113 if ( !is_email( $user_email ) ) 114 $errors->add('user_email', __("Please check your email address.")); 115 116 $limited_email_domains = get_site_option( 'limited_email_domains' ); 117 if ( is_array( $limited_email_domains ) && empty( $limited_email_domains ) == false ) { 118 $emaildomain = substr( $user_email, 1 + strpos( $user_email, '@' ) ); 119 if( in_array( $emaildomain, $limited_email_domains ) == false ) { 120 $errors->add('user_email', __("Sorry, that email address is not allowed!")); 121 } 122 } 123 124 // Check if the username has been used already. 125 if ( username_exists($user_name) ) 126 $errors->add('user_name', __("Sorry, that username already exists!")); 127 128 // Check if the email address has been used already. 129 if ( email_exists($user_email) ) 130 $errors->add('user_email', __("Sorry, that email address is already used!")); 131 132 $result = array('user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors); 133 134 return apply_filters('wpmu_validate_user_signup', $result); 104 return false; 135 105 } 136 106 } 107 108 // Deprecated - 1.2.6 109 if ( !function_exists( 'is_site_admin' ) ) { 110 function is_site_admin( $user_id = false ) { 111 return is_super_admin( $user_id ); 112 } 113 } 114 137 115 ?> -
trunk/bp-forums.php
r3232 r3300 1 1 <?php 2 2 3 /* Define the parent forum ID */ 3 4 if ( !defined( 'BP_FORUMS_PARENT_FORUM_ID' ) ) 4 5 define( 'BP_FORUMS_PARENT_FORUM_ID', 1 ); 5 6 7 if ( !defined( 'BP_FORUMS_SLUG' ) ) 8 define( 'BP_FORUMS_SLUG', 'forums' ); 9 6 10 if ( !defined( 'BB_PATH' ) ) 7 11 require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-bbpress.php' ); … … 13 17 global $bp; 14 18 15 if ( !defined( 'BP_FORUMS_SLUG' ) )16 define ( 'BP_FORUMS_SLUG', $bp->pages->forums->slug );17 18 19 /* For internal identification */ 19 20 $bp->forums->id = 'forums'; 20 $bp->forums->name = $bp->pages->forums->name;21 $bp->forums->slug = BP_FORUMS_SLUG;22 21 23 22 $bp->forums->image_base = BP_PLUGIN_URL . '/bp-forums/images'; 24 23 $bp->forums->bbconfig = $bp->site_options['bb-config-location']; 24 $bp->forums->slug = BP_FORUMS_SLUG; 25 25 26 26 /* Register this in the active components array */ … … 40 40 } 41 41 42 function bp_forums_setup_root_component() { 43 /* Register 'forums' as a root component */ 44 bp_core_add_root_component( BP_FORUMS_SLUG ); 45 } 46 add_action( 'bp_setup_root_components', 'bp_forums_setup_root_component' ); 47 42 48 function bp_forums_directory_forums_setup() { 43 49 global $bp; 44 50 45 51 if ( $bp->current_component == $bp->forums->slug ) { 46 if ( (int) $bp->site_options['bp-disable-forum-directory'] || ! bp_is_active( 'groups' ) )52 if ( (int) $bp->site_options['bp-disable-forum-directory'] || !function_exists( 'groups_install' ) ) 47 53 return false; 48 54 … … 63 69 if ( $bp->groups->current_group = groups_get_group( array( 'group_id' => $_POST['topic_group_id'] ) ) ) { 64 70 /* Auto join this user if they are not yet a member of this group */ 65 if ( !is_s ite_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )71 if ( !is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) ) 66 72 groups_join_group( $bp->groups->current_group->id, $bp->groups->current_group->id ); 67 73 … … 73 79 74 80 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/forum/topic/' . $topic->topic_slug . '/' ); 81 } else { 82 bp_core_add_message( __( 'Please pick the group forum where you would like to post this topic.', 'buddypress' ), 'error' ); 75 83 } 76 84 } … … 87 95 global $bp; 88 96 89 if ( !is_s ite_admin() )97 if ( !is_super_admin() ) 90 98 return false; 91 99 … … 119 127 120 128 return bb_new_forum( array( 'forum_name' => stripslashes( $forum_name ), 'forum_desc' => stripslashes( $forum_desc ), 'forum_parent' => $forum_parent_id, 'forum_order' => $forum_order, 'forum_is_category' => $forum_is_category ) ); 129 } 130 131 function bp_forums_update_forum( $args = '' ) { 132 do_action( 'bbpress_init' ); 133 134 $defaults = array( 135 'forum_id' => '', 136 'forum_name' => '', 137 'forum_desc' => '', 138 'forum_slug' => '', 139 'forum_parent_id' => BP_FORUMS_PARENT_FORUM_ID, 140 'forum_order' => false, 141 'forum_is_category' => 0 142 ); 143 144 $r = wp_parse_args( $args, $defaults ); 145 extract( $r, EXTR_SKIP ); 146 147 return bb_update_forum( array( 'forum_id' => (int)$forum_id, 'forum_name' => stripslashes( $forum_name ), 'forum_desc' => stripslashes( $forum_desc ), 'forum_slug' => stripslashes( $forum_slug ), 'forum_parent' => $forum_parent_id, 'forum_order' => $forum_order, 'forum_is_category' => $forum_is_category ) ); 121 148 } 122 149 … … 356 383 357 384 /* Fetch fullname for the topic's last poster */ 358 if ( bp_is_active( 'xprofile' ) ) {385 if ( function_exists( 'xprofile_install' ) ) { 359 386 $poster_names = $wpdb->get_results( $wpdb->prepare( "SELECT t.topic_id, pd.value FROM {$bp->profile->table_name_data} pd, {$bbdb->topics} t WHERE pd.user_id = t.topic_last_poster AND pd.field_id = 1 AND t.topic_id IN ( {$topic_ids} )" ) ); 360 387 for ( $i = 0; $i < count( $topics ); $i++ ) { … … 441 468 $post_position = $post->post_position; 442 469 443 $post = bb_insert_post( array( 'post_id' => $post_id, 'topic_id' => $topic_id, 'post_text' => stripslashes( trim( $post_text ) ), 'post_time' => $post_time, 'poster_id' => $poster_id, 'poster_ip' => $poster_ip, 'post_status' => $post_status, 'post_position' => $post_position ) );444 445 if ( $post )470 $post_id = bb_insert_post( array( 'post_id' => $post_id, 'topic_id' => $topic_id, 'post_text' => stripslashes( trim( $post_text ) ), 'post_time' => $post_time, 'poster_id' => $poster_id, 'poster_ip' => $poster_ip, 'post_status' => $post_status, 'post_position' => $post_position ) ); 471 472 if ( $post_id ) 446 473 do_action( 'bp_forums_new_post', $post_id ); 447 474 448 return $post ;475 return $post_id; 449 476 } 450 477 … … 474 501 475 502 /* Fetch fullname for each poster. */ 476 if ( bp_is_active( 'xprofile' ) ) {503 if ( function_exists( 'xprofile_install' ) ) { 477 504 $poster_names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id, pd.value FROM {$bp->profile->table_name_data} pd WHERE pd.user_id IN ( {$user_ids} )" ) ); 478 505 for ( $i = 0; $i < count( $posts ); $i++ ) { … … 501 528 global $bp, $wp_roles, $bb_table_prefix; 502 529 503 $bb_cap = get_user meta( $bp->loggedin_user->id, $bb_table_prefix . 'capabilities');530 $bb_cap = get_user_meta( $bp->loggedin_user->id, $bb_table_prefix . 'capabilities', true ); 504 531 505 532 if ( empty( $bb_cap ) ) -
trunk/bp-forums/bp-forums-admin.php
r2665 r3300 122 122 123 123 function bp_forums_bbpress_install() { 124 global $wpdb, $bbdb ;124 global $wpdb, $bbdb, $bp; 125 125 126 126 check_admin_referer( 'bp_forums_new_install_init' ); … … 141 141 "define( 'BB_LOGGED_I" => array( "'put your unique phrase here'", "'" . addslashes( LOGGED_IN_KEY ) . "'" ), 142 142 "define( 'BB_NONCE_KE" => array( "'put your unique phrase here'", "'" . addslashes( NONCE_KEY ) . "'" ), 143 "\$bb_table_prefix = '" => array( "'bb_'", "'" . $ wpdb->base_prefix . "bb_'" ),143 "\$bb_table_prefix = '" => array( "'bb_'", "'" . $bp->table_prefix . "bb_'" ), 144 144 "define( 'BB_LANG', '" => array( "''", "'" . WPLANG . "'" ) 145 145 ) … … 154 154 155 155 $file = substr( $file, 0, -2 ); 156 $file .= "\n" . '$bb->custom_user_table = "' . $wpdb->users . '";';157 $file .= "\n" . '$bb->custom_user_meta_table = "' . $wpdb->usermeta . '";';158 $file .= "\n\n" . '$bb->uri = "' . BP_PLUGIN_URL . '/bp-forums/bbpress/";';159 $file .= "\n" . '$bb->name = "' . get_blog_option( BP_ROOT_BLOG, 'name' ) . ' ' . __( 'Forums', 'buddypress' ) . '";';156 $file .= "\n" . '$bb->custom_user_table = \'' . $wpdb->users . '\';'; 157 $file .= "\n" . '$bb->custom_user_meta_table = \'' . $wpdb->usermeta . '\';'; 158 $file .= "\n\n" . '$bb->uri = \'' . BP_PLUGIN_URL . '/bp-forums/bbpress/\';'; 159 $file .= "\n" . '$bb->name = \'' . get_blog_option( BP_ROOT_BLOG, 'name' ) . ' ' . __( 'Forums', 'buddypress' ) . '\';'; 160 160 161 161 if ( bp_core_is_multisite() ) … … 163 163 164 164 if ( defined( 'AUTH_SALT' ) ) 165 $file .= "\n\n" . 'define(\'BB_AUTH_SALT\', "' . addslashes( AUTH_SALT ) . '");';165 $file .= "\n\n" . 'define(\'BB_AUTH_SALT\', \'' . addslashes( AUTH_SALT ) . '\');'; 166 166 167 167 if ( defined( 'LOGGED_IN_SALT' ) ) 168 $file .= "\n" . 'define(\'BB_LOGGED_IN_SALT\', "' . addslashes( LOGGED_IN_SALT ) . '");';168 $file .= "\n" . 'define(\'BB_LOGGED_IN_SALT\', \'' . addslashes( LOGGED_IN_SALT ) . '\');'; 169 169 170 170 if ( defined( 'SECURE_AUTH_SALT' ) ) 171 $file .= "\n" . 'define(\'BB_SECURE_AUTH_SALT\', "' . addslashes( SECURE_AUTH_SALT ) . '");';171 $file .= "\n" . 'define(\'BB_SECURE_AUTH_SALT\', \'' . addslashes( SECURE_AUTH_SALT ) . '\');'; 172 172 173 173 $file .= "\n\n" . 'define(\'WP_AUTH_COOKIE_VERSION\', 2);'; -
trunk/bp-forums/bp-forums-bbpress.php
r2209 r3300 66 66 /* This must be loaded before functionss.bb-admin.php otherwise we get a function conflict. */ 67 67 if ( !$tables_installed = (boolean) $bbdb->get_results( 'DESCRIBE `' . $bbdb->forums . '`;', ARRAY_A ) ) 68 require_once( ABSPATH . 'wp-admin/ upgrade-functions.php' );68 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 69 69 70 70 require_once( BB_PATH . 'bb-admin/includes/functions.bb-admin.php' ); 71 71 72 72 if ( is_object( $wp_roles ) ) { 73 $bb_roles = &$wp_roles;73 $bb_roles = $wp_roles; 74 74 bb_init_roles( $bb_roles ); 75 75 } … … 104 104 $site_admins = get_site_option( 'site_admins', array('admin') ); 105 105 foreach ( (array)$site_admins as $site_admin ) 106 update_user meta( bp_core_get_userid( $site_admin ), $bb_table_prefix . 'capabilities', array( 'keymaster' => true ) );106 update_user_meta( bp_core_get_userid( $site_admin ), $bb_table_prefix . 'capabilities', array( 'keymaster' => true ) ); 107 107 108 108 // Create the first forum. … … 131 131 extract( $args, EXTR_SKIP ); 132 132 133 return update_user meta( $id, $meta_key, $meta_value );133 return update_user_meta( $id, $meta_key, $meta_value ); 134 134 } 135 135 } -
trunk/bp-forums/bp-forums-filters.php
r2770 r3300 3 3 /* Apply WordPress defined filters */ 4 4 add_filter( 'bp_forums_bbconfig_location', 'wp_filter_kses', 1 ); 5 add_filter( 'bp_forums_bbconfig_location', ' attribute_escape', 1 );5 add_filter( 'bp_forums_bbconfig_location', 'esc_attr', 1 ); 6 6 7 7 add_filter( 'bp_get_the_topic_title', 'wp_filter_kses', 1 ); 8 8 add_filter( 'bp_get_the_topic_latest_post_excerpt', 'bp_forums_filter_kses', 1 ); 9 9 add_filter( 'bp_get_the_topic_post_content', 'bp_forums_filter_kses', 1 ); 10 11 add_filter( 'bp_get_the_topic_title', 'force_balance_tags' ); 12 add_filter( 'bp_get_the_topic_latest_post_excerpt', 'force_balance_tags' ); 13 add_filter( 'bp_get_the_topic_post_content', 'force_balance_tags' ); 10 14 11 15 add_filter( 'bp_get_the_topic_title', 'wptexturize' ); … … 31 35 add_filter( 'bp_get_the_topic_poster_name', 'stripslashes_deep' ); 32 36 add_filter( 'bp_get_the_topic_last_poster_name', 'stripslashes_deep' ); 37 add_filter( 'bp_get_the_topic_object_name', 'stripslashes_deep' ); 33 38 34 39 add_filter( 'bp_get_the_topic_post_content', 'make_clickable' ); … … 84 89 } 85 90 91 /** 92 * bp_forums_add_forum_topic_to_page_title( $title ) 93 * 94 * Append forum topic to page title 95 * 96 * @global object $bp 97 * @param string $title 98 * @return string 99 */ 100 function bp_forums_add_forum_topic_to_page_title( $title ) { 101 global $bp; 102 103 if ( $bp->current_action == 'forum' && $bp->action_variables[0] == 'topic' ) { 104 if ( bp_has_forum_topic_posts() ) { 105 $title .= ' | ' . bp_get_the_topic_title(); 106 } 107 } 108 109 return $title; 110 } 111 add_filter( 'bp_page_title', 'bp_forums_add_forum_topic_to_page_title' ); 112 86 113 ?> -
trunk/bp-forums/bp-forums-templatetags.php
r3247 r3300 7 7 var $topic; 8 8 9 var $forum_id; 10 9 11 var $in_the_loop; 10 12 … … 26 28 $this->type = $type; 27 29 $this->search_terms = $search_terms; 30 $this->forum_id = $forum_id; 28 31 29 32 switch ( $type ) { … … 48 51 49 52 if ( !(int)$this->topics ) { 50 $this->topic_count = 0;53 $this->topic_count = 0; 51 54 $this->total_topic_count = 0; 52 55 } else { … … 60 63 } 61 64 62 if ( !$max || $max >= $topic_count ) 65 if ( !$max || $max >= $topic_count ) { 63 66 $this->total_topic_count = $topic_count; 64 else67 } else { 65 68 $this->total_topic_count = (int)$max; 69 } 66 70 67 71 if ( $max ) { 68 if ( $max >= count( $this->topics) ) {72 if ( $max >= count($this->topics) ) { 69 73 $this->topic_count = count( $this->topics ); 70 74 } else { … … 99 103 'base' => add_query_arg( array( 'p' => '%#%', 'n' => $this->pag_num ) ), 100 104 'format' => '', 101 'total' => ceil( (int)$this->total_topic_count / (int)$this->pag_num 105 'total' => ceil( (int)$this->total_topic_count / (int)$this->pag_num), 102 106 'current' => $this->pag_page, 103 107 'prev_text' => '←', … … 259 263 260 264 $post = bb_get_first_post( (int)$forum_template->topic->topic_id, false ); 261 return apply_filters( 'bp_get_the_topic_text', attribute_escape( $post->post_text ) );265 return apply_filters( 'bp_get_the_topic_text', esc_attr( $post->post_text ) ); 262 266 } 263 267 … … 295 299 global $forum_template; 296 300 297 if ( !$name = bp_core_get_userlink( $forum_template->topic->poster_id ) ) 301 $poster_id = ( empty( $forum_template->topic->poster_id ) ) ? $forum_template->topic->topic_poster : $forum_template->topic->poster_id; 302 303 if ( !$name = bp_core_get_userlink( $poster_id ) ) 298 304 return __( 'Deleted User', 'buddypress' ); 299 305 … … 467 473 global $forum_template; 468 474 469 return $forum_template->topic->topic_posts;475 return apply_filters( 'bp_get_the_topic_total_posts', $forum_template->topic->topic_posts ); 470 476 } 471 477 … … 557 563 $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'edit', 'bp_forums_edit_topic' ) . '">' . __( 'Edit Topic', 'buddypress' ) . '</a>'; 558 564 559 if ( $bp->is_item_admin || $bp->is_item_mod || is_s ite_admin() ) {565 if ( $bp->is_item_admin || $bp->is_item_mod || is_super_admin() ) { 560 566 if ( 0 == (int)$forum_template->topic->topic_sticky ) 561 567 $links[] = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'stick', 'bp_forums_stick_topic' ) . '">' . __( 'Sticky Topic', 'buddypress' ) . '</a>'; … … 592 598 $class .= ' closed'; 593 599 594 return trim( $class);600 return apply_filters( 'bp_get_the_topic_css_class', trim( $class ) ); 595 601 } 596 602 … … 670 676 global $bp, $forum_template; 671 677 672 $from_num = bp_core_number_format( intval( ( $forum_template->pag_page - 1 ) * $forum_template->pag_num ) + 1 ); 673 $to_num = bp_core_number_format( ( $from_num + ( $forum_template->pag_num - 1 ) > $forum_template->total_topic_count ) ? $forum_template->total_topic_count : $from_num + ( $forum_template->pag_num - 1 ) ); 678 $start_num = intval( ( $forum_template->pag_page - 1 ) * $forum_template->pag_num ) + 1; 679 $from_num = bp_core_number_format( $start_num ); 680 $to_num = bp_core_number_format( ( $start_num + ( $forum_template->pag_num - 1 ) > $forum_template->total_topic_count ) ? $forum_template->total_topic_count : $start_num + ( $forum_template->pag_num - 1 ) ); 674 681 $total = bp_core_number_format( $forum_template->total_topic_count ); 675 682 … … 678 685 $pag_filter = sprintf( __( ' matching tag "%s"', 'buddypress' ), $forum_template->search_terms ); 679 686 680 return apply_filters( 'bp_get_forum_pagination_count', sprintf( __( 'Viewing topic %s to %s (of %s total topics%s)', 'buddypress' ), $from_num, $to_num, $total, $pag_filter ) );687 return apply_filters( 'bp_get_forum_pagination_count', sprintf( __( 'Viewing topic %s to %s (of %s total topics%s)', 'buddypress' ), $from_num, $to_num, $total, $pag_filter ) . '<span class="ajax-loader"></span>' ); 681 688 } 682 689 … … 697 704 var $post; 698 705 706 var $forum_id; 699 707 var $topic_id; 700 708 var $topic; … … 712 720 var $order; 713 721 714 function BP_Forums_Template_Topic( $topic_id, $per_page, $max ) {722 function BP_Forums_Template_Topic( $topic_id, $per_page, $max, $order ) { 715 723 global $bp, $current_user, $forum_template; 716 724 … … 721 729 $this->topic_id = $topic_id; 722 730 $forum_template->topic = (object) bp_forums_get_topic_details( $this->topic_id ); 731 $this->forum_id = $forum_template->topic->forum_id; 723 732 724 733 $this->posts = bp_forums_get_topic_posts( array( 'topic_id' => $this->topic_id, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'order' => $this->order ) ); 725 734 726 735 if ( !$this->posts ) { 727 $this->post_count = 0;736 $this->post_count = 0; 728 737 $this->total_post_count = 0; 729 738 } else { 730 if ( !$max || $max >= (int) 731 $this->total_post_count = (int) 739 if ( !$max || $max >= (int)$forum_template->topic->topic_posts ) { 740 $this->total_post_count = (int)$forum_template->topic->topic_posts; 732 741 } else { 733 742 $this->total_post_count = (int)$max; … … 814 823 'topic_id' => false, 815 824 'per_page' => 15, 816 'max' => false 825 'max' => false, 826 'order' => 'ASC' 817 827 ); 818 828 … … 823 833 $topic_id = bp_forums_get_topic_id_from_slug( $bp->action_variables[1] ); 824 834 825 if ( is_numeric( $topic_id ) ) 826 $topic_template = new BP_Forums_Template_Topic( $topic_id, $per_page, $max ); 827 else 835 if ( is_numeric( $topic_id ) ) { 836 $topic_template = new BP_Forums_Template_Topic( $topic_id, $per_page, $max, $order ); 837 838 // Current topic forum_id needs to match current_group forum_id 839 if ( $bp->current_component == $bp->groups->slug && $topic_template->forum_id != groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' ) ) 840 return false; 841 842 } else { 828 843 return false; 844 } 829 845 830 846 return apply_filters( 'bp_has_topic_posts', $topic_template->has_posts(), &$topic_template ); … … 857 873 858 874 return apply_filters( 'bp_get_the_topic_post_content', stripslashes( $topic_template->post->post_text ) ); 875 } 876 877 function bp_the_topic_post_css_class() { 878 echo bp_get_the_topic_post_css_class(); 879 } 880 881 function bp_get_the_topic_post_css_class() { 882 global $topic_template; 883 884 $class = false; 885 886 if ( $topic_template->current_post % 2 == 1 ) 887 $class .= 'alt'; 888 889 if ( 1 == (int)$topic_template->post->post_status ) 890 $class .= ' deleted'; 891 892 if ( 0 == (int)$topic_template->post->post_status ) 893 $class .= ' open'; 894 895 return apply_filters( 'bp_get_the_topic_post_css_class', trim( $class ) ); 859 896 } 860 897 … … 936 973 $query_vars = '?' . $_SERVER['QUERY_STRING']; 937 974 938 $links = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . $topic_template->post->id .'edit/post/' . $topic_template->post->post_id . '/' . $query_vars, 'bp_forums_edit_post' ) . '">' . __( 'Edit', 'buddypress' ) . '</a> ' . $seperator . ' ';975 $links = '<a href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'edit/post/' . $topic_template->post->post_id . '/' . $query_vars, 'bp_forums_edit_post' ) . '">' . __( 'Edit', 'buddypress' ) . '</a> ' . $seperator . ' '; 939 976 $links .= '<a class="confirm" id="post-delete-link" href="' . wp_nonce_url( bp_get_the_topic_permalink() . 'delete/post/' . $topic_template->post->post_id, 'bp_forums_delete_post' ) . '">' . __( 'Delete', 'buddypress' ) . '</a> | '; 940 977 … … 949 986 950 987 $post = bp_forums_get_post( $bp->action_variables[4] ); 951 return apply_filters( 'bp_get_the_topic_post_edit_text', attribute_escape( $post->post_text ) );988 return apply_filters( 'bp_get_the_topic_post_edit_text', esc_attr( $post->post_text ) ); 952 989 } 953 990 … … 964 1001 global $bp, $topic_template; 965 1002 966 $from_num = intval( ( $topic_template->pag_page - 1 ) * $topic_template->pag_num ) + 1; 967 $to_num = ( $from_num + ( $topic_template->pag_num - 1 ) > $topic_template->total_post_count ) ? $topic_template->total_post_count : $from_num + ( $topic_template->pag_num - 1 ); 968 969 echo apply_filters( 'bp_the_topic_pagination_count', sprintf( __( 'Viewing post %d to %d (%d total posts)', 'buddypress' ), $from_num, $to_num, $topic_template->total_post_count ) ); 1003 $start_num = intval( ( $topic_template->pag_page - 1 ) * $topic_template->pag_num ) + 1; 1004 $from_num = bp_core_number_format( $start_num ); 1005 $to_num = bp_core_number_format( ( $start_num + ( $topic_template->pag_num - 1 ) > $topic_template->total_post_count ) ? $topic_template->total_post_count : $start_num + ( $topic_template->pag_num - 1 ) ); 1006 $total = bp_core_number_format( $topic_template->total_post_count ); 1007 1008 echo apply_filters( 'bp_the_topic_pagination_count', sprintf( __( 'Viewing post %1$s to %2$s (%3$s total posts)', 'buddypress' ), $from_num, $to_num, $total ) ); 970 1009 ?> 971 1010 <span class="ajax-loader"></span> … … 991 1030 ?> 992 1031 <form action="" method="get" id="search-forums-form"> 993 <label><input type="text" name="s" id="forums_search" value="<?php echo attribute_escape($search_value) ?>" onfocus="if (this.value == '<?php _e( 'Search anything...', 'buddypress' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search anything...', 'buddypress' ) ?>';}" /></label>1032 <label><input type="text" name="s" id="forums_search" value="<?php echo esc_attr($search_value) ?>" onfocus="if (this.value == '<?php _e( 'Search anything...', 'buddypress' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'Search anything...', 'buddypress' ) ?>';}" /></label> 994 1033 <input type="submit" id="forums_search_submit" name="forums_search_submit" value="<?php _e( 'Search', 'buddypress' ) ?>" /> 995 1034 </form> … … 1039 1078 global $topic_template; 1040 1079 1041 return apply_filters( 'bp_get_forum_action', $bp->root_domain . attribute_escape( $_SERVER['REQUEST_URI'] ) );1080 return apply_filters( 'bp_get_forum_action', $bp->root_domain . esc_attr( $_SERVER['REQUEST_URI'] ) ); 1042 1081 } 1043 1082 … … 1048 1087 global $bp; 1049 1088 1050 return apply_filters( 'bp_get_forum_topic_action', $bp->root_domain . attribute_escape( $_SERVER['REQUEST_URI'] ) );1089 return apply_filters( 'bp_get_forum_topic_action', $bp->root_domain . esc_attr( $_SERVER['REQUEST_URI'] ) ); 1051 1090 } 1052 1091 -
trunk/bp-friends.php
r3232 r3300 1 1 <?php 2 3 define ( 'BP_FRIENDS_DB_VERSION', '1800' ); 4 5 /* Define the slug for the component */ 6 if ( !defined( 'BP_FRIENDS_SLUG' ) ) 7 define ( 'BP_FRIENDS_SLUG', 'friends' ); 8 2 9 require ( BP_PLUGIN_DIR . '/bp-friends/bp-friends-classes.php' ); 3 10 require ( BP_PLUGIN_DIR . '/bp-friends/bp-friends-templatetags.php' ); 4 11 5 12 function friends_setup_globals() { 6 global $bp, $wpdb; 7 8 if ( !defined( 'BP_FRIENDS_SLUG' ) ) 9 define( 'BP_FRIENDS_SLUG', 'friends' ); 13 global $bp; 10 14 11 15 /* For internal identification */ 12 16 $bp->friends->id = 'friends'; 13 17 14 $bp->friends->table_name = $wpdb->base_prefix . 'bp_friends'; 18 $bp->friends->slug = BP_FRIENDS_SLUG; 19 20 $bp->friends->table_name = $bp->table_prefix . 'bp_friends'; 21 15 22 $bp->friends->format_notification_function = 'friends_format_notifications'; 16 $bp->friends->slug = BP_FRIENDS_SLUG;17 23 18 24 /* Register this in the active components array */ … … 103 109 function friends_screen_notification_settings() { 104 110 global $current_user; ?> 105 <table class="notification-settings" id="friends-notification-settings"> 106 <tr> 107 <th class="icon"></th> 108 <th class="title"><?php _e( 'Friends', 'buddypress' ) ?></th> 109 <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th> 110 <th class="no"><?php _e( 'No', 'buddypress' )?></th> 111 </tr> 112 <tr> 113 <td></td> 114 <td><?php _e( 'A member sends you a friendship request', 'buddypress' ) ?></td> 115 <td class="yes"><input type="radio" name="notifications[notification_friends_friendship_request]" value="yes" <?php if ( !get_usermeta( $current_user->id,'notification_friends_friendship_request') || 'yes' == get_usermeta( $current_user->id,'notification_friends_friendship_request') ) { ?>checked="checked" <?php } ?>/></td> 116 <td class="no"><input type="radio" name="notifications[notification_friends_friendship_request]" value="no" <?php if ( get_usermeta( $current_user->id,'notification_friends_friendship_request') == 'no' ) { ?>checked="checked" <?php } ?>/></td> 117 </tr> 118 <tr> 119 <td></td> 120 <td><?php _e( 'A member accepts your friendship request', 'buddypress' ) ?></td> 121 <td class="yes"><input type="radio" name="notifications[notification_friends_friendship_accepted]" value="yes" <?php if ( !get_usermeta( $current_user->id,'notification_friends_friendship_accepted') || 'yes' == get_usermeta( $current_user->id,'notification_friends_friendship_accepted') ) { ?>checked="checked" <?php } ?>/></td> 122 <td class="no"><input type="radio" name="notifications[notification_friends_friendship_accepted]" value="no" <?php if ( 'no' == get_usermeta( $current_user->id,'notification_friends_friendship_accepted') ) { ?>checked="checked" <?php } ?>/></td> 123 </tr> 124 125 <?php do_action( 'friends_screen_notification_settings' ); ?> 111 <table class="notification-settings zebra" id="friends-notification-settings"> 112 <thead> 113 <tr> 114 <th class="icon"></th> 115 <th class="title"><?php _e( 'Friends', 'buddypress' ) ?></th> 116 <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th> 117 <th class="no"><?php _e( 'No', 'buddypress' )?></th> 118 </tr> 119 </thead> 120 121 <tbody> 122 <tr> 123 <td></td> 124 <td><?php _e( 'A member sends you a friendship request', 'buddypress' ) ?></td> 125 <td class="yes"><input type="radio" name="notifications[notification_friends_friendship_request]" value="yes" <?php if ( !get_user_meta( $current_user->id, 'notification_friends_friendship_request', true ) || 'yes' == get_user_meta( $current_user->id, 'notification_friends_friendship_request', true ) ) { ?>checked="checked" <?php } ?>/></td> 126 <td class="no"><input type="radio" name="notifications[notification_friends_friendship_request]" value="no" <?php if ( get_user_meta( $current_user->id, 'notification_friends_friendship_request', true ) == 'no' ) { ?>checked="checked" <?php } ?>/></td> 127 </tr> 128 <tr> 129 <td></td> 130 <td><?php _e( 'A member accepts your friendship request', 'buddypress' ) ?></td> 131 <td class="yes"><input type="radio" name="notifications[notification_friends_friendship_accepted]" value="yes" <?php if ( !get_user_meta( $current_user->id, 'notification_friends_friendship_accepted', true ) || 'yes' == get_user_meta( $current_user->id, 'notification_friends_friendship_accepted', true ) ) { ?>checked="checked" <?php } ?>/></td> 132 <td class="no"><input type="radio" name="notifications[notification_friends_friendship_accepted]" value="no" <?php if ( 'no' == get_user_meta( $current_user->id, 'notification_friends_friendship_accepted', true ) ) { ?>checked="checked" <?php } ?>/></td> 133 </tr> 134 135 <?php do_action( 'friends_screen_notification_settings' ); ?> 136 </tbody> 126 137 </table> 127 138 <?php … … 237 248 'item_id' => false, 238 249 'secondary_item_id' => false, 239 'recorded_time' => gmdate( "Y-m-d H:i:s"),250 'recorded_time' => bp_core_current_time(), 240 251 'hide_sitewide' => false 241 252 ); … … 318 329 $friendship->is_confirmed = 0; 319 330 $friendship->is_limited = 0; 320 $friendship->date_created = time();331 $friendship->date_created = bp_core_current_time(); 321 332 322 333 if ( $force_accept ) … … 372 383 friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id ); 373 384 374 / * Remove the friend request notice */385 // Remove the friend request notice 375 386 bp_core_delete_notifications_for_user_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_request' ); 376 387 377 / * Add a friend accepted notice for the initiating user */388 // Add a friend accepted notice for the initiating user 378 389 bp_core_add_notification( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_accepted' ); 379 390 … … 381 392 $friend_link = bp_core_get_userlink( $friendship->friend_user_id ); 382 393 383 / * Record in activity streams for the initiator */394 // Record in activity streams for the initiator 384 395 friends_record_activity( array( 385 'user_id' => $friendship->initiator_user_id, 386 'type' => 'friendship_created', 387 'action' => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $initiator_link, $friend_link ), &$friendship ), 388 'item_id' => $friendship_id 396 'user_id' => $friendship->initiator_user_id, 397 'type' => 'friendship_created', 398 'action' => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $initiator_link, $friend_link ), &$friendship ), 399 'item_id' => $friendship_id, 400 'secondary_item_id' => $friendship->friend_user_id 389 401 ) ); 390 402 391 / * Record in activity streams for the friend */403 // Record in activity streams for the friend 392 404 friends_record_activity( array( 393 'user_id' => $friendship->friend_user_id, 394 'type' => 'friendship_created', 395 'action' => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $friend_link, $initiator_link ), &$friendship ), 396 'item_id' => $friendship_id, 397 'hide_sitewide' => true /* We've already got the first entry site wide */ 405 'user_id' => $friendship->friend_user_id, 406 'type' => 'friendship_created', 407 'action' => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $friend_link, $initiator_link ), &$friendship ), 408 'item_id' => $friendship_id, 409 'secondary_item_id' => $friendship->initiator_user_id, 410 'hide_sitewide' => true // We've already got the first entry site wide 398 411 ) ); 399 412 400 / * Send the email notification */413 // Send the email notification 401 414 require_once( BP_PLUGIN_DIR . '/bp-friends/bp-friends-notifications.php' ); 402 415 friends_notification_accepted_request( $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id ); … … 444 457 445 458 if ( !$count = wp_cache_get( 'bp_total_friend_count_' . $user_id, 'bp' ) ) { 446 $count = get_user meta( $user_id, 'total_friend_count');459 $count = get_user_meta( $user_id, 'total_friend_count', true ); 447 460 if ( empty( $count ) ) $count = 0; 448 461 wp_cache_set( 'bp_total_friend_count_' . $user_id, $count, 'bp' ); … … 547 560 function friends_update_friend_totals( $initiator_user_id, $friend_user_id, $status = 'add' ) { 548 561 if ( 'add' == $status ) { 549 update_user meta( $initiator_user_id, 'total_friend_count', (int)get_usermeta( $initiator_user_id, 'total_friend_count') + 1 );550 update_user meta( $friend_user_id, 'total_friend_count', (int)get_usermeta( $friend_user_id, 'total_friend_count') + 1 );562 update_user_meta( $initiator_user_id, 'total_friend_count', (int)get_user_meta( $initiator_user_id, 'total_friend_count', true ) + 1 ); 563 update_user_meta( $friend_user_id, 'total_friend_count', (int)get_user_meta( $friend_user_id, 'total_friend_count', true ) + 1 ); 551 564 } else { 552 update_user meta( $initiator_user_id, 'total_friend_count', (int)get_usermeta( $initiator_user_id, 'total_friend_count') - 1 );553 update_user meta( $friend_user_id, 'total_friend_count', (int)get_usermeta( $friend_user_id, 'total_friend_count') - 1 );565 update_user_meta( $initiator_user_id, 'total_friend_count', (int)get_user_meta( $initiator_user_id, 'total_friend_count', true ) - 1 ); 566 update_user_meta( $friend_user_id, 'total_friend_count', (int)get_user_meta( $friend_user_id, 'total_friend_count', true ) - 1 ); 554 567 } 555 568 } … … 559 572 560 573 /* Remove usermeta */ 561 delete_user meta( $user_id, 'total_friend_count' );574 delete_user_meta( $user_id, 'total_friend_count' ); 562 575 563 576 /* Remove friendship requests FROM user */ … … 566 579 do_action( 'friends_remove_data', $user_id ); 567 580 } 568 add_action( 'wpmu_delete_user', 'friends_remove_data' , 1);569 add_action( 'delete_user', 'friends_remove_data' , 1);570 add_action( 'make_spam_user', 'friends_remove_data' , 1);581 add_action( 'wpmu_delete_user', 'friends_remove_data' ); 582 add_action( 'delete_user', 'friends_remove_data' ); 583 add_action( 'make_spam_user', 'friends_remove_data' ); 571 584 572 585 … … 595 608 global $bp; 596 609 597 if ( isset( $_GET['new']) )598 bp_core_delete_notifications_for_user_by_type( $bp-> displayed_user->id, $bp->friends->id, 'friendship_accepted' );610 if ( isset( $_GET['new'] ) ) 611 bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->friends->id, 'friendship_accepted' ); 599 612 } 600 613 add_action( 'bp_activity_screen_my_activity', 'friends_clear_friend_notifications' ); -
trunk/bp-friends/bp-friends-classes.php
r2919 r3300 61 61 if ( $this->id ) { 62 62 // Update 63 $result = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET initiator_user_id = %d, friend_user_id = %d, is_confirmed = %d, is_limited = %d, date_created = FROM_UNIXTIME(%d)) WHERE id = %d", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created, $this->id ) );63 $result = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET initiator_user_id = %d, friend_user_id = %d, is_confirmed = %d, is_limited = %d, date_created = %s ) WHERE id = %d", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created, $this->id ) ); 64 64 } else { 65 65 // Save 66 $result = $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->friends->table_name} ( initiator_user_id, friend_user_id, is_confirmed, is_limited, date_created ) VALUES ( %d, %d, %d, %d, FROM_UNIXTIME(%d))", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created ) );66 $result = $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->friends->table_name} ( initiator_user_id, friend_user_id, is_confirmed, is_limited, date_created ) VALUES ( %d, %d, %d, %d, %s )", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created ) ); 67 67 $this->id = $wpdb->insert_id; 68 68 } … … 127 127 $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d OR friend_user_id = %d) AND is_confirmed = 1", $user_id, $user_id ) ); 128 128 129 if ( !$count ) 129 // Do not update meta if user has never had friends 130 if ( !$count && !get_user_meta( $user_id, 'total_friend_count', true ) ) 130 131 return 0; 131 132 132 update_user meta( $user_id, 'total_friend_count',$count );133 return $count;133 update_user_meta( $user_id, 'total_friend_count', (int)$count ); 134 return (int)$count; 134 135 } 135 136 … … 202 203 global $wpdb, $bp; 203 204 204 return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET is_confirmed = 1, date_created = FROM_UNIXTIME(%d) WHERE id = %d AND friend_user_id = %d",time(), $friendship_id, $bp->loggedin_user->id ) );205 return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET is_confirmed = 1, date_created = %s WHERE id = %d AND friend_user_id = %d", bp_core_current_time(), $friendship_id, $bp->loggedin_user->id ) ); 205 206 } 206 207 … … 315 316 global $wpdb, $bp; 316 317 318 // Get friends of $user_id 319 $friend_ids = BP_Friends_Friendship::get_friend_user_ids( $user_id ); 320 321 // Delete all friendships related to $user_id 317 322 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE friend_user_id = %d OR initiator_user_id = %d", $user_id, $user_id ) ); 318 323 319 324 // Delete friend request notifications for members who have a notification from this user. 320 325 $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE component_name = 'friends' AND ( component_action = 'friendship_request' OR component_action = 'friendship_accepted' ) AND item_id = %d", $user_id ) ); 326 327 // Loop through friend_ids and update their counts 328 foreach ( (array)$friend_ids as $friend_id ) { 329 BP_Friends_Friendship::total_friend_count( $friend_id ); 330 } 321 331 } 322 332 } -
trunk/bp-friends/bp-friends-notifications.php
r2941 r3300 6 6 $initiator_name = bp_core_get_user_displayname( $initiator_id ); 7 7 8 if ( 'no' == get_user meta( (int)$friend_id, 'notification_friends_friendship_request') )8 if ( 'no' == get_user_meta( (int)$friend_id, 'notification_friends_friendship_request', true ) ) 9 9 return false; 10 10 … … 18 18 19 19 // Set up and send the message 20 $to = $ud->user_email; 21 $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( 'New friendship request from %s', 'buddypress' ), $initiator_name ); 20 $to = $ud->user_email; 21 $sitename = wp_specialchars_decode( get_blog_option( BP_ROOT_BLOG, 'blogname' ), ENT_QUOTES ); 22 $subject = '[' . $sitename . '] ' . sprintf( __( 'New friendship request from %s', 'buddypress' ), $initiator_name ); 22 23 23 24 $message = sprintf( __( … … 48 49 $friend_name = bp_core_get_user_displayname( $friend_id ); 49 50 50 if ( 'no' == get_user meta( (int)$initiator_id, 'notification_friends_friendship_accepted') )51 if ( 'no' == get_user_meta( (int)$initiator_id, 'notification_friends_friendship_accepted', true ) ) 51 52 return false; 52 53 … … 57 58 58 59 // Set up and send the message 59 $to = $ud->user_email; 60 $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . sprintf( __( '%s accepted your friendship request', 'buddypress' ), $friend_name ); 60 $to = $ud->user_email; 61 $sitename = wp_specialchars_decode( get_blog_option( BP_ROOT_BLOG, 'blogname' ), ENT_QUOTES ); 62 $subject = '[' . $sitename . '] ' . sprintf( __( '%s accepted your friendship request', 'buddypress' ), $friend_name ); 61 63 62 64 $message = sprintf( __( -
trunk/bp-friends/bp-friends-templatetags.php
r3263 r3300 105 105 <form action="<?php echo $action ?>" id="friend-search-form" method="post"> 106 106 107 <label for="friend-search-box" id="friend-search-label"><?php echo $label ?></label>108 <input type="search" name="friend-search-box" id="friend-search-box" value="<?php echo $value ?>"<?php echo $disabled ?> />109 110 <?php wp_nonce_field( 'friends_search', '_wpnonce_friend_search' ) ?>111 <input type="hidden" name="initiator" id="initiator" value="<?php echo attribute_escape( $bp->displayed_user->id ) ?>" />107 <label for="friend-search-box" id="friend-search-label"><?php echo $label ?></label> 108 <input type="search" name="friend-search-box" id="friend-search-box" value="<?php echo $value ?>"<?php echo $disabled ?> /> 109 110 <?php wp_nonce_field( 'friends_search', '_wpnonce_friend_search' ) ?> 111 <input type="hidden" name="initiator" id="initiator" value="<?php echo esc_attr( $bp->displayed_user->id ) ?>" /> 112 112 113 113 </form> -
trunk/bp-groups.php
r3273 r3300 16 16 $bp->groups->slug = BP_GROUPS_SLUG; 17 17 18 $bp->groups->table_name = $wpdb->base_prefix . 'bp_groups'; 19 $bp->groups->table_name_members = $wpdb->base_prefix . 'bp_groups_members'; 20 $bp->groups->table_name_groupmeta = $wpdb->base_prefix . 'bp_groups_groupmeta'; 18 $bp->groups->table_name = $bp->table_prefix . 'bp_groups'; 19 $bp->groups->table_name_members = $bp->table_prefix . 'bp_groups_members'; 20 $bp->groups->table_name_groupmeta = $bp->table_prefix . 'bp_groups_groupmeta'; 21 21 22 $bp->groups->format_notification_function = 'groups_format_notifications'; 22 23 … … 37 38 $bp->groups->valid_status = apply_filters( 'groups_valid_status', array( 'public', 'private', 'hidden' ) ); 38 39 40 // Auto join group when non group member performs group activity 41 $bp->groups->auto_join = defined( 'BP_DISABLE_AUTO_GROUP_JOIN' ) ? false : true; 42 39 43 do_action( 'groups_setup_globals' ); 40 44 } … … 44 48 global $bp; 45 49 46 if ( $ group_id = BP_Groups_Group::group_exists($bp->current_action) ) {50 if ( $bp->current_component == $bp->groups->slug && $group_id = BP_Groups_Group::group_exists($bp->current_action) ) { 47 51 48 52 /* This is a single group page. */ … … 51 55 52 56 /* Using "item" not "group" for generic support in other components. */ 53 if ( is_s ite_admin() )57 if ( is_super_admin() ) 54 58 $bp->is_item_admin = 1; 55 59 else … … 100 104 101 105 if ( !$bp->bp_options_avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->groups->current_group->id, 'object' => 'group', 'type' => 'thumb', 'avatar_dir' => 'group-avatars', 'alt' => __( 'Group Avatar', 'buddypress' ) ) ) ) 102 $bp->bp_options_avatar = '<img src="' . attribute_escape( $group->avatar_full ) . '" class="avatar" alt="' . attribute_escape( $group->name ) . '" />';106 $bp->bp_options_avatar = '<img src="' . esc_attr( $group->avatar_full ) . '" class="avatar" alt="' . esc_attr( $group->name ) . '" />'; 103 107 104 108 $group_link = $bp->root_domain . '/' . $bp->groups->slug . '/' . $bp->groups->current_group->slug . '/'; … … 106 110 // If this is a private or hidden group, does the user have access? 107 111 if ( 'private' == $bp->groups->current_group->status || 'hidden' == $bp->groups->current_group->status ) { 108 if ( $bp->groups->current_group->is_user_member && is_user_logged_in() || is_s ite_admin() )112 if ( $bp->groups->current_group->is_user_member && is_user_logged_in() || is_super_admin() ) 109 113 $bp->groups->current_group->user_has_access = true; 110 114 else … … 128 132 129 133 // If this is a private group, and the user is not a member, show a "Request Membership" nav item. 130 if ( !is_s ite_admin() && is_user_logged_in() && !$bp->groups->current_group->is_user_member && !groups_check_for_membership_request( $bp->loggedin_user->id, $bp->groups->current_group->id ) && $bp->groups->current_group->status == 'private' )134 if ( !is_super_admin() && is_user_logged_in() && !$bp->groups->current_group->is_user_member && !groups_check_for_membership_request( $bp->loggedin_user->id, $bp->groups->current_group->id ) && $bp->groups->current_group->status == 'private' ) 131 135 bp_core_new_subnav_item( array( 'name' => __( 'Request Membership', 'buddypress' ), 'slug' => 'request-membership', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_request_membership', 'position' => 30 ) ); 132 136 … … 166 170 167 171 /* Don't show this menu to non site admins or if you're viewing your own profile */ 168 if ( !is_s ite_admin() )172 if ( !is_super_admin() ) 169 173 return false; 170 174 ?> … … 226 230 227 231 groups_record_activity( array( 228 'action' => apply_filters( 'groups_activity_accepted_invite_action', sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . attribute_escape( $group->name ) . '</a>' ), $bp->loggedin_user->id, &$group ),232 'action' => apply_filters( 'groups_activity_accepted_invite_action', sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>' ), $bp->loggedin_user->id, &$group ), 229 233 'type' => 'joined_group', 230 234 'item_id' => $group->id … … 292 296 293 297 /* Auto join this user if they are not yet a member of this group */ 294 if ( !is_site_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )298 if ( $bp->groups->auto_join && !is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) ) 295 299 groups_join_group( $bp->groups->current_group->id, $bp->loggedin_user->id ); 296 300 … … 470 474 471 475 /* Auto join this user if they are not yet a member of this group */ 472 if ( !is_site_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )476 if ( $bp->groups->auto_join && !is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) ) 473 477 groups_join_group( $bp->groups->current_group->id, $bp->loggedin_user->id ); 474 478 … … 492 496 493 497 if ( $bp->is_single_item ) { 498 /* Refresh the group member count meta */ 499 groups_update_groupmeta( $bp->groups->current_group->id, 'total_member_count', groups_get_total_member_count( $bp->groups->current_group->id ) ); 500 494 501 do_action( 'groups_screen_group_members', $bp->groups->current_group->id ); 495 502 bp_core_load_template( apply_filters( 'groups_template_group_members', 'groups/single/home' ) ); … … 711 718 $status = $bp->action_variables[2]; 712 719 713 / * Check the nonce first. */720 // Check the nonce first. 714 721 if ( !check_admin_referer( 'groups_promote_member' ) ) 715 722 return false; 716 723 717 724 // Promote a user. 718 if ( !groups_promote_member( $user_id, $bp->groups->current_group->id, $status ) ) {725 if ( !groups_promote_member( $user_id, $bp->groups->current_group->id, $status ) ) 719 726 bp_core_add_message( __( 'There was an error when promoting that user, please try again', 'buddypress' ), 'error' ); 720 } else {727 else 721 728 bp_core_add_message( __( 'User promoted successfully', 'buddypress' ) ); 722 }723 729 724 730 do_action( 'groups_promoted_member', $user_id, $bp->groups->current_group->id ); … … 730 736 $user_id = $bp->action_variables[2]; 731 737 732 / * Check the nonce first. */738 // Check the nonce first. 733 739 if ( !check_admin_referer( 'groups_demote_member' ) ) 734 740 return false; 735 741 736 742 // Demote a user. 737 if ( !groups_demote_member( $user_id, $bp->groups->current_group->id ) ) {743 if ( !groups_demote_member( $user_id, $bp->groups->current_group->id ) ) 738 744 bp_core_add_message( __( 'There was an error when demoting that user, please try again', 'buddypress' ), 'error' ); 739 } else {745 else 740 746 bp_core_add_message( __( 'User demoted successfully', 'buddypress' ) ); 741 }742 747 743 748 do_action( 'groups_demoted_member', $user_id, $bp->groups->current_group->id ); … … 749 754 $user_id = $bp->action_variables[2]; 750 755 751 / * Check the nonce first. */756 // Check the nonce first. 752 757 if ( !check_admin_referer( 'groups_ban_member' ) ) 753 758 return false; 754 759 755 760 // Ban a user. 756 if ( !groups_ban_member( $user_id, $bp->groups->current_group->id ) ) {761 if ( !groups_ban_member( $user_id, $bp->groups->current_group->id ) ) 757 762 bp_core_add_message( __( 'There was an error when banning that user, please try again', 'buddypress' ), 'error' ); 758 } else {763 else 759 764 bp_core_add_message( __( 'User banned successfully', 'buddypress' ) ); 760 }761 765 762 766 do_action( 'groups_banned_member', $user_id, $bp->groups->current_group->id ); … … 768 772 $user_id = $bp->action_variables[2]; 769 773 770 / * Check the nonce first. */774 // Check the nonce first. 771 775 if ( !check_admin_referer( 'groups_unban_member' ) ) 772 776 return false; 773 777 774 778 // Remove a ban for user. 775 if ( !groups_unban_member( $user_id, $bp->groups->current_group->id ) ) {779 if ( !groups_unban_member( $user_id, $bp->groups->current_group->id ) ) 776 780 bp_core_add_message( __( 'There was an error when unbanning that user, please try again', 'buddypress' ), 'error' ); 777 } else {781 else 778 782 bp_core_add_message( __( 'User ban removed successfully', 'buddypress' ) ); 779 }780 783 781 784 do_action( 'groups_unbanned_member', $user_id, $bp->groups->current_group->id ); … … 784 787 } 785 788 789 if ( 'remove' == $bp->action_variables[1] && is_numeric( $bp->action_variables[2] ) ) { 790 $user_id = $bp->action_variables[2]; 791 792 // Check the nonce first. 793 if ( !check_admin_referer( 'groups_remove_member' ) ) 794 return false; 795 796 // Remove a user. 797 if ( !groups_remove_member( $user_id, $bp->groups->current_group->id ) ) 798 bp_core_add_message( __( 'There was an error removing that user from the group, please try again', 'buddypress' ), 'error' ); 799 else 800 bp_core_add_message( __( 'User removed successfully', 'buddypress' ) ); 801 802 do_action( 'groups_removed_member', $user_id, $bp->groups->current_group->id ); 803 804 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . 'admin/manage-members/' ); 805 } 806 786 807 do_action( 'groups_screen_group_admin_manage_members', $bp->groups->current_group->id ); 787 808 … … 795 816 796 817 if ( $bp->current_component == $bp->groups->slug && 'membership-requests' == $bp->action_variables[0] ) { 818 819 /* Ask for a login if the user is coming here via an email notification */ 820 if ( !is_user_logged_in() ) 821 bp_core_redirect( site_url( 'wp-login.php?redirect_to=' . $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_item . '/admin/membership-requests/' ) ); 797 822 798 823 if ( !$bp->is_item_admin || 'public' == $bp->groups->current_group->status ) … … 850 875 if ( $bp->current_component == $bp->groups->slug && 'delete-group' == $bp->action_variables[0] ) { 851 876 852 if ( !$bp->is_item_admin && !is_s ite_admin() )877 if ( !$bp->is_item_admin && !is_super_admin() ) 853 878 return false; 854 879 … … 881 906 function groups_screen_notification_settings() { 882 907 global $current_user; ?> 883 <table class="notification-settings" id="groups-notification-settings"> 884 <tr> 885 <th class="icon"></th> 886 <th class="title"><?php _e( 'Groups', 'buddypress' ) ?></th> 887 <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th> 888 <th class="no"><?php _e( 'No', 'buddypress' )?></th> 889 </tr> 890 <tr> 891 <td></td> 892 <td><?php _e( 'A member invites you to join a group', 'buddypress' ) ?></td> 893 <td class="yes"><input type="radio" name="notifications[notification_groups_invite]" value="yes" <?php if ( !get_usermeta( $current_user->id, 'notification_groups_invite') || 'yes' == get_usermeta( $current_user->id, 'notification_groups_invite') ) { ?>checked="checked" <?php } ?>/></td> 894 <td class="no"><input type="radio" name="notifications[notification_groups_invite]" value="no" <?php if ( 'no' == get_usermeta( $current_user->id, 'notification_groups_invite') ) { ?>checked="checked" <?php } ?>/></td> 895 </tr> 896 <tr> 897 <td></td> 898 <td><?php _e( 'Group information is updated', 'buddypress' ) ?></td> 899 <td class="yes"><input type="radio" name="notifications[notification_groups_group_updated]" value="yes" <?php if ( !get_usermeta( $current_user->id, 'notification_groups_group_updated') || 'yes' == get_usermeta( $current_user->id, 'notification_groups_group_updated') ) { ?>checked="checked" <?php } ?>/></td> 900 <td class="no"><input type="radio" name="notifications[notification_groups_group_updated]" value="no" <?php if ( 'no' == get_usermeta( $current_user->id, 'notification_groups_group_updated') ) { ?>checked="checked" <?php } ?>/></td> 901 </tr> 902 <tr> 903 <td></td> 904 <td><?php _e( 'You are promoted to a group administrator or moderator', 'buddypress' ) ?></td> 905 <td class="yes"><input type="radio" name="notifications[notification_groups_admin_promotion]" value="yes" <?php if ( !get_usermeta( $current_user->id, 'notification_groups_admin_promotion') || 'yes' == get_usermeta( $current_user->id, 'notification_groups_admin_promotion') ) { ?>checked="checked" <?php } ?>/></td> 906 <td class="no"><input type="radio" name="notifications[notification_groups_admin_promotion]" value="no" <?php if ( 'no' == get_usermeta( $current_user->id, 'notification_groups_admin_promotion') ) { ?>checked="checked" <?php } ?>/></td> 907 </tr> 908 <tr> 909 <td></td> 910 <td><?php _e( 'A member requests to join a private group for which you are an admin', 'buddypress' ) ?></td> 911 <td class="yes"><input type="radio" name="notifications[notification_groups_membership_request]" value="yes" <?php if ( !get_usermeta( $current_user->id, 'notification_groups_membership_request') || 'yes' == get_usermeta( $current_user->id, 'notification_groups_membership_request') ) { ?>checked="checked" <?php } ?>/></td> 912 <td class="no"><input type="radio" name="notifications[notification_groups_membership_request]" value="no" <?php if ( 'no' == get_usermeta( $current_user->id, 'notification_groups_membership_request') ) { ?>checked="checked" <?php } ?>/></td> 913 </tr> 914 915 <?php do_action( 'groups_screen_notification_settings' ); ?> 908 <table class="notification-settings zebra" id="groups-notification-settings"> 909 <thead> 910 <tr> 911 <th class="icon"></th> 912 <th class="title"><?php _e( 'Groups', 'buddypress' ) ?></th> 913 <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th> 914 <th class="no"><?php _e( 'No', 'buddypress' )?></th> 915 </tr> 916 </thead> 917 918 <tbody> 919 <tr> 920 <td></td> 921 <td><?php _e( 'A member invites you to join a group', 'buddypress' ) ?></td> 922 <td class="yes"><input type="radio" name="notifications[notification_groups_invite]" value="yes" <?php if ( !get_user_meta( $current_user->id, 'notification_groups_invite', true ) || 'yes' == get_user_meta( $current_user->id, 'notification_groups_invite', true ) ) { ?>checked="checked" <?php } ?>/></td> 923 <td class="no"><input type="radio" name="notifications[notification_groups_invite]" value="no" <?php if ( 'no' == get_user_meta( $current_user->id, 'notification_groups_invite', true ) ) { ?>checked="checked" <?php } ?>/></td> 924 </tr> 925 <tr> 926 <td></td> 927 <td><?php _e( 'Group information is updated', 'buddypress' ) ?></td> 928 <td class="yes"><input type="radio" name="notifications[notification_groups_group_updated]" value="yes" <?php if ( !get_user_meta( $current_user->id, 'notification_groups_group_updated', true ) || 'yes' == get_user_meta( $current_user->id, 'notification_groups_group_updated', true ) ) { ?>checked="checked" <?php } ?>/></td> 929 <td class="no"><input type="radio" name="notifications[notification_groups_group_updated]" value="no" <?php if ( 'no' == get_user_meta( $current_user->id, 'notification_groups_group_updated', true ) ) { ?>checked="checked" <?php } ?>/></td> 930 </tr> 931 <tr> 932 <td></td> 933 <td><?php _e( 'You are promoted to a group administrator or moderator', 'buddypress' ) ?></td> 934 <td class="yes"><input type="radio" name="notifications[notification_groups_admin_promotion]" value="yes" <?php if ( !get_user_meta( $current_user->id, 'notification_groups_admin_promotion', true ) || 'yes' == get_user_meta( $current_user->id, 'notification_groups_admin_promotion', true ) ) { ?>checked="checked" <?php } ?>/></td> 935 <td class="no"><input type="radio" name="notifications[notification_groups_admin_promotion]" value="no" <?php if ( 'no' == get_user_meta( $current_user->id, 'notification_groups_admin_promotion', true ) ) { ?>checked="checked" <?php } ?>/></td> 936 </tr> 937 <tr> 938 <td></td> 939 <td><?php _e( 'A member requests to join a private group for which you are an admin', 'buddypress' ) ?></td> 940 <td class="yes"><input type="radio" name="notifications[notification_groups_membership_request]" value="yes" <?php if ( !get_user_meta( $current_user->id, 'notification_groups_membership_request', true ) || 'yes' == get_user_meta( $current_user->id, 'notification_groups_membership_request', true ) ) { ?>checked="checked" <?php } ?>/></td> 941 <td class="no"><input type="radio" name="notifications[notification_groups_membership_request]" value="no" <?php if ( 'no' == get_user_meta( $current_user->id, 'notification_groups_membership_request', true ) ) { ?>checked="checked" <?php } ?>/></td> 942 </tr> 943 944 <?php do_action( 'groups_screen_notification_settings' ); ?> 945 </tbody> 916 946 </table> 917 947 <?php … … 982 1012 } 983 1013 984 if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'name' => $_POST['group-name'], 'description' => $_POST['group-desc'], 'slug' => groups_check_slug( sanitize_title( $_POST['group-name']) ), 'date_created' => gmdate( "Y-m-d H:i:s" ), 'status' => 'public' ) ) ) {1014 if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'name' => $_POST['group-name'], 'description' => $_POST['group-desc'], 'slug' => groups_check_slug( sanitize_title( esc_attr( $_POST['group-name'] ) ) ), 'date_created' => gmdate( "Y-m-d H:i:s" ), 'status' => 'public' ) ) ) { 985 1015 bp_core_add_message( __( 'There was an error