| webmaster@1 | 1 <?php | 
| webmaster@9 | 2 // $Id: install.php,v 1.113.2.5 2008/07/18 07:17:44 dries Exp $ | 
| webmaster@1 | 3 | 
| webmaster@1 | 4 require_once './includes/install.inc'; | 
| webmaster@1 | 5 | 
| webmaster@1 | 6 define('MAINTENANCE_MODE', 'install'); | 
| webmaster@1 | 7 | 
| webmaster@1 | 8 /** | 
| webmaster@1 | 9  * The Drupal installation happens in a series of steps. We begin by verifying | 
| webmaster@1 | 10  * that the current environment meets our minimum requirements. We then go | 
| webmaster@1 | 11  * on to verify that settings.php is properly configured. From there we | 
| webmaster@1 | 12  * connect to the configured database and verify that it meets our minimum | 
| webmaster@1 | 13  * requirements. Finally we can allow the user to select an installation | 
| webmaster@1 | 14  * profile and complete the installation process. | 
| webmaster@1 | 15  * | 
| webmaster@1 | 16  * @param $phase | 
| webmaster@1 | 17  *   The installation phase we should proceed to. | 
| webmaster@1 | 18  */ | 
| webmaster@1 | 19 function install_main() { | 
| webmaster@1 | 20   require_once './includes/bootstrap.inc'; | 
| webmaster@1 | 21   drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION); | 
| webmaster@1 | 22 | 
| webmaster@1 | 23   // This must go after drupal_bootstrap(), which unsets globals! | 
| webmaster@1 | 24   global $profile, $install_locale, $conf; | 
| webmaster@1 | 25 | 
| webmaster@1 | 26   require_once './modules/system/system.install'; | 
| webmaster@1 | 27   require_once './includes/file.inc'; | 
| webmaster@1 | 28 | 
| webmaster@1 | 29   // Ensure correct page headers are sent (e.g. caching) | 
| webmaster@1 | 30   drupal_page_header(); | 
| webmaster@1 | 31 | 
| webmaster@1 | 32   // Set up $language, so t() caller functions will still work. | 
| webmaster@1 | 33   drupal_init_language(); | 
| webmaster@1 | 34 | 
| webmaster@1 | 35   // Load module basics (needed for hook invokes). | 
| webmaster@1 | 36   include_once './includes/module.inc'; | 
| webmaster@1 | 37   $module_list['system']['filename'] = 'modules/system/system.module'; | 
| webmaster@1 | 38   $module_list['filter']['filename'] = 'modules/filter/filter.module'; | 
| webmaster@1 | 39   module_list(TRUE, FALSE, FALSE, $module_list); | 
| webmaster@1 | 40   drupal_load('module', 'system'); | 
| webmaster@1 | 41   drupal_load('module', 'filter'); | 
| webmaster@1 | 42 | 
| webmaster@1 | 43   // Set up theme system for the maintenance page. | 
| webmaster@1 | 44   drupal_maintenance_theme(); | 
| webmaster@1 | 45 | 
| webmaster@1 | 46   // Check existing settings.php. | 
| webmaster@1 | 47   $verify = install_verify_settings(); | 
| webmaster@1 | 48 | 
| webmaster@1 | 49   if ($verify) { | 
| webmaster@1 | 50     // Since we have a database connection, we use the normal cache system. | 
| webmaster@1 | 51     // This is important, as the installer calls into the Drupal system for | 
| webmaster@1 | 52     // the clean URL checks, so we should maintain the cache properly. | 
| webmaster@1 | 53     require_once './includes/cache.inc'; | 
| webmaster@1 | 54     $conf['cache_inc'] = './includes/cache.inc'; | 
| webmaster@1 | 55 | 
| webmaster@1 | 56     // Establish a connection to the database. | 
| webmaster@1 | 57     require_once './includes/database.inc'; | 
| webmaster@1 | 58     db_set_active(); | 
| webmaster@1 | 59 | 
| webmaster@1 | 60     // Check if Drupal is installed. | 
| webmaster@1 | 61     $task = install_verify_drupal(); | 
| webmaster@1 | 62     if ($task == 'done') { | 
| webmaster@1 | 63       install_already_done_error(); | 
| webmaster@1 | 64     } | 
| webmaster@1 | 65   } | 
| webmaster@1 | 66   else { | 
| webmaster@1 | 67     // Since no persistent storage is available yet, and functions that check | 
| webmaster@1 | 68     // for cached data will fail, we temporarily replace the normal cache | 
| webmaster@1 | 69     // system with a stubbed-out version that short-circuits the actual | 
| webmaster@1 | 70     // caching process and avoids any errors. | 
| webmaster@1 | 71     require_once './includes/cache-install.inc'; | 
| webmaster@1 | 72     $conf['cache_inc'] = './includes/cache-install.inc'; | 
| webmaster@1 | 73 | 
| webmaster@1 | 74     $task = NULL; | 
| webmaster@1 | 75   } | 
| webmaster@1 | 76 | 
| webmaster@1 | 77   // Decide which profile to use. | 
| webmaster@1 | 78   if (!empty($_GET['profile'])) { | 
| webmaster@1 | 79     $profile = preg_replace('/[^a-zA-Z_0-9]/', '', $_GET['profile']); | 
| webmaster@1 | 80   } | 
| webmaster@1 | 81   elseif ($profile = install_select_profile()) { | 
| webmaster@1 | 82     install_goto("install.php?profile=$profile"); | 
| webmaster@1 | 83   } | 
| webmaster@1 | 84   else { | 
| webmaster@1 | 85     install_no_profile_error(); | 
| webmaster@1 | 86   } | 
| webmaster@1 | 87 | 
| webmaster@1 | 88   // Load the profile. | 
| webmaster@1 | 89   require_once "./profiles/$profile/$profile.profile"; | 
| webmaster@1 | 90 | 
| webmaster@1 | 91   // Locale selection | 
| webmaster@1 | 92   if (!empty($_GET['locale'])) { | 
| webmaster@1 | 93     $install_locale = preg_replace('/[^a-zA-Z_0-9]/', '', $_GET['locale']); | 
| webmaster@1 | 94   } | 
| webmaster@1 | 95   elseif (($install_locale = install_select_locale($profile)) !== FALSE) { | 
| webmaster@1 | 96     install_goto("install.php?profile=$profile&locale=$install_locale"); | 
| webmaster@1 | 97   } | 
| webmaster@1 | 98 | 
| webmaster@1 | 99   // Tasks come after the database is set up | 
| webmaster@1 | 100   if (!$task) { | 
| webmaster@7 | 101     global $db_url; | 
| webmaster@7 | 102 | 
| webmaster@7 | 103     if (!$verify && !empty($db_url)) { | 
| webmaster@7 | 104       // Do not install over a configured settings.php. | 
| webmaster@7 | 105       install_already_done_error(); | 
| webmaster@7 | 106     } | 
| webmaster@7 | 107 | 
| webmaster@1 | 108     // Check the installation requirements for Drupal and this profile. | 
| webmaster@1 | 109     install_check_requirements($profile, $verify); | 
| webmaster@1 | 110 | 
| webmaster@1 | 111     // Verify existence of all required modules. | 
| webmaster@1 | 112     $modules = drupal_verify_profile($profile, $install_locale); | 
| webmaster@1 | 113 | 
| webmaster@1 | 114     // If any error messages are set now, it means a requirement problem. | 
| webmaster@1 | 115     $messages = drupal_set_message(); | 
| webmaster@1 | 116     if (!empty($messages['error'])) { | 
| webmaster@1 | 117       install_task_list('requirements'); | 
| webmaster@1 | 118       drupal_set_title(st('Requirements problem')); | 
| webmaster@1 | 119       print theme('install_page', ''); | 
| webmaster@1 | 120       exit; | 
| webmaster@1 | 121     } | 
| webmaster@1 | 122 | 
| webmaster@1 | 123     // Change the settings.php information if verification failed earlier. | 
| webmaster@1 | 124     // Note: will trigger a redirect if database credentials change. | 
| webmaster@1 | 125     if (!$verify) { | 
| webmaster@1 | 126       install_change_settings($profile, $install_locale); | 
| webmaster@1 | 127     } | 
| webmaster@1 | 128 | 
| webmaster@1 | 129     // Install system.module. | 
| webmaster@1 | 130     drupal_install_system(); | 
| webmaster@1 | 131     // Save the list of other modules to install for the 'profile-install' | 
| webmaster@1 | 132     // task. variable_set() can be used now that system.module is installed | 
| webmaster@1 | 133     // and drupal is bootstrapped. | 
| webmaster@1 | 134     variable_set('install_profile_modules', array_diff($modules, array('system'))); | 
| webmaster@1 | 135   } | 
| webmaster@1 | 136 | 
| webmaster@1 | 137   // The database is set up, turn to further tasks. | 
| webmaster@1 | 138   install_tasks($profile, $task); | 
| webmaster@1 | 139 } | 
| webmaster@1 | 140 | 
| webmaster@1 | 141 /** | 
| webmaster@1 | 142  * Verify if Drupal is installed. | 
| webmaster@1 | 143  */ | 
| webmaster@1 | 144 function install_verify_drupal() { | 
| webmaster@1 | 145   // Read the variable manually using the @ so we don't trigger an error if it fails. | 
| webmaster@1 | 146   $result = @db_query("SELECT value FROM {variable} WHERE name = '%s'", 'install_task'); | 
| webmaster@1 | 147   if ($result) { | 
| webmaster@1 | 148     return unserialize(db_result($result)); | 
| webmaster@1 | 149   } | 
| webmaster@1 | 150 } | 
| webmaster@1 | 151 | 
| webmaster@1 | 152 /** | 
| webmaster@1 | 153  * Verify existing settings.php | 
| webmaster@1 | 154  */ | 
| webmaster@1 | 155 function install_verify_settings() { | 
| webmaster@1 | 156   global $db_prefix, $db_type, $db_url; | 
| webmaster@1 | 157 | 
| webmaster@1 | 158   // Verify existing settings (if any). | 
| webmaster@1 | 159   if (!empty($db_url)) { | 
| webmaster@1 | 160     // We need this because we want to run form_get_errors. | 
| webmaster@1 | 161     include_once './includes/form.inc'; | 
| webmaster@1 | 162 | 
| webmaster@1 | 163     $url = parse_url(is_array($db_url) ? $db_url['default'] : $db_url); | 
| webmaster@1 | 164     $db_user = urldecode($url['user']); | 
| webmaster@1 | 165     $db_pass = isset($url['pass']) ? urldecode($url['pass']) : NULL; | 
| webmaster@1 | 166     $db_host = urldecode($url['host']); | 
| webmaster@1 | 167     $db_port = isset($url['port']) ? urldecode($url['port']) : ''; | 
| webmaster@1 | 168     $db_path = ltrim(urldecode($url['path']), '/'); | 
| webmaster@1 | 169     $settings_file = './'. conf_path(FALSE, TRUE) .'/settings.php'; | 
| webmaster@1 | 170 | 
| webmaster@1 | 171     $form_state = array(); | 
| webmaster@1 | 172     _install_settings_form_validate($db_prefix, $db_type, $db_user, $db_pass, $db_host, $db_port, $db_path, $settings_file, $form_state); | 
| webmaster@1 | 173     if (!form_get_errors()) { | 
| webmaster@1 | 174       return TRUE; | 
| webmaster@1 | 175     } | 
| webmaster@1 | 176   } | 
| webmaster@1 | 177   return FALSE; | 
| webmaster@1 | 178 } | 
| webmaster@1 | 179 | 
| webmaster@1 | 180 /** | 
| webmaster@1 | 181  * Configure and rewrite settings.php. | 
| webmaster@1 | 182  */ | 
| webmaster@1 | 183 function install_change_settings($profile = 'default', $install_locale = '') { | 
| webmaster@1 | 184   global $db_url, $db_type, $db_prefix; | 
| webmaster@1 | 185 | 
| webmaster@1 | 186   $url = parse_url(is_array($db_url) ? $db_url['default'] : $db_url); | 
| webmaster@1 | 187   $db_user = isset($url['user']) ? urldecode($url['user']) : ''; | 
| webmaster@1 | 188   $db_pass = isset($url['pass']) ? urldecode($url['pass']) : ''; | 
| webmaster@1 | 189   $db_host = isset($url['host']) ? urldecode($url['host']) : ''; | 
| webmaster@1 | 190   $db_port = isset($url['port']) ? urldecode($url['port']) : ''; | 
| webmaster@1 | 191   $db_path = ltrim(urldecode($url['path']), '/'); | 
| webmaster@1 | 192   $conf_path = './'. conf_path(FALSE, TRUE); | 
| webmaster@1 | 193   $settings_file = $conf_path .'/settings.php'; | 
| webmaster@1 | 194 | 
| webmaster@1 | 195   // We always need this because we want to run form_get_errors. | 
| webmaster@1 | 196   include_once './includes/form.inc'; | 
| webmaster@1 | 197   install_task_list('database'); | 
| webmaster@1 | 198 | 
| webmaster@1 | 199   $output = drupal_get_form('install_settings_form', $profile, $install_locale, $settings_file, $db_url, $db_type, $db_prefix, $db_user, $db_pass, $db_host, $db_port, $db_path); | 
| webmaster@1 | 200   drupal_set_title(st('Database configuration')); | 
| webmaster@1 | 201   print theme('install_page', $output); | 
| webmaster@1 | 202   exit; | 
| webmaster@1 | 203 } | 
| webmaster@1 | 204 | 
| webmaster@1 | 205 | 
| webmaster@1 | 206 /** | 
| webmaster@1 | 207  * Form API array definition for install_settings. | 
| webmaster@1 | 208  */ | 
| webmaster@1 | 209 function install_settings_form(&$form_state, $profile, $install_locale, $settings_file, $db_url, $db_type, $db_prefix, $db_user, $db_pass, $db_host, $db_port, $db_path) { | 
| webmaster@1 | 210   if (empty($db_host)) { | 
| webmaster@1 | 211     $db_host = 'localhost'; | 
| webmaster@1 | 212   } | 
| webmaster@1 | 213   $db_types = drupal_detect_database_types(); | 
| webmaster@1 | 214 | 
| webmaster@1 | 215   // If both 'mysql' and 'mysqli' are available, we disable 'mysql': | 
| webmaster@1 | 216   if (isset($db_types['mysqli'])) { | 
| webmaster@1 | 217     unset($db_types['mysql']); | 
| webmaster@1 | 218   } | 
| webmaster@1 | 219 | 
| webmaster@1 | 220   if (count($db_types) == 0) { | 
| webmaster@1 | 221     $form['no_db_types'] = array( | 
| webmaster@1 | 222       '#value' => st('Your web server does not appear to support any common database types. Check with your hosting provider to see if they offer any databases that <a href="@drupal-databases">Drupal supports</a>.', array('@drupal-databases' => 'http://drupal.org/node/270#database')), | 
| webmaster@1 | 223     ); | 
| webmaster@1 | 224   } | 
| webmaster@1 | 225   else { | 
| webmaster@1 | 226     $form['basic_options'] = array( | 
| webmaster@1 | 227       '#type' => 'fieldset', | 
| webmaster@1 | 228       '#title' => st('Basic options'), | 
| webmaster@1 | 229       '#description' => '<p>'. st('To set up your @drupal database, enter the following information.', array('@drupal' => drupal_install_profile_name())) .'</p>', | 
| webmaster@1 | 230     ); | 
| webmaster@1 | 231 | 
| webmaster@1 | 232     if (count($db_types) > 1) { | 
| webmaster@1 | 233       $form['basic_options']['db_type'] = array( | 
| webmaster@1 | 234         '#type' => 'radios', | 
| webmaster@1 | 235         '#title' => st('Database type'), | 
| webmaster@1 | 236         '#required' => TRUE, | 
| webmaster@1 | 237         '#options' => $db_types, | 
| webmaster@1 | 238         '#default_value' => ($db_type ? $db_type : current($db_types)), | 
| webmaster@1 | 239         '#description' => st('The type of database your @drupal data will be stored in.', array('@drupal' => drupal_install_profile_name())), | 
| webmaster@1 | 240       ); | 
| webmaster@1 | 241       $db_path_description = st('The name of the database your @drupal data will be stored in. It must exist on your server before @drupal can be installed.', array('@drupal' => drupal_install_profile_name())); | 
| webmaster@1 | 242     } | 
| webmaster@1 | 243     else { | 
| webmaster@1 | 244       if (count($db_types) == 1) { | 
| webmaster@1 | 245         $db_types = array_values($db_types); | 
| webmaster@1 | 246         $form['basic_options']['db_type'] = array( | 
| webmaster@1 | 247           '#type' => 'hidden', | 
| webmaster@1 | 248           '#value' => $db_types[0], | 
| webmaster@1 | 249         ); | 
| webmaster@1 | 250         $db_path_description = st('The name of the %db_type database your @drupal data will be stored in. It must exist on your server before @drupal can be installed.', array('%db_type' => $db_types[0], '@drupal' => drupal_install_profile_name())); | 
| webmaster@1 | 251       } | 
| webmaster@1 | 252     } | 
| webmaster@1 | 253 | 
| webmaster@1 | 254     // Database name | 
| webmaster@1 | 255     $form['basic_options']['db_path'] = array( | 
| webmaster@1 | 256       '#type' => 'textfield', | 
| webmaster@1 | 257       '#title' => st('Database name'), | 
| webmaster@1 | 258       '#default_value' => $db_path, | 
| webmaster@1 | 259       '#size' => 45, | 
| webmaster@1 | 260       '#maxlength' => 45, | 
| webmaster@1 | 261       '#required' => TRUE, | 
| webmaster@1 | 262       '#description' => $db_path_description | 
| webmaster@1 | 263     ); | 
| webmaster@1 | 264 | 
| webmaster@1 | 265     // Database username | 
| webmaster@1 | 266     $form['basic_options']['db_user'] = array( | 
| webmaster@1 | 267       '#type' => 'textfield', | 
| webmaster@1 | 268       '#title' => st('Database username'), | 
| webmaster@1 | 269       '#default_value' => $db_user, | 
| webmaster@1 | 270       '#size' => 45, | 
| webmaster@1 | 271       '#maxlength' => 45, | 
| webmaster@1 | 272       '#required' => TRUE, | 
| webmaster@1 | 273     ); | 
| webmaster@1 | 274 | 
| webmaster@1 | 275     // Database username | 
| webmaster@1 | 276     $form['basic_options']['db_pass'] = array( | 
| webmaster@1 | 277       '#type' => 'password', | 
| webmaster@1 | 278       '#title' => st('Database password'), | 
| webmaster@1 | 279       '#default_value' => $db_pass, | 
| webmaster@1 | 280       '#size' => 45, | 
| webmaster@1 | 281       '#maxlength' => 45, | 
| webmaster@1 | 282     ); | 
| webmaster@1 | 283 | 
| webmaster@1 | 284     $form['advanced_options'] = array( | 
| webmaster@1 | 285       '#type' => 'fieldset', | 
| webmaster@1 | 286       '#title' => st('Advanced options'), | 
| webmaster@1 | 287       '#collapsible' => TRUE, | 
| webmaster@1 | 288       '#collapsed' => TRUE, | 
| webmaster@1 | 289       '#description' => st("These options are only necessary for some sites. If you're not sure what you should enter here, leave the default settings or check with your hosting provider.") | 
| webmaster@1 | 290     ); | 
| webmaster@1 | 291 | 
| webmaster@1 | 292     // Database host | 
| webmaster@1 | 293     $form['advanced_options']['db_host'] = array( | 
| webmaster@1 | 294       '#type' => 'textfield', | 
| webmaster@1 | 295       '#title' => st('Database host'), | 
| webmaster@1 | 296       '#default_value' => $db_host, | 
| webmaster@1 | 297       '#size' => 45, | 
| webmaster@1 | 298       '#maxlength' => 45, | 
| webmaster@1 | 299       '#required' => TRUE, | 
| webmaster@1 | 300       '#description' => st('If your database is located on a different server, change this.'), | 
| webmaster@1 | 301     ); | 
| webmaster@1 | 302 | 
| webmaster@1 | 303     // Database port | 
| webmaster@1 | 304     $form['advanced_options']['db_port'] = array( | 
| webmaster@1 | 305       '#type' => 'textfield', | 
| webmaster@1 | 306       '#title' => st('Database port'), | 
| webmaster@1 | 307       '#default_value' => $db_port, | 
| webmaster@1 | 308       '#size' => 45, | 
| webmaster@1 | 309       '#maxlength' => 45, | 
| webmaster@1 | 310       '#description' => st('If your database server is listening to a non-standard port, enter its number.'), | 
| webmaster@1 | 311     ); | 
| webmaster@1 | 312 | 
| webmaster@1 | 313     // Table prefix | 
| webmaster@1 | 314     $prefix = ($profile == 'default') ? 'drupal_' : $profile .'_'; | 
| webmaster@1 | 315     $form['advanced_options']['db_prefix'] = array( | 
| webmaster@1 | 316       '#type' => 'textfield', | 
| webmaster@1 | 317       '#title' => st('Table prefix'), | 
| webmaster@1 | 318       '#default_value' => $db_prefix, | 
| webmaster@1 | 319       '#size' => 45, | 
| webmaster@1 | 320       '#maxlength' => 45, | 
| webmaster@1 | 321       '#description' => st('If more than one application will be sharing this database, enter a table prefix such as %prefix for your @drupal site here.', array('@drupal' => drupal_install_profile_name(), '%prefix' => $prefix)), | 
| webmaster@1 | 322     ); | 
| webmaster@1 | 323 | 
| webmaster@1 | 324     $form['save'] = array( | 
| webmaster@1 | 325       '#type' => 'submit', | 
| webmaster@1 | 326       '#value' => st('Save and continue'), | 
| webmaster@1 | 327     ); | 
| webmaster@1 | 328 | 
| webmaster@1 | 329     $form['errors'] = array(); | 
| webmaster@1 | 330     $form['settings_file'] = array('#type' => 'value', '#value' => $settings_file); | 
| webmaster@1 | 331     $form['_db_url'] = array('#type' => 'value'); | 
| webmaster@1 | 332     $form['#action'] = "install.php?profile=$profile". ($install_locale ? "&locale=$install_locale" : ''); | 
| webmaster@1 | 333     $form['#redirect'] = FALSE; | 
| webmaster@1 | 334   } | 
| webmaster@1 | 335   return $form; | 
| webmaster@1 | 336 } | 
| webmaster@1 | 337 | 
| webmaster@1 | 338 /** | 
| webmaster@1 | 339  * Form API validate for install_settings form. | 
| webmaster@1 | 340  */ | 
| webmaster@1 | 341 function install_settings_form_validate($form, &$form_state) { | 
| webmaster@1 | 342   global $db_url; | 
| webmaster@1 | 343   _install_settings_form_validate($form_state['values']['db_prefix'], $form_state['values']['db_type'], $form_state['values']['db_user'], $form_state['values']['db_pass'], $form_state['values']['db_host'], $form_state['values']['db_port'], $form_state['values']['db_path'], $form_state['values']['settings_file'], $form_state, $form); | 
| webmaster@1 | 344 } | 
| webmaster@1 | 345 | 
| webmaster@1 | 346 /** | 
| webmaster@1 | 347  * Helper function for install_settings_validate. | 
| webmaster@1 | 348  */ | 
| webmaster@1 | 349 function _install_settings_form_validate($db_prefix, $db_type, $db_user, $db_pass, $db_host, $db_port, $db_path, $settings_file, &$form_state, $form = NULL) { | 
| webmaster@1 | 350   global $db_url; | 
| webmaster@1 | 351 | 
| webmaster@1 | 352   // Verify the table prefix | 
| webmaster@1 | 353   if (!empty($db_prefix) && is_string($db_prefix) && !preg_match('/^[A-Za-z0-9_.]+$/', $db_prefix)) { | 
| webmaster@1 | 354     form_set_error('db_prefix', st('The database table prefix you have entered, %db_prefix, is invalid. The table prefix can only contain alphanumeric characters, periods, or underscores.', array('%db_prefix' => $db_prefix)), 'error'); | 
| webmaster@1 | 355   } | 
| webmaster@1 | 356 | 
| webmaster@1 | 357   if (!empty($db_port) && !is_numeric($db_port)) { | 
| webmaster@1 | 358     form_set_error('db_port', st('Database port must be a number.')); | 
| webmaster@1 | 359   } | 
| webmaster@1 | 360 | 
| webmaster@1 | 361   // Check database type | 
| webmaster@1 | 362   if (!isset($form)) { | 
| webmaster@1 | 363     $_db_url = is_array($db_url) ? $db_url['default'] : $db_url; | 
| webmaster@1 | 364     $db_type = substr($_db_url, 0, strpos($_db_url, '://')); | 
| webmaster@1 | 365   } | 
| webmaster@1 | 366   $databases = drupal_detect_database_types(); | 
| webmaster@1 | 367   if (!in_array($db_type, $databases)) { | 
| webmaster@1 | 368     form_set_error('db_type', st("In your %settings_file file you have configured @drupal to use a %db_type server, however your PHP installation currently does not support this database type.", array('%settings_file' => $settings_file, '@drupal' => drupal_install_profile_name(), '%db_type' => $db_type))); | 
| webmaster@1 | 369   } | 
| webmaster@1 | 370   else { | 
| webmaster@1 | 371     // Verify | 
| webmaster@1 | 372     $db_url = $db_type .'://'. urlencode($db_user) . ($db_pass ? ':'. urlencode($db_pass) : '') .'@'. ($db_host ? urlencode($db_host) : 'localhost') . ($db_port ? ":$db_port" : '') .'/'. urlencode($db_path); | 
| webmaster@1 | 373     if (isset($form)) { | 
| webmaster@1 | 374       form_set_value($form['_db_url'], $db_url, $form_state); | 
| webmaster@1 | 375     } | 
| webmaster@1 | 376     $success = array(); | 
| webmaster@1 | 377 | 
| webmaster@1 | 378     $function = 'drupal_test_'. $db_type; | 
| webmaster@1 | 379     if (!$function($db_url, $success)) { | 
| webmaster@1 | 380       if (isset($success['CONNECT'])) { | 
| webmaster@1 | 381         form_set_error('db_type', st('In order for Drupal to work, and to continue with the installation process, you must resolve all permission issues reported above. We were able to verify that we have permission for the following commands: %commands. For more help with configuring your database server, see the <a href="http://drupal.org/node/258">Installation and upgrading handbook</a>. If you are unsure what any of this means you should probably contact your hosting provider.', array('%commands' => implode($success, ', ')))); | 
| webmaster@1 | 382       } | 
| webmaster@1 | 383       else { | 
| webmaster@1 | 384         form_set_error('db_type', ''); | 
| webmaster@1 | 385       } | 
| webmaster@1 | 386     } | 
| webmaster@1 | 387   } | 
| webmaster@1 | 388 } | 
| webmaster@1 | 389 | 
| webmaster@1 | 390 /** | 
| webmaster@1 | 391  * Form API submit for install_settings form. | 
| webmaster@1 | 392  */ | 
| webmaster@1 | 393 function install_settings_form_submit($form, &$form_state) { | 
| webmaster@1 | 394   global $profile, $install_locale; | 
| webmaster@1 | 395 | 
| webmaster@1 | 396   // Update global settings array and save | 
| webmaster@1 | 397   $settings['db_url'] = array( | 
| webmaster@1 | 398     'value'    => $form_state['values']['_db_url'], | 
| webmaster@1 | 399     'required' => TRUE, | 
| webmaster@1 | 400   ); | 
| webmaster@1 | 401   $settings['db_prefix'] = array( | 
| webmaster@1 | 402     'value'    => $form_state['values']['db_prefix'], | 
| webmaster@1 | 403     'required' => TRUE, | 
| webmaster@1 | 404   ); | 
| webmaster@1 | 405   drupal_rewrite_settings($settings); | 
| webmaster@1 | 406 | 
| webmaster@1 | 407   // Continue to install profile step | 
| webmaster@1 | 408   install_goto("install.php?profile=$profile". ($install_locale ? "&locale=$install_locale" : '')); | 
| webmaster@1 | 409 } | 
| webmaster@1 | 410 | 
| webmaster@1 | 411 /** | 
| webmaster@1 | 412  * Find all .profile files. | 
| webmaster@1 | 413  */ | 
| webmaster@1 | 414 function install_find_profiles() { | 
| webmaster@1 | 415   return file_scan_directory('./profiles', '\.profile$', array('.', '..', 'CVS'), 0, TRUE, 'name', 0); | 
| webmaster@1 | 416 } | 
| webmaster@1 | 417 | 
| webmaster@1 | 418 /** | 
| webmaster@1 | 419  * Allow admin to select which profile to install. | 
| webmaster@1 | 420  * | 
| webmaster@1 | 421  * @return | 
| webmaster@1 | 422  *   The selected profile. | 
| webmaster@1 | 423  */ | 
| webmaster@1 | 424 function install_select_profile() { | 
| webmaster@1 | 425   include_once './includes/form.inc'; | 
| webmaster@1 | 426 | 
| webmaster@1 | 427   $profiles = install_find_profiles(); | 
| webmaster@1 | 428   // Don't need to choose profile if only one available. | 
| webmaster@1 | 429   if (sizeof($profiles) == 1) { | 
| webmaster@1 | 430     $profile = array_pop($profiles); | 
| webmaster@1 | 431     require_once $profile->filename; | 
| webmaster@1 | 432     return $profile->name; | 
| webmaster@1 | 433   } | 
| webmaster@1 | 434   elseif (sizeof($profiles) > 1) { | 
| webmaster@1 | 435     foreach ($profiles as $profile) { | 
| webmaster@1 | 436       if (!empty($_POST['profile']) && ($_POST['profile'] == $profile->name)) { | 
| webmaster@1 | 437         return $profile->name; | 
| webmaster@1 | 438       } | 
| webmaster@1 | 439     } | 
| webmaster@1 | 440 | 
| webmaster@1 | 441     install_task_list('profile-select'); | 
| webmaster@1 | 442 | 
| webmaster@1 | 443     drupal_set_title(st('Select an installation profile')); | 
| webmaster@1 | 444     print theme('install_page', drupal_get_form('install_select_profile_form', $profiles)); | 
| webmaster@1 | 445     exit; | 
| webmaster@1 | 446   } | 
| webmaster@1 | 447 } | 
| webmaster@1 | 448 | 
| webmaster@1 | 449 /** | 
| webmaster@1 | 450  * Form API array definition for the profile selection form. | 
| webmaster@9 | 451  * | 
| webmaster@9 | 452  * @param $form_state | 
| webmaster@9 | 453  *   Array of metadata about state of form processing. | 
| webmaster@9 | 454  * @param $profile_files | 
| webmaster@9 | 455  *   Array of .profile files, as returned from file_scan_directory(). | 
| webmaster@1 | 456  */ | 
| webmaster@9 | 457 function install_select_profile_form(&$form_state, $profile_files) { | 
| webmaster@9 | 458   $profiles = array(); | 
| webmaster@9 | 459   $names = array(); | 
| webmaster@9 | 460 | 
| webmaster@9 | 461   foreach ($profile_files as $profile) { | 
| webmaster@1 | 462     include_once($profile->filename); | 
| webmaster@9 | 463 | 
| webmaster@9 | 464     // Load profile details and store them for later retrieval. | 
| webmaster@1 | 465     $function = $profile->name .'_profile_details'; | 
| webmaster@1 | 466     if (function_exists($function)) { | 
| webmaster@1 | 467       $details = $function(); | 
| webmaster@1 | 468     } | 
| webmaster@9 | 469     $profiles[$profile->name] = $details; | 
| webmaster@9 | 470 | 
| webmaster@9 | 471     // Determine the name of the profile; default to file name if defined name | 
| webmaster@9 | 472     // is unspecified. | 
| webmaster@1 | 473     $name = isset($details['name']) ? $details['name'] : $profile->name; | 
| webmaster@9 | 474     $names[$profile->name] = $name; | 
| webmaster@9 | 475   } | 
| webmaster@9 | 476 | 
| webmaster@9 | 477   // Display radio buttons alphabetically by human-readable name. | 
| webmaster@9 | 478   natcasesort($names); | 
| webmaster@9 | 479   foreach ($names as $profile => $name) { | 
| webmaster@1 | 480     $form['profile'][$name] = array( | 
| webmaster@1 | 481       '#type' => 'radio', | 
| webmaster@1 | 482       '#value' => 'default', | 
| webmaster@9 | 483       '#return_value' => $profile, | 
| webmaster@1 | 484       '#title' => $name, | 
| webmaster@9 | 485       '#description' => isset($profiles[$profile]['description']) ? $profiles[$profile]['description'] : '', | 
| webmaster@1 | 486       '#parents' => array('profile'), | 
| webmaster@1 | 487     ); | 
| webmaster@1 | 488   } | 
| webmaster@1 | 489   $form['submit'] =  array( | 
| webmaster@1 | 490     '#type' => 'submit', | 
| webmaster@1 | 491     '#value' => st('Save and continue'), | 
| webmaster@1 | 492   ); | 
| webmaster@1 | 493   return $form; | 
| webmaster@1 | 494 } | 
| webmaster@1 | 495 | 
| webmaster@1 | 496 /** | 
| webmaster@1 | 497  * Find all .po files for the current profile. | 
| webmaster@1 | 498  */ | 
| webmaster@1 | 499 function install_find_locales($profilename) { | 
| webmaster@1 | 500   $locales = file_scan_directory('./profiles/'. $profilename .'/translations', '\.po$', array('.', '..', 'CVS'), 0, FALSE); | 
| webmaster@1 | 501   array_unshift($locales, (object) array('name' => 'en')); | 
| webmaster@1 | 502   return $locales; | 
| webmaster@1 | 503 } | 
| webmaster@1 | 504 | 
| webmaster@1 | 505 /** | 
| webmaster@1 | 506  * Allow admin to select which locale to use for the current profile. | 
| webmaster@1 | 507  * | 
| webmaster@1 | 508  * @return | 
| webmaster@1 | 509  *   The selected language. | 
| webmaster@1 | 510  */ | 
| webmaster@1 | 511 function install_select_locale($profilename) { | 
| webmaster@1 | 512   include_once './includes/file.inc'; | 
| webmaster@1 | 513   include_once './includes/form.inc'; | 
| webmaster@1 | 514 | 
| webmaster@1 | 515   // Find all available locales. | 
| webmaster@1 | 516   $locales = install_find_locales($profilename); | 
| webmaster@1 | 517 | 
| webmaster@1 | 518   // If only the built-in (English) language is available, | 
| webmaster@1 | 519   // and we are using the default profile, inform the user | 
| webmaster@1 | 520   // that the installer can be localized. Otherwise we assume | 
| webmaster@1 | 521   // the user know what he is doing. | 
| webmaster@1 | 522   if (count($locales) == 1) { | 
| webmaster@1 | 523     if ($profilename == 'default') { | 
| webmaster@1 | 524       install_task_list('locale-select'); | 
| webmaster@1 | 525       drupal_set_title(st('Choose language')); | 
| webmaster@1 | 526       if (!empty($_GET['localize'])) { | 
| webmaster@1 | 527         $output = '<p>'. st('With the addition of an appropriate translation package, this installer is capable of proceeding in another language of your choice. To install and use Drupal in a language other than English:') .'</p>'; | 
| webmaster@1 | 528         $output .= '<ul><li>'. st('Determine if <a href="@translations" target="_blank">a translation of this Drupal version</a> is available in your language of choice. A translation is provided via a translation package; each translation package enables the display of a specific version of Drupal in a specific language. Not all languages are available for every version of Drupal.', array('@translations' => 'http://drupal.org/project/translations')) .'</li>'; | 
| webmaster@1 | 529         $output .= '<li>'. st('If an alternative translation package of your choice is available, download and extract its contents to your Drupal root directory.') .'</li>'; | 
| webmaster@1 | 530         $output .= '<li>'. st('Return to choose language using the second link below and select your desired language from the displayed list. Reloading the page allows the list to automatically adjust to the presence of new translation packages.') .'</li>'; | 
| webmaster@1 | 531         $output .= '</ul><p>'. st('Alternatively, to install and use Drupal in English, or to defer the selection of an alternative language until after installation, select the first link below.') .'</p>'; | 
| webmaster@1 | 532         $output .= '<p>'. st('How should the installation continue?') .'</p>'; | 
| webmaster@1 | 533         $output .= '<ul><li><a href="install.php?profile='. $profilename .'&locale=en">'. st('Continue installation in English') .'</a></li><li><a href="install.php?profile='. $profilename .'">'. st('Return to choose a language') .'</a></li></ul>'; | 
| webmaster@1 | 534       } | 
| webmaster@1 | 535       else { | 
| webmaster@1 | 536         $output = '<ul><li><a href="install.php?profile='. $profilename .'&locale=en">'. st('Install Drupal in English') .'</a></li><li><a href="install.php?profile='. $profilename .'&localize=true">'. st('Learn how to install Drupal in other languages') .'</a></li></ul>'; | 
| webmaster@1 | 537       } | 
| webmaster@1 | 538       print theme('install_page', $output); | 
| webmaster@1 | 539       exit; | 
| webmaster@1 | 540     } | 
| webmaster@1 | 541     // One language, but not the default profile, assume | 
| webmaster@1 | 542     // the user knows what he is doing. | 
| webmaster@1 | 543     return FALSE; | 
| webmaster@1 | 544   } | 
| webmaster@1 | 545   else { | 
| webmaster@1 | 546     // Allow profile to pre-select the language, skipping the selection. | 
| webmaster@1 | 547     $function = $profilename .'_profile_details'; | 
| webmaster@1 | 548     if (function_exists($function)) { | 
| webmaster@1 | 549       $details = $function(); | 
| webmaster@1 | 550       if (isset($details['language'])) { | 
| webmaster@1 | 551         foreach ($locales as $locale) { | 
| webmaster@1 | 552           if ($details['language'] == $locale->name) { | 
| webmaster@1 | 553             return $locale->name; | 
| webmaster@1 | 554           } | 
| webmaster@1 | 555         } | 
| webmaster@1 | 556       } | 
| webmaster@1 | 557     } | 
| webmaster@1 | 558 | 
| webmaster@1 | 559     foreach ($locales as $locale) { | 
| webmaster@1 | 560       if ($_POST['locale'] == $locale->name) { | 
| webmaster@1 | 561         return $locale->name; | 
| webmaster@1 | 562       } | 
| webmaster@1 | 563     } | 
| webmaster@1 | 564 | 
| webmaster@1 | 565     install_task_list('locale-select'); | 
| webmaster@1 | 566 | 
| webmaster@1 | 567     drupal_set_title(st('Choose language')); | 
| webmaster@1 | 568     print theme('install_page', drupal_get_form('install_select_locale_form', $locales)); | 
| webmaster@1 | 569     exit; | 
| webmaster@1 | 570   } | 
| webmaster@1 | 571 } | 
| webmaster@1 | 572 | 
| webmaster@1 | 573 /** | 
| webmaster@1 | 574  * Form API array definition for language selection. | 
| webmaster@1 | 575  */ | 
| webmaster@1 | 576 function install_select_locale_form(&$form_state, $locales) { | 
| webmaster@1 | 577   include_once './includes/locale.inc'; | 
| webmaster@1 | 578   $languages = _locale_get_predefined_list(); | 
| webmaster@1 | 579   foreach ($locales as $locale) { | 
| webmaster@1 | 580     // Try to use verbose locale name | 
| webmaster@1 | 581     $name = $locale->name; | 
| webmaster@1 | 582     if (isset($languages[$name])) { | 
| webmaster@1 | 583       $name = $languages[$name][0] . (isset($languages[$name][1]) ? ' '. st('(@language)', array('@language' => $languages[$name][1])) : ''); | 
| webmaster@1 | 584     } | 
| webmaster@1 | 585     $form['locale'][$locale->name] = array( | 
| webmaster@1 | 586       '#type' => 'radio', | 
| webmaster@1 | 587       '#return_value' => $locale->name, | 
| webmaster@1 | 588       '#default_value' => ($locale->name == 'en' ? TRUE : FALSE), | 
| webmaster@1 | 589       '#title' => $name . ($locale->name == 'en' ? ' '. st('(built-in)') : ''), | 
| webmaster@1 | 590       '#parents' => array('locale') | 
| webmaster@1 | 591     ); | 
| webmaster@1 | 592   } | 
| webmaster@1 | 593   $form['submit'] =  array( | 
| webmaster@1 | 594     '#type' => 'submit', | 
| webmaster@1 | 595     '#value' => st('Select language'), | 
| webmaster@1 | 596   ); | 
| webmaster@1 | 597   return $form; | 
| webmaster@1 | 598 } | 
| webmaster@1 | 599 | 
| webmaster@1 | 600 /** | 
| webmaster@1 | 601  * Show an error page when there are no profiles available. | 
| webmaster@1 | 602  */ | 
| webmaster@1 | 603 function install_no_profile_error() { | 
| webmaster@1 | 604   install_task_list('profile-select'); | 
| webmaster@1 | 605   drupal_set_title(st('No profiles available')); | 
| webmaster@1 | 606   print theme('install_page', '<p>'. st('We were unable to find any installer profiles. Installer profiles tell us what modules to enable and what schema to install in the database. A profile is necessary to continue with the installation process.') .'</p>'); | 
| webmaster@1 | 607   exit; | 
| webmaster@1 | 608 } | 
| webmaster@1 | 609 | 
| webmaster@1 | 610 | 
| webmaster@1 | 611 /** | 
| webmaster@1 | 612  * Show an error page when Drupal has already been installed. | 
| webmaster@1 | 613  */ | 
| webmaster@1 | 614 function install_already_done_error() { | 
| webmaster@1 | 615   global $base_url; | 
| webmaster@1 | 616 | 
| webmaster@1 | 617   drupal_set_title(st('Drupal already installed')); | 
| webmaster@1 | 618   print theme('install_page', st('<ul><li>To start over, you must empty your existing database.</li><li>To install to a different database, edit the appropriate <em>settings.php</em> file in the <em>sites</em> folder.</li><li>To upgrade an existing installation, proceed to the <a href="@base-url/update.php">update script</a>.</li><li>View your <a href="@base-url">existing site</a>.</li></ul>', array('@base-url' => $base_url))); | 
| webmaster@1 | 619   exit; | 
| webmaster@1 | 620 } | 
| webmaster@1 | 621 | 
| webmaster@1 | 622 /** | 
| webmaster@1 | 623  * Tasks performed after the database is initialized. | 
| webmaster@1 | 624  */ | 
| webmaster@1 | 625 function install_tasks($profile, $task) { | 
| webmaster@1 | 626   global $base_url, $install_locale; | 
| webmaster@1 | 627 | 
| webmaster@1 | 628   // Bootstrap newly installed Drupal, while preserving existing messages. | 
| webmaster@1 | 629   $messages = isset($_SESSION['messages']) ? $_SESSION['messages'] : ''; | 
| webmaster@1 | 630   drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); | 
| webmaster@1 | 631   $_SESSION['messages'] = $messages; | 
| webmaster@1 | 632 | 
| webmaster@1 | 633   // URL used to direct page requests. | 
| webmaster@1 | 634   $url = $base_url .'/install.php?locale='. $install_locale .'&profile='. $profile; | 
| webmaster@1 | 635 | 
| webmaster@1 | 636   // Build a page for final tasks. | 
| webmaster@1 | 637   if (empty($task)) { | 
| webmaster@1 | 638     variable_set('install_task', 'profile-install'); | 
| webmaster@1 | 639     $task = 'profile-install'; | 
| webmaster@1 | 640   } | 
| webmaster@1 | 641 | 
| webmaster@1 | 642   // We are using a list of if constructs here to allow for | 
| webmaster@1 | 643   // passing from one task to the other in the same request. | 
| webmaster@1 | 644 | 
| webmaster@1 | 645   // Install profile modules. | 
| webmaster@1 | 646   if ($task == 'profile-install') { | 
| webmaster@1 | 647     $modules = variable_get('install_profile_modules', array()); | 
| webmaster@1 | 648     $files = module_rebuild_cache(); | 
| webmaster@1 | 649     variable_del('install_profile_modules'); | 
| webmaster@1 | 650     $operations = array(); | 
| webmaster@1 | 651     foreach ($modules as $module) { | 
| webmaster@1 | 652       $operations[] = array('_install_module_batch', array($module, $files[$module]->info['name'])); | 
| webmaster@1 | 653     } | 
| webmaster@1 | 654     $batch = array( | 
| webmaster@1 | 655       'operations' => $operations, | 
| webmaster@1 | 656       'finished' => '_install_profile_batch_finished', | 
| webmaster@1 | 657       'title' => st('Installing @drupal', array('@drupal' => drupal_install_profile_name())), | 
| webmaster@1 | 658       'error_message' => st('The installation has encountered an error.'), | 
| webmaster@1 | 659     ); | 
| webmaster@1 | 660     // Start a batch, switch to 'profile-install-batch' task. We need to | 
| webmaster@1 | 661     // set the variable here, because batch_process() redirects. | 
| webmaster@1 | 662     variable_set('install_task', 'profile-install-batch'); | 
| webmaster@1 | 663     batch_set($batch); | 
| webmaster@1 | 664     batch_process($url, $url); | 
| webmaster@1 | 665   } | 
| webmaster@1 | 666   // We are running a batch install of the profile's modules. | 
| webmaster@1 | 667   // This might run in multiple HTTP requests, constantly redirecting | 
| webmaster@1 | 668   // to the same address, until the batch finished callback is invoked | 
| webmaster@1 | 669   // and the task advances to 'locale-initial-import'. | 
| webmaster@1 | 670   if ($task == 'profile-install-batch') { | 
| webmaster@1 | 671     include_once 'includes/batch.inc'; | 
| webmaster@1 | 672     $output = _batch_page(); | 
| webmaster@1 | 673   } | 
| webmaster@1 | 674 | 
| webmaster@1 | 675   // Import interface translations for the enabled modules. | 
| webmaster@1 | 676   if ($task == 'locale-initial-import') { | 
| webmaster@1 | 677     if (!empty($install_locale) && ($install_locale != 'en')) { | 
| webmaster@1 | 678       include_once 'includes/locale.inc'; | 
| webmaster@1 | 679       // Enable installation language as default site language. | 
| webmaster@1 | 680       locale_add_language($install_locale, NULL, NULL, NULL, NULL, NULL, 1, TRUE); | 
| webmaster@1 | 681       // Collect files to import for this language. | 
| webmaster@1 | 682       $batch = locale_batch_by_language($install_locale, '_install_locale_initial_batch_finished'); | 
| webmaster@1 | 683       if (!empty($batch)) { | 
| webmaster@1 | 684         // Remember components we cover in this batch set. | 
| webmaster@1 | 685         variable_set('install_locale_batch_components', $batch['#components']); | 
| webmaster@1 | 686         // Start a batch, switch to 'locale-batch' task. We need to | 
| webmaster@1 | 687         // set the variable here, because batch_process() redirects. | 
| webmaster@1 | 688         variable_set('install_task', 'locale-initial-batch'); | 
| webmaster@1 | 689         batch_set($batch); | 
| webmaster@1 | 690         batch_process($url, $url); | 
| webmaster@1 | 691       } | 
| webmaster@1 | 692     } | 
| webmaster@1 | 693     // Found nothing to import or not foreign language, go to next task. | 
| webmaster@1 | 694     $task = 'configure'; | 
| webmaster@1 | 695   } | 
| webmaster@1 | 696   if ($task == 'locale-initial-batch') { | 
| webmaster@1 | 697     include_once 'includes/batch.inc'; | 
| webmaster@1 | 698     include_once 'includes/locale.inc'; | 
| webmaster@1 | 699     $output = _batch_page(); | 
| webmaster@1 | 700   } | 
| webmaster@1 | 701 | 
| webmaster@1 | 702   if ($task == 'configure') { | 
| webmaster@1 | 703     if (variable_get('site_name', FALSE) || variable_get('site_mail', FALSE)) { | 
| webmaster@1 | 704       // Site already configured: This should never happen, means re-running | 
| webmaster@1 | 705       // the installer, possibly by an attacker after the 'install_task' variable | 
| webmaster@1 | 706       // got accidentally blown somewhere. Stop it now. | 
| webmaster@1 | 707       install_already_done_error(); | 
| webmaster@1 | 708     } | 
| webmaster@1 | 709     $form = drupal_get_form('install_configure_form', $url); | 
| webmaster@1 | 710 | 
| webmaster@1 | 711     if (!variable_get('site_name', FALSE) && !variable_get('site_mail', FALSE)) { | 
| webmaster@1 | 712       // Not submitted yet: Prepare to display the form. | 
| webmaster@1 | 713       $output = $form; | 
| webmaster@1 | 714       drupal_set_title(st('Configure site')); | 
| webmaster@1 | 715 | 
| webmaster@1 | 716       // Warn about settings.php permissions risk | 
| webmaster@1 | 717       $settings_dir = './'. conf_path(); | 
| webmaster@1 | 718       $settings_file = $settings_dir .'/settings.php'; | 
| webmaster@1 | 719       if (!drupal_verify_install_file($settings_file, FILE_EXIST|FILE_READABLE|FILE_NOT_WRITABLE) || !drupal_verify_install_file($settings_dir, FILE_NOT_WRITABLE, 'dir')) { | 
| webmaster@1 | 720         drupal_set_message(st('All necessary changes to %dir and %file have been made, so you should remove write permissions to them now in order to avoid security risks. If you are unsure how to do so, please consult the <a href="@handbook_url">on-line handbook</a>.', array('%dir' => $settings_dir, '%file' => $settings_file, '@handbook_url' => 'http://drupal.org/getting-started')), 'error'); | 
| webmaster@1 | 721       } | 
| webmaster@1 | 722       else { | 
| webmaster@1 | 723         drupal_set_message(st('All necessary changes to %dir and %file have been made. They have been set to read-only for security.', array('%dir' => $settings_dir, '%file' => $settings_file))); | 
| webmaster@1 | 724       } | 
| webmaster@1 | 725 | 
| webmaster@1 | 726       // Add JavaScript validation. | 
| webmaster@1 | 727       _user_password_dynamic_validation(); | 
| webmaster@1 | 728       drupal_add_js(drupal_get_path('module', 'system') .'/system.js', 'module'); | 
| webmaster@1 | 729       // We add these strings as settings because JavaScript translation does not | 
| webmaster@1 | 730       // work on install time. | 
| webmaster@1 | 731       drupal_add_js(array('copyFieldValue' => array('edit-site-mail' => array('edit-account-mail')), 'cleanURL' => array('success' => st('Your server has been successfully tested to support this feature.'), 'failure' => st('Your system configuration does not currently support this feature. The <a href="http://drupal.org/node/15365">handbook page on Clean URLs</a> has additional troubleshooting information.'), 'testing' => st('Testing clean URLs...'))), 'setting'); | 
| webmaster@1 | 732       drupal_add_js(' | 
| webmaster@1 | 733 // Global Killswitch | 
| webmaster@1 | 734 if (Drupal.jsEnabled) { | 
| webmaster@1 | 735   $(document).ready(function() { | 
| webmaster@1 | 736     Drupal.cleanURLsInstallCheck(); | 
| webmaster@1 | 737     Drupal.setDefaultTimezone(); | 
| webmaster@1 | 738   }); | 
| webmaster@1 | 739 }', 'inline'); | 
| webmaster@1 | 740       // Build menu to allow clean URL check. | 
| webmaster@1 | 741       menu_rebuild(); | 
| webmaster@1 | 742     } | 
| webmaster@1 | 743 | 
| webmaster@1 | 744     else { | 
| webmaster@1 | 745       $task = 'profile'; | 
| webmaster@1 | 746     } | 
| webmaster@1 | 747   } | 
| webmaster@1 | 748 | 
| webmaster@1 | 749   // If found an unknown task or the 'profile' task, which is | 
| webmaster@1 | 750   // reserved for profiles, hand over the control to the profile, | 
| webmaster@1 | 751   // so it can run any number of custom tasks it defines. | 
| webmaster@1 | 752   if (!in_array($task, install_reserved_tasks())) { | 
| webmaster@1 | 753     $function = $profile .'_profile_tasks'; | 
| webmaster@1 | 754     if (function_exists($function)) { | 
| webmaster@1 | 755       // The profile needs to run more code, maybe even more tasks. | 
| webmaster@1 | 756       // $task is sent through as a reference and may be changed! | 
| webmaster@1 | 757       $output = $function($task, $url); | 
| webmaster@1 | 758     } | 
| webmaster@1 | 759 | 
| webmaster@1 | 760     // If the profile doesn't move on to a new task we assume | 
| webmaster@1 | 761     // that it is done. | 
| webmaster@1 | 762     if ($task == 'profile') { | 
| webmaster@1 | 763       $task = 'profile-finished'; | 
| webmaster@1 | 764     } | 
| webmaster@1 | 765   } | 
| webmaster@1 | 766 | 
| webmaster@1 | 767   // Profile custom tasks are done, so let the installer regain | 
| webmaster@1 | 768   // control and proceed with importing the remaining translations. | 
| webmaster@1 | 769   if ($task == 'profile-finished') { | 
| webmaster@1 | 770     if (!empty($install_locale) && ($install_locale != 'en')) { | 
| webmaster@1 | 771       include_once 'includes/locale.inc'; | 
| webmaster@1 | 772       // Collect files to import for this language. Skip components | 
| webmaster@1 | 773       // already covered in the initial batch set. | 
| webmaster@1 | 774       $batch = locale_batch_by_language($install_locale, '_install_locale_remaining_batch_finished', variable_get('install_locale_batch_components', array())); | 
| webmaster@1 | 775       // Remove temporary variable. | 
| webmaster@1 | 776       variable_del('install_locale_batch_components'); | 
| webmaster@1 | 777       if (!empty($batch)) { | 
| webmaster@1 | 778         // Start a batch, switch to 'locale-remaining-batch' task. We need to | 
| webmaster@1 | 779         // set the variable here, because batch_process() redirects. | 
| webmaster@1 | 780         variable_set('install_task', 'locale-remaining-batch'); | 
| webmaster@1 | 781         batch_set($batch); | 
| webmaster@1 | 782         batch_process($url, $url); | 
| webmaster@1 | 783       } | 
| webmaster@1 | 784     } | 
| webmaster@1 | 785     // Found nothing to import or not foreign language, go to next task. | 
| webmaster@1 | 786     $task = 'finished'; | 
| webmaster@1 | 787   } | 
| webmaster@1 | 788   if ($task == 'locale-remaining-batch') { | 
| webmaster@1 | 789     include_once 'includes/batch.inc'; | 
| webmaster@1 | 790     include_once 'includes/locale.inc'; | 
| webmaster@1 | 791     $output = _batch_page(); | 
| webmaster@1 | 792   } | 
| webmaster@1 | 793 | 
| webmaster@1 | 794   // Display a 'finished' page to user. | 
| webmaster@1 | 795   if ($task == 'finished') { | 
| webmaster@1 | 796     drupal_set_title(st('@drupal installation complete', array('@drupal' => drupal_install_profile_name()))); | 
| webmaster@1 | 797     $messages = drupal_set_message(); | 
| webmaster@1 | 798     $output = '<p>'. st('Congratulations, @drupal has been successfully installed.', array('@drupal' => drupal_install_profile_name())) .'</p>'; | 
| webmaster@1 | 799     $output .= '<p>'. (isset($messages['error']) ? st('Please review the messages above before continuing on to <a href="@url">your new site</a>.', array('@url' => url(''))) : st('You may now visit <a href="@url">your new site</a>.', array('@url' => url('')))) .'</p>'; | 
| webmaster@1 | 800     $task = 'done'; | 
| webmaster@1 | 801   } | 
| webmaster@1 | 802 | 
| webmaster@1 | 803   // The end of the install process. Remember profile used. | 
| webmaster@1 | 804   if ($task == 'done') { | 
| webmaster@1 | 805     // Rebuild menu to get content type links registered by the profile, | 
| webmaster@1 | 806     // and possibly any other menu items created through the tasks. | 
| webmaster@1 | 807     menu_rebuild(); | 
| webmaster@1 | 808 | 
| webmaster@1 | 809     // Register actions declared by any modules. | 
| webmaster@1 | 810     actions_synchronize(); | 
| webmaster@1 | 811 | 
| webmaster@1 | 812     // Randomize query-strings on css/js files, to hide the fact that | 
| webmaster@1 | 813     // this is a new install, not upgraded yet. | 
| webmaster@1 | 814     _drupal_flush_css_js(); | 
| webmaster@1 | 815 | 
| webmaster@1 | 816     variable_set('install_profile', $profile); | 
| webmaster@1 | 817   } | 
| webmaster@1 | 818 | 
| webmaster@1 | 819   // Set task for user, and remember the task in the database. | 
| webmaster@1 | 820   install_task_list($task); | 
| webmaster@1 | 821   variable_set('install_task', $task); | 
| webmaster@1 | 822 | 
| webmaster@1 | 823   // Output page, if some output was required. Otherwise it is possible | 
| webmaster@1 | 824   // that we are printing a JSON page and theme output should not be there. | 
| webmaster@1 | 825   if (isset($output)) { | 
| webmaster@1 | 826     print theme('maintenance_page', $output); | 
| webmaster@1 | 827   } | 
| webmaster@1 | 828 } | 
| webmaster@1 | 829 | 
| webmaster@1 | 830 /** | 
| webmaster@1 | 831  * Batch callback for batch installation of modules. | 
| webmaster@1 | 832  */ | 
| webmaster@1 | 833 function _install_module_batch($module, $module_name, &$context) { | 
| webmaster@1 | 834   _drupal_install_module($module); | 
| webmaster@1 | 835   // We enable the installed module right away, so that the module will be | 
| webmaster@1 | 836   // loaded by drupal_bootstrap in subsequent batch requests, and other | 
| webmaster@1 | 837   // modules possibly depending on it can safely perform their installation | 
| webmaster@1 | 838   // steps. | 
| webmaster@1 | 839   module_enable(array($module)); | 
| webmaster@1 | 840   $context['results'][] = $module; | 
| webmaster@1 | 841   $context['message'] = 'Installed '. $module_name .' module.'; | 
| webmaster@1 | 842 } | 
| webmaster@1 | 843 | 
| webmaster@1 | 844 /** | 
| webmaster@1 | 845  * Finished callback for the modules install batch. | 
| webmaster@1 | 846  * | 
| webmaster@1 | 847  * Advance installer task to language import. | 
| webmaster@1 | 848  */ | 
| webmaster@1 | 849 function _install_profile_batch_finished($success, $results) { | 
| webmaster@1 | 850   variable_set('install_task', 'locale-initial-import'); | 
| webmaster@1 | 851 } | 
| webmaster@1 | 852 | 
| webmaster@1 | 853 /** | 
| webmaster@1 | 854  * Finished callback for the first locale import batch. | 
| webmaster@1 | 855  * | 
| webmaster@1 | 856  * Advance installer task to the configure screen. | 
| webmaster@1 | 857  */ | 
| webmaster@1 | 858 function _install_locale_initial_batch_finished($success, $results) { | 
| webmaster@1 | 859   variable_set('install_task', 'configure'); | 
| webmaster@1 | 860 } | 
| webmaster@1 | 861 | 
| webmaster@1 | 862 /** | 
| webmaster@1 | 863  * Finished callback for the second locale import batch. | 
| webmaster@1 | 864  * | 
| webmaster@1 | 865  * Advance installer task to the finished screen. | 
| webmaster@1 | 866  */ | 
| webmaster@1 | 867 function _install_locale_remaining_batch_finished($success, $results) { | 
| webmaster@1 | 868   variable_set('install_task', 'finished'); | 
| webmaster@1 | 869 } | 
| webmaster@1 | 870 | 
| webmaster@1 | 871 /** | 
| webmaster@1 | 872  * The list of reserved tasks to run in the installer. | 
| webmaster@1 | 873  */ | 
| webmaster@1 | 874 function install_reserved_tasks() { | 
| webmaster@1 | 875   return array('configure', 'profile-install', 'profile-install-batch', 'locale-initial-import', 'locale-initial-batch', 'profile-finished', 'locale-remaining-batch', 'finished', 'done'); | 
| webmaster@1 | 876 } | 
| webmaster@1 | 877 | 
| webmaster@1 | 878 /** | 
| webmaster@1 | 879  * Check installation requirements and report any errors. | 
| webmaster@1 | 880  */ | 
| webmaster@1 | 881 function install_check_requirements($profile, $verify) { | 
| webmaster@1 | 882 | 
| webmaster@1 | 883   // If Drupal is not set up already, we need to create a settings file. | 
| webmaster@1 | 884   if (!$verify) { | 
| webmaster@1 | 885     $writable = FALSE; | 
| webmaster@1 | 886     $conf_path = './'. conf_path(FALSE, TRUE); | 
| webmaster@1 | 887     $settings_file = $conf_path .'/settings.php'; | 
| webmaster@1 | 888     $file = $conf_path; | 
| webmaster@7 | 889     $exists = FALSE; | 
| webmaster@1 | 890     // Verify that the directory exists. | 
| webmaster@1 | 891     if (drupal_verify_install_file($conf_path, FILE_EXIST, 'dir')) { | 
| webmaster@7 | 892       // Check to make sure a settings.php already exists. | 
| webmaster@7 | 893       $file = $settings_file; | 
| webmaster@1 | 894       if (drupal_verify_install_file($settings_file, FILE_EXIST)) { | 
| webmaster@7 | 895         $exists = TRUE; | 
| webmaster@1 | 896         // If it does, make sure it is writable. | 
| webmaster@1 | 897         $writable = drupal_verify_install_file($settings_file, FILE_READABLE|FILE_WRITABLE); | 
| webmaster@1 | 898       } | 
| webmaster@1 | 899     } | 
| webmaster@7 | 900     if (!$exists) { | 
| webmaster@9 | 901       drupal_set_message(st('The @drupal installer requires that you create a settings file as part of the installation process. | 
| webmaster@9 | 902 <ol> | 
| webmaster@9 | 903 <li>Copy the %default_file file to %file.</li> | 
| webmaster@9 | 904 <li>Change file permissions so that it is writable by the web server. If you are unsure how to grant file permissions, please consult the <a href="@handbook_url">on-line handbook</a>.</li> | 
| webmaster@9 | 905 </ol> | 
| webmaster@9 | 906 More details about installing Drupal are available in INSTALL.txt.', array('@drupal' => drupal_install_profile_name(), '%file' => $file, '%default_file' => $conf_path .'/default.settings.php', '@handbook_url' => 'http://drupal.org/server-permissions')), 'error'); | 
| webmaster@7 | 907     } | 
| webmaster@7 | 908     elseif (!$writable) { | 
| webmaster@1 | 909       drupal_set_message(st('The @drupal installer requires write permissions to %file during the installation process. If you are unsure how to grant file permissions, please consult the <a href="@handbook_url">on-line handbook</a>.', array('@drupal' => drupal_install_profile_name(), '%file' => $file, '@handbook_url' => 'http://drupal.org/server-permissions')), 'error'); | 
| webmaster@1 | 910     } | 
| webmaster@1 | 911   } | 
| webmaster@1 | 912 | 
| webmaster@1 | 913   // Check the other requirements. | 
| webmaster@1 | 914   $requirements = drupal_check_profile($profile); | 
| webmaster@1 | 915   $severity = drupal_requirements_severity($requirements); | 
| webmaster@1 | 916 | 
| webmaster@1 | 917   // If there are issues, report them. | 
| webmaster@1 | 918   if ($severity == REQUIREMENT_ERROR) { | 
| webmaster@1 | 919 | 
| webmaster@1 | 920     foreach ($requirements as $requirement) { | 
| webmaster@1 | 921       if (isset($requirement['severity']) && $requirement['severity'] == REQUIREMENT_ERROR) { | 
| webmaster@1 | 922         $message = $requirement['description']; | 
| webmaster@1 | 923         if (isset($requirement['value']) && $requirement['value']) { | 
| webmaster@1 | 924           $message .= ' ('. st('Currently using !item !version', array('!item' => $requirement['title'], '!version' => $requirement['value'])) .')'; | 
| webmaster@1 | 925         } | 
| webmaster@1 | 926         drupal_set_message($message, 'error'); | 
| webmaster@1 | 927       } | 
| webmaster@1 | 928     } | 
| webmaster@1 | 929   } | 
| webmaster@1 | 930   if ($severity == REQUIREMENT_WARNING) { | 
| webmaster@1 | 931 | 
| webmaster@1 | 932     foreach ($requirements as $requirement) { | 
| webmaster@1 | 933       if (isset($requirement['severity']) && $requirement['severity'] == REQUIREMENT_WARNING) { | 
| webmaster@1 | 934         $message = $requirement['description']; | 
| webmaster@1 | 935         if (isset($requirement['value']) && $requirement['value']) { | 
| webmaster@1 | 936           $message .= ' ('. st('Currently using !item !version', array('!item' => $requirement['title'], '!version' => $requirement['value'])) .')'; | 
| webmaster@1 | 937         } | 
| webmaster@1 | 938         drupal_set_message($message, 'warning'); | 
| webmaster@1 | 939       } | 
| webmaster@1 | 940     } | 
| webmaster@1 | 941   } | 
| webmaster@1 | 942 } | 
| webmaster@1 | 943 | 
| webmaster@1 | 944 /** | 
| webmaster@1 | 945  * Add the installation task list to the current page. | 
| webmaster@1 | 946  */ | 
| webmaster@1 | 947 function install_task_list($active = NULL) { | 
| webmaster@1 | 948   // Default list of tasks. | 
| webmaster@1 | 949   $tasks = array( | 
| webmaster@1 | 950     'profile-select'        => st('Choose profile'), | 
| webmaster@1 | 951     'locale-select'         => st('Choose language'), | 
| webmaster@1 | 952     'requirements'          => st('Verify requirements'), | 
| webmaster@1 | 953     'database'              => st('Set up database'), | 
| webmaster@1 | 954     'profile-install-batch' => st('Install profile'), | 
| webmaster@1 | 955     'locale-initial-batch'  => st('Set up translations'), | 
| webmaster@1 | 956     'configure'             => st('Configure site'), | 
| webmaster@1 | 957   ); | 
| webmaster@1 | 958 | 
| webmaster@1 | 959   $profiles = install_find_profiles(); | 
| webmaster@1 | 960   $profile = isset($_GET['profile']) && isset($profiles[$_GET['profile']]) ? $_GET['profile'] : '.'; | 
| webmaster@1 | 961   $locales = install_find_locales($profile); | 
| webmaster@1 | 962 | 
| webmaster@1 | 963   // If we have only one profile, remove 'Choose profile' | 
| webmaster@1 | 964   // and rename 'Install profile'. | 
| webmaster@1 | 965   if (count($profiles) == 1) { | 
| webmaster@1 | 966     unset($tasks['profile-select']); | 
| webmaster@1 | 967     $tasks['profile-install-batch'] = st('Install site'); | 
| webmaster@1 | 968   } | 
| webmaster@1 | 969 | 
| webmaster@1 | 970   // Add tasks defined by the profile. | 
| webmaster@1 | 971   if ($profile) { | 
| webmaster@1 | 972     $function = $profile .'_profile_task_list'; | 
| webmaster@1 | 973     if (function_exists($function)) { | 
| webmaster@1 | 974       $result = $function(); | 
| webmaster@1 | 975       if (is_array($result)) { | 
| webmaster@1 | 976         $tasks += $result; | 
| webmaster@1 | 977       } | 
| webmaster@1 | 978     } | 
| webmaster@1 | 979   } | 
| webmaster@1 | 980 | 
| webmaster@1 | 981   if (count($locales) < 2 || empty($_GET['locale']) || $_GET['locale'] == 'en') { | 
| webmaster@1 | 982     // If not required, remove translation import from the task list. | 
| webmaster@1 | 983     unset($tasks['locale-initial-batch']); | 
| webmaster@1 | 984   } | 
| webmaster@1 | 985   else { | 
| webmaster@1 | 986     // If required, add remaining translations import task. | 
| webmaster@1 | 987     $tasks += array('locale-remaining-batch' => st('Finish translations')); | 
| webmaster@1 | 988   } | 
| webmaster@1 | 989 | 
| webmaster@1 | 990   // Add finished step as the last task. | 
| webmaster@1 | 991   $tasks += array( | 
| webmaster@1 | 992     'finished'     => st('Finished') | 
| webmaster@1 | 993   ); | 
| webmaster@1 | 994 | 
| webmaster@1 | 995   // Let the theming function know that 'finished' and 'done' | 
| webmaster@1 | 996   // include everything, so every step is completed. | 
| webmaster@1 | 997   if (in_array($active, array('finished', 'done'))) { | 
| webmaster@1 | 998     $active = NULL; | 
| webmaster@1 | 999   } | 
| webmaster@1 | 1000   drupal_set_content('left', theme_task_list($tasks, $active)); | 
| webmaster@1 | 1001 } | 
| webmaster@1 | 1002 | 
| webmaster@1 | 1003 /** | 
| webmaster@1 | 1004  * Form API array definition for site configuration. | 
| webmaster@1 | 1005  */ | 
| webmaster@1 | 1006 function install_configure_form(&$form_state, $url) { | 
| webmaster@1 | 1007 | 
| webmaster@1 | 1008   $form['intro'] = array( | 
| webmaster@1 | 1009     '#value' => st('To configure your website, please provide the following information.'), | 
| webmaster@1 | 1010     '#weight' => -10, | 
| webmaster@1 | 1011   ); | 
| webmaster@1 | 1012   $form['site_information'] = array( | 
| webmaster@1 | 1013     '#type' => 'fieldset', | 
| webmaster@1 | 1014     '#title' => st('Site information'), | 
| webmaster@1 | 1015     '#collapsible' => FALSE, | 
| webmaster@1 | 1016   ); | 
| webmaster@1 | 1017   $form['site_information']['site_name'] = array( | 
| webmaster@1 | 1018     '#type' => 'textfield', | 
| webmaster@1 | 1019     '#title' => st('Site name'), | 
| webmaster@1 | 1020     '#required' => TRUE, | 
| webmaster@1 | 1021     '#weight' => -20, | 
| webmaster@1 | 1022   ); | 
| webmaster@1 | 1023   $form['site_information']['site_mail'] = array( | 
| webmaster@1 | 1024     '#type' => 'textfield', | 
| webmaster@1 | 1025     '#title' => st('Site e-mail address'), | 
| webmaster@1 | 1026     '#default_value' => ini_get('sendmail_from'), | 
| webmaster@1 | 1027     '#description' => st("The <em>From</em> address in automated e-mails sent during registration and new password requests, and other notifications. (Use an address ending in your site's domain to help prevent this e-mail being flagged as spam.)"), | 
| webmaster@1 | 1028     '#required' => TRUE, | 
| webmaster@1 | 1029     '#weight' => -15, | 
| webmaster@1 | 1030   ); | 
| webmaster@1 | 1031   $form['admin_account'] = array( | 
| webmaster@1 | 1032     '#type' => 'fieldset', | 
| webmaster@1 | 1033     '#title' => st('Administrator account'), | 
| webmaster@1 | 1034     '#collapsible' => FALSE, | 
| webmaster@1 | 1035   ); | 
| webmaster@1 | 1036   $form['admin_account']['account']['#tree'] = TRUE; | 
| webmaster@1 | 1037   $form['admin_account']['markup'] = array( | 
| webmaster@1 | 1038     '#value' => '<p class="description">'. st('The administrator account has complete access to the site; it will automatically be granted all permissions and can perform any administrative activity. This will be the only account that can perform certain activities, so keep its credentials safe.') .'</p>', | 
| webmaster@1 | 1039     '#weight' => -10, | 
| webmaster@1 | 1040   ); | 
| webmaster@1 | 1041 | 
| webmaster@1 | 1042   $form['admin_account']['account']['name'] = array('#type' => 'textfield', | 
| webmaster@1 | 1043     '#title' => st('Username'), | 
| webmaster@1 | 1044     '#maxlength' => USERNAME_MAX_LENGTH, | 
| webmaster@1 | 1045     '#description' => st('Spaces are allowed; punctuation is not allowed except for periods, hyphens, and underscores.'), | 
| webmaster@1 | 1046     '#required' => TRUE, | 
| webmaster@1 | 1047     '#weight' => -10, | 
| webmaster@1 | 1048   ); | 
| webmaster@1 | 1049 | 
| webmaster@1 | 1050   $form['admin_account']['account']['mail'] = array('#type' => 'textfield', | 
| webmaster@1 | 1051     '#title' => st('E-mail address'), | 
| webmaster@1 | 1052     '#maxlength' => EMAIL_MAX_LENGTH, | 
| webmaster@1 | 1053     '#description' => st('All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'), | 
| webmaster@1 | 1054     '#required' => TRUE, | 
| webmaster@1 | 1055     '#weight' => -5, | 
| webmaster@1 | 1056   ); | 
| webmaster@1 | 1057   $form['admin_account']['account']['pass'] = array( | 
| webmaster@1 | 1058     '#type' => 'password_confirm', | 
| webmaster@1 | 1059     '#required' => TRUE, | 
| webmaster@1 | 1060     '#size' => 25, | 
| webmaster@1 | 1061     '#weight' => 0, | 
| webmaster@1 | 1062   ); | 
| webmaster@1 | 1063 | 
| webmaster@1 | 1064   $form['server_settings'] = array( | 
| webmaster@1 | 1065     '#type' => 'fieldset', | 
| webmaster@1 | 1066     '#title' => st('Server settings'), | 
| webmaster@1 | 1067     '#collapsible' => FALSE, | 
| webmaster@1 | 1068   ); | 
| webmaster@1 | 1069   $form['server_settings']['date_default_timezone'] = array( | 
| webmaster@1 | 1070     '#type' => 'select', | 
| webmaster@1 | 1071     '#title' => st('Default time zone'), | 
| webmaster@1 | 1072     '#default_value' => 0, | 
| webmaster@1 | 1073     '#options' => _system_zonelist(), | 
| webmaster@1 | 1074     '#description' => st('By default, dates in this site will be displayed in the chosen time zone.'), | 
| webmaster@1 | 1075     '#weight' => 5, | 
| webmaster@1 | 1076   ); | 
| webmaster@1 | 1077 | 
| webmaster@1 | 1078   $form['server_settings']['clean_url'] = array( | 
| webmaster@1 | 1079     '#type' => 'radios', | 
| webmaster@1 | 1080     '#title' => st('Clean URLs'), | 
| webmaster@1 | 1081     '#default_value' => 0, | 
| webmaster@1 | 1082     '#options' => array(0 => st('Disabled'), 1 => st('Enabled')), | 
| webmaster@1 | 1083     '#description' => st('This option makes Drupal emit "clean" URLs (i.e. without <code>?q=</code> in the URL).'), | 
| webmaster@1 | 1084     '#disabled' => TRUE, | 
| webmaster@1 | 1085     '#prefix' => '<div id="clean-url" class="install">', | 
| webmaster@1 | 1086     '#suffix' => '</div>', | 
| webmaster@1 | 1087     '#weight' => 10, | 
| webmaster@1 | 1088   ); | 
| webmaster@1 | 1089 | 
| webmaster@1 | 1090   $form['server_settings']['update_status_module'] = array( | 
| webmaster@1 | 1091     '#type' => 'checkboxes', | 
| webmaster@1 | 1092     '#title' => st('Update notifications'), | 
| webmaster@1 | 1093     '#options' => array(1 => st('Check for updates automatically')), | 
| webmaster@1 | 1094     '#default_value' => array(1), | 
| webmaster@1 | 1095     '#description' => st('With this option enabled, Drupal will notify you when new releases are available. This will significantly enhance your site\'s security and is <strong>highly recommended</strong>. This requires your site to periodically send anonymous information on its installed components to <a href="@drupal">drupal.org</a>. For more information please see the <a href="@update">update notification information</a>.', array('@drupal' => 'http://drupal.org', '@update' => 'http://drupal.org/handbook/modules/update')), | 
| webmaster@1 | 1096     '#weight' => 15, | 
| webmaster@1 | 1097   ); | 
| webmaster@1 | 1098 | 
| webmaster@1 | 1099   $form['submit'] = array( | 
| webmaster@1 | 1100     '#type' => 'submit', | 
| webmaster@1 | 1101     '#value' => st('Save and continue'), | 
| webmaster@1 | 1102     '#weight' => 15, | 
| webmaster@1 | 1103   ); | 
| webmaster@1 | 1104   $form['#action'] = $url; | 
| webmaster@1 | 1105   $form['#redirect'] = FALSE; | 
| webmaster@1 | 1106 | 
| webmaster@1 | 1107   // Allow the profile to alter this form. $form_state isn't available | 
| webmaster@1 | 1108   // here, but to conform to the hook_form_alter() signature, we pass | 
| webmaster@1 | 1109   // an empty array. | 
| webmaster@1 | 1110   $hook_form_alter = $_GET['profile'] .'_form_alter'; | 
| webmaster@1 | 1111   if (function_exists($hook_form_alter)) { | 
| webmaster@1 | 1112     $hook_form_alter($form, array(), 'install_configure'); | 
| webmaster@1 | 1113   } | 
| webmaster@1 | 1114   return $form; | 
| webmaster@1 | 1115 } | 
| webmaster@1 | 1116 | 
| webmaster@1 | 1117 /** | 
| webmaster@1 | 1118  * Form API validate for the site configuration form. | 
| webmaster@1 | 1119  */ | 
| webmaster@1 | 1120 function install_configure_form_validate($form, &$form_state) { | 
| webmaster@1 | 1121   if ($error = user_validate_name($form_state['values']['account']['name'])) { | 
| webmaster@1 | 1122     form_error($form['admin_account']['account']['name'], $error); | 
| webmaster@1 | 1123   } | 
| webmaster@1 | 1124   if ($error = user_validate_mail($form_state['values']['account']['mail'])) { | 
| webmaster@1 | 1125     form_error($form['admin_account']['account']['mail'], $error); | 
| webmaster@1 | 1126   } | 
| webmaster@1 | 1127   if ($error = user_validate_mail($form_state['values']['site_mail'])) { | 
| webmaster@1 | 1128     form_error($form['site_information']['site_mail'], $error); | 
| webmaster@1 | 1129   } | 
| webmaster@1 | 1130 } | 
| webmaster@1 | 1131 | 
| webmaster@1 | 1132 /** | 
| webmaster@1 | 1133  * Form API submit for the site configuration form. | 
| webmaster@1 | 1134  */ | 
| webmaster@1 | 1135 function install_configure_form_submit($form, &$form_state) { | 
| webmaster@1 | 1136   global $user; | 
| webmaster@1 | 1137 | 
| webmaster@1 | 1138   variable_set('site_name', $form_state['values']['site_name']); | 
| webmaster@1 | 1139   variable_set('site_mail', $form_state['values']['site_mail']); | 
| webmaster@1 | 1140   variable_set('date_default_timezone', $form_state['values']['date_default_timezone']); | 
| webmaster@1 | 1141 | 
| webmaster@1 | 1142   // Enable update.module if this option was selected. | 
| webmaster@1 | 1143   if ($form_state['values']['update_status_module'][1]) { | 
| webmaster@1 | 1144     drupal_install_modules(array('update')); | 
| webmaster@1 | 1145   } | 
| webmaster@1 | 1146 | 
| webmaster@1 | 1147   // Turn this off temporarily so that we can pass a password through. | 
| webmaster@1 | 1148   variable_set('user_email_verification', FALSE); | 
| webmaster@1 | 1149   $form_state['old_values'] = $form_state['values']; | 
| webmaster@1 | 1150   $form_state['values'] = $form_state['values']['account']; | 
| webmaster@1 | 1151 | 
| webmaster@1 | 1152   // We precreated user 1 with placeholder values. Let's save the real values. | 
| webmaster@1 | 1153   $account = user_load(1); | 
| webmaster@1 | 1154   $merge_data = array('init' => $form_state['values']['mail'], 'roles' => array(), 'status' => 1); | 
| webmaster@1 | 1155   user_save($account, array_merge($form_state['values'], $merge_data)); | 
| webmaster@1 | 1156   // Log in the first user. | 
| webmaster@1 | 1157   user_authenticate($form_state['values']); | 
| webmaster@1 | 1158   $form_state['values'] = $form_state['old_values']; | 
| webmaster@1 | 1159   unset($form_state['old_values']); | 
| webmaster@1 | 1160   variable_set('user_email_verification', TRUE); | 
| webmaster@1 | 1161 | 
| webmaster@1 | 1162   if (isset($form_state['values']['clean_url'])) { | 
| webmaster@1 | 1163     variable_set('clean_url', $form_state['values']['clean_url']); | 
| webmaster@1 | 1164   } | 
| webmaster@1 | 1165   // The user is now logged in, but has no session ID yet, which | 
| webmaster@1 | 1166   // would be required later in the request, so remember it. | 
| webmaster@1 | 1167   $user->sid = session_id(); | 
| webmaster@1 | 1168 | 
| webmaster@1 | 1169   // Record when this install ran. | 
| webmaster@1 | 1170   variable_set('install_time', time()); | 
| webmaster@1 | 1171 } | 
| webmaster@1 | 1172 | 
| webmaster@1 | 1173 // Start the installer. | 
| webmaster@1 | 1174 install_main(); |