diff --git a/admin/index.php b/admin/index.php
index ab015cc6..3974f953 100644
--- a/admin/index.php
+++ b/admin/index.php
@@ -6,10 +6,6 @@ require '../common.php';
const ADMIN_PANEL = true;
const MYAAC_ADMIN = true;
-if(file_exists(BASE . 'config.local.php')) {
- require_once BASE . 'config.local.php';
-}
-
if(file_exists(BASE . 'install') && (!isset($config['installed']) || !$config['installed']))
{
header('Location: ' . BASE_URL . 'install/');
@@ -34,12 +30,6 @@ if(!$db->hasTable('myaac_account_actions')) {
throw new RuntimeException('Seems that the table myaac_account_actions of MyAAC doesn\'t exist in the database. This is a fatal error. You can try to reinstall MyAAC by visiting this url.');
}
-if(config('env') === 'dev') {
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- error_reporting(E_ALL);
-}
-
// event system
require_once SYSTEM . 'hooks.php';
$hooks = new Hooks();
diff --git a/common.php b/common.php
index 267ca591..7bea3ca4 100644
--- a/common.php
+++ b/common.php
@@ -143,6 +143,23 @@ if(!IS_CLI) {
//define('CURRENT_URL', BASE_URL . $_SERVER['REQUEST_URI']);
}
+require SYSTEM . 'config.php';
+if (file_exists(BASE . 'config.local.php')) {
+ require BASE . 'config.local.php';
+}
+
+ini_set('log_errors', 1);
+if(@$config['env'] === 'dev') {
+ ini_set('display_errors', 1);
+ ini_set('display_startup_errors', 1);
+ error_reporting(E_ALL);
+}
+else {
+ ini_set('display_errors', 0);
+ ini_set('display_startup_errors', 0);
+ error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
+}
+
$autoloadFile = VENDOR . 'autoload.php';
if (!is_file($autoloadFile)) {
throw new RuntimeException('The vendor folder is missing. Please download Composer: https://getcomposer.org/download, install it and execute in the main MyAAC directory this command: composer install. Or download MyAAC from GitHub releases, which includes Vendor folder.');
diff --git a/index.php b/index.php
index 1e8b2b32..5ead45b9 100644
--- a/index.php
+++ b/index.php
@@ -56,22 +56,6 @@ if(preg_match("/^(.*)\.(gif|jpg|png|jpeg|tiff|bmp|css|js|less|map|html|zip|rar|g
exit;
}
-if(file_exists(BASE . 'config.local.php')) {
- require_once BASE . 'config.local.php';
-}
-
-ini_set('log_errors', 1);
-if(config('env') === 'dev') {
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- error_reporting(E_ALL);
-}
-else {
- ini_set('display_errors', 0);
- ini_set('display_startup_errors', 0);
- error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
-}
-
if((!isset($config['installed']) || !$config['installed']) && file_exists(BASE . 'install'))
{
header('Location: ' . BASE_URL . 'install/');
@@ -162,7 +146,7 @@ if(setting('core.backward_support')) {
$config['site'] = &$config;
$config['server'] = &$config['lua'];
- $config['site']['shop_system'] = $config['gifts_system'];
+ $config['site']['shop_system'] = setting('core.gifts_system');
$config['site']['gallery_page'] = true;
if(!isset($config['vdarkborder']))
diff --git a/install/index.php b/install/index.php
index 0cbcd658..22440101 100644
--- a/install/index.php
+++ b/install/index.php
@@ -12,9 +12,7 @@ require SYSTEM . 'functions.php';
require BASE . 'install/includes/functions.php';
require BASE . 'install/includes/locale.php';
require SYSTEM . 'clients.conf.php';
-
-if(file_exists(BASE . 'config.local.php'))
- require BASE . 'config.local.php';
+require LIBS . 'settings.php';
// ignore undefined index from Twig autoloader
$config['env'] = 'prod';
diff --git a/install/steps/5-database.php b/install/steps/5-database.php
index 3e1922ea..39010818 100644
--- a/install/steps/5-database.php
+++ b/install/steps/5-database.php
@@ -11,16 +11,11 @@ if(!isset($_SESSION['var_server_path'])) {
}
if(!$error) {
- $content = " 'prod',
+ ];
foreach($_SESSION as $key => $value)
{
@@ -34,12 +29,13 @@ if(!$error) {
}
if(!in_array($key, ['var_usage', 'var_date_timezone', 'var_client', 'var_account', 'var_account_id', 'var_password', 'var_password_confirm', 'var_step', 'var_email', 'var_player_name'], true)) {
- $content .= '$config[\'' . str_replace('var_', '', $key) . '\'] = \'' . $value . '\';';
- $content .= PHP_EOL;
+ $configToSave[str_replace('var_', '', $key)] = $value;
}
}
}
+ $configToSave['cache_prefix'] = 'myaac_' . generateRandomString(8, true, false, true);
+
require BASE . 'install/includes/config.php';
if(!$error) {
@@ -76,13 +72,8 @@ if(!$error) {
'message' => $locale['loading_spinner']
));
- $content .= '$config[\'cache_prefix\'] = \'myaac_' . generateRandomString(8, true, false, true, false) . '_\';';
-
- $saved = true;
- if(!$error) {
- $saved = file_put_contents(BASE . 'config.local.php', $content);
- }
-
+ $content = '';
+ $saved = Settings::saveConfig($configToSave, BASE . 'config.local.php', $content);
if($saved) {
success($locale['step_database_config_saved']);
if(!$error) {
@@ -93,7 +84,7 @@ if(!$error) {
$_SESSION['config_content'] = $content;
unset($_SESSION['saved']);
- $locale['step_database_error_file'] = str_replace('$FILE$', '' . BASE . 'config.local.php', $locale['step_database_error_file']);
+ $locale['step_database_error_file'] = str_replace('$FILE$', '' . BASE . 'config.php', $locale['step_database_error_file']);
error($locale['step_database_error_file'] . '
');
}
diff --git a/install/tools/7-finish.php b/install/tools/7-finish.php
index 23854887..22772714 100644
--- a/install/tools/7-finish.php
+++ b/install/tools/7-finish.php
@@ -11,11 +11,11 @@ ini_set('max_execution_time', 300);
ob_implicit_flush();
ob_end_flush();
header('X-Accel-Buffering: no');
-
+/*
if(isset($config['installed']) && $config['installed'] && !isset($_SESSION['saved'])) {
warning($locale['already_installed']);
return;
-}
+}*/
require SYSTEM . 'init.php';
diff --git a/login.php b/login.php
index 3ab0b5e9..6fb43f38 100644
--- a/login.php
+++ b/login.php
@@ -1,7 +1,5 @@
$value) {
diff --git a/config.php b/system/config.php
similarity index 100%
rename from config.php
rename to system/config.php
diff --git a/system/database.php b/system/database.php
index 41be6c87..e50e8568 100644
--- a/system/database.php
+++ b/system/database.php
@@ -9,7 +9,11 @@
*/
defined('MYAAC') or die('Direct access not allowed!');
-if(!isset($config['database_user'][0], $config['database_password'][0], $config['database_name'][0]))
+if (!isset($config['database_overwrite'])) {
+ $config['database_overwrite'] = false;
+}
+
+if(!$config['database_overwrite'] && !isset($config['database_user'][0], $config['database_password'][0], $config['database_name'][0]))
{
if(isset($config['lua']['sqlType'])) {// tfs 0.3
if(isset($config['lua']['mysqlHost'])) {// tfs 0.2
@@ -116,4 +120,4 @@ catch(PDOException $error) {
'
MySQL is not configured propertly in config.lua.' .
'MySQL server is not running.' .
'' . $error->getMessage());
-}
\ No newline at end of file
+}
diff --git a/system/init.php b/system/init.php
index 5cc1d70a..9dfa77cf 100644
--- a/system/init.php
+++ b/system/init.php
@@ -9,11 +9,6 @@
*/
defined('MYAAC') or die('Direct access not allowed!');
-// load configuration
-require_once BASE . 'config.php';
-if(file_exists(BASE . 'config.local.php')) // user customizations
- require BASE . 'config.local.php';
-
if(!isset($config['installed']) || !$config['installed']) {
throw new RuntimeException('MyAAC has not been installed yet or there was error during installation. Please install again.');
}
@@ -22,12 +17,16 @@ if(config('env') === 'dev') {
require SYSTEM . 'exception.php';
}
+if(empty($config['server_path'])) {
+ throw new RuntimeException('Server Path has been not set. Go to config.php and set it.');
+}
+
// take care of trailing slash at the end
if($config['server_path'][strlen($config['server_path']) - 1] !== '/')
$config['server_path'] .= '/';
// enable gzip compression if supported by the browser
-if($config['gzip_output'] && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false && function_exists('ob_gzhandler'))
+if(isset($config['gzip_output']) && $config['gzip_output'] && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false && function_exists('ob_gzhandler'))
ob_start('ob_gzhandler');
// cache
diff --git a/system/libs/Settings.php b/system/libs/Settings.php
index 026aeba0..a72b41e7 100644
--- a/system/libs/Settings.php
+++ b/system/libs/Settings.php
@@ -53,11 +53,22 @@ class Settings implements ArrayAccess
}
}
- public function save($pluginName, $settings) {
+ public function save($pluginName, $values) {
global $db;
+ if (!isset($this->settingsFile[$pluginName])) {
+ throw new RuntimeException('Error on save settings: plugin does not exist');
+ }
+
+ $settings = $this->settingsFile[$pluginName];
+ if (isset($settings['callbacks']['beforeSave'])) {
+ if (!$settings['callbacks']['beforeSave']($settings, $values)) {
+ return false;
+ }
+ }
+
$db->query('DELETE FROM `' . TABLE_PREFIX . 'settings` WHERE `name` = ' . $db->quote($pluginName) . ';');
- foreach ($settings as $key => $value) {
+ foreach ($values as $key => $value) {
try {
$db->insert(TABLE_PREFIX . 'settings', ['name' => $pluginName, 'key' => $key, 'value' => $value]);
} catch (PDOException $error) {
@@ -69,6 +80,8 @@ class Settings implements ArrayAccess
if ($cache->enabled()) {
$cache->delete('settings');
}
+
+ return true;
}
public function updateInDatabase($pluginName, $key, $value)
@@ -103,6 +116,18 @@ class Settings implements ArrayAccess
}
}
+ $config = [];
+ require BASE . 'config.local.php';
+
+ foreach ($config as $key => $value) {
+ if (is_bool($value)) {
+ $settingsDb[$key] = $value ? 'true' : 'false';
+ }
+ else {
+ $settingsDb[$key] = (string)$value;
+ }
+ }
+
$javascript = '';
ob_start();
?>
@@ -261,7 +286,7 @@ class Settings implements ArrayAccess
echo '