1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
use html_go\exceptions\InternalException; |
4
|
|
|
use html_go\model\Config; |
5
|
|
|
|
6
|
|
|
function get_site_object(): \stdClass { |
7
|
|
|
$config = get_config(); |
8
|
|
|
$site = new \stdClass(); |
9
|
|
|
$site->url = $config->getString(Config::KEY_SITE_URL); |
10
|
|
|
$site->name = $config->getString(Config::KEY_SITE_NAME); |
11
|
|
|
$site->title = $config->getString(Config::KEY_SITE_TITLE); |
12
|
|
|
$site->description = $config->getString(Config::KEY_SITE_DESCRIPTION); |
13
|
|
|
$site->tagline = $config->getString(Config::KEY_SITE_TAGLINE); |
14
|
|
|
$site->copyright = $config->getString(Config::KEY_SITE_COPYRIGHT); |
15
|
|
|
$site->language = $config->getString(Config::KEY_LANG); |
16
|
|
|
$site->theme = $config->getString(Config::KEY_THEME_NAME); |
17
|
|
|
$site->tpl_engine = $config->getString(Config::KEY_TPL_ENGINE); |
18
|
|
|
return $site; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* |
23
|
|
|
* @param string $titleLangKey |
24
|
|
|
* @param string $template |
25
|
|
|
* @param string $section |
26
|
|
|
* @param string $action |
27
|
|
|
* @param array<mixed> $params |
28
|
|
|
* @param array<\stdClass> $list |
29
|
|
|
* @return \stdClass |
30
|
|
|
*/ |
31
|
|
|
function get_admin_content_object(string $titleLangKey, string $template, string $section, string $action, array $params = [], array $list = []): \stdClass { |
32
|
|
|
$data = [ |
33
|
|
|
'title' => get_i18n()->getText($titleLangKey), |
34
|
|
|
'template' => $template, |
35
|
|
|
'context' => get_config()->getString(Config::KEY_ADMIN_CONTEXT), |
36
|
|
|
'section' => $section, |
37
|
|
|
'action' => $action, |
38
|
|
|
'list' => $list |
39
|
|
|
]; |
40
|
|
|
return get_model_factory()->createAdminContentObject(\array_merge($data, $params)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Returns the admin dashboard view content object. |
45
|
|
|
* @param array<mixed> $args |
46
|
|
|
* @return \stdClass |
47
|
|
|
*/ |
48
|
|
|
function get_dashboard_view_content_object(array $args): \stdClass { |
49
|
|
|
return get_admin_content_object( |
50
|
|
|
'admin.dashboard.title', |
51
|
|
|
'dashboard.html', |
52
|
|
|
ADMIN_CONSOLE_SECTION, |
53
|
|
|
ADMIN_ACTION_VIEW, |
54
|
|
|
$args); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Persist content. |
59
|
|
|
* @param string $section |
60
|
|
|
* @param array<mixed> $data |
61
|
|
|
* @throws InternalException |
62
|
|
|
*/ |
63
|
|
|
function save_content(string $section, array $data): void { |
64
|
|
|
switch ($section) { |
65
|
|
|
case CATEGORY_SECTION: |
66
|
|
|
$filename = URLify::slug(\strtolower($data['title'])); |
67
|
|
|
$filePath = CATEGORY_ROOT.DS.$filename.CONTENT_FILE_EXT; |
68
|
|
|
break; |
69
|
|
|
default: |
70
|
|
|
throw new InternalException("Unknown section [$section]"); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
unset($data[ADMIN_KEY_STR], $data[ADMIN_ACTION_STR], $data['save'], $data[ADMIN_CONTEXT_STR], $data['errorKey']); |
74
|
|
|
|
75
|
|
|
if (($json = \json_encode($data, JSON_PRETTY_PRINT)) === false) { |
76
|
|
|
throw new InternalException("json_encode function failed!"); |
77
|
|
|
} |
78
|
|
|
if (\file_put_contents($filePath, $json) === false) { |
79
|
|
|
throw new InternalException("file_put_contents function failed!"); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
get_index_manager()->reindex(); |
83
|
|
|
} |
84
|
|
|
|