1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-26 16:30:52 +01:00
vichan/inc/mod/config-editor.php

97 lines
2.5 KiB
PHP
Raw Normal View History

2012-05-20 12:21:33 +02:00
<?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;
2013-08-03 11:21:02 +02:00
$line_no = 0;
2012-05-20 12:21:33 +02:00
foreach ($config_file as $line) {
if ($temp_comment) {
$var['comment'][] = $temp_comment;
$temp_comment = false;
}
2013-08-03 11:21:02 +02:00
if (preg_match('!^\s*// ([^$].*)$!', $line, $matches)) {
2012-05-20 12:21:33 +02:00
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;
2013-08-03 11:21:02 +02:00
} elseif (preg_match('!^[\s/]*\$config\[(.+?)\] = (.+?)(;( //.+)?)?$!', $line, $matches)) {
if (preg_match('!^\s*//\s*!', $line)) {
$var['commented'] = true;
}
2012-05-20 12:21:33 +02:00
$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];
}
2013-08-03 11:21:02 +02:00
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)) {
2012-05-20 12:21:33 +02:00
$var['type'] = 'unknown';
2013-08-03 11:21:02 +02:00
} else {
2012-05-20 12:21:33 +02:00
$var['type'] = gettype($temp);
2013-08-03 11:21:02 +02:00
}
2012-05-20 12:21:33 +02:00
unset($var['default_temp']);
if (!is_array($var['name']) || (end($var['name']) != '' && !in_array(reset($var['name']), array('stylesheets')))) {
2013-08-03 11:21:02 +02:00
$already_exists = false;
foreach ($conf as $_var) {
if ($var['name'] == $_var['name'])
$already_exists = true;
}
if (!$already_exists)
2012-05-20 12:21:33 +02:00
$conf[] = $var;
}
}
$var = array(
'name' => false,
'comment' => array(),
'default' => false,
2013-08-03 11:21:02 +02:00
'default_temp' => false,
'commented' => false
2012-05-20 12:21:33 +02:00
);
}
2013-08-03 11:21:02 +02:00
if (trim($line) === '') {
$var['comment'] = array();
}
$line_no++;
2012-05-20 12:21:33 +02:00
}
return $conf;
}