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

Better/working web config editor

This commit is contained in:
Michael Foster 2013-08-03 05:21:02 -04:00
parent 3ed15565b0
commit c9684fc000
4 changed files with 42 additions and 18 deletions

View File

@ -355,8 +355,9 @@
// Always act as if the user had typed "noko" into the email field. // Always act as if the user had typed "noko" into the email field.
$config['always_noko'] = false; $config['always_noko'] = false;
// Custom tripcodes. The below example makes a tripcode of "#test123" evaluate to "!HelloWorld". // Example: Custom tripcodes. The below example makes a tripcode of "#test123" evaluate to "!HelloWorld".
// $config['custom_tripcode']['#test123'] = '!HelloWorld'; // $config['custom_tripcode']['#test123'] = '!HelloWorld';
// Example: Custom secure tripcode.
// $config['custom_tripcode']['##securetrip'] = '!!somethingelse'; // $config['custom_tripcode']['##securetrip'] = '!!somethingelse';
// Allow users to mark their image as a "spoiler" when posting. The thumbnail will be replaced with a // Allow users to mark their image as a "spoiler" when posting. The thumbnail will be replaced with a
@ -523,6 +524,7 @@
// Thumbnail to use for the non-image file uploads. // Thumbnail to use for the non-image file uploads.
$config['file_icons']['default'] = 'file.png'; $config['file_icons']['default'] = 'file.png';
$config['file_icons']['zip'] = 'zip.png'; $config['file_icons']['zip'] = 'zip.png';
// Example: Custom thumbnail for certain file extension.
// $config['file_icons']['extension'] = 'some_file.png'; // $config['file_icons']['extension'] = 'some_file.png';
// Location of above images. // Location of above images.
@ -1199,7 +1201,8 @@
// array('127.0.0.1', 80) // array('127.0.0.1', 80)
// array('127.0.0.1', 80, 'example.org') // array('127.0.0.1', 80, 'example.org')
// ); // );
// Connection timeout, in seconds.
// Connection timeout for $config['purge'], in seconds.
$config['purge_timeout'] = 3; $config['purge_timeout'] = 3;
// Additional mod.php?/ pages. Look in inc/mod/pages.php for help. // Additional mod.php?/ pages. Look in inc/mod/pages.php for help.
@ -1210,7 +1213,7 @@
// // ... // // ...
// }; // };
// Add links to dashboard (will all be in a new "Other" category). // Example: Add links to dashboard (will all be in a new "Other" category).
// $config['mod']['dashboard_links']['Something'] = '?/something'; // $config['mod']['dashboard_links']['Something'] = '?/something';
// Remote servers. I'm not even sure if this code works anymore. It might. Haven't tried it in a while. // Remote servers. I'm not even sure if this code works anymore. It might. Haven't tried it in a while.

View File

@ -157,7 +157,7 @@ function loadConfig() {
if ($config['verbose_errors']) { if ($config['verbose_errors']) {
set_error_handler('verbose_error_handler'); set_error_handler('verbose_error_handler');
error_reporting(E_ALL); error_reporting(E_ALL);
ini_set('display_errors', false); ini_set('display_errors', true);
ini_set('html_errors', false); ini_set('html_errors', false);
} }

View File

@ -13,13 +13,14 @@ function config_vars() {
'default_temp' => false 'default_temp' => false
); );
$temp_comment = false; $temp_comment = false;
$line_no = 0;
foreach ($config_file as $line) { foreach ($config_file as $line) {
if ($temp_comment) { if ($temp_comment) {
$var['comment'][] = $temp_comment; $var['comment'][] = $temp_comment;
$temp_comment = false; $temp_comment = false;
} }
if (preg_match('!^\s*// (.*)$!', $line, $matches)) { if (preg_match('!^\s*// ([^$].*)$!', $line, $matches)) {
if ($var['default'] !== false) { if ($var['default'] !== false) {
$line = ''; $line = '';
$temp_comment = $matches[1]; $temp_comment = $matches[1];
@ -28,7 +29,10 @@ function config_vars() {
} }
} else if ($var['default_temp'] !== false) { } else if ($var['default_temp'] !== false) {
$var['default_temp'] .= "\n" . $line; $var['default_temp'] .= "\n" . $line;
} elseif (preg_match('!^\s*\$config\[(.+?)\] = (.+?)(;( //.+)?)?$!', $line, $matches)) { } elseif (preg_match('!^[\s/]*\$config\[(.+?)\] = (.+?)(;( //.+)?)?$!', $line, $matches)) {
if (preg_match('!^\s*//\s*!', $line)) {
$var['commented'] = true;
}
$var['name'] = explode('][', $matches[1]); $var['name'] = explode('][', $matches[1]);
if (count($var['name']) == 1) { if (count($var['name']) == 1) {
$var['name'] = preg_replace('/^\'(.*)\'$/', '$1', end($var['name'])); $var['name'] = preg_replace('/^\'(.*)\'$/', '$1', end($var['name']));
@ -43,20 +47,30 @@ function config_vars() {
$var['default_temp'] = $matches[2]; $var['default_temp'] = $matches[2];
} }
if (trim($line) === '') {
if ($var['name'] !== false) { if ($var['name'] !== false) {
if ($var['default_temp']) if ($var['default_temp'])
$var['default'] = $var['default_temp']; $var['default'] = $var['default_temp'];
if ($var['default'][0] == '&')
$temp = eval('return ' . $var['default'] . ';'); continue; // This is just an alias.
if (!isset($temp)) if (!preg_match('/^array|\[\]|function/', $var['default']) && !preg_match('/^Example: /', trim(implode(' ', $var['comment'])))) {
$syntax_error = true;
$temp = eval('$syntax_error = false;return ' . $var['default'] . ';');
if ($syntax_error && $temp === false) {
error('Error parsing config.php (line ' . $line_no . ')!', null, $var);
} elseif (!isset($temp)) {
$var['type'] = 'unknown'; $var['type'] = 'unknown';
else } else {
$var['type'] = gettype($temp); $var['type'] = gettype($temp);
}
unset($var['default_temp']); unset($var['default_temp']);
if (!is_array($var['name']) || (end($var['name']) != '' && !in_array(reset($var['name']), array('stylesheets')))) { if (!is_array($var['name']) || (end($var['name']) != '' && !in_array(reset($var['name']), array('stylesheets')))) {
$already_exists = false;
foreach ($conf as $_var) {
if ($var['name'] == $_var['name'])
$already_exists = true;
}
if (!$already_exists)
$conf[] = $var; $conf[] = $var;
} }
} }
@ -65,9 +79,16 @@ function config_vars() {
'name' => false, 'name' => false,
'comment' => array(), 'comment' => array(),
'default' => false, 'default' => false,
'default_temp' => false 'default_temp' => false,
'commented' => false
); );
} }
if (trim($line) === '') {
$var['comment'] = array();
}
$line_no++;
} }
return $conf; return $conf;

View File

@ -1975,7 +1975,7 @@ function mod_config() {
foreach ($var['name'] as $n) foreach ($var['name'] as $n)
$c = &$c[$n]; $c = &$c[$n];
} else { } else {
$c = $config[$var['name']]; $c = @$config[$var['name']];
} }
$var['value'] = $c; $var['value'] = $c;