Index: admin_events_handler.php =================================================================== --- admin_events_handler.php (revision 13557) +++ admin_events_handler.php (working copy) @@ -327,18 +327,20 @@ $field_options['default'] = $default_value; } - $fields[ $field_info['Field'] ] = $this->transformDump($field_options); - $grids_fields[ $field_info['Field'] ] = $this->transformDump($grid_col_options); + $fields[ $field_info['Field'] ] = $field_options; //$this->transformDump($field_options); + $grids_fields[ $field_info['Field'] ] = $grid_col_options; //$this->transformDump($grid_col_options); } $grids['Default']['Fields'] = $grids_fields; - $ret = "'IDField' => '".$id_field."',\n'Fields' => A".substr(stripslashes(var_export($fields, true)), 1).','; - $ret .= "\n"."'Grids' => ".stripslashes(var_export($grids, true)); + $ret = Array ( + 'IDField' => $id_field, + 'Fields' => $fields, + 'Grids' => $grids, + ); - $ret = str_replace('array (', 'Array (', $ret); - $ret = preg_replace("/'(.*?)' => 'Array \((.*?), \)',/", "'\\1' => Array (\\2),", $ret); - $ret = preg_replace("/\n '/", "\n\t'", $ret); + $decorator = new UnitConfigDecorator(); + $ret = $decorator->decorate($ret); $this->Application->InitParser(); ob_start(); @@ -357,19 +359,6 @@ $event->status = erSTOP; } - function transformDump($dump) - { - if (is_array($dump)) { - $dump = var_export($dump, true); - } - - $dump = preg_replace("/,\n[ ]*/", ', ', $dump); - $dump = preg_replace("/array \(\n[ ]*/", 'Array (', $dump); // replace array start - $dump = preg_replace("/,\n[ ]*\),/", "),", $dump); // replace array end - - return $dump; - } - /** * Refreshes ThemeFiles & Theme tables by actual content on HDD * @@ -1344,4 +1333,59 @@ echo $json_helper->encode($ret); } +} + + +class UnitConfigDecorator { + + var $parentPath = Array (); + + function decorate($var, $level = 0) + { + $ret = ''; + + $deep_level = count($this->parentPath); + + if ($deep_level && ($this->parentPath[0] == 'Fields')) { + $expand = $level < 2; + } + elseif ($deep_level && ($this->parentPath[0] == 'Grids')) { + if ($deep_level == 3 && $this->parentPath[2] == 'Icons') { + $expand = false; + } + else { + $expand = $level < 4; + } + } + else { + $expand = $level == 0; + } + + if (is_array($var)) { + $ret .= 'Array ('; + $prepend = $expand ? "\n" . str_repeat("\t", $level + 1) : ''; + + foreach ($var as $key => $value) { + array_push($this->parentPath, $key); + $ret .= $prepend . (is_string($key) ? "'" . $key . "'" : $key) . ' => ' . $this->decorate($value, $level + 1) . ', '; + array_pop($this->parentPath); + } + + $prepend = $expand ? "\n" . str_repeat("\t", $level) : ''; + $ret = rtrim($ret, ', ') . $prepend . ')'; + } + else { + if (is_null($var)) { + $ret = 'NULL'; + } + elseif (is_string($var)) { + $ret = "'" . $var . "'"; + } + else { + $ret = $var; + } + } + + return $ret; + } } \ No newline at end of file