-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·61 lines (56 loc) · 1.85 KB
/
index.php
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
<?php namespace x\art;
function content($content) {
if (!$content) {
return $content;
}
\extract(\lot(), \EXTR_SKIP);
if (empty($page)) {
return $content;
}
// Append custom CSS before `</head>`
$content = \strtr($content, ['</head>' => $page->style . '</head>']);
// Append custom JS before `</body>`
$content = \strtr($content, ['</body>' => $page->script . '</body>']);
return $content;
}
function page__script($script) {
if ("" === ($script = \trim($script ?? ""))) {
return null;
}
if (false === \strpos($script, '</script>') && false === \strpos($script, '<script ')) {
return '<script>' . $script . '</script>';
}
return $script;
}
function page__style($style) {
if ("" === ($style = \trim($style ?? ""))) {
return null;
}
if (false === \strpos($style, '</style>') && false === \strpos($style, '<link ')) {
return '<style media="screen">' . $style . '</style>';
}
return $style;
}
function route__page($content, $path) {
\extract(\lot(), \EXTR_SKIP);
$folder = \LOT . \D . 'page' . \D . \trim($path ?? $state->route, '/');
if ($file = \exist([
$folder . '.archive',
$folder . '.page'
], 1)) {
$page = new \Page($file);
$script = $page->script;
$style = $page->style;
\State::set([
'is' => ['art' => $art = $script || $style],
'not' => ['art' => !$art]
]);
}
}
// Temporarily disable art page by adding query string `?art=false` in URL
if (!\array_key_exists('art', $_GET) || !empty($_GET['art'])) {
\Hook::set('content', __NAMESPACE__ . "\\content", 1);
\Hook::set('page.script', __NAMESPACE__ . "\\page__script", 2);
\Hook::set('page.style', __NAMESPACE__ . "\\page__style", 2);
\Hook::set('route.page', __NAMESPACE__ . "\\route__page", 0);
}