00001 <?php
00002
00003
00004 require_once './includes/install.inc';
00005
00009 define('MAINTENANCE_MODE', 'install');
00010
00022 function install_main() {
00023 require_once './includes/bootstrap.inc';
00024 drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
00025
00026
00027 global $profile, $install_locale, $conf;
00028
00029 require_once './modules/system/system.install';
00030 require_once './includes/file.inc';
00031
00032
00033 drupal_page_header();
00034
00035
00036 drupal_init_language();
00037
00038
00039 include_once './includes/module.inc';
00040 $module_list['system']['filename'] = 'modules/system/system.module';
00041 $module_list['filter']['filename'] = 'modules/filter/filter.module';
00042 module_list(TRUE, FALSE, FALSE, $module_list);
00043 drupal_load('module', 'system');
00044 drupal_load('module', 'filter');
00045
00046
00047 drupal_maintenance_theme();
00048
00049
00050 $verify = install_verify_settings();
00051
00052 if ($verify) {
00053
00054
00055
00056 require_once './includes/cache.inc';
00057 $conf['cache_inc'] = './includes/cache.inc';
00058
00059
00060 require_once './includes/database.inc';
00061 db_set_active();
00062
00063
00064 $task = install_verify_drupal();
00065 if ($task == 'done') {
00066 install_already_done_error();
00067 }
00068 }
00069 else {
00070
00071
00072
00073
00074 require_once './includes/cache-install.inc';
00075 $conf['cache_inc'] = './includes/cache-install.inc';
00076
00077 $task = NULL;
00078 }
00079
00080
00081 if (!empty($_GET['profile'])) {
00082 $profile = preg_replace('/[^a-zA-Z_0-9]/', '', $_GET['profile']);
00083 }
00084 elseif ($profile = install_select_profile()) {
00085 install_goto("install.php?profile=$profile");
00086 }
00087 else {
00088 install_no_profile_error();
00089 }
00090
00091
00092 require_once "./profiles/$profile/$profile.profile";
00093
00094
00095 if (!empty($_GET['locale'])) {
00096 $install_locale = preg_replace('/[^a-zA-Z_0-9]/', '', $_GET['locale']);
00097 }
00098 elseif (($install_locale = install_select_locale($profile)) !== FALSE) {
00099 install_goto("install.php?profile=$profile&locale=$install_locale");
00100 }
00101
00102
00103 if (!$task) {
00104
00105 install_check_requirements($profile, $verify);
00106
00107
00108 $modules = drupal_verify_profile($profile, $install_locale);
00109
00110
00111 $messages = drupal_set_message();
00112 if (!empty($messages['error'])) {
00113 install_task_list('requirements');
00114 drupal_set_title(st('Requirements problem'));
00115 print theme('install_page', '');
00116 exit;
00117 }
00118
00119
00120
00121 if (!$verify) {
00122 install_change_settings($profile, $install_locale);
00123 }
00124
00125
00126 drupal_install_system();
00127
00128
00129
00130 variable_set('install_profile_modules', array_diff($modules, array('system')));
00131 }
00132
00133
00134 install_tasks($profile, $task);
00135 }
00136
00140 function install_verify_drupal() {
00141
00142 $result = @db_query("SELECT value FROM {variable} WHERE name = '%s'", 'install_task');
00143 if ($result) {
00144 return unserialize(db_result($result));
00145 }
00146 }
00147
00151 function install_verify_settings() {
00152 global $db_prefix, $db_type, $db_url;
00153
00154
00155 if (!empty($db_url)) {
00156
00157 include_once './includes/form.inc';
00158
00159 $url = parse_url(is_array($db_url) ? $db_url['default'] : $db_url);
00160 $db_user = urldecode($url['user']);
00161 $db_pass = isset($url['pass']) ? urldecode($url['pass']) : NULL;
00162 $db_host = urldecode($url['host']);
00163 $db_port = isset($url['port']) ? urldecode($url['port']) : '';
00164 $db_path = ltrim(urldecode($url['path']), '/');
00165 $settings_file = './' . conf_path(FALSE, TRUE) . '/settings.php';
00166
00167 $form_state = array();
00168 _install_settings_form_validate($db_prefix, $db_type, $db_user, $db_pass, $db_host, $db_port, $db_path, $settings_file, $form_state);
00169 if (!form_get_errors()) {
00170 return TRUE;
00171 }
00172 }
00173 return FALSE;
00174 }
00175
00179 function install_change_settings($profile = 'default', $install_locale = '') {
00180 global $db_url, $db_type, $db_prefix;
00181
00182 $url = parse_url(is_array($db_url) ? $db_url['default'] : $db_url);
00183 $db_user = isset($url['user']) ? urldecode($url['user']) : '';
00184 $db_pass = isset($url['pass']) ? urldecode($url['pass']) : '';
00185 $db_host = isset($url['host']) ? urldecode($url['host']) : '';
00186 $db_port = isset($url['port']) ? urldecode($url['port']) : '';
00187 $db_path = ltrim(urldecode($url['path']), '/');
00188 $conf_path = './' . conf_path(FALSE, TRUE);
00189 $settings_file = $conf_path . '/settings.php';
00190
00191
00192 include_once './includes/form.inc';
00193 install_task_list('database');
00194
00195 if ($db_url == 'mysql://username:password@localhost/databasename') {
00196 $db_user = $db_pass = $db_path = '';
00197 }
00198 elseif (!empty($db_url)) {
00199
00200 install_already_done_error();
00201 }
00202
00203 $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);
00204 drupal_set_title(st('Database configuration'));
00205 print theme('install_page', $output);
00206 exit;
00207 }
00208
00209
00213 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) {
00214 if (empty($db_host)) {
00215 $db_host = 'localhost';
00216 }
00217 $db_types = drupal_detect_database_types();
00218
00219
00220 if (isset($db_types['mysqli'])) {
00221 unset($db_types['mysql']);
00222 }
00223
00224 if (count($db_types) == 0) {
00225 $form['no_db_types'] = array(
00226 '#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')),
00227 );
00228 }
00229 else {
00230 $form['basic_options'] = array(
00231 '#type' => 'fieldset',
00232 '#title' => st('Basic options'),
00233 '#description' => '<p>' . st('To set up your @drupal database, enter the following information.', array('@drupal' => drupal_install_profile_name())) . '</p>',
00234 );
00235
00236 if (count($db_types) > 1) {
00237 $form['basic_options']['db_type'] = array(
00238 '#type' => 'radios',
00239 '#title' => st('Database type'),
00240 '#required' => TRUE,
00241 '#options' => $db_types,
00242 '#default_value' => ($db_type ? $db_type : current($db_types)),
00243 '#description' => st('The type of database your @drupal data will be stored in.', array('@drupal' => drupal_install_profile_name())),
00244 );
00245 $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()));
00246 }
00247 else {
00248 if (count($db_types) == 1) {
00249 $db_types = array_values($db_types);
00250 $form['basic_options']['db_type'] = array(
00251 '#type' => 'hidden',
00252 '#value' => $db_types[0],
00253 );
00254 $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()));
00255 }
00256 }
00257
00258
00259 $form['basic_options']['db_path'] = array(
00260 '#type' => 'textfield',
00261 '#title' => st('Database name'),
00262 '#default_value' => $db_path,
00263 '#size' => 45,
00264 '#maxlength' => 45,
00265 '#required' => TRUE,
00266 '#description' => $db_path_description
00267 );
00268
00269
00270 $form['basic_options']['db_user'] = array(
00271 '#type' => 'textfield',
00272 '#title' => st('Database username'),
00273 '#default_value' => $db_user,
00274 '#size' => 45,
00275 '#maxlength' => 45,
00276 '#required' => TRUE,
00277 );
00278
00279
00280 $form['basic_options']['db_pass'] = array(
00281 '#type' => 'password',
00282 '#title' => st('Database password'),
00283 '#default_value' => $db_pass,
00284 '#size' => 45,
00285 '#maxlength' => 45,
00286 );
00287
00288 $form['advanced_options'] = array(
00289 '#type' => 'fieldset',
00290 '#title' => st('Advanced options'),
00291 '#collapsible' => TRUE,
00292 '#collapsed' => TRUE,
00293 '#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.")
00294 );
00295
00296
00297 $form['advanced_options']['db_host'] = array(
00298 '#type' => 'textfield',
00299 '#title' => st('Database host'),
00300 '#default_value' => $db_host,
00301 '#size' => 45,
00302 '#maxlength' => 45,
00303 '#required' => TRUE,
00304 '#description' => st('If your database is located on a different server, change this.'),
00305 );
00306
00307
00308 $form['advanced_options']['db_port'] = array(
00309 '#type' => 'textfield',
00310 '#title' => st('Database port'),
00311 '#default_value' => $db_port,
00312 '#size' => 45,
00313 '#maxlength' => 45,
00314 '#description' => st('If your database server is listening to a non-standard port, enter its number.'),
00315 );
00316
00317
00318 $prefix = ($profile == 'default') ? 'drupal_' : $profile . '_';
00319 $form['advanced_options']['db_prefix'] = array(
00320 '#type' => 'textfield',
00321 '#title' => st('Table prefix'),
00322 '#default_value' => $db_prefix,
00323 '#size' => 45,
00324 '#maxlength' => 45,
00325 '#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)),
00326 );
00327
00328 $form['save'] = array(
00329 '#type' => 'submit',
00330 '#value' => st('Save and continue'),
00331 );
00332
00333 $form['errors'] = array();
00334 $form['settings_file'] = array('#type' => 'value', '#value' => $settings_file);
00335 $form['_db_url'] = array('#type' => 'value');
00336 $form['#action'] = "install.php?profile=$profile" . ($install_locale ? "&locale=$install_locale" : '');
00337 $form['#redirect'] = FALSE;
00338 }
00339 return $form;
00340 }
00341
00345 function install_settings_form_validate($form, &$form_state) {
00346 global $db_url;
00347 _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);
00348 }
00349
00353 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) {
00354 global $db_url;
00355
00356
00357 if (!empty($db_prefix) && is_string($db_prefix) && !preg_match('/^[A-Za-z0-9_.]+$/', $db_prefix)) {
00358 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');
00359 }
00360
00361 if (!empty($db_port) && !is_numeric($db_port)) {
00362 form_set_error('db_port', st('Database port must be a number.'));
00363 }
00364
00365
00366 if (!isset($form)) {
00367 $_db_url = is_array($db_url) ? $db_url['default'] : $db_url;
00368 $db_type = substr($_db_url, 0, strpos($_db_url, '://'));
00369 }
00370 $databases = drupal_detect_database_types();
00371 if (!in_array($db_type, $databases)) {
00372 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)));
00373 }
00374 else {
00375
00376 $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);
00377 if (isset($form)) {
00378 form_set_value($form['_db_url'], $db_url, $form_state);
00379 }
00380 $success = array();
00381
00382 $function = 'drupal_test_' . $db_type;
00383 if (!$function($db_url, $success)) {
00384 if (isset($success['CONNECT'])) {
00385 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, ', '))));
00386 }
00387 else {
00388 form_set_error('db_type', '');
00389 }
00390 }
00391 }
00392 }
00393
00397 function install_settings_form_submit($form, &$form_state) {
00398 global $profile, $install_locale;
00399
00400
00401 $settings['db_url'] = array(
00402 'value' => $form_state['values']['_db_url'],
00403 'required' => TRUE,
00404 );
00405 $settings['db_prefix'] = array(
00406 'value' => $form_state['values']['db_prefix'],
00407 'required' => TRUE,
00408 );
00409 drupal_rewrite_settings($settings);
00410
00411
00412 install_goto("install.php?profile=$profile" . ($install_locale ? "&locale=$install_locale" : ''));
00413 }
00414
00418 function install_find_profiles() {
00419 return file_scan_directory('./profiles', '\.profile$', array('.', '..', 'CVS'), 0, TRUE, 'name', 0);
00420 }
00421
00428 function install_select_profile() {
00429 include_once './includes/form.inc';
00430
00431 $profiles = install_find_profiles();
00432
00433 if (sizeof($profiles) == 1) {
00434 $profile = array_pop($profiles);
00435 require_once $profile->filename;
00436 return $profile->name;
00437 }
00438 elseif (sizeof($profiles) > 1) {
00439 foreach ($profiles as $profile) {
00440 if (!empty($_POST['profile']) && ($_POST['profile'] == $profile->name)) {
00441 return $profile->name;
00442 }
00443 }
00444
00445 install_task_list('profile-select');
00446
00447 drupal_set_title(st('Select an installation profile'));
00448 print theme('install_page', drupal_get_form('install_select_profile_form', $profiles));
00449 exit;
00450 }
00451 }
00452
00456 function install_select_profile_form(&$form_state, $profiles) {
00457 foreach ($profiles as $profile) {
00458 include_once($profile->filename);
00459
00460 $function = $profile->name . '_profile_details';
00461 if (function_exists($function)) {
00462 $details = $function();
00463 }
00464
00465 $name = isset($details['name']) ? $details['name'] : $profile->name;
00466 $form['profile'][$name] = array(
00467 '#type' => 'radio',
00468 '#value' => 'default',
00469 '#return_value' => $profile->name,
00470 '#title' => $name,
00471 '#description' => isset($details['description']) ? $details['description'] : '',
00472 '#parents' => array('profile'),
00473 );
00474 }
00475 $form['submit'] = array(
00476 '#type' => 'submit',
00477 '#value' => st('Save and continue'),
00478 );
00479 return $form;
00480 }
00481
00485 function install_find_locales($profilename) {
00486 $locales = file_scan_directory('./profiles/' . $profilename . '/translations', '\.po$', array('.', '..', 'CVS'), 0, FALSE);
00487 array_unshift($locales, (object) array('name' => 'en'));
00488 return $locales;
00489 }
00490
00497 function install_select_locale($profilename) {
00498 include_once './includes/file.inc';
00499 include_once './includes/form.inc';
00500
00501
00502 $locales = install_find_locales($profilename);
00503
00504
00505
00506
00507
00508 if (count($locales) == 1) {
00509 if ($profilename == 'default') {
00510 install_task_list('locale-select');
00511 drupal_set_title(st('Choose language'));
00512 if (!empty($_GET['localize'])) {
00513 $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>';
00514 $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>';
00515 $output .= '<li>' . st('If an alternative translation package of your choice is available, download and extract its contents to your Drupal root directory.') . '</li>';
00516 $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>';
00517 $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>';
00518 $output .= '<p>' . st('How should the installation continue?') . '</p>';
00519 $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>';
00520 }
00521 else {
00522 $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>';
00523 }
00524 print theme('install_page', $output);
00525 exit;
00526 }
00527
00528
00529 return FALSE;
00530 }
00531 else {
00532
00533 $function = $profilename . '_profile_details';
00534 if (function_exists($function)) {
00535 $details = $function();
00536 if (isset($details['language'])) {
00537 foreach ($locales as $locale) {
00538 if ($details['language'] == $locale->name) {
00539 return $locale->name;
00540 }
00541 }
00542 }
00543 }
00544
00545 foreach ($locales as $locale) {
00546 if ($_POST['locale'] == $locale->name) {
00547 return $locale->name;
00548 }
00549 }
00550
00551 install_task_list('locale-select');
00552
00553 drupal_set_title(st('Choose language'));
00554 print theme('install_page', drupal_get_form('install_select_locale_form', $locales));
00555 exit;
00556 }
00557 }
00558
00562 function install_select_locale_form(&$form_state, $locales) {
00563 include_once './includes/locale.inc';
00564 $languages = _locale_get_predefined_list();
00565 foreach ($locales as $locale) {
00566
00567 $name = $locale->name;
00568 if (isset($languages[$name])) {
00569 $name = $languages[$name][0] . (isset($languages[$name][1]) ? ' ' . st('(@language)', array('@language' => $languages[$name][1])) : '');
00570 }
00571 $form['locale'][$locale->name] = array(
00572 '#type' => 'radio',
00573 '#return_value' => $locale->name,
00574 '#default_value' => ($locale->name == 'en' ? TRUE : FALSE),
00575 '#title' => $name . ($locale->name == 'en' ? ' ' . st('(built-in)') : ''),
00576 '#parents' => array('locale')
00577 );
00578 }
00579 $form['submit'] = array(
00580 '#type' => 'submit',
00581 '#value' => st('Select language'),
00582 );
00583 return $form;
00584 }
00585
00589 function install_no_profile_error() {
00590 install_task_list('profile-select');
00591 drupal_set_title(st('No profiles available'));
00592 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>');
00593 exit;
00594 }
00595
00596
00600 function install_already_done_error() {
00601 global $base_url;
00602
00603 drupal_set_title(st('Drupal already installed'));
00604 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)));
00605 exit;
00606 }
00607
00611 function install_tasks($profile, $task) {
00612 global $base_url, $install_locale;
00613
00614
00615 $messages = isset($_SESSION['messages']) ? $_SESSION['messages'] : '';
00616 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
00617 $_SESSION['messages'] = $messages;
00618
00619
00620 $url = $base_url . '/install.php?locale=' . $install_locale . '&profile=' . $profile;
00621
00622
00623 if (empty($task)) {
00624 variable_set('install_task', 'profile-install');
00625 $task = 'profile-install';
00626 }
00627
00628
00629
00630
00631
00632 if ($task == 'profile-install') {
00633 $modules = variable_get('install_profile_modules', array());
00634 $files = module_rebuild_cache();
00635 variable_del('install_profile_modules');
00636 $operations = array();
00637 foreach ($modules as $module) {
00638 $operations[] = array('_install_module_batch', array($module, $files[$module]->info['name']));
00639 }
00640 $batch = array(
00641 'operations' => $operations,
00642 'finished' => '_install_profile_batch_finished',
00643 'title' => st('Installing @drupal', array('@drupal' => drupal_install_profile_name())),
00644 'error_message' => st('The installation has encountered an error.'),
00645 );
00646
00647
00648 variable_set('install_task', 'profile-install-batch');
00649 batch_set($batch);
00650 batch_process($url, $url);
00651 }
00652
00653
00654
00655
00656 if ($task == 'profile-install-batch') {
00657 include_once 'includes/batch.inc';
00658 $output = _batch_page();
00659 }
00660
00661
00662 if ($task == 'locale-initial-import') {
00663 if (!empty($install_locale) && ($install_locale != 'en')) {
00664 include_once 'includes/locale.inc';
00665
00666 locale_add_language($install_locale, NULL, NULL, NULL, NULL, NULL, 1, TRUE);
00667
00668 $batch = locale_batch_by_language($install_locale, '_install_locale_initial_batch_finished');
00669 if (!empty($batch)) {
00670
00671 variable_set('install_locale_batch_components', $batch['#components']);
00672
00673
00674 variable_set('install_task', 'locale-initial-batch');
00675 batch_set($batch);
00676 batch_process($url, $url);
00677 }
00678 }
00679
00680 $task = 'configure';
00681 }
00682 if ($task == 'locale-initial-batch') {
00683 include_once 'includes/batch.inc';
00684 include_once 'includes/locale.inc';
00685 $output = _batch_page();
00686 }
00687
00688 if ($task == 'configure') {
00689 if (variable_get('site_name', FALSE) || variable_get('site_mail', FALSE)) {
00690
00691
00692
00693 install_already_done_error();
00694 }
00695 $form = drupal_get_form('install_configure_form', $url);
00696
00697 if (!variable_get('site_name', FALSE) && !variable_get('site_mail', FALSE)) {
00698
00699 $output = $form;
00700 drupal_set_title(st('Configure site'));
00701
00702
00703 $settings_dir = './' . conf_path();
00704 $settings_file = $settings_dir . '/settings.php';
00705 if (!drupal_verify_install_file($settings_file, FILE_EXIST|FILE_READABLE|FILE_NOT_WRITABLE) || !drupal_verify_install_file($settings_dir, FILE_NOT_WRITABLE, 'dir')) {
00706 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');
00707 }
00708 else {
00709 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)));
00710 }
00711
00712
00713 _user_password_dynamic_validation();
00714 drupal_add_js(drupal_get_path('module', 'system') . '/system.js', 'module');
00715
00716
00717 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');
00718 drupal_add_js('
00719 // Global Killswitch
00720 if (Drupal.jsEnabled) {
00721 $(document).ready(function() {
00722 Drupal.cleanURLsInstallCheck();
00723 Drupal.setDefaultTimezone();
00724 });
00725 }', 'inline');
00726
00727 menu_rebuild();
00728 }
00729
00730 else {
00731 $task = 'profile';
00732 }
00733 }
00734
00735
00736
00737
00738 if (!in_array($task, install_reserved_tasks())) {
00739 $function = $profile . '_profile_tasks';
00740 if (function_exists($function)) {
00741
00742
00743 $output = $function($task, $url);
00744 }
00745
00746
00747
00748 if ($task == 'profile') {
00749 $task = 'profile-finished';
00750 }
00751 }
00752
00753
00754
00755 if ($task == 'profile-finished') {
00756 if (!empty($install_locale) && ($install_locale != 'en')) {
00757 include_once 'includes/locale.inc';
00758
00759
00760 $batch = locale_batch_by_language($install_locale, '_install_locale_remaining_batch_finished', variable_get('install_locale_batch_components', array()));
00761
00762 variable_del('install_locale_batch_components');
00763 if (!empty($batch)) {
00764
00765
00766 variable_set('install_task', 'locale-remaining-batch');
00767 batch_set($batch);
00768 batch_process($url, $url);
00769 }
00770 }
00771
00772 $task = 'finished';
00773 }
00774 if ($task == 'locale-remaining-batch') {
00775 include_once 'includes/batch.inc';
00776 include_once 'includes/locale.inc';
00777 $output = _batch_page();
00778 }
00779
00780
00781 if ($task == 'finished') {
00782 drupal_set_title(st('@drupal installation complete', array('@drupal' => drupal_install_profile_name())));
00783 $messages = drupal_set_message();
00784 $output = '<p>' . st('Congratulations, @drupal has been successfully installed.', array('@drupal' => drupal_install_profile_name())) . '</p>';
00785 $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>';
00786 $task = 'done';
00787 }
00788
00789
00790 if ($task == 'done') {
00791
00792
00793 menu_rebuild();
00794
00795
00796 actions_synchronize();
00797
00798
00799
00800 _drupal_flush_css_js();
00801
00802 variable_set('install_profile', $profile);
00803 }
00804
00805
00806 install_task_list($task);
00807 variable_set('install_task', $task);
00808
00809
00810
00811 if (isset($output)) {
00812 print theme('maintenance_page', $output);
00813 }
00814 }
00815
00819 function _install_module_batch($module, $module_name, &$context) {
00820 _drupal_install_module($module);
00821
00822
00823
00824
00825 module_enable(array($module));
00826 $context['results'][] = $module;
00827 $context['message'] = 'Installed ' . $module_name . ' module.';
00828 }
00829
00835 function _install_profile_batch_finished($success, $results) {
00836 variable_set('install_task', 'locale-initial-import');
00837 }
00838
00844 function _install_locale_initial_batch_finished($success, $results) {
00845 variable_set('install_task', 'configure');
00846 }
00847
00853 function _install_locale_remaining_batch_finished($success, $results) {
00854 variable_set('install_task', 'finished');
00855 }
00856
00860 function install_reserved_tasks() {
00861 return array('configure', 'profile-install', 'profile-install-batch', 'locale-initial-import', 'locale-initial-batch', 'profile-finished', 'locale-remaining-batch', 'finished', 'done');
00862 }
00863
00867 function install_check_requirements($profile, $verify) {
00868
00869
00870 if (!$verify) {
00871 $writable = FALSE;
00872 $conf_path = './' . conf_path(FALSE, TRUE);
00873 $settings_file = $conf_path . '/settings.php';
00874 $file = $conf_path;
00875
00876 if (drupal_verify_install_file($conf_path, FILE_EXIST, 'dir')) {
00877
00878 if (drupal_verify_install_file($settings_file, FILE_EXIST)) {
00879
00880 $writable = drupal_verify_install_file($settings_file, FILE_READABLE|FILE_WRITABLE);
00881 $file = $settings_file;
00882 }
00883 else {
00884
00885 $writable = drupal_verify_install_file($conf_path, FILE_READABLE|FILE_WRITABLE, 'dir');
00886 }
00887 }
00888
00889 if (!$writable) {
00890 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');
00891 }
00892 }
00893
00894
00895 $requirements = drupal_check_profile($profile);
00896 $severity = drupal_requirements_severity($requirements);
00897
00898
00899 if ($severity == REQUIREMENT_ERROR) {
00900
00901 foreach ($requirements as $requirement) {
00902 if (isset($requirement['severity']) && $requirement['severity'] == REQUIREMENT_ERROR) {
00903 $message = $requirement['description'];
00904 if (isset($requirement['value']) && $requirement['value']) {
00905 $message .= ' (' . st('Currently using !item !version', array('!item' => $requirement['title'], '!version' => $requirement['value'])) . ')';
00906 }
00907 drupal_set_message($message, 'error');
00908 }
00909 }
00910 }
00911 if ($severity == REQUIREMENT_WARNING) {
00912
00913 foreach ($requirements as $requirement) {
00914 if (isset($requirement['severity']) && $requirement['severity'] == REQUIREMENT_WARNING) {
00915 $message = $requirement['description'];
00916 if (isset($requirement['value']) && $requirement['value']) {
00917 $message .= ' (' . st('Currently using !item !version', array('!item' => $requirement['title'], '!version' => $requirement['value'])) . ')';
00918 }
00919 drupal_set_message($message, 'warning');
00920 }
00921 }
00922 }
00923 }
00924
00928 function install_task_list($active = NULL) {
00929
00930 $tasks = array(
00931 'profile-select' => st('Choose profile'),
00932 'locale-select' => st('Choose language'),
00933 'requirements' => st('Verify requirements'),
00934 'database' => st('Set up database'),
00935 'profile-install-batch' => st('Install profile'),
00936 'locale-initial-batch' => st('Set up translations'),
00937 'configure' => st('Configure site'),
00938 );
00939
00940 $profiles = install_find_profiles();
00941 $profile = isset($_GET['profile']) && isset($profiles[$_GET['profile']]) ? $_GET['profile'] : '.';
00942 $locales = install_find_locales($profile);
00943
00944
00945
00946 if (count($profiles) == 1) {
00947 unset($tasks['profile-select']);
00948 $tasks['profile-install-batch'] = st('Install site');
00949 }
00950
00951
00952 if ($profile) {
00953 $function = $profile . '_profile_task_list';
00954 if (function_exists($function)) {
00955 $result = $function();
00956 if (is_array($result)) {
00957 $tasks += $result;
00958 }
00959 }
00960 }
00961
00962 if (count($locales) < 2 || empty($_GET['locale']) || $_GET['locale'] == 'en') {
00963
00964 unset($tasks['locale-initial-batch']);
00965 }
00966 else {
00967
00968 $tasks += array('locale-remaining-batch' => st('Finish translations'));
00969 }
00970
00971
00972 $tasks += array(
00973 'finished' => st('Finished')
00974 );
00975
00976
00977
00978 if (in_array($active, array('finished', 'done'))) {
00979 $active = NULL;
00980 }
00981 drupal_set_content('left', theme_task_list($tasks, $active));
00982 }
00983
00987 function install_configure_form(&$form_state, $url) {
00988
00989 $form['intro'] = array(
00990 '#value' => st('To configure your website, please provide the following information.'),
00991 '#weight' => -10,
00992 );
00993 $form['site_information'] = array(
00994 '#type' => 'fieldset',
00995 '#title' => st('Site information'),
00996 '#collapsible' => FALSE,
00997 );
00998 $form['site_information']['site_name'] = array(
00999 '#type' => 'textfield',
01000 '#title' => st('Site name'),
01001 '#required' => TRUE,
01002 '#weight' => -20,
01003 );
01004 $form['site_information']['site_mail'] = array(
01005 '#type' => 'textfield',
01006 '#title' => st('Site e-mail address'),
01007 '#default_value' => ini_get('sendmail_from'),
01008 '#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.)"),
01009 '#required' => TRUE,
01010 '#weight' => -15,
01011 );
01012 $form['admin_account'] = array(
01013 '#type' => 'fieldset',
01014 '#title' => st('Administrator account'),
01015 '#collapsible' => FALSE,
01016 );
01017 $form['admin_account']['account']['#tree'] = TRUE;
01018 $form['admin_account']['markup'] = array(
01019 '#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>',
01020 '#weight' => -10,
01021 );
01022
01023 $form['admin_account']['account']['name'] = array('#type' => 'textfield',
01024 '#title' => st('Username'),
01025 '#maxlength' => USERNAME_MAX_LENGTH,
01026 '#description' => st('Spaces are allowed; punctuation is not allowed except for periods, hyphens, and underscores.'),
01027 '#required' => TRUE,
01028 '#weight' => -10,
01029 );
01030
01031 $form['admin_account']['account']['mail'] = array('#type' => 'textfield',
01032 '#title' => st('E-mail address'),
01033 '#maxlength' => EMAIL_MAX_LENGTH,
01034 '#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.'),
01035 '#required' => TRUE,
01036 '#weight' => -5,
01037 );
01038 $form['admin_account']['account']['pass'] = array(
01039 '#type' => 'password_confirm',
01040 '#required' => TRUE,
01041 '#size' => 25,
01042 '#weight' => 0,
01043 );
01044
01045 $form['server_settings'] = array(
01046 '#type' => 'fieldset',
01047 '#title' => st('Server settings'),
01048 '#collapsible' => FALSE,
01049 );
01050 $form['server_settings']['date_default_timezone'] = array(
01051 '#type' => 'select',
01052 '#title' => st('Default time zone'),
01053 '#default_value' => 0,
01054 '#options' => _system_zonelist(),
01055 '#description' => st('By default, dates in this site will be displayed in the chosen time zone.'),
01056 '#weight' => 5,
01057 );
01058
01059 $form['server_settings']['clean_url'] = array(
01060 '#type' => 'radios',
01061 '#title' => st('Clean URLs'),
01062 '#default_value' => 0,
01063 '#options' => array(0 => st('Disabled'), 1 => st('Enabled')),
01064 '#description' => st('This option makes Drupal emit "clean" URLs (i.e. without <code>?q=</code> in the URL).'),
01065 '#disabled' => TRUE,
01066 '#prefix' => '<div id="clean-url" class="install">',
01067 '#suffix' => '</div>',
01068 '#weight' => 10,
01069 );
01070
01071 $form['server_settings']['update_status_module'] = array(
01072 '#type' => 'checkboxes',
01073 '#title' => st('Update notifications'),
01074 '#options' => array(1 => st('Check for updates automatically')),
01075 '#default_value' => array(1),
01076 '#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')),
01077 '#weight' => 15,
01078 );
01079
01080 $form['submit'] = array(
01081 '#type' => 'submit',
01082 '#value' => st('Save and continue'),
01083 '#weight' => 15,
01084 );
01085 $form['#action'] = $url;
01086 $form['#redirect'] = FALSE;
01087
01088
01089
01090
01091 $hook_form_alter = $_GET['profile'] . '_form_alter';
01092 if (function_exists($hook_form_alter)) {
01093 $hook_form_alter($form, array(), 'install_configure');
01094 }
01095 return $form;
01096 }
01097
01101 function install_configure_form_validate($form, &$form_state) {
01102 if ($error = user_validate_name($form_state['values']['account']['name'])) {
01103 form_error($form['admin_account']['account']['name'], $error);
01104 }
01105 if ($error = user_validate_mail($form_state['values']['account']['mail'])) {
01106 form_error($form['admin_account']['account']['mail'], $error);
01107 }
01108 if ($error = user_validate_mail($form_state['values']['site_mail'])) {
01109 form_error($form['site_information']['site_mail'], $error);
01110 }
01111 }
01112
01116 function install_configure_form_submit($form, &$form_state) {
01117 global $user;
01118
01119 variable_set('site_name', $form_state['values']['site_name']);
01120 variable_set('site_mail', $form_state['values']['site_mail']);
01121 variable_set('date_default_timezone', $form_state['values']['date_default_timezone']);
01122
01123
01124 if ($form_state['values']['update_status_module'][1]) {
01125 drupal_install_modules(array('update'));
01126 }
01127
01128
01129 variable_set('user_email_verification', FALSE);
01130 $form_state['old_values'] = $form_state['values'];
01131 $form_state['values'] = $form_state['values']['account'];
01132
01133
01134 $account = user_load(1);
01135 $merge_data = array('init' => $form_state['values']['mail'], 'roles' => array(), 'status' => 1);
01136 user_save($account, array_merge($form_state['values'], $merge_data));
01137
01138 user_authenticate($form_state['values']);
01139 $form_state['values'] = $form_state['old_values'];
01140 unset($form_state['old_values']);
01141 variable_set('user_email_verification', TRUE);
01142
01143 if (isset($form_state['values']['clean_url'])) {
01144 variable_set('clean_url', $form_state['values']['clean_url']);
01145 }
01146
01147
01148 $user->sid = session_id();
01149
01150
01151 variable_set('install_time', time());
01152 }
01153
01154
01155 install_main();