/**
 * Bootstrap bbPress 1.x, and manipulate globals to integrate with BuddyPress.
 *
 * @return bool|null Returns false on failure.
 */
function bp_forums_load_bbpress()
{
    global $wpdb, $wp_roles, $current_user, $wp_users_object;
    global $bb, $bbdb, $bb_table_prefix, $bb_current_user;
    global $bb_roles, $wp_taxonomy_object, $bb_queries;
    // Return if we've already run this function.
    if (is_object($bbdb)) {
        return;
    }
    if (!bp_forums_is_installed_correctly()) {
        return false;
    }
    $bp = buddypress();
    define('BB_PATH', $bp->plugin_dir . '/bp-forums/bbpress/');
    define('BACKPRESS_PATH', $bp->plugin_dir . '/bp-forums/bbpress/bb-includes/backpress/');
    define('BB_URL', $bp->plugin_url . 'bp-forums/bbpress/');
    define('BB_INC', 'bb-includes/');
    require BB_PATH . BB_INC . 'class.bb-query.php';
    require BB_PATH . BB_INC . 'class.bb-walker.php';
    require BB_PATH . BB_INC . 'functions.bb-core.php';
    require BB_PATH . BB_INC . 'functions.bb-forums.php';
    require BB_PATH . BB_INC . 'functions.bb-topics.php';
    require BB_PATH . BB_INC . 'functions.bb-posts.php';
    require BB_PATH . BB_INC . 'functions.bb-topic-tags.php';
    require BB_PATH . BB_INC . 'functions.bb-capabilities.php';
    require BB_PATH . BB_INC . 'functions.bb-meta.php';
    require BB_PATH . BB_INC . 'functions.bb-pluggable.php';
    require BB_PATH . BB_INC . 'functions.bb-formatting.php';
    require BB_PATH . BB_INC . 'functions.bb-template.php';
    require BACKPRESS_PATH . 'class.wp-taxonomy.php';
    require BB_PATH . BB_INC . 'class.bb-taxonomy.php';
    require BB_PATH . 'bb-admin/includes/functions.bb-admin.php';
    $bb = new stdClass();
    require bp_get_option('bb-config-location');
    // Setup the global database connection
    $bbdb = new BPDB(BBDB_USER, BBDB_PASSWORD, BBDB_NAME, BBDB_HOST);
    // Set the table names
    $bbdb->forums = $bb_table_prefix . 'forums';
    $bbdb->meta = $bb_table_prefix . 'meta';
    $bbdb->posts = $bb_table_prefix . 'posts';
    $bbdb->terms = $bb_table_prefix . 'terms';
    $bbdb->term_relationships = $bb_table_prefix . 'term_relationships';
    $bbdb->term_taxonomy = $bb_table_prefix . 'term_taxonomy';
    $bbdb->topics = $bb_table_prefix . 'topics';
    if (isset($bb->custom_user_table)) {
        $bbdb->users = $bb->custom_user_table;
    } else {
        $bbdb->users = $wpdb->users;
    }
    if (isset($bb->custom_user_meta_table)) {
        $bbdb->usermeta = $bb->custom_user_meta_table;
    } else {
        $bbdb->usermeta = $wpdb->usermeta;
    }
    $bbdb->prefix = $bb_table_prefix;
    define('BB_INSTALLING', false);
    if (is_object($wp_roles)) {
        $bb_roles = $wp_roles;
        bb_init_roles($bb_roles);
    }
    /**
     * Fires during the bootstrap setup for bbPress 1.x.
     *
     * @since 1.1.0
     */
    do_action('bb_got_roles');
    /**
     * Fires during the bootstrap setup for bbPress 1.x.
     *
     * @since 1.1.0
     */
    do_action('bb_init');
    /**
     * Fires during the bootstrap setup for bbPress 1.x.
     *
     * @since 1.1.0
     */
    do_action('init_roles');
    $bb_current_user = $current_user;
    $wp_users_object = new BP_Forums_BB_Auth();
    if (!isset($wp_taxonomy_object)) {
        $wp_taxonomy_object = new BB_Taxonomy($bbdb);
    }
    $wp_taxonomy_object->register_taxonomy('bb_topic_tag', 'bb_topic');
    // Set a site id if there isn't one already
    if (!isset($bb->site_id)) {
        $bb->site_id = bp_get_root_blog_id();
    }
    // Check if the tables are installed, if not, install them
    if (!($tables_installed = (bool) $bbdb->get_results('DESCRIBE `' . $bbdb->forums . '`;', ARRAY_A))) {
        require BB_PATH . 'bb-admin/includes/defaults.bb-schema.php';
        // Backticks and "IF NOT EXISTS" break the dbDelta function.
        bp_bb_dbDelta(str_replace(' IF NOT EXISTS', '', str_replace('`', '', $bb_queries)));
        require BB_PATH . 'bb-admin/includes/functions.bb-upgrade.php';
        bb_update_db_version();
        // Set the site admins as the keymasters
        $site_admins = get_site_option('site_admins', array('admin'));
        foreach ((array) $site_admins as $site_admin) {
            bp_update_user_meta(bp_core_get_userid($site_admin), $bb_table_prefix . 'capabilities', array('keymaster' => true));
        }
        // Create the first forum.
        bb_new_forum(array('forum_name' => 'Default Forum'));
        // Set the site URI
        bb_update_option('uri', BB_URL);
    }
    /**
     * Fires inside an anonymous function that is run on bbPress shutdown.
     *
     * @since 1.1.0
     */
    register_shutdown_function(create_function('', 'do_action("bb_shutdown");'));
}
function bb_upgrade_all()
{
    if (!ini_get('safe_mode')) {
        set_time_limit(600);
    }
    $_do_user_operations = true;
    if (bb_get_option('nxt_table_prefix') || defined('BB_SCHEMA_IGNORE_nxt_USERS_TABLES') && BB_SCHEMA_IGNORE_nxt_USERS_TABLES) {
        $_do_user_operations = false;
    }
    $bb_upgrade = array();
    // Pre DB Delta
    if ($_do_user_operations) {
        $bb_upgrade['messages'][] = bb_upgrade_160();
        // Break blocked users
        $bb_upgrade['messages'][] = bb_upgrade_170();
        // Escaping in usermeta
        $bb_upgrade['messages'][] = bb_upgrade_180();
        // Delete users for real
    }
    $bb_upgrade['messages'][] = bb_upgrade_190();
    // Move topic_resolved to topicmeta
    $bb_upgrade['messages'][] = bb_upgrade_200();
    // Indices
    $bb_upgrade['messages'][] = bb_upgrade_210();
    // Convert text slugs to varchar slugs
    $bb_upgrade['messages'][] = bb_upgrade_220();
    // remove bb_tagged primary key, add new column and primary key
    require_once BACKPRESS_PATH . 'class.bp-sql-schema-parser.php';
    require_once BB_PATH . 'bb-admin/includes/defaults.bb-schema.php';
    $delta = BP_SQL_Schema_Parser::delta($bbdb, $bb_queries, $bb_schema_ignore);
    if (is_array($delta)) {
        $bb_upgrade['messages'] = array_merge($bb_upgrade['messages'], $delta['messages']);
        $bb_upgrade['errors'] = $delta['errors'];
    } else {
        $bb_upgrade['errors'] = array();
    }
    // Post DB Delta
    $bb_upgrade['messages'][] = bb_upgrade_1000();
    // Make forum and topic slugs
    $bb_upgrade['messages'][] = bb_upgrade_1010();
    // Make sure all forums have a valid parent
    if ($_do_user_operations) {
        $bb_upgrade['messages'][] = bb_upgrade_1020();
        // Add a user_nicename to existing users
    }
    $bb_upgrade['messages'][] = bb_upgrade_1030();
    // Move admin_email option to from_email
    $bb_upgrade['messages'][] = bb_upgrade_1040();
    // Activate Akismet and bozo plugins and convert active plugins to new convention on upgrade only
    $bb_upgrade['messages'][] = bb_upgrade_1050();
    // Update active theme if present
    $bb_upgrade['messages'][] = bb_upgrade_1070();
    // trim whitespace from raw_tag
    $bb_upgrade['messages'][] = bb_upgrade_1080();
    // Convert tags to taxonomy
    if ($_do_user_operations) {
        $bb_upgrade['messages'][] = bb_upgrade_1090();
        // Add display names
    }
    $bb_upgrade['messages'][] = bb_upgrade_1100();
    // Replace forum_stickies index with stickies (#876)
    $bb_upgrade['messages'][] = bb_upgrade_1110();
    // Create plugin directory (#1083)
    $bb_upgrade['messages'][] = bb_upgrade_1120();
    // Create theme directory (#1083)
    $bb_upgrade['messages'][] = bb_upgrade_1130();
    // Add subscriptions option and set it to true (#1268)
    bb_update_db_version();
    nxt_cache_flush();
    $bb_upgrade['messages'] = array_filter($bb_upgrade['messages']);
    $bb_upgrade['errors'] = array_filter($bb_upgrade['errors']);
    return $bb_upgrade;
}
Exemplo n.º 3
0
function bp_forums_load_bbpress() {
	global $bp, $wpdb, $wp_roles, $current_user, $wp_users_object;
	global $bb, $bbdb, $bb_table_prefix, $bb_current_user;
	global $bb_roles, $wp_taxonomy_object;

	/* Return if we've already run this function. */
	if ( is_object( $bbdb ) && is_object( $bb_roles ) )
		return;

	if ( !bp_forums_is_installed_correctly() )
		return false;

	define( 'BB_PATH', BP_PLUGIN_DIR . '/bp-forums/bbpress/' );
	define( 'BACKPRESS_PATH', BP_PLUGIN_DIR . '/bp-forums/bbpress/bb-includes/backpress/' );
	define( 'BB_URL', BP_PLUGIN_URL . '/bp-forums/bbpress/' );
	define( 'BB_INC', 'bb-includes/' );

	require_once( BB_PATH . BB_INC . 'class.bb-query.php' );
	require_once( BB_PATH . BB_INC . 'class.bb-walker.php' );

	require_once( BB_PATH . BB_INC . 'functions.bb-core.php' );
	require_once( BB_PATH . BB_INC . 'functions.bb-forums.php' );
	require_once( BB_PATH . BB_INC . 'functions.bb-topics.php' );
	require_once( BB_PATH . BB_INC . 'functions.bb-posts.php' );
	require_once( BB_PATH . BB_INC . 'functions.bb-topic-tags.php' );
	require_once( BB_PATH . BB_INC . 'functions.bb-capabilities.php' );
	require_once( BB_PATH . BB_INC . 'functions.bb-meta.php' );
	require_once( BB_PATH . BB_INC . 'functions.bb-pluggable.php' );
	require_once( BB_PATH . BB_INC . 'functions.bb-formatting.php' );
	require_once( BB_PATH . BB_INC . 'functions.bb-template.php' );

	require_once( BACKPRESS_PATH . 'class.wp-taxonomy.php' );
	require_once( BB_PATH . BB_INC . 'class.bb-taxonomy.php' );

	$bb = new stdClass();
	require_once( $bp->forums->bbconfig );

	// Setup the global database connection
	$bbdb = new BPDB ( BBDB_USER, BBDB_PASSWORD, BBDB_NAME, BBDB_HOST );

	/* Set the table names */
	$bbdb->forums = $bb_table_prefix . 'forums';
	$bbdb->meta = $bb_table_prefix . 'meta';
	$bbdb->posts = $bb_table_prefix . 'posts';
	$bbdb->terms = $bb_table_prefix . 'terms';
	$bbdb->term_relationships = $bb_table_prefix . 'term_relationships';
	$bbdb->term_taxonomy = $bb_table_prefix . 'term_taxonomy';
	$bbdb->topics = $bb_table_prefix . 'topics';

	if ( isset( $bb->custom_user_table ) )
		$bbdb->users = $bb->custom_user_table;
	else
		$bbdb->users = $wpdb->users;

	if ( isset( $bb->custom_user_meta_table ) )
		$bbdb->usermeta = $bb->custom_user_meta_table;
	else
		$bbdb->usermeta = $wpdb->usermeta;

	$bbdb->prefix = $bb_table_prefix;

	define( 'BB_INSTALLING', false );

	/* This must be loaded before functionss.bb-admin.php otherwise we get a function conflict. */
	if ( !$tables_installed = (boolean) $bbdb->get_results( 'DESCRIBE `' . $bbdb->forums . '`;', ARRAY_A ) )
		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );

	require_once( BB_PATH . 'bb-admin/includes/functions.bb-admin.php' );

	if ( is_object( $wp_roles ) ) {
		$bb_roles = $wp_roles;
		bb_init_roles( $bb_roles );
	}

	do_action( 'bb_got_roles' );
	do_action( 'bb_init' );
	do_action( 'init_roles' );

	$bb_current_user = $current_user;
	$wp_users_object = new BP_Forums_BB_Auth;

	if ( !isset( $wp_taxonomy_object ) )
		$wp_taxonomy_object = new BB_Taxonomy( $bbdb );

	$wp_taxonomy_object->register_taxonomy( 'bb_topic_tag', 'bb_topic' );

	// Set a site id if there isn't one already
	if ( !isset( $bb->site_id ) )
		$bb->site_id = BP_ROOT_BLOG;

	/* Check if the tables are installed, if not, install them */
	if ( !$tables_installed ) {
		require_once( BB_PATH . 'bb-admin/includes/defaults.bb-schema.php' );

		/* Backticks and "IF NOT EXISTS" break the dbDelta function. */
		dbDelta( str_replace( ' IF NOT EXISTS', '', str_replace( '`', '', $bb_queries ) ) );

		require_once( BB_PATH . 'bb-admin/includes/functions.bb-upgrade.php' );
		bb_update_db_version();

		/* Set the site admins as the keymasters */
		$site_admins = get_site_option( 'site_admins', array('admin') );
		foreach ( (array)$site_admins as $site_admin )
			update_user_meta( bp_core_get_userid( $site_admin ), $bb_table_prefix . 'capabilities', array( 'keymaster' => true ) );

		// Create the first forum.
		bb_new_forum( array( 'forum_name' => 'Default Forum' ) );

		// Set the site URI
		bb_update_option( 'uri', BB_URL );
	}

	register_shutdown_function( create_function( '', 'do_action("bb_shutdown");' ) );
}