| @@ -9,8 +9,9 @@ | ||
| 9 | 9 | 'open' => '{' . PHP_EOL, |
| 10 | 10 | 'close' => PHP_EOL . '}', |
| 11 | 11 | 'parent' => 0 |
| 12 | 12 | ]; |
| 13 | + private $setup = false; | |
| 13 | 14 | |
| 14 | 15 | public function start() |
| 15 | 16 | { |
| 16 | 17 | // write headers |
| @@ -29,10 +30,23 @@ | ||
| 29 | 30 | } |
| 30 | 31 | |
| 31 | 32 | fputs($this->fh, $this->parts['open'] . PHP_EOL); |
| 32 | 33 | $this->counter = 0; |
| 34 | + | |
| 35 | + update_option('iwp_exporter_json_config', [ | |
| 36 | + 'parts' => $this->parts | |
| 37 | + ]); | |
| 33 | 38 | } |
| 34 | 39 | |
| 40 | + public function loadConfig() | |
| 41 | + { | |
| 42 | + if (!$this->setup) { | |
| 43 | + $config = get_option('iwp_exporter_json_config', []); | |
| 44 | + $this->parts = $config['parts']; | |
| 45 | + $this->setup = true; | |
| 46 | + } | |
| 47 | + } | |
| 48 | + | |
| 35 | 49 | public function generate_wrapper($fields, $output = [], $parent = 0, $depth = 0) |
| 36 | 50 | { |
| 37 | 51 | |
| 38 | 52 | $current_items = array_filter($fields, function ($item) use ($parent) { |
| @@ -58,8 +72,9 @@ | ||
| 58 | 72 | } |
| 59 | 73 | |
| 60 | 74 | public function add($mapper) |
| 61 | 75 | { |
| 76 | + $this->loadConfig(); | |
| 62 | 77 | |
| 63 | 78 | // $data = array_map(function($value){ |
| 64 | 79 | // if(is_array($value)){ |
| 65 | 80 | // $value = implode('|', $value); |
| @@ -77,8 +92,10 @@ | ||
| 77 | 92 | } |
| 78 | 93 | |
| 79 | 94 | public function end() |
| 80 | 95 | { |
| 96 | + $this->loadConfig(); | |
| 97 | + | |
| 81 | 98 | fputs($this->fh, PHP_EOL . $this->parts['close']); |
| 82 | 99 | fclose($this->fh); |
| 83 | 100 | } |
| 84 | 101 | |