1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-14 10:57:38 +01:00

Config editort

This commit is contained in:
Michael Save 2012-05-20 20:20:50 +10:00
parent 0f04117037
commit d3739c48c2
6 changed files with 158 additions and 17 deletions

View File

@ -1539,6 +1539,91 @@ function mod_report_dismiss($id, $all = false) {
header('Location: ?/reports', true, $config['redirect_http']); header('Location: ?/reports', true, $config['redirect_http']);
} }
function mod_config() {
global $config, $mod;
if (!hasPermission($config['mod']['edit_config']))
error($config['error']['noaccess']);
require_once 'inc/mod/config-editor.php';
$conf = config_vars();
foreach ($conf as &$var) {
if (is_array($var['name'])) {
$c = &$config;
foreach ($var['name'] as $n)
$c = &$c[$n];
} else {
$c = $config[$var['name']];
}
$var['value'] = $c;
}
unset($var);
if (isset($_POST['save'])) {
$config_append = '';
foreach ($conf as $var) {
$field_name = 'cf_' . (is_array($var['name']) ? implode('/', $var['name']) : $var['name']);
if ($var['type'] == 'boolean')
$value = isset($_POST[$field_name]);
elseif (isset($_POST[$field_name]))
$value = $_POST[$field_name];
else
continue; // ???
if (!settype($value, $var['type']))
continue; // invalid
if ($value != $var['value']) {
// This value has been changed.
$config_append .= '$config';
if (is_array($var['name'])) {
foreach ($var['name'] as $name)
$config_append .= '[' . var_export($name, true) . ']';
} else {
$config_append .= '[' . var_export($var['name'], true) . ']';
}
$config_append .= ' = ' . var_export($value, true) . ";\n";
}
}
if(!empty($config_append)) {
$config_append = "\n// Changes made via web editor by \"" . $mod['username'] . "\" @ " . date('r') . ":\n" . $config_append . "\n";
if(!@file_put_contents('inc/instance-config.php', $config_append, FILE_APPEND)) {
$config_append = htmlentities($config_append);
if($config['minify_html'])
$config_append = str_replace("\n", '
', $config_append);
$page = array();
$page['title'] = 'Cannot write to file!';
$page['config'] = $config;
$page['body'] = '
<p style="text-align:center">Tinyboard could not write to <strong>inc/instance-config.php</strong> with the ammended configuration, probably due to a permissions error.</p>
<p style="text-align:center">You may proceed with these changes manually by copying and pasting the following code to the end of <strong>inc/instance-config.php</strong>:</p>
<textarea style="width:700px;height:370px;margin:auto;display:block;background:white;color:black" readonly>' . $config_append . '</textarea>
';
echo Element('page.html', $page);
exit;
}
}
header('Location: ?/', true, $config['redirect_http']);
exit;
}
mod_page('Config editor', 'mod/config-editor.html', array('conf' => $conf));
}
function mod_debug_antispam() { function mod_debug_antispam() {
global $pdo, $config; global $pdo, $config;

View File

@ -27,7 +27,7 @@ function load_twig() {
$twig = new Twig_Environment($loader, array( $twig = new Twig_Environment($loader, array(
'autoescape' => false, 'autoescape' => false,
'cache' => "{$config['dir']['template']}/cache", 'cache' => "{$config['dir']['template']}/cache",
'debug' => ($config['debug'] ? true : false), 'debug' => $config['debug']
)); ));
$twig->addExtension(new Twig_Extensions_Extension_Tinyboard()); $twig->addExtension(new Twig_Extensions_Extension_Tinyboard());
$twig->addExtension(new Twig_Extensions_Extension_I18n()); $twig->addExtension(new Twig_Extensions_Extension_I18n());

View File

@ -65,6 +65,8 @@ $pages = array(
'/(\w+)/bump(un)?lock/(\d+)' => 'bumplock', // "bumplock" thread '/(\w+)/bump(un)?lock/(\d+)' => 'bumplock', // "bumplock" thread
'/(\w+)/move/(\d+)' => 'move', // move thread '/(\w+)/move/(\d+)' => 'move', // move thread
'/config' => 'config', // config editor
// these pages aren't listed in the dashboard without $config['debug'] // these pages aren't listed in the dashboard without $config['debug']
'/debug/antispam' => 'debug_antispam', '/debug/antispam' => 'debug_antispam',

View File

@ -388,19 +388,15 @@ div.blotter {
font-weight: bold; font-weight: bold;
text-align: center; text-align: center;
} }
table.mod.config-editor {
/* Uboachan stuff */ font-size: 9pt;
div.styles-sidebar { width: 100%;
text-align: center;
padding-bottom: 0px;
} }
div.styles-sidebar a { table.mod.config-editor td {
margin: 0 5px; text-align: left;
padding: 5px;
border-bottom: 1px solid #98e;
} }
div.styles-sidebar a.selected { table.mod.config-editor input[type="text"] {
text-decoration: none; width: 98%;
}
.category {
background: #98E;
color: black;
} }

View File

@ -0,0 +1,56 @@
<form method="post" action="">
<table class="mod config-editor">
<tr>
<th class="minimal">Name</th>
<th>Value</th>
<th class="minimal">Type</th>
<th>Description</th>
</tr>
{% for var in conf if var.type != 'array' %}
{% if var.name|count == 1 %}
{% set name = 'cf_' ~ var.name %}
{% else %}
{% set name = 'cf_' ~ var.name|join('/') %}
{% endif %}
<tr>
<th class="minimal">
{% if var.name|count == 1 %}
{{ var.name }}
{% else %}
{{ var.name|join(' &rarr; ') }}
{% endif %}
</th>
<td>
{% if var.type == 'string' %}
<input name="{{ name }}" type="text" value="{{ var.value|e }}">
{% elseif var.type == 'integer' %}
<input name="{{ name }}" type="number" value="{{ var.value|e }}">
{% elseif var.type == 'boolean' %}
<input name="{{ name }}" type="checkbox" {% if var.value %}checked{% endif %}>
{% else %}
?
{% endif %}
{% if var.type == 'integer' or var.type == 'boolean' %}
<small>Default: <code>{{ var.default }}</code></small>
{% endif %}
</td>
<td class="minimal">
{{ var.type|e }}
</td>
<td>
{{ var.comment|join('<br>') }}
</td>
</tr>
{% endfor %}
</table>
<ul style="padding:0;text-align:center;list-style:none">
<li><input name="save" type="submit" value="{% trans 'Save changes' %}"></li>
</ul>
</form>

View File

@ -1,9 +1,11 @@
{% for board_posts in posts %} {% for board_posts in posts %}
<fieldset> <fieldset>
<legend> <legend>
<a href="?/{{ config.board_path|sprintf(board_posts.board.uri) }}{{ config.file_index }}">{{ config.board_abbreviation|sprintf(board_posts.board.uri) }}</a> <a href="?/{{ config.board_path|sprintf(board_posts.board.uri) }}{{ config.file_index }}">
- {{ config.board_abbreviation|sprintf(board_posts.board.uri) }}
{{ board_posts.board.title|e }} -
{{ board_posts.board.title|e }}
</a>
</legend> </legend>
{{ board_posts.posts|join('<hr>') }} {{ board_posts.posts|join('<hr>') }}
</fieldset> </fieldset>