Changeset 5885 for trunk/bp-forums/bp-forums-admin.php
- Timestamp:
- 03/05/2012 06:17:43 AM (14 years ago)
- File:
-
- 1 edited
-
trunk/bp-forums/bp-forums-admin.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-forums/bp-forums-admin.php
r5749 r5885 1 1 <?php 2 2 3 // Exit if accessed directly 3 4 if ( !defined( 'ABSPATH' ) ) exit; 4 5 6 /** UI ************************************************************************/ 7 5 8 function bp_forums_add_admin_menu() { 6 9 7 10 if ( ! bp_current_user_can( 'bp_moderate' ) ) 11 return; 12 13 if ( ! bp_forums_is_repair() ) 8 14 return; 9 15 … … 18 24 19 25 function bp_forums_bbpress_admin() { 20 21 $action = bp_get_admin_url( 'admin.php?page=bb-forums-setup&reinstall=1' ); ?> 26 ?> 22 27 23 28 <div class="wrap"> 29 24 30 <?php screen_icon( 'buddypress' ); ?> 25 31 26 32 <h2 class="nav-tab-wrapper"><?php bp_core_admin_tabs( __( 'Forums', 'buddypress' ) ); ?></h2> 27 33 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> 32 42 </div> 33 43 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> 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> 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 158 47 add_thickbox(); 159 48 wp_enqueue_script( 'plugin-install' ); … … 161 50 ?> 162 51 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> 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> 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> 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 ********************************************************************/ 125 126 function bp_forums_bbpress_install( $location = '' ) { 228 127 global $wpdb, $bp; 229 128 230 check_admin_referer( 'bp_forums_new_install_init' ); 129 if ( empty( $location ) ) 130 $location = ABSPATH . 'bb-config.php'; 231 131 232 132 // Create the bb-config.php file 233 133 $initial_write = bp_forums_bbpress_write( 234 134 BP_PLUGIN_DIR . '/bp-forums/bbpress/bb-config-sample.php', 235 ABSPATH . 'bb-config.php',135 $location, 236 136 array( 237 137 "define( 'BBDB_NAME'," => array( "'bbpress'", "'" . DB_NAME . "'" ), … … 251 151 252 152 // 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 else153 if ( $initial_write == 1 ) { 154 $file = file_get_contents( $location ); 155 } else { 256 156 $file = &$initial_write; 157 } 257 158 258 159 $file = trim( $file ); 259 if ( '?>' == substr( $file, -2, 2 ) ) 160 if ( '?>' == substr( $file, -2, 2 ) ) { 260 161 $file = substr( $file, 0, -2 ); 162 } 261 163 262 164 $file .= "\n" . '$bb->custom_user_table = \'' . $wpdb->users . '\';'; … … 265 167 $file .= "\n" . '$bb->name = \'' . get_blog_option( bp_get_root_blog_id(), 'blogname' ) . ' ' . __( 'Forums', 'buddypress' ) . '\';'; 266 168 267 if ( is_multisite() ) 169 if ( is_multisite() ) { 268 170 $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' ) ) { 271 174 $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' ) ) { 274 178 $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' ) ) { 277 182 $file .= "\n" . 'define(\'BB_SECURE_AUTH_SALT\', \'' . addslashes( SECURE_AUTH_SALT ) . '\');'; 183 } 278 184 279 185 $file .= "\n\n" . 'define(\'WP_AUTH_COOKIE_VERSION\', 2);'; … … 281 187 282 188 if ( $initial_write == 1 ) { 283 $file_handle = fopen( ABSPATH . 'bb-config.php', 'w' );189 $file_handle = fopen( $location, 'w' ); 284 190 fwrite( $file_handle, $file ); 285 191 fclose( $file_handle ); … … 288 194 } 289 195 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; 292 199 } 293 200 294 201 function bp_forums_bbpress_write( $file_source, $file_target, $alterations ) { 295 202 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 ) ) { 297 204 return -1; 298 299 if ( !$file_target ) 205 } 206 207 if ( empty( $file_target ) ) { 300 208 $file_target = $file_source; 301 302 if ( !$alterations || !is_array( $alterations ) ) 209 } 210 211 if ( empty( $alterations ) || !is_array( $alterations ) ) { 303 212 return -2; 213 } 304 214 305 215 // Get the existing lines in the file … … 336 246 } 337 247 338 if ( empty( $writable ) ) 248 if ( empty( $writable ) ) { 339 249 return trim( join( null, $modified_lines ) ); 250 } 340 251 341 252 // Open the file for writing - rewrites the whole file
Note: See TracChangeset
for help on using the changeset viewer.