Exemple #1
0
    $error = true;
}
// Get the current directory
$upload_dir = __DIR__;
// Connect to the database
$db = false;
$dbConnection = false;
$errorMessage = '';
$args = array('host' => $_DB_host, 'user' => $_DB_user, 'pass' => $_DB_pass, 'name' => $_DB_name, 'charset' => $db_connection_charset);
if (!$error && !TESTMODE) {
    try {
        $dbConnection = Geeklog\Db::connect(Geeklog\Db::DB_MYSQLI, $args);
        $db = true;
    } catch (\Exception $e) {
        try {
            $dbConnection = Geeklog\Db::connect(Geeklog\Db::DB_MYSQL, $args);
            $db = true;
        } catch (\Exception $e) {
            $errorMessage = $e->getMessage();
            $dbConnection = false;
        }
    }
    if (empty($dbConnection) || !$db) {
        echo $installer->getAlertMsg($LANG_ERROR[9] . $errorMessage . '<br>' . $LANG_ERROR[10]);
        $error = true;
    }
} else {
    $dbConnection = false;
}
// Single file mode
if (!$error && !isset($_REQUEST["fn"]) && $filename != "") {
 /**
  * Modify db-config.php
  *
  * @param   string $dbConfigFilePath Full path to db-config.php
  * @param   array  $db               Database information to save
  * @return  bool True if successful, false if not
  */
 private function writeConfig($dbConfigFilePath, array $db)
 {
     // We may have included db-config.php elsewhere already, in which case
     // all of these variables need to be imported from the global namespace
     global $_DB_host, $_DB_name, $_DB_user, $_DB_pass, $_DB_table_prefix, $_DB_dbms, $_DB_charset;
     require_once $dbConfigFilePath;
     // Grab the current DB values
     $isUtf8 = false;
     if (!empty($_DB_charset)) {
         $isUtf8 = $_DB_charset === 'utf8' || $_DB_charset === 'utf8mb4';
     } elseif (isset($db['utf8'])) {
         $isUtf8 = $db['utf8'];
     }
     $db = array('host' => isset($db['host']) ? $db['host'] : $_DB_host, 'name' => isset($db['name']) ? $db['name'] : $_DB_name, 'user' => isset($db['user']) ? $db['user'] : $_DB_user, 'pass' => isset($db['pass']) ? $db['pass'] : $_DB_pass, 'table_prefix' => isset($db['table_prefix']) ? $db['table_prefix'] : $_DB_table_prefix, 'type' => isset($db['type']) ? $db['type'] : $_DB_dbms);
     if ($db['type'] === 'mysql-innodb') {
         $db['type'] = 'mysql';
     }
     // Read in db-config.php so we can insert the DB information
     clearstatcache();
     $dbConfigData = @file_get_contents($dbConfigFilePath);
     // Replace the values with the new ones
     $dbConfigData = str_replace("\$_DB_host = '" . $_DB_host . "';", "\$_DB_host = '" . $db['host'] . "';", $dbConfigData);
     // Host
     $dbConfigData = str_replace("\$_DB_name = '" . $_DB_name . "';", "\$_DB_name = '" . $db['name'] . "';", $dbConfigData);
     // Database
     $dbConfigData = str_replace("\$_DB_user = '******';", "\$_DB_user = '******'user'] . "';", $dbConfigData);
     // Username
     $dbConfigData = str_replace("\$_DB_pass = '******';", "\$_DB_pass = '******'pass'] . "';", $dbConfigData);
     // Password
     $dbConfigData = str_replace("\$_DB_table_prefix = '" . $_DB_table_prefix . "';", "\$_DB_table_prefix = '" . $db['table_prefix'] . "';", $dbConfigData);
     // Table prefix
     $dbConfigData = str_replace("\$_DB_dbms = '" . $_DB_dbms . "';", "\$_DB_dbms = '" . $db['type'] . "';", $dbConfigData);
     // Database type ('mysql' or 'pgsql')
     if ($db['type'] === 'mysql' && $isUtf8 && version_compare(self::GL_VERSION, '2.1.2', '>=') && (!empty($_DB_charset) || $this->env['mode'] === 'install')) {
         if (!empty($_DB_charset)) {
             $db['charset'] = $_DB_charset;
         } else {
             require_once __DIR__ . '/db.class.php';
             $dbTypes = Geeklog\Db::getDrivers();
             if (in_array(Geeklog\Db::DB_MYSQLI, $dbTypes)) {
                 $driver = Geeklog\Db::connect(Geeklog\Db::DB_MYSQLI, $db);
             } else {
                 $driver = Geeklog\Db::connect(Geeklog\Db::DB_MYSQL, $db);
             }
             $db['charset'] = $driver->getVersion() >= 50503 ? 'utf8mb4' : 'utf8';
         }
         $dbConfigData = str_replace("\$_DB_charset = '" . $_DB_charset . "';", "\$_DB_charset = '" . $db['charset'] . "';", $dbConfigData);
         // Charset
     }
     // Write our changes to db-config.php
     $result = @file_put_contents($dbConfigFilePath, $dbConfigData) !== false;
     return $result;
 }