Browse Source

[TASK] added config admin tab

pull/135/head
Kanti 11 years ago
parent
commit
8c2c06ec5e
5 changed files with 115 additions and 3 deletions
  1. +44
    -0
      system/admin/views/config.html.php
  2. +50
    -1
      system/htmly.php
  3. +18
    -0
      system/includes/dispatch.php
  4. +2
    -1
      system/includes/functions.php
  5. +1
    -1
      themes/default/css/toolbar.css

+ 44
- 0
system/admin/views/config.html.php View 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>

+ 50
- 1
system/htmly.php View File

@ -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> &#187; 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()) {


+ 18
- 0
system/includes/dispatch.php View File

@ -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);


+ 2
- 1
system/includes/functions.php View File

@ -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>';


+ 1
- 1
themes/default/css/toolbar.css View File

@ -1 +1 @@
body{ padding-top:30px;}#toolbar {background: #666666;box-shadow: 0 5px 15px #000000;color: #CCCCCC;font-family: Georgia, sans-serif;left: 0;margin: 0 -20px;padding: 0 25px;position: fixed;right: 0;top: 0;z-index: 600;border: 0 none;font-size: 15px;text-align: left;vertical-align: baseline;min-height:30px;}#toolbar ul {margin:0;padding-top:5px;padding-bottom:5px;padding-left:30px;float:left;}#toolbar ul li, #toolbar ul li a {float: left;list-style: none outside none;margin:0;}#toolbar a {color: #FFFFFF;font-size: 0.846em;text-decoration: none;border-radius: 10px;padding: 0 10px;line-height:1.6;} @media all and (max-width: 550px) {body{ padding-top:60px;}}
body{padding-top:30px}#toolbar{background:#666;box-shadow:0 5px 15px #000;color:#CCC;font-family:Georgia,sans-serif;left:0;margin:0 -20px;padding:0 25px;position:fixed;right:0;top:0;z-index:600;border:0;font-size:15px;text-align:left;vertical-align:baseline;min-height:30px}#toolbar ul{margin:0;padding-top:5px;padding-bottom:5px;padding-left:30px;float:left}#toolbar ul li,#toolbar ul li a{float:left;list-style:none;margin:0}#toolbar a{color:#FFF;font-size:.846em;text-decoration:none;border-radius:10px;padding:0 10px;line-height:1.6}@media all and (max-width:550px){body{padding-top:60px}}table#config td:first-child{width:30%}table#config td:last-child{width:70%}table#config input{width:100%;box-sizing:border-box}table#config tr:last-child td{border-bottom:none}

Loading…
Cancel
Save