diff options
author | Paul Arthur <paul.arthur@flowerysong.com> | 2013-05-13 18:13:32 -0400 |
---|---|---|
committer | Paul Arthur <paul.arthur@flowerysong.com> | 2013-05-13 21:11:18 -0400 |
commit | 716c50f2e9b4f1a3f7c1cbacb7010b040f8515dc (patch) | |
tree | f5ac88c0086b1d6acc75dc485c36227bb94ca733 | |
parent | 3ade42684d38d0b2b645962a4593d3ed5f1eeec6 (diff) | |
download | ampache-716c50f2e9b4f1a3f7c1cbacb7010b040f8515dc.tar.gz ampache-716c50f2e9b4f1a3f7c1cbacb7010b040f8515dc.tar.bz2 ampache-716c50f2e9b4f1a3f7c1cbacb7010b040f8515dc.zip |
Clean up the install code a bit
Remove lang/charset copypasta, unnecessary setting of $prefix,
unnecessary constants.
-rw-r--r-- | install.php | 200 | ||||
-rw-r--r-- | templates/install_header.inc.php | 1 | ||||
-rw-r--r-- | templates/show_install.inc.php | 3 | ||||
-rw-r--r-- | templates/show_install_account.inc.php | 3 | ||||
-rw-r--r-- | templates/show_install_config.inc.php | 12 | ||||
-rw-r--r-- | templates/show_install_lang.inc.php | 3 |
6 files changed, 48 insertions, 174 deletions
diff --git a/install.php b/install.php index ed16ea5f..b322d215 100644 --- a/install.php +++ b/install.php @@ -26,59 +26,67 @@ require_once $prefix . '/lib/install.lib.php'; set_error_handler('ampache_error_handler'); -/* First things first we must be sure that they actually still need to - install ampache -*/ +// Redirect if installation is already complete. if (!install_check_status($configfile)) { - $redirect_url = "login.php"; + $redirect_url = 'login.php'; require_once Config::get('prefix') . '/templates/error_page.inc.php'; exit; } -define('INSTALL','1'); +define('INSTALL', 1); -/* Clean up incoming variables */ +// Clean up incoming variables $web_path = scrub_in($_REQUEST['web_path']); $username = scrub_in($_REQUEST['local_username']); $password = $_REQUEST['local_pass']; $hostname = scrub_in($_REQUEST['local_host']); $database = scrub_in($_REQUEST['local_db']); +// Charset and gettext setup +$htmllang = $_REQUEST['htmllang']; +$charset = $_REQUEST['charset']; + +if (!$htmllang) { + if ($_ENV['LANG']) { + $lang = $_ENV['LANG']; + } + else { + $lang = 'en_US'; + } + if(strpos($lang, '.')) { + $langtmp = explode('.', $lang); + $htmllang = $langtmp[0]; + $charset = $langtmp[1]; + } + else { + $htmllang = $lang; + } +} +Config::set('lang', $htmllang, true); +Config::set('site_charset', $charset ?: 'UTF-8', true); +load_gettext(); +header ('Content-Type: text/html; charset=' . Config::get('site_charset')); + // Correct potential \ or / in the dirname $safe_dirname = rtrim(dirname($_SERVER['PHP_SELF']),"/\\"); -define('WEB_PATH',$http_type . $_SERVER['HTTP_HOST'] . $safe_dirname . '/' . basename($_SERVER['PHP_SELF'])); -define('WEB_ROOT',$http_type . $_SERVER['HTTP_HOST'] . $safe_dirname); +$web_path = $http_type . $_SERVER['HTTP_HOST'] . $safe_dirname; unset($safe_dirname); -/* Catch the Current Action */ switch ($_REQUEST['action']) { case 'create_db': - /* Get the variables for the language */ - $htmllang = $_REQUEST['htmllang']; - $charset = $_REQUEST['charset']; - - // Set the lang in the conf array - Config::set('lang', $htmllang, true); - Config::set('site_charset', $charset, true); - load_gettext(); - if (!install_insert_db($username,$password,$hostname,$database)) { require_once 'templates/show_install.inc.php'; break; } // Now that it's inserted save the lang preference - Preference::update('lang','-1',$htmllang); - - header ("Location: " . WEB_PATH . "?action=show_create_config&local_db=$database&local_host=$hostname&htmllang=$htmllang&charset=$charset"); + Preference::update('lang', '-1', Config::get('lang')); + header ('Location: ' . $web_path . "/install.php?action=show_create_config&local_db=$database&local_host=$hostname&htmllang=$htmllang&charset=$charset"); break; case 'create_config': - - $htmllang = $_REQUEST['htmllang']; - $charset = $_REQUEST['charset']; // Test and make sure that the values they give us actually work Config::set_by_array(array( 'database_username' => $username, @@ -100,170 +108,38 @@ switch ($_REQUEST['action']) { require_once 'templates/show_install_config.inc.php'; break; case 'show_create_config': - - /* Attempt to Guess the Web_path */ - $web_path = dirname($_SERVER['PHP_SELF']); - $web_path = rtrim($web_path,"\/"); - - /* Get the variables for the language */ - $htmllang = $_REQUEST['htmllang']; - $charset = $_REQUEST['charset']; - - // Set the lang in the conf array - Config::set('lang', $htmllang, true); - - // We need the charset for the different languages - $charsets = array( - 'ar_SA' => 'UTF-8', - 'de_DE' => 'ISO-8859-15', - 'en_US' => 'iso-8859-1', - 'en_GB' => 'UTF-8', - 'ja_JP' => 'UTF-8', - 'es_ES' => 'iso-8859-1', - 'fr_FR' => 'iso-8859-1', - 'el_GR' => 'el_GR.utf-8', - 'it_IT' => 'UTF-8', - 'nl_NL' => 'ISO-8859-15', - 'tr_TR' => 'iso-8859-9', - 'zh_CN' => 'GBK'); - $charset = $charsets[$_REQUEST['htmllang']]; - - // Set the site_charset in the conf array - Config::set('site_charset', $charsets[$_REQUEST['htmllang']], true); - - /* load_gettext mojo */ - load_gettext(); - header ("Content-Type: text/html; charset=" . Config::get('site_charset')); - require_once 'templates/show_install_config.inc.php'; break; case 'create_account': - $results = parse_ini_file($configfile); Config::set_by_array($results, true); - /* Get the variables for the language */ - $htmllang = $_REQUEST['htmllang']; - $charset = $_REQUEST['charset']; - - // Set the lang in the conf array - Config::set('lang', $htmllang, true); - Config::set('site_charset', $charset, true); - load_gettext(); - $password2 = scrub_in($_REQUEST['local_pass2']); - if (!install_create_account($username,$password,$password2)) { + if (!install_create_account($username, $password, $password2)) { require_once Config::get('prefix') . '/templates/show_install_account.inc.php'; break; } - header ("Location: " . WEB_ROOT . "/login.php"); + header ("Location: " . $web_path . '/login.php'); break; case 'show_create_account': - $results = parse_ini_file($configfile); - /* Get the variables for the language */ - $htmllang = $_REQUEST['htmllang']; - $charset = $_REQUEST['charset']; - - // Set the lang in the conf array - Config::set('lang', $htmllang, true); - Config::set('site_charset', $charset, true); - load_gettext(); - /* Make sure we've got a valid config file */ if (!check_config_values($results)) { - Error::add('general', T_('Error: Config file not found or Unreadable')); + Error::add('general', T_('Error: Config file not found or unreadable')); require_once Config::get('prefix') . '/templates/show_install_config.inc.php'; break; } - /* Get the variables for the language */ - $htmllang = $_REQUEST['htmllang']; - $charset = $_REQUEST['charset']; - - // Set the lang in the conf array - Config::set('lang', $htmllang, true); - - // We need the charset for the different languages - $charsets = array( - 'ar_SA' => 'UTF-8', - 'de_DE' => 'ISO-8859-15', - 'en_US' => 'iso-8859-1', - 'ja_JP' => 'UTF-8', - 'en_GB' => 'UTF-8', - 'es_ES' => 'iso-8859-1', - 'fr_FR' => 'iso-8859-1', - 'it_IT' => 'UTF-8', - 'nl_NL' => 'ISO-8859-15', - 'tr_TR' => 'iso-8859-9', - 'zh_CN' => 'GBK'); - $charset = $charsets[$_REQUEST['htmllang']]; - - // Set the site_charset in the conf array - Config::set('site_charset', $charsets[$_REQUEST['htmllang']], true); - - /* load_gettext mojo */ - load_gettext(); - header ("Content-Type: text/html; charset=" . Config::get('site_charset')); - require_once Config::get('prefix') . '/templates/show_install_account.inc.php'; break; - case 'init': - /* First step of installation */ - // Get the language - $htmllang = $_POST['htmllang']; - - // Set the lang in the conf array - Config::set('lang', $htmllang, true); - - // We need the charset for the different languages - $charsets = array( - 'ar_SA' => 'UTF-8', - 'de_DE' => 'ISO-8859-15', - 'en_US' => 'iso-8859-1', - 'cs_CZ' => 'UTF-8', - 'ja_JP' => 'UTF-8', - 'en_GB' => 'UTF-8', - 'es_ES' => 'iso-8859-1', - 'fr_FR' => 'iso-8859-1', - 'it_IT' => 'UTF-8', - 'nl_NL' => 'ISO-8859-15', - 'tr_TR' => 'iso-8859-9', - 'zh_CN' => 'GBK'); - $charset = $charsets[$_POST['htmllang']]; - - // Set the site_charset in the conf array - Config::set('site_charset', $charsets[$_POST['htmllang']], true); - - // Now we make voodoo with the Load gettext mojo - load_gettext(); - - // Page ready :) - header ("Content-Type: text/html; charset=$charset"); + case 'init': require_once 'templates/show_install.inc.php'; break; - default: - if ($_ENV['LANG']) { - $lang = $_ENV['LANG']; - } else { - $lang = "en_US"; - } - if(strpos($lang, ".")) { - $langtmp = explode(".", $lang); - $htmllang = $langtmp[0]; - $charset = $langtmp[1]; - } else { - $htmllang = $lang; - $charset = "UTF-8"; - } - Config::set('lang', $htmllang, true); - Config::set('site_charset', $charset, true); - load_gettext(); - - /* Show the language options first */ + default: + // Show the language options first require_once 'templates/show_install_lang.inc.php'; break; } // end action switch diff --git a/templates/install_header.inc.php b/templates/install_header.inc.php index 8b5c6434..112ee4b2 100644 --- a/templates/install_header.inc.php +++ b/templates/install_header.inc.php @@ -20,7 +20,6 @@ * */ -$prefix = realpath(dirname(__FILE__). "/../"); ?> <?php if (!defined('INSTALL')) { exit; } ?> <?php $results = 0; ?> diff --git a/templates/show_install.inc.php b/templates/show_install.inc.php index 7350f431..dcbae665 100644 --- a/templates/show_install.inc.php +++ b/templates/show_install.inc.php @@ -20,7 +20,6 @@ * */ -$prefix = realpath(dirname(__FILE__). "/../"); require $prefix . '/templates/install_header.inc.php'; ?> <div class="content"> @@ -34,7 +33,7 @@ require $prefix . '/templates/install_header.inc.php'; <?php Error::display('general'); ?> <br /> <span class="header2"><?php echo T_('Insert Ampache Database'); ?></span> - <form method="post" action="<?php echo WEB_PATH . "?action=create_db&htmllang=$htmllang&charset=$charset"; ?>" enctype="multipart/form-data" > + <form method="post" action="<?php echo $web_path . "/install.php?action=create_db&htmllang=$htmllang&charset=$charset"; ?>" enctype="multipart/form-data" > <table> <tr> <td class="align"><?php echo T_("Desired Database Name"); ?></td> diff --git a/templates/show_install_account.inc.php b/templates/show_install_account.inc.php index e3a0a0d1..9baa2eeb 100644 --- a/templates/show_install_account.inc.php +++ b/templates/show_install_account.inc.php @@ -20,7 +20,6 @@ * */ -$prefix = realpath(dirname(__FILE__). "/../"); require $prefix . '/templates/install_header.inc.php'; ?> <div class="content"> @@ -33,7 +32,7 @@ require $prefix . '/templates/install_header.inc.php'; <?php Error::display('general'); ?> <br /> <span class="header2"><?php echo T_('Create Admin Account'); ?></span> - <form method="post" action="<?php echo WEB_PATH . "?action=create_account&htmllang=$htmllang&charset=$charset"; ?>" enctype="multipart/form-data" > + <form method="post" action="<?php echo $web_path . "/install.php?action=create_account&htmllang=$htmllang&charset=$charset"; ?>" enctype="multipart/form-data" > <table> <tr> <td class="align"><?php echo T_('Username'); ?></td> diff --git a/templates/show_install_config.inc.php b/templates/show_install_config.inc.php index 9ec17b1f..ced21e38 100644 --- a/templates/show_install_config.inc.php +++ b/templates/show_install_config.inc.php @@ -20,7 +20,9 @@ * */ -$prefix = realpath(dirname(__FILE__). "/../"); +// Try to guess the web path +$web_path_guess = rtrim(dirname($_SERVER['PHP_SELF']), '\/'); + require $prefix . '/templates/install_header.inc.php'; ?> <div class="content"> @@ -35,11 +37,11 @@ require $prefix . '/templates/install_header.inc.php'; <span class="header2"><?php echo T_('Generate Config File'); ?></span> <?php Error::display('config'); ?> -<form method="post" action="<?php echo WEB_PATH . "?action=create_config"; ?>" enctype="multipart/form-data" > +<form method="post" action="<?php echo $web_path . "/install.php?action=create_config"; ?>" enctype="multipart/form-data" > <table> <tr> <td class="align"><?php echo T_('Web Path'); ?></td> - <td class="align"><input type="text" name="web_path" value="<?php echo $web_path; ?>" /></td> + <td class="align"><input type="text" name="web_path" value="<?php echo scrub_out($web_path_guess); ?>" /></td> </tr> <tr> <td class="align"><?php echo T_('Database Name'); ?></td> @@ -90,13 +92,13 @@ require $prefix . '/templates/install_header.inc.php'; <tr> <td> </td> <td> - <?php $check_url = WEB_PATH . "?action=show_create_config&htmllang=$htmllang&charset=$charset&local_db=" . $_REQUEST['local_db'] . "&local_host=" . $_REQUEST['local_host']; ?> + <?php $check_url = $web_path . "/install.php?action=show_create_config&htmllang=$htmllang&charset=$charset&local_db=" . $_REQUEST['local_db'] . "&local_host=" . $_REQUEST['local_host']; ?> <a href="<?php echo $check_url; ?>">[<?php echo T_('Recheck Config'); ?>]</a> </td> </tr> </table> <br /> - <form method="post" action="<?php echo WEB_PATH . "?action=show_create_account&htmllang=$htmllang&charset=$charset"; ?>" enctype="multipart/form-data"> + <form method="post" action="<?php echo $web_path . "/install.php?action=show_create_account&htmllang=$htmllang&charset=$charset"; ?>" enctype="multipart/form-data"> <input type="submit" value="<?php echo T_('Continue to Step 3'); ?>" /> </form> </div> diff --git a/templates/show_install_lang.inc.php b/templates/show_install_lang.inc.php index 8fa5240b..559b3957 100644 --- a/templates/show_install_lang.inc.php +++ b/templates/show_install_lang.inc.php @@ -20,7 +20,6 @@ * */ -$prefix = realpath(dirname(__FILE__). "/../"); require $prefix . '/templates/install_header.inc.php'; ?> <?php require_once $prefix . '/templates/show_install_check.inc.php'; ?> @@ -30,7 +29,7 @@ require $prefix . '/templates/install_header.inc.php'; <p> <?php Error::display('general'); ?> </p> -<form method="post" action="<?php echo WEB_PATH . "?action=init"; ?>" enctype="multipart/form-data" > +<form method="post" action="<?php echo $web_path . "/install.php?action=init"; ?>" enctype="multipart/form-data" > <?php $languages = get_languages(); |