diff --git a/admin/pages/settings.php b/admin/pages/settings.php index e5eae974..c33e76ef 100644 --- a/admin/pages/settings.php +++ b/admin/pages/settings.php @@ -21,11 +21,11 @@ $plugin = $_GET['plugin']; if($plugin != 'core') { $pluginSettings = Plugins::getPluginSettings($plugin); if (!$pluginSettings) { - error('This plugin does not exist or does not have options defined.'); + error('This plugin does not exist or does not have settings defined.'); return; } - $settingsFilePath = PLUGINS . $plugin . '/settings.php'; + $settingsFilePath = BASE . $pluginSettings; } else { $settingsFilePath = SYSTEM . 'settings.php'; @@ -36,13 +36,7 @@ if (!file_exists($settingsFilePath)) { return; } -if($plugin === 'core') { - $settingsFile = require $settingsFilePath; -} -else { - $settingsFile = require $settingsFilePath; -} - +$settingsFile = require $settingsFilePath; if (!is_array($settingsFile)) { return; } @@ -61,182 +55,14 @@ if (isset($_POST['save'])) { if ($cache->enabled()) { $cache->delete('settings'); } + success('Saved at ' . date('H:i')); } $title = ($plugin == 'core' ? 'Settings' : 'Plugin Settings - ' . $plugin); -$query = 'SELECT `key`, `value` FROM `' . TABLE_PREFIX . 'settings` WHERE `plugin_name` = ' . $db->quote($plugin) . ';'; -$query = $db->query($query); +$settings = Settings::parse($plugin, $settingsFile['settings']); -$settingsDb = []; -if($query->rowCount() > 0) { - foreach($query->fetchAll(PDO::FETCH_ASSOC) as $value) { - $settingsDb[$value['key']] = $value['value']; - } -} - -?> - -
+$twig->display('admin.settings.html.twig', [ + 'settings' => $settings, +]); diff --git a/system/compat_config.php b/system/compat_config.php index 3bb926c4..2529442f 100644 --- a/system/compat_config.php +++ b/system/compat_config.php @@ -18,8 +18,30 @@ $deprecatedConfig = [ 'views_counter', 'outfit_images_url', 'item_images_url', + 'account_country', + 'team_display_outfit', + 'team_display_status', + 'team_display_world', + 'team_display_lastlogin', + 'multiworld', ]; foreach ($deprecatedConfig as $value) { - $config[$value] = $settings['core.'.$value]['value']; + config( + [ + $value, + $settings['core.'.$value]['value'] + ] + ); + + //var_dump($settings['core.'.$value]['value']); } + +$vocationsParsed = array_map( + function(string $value): string { + return trim($value); + }, + explode(',', $settings['core.vocations']['value']) +); + +config(['vocations', $vocationsParsed]); diff --git a/system/functions.php b/system/functions.php index e6f7b9d9..475fa174 100644 --- a/system/functions.php +++ b/system/functions.php @@ -1492,8 +1492,8 @@ function right($str, $length) { } function getCreatureImgPath($creature){ - $creature_path = config('creatures_images_url'); - $creature_gfx_name = trim(strtolower($creature)) . config('creatures_images_extension'); + $creature_path = config('monsters_images_url'); + $creature_gfx_name = trim(strtolower($creature)) . config('monsters_images_extension'); if (!file_exists($creature_path . $creature_gfx_name)) { $creature_gfx_name = str_replace(" ", "", $creature_gfx_name); if (file_exists($creature_path . $creature_gfx_name)) { diff --git a/system/init.php b/system/init.php index 057bb7a4..0821d621 100644 --- a/system/init.php +++ b/system/init.php @@ -148,35 +148,5 @@ define('USE_ACCOUNT_NAME', $db->hasColumn('accounts', 'name')); define('USE_ACCOUNT_NUMBER', $db->hasColumn('accounts', 'number')); define('USE_ACCOUNT_SALT', $db->hasColumn('accounts', 'salt')); -// load vocation names -$tmp = ''; -if($cache->enabled() && $cache->fetch('vocations', $tmp)) { - $config['vocations'] = unserialize($tmp); -} -else { - if(!class_exists('DOMDocument')) { - throw new RuntimeException('Please install PHP xml extension. MyAAC will not work without it.'); - } - - $vocations = new DOMDocument(); - $file = $config['data_path'] . 'XML/vocations.xml'; - if(!@file_exists($file)) - $file = $config['data_path'] . 'vocations.xml'; - - if(!$vocations->load($file)) - throw new RuntimeException('ERROR: Cannot load vocations.xml - the file is malformed. Check the file with xml syntax validator.'); - - $config['vocations'] = array(); - foreach($vocations->getElementsByTagName('vocation') as $vocation) { - $id = $vocation->getAttribute('id'); - $config['vocations'][$id] = $vocation->getAttribute('name'); - } - - if($cache->enabled()) { - $cache->set('vocations', serialize($config['vocations']), 120); - } -} -unset($tmp, $id, $vocation); - require LIBS . 'Towns.php'; Towns::load(); diff --git a/system/libs/Settings.php b/system/libs/Settings.php index ca5b2634..ff44aceb 100644 --- a/system/libs/Settings.php +++ b/system/libs/Settings.php @@ -18,7 +18,7 @@ class Settings implements ArrayAccess /** * @return Settings */ - public static function getInstance() + public static function getInstance(): Settings { if (!self::$instance) { self::$instance = new self(); @@ -52,6 +52,210 @@ class Settings implements ArrayAccess } } + public static function parse($plugin, $settings): string + { + global $db; + + $query = 'SELECT `key`, `value` FROM `' . TABLE_PREFIX . 'settings` WHERE `plugin_name` = ' . $db->quote($plugin) . ';'; + $query = $db->query($query); + + $settingsDb = []; + if($query->rowCount() > 0) { + foreach($query->fetchAll(PDO::FETCH_ASSOC) as $value) { + $settingsDb[$value['key']] = $value['value']; + } + } + + ob_start(); + ?> + +Name | +Value | +Description | +
---|---|---|
+ | + '; + } + + else if($setting['type'] === 'textarea') { + echo ''; + } + + else if ($setting['type'] === 'options') { + if ($setting['options'] === '$templates') { + $templates = []; + foreach (get_templates() as $value) { + $templates[$value] = $value; + } + + $setting['options'] = $templates; + } + + else if($setting['options'] === '$clients') { + $clients = []; + foreach((array)config('clients') as $client) { + + $client_version = (string)($client / 100); + if(strpos($client_version, '.') === false) + $client_version .= '.0'; + + $clients[$client] = $client_version; + } + + $setting['options'] = $clients; + } + + else { + if (is_string($setting['options'])) { + $setting['options'] = explode(',', $setting['options']); + foreach ($setting['options'] as &$option) { + $option = trim($option); + } + } + } + + echo ''; + } + + if (!isset($setting['hidden']) || !$setting['hidden']) { + ?> + | +
+
+ ';
+ echo 'Default: ';
+ if ($setting['type'] === 'boolean') {
+ echo ($setting['default'] ? 'Yes' : 'No');
+ }
+ else if (in_array($setting['type'], ['text', 'number', 'email', 'password', 'textarea'])) {
+ echo $setting['default'];
+ }
+ else if ($setting['type'] === 'options') {
+ echo $setting['options'][$setting['default']];
+ }
+ ?>
+
+ |
+