* @copyright 2020 MyAAC * @link https://my-aac.org */ class Settings implements ArrayAccess { static private $instance; private $plugins = []; private $settings = []; private $cache = []; /** * @return Settings */ public static function getInstance(): Settings { if (!self::$instance) { self::$instance = new self(); } return self::$instance; } public function load() { $cache = Cache::getInstance(); if ($cache->enabled()) { $tmp = ''; if ($cache->fetch('settings', $tmp)) { $this->settings = unserialize($tmp); return; } } global $db; $settings = $db->query('SELECT * FROM `' . TABLE_PREFIX . 'settings`'); if($settings->rowCount() > 0) { foreach ($settings->fetchAll(PDO::FETCH_ASSOC) as $setting) { $this->settings[$setting['plugin_name']][$setting['key']] = $setting['value']; } } if ($cache->enabled()) { $cache->set('settings', serialize($this->settings), 600); } } 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']];
}
?>
|