streams/Code/Module/Settings/Features.php

72 lines
2 KiB
PHP
Raw Normal View History

2016-09-07 03:10:56 +00:00
<?php
2022-02-16 04:08:28 +00:00
namespace Code\Module\Settings;
2016-09-07 03:10:56 +00:00
2022-02-16 04:08:28 +00:00
use Code\Lib\Libsync;
use Code\Lib as Zlib;
use Code\Render\Theme;
2022-02-12 20:43:29 +00:00
2016-09-07 03:10:56 +00:00
2021-12-02 23:02:31 +00:00
class Features
{
public function post()
{
check_form_security_token_redirectOnErr('/settings/features', 'settings_features');
2022-01-25 23:33:22 +00:00
$features = Zlib\Features::get(false);
2021-12-02 23:02:31 +00:00
foreach ($features as $fname => $fdata) {
foreach (array_slice($fdata, 1) as $f) {
$k = $f[0];
2021-12-03 03:01:39 +00:00
if (array_key_exists("feature_$k", $_POST)) {
2021-12-02 23:02:31 +00:00
set_pconfig(local_channel(), 'feature', $k, (string)$_POST["feature_$k"]);
2021-12-03 03:01:39 +00:00
} else {
2021-12-02 23:02:31 +00:00
set_pconfig(local_channel(), 'feature', $k, '');
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
}
}
Libsync::build_sync_packet();
return;
}
public function get()
{
$arr = [];
$harr = [];
2022-01-25 23:33:22 +00:00
$all_features_raw = Zlib\Features::get(false);
2021-12-02 23:02:31 +00:00
foreach ($all_features_raw as $fname => $fdata) {
foreach (array_slice($fdata, 1) as $f) {
2022-01-25 23:33:22 +00:00
$harr[$f[0]] = ((intval(Zlib\Features::enabled(local_channel(), $f[0]))) ? "1" : '');
2021-12-02 23:02:31 +00:00
}
}
2022-01-25 23:33:22 +00:00
$features = Zlib\Features::get(true);
2021-12-02 23:02:31 +00:00
foreach ($features as $fname => $fdata) {
$arr[$fname] = [];
$arr[$fname][0] = $fdata[0];
foreach (array_slice($fdata, 1) as $f) {
2022-01-25 23:33:22 +00:00
$arr[$fname][1][] = array('feature_' . $f[0], $f[1], ((intval(Zlib\Features::enabled(local_channel(), $f[0]))) ? "1" : ''), $f[2], array(t('Off'), t('On')));
2021-12-02 23:02:31 +00:00
unset($harr[$f[0]]);
}
}
2022-02-12 20:43:29 +00:00
$tpl = Theme::get_template("settings_features.tpl");
2021-12-02 23:02:31 +00:00
$o .= replace_macros($tpl, array(
'$form_security_token' => get_form_security_token("settings_features"),
'$title' => t('Additional Features'),
'$features' => $arr,
'$hiddens' => $harr,
'$baseurl' => z_root(),
'$submit' => t('Submit'),
));
return $o;
}
}