Simple file editor replacement for ?/config (optional). Issue #127
This commit is contained in:
parent
157dcf9fb1
commit
5a44c50811
@ -929,6 +929,9 @@
|
|||||||
// Automatically dismiss all reports regarding a thread when it is locked
|
// Automatically dismiss all reports regarding a thread when it is locked
|
||||||
$config['mod']['dismiss_reports_on_lock'] = true;
|
$config['mod']['dismiss_reports_on_lock'] = true;
|
||||||
|
|
||||||
|
// Replace ?/config with a simple text editor for editing inc/instance-config.php
|
||||||
|
$config['mod']['config_editor_php'] = false;
|
||||||
|
|
||||||
// Probably best not to change these:
|
// Probably best not to change these:
|
||||||
if (!defined('JANITOR')) {
|
if (!defined('JANITOR')) {
|
||||||
define('JANITOR', 0, true);
|
define('JANITOR', 0, true);
|
||||||
@ -999,7 +1002,7 @@
|
|||||||
// Bypass flood check
|
// Bypass flood check
|
||||||
$config['mod']['flood'] = ADMIN;
|
$config['mod']['flood'] = ADMIN;
|
||||||
// Raw HTML posting
|
// Raw HTML posting
|
||||||
$config['mod']['rawhtml'] = DISABLED;
|
$config['mod']['rawhtml'] = ADMIN;
|
||||||
|
|
||||||
/* Administration */
|
/* Administration */
|
||||||
// View the report queue
|
// View the report queue
|
||||||
@ -1077,8 +1080,6 @@
|
|||||||
// Delete news entries
|
// Delete news entries
|
||||||
$config['mod']['news_delete'] = ADMIN;
|
$config['mod']['news_delete'] = ADMIN;
|
||||||
|
|
||||||
// View the current configuration
|
|
||||||
$config['mod']['show_config'] = ADMIN;
|
|
||||||
// Edit the current configuration (via web interface)
|
// Edit the current configuration (via web interface)
|
||||||
$config['mod']['edit_config'] = ADMIN;
|
$config['mod']['edit_config'] = ADMIN;
|
||||||
|
|
||||||
|
@ -1304,13 +1304,12 @@ function mod_edit_post($board, $edit_raw_html, $postID) {
|
|||||||
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $postID) . '#' . $postID, true, $config['redirect_http']);
|
header('Location: ?/' . sprintf($config['board_path'], $board) . $config['dir']['res'] . sprintf($config['file_page'], $post['thread'] ? $post['thread'] : $postID) . '#' . $postID, true, $config['redirect_http']);
|
||||||
} else {
|
} else {
|
||||||
if ($config['minify_html']) {
|
if ($config['minify_html']) {
|
||||||
// $post['body_nomarkup'] = str_replace("\n", '
', $post['body_nomarkup']);
|
$post['body_nomarkup'] = str_replace("\n", '
', utf8tohtml($post['body_nomarkup']));
|
||||||
// $post['body'] = str_replace("\n", '
', $post['body']);
|
$post['body'] = str_replace("\n", '
', utf8tohtml($post['body']));
|
||||||
|
$post['body_nomarkup'] = str_replace("\r", '', $post['body_nomarkup']);
|
||||||
|
$post['body'] = str_replace("\r", '', $post['body']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Minifying this page causes an issue with newlines in the textarea. This is a temporary solution.
|
|
||||||
$config['minify_html'] = false;
|
|
||||||
|
|
||||||
mod_page(_('Edit post'), 'mod/edit_post_form.html', array('token' => $security_token, 'board' => $board, 'raw' => $edit_raw_html, 'post' => $post));
|
mod_page(_('Edit post'), 'mod/edit_post_form.html', array('token' => $security_token, 'board' => $board, 'raw' => $edit_raw_html, 'post' => $post));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1948,6 +1947,24 @@ function mod_config() {
|
|||||||
if (!hasPermission($config['mod']['edit_config']))
|
if (!hasPermission($config['mod']['edit_config']))
|
||||||
error($config['error']['noaccess']);
|
error($config['error']['noaccess']);
|
||||||
|
|
||||||
|
if ($config['mod']['config_editor_php']) {
|
||||||
|
$readonly = !is_writable('inc/instance-config.php');
|
||||||
|
|
||||||
|
if (!$readonly && isset($_POST['code'])) {
|
||||||
|
$code = $_POST['code'];
|
||||||
|
file_put_contents('inc/instance-config.php', $code);
|
||||||
|
header('Location: ?/config', true, $config['redirect_http']);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$instance_config = file_get_contents('inc/instance-config.php');
|
||||||
|
$instance_config = str_replace("\n", '
', utf8tohtml($instance_config));
|
||||||
|
|
||||||
|
mod_page(_('Config editor'), 'mod/config-editor-php.html', array('php' => $instance_config, 'readonly' => $readonly));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
require_once 'inc/mod/config-editor.php';
|
require_once 'inc/mod/config-editor.php';
|
||||||
|
|
||||||
$conf = config_vars();
|
$conf = config_vars();
|
||||||
|
45
templates/mod/config-editor-php.html
Normal file
45
templates/mod/config-editor-php.html
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
{% if readonly %}
|
||||||
|
<p style="text-align:center;max-width:800px;margin:20px auto">Tinyboard does not have the required permissions to edit <strong>inc/instance-config.php</strong>. To make changes, you will need to change the file's permissions first or manually edit the code.</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
{% if not readonly %}<form method="post" action="">{% endif %}
|
||||||
|
<textarea name="code" id="code" style="display:block; margin:auto;width:100%;max-width:800px;height:500px{% if readonly %};background:#eee" readonly{% else %}"{% endif %}>
|
||||||
|
{{ php }}
|
||||||
|
</textarea>
|
||||||
|
|
||||||
|
<ul style="padding:0;text-align:center;list-style:none">
|
||||||
|
<li><input name="save" type="submit" value="{% trans 'Save changes' %}"{% if readonly %} disabled{% endif %}></li>
|
||||||
|
</ul>
|
||||||
|
{% if not readonly %}</form>{% endif %}
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
var observe;
|
||||||
|
if (window.attachEvent) {
|
||||||
|
observe = function (element, event, handler) {
|
||||||
|
element.attachEvent('on'+event, handler);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
observe = function (element, event, handler) {
|
||||||
|
element.addEventListener(event, handler, false);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var text = document.getElementById('code');
|
||||||
|
function resize () {
|
||||||
|
text.style.height = 'auto';
|
||||||
|
text.style.height = text.scrollHeight+'px';
|
||||||
|
}
|
||||||
|
/* 0-timeout to get the already changed text */
|
||||||
|
function delayedResize () {
|
||||||
|
window.setTimeout(resize, 0);
|
||||||
|
}
|
||||||
|
observe(text, 'change', resize);
|
||||||
|
observe(text, 'cut', delayedResize);
|
||||||
|
observe(text, 'paste', delayedResize);
|
||||||
|
observe(text, 'drop', delayedResize);
|
||||||
|
observe(text, 'keydown', delayedResize);
|
||||||
|
|
||||||
|
resize();
|
||||||
|
</script>
|
@ -94,7 +94,7 @@
|
|||||||
{% if mod|hasPermission(config.mod.rebuild) %}
|
{% if mod|hasPermission(config.mod.rebuild) %}
|
||||||
<li><a href="?/rebuild">{% trans 'Rebuild' %}</a></li>
|
<li><a href="?/rebuild">{% trans 'Rebuild' %}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if mod|hasPermission(config.mod.show_config) %}
|
{% if mod|hasPermission(config.mod.edit_config) %}
|
||||||
<li><a href="?/config">{% trans 'Configuration' %}</a></li>
|
<li><a href="?/config">{% trans 'Configuration' %}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
{% trans %}Comment{% endtrans %}
|
{% trans %}Comment{% endtrans %}
|
||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<textarea name="body" id="body" rows="8" cols="35">{% if raw %}{{ post.body|e }}{% else %}{{ post.body_nomarkup|e }}{% endif %}</textarea>
|
<textarea name="body" id="body" rows="8" cols="35">{% if raw %}{{ post.body }}{% else %}{{ post.body_nomarkup }}{% endif %}</textarea>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
Loading…
Reference in New Issue
Block a user