$name, 'comment' => $currentComment, 'type' => $type, 'value' => $value); $currentComment = ''; } } return $config; } $orig = parse_config('config.dist.php'); $local = parse_config('config.local.php'); $config = array(); foreach ($local as $name=>$properties) { $config[$name] = array(); $config[$name]['local'] = $properties; } foreach ($orig as $name=>$properties) { if (!isset($config[$name])) $config[$name] = array(); $config[$name]['orig'] = $properties; } if (!empty($_POST['save'])) { foreach ($config as $name=>&$prop) { if (!isset($_POST[$name])) continue; if (!isset($prop['local'])) continue; if ($prop['local']['type'] == 'code') continue; switch ($prop['local']['type']) { case 'bool': $prop['local']['value'] = (bool) $_POST[$name]; break; case 'int': $prop['local']['value'] = (int) $_POST[$name]; break; case 'string': $prop['local']['value'] = (string) $_POST[$name]; break; default: break; } } $out = "&$prop) { $comment = str_replace("\n", "\n// ", trim($prop['local']['comment'])); $out .= "// ".$comment."\n"; $out .= "define('".$name."', "; if ($prop['local']['type'] == 'string') $out .= '\''.str_replace('\'', '\\\'', $prop['local']['value']).'\''; elseif ($prop['local']['type'] == 'bool') $out .= $prop['local']['value'] ? 'true' : 'false'; else $out .= $prop['local']['value']; $out .= ");\n\n"; } $out .= "?>"; file_put_contents(LENCRIER_ROOT . '/config.local.php', $out); utils::redirect('/admin/config.php'); } $title = 'Configuration'; $tpl->assign('config', $config); $tpl->display('admin/config.tpl'); ?>