empty($_POST["dbhost"]) ? "localhost" : $_POST["dbhost"],
"user" => empty($_POST["dbuser"]) ? "root" : $_POST["dbuser"],
"password" => empty($_POST["dbpass"]) ? "" : $_POST["dbpass"],
"dbname" => empty($_POST["dbname"]) ? "gallery3" : $_POST["dbname"],
"prefix" => empty($_POST["prefix"]) ? "" : $_POST["prefix"],
"type" => function_exists("mysqli_set_charset") ? "mysqli" : "mysql");
switch (@$_GET["step"]) {
default:
case "welcome":
$errors = check_environment();
if ($errors) {
$content = render("environment_errors.html.php", array("errors" => $errors));
} else {
$request_db_info = $is_var_writable = installer::var_writable();
$content = render("var_dir_status.html.php", array("writable" => $is_var_writable));
}
break;
case "save_db_info":
$request_db_info = true;
if (!installer::connect($config)) {
$content = render("invalid_db_info.html.php");
} else if (!installer::select_db($config)) {
$content = render("missing_db.html.php");
} else if (!installer::db_empty($config)) {
$content = render("db_not_empty.html.php");
} else if (!installer::unpack_var()) {
$content = oops("Unable to create files inside the var directory");
} else if (!installer::unpack_sql($config)) {
$content = oops("Failed to create tables in your database:" . mysql_error());
} else if (!installer::create_database_config($config)) {
$content = oops("Couldn't create var/database.php");
} else {
try {
list ($user, $password) = installer::create_admin($config);
installer::create_admin_session($config);
$content = render("success.html.php", array("user" => $user, "password" => $password));
installer::create_private_key($config);
$request_db_info = false;
} catch (Exception $e) {
$content = oops($e->getMessage());
}
}
break;
}
}
if (empty($errors) && !empty($request_db_info)) {
$database_form = render("get_db_info.html.php", $config);
}
include("views/install.html.php");
function render($view, $args=array()) {
ob_start();
extract($args);
include(DOCROOT . "installer/views/" . $view);
return ob_get_clean();
}
function oops($error) {
return render("oops.html.php", array("error" => $error));
}
function check_environment() {
if (!function_exists("mysql_query") && !function_exists("mysqli_set_charset")) {
$errors[] = "Gallery 3 requires a MySQL database, but PHP doesn't have either the MySQL or the MySQLi extension.";
}
if (!@preg_match("/^.$/u", utf8_encode("\xF1"))) {
$errors[] = "PHP is missing Perl-Compatible Regular Expression support.";
}
if (!(function_exists("spl_autoload_register"))) {
$errors[] = "PHP is missing Standard PHP Library (SPL) support";
}
if (!(class_exists("ReflectionClass"))) {
$errors[] = "PHP is missing reflection support";
}
if (!(function_exists("filter_list"))) {
$errors[] = "PHP is missing the filter extension";
}
if (!(extension_loaded("iconv"))) {
$errors[] = "PHP is missing the iconv extension";
}
if (extension_loaded("mbstring") && (ini_get("mbstring.func_overload") & MB_OVERLOAD_STRING)) {
$errors[] = "The mbstring extension is overloading PHP's native string functions. Please disable it.";
}
if (!function_exists("json_encode")) {
$errors[] = "PHP is missing the JavaScript Object Notation (JSON) extension. Please install it.";
}
return @$errors;
}