Diff: STRATO-apps/wordpress_03/app/wp-content/themes/blocksy/inc/components/builder/footer-logic.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 +
3 + class Blocksy_Footer_Builder {
4 + private $default_value = null;
5 +
6 + private $section_value = null;
7 + private $current_section = null;
8 +
9 + public function get_default_value() {
10 + if ($this->default_value) {
11 + return $this->default_value;
12 + }
13 +
14 + $this->default_value = [
15 + 'current_section' => 'type-1',
16 + 'sections' => [
17 + $this->get_structure_for([
18 + 'id' => 'type-1',
19 + 'rows' => [
20 + 'top-row' => [
21 + 'columns' => [
22 + [],
23 + []
24 + ]
25 + ],
26 +
27 + 'middle-row' => [
28 + 'columns' => [
29 + [],
30 + [],
31 + []
32 + ]
33 + ],
34 +
35 + 'bottom-row' => [
36 + 'columns' => [
37 + ['copyright']
38 + ]
39 + ],
40 + ]
41 + ]),
42 +
43 + $this->get_structure_for([
44 + 'id' => 'type-2',
45 + 'rows' => [
46 + 'top-row' => [
47 + 'columns' => [
48 + [],
49 + []
50 + ]
51 + ],
52 +
53 + 'middle-row' => [
54 + 'columns' => [
55 + [],
56 + [],
57 + [],
58 + []
59 + ]
60 + ],
61 +
62 + 'bottom-row' => [
63 + 'columns' => [
64 + ['copyright']
65 + ]
66 + ],
67 + ]
68 + ])
69 + ]
70 + ];
71 +
72 + return $this->default_value;
73 + }
74 +
75 + public function enabled_on_this_page() {
76 + return blocksy_default_akg(
77 + 'disable_footer',
78 + blocksy_get_post_options(),
79 + 'no'
80 + ) === 'no';
81 + }
82 +
83 + public function translation_keys() {
84 + $render = new Blocksy_Footer_Builder_Render();
85 + $sections = $render->get_section_value();
86 +
87 + $result = [];
88 +
89 + foreach ($sections['sections'] as $section) {
90 + foreach ($section['items'] as $item) {
91 + $nested_item = $render->get_item_config_for($item['id']);
92 +
93 + if (
94 + ! isset($nested_item['config']['translation_keys'])
95 + ||
96 + empty($nested_item['config']['translation_keys'])
97 + ) {
98 + continue;
99 + }
100 +
101 + foreach ($nested_item['config']['translation_keys'] as $key) {
102 + if (! isset($item['values'][$key['key']])) {
103 + continue;
104 + }
105 +
106 + $key_prefix = 'footer:' . $section['id'] . ':' . $item['id'] . ':' . $key['key'];
107 +
108 + if (isset($key['all_layers'])) {
109 + foreach ($item['values'][$key['key']] as $single_layer) {
110 + foreach ($key['all_layers'] as $layer_key) {
111 + if (! isset($single_layer[$layer_key])) {
112 + continue;
113 + }
114 +
115 + $result[] = array_merge($key, [
116 + 'key' => $key_prefix . ':' . $single_layer['id'] . ':' . $layer_key,
117 + 'value' => $single_layer[$layer_key]
118 + ]);
119 + }
120 + }
121 + } else {
122 + $result[] = array_merge($key, [
123 + 'key' => $key_prefix,
124 + 'value' => $item['values'][$key['key']]
125 + ]);
126 + }
127 + }
128 + }
129 + }
130 +
131 + return $result;
132 + }
133 +
134 + public function typography_keys() {
135 + $render = new Blocksy_Footer_Builder_Render();
136 + $section = $render->get_current_section();
137 +
138 + $result = [];
139 +
140 + foreach ($section['items'] as $item) {
141 + $nested_item = $render->get_item_config_for($item['id']);
142 +
143 + if (
144 + ! isset($nested_item['config']['typography_keys'])
145 + ||
146 + empty($nested_item['config']['typography_keys'])
147 + ) {
148 + continue;
149 + }
150 +
151 + $data = $render->get_item_data_for($item['id']);
152 +
153 + foreach ($nested_item['config']['typography_keys'] as $key) {
154 + $result[] = blocksy_akg($key, $data, []);
155 + }
156 + }
157 +
158 + return $result;
159 + }
160 +
161 + public function render() {
162 + if (! $this->enabled_on_this_page()) {
163 + return '';
164 + }
165 +
166 + $render = new Blocksy_Footer_Builder_Render();
167 + return $render->render();
168 + }
169 +
170 + public function get_structure_for($args = []) {
171 + $args = wp_parse_args($args, [
172 + 'id' => null,
173 + 'mode' => 'columns',
174 + 'rows' => []
175 + ]);
176 +
177 + $args['rows'] = wp_parse_args($args['rows'], [
178 + 'top-row' => [],
179 + 'middle-row' => [],
180 + 'bottom-row' => [],
181 + ]);
182 +
183 + $base = [
184 + 'id' => $args['id'],
185 + 'mode' => $args['mode'],
186 + 'rows' => [
187 + $this->get_bar_structure_for(array_merge([
188 + 'id' => 'top-row',
189 + 'mode' => $args['mode'],
190 + ], $args['rows']['top-row'])),
191 + $this->get_bar_structure_for(array_merge([
192 + 'id' => 'middle-row',
193 + 'mode' => $args['mode']
194 + ], $args['rows']['middle-row'])),
195 + $this->get_bar_structure_for(array_merge([
196 + 'id' => 'bottom-row',
197 + 'mode' => $args['mode']
198 + ], $args['rows']['bottom-row'])),
199 + ],
200 + 'items' => [],
201 + 'settings' => []
202 + ];
203 +
204 + return $base;
205 + }
206 +
207 + private function get_bar_structure_for($args = []) {
208 + $args = wp_parse_args($args, [
209 + 'id' => null,
210 + 'mode' => 'columns',
211 + 'columns' => [
212 + /**
213 + * We always have one column available
214 + */
215 + [],
216 + [],
217 + []
218 + ]
219 + ]);
220 +
221 + return array_merge([
222 + 'id' => $args['id'],
223 + 'columns' => $args['columns']
224 + ]);
225 + }
226 +
227 + public function get_section_value() {
228 + if (! $this->section_value || is_customize_preview()) {
229 + $this->section_value = blocksy_get_theme_mod(
230 + 'footer_placements',
231 + $this->get_default_value()
232 + );
233 + }
234 +
235 + return $this->section_value;
236 + }
237 +
238 + public function get_current_section_id() {
239 + return $this->get_current_section()['id'];
240 + }
241 +
242 + public function get_current_section() {
243 + if (! $this->current_section) {
244 + $this->current_section = $this->get_section_value()['sections'][0];
245 +
246 + foreach ($this->get_section_value()['sections'] as $single_section) {
247 + if ($single_section['id'] === $this->get_filtered_section_id()) {
248 + $this->current_section = $single_section;
249 + break;
250 + }
251 + }
252 + }
253 +
254 + return $this->current_section;
255 + }
256 +
257 + private function get_filtered_section_id() {
258 + if (
259 + is_customize_preview()
260 + &&
261 + isset($this->get_section_value()['__forced_static_footer__'])
262 + ) {
263 + return $this->get_section_value()['__forced_static_footer__'];
264 + }
265 +
266 + return apply_filters(
267 + 'blocksy:footer:current_section_id',
268 + 'type-1',
269 + $this->get_section_value()
270 + );
271 + }
272 +
273 + public function patch_value_for($processed_terms) {
274 + $current_value = blocksy_get_theme_mod(
275 + 'footer_placements',
276 + $this->get_default_value()
277 + );
278 +
279 + foreach ($current_value['sections'] as $index => $header) {
280 + if (! isset($header['items'])) {
281 + continue;
282 + }
283 +
284 + foreach ($header['items'] as $item_index => $item) {
285 + if (! isset($item['values'])) {
286 + continue;
287 + }
288 +
289 + if (! isset($item['values']['menu'])) {
290 + continue;
291 + }
292 +
293 + if (! isset($processed_terms[$item['values']['menu']])) {
294 + continue;
295 + }
296 +
297 + $current_value['sections'][$index][
298 + 'items'
299 + ][$item_index]['values']['menu'] = $processed_terms[$item['values']['menu']];
300 + }
301 + }
302 +
303 + set_theme_mod('footer_placements', $current_value);
304 + }
305 + }
306 +
307 +