BB_Install

BbPress Installation class.

Defined (1)

The class is defined in the following location(s).

/bp-forums/bbpress/bb-admin/includes/class.bb-install.php  
  1. class BB_Install 
  2. /** 
  3. * The file where the class was instantiated 
  4. * @var string 
  5. */ 
  6. var $caller; 
  7.  
  8. /** 
  9. * Whether or not we need to load some of the includes normally loaded by bb-settings.php 
  10. * @var boolean 
  11. */ 
  12. var $load_includes = false; 
  13.  
  14. /** 
  15. * An array of available languages to use in the installer 
  16. * @var array 
  17. */ 
  18. var $languages = array( 'en_US' => 'en_US' ); 
  19.  
  20. /** 
  21. * The currently selected language for the installer 
  22. * @var string 
  23. */ 
  24. var $language = 'en_US'; 
  25.  
  26. /** 
  27. * The current step in the install process 
  28. * @var integer 
  29. */ 
  30. var $step; 
  31.  
  32. /** 
  33. * Info about config files and their locations 
  34. * @var array 
  35. */ 
  36. var $configs = array( 
  37. 'writable' => false,  
  38. 'bb-config.php' => false,  
  39. 'config.php' => false 
  40. ); 
  41.  
  42. /** 
  43. * An array of the current status of each step 
  44. * @var array 
  45. */ 
  46. var $step_status = array( 
  47. 0 => 'incomplete',  
  48. 1 => 'incomplete',  
  49. 2 => 'incomplete',  
  50. 3 => 'incomplete',  
  51. 4 => 'incomplete' 
  52. ); 
  53.  
  54. /** 
  55. * An array of most strings in use, including errors 
  56. * @var array 
  57. */ 
  58. var $strings = array(); 
  59.  
  60. /** 
  61. * The data being manipulated as we go through the forms 
  62. * @var array 
  63. */ 
  64. var $data = array(); 
  65.  
  66. /** 
  67. * A boolean that can get flagged to stop posting of a form getting processed 
  68. * @var boolean 
  69. */ 
  70. var $stop_process = false; 
  71.  
  72. /** 
  73. * Keeps track of where the tabindex is up to 
  74. * @var integer 
  75. */ 
  76. var $tabindex = 0; 
  77.  
  78. /** 
  79. * Constructor 
  80. * Loads everything we might need to do the business 
  81. * @param string $caller The full path of the file that instantiated the class 
  82. * @return boolean Always returns true 
  83. */ 
  84. function __construct( $caller ) 
  85. $this->caller = $caller; 
  86.  
  87. $this->set_initial_step(); 
  88. $this->define_paths(); 
  89.  
  90. // We need to load these when bb-settings.php isn't loaded 
  91. if ( $this->load_includes ) { 
  92. require_once( BACKPRESS_PATH . 'functions.core.php' ); 
  93. require_once( BACKPRESS_PATH . 'functions.compat.php' ); 
  94. require_once( BACKPRESS_PATH . 'functions.formatting.php' ); 
  95. require_once( BACKPRESS_PATH . 'functions.plugin-api.php' ); 
  96. require_once( BACKPRESS_PATH . 'class.wp-error.php' ); 
  97. require_once( BB_PATH . BB_INC . 'functions.bb-core.php' ); 
  98. require_once( BB_PATH . BB_INC . 'functions.bb-meta.php' ); 
  99. require_once( BB_PATH . BB_INC . 'class.bp-options.php' ); 
  100. require_once( BACKPRESS_PATH . 'functions.bp-options.php' ); 
  101. require_once( BACKPRESS_PATH . 'functions.kses.php' ); 
  102. require_once( BB_PATH . BB_INC . 'functions.bb-l10n.php' ); 
  103. require_once( BB_PATH . BB_INC . 'functions.bb-template.php' ); 
  104.  
  105. $this->get_languages(); 
  106. $this->set_language(); 
  107.  
  108. if ( $this->language ) { 
  109. global $locale; 
  110. global $l10n; 
  111. $locale = $this->language; 
  112. unset( $l10n['default'] ); 
  113.  
  114. if ( !class_exists( 'MO' ) ) { 
  115. require_once( BACKPRESS_PATH . 'pomo/mo.php' ); 
  116.  
  117. // Load the default text localization domain. Doing this twice doesn't hurt too much. 
  118. bb_load_default_textdomain(); 
  119.  
  120. // Pull in locale data after loading text domain. 
  121. if ( $this->load_includes ) { 
  122. require_once( BB_PATH . BB_INC . 'class.bb-locale.php' ); 
  123. global $bb_locale; 
  124. $bb_locale = new BB_Locale(); 
  125.  
  126. $this->prepare_strings(); 
  127. $this->check_prerequisites(); 
  128. $this->check_configs(); 
  129.  
  130. if ( $this->step > -1 ) { 
  131. $this->set_step(); 
  132. $this->prepare_data(); 
  133. $this->process_form(); 
  134.  
  135. return true; 
  136.  
  137. function BB_Install( $caller ) { 
  138. $this->__construct( $caller ); 
  139.  
  140. /** 
  141. * Set initial step 
  142. * Sets the step from the post data and keeps it within range 
  143. * @return integer The calculated step 
  144. */ 
  145. function set_initial_step() 
  146. // Set the step based on the $_POST value or 0 
  147. $this->step = $_POST['step'] ? (integer) $_POST['step'] : 0; 
  148.  
  149. // Make sure the requested step is from 0-4 
  150. if ( 0 > $this->step || 4 < $this->step ) { 
  151. $this->step = 0; 
  152. return $this->step; 
  153.  
  154. /** 
  155. * Prepare text strings 
  156. * Sets up many of the strings to be used by the class that may 
  157. * be later subject to change due to processing of the forms 
  158. */ 
  159. function prepare_strings() 
  160. $this->strings = array( 
  161. -1 => array( 
  162. 'title' => __( 'bbPress › Error' ),  
  163. 'h1' => __( 'Oh dear!' ),  
  164. 'messages' => array() 
  165. ),  
  166. 0 => array( 
  167. 'title' => sprintf( __( '%1$s › %2$s' ), __( 'bbPress installer' ), __( 'Welcome' ) ),  
  168. 'h2' => __( 'Welcome to the bbPress installer' ),  
  169. 'status' => '',  
  170. 'messages' => array(),  
  171. 'intro' => array( 
  172. __( 'We\'re now going to go through a few steps to get you up and running.' ),  
  173. __( 'Ready? Then let\'s get started!' ) 
  174. ),  
  175. 1 => array( 
  176. 'title' => sprintf( __( '%1$s › %2$s' ), __( 'bbPress installer' ), __( 'Step 1' ) ),  
  177. 'h2' => sprintf( __( '%1$s - %2$s' ), __( 'Step 1' ), __( 'Database configuration' ) ),  
  178. 'status' => '',  
  179. 'intro' => array( 
  180. __( 'In this step you need to enter your database connection details. The installer will attempt to create a file called <code>bb-config.php</code> in the root directory of your bbPress installation.' ),  
  181. __( 'If you\'re not sure what to put here, contact your web hosting provider.' ) 
  182. ),  
  183. 'messages' => array() 
  184. ),  
  185. 2 => array( 
  186. 'title' => sprintf( __( '%1$s › %2$s' ), __( 'bbPress installer' ), __( 'Step 2' ) ),  
  187. 'h2' => sprintf( __( '%1$s - %2$s' ), __( 'Step 2' ), __( 'WordPress integration (optional)' ) ),  
  188. 'status' => __( '« skipped' ),  
  189. 'intro' => array( 
  190. __( 'bbPress can integrate login and user data seamlessly with WordPress. You can safely skip this step if you do not wish to integrate with an existing WordPress install.' ) 
  191. ),  
  192. 'messages' => array(),  
  193. 'form_errors' => array() 
  194. ),  
  195. 3 => array( 
  196. 'title' => sprintf( __( '%1$s › %2$s' ), __( 'bbPress installer' ), __( 'Step 3' ) ),  
  197. 'h2' => sprintf( __( '%1$s - %2$s' ), __( 'Step 3' ), __( 'Site settings' ) ),  
  198. 'status' => '',  
  199. 'intro' => array( 
  200. __( 'Finalize your installation by adding a name, your first user and your first forum.' ) 
  201. ),  
  202. 'messages' => array(),  
  203. 'form_errors' => array(),  
  204. 'scripts' => array() 
  205. ),  
  206. 4 => array( 
  207. 'title' => sprintf( __( '%1$s › %2$s' ), __( 'bbPress installer' ), __( 'Finished' ) ),  
  208. 'h2' => __( 'Installation complete!' ),  
  209. 'messages' => array() 
  210. ); 
  211.  
  212. /** 
  213. * Check installation pre-requisites 
  214. * Checks for appropriate PHP extensions. 
  215. * @return boolean False if any pre-requisites are not met, otherwise true 
  216. */ 
  217. function check_prerequisites() 
  218. // BPDB wants the MySQL extension - this is also checked when BPDB is initialised so may be a bit redundant here 
  219. if ( !extension_loaded( 'mysql' ) ) { 
  220. $this->strings[-1]['messages']['error'][] = __( 'Your PHP installation appears to be missing the MySQL extension which is required for bbPress' ); 
  221. $this->step = -1; 
  222.  
  223. if ( defined( 'BB_IS_WP_LOADED' ) && BB_IS_WP_LOADED ) { 
  224. $this->strings[-1]['messages']['error'][] = __( 'Please complete your installation before attempting to include WordPress within bbPress' ); 
  225. $this->step = -1; 
  226.  
  227. if ( $this->step === -1 ) { 
  228. return false; 
  229.  
  230. return true; 
  231.  
  232. /** 
  233. * Define path constants 
  234. * Sets some bbPress constants if they are not otherwise available based 
  235. * on the classes initiating file path. 
  236. * @return boolean False if no path was supplied, otherwise always true 
  237. */ 
  238. function define_paths() 
  239. if ( !$this->caller ) { 
  240. return false; 
  241.  
  242. if ( !defined( 'BACKPRESS_PATH' ) ) { 
  243. // Define BACKPRESS_PATH 
  244. // Tell us to load includes because bb-settings.php was not loaded 
  245. // bb-settings.php is generally not loaded on steps -1, 0 and 1 but 
  246. // there are exceptions, so this is safer than just reading the step 
  247. $this->load_includes = true; 
  248. define( 'BACKPRESS_PATH', BB_PATH . BB_INC . 'backpress/' ); 
  249.  
  250. // Define the language file directory 
  251. if ( !defined( 'BB_LANG_DIR' ) ) { 
  252. define( 'BB_LANG_DIR', BB_PATH . 'my-languages/' ); 
  253.  
  254. return true; 
  255.  
  256. /** 
  257. * Gets an array of available languages form the language directory 
  258. * @return array 
  259. */ 
  260. function get_languages() 
  261. foreach ( bb_glob( BB_LANG_DIR . '*.mo' ) as $language ) { 
  262. if ( substr( $language, 0, 18 ) === 'continents-cities-' ) { 
  263. continue; 
  264. $language = str_replace( '.mo', '', basename( $language ) ); 
  265. $this->languages[$language] = $language; 
  266.  
  267. return $this->languages; 
  268.  
  269. /** 
  270. * Returns a language selector for switching installation languages 
  271. * @return string|false Either the html for the selector or false if there are no languages 
  272. */ 
  273. function get_language_selector() 
  274. // Don't provide a selection if there is only english 
  275. if ( 2 > count( $this->languages ) ) { 
  276. return false; 
  277.  
  278. $r = '<script type="text/javascript" charset="utf-8">' . "\n"; 
  279. $r .= "\t" . 'function changeLanguage(selectObj) {' . "\n"; 
  280. $r .= "\t\t" . 'var selectedLanguage = selectObj.options[selectObj.selectedIndex].value;' . "\n"; 
  281. $r .= "\t\t" . 'location.href = "install.php?language=" + selectedLanguage;' . "\n"; 
  282. $r .= "\t" . '}' . "\n"; 
  283. $r .= '</script>' . "\n"; 
  284. //$r .= '<form id="lang" action="install.php">' . "\n"; 
  285. $r .= "\t" . '<fieldset>' . "\n"; 
  286. $r .= "\t\t" . '<label class="has-note has-label for-select">' . "\n"; 
  287. $r .= "\t\t\t" . '<span>' . __( 'Installation language' ) . '</span>' . "\n"; 
  288. $this->tabindex++; 
  289. $r .= "\t\t\t" . '<select class="has-note" onchange="changeLanguage(this);" name="language" tabindex="' . $this->tabindex . '">' . "\n"; 
  290. foreach ( $this->languages as $language ) { 
  291. $selected = ''; 
  292. if ( $language == $this->language ) { 
  293. $selected = ' selected="selected"'; 
  294. $r .= "\t\t\t\t" . '<option value="' . $language . '"' . $selected . '>' . $language . '</option>' . "\n"; 
  295. $r .= "\t\t\t" . '</select>' . "\n"; 
  296. $r .= "\t\t\t" . '<a class="note-toggle" href="javascript:void(0);" onclick="toggleNote(\'note-language\');">?</a>' . "\n"; 
  297. $r .= "\t\t\t" . '<p id="note-language" class="note" style="display:none">' . __( 'Sets the language to be used during the installation process only.' ) . '</p>' . "\n"; 
  298. $r .= "\t\t\t" . '<div class="clear"></div>' . "\n"; 
  299. $r .= "\t\t" . '</label>' . "\n"; 
  300. $r .= "\t" . '</fieldset>' . "\n"; 
  301. //$r .= '</form>' . "\n"; 
  302.  
  303. echo $r; 
  304.  
  305. /** 
  306. * Sets the current installation language 
  307. * @return string The currently set language 
  308. */ 
  309. function set_language() 
  310. if ( isset( $_COOKIE['bb_install_language'] ) && 1 < count( $this->languages ) ) { 
  311. if ( in_array( $_COOKIE['bb_install_language'], $this->languages ) ) { 
  312. $this->language = $_COOKIE['bb_install_language']; 
  313.  
  314. $language_requested = false; 
  315. if ( isset( $_POST['language'] ) && $_POST['language'] ) { 
  316. $language_requested = (string) $_POST['language']; 
  317. } elseif ( isset( $_GET['language'] ) && $_GET['language'] ) { 
  318. $language_requested = (string) $_GET['language']; 
  319.  
  320. if ( $language_requested && 1 < count( $this->languages ) ) { 
  321. if ( in_array( $language_requested, $this->languages ) ) { 
  322. $this->language = $language_requested; 
  323. setcookie( 'bb_install_language', $this->language ); 
  324.  
  325. if ( !$this->language || 'en_US' === $this->language ) { 
  326. $this->language = 'en_US'; 
  327. setcookie( 'bb_install_language', ' ', time() - 31536000 ); 
  328.  
  329. return $this->language; 
  330.  
  331. /** 
  332. * Tests whether database tables exist 
  333. * Checks for the existence of the forum table in the database that is 
  334. * currently configured. 
  335. * @return boolean False if the table isn't found, otherwise true 
  336. */ 
  337. function database_tables_are_installed() 
  338. global $bbdb; 
  339. $bbdb->suppress_errors(); 
  340. $installed = (boolean) $bbdb->get_results( 'DESCRIBE `' . $bbdb->forums . '`;', ARRAY_A ); 
  341. $bbdb->suppress_errors( false ); 
  342. return $installed; 
  343.  
  344. /** 
  345. * Tests whether an option is set in the database 
  346. * @return boolean False if the option isn't set, otherwise true 
  347. */ 
  348. function bb_options_are_set() 
  349. if ( $this->load_includes ) { 
  350. return false; 
  351. if ( !bb_get_option( 'uri' ) ) { 
  352. return false; 
  353. return true; 
  354.  
  355. /** 
  356. * Tests whether bbPress is installed 
  357. * @return boolean False if bbPress isn't installed, otherwise true 
  358. */ 
  359. function is_installed() 
  360. if ( !$this->database_tables_are_installed() ) { 
  361. return false; 
  362. if ( !$this->bb_options_are_set() ) { 
  363. return false; 
  364. return true; 
  365.  
  366. /** 
  367. * Checks for configs and sets variables describing current install state 
  368. * @return integer The current step we should be on based on the existence of the config file 
  369. */ 
  370. function check_configs() 
  371. // Check for a config file 
  372. if ( file_exists( BB_PATH . 'bb-config.php' ) ) { 
  373. $this->configs['bb-config.php'] = BB_PATH . 'bb-config.php'; 
  374. } elseif ( file_exists( dirname( BB_PATH ) . '/bb-config.php' ) ) { 
  375. $this->configs['bb-config.php'] = dirname( BB_PATH ) . '/bb-config.php'; 
  376.  
  377. // Check for an old config file 
  378. if ( file_exists( BB_PATH . 'config.php' ) ) { 
  379. $this->configs['config.php'] = BB_PATH . 'config.php'; 
  380. } elseif ( file_exists( dirname( BB_PATH ) . '/config.php' ) ) { 
  381. $this->configs['config.php'] = dirname( BB_PATH ) . '/config.php'; 
  382.  
  383. if ( $this->configs['config.php'] && !$this->configs['bb-config.php'] ) { 
  384. // There is an old school config file 
  385. // Step -1 is where we send fatal errors from any screen 
  386. $this->strings[-1]['messages']['error'][] = __( 'An old <code>config.php</code> file has been detected in your installation. You should remove it and run the <a href="install.php">installer</a> again. You can use the same database connection details if you do.' ); 
  387. $this->step = -1; 
  388. return $this->step; 
  389.  
  390. // Check if bbPress is already installed 
  391. // Is there a current config file 
  392. if ( $this->configs['bb-config.php'] ) { 
  393.  
  394. // Is it valid 
  395. if ( $this->validate_current_config() ) { 
  396. // Step 1 is complete 
  397. $this->step_status[1] = 'complete'; 
  398. $this->strings[1]['status'] = __( '« completed' ); 
  399.  
  400. // On step 1 we want to report that the file is good and allow the user to continue 
  401. if ( $this->step === 1 ) { 
  402. // Stop form processing if it is posted 
  403. $this->stop_process = true; 
  404.  
  405. // Display a nice message saying the config file exists 
  406. $this->strings[1]['messages']['message'][] = __( 'A valid configuration file was found at <code>bb-config.php</code><br />You may continue to the next step.' ); 
  407. return $this->step; 
  408. } else { 
  409. // Invalid config files on any step cause us to exit to step 0 
  410. $this->strings[-1]['messages']['error'][] = __( 'An invalid configuration file was found at <code>bb-config.php</code><br />The installation cannot continue.' ); 
  411. $this->strings[-1]['messages'][0][] = __( 'Usually this is caused by one of the database connection settings being incorrect. Make sure that the specified user has appropriate permission to access the database.' ); 
  412. $this->step = -1; 
  413.  
  414. // If we have made it this far, then we can check if the database tables exist and have content 
  415. if ( $this->is_installed() ) { 
  416. // The database is installed 
  417. // The following standard functions should be available 
  418. if ( bb_get_option( 'bb_db_version' ) > bb_get_option_from_db( 'bb_db_version' ) ) { 
  419. // The database needs upgrading 
  420. $this->strings[-1]['messages'][0][] = __( 'bbPress is already installed, but appears to require an upgrade.' ); 
  421. } else { 
  422. $this->strings[-1]['messages'][0][] = __( 'bbPress is already installed.' ); 
  423. $this->strings[-1]['messages'][0][] = sprintf( 
  424. __( 'Perhaps you meant to run the <a href="%s">upgrade script</a> instead?' ),  
  425. bb_get_uri( 'bb-admin/upgrade.php', null, BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN ) 
  426. ); 
  427. $this->step = -1; 
  428.  
  429. } else { 
  430.  
  431. if ( 2 > $this->step && !file_exists( BB_PATH . 'bb-config-sample.php' ) ) { 
  432. // There is no sample config file 
  433. $this->strings[0]['messages']['error'][] = __( 'I could not find the file <code>bb-config-sample.php</code><br />Please upload it to the root directory of your bbPress installation.' ); 
  434. $this->step = 0; 
  435.  
  436. if ( 1 !== $this->step ) { 
  437. // There is no config file, go back to the beginning 
  438. $this->strings[0]['messages']['message'][] = __( 'There doesn\'t seem to be a <code>bb-config.php</code> file. This usually means that you want to install bbPress.' ); 
  439. $this->step = 0; 
  440.  
  441.  
  442. // Check if the config file path is writable 
  443. if ( file_exists( $this->configs['bb-config.php'] ) ) { 
  444. if ( is_writable( $this->configs['bb-config.php'] ) ) { 
  445. $this->configs['writable'] = true; 
  446. } elseif ( is_writable( BB_PATH ) ) { 
  447. $this->configs['writable'] = true; 
  448.  
  449. return $this->step; 
  450.  
  451. /** 
  452. * Determines if the current config is valid 
  453. * @return boolean False if the config is bad, otherwise true 
  454. */ 
  455. function validate_current_config() 
  456. // If we are validating then the config file has already been included 
  457. // So we can just check for valid constants 
  458.  
  459. // The required constants for a valid config file 
  460. $required_constants = array( 
  461. 'BBDB_NAME',  
  462. 'BBDB_USER',  
  463. 'BBDB_PASSWORD',  
  464. 'BBDB_HOST' 
  465. ); 
  466.  
  467. // Check the required constants are defined 
  468. foreach ( $required_constants as $required_constant ) { 
  469. if ( !defined( $required_constant ) ) { 
  470. return false; 
  471.  
  472. global $bb_table_prefix; 
  473.  
  474. if ( !isset( $bb_table_prefix ) ) { 
  475. return false; 
  476.  
  477. // Everthing is OK so far, validate the connection as well 
  478. return $this->validate_current_database(); 
  479.  
  480. /** 
  481. * Validates the current database settings 
  482. * @return boolean False if the current database isn't valid, otherwise true 
  483. */ 
  484. function validate_current_database() 
  485. global $bbdb; 
  486. $db = $bbdb->db_connect( "SELECT * FROM $bbdb->forums LIMIT 1" ); 
  487.  
  488. if ( !is_resource( $db ) ) { 
  489. return false; 
  490.  
  491. return true; 
  492.  
  493. /** 
  494. * Sets up default values for input data as well as labels and notes 
  495. * @return void 
  496. */ 
  497. function prepare_data() 
  498. /** 
  499. * Should be exactly the same as the default value of the KEYS in bb-config-sample.php 
  500. * @since 1.0 
  501. */ 
  502. $_bb_default_secret_key = 'put your unique phrase here'; 
  503.  
  504. $this->data = array( 
  505. 0 => array( 
  506. 'form' => array( 
  507. 'forward_0_0' => array( 
  508. 'value' => __( 'Go to step 1' ) 
  509. ),  
  510. 1 => array( 
  511. 'form' => array( 
  512. 'bbdb_name' => array( 
  513. 'value' => '',  
  514. 'label' => __( 'Database name' ),  
  515. 'note' => __( 'The name of the database in which you want to run bbPress.' ) 
  516. ),  
  517. 'bbdb_user' => array( 
  518. 'value' => '',  
  519. 'label' => __( 'Database user' ),  
  520. 'note' => __( 'The database user that has access to that database.' ),  
  521. 'autocomplete' => 'off' 
  522. ),  
  523. 'bbdb_password' => array( 
  524. 'type' => 'password',  
  525. 'value' => '',  
  526. 'label' => __( 'Database password' ),  
  527. 'note' => __( 'That database user\'s password.' ),  
  528. 'autocomplete' => 'off' 
  529. ),  
  530. 'bb_lang' => array( 
  531. 'value' => '',  
  532. 'label' => __( 'Language' ),  
  533. 'note' => sprintf( __( 'The language which bbPress will be presented in once installed. Your current installer language choice (%s) will be the same for the rest of the install process.' ), $this->language ) 
  534. ),  
  535. 'toggle_1' => array( 
  536. 'value' => 0,  
  537. 'label' => __( 'Show advanced settings' ),  
  538. 'note' => __( 'These settings usually do not have to be changed.' ),  
  539. 'checked' => '',  
  540. 'display' => 'none' 
  541. ),  
  542. 'bbdb_host' => array( 
  543. 'value' => 'localhost',  
  544. 'label' => __( 'Database host' ),  
  545. 'note' => __( 'The domain name or IP address of the server where the database is located. If the database is on the same server as the web site, then this probably should remain <strong>localhost</strong>.' ),  
  546. 'prerequisite' => 'toggle_1' 
  547. ),  
  548. 'bbdb_charset' => array( 
  549. 'value' => 'utf8',  
  550. 'label' => __( 'Database character set' ),  
  551. 'note' => __( 'The best choice is <strong>utf8</strong>, but you will need to match the character set which you created the database with.' ),  
  552. 'prerequisite' => 'toggle_1' 
  553. ),  
  554. 'bbdb_collate' => array( 
  555. 'value' => '',  
  556. 'label' => __( 'Database character collation' ),  
  557. 'note' => __( 'The character collation value set when the database was created.' ),  
  558. 'prerequisite' => 'toggle_1' 
  559. ),  
  560. /** 
  561. 'bb_auth_key' => array( 
  562. 'value' => $_bb_default_secret_key,  
  563. 'label' => __( 'bbPress "auth" cookie key' ),  
  564. 'note' => __( 'This should be a unique and secret phrase, it will be used to make your bbPress "auth" cookie unique and harder for an attacker to decipher.' ),  
  565. 'prerequisite' => 'toggle_1' 
  566. ),  
  567. 'bb_secure_auth_key' => array( 
  568. 'value' => $_bb_default_secret_key,  
  569. 'label' => __( 'bbPress "secure auth" cookie key' ),  
  570. 'note' => __( 'This should be a unique and secret phrase, it will be used to make your bbPress "secure auth" cookie unique and harder for an attacker to decipher.' ),  
  571. 'prerequisite' => 'toggle_1' 
  572. ),  
  573. 'bb_logged_in_key' => array( 
  574. 'value' => $_bb_default_secret_key,  
  575. 'label' => __( 'bbPress "logged in" cookie key' ),  
  576. 'note' => __( 'This should be a unique and secret phrase, it will be used to make your bbPress "logged in" cookie unique and harder for an attacker to decipher.' ),  
  577. 'prerequisite' => 'toggle_1' 
  578. ),  
  579. 'bb_nonce_key' => array( 
  580. 'value' => $_bb_default_secret_key,  
  581. 'label' => __( 'bbPress "nonce" key' ),  
  582. 'note' => __( 'This should be a unique and secret phrase, it will be used to make form submission harder for an attacker to spoof.' ),  
  583. 'prerequisite' => 'toggle_1' 
  584. ),  
  585. */ 
  586. 'bb_table_prefix' => array( 
  587. 'value' => 'bb_',  
  588. 'label' => __( 'Table name prefix' ),  
  589. 'note' => __( 'If you are running multiple bbPress sites in a single database, you will probably want to change this.' ),  
  590. 'prerequisite' => 'toggle_1' 
  591. ),  
  592. 'config' => array( 
  593. 'value' => '',  
  594. 'label' => __( 'Contents for <code>bb-config.php</code>' ),  
  595. 'note' => __( 'Once you have created the configuration file, you can check for it below.' ) 
  596. ),  
  597. 'forward_1_0' => array( 
  598. 'value' => __( 'Save database configuration file' ) 
  599. ),  
  600. 'back_1_1' => array( 
  601. 'value' => __( '« Go back' ) 
  602. ),  
  603. 'forward_1_1' => array( 
  604. 'value' => __( 'Check for configuration file' ) 
  605. ),  
  606. 'forward_1_2' => array( 
  607. 'value' => __( 'Go to step 2' ) 
  608. ),  
  609.  
  610. 2 => array( 
  611. 'form' => array( 
  612. 'toggle_2_0' => array( 
  613. 'value' => 0,  
  614. 'label' => __( 'Add integration settings' ),  
  615. 'note' => __( 'If you want to integrate bbPress with an existing WordPress site.' ),  
  616. 'checked' => '',  
  617. 'display' => 'none',  
  618. 'toggle_value' => array( 
  619. 'target' => 'forward_2_0',  
  620. 'off_value' => __( 'Skip WordPress integration' ),  
  621. 'on_value' => __( 'Save WordPress integration settings' ) 
  622. ),  
  623. 'toggle_2_1' => array( 
  624. 'value' => 0,  
  625. 'label' => __( 'Add cookie integration settings' ),  
  626. 'note' => __( 'If you want to allow shared logins with an existing WordPress site.' ),  
  627. 'checked' => '',  
  628. 'display' => 'none',  
  629. 'prerequisite' => 'toggle_2_0' 
  630. ),  
  631. 'wp_siteurl' => array( 
  632. 'value' => '',  
  633. 'label' => __( 'WordPress address (URL)' ),  
  634. 'note' => __( 'This value should exactly match the <strong>WordPress address (URL)</strong> setting in your WordPress general settings.' ),  
  635. 'prerequisite' => 'toggle_2_1' 
  636. ),  
  637. 'wp_home' => array( 
  638. 'value' => '',  
  639. 'label' => __( 'Blog address (URL)' ),  
  640. 'note' => __( 'This value should exactly match the <strong>Blog address (URL)</strong> setting in your WordPress general settings.' ),  
  641. 'prerequisite' => 'toggle_2_1' 
  642. ),  
  643. 'wp_auth_key' => array( 
  644. 'value' => '',  
  645. 'label' => __( 'WordPress "auth" cookie key' ),  
  646. 'note' => __( 'This value must match the value of the constant named "AUTH_KEY" in your WordPress <code>wp-config.php</code> file. This will replace the bbPress "auth" cookie key set in the first step.' ),  
  647. 'prerequisite' => 'toggle_2_1',  
  648. 'autocomplete' => 'off' 
  649. ),  
  650. 'wp_auth_salt' => array( 
  651. 'value' => '',  
  652. 'label' => __( 'WordPress "auth" cookie salt' ),  
  653. 'note' => __( 'This must match the value of the WordPress setting named "auth_salt" in your WordPress site. Look for the option labeled "auth_salt" in <a href="#" id="getAuthSaltOption" onclick="window.open(this.href); return false;">this WordPress admin page</a>. If you leave this blank the installer will try to fetch the value based on your WordPress database integration settings.' ),  
  654. 'prerequisite' => 'toggle_2_1',  
  655. 'autocomplete' => 'off' 
  656. ),  
  657. 'wp_secure_auth_key' => array( 
  658. 'value' => '',  
  659. 'label' => __( 'WordPress "secure auth" cookie key' ),  
  660. 'note' => __( 'This value must match the value of the constant named "SECURE_AUTH_KEY" in your WordPress <code>wp-config.php</code> file. This will replace the bbPress "secure auth" cookie key set in the first step.' ),  
  661. 'prerequisite' => 'toggle_2_1',  
  662. 'autocomplete' => 'off' 
  663. ),  
  664. 'wp_secure_auth_salt' => array( 
  665. 'value' => '',  
  666. 'label' => __( 'WordPress "secure auth" cookie salt' ),  
  667. 'note' => __( 'This must match the value of the WordPress setting named "secure_auth_salt" in your WordPress site. Look for the option labeled "secure_auth_salt" in <a href="#" id="getSecureAuthSaltOption" onclick="window.open(this.href); return false;">this WordPress admin page</a>. If you leave this blank the installer will try to fetch the value based on your WordPress database integration settings. Sometimes this value is not set in WordPress, in that case you can leave this setting blank as well.' ),  
  668. 'prerequisite' => 'toggle_2_1',  
  669. 'autocomplete' => 'off' 
  670. ),  
  671. 'wp_logged_in_key' => array( 
  672. 'value' => '',  
  673. 'label' => __( 'WordPress "logged in" cookie key' ),  
  674. 'note' => __( 'This value must match the value of the constant named "LOGGED_IN_KEY" in your WordPress <code>wp-config.php</code> file. This will replace the bbPress "logged in" cookie key set in the first step.' ),  
  675. 'prerequisite' => 'toggle_2_1',  
  676. 'autocomplete' => 'off' 
  677. ),  
  678. 'wp_logged_in_salt' => array( 
  679. 'value' => '',  
  680. 'label' => __( 'WordPress "logged in" cookie salt' ),  
  681. 'note' => __( 'This must match the value of the WordPress setting named "logged_in_salt" in your WordPress site. Look for the option labeled "logged_in_salt" in <a href="#" id="getLoggedInSaltOption" onclick="window.open(this.href); return false;">this WordPress admin page</a>. If you leave this blank the installer will try to fetch the value based on your WordPress database integration settings.' ),  
  682. 'prerequisite' => 'toggle_2_1',  
  683. 'autocomplete' => 'off' 
  684. ),  
  685. 'toggle_2_2' => array( 
  686. 'value' => 0,  
  687. 'label' => __( 'Add user database integration settings' ),  
  688. 'note' => __( 'If you want to share user data with an existing WordPress site.' ),  
  689. 'checked' => '',  
  690. 'display' => 'none',  
  691. 'prerequisite' => 'toggle_2_0' 
  692. ),  
  693. 'wp_table_prefix' => array( 
  694. 'value' => 'wp_',  
  695. 'default_value' => '', // Used when setting is ignored 
  696. 'label' => __( 'User database table prefix' ),  
  697. 'note' => __( 'If your bbPress and WordPress sites share the same database, then this is the same value as <code>$table_prefix</code> in your WordPress <code>wp-config.php</code> file. It is usually <strong>wp_</strong>.' ),  
  698. 'prerequisite' => 'toggle_2_2' 
  699. ),  
  700. 'wordpress_mu_primary_blog_id' => array( 
  701. 'value' => '',  
  702. 'default_value' => '',  
  703. 'label' => __( 'WordPress MU primary blog ID' ),  
  704. 'note' => __( 'If you are integrating with a WordPress MU site you need to specify the primary blog ID for that site. It is usually <strong>1</strong>. You should probably leave this blank if you are integrating with a standard WordPress site' ),  
  705. 'prerequisite' => 'toggle_2_2' 
  706. ),  
  707. 'toggle_2_3' => array( 
  708. 'value' => 0,  
  709. 'label' => __( 'Show advanced database settings' ),  
  710. 'note' => __( 'If your bbPress and WordPress site do not share the same database, then you will need to add advanced settings.' ),  
  711. 'checked' => '',  
  712. 'display' => 'none',  
  713. 'prerequisite' => 'toggle_2_2' 
  714. ),  
  715. 'user_bbdb_name' => array( 
  716. 'value' => '',  
  717. 'label' => __( 'User database name' ),  
  718. 'note' => __( 'The name of the database in which your user tables reside.' ),  
  719. 'prerequisite' => 'toggle_2_3' 
  720. ),  
  721. 'user_bbdb_user' => array( 
  722. 'value' => '',  
  723. 'label' => __( 'User database user' ),  
  724. 'note' => __( 'The database user that has access to that database.' ),  
  725. 'prerequisite' => 'toggle_2_3',  
  726. 'autocomplete' => 'off' 
  727. ),  
  728. 'user_bbdb_password' => array( 
  729. 'type' => 'password',  
  730. 'value' => '',  
  731. 'label' => __( 'User database password' ),  
  732. 'note' => __( 'That database user\'s password.' ),  
  733. 'prerequisite' => 'toggle_2_3',  
  734. 'autocomplete' => 'off' 
  735. ),  
  736. 'user_bbdb_host' => array( 
  737. 'value' => '',  
  738. 'label' => __( 'User database host' ),  
  739. 'note' => __( 'The domain name or IP address of the server where the database is located. If the database is on the same server as the web site, then this probably should be <strong>localhost</strong>.' ),  
  740. 'prerequisite' => 'toggle_2_3' 
  741. ),  
  742. 'user_bbdb_charset' => array( 
  743. 'value' => '',  
  744. 'label' => __( 'User database character set' ),  
  745. 'note' => __( 'The best choice is <strong>utf8</strong>, but you will need to match the character set which you created the database with.' ),  
  746. 'prerequisite' => 'toggle_2_3' 
  747. ),  
  748. 'user_bbdb_collate' => array( 
  749. 'value' => '',  
  750. 'label' => __( 'User database character collation' ),  
  751. 'note' => __( 'The character collation value set when the user database was created.' ),  
  752. 'prerequisite' => 'toggle_2_3' 
  753. ),  
  754. 'custom_user_table' => array( 
  755. 'value' => '',  
  756. 'label' => __( 'User database "user" table' ),  
  757. 'note' => __( 'The complete table name, including any prefix.' ),  
  758. 'prerequisite' => 'toggle_2_3' 
  759. ),  
  760. 'custom_user_meta_table' => array( 
  761. 'value' => '',  
  762. 'label' => __( 'User database "user meta" table' ),  
  763. 'note' => __( 'The complete table name, including any prefix.' ),  
  764. 'prerequisite' => 'toggle_2_3' 
  765. ),  
  766. 'forward_2_0' => array( 
  767. 'value' => __( 'Skip WordPress integration' ) 
  768. ),  
  769. 'back_2_1' => array( 
  770. 'value' => __( '« Go back' ) 
  771. ),  
  772. 'forward_2_1' => array( 
  773. 'value' => __( 'Go to step 3' ) 
  774. ),  
  775.  
  776. 3 => array( 
  777. 'form' => array( 
  778. 'name' => array( 
  779. 'value' => '',  
  780. 'label' => __( 'Site name' ),  
  781. 'note' => __( 'This is what you are going to call your bbPress site.' ) 
  782. ),  
  783. 'uri' => array( 
  784. 'value' => $this->guess_uri(),  
  785. 'label' => __( 'Site address (URL)' ),  
  786. 'note' => __( 'We have attempted to guess this; it\'s usually correct, but change it here if you wish.' ) 
  787. ),  
  788. 'keymaster_user_login' => array( 
  789. 'value' => '',  
  790. 'maxlength' => 60,  
  791. 'label' => __( '"Key Master" Username' ),  
  792. 'note' => __( 'This is the user login for the initial bbPress administrator (known as a "Key Master").' ),  
  793. 'autocomplete' => 'off' 
  794. ),  
  795. 'keymaster_user_email' => array( 
  796. 'value' => '',  
  797. 'maxlength' => 100,  
  798. 'label' => __( '"Key Master" Email address' ),  
  799. 'note' => __( 'The login details will be emailed to this address.' ),  
  800. 'autocomplete' => 'off' 
  801. ),  
  802. 'keymaster_user_type' => array( 
  803. 'value' => 'new' 
  804. ),  
  805. 'forum_name' => array( 
  806. 'value' => '',  
  807. 'maxlength' => 150,  
  808. 'label' => __( 'First forum name' ),  
  809. 'note' => __( 'This can be changed after installation, so don\'t worry about it too much.' ) 
  810. ),  
  811. 'forward_3_0' => array( 
  812. 'value' => __( 'Save site settings' ) 
  813. ),  
  814. 'back_3_1' => array( 
  815. 'value' => __( '« Go back' ) 
  816. ),  
  817. 'forward_3_1' => array( 
  818. 'value' => __( 'Complete the installation' ) 
  819. ),  
  820.  
  821. 4 => array( 
  822. 'form' => array( 
  823. 'toggle_4' => array( 
  824. 'value' => 0,  
  825. 'label' => __( 'Show installation messages' ) 
  826. ),  
  827. 'error_log' => array( 
  828. 'value' => '',  
  829. 'label' => __( 'Installation errors' ) 
  830. ),  
  831. 'installation_log' => array( 
  832. 'value' => '',  
  833. 'label' => __( 'Installation log' ) 
  834. ); 
  835.  
  836. /** 
  837. * Guesses the final installed URI based on the location of the install script 
  838. * @return string The guessed URI 
  839. */ 
  840. function guess_uri() 
  841. global $bb; 
  842.  
  843. if ( $bb->uri ) { 
  844. $uri = $bb->uri; 
  845. } else { 
  846. $schema = 'http://'; 
  847. if ( isset( $_SERVER['HTTPS'] ) && strtolower( $_SERVER['HTTPS'] ) == 'on' ) { 
  848. $schema = 'https://'; 
  849. $uri = preg_replace( '|/bb-admin/.*|i', '/', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); 
  850.  
  851. return rtrim( $uri, " \t\n\r\0\x0B/" ) . '/'; 
  852.  
  853. /** 
  854. * Writes the given alterations to file 
  855. * @param $file_source string The full path to the file to be read from 
  856. * @param $file_target string The full path to the file to be written to 
  857. * @param $alterations array An array of arrays containing alterations to be made 
  858. * @return void 
  859. */ 
  860. function write_lines_to_file( $file_source, $file_target, $alterations ) 
  861. if ( !$file_source || !file_exists( $file_source ) || !is_file( $file_source ) ) { 
  862. return -1; 
  863.  
  864. if ( !$file_target ) { 
  865. $file_target = $file_source; 
  866.  
  867. if ( !$alterations || !is_array( $alterations ) ) { 
  868. return -2; 
  869.  
  870. /** 
  871. Alterations array takes the form 
  872. array( 
  873. '1st 20 chars of line' => array( 'Search string', 'Replacement string' ),  
  874. '1st 20 chars of line' => array( 'Search string', 'Replacement string' ) 
  875. ); 
  876. */ 
  877.  
  878. // Get the existing lines in the file 
  879. $lines = file( $file_source ); 
  880.  
  881. // Initialise an array to store the modified lines 
  882. $modified_lines = array(); 
  883.  
  884. // Loop through the lines and modify them 
  885. foreach ( $lines as $line ) { 
  886. if ( isset( $alterations[substr( $line, 0, 20 )] ) ) { 
  887. $alteration = $alterations[substr( $line, 0, 20 )]; 
  888. $modified_lines[] = str_replace( $alteration[0], $alteration[1], $line ); 
  889. } else { 
  890. $modified_lines[] = $line; 
  891.  
  892. $writable = true; 
  893. if ( file_exists( $file_target ) ) { 
  894. if ( !is_writable( $file_target ) ) { 
  895. $writable = false; 
  896. } else { 
  897. $dir_target = dirname( $file_target ); 
  898. if ( file_exists( $dir_target ) ) { 
  899. if ( !is_writable( $dir_target ) || !is_dir( $dir_target ) ) { 
  900. $writable = false; 
  901. } else { 
  902. $writable = false; 
  903.  
  904. if ( !$writable ) { 
  905. return trim( join( null, $modified_lines ) ); 
  906.  
  907. // Open the file for writing - rewrites the whole file 
  908. $file_handle = fopen( $file_target, 'w' ); 
  909.  
  910. // Write lines one by one to avoid OS specific newline hassles 
  911. foreach ( $modified_lines as $modified_line ) { 
  912. if ( false !== strpos( $modified_line, '?>' ) ) { 
  913. $modified_line = '?>'; 
  914. fwrite( $file_handle, $modified_line ); 
  915. if ( $modified_line == '?>' ) { 
  916. break; 
  917.  
  918. // Close the config file 
  919. fclose( $file_handle ); 
  920.  
  921. @chmod( $file_target, 0666 ); 
  922.  
  923. return 1; 
  924.  
  925. /** 
  926. * Reports whether the request method is post or not 
  927. * @return boolean True if the page was posted, otherwise false 
  928. */ 
  929. function is_posted() 
  930. if ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) ) { 
  931. return true; 
  932. return false; 
  933.  
  934. /** 
  935. * Determines which step the installer is on based on user input 
  936. * @return boolean Always returns true 
  937. **/ 
  938. function set_step() 
  939. if ( $this->is_posted() ) { 
  940. switch ( $this->step ) { 
  941. case 1: 
  942. $this->set_language(); 
  943. if ( $_POST['forward_0_0'] ) { 
  944. $this->stop_process = 1; 
  945. break; 
  946.  
  947. case 2: 
  948. if ( $_POST['forward_1_2'] ) { 
  949. $this->stop_process = 1; 
  950. break; 
  951.  
  952. case 3: 
  953. // If this is actually a request to go back to step 2 
  954. if ( $_POST['back_2_1'] ) { 
  955. $this->step = 2; 
  956. break; 
  957.  
  958. // If we have come forward from step 2 then don't process form 3 
  959. if ( $_POST['forward_2_1'] ) { 
  960. $this->stop_process = true; 
  961.  
  962. // Determine what the status of the previous step was based on input 
  963. if ( $_POST['toggle_2_0'] ) { 
  964. $this->strings[2]['status'] = __( '« completed' ); 
  965. $this->step_status[2] = 'complete'; 
  966. break; 
  967.  
  968. case 4: 
  969. // Determine what the status of the previous step was based on input 
  970. if ( $_POST['toggle_2_0'] ) { 
  971. $this->strings[2]['status'] = __( '« completed' ); 
  972. $this->step_status[2] = 'complete'; 
  973.  
  974. // If this is actually a request to go back to step 3 
  975. if ( $_POST['back_3_1'] ) { 
  976. $this->step = 3; 
  977. break; 
  978.  
  979. // We have to have come forward from step 3 
  980. if ( $_POST['forward_3_1'] ) { 
  981. $this->strings[3]['status'] = __( '« completed' ); 
  982. $this->step_status[3] = 'complete'; 
  983. } else { 
  984. $this->step = 2; 
  985. break; 
  986. return true; 
  987.  
  988. /** 
  989. * Sanitizes all data stored in the data array 
  990. * @return boolean Always returns true 
  991. **/ 
  992. function sanitize_form_data() 
  993. foreach ( $this->data as $step => $data ) { 
  994. if ( isset( $data['form'] ) && is_array( $data['form'] ) ) { 
  995. foreach ( $data['form'] as $key => $value ) { 
  996. $this->data[$step]['form'][$key]['value'] = esc_attr( $value['value'] ); 
  997. return true; 
  998.  
  999. /** 
  1000. * Directs processing of the form data based on the current step 
  1001. * @return boolean Always returns true 
  1002. **/ 
  1003. function process_form() 
  1004. if ( $this->is_posted() && !$this->stop_process ) { 
  1005. switch ( $this->step ) { 
  1006. case 1: 
  1007. $this->process_form_config_file(); 
  1008. break; 
  1009.  
  1010. case 2: 
  1011. $this->process_form_wordpress_integration(); 
  1012. break; 
  1013.  
  1014. case 3: 
  1015. $this->process_form_site_options(); 
  1016. break; 
  1017.  
  1018. case 4: 
  1019. $this->process_form_finalise_installation(); 
  1020. break; 
  1021. return true; 
  1022.  
  1023. /** 
  1024. * Takes inputted form data and injects it into the data array 
  1025. * @param integer $step Which steps data to process 
  1026. * @return boolean Always returns true 
  1027. **/ 
  1028. function inject_form_values_into_data( $step ) 
  1029. $data =& $this->data[$step]['form']; 
  1030.  
  1031. foreach ( $data as $key => $value ) { 
  1032. if ( 'forward_' !== substr( $key, 0, 8 ) && 'back_' !== substr( $key, 0, 5 ) ) { 
  1033. if ( isset( $data[$key]['prerequisite'] ) && !$_POST[$data[$key]['prerequisite']] ) { 
  1034. if ( isset( $data[$key]['default_value'] ) ) { 
  1035. $data[$key]['value'] = $data[$key]['default_value']; 
  1036. // do nothing - keep the default value 
  1037. } else { 
  1038. $data[$key]['value'] = stripslashes_deep( trim( $_POST[$key] ) ); 
  1039.  
  1040. return true; 
  1041.  
  1042. /** 
  1043. * Validates the supplied config file data and writes it to the config file. 
  1044. * @return void 
  1045. **/ 
  1046. function process_form_config_file() 
  1047. $this->inject_form_values_into_data( 1 ); 
  1048.  
  1049. $data =& $this->data[1]['form']; 
  1050.  
  1051. if ( 'en_US' == $data['bb_lang']['value'] ) { 
  1052. $data['bb_lang']['value'] = ''; 
  1053.  
  1054. if ( $data['toggle_1']['value'] ) { 
  1055. $data['toggle_1']['checked'] = 'checked="checked"'; 
  1056. $data['toggle_1']['display'] = 'block'; 
  1057.  
  1058. // Deal with slashes in the keys 
  1059. //$data['bb_auth_key']['value'] = addslashes( stripslashes( $data['bb_auth_key']['value'] ) ); 
  1060. //$data['bb_secure_auth_key']['value'] = addslashes( stripslashes( $data['bb_secure_auth_key']['value'] ) ); 
  1061. //$data['bb_logged_in_key']['value'] = addslashes( stripslashes( $data['bb_logged_in_key']['value'] ) ); 
  1062. //$data['bb_nonce_key']['value'] = addslashes( stripslashes( $data['bb_nonce_key']['value'] ) ); 
  1063.  
  1064. $requested_prefix = $data['bb_table_prefix']['value']; 
  1065. $data['bb_table_prefix']['value'] = preg_replace( '/[^0-9a-zA-Z_]/', '', $data['bb_table_prefix']['value'] ); 
  1066. if ( $requested_prefix !== $data['bb_table_prefix']['value'] ) { 
  1067. $data['toggle_1']['checked'] = 'checked="checked"'; 
  1068. $data['toggle_1']['display'] = 'block'; 
  1069. $this->step_status[1] = 'incomplete'; 
  1070. $this->strings[1]['messages']['error'][] = __( 'The table prefix can only contain letters, numbers and underscores.<br />Please review the suggestion below.' ); 
  1071. $this->strings[1]['form_errors']['bb_table_prefix'][] = __( '• Based on your input the following prefix is suggested.' ); 
  1072. return 'incomplete'; 
  1073. if ( empty( $data['bb_table_prefix']['value'] ) ) { 
  1074. $data['bb_table_prefix']['value'] = 'bb_'; 
  1075. $data['toggle_1']['checked'] = 'checked="checked"'; 
  1076. $data['toggle_1']['display'] = 'block'; 
  1077. $this->step_status[1] = 'incomplete'; 
  1078. $this->strings[1]['messages']['error'][] = __( 'The table prefix can not be blank.<br />Please review the suggestion below.' ); 
  1079. $this->strings[1]['form_errors']['bb_table_prefix'][] = __( '• The default prefix has been inserted.' ); 
  1080. return 'incomplete'; 
  1081.  
  1082. // Stop here if we are going backwards 
  1083. if ( $_POST['back_1_1'] ) { 
  1084. $this->step_status[1] = 'incomplete'; 
  1085. return 'incomplete'; 
  1086.  
  1087. // Test the db connection. 
  1088. define( 'BBDB_NAME', $data['bbdb_name']['value'] ); 
  1089. define( 'BBDB_USER', $data['bbdb_user']['value'] ); 
  1090. define( 'BBDB_PASSWORD', $data['bbdb_password']['value'] ); 
  1091. define( 'BBDB_HOST', $data['bbdb_host']['value'] ); 
  1092. define( 'BBDB_CHARSET', $data['bbdb_charset']['value'] ); 
  1093. define( 'BBDB_COLLATE', $data['bbdb_collate']['value'] ); 
  1094.  
  1095. // We'll fail here if the values are no good. 
  1096. require_once( BACKPRESS_PATH . 'class.bpdb-multi.php' ); 
  1097.  
  1098. $bbdb = new BPDB_Multi( array( 
  1099. 'name' => BBDB_NAME,  
  1100. 'user' => BBDB_USER,  
  1101. 'password' => BBDB_PASSWORD,  
  1102. 'host' => BBDB_HOST,  
  1103. 'charset' => defined( 'BBDB_CHARSET' ) ? BBDB_CHARSET : false,  
  1104. 'collate' => defined( 'BBDB_COLLATE' ) ? BBDB_COLLATE : false,  
  1105. 'errors' => 'suppress' 
  1106. ) ); 
  1107.  
  1108. if ( !$bbdb->db_connect( 'SHOW TABLES;' ) ) { 
  1109. $bbdb->suppress_errors( false ); 
  1110. $this->step_status[1] = 'incomplete'; 
  1111. $this->strings[1]['messages']['error'][] = __( 'There was a problem connecting to the database you specified.<br />Please check the settings, then try again.' ); 
  1112. return 'error'; 
  1113. $bbdb->suppress_errors( false ); 
  1114.  
  1115. $config_result = $this->write_lines_to_file( 
  1116. BB_PATH . 'bb-config-sample.php',  
  1117. BB_PATH . 'bb-config.php',  
  1118. array( 
  1119. "define( 'BBDB_NAME', " => array( "'bbpress'", "'" . $data['bbdb_name']['value'] . "'" ),  
  1120. "define( 'BBDB_USER', " => array( "'username'", "'" . $data['bbdb_user']['value'] . "'" ),  
  1121. "define( 'BBDB_PASSWO" => array( "'password'", "'" . $data['bbdb_password']['value'] . "'" ),  
  1122. "define( 'BBDB_HOST', " => array( "'localhost'", "'" . $data['bbdb_host']['value'] . "'" ),  
  1123. "define( 'BBDB_CHARSE" => array( "'utf8'", "'" . $data['bbdb_charset']['value'] . "'" ),  
  1124. "define( 'BBDB_COLLAT" => array( "''", "'" . $data['bbdb_collate']['value'] . "'" ),  
  1125. //"define( 'BB_AUTH_KEY" => array( "'put your unique phrase here'", "'" . $data['bb_auth_key']['value'] . "'" ),  
  1126. //"define( 'BB_SECURE_A" => array( "'put your unique phrase here'", "'" . $data['bb_secure_auth_key']['value'] . "'" ),  
  1127. //"define( 'BB_LOGGED_I" => array( "'put your unique phrase here'", "'" . $data['bb_logged_in_key']['value'] . "'" ),  
  1128. //"define( 'BB_NONCE_KE" => array( "'put your unique phrase here'", "'" . $data['bb_nonce_key']['value'] . "'" ),  
  1129. "\$bb_table_prefix = '" => array( "'bb_'", "'" . $data['bb_table_prefix']['value'] . "'" ),  
  1130. "define( 'BB_LANG', '" => array( "''", "'" . $data['bb_lang']['value'] . "'" ) 
  1131. ); 
  1132.  
  1133. switch ( $config_result ) { 
  1134. case -1: 
  1135. $this->step_status[1] = 'error'; 
  1136. $this->strings[1]['messages']['error'][] = __( 'I could not find the file <code>bb-config-sample.php</code><br />Please upload it to the root directory of your bbPress installation.' ); 
  1137. return 'error'; 
  1138. break; 
  1139. case 1: 
  1140. $this->configs['bb-config.php'] = BB_PATH . 'bb-config.php'; 
  1141. $this->step_status[1] = 'complete'; 
  1142. $this->strings[1]['messages']['message'][] = __( 'Your settings have been saved to the file <code>bb-config.php</code><br />You can now continue to the next step.' ); 
  1143. break; 
  1144. default: 
  1145. // Just write the contents to screen 
  1146. $this->data[1]['form']['config']['value'] = $config_result; 
  1147.  
  1148. $this->step_status[1] = 'manual'; 
  1149. $this->strings[1]['messages']['error'][] = __( 'Your settings could not be saved to a configuration file. You will need to save the text shown below into a file named <code>bb-config.php</code> in the root directory of your bbPress installation before you can continue.' ); 
  1150. break; 
  1151.  
  1152. /** 
  1153. * Validates the WordPress integration settings 
  1154. * @return void 
  1155. **/ 
  1156. function process_form_wordpress_integration() 
  1157. // Check the referer 
  1158. bb_check_admin_referer( 'bbpress-installer' ); 
  1159.  
  1160. $this->inject_form_values_into_data( 2 ); 
  1161.  
  1162. $data =& $this->data[2]['form']; 
  1163.  
  1164. // If there are no settings then goto step 3 
  1165. if ( !$data['toggle_2_0']['value'] && !$_POST['back_2_1'] ) { 
  1166. $this->step_status[2] = 'complete'; 
  1167. $this->strings[2]['messages']['message'][] = __( 'You have chosen to skip the WordPress integration step. You can always integrate WordPress later from within the admin area of bbPress.' ); 
  1168. return 'complete'; 
  1169.  
  1170. // If integration is selected 
  1171. if ( $data['toggle_2_0']['value'] ) { 
  1172. $data['toggle_2_0']['checked'] = 'checked="checked"'; 
  1173. $data['toggle_2_0']['display'] = 'block'; 
  1174. $data['forward_2_0']['value'] = $data['toggle_2_0']['toggle_value']['on_value']; 
  1175.  
  1176. if ( $data['toggle_2_1']['value'] ) { 
  1177. $data['toggle_2_1']['checked'] = 'checked="checked"'; 
  1178. $data['toggle_2_1']['display'] = 'block'; 
  1179.  
  1180. // Check the wp_siteurl URL for errors 
  1181. $data['wp_siteurl']['value'] = $data['wp_siteurl']['value'] ? rtrim( $data['wp_siteurl']['value'], " \t\n\r\0\x0B/" ) . '/' : ''; 
  1182. $this->strings[2]['form_errors']['wp_siteurl'][] = empty( $data['wp_siteurl']['value'] ) ? 'empty' : false; 
  1183. if ( $parsed = parse_url( $data['wp_siteurl']['value'] ) ) { 
  1184. $this->strings[2]['form_errors']['wp_siteurl'][] = preg_match( '/https?/i', $parsed['scheme'] ) ? false : 'urlscheme'; 
  1185. $this->strings[2]['form_errors']['wp_siteurl'][] = empty( $parsed['host'] ) ? 'urlhost' : false; 
  1186. } else { 
  1187. $this->strings[2]['form_errors']['wp_siteurl'][] = 'urlparse'; 
  1188.  
  1189. // Check the wp_home URL for errors 
  1190. $data['wp_home']['value'] = $data['wp_home']['value'] ? rtrim( $data['wp_home']['value'], " \t\n\r\0\x0B/" ) . '/' : ''; 
  1191. $this->strings[2]['form_errors']['wp_home'][] = empty( $data['wp_home']['value'] ) ? 'empty' : false; 
  1192. if ( $parsed = parse_url( $data['wp_home']['value'] ) ) { 
  1193. $this->strings[2]['form_errors']['wp_home'][] = preg_match( '/https?/i', $parsed['scheme'] ) ? false : 'urlscheme'; 
  1194. $this->strings[2]['form_errors']['wp_home'][] = empty( $parsed['host'] ) ? 'urlhost' : false; 
  1195. } else { 
  1196. $this->strings[2]['form_errors']['wp_home'][] = 'urlparse'; 
  1197.  
  1198. // Deal with slashes in the keys 
  1199. $data['wp_auth_key']['value'] = addslashes( stripslashes( $data['wp_auth_key']['value'] ) ); 
  1200. $data['wp_auth_salt']['value'] = addslashes( stripslashes( $data['wp_auth_salt']['value'] ) ); 
  1201. $data['wp_secure_auth_key']['value'] = addslashes( stripslashes( $data['wp_secure_auth_key']['value'] ) ); 
  1202. $data['wp_secure_auth_salt']['value'] = addslashes( stripslashes( $data['wp_secure_auth_salt']['value'] ) ); 
  1203. $data['wp_logged_in_key']['value'] = addslashes( stripslashes( $data['wp_logged_in_key']['value'] ) ); 
  1204. $data['wp_logged_in_salt']['value'] = addslashes( stripslashes( $data['wp_logged_in_salt']['value'] ) ); 
  1205.  
  1206. // Check the keys for errors 
  1207. $this->strings[2]['form_errors']['wp_auth_key'][] = empty( $data['wp_auth_key']['value'] ) ? 'empty' : false; 
  1208. $this->strings[2]['form_errors']['wp_secure_auth_key'][] = empty( $data['wp_secure_auth_key']['value'] ) ? 'empty' : false; 
  1209. $this->strings[2]['form_errors']['wp_logged_in_key'][] = empty( $data['wp_logged_in_key']['value'] ) ? 'empty' : false; 
  1210.  
  1211. // Salts can be taken from the database if specified 
  1212. if ( !$data['toggle_2_2']['value'] ) { 
  1213. $this->strings[2]['form_errors']['wp_auth_salt'][] = empty( $data['wp_auth_salt']['value'] ) ? 'empty' : false; 
  1214. // NB; secure_auth_salt is not always set in WordPress 
  1215. $this->strings[2]['form_errors']['wp_logged_in_salt'][] = empty( $data['wp_logged_in_salt']['value'] ) ? 'empty' : false; 
  1216.  
  1217. // If database integration is selected 
  1218. if ( $data['toggle_2_2']['value'] ) { 
  1219. $data['toggle_2_2']['checked'] = 'checked="checked"'; 
  1220. $data['toggle_2_2']['display'] = 'block'; 
  1221.  
  1222. // Make the wp_table_prefix valid 
  1223. $data['wp_table_prefix']['value'] = preg_replace( '/[^0-9a-zA-Z_]/', '', $data['wp_table_prefix']['value'] ); 
  1224. $data['wp_table_prefix']['value'] = empty( $data['wp_table_prefix']['value'] ) ? 'wp_' : $data['wp_table_prefix']['value']; 
  1225.  
  1226. // Make the wordpress_mu_primary_blog_id valid 
  1227. $data['wordpress_mu_primary_blog_id']['value'] = preg_replace( '/[^0-9]/', '', $data['wordpress_mu_primary_blog_id']['value'] ); 
  1228.  
  1229. // If advanced database integration is selected 
  1230. if ( $data['toggle_2_3']['value'] ) { 
  1231. $data['toggle_2_3']['checked'] = 'checked="checked"'; 
  1232. $data['toggle_2_3']['display'] = 'block'; 
  1233.  
  1234. if ( !$data['toggle_2_1']['value'] && !$data['toggle_2_2']['value'] ) { 
  1235. $this->step_status[2] = 'incomplete'; 
  1236. $this->strings[2]['messages']['error'][] = __( 'You must enter your settings for integration setup to complete. Choose which integration settings you wish to enter from the options below.' ); 
  1237. $this->strings[2]['form_errors']['toggle_2_1'][] = true; 
  1238. $this->strings[2]['form_errors']['toggle_2_2'][] = true; 
  1239. return 'incomplete'; 
  1240.  
  1241. // Remove empty values from the error array 
  1242. foreach ( $this->strings[2]['form_errors'] as $input => $types) { 
  1243. $types = array_filter( $types); 
  1244. if ( !count( $types ) ) { 
  1245. unset( $this->strings[2]['form_errors'][$input] ); 
  1246.  
  1247. // Check for errors and build error messages 
  1248. if ( count( $this->strings[2]['form_errors'] ) ) { 
  1249.  
  1250. $this->step_status[2] = 'incomplete'; 
  1251. $this->strings[2]['messages']['error'][] = __( 'Your integration settings have not been processed due to errors with the items marked below.' ); 
  1252.  
  1253. foreach ( $this->strings[2]['form_errors'] as $input => $types ) { 
  1254. $errors = array(); 
  1255.  
  1256. foreach ( $types as $type ) { 
  1257. switch ( $type ) { 
  1258. case 'empty': 
  1259. // Only return this error when empty 
  1260. $errors = array( __( '• This value is required to continue.' ) ); 
  1261. break(2); 
  1262. case 'urlparse': 
  1263. $errors[] = __( '• This does not appear to be a valid URL.' ); 
  1264. break; 
  1265. case 'urlscheme': 
  1266. $errors[] = __( '• The URL must begin with "http" or "https".' ); 
  1267. break; 
  1268. case 'urlhost': 
  1269. $errors[] = __( '• The URL does not contain a host name.' ); 
  1270. break; 
  1271.  
  1272. $this->strings[2]['form_errors'][$input] = $errors; 
  1273.  
  1274. return 'incomplete'; 
  1275.  
  1276. // If database integration is selected 
  1277. if ( $data['toggle_2_2']['value'] ) { 
  1278.  
  1279. // Test the db connection. 
  1280.  
  1281. // Setup variables and constants if available 
  1282. global $bb; 
  1283. $bb->wp_table_prefix = $data['wp_table_prefix']['value']; 
  1284. if ( $data['toggle_2_3']['value'] ) { 
  1285. // These may be empty at this particular stage 
  1286. if ( !empty( $data['user_bbdb_name']['value'] ) ) { 
  1287. $bb->user_bbdb_name = $data['user_bbdb_name']['value']; 
  1288. if ( !empty( $data['user_bbdb_user']['value'] ) ) { 
  1289. $bb->user_bbdb_user = $data['user_bbdb_user']['value']; 
  1290. if ( !empty( $data['user_bbdb_password']['value'] ) ) { 
  1291. $bb->user_bbdb_password = $data['user_bbdb_password']['value']; 
  1292. if ( !empty( $data['user_bbdb_host']['value'] ) ) { 
  1293. $bb->user_bbdb_host = $data['user_bbdb_host']['value']; 
  1294. if ( !empty( $data['user_bbdb_charset']['value'] ) ) { 
  1295. $bb->user_bbdb_charset = preg_replace( '/[^a-z0-9_-]/i', '', $data['user_bbdb_charset']['value'] ); 
  1296. if ( !empty( $data['user_bbdb_collate']['value'] ) ) { 
  1297. $bb->user_bbdb_collate = preg_replace( '/[^a-z0-9_-]/i', '', $data['user_bbdb_collate']['value'] ); 
  1298. if ( !empty( $data['custom_user_table']['value'] ) ) { 
  1299. $bb->custom_user_table = preg_replace( '/[^a-z0-9_-]/i', '', $data['custom_user_table']['value'] ); 
  1300. if ( !empty( $data['custom_user_meta_table']['value'] ) ) { 
  1301. $bb->custom_user_meta_table = preg_replace( '/[^a-z0-9_-]/i', '', $data['custom_user_meta_table']['value'] ); 
  1302.  
  1303. // Bring in the database object 
  1304. global $bbdb; 
  1305. global $bb_table_prefix; 
  1306.  
  1307. // Resolve the custom user tables for bpdb 
  1308. bb_set_custom_user_tables(); 
  1309.  
  1310. if ( isset( $bb->custom_databases) && isset( $bb->custom_databases['user'] ) ) { 
  1311. $bbdb->add_db_server( 'user', $bb->custom_databases['user'] ); 
  1312.  
  1313. // Add custom tables if required 
  1314. if ( isset( $bb->custom_tables['users'] ) || isset( $bb->custom_tables['usermeta'] ) ) { 
  1315. $bbdb->tables = array_merge( $bbdb->tables, $bb->custom_tables ); 
  1316. if ( is_wp_error( $bbdb->set_prefix( $bb_table_prefix ) ) ) { 
  1317. die( __( 'Your user table prefix may only contain letters, numbers and underscores.' ) ); 
  1318.  
  1319. // Hide errors for the test 
  1320. $bbdb->hide_errors(); 
  1321.  
  1322. $result = $bbdb->query( 'DESCRIBE ' . $bbdb->users . ';' ); 
  1323. $result_error = $bbdb->get_error(); 
  1324.  
  1325. // Select from the user table (may fail if there are no records in the table) 
  1326. if ( !$result && $result_error ) { 
  1327. // We couldn't connect to the database at all 
  1328.  
  1329. // Turn errors back on 
  1330. $bbdb->show_errors(); 
  1331.  
  1332. // Set the status 
  1333. $this->step_status[2] = 'incomplete'; 
  1334. if ( !empty( $data['user_bbdb_name']['value'] ) ) { 
  1335. $this->strings[2]['form_errors']['user_bbdb_name'][] = true; 
  1336. if ( !empty( $data['user_bbdb_user']['value'] ) ) { 
  1337. $this->strings[2]['form_errors']['user_bbdb_user'][] = true; 
  1338. if ( !empty( $data['user_bbdb_password']['value'] ) ) { 
  1339. $this->strings[2]['form_errors']['user_bbdb_password'][] = true; 
  1340. if ( !empty( $data['user_bbdb_host']['value'] ) ) { 
  1341. $this->strings[2]['form_errors']['user_bbdb_host'][] = true; 
  1342. if ( !empty( $data['custom_user_table']['value'] ) ) { 
  1343. $this->strings[2]['form_errors']['custom_user_table'][] = true; 
  1344. if ( !empty( $data['custom_user_meta_table']['value'] ) ) { 
  1345. $this->strings[2]['form_errors']['custom_user_meta_table'][] = true; 
  1346. $this->strings[2]['messages']['error'][] = __( 'There was a problem connecting to the WordPress user database you specified. Please check the settings, then try again.' ); 
  1347. return 'incomplete'; 
  1348.  
  1349. if ( $result_error ) { 
  1350. // The result is an error, presumably telling us the table doesn't exist 
  1351.  
  1352. // Turn errors back on 
  1353. $bbdb->show_errors(); 
  1354.  
  1355. // Set the status 
  1356. $this->step_status[2] = 'incomplete'; 
  1357.  
  1358. if ( $data['toggle_2_3']['value'] ) { 
  1359. $this->strings[2]['messages']['error'][] = __( 'Existing WordPress user tables could not be found in the WordPress database you specified.' ); 
  1360. } else { 
  1361. $this->strings[2]['messages']['error'][] = __( 'Existing WordPress user tables could not be found in the bbPress database you specified in step 1.<br /><br />This is probably because the database does not already contain working WordPress tables. You may need to specify advanced database settings or leave integration until after installation.' ); 
  1362. $this->strings[2]['form_errors']['wp_table_prefix'][] = __( '• This may not be a valid user table prefix.' ); 
  1363. return 'incomplete'; 
  1364.  
  1365. // Turn errors back on 
  1366. $bbdb->show_errors(); 
  1367.  
  1368. // Stop here if we are going backwards 
  1369. if ( $_POST['back_2_1'] ) { 
  1370. $this->step_status[2] = 'incomplete'; 
  1371. return 'incomplete'; 
  1372.  
  1373. // If we make it this may we are complete, so set the status to complete 
  1374. $this->step_status[2] = 'complete'; 
  1375. $this->strings[2]['messages']['message'][] = __( 'Your WordPress integration cookie and database settings have been successfully validated. They will be saved after the next step.<br /><br />Once you have finished installing, you should visit the WordPress integration section of the bbPress admin area for further options and integration instructions, including user mapping and the correct cookie settings to add to your WordPress configuration file.' ); 
  1376. return 'complete'; 
  1377.  
  1378. /** 
  1379. * Validates the site options. 
  1380. * @return void 
  1381. **/ 
  1382. function process_form_site_options() 
  1383. // Check the referer 
  1384. bb_check_admin_referer( 'bbpress-installer' ); 
  1385.  
  1386. $this->inject_form_values_into_data( 2 ); 
  1387. $this->inject_form_values_into_data( 3 ); 
  1388.  
  1389. $data =& $this->data[3]['form']; 
  1390.  
  1391. $this->strings[3]['form_errors']['name'][] = empty( $data['name']['value'] ) ? 'empty' : false; 
  1392.  
  1393. $data['uri']['value'] = $data['uri']['value'] ? rtrim( $data['uri']['value'], " \t\n\r\0\x0B/" ) . '/' : ''; 
  1394. $this->strings[3]['form_errors']['uri'][] = empty( $data['uri']['value'] ) ? 'empty' : false; 
  1395. if ( $parsed = parse_url( $data['uri']['value'] ) ) { 
  1396. $this->strings[3]['form_errors']['uri'][] = preg_match( '/https?/i', $parsed['scheme'] ) ? false : 'urlscheme'; 
  1397. $this->strings[3]['form_errors']['uri'][] = empty( $parsed['host'] ) ? 'urlhost' : false; 
  1398. } else { 
  1399. $this->strings[3]['form_errors']['uri'][] = 'urlparse'; 
  1400.  
  1401. $this->strings[3]['form_errors']['keymaster_user_login'][] = empty( $data['keymaster_user_login']['value'] ) ? 'empty' : false; 
  1402. if ( $data['keymaster_user_login']['value'] != sanitize_user( $data['keymaster_user_login']['value'], true ) ) { 
  1403. $this->strings[3]['form_errors']['keymaster_user_login'][] = 'userlogin'; 
  1404. $data['keymaster_user_login']['value'] = sanitize_user( $data['keymaster_user_login']['value'], true ); 
  1405.  
  1406. // Check for a valid email 
  1407. $this->strings[3]['form_errors']['keymaster_user_email'][] = empty( $data['keymaster_user_email']['value'] ) ? 'empty' : false; 
  1408. $this->strings[3]['form_errors']['keymaster_user_email'][] = !is_email( $data['keymaster_user_email']['value'] ) ? 'email' : false; 
  1409.  
  1410. // Check for a forum name 
  1411. if ( !$this->database_tables_are_installed() ) { 
  1412. $this->strings[3]['form_errors']['forum_name'][] = empty( $data['forum_name']['value'] ) ? 'empty' : false; 
  1413.  
  1414. // Remove empty values from the error array 
  1415. foreach ( $this->strings[3]['form_errors'] as $input => $types ) { 
  1416. $types = array_filter( $types ); 
  1417. if ( !count( $types ) ) { 
  1418. unset( $this->strings[3]['form_errors'][$input] ); 
  1419.  
  1420. // Check for errors and build error messages 
  1421. if ( count( $this->strings[3]['form_errors'] ) ) { 
  1422.  
  1423. $this->step_status[3] = 'incomplete'; 
  1424. $this->strings[3]['messages']['error'][] = __( 'Your site settings have not been processed due to errors with the items marked below.' ); 
  1425.  
  1426. foreach ( $this->strings[3]['form_errors'] as $input => $types ) { 
  1427. $errors = array(); 
  1428.  
  1429. foreach ( $types as $type ) { 
  1430. switch ( $type ) { 
  1431. case 'empty': 
  1432. // Only return this error when empty 
  1433. $errors = array( __( '• This value is required to continue.' ) ); 
  1434. break(2); 
  1435. case 'urlparse': 
  1436. $errors[] = __( '• This does not appear to be a valid URL.' ); 
  1437. break; 
  1438. case 'urlscheme': 
  1439. $errors[] = __( '• The URL must begin with "http" or "https".' ); 
  1440. break; 
  1441. case 'urlhost': 
  1442. $errors[] = __( '• The URL does not contain a host name.' ); 
  1443. break; 
  1444. case 'userlogin': 
  1445. $errors[] = __( '• Contains disallowed characters which have been removed.' ); 
  1446. break; 
  1447. case 'email': 
  1448. $errors[] = __( '• The user email address appears to be invalid.' ); 
  1449. break; 
  1450.  
  1451. $this->strings[3]['form_errors'][$input] = $errors; 
  1452.  
  1453. return 'incomplete'; 
  1454.  
  1455. // Stop here if we are going backwards 
  1456. if ( $_POST['back_3_1'] ) { 
  1457. $this->step_status[3] = 'incomplete'; 
  1458. return 'incomplete'; 
  1459.  
  1460. // If we make it this far we are good to go 
  1461. $this->step_status[3] = 'complete'; 
  1462. $this->strings[3]['messages']['message'][] = __( 'Your site settings have been saved and we are now ready to complete the installation. So what are you waiting for?' ); 
  1463. return 'complete'; 
  1464.  
  1465. /** 
  1466. * Finalises the installation by creating the database and writing all the supplied data to the database. 
  1467. * @return void 
  1468. **/ 
  1469. function process_form_finalise_installation() 
  1470. require_once( BB_PATH . 'bb-admin/includes/functions.bb-upgrade.php' ); 
  1471. require_once( BB_PATH . 'bb-admin/includes/functions.bb-admin.php' ); 
  1472.  
  1473. $this->inject_form_values_into_data( 2 ); 
  1474. $this->inject_form_values_into_data( 3 ); 
  1475.  
  1476. $data2 =& $this->data[2]['form']; 
  1477. $data3 =& $this->data[3]['form']; 
  1478. $data4 =& $this->data[4]['form']; 
  1479.  
  1480. $error_log = array(); 
  1481. $installation_log = array(); 
  1482.  
  1483. // Check the referer 
  1484. bb_check_admin_referer( 'bbpress-installer' ); 
  1485. $installation_log[] = __( 'Referrer is OK, beginning installation…' ); 
  1486.  
  1487. global $bbdb; 
  1488.  
  1489. // Setup user table variables and constants if available 
  1490. if ( $data2['toggle_2_2']['value'] ) { 
  1491.  
  1492. $installation_log[] = '>>> ' . __( 'Setting up custom user table constants' ); 
  1493.  
  1494. global $bb; 
  1495. global $bb_table_prefix; 
  1496.  
  1497. if ( !empty( $data2['wp_table_prefix']['value'] ) ) { 
  1498. $bb->wp_table_prefix = $data2['wp_table_prefix']['value']; 
  1499. if ( !empty( $data2['user_bbdb_name']['value'] ) ) { 
  1500. $bb->user_bbdb_name = $data2['user_bbdb_name']['value']; 
  1501. if ( !empty( $data2['user_bbdb_user']['value'] ) ) { 
  1502. $bb->user_bbdb_user = $data2['user_bbdb_user']['value']; 
  1503. if ( !empty( $data2['user_bbdb_password']['value'] ) ) { 
  1504. $bb->user_bbdb_password = $data2['user_bbdb_password']['value']; 
  1505. if ( !empty( $data2['user_bbdb_host']['value'] ) ) { 
  1506. $bb->user_bbdb_host = $data2['user_bbdb_host']['value']; 
  1507. if ( !empty( $data2['user_bbdb_charset']['value'] ) ) { 
  1508. $bb->user_bbdb_charset = preg_replace( '/[^a-z0-9_-]/i', '', $data2['user_bbdb_charset']['value'] ); 
  1509. if ( !empty( $data2['user_bbdb_collate']['value'] ) ) { 
  1510. $bb->user_bbdb_collate = preg_replace( '/[^a-z0-9_-]/i', '', $data2['user_bbdb_collate']['value'] ); 
  1511.  
  1512. bb_set_custom_user_tables(); 
  1513.  
  1514. // Add custom user database if required 
  1515. if ( isset( $bb->custom_databases['user'] ) ) { 
  1516. $bbdb->add_db_server( 'user', $bb->custom_databases['user'] ); 
  1517.  
  1518. // Add custom tables if required 
  1519. if ( isset( $bb->custom_tables ) ) { 
  1520. $bbdb->tables = array_merge( $bbdb->tables, $bb->custom_tables ); 
  1521. if ( is_wp_error( $bbdb->set_prefix( $bb_table_prefix ) ) ) 
  1522. die( __( 'Your user table prefix may only contain letters, numbers and underscores.' ) ); 
  1523.  
  1524. // Create the database 
  1525. $installation_log[] = "\n" . __( 'Step 1 - Creating database tables' ); 
  1526.  
  1527. if ( !$this->database_tables_are_installed() ) { 
  1528. // Hide db errors 
  1529. $bbdb->hide_errors(); 
  1530. // Install the database 
  1531. $alterations = bb_install(); 
  1532. // Show db errors 
  1533. $bbdb->show_errors(); 
  1534.  
  1535. if ( isset( $alterations['errors'] ) && is_array( $alterations['errors'] ) ) { 
  1536. $error_log = array_merge( $error_log, $alterations['errors'] ); 
  1537. if ( isset( $alterations['messages'] ) && is_array( $alterations['messages'] ) ) { 
  1538. $installation_log = array_merge( $installation_log, $alterations['messages'] ); 
  1539.  
  1540. if ( !$this->database_tables_are_installed() ) { 
  1541. $installation_log[] = '>>> ' . __( 'Database installation failed!!!' ); 
  1542. $installation_log[] = '>>>>>> ' . __( 'Halting installation!' ); 
  1543. $error_log[] = __( 'Database installation failed!!!' ); 
  1544.  
  1545. $this->step_status[4] = 'incomplete'; 
  1546. $this->strings[4]['h2'] = __( 'Installation failed!' ); 
  1547. $this->strings[4]['messages']['error'][] = __( 'The database failed to install. You may need to replace bbPress with a fresh copy and start again.' ); 
  1548.  
  1549. $data4['installation_log']['value'] = join( "\n", $installation_log ); 
  1550. $data4['error_log']['value'] = join( "\n", $error_log ); 
  1551.  
  1552. return 'incomplete'; 
  1553. } else { 
  1554. $installation_log[] = '>>> ' . __( 'Database is already installed!!!' ); 
  1555.  
  1556. // Integration settings passed from step 2 
  1557. // These are already validated provided that the referer checks out 
  1558. $installation_log[] = "\n" . __( 'Step 2 - WordPress integration (optional)' ); 
  1559. if ( $data2['toggle_2_0']['value'] ) { 
  1560. if ( $data2['toggle_2_1']['value'] ) { 
  1561. bb_update_option( 'wp_siteurl', $data2['wp_siteurl']['value'] ); 
  1562. $installation_log[] = '>>> ' . __( 'WordPress address (URL):' ) . ' ' . $data2['wp_siteurl']['value']; 
  1563.  
  1564. bb_update_option( 'wp_home', $data2['wp_home']['value'] ); 
  1565. $installation_log[] = '>>> ' . __( 'Blog address (URL):' ) . ' ' . $data2['wp_home']['value']; 
  1566.  
  1567. $config_result = $this->write_lines_to_file( 
  1568. BB_PATH . 'bb-config.php',  
  1569. false,  
  1570. array( 
  1571. "define( 'BB_AUTH_KEY" => array( "'" . BB_AUTH_KEY . "'", "'" . $data2['wp_auth_key']['value'] . "'" ),  
  1572. "define( 'BB_SECURE_A" => array( "'" . BB_SECURE_AUTH_KEY . "'", "'" . $data2['wp_secure_auth_key']['value'] . "'" ),  
  1573. "define( 'BB_LOGGED_I" => array( "'" . BB_LOGGED_IN_KEY . "'", "'" . $data2['wp_logged_in_key']['value'] . "'" ),  
  1574. ); 
  1575.  
  1576. switch ( $config_result ) { 
  1577. case 1: 
  1578. $installation_log[] = '>>> ' . __( 'WordPress cookie keys set.' ); 
  1579. break; 
  1580. default: 
  1581. $error_log[] = '>>> ' . __( 'WordPress cookie keys not set.' ); 
  1582. $error_log[] = '>>>>>> ' . __( 'Your "bb-config.php" file was not writable.' ); 
  1583. $error_log[] = '>>>>>> ' . __( 'You will need to manually re-define "BB_AUTH_KEY", "BB_SECURE_AUTH_KEY" and "BB_LOGGED_IN_KEY" in your "bb-config.php" file.' ); 
  1584. $installation_log[] = '>>> ' . __( 'WordPress cookie keys not set.' ); 
  1585. break; 
  1586.  
  1587. if ( !empty( $data2['wp_auth_salt']['value'] ) ) { 
  1588. bb_update_option( 'bb_auth_salt', $data2['wp_auth_salt']['value'] ); 
  1589. $installation_log[] = '>>> ' . __( 'WordPress "auth" cookie salt set from input.' ); 
  1590.  
  1591. if ( !empty( $data2['wp_secure_auth_salt']['value'] ) ) { 
  1592. bb_update_option( 'bb_secure_auth_salt', $data2['wp_secure_auth_salt']['value'] ); 
  1593. $installation_log[] = '>>> ' . __( 'WordPress "secure auth" cookie salt set from input.' ); 
  1594.  
  1595. if ( !empty( $data2['wp_logged_in_salt']['value'] ) ) { 
  1596. bb_update_option( 'bb_logged_in_salt', $data2['wp_logged_in_salt']['value'] ); 
  1597. $installation_log[] = '>>> ' . __( 'WordPress "logged in" cookie salt set from input.' ); 
  1598.  
  1599. if ( $data2['toggle_2_2']['value'] ) { 
  1600. if ( 
  1601. !bb_get_option( 'bb_auth_salt' ) || 
  1602. !bb_get_option( 'bb_secure_auth_salt' ) || 
  1603. !bb_get_option( 'bb_logged_in_salt' ) 
  1604. ) { 
  1605. $installation_log[] = '>>> ' . __( 'Fetching missing WordPress cookie salts.' ); 
  1606.  
  1607. $_prefix = $bb->wp_table_prefix; 
  1608. if ( !empty( $data2['wordpress_mu_primary_blog_id']['value'] ) ) { 
  1609. $_prefix .= $data2['wordpress_mu_primary_blog_id']['value'] . '_'; 
  1610.  
  1611. if ( isset( $bb->custom_databases['user'] ) ) { 
  1612. $bbdb->tables['options'] = array( 'user', $_prefix . 'options' ); 
  1613. } else { 
  1614. $bbdb->tables['options'] = $_prefix . 'options'; 
  1615.  
  1616. unset( $_prefix ); 
  1617.  
  1618. $bbdb->set_prefix( $bb_table_prefix ); 
  1619.  
  1620. if ( !bb_get_option( 'bb_auth_salt' ) ) { 
  1621. $wp_auth_salt = $bbdb->get_var( "SELECT `option_value` FROM $bbdb->options WHERE `option_name` = 'auth_salt' LIMIT 1" ); 
  1622. if ( $wp_auth_salt ) { 
  1623. bb_update_option( 'bb_auth_salt', $wp_auth_salt ); 
  1624. $installation_log[] = '>>>>>> ' . __( 'WordPress "auth" cookie salt set.' ); 
  1625. } else { 
  1626. $error_log[] = '>>> ' . __( 'WordPress "auth" cookie salt not set.' ); 
  1627. $error_log[] = '>>>>>> ' . __( 'Could not fetch "auth" cookie salt from the WordPress options table.' ); 
  1628. $error_log[] = '>>>>>> ' . __( 'You will need to manually define the "auth" cookie salt in your database.' ); 
  1629. $installation_log[] = '>>>>>> ' . __( 'WordPress "auth" cookie salt not set.' ); 
  1630.  
  1631. if ( !bb_get_option( 'bb_secure_auth_salt' ) ) { 
  1632. $wp_secure_auth_salt = $bbdb->get_var( "SELECT `option_value` FROM $bbdb->options WHERE `option_name` = 'secure_auth_salt' LIMIT 1" ); 
  1633. if ( $wp_secure_auth_salt ) { 
  1634. bb_update_option( 'bb_secure_auth_salt', $wp_secure_auth_salt ); 
  1635. $installation_log[] = '>>>>>> ' . __( 'WordPress "secure auth" cookie salt set.' ); 
  1636. } else { 
  1637. // This cookie salt is sometimes empty so don't error 
  1638. $installation_log[] = '>>>>>> ' . __( 'WordPress "secure auth" cookie salt not set.' ); 
  1639.  
  1640. if ( !bb_get_option( 'bb_logged_in_salt' ) ) { 
  1641. $wp_logged_in_salt = $bbdb->get_var( "SELECT `option_value` FROM $bbdb->options WHERE `option_name` = 'logged_in_salt' LIMIT 1" ); 
  1642. if ( $wp_logged_in_salt ) { 
  1643. bb_update_option( 'bb_logged_in_salt', $wp_logged_in_salt ); 
  1644. $installation_log[] = '>>>>>> ' . __( 'WordPress "logged in" cookie salt set.' ); 
  1645. } else { 
  1646. $error_log[] = '>>> ' . __( 'WordPress "logged in" cookie salt not set.' ); 
  1647. $error_log[] = '>>>>>> ' . __( 'Could not fetch "logged in" cookie salt from the WordPress options table.' ); 
  1648. $error_log[] = '>>>>>> ' . __( 'You will need to manually define the "logged in" cookie salt in your database.' ); 
  1649. $installation_log[] = '>>>>>> ' . __( 'WordPress "logged in" cookie salt not set.' ); 
  1650.  
  1651. if ( !empty( $data2['wp_table_prefix']['value'] ) ) { 
  1652. bb_update_option( 'wp_table_prefix', $data2['wp_table_prefix']['value'] ); 
  1653. $installation_log[] = '>>> ' . __( 'User database table prefix:' ) . ' ' . $data2['wp_table_prefix']['value']; 
  1654.  
  1655. if ( !empty( $data2['wordpress_mu_primary_blog_id']['value'] ) ) { 
  1656. bb_update_option( 'wordpress_mu_primary_blog_id', $data2['wordpress_mu_primary_blog_id']['value'] ); 
  1657. $installation_log[] = '>>> ' . __( 'WordPress MU primary blog ID:' ) . ' ' . $data2['wordpress_mu_primary_blog_id']['value']; 
  1658.  
  1659. if ( $data2['toggle_2_3']['value'] ) { 
  1660. if ( !empty( $data2['user_bbdb_name']['value'] ) ) { 
  1661. bb_update_option( 'user_bbdb_name', $data2['user_bbdb_name']['value'] ); 
  1662. $installation_log[] = '>>> ' . __( 'User database name:' ) . ' ' . $data2['user_bbdb_name']['value']; 
  1663. if ( !empty( $data2['user_bbdb_user']['value'] ) ) { 
  1664. bb_update_option( 'user_bbdb_user', $data2['user_bbdb_user']['value'] ); 
  1665. $installation_log[] = '>>> ' . __( 'User database user:' ) . ' ' . $data2['user_bbdb_user']['value']; 
  1666. if ( !empty( $data2['user_bbdb_password']['value'] ) ) { 
  1667. bb_update_option( 'user_bbdb_password', $data2['user_bbdb_password']['value'] ); 
  1668. $installation_log[] = '>>> ' . __( 'User database password:' ) . ' ' . $data2['user_bbdb_password']['value']; 
  1669. if ( !empty( $data2['user_bbdb_host']['value'] ) ) { 
  1670. bb_update_option( 'user_bbdb_host', $data2['user_bbdb_host']['value'] ); 
  1671. $installation_log[] = '>>> ' . __( 'User database host:' ) . ' ' . $data2['user_bbdb_host']['value']; 
  1672. if ( !empty( $data2['user_bbdb_charset']['value'] ) ) { 
  1673. bb_update_option( 'user_bbdb_charset', $data2['user_bbdb_charset']['value'] ); 
  1674. $installation_log[] = '>>> ' . __( 'User database character set:' ) . ' ' . $data2['user_bbdb_charset']['value']; 
  1675. if ( !empty( $data2['user_bbdb_collate']['value'] ) ) { 
  1676. bb_update_option( 'user_bbdb_collate', $data2['user_bbdb_collate']['value'] ); 
  1677. $installation_log[] = '>>> ' . __( 'User database collation:' ) . ' ' . $data2['user_bbdb_collate']['value']; 
  1678. if ( !empty( $data2['custom_user_table']['value'] ) ) { 
  1679. bb_update_option( 'custom_user_table', $data2['custom_user_table']['value'] ); 
  1680. $installation_log[] = '>>> ' . __( 'User database "user" table:' ) . ' ' . $data2['custom_user_table']['value']; 
  1681. if ( !empty( $data2['custom_user_meta_table']['value'] ) ) { 
  1682. bb_update_option( 'custom_user_meta_table', $data2['custom_user_meta_table']['value'] ); 
  1683. $installation_log[] = '>>> ' . __( 'User database "user meta" table:' ) . ' ' . $data2['custom_user_meta_table']['value']; 
  1684. } else { 
  1685. $installation_log[] = '>>> ' . __( 'Integration not enabled' ); 
  1686.  
  1687. // Site settings passed from step 3 
  1688. // These are already validated provided that the referer checks out 
  1689. $installation_log[] = "\n" . __( 'Step 3 - Site settings' ); 
  1690. bb_update_option( 'name', $data3['name']['value'] ); 
  1691. $installation_log[] = '>>> ' . __( 'Site name:' ) . ' ' . $data3['name']['value']; 
  1692. bb_update_option( 'uri', $data3['uri']['value'] ); 
  1693. $installation_log[] = '>>> ' . __( 'Site address (URL):' ) . ' ' . $data3['uri']['value']; 
  1694. bb_update_option( 'from_email', $data3['keymaster_user_email']['value'] ); 
  1695. $installation_log[] = '>>> ' . __( 'From email address:' ) . ' ' . $data3['keymaster_user_email']['value']; 
  1696.  
  1697. // Create the key master 
  1698. $keymaster_created = false; 
  1699.  
  1700. switch ( $data3['keymaster_user_type']['value'] ) { 
  1701. case 'new': 
  1702.  
  1703. // Check to see if the user login already exists 
  1704. if ( $keymaster_user = bb_get_user( $data3['keymaster_user_login']['value'], array( 'by' => 'login' ) ) ) { 
  1705. // The keymaster is an existing bbPress user 
  1706. $installation_log[] = '>>> ' . __( 'Key master could not be created!' ); 
  1707. $installation_log[] = '>>>>>> ' . __( 'That login is already taken!' ); 
  1708. $error_log[] = __( 'Key master could not be created!' ); 
  1709.  
  1710. if ( $keymaster_user->bb_capabilities['keymaster'] ) { 
  1711. // The existing user is a key master - continue 
  1712. $bb_current_user = bb_set_current_user( $keymaster_user->ID ); 
  1713. $installation_log[] = '>>>>>> ' . __( 'Existing key master entered!' ); 
  1714. $data4['keymaster_user_password']['value'] = __( 'Your bbPress password' ); 
  1715. $data3['keymaster_user_email']['value'] = $keymaster_user->user_email; 
  1716. bb_update_option( 'from_email', $keymaster_user->user_email); 
  1717. $installation_log[] = '>>>>>> ' . __( 'Re-setting admin email address.' ); 
  1718. $keymaster_created = true; 
  1719. } else { 
  1720. // The existing user is a non-key master user - halt installation 
  1721. $installation_log[] = '>>>>>> ' . __( 'Existing user without key master role entered!' ); 
  1722. $installation_log[] = '>>>>>>>>> ' . __( 'Halting installation!' ); 
  1723. $this->step_status[4] = 'incomplete'; 
  1724. $this->strings[4]['h2'] = __( 'Installation failed!' ); 
  1725. $this->strings[4]['messages']['error'][] = __( 'The key master could not be created. An existing user was found with that user login.' ); 
  1726.  
  1727. $data4['installation_log']['value'] = join( "\n", $installation_log ); 
  1728. $data4['error_log']['value'] = join( "\n", $error_log ); 
  1729.  
  1730. return 'incomplete'; 
  1731.  
  1732. break; 
  1733.  
  1734. // Helper function to let us know the password that was created 
  1735. global $keymaster_password; 
  1736. function bb_get_keymaster_password( $user_id, $pass ) { 
  1737. global $keymaster_password; 
  1738. $keymaster_password = $pass; 
  1739. add_action( 'bb_new_user', 'bb_get_keymaster_password', 10, 2 ); 
  1740.  
  1741. // Create the new user (automattically given key master role when BB_INSTALLING is true) 
  1742. if ( $keymaster_user_id = bb_new_user( $data3['keymaster_user_login']['value'], $data3['keymaster_user_email']['value'], '' ) ) { 
  1743. $bb_current_user = bb_set_current_user( $keymaster_user_id ); 
  1744. $data4['keymaster_user_password']['value'] = $keymaster_password; 
  1745. $installation_log[] = '>>> ' . __( 'Key master created' ); 
  1746. $installation_log[] = '>>>>>> ' . __( 'Username:' ) . ' ' . $data3['keymaster_user_login']['value']; 
  1747. $installation_log[] = '>>>>>> ' . __( 'Email address:' ) . ' ' . $data3['keymaster_user_email']['value']; 
  1748. $installation_log[] = '>>>>>> ' . __( 'Password:' ) . ' ' . $data4['keymaster_user_password']['value']; 
  1749. $keymaster_created = true; 
  1750. } else { 
  1751. $installation_log[] = '>>> ' . __( 'Key master could not be created!' ); 
  1752. $installation_log[] = '>>>>>> ' . __( 'Halting installation!' ); 
  1753. $error_log[] = __( 'Key master could not be created!' ); 
  1754. $this->step_status[4] = 'incomplete'; 
  1755. $this->strings[4]['h2'] = __( 'Installation failed!' ); 
  1756. $this->strings[4]['messages']['error'][] = __( 'The key master could not be created. You may need to replace bbPress with a fresh copy and start again.' ); 
  1757.  
  1758. $data4['installation_log']['value'] = join( "\n", $installation_log ); 
  1759. $data4['error_log']['value'] = join( "\n", $error_log ); 
  1760.  
  1761. return 'incomplete'; 
  1762. break; 
  1763.  
  1764. case 'old': 
  1765. if ( $keymaster_user = bb_get_user( $data3['keymaster_user_login']['value'], array( 'by' => 'login' ) ) ) { 
  1766. // The keymaster is an existing bbPress or WordPress user 
  1767. $bb_current_user = bb_set_current_user( $keymaster_user->ID ); 
  1768. $bb_current_user->set_role( 'keymaster' ); 
  1769. $data4['keymaster_user_password']['value'] = __( 'Your existing password' ); 
  1770. $installation_log[] = '>>> ' . __( 'Key master role assigned to existing user' ); 
  1771. $installation_log[] = '>>>>>> ' . __( 'Username:' ) . ' ' . $data3['keymaster_user_login']['value']; 
  1772. $installation_log[] = '>>>>>> ' . __( 'Email address:' ) . ' ' . $data3['keymaster_user_email']['value']; 
  1773. $installation_log[] = '>>>>>> ' . __( 'Password:' ) . ' ' . $data4['keymaster_user_password']['value']; 
  1774. $keymaster_created = true; 
  1775. } else { 
  1776. $installation_log[] = '>>> ' . __( 'Key master role could not be assigned to existing user!' ); 
  1777. $installation_log[] = '>>>>>> ' . __( 'Halting installation!' ); 
  1778. $error_log[] = __( 'Key master could not be created!' ); 
  1779. $this->step_status[4] = 'incomplete'; 
  1780. $this->strings[4]['h2'] = __( 'Installation failed!' ); 
  1781. $this->strings[4]['messages']['error'][] = __( 'The key master could not be assigned. You may need to replace bbPress with a fresh copy and start again.' ); 
  1782.  
  1783. $data4['installation_log']['value'] = join( "\n", $installation_log ); 
  1784. $data4['error_log']['value'] = join( "\n", $error_log ); 
  1785.  
  1786. return 'incomplete'; 
  1787. break; 
  1788.  
  1789. // Don't create an initial forum if any forums already exist 
  1790. if (!$bbdb->get_results( 'SELECT `forum_id` FROM `' . $bbdb->forums . '` LIMIT 1;' ) ) { 
  1791. if ( $this->language != BB_LANG) { 
  1792. global $locale, $l10n; 
  1793. $locale = BB_LANG; 
  1794. unset( $l10n['default'] ); 
  1795. bb_load_default_textdomain(); 
  1796.  
  1797. $description = __( 'Just another bbPress community' ); 
  1798. bb_update_option( 'description', $description); 
  1799.  
  1800. if ( $this->language != BB_LANG) { 
  1801. $locale = $this->language; 
  1802. unset( $l10n['default'] ); 
  1803. bb_load_default_textdomain(); 
  1804.  
  1805. $installation_log[] = '>>> ' . __( 'Description:' ) . ' ' . $description; 
  1806.  
  1807. if ( $forum_id = bb_new_forum( array( 'forum_name' => $data3['forum_name']['value'] ) ) ) { 
  1808. $installation_log[] = '>>> ' . __( 'Forum name:' ) . ' ' . $data3['forum_name']['value']; 
  1809.  
  1810. if ( $this->language != BB_LANG) { 
  1811. $locale = BB_LANG; 
  1812. unset( $l10n['default'] ); 
  1813. bb_load_default_textdomain(); 
  1814.  
  1815. $topic_title = __( 'Your first topic' ); 
  1816. $topic_id = bb_insert_topic( 
  1817. array( 
  1818. 'topic_title' => $topic_title,  
  1819. 'forum_id' => $forum_id,  
  1820. 'tags' => 'bbPress' 
  1821. ); 
  1822. $post_text = __( 'First Post! w00t.' ); 
  1823. bb_insert_post( 
  1824. array( 
  1825. 'topic_id' => $topic_id,  
  1826. 'post_text' => $post_text 
  1827. ); 
  1828.  
  1829. if ( $this->language != BB_LANG ) { 
  1830. $locale = $this->language; 
  1831. unset( $l10n['default'] ); 
  1832. bb_load_default_textdomain(); 
  1833.  
  1834. $installation_log[] = '>>>>>> ' . __( 'Topic:' ) . ' ' . $topic_title; 
  1835. $installation_log[] = '>>>>>>>>> ' . __( 'Post:' ) . ' ' . $post_text; 
  1836. } else { 
  1837. $installation_log[] = '>>> ' . __( 'Forum could not be created!' ); 
  1838. $error_log[] = __( 'Forum could not be created!' ); 
  1839. } else { 
  1840. $installation_log[] = '>>> ' . __( 'There are existing forums in this database.' ); 
  1841. $installation_log[] = '>>>>>> ' . __( 'No new forum created.' ); 
  1842. $error_log[] = __( 'Forums already exist!' ); 
  1843.  
  1844. if ( defined( 'BB_PLUGIN_DIR' ) && BB_PLUGIN_DIR && !file_exists( BB_PLUGIN_DIR ) ) { 
  1845. // Just suppress errors as this is not critical 
  1846. if ( @mkdir( BB_PLUGIN_DIR, 0755 ) ) { 
  1847. $installation_log[] = '>>> ' . sprintf( __( 'Making plugin directory at %s.' ), BB_PLUGIN_DIR ); 
  1848.  
  1849. if ( defined( 'BB_THEME_DIR' ) && BB_THEME_DIR && !file_exists( BB_THEME_DIR ) ) { 
  1850. // Just suppress errors as this is not critical 
  1851. if ( @mkdir( BB_THEME_DIR, 0755 ) ) { 
  1852. $installation_log[] = '>>> ' . sprintf( __( 'Making theme directory at %s.' ), BB_THEME_DIR ); 
  1853.  
  1854. if ( $keymaster_created ) { 
  1855. $keymaster_email_message = sprintf( 
  1856. __( "Your new bbPress site has been successfully set up at:\n\n%1\$s\n\nYou can log in to the key master account with the following information:\n\nUsername: %2\$s\nPassword: %3\$s\n\nWe hope you enjoy your new forums. Thanks!\n\n--The bbPress Team\nhttp://bbpress.org/" ),  
  1857. bb_get_uri( null, null, BB_URI_CONTEXT_TEXT ),  
  1858. $data3['keymaster_user_login']['value'],  
  1859. $data4['keymaster_user_password']['value'] 
  1860. ); 
  1861.  
  1862. if ( bb_mail( $data3['keymaster_user_email']['value'], __( 'New bbPress installation' ), $keymaster_email_message ) ) { 
  1863. $installation_log[] = '>>> ' . __( 'Key master email sent' ); 
  1864. } else { 
  1865. $installation_log[] = '>>> ' . __( 'Key master email not sent!' ); 
  1866. $error_log[] = __( 'Key master email not sent!' ); 
  1867.  
  1868. if ( count( $error_log ) ) { 
  1869. $this->strings[4]['h2'] = __( 'Installation completed with some errors!' ); 
  1870. $this->strings[4]['messages']['error'][] = __( 'Your installation completed with some minor errors. See the error log below for more specific information.' ); 
  1871. $installation_log[] = "\n" . __( 'There were some errors encountered during installation!' ); 
  1872. } else { 
  1873. $this->strings[4]['messages']['message'][] = __( 'Your installation completed successfully.' ); 
  1874. $installation_log[] = "\n" . __( 'Installation complete!' ); 
  1875.  
  1876. $this->step_status[4] = 'complete'; 
  1877.  
  1878. $data4['installation_log']['value'] = join( "\n", $installation_log ); 
  1879. $data4['error_log']['value'] = join( "\n", $error_log ); 
  1880.  
  1881. return 'complete'; 
  1882.  
  1883. /** 
  1884. * Prints a text input form element. 
  1885. * @param $key string The key of the data to populate the element with. 
  1886. * @param $direction string Optional. The text direction, only 'ltr' or 'rtl' are acceptable. 
  1887. * @return void 
  1888. **/ 
  1889. function input_text( $key, $direction = false ) 
  1890. $data = $this->data[$this->step]['form'][$key]; 
  1891.  
  1892. $class = ''; 
  1893. $classes = array(); 
  1894. if ( isset( $data['note'] ) ) { 
  1895. $classes[] = 'has-note'; 
  1896. if ( isset( $data['label'] ) ) { 
  1897. $classes[] = 'has-label'; 
  1898.  
  1899. if ( isset( $this->data[$this->step]['form'][$key]['type'] ) ) { 
  1900. $type = $this->data[$this->step]['form'][$key]['type']; 
  1901. } else { 
  1902. $type = 'text'; 
  1903. $classes[] = 'for-input-' . $type; 
  1904.  
  1905. if ( isset( $this->strings[$this->step]['form_errors'][$key] ) ) { 
  1906. $classes[] = 'error'; 
  1907. if ( count( $classes ) ) { 
  1908. $class = ' class="' . join( ' ', $classes ) . '"'; 
  1909.  
  1910. $r = "\t" . '<label id="label-' . esc_attr( $key ) . '" for="' . esc_attr( $key ) . '"' . $class . '>' . "\n"; 
  1911.  
  1912. if ( isset( $data['label'] ) ) { 
  1913. $r .= "\t\t" . '<span>' . $data['label'] . '</span>' . "\n"; 
  1914.  
  1915. if ( isset( $this->strings[$this->step]['form_errors'][$key] ) ) { 
  1916. foreach ( $this->strings[$this->step]['form_errors'][$key] as $error ) { 
  1917. if ( !is_bool( $error ) ) { 
  1918. $r .= "\t\t" . '<span class="error">' . $error . '</span>' . "\n"; 
  1919.  
  1920. if ( isset( $data['maxlength'] ) && is_integer( $data['maxlength'] ) ) { 
  1921. $maxlength = ' maxlength="' . esc_attr( $data['maxlength'] ) . '"'; 
  1922.  
  1923. if ( $direction && in_array( strtolower( $direction ), array( 'ltr', 'rtl' ) ) ) { 
  1924. $direction = ' dir="' . esc_attr( strtolower( $direction ) ) . '"'; 
  1925.  
  1926. if ( isset( $data['autocomplete'] ) ) { 
  1927. $autocomplete = ' autocomplete="' . esc_attr( $data['autocomplete'] ) . '"'; 
  1928. } else { 
  1929. $autocomplete = ''; 
  1930.  
  1931. $this->tabindex++; 
  1932. $r .= "\t\t" . '<input' . $direction . ' type="' . esc_attr( $type ) . '" id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" class="text' . $has_note_class . '" value="' . esc_attr( $data['value'] ) . '"' . $maxlength . $autocomplete . ' tabindex="' . $this->tabindex . '" />' . "\n"; 
  1933.  
  1934. if ( isset( $data['note'] ) ) { 
  1935. $r .= "\t\t" . '<a class="note-toggle" href="javascript:void(0);" onclick="toggleNote(\'note-' . esc_attr( $key ) . '\');">?</a>' . "\n"; 
  1936. $r .= "\t\t" . '<p id="note-' . esc_attr( $key ) . '" class="note" style="display:none">' . $data['note'] . '</p>' . "\n"; 
  1937.  
  1938. $r .= "\t\t" . '<div class="clear"></div>' . "\n"; 
  1939. $r .= "\t" . '</label>' . "\n"; 
  1940.  
  1941. echo $r; 
  1942.  
  1943. /** 
  1944. * Prints a hidden input form element. 
  1945. * @param $key string The key of the data to populate the element with. 
  1946. * @return void 
  1947. **/ 
  1948. function input_hidden( $key ) 
  1949. $r = "\t" . '<input type="hidden" id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" value="' . esc_attr( $this->data[$this->step]['form'][$key]['value'] ) . '" />' . "\n"; 
  1950.  
  1951. echo $r; 
  1952.  
  1953. /** 
  1954. * Prints a textarea form element. 
  1955. * @param $key string The key of the data to populate the element with. 
  1956. * @param $direction string Optional. The text direction, only 'ltr' or 'rtl' are acceptable. 
  1957. * @return void 
  1958. **/ 
  1959. function textarea( $key, $direction = false) 
  1960. $data = $this->data[$this->step]['form'][$key]; 
  1961.  
  1962. $class = ''; 
  1963. $classes = array( 'for-textarea' ); 
  1964. if ( isset( $data['note'] ) ) { 
  1965. $classes[] = 'has-note'; 
  1966. if ( isset( $data['label'] ) ) { 
  1967. $classes[] = 'has-label'; 
  1968. if ( count( $classes ) ) { 
  1969. $class = ' class="' . join( ' ', $classes ) . '"'; 
  1970.  
  1971. $r = "\t" . '<label id="label-' . esc_attr( $key ) . '"' . $class . ' for="' . esc_attr( $key ) . '">' . "\n"; 
  1972.  
  1973. if ( isset( $data['label'] ) ) { 
  1974. $r .= "\t\t" . '<span>' . $data['label'] . '</span>' . "\n"; 
  1975.  
  1976. if ( isset( $data['note'] ) ) { 
  1977. $r .= "\t\t" . '<a class="note-toggle" href="javascript:void(0);" onclick="toggleNote(\'note-' . esc_attr( $key ) . '\');">?</a>' . "\n"; 
  1978. $r .= "\t\t" . '<p id="note-' . esc_attr( $key ) . '" class="note" style="display:none">' . $data['note'] . '</p>' . "\n"; 
  1979.  
  1980. if ( $direction && in_array( strtolower( $direction ), array( 'ltr', 'rtl' ) ) ) { 
  1981. $direction = ' dir="' . esc_attr( strtolower( $direction ) ) . '"'; 
  1982.  
  1983. $this->tabindex++; 
  1984. $r .= "\t\t" . '<textarea id="' . esc_attr( $key ) . '" rows="5" cols="30"' . $direction . ' tabindex="' . $this->tabindex . '">' . esc_html( $data['value'] ) . '</textarea>' . "\n"; 
  1985.  
  1986. $r .= "\t" . '</label>' . "\n"; 
  1987.  
  1988. echo $r; 
  1989.  
  1990. /** 
  1991. * Prints a select form element populated with options. 
  1992. * @param $key string The key of the data to populate the element with. 
  1993. * @return void 
  1994. **/ 
  1995. function select( $key ) 
  1996. $data = $this->data[$this->step]['form'][$key]; 
  1997.  
  1998. $class = ''; 
  1999. $classes = array( 'for-select' ); 
  2000. if ( isset( $data['note'] ) ) { 
  2001. $classes[] = 'has-note'; 
  2002. if ( isset( $data['label'] ) ) { 
  2003. $classes[] = 'has-label'; 
  2004. if ( count( $classes ) ) { 
  2005. $class = ' class="' . join( ' ', $classes ) . '"'; 
  2006.  
  2007. $r = "\t" . '<label id="label-' . esc_attr( $key ) . '"' . $class . ' for="' . esc_attr( $key ) . '">' . "\n"; 
  2008.  
  2009. if ( isset( $data['label'] ) ) { 
  2010. $r .= "\t\t" . '<span>' . $data['label'] . '</span>' . "\n"; 
  2011.  
  2012. if ( isset( $data['options'] ) ) { 
  2013. $r .= "\t\t" . '<select id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '"'; 
  2014. if ( isset( $data['onchange'] ) ) { 
  2015. $r .= ' onchange="' . esc_attr( $data['onchange'] ) . '"'; 
  2016. $this->tabindex++; 
  2017. $r .= ' tabindex="' . $this->tabindex . '">' . "\n"; 
  2018.  
  2019. foreach ( $data['options'] as $value => $display ) { 
  2020. if ( $data['value'] == $value ) { 
  2021. $selected = ' selected="selected"'; 
  2022. } else { 
  2023. $selected = ''; 
  2024.  
  2025. $r .= "\t\t\t" . '<option value="' . esc_attr( $value ) . '"' . $selected . '>' . esc_html( $display ) . '</option>' . "\n"; 
  2026.  
  2027. $r .= "\t\t" . '</select>'; 
  2028.  
  2029. if ( isset( $data['note'] ) ) { 
  2030. $r .= "\t\t" . '<a class="note-toggle" href="javascript:void(0);" onclick="toggleNote(\'note-' . esc_attr( $key ) . '\');">?</a>' . "\n"; 
  2031. $r .= "\t\t" . '<p id="note-' . esc_attr( $key ) . '" class="note" style="display:none">' . $data['note'] . '</p>' . "\n"; 
  2032.  
  2033. $r .= "\t\t" . '<div class="clear"></div>' . "\n"; 
  2034. $r .= "\t" . '</label>' . "\n"; 
  2035.  
  2036. echo $r; 
  2037.  
  2038. /** 
  2039. * Prints an appropriate language selection form element if there are any available. 
  2040. * @return void 
  2041. **/ 
  2042. function select_language() 
  2043. if ( count( $this->languages ) > 1 ) { 
  2044. $this->data[1]['form']['bb_lang']['value'] = $this->language; 
  2045. $this->data[1]['form']['bb_lang']['options'] = $this->languages; 
  2046. $this->select( 'bb_lang' ); 
  2047. } else { 
  2048. $this->data[1]['form']['bb_lang']['value'] = 'en_US'; 
  2049. $this->input_hidden( 'bb_lang' ); 
  2050.  
  2051. /** 
  2052. * Prints an input checkbox which controls display of an optional section of settings. 
  2053. * @param string $key The identifier of the area to be toggled. 
  2054. * @return void 
  2055. **/ 
  2056. function input_toggle( $key ) 
  2057. $data = $this->data[$this->step]['form'][$key]; 
  2058.  
  2059. $class = ''; 
  2060. $classes = array( 'for-toggle' ); 
  2061. if ( isset( $data['note'] ) ) { 
  2062. $classes[] = 'has-note'; 
  2063. if ( isset( $data['label'] ) ) { 
  2064. $classes[] = 'has-label'; 
  2065.  
  2066. $onclick = 'toggleBlock(this, \'' . esc_js( $key . '_target' ) . '\' );'; 
  2067. if ( isset( $data['toggle_value'] ) ) { 
  2068. $onclick .= ' toggleValue(this, \'' . esc_js( $data['toggle_value']['target'] ) . '\', \'' . esc_js( $data['toggle_value']['off_value'] ) . '\', \'' . esc_js( $data['toggle_value']['on_value'] ) . '\' );'; 
  2069.  
  2070. $checked = $data['checked'] ? ' ' . trim( $data['checked'] ) : ''; 
  2071.  
  2072. if ( isset( $this->strings[$this->step]['form_errors'][$key] ) ) { 
  2073. $classes[] = 'error'; 
  2074. if ( count( $classes ) ) { 
  2075. $class = ' class="' . join( ' ', $classes ) . '"'; 
  2076.  
  2077. $r = "\t" . '<label id="label-' . esc_attr( $key ) . '"' . $class . ' for="' . esc_attr( $key ) . '">' . "\n"; 
  2078.  
  2079. $r .= "\t\t" . '<span>' . "\n"; 
  2080. $this->tabindex++; 
  2081. $r .= "\t\t\t" . '<input type="checkbox" id="' . esc_attr( $key ) . '" name="' . esc_attr( $key ) . '" class="checkbox" onclick="' . esc_attr( $onclick ) . '"' . $checked . ' value="1" tabindex="' . $this->tabindex . '" />' . "\n"; 
  2082. if ( isset( $data['label'] ) ) { 
  2083. $r .= "\t\t\t" . $data['label'] . "\n"; 
  2084. $r .= "\t\t" . '</span>' . "\n"; 
  2085.  
  2086. if ( isset( $data['note'] ) ) { 
  2087. $r .= "\t\t" . '<a class="note-toggle" href="javascript:void(0);" onclick="toggleNote(\'note-' . esc_attr( $key ) . '\');">?</a>' . "\n"; 
  2088. $r .= "\t\t" . '<p id="note-' . esc_attr( $key ) . '" class="note" style="display:none">' . $data['note'] . '</p>' . "\n"; 
  2089.  
  2090. $r .= "\t\t" . '<div class="clear"></div>' . "\n"; 
  2091. $r .= "\t" . '</label>' . "\n"; 
  2092.  
  2093. echo $r; 
  2094.  
  2095. /** 
  2096. * Prints the input buttons which post each step and optionally go back a step. 
  2097. * @param string $forward The HTML element ID of the forward button. 
  2098. * @param string $back Optional. The HTML element ID of the back button. 
  2099. * @return void 
  2100. **/ 
  2101. function input_buttons( $forward, $back = false, $step = false ) 
  2102. $data_back = $back ? $this->data[$this->step]['form'][$back] : false; 
  2103. $data_forward = $this->data[$this->step]['form'][$forward]; 
  2104.  
  2105. $r = '<fieldset class="buttons">' . "\n"; 
  2106.  
  2107. if ( !$step ) { 
  2108. $step = $this->step; 
  2109. $r .= "\t" . '<input type="hidden" id="step" name="step" value="' . (int) $step . '" />' . "\n"; 
  2110.  
  2111. if ( $back) { 
  2112. $r .= "\t" . '<label id="label-' . esc_attr( $back ) . '" for="' . esc_attr( $back ) . '" class="back">' . "\n"; 
  2113. $this->tabindex++; 
  2114. $r .= "\t\t" . '<input type="submit" id="' . esc_attr( $back ) . '" name="' . esc_attr( $back ) . '" class="button" value="' . esc_attr( $data_back['value'] ) . '" tabindex="' . $this->tabindex . '" />' . "\n"; 
  2115. $r .= "\t" . '</label>' . "\n"; 
  2116.  
  2117. $r .= "\t" . '<label id="label-' . esc_attr( $forward ) . '" for="' . esc_attr( $forward ) . '" class="forward">' . "\n"; 
  2118. $this->tabindex++; 
  2119. $r .= "\t\t" . '<input type="submit" id="' . esc_attr( $forward ) . '" name="' . esc_attr( $forward ) . '" class="button" value="' . esc_attr( $data_forward['value'] ) . '" tabindex="' . $this->tabindex . '" />' . "\n"; 
  2120. $r .= "\t" . '</label>' . "\n"; 
  2121.  
  2122. $r .= '</fieldset>' . "\n"; 
  2123.  
  2124. echo $r; 
  2125.  
  2126. /** 
  2127. * Prints hidden input elements containing the data inputted in a given step. 
  2128. * @param integer $step Optional. The number of the step whose hidden inputs should be printed. 
  2129. * @return void 
  2130. **/ 
  2131. function hidden_step_inputs( $step = false ) 
  2132. if ( !$step ) { 
  2133. $step = $this->step; 
  2134. } elseif ( $step !== $this->step ) { 
  2135. $this->inject_form_values_into_data( $step ); 
  2136.  
  2137. $data = $this->data[$step]['form']; 
  2138.  
  2139. $r = '<fieldset>' . "\n"; 
  2140.  
  2141. foreach ( $data as $key => $value ) { 
  2142. if ( 'forward_' !== substr( $key, 0, 8 ) && 'back_' !== substr( $key, 0, 5 ) ) { 
  2143. $r .= "\t" . '<input type="hidden" name="' . esc_attr( $key ) . '" value="' . esc_attr( $value['value'] ) . '" />' . "\n"; 
  2144.  
  2145. $r .= '</fieldset>' . "\n"; 
  2146.  
  2147. echo $r; 
  2148.  
  2149. /** 
  2150. * Rewrites the admin user input into a select element containing existing WordPress administrators. 
  2151. * @return boolean True if the select element was created, otherwise false. 
  2152. **/ 
  2153. function populate_keymaster_user_login_from_user_tables() 
  2154. $data =& $this->data[3]['form']['keymaster_user_login']; 
  2155.  
  2156. // Get the existing WordPress admin users 
  2157.  
  2158. // Setup variables and constants if available 
  2159. global $bb; 
  2160. if ( !empty( $this->data[2]['form']['wp_table_prefix']['value'] ) ) { 
  2161. $bb->wp_table_prefix = $this->data[2]['form']['wp_table_prefix']['value']; 
  2162. if ( !empty( $this->data[2]['form']['user_bbdb_name']['value'] ) ) { 
  2163. $bb->user_bbdb_name = $this->data[2]['form']['user_bbdb_name']['value']; 
  2164. if ( !empty( $this->data[2]['form']['user_bbdb_user']['value'] ) ) { 
  2165. $bb->user_bbdb_user = $this->data[2]['form']['user_bbdb_user']['value']; 
  2166. if ( !empty( $this->data[2]['form']['user_bbdb_password']['value'] ) ) { 
  2167. $bb->user_bbdb_password = $this->data[2]['form']['user_bbdb_password']['value']; 
  2168. if ( !empty( $this->data[2]['form']['user_bbdb_host']['value'] ) ) { 
  2169. $bb->user_bbdb_host = $this->data[2]['form']['user_bbdb_host']['value']; 
  2170. if ( !empty( $this->data[2]['form']['user_bbdb_charset']['value'] ) ) { 
  2171. $bb->user_bbdb_charset = preg_replace( '/[^a-z0-9_-]/i', '', $this->data[2]['form']['user_bbdb_charset']['value'] ); 
  2172. if ( !empty( $this->data[2]['form']['user_bbdb_collate']['value'] ) ) { 
  2173. $bb->user_bbdb_charset = preg_replace( '/[^a-z0-9_-]/i', '', $this->data[2]['form']['user_bbdb_collate']['value'] ); 
  2174. if ( !empty( $this->data[2]['form']['custom_user_table']['value'] ) ) { 
  2175. $bb->custom_user_table = preg_replace( '/[^a-z0-9_-]/i', '', $this->data[2]['form']['custom_user_table']['value'] ); 
  2176. if ( !empty( $this->data[2]['form']['custom_user_meta_table']['value'] ) ) { 
  2177. $bb->custom_user_meta_table = preg_replace( '/[^a-z0-9_-]/i', '', $this->data[2]['form']['custom_user_meta_table']['value'] ); 
  2178.  
  2179. global $bbdb; 
  2180. global $bb_table_prefix; 
  2181.  
  2182. // Resolve the custom user tables for bpdb 
  2183. bb_set_custom_user_tables(); 
  2184.  
  2185. if ( isset( $bb->custom_databases ) && isset( $bb->custom_databases['user'] ) ) { 
  2186. $bbdb->add_db_server( 'user', $bb->custom_databases['user'] ); 
  2187.  
  2188. // Add custom tables if required 
  2189. if ( isset( $bb->custom_tables['users'] ) || isset( $bb->custom_tables['usermeta'] ) ) { 
  2190. $bbdb->tables = array_merge( $bbdb->tables, $bb->custom_tables ); 
  2191. if ( is_wp_error( $bbdb->set_prefix( $bb_table_prefix ) ) ) { 
  2192. die( __( 'Your user table prefix may only contain letters, numbers and underscores.' ) ); 
  2193.  
  2194. $bb_keymaster_meta_key = $bbdb->escape( $bb_table_prefix . 'capabilities' ); 
  2195. $wp_administrator_meta_key = $bbdb->escape( $bb->wp_table_prefix . 'capabilities' ); 
  2196. if ( !empty( $this->data[2]['form']['wordpress_mu_primary_blog_id']['value'] ) ) { 
  2197. $wp_administrator_meta_key = $bb->wp_table_prefix . $this->data[2]['form']['wordpress_mu_primary_blog_id']['value'] . '_capabilities'; 
  2198.  
  2199. $keymaster_query = <<<EOQ 
  2200. SELECT 
  2201. user_login, user_email, display_name 
  2202. FROM 
  2203. $bbdb->users 
  2204. LEFT JOIN 
  2205. $bbdb->usermeta ON 
  2206. $bbdb->users.ID = $bbdb->usermeta.user_id 
  2207. WHERE 
  2208. meta_key = '$wp_administrator_meta_key' AND 
  2209. meta_value LIKE '%administrator%' 
  2210. ) OR 
  2211. meta_key = '$bb_keymaster_meta_key' AND 
  2212. meta_value LIKE '%keymaster%' 
  2213. ) AND 
  2214. user_email IS NOT NULL AND 
  2215. user_email != '' 
  2216. ORDER BY 
  2217. user_login; 
  2218. EOQ; 
  2219. $bbdb->suppress_errors(); 
  2220.  
  2221. if ( $keymasters = $bbdb->get_results( $keymaster_query, ARRAY_A ) ) { 
  2222.  
  2223. $bbdb->suppress_errors( false ); 
  2224.  
  2225. if ( count( $keymasters ) ) { 
  2226. $email_maps = ''; 
  2227. $data['options'] = array(); 
  2228. $data['onchange'] = 'changeKeymasterEmail( this, \'keymaster_user_email\' );'; 
  2229. $data['note'] = __( 'Please select an existing bbPress Keymaster or WordPress administrator.' ); 
  2230.  
  2231. $data['options'][''] = ''; 
  2232. foreach ( $keymasters as $keymaster ) { 
  2233. $email_maps .= 'emailMap[\'' . $keymaster['user_login'] . '\'] = \'' . $keymaster['user_email'] . '\';' . "\n\t\t\t\t\t\t\t\t"; 
  2234. if ( $keymaster['display_name'] ) { 
  2235. $data['options'][$keymaster['user_login']] = $keymaster['user_login'] . ' (' . $keymaster['display_name'] . ')'; 
  2236. } else { 
  2237. $data['options'][$keymaster['user_login']] = $keymaster['user_login']; 
  2238.  
  2239. $this->strings[3]['scripts']['changeKeymasterEmail'] = <<<EOS 
  2240. <script type="text/javascript" charset="utf-8"> 
  2241. function changeKeymasterEmail( selectObj, target ) { 
  2242. var emailMap = new Array; 
  2243. emailMap[''] = ''; 
  2244. $email_maps 
  2245. var targetObj = document.getElementById( target ); 
  2246. var selectedAdmin = selectObj.options[selectObj.selectedIndex].value; 
  2247. targetObj.value = emailMap[selectedAdmin]; 
  2248. </script> 
  2249. EOS; 
  2250.  
  2251. $this->data[3]['form']['keymaster_user_type']['value'] = 'old'; 
  2252.  
  2253. return true; 
  2254.  
  2255. $bbdb->suppress_errors( false ); 
  2256.  
  2257. return false; 
  2258.  
  2259. /** 
  2260. * Sends HTTP headers and prints the page header. 
  2261. * @return void 
  2262. **/ 
  2263. function header() 
  2264. nocache_headers(); 
  2265.  
  2266. bb_install_header( $this->strings[$this->step]['title'], $this->strings[$this->step]['h1'], true ); 
  2267.  
  2268. /** 
  2269. * Prints the page footer. 
  2270. * @return void 
  2271. **/ 
  2272. function footer() 
  2273. bb_install_footer(); 
  2274.  
  2275. /** 
  2276. * Prints the returned messages for the current step. 
  2277. * @return void 
  2278. **/ 
  2279. function messages() 
  2280. if ( isset( $this->strings[$this->step]['messages'] ) ) { 
  2281. $messages = $this->strings[$this->step]['messages']; 
  2282.  
  2283. // This count works as long as $messages is only two-dimensional 
  2284. $count = ( count( $messages, COUNT_RECURSIVE ) - count( $messages ) ); 
  2285. $i = 0; 
  2286. $r = ''; 
  2287. foreach ( $messages as $type => $paragraphs ) { 
  2288. $class = $type ? $type : ''; 
  2289.  
  2290. foreach ( $paragraphs as $paragraph ) { 
  2291. $i++; 
  2292. $class = ( $i === $count ) ? ( $class . ' last' ) : $class; 
  2293. $r .= '<p class="' . esc_attr( $class ) . '">' . $paragraph . '</p>' . "\n"; 
  2294. echo $r; 
  2295.  
  2296. /** 
  2297. * Prints the introduction paragraphs for the current step. 
  2298. * @return void 
  2299. **/ 
  2300. function intro() 
  2301. if ( 'incomplete' == $this->step_status[$this->step] && isset( $this->strings[$this->step]['intro'] ) ) { 
  2302. $messages = $this->strings[$this->step]['intro']; 
  2303. $count = count( $messages ); 
  2304. $i = 0; 
  2305. $r = ''; 
  2306. foreach ( $messages as $paragraph ) { 
  2307. $i++; 
  2308. $class = ( $i === $count ) ? 'intro last' : 'intro'; 
  2309. $r .= '<p class="' . $class . '">' . $paragraph . '</p>' . "\n"; 
  2310. echo $r; 
  2311.  
  2312. /** 
  2313. * Prints the standard header for each step. 
  2314. * @param integer $step The number of the step whose header should be printed. 
  2315. * @return void 
  2316. **/ 
  2317. function step_header( $step ) 
  2318. $class = ( $step == $this->step ) ? 'open' : 'closed'; 
  2319.  
  2320. $r = '<div id="' . esc_attr( 'step' . $step ) . '" class="' . $class . '">' . "\n"; 
  2321. $r .= '<h2 class="' . $class . '">' . $this->strings[$step]['h2'] . '</h2>' . "\n"; 
  2322. $r .= '<div>' . "\n"; 
  2323.  
  2324. if ( $step < $this->step && $this->strings[$step]['status'] ) { 
  2325. $r .= '<p class="status">' . $this->strings[$step]['status'] . '</p>' . "\n"; 
  2326.  
  2327. echo $r; 
  2328.  
  2329. if ( $step == $this->step ) { 
  2330. $this->intro(); 
  2331.  
  2332. $this->tabindex = 0; 
  2333.  
  2334. /** 
  2335. * Prints the standard step footer. 
  2336. * @return void 
  2337. **/ 
  2338. function step_footer() 
  2339. $r = '</div></div>' . "\n"; 
  2340.  
  2341. echo $r; 
  2342. } // END class BB_Install