yf_settings admin moduleSystem settings interface.
| File | plugins/conf/admin_modules/yf_settings.class.php |
|---|---|
| Use | admin URL ?object=settings |
A site sets them in its config with $PROJECT_CONF['settings']['NAME'] = ...;
| Property | Default | Description |
|---|---|---|
$SUPERADMIN_ONLYbool |
false |
When true, only super-admins (ADMIN_GROUP 1) may use this action |
$_used_modules |
null |
|
$cache_drivers |
['memcache' => 'memcache', 'files' => 'files', 'redis' => 'redis', 'tmp' => 'tmp'] |
|
$css_frameworks |
['bs3' => 'Bootstrap 3', 'bs4' => 'Bootstrap 4', 'bs5' => 'Bootstrap 5', 'empty' => 'No CSS framework'] |
|
$css_subthemes |
|
|
$db_drivers |
['mysqli' => 'mysqli'] |
|
$default_skins |
['user' => 'User (default)', 'admin' => 'Admin (default)'] |
|
$tpl_drivers |
['yf' => 'YF stpl (default)'] |
public function cache_purge()
public function cache_purge()
{
$result = _class('cache')->_clear_all();
return js_redirect(url('/@object'));
}
public function display_what()
public function display_what()
{
$r = null;
$hooks_data = _class('admin_methods')->call_hooks('settings', $r);
$avail_hook_modules = [];
foreach ((array) $hooks_data as $k => $v) {
list($module_name) = explode('___', $k);
$avail_hook_modules[$module_name] = $k;
}
$settings = $this->_get_settings($hooks_data);
if (main()->is_post()) {
parse_str($_POST['sort'], $tmp);
$posted_sort = [];
foreach ((array) $tmp['sort'] as $v) {
$posted_sort[$v] = $v;
}
foreach ((array) $settings as $s) {
$name = $s['item'];
$_n = str_replace('_', '', $name);
if ( ! isset($avail_hook_modules[$name])) {
unset($posted_sort[$_n]);
continue;
}
$posted_sort[$_n] = $name;
}
$to_save = [];
$i = 0;
foreach ((array) $posted_sort as $_n => $name) {
$to_save[$name] = [
'item' => $name,
'value' => isset($_POST['check'][$_n]) ? 1 : 0,
'order' => ++$i,
];
}
if ($to_save) {
db()->query('TRUNCATE TABLE ' . db('settings'));
db()->insert_safe('settings', $to_save);
}
return js_redirect('/@object/@action');
}
jquery('
var container = $("#settings-sortable-container")
container.find("ul").sortable();
container.closest("form").on("submit", function(){
$(this).find("input[name=sort][type=hidden]").val( container.find("ul").sortable("serialize", { key: "sort[]" }) )
});
');
$container_html = '
<div class="span6" id="settings-sortable-container">
<ul class="nav nav-pills nav-stacked" id="sortable_settings">
';
foreach ((array) $settings as $s) {
$name = $s['item'];
if ( ! isset($avail_hook_modules[$name])) {
continue;
}
$hooks = $hooks_data[$avail_hook_modules[$name]];
$is_checked = $s['value'] ? 1 : 0;
$container_html .= '<li class="item" id="liitem_' . str_replace('_', '', $name) . '"><a style="cursor:move;"><i class="icon icon-move fa fa-arrows"></i> ' . t($name) . ' (' . (count((array) $hooks)) . ')'
. ' <input type="checkbox" name="check[' . str_replace('_', '', $name) . ']" value="1" style="float:right;"' . ($is_checked ? ' checked="checked"' : '') . '></a></li>' . PHP_EOL;
}
$container_html .= '
</ul>
</div>
';
$a['back_link'] = url('/@object');
return form($a, ['legend' => 'Settings items'])
->hidden('sort')
->container($container_html, ['wide' => 1])
->save_and_back();
}
public function show()
public function show()
{
if ($this->SUPERADMIN_ONLY && main()->ADMIN_GROUP != 1) {
return _class('graphics')->_action_on_block_denied('center_area') ?: '';
}
$r = [];
foreach ((array) conf() as $k => $v) {
if (is_array($v)) {
foreach ((array) $v as $k2 => $v2) {
$r[$k . '__' . $k2] = $v2;
}
} else {
$r[$k] = $v;
}
}
return '<pre>' . _prepare_html(print_r($r, 1)) . '</pre>';
}
_ hooks and helpers; not routable as page actionspublic function _addslashes($val)
public function _addslashes($val)
{
if (is_array($val)) {
foreach ($val as $k => $v) {
$val[$k] = $this->_addslashes($v);
}
return $val;
}
return addslashes($val);
}
public function _get_settings($hooks_data)
public function _get_settings($hooks_data)
{
$i = null;
$settings = db()->from('settings')->order_by('`order`, item ASC')->get_all();
if ( ! $settings && $hooks_data) {
$settings = [];
$i = 0;
foreach ((array) $hooks_data as $k => $v) {
list($module_name) = explode('___', $k);
$settings[] = [
'item' => $module_name,
'value' => 0,
'order' => ++$i,
];
}
if ($settings) {
db()->insert_safe('settings', $settings);
}
}
return $settings;
}
public function _hook_settings(&$selected = [])
public function _hook_settings(&$selected = [])
{
$selected['site_maintenance'] = conf('site_maintenance') ?: 0;
$selected['main[USE_SYSTEM_CACHE]'] = module_conf('main', 'USE_SYSTEM_CACHE') || (defined('USE_CACHE') && USE_CACHE) ?: 0; // TODO: unify and simplify
$selected['cache[DRIVER]'] = module_conf('cache', 'DRIVER') ?: 'memcache';
$selected['main[ALLOW_DEBUG_PROFILING]'] = main()->ALLOW_DEBUG_PROFILING;
$selected['DEBUG_CONSOLE_POPUP'] = conf('DEBUG_CONSOLE_POPUP');
return [
['yes_no_box', 'site_maintenance', ['tip' => '']],
['yes_no_box', 'main[USE_SYSTEM_CACHE]', ['desc' => 'use_cache']],
['select_box', 'cache[DRIVER]', $this->cache_drivers, ['desc' => 'cache_driver']],
['select_box', 'css_framework', $this->css_frameworks, ['show_text' => 1]], // TODO: link to edit
['yes_no_box', 'main[ALLOW_DEBUG_PROFILING]', ['desc' => 'Use built-in code profiling (for DEBUG_MODE)']],
['yes_no_box', 'DEBUG_CONSOLE_POPUP', ['desc' => 'Debug console as popup window (for DEBUG_MODE)']],
];
}
public function _hook_side_column()
public function _hook_side_column()
{
if ( ! $this->_used_modules) {
return false;
}
$items = [];
$url = process_url(url('/@object'));
foreach ((array) $this->_used_modules as $module_name) {
$items[] = '<li><a href="' . $url . '#module_' . $module_name . '"><i class="icon-chevron-right fa fa-chevron-right"></i> ' . t($module_name) . '</a></li>';
}
return '<div class="span3 bs-docs-sidebar"><ul class="nav nav-list bs-docs-sidenav">' . implode(PHP_EOL, $items) . '</ul></div>';
}
public function _prepare_to_save($a)
public function _prepare_to_save($a)
{
$to_save = [];
foreach ((array) $a as $k => $v) {
if (is_string($v) && ! strlen($v)) {
continue;
}
if (is_array($v)) {
foreach ((array) $v as $k2 => $v2) {
if ( ! $k2 || (is_string($v2) && ! strlen($v2))) {
unset($v[$k2]);
}
}
if ( ! count((array) $v)) {
continue;
}
}
$to_save[$k] = $v;
}
if ($to_save) {
foreach ((array) $to_save as $k => $v) {
if (is_array($v)) {
foreach ((array) $v as $k2 => $v2) {
$to_save[$k . '::' . $k2] = '$CONF[\'' . $this->_addslashes($k) . '\'][\'' . $this->_addslashes($k2) . '\'] = \'' . $this->_addslashes($v2) . '\';';
}
unset($to_save[$k]);
} elseif (false !== strpos($k, '__')) {
list($_module, $_setting) = explode('__', $k);
$to_save[$k] = '$CONF[\'' . $this->_addslashes($_module) . '\'][\'' . $this->_addslashes($_setting) . '\'] = \'' . $this->_addslashes($v) . '\';';
} else {
$to_save[$k] = '$CONF[\'' . $this->_addslashes($k) . '\'] = \'' . $this->_addslashes($v) . '\';';
}
}
}
return $to_save;
}