Index: /trunk/bp-core/admin/bp-core-functions.php
===================================================================
--- /trunk/bp-core/admin/bp-core-functions.php (revision 8116)
+++ /trunk/bp-core/admin/bp-core-functions.php (revision 8117)
@@ -75,9 +75,14 @@
*/
function bp_core_modify_admin_menu_highlight() {
- global $plugin_page, $submenu_file;
+ global $pagenow, $plugin_page, $submenu_file;
// This tweaks the Settings subnav menu to show only one BuddyPress menu item
if ( ! in_array( $plugin_page, array( 'bp-activity', 'bp-general-settings', ) ) )
$submenu_file = 'bp-components';
+
+ // Network Admin > Tools
+ if ( in_array( $plugin_page, array( 'bp-tools', 'available-tools' ) ) ) {
+ $submenu_file = $plugin_page;
+ }
}
@@ -389,5 +394,5 @@
'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bp-settings' ), 'admin.php' ) ),
'name' => __( 'Settings', 'buddypress' )
- )
+ ),
);
Index: /trunk/bp-core/admin/bp-core-tools.php
===================================================================
--- /trunk/bp-core/admin/bp-core-tools.php (revision 8117)
+++ /trunk/bp-core/admin/bp-core-tools.php (revision 8117)
@@ -0,0 +1,329 @@
+
+
+ array(
+ 'bp-total-member-count',
+ __( 'Count total members', 'buddypress' ),
+ 'bp_admin_repair_count_members',
+ ),
+ );
+
+ // Friends:
+ // - user friend count
+ if ( bp_is_active( 'friends' ) ) {
+ $repair_list[0] = array(
+ 'bp-user-friends',
+ __( 'Count friends for each user', 'buddypress' ),
+ 'bp_admin_repair_friend_count',
+ );
+ }
+
+ // Groups:
+ // - user group count
+ if ( bp_is_active( 'groups' ) ) {
+ $repair_list[10] = array(
+ 'bp-group-count',
+ __( 'Count groups for each user', 'buddypress' ),
+ 'bp_admin_repair_group_count',
+ );
+ }
+
+ ksort( $repair_list );
+
+ return (array) apply_filters( 'bp_repair_list', $repair_list );
+}
+
+/**
+ * Recalculate friend counts for each user.
+ *
+ * @since BuddyPress (2.0.0)
+ *
+ * @return array
+ */
+function bp_admin_repair_friend_count() {
+ global $wpdb, $bp;
+
+ if ( ! bp_is_active( 'friends' ) ) {
+ return;
+ }
+
+ $statement = __( 'Counting the number of friends for each user… %s', 'buddypress' );
+ $result = __( 'Failed!', 'buddypress' );
+
+ $sql_delete = "DELETE FROM {$wpdb->usermeta} WHERE meta_key IN ( 'total_friend_count' );";
+ if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) {
+ return array( 1, sprintf( $statement, $result ) );
+ }
+
+ // Walk through all users on the site
+ $total_users = $wpdb->get_row( "SELECT count(ID) as c FROM {$wpdb->users}" )->c;
+
+ $updated = array();
+ if ( $total_users > 0 ) {
+ $per_query = 500;
+ $offset = 0;
+ while ( $offset < $total_users ) {
+ // Only bother updating counts for users who actually have friendships
+ $friendships = $wpdb->get_results( $wpdb->prepare( "SELECT initiator_user_id, friend_user_id FROM {$bp->friends->table_name} WHERE is_confirmed = 1 AND ( ( initiator_user_id > %d AND initiator_user_id <= %d ) OR ( friend_user_id > %d AND friend_user_id <= %d ) )", $offset, $offset + $per_query, $offset, $offset + $per_query ) );
+
+ // The previous query will turn up duplicates, so we
+ // filter them here
+ foreach ( $friendships as $friendship ) {
+ if ( ! isset( $updated[ $friendship->initiator_user_id ] ) ) {
+ BP_Friends_Friendship::total_friend_count( $friendship->initiator_user_id );
+ $updated[ $friendship->initiator_user_id ] = 1;
+ }
+
+ if ( ! isset( $updated[ $friendship->friend_user_id ] ) ) {
+ BP_Friends_Friendship::total_friend_count( $friendship->friend_user_id );
+ $updated[ $friendship->friend_user_id ] = 1;
+ }
+ }
+
+ $offset += $per_query;
+ }
+ } else {
+ return array( 2, sprintf( $statement, $result ) );
+ }
+
+ return array( 0, sprintf( $statement, __( 'Complete!', 'buddypress' ) ) );
+}
+
+/**
+ * Recalculate group counts for each user.
+ *
+ * @since BuddyPress (2.0.0)
+ *
+ * @return array
+ */
+function bp_admin_repair_group_count() {
+ global $wpdb, $bp;
+
+ if ( ! bp_is_active( 'groups' ) ) {
+ return;
+ }
+
+ $statement = __( 'Counting the number of groups for each user… %s', 'buddypress' );
+ $result = __( 'Failed!', 'buddypress' );
+
+ $sql_delete = "DELETE FROM {$wpdb->usermeta} WHERE meta_key IN ( 'total_group_count' );";
+ if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) {
+ return array( 1, sprintf( $statement, $result ) );
+ }
+
+ // Walk through all users on the site
+ $total_users = $wpdb->get_row( "SELECT count(ID) as c FROM {$wpdb->users}" )->c;
+
+ if ( $total_users > 0 ) {
+ $per_query = 500;
+ $offset = 0;
+ while ( $offset < $total_users ) {
+ // But only bother to update counts for users that have groups
+ $users = $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->groups->table_name_members} WHERE is_confirmed = 1 AND is_banned = 0 AND user_id > %d AND user_id <= %d", $offset, $offset + $per_query ) );
+
+ foreach ( $users as $user ) {
+ BP_Groups_Member::refresh_total_group_count_for_user( $user );
+ }
+
+ $offset += $per_query;
+ }
+ } else {
+ return array( 2, sprintf( $statement, $result ) );
+ }
+
+ return array( 0, sprintf( $statement, __( 'Complete!', 'buddypress' ) ) );
+}
+
+/**
+ * Recalculate the total number of active site members.
+ *
+ * @since BuddyPress (2.0.0)
+ */
+function bp_admin_repair_count_members() {
+ $statement = __( 'Counting the number of active members on the site… %s', 'buddypress' );
+ delete_transient( 'bp_active_member_count' );
+ bp_core_get_active_member_count();
+ return array( 0, sprintf( $statement, __( 'Complete!', 'buddypress' ) ) );
+}
+
+/**
+ * Assemble admin notices relating success/failure of repair processes.
+ *
+ * @since BuddyPress (2.0.0)
+ *
+ * @param string $message Feedback message.
+ * @param unknown $class Unused.
+ */
+function bp_admin_tools_feedback( $message, $class = false ) {
+ if ( is_string( $message ) ) {
+ $message = '' . $message . '
';
+ $class = $class ? $class : 'updated';
+ } elseif ( is_wp_error( $message ) ) {
+ $errors = $message->get_error_messages();
+
+ switch ( count( $errors ) ) {
+ case 0:
+ return false;
+ break;
+
+ case 1:
+ $message = '' . $errors[0] . '
';
+ break;
+
+ default:
+ $message = '' . "\n\t" . '- ' . implode( '
' . "\n\t" . '- ', $errors ) . '
' . "\n" . '
';
+ break;
+ }
+
+ $class = $class ? $class : 'error';
+ } else {
+ return false;
+ }
+
+ $message = '' . $message . '
';
+ $message = str_replace( "'", "\'", $message );
+ $lambda = create_function( '', "echo '$message';" );
+
+ add_action( 'admin_notices', $lambda );
+
+ return $lambda;
+}
+
+/**
+ * Render the Available Tools page.
+ *
+ * We register this page on Network Admin as a top-level home for our
+ * BuddyPress tools. This displays the default content.
+ *
+ * @since BuddyPress (2.0.0)
+ */
+function bp_core_admin_available_tools_page() {
+ ?>
+
+
+
+
+
+
+ 'bp-tools'
+ );
+
+ $page = bp_core_do_network_admin() ? 'admin.php' : 'tools.php' ;
+ $url = add_query_arg( $query_arg, bp_get_admin_url( $page ) );
+ ?>
+
+ admin_dir . 'bp-core-components.php' );
require( $this->admin_dir . 'bp-core-slugs.php' );
+ require( $this->admin_dir . 'bp-core-tools.php' );
}
@@ -153,4 +154,8 @@
// Add a link to BuddyPress About page to the admin bar
add_action( 'admin_bar_menu', array( $this, 'admin_bar_about_link' ), 15 );
+
+ // Add a description of new BuddyPress tools in the available tools page
+ add_action( 'tool_box', 'bp_core_admin_available_tools_intro' );
+ add_action( 'bp_network_tool_box', 'bp_core_admin_available_tools_intro' );
/** Filters ***********************************************************/
@@ -243,4 +248,40 @@
);
+ // For consistency with non-Multisite, we add a Tools menu in
+ // the Network Admin as a home for our Tools panel
+ if ( is_multisite() && bp_core_do_network_admin() ) {
+ $tools_parent = 'network-tools';
+
+ $hooks[] = add_menu_page(
+ __( 'Tools', 'buddypress' ),
+ __( 'Tools', 'buddypress' ),
+ 'manage_network_options',
+ $tools_parent,
+ 'bp_core_tools_top_level_item',
+ '',
+ 24 // just above Settings
+ );
+
+ $hooks[] = add_submenu_page(
+ $tools_parent,
+ __( 'Available Tools', 'buddypress' ),
+ __( 'Available Tools', 'buddypress' ),
+ 'manage_network_options',
+ 'available-tools',
+ 'bp_core_admin_available_tools_page'
+ );
+ } else {
+ $tools_parent = 'tools.php';
+ }
+
+ $hooks[] = add_submenu_page(
+ $tools_parent,
+ __( 'BuddyPress Tools', 'buddypress' ),
+ __( 'BuddyPress', 'buddypress' ),
+ 'manage_options',
+ 'bp-tools',
+ 'bp_core_admin_tools'
+ );
+
// Fudge the highlighted subnav item when on a BuddyPress admin page
foreach( $hooks as $hook ) {
@@ -401,4 +442,7 @@
remove_submenu_page( $this->settings_page, 'bp-page-settings' );
remove_submenu_page( $this->settings_page, 'bp-settings' );
+
+ // Network Admin Tools
+ remove_submenu_page( 'network-tools', 'network-tools' );
// About and Credits pages