1
|
|
|
<?php namespace Modules\Setting\Providers; |
2
|
|
|
|
3
|
|
|
use Illuminate\Support\ServiceProvider; |
4
|
|
|
|
5
|
|
|
class ThemeServiceProvider extends ServiceProvider |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Register the service provider. |
9
|
|
|
* @return void |
10
|
|
|
*/ |
11
|
|
|
public function register() |
12
|
|
|
{ |
13
|
|
|
$this->app->booted(function () { |
14
|
|
|
$this->registerAllThemes(); |
15
|
|
|
$this->setActiveTheme(); |
16
|
|
|
}); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Set the active theme based on the settings |
21
|
|
|
*/ |
22
|
|
|
private function setActiveTheme() |
23
|
|
|
{ |
24
|
|
|
if ($this->app->runningInConsole() || ! app('asgard.isInstalled')) { |
25
|
|
|
return; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
if ($this->inAdministration()) { |
29
|
|
|
$themeName = $this->app['config']->get('asgard.core.core.admin-theme'); |
30
|
|
|
|
31
|
|
|
return $this->app['stylist']->activate($themeName, true); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$themeName = $this->app['setting.settings']->get('core::template', null, 'Flatly'); |
35
|
|
|
|
36
|
|
|
return $this->app['stylist']->activate($themeName, true); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Check if we are in the administration |
41
|
|
|
* @return bool |
42
|
|
|
*/ |
43
|
|
|
private function inAdministration() |
44
|
|
|
{ |
45
|
|
|
$segment = config('laravellocalization.hideDefaultLocaleInURL', false) ? 1 : 2; |
46
|
|
|
|
47
|
|
|
return $this->app['request']->segment($segment) === $this->app['config']->get('asgard.core.core.admin-prefix'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Register all themes with activating them |
52
|
|
|
*/ |
53
|
|
|
private function registerAllThemes() |
54
|
|
|
{ |
55
|
|
|
$directories = $this->app['files']->directories(config('stylist.themes.paths', [base_path('/Themes')])[0]); |
56
|
|
|
|
57
|
|
|
foreach ($directories as $directory) { |
58
|
|
|
$this->app['stylist']->registerPath($directory); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|