View source
<?php
require_once './includes/install.inc';
function install_main() {
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
global $profile, $install_locale;
require_once './modules/system/system.install';
require_once './includes/file.inc';
drupal_page_header();
$verify = install_verify_settings();
if ($verify) {
require_once './includes/database.inc';
db_set_active();
if (install_verify_drupal()) {
install_already_done_error();
}
}
include_once './includes/module.inc';
$module_list['system']['filename'] = 'modules/system/system.module';
$module_list['filter']['filename'] = 'modules/filter/filter.module';
module_list(TRUE, FALSE, FALSE, $module_list);
drupal_load('module', 'system');
drupal_load('module', 'filter');
if (!empty($_GET['profile'])) {
$profile = preg_replace('/[^a-zA-Z_0-9]/', '', $_GET['profile']);
}
elseif ($profile = install_select_profile()) {
install_goto("install.php?profile={$profile}");
}
else {
install_no_profile_error();
}
if (!empty($_GET['locale'])) {
$install_locale = preg_replace('/[^a-zA-Z_0-9]/', '', $_GET['locale']);
}
elseif (($install_locale = install_select_locale($profile)) !== FALSE) {
install_goto("install.php?profile={$profile}&locale={$install_locale}");
}
require_once "./profiles/{$profile}/{$profile}.profile";
install_check_requirements($profile);
if (!$verify) {
install_change_settings($profile, $install_locale);
}
$modules = drupal_verify_profile($profile, $install_locale);
if (!$modules) {
install_missing_modules_error($profile);
}
drupal_install_profile($profile, $modules);
$settings_file = './' . conf_path() . '/settings.php';
if (!drupal_verify_install_file($settings_file, FILE_EXIST | FILE_READABLE | FILE_NOT_WRITABLE)) {
drupal_set_message(st('All necessary changes to %file have been made, so you should now remove write permissions to this file. Failure to remove write permissions to this file is a security risk.', array(
'%file' => $settings_file,
)), 'error');
}
else {
drupal_set_message(st('All necessary changes to %file have been made. It has been set to read-only for security.', array(
'%file' => $settings_file,
)));
}
install_complete($profile);
}
function install_verify_drupal() {
$result = @db_query("SELECT name FROM {system} WHERE name = 'system'");
return $result && db_result($result) == 'system';
}
function install_verify_settings() {
global $db_prefix, $db_type, $db_url;
if ($_SERVER['REQUEST_METHOD'] == 'GET' && $db_url != 'mysql://username:password@localhost/databasename') {
include_once './includes/form.inc';
$url = parse_url(is_array($db_url) ? $db_url['default'] : $db_url);
$db_user = urldecode($url['user']);
$db_pass = urldecode($url['pass']);
$db_host = urldecode($url['host']);
$db_port = isset($url['port']) ? urldecode($url['port']) : '';
$db_path = ltrim(urldecode($url['path']), '/');
$settings_file = './' . conf_path() . '/settings.php';
_install_settings_form_validate($db_prefix, $db_type, $db_user, $db_pass, $db_host, $db_port, $db_path, $settings_file);
if (!form_get_errors()) {
return TRUE;
}
}
return FALSE;
}
function install_change_settings($profile = 'default', $install_locale = '') {
global $db_url, $db_type, $db_prefix;
$url = parse_url(is_array($db_url) ? $db_url['default'] : $db_url);
$db_user = urldecode($url['user']);
$db_pass = urldecode($url['pass']);
$db_host = urldecode($url['host']);
$db_port = isset($url['port']) ? urldecode($url['port']) : '';
$db_path = ltrim(urldecode($url['path']), '/');
$settings_file = './' . conf_path() . '/settings.php';
include_once './includes/form.inc';
drupal_maintenance_theme();
if ($db_url == 'mysql://username:password@localhost/databasename') {
$db_user = $db_pass = $db_path = '';
}
elseif (!empty($db_url)) {
install_already_done_error();
}
if (!drupal_verify_install_file($settings_file, FILE_EXIST | FILE_READABLE | FILE_WRITABLE)) {
drupal_set_message(st('The @drupal installer requires write permissions to %file during the installation process.', array(
'@drupal' => drupal_install_profile_name(),
'%file' => $settings_file,
)), 'error');
drupal_set_title(st('Drupal database setup'));
print theme('install_page', '');
exit;
}
$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);
drupal_set_title(st('Database configuration'));
print theme('install_page', $output);
exit;
}
function install_settings_form($profile, $install_locale, $settings_file, $db_url, $db_type, $db_prefix, $db_user, $db_pass, $db_host, $db_port, $db_path) {
$db_types = drupal_detect_database_types();
if (count($db_types) == 0) {
$form['no_db_types'] = array(
'#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',
)),
);
}
else {
$form['basic_options'] = array(
'#type' => 'fieldset',
'#title' => st('Basic options'),
'#description' => '<p>' . st('To set up your @drupal database, enter the following information.', array(
'@drupal' => drupal_install_profile_name(),
)) . '</p>',
);
if (count($db_types) > 1) {
$db_types = drupal_detect_database_types();
$form['basic_options']['db_type'] = array(
'#type' => 'radios',
'#title' => st('Database type'),
'#required' => TRUE,
'#options' => $db_types,
'#default_value' => $db_type ? $db_type : current($db_types),
'#description' => st('The type of database your @drupal data will be stored in.', array(
'@drupal' => drupal_install_profile_name(),
)),
);
$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(),
));
}
else {
if (count($db_types) == 1) {
$db_types = array_values($db_types);
$form['basic_options']['db_type'] = array(
'#type' => 'hidden',
'#value' => $db_types[0],
);
$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(),
));
}
}
$form['basic_options']['db_path'] = array(
'#type' => 'textfield',
'#title' => st('Database name'),
'#default_value' => $db_path,
'#size' => 45,
'#maxlength' => 45,
'#required' => TRUE,
'#description' => $db_path_description,
);
$form['basic_options']['db_user'] = array(
'#type' => 'textfield',
'#title' => st('Database username'),
'#default_value' => $db_user,
'#size' => 45,
'#maxlength' => 45,
'#required' => TRUE,
);
$form['basic_options']['db_pass'] = array(
'#type' => 'password',
'#title' => st('Database password'),
'#default_value' => $db_pass,
'#size' => 45,
'#maxlength' => 45,
);
$form['advanced_options'] = array(
'#type' => 'fieldset',
'#title' => st('Advanced options'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#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."),
);
$form['advanced_options']['db_host'] = array(
'#type' => 'textfield',
'#title' => st('Database host'),
'#default_value' => $db_host,
'#size' => 45,
'#maxlength' => 45,
'#required' => TRUE,
'#description' => st('If your database is located on a different server, change this.'),
);
$form['advanced_options']['db_port'] = array(
'#type' => 'textfield',
'#title' => st('Database port'),
'#default_value' => $db_port,
'#size' => 45,
'#maxlength' => 45,
'#description' => st('If your database server is listening to a non-standard port, enter its number.'),
);
$form['advanced_options']['db_prefix'] = array(
'#type' => 'textfield',
'#title' => st('Table prefix'),
'#default_value' => $db_prefix,
'#size' => 45,
'#maxlength' => 45,
'#description' => st('If more than one @drupal web site will be sharing this database, enter a table prefix for your @drupal site here.', array(
'@drupal' => drupal_install_profile_name(),
)),
);
$form['save'] = array(
'#type' => 'submit',
'#value' => st('Save configuration'),
);
$form['errors'] = array();
$form['settings_file'] = array(
'#type' => 'value',
'#value' => $settings_file,
);
$form['_db_url'] = array(
'#type' => 'value',
);
$form['#action'] = "install.php?profile={$profile}" . ($install_locale ? "&locale={$install_locale}" : '');
$form['#redirect'] = NULL;
}
return $form;
}
function install_settings_form_validate($form_id, $form_values, $form) {
global $db_url;
_install_settings_form_validate($form_values['db_prefix'], $form_values['db_type'], $form_values['db_user'], $form_values['db_pass'], $form_values['db_host'], $form_values['db_port'], $form_values['db_path'], $form_values['settings_file'], $form);
}
function _install_settings_form_validate($db_prefix, $db_type, $db_user, $db_pass, $db_host, $db_port, $db_path, $settings_file, $form = NULL) {
global $db_url;
if ($db_user == 'username' && $db_pass == 'password') {
form_set_error('db_user', st('You have configured @drupal to use the default username and password. This is not allowed for security reasons.', array(
'@drupal' => drupal_install_profile_name(),
)));
}
if (!empty($db_prefix) && is_string($db_prefix) && !preg_match('/^[A-Za-z0-9_]+$/', $db_prefix)) {
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 or underscores.', array(
'%db_prefix' => $db_prefix,
)), 'error');
}
if (!empty($db_port) && !is_numeric($db_port)) {
form_set_error('db_port', st('Database port must be a number.'));
}
if (!isset($form)) {
$_db_url = is_array($db_url) ? $db_url['default'] : $db_url;
$db_type = substr($_db_url, 0, strpos($_db_url, '://'));
}
$databases = drupal_detect_database_types();
if (!in_array($db_type, $databases)) {
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,
)));
}
else {
$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);
if (isset($form)) {
form_set_value($form['_db_url'], $db_url);
}
$success = array();
$function = 'drupal_test_' . $db_type;
if (!$function($db_url, $success)) {
if (isset($success['CONNECT'])) {
form_set_error('db_type', st('In order for Drupal to work and to proceed 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, ', '),
)));
}
else {
form_set_error('db_type', '');
}
}
}
}
function install_settings_form_submit($form_id, $form_values) {
global $profile, $install_locale;
$settings['db_url'] = array(
'value' => $form_values['_db_url'],
'required' => TRUE,
);
$settings['db_prefix'] = array(
'value' => $form_values['db_prefix'],
'required' => TRUE,
);
drupal_rewrite_settings($settings);
install_goto("install.php?profile={$profile}" . ($install_locale ? "&locale={$install_locale}" : ''));
}
function install_select_profile() {
include_once './includes/form.inc';
$profiles = file_scan_directory('./profiles', '\\.profile$', array(
'.',
'..',
'CVS',
), 0, TRUE, 'name', 0);
if (sizeof($profiles) == 1) {
$profile = array_pop($profiles);
require_once $profile->filename;
return $profile->name;
}
elseif (sizeof($profiles) > 1) {
foreach ($profiles as $profile) {
if ($_POST['profile'] == $profile->name) {
return $profile->name;
}
}
drupal_maintenance_theme();
drupal_set_title(st('Select an installation profile'));
print theme('install_page', drupal_get_form('install_select_profile_form', $profiles));
exit;
}
}
function install_select_profile_form($profiles) {
foreach ($profiles as $profile) {
include_once $profile->filename;
$function = $profile->name . '_profile_details';
if (function_exists($function)) {
$details = $function();
}
$name = isset($details['name']) ? $details['name'] : $profile->name;
$form['profile'][$name] = array(
'#type' => 'radio',
'#value' => 'default',
'#return_value' => $profile->name,
'#title' => $name,
'#description' => isset($details['description']) ? $details['description'] : '',
'#parents' => array(
'profile',
),
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => st('Save configuration'),
);
return $form;
}
function install_select_locale($profilename) {
include_once './includes/file.inc';
include_once './includes/form.inc';
$locales = file_scan_directory('./profiles/' . $profilename, '\\.po$', array(
'.',
'..',
'CVS',
), 0, FALSE);
array_unshift($locales, (object) array(
'name' => 'en',
));
if (sizeof($locales) == 1) {
return FALSE;
}
else {
foreach ($locales as $locale) {
if ($_POST['locale'] == $locale->name) {
return $locale->name;
}
}
drupal_maintenance_theme();
drupal_set_title(st('Choose your preferred language'));
print theme('install_page', drupal_get_form('install_select_locale_form', $locales));
exit;
}
}
function install_select_locale_form($locales) {
include_once './includes/locale.inc';
$languages = _locale_get_iso639_list();
foreach ($locales as $locale) {
$name = $locale->name;
if (isset($languages[$name])) {
$name = $languages[$name][0] . (isset($languages[$name][1]) ? ' ' . st('(@language)', array(
'@language' => $languages[$name][1],
)) : '');
}
$form['locale'][$locale->name] = array(
'#type' => 'radio',
'#return_value' => $locale->name,
'#default_value' => $locale->name == 'en' ? TRUE : FALSE,
'#title' => $name . ($locale->name == 'en' ? ' ' . st('(built-in)') : ''),
'#parents' => array(
'locale',
),
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => st('Save configuration'),
);
return $form;
}
function install_no_profile_error() {
drupal_maintenance_theme();
drupal_set_title(st('No profiles available'));
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>');
exit;
}
function install_already_done_error() {
global $base_url;
drupal_maintenance_theme();
drupal_set_title(st('Drupal already installed'));
print theme('install_page', st('<ul><li>To start over, you must empty your existing database and replace the appropriate <em>settings.php</em> with an unmodified copy.</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></ul>', array(
'@base-url' => $base_url,
)));
exit;
}
function install_missing_modules_error($profile) {
global $base_url;
drupal_maintenance_theme();
drupal_set_title(st('Modules missing'));
print theme('install_page', '<p>' . st('One or more required modules are missing. Please check the error messages and <a href="!url">try again</a>.', array(
'!url' => "install.php?profile={$profile}",
)) . '</p>');
exit;
}
function install_complete($profile) {
global $base_url;
$output = '';
variable_set('install_profile', $profile);
$messages = $_SESSION['messages'];
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$_SESSION['messages'] = $messages;
drupal_maintenance_theme();
drupal_set_title(st('@drupal installation complete', array(
'@drupal' => drupal_install_profile_name(),
)));
$output .= '<p>' . st('Congratulations, @drupal has been successfully installed.', array(
'@drupal' => drupal_install_profile_name(),
)) . '</p>';
$function = $profile . '_profile_final';
if (function_exists($function)) {
$profile_message = $function();
}
if (isset($profile_message)) {
$output .= $profile_message;
}
else {
$output .= '<p>' . (drupal_set_message() ? 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>';
}
print theme('maintenance_page', $output);
}
function install_check_requirements($profile) {
$requirements = drupal_check_profile($profile);
$severity = drupal_requirements_severity($requirements);
if ($severity == REQUIREMENT_ERROR) {
drupal_maintenance_theme();
foreach ($requirements as $requirement) {
if (isset($requirement['severity']) && $requirement['severity'] == REQUIREMENT_ERROR) {
drupal_set_message($requirement['description'] . ' (' . st('Currently using !item !version', array(
'!item' => $requirement['title'],
'!version' => $requirement['value'],
)) . ')', 'error');
}
}
drupal_set_title(st('Incompatible environment'));
print theme('install_page', '');
exit;
}
}
install_main();