summaryrefslogtreecommitdiff
path: root/inc/mod/config-editor.php
diff options
context:
space:
mode:
authorMichael Save <savetheinternet@tinyboard.org>2012-05-20 20:21:33 +1000
committerMichael Save <savetheinternet@tinyboard.org>2012-05-20 20:21:33 +1000
commit4a48888b559ef6233283173ba13ad2a85217e5d1 (patch)
tree92d9d948dda37d42f5fde0b573176794ba69cfb2 /inc/mod/config-editor.php
parentd3739c48c2c2deec83e6abf74ed8e03470581750 (diff)
Config editor
Diffstat (limited to 'inc/mod/config-editor.php')
-rw-r--r--inc/mod/config-editor.php75
1 files changed, 75 insertions, 0 deletions
diff --git a/inc/mod/config-editor.php b/inc/mod/config-editor.php
new file mode 100644
index 00000000..484bd908
--- /dev/null
+++ b/inc/mod/config-editor.php
@@ -0,0 +1,75 @@
+<?php
+
+function config_vars() {
+ global $config;
+
+ $config_file = file('inc/config.php', FILE_IGNORE_NEW_LINES);
+ $conf = array();
+
+ $var = array(
+ 'name' => false,
+ 'comment' => array(),
+ 'default' => false,
+ 'default_temp' => false
+ );
+ $temp_comment = false;
+ foreach ($config_file as $line) {
+ if ($temp_comment) {
+ $var['comment'][] = $temp_comment;
+ $temp_comment = false;
+ }
+
+ if (preg_match('!^\s*// (.*)$!', $line, $matches)) {
+ if ($var['default'] !== false) {
+ $line = '';
+ $temp_comment = $matches[1];
+ } else {
+ $var['comment'][] = $matches[1];
+ }
+ } else if ($var['default_temp'] !== false) {
+ $var['default_temp'] .= "\n" . $line;
+ } elseif (preg_match('!^\s*\$config\[(.+?)\] = (.+?)(;( //.+)?)?$!', $line, $matches)) {
+ $var['name'] = explode('][', $matches[1]);
+ if (count($var['name']) == 1) {
+ $var['name'] = preg_replace('/^\'(.*)\'$/', '$1', end($var['name']));
+ } else {
+ foreach ($var['name'] as &$i)
+ $i = preg_replace('/^\'(.*)\'$/', '$1', $i);
+ }
+
+ if (isset($matches[3]))
+ $var['default'] = $matches[2];
+ else
+ $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))
+ $var['type'] = 'unknown';
+ else
+ $var['type'] = gettype($temp);
+
+ unset($var['default_temp']);
+
+ if (!is_array($var['name']) || (end($var['name']) != '' && !in_array(reset($var['name']), array('stylesheets')))) {
+ $conf[] = $var;
+ }
+ }
+
+ $var = array(
+ 'name' => false,
+ 'comment' => array(),
+ 'default' => false,
+ 'default_temp' => false
+ );
+ }
+ }
+
+ return $conf;
+}
+