From 5a44c50811ba9a927add4d54604307692492df8a Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Thu, 1 Aug 2013 17:18:10 -0400 Subject: [PATCH] Simple file editor replacement for ?/config (optional). Issue #127 --- inc/config.php | 7 +++-- inc/mod/pages.php | 29 ++++++++++++++---- templates/mod/config-editor-php.html | 45 ++++++++++++++++++++++++++++ templates/mod/dashboard.html | 2 +- templates/mod/edit_post_form.html | 2 +- 5 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 templates/mod/config-editor-php.html diff --git a/inc/config.php b/inc/config.php index d82ebfc6..bddb9e4c 100644 --- a/inc/config.php +++ b/inc/config.php @@ -929,6 +929,9 @@ // Automatically dismiss all reports regarding a thread when it is locked $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: if (!defined('JANITOR')) { define('JANITOR', 0, true); @@ -999,7 +1002,7 @@ // Bypass flood check $config['mod']['flood'] = ADMIN; // Raw HTML posting - $config['mod']['rawhtml'] = DISABLED; + $config['mod']['rawhtml'] = ADMIN; /* Administration */ // View the report queue @@ -1077,8 +1080,6 @@ // Delete news entries $config['mod']['news_delete'] = ADMIN; - // View the current configuration - $config['mod']['show_config'] = ADMIN; // Edit the current configuration (via web interface) $config['mod']['edit_config'] = ADMIN; diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 1e0dc7c9..615e85c7 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -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']); } else { if ($config['minify_html']) { - // $post['body_nomarkup'] = str_replace("\n", ' ', $post['body_nomarkup']); - // $post['body'] = str_replace("\n", ' ', $post['body']); + $post['body_nomarkup'] = str_replace("\n", ' ', utf8tohtml($post['body_nomarkup'])); + $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)); } } @@ -1948,6 +1947,24 @@ function mod_config() { if (!hasPermission($config['mod']['edit_config'])) 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'; $conf = config_vars(); diff --git a/templates/mod/config-editor-php.html b/templates/mod/config-editor-php.html new file mode 100644 index 00000000..54c398e4 --- /dev/null +++ b/templates/mod/config-editor-php.html @@ -0,0 +1,45 @@ +{% if readonly %} +

Tinyboard does not have the required permissions to edit inc/instance-config.php. To make changes, you will need to change the file's permissions first or manually edit the code.

+{% endif %} + + +{% if not readonly %}
{% endif %} + + + +{% if not readonly %}
{% endif %} + + \ No newline at end of file diff --git a/templates/mod/dashboard.html b/templates/mod/dashboard.html index 5f6585fc..e9fb7c9c 100644 --- a/templates/mod/dashboard.html +++ b/templates/mod/dashboard.html @@ -94,7 +94,7 @@ {% if mod|hasPermission(config.mod.rebuild) %}
  • {% trans 'Rebuild' %}
  • {% endif %} - {% if mod|hasPermission(config.mod.show_config) %} + {% if mod|hasPermission(config.mod.edit_config) %}
  • {% trans 'Configuration' %}
  • {% endif %} diff --git a/templates/mod/edit_post_form.html b/templates/mod/edit_post_form.html index b9359c68..a2980d35 100644 --- a/templates/mod/edit_post_form.html +++ b/templates/mod/edit_post_form.html @@ -32,7 +32,7 @@ {% trans %}Comment{% endtrans %} - +