Skip to:
Content

BuddyPress.org

Changeset 5885


Ignore:
Timestamp:
03/05/2012 06:17:43 AM (13 years ago)
Author:
johnjamesjacoby
Message:

First pass at rearranging settings and forums settings screens to accommodate bbPress 2.x migration:

  • Simplify and move old bb-config.php file write logic into Settings screen
  • Introduce new functions for checking what possible mode the Forums screen is in
  • Deprecate old forum admin code for now, will probably be removed later
  • Deprecate $bp->bbconfig setting and use bp_get_option() instead
  • Clean up the Settings screen and add dedicated groups for Profiles and Forums
  • See #3598
  • More to do
Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/admin/bp-core-functions.php

    r5749 r5885  
    360360    );
    361361
    362     // If forums component is active, add additional tab
    363     if ( bp_is_active( 'forums' ) ) {
     362    // If forums component is active and bbPress 1.x is in use add additional tab
     363    if ( bp_is_active( 'forums' ) && bp_forums_is_repair() ) {
    364364        $tabs['3'] = array(
    365365            'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bb-forums-setup'  ), 'admin.php' ) ),
  • trunk/bp-core/admin/bp-core-settings.php

    r5883 r5885  
    1616 * @since BuddyPress (r2786)
    1717 */
    18 function bp_admin_setting_callback_main_section() {
    19 ?>
    20 
    21     <p><?php _e( 'Main community settings for enabling features and setting time limits', 'buddypress' ); ?></p>
    22 
    23 <?php
    24 }
     18function bp_admin_setting_callback_main_section() { }
     19
     20/**
     21 * Throttle setting field
     22 *
     23 * @since BuddyPress (r2737)
     24 *
     25 * @uses bp_form_option() To output the option value
     26 */
     27function bp_admin_setting_callback_admin_bar() {
     28?>
     29
     30    <input id="hide-loggedout-adminbar" name="hide-loggedout-adminbar" type="checkbox" value="1" <?php checked( !bp_hide_loggedout_adminbar( false ) ); ?> />
     31    <label for="hide-loggedout-adminbar"><?php _e( 'Show the admin bar for logged out users', 'buddypress' ); ?></label>
     32
     33<?php
     34}
     35
     36/**
     37 * Allow subscriptions setting field
     38 *
     39 * @since BuddyPress (r2737)
     40 *
     41 * @uses checked() To display the checked attribute
     42 */
     43function bp_admin_setting_callback_account_deletion() {
     44?>
     45
     46    <input id="bp-disable-account-deletion" name="bp-disable-account-deletion" type="checkbox" value="1" <?php checked( !bp_disable_account_deletion( true ) ); ?> />
     47    <label for="bp-disable-account-deletion"><?php _e( 'Allow registered members to delete their own accounts', 'buddypress' ); ?></label>
     48
     49<?php
     50}
     51
     52/**
     53 * Use the WordPress editor setting field
     54 *
     55 * @since BuddyPress (r3586)
     56 *
     57 * @uses checked() To display the checked attribute
     58 */
     59function bp_admin_setting_callback_use_wp_editor() {
     60?>
     61
     62    <input id="_bp_use_wp_editor" name="_bp_use_wp_editor" type="checkbox" id="_bp_use_wp_editor" value="1" <?php checked( bp_use_wp_editor( true ) ); ?> />
     63    <label for="_bp_use_wp_editor"><?php _e( 'Use the fancy WordPress editor to create and edit topics and replies', 'buddypress' ); ?></label>
     64
     65<?php
     66}
     67
     68/** Activity *******************************************************************/
     69
     70/**
     71 * Groups settings section description for the settings page
     72 *
     73 * @since BuddyPress (1.6)
     74 */
     75function bp_admin_setting_callback_activity_section() { }
     76
     77/**
     78 * Allow Akismet setting field
     79 *
     80 * @since BuddyPress (r3575)
     81 *
     82 * @uses checked() To display the checked attribute
     83 */
     84function bp_admin_setting_callback_activity_akismet() {
     85?>
     86
     87    <input id="_bp_enable_akismet" name="_bp_enable_akismet" type="checkbox" value="1" <?php checked( bp_is_akismet_active( true ) ); ?> />
     88    <label for="_bp_enable_akismet"><?php _e( 'Allow Akismet to scan for activity stream spam', 'buddypress' ); ?></label>
     89
     90<?php
     91}
     92
     93/** XProfile ******************************************************************/
     94
     95/**
     96 * Profile settings section description for the settings page
     97 *
     98 * @since BuddyPress (1.0)
     99 */
     100function bp_admin_setting_callback_xprofile_section() { }
    25101
    26102/**
     
    41117
    42118/**
    43  * Throttle setting field
    44  *
    45  * @since BuddyPress (r2737)
    46  *
    47  * @uses bp_form_option() To output the option value
    48  */
    49 function bp_admin_setting_callback_admin_bar() {
    50 ?>
    51 
    52     <input id="hide-loggedout-adminbar" name="hide-loggedout-adminbar" type="checkbox" value="1" <?php checked( !bp_hide_loggedout_adminbar( false ) ); ?> />
    53     <label for="hide-loggedout-adminbar"><?php _e( 'Show the admin bar for guest/anonymous users', 'buddypress' ); ?></label>
    54 
    55 <?php
    56 }
    57 
    58 /**
    59119 * Allow favorites setting field
    60120 *
     
    67127
    68128    <input id="bp-disable-avatar-uploads" name="bp-disable-avatar-uploads" type="checkbox" value="1" <?php checked( !bp_disable_avatar_uploads( true ) ); ?> />
    69     <label for="bp-disable-avatar-uploads"><?php _e( 'Allow members to upload avatars', 'buddypress' ); ?></label>
    70 
    71 <?php
    72 }
    73 
    74 /**
    75  * Allow subscriptions setting field
    76  *
    77  * @since BuddyPress (r2737)
    78  *
    79  * @uses checked() To display the checked attribute
    80  */
    81 function bp_admin_setting_callback_account_deletion() {
    82 ?>
    83 
    84     <input id="bp-disable-account-deletion" name="bp-disable-account-deletion" type="checkbox" value="1" <?php checked( !bp_disable_account_deletion( true ) ); ?> />
    85     <label for="bp-disable-account-deletion"><?php _e( 'Allow members to delete their own accounts', 'buddypress' ); ?></label>
    86 
    87 <?php
    88 }
    89 
    90 /**
    91  * Use the WordPress editor setting field
    92  *
    93  * @since BuddyPress (r3586)
    94  *
    95  * @uses checked() To display the checked attribute
    96  */
    97 function bp_admin_setting_callback_use_wp_editor() {
    98 ?>
    99 
    100     <input id="_bp_use_wp_editor" name="_bp_use_wp_editor" type="checkbox" id="_bp_use_wp_editor" value="1" <?php checked( bp_use_wp_editor( true ) ); ?> />
    101     <label for="_bp_use_wp_editor"><?php _e( 'Use the fancy WordPress editor to create and edit topics and replies', 'buddypress' ); ?></label>
    102 
    103 <?php
    104 }
    105 
    106 /** Activity *******************************************************************/
     129    <label for="bp-disable-avatar-uploads"><?php _e( 'Allow registered members to upload avatars', 'buddypress' ); ?></label>
     130
     131<?php
     132}
     133
     134/** Groups Section ************************************************************/
    107135
    108136/**
     
    111139 * @since BuddyPress (1.6)
    112140 */
    113 function bp_admin_setting_callback_activity_section() {
    114 ?>
    115 
    116     <p><?php _e( 'Settings for the Actvity component', 'buddypress' ); ?></p>
    117 
    118 <?php
    119 }
    120 
    121 /**
    122  * Allow Akismet setting field
    123  *
    124  * @since BuddyPress (r3575)
    125  *
    126  * @uses checked() To display the checked attribute
    127  */
    128 function bp_admin_setting_callback_activity_akismet() {
    129 ?>
    130 
    131     <input id="_bp_enable_akismet" name="_bp_enable_akismet" type="checkbox" value="1" <?php checked( bp_is_akismet_active( true ) ); ?> />
    132     <label for="_bp_enable_akismet"><?php _e( 'Allow Akismet to scan for activity stream spam', 'buddypress' ); ?></label>
    133 
    134 <?php
    135 }
    136 
    137 /** Groups Section ************************************************************/
    138 
    139 /**
    140  * Groups settings section description for the settings page
    141  *
    142  * @since BuddyPress (1.6)
    143  */
    144 function bp_admin_setting_callback_groups_section() {
    145 ?>
    146 
    147     <p><?php _e( 'Settings for the Groups component', 'buddypress' ); ?></p>
    148 
    149 <?php
    150 }
     141function bp_admin_setting_callback_groups_section() { }
    151142
    152143/**
     
    167158}
    168159
     160/** Forums Section ************************************************************/
     161
     162/**
     163 * Forums settings section description for the settings page
     164 *
     165 * @since BuddyPress (1.6)
     166 */
     167function bp_admin_setting_callback_bbpress_section() { }
     168
     169/**
     170 * Allow topic and reply revisions
     171 *
     172 * @since BuddyPress (1.6)
     173 * @uses checked() To display the checked attribute
     174 * @uses bp_get_option() To get the config location
     175 * @uses bp_form_option() To get the sanitized form option
     176 */
     177function bp_admin_setting_callback_bbpress_configuration() {
     178
     179    $config_location = bp_get_option( 'bb-config-location' );
     180    $file_exists     = (bool) ( file_exists( $config_location ) || is_file( $config_location ) ); ?>
     181
     182    <input name="bb-config-location" type="text" id="bb-config-location" value="<?php bp_form_option( 'bb-config-location', '' ); ?>" class="medium-text" style="width: 300px;" />
     183
     184    <?php if ( false === $file_exists ) : ?>
     185
     186        <a class="button" href="<?php bp_admin_url( 'admin.php?page=bb-forums-setup&repair=1' ); ?>" title="<?php _e( 'Attempt to save a new config file.', 'buddypress' ); ?>"><?php _e( 'Repair', 'buddypress' ) ?></a>
     187        <span class="attention"><?php _e( 'File does not exist', 'buddypress' ); ?></span>
     188
     189    <?php endif; ?>
     190
     191    <p class="description"><?php _e( 'Absolute path to your bbPress configuration file.', 'buddypress' ); ?></p>
     192
     193<?php
     194}
     195
    169196/** Settings Page *************************************************************/
    170197
     
    180207function bp_core_admin_settings() {
    181208    global $wp_settings_fields;
    182    
    183     // We're saving our own options, until the WP Settings API is updated to work with Multisite
    184     $form_action = add_query_arg( 'page', 'bp-settings', bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
    185209
    186210    if ( !empty( $_POST['submit'] ) ) {
    187211        check_admin_referer( 'buddypress-options' );
    188        
     212
    189213        // Because many settings are saved with checkboxes, and thus will have no values
    190214        // in the $_POST array when unchecked, we loop through the registered settings
     
    193217                foreach( $settings as $setting_name => $setting ) {
    194218                    $value = isset( $_POST[$setting_name] ) ? $_POST[$setting_name] : '';
    195                    
     219
    196220                    bp_update_option( $setting_name, $value );
    197221                }
    198222            }
    199223        }
    200        
     224
    201225        // Some legacy options are not registered with the Settings API
    202226        $legacy_options = array(
     
    207231            'bp_restrict_group_creation'
    208232        );
    209        
     233
    210234        foreach( $legacy_options as $legacy_option ) {
    211235            // Note: Each of these options is represented by its opposite in the UI
     
    216240        }
    217241    }
    218 ?>
     242   
     243    // We're saving our own options, until the WP Settings API is updated to work with Multisite
     244    $form_action = add_query_arg( 'page', 'bp-settings', bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) ); ?>
    219245
    220246    <div class="wrap">
     
    368394        /** bbPress Core ******************************************************/
    369395
    370         if ( defined( 'BBP_VERSION' ) ) {
     396        if ( bp_forums_is_bbpress_active() ) {
    371397
    372398            // Forum archive slug
  • trunk/bp-core/bp-core-admin.php

    r5868 r5885  
    307307        add_settings_section( 'bp_main',            __( 'Main Settings',    'buddypress' ), 'bp_admin_setting_callback_main_section',     'buddypress'            );
    308308
    309         // Edit lock setting
    310         add_settings_field( '_bp_profile_sync',     __( 'Profile Syncing',  'buddypress' ), 'bp_admin_setting_callback_profile_sync',     'buddypress', 'bp_main' );
    311         register_setting  ( 'buddypress',           '_bp_profile_sync',     'intval'                                                                              );
    312 
    313309        // Throttle setting
    314310        add_settings_field( '_bp_admin_bar',        __( 'Toolbar',        'buddypress' ), 'bp_admin_setting_callback_admin_bar',        'buddypress', 'bp_main' );
    315311        register_setting  ( 'buddypress',           '_bp_admin_bar',        'intval'                                                                              );
    316312
    317         // Allow topic and reply revisions
    318         add_settings_field( '_bp_avatar_uploads',   __( 'Avatar Uploads',   'buddypress' ), 'bp_admin_setting_callback_avatar_uploads',   'buddypress', 'bp_main' );
    319         register_setting  ( 'buddypress',           '_bp_avatar_uploads',   'intval'                                                                              );
    320 
    321313        // Allow favorites setting
    322314        add_settings_field( '_bp_account_deletion', __( 'Account Deletion', 'buddypress' ), 'bp_admin_setting_callback_account_deletion', 'buddypress', 'bp_main' );
    323315        register_setting  ( 'buddypress',           '_bp_account_deletion', 'intval'                                                                              );
    324316
    325         // Allow global access setting
    326         if ( function_exists( 'wp_editor' ) ) {
    327             add_settings_field( '_bp_use_wp_editor', __( 'Fancy Editor',    'buddypress' ), 'bp_admin_setting_callback_use_wp_editor',    'buddypress', 'bp_main' );
    328             register_setting  ( 'buddypress',        '_bp_use_wp_editor',   'intval'                                                                              );
     317        /** XProfile Section **************************************************/
     318
     319        if ( bp_is_active( 'xprofile' ) ) {
     320
     321            // Add the main section
     322            add_settings_section( 'bp_xprofile',      __( 'Profile Settings', 'buddypress' ), 'bp_admin_setting_callback_xprofile_section', 'buddypress'                );
     323
     324            // Allow topic and reply revisions
     325            add_settings_field( '_bp_avatar_uploads', __( 'Avatar Uploads',   'buddypress' ), 'bp_admin_setting_callback_avatar_uploads',   'buddypress', 'bp_xprofile' );
     326            register_setting  ( 'buddypress',         '_bp_avatar_uploads',   'intval'                                                                                  );
     327
     328            // Profile sync setting
     329            add_settings_field( '_bp_profile_sync',   __( 'Profile Syncing',  'buddypress' ), 'bp_admin_setting_callback_profile_sync',     'buddypress', 'bp_xprofile' );
     330            register_setting  ( 'buddypress',         '_bp_profile_sync',     'intval'                                                                                  );
    329331        }
    330332
    331333        /** Groups Section ****************************************************/
    332334
    333         // @todo move into groups component
    334335        if ( bp_is_active( 'groups' ) ) {
    335336
     
    339340            // Allow subscriptions setting
    340341            add_settings_field( '_bp_group_creation', __( 'Group Creation',   'buddypress' ), 'bp_admin_setting_callback_group_creation',   'buddypress', 'bp_groups' );
    341             register_setting  ( 'buddypress',         '_bp_group_creation',   'intval'                                                                                );
     342            register_setting  ( 'buddypress',         '_bp_group_creation',   'intval'                                                                                );           
     343        }
     344
     345        /** Forums ************************************************************/
     346
     347        if ( bp_is_active( 'forums' ) && bp_forums_is_installed_correctly() ) {
     348
     349            // Add the main section
     350            add_settings_section( 'bp_forums',        __( 'Forums Settings',       'buddypress' ), 'bp_admin_setting_callback_bbpress_section',       'buddypress'              );
     351
     352            // Allow subscriptions setting
     353            add_settings_field( 'bb-config-location', __( 'bbPress Configuration', 'buddypress' ), 'bp_admin_setting_callback_bbpress_configuration', 'buddypress', 'bp_forums' );
     354            register_setting  ( 'buddypress',         'bb-config-location',        ''                                                                                           );
    342355        }
    343356
    344357        /** Activity Section **************************************************/
    345358
    346         // @todo move into activity component
    347359        if ( bp_is_active( 'activity' ) && ( is_plugin_active( 'akismet/akismet.php' ) && defined( 'AKISMET_VERSION' ) ) ) {
    348360
  • trunk/bp-forums/bp-forums-admin.php

    r5749 r5885  
    11<?php
     2
    23// Exit if accessed directly
    34if ( !defined( 'ABSPATH' ) ) exit;
    45
     6/** UI ************************************************************************/
     7
    58function bp_forums_add_admin_menu() {
    69
    710    if ( ! bp_current_user_can( 'bp_moderate' ) )
     11        return;
     12
     13    if ( ! bp_forums_is_repair() )
    814        return;
    915
     
    1824
    1925function bp_forums_bbpress_admin() {
    20 
    21     $action = bp_get_admin_url( 'admin.php?page=bb-forums-setup&reinstall=1' ); ?>
     26?>
    2227
    2328    <div class="wrap">
     29
    2430        <?php screen_icon( 'buddypress' ); ?>
    2531
    2632        <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( __( 'Forums', 'buddypress' ) ); ?></h2>
    2733
    28         <?php if ( isset( $_POST['submit'] ) ) : ?>
    29 
    30             <div id="message" class="updated fade">
    31                 <p><?php _e( 'Settings Saved.', 'buddypress' ) ?></p>
     34        <h3><?php _e( 'Forum Repair', 'buddypress' ); ?></h3>
     35
     36        <?php if ( bp_forums_is_repair() ) : ?>
     37
     38            <p><?php printf( __( 'The following configuration was successfully saved to: %s', 'buddypress' ), bp_get_option( 'bb-config-location' ) );?></p>
     39
     40            <div id="template">
     41                <textarea cols="70" rows="25" name="bb-config" id="bb-config"><?php echo bp_forums_bbpress_install( bp_get_option( 'bb-config-location' ) ); ?></textarea>
    3242            </div>
    3343
    34         <?php endif; ?>
    35 
    36         <?php
    37 
    38         if ( isset( $_REQUEST['reinstall'] ) || !bp_forums_is_installed_correctly() ) :
    39 
    40             // Delete the bb-config.php location option
    41             bp_delete_option( 'bb-config-location' );
    42             bp_forums_bbpress_install_wizard();
    43 
    44         else : ?>
    45 
    46             <div style="width: 45%; float: left; margin-top: 20px;">
    47                 <h3><?php _e( '(Installed)', 'buddypress' ); ?> <?php _e( 'Forums for Groups', 'buddypress' ) ?></h3>
    48 
    49                 <p><?php _e( 'Give each individual group its own discussion forum. Choose this if you\'d like to keep your members\' conversations separated into distinct areas.' , 'buddypress' ); ?></p>
    50                 <p class="description"><?php _e( 'You may use an existing bbPress installation if you have one.', 'buddypress' ); ?></p>
    51 
    52                 <h4 style="margin-bottom: 10px;"><?php _e( 'Features', 'buddypress' ); ?></h4>
    53                 <ul class="description" style="list-style: square; margin-left: 30px;">
    54                     <li><?php _e( 'Group Integration',           'buddypress' ); ?></p></li>
    55                     <li><?php _e( 'Member Profile Integration',  'buddypress' ); ?></p></li>
    56                     <li><?php _e( 'Activity Stream Integration', 'buddypress' ); ?></p></li>
    57                     <li><?php _e( '@ Mention Integration',       'buddypress' ); ?></p></li>
    58                 </ul>
    59 
    60                 <div>
    61                     <a class="button button-primary" href="<?php echo $action ?>"><?php _e( 'Uninstall Group Forums', 'buddypress' ) ?></a> &nbsp;
    62                 </div>
    63             </div>
    64 
    65             <div style="width: 45%; float: left; margin: 20px 0 20px 20px; padding: 0 20px 20px 20px; border: 1px solid #ddd; background-color: #fff;">
    66                 <h3><?php _e( 'New! Site Wide Forums', 'buddypress' ) ?></h3>
    67                 <p><?php _e( 'Your site will have central forums that are not isolated to any specific group. Choose this if you\'d like to have a central forum area for your members.', 'buddypress' ) ?></p>
    68                 <p class="description"><?php _e( 'You may activate both Group and Site Wide forums, but this may create a poor experience for your members.', 'buddypress' ) ?></p>
    69 
    70                 <h4 style="margin-bottom: 10px;"><?php _e( 'Features', 'buddypress' ); ?></h4>
    71                 <ul class="description" style="list-style: square; margin-left: 30px;">
    72                     <li><?php _e( 'Central Discussion Area',     'buddypress' ); ?></p></li>
    73                     <li><?php _e( 'Forum Plugins Available',     'buddypress' ); ?></p></li>
    74                     <li><?php _e( 'Activity Stream Integration', 'buddypress' ); ?></p></li>
    75                     <li><?php _e( '@ Mention Integration',       'buddypress' ); ?></p></li>
    76                 </ul>
    77                 <div>
    78                     <a class="button thickbox button-primary" href="<?php bp_admin_url( add_query_arg( array( 'tab' => 'plugin-information', 'plugin' => 'bbpress', 'TB_iframe' => 'true', 'width' => '640', 'height' => '500' ), 'plugin-install.php' ) ); ?>"><?php _e( 'Install Site Wide Forums', 'buddypress' ) ?></a> &nbsp;
    79                 </div>
    80             </div>
    81 
    82         <?php endif; ?>
    83 
    84     </div>
    85 <?php
    86 }
    87 
    88 function bp_forums_bbpress_install_wizard() {
    89     $post_url = network_admin_url( 'admin.php?page=bb-forums-setup' );
    90 
    91     $step = isset( $_REQUEST['step'] ) ? $_REQUEST['step'] : '';
    92 
    93     switch( $step ) {
    94         case 'existing':
    95             if ( isset( $_REQUEST['doinstall'] ) && ( 1 == (int) $_REQUEST['doinstall'] ) ) {
    96                 if ( !bp_forums_configure_existing_install() ) {
    97                     _e( 'The bb-config.php file was not found at that location, please try again.', 'buddypress' );
    98                 } else {
    99                     ?>
    100                     <h3><?php _e( 'Forums were set up correctly using your existing bbPress install!', 'buddypress' ) ?></h3>
    101                     <p><?php _e( 'BuddyPress will now use its internal copy of bbPress to run the forums on your site. If you wish, you can remove your old bbPress installation files, as long as you keep the bb-config.php file in the same location.', 'buddypress' ) ?></p><?php
    102                 }
    103             } else { ?>
    104 
    105                     <form action="" method="post">
    106                         <h3><?php _e( 'Existing bbPress Installation', 'buddypress' ) ?></h3>
    107                         <p><?php _e( "BuddyPress can make use of your existing bbPress install. Just provide the location of your <code>bb-config.php</code> file, and BuddyPress will do the rest.", 'buddypress' ) ?></p>
    108                         <p><label><code>bb-config.php</code> file location:</label><br /><input style="width: 50%" type="text" name="bbconfigloc" id="bbconfigloc" value="<?php echo str_replace( 'buddypress', '', $_SERVER['DOCUMENT_ROOT'] ) ?>" /></p>
    109                         <p><input type="submit" class="button-primary" value="<?php _e( 'Complete Installation', 'buddypress' ) ?>" /></p>
    110                         <input type="hidden" name="step" value="existing" />
    111                         <input type="hidden" name="doinstall" value="1" />
    112                         <?php wp_nonce_field( 'bp_forums_existing_install_init' ) ?>
    113                     </form>
    114 
    115                 <?php
    116             }
    117         break;
    118 
    119         case 'new':
    120             if ( isset( $_REQUEST['doinstall'] ) && 1 == (int) $_REQUEST['doinstall'] ) {
    121                 $result = bp_forums_bbpress_install();
    122 
    123                 switch ( $result ) {
    124                     case 1:
    125                         _e( '<p>All done! Configuration settings have been saved to the file <code>bb-config.php</code> in the root of your WordPress install.</p>', 'buddypress' );
    126                         break;
    127                     default:
    128                         // Just write the contents to screen
    129                         _e( '<p>A configuration file could not be created. No problem, but you will need to save the text shown below into a file named <code>bb-config.php</code> in the root directory of your WordPress installation before you can start using the forum functionality.</p>', 'buddypress' ); ?>
    130 
    131                         <textarea style="display:block; margin-top: 30px; width: 80%;" rows="50"><?php echo htmlspecialchars( $result ); ?></textarea>
    132 
    133                     <?php
    134                         break;
    135                 }
    136             } else { ?>
    137 
    138                 <h3><?php _e( 'New bbPress Installation', 'buddypress' ) ?></h3>
    139                 <p><?php _e( "You've decided to set up a new installation of bbPress for forum management in BuddyPress. This is very simple and is usually just a one click
    140                 process. When you're ready, hit the link below.", 'buddypress' ) ?></p>
    141                 <p><a class="button-primary" href="<?php echo wp_nonce_url( $post_url . '&step=new&doinstall=1', 'bp_forums_new_install_init' ) ?>"><?php _e( 'Complete Installation', 'buddypress' ) ?></a></p>
    142 
    143                 <?php
    144             }
    145         break;
    146 
    147         default:
    148             if ( !file_exists( BP_PLUGIN_DIR . '/bp-forums/bbpress/' ) ) { ?>
    149 
    150                 <div id="message" class="error">
    151                     <p><?php printf( __( 'bbPress files were not found. To install the forums component you must download a copy of bbPress and make sure it is in the folder: "%s"', 'buddypress' ), 'wp-content/plugins/buddypress/bp-forums/bbpress/' ) ?></p>
    152                 </div>
    153 
    154             <?php } else {
    155 
    156                 // Include the plugin install
    157 
     44        <?php elseif ( bp_forums_is_migrate() ) : ?>
     45
     46            <?php
    15847                add_thickbox();
    15948                wp_enqueue_script( 'plugin-install' );
     
    16150            ?>
    16251
    163                 <div style="width: 45%; float: left;  margin-top: 20px;">
    164                     <h3><?php _e( 'Forums for Groups', 'buddypress' ) ?></h3>
    165 
    166                     <p><?php _e( 'Give each individual group its own discussion forum. Choose this if you\'d like to keep your members\' conversations separated into distinct areas.' , 'buddypress' ); ?></p>
    167                     <p class="description"><?php _e( 'You may use an existing bbPress installation if you have one.', 'buddypress' ); ?></p>
    168 
    169                     <h4 style="margin-bottom: 10px;"><?php _e( 'Features', 'buddypress' ); ?></h4>
    170                     <ul class="description" style="list-style: square; margin-left: 30px;">
    171                         <li><?php _e( 'Group Integration',           'buddypress' ); ?></p></li>
    172                         <li><?php _e( 'Member Profile Integration',  'buddypress' ); ?></p></li>
    173                         <li><?php _e( 'Activity Stream Integration', 'buddypress' ); ?></p></li>
    174                         <li><?php _e( '@ Mention Integration',       'buddypress' ); ?></p></li>
    175                     </ul>
    176 
    177                     <div>
    178                         <a class="button button-primary" href="<?php echo $post_url . '&step=new' ?>"><?php _e( 'Install Group Forums', 'buddypress' ) ?></a> &nbsp;
    179                         <a class="button" href="<?php echo $post_url . '&step=existing' ?>"><?php _e( 'Use Existing Installation', 'buddypress' ) ?></a>
    180                     </div>
    181                 </div>
    182 
    183                 <div style="width: 45%; float: left; margin: 20px 0 20px 20px; padding: 0 20px 20px 20px; border: 1px solid #ddd; background-color: #fff;">
    184                     <h3><?php _e( 'New! Site Wide Forums', 'buddypress' ) ?></h3>
    185                     <p><?php _e( 'Your site will have central forums that are not isolated to any specific group. Choose this if you\'d like to have a central forum area for your members.', 'buddypress' ) ?></p>
    186                     <p class="description"><?php _e( 'You may activate both Group and Site Wide forums, but this may create a poor experience for your members.', 'buddypress' ) ?></p>
    187 
    188                     <h4 style="margin-bottom: 10px;"><?php _e( 'Features', 'buddypress' ); ?></h4>
    189                     <ul class="description" style="list-style: square; margin-left: 30px;">
    190                         <li><?php _e( 'Central Discussion Area',     'buddypress' ); ?></p></li>
    191                         <li><?php _e( 'Forum Plugins Available',     'buddypress' ); ?></p></li>
    192                         <li><?php _e( 'Activity Stream Integration', 'buddypress' ); ?></p></li>
    193                         <li><?php _e( '@ Mention Integration',       'buddypress' ); ?></p></li>
    194                     </ul>
    195                     <div>
    196                         <a class="button thickbox button-primary" href="<?php bp_admin_url( add_query_arg( array( 'tab' => 'plugin-information', 'plugin' => 'bbpress', 'TB_iframe' => 'true', 'width' => '640', 'height' => '500' ), 'plugin-install.php' ) ); ?>"><?php _e( 'Install Site Wide Forums', 'buddypress' ) ?></a> &nbsp;
    197                     </div>
    198                 </div>
    199 
    200             <?php }
    201         break;
    202     }
    203 }
    204 
    205 function bp_forums_configure_existing_install() {
    206 
    207     check_admin_referer( 'bp_forums_existing_install_init' );
    208 
    209     // Sanitize $_REQUEST['bbconfigloc']
    210     $_REQUEST['bbconfigloc'] = apply_filters( 'bp_forums_bbconfig_location', $_REQUEST['bbconfigloc'] );
    211 
    212     if ( false === strpos( $_REQUEST['bbconfigloc'], 'bb-config.php' ) ) {
    213         if ( '/' != substr( $_REQUEST['bbconfigloc'], -1, 1 ) )
    214             $_REQUEST['bbconfigloc'] .= '/';
    215 
    216         $_REQUEST['bbconfigloc'] .= 'bb-config.php';
    217     }
    218 
    219     bp_update_option( 'bb-config-location', $_REQUEST['bbconfigloc'] );
    220 
    221     if ( !file_exists( $_REQUEST['bbconfigloc'] ) )
    222         return false;
    223 
    224     return true;
    225 }
    226 
    227 function bp_forums_bbpress_install() {
     52            <a class="button thickbox button-primary" href="<?php bp_admin_url( add_query_arg( array( 'tab' => 'plugin-information', 'plugin' => 'bbpress', 'TB_iframe' => 'true', 'width' => '640', 'height' => '500' ), 'plugin-install.php' ) ); ?>"><?php _e( 'Install Site Wide Forums', 'buddypress' ) ?></a> &nbsp;
     53
     54        <?php else : ?>
     55
     56        <?php endif; ?>
     57
     58    </div>
     59<?php
     60}
     61
     62/** _is_ **********************************************************************/
     63
     64/**
     65 * Trying to repair a bbPress 1.x installation
     66 *
     67 * @since BuddyPress (1.6)
     68 * @return boolean True if option exists, false if not
     69 */
     70function bp_forums_is_repair() {
     71
     72    // Bail if bbPress 1.x was never installed
     73    if ( isset( $_REQUEST['repair'] ) && bp_forums_is_installed_correctly() )
     74        return true;
     75
     76    return false;
     77}
     78
     79/**
     80 * bbPress 1.x is installed, and we're moving to bbPress 2.x
     81 *
     82 * @since BuddyPress (1.6)
     83 * @return boolean True if option exists, false if not
     84 */
     85function bp_forums_is_migrate() {
     86
     87    // Bail if bbPress 1.x was never installed
     88    if ( isset( $_REQUEST['migrate'] ) && bp_forums_is_installed_correctly() )
     89        return true;
     90
     91    return false;
     92}
     93
     94/**
     95 * bbPress was never installed before, and bbPress 2.x is not installed yet
     96 *
     97 * @since BuddyPress (1.6)
     98 * @return boolean True if option exists, false if not
     99 */
     100function bp_forums_is_fresh_install() {
     101
     102    // Bail if bbPress 1.x was never installed
     103    if ( isset( $_REQUEST['install'] ) && ! bp_forums_is_installed_correctly() )
     104        return true;
     105
     106    return false;
     107}
     108
     109/**
     110 * Both bbPress 1.x and bbPress 2.x are installed
     111 *
     112 * @since BuddyPress (1.6)
     113 * @return boolean True if option exists, false if not
     114 */
     115function bp_forums_is_hybrid_install() {
     116
     117    // Bail if bbPress 1.x was never installed
     118    if ( isset( $_REQUEST['install'] ) && bp_forums_is_bbpress_active && bp_forums_is_installed_correctly() )
     119        return true;
     120
     121    return false;
     122}
     123
     124/** Config ********************************************************************/
     125
     126function bp_forums_bbpress_install( $location = '' ) {
    228127    global $wpdb, $bp;
    229128
    230     check_admin_referer( 'bp_forums_new_install_init' );
     129    if ( empty( $location ) )
     130        $location = ABSPATH . 'bb-config.php';
    231131
    232132    // Create the bb-config.php file
    233133    $initial_write = bp_forums_bbpress_write(
    234134        BP_PLUGIN_DIR . '/bp-forums/bbpress/bb-config-sample.php',
    235         ABSPATH . 'bb-config.php',
     135        $location,
    236136        array(
    237137            "define( 'BBDB_NAME',"  => array( "'bbpress'",                      "'" . DB_NAME . "'" ),
     
    251151
    252152    // Add the custom user and usermeta entries to the config file
    253     if ( $initial_write == 1 )
    254         $file = file_get_contents( ABSPATH . 'bb-config.php' );
    255     else
     153    if ( $initial_write == 1 ) {
     154        $file = file_get_contents( $location );
     155    } else {
    256156        $file = &$initial_write;
     157    }
    257158
    258159    $file = trim( $file );
    259     if ( '?>' == substr( $file, -2, 2 ) )
     160    if ( '?>' == substr( $file, -2, 2 ) ) {
    260161        $file = substr( $file, 0, -2 );
     162    }
    261163
    262164    $file .= "\n" .   '$bb->custom_user_table = \'' . $wpdb->users . '\';';
     
    265167    $file .= "\n" .   '$bb->name = \'' . get_blog_option( bp_get_root_blog_id(), 'blogname' ) . ' ' . __( 'Forums', 'buddypress' ) . '\';';
    266168
    267     if ( is_multisite() )
     169    if ( is_multisite() ) {
    268170        $file .= "\n" .   '$bb->wordpress_mu_primary_blog_id = ' . bp_get_root_blog_id() . ';';
    269 
    270     if ( defined( 'AUTH_SALT' ) )
     171    }
     172
     173    if ( defined( 'AUTH_SALT' ) ) {
    271174        $file .= "\n\n" . 'define(\'BB_AUTH_SALT\', \'' . addslashes( AUTH_SALT ) . '\');';
    272 
    273     if ( defined( 'LOGGED_IN_SALT' ) )
     175    }
     176
     177    if ( defined( 'LOGGED_IN_SALT' ) ) {
    274178        $file .= "\n" .   'define(\'BB_LOGGED_IN_SALT\', \'' . addslashes( LOGGED_IN_SALT ) . '\');';
    275 
    276     if ( defined( 'SECURE_AUTH_SALT' ) )
     179    }
     180
     181    if ( defined( 'SECURE_AUTH_SALT' ) ) {
    277182        $file .= "\n" .   'define(\'BB_SECURE_AUTH_SALT\', \'' . addslashes( SECURE_AUTH_SALT ) . '\');';
     183    }
    278184
    279185    $file .= "\n\n" . 'define(\'WP_AUTH_COOKIE_VERSION\', 2);';
     
    281187
    282188    if ( $initial_write == 1 ) {
    283         $file_handle = fopen( ABSPATH . 'bb-config.php', 'w' );
     189        $file_handle = fopen( $location, 'w' );
    284190        fwrite( $file_handle, $file );
    285191        fclose( $file_handle );
     
    288194    }
    289195
    290     bp_update_option( 'bb-config-location', ABSPATH . 'bb-config.php' );
    291     return $initial_write;
     196    bp_update_option( 'bb-config-location', $location );
     197
     198    return $file;
    292199}
    293200
    294201function bp_forums_bbpress_write( $file_source, $file_target, $alterations ) {
    295202
    296     if ( !$file_source || !file_exists( $file_source ) || !is_file( $file_source ) )
     203    if ( empty( $file_source ) || !file_exists( $file_source ) || !is_file( $file_source ) ) {
    297204        return -1;
    298 
    299     if ( !$file_target )
     205    }
     206
     207    if ( empty( $file_target ) ) {
    300208        $file_target = $file_source;
    301 
    302     if ( !$alterations || !is_array( $alterations ) )
     209    }
     210
     211    if ( empty( $alterations ) || !is_array( $alterations ) ) {
    303212        return -2;
     213    }
    304214
    305215    // Get the existing lines in the file
     
    336246    }
    337247
    338     if ( empty( $writable ) )
     248    if ( empty( $writable ) ) {
    339249        return trim( join( null, $modified_lines ) );
     250    }
    340251
    341252    // Open the file for writing - rewrites the whole file
  • trunk/bp-forums/bp-forums-bbpress-sa.php

    r5796 r5885  
    4040
    4141    $bb = new stdClass();
    42     require( $bp->forums->bbconfig );
     42    require( bp_get_option( 'bb-config-location' ) );
    4343
    4444    // Setup the global database connection
  • trunk/bp-forums/bp-forums-functions.php

    r5871 r5885  
    11<?php
     2
    23// Exit if accessed directly
    34if ( !defined( 'ABSPATH' ) ) exit;
    45
     6/** bbPress 2.x ***************************************************************/
     7
     8/**
     9 * Used to see if bbPress 2.x is installed and active
     10 *
     11 * @since BuddyPress (1.6)
     12 * @return boolean True if bbPress 2.x is active, false if not
     13 */
     14function bp_forums_is_bbpress_active() {
     15
     16    // Single site
     17    if ( is_plugin_active( 'bbpress/bbpress.php' ) )
     18        return true;
     19
     20    // Network active
     21    if ( is_plugin_active_for_network( 'bbpress/bbpress.php' ) )
     22        return true;
     23
     24    // Nope
     25    return false;
     26}
     27
     28/** bbPress 1.x ***************************************************************/
     29
     30/**
     31 * If the bb-config-location option exists, bbPress 1.x was previously installed
     32 *
     33 * @since BuddyPress (1.2)
     34 * @return boolean True if option exists, false if not
     35 */
    536function bp_forums_is_installed_correctly() {
    6     global $bp;
    7 
    8     if ( isset( $bp->forums->bbconfig ) && is_file( $bp->forums->bbconfig ) )
     37    if ( bp_get_option( 'bb-config-location' ) )
    938        return true;
    1039
  • trunk/bp-forums/bp-forums-loader.php

    r5868 r5885  
    4747        if ( !defined( 'BP_FORUMS_SLUG' ) )
    4848            define( 'BP_FORUMS_SLUG', $this->id );
    49 
    50         // The location of the bbPress stand-alone config file
    51         if ( isset( $bp->site_options['bb-config-location'] ) )
    52             $this->bbconfig = $bp->site_options['bb-config-location'];
    5349
    5450        // All globals for messaging component.
Note: See TracChangeset for help on using the changeset viewer.