summaryrefslogtreecommitdiff
path: root/inc/mod/config-editor.php
diff options
context:
space:
mode:
authorczaks <marcin@6irc.net>2013-08-05 06:03:40 -0400
committerczaks <marcin@6irc.net>2013-08-05 06:03:40 -0400
commita84c4510fccfdc0cfb6f187633daea10dc70f326 (patch)
tree6077f5211196ae40cac0184bb7cc67b81d320b0b /inc/mod/config-editor.php
parent33c7abf11f3a9b5c0964a2d7a25533c2849dbc78 (diff)
parenta8327c3a37fd22d2aa5d63061c9d3eaa30ae425a (diff)
Merge branch 'master' of github.com:vichan-devel/Tinyboard
Conflicts: js/post-hider.js
Diffstat (limited to 'inc/mod/config-editor.php')
-rw-r--r--inc/mod/config-editor.php93
1 files changed, 80 insertions, 13 deletions
diff --git a/inc/mod/config-editor.php b/inc/mod/config-editor.php
index 484bd908..27740378 100644
--- a/inc/mod/config-editor.php
+++ b/inc/mod/config-editor.php
@@ -1,5 +1,43 @@
<?php
+function permission_to_edit_config_var($varname) {
+ global $config, $mod;
+
+ if (is_array($config['mod']['config'][DISABLED])) {
+ foreach ($config['mod']['config'][DISABLED] as $disabled_var_name) {
+ $disabled_var_name = explode('>', $disabled_var_name);
+ if (count($disabled_var_name) == 1)
+ $disabled_var_name = $disabled_var_name[0];
+ if ($varname == $disabled_var_name)
+ return false;
+ }
+ }
+
+ $allow_only = false;
+ // for ($perm = (int)$mod['type']; $perm >= JANITOR; $perm --) {
+ for ($perm = JANITOR; $perm <= (int)$mod['type']; $perm ++) {
+ $allow_only = false;
+ if (is_array($config['mod']['config'][$perm])) {
+ foreach ($config['mod']['config'][$perm] as $perm_var_name) {
+ if ($perm_var_name == '!') {
+ $allow_only = true;
+ continue;
+ }
+ $perm_var_name = explode('>', $perm_var_name);
+ if ((count($perm_var_name) == 1 && $varname == $perm_var_name[0]) ||
+ (is_array($varname) && array_slice($varname, 0, count($perm_var_name)) == $perm_var_name)) {
+ if ($allow_only)
+ return true;
+ else
+ return false;
+ }
+ }
+ }
+ }
+
+ return !$allow_only;
+}
+
function config_vars() {
global $config;
@@ -13,13 +51,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 +67,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,21 +85,38 @@ 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 ($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')))) {
- $conf[] = $var;
+ $already_exists = false;
+ foreach ($conf as $_var) {
+ if ($var['name'] == $_var['name'])
+ $already_exists = true;
+
+ }
+ if (!$already_exists && permission_to_edit_config_var($var['name']))
+ $conf[] = $var;
}
}
@@ -65,9 +124,17 @@ function config_vars() {
'name' => false,
'comment' => array(),
'default' => false,
- 'default_temp' => false
+ 'default_temp' => false,
+ 'commented' => false,
+ 'permissions' => false,
);
}
+
+ if (trim($line) === '') {
+ $var['comment'] = array();
+ }
+
+ $line_no++;
}
return $conf;