plugin_dir . '/bp-forums/bbpress/bb-config-sample.php', $location, array( "define( 'BBDB_NAME'," => array( "'bbpress'", "'" . DB_NAME . "'" ), "define( 'BBDB_USER'," => array( "'username'", "'" . DB_USER . "'" ), "define( 'BBDB_PASSWO" => array( "'password'", "'" . DB_PASSWORD . "'" ), "define( 'BBDB_HOST'," => array( "'localhost'", "'" . DB_HOST . "'" ), "define( 'BBDB_CHARSE" => array( "'utf8'", "'" . DB_CHARSET . "'" ), "define( 'BBDB_COLLAT" => array( "''", "'" . DB_COLLATE . "'" ), "define( 'BB_AUTH_KEY" => array( "'put your unique phrase here'", "'" . addslashes( AUTH_KEY ) . "'" ), "define( 'BB_SECURE_A" => array( "'put your unique phrase here'", "'" . addslashes( SECURE_AUTH_KEY ) . "'" ), "define( 'BB_LOGGED_I" => array( "'put your unique phrase here'", "'" . addslashes( LOGGED_IN_KEY ) . "'" ), "define( 'BB_NONCE_KE" => array( "'put your unique phrase here'", "'" . addslashes( NONCE_KEY ) . "'" ), "\$bb_table_prefix = '" => array( "'bb_'", "'" . $bp->table_prefix . "bb_'" ), "define( 'BB_LANG', '" => array( "''", "'" . get_locale() . "'" ) ) ); // Add the custom user and usermeta entries to the config file. if ( $initial_write == 1 ) { $file = file_get_contents( $location ); } else { $file = &$initial_write; } $file = trim( $file ); if ( '?>' == substr( $file, -2, 2 ) ) { $file = substr( $file, 0, -2 ); } $file .= "\n" . '$bb->custom_user_table = \'' . $wpdb->users . '\';'; $file .= "\n" . '$bb->custom_user_meta_table = \'' . $wpdb->usermeta . '\';'; $file .= "\n\n" . '$bb->uri = \'' . $bp->plugin_url . '/bp-forums/bbpress/\';'; $file .= "\n" . '$bb->name = \'' . get_blog_option( bp_get_root_blog_id(), 'blogname' ) . ' ' . __( 'Forums', 'buddypress' ) . '\';'; if ( is_multisite() ) { $file .= "\n" . '$bb->wordpress_mu_primary_blog_id = ' . bp_get_root_blog_id() . ';'; } if ( defined( 'AUTH_SALT' ) ) { $file .= "\n\n" . 'define(\'BB_AUTH_SALT\', \'' . addslashes( AUTH_SALT ) . '\');'; } if ( defined( 'LOGGED_IN_SALT' ) ) { $file .= "\n" . 'define(\'BB_LOGGED_IN_SALT\', \'' . addslashes( LOGGED_IN_SALT ) . '\');'; } if ( defined( 'SECURE_AUTH_SALT' ) ) { $file .= "\n" . 'define(\'BB_SECURE_AUTH_SALT\', \'' . addslashes( SECURE_AUTH_SALT ) . '\');'; } $file .= "\n\n" . 'define(\'WP_AUTH_COOKIE_VERSION\', 2);'; $file .= "\n\n" . '?>'; if ( $initial_write == 1 ) { $file_handle = fopen( $location, 'w' ); fwrite( $file_handle, $file ); fclose( $file_handle ); } else { $initial_write = $file; } bp_update_option( 'bb-config-location', $location ); return $initial_write; } function bp_forums_bbpress_write( $file_source, $file_target, $alterations ) { if ( empty( $file_source ) || !file_exists( $file_source ) || !is_file( $file_source ) ) { return -1; } if ( empty( $file_target ) ) { $file_target = $file_source; } if ( empty( $alterations ) || !is_array( $alterations ) ) { return -2; } // Get the existing lines in the file. $lines = file( $file_source ); // Initialise an array to store the modified lines. $modified_lines = array(); // Loop through the lines and modify them. foreach ( (array) $lines as $line ) { if ( isset( $alterations[substr( $line, 0, 20 )] ) ) { $alteration = $alterations[substr( $line, 0, 20 )]; $modified_lines[] = str_replace( $alteration[0], $alteration[1], $line ); } else { $modified_lines[] = $line; } } $writable = true; if ( file_exists( $file_target ) ) { if ( !is_writable( $file_target ) ) { $writable = false; } } else { $dir_target = dirname( $file_target ); if ( file_exists( $dir_target ) ) { if ( !is_writable( $dir_target ) || !is_dir( $dir_target ) ) { $writable = false; } } else { $writable = false; } } if ( empty( $writable ) ) { return trim( join( null, $modified_lines ) ); } // Open the file for writing - rewrites the whole file. $file_handle = fopen( $file_target, 'w' ); // Write lines one by one to avoid OS specific newline hassles. foreach ( (array) $modified_lines as $modified_line ) { if ( strlen( $modified_line ) - 2 === strrpos( $modified_line, '?>' ) ) { $modified_line = '?>'; } fwrite( $file_handle, $modified_line ); if ( $modified_line == '?>' ) { break; } } // Close the config file. fclose( $file_handle ); @chmod( $file_target, 0666 ); return 1; }