'; } // Open config.php ... if it exists elseif (@file_exists($config_file)) { include($config_file); // Is Piwigo already installed ? if (defined("PHPWG_INSTALLED")) { die('Piwigo is already installed'); } } include(PHPWG_ROOT_PATH .'include/dblayer/functions_'.$dblayer.'.inc.php'); include(PHPWG_ROOT_PATH . 'include/constants.php'); include(PHPWG_ROOT_PATH . 'include/functions.inc.php'); include(PHPWG_ROOT_PATH . 'admin/include/functions.php'); include(PHPWG_ROOT_PATH . 'admin/include/functions_upgrade.php'); if (isset($_GET['language'])) { $language = strip_tags($_GET['language']); } else { $language = 'en_UK'; // Try to get browser language foreach (get_languages('utf-8') as $language_code => $language_name) { if (substr($language_code,0,2) == @substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2)) { $language = $language_code; break; } } } if ('fr_FR' == $language) { define('PHPWG_DOMAIN', 'fr.piwigo.org'); } else if ('de_DE' == $language) { define('PHPWG_DOMAIN', 'de.piwigo.org'); } else if ('es_ES' == $language) { define('PHPWG_DOMAIN', 'es.piwigo.org'); } else if ('pl_PL' == $language) { define('PHPWG_DOMAIN', 'pl.piwigo.org'); } else if ('zh_CN' == $language) { define('PHPWG_DOMAIN', 'cn.piwigo.org'); } else { define('PHPWG_DOMAIN', 'piwigo.org'); } define('PHPWG_URL', 'http://'.PHPWG_DOMAIN); if (empty($step) || ($step != 3)) { load_language('common.lang', '', array('language' => $language, 'target_charset'=>'utf-8')); load_language('admin.lang', '', array('language' => $language, 'target_charset'=>'utf-8')); load_language('install.lang', '', array('language' => $language, 'target_charset'=>'utf-8')); } header('Content-Type: text/html; charset=UTF-8'); //------------------------------------------------- check php version if (version_compare(PHP_VERSION, REQUIRED_PHP_VERSION, '<')) { include(PHPWG_ROOT_PATH.'install/php5_apache_configuration.php'); } //----------------------------------------------------- template initialization include( PHPWG_ROOT_PATH .'include/template.class.php'); $template = new Template(PHPWG_ROOT_PATH.'admin/themes', 'roma'); $template->set_filenames( array('install' => 'install.tpl') ); if (!isset($step)) { $step = 1; } //---------------------------------------------------------------- form analyze if ( isset( $_POST['install'] )) { ob_start(); if (($pwg_db_link = pwg_db_connect($_POST['dbhost'], $_POST['dbuser'], $_POST['dbpasswd'], $_POST['dbname'], false))!==false) { if (pwg_select_db($_POST['dbname'], $pwg_db_link, false)!==false) { array_push( $infos, l10n('Parameters are correct') ); } else { array_push( $errors, l10n('Connection to server succeed, but it was impossible to connect to database') ); } ob_end_clean(); $required_version = constant('REQUIRED_'.strtoupper($dblayer).'_VERSION'); if ( version_compare(pwg_get_db_version(), $required_version, '>=') ) { $pwg_charset = 'utf-8'; $pwg_db_charset = 'utf8'; if ($dblayer=='mysql') { $install_charset_collate = "DEFAULT CHARACTER SET $pwg_db_charset"; } else { $install_charset_collate = ''; } } else { $pwg_charset = 'iso-8859-1'; $pwg_db_charset = 'latin1'; $install_charset_collate = ''; if ( !array_key_exists($language, get_languages($pwg_charset) ) ) { $language='en_UK'; } } } else { array_push( $errors, l10n('Can\'t connect to server') ); ob_end_clean(); } $webmaster = trim(preg_replace( '/\s{2,}/', ' ', $admin_name )); if ( empty($webmaster)) array_push( $errors, l10n('enter a login for webmaster') ); else if ( preg_match( '/[\'"]/', $webmaster ) ) array_push( $errors, l10n('webmaster login can\'t contain characters \' or "') ); if ( $admin_pass1 != $admin_pass2 || empty($admin_pass1) ) array_push( $errors, l10n('please enter your password again') ); if ( empty($admin_mail)) array_push( $errors, l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)') ); else { $error_mail_address = validate_mail_address(null, $admin_mail); if (!empty($error_mail_address)) array_push( $errors, $error_mail_address ); } if ( count( $errors ) == 0 ) { $step = 2; $file_content = ''; @umask(0111); // writing the configuration file if ( !($fp = @fopen( $config_file, 'w' ))) { $html_content = htmlentities( $file_content, ENT_QUOTES ); $html_content = nl2br( $html_content ); $error_copy = l10n('Copy the text in pink between hyphens and paste it into the file "local/config/database.inc.php"(Warning : database.inc.php must only contain what is in pink, no line return or space character)'); $error_copy .= '
--------------------------------------------------------------------
'; $error_copy .= '' . $html_content . ''; $error_copy .= '
--------------------------------------------------------------------
'; } @fputs($fp, $file_content, strlen($file_content)); @fclose($fp); // tables creation, based on piwigo_structure.sql execute_sqlfile( PHPWG_ROOT_PATH.'install/piwigo_structure-'.$dblayer.'.sql', DEFAULT_PREFIX_TABLE, $prefixeTable ); // We fill the tables with basic informations execute_sqlfile( PHPWG_ROOT_PATH.'install/config.sql', DEFAULT_PREFIX_TABLE, $prefixeTable ); $query = ' INSERT INTO '.$prefixeTable.'config (param,value,comment) VALUES (\'secret_key\',\'md5('.pwg_db_cast_to_text(DB_RANDOM_FUNCTION.'()').')\', \'a secret key specific to the gallery for internal use\');'; pwg_query($query); // fill $conf global array load_conf_from_db(); $insert = array( 'id' => 1, 'galleries_url' => PHPWG_ROOT_PATH.'galleries/', ); mass_inserts(SITES_TABLE, array_keys($insert), array($insert)); // webmaster admin user $inserts = array( array( 'id' => 1, 'username' => $admin_name, 'password' => md5($admin_pass1), 'mail_address' => $admin_mail, ), array( 'id' => 2, 'username' => 'guest', ), ); mass_inserts(USERS_TABLE, array_keys($inserts[0]), $inserts); create_user_infos(array(1,2), array('language' => $language)); // Available upgrades must be ignored after a fresh installation. To // make PWG avoid upgrading, we must tell it upgrades have already been // made. list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); define('CURRENT_DATE', $dbnow); $datas = array(); foreach (get_available_upgrade_ids() as $upgrade_id) { array_push( $datas, array( 'id' => $upgrade_id, 'applied' => CURRENT_DATE, 'description' => 'upgrade included in installation', ) ); } mass_inserts( UPGRADE_TABLE, array_keys($datas[0]), $datas ); } } //------------------------------------------------------ start template output if ($step == 3) { @umask(0111); // writing the new configuration file if ( !($fp = @fopen( $config_file, 'w' ))) { $html_content = htmlentities( $file_content, ENT_QUOTES ); $html_content = nl2br( $html_content ); $error_copy = l10n('Copy the text in pink between hyphens and paste it into the file "local/config/database.inc.php"(Warning : database.inc.php must only contain what is in pink, no line return or space character)'); $error_copy .= '
--------------------------------------------------------------------
'; $error_copy .= '' . $html_content . ''; $error_copy .= '
--------------------------------------------------------------------
'; } else { @fputs($fp, $file_content, strlen($file_content)); @fclose($fp); @unlink($old_config_file); header("Location: index.php"); exit(); } $template->assign( array( 'T_CONTENT_ENCODING' => 'utf-8', 'migration' => true )); } else { $dbengines = available_engines(); foreach (get_languages('utf-8') as $language_code => $language_name) { if ($language == $language_code) { $template->assign('language_selection', $language_code); } $languages_options[$language_code] = $language_name; } $template->assign('language_options', $languages_options); $template->assign( array( 'T_CONTENT_ENCODING' => 'utf-8', 'RELEASE' => PHPWG_VERSION, 'F_ACTION' => 'install.php?language=' . $language, 'F_DB_ENGINES' => $dbengines, 'F_DB_LAYER' => $dblayer, 'F_DB_HOST' => $dbhost, 'F_DB_USER' => $dbuser, 'F_DB_NAME' => $dbname, 'F_DB_PREFIX' => $prefixeTable, 'F_ADMIN' => $admin_name, 'F_ADMIN_EMAIL' => $admin_mail, 'L_INSTALL_HELP' => sprintf(l10n('Need help ? Ask your question on Piwigo message board.'), PHPWG_URL.'/forum'), )); } //------------------------------------------------------ errors & infos display if ($step == 1) { $template->assign('install', true); } elseif ($step == 3) { if (isset($error_copy)) { array_push($errors, $error_copy); } } else { array_push($infos, l10n('The configuration of Piwigo is finished, here is the next step

* go to the identification page and use the login/password given for webmaster
* this login will enable you to access to the administration panel and to the instructions in order to place pictures in your directories')); if (isset($error_copy)) { array_push($errors, $error_copy); } else { session_set_save_handler('pwg_session_open', 'pwg_session_close', 'pwg_session_read', 'pwg_session_write', 'pwg_session_destroy', 'pwg_session_gc' ); if ( function_exists('ini_set') ) { ini_set('session.use_cookies', $conf['session_use_cookies']); ini_set('session.use_only_cookies', $conf['session_use_only_cookies']); ini_set('session.use_trans_sid', intval($conf['session_use_trans_sid'])); ini_set('session.cookie_httponly', 1); } session_name($conf['session_name']); session_set_cookie_params(0, cookie_path()); $user = build_user(1, true); log_user($user['id'], false); } $template->assign( 'SUBSCRIBE_BASE_URL', get_newsletter_subscribe_base_url($language) ); } if (count($errors) != 0) { $template->assign('errors', $errors); } if (count($infos) != 0 ) { $template->assign('infos', $infos); } //----------------------------------------------------------- html code display $template->pparse('install'); ?>