PHP WebShell
Текущая директория: /var/www/bitcardoApp/config
Просмотр файла: settings.php
<?php
// config/settings.php
// Requires: config/db_config.php ($conn) loaded before this file.
// Purpose: Provide global get_settings()/is_enabled() helpers, with safe aliases.
/**
* Load all settings from DB into a request-local cache (refresh every 60s).
*/
if (!function_exists('settings_load_cache')) {
function settings_load_cache(mysqli $conn): array {
static $cache = null, $last = 0;
if ($cache !== null && (time() - $last) < 60) {
return $cache;
}
$cache = [];
if ($res = $conn->query("SELECT setting_key, setting_value FROM site_settings")) {
while ($row = $res->fetch_assoc()) {
// normalize keys to lowercase
$cache[strtolower($row['setting_key'])] = $row['setting_value'];
}
$res->free();
}
$last = time();
return $cache;
}
}
/**
* Canonical getter: get_settings($key, $default)
* - keys are looked up lowercase in DB (site_settings)
* - fallback to UPPERCASE constant from serv_config.php
* - else return $default
*/
if (!function_exists('get_settings')) {
function get_settings(string $key, $default = null) {
global $conn;
$k = strtolower($key);
// DB override if available
if ($conn instanceof mysqli) {
$all = settings_load_cache($conn);
if (array_key_exists($k, $all)) {
return $all[$k];
}
}
// Fallback to UPPERCASE constant (from serv_config.php) if present
$const = strtoupper($k);
if (defined($const)) {
return constant($const);
}
return $default;
}
}
/**
* Enabled check using get_settings
*/
if (!function_exists('is_enabled')) {
function is_enabled(string $key, $default = false): bool {
$v = get_settings($key, $default);
if (is_bool($v)) return $v;
$v = strtolower((string)$v);
return in_array($v, ['1','true','on','yes'], true);
}
}
// ---------- Optional aliases for symmetry (use if you want) ----------
if (!function_exists('is_enabled_setting')) {
function is_enabled_setting(string $key, $default = false): bool {
return is_enabled($key, $default);
}
}
Выполнить команду
Для локальной разработки. Не используйте в интернете!