--- includes/install.inc.orig 2006-02-16 09:18:41.000000000 -0500 +++ includes/install.inc 2006-02-17 12:08:54.000000000 -0500 @@ -4,6 +4,8 @@ define('SCHEMA_UNINSTALLED', -1); define('SCHEMA_INSTALLED', 0); +define('DRUPAL_MINIMUM_PHP', '4.3.3'); +define('DRUPAL_MINIMUM_MEMORY', '8M'); // The system module (Drupal core) is currently a special case include_once './database/updates.inc'; @@ -79,3 +81,193 @@ function drupal_set_installed_schema_version($module, $version) { db_query("UPDATE {system} SET schema_version = %d WHERE name = '%s'", $version, $module); } + +/** + * Auto detect the base_url with PHP predefined variables. + * + * @param $file + * The name of the file calling this function so we can strip it out of + * the URI when generating the base_url. + * + * @return + * The auto-detected $base_url that should be configured in settings.php + */ +function drupal_detect_baseurl($file = 'index.php') { + $proto = $_SERVER['HTTPS'] ? 'https://' : 'http://'; + $host = $_SERVER['SERVER_NAME']; + $port = ($_SERVER['SERVER_PORT'] == 80 ? '' : ':'. $_SERVER['SERVER_PORT']); + $dir = preg_replace("$/$file$", '', $_SERVER['REQUEST_URI']); + return "$proto$host$port$dir"; +} + +/** + * Some php.ini options are written in shorthand (ie 1K instead of 1024 bytes). + * This function converts php.ini shorthand into bytes. + * + * @param $shorthand + * A memory string in php.ini shorthand notation (ie 1K, 8M, 10G) + * + * @return + * The shorthand value converted to bytes. + */ +function drupal_shorthand_to_bytes($shorthand) { + $result = trim($shorthand); + $modifier = strtolower($result{strlen($result)-1}); + switch ($modifier) { + case 'g': + $result *= 1024; + case 'm': + $result *= 1024; + case 'k': + $result *= 1024; + } + return $result; +} + +/** + * Detect all databases supported by Drupal that are compiled into the current + * PHP installation. + * + * @return + * An array of database types compiled into PHP. + */ +function drupal_detect_database_types() { + $dbs = array(); + + if (function_exists(mysql_connect)) { + $dbs[] = 'mysql'; + } + if (function_exists(mysqli_connect)) { + $dbs[] = 'mysqli'; + } + if (function_exists(pg_connect)) { + $dbs[] = 'pgsql'; + } + + return $dbs; +} + +/** + * Verify that the installed version of PHP meets our minimum requirements. + * + * @param $version + * An array with some or all of the following directives: + * 'required_version' = the required version of PHP + * 'message' = message to display if version is invalid + * ("%required_version" and "%installed_version" will be + * automatically replaced if included in the message + * text.) + * 'message_type' = message type (ie, 'error', 'status') + */ +function drupal_verify_php_version($version = array()) { + if (!function_exists(version_compare) || + version_compare(phpversion(), $version['required_version'], '<')) { + // version_compare() was added in PHP 4.1. + drupal_set_message(strtr($version['message'], array('%required_version' => $version['required_version'], '%installed_version' => phpversion())), $version['message_type']); + } +} + +/** + * Verify the value of the specified configuration option as found in php.ini. + * + * @param $setting + * An array with some or all of the following directives: + * 'required_value' = the required value of the configuration option + * 'shorthand' = TRUE/FALSE whether the option is in shorthand notation + * 'operator' = optional comparison operator + * 'message' = message to display if comparison fails + * ("%required_value" and "%current_value" will be + * automatically replaced if included in the message + * text.) + * 'message_type' = message type (ie, 'error', 'status') + */ +function drupal_verify_php_settings($settings = array()) { + foreach ($settings as $setting => $data) { + // handle special case (not from php.ini) + if ($setting == 'version') { + drupal_verify_php_version($data); + } + else { + if ($data['shorthand']) { + $required = drupal_shorthand_to_bytes($data['required_value']); + $current = drupal_shorthand_to_bytes(ini_get($setting)); + } + else { + $required = $data['required_value']; + $current = ini_get($setting); + } + + switch ($data['operator']) { + case '<': + $valid = ($current < $required); + break; + case '<=': + $valid = ($current <= $required); + break; + case '==': + default: + $valid = ($current == $required); + break; + case '>=': + $valid = ($current >= $required); + break; + case '>': + $valid = ($current > $required); + break; + case '!=': + case '<>': + $valid = ($current != $required); + break; + case '===': + $valid = ($current === $required); + break; + case '!==': + $valid = ($current !== $required); + break; + } + + if (!$valid && isset($data['message'])) { + $message_type = $data['message_type'] ? $data['message_type'] : 'status'; + drupal_set_message(strtr($data['message'], array('%current_value' => ini_get($setting), '%required_value' => $data['required_value'])), $message_type); + } + } + } +} + +function drupal_verify_php_requirements() { + // verify version of PHP + $settings['version'] = array( + 'required_version' => DRUPAL_MINIMUM_PHP, + 'message' => t('Drupal requires PHP version %required_version or greater. You are using PHP version %installed_version so Drupal will not work properly on this installation.'), + 'message_type' => 'error' + ); + + // verify safe_mode + $settings['safe_mode'] = array( + 'required_value' => 0, + 'message' => t('PHP safe_mode is currently enabled. You must disable safe_mode for Drupal to properly function.'), + 'message_type' => 'error' + ); + + // verify register_globals + $settings['register_globals'] = array( + 'required_value' => 0, + 'message' => t('PHP register_globals is currently enabled. As of Drupal 4.2.0 it is advised that you disable register_globals.') + ); + + // verify PHP memory limits + if (function_exists(memory_get_usage)) { + // memory_get_usage() will only be defined if PHP is compiled with + // the --enable-memory-limit configuration option. + $settings['memory_limit'] = array( + 'required_value' => DRUPAL_MINIMUM_MEMORY, + 'operator' => '>=', + 'message' => t('Your PHP installation limits Drupal to using only %current_value of RAM. It is suggested that you modify the memory_limit directive to allow at least %required_value of RAM.'), + 'shorthand' => TRUE + ); + } + + // TODO: call module .install hooks for non-core or profile requirements + + drupal_verify_php_settings($settings); +}