_ci = &get_instance(); if (!function_exists('mysqli_connect')) { $this->dbdriver = 'mysql'; } } public function install($config, $username, $password) { $config['dbdriver'] = $this->dbdriver; $config['db_debug'] = true; $config['char_set'] = "utf8"; $config['dbcollat'] = "utf8_general_ci"; $config['autoinit'] = true; $this->_ci->load->database($config); $this->_ci->load->dbforge(); $has_utf8mb4 = (version_compare($this->_ci->db->version(), "5.5") == 1); if ($has_utf8mb4) { $config['char_set'] = "utf8mb4"; $config['dbcollat'] = "utf8mb4_general_ci"; } $schema = file_get_contents(APPPATH . 'schema/pancake.sql'); if (!$this->_write_db_config($config, $has_utf8mb4)) { return false; } $data["username"] = $username; $data["password"] = $password; $data['salt'] = substr(md5(uniqid(rand(), true)), 0, 10); $data['password'] = sha1($data['password'] . $data['salt']); $data['dbprefix'] = $config['dbprefix']; $data['version'] = file_get_contents(FCPATH . 'system/pancake/VERSION'); $data['rss_password'] = random_string('alnum', 12); $data['timezone'] = @date_default_timezone_get(); // Include migration config to know which migration to start from include './system/pancake/config/migration.php'; $data['migration'] = $config['migration_version']; $data['now'] = time(); $data['now_datetime'] = date("Y-m-d H:i:s"); $this->_ci->config->load("license"); $data["site_name"] = "Pancake"; $data["first_name"] = $this->_ci->config->item("first_name"); $data["notify_email"] = $this->_ci->config->item("email"); $data["last_name"] = $this->_ci->config->item("last_name"); $data["license_key"] = $this->_ci->config->item("license_key"); $data["currency"] = "USD"; $data["tax_rate"] = "0"; $data["theme"] = "flat-pancake"; $data["mailing_address"] = ""; foreach ($data as $key => $val) { if (strtoupper($key) == "TAX_RATE") { // Fixes an issue with MySQL in Strict Mode if the tax was empty. $val = (float) $val; } $escaped_val = $this->_ci->db->escape_str($val); $schema = str_replace('{' . strtoupper($key) . '}', $escaped_val, $schema); } $schema = explode('-- split --', $schema); foreach ($schema as $query) { if (stristr($query, "charset = utf8") !== false && $has_utf8mb4) { $query = str_ireplace("charset = utf8", "charset = utf8mb4", $query); } if (!$this->_ci->db->query(rtrim(trim($query), "\n;"))) { switch ($this->dbdriver) { case 'mysql': $error = mysql_error(); break; case 'mysqli': $error = mysqli_error($this->_ci->db->conn_id); break; } show_error(strtoupper($this->dbdriver) . ' ERROR: ' . $error); } } $this->_ci->load->helper("cookie"); set_cookie(array( 'name' => 'identity', 'value' => $username, 'expire' => 60 * 60 * 24 * 365 * 2, )); $salt = sha1($password); $this->_ci->db->update("users", ['remember_code' => $salt]); set_cookie(array( 'name' => 'remember_code', 'value' => $salt, 'expire' => 60 * 60 * 24 * 365 * 2, )); return true; } private function _write_db_config($config, $has_utf8mb4) { $replace = array( '{HOSTNAME}' => $config['hostname'], '{USERNAME}' => $config['username'], '{PASSWORD}' => $config['password'], '{DATABASE}' => $config['database'], '{PORT}' => $config['port'], '{DBPREFIX}' => $config['dbprefix'], ); $charset = $has_utf8mb4 ? "utf8mb4" : "utf8"; $template = <<