mirror of
https://github.com/danpros/htmly.git
synced 2026-04-21 04:56:23 +05:30
[TASK] added config admin tab
This commit is contained in:
parent
1fe0420748
commit
8c2c06ec5e
5 changed files with 115 additions and 3 deletions
44
system/admin/views/config.html.php
Normal file
44
system/admin/views/config.html.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<h2>Your Settings:</h2>
|
||||
<p>
|
||||
<u>hint:</u> Use <code>Ctrl</code>/<code>CMD⌘</code> + <code>F</code> to search for your config key or value.
|
||||
</p>
|
||||
<form method="POST">
|
||||
<input type="hidden" name="csrf_token" value="<?php echo get_csrf(); ?>">
|
||||
<input type="submit">
|
||||
<table id="config">
|
||||
<tr>
|
||||
<td><input type="text" name="newKey" placeholder="Your New Config Key"></td>
|
||||
<td><input type="text" name="newValue" placeholder="Your New Value"></td>
|
||||
</tr>
|
||||
<?php
|
||||
global $config_file;
|
||||
$array = [
|
||||
"google.wmt" => "hallo",
|
||||
];
|
||||
if (file_exists($config_file)) {
|
||||
$array = parse_ini_file($config_file, true);
|
||||
}
|
||||
function valueMaker($value)
|
||||
{
|
||||
if (is_string($value))
|
||||
return htmlspecialchars($value);
|
||||
|
||||
if ($value === true)
|
||||
return "true";
|
||||
if ($value === false)
|
||||
return "false";
|
||||
|
||||
if ($value == false)
|
||||
return "0";
|
||||
return (string)$value;
|
||||
}
|
||||
foreach ($array as $key => $value) {
|
||||
echo '<tr>';
|
||||
echo '<td><label for="' . $key . '">' . $key . '</label></td>';
|
||||
echo '<td><input type="text" name="-config-' . $key . '" value="' . valueMaker($value) . '"></td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<input type="submit">
|
||||
</form>
|
||||
|
|
@ -4,7 +4,8 @@
|
|||
date_default_timezone_set('Asia/Jakarta');
|
||||
|
||||
// Load the configuration file
|
||||
config('source', 'config/config.ini');
|
||||
$config_file = 'config/config.ini';
|
||||
config('source', $config_file);
|
||||
if(config('timezone')) {
|
||||
date_default_timezone_set(config('timezone'));
|
||||
}
|
||||
|
|
@ -1032,6 +1033,54 @@ post('/admin/import', function () {
|
|||
}
|
||||
});
|
||||
|
||||
// Config page
|
||||
get('/admin/config', function () {
|
||||
if (login()) {
|
||||
config('views.root', 'system/admin/views');
|
||||
render('config', array(
|
||||
'head_contents' => head_contents('Config - ' . blog_title(), blog_description(), site_url()),
|
||||
'bodyclass' => 'config',
|
||||
'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> » Config'
|
||||
));
|
||||
} else {
|
||||
$login = site_url() . 'login';
|
||||
header("location: $login");
|
||||
}
|
||||
die;
|
||||
});
|
||||
|
||||
|
||||
// Config page
|
||||
post('/admin/config', function () {
|
||||
error_reporting(E_ALL);
|
||||
ini_set("display_errors", 1);
|
||||
|
||||
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
|
||||
if (login() && $proper) {
|
||||
$newKey = from($_REQUEST, 'newKey');
|
||||
$newValue = from($_REQUEST, 'newValue');
|
||||
|
||||
$new_config = array();
|
||||
$new_Keys = array();
|
||||
if(!empty($newKey)){
|
||||
$new_Keys[$newKey] = $newValue;
|
||||
}
|
||||
foreach($_POST as $name => $value){
|
||||
if(substr($name,0,8) == "-config-"){
|
||||
$name = str_replace("_", ".",substr($name,8));
|
||||
$new_config[$name] = $value;
|
||||
}
|
||||
}
|
||||
save_config($new_config, $new_Keys);
|
||||
$login = site_url() . 'admin/config';
|
||||
header("location: $login");
|
||||
} else {
|
||||
$login = site_url() . 'login';
|
||||
header("location: $login");
|
||||
}
|
||||
die;
|
||||
});
|
||||
|
||||
// Backup page
|
||||
get('/admin/backup', function () {
|
||||
if (login()) {
|
||||
|
|
|
|||
|
|
@ -52,6 +52,24 @@ function config($key, $value = null)
|
|||
$_config[$key] = $value;
|
||||
}
|
||||
|
||||
function save_config($data = array(),$new = array()){
|
||||
global $config_file;
|
||||
|
||||
$string = file_get_contents($config_file) . "\n";
|
||||
|
||||
foreach ($data as $word => $value) {
|
||||
$value = str_replace('"','\"',$value);
|
||||
$string = preg_replace("/^" . $word . " = .+$/m", $word . ' = "' . $value . '"', $string);
|
||||
}
|
||||
$string = rtrim($string);
|
||||
foreach ($new as $word => $value) {
|
||||
$value = str_replace('"','\"',$value);
|
||||
$string .= "\n" . $word . ' = "' . $value . '"' . "\n";
|
||||
}
|
||||
$string = rtrim($string);
|
||||
return file_put_contents($config_file, $string);
|
||||
}
|
||||
|
||||
function to_b64($str)
|
||||
{
|
||||
$str = base64_encode($str);
|
||||
|
|
|
|||
|
|
@ -1662,10 +1662,11 @@ EOF;
|
|||
echo '<li><a href="' . $base . 'edit/profile">Edit profile</a></li>';
|
||||
echo '<li><a href="' . $base . 'admin/import">Import</a></li>';
|
||||
echo '<li><a href="' . $base . 'admin/backup">Backup</a></li>';
|
||||
echo '<li><a href="' . $base . 'admin/config">Config</a></li>';
|
||||
echo '<li><a href="' . $base . 'admin/clear-cache">Clear cache</a></li>';
|
||||
if ($updater->able()) {
|
||||
$info = $updater->getNewestInfo();
|
||||
echo '<li><a href="' . $base . 'admin/update/now/' . $CSRF . '">Update to ' . $info['tag_name'] . '</a></li>';
|
||||
echo '<li><a href="' . $base . 'admin/update/now/' . $CSRF . '" alt="' . $info['name'] . '">Update to ' . $info['tag_name'] . '</a></li>';
|
||||
}
|
||||
echo '<li><a href="' . $base . 'logout">Logout</a></li>';
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue