Commit 4216cf9d authored by root's avatar root Committed by lechuck
Browse files

Import buddypress 1.2.8

parent be10a4fc
......@@ -98,7 +98,7 @@ function bp_activity_check_installed() {
if ( get_site_option( 'bp-activity-db-version' ) < BP_ACTIVITY_DB_VERSION )
bp_activity_install();
}
add_action( 'admin_menu', 'bp_activity_check_installed' );
add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', 'bp_activity_check_installed' );
function bp_activity_setup_root_component() {
/* Register 'activity' as a root component (for RSS feed use) */
......
......@@ -60,7 +60,7 @@ function bp_blogs_check_installed() {
bp_blogs_install();
}
}
add_action( 'admin_menu', 'bp_blogs_check_installed' );
add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', 'bp_blogs_check_installed' );
function bp_blogs_setup_globals() {
global $bp, $wpdb;
......
......@@ -284,7 +284,7 @@ function bp_core_check_installed() {
if ( get_site_option( 'bp-core-db-version' ) < BP_CORE_DB_VERSION )
bp_core_install();
}
add_action( 'admin_menu', 'bp_core_check_installed' );
add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', 'bp_core_check_installed' );
/**
* bp_core_add_admin_menu()
......@@ -300,7 +300,11 @@ function bp_core_add_admin_menu() {
if ( !is_super_admin() )
return false;
/* Add the administration tab under the "Site Admin" tab for site administrators */
// If this is WP 3.1+ and multisite is enabled, only load on the Network Admin
if ( is_multisite() && function_exists( 'is_network_admin' ) && ! is_network_admin() )
return false;
// Add the administration tab under the "Site Admin" tab for site administrators
bp_core_add_admin_menu_page( array(
'menu_title' => __( 'BuddyPress', 'buddypress' ),
'page_title' => __( 'BuddyPress', 'buddypress' ),
......@@ -312,7 +316,7 @@ function bp_core_add_admin_menu() {
add_submenu_page( 'bp-general-settings', __( 'General Settings', 'buddypress'), __( 'General Settings', 'buddypress' ), 'manage_options', 'bp-general-settings', 'bp_core_admin_settings' );
add_submenu_page( 'bp-general-settings', __( 'Component Setup', 'buddypress'), __( 'Component Setup', 'buddypress' ), 'manage_options', 'bp-component-setup', 'bp_core_admin_component_setup' );
}
add_action( 'admin_menu', 'bp_core_add_admin_menu' );
add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', 'bp_core_add_admin_menu' );
/**
* bp_core_is_root_component()
......
......@@ -43,19 +43,19 @@ function bp_core_admin_settings() {
<tbody>
<?php if ( function_exists( 'xprofile_install' ) ) :?>
<tr>
<th scope="row"><?php _e( 'Base profile group name', 'buddypress' ) ?>:</th>
<th scope="row"><p><?php _e( 'Base profile group name', 'buddypress' ) ?>:</p></th>
<td>
<input name="bp-admin[bp-xprofile-base-group-name]" id="bp-xprofile-base-group-name" value="<?php echo get_site_option('bp-xprofile-base-group-name') ?>" />
</td>
</tr>
<tr>
<th scope="row"><?php _e( 'Full Name field name', 'buddypress' ) ?>:</th>
<th scope="row"><p><?php _e( 'Full Name field name', 'buddypress' ) ?>:</p></th>
<td>
<input name="bp-admin[bp-xprofile-fullname-field-name]" id="bp-xprofile-fullname-field-name" value="<?php echo get_site_option('bp-xprofile-fullname-field-name') ?>" />
</td>
</tr>
<tr>
<th scope="row"><?php _e( 'Disable BuddyPress to WordPress profile syncing?', 'buddypress' ) ?>:</th>
<th scope="row"><p><?php _e( 'Disable BuddyPress to WordPress profile syncing?', 'buddypress' ) ?>:</p></th>
<td>
<input type="radio" name="bp-admin[bp-disable-profile-sync]"<?php if ( (int)get_site_option( 'bp-disable-profile-sync' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-profile-sync" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
<input type="radio" name="bp-admin[bp-disable-profile-sync]"<?php if ( !(int)get_site_option( 'bp-disable-profile-sync' ) || '' == get_site_option( 'bp-disable-profile-sync' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-profile-sync" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
......@@ -63,21 +63,21 @@ function bp_core_admin_settings() {
</tr>
<?php endif; ?>
<tr>
<th scope="row"><?php _e( 'Hide admin bar for logged out users?', 'buddypress' ) ?>:</th>
<th scope="row"><p><?php _e( 'Hide admin bar for logged out users?', 'buddypress' ) ?>:</p></th>
<td>
<input type="radio" name="bp-admin[hide-loggedout-adminbar]"<?php if ( (int)get_site_option( 'hide-loggedout-adminbar' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-hide-loggedout-adminbar-yes" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
<input type="radio" name="bp-admin[hide-loggedout-adminbar]"<?php if ( !(int)get_site_option( 'hide-loggedout-adminbar' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-hide-loggedout-adminbar-no" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
</td>
</tr>
<tr>
<th scope="row"><?php _e( 'Disable avatar uploads? (Gravatars will still work)', 'buddypress' ) ?>:</th>
<th scope="row"><p><?php _e( 'Disable avatar uploads? (Gravatars will still work)', 'buddypress' ) ?>:</p></th>
<td>
<input type="radio" name="bp-admin[bp-disable-avatar-uploads]"<?php if ( (int)get_site_option( 'bp-disable-avatar-uploads' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-disable-avatar-uploads-yes" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
<input type="radio" name="bp-admin[bp-disable-avatar-uploads]"<?php if ( !(int)get_site_option( 'bp-disable-avatar-uploads' ) ) : ?> checked="checked"<?php endif; ?> id="bp-admin-disable-avatar-uploads-no" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
</td>
</tr>
<tr>
<th scope="row"><?php _e( 'Disable user account deletion?', 'buddypress' ) ?>:</th>
<th scope="row"><p><?php _e( 'Disable user account deletion?', 'buddypress' ) ?>:</p></th>
<td>
<input type="radio" name="bp-admin[bp-disable-account-deletion]"<?php if ( (int)get_site_option( 'bp-disable-account-deletion' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-account-deletion" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
<input type="radio" name="bp-admin[bp-disable-account-deletion]"<?php if ( !(int)get_site_option( 'bp-disable-account-deletion' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-account-deletion" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
......@@ -85,7 +85,7 @@ function bp_core_admin_settings() {
</tr>
<?php if ( function_exists( 'bp_forums_setup') ) : ?>
<tr>
<th scope="row"><?php _e( 'Disable global forum directory?', 'buddypress' ) ?>:</th>
<th scope="row"><p><?php _e( 'Disable global forum directory?', 'buddypress' ) ?>:</p></th>
<td>
<input type="radio" name="bp-admin[bp-disable-forum-directory]"<?php if ( (int)get_site_option( 'bp-disable-forum-directory' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-forum-directory" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
<input type="radio" name="bp-admin[bp-disable-forum-directory]"<?php if ( !(int)get_site_option( 'bp-disable-forum-directory' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-forum-directory" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
......@@ -94,7 +94,7 @@ function bp_core_admin_settings() {
<?php endif; ?>
<?php if ( function_exists( 'bp_activity_install') ) : ?>
<tr>
<th scope="row"><?php _e( 'Disable activity stream commenting on blog and forum posts?', 'buddypress' ) ?>:</th>
<th scope="row"><p><?php _e( 'Disable activity stream commenting on blog and forum posts?', 'buddypress' ) ?>:</p></th>
<td>
<input type="radio" name="bp-admin[bp-disable-blogforum-comments]"<?php if ( (int)get_site_option( 'bp-disable-blogforum-comments' ) || false === get_site_option( 'bp-disable-blogforum-comments' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-blogforum-comments" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
<input type="radio" name="bp-admin[bp-disable-blogforum-comments]"<?php if ( !(int)get_site_option( 'bp-disable-blogforum-comments' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-blogforum-comments" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
......@@ -103,7 +103,7 @@ function bp_core_admin_settings() {
<?php endif; ?>
<tr>
<th scope="row"><?php _e( 'Default User Avatar', 'buddypress' ) ?></th>
<th scope="row"><p><?php _e( 'Default User Avatar', 'buddypress' ) ?></p></th>
<td>
<p><?php _e( 'For users without a custom avatar of their own, you can either display a generic logo or a generated one based on their email address', 'buddypress' ) ?></p>
......
......@@ -273,18 +273,42 @@ function bp_adminbar_random_menu() {
<?php
}
// Actions used to build the admin bar
add_action( 'bp_adminbar_logo', 'bp_adminbar_logo' );
add_action( 'bp_adminbar_menus', 'bp_adminbar_login_menu', 2 );
add_action( 'bp_adminbar_menus', 'bp_adminbar_account_menu', 4 );
add_action( 'bp_adminbar_menus', 'bp_adminbar_blogs_menu', 6 );
add_action( 'bp_adminbar_menus', 'bp_adminbar_thisblog_menu', 6 );
add_action( 'bp_adminbar_menus', 'bp_adminbar_notifications_menu', 8 );
add_action( 'bp_adminbar_menus', 'bp_adminbar_authors_menu', 12 );
add_action( 'bp_adminbar_menus', 'bp_adminbar_random_menu', 100 );
// Actions used to append admin bar to footer
add_action( 'wp_footer', 'bp_core_admin_bar', 8 );
add_action( 'admin_footer', 'bp_core_admin_bar' );
/**
* Provides fallback support for the WordPress 3.1 admin bar
*
* By default, this function turns off the WP 3.1 admin bar in favor of the classic BP BuddyBar.
* To turn off the BP BuddyBar in favor of WP's admin bar, place the following in wp-config.php:
* define( 'BP_USE_WP_ADMIN_BAR', true );
*
* @package BuddyPress Core
* @since 1.2.8
*/
function bp_core_load_admin_bar() {
global $wp_version;
if ( defined( 'BP_USE_WP_ADMIN_BAR' ) && BP_USE_WP_ADMIN_BAR && version_compare( $wp_version, 3.1, '>=' ) ) {
// TODO: Add BP support to WP admin bar
return;
} elseif ( !defined( 'BP_DISABLE_ADMIN_BAR' ) || !BP_DISABLE_ADMIN_BAR ) {
// Keep the WP admin bar from loading
if ( function_exists( 'show_admin_bar' ) )
show_admin_bar( false );
// Actions used to build the BP admin bar
add_action( 'bp_adminbar_logo', 'bp_adminbar_logo' );
add_action( 'bp_adminbar_menus', 'bp_adminbar_login_menu', 2 );
add_action( 'bp_adminbar_menus', 'bp_adminbar_account_menu', 4 );
add_action( 'bp_adminbar_menus', 'bp_adminbar_blogs_menu', 6 );
add_action( 'bp_adminbar_menus', 'bp_adminbar_thisblog_menu', 6 );
add_action( 'bp_adminbar_menus', 'bp_adminbar_notifications_menu', 8 );
add_action( 'bp_adminbar_menus', 'bp_adminbar_authors_menu', 12 );
add_action( 'bp_adminbar_menus', 'bp_adminbar_random_menu', 100 );
// Actions used to append BP admin bar to footer
add_action( 'wp_footer', 'bp_core_admin_bar', 8 );
add_action( 'admin_footer', 'bp_core_admin_bar' );
}
}
add_action( 'bp_loaded', 'bp_core_load_admin_bar' );
?>
\ No newline at end of file
......@@ -522,7 +522,7 @@ function bp_core_check_avatar_size($file) {
}
function bp_core_check_avatar_type($file) {
if ( ( strlen($file['file']['type']) && !preg_match('/(jpe?g|gif|png)$/', $file['file']['type'] ) ) && !preg_match( '/(jpe?g|gif|png)$/', $file['file']['name'] ) )
if ( ( !empty( $file['file']['type'] ) && !preg_match('/(jpe?g|gif|png)$/', $file['file']['type'] ) ) || !preg_match( '/(jpe?g|gif|png)$/', $file['file']['name'] ) )
return false;
return true;
......@@ -567,7 +567,7 @@ function bp_core_avatar_url() {
// If multisite, and current blog does not match root blog, make adjustments
if ( bp_core_is_multisite() && BP_ROOT_BLOG != $current_blog->blog_id )
$upload_dir['baseurl'] = str_replace( get_blog_option( $current_blog->blog_id, 'home' ) , get_blog_option( BP_ROOT_BLOG, 'home' ), $upload_dir['baseurl'] );
$upload_dir['baseurl'] = trailingslashit( get_blog_option( BP_ROOT_BLOG, 'home' ) ) . get_blog_option( BP_ROOT_BLOG, 'upload_path' );
return apply_filters( 'bp_core_avatar_url', $upload_dir['baseurl'] );
}
......
......@@ -112,4 +112,17 @@ if ( !function_exists( 'is_site_admin' ) ) {
}
}
// Added for WordPress 3.1 support
if ( !function_exists( 'get_dashboard_url' ) ) {
/**
* Make sure the 'network_admin_menu' hook (which is new to 3.1) fires
* on our reliable friend 'admin_menu'
*/
function bp_network_admin_menu() {
do_action( 'network_admin_menu' );
}
add_action( 'admin_menu', 'bp_network_admin_menu' );
}
?>
......@@ -102,7 +102,7 @@ function bp_forums_add_admin_menu() {
/* Add the administration tab under the "Site Admin" tab for site administrators */
add_submenu_page( 'bp-general-settings', __( 'Forums Setup', 'buddypress' ), __( 'Forums Setup', 'buddypress' ), 'manage_options', 'bb-forums-setup', "bp_forums_bbpress_admin" );
}
add_action( 'admin_menu', 'bp_forums_add_admin_menu' );
add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', 'bp_forums_add_admin_menu' );
/* Forum Functions */
......
......@@ -10,7 +10,11 @@ bb_get_admin_header();
<?php if ( is_callable($bb_admin_page) ) : call_user_func( $bb_admin_page ); else : ?>
<p><?php _e('Nothing to see here.'); ?><p>
<h2><?php _e( 'Page not found' ); ?></h2>
<?php
bb_admin_notice( __( 'There is no administration page at the requested address. Please check the address you entered and try again.' ), 'error' );
do_action( 'bb_admin_notices' );
?>
<?php endif; ?>
......
......@@ -16,8 +16,10 @@ require_once( BB_PATH . 'bb-admin/includes/functions.bb-admin.php' );
$bb_admin_page = bb_find_filename( $_SERVER['PHP_SELF'] );
$_check_callback = false;
if ( $bb_admin_page == 'admin-base.php' ) {
$bb_admin_page = $_GET['plugin'];
$bb_admin_page = (string) @$_GET['plugin'];
$_check_callback = true;
}
wp_enqueue_script( 'common' );
......@@ -34,4 +36,10 @@ if ( isset( $_GET['foldmenu'] ) ) {
}
bb_admin_menu_generator();
bb_get_current_admin_menu();
if ( $_check_callback ) {
if ( empty( $bb_registered_plugin_callbacks ) || empty( $bb_admin_page ) || !in_array( $bb_admin_page, $bb_registered_plugin_callbacks ) ) {
unset( $bb_admin_page );
}
}
?>
......@@ -309,6 +309,9 @@ class BB_Install
function get_languages()
{
foreach ( bb_glob( BB_LANG_DIR . '*.mo' ) as $language ) {
if ( substr( $language, 0, 18 ) === 'continents-cities-' ) {
continue;
}
$language = str_replace( '.mo', '', basename( $language ) );
$this->languages[$language] = $language;
}
......
......@@ -113,33 +113,37 @@ $bb_queries['topics'] = "CREATE TABLE IF NOT EXISTS `$bbdb->topics` (
KEY `stickies` (`topic_status`, `topic_sticky`, `topic_time`)
);";
// users - 'user_login', 'user_nicename' and 'user_registered' indices are inconsistent with WordPress
$bb_queries['users'] = "CREATE TABLE IF NOT EXISTS `$bbdb->users` (
`ID` bigint(20) unsigned NOT NULL auto_increment,
`user_login` varchar(60) NOT NULL default '',
`user_pass` varchar(64) NOT NULL default '',
`user_nicename` varchar(50) NOT NULL default '',
`user_email` varchar(100) NOT NULL default '',
`user_url` varchar(100) NOT NULL default '',
`user_registered` datetime NOT NULL default '0000-00-00 00:00:00',
`user_status` int(11) NOT NULL default 0,
`display_name` varchar(250) NOT NULL default '',
PRIMARY KEY (`ID`),
UNIQUE KEY `user_login` (`user_login`),
UNIQUE KEY `user_nicename` (`user_nicename`),
KEY `user_registered` (`user_registered`)
);";
// usermeta
$bb_queries['usermeta'] = "CREATE TABLE IF NOT EXISTS `$bbdb->usermeta` (
`umeta_id` bigint(20) NOT NULL auto_increment,
`user_id` bigint(20) NOT NULL default 0,
`meta_key` varchar(255),
`meta_value` longtext,
PRIMARY KEY (`umeta_id`),
KEY `user_id` (`user_id`),
KEY `meta_key` (`meta_key`)
);";
if ( bb_get_option( 'wp_table_prefix' ) || ( defined( 'BB_SCHEMA_IGNORE_WP_USERS_TABLES' ) && BB_SCHEMA_IGNORE_WP_USERS_TABLES ) ) {
// Don't add user tables
} else {
// users - 'user_login', 'user_nicename' and 'user_registered' indices are inconsistent with WordPress
$bb_queries['users'] = "CREATE TABLE IF NOT EXISTS `$bbdb->users` (
`ID` bigint(20) unsigned NOT NULL auto_increment,
`user_login` varchar(60) NOT NULL default '',
`user_pass` varchar(64) NOT NULL default '',
`user_nicename` varchar(50) NOT NULL default '',
`user_email` varchar(100) NOT NULL default '',
`user_url` varchar(100) NOT NULL default '',
`user_registered` datetime NOT NULL default '0000-00-00 00:00:00',
`user_status` int(11) NOT NULL default 0,
`display_name` varchar(250) NOT NULL default '',
PRIMARY KEY (`ID`),
UNIQUE KEY `user_login` (`user_login`),
UNIQUE KEY `user_nicename` (`user_nicename`),
KEY `user_registered` (`user_registered`)
);";
// usermeta
$bb_queries['usermeta'] = "CREATE TABLE IF NOT EXISTS `$bbdb->usermeta` (
`umeta_id` bigint(20) NOT NULL auto_increment,
`user_id` bigint(20) NOT NULL default 0,
`meta_key` varchar(255),
`meta_value` longtext,
PRIMARY KEY (`umeta_id`),
KEY `user_id` (`user_id`),
KEY `meta_key` (`meta_key`)
);";
}
$bb_queries = apply_filters( 'bb_schema_pre_charset', $bb_queries );
......@@ -212,6 +216,18 @@ if ( bb_get_option('wp_table_prefix') || ( defined( 'BB_SCHEMA_IGNORE_WP_USERS_K
$bb_schema_ignore = false;
}
if ( bb_get_option('wp_table_prefix') || ( defined( 'BB_SCHEMA_IGNORE_WP_USERS_TABLES' ) && BB_SCHEMA_IGNORE_WP_USERS_TABLES ) ) {
if ( $bb_schema_ignore ) {
$bb_schema_ignore['tables'] = array( $bbdb->users, $bbdb->usermeta );
} else {
$bb_schema_ignore = array(
'tables' => array( $bbdb->users, $bbdb->usermeta ),
'columns' => array(),
'indices' => array()
);
}
}
$bb_schema_ignore = apply_filters( 'bb_schema_ignore', $bb_schema_ignore );
do_action( 'bb_schema_defined' );
......
......@@ -117,6 +117,10 @@ function bb_admin_menu_generator()
function bb_admin_add_menu( $display_name, $capability, $file_name, $menu_position = false, $class = '', $id = '' )
{
global $bb_menu;
global $bb_registered_plugin_callbacks;
if ( empty( $bb_registered_plugin_callbacks ) ) {
$bb_registered_plugin_callbacks = array();
}
if ( $display_name && $capability && $file_name ) {
// Get an array of the keys
......@@ -164,6 +168,10 @@ function bb_admin_add_menu( $display_name, $capability, $file_name, $menu_positi
$plugin_menu_next++;
}
if ( strpos( $file_name, '.php' ) === false ) {
$bb_registered_plugin_callbacks[] = $file_name;
}
// Add the menu item at the given key
$bb_menu[$plugin_menu_next] = array( $display_name, $capability, $file_name, $class, $id );
......@@ -178,7 +186,15 @@ function bb_admin_add_menu( $display_name, $capability, $file_name, $menu_positi
function bb_admin_add_submenu( $display_name, $capability, $file_name, $parent = 'plugins.php' )
{
global $bb_submenu;
global $bb_registered_plugin_callbacks;
if ( empty( $bb_registered_plugin_callbacks ) ) {
$bb_registered_plugin_callbacks = array();
}
if ( $display_name && $capability && $file_name ) {
if ( strpos( $file_name, '.php' ) === false ) {
$bb_registered_plugin_callbacks[] = $file_name;
}
$bb_submenu[$parent][] = array( $display_name, $capability, $file_name );
ksort( $bb_submenu );
}
......@@ -397,10 +413,13 @@ function bb_get_ids_by_role( $role = 'moderator', $sort = 0, $page = 1, $limit =
function bb_user_row( $user, $role = '', $email = false ) {
$actions = "<a href='" . esc_attr( get_user_profile_link( $user->ID ) ) . "'>" . __('View') . "</a>";
if ( bb_current_user_can( 'edit_user', $user_id ) )
$title = '';
if ( bb_current_user_can( 'edit_user', $user_id ) ) {
$actions .= " | <a href='" . esc_attr( get_profile_tab_link( $user->ID, 'edit' ) ) . "'>" . __('Edit') . "</a>";
$title = " title='" . esc_attr( sprintf( __( 'User ID: %d' ), $user->ID ) ) . "'";
}
$r = "\t<tr id='user-$user->ID'" . get_alt_class("user-$role") . ">\n";
$r .= "\t\t<td class=\"user\">" . bb_get_avatar( $user->ID, 32 ) . "<span class=\"row-title\"><a href='" . get_user_profile_link( $user->ID ) . "'>" . get_user_name( $user->ID ) . "</a></span><div><span class=\"row-actions\">$actions</span>&nbsp;</div></td>\n";
$r .= "\t\t<td class=\"user\">" . bb_get_avatar( $user->ID, 32 ) . "<span class=\"row-title\"><a href='" . get_user_profile_link( $user->ID ) . "'" . $title . ">" . get_user_name( $user->ID ) . "</a></span><div><span class=\"row-actions\">$actions</span>&nbsp;</div></td>\n";
$r .= "\t\t<td><a href='" . get_user_profile_link( $user->ID ) . "'>" . get_user_display_name( $user->ID ) . "</a></td>\n";
if ( $email ) {
$email = bb_get_user_email( $user->ID );
......
<?php
function bb_recount_topic_posts()
{
global $bbdb;
$statement = __( 'Counting the number of posts in each topic&hellip; %s' );
$result = __( 'Failed!' );
$sql = "INSERT INTO `$bbdb->topics` (`topic_id`, `topic_posts`) (SELECT `topic_id`, COUNT(`post_status`) as `topic_posts` FROM `$bbdb->posts` WHERE `post_status` = '0' GROUP BY `topic_id`) ON DUPLICATE KEY UPDATE `topic_posts` = VALUES(`topic_posts`);";
if ( is_wp_error( $bbdb->query( $sql ) ) ) {
return sprintf( $statement, $result );
}
$result = __( 'Complete!' );
return sprintf( $statement, $result );
}
function bb_recount_topic_voices()
{
global $bbdb;
$statement = __( 'Counting the number of voices in each topic&hellip; %s' );
$result = __( 'Failed!' );
$sql_delete = "DELETE FROM `$bbdb->meta` WHERE `object_type` = 'bb_topic' AND `meta_key` = 'voices_count';";
if ( is_wp_error( $bbdb->query( $sql_delete ) ) ) {
return sprintf( $statement, $result );
}
$sql = "INSERT INTO `$bbdb->meta` (`object_type`, `object_id`, `meta_key`, `meta_value`) (SELECT 'bb_topic', `topic_id`, 'voices_count', COUNT(DISTINCT `poster_id`) as `meta_value` FROM `$bbdb->posts` WHERE `post_status` = '0' GROUP BY `topic_id`);";
if ( is_wp_error( $bbdb->query( $sql ) ) ) {
return sprintf( $statement, $result );
}
$result = __( 'Complete!' );
return sprintf( $statement, $result );
}
function bb_recount_topic_deleted_posts()
{
global $bbdb;
$statement = __( 'Counting the number of deleted posts in each topic&hellip; %s' );
$result = __( 'Failed!' );
$sql_delete = "DELETE FROM `$bbdb->meta` WHERE `object_type` = 'bb_topic' AND `meta_key` = 'deleted_posts';";
if ( is_wp_error( $bbdb->query( $sql_delete ) ) ) {
return sprintf( $statement, $result );
}
$sql = "INSERT INTO `$bbdb->meta` (`object_type`, `object_id`, `meta_key`, `meta_value`) (SELECT 'bb_topic', `topic_id`, 'deleted_posts', COUNT(`post_status`) as `meta_value` FROM `$bbdb->posts` WHERE `post_status` != '0' GROUP BY `topic_id`);";
if ( is_wp_error( $bbdb->query( $sql ) ) ) {
return sprintf( $statement, $result );
}
$result = __( 'Complete!' );
return sprintf( $statement, $result );
}
function bb_recount_forum_topics()
{
global $bbdb;
$statement = __( 'Counting the number of topics in each forum&hellip; %s' );
$result = __( 'Failed!' );
$sql = "INSERT INTO `$bbdb->forums` (`forum_id`, `topics`) (SELECT `forum_id`, COUNT(`topic_status`) as `topics` FROM `$bbdb->topics` WHERE `topic_status` = '0' GROUP BY `forum_id`) ON DUPLICATE KEY UPDATE `topics` = VALUES(`topics`);";
if ( is_wp_error( $bbdb->query( $sql ) ) ) {
return sprintf( $statement, $result );
}
$result = __( 'Complete!' );
return sprintf( $statement, $result );
}
function bb_recount_forum_posts()
{
global $bbdb;
$statement = __( 'Counting the number of posts in each forum&hellip; %s' );
$result = __( 'Failed!' );
$sql = "INSERT INTO `$bbdb->forums` (`forum_id`, `posts`) (SELECT `forum_id`, COUNT(`post_status`) as `posts` FROM `$bbdb->posts` WHERE `post_status` = '0' GROUP BY `forum_id`) ON DUPLICATE KEY UPDATE `posts` = VALUES(`posts`);";
if ( is_wp_error( $bbdb->query( $sql ) ) ) {
return sprintf( $statement, $result );
}
$result = __( 'Complete!' );
return sprintf( $statement, $result );
}
function bb_recount_user_topics_replied()
{
global $bbdb;
$statement = __( 'Counting the number of topics to which each user has replied&hellip; %s' );
$result = __( 'Failed!' );
$sql_select = "SELECT `poster_id`, COUNT(DISTINCT `topic_id`) as `_count` FROM `$bbdb->posts` WHERE `post_status` = '0' GROUP BY `poster_id`;";
$insert_rows = $bbdb->get_results( $sql_select );
if ( is_wp_error( $insert_rows ) ) {
return sprintf( $statement, $result );
}
$meta_key = $bbdb->prefix . 'topics_replied';
$insert_values = array();
foreach ( $insert_rows as $insert_row ) {
$insert_values[] = "('$insert_row->poster_id', '$meta_key', '$insert_row->_count')";
}
if ( !count( $insert_values ) ) {
return sprintf( $statement, $result );
}
$sql_delete = "DELETE FROM `$bbdb->usermeta` WHERE `meta_key` = '$meta_key';";
if ( is_wp_error( $bbdb->query( $sql_delete ) ) ) {
return sprintf( $statement, $result );
}
$insert_values = array_chunk( $insert_values, 10000 );
foreach ( $insert_values as $chunk ) {
$chunk = "\n" . join( ",\n", $chunk );
$sql_insert = "INSERT INTO `$bbdb->usermeta` (`user_id`, `meta_key`, `meta_value`) VALUES $chunk;";
if ( is_wp_error( $bbdb->query( $sql_insert ) ) ) {
return sprintf( $statement, $result );
}
}
$result = __( 'Complete!' );
return sprintf( $statement, $result );
}
// TODO - make fast - see #1146
function bb_recount_topic_tags()
{
// Reset tag count to zero
$bbdb->query( "UPDATE $bbdb->topics SET tag_count = 0" );
// Get all tags
$terms = $wp_taxonomy_object->get_terms( 'bb_topic_tag' );
if ( !is_wp_error( $terms ) && is_array( $terms ) ) {
$message = __('Counted topic tags');
foreach ( $terms as $term ) {