-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArchLinuxTheme.php
83 lines (70 loc) · 2.17 KB
/
ArchLinuxTheme.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace ArchLinux\Theme;
use Flarum\Foundation\Config;
use Flarum\Frontend\Document;
use Illuminate\Contracts\View\Factory as ViewFactory;
use Illuminate\Support\Arr;
class ArchLinuxTheme
{
private const ASSETS_PATH = '/assets/extensions/archlinux-de-theme-archlinux';
public function __construct(private Config $config, private ViewFactory $factory)
{
}
public function __invoke(Document $document): void
{
$forumApiDocument = $document->getForumApiDocument();
Arr::set($document->meta, 'theme-color', '#333');
Arr::set(
$document->head,
'manifest',
'<link rel="manifest" href="' . self::ASSETS_PATH . '/manifest.webmanifest">'
);
if (!Arr::get($forumApiDocument, 'data.attributes.faviconUrl')) {
Arr::set(
$document->head,
'favicon',
'<link rel="icon" href="' . self::ASSETS_PATH . '/archicon.svg" sizes="any" type="image/svg+xml">'
);
}
$config = $this->getConfig();
Arr::set(
$forumApiDocument,
'data.attributes.headerHtml',
$this->createHeader($config) . Arr::get($forumApiDocument, 'data.attributes.headerHtml', '')
);
Arr::set(
$forumApiDocument,
'data.attributes.footerHtml',
Arr::get($forumApiDocument, 'data.attributes.footerHtml', '') . $this->createFooter($config)
);
$document->setForumApiDocument($forumApiDocument);
}
/**
* @return string[]
*/
private function getConfig(): array
{
$config = $this->config->offsetGet('arch');
return is_array($config) ? $config : [];
}
/**
* @param string[] $config
*/
private function createHeader(array $config): string
{
return $this->factory->make(
'theme-archlinux::header',
$config
)->render();
}
/**
* @param string[] $config
*/
private function createFooter(array $config): string
{
return $this->factory->make(
'theme-archlinux::footer',
$config
)->render();
}
}