-
Notifications
You must be signed in to change notification settings - Fork 15
/
extend.php
58 lines (48 loc) · 1.58 KB
/
extend.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
<?php
/*
* This file is part of flarum-lang/chinese-simplified.
*
* Copyright (c) 2024 Golden.
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
use Flarum\Extend;
use Flarum\Extend\LanguagePack;
use Flarum\Frontend\Document;
use Flarum\Settings\SettingsRepositoryInterface;
$extKey = 'flarum-lang-chinese-simplified';
$settings = resolve(SettingsRepositoryInterface::class);
$useGoogleFonts = $settings->get($extKey.'.use_google_fonts');
function is_mobile() {
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$mobile_agents = ['Mobile', 'Android', 'Silk/', 'Kindle', 'BlackBerry', 'Opera Mini', 'Opera Mobi'];
foreach ($mobile_agents as $agent) {
if (stripos($user_agent, $agent) !== false) {
return true;
}
}
return false;
}
$insertFonts = function (Document $document) use ($extKey) {
if (!is_mobile()) {
$document->head[] = '<link rel="stylesheet" href="/assets/extensions/'. $extKey .'/google-fonts/google-fonts.css">';
}
};
$extends = [
(new Extend\Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js')
->css(__DIR__.'/less/admin.less'),
new LanguagePack,
];
if ($useGoogleFonts) {
$extends[] = (new Extend\Frontend('forum'))
->content(function (Document $document) use ($insertFonts) {
$insertFonts($document);
});
$extends[] = (new Extend\Frontend('admin'))
->content(function (Document $document) use ($insertFonts) {
$insertFonts($document);
});
}
return $extends;