From c9684fc0001ceaa521e80a50d353ecbfe3fafe9b Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Sat, 3 Aug 2013 05:21:02 -0400 Subject: Better/working web config editor --- inc/mod/config-editor.php | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'inc/mod/config-editor.php') diff --git a/inc/mod/config-editor.php b/inc/mod/config-editor.php index 484bd908..d6cad8f0 100644 --- a/inc/mod/config-editor.php +++ b/inc/mod/config-editor.php @@ -13,13 +13,14 @@ function config_vars() { 'default_temp' => false ); $temp_comment = false; + $line_no = 0; foreach ($config_file as $line) { if ($temp_comment) { $var['comment'][] = $temp_comment; $temp_comment = false; } - if (preg_match('!^\s*// (.*)$!', $line, $matches)) { + if (preg_match('!^\s*// ([^$].*)$!', $line, $matches)) { if ($var['default'] !== false) { $line = ''; $temp_comment = $matches[1]; @@ -28,7 +29,10 @@ function config_vars() { } } else if ($var['default_temp'] !== false) { $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]); if (count($var['name']) == 1) { $var['name'] = preg_replace('/^\'(.*)\'$/', '$1', end($var['name'])); @@ -43,20 +47,30 @@ function config_vars() { $var['default_temp'] = $matches[2]; } - if (trim($line) === '') { - if ($var['name'] !== false) { - if ($var['default_temp']) - $var['default'] = $var['default_temp']; - - $temp = eval('return ' . $var['default'] . ';'); - if (!isset($temp)) + if ($var['name'] !== false) { + if ($var['default_temp']) + $var['default'] = $var['default_temp']; + if ($var['default'][0] == '&') + continue; // This is just an alias. + 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'; - else + } else { $var['type'] = gettype($temp); - + } unset($var['default_temp']); - 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; } } @@ -65,9 +79,16 @@ function config_vars() { 'name' => false, 'comment' => array(), 'default' => false, - 'default_temp' => false + 'default_temp' => false, + 'commented' => false ); } + + if (trim($line) === '') { + $var['comment'] = array(); + } + + $line_no++; } return $conf; -- cgit v1.3 From 0d1bfa47f1f459b4893426e752ce2d3e9b2de030 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Sat, 3 Aug 2013 05:41:01 -0400 Subject: Web config editor: Write "MOD", "JANITOR", etc. to instance-config instead of just int representations --- inc/mod/config-editor.php | 10 +++++++++- inc/mod/pages.php | 15 ++++++++++++++- templates/mod/config-editor.html | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) (limited to 'inc/mod/config-editor.php') diff --git a/inc/mod/config-editor.php b/inc/mod/config-editor.php index d6cad8f0..caca5a0e 100644 --- a/inc/mod/config-editor.php +++ b/inc/mod/config-editor.php @@ -62,6 +62,13 @@ function config_vars() { } else { $var['type'] = gettype($temp); } + + if ($var['type'] == 'integer' && $var['name'][0] == 'mod' && + (in_array($var['default'], array('JANITOR', 'MOD', 'ADMIN', 'DISABLED')) || mb_strpos($var['default'], "\$config['mod']") === 0)) { + // Permissions variable + $var['permissions'] = true; + } + unset($var['default_temp']); if (!is_array($var['name']) || (end($var['name']) != '' && !in_array(reset($var['name']), array('stylesheets')))) { $already_exists = false; @@ -80,7 +87,8 @@ function config_vars() { 'comment' => array(), 'default' => false, 'default_temp' => false, - 'commented' => false + 'commented' => false, + 'permissions' => false, ); } diff --git a/inc/mod/pages.php b/inc/mod/pages.php index 6c46a84f..13520871 100644 --- a/inc/mod/pages.php +++ b/inc/mod/pages.php @@ -2010,7 +2010,20 @@ function mod_config() { $config_append .= '[' . var_export($var['name'], true) . ']'; } - $config_append .= ' = ' . var_export($value, true) . ";\n"; + + $config_append .= ' = '; + if ($var['permissions'] && in_array($value, array(JANITOR, MOD, ADMIN, DISABLED))) { + $perm_array = array( + JANITOR => 'JANITOR', + MOD => 'MOD', + ADMIN => 'ADMIN', + DISABLED => 'DISABLED' + ); + $config_append .= $perm_array[$value]; + } else { + $config_append .= var_export($value, true); + } + $config_append .= ";\n"; } } diff --git a/templates/mod/config-editor.html b/templates/mod/config-editor.html index 41e01dad..d333e9a2 100644 --- a/templates/mod/config-editor.html +++ b/templates/mod/config-editor.html @@ -25,7 +25,7 @@ {% if var.type == 'string' %} - {% elseif var.type == 'integer' and var.name.0 == 'mod' and (var.default in ['JANITOR', 'MOD', 'ADMIN', 'DISABLED'] or var.default|slice(0, 14) == "$config['mod']") and var.value <= constant('DISABLED') %} + {% elseif var.permissions %}