diff --git a/admin/pages/accounts.php b/admin/pages/accounts.php
index 759b9361..24338fd8 100644
--- a/admin/pages/accounts.php
+++ b/admin/pages/accounts.php
@@ -361,7 +361,7 @@ else if (isset($_REQUEST['search'])) {
- Email: getEMail() . '">Send Mail)' : ''); ?>
+ Email: getEMail() . '">Send Mail)' : ''); ?>
diff --git a/admin/pages/mailer.php b/admin/pages/mailer.php
index ea45eeb0..7d12f14b 100644
--- a/admin/pages/mailer.php
+++ b/admin/pages/mailer.php
@@ -15,7 +15,7 @@ if (!hasFlag(FLAG_CONTENT_MAILER) && !superAdmin()) {
return;
}
-if (!config('mail_enabled')) {
+if (!setting('core.mail_enabled')) {
echo 'Mail support disabled in config.';
return;
}
diff --git a/admin/pages/settings.php b/admin/pages/settings.php
index c33e76ef..a65af8ff 100644
--- a/admin/pages/settings.php
+++ b/admin/pages/settings.php
@@ -61,7 +61,7 @@ if (isset($_POST['save'])) {
$title = ($plugin == 'core' ? 'Settings' : 'Plugin Settings - ' . $plugin);
-$settings = Settings::parse($plugin, $settingsFile['settings']);
+$settings = Settings::display($plugin, $settingsFile['settings']);
$twig->display('admin.settings.html.twig', [
'settings' => $settings,
diff --git a/admin/pages/visitors.php b/admin/pages/visitors.php
index 77626eb0..8ab78521 100644
--- a/admin/pages/visitors.php
+++ b/admin/pages/visitors.php
@@ -16,7 +16,7 @@ use DeviceDetector\Parser\OperatingSystem;
$title = 'Visitors';
$use_datatable = true;
-if (!$config['visitors_counter']): ?>
+if (!setting('core.visitors_counter')): ?>
Visitors counter is disabled.
You can enable it by editing this configurable in
config.local.php file:
$config['visitors_counter'] = true;
@@ -25,10 +25,9 @@ if (!$config['visitors_counter']): ?>
endif;
require SYSTEM . 'libs/visitors.php';
-$visitors = new Visitors($config['visitors_counter_ttl']);
+$visitors = new Visitors(setting('core.visitors_counter_ttl'));
-function compare($a, $b)
-{
+function compare($a, $b): int {
return $a['lastvisit'] > $b['lastvisit'] ? -1 : 1;
}
@@ -61,7 +60,7 @@ foreach ($tmp as &$visitor) {
}
$twig->display('admin.visitors.html.twig', array(
- 'config_visitors_counter_ttl' => $config['visitors_counter_ttl'],
+ 'config_visitors_counter_ttl' => setting('core.visitors_counter_ttl'),
'visitors' => $tmp
));
?>
diff --git a/admin/template/menus.php b/admin/template/menus.php
index 526a528d..5e60b39e 100644
--- a/admin/template/menus.php
+++ b/admin/template/menus.php
@@ -17,7 +17,7 @@ return [
['name' => 'Add', 'link' => 'changelog&action=new', 'icon' => 'plus', 'order' => 20],
],
],
- ['name' => 'Mailer', 'icon' => 'envelope', 'order' => 40, 'link' => 'mailer', 'disabled' => !config('mail_enabled')],
+ ['name' => 'Mailer', 'icon' => 'envelope', 'order' => 40, 'link' => 'mailer', 'disabled' => !setting('core.mail_enabled')],
['name' => 'Pages', 'icon' => 'book', 'order' => 50, 'link' =>
[
['name' => 'View', 'link' => 'pages', 'icon' => 'list', 'order' => 10],
diff --git a/config.php b/config.php
index b9acd74d..f6298198 100644
--- a/config.php
+++ b/config.php
@@ -61,23 +61,6 @@ $config = array(
'account_change_character_sex_points' => 30, // cost of sex change
'characters_per_account' => 10, // max. number of characters per account
- // mail
- 'mail_enabled' => false, // is aac maker configured to send e-mails?
- 'mail_address' => 'no-reply@your-server.org', // server e-mail address (from:)
- 'mail_admin' => 'your-address@your-server.org', // admin email address, where mails from contact form will be sent
- 'mail_signature' => array( // signature that will be included at the end of every message sent using _mail function
- 'plain' => ""/*"--\nMy Server,\nhttp://www.myserver.com"*/,
- 'html' => ''/*'
My Server,\n
myserver.com '*/
- ),
- 'smtp_enabled' => false, // send by smtp or mail function (set false if use mail function, set to true if you use GMail or Microsoft Outlook)
- 'smtp_host' => '', // mail host. smtp.gmail.com for GMail / smtp-mail.outlook.com for Microsoft Outlook
- 'smtp_port' => 25, // 25 (default) / 465 (ssl, GMail) / 587 (tls, Microsoft Outlook)
- 'smtp_auth' => true, // need authorization?
- 'smtp_user' => 'admin@example.org', // here your email username
- 'smtp_pass' => '',
- 'smtp_secure' => '', // What kind of encryption to use on the SMTP connection. Options: '', 'ssl' (GMail) or 'tls' (Microsoft Outlook)
- 'smtp_debug' => false, // set true to debug (you will see more info in error.log)
-
//
'generate_new_reckey' => true, // let player generate new recovery key, he will receive e-mail with new rec key (not display on page, hacker can't generate rec key)
'generate_new_reckey_price' => 20, // price for new recovery key
@@ -217,13 +200,8 @@ $config = array(
'admin_panel_modules' => 'statistics,web_status,server_status,lastlogin,created,points,coins,balance', // default - statistics,web_status,server_status,lastlogin,created,points,coins,balance
// other
- 'anonymous_usage_statistics' => true,
'email_lai_sec_interval' => 60, // time in seconds between e-mails to one account from lost account interface, block spam
'google_analytics_id' => '', // e.g.: UA-XXXXXXX-X
- 'experiencetable_columns' => 3, // how many columns to display in experience table page. * experiencetable_rows, 5 = 500 (will show up to 500 level)
- 'experiencetable_rows' => 200, // till how many levels in one column
- 'date_timezone' => 'Europe/Berlin', // more info at http://php.net/manual/en/timezones.php
- 'footer_show_load_time' => true, // display load time of the page in the footer
'npc' => array()
);
diff --git a/index.php b/index.php
index 70bfdebf..5f887570 100644
--- a/index.php
+++ b/index.php
@@ -104,7 +104,7 @@ $hooks->trigger(HOOK_STARTUP);
// anonymous usage statistics
// sent only when user agrees
-if(isset($config['anonymous_usage_statistics']) && $config['anonymous_usage_statistics']) {
+if(setting('core.anonymous_usage_statistics')) {
$report_time = 30 * 24 * 60 * 60; // report one time per 30 days
$should_report = true;
@@ -137,17 +137,16 @@ if(isset($config['anonymous_usage_statistics']) && $config['anonymous_usage_stat
}
}
-if($config['views_counter'])
+if(setting('core.views_counter'))
require_once SYSTEM . 'counter.php';
-if($config['visitors_counter'])
-{
+if(setting('core.visitors_counter')) {
require_once SYSTEM . 'libs/visitors.php';
- $visitors = new Visitors($config['visitors_counter_ttl']);
+ $visitors = new Visitors(setting('core.visitors_counter_ttl'));
}
// backward support for gesior
-if($config['backward_support']) {
+if(setting('core.backward_support')) {
define('INITIALIZED', true);
$SQL = $db;
$layout_header = template_header();
diff --git a/install/index.php b/install/index.php
index 1c008c38..7de02a06 100644
--- a/install/index.php
+++ b/install/index.php
@@ -91,10 +91,6 @@ if($step == 'database') {
break;
}
}
- else if($key == 'mail_admin' && !Validator::email($value)) {
- $errors[] = $locale['step_config_mail_admin_error'];
- break;
- }
else if($key == 'timezone' && !in_array($value, DateTimeZone::listIdentifiers())) {
$errors[] = $locale['step_config_timezone_error'];
break;
diff --git a/install/steps/5-database.php b/install/steps/5-database.php
index 13a79d56..7fb1969b 100644
--- a/install/steps/5-database.php
+++ b/install/steps/5-database.php
@@ -79,11 +79,6 @@ if(!$error) {
'message' => $locale['loading_spinner']
));
- if(!Validator::email($_SESSION['var_mail_admin'])) {
- error($locale['step_config_mail_admin_error']);
- $error = true;
- }
-
$content .= '$config[\'session_prefix\'] = \'myaac_' . generateRandomString(8, true, false, true, false) . '_\';';
$content .= PHP_EOL;
$content .= '$config[\'cache_prefix\'] = \'myaac_' . generateRandomString(8, true, false, true, false) . '_\';';
diff --git a/system/compat/config.php b/system/compat/config.php
index 2529442f..39cb5833 100644
--- a/system/compat/config.php
+++ b/system/compat/config.php
@@ -30,7 +30,7 @@ foreach ($deprecatedConfig as $value) {
config(
[
$value,
- $settings['core.'.$value]['value']
+ setting('core.'.$value)
]
);
@@ -41,7 +41,7 @@ $vocationsParsed = array_map(
function(string $value): string {
return trim($value);
},
- explode(',', $settings['core.vocations']['value'])
+ explode(',', setting('core.vocations'))
);
config(['vocations', $vocationsParsed]);
diff --git a/system/functions.php b/system/functions.php
index 475fa174..1ad9be6e 100644
--- a/system/functions.php
+++ b/system/functions.php
@@ -32,52 +32,48 @@ function message($message, $type, $return)
return true;
}
function success($message, $return = false) {
- return message($message, 'success', $return);
+ return message($message, 'success', $return);
}
function warning($message, $return = false) {
- return message($message, 'warning', $return);
+ return message($message, 'warning', $return);
}
function note($message, $return = false) {
- return message($message, 'note', $return);
+ return message($message, 'note', $return);
}
function error($message, $return = false) {
- return message($message, ((defined('MYAAC_INSTALL') || defined('MYAAC_ADMIN')) ? 'danger' : 'error'), $return);
+ return message($message, ((defined('MYAAC_INSTALL') || defined('MYAAC_ADMIN')) ? 'danger' : 'error'), $return);
}
-function longToIp($ip)
+function longToIp($ip): string
{
$exp = explode(".", long2ip($ip));
return $exp[3].".".$exp[2].".".$exp[1].".".$exp[0];
}
-function generateLink($url, $name, $blank = false) {
+function generateLink($url, $name, $blank = false): string {
return '
' . $name . ' ';
}
-function getFullLink($page, $name, $blank = false) {
+function getFullLink($page, $name, $blank = false): string {
return generateLink(getLink($page), $name, $blank);
}
-function getLink($page, $action = null)
-{
- $settings = Settings::getInstance();
- return BASE_URL . ($settings['core.friendly_urls']['value'] ? '' : 'index.php/') . $page . ($action ? '/' . $action : '');
+function getLink($page, $action = null): string {
+ return BASE_URL . (setting('core.friendly_urls') ? '' : 'index.php/') . $page . ($action ? '/' . $action : '');
}
-function internalLayoutLink($page, $action = null) {return getLink($page, $action);}
-
-function getForumThreadLink($thread_id, $page = NULL)
-{
- $settings = Settings::getInstance();
- return BASE_URL . ($settings['core.friendly_urls']['value'] ? '' : 'index.php/') . 'forum/thread/' . (int)$thread_id . (isset($page) ? '/' . $page : '');
+function internalLayoutLink($page, $action = null): string {
+ return getLink($page, $action);
}
-function getForumBoardLink($board_id, $page = NULL)
-{
- $settings = Settings::getInstance();
- return BASE_URL . ($settings['core.friendly_urls']['value'] ? '' : 'index.php/') . 'forum/board/' . (int)$board_id . (isset($page) ? '/' . $page : '');
+function getForumThreadLink($thread_id, $page = NULL): string {
+ return BASE_URL . (setting('core.friendly_urls') ? '' : 'index.php/') . 'forum/thread/' . (int)$thread_id . (isset($page) ? '/' . $page : '');
}
-function getPlayerLink($name, $generate = true)
+function getForumBoardLink($board_id, $page = NULL): string {
+ return BASE_URL . (setting('core.friendly_urls') ? '' : 'index.php/') . 'forum/board/' . (int)$board_id . (isset($page) ? '/' . $page : '');
+}
+
+function getPlayerLink($name, $generate = true): string
{
if(is_numeric($name))
{
@@ -87,23 +83,21 @@ function getPlayerLink($name, $generate = true)
$name = $player->getName();
}
- $settings = Settings::getInstance();
- $url = BASE_URL . ($settings['core.friendly_urls']['value'] ? '' : 'index.php/') . 'characters/' . urlencode($name);
+ $url = BASE_URL . (setting('core.friendly_urls') ? '' : 'index.php/') . 'characters/' . urlencode($name);
if(!$generate) return $url;
return generateLink($url, $name);
}
-function getMonsterLink($name, $generate = true)
+function getMonsterLink($name, $generate = true): string
{
- $settings = Settings::getInstance();
- $url = BASE_URL . ($settings['core.friendly_urls']['value'] ? '' : 'index.php/') . 'creatures/' . urlencode($name);
+ $url = BASE_URL . (setting('core.friendly_urls') ? '' : 'index.php/') . 'creatures/' . urlencode($name);
if(!$generate) return $url;
return generateLink($url, $name);
}
-function getHouseLink($name, $generate = true)
+function getHouseLink($name, $generate = true): string
{
global $db;
@@ -115,17 +109,14 @@ function getHouseLink($name, $generate = true)
$name = $house->fetchColumn();
}
- $settings = Settings::getInstance();
- $url = BASE_URL . ($settings['core.friendly_urls']['value'] ? '' : 'index.php/') . 'houses/' . urlencode($name);
+ $url = BASE_URL . (setting('core.friendly_urls') ? '' : 'index.php/') . 'houses/' . urlencode($name);
if(!$generate) return $url;
return generateLink($url, $name);
}
-function getGuildLink($name, $generate = true)
+function getGuildLink($name, $generate = true): string
{
- global $config;
-
if(is_numeric($name)) {
$name = getGuildNameById($name);
if ($name === false) {
@@ -133,8 +124,7 @@ function getGuildLink($name, $generate = true)
}
}
- $settings = Settings::getInstance();
- $url = BASE_URL . ($settings['core.friendly_urls']['value'] ? '' : 'index.php/') . 'guilds/' . urlencode($name);
+ $url = BASE_URL . (setting('core.friendly_urls') ? '' : 'index.php/') . 'guilds/' . urlencode($name);
if(!$generate) return $url;
return generateLink($url, $name);
@@ -180,7 +170,7 @@ function getItemRarity($chance) {
return '';
}
-function getFlagImage($country)
+function getFlagImage($country): string
{
if(!isset($country[0]))
return '';
@@ -202,7 +192,7 @@ function getFlagImage($country)
* @param mixed $v Variable to check.
* @return bool Value boolean status.
*/
-function getBoolean($v)
+function getBoolean($v): bool
{
if(is_bool($v)) {
return $v;
@@ -225,7 +215,7 @@ function getBoolean($v)
* @param bool $special Should special characters by used?
* @return string Generated string.
*/
-function generateRandomString($length, $lowCase = true, $upCase = false, $numeric = false, $special = false)
+function generateRandomString($length, $lowCase = true, $upCase = false, $numeric = false, $special = false): string
{
$characters = '';
if($lowCase)
@@ -465,7 +455,7 @@ function tickers()
* Types: head_start, head_end, body_start, body_end, center_top
*
*/
-function template_place_holder($type)
+function template_place_holder($type): string
{
global $twig, $template_place_holders;
$ret = '';
@@ -489,7 +479,7 @@ function template_place_holder($type)
/**
* Returns content to be used by templates.
*/
-function template_header($is_admin = false)
+function template_header($is_admin = false): string
{
global $title_full, $config, $twig;
$charset = isset($config['charset']) ? $config['charset'] : 'utf-8';
@@ -506,29 +496,32 @@ function template_header($is_admin = false)
/**
* Returns footer content to be used by templates.
*/
-function template_footer()
+function template_footer(): string
{
- global $config, $views_counter;
+ global $views_counter;
$ret = '';
- if(admin())
+ if(admin()) {
$ret .= generateLink(ADMIN_URL, 'Admin Panel', true);
+ }
- if($config['visitors_counter'])
- {
+ if(setting('core.visitors_counter')) {
global $visitors;
$amount = $visitors->getAmountVisitors();
$ret .= '
Currently there ' . ($amount > 1 ? 'are' : 'is') . ' ' . $amount . ' visitor' . ($amount > 1 ? 's' : '') . '.';
}
- if($config['views_counter'])
+ if(setting('core.views_counter')) {
$ret .= '
Page has been viewed ' . $views_counter . ' times.';
+ }
- if(config('footer_show_load_time')) {
+ if(setting('core.footer_load_time')) {
$ret .= '
Load time: ' . round(microtime(true) - START_TIME, 4) . ' seconds.';
}
- if(isset($config['footer'][0]))
- $ret .= '
' . $config['footer'];
+ $settingFooter = setting('core.footer');
+ if(isset($settingFooter[0])) {
+ $ret .= '
' . $settingFooter;
+ }
// please respect my work and help spreading the word, thanks!
return $ret . '
' . base64_decode('UG93ZXJlZCBieSA8YSBocmVmPSJodHRwOi8vbXktYWFjLm9yZyIgdGFyZ2V0PSJfYmxhbmsiPk15QUFDLjwvYT4=');
@@ -822,7 +815,7 @@ function getWorldName($id)
/**
* Mailing users.
- * $config['mail_enabled'] have to be enabled.
+ * Mailing has to be enabled in settings (in Admin Panel).
*
* @param string $to Recipient email address.
* @param string $subject Subject of the message.
@@ -834,8 +827,9 @@ function _mail($to, $subject, $body, $altBody = '', $add_html_tags = true)
{
global $mailer, $config;
- if (!config('mail_enabled')) {
- log_append('mailer-error.log', '_mail() function has been used, but config.mail_enabled is disabled.');
+ if (!setting('core.mail_enabled')) {
+ log_append('mailer-error.log', '_mail() function has been used, but Mail Support is disabled.');
+ return false;
}
if(!$mailer)
@@ -847,47 +841,60 @@ function _mail($to, $subject, $body, $altBody = '', $add_html_tags = true)
$mailer->clearAllRecipients();
}
- $signature_html = '';
- if(isset($config['mail_signature']['html']))
- $signature_html = $config['mail_signature']['html'];
-
+ $signature_html = setting('core.mail_signature_html');
if($add_html_tags && isset($body[0]))
$tmp_body = '' . $body . '
' . $signature_html . '';
else
$tmp_body = $body . '
' . $signature_html;
- if($config['smtp_enabled'])
+ define('MAIL_MAIL', 0);
+ define('MAIL_SMTP', 1);
+
+ $mailOption = setting('core.mail_option');
+ if($mailOption == MAIL_SMTP)
{
$mailer->isSMTP();
- $mailer->Host = $config['smtp_host'];
- $mailer->Port = (int)$config['smtp_port'];
- $mailer->SMTPAuth = $config['smtp_auth'];
- $mailer->Username = $config['smtp_user'];
- $mailer->Password = $config['smtp_pass'];
- $mailer->SMTPSecure = isset($config['smtp_secure']) ? $config['smtp_secure'] : '';
+ $mailer->Host = setting('core.smtp_host');
+ $mailer->Port = setting('core.smtp_port');
+ $mailer->SMTPAuth = setting('core.smtp_auth');
+ $mailer->Username = setting('core.smtp_user');
+ $mailer->Password = setting('core.smtp_pass');
+
+ define('SMTP_SECURITY_NONE', 0);
+ define('SMTP_SECURITY_SSL', 1);
+ define('SMTP_SECURITY_TLS', 2);
+
+ $security = setting('core.smtp_security');
+
+ $tmp = '';
+ if ($security === SMTP_SECURITY_SSL) {
+ $tmp = 'ssl';
+ }
+ else if ($security == SMTP_SECURITY_TLS) {
+ $tmp = 'tls';
+ }
+
+ $mailer->SMTPSecure = $tmp;
}
else {
$mailer->isMail();
}
$mailer->isHTML(isset($body[0]) > 0);
- $mailer->From = $config['mail_address'];
- $mailer->Sender = $config['mail_address'];
+ $mailer->From = setting('core.mail_address');
+ $mailer->Sender = setting('core.mail_address');
$mailer->CharSet = 'utf-8';
$mailer->FromName = $config['lua']['serverName'];
$mailer->Subject = $subject;
$mailer->addAddress($to);
$mailer->Body = $tmp_body;
- if(config('smtp_debug')) {
+ if(setting('core.smtp_debug')) {
$mailer->SMTPDebug = 2;
$mailer->Debugoutput = 'echo';
}
- $signature_plain = '';
- if(isset($config['mail_signature']['plain']))
- $signature_plain = $config['mail_signature']['plain'];
-
+ $signature_plain = setting('core.mail_signature_plain');
if(isset($altBody[0])) {
$mailer->AltBody = $altBody . $signature_plain;
}
@@ -1121,7 +1128,16 @@ function configLua($key) {
function setting($key)
{
$settings = Settings::getInstance();
- return $settings[$key];
+
+ if (is_array($key)) {
+ if (is_null($key[1])) {
+ unset($settings[$key[0]]);
+ }
+
+ return $settings[$key[0]] = $key[1];
+ }
+
+ return $settings[$key]['value'];
}
function clearCache()
diff --git a/system/init.php b/system/init.php
index 0821d621..8e963db1 100644
--- a/system/init.php
+++ b/system/init.php
@@ -18,7 +18,6 @@ if(!isset($config['installed']) || !$config['installed']) {
throw new RuntimeException('MyAAC has not been installed yet or there was error during installation. Please install again.');
}
-date_default_timezone_set($config['date_timezone']);
// take care of trailing slash at the end
if($config['server_path'][strlen($config['server_path']) - 1] !== '/')
$config['server_path'] .= '/';
@@ -120,7 +119,7 @@ if(!isset($config['highscores_ids_hidden']) || count($config['highscores_ids_hid
$config['highscores_ids_hidden'] = array(0);
}
-$config['account_create_character_create'] = config('account_create_character_create') && (!config('mail_enabled') || !config('account_mail_verify'));
+$config['account_create_character_create'] = config('account_create_character_create') && (!setting('core.mail_enabled') || !config('account_mail_verify'));
// POT
require_once SYSTEM . 'libs/pot/OTS.php';
@@ -136,12 +135,13 @@ $settings = Settings::getInstance();
$settings->load();
// deprecated config values
-require_once __DIR__ . '/compat_config.php';
+require_once SYSTEM . 'compat/config.php';
-$settingsItemImagesURL = $settings['core.item_images_url'];
-if($settingsItemImagesURL['value'][strlen($settingsItemImagesURL['value']) - 1] !== '/') {
- $settingsItemImagesURL['value'] .= '/';
- $settings['core.item_images_url'] = $settingsItemImagesURL;
+date_default_timezone_set(setting('core.date_timezone'));
+
+$settingsItemImagesURL = setting('core.item_images_url');
+if($settingsItemImagesURL[strlen($settingsItemImagesURL) - 1] !== '/') {
+ setting(['core.item_images_url', $settingsItemImagesURL . '/']);
}
define('USE_ACCOUNT_NAME', $db->hasColumn('accounts', 'name'));
diff --git a/system/libs/Settings.php b/system/libs/Settings.php
index b784e6dd..ff75a627 100644
--- a/system/libs/Settings.php
+++ b/system/libs/Settings.php
@@ -11,9 +11,10 @@
class Settings implements ArrayAccess
{
static private $instance;
- private $plugins = [];
+ private $settingsArray = [];
private $settings = [];
private $cache = [];
+ private $valuesAsked = [];
/**
* @return Settings
@@ -52,7 +53,25 @@ class Settings implements ArrayAccess
}
}
- public static function parse($plugin, $settings): string
+ public function updateInDatabase($pluginName, $key, $value)
+ {
+ global $db;
+ $db->update(TABLE_PREFIX . 'settings', ['value' => $value], ['plugin_name' => $pluginName, 'key' => $key]);
+ }
+
+ public function deleteFromDatabase($pluginName, $key = null)
+ {
+ global $db;
+
+ if (!isset($key)) {
+ $db->delete(TABLE_PREFIX . 'settings', ['plugin_name' => $pluginName], -1);
+ }
+ else {
+ $db->delete(TABLE_PREFIX . 'settings', ['plugin_name' => $pluginName, 'key' => $key]);
+ }
+ }
+
+ public static function display($plugin, $settings): string
{
global $db;
@@ -93,7 +112,7 @@ class Settings implements ArrayAccess
$j = 0;
foreach($settings as $key => $setting) {
if ($setting['type'] === 'category') {
- if ($j++ !== 0) {
+ if ($j++ !== 0) { // close previous category
echo '
';
}
?>
@@ -103,7 +122,7 @@ class Settings implements ArrayAccess
}
if ($setting['type'] === 'section') {
- if ($i++ !== 0) {
+ if ($i++ !== 0) { // close previous section
echo '';
}
?>
@@ -190,6 +209,14 @@ class Settings implements ArrayAccess
$setting['options'] = $clients;
}
+ else if ($setting['options'] == '$timezones') {
+ $timezones = [];
+ foreach (DateTimeZone::listIdentifiers() as $value) {
+ $timezones[$value] = $value;
+ }
+
+ $setting['options'] = $timezones;
+ }
else {
if (is_string($setting['options'])) {
@@ -263,47 +290,61 @@ class Settings implements ArrayAccess
throw new \RuntimeException("Settings: You cannot set empty offset with value: $value!");
}
- $pluginName = $offset;
- if (strpos($offset, '.')) {
- $explode = explode('.', $offset, 2);
+ $this->loadPlugin($offset);
- $pluginName = $explode[0];
- $key = $explode[1];
- }
-
- $this->loadPlugin($pluginName);
+ $pluginName = $this->valuesAsked['pluginName'];
+ $key = $this->valuesAsked['key'];
// remove whole plugin settings
- if (!isset($key)) {
- $this->plugins[$pluginName] = [];
-
- // remove from settings
- if (isset($this->settings[$pluginName])) {
- unset($this->settings[$pluginName]);
- }
-
- // remove from cache
- if (isset($this->cache[$pluginName])) {
- unset($this->cache[$pluginName]);
- }
- /*foreach ($this->cache as $_key => $value) {
- if (strpos($_key, $pluginName) !== false) {
- unset($this->cache[$_key]);
- }
- }*/
+ if (!isset($value)) {
+ $this->offsetUnset($offset);
+ $this->deleteFromDatabase($pluginName, $key);
+ return;
}
- $this->settings[$pluginName][$key] = $value['value'];
+ $this->settings[$pluginName][$key] = $value;
+ $this->updateInDatabase($pluginName, $key, $value);
}
#[\ReturnTypeWillChange]
- public function offsetExists($offset) {
- return isset($this->settings[$offset]);
+ public function offsetExists($offset): bool
+ {
+ $this->loadPlugin($offset);
+
+ $pluginName = $this->valuesAsked['pluginName'];
+ $key = $this->valuesAsked['key'];
+
+ // remove specified plugin settings (all)
+ if(is_null($key)) {
+ return isset($this->settings[$offset]);
+ }
+
+ return isset($this->settings[$pluginName][$key]);
}
#[\ReturnTypeWillChange]
- public function offsetUnset($offset) {
- unset($this->settings[$offset]);
+ public function offsetUnset($offset)
+ {
+ $this->loadPlugin($offset);
+
+ $pluginName = $this->valuesAsked['pluginName'];
+ $key = $this->valuesAsked['key'];
+
+ if (isset($this->cache[$offset])) {
+ unset($this->cache[$offset]);
+ }
+
+ // remove specified plugin settings (all)
+ if(!isset($key)) {
+ unset($this->settingsArray[$pluginName]);
+ unset($this->settings[$pluginName]);
+ $this->deleteFromDatabase($pluginName);
+ return;
+ }
+
+ unset($this->settingsArray[$pluginName][$key]);
+ unset($this->settings[$pluginName][$key]);
+ $this->deleteFromDatabase($pluginName, $key);
}
/**
@@ -322,24 +363,19 @@ class Settings implements ArrayAccess
return $this->cache[$offset];
}
- $pluginName = $offset;
- if (strpos($offset, '.')) {
- $explode = explode('.', $offset, 2);
+ $this->loadPlugin($offset);
- $pluginName = $explode[0];
- $key = $explode[1];
- }
-
- $this->loadPlugin($pluginName);
+ $pluginName = $this->valuesAsked['pluginName'];
+ $key = $this->valuesAsked['key'];
// return specified plugin settings (all)
if(!isset($key)) {
- return $this->plugins[$pluginName];
+ return $this->settingsArray[$pluginName];
}
$ret = [];
- if(isset($this->plugins[$pluginName][$key])) {
- $ret = $this->plugins[$pluginName][$key];
+ if(isset($this->settingsArray[$pluginName][$key])) {
+ $ret = $this->settingsArray[$pluginName][$key];
}
if(isset($this->settings[$pluginName][$key])) {
@@ -348,7 +384,7 @@ class Settings implements ArrayAccess
$ret['value'] = $value;
}
else {
- $ret['value'] = $this->plugins[$pluginName][$key]['default'];
+ $ret['value'] = $this->settingsArray[$pluginName][$key]['default'];
}
if(isset($ret['type'])) {
@@ -370,15 +406,36 @@ class Settings implements ArrayAccess
return $ret;
}
- private function loadPlugin($pluginName)
+ private function updateValuesAsked($offset)
{
- if (!isset($this->plugins[$pluginName])) {
+ $pluginName = $offset;
+ if (strpos($offset, '.')) {
+ $explode = explode('.', $offset, 2);
+
+ $pluginName = $explode[0];
+ $key = $explode[1];
+
+ $this->valuesAsked = ['pluginName' => $pluginName, 'key' => $key];
+ }
+ else {
+ $this->valuesAsked = ['pluginName' => $pluginName, 'key' => null];
+ }
+ }
+
+ private function loadPlugin($offset)
+ {
+ $this->updateValuesAsked($offset);
+
+ $pluginName = $this->valuesAsked['pluginName'];
+ $key = $this->valuesAsked['key'];
+
+ if (!isset($this->settingsArray[$pluginName])) {
if ($pluginName === 'core') {
$settingsFilePath = SYSTEM . 'settings.php';
} else {
$pluginSettings = Plugins::getPluginSettings($pluginName);
if (!$pluginSettings) {
- error('This plugin does not exist or does not have settings defined.');
+ warning("Setting $pluginName does not exist or does not have settings defined.");
return;
}
@@ -390,7 +447,7 @@ class Settings implements ArrayAccess
}
$tmp = require $settingsFilePath;
- $this->plugins[$pluginName] = $tmp['settings'];
+ $this->settingsArray[$pluginName] = $tmp['settings'];
}
}
}
diff --git a/system/pages/account/change_password.php b/system/pages/account/change_password.php
index 01190497..aa5f19e7 100644
--- a/system/pages/account/change_password.php
+++ b/system/pages/account/change_password.php
@@ -69,7 +69,7 @@ else
$account_logged->logAction('Account password changed.');
$message = '';
- if($config['mail_enabled'] && $config['send_mail_when_change_password']) {
+ if(setting('core.mail_enabled') && $config['send_mail_when_change_password']) {
$mailBody = $twig->render('mail.password_changed.html.twig', array(
'new_password' => $org_pass,
'ip' => get_browser_real_ip(),
diff --git a/system/pages/account/create.php b/system/pages/account/create.php
index dd7c7713..2aa7c544 100644
--- a/system/pages/account/create.php
+++ b/system/pages/account/create.php
@@ -219,7 +219,7 @@ if($save)
$tmp_account = (USE_ACCOUNT_NAME ? $account_name : $account_id);
}
- if($config['mail_enabled'] && $config['account_mail_verify'])
+ if(setting('core.mail_enabled') && $config['account_mail_verify'])
{
$hash = md5(generateRandomString(16, true, true) . $email);
$new_account->setCustomField('email_hash', $hash);
@@ -294,7 +294,7 @@ if($save)
'custom_buttons' => config('account_create_character_create') ? '' : null
));
- if($config['mail_enabled'] && $config['account_welcome_mail'])
+ if(setting('core.mail_enabled') && $config['account_welcome_mail'])
{
$mailBody = $twig->render('account.welcome_mail.html.twig', array(
'account' => $tmp_account
@@ -313,7 +313,7 @@ if($save)
}
$country_recognized = null;
-if($config['account_country_recognize']) {
+if(setting('core.account_country_recognize')) {
$country_session = getSession('country');
if($country_session !== false) { // get from session
$country_recognized = $country_session;
diff --git a/system/pages/account/lost.php b/system/pages/account/lost.php
index a474540c..7cef82cd 100644
--- a/system/pages/account/lost.php
+++ b/system/pages/account/lost.php
@@ -11,7 +11,7 @@
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Lost Account Interface';
-if(!$config['mail_enabled'])
+if(!setting('core.mail_enabled'))
{
echo '