1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
<?php
class Skin {
public string $title = 'title';
public array $static = [];
public array $meta = [];
protected array $langKeys = [];
protected array $options = [
'full_width' => false,
'dynlogo_enabled' => true,
'logo_path_map' => [],
'logo_link_map' => [],
];
public function renderPage($f, ...$vars): Response {
$f = '\\skin\\'.str_replace('/', '\\', $f);
$ctx = new SkinContext(substr($f, 0, ($pos = strrpos($f, '\\'))));
$body = call_user_func_array([$ctx, substr($f, $pos+1)], $vars);
if (is_array($body))
list($body, $js) = $body;
else
$js = null;
$theme = themes::getUserTheme();
if ($theme != 'auto' && !themes::themeExists($theme))
$theme = 'auto';
$layout_ctx = new SkinContext('\\skin\\base');
$lang = $this->getLang();
$lang = !empty($lang) ? json_encode($lang, JSON_UNESCAPED_UNICODE) : '';
return new Response(200, $layout_ctx->layout(
static: $this->static,
theme: $theme,
title: $this->title,
opts: $this->options,
js: $js,
meta: $this->meta,
unsafe_lang: $lang,
unsafe_body: $body,
exec_time: exectime()
));
}
public function addLangKeys(array $keys): void {
$this->langKeys = array_merge($this->langKeys, $keys);
}
protected function getLang(): array {
$lang = [];
$ld = LangData::getInstance();
foreach ($this->langKeys as $key)
$lang[$key] = $ld[$key];
return $lang;
}
public function setOptions(array $options): void {
$this->options = array_merge($this->options, $options);
}
}
|