diff options
author | z0rglub <z0rglub@piwigo.org> | 2004-09-20 20:54:22 +0000 |
---|---|---|
committer | z0rglub <z0rglub@piwigo.org> | 2004-09-20 20:54:22 +0000 |
commit | 86770499b50257360799b748aa164d7751009e36 (patch) | |
tree | 7b36060fe18e397b12360496aca8e74e7bb8c503 /install.php | |
parent | 9d0ffba6377a0a011d773ad03cff08d9c5cc0268 (diff) |
- commenting unused function guess_lang
- code refactoring (commenting, code conventions)
- reorganize variable init in install.php avoiding "undefined constant" in
languages files
- PhpWebGallery site and forum URL are not variables anymore, only text in
language file
git-svn-id: http://piwigo.org/svn/trunk@529 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'install.php')
-rw-r--r-- | install.php | 239 |
1 files changed, 129 insertions, 110 deletions
diff --git a/install.php b/install.php index 55f8f3fec..bff9ddce8 100644 --- a/install.php +++ b/install.php @@ -32,56 +32,75 @@ define('PHPWG_ROOT_PATH','./'); function guess_lang() { return 'en_UK.iso-8859-1'; - global $_SERVER; - $languages = array(); - $i = 0; - if ( $opendir = opendir ( PHPWG_ROOT_PATH.'language/' ) ) - { - while ( $file = readdir ( $opendir ) ) - { - if ( is_dir ( PHPWG_ROOT_PATH.'language/'.$file )&& !substr_count($file,'.')) - { - $languages[$i++] =$file; - } - } - } - if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) - { - $accept_lang_ary = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); - for ($i = 0; $i < sizeof($accept_lang_ary); $i++) - { - for ($j=0; $j<sizeof($languages); $j++) - { - if (preg_match('#' . substr($languages[$j],0,2) . '#i', substr(trim($accept_lang_ary[$i]),0,2))) - { - if (file_exists(PHPWG_ROOT_PATH . 'language/' . $languages[$j].'/install.lang.php')) - { - return $languages[$j]; - } - } - } - } - } - return 'en_EN'; +// $languages = array(); +// $i = 0; +// if ($opendir = opendir(PHPWG_ROOT_PATH.'language/')) +// { +// while ( $file = readdir ( $opendir ) ) +// { +// if ( is_dir ( PHPWG_ROOT_PATH.'language/'.$file )&& !substr_count($file,'.')) +// { +// $languages[$i++] =$file; +// } +// } +// } + +// if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) +// { +// $accept_lang_ary = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); +// for ($i = 0; $i < sizeof($accept_lang_ary); $i++) +// { +// for ($j=0; $j<sizeof($languages); $j++) +// { +// if (preg_match('#' . substr($languages[$j],0,2) . '#i', substr(trim($accept_lang_ary[$i]),0,2))) +// { +// if (file_exists(PHPWG_ROOT_PATH . 'language/' . $languages[$j].'/install.lang.php')) +// { +// return $languages[$j]; +// } +// } +// } +// } +// } +// return 'en_EN'; } -function execute_sqlfile( $filepath, $replaced, $replacing ) +/** + * loads an sql file and executes all queries + * + * Before executing a query, $replaced is... replaced by $replacing. This is + * useful when the SQL file contains generic words. Drop table queries are + * not executed. + * + * @param string filepath + * @param string replaced + * @param string replacing + * @return void + */ +function execute_sqlfile($filepath, $replaced, $replacing) { - $sql_lines = file( $filepath ); + $sql_lines = file($filepath); $query = ''; - foreach ( $sql_lines as $sql_line ) { - $sql_line = trim( $sql_line ); - if ( preg_match( '/(^--|^$)/', $sql_line ) ) continue; + foreach ($sql_lines as $sql_line) + { + $sql_line = trim($sql_line); + if (preg_match('/(^--|^$)/', $sql_line)) + { + continue; + } $query.= ' '.$sql_line; // if we reached the end of query, we execute it and reinitialize the // variable "query" - if ( preg_match( '/;$/', $sql_line ) ) + if (preg_match('/;$/', $sql_line)) { - $query = trim( $query ); - $query = str_replace( $replaced, $replacing, $query ); + $query = trim($query); + $query = str_replace($replaced, $replacing, $query); // we don't execute "DROP TABLE" queries - if ( !preg_match( '/^DROP TABLE/i', $query ) ) mysql_query( $query ); + if (!preg_match('/^DROP TABLE/i', $query)) + { + mysql_query($query); + } $query = ''; } } @@ -137,24 +156,6 @@ if( !get_magic_quotes_gpc() ) //----------------------------------------------------- variable initialization $install_style = 'default'; -$release_version = '1.4'; -if ( isset( $_POST['language'] )) -{ - $language = strip_tags($_POST['language']); -} -else -{ - $language = guess_lang(); -} - -if ( !file_exists(@realpath(PHPWG_ROOT_PATH . 'language/' . $language . '/install.lang.php')) ) -{ - $language = 'en_UK.iso-8859-1'; -} - -include( './language/'.$language.'/common.lang.php' ); -include( './language/'.$language.'/admin.lang.php' ); -include( './language/'.$language.'/install.lang.php' ); // Obtain various vars $dbhost = (!empty($_POST['dbhost'])) ? $_POST['dbhost'] : 'localhost'; @@ -162,7 +163,7 @@ $dbuser = (!empty($_POST['dbuser'])) ? $_POST['dbuser'] : ''; $dbpasswd = (!empty($_POST['dbpasswd'])) ? $_POST['dbpasswd'] : ''; $dbname = (!empty($_POST['dbname'])) ? $_POST['dbname'] : ''; -$table_prefix = (!empty($_POST['prefix'])) ? $_POST['prefix'] : 'phpwg_'; +$table_prefix = (!empty($_POST['prefix'])) ? $_POST['prefix'] : 'phpwebgallery_'; $admin_name = (!empty($_POST['admin_name'])) ? $_POST['admin_name'] : ''; $admin_pass1 = (!empty($_POST['admin_pass1'])) ? $_POST['admin_pass1'] : ''; @@ -176,23 +177,40 @@ $errors = array(); $config_file = PHPWG_ROOT_PATH.'include/mysql.inc.php'; if (@file_exists($config_file)) { - include($config_file); -} - -// Is phpBB already installed? Yes? Redirect to the index -if (defined("PHPWG_INSTALLED")) -{ - die( 'PhpWebGallery is already installed' ); + include($config_file); + // Is PhpWebGallery already installed ? + if (defined("PHPWG_INSTALLED")) + { + die('PhpWebGallery is already installed'); + } } include(PHPWG_ROOT_PATH . 'include/constants.php'); include(PHPWG_ROOT_PATH . 'include/functions.inc.php'); include(PHPWG_ROOT_PATH . 'include/template.php'); + +if ( isset( $_POST['language'] )) +{ + $language = strip_tags($_POST['language']); +} +else +{ + $language = guess_lang(); +} + +if ( !file_exists(@realpath(PHPWG_ROOT_PATH . 'language/' . $language . '/install.lang.php')) ) +{ + $language = 'en_UK.iso-8859-1'; +} + +include( './language/'.$language.'/common.lang.php' ); +include( './language/'.$language.'/admin.lang.php' ); +include( './language/'.$language.'/install.lang.php' ); //----------------------------------------------------- template initialization $template=setup_style($install_style); $template->set_filenames( array('install'=>'install.tpl') ); $step = 1; -//----------------------------------------------------- form analyze +//---------------------------------------------------------------- form analyze if ( isset( $_POST['install'] )) { if ( @mysql_connect( $_POST['dbhost'], @@ -297,50 +315,51 @@ if ( isset( $_POST['install'] )) } } -$template->assign_vars(array( - 'RELEASE'=>$release_version, - - 'L_BASE_TITLE'=>$lang['Initial_config'], - 'L_LANG_TITLE'=>$lang['Default_lang'], - 'L_DB_TITLE'=>$lang['step1_title'], - 'L_DB_HOST'=>$lang['step1_host'], - 'L_DB_HOST_INFO'=>$lang['step1_host_info'], - 'L_DB_USER'=>$lang['step1_user'], - 'L_DB_USER_INFO'=>$lang['step1_user_info'], - 'L_DB_PASS'=>$lang['step1_pass'], - 'L_DB_PASS_INFO'=>$lang['step1_pass_info'], - 'L_DB_NAME'=>$lang['step1_database'], - 'L_DB_NAME_INFO'=>$lang['step1_database_info'], - 'L_DB_PREFIX'=>$lang['step1_prefix'], - 'L_DB_PREFIX_INFO'=>$lang['step1_prefix_info'], - 'L_ADMIN_TITLE'=>$lang['step2_title'], - 'L_ADMIN'=>$lang['install_webmaster'], - 'L_ADMIN_INFO'=>$lang['install_webmaster_info'], - 'L_ADMIN_PASSWORD'=>$lang['step2_pwd'], - 'L_ADMIN_PASSWORD_INFO'=>$lang['step2_pwd_info'], - 'L_ADMIN_CONFIRM_PASSWORD'=>$lang['step2_pwd_conf'], - 'L_ADMIN_CONFIRM_PASSWORD_INFO'=>$lang['step2_pwd_conf_info'], - 'L_ADMIN_EMAIL'=>$lang['conf_general_mail_webmaster'], - 'L_ADMIN_EMAIL_INFO'=>$lang['conf_general_mail_webmaster_info'], - 'L_SUBMIT'=>$lang['Start_Install'], - 'L_HELP'=>$lang['install_help'], - 'L_ERR_COPY'=>$lang['step1_err_copy'], - 'L_END_TITLE'=>$lang['install_end_title'], - 'L_END_MESSAGE'=>$lang['install_end_message'], +$template->assign_vars( + array( + 'RELEASE'=>PHPWG_VERSION, - 'F_ACTION'=>add_session_id( 'install.php' ), - 'F_DB_HOST'=>$dbhost, - 'F_DB_USER'=>$dbuser, - 'F_DB_NAME'=>$dbname, - 'F_DB_PREFIX'=>$table_prefix, - 'F_ADMIN'=>$admin_name, - 'F_ADMIN_EMAIL'=>$admin_mail, - 'F_LANG_SELECT'=>language_select($language), - - 'T_CONTENT_ENCODING' => $lang_info['charset'] - )); - -//-------------------------------------------------------- errors & infos display + 'L_BASE_TITLE'=>$lang['Initial_config'], + 'L_LANG_TITLE'=>$lang['Default_lang'], + 'L_DB_TITLE'=>$lang['step1_title'], + 'L_DB_HOST'=>$lang['step1_host'], + 'L_DB_HOST_INFO'=>$lang['step1_host_info'], + 'L_DB_USER'=>$lang['step1_user'], + 'L_DB_USER_INFO'=>$lang['step1_user_info'], + 'L_DB_PASS'=>$lang['step1_pass'], + 'L_DB_PASS_INFO'=>$lang['step1_pass_info'], + 'L_DB_NAME'=>$lang['step1_database'], + 'L_DB_NAME_INFO'=>$lang['step1_database_info'], + 'L_DB_PREFIX'=>$lang['step1_prefix'], + 'L_DB_PREFIX_INFO'=>$lang['step1_prefix_info'], + 'L_ADMIN_TITLE'=>$lang['step2_title'], + 'L_ADMIN'=>$lang['install_webmaster'], + 'L_ADMIN_INFO'=>$lang['install_webmaster_info'], + 'L_ADMIN_PASSWORD'=>$lang['step2_pwd'], + 'L_ADMIN_PASSWORD_INFO'=>$lang['step2_pwd_info'], + 'L_ADMIN_CONFIRM_PASSWORD'=>$lang['step2_pwd_conf'], + 'L_ADMIN_CONFIRM_PASSWORD_INFO'=>$lang['step2_pwd_conf_info'], + 'L_ADMIN_EMAIL'=>$lang['conf_mail_webmaster'], + 'L_ADMIN_EMAIL_INFO'=>$lang['conf_mail_webmaster_info'], + 'L_SUBMIT'=>$lang['Start_Install'], + 'L_HELP'=>$lang['install_help'], + 'L_ERR_COPY'=>$lang['step1_err_copy'], + 'L_END_TITLE'=>$lang['install_end_title'], + 'L_END_MESSAGE'=>$lang['install_end_message'], + + 'F_ACTION'=>add_session_id( 'install.php' ), + 'F_DB_HOST'=>$dbhost, + 'F_DB_USER'=>$dbuser, + 'F_DB_NAME'=>$dbname, + 'F_DB_PREFIX'=>$table_prefix, + 'F_ADMIN'=>$admin_name, + 'F_ADMIN_EMAIL'=>$admin_mail, + 'F_LANG_SELECT'=>language_select($language), + + 'T_CONTENT_ENCODING' => $lang_info['charset'] + )); + +//------------------------------------------------------ errors & infos display if ( sizeof( $errors ) != 0 ) { $template->assign_block_vars('errors',array()); |