Skip to:
Content

BuddyPress.org

Changeset 6108


Ignore:
Timestamp:
06/18/2012 01:06:13 PM (12 years ago)
Author:
boonebgorges
Message:

Reinstates 1.5.x integration of bbPress 1.x forum installation and configuration

In anticipation for a full switchover to bbPress 2.x in BuddyPress 1.6, several
aspects of the forum configuration and setup process were modified. Since
the migration to bbPress 2.x is being put off to a later version of BuddyPress,
it's necessary to revert some of these changes back to their BP 1.5.x state.

This changeset also fixes a bug in the bb-config.php creation script, where
a salt containing the string '?>' could result in early termination of the
config file.

Fixes #4269

Location:
trunk
Files:
6 edited

Legend:

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

    r6094 r6108  
    366366    );
    367367
    368     // If forums component is active and bbPress 1.x is in use add additional tab
    369     if ( bp_is_active( 'forums' ) && bp_forums_is_repair() ) {
     368    // If forums component is active, add additional tab
     369    if ( bp_is_active( 'forums' ) ) {
    370370        $tabs['3'] = array(
    371371            'href' => bp_get_admin_url( add_query_arg( array( 'page' => 'bb-forums-setup'  ), 'admin.php' ) ),
  • trunk/bp-core/admin/bp-core-update.php

    r6105 r6108  
    541541        $screenshot    = '';
    542542
    543         if ( !empty( $installed_themes[$current_theme]['Screenshot'] ) ) {
    544             $screenshot = trailingslashit( get_stylesheet_directory_uri() ) . $installed_themes[$current_theme]['Screenshot'];
     543        if ( !empty( $installed_themes[$current_theme->stylesheet]['Screenshot'] ) ) {
     544            $screenshot = trailingslashit( get_stylesheet_directory_uri() ) . $installed_themes[$current_theme->stylesheet]['Screenshot'];
    545545        } ?>
    546546
  • trunk/bp-forums/bp-forums-admin.php

    r5885 r6108  
    11<?php
    2 
    32// Exit if accessed directly
    43if ( !defined( 'ABSPATH' ) ) exit;
    54
    6 /** UI ************************************************************************/
    7 
    85function bp_forums_add_admin_menu() {
    9 
    10     if ( ! bp_current_user_can( 'bp_moderate' ) )
    11         return;
    12 
    13     if ( ! bp_forums_is_repair() )
    14         return;
    15 
    16     // Add the option pages
    17     $page = bp_core_do_network_admin()  ? 'settings.php' : 'options-general.php';
    18     $hook = add_submenu_page( $page, __( 'BuddyPress Forums', 'buddypress' ), __( 'BuddyPress Forums', 'buddypress' ), 'manage_options', 'bb-forums-setup', 'bp_forums_bbpress_admin' );
    19 
    20     // Fudge the highlighted subnav item when on a BuddyPress admin page
     6    global $bp;
     7
     8    if ( !is_super_admin() )
     9        return false;
     10
     11    $page  = bp_core_do_network_admin()  ? 'settings.php' : 'options-general.php';
     12
     13    // Add the administration tab under the "Site Admin" tab for site administrators
     14    $hook = add_submenu_page( $page, __( 'Forums', 'buddypress' ), __( 'Forums', 'buddypress' ), 'manage_options', 'bb-forums-setup', "bp_forums_bbpress_admin" );
     15
     16    // Fudge the highlighted subnav item when on the BuddyPress Forums admin page
    2117    add_action( "admin_head-$hook", 'bp_core_modify_admin_menu_highlight' );
    2218}
     
    2420
    2521function bp_forums_bbpress_admin() {
    26 ?>
     22    global $bp;
     23
     24    $action = bp_get_admin_url( 'admin.php?page=bb-forums-setup&reinstall=1' ); ?>
    2725
    2826    <div class="wrap">
    29 
    3027        <?php screen_icon( 'buddypress' ); ?>
    3128
    3229        <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( __( 'Forums', 'buddypress' ) ); ?></h2>
    3330
    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>
     31        <?php if ( isset( $_POST['submit'] ) ) : ?>
     32
     33            <div id="message" class="updated fade">
     34                <p><?php _e( 'Settings Saved.', 'buddypress' ) ?></p>
    4235            </div>
    4336
    44         <?php elseif ( bp_forums_is_migrate() ) : ?>
    45 
    46             <?php
     37        <?php endif; ?>
     38
     39        <?php
     40
     41        if ( isset( $_REQUEST['reinstall'] ) || !bp_forums_is_installed_correctly() ) :
     42
     43            // Delete the bb-config.php location option
     44            bp_delete_option( 'bb-config-location' );
     45            bp_forums_bbpress_install_wizard();
     46
     47        else : ?>
     48
     49            <div style="width: 45%; float: left; margin-top: 20px;">
     50                <h3><?php _e( '(Installed)', 'buddypress' ); ?> <?php _e( 'Forums for Groups', 'buddypress' ) ?></h3>
     51
     52                <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>
     53                <p class="description"><?php _e( 'You may use an existing bbPress installation if you have one.', 'buddypress' ); ?></p>
     54
     55                <h4 style="margin-bottom: 10px;"><?php _e( 'Features', 'buddypress' ); ?></h4>
     56                <ul class="description" style="list-style: square; margin-left: 30px;">
     57                    <li><?php _e( 'Group Integration',           'buddypress' ); ?></p></li>
     58                    <li><?php _e( 'Member Profile Integration',  'buddypress' ); ?></p></li>
     59                    <li><?php _e( 'Activity Stream Integration', 'buddypress' ); ?></p></li>
     60                    <li><?php _e( '@ Mention Integration',       'buddypress' ); ?></p></li>
     61                </ul>
     62
     63                <div>
     64                    <a class="button button-primary" href="<?php echo $action ?>"><?php _e( 'Uninstall Group Forums', 'buddypress' ) ?></a> &nbsp;
     65                </div>
     66            </div>
     67
     68            <div style="width: 45%; float: left; margin: 20px 0 20px 20px; padding: 0 20px 20px 20px; border: 1px solid #ddd; background-color: #fff;">
     69                <h3><?php _e( 'New! Site Wide Forums', 'buddypress' ) ?></h3>
     70                <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>
     71                <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>
     72
     73                <h4 style="margin-bottom: 10px;"><?php _e( 'Features', 'buddypress' ); ?></h4>
     74                <ul class="description" style="list-style: square; margin-left: 30px;">
     75                    <li><?php _e( 'Central Discussion Area',     'buddypress' ); ?></p></li>
     76                    <li><?php _e( 'Forum Plugins Available',     'buddypress' ); ?></p></li>
     77                    <li><?php _e( 'Activity Stream Integration', 'buddypress' ); ?></p></li>
     78                    <li><?php _e( '@ Mention Integration',       'buddypress' ); ?></p></li>
     79                </ul>
     80                <div>
     81                    <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;
     82                </div>
     83            </div>
     84
     85        <?php endif; ?>
     86
     87    </div>
     88<?php
     89}
     90
     91function bp_forums_bbpress_install_wizard() {
     92    $post_url = network_admin_url( 'admin.php?page=bb-forums-setup' );
     93
     94    $step = isset( $_REQUEST['step'] ) ? $_REQUEST['step'] : '';
     95
     96    switch( $step ) {
     97        case 'existing':
     98            if ( isset( $_REQUEST['doinstall'] ) && ( 1 == (int) $_REQUEST['doinstall'] ) ) {
     99                if ( !bp_forums_configure_existing_install() ) {
     100                    _e( 'The bb-config.php file was not found at that location, please try again.', 'buddypress' );
     101                } else {
     102                    ?>
     103                    <h3><?php _e( 'Forums were set up correctly using your existing bbPress install!', 'buddypress' ) ?></h3>
     104                    <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
     105                }
     106            } else { ?>
     107
     108                    <form action="" method="post">
     109                        <h3><?php _e( 'Existing bbPress Installation', 'buddypress' ) ?></h3>
     110                        <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>
     111                        <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>
     112                        <p><input type="submit" class="button-primary" value="<?php _e( 'Complete Installation', 'buddypress' ) ?>" /></p>
     113                        <input type="hidden" name="step" value="existing" />
     114                        <input type="hidden" name="doinstall" value="1" />
     115                        <?php wp_nonce_field( 'bp_forums_existing_install_init' ) ?>
     116                    </form>
     117
     118                <?php
     119            }
     120        break;
     121
     122        case 'new':
     123            if ( isset( $_REQUEST['doinstall'] ) && 1 == (int)$_REQUEST['doinstall'] ) {
     124                $result = bp_forums_bbpress_install();
     125
     126                switch ( $result ) {
     127                    case 1:
     128                        _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' );
     129                        break;
     130                    default:
     131                        // Just write the contents to screen
     132                        _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' ); ?>
     133
     134                        <textarea style="display:block; margin-top: 30px; width: 80%;" rows="50"><?php echo htmlspecialchars( $result ); ?></textarea>
     135
     136                    <?php
     137                        break;
     138                }
     139            } else { ?>
     140
     141                <h3><?php _e( 'New bbPress Installation', 'buddypress' ) ?></h3>
     142                <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
     143                process. When you're ready, hit the link below.", 'buddypress' ) ?></p>
     144                <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>
     145
     146                <?php
     147            }
     148        break;
     149
     150        default:
     151            if ( !file_exists( BP_PLUGIN_DIR . '/bp-forums/bbpress/' ) ) { ?>
     152
     153                <div id="message" class="error">
     154                    <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>
     155                </div>
     156
     157            <?php } else {
     158
     159                // Include the plugin install
     160
    47161                add_thickbox();
    48162                wp_enqueue_script( 'plugin-install' );
     
    50164            ?>
    51165
    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  */
    70 function 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  */
    85 function 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  */
    100 function 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  */
    115 function 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 ********************************************************************/
     166                <div style="width: 45%; float: left;  margin-top: 20px;">
     167                    <h3><?php _e( 'Forums for Groups', 'buddypress' ) ?></h3>
     168
     169                    <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>
     170                    <p class="description"><?php _e( 'You may use an existing bbPress installation if you have one.', 'buddypress' ); ?></p>
     171
     172                    <h4 style="margin-bottom: 10px;"><?php _e( 'Features', 'buddypress' ); ?></h4>
     173                    <ul class="description" style="list-style: square; margin-left: 30px;">
     174                        <li><?php _e( 'Group Integration',           'buddypress' ); ?></p></li>
     175                        <li><?php _e( 'Member Profile Integration',  'buddypress' ); ?></p></li>
     176                        <li><?php _e( 'Activity Stream Integration', 'buddypress' ); ?></p></li>
     177                        <li><?php _e( '@ Mention Integration',       'buddypress' ); ?></p></li>
     178                    </ul>
     179
     180                    <div>
     181                        <a class="button button-primary" href="<?php echo $post_url . '&step=new' ?>"><?php _e( 'Install Group Forums', 'buddypress' ) ?></a> &nbsp;
     182                        <a class="button" href="<?php echo $post_url . '&step=existing' ?>"><?php _e( 'Use Existing Installation', 'buddypress' ) ?></a>
     183                    </div>
     184                </div>
     185
     186                <div style="width: 45%; float: left; margin: 20px 0 20px 20px; padding: 0 20px 20px 20px; border: 1px solid #ddd; background-color: #fff;">
     187                    <h3><?php _e( 'New! Site Wide Forums', 'buddypress' ) ?></h3>
     188                    <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>
     189                    <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>
     190
     191                    <h4 style="margin-bottom: 10px;"><?php _e( 'Features', 'buddypress' ); ?></h4>
     192                    <ul class="description" style="list-style: square; margin-left: 30px;">
     193                        <li><?php _e( 'Central Discussion Area',     'buddypress' ); ?></p></li>
     194                        <li><?php _e( 'Forum Plugins Available',     'buddypress' ); ?></p></li>
     195                        <li><?php _e( 'Activity Stream Integration', 'buddypress' ); ?></p></li>
     196                        <li><?php _e( '@ Mention Integration',       'buddypress' ); ?></p></li>
     197                    </ul>
     198                    <div>
     199                        <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;
     200                    </div>
     201                </div>
     202
     203            <?php }
     204        break;
     205    }
     206}
     207
     208function bp_forums_configure_existing_install() {
     209    global $wpdb, $bbdb;
     210
     211    check_admin_referer( 'bp_forums_existing_install_init' );
     212
     213    // Sanitize $_REQUEST['bbconfigloc']
     214    $_REQUEST['bbconfigloc'] = apply_filters( 'bp_forums_bbconfig_location', $_REQUEST['bbconfigloc'] );
     215
     216    if ( false === strpos( $_REQUEST['bbconfigloc'], 'bb-config.php' ) ) {
     217        if ( '/' != substr( $_REQUEST['bbconfigloc'], -1, 1 ) )
     218            $_REQUEST['bbconfigloc'] .= '/';
     219
     220        $_REQUEST['bbconfigloc'] .= 'bb-config.php';
     221    }
     222
     223    bp_update_option( 'bb-config-location', $_REQUEST['bbconfigloc'] );
     224
     225    if ( !file_exists( $_REQUEST['bbconfigloc'] ) ) {
     226        return false;
     227    }
     228
     229    return true;
     230}
    125231
    126232function bp_forums_bbpress_install( $location = '' ) {
    127     global $wpdb, $bp;
    128 
    129     if ( empty( $location ) )
     233    global $wpdb, $bbdb, $bp;
     234
     235    check_admin_referer( 'bp_forums_new_install_init' );
     236
     237    if ( empty( $location ) ) {
    130238        $location = ABSPATH . 'bb-config.php';
     239    }
    131240
    132241    // Create the bb-config.php file
     
    164273    $file .= "\n" .   '$bb->custom_user_table = \'' . $wpdb->users . '\';';
    165274    $file .= "\n" .   '$bb->custom_user_meta_table = \'' . $wpdb->usermeta . '\';';
    166     $file .= "\n\n" . '$bb->uri = \'' . BP_PLUGIN_URL . 'bp-forums/bbpress/\';';
     275    $file .= "\n\n" . '$bb->uri = \'' . BP_PLUGIN_URL . '/bp-forums/bbpress/\';';
    167276    $file .= "\n" .   '$bb->name = \'' . get_blog_option( bp_get_root_blog_id(), 'blogname' ) . ' ' . __( 'Forums', 'buddypress' ) . '\';';
    168277
     
    195304
    196305    bp_update_option( 'bb-config-location', $location );
    197 
    198     return $file;
     306    return $initial_write;
    199307}
    200308
     
    255363    // Write lines one by one to avoid OS specific newline hassles
    256364    foreach ( (array) $modified_lines as $modified_line ) {
    257         if ( false !== strpos( $modified_line, '?>' ) ) {
     365        if ( strlen( $modified_line ) - 2 === strrpos( $modified_line, '?>' ) ) {
    258366            $modified_line = '?>';
    259367        }
     368
    260369        fwrite( $file_handle, $modified_line );
    261370        if ( $modified_line == '?>' ) {
  • trunk/bp-forums/bp-forums-functions.php

    r6093 r6108  
    3535 */
    3636function bp_forums_is_installed_correctly() {
    37     if ( bp_get_option( 'bb-config-location' ) )
     37    global $bp;
     38
     39    if ( isset( $bp->forums->bbconfig ) && is_file( $bp->forums->bbconfig ) )
    3840        return true;
    3941
  • trunk/bp-forums/bp-forums-loader.php

    r6093 r6108  
    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'];
    4953
    5054        // All globals for messaging component.
  • trunk/bp-themes/bp-default/groups/create.php

    r5888 r6108  
    108108                    </div>
    109109
    110                     <?php if ( bp_is_active( 'forums' ) && bp_forums_is_installed_correctly() ) : ?>
     110                    <?php if ( bp_is_active( 'forums' ) ) : ?>
    111111
    112112                        <h4><?php _e( 'Group Forums', 'buddypress' ); ?></h4>
    113113
    114                         <p><?php _e( 'Should this group have a forum?', 'buddypress' ); ?></p>
    115 
    116                         <div class="checkbox">
    117                             <label><input type="checkbox" name="group-show-forum" id="group-show-forum" value="1"<?php checked( bp_get_new_group_enable_forum(), true, true ); ?> /> <?php _e( 'Enable discussion forum', 'buddypress' ); ?></label>
    118                         </div>
     114                        <?php if ( bp_forums_is_installed_correctly() ) : ?>
     115
     116                            <p><?php _e( 'Should this group have a forum?', 'buddypress' ); ?></p>
     117
     118                            <div class="checkbox">
     119                                <label><input type="checkbox" name="group-show-forum" id="group-show-forum" value="1"<?php checked( bp_get_new_group_enable_forum(), true, true ); ?> /> <?php _e( 'Enable discussion forum', 'buddypress' ); ?></label>
     120                            </div>
     121                        <?php elseif ( is_super_admin() ) : ?>
     122
     123                            <p><?php printf( __( '<strong>Attention Site Admin:</strong> Group forums require the <a href="%s">correct setup and configuration</a> of a bbPress installation.', 'buddypress' ), bp_core_do_network_admin() ? network_admin_url( 'settings.php?page=bb-forums-setup' ) :  admin_url( 'admin.php?page=bb-forums-setup' ) ); ?></p>
     124
     125                        <?php endif; ?>
    119126
    120127                    <?php endif; ?>
Note: See TracChangeset for help on using the changeset viewer.