-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
74 lines (67 loc) · 2.73 KB
/
Plugin.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
<?php namespace KosmosKosmos\EssentialVars;
use App;
use Lang;
use View;
use Event;
use Cache;
use Config;
use Cms\Classes\Theme;
use System\Classes\PluginBase;
use Backend\Models\BrandSetting;
class Plugin extends PluginBase {
public function pluginDetails() {
return [
'name' => 'EssentialVars',
'description' => 'Adds the app_[url|logo|favicon|name|debug|description] and theme variables to Mail & CMS templates',
'author' => 'KosmosKosmos',
'icon' => 'icon-code',
];
}
public function boot() {
$themePath = themes_path(Theme::getActiveThemeCode().'/lang');
if (is_dir($themePath)) {
Lang::addNamespace('theme', $themePath);
}
App::before(function () {
Event::listen('mailer.beforeAddContent', function () {
$appVars = $this->getAppVars();
foreach ($appVars as $key => $appVar) {
View::share($key, $appVar);
}
});
Event::listen('cms.page.beforeDisplay', function ($controller, $url, $page) {
$appVars = $this->getAppVars();
foreach ($appVars as $key => $appVar) {
$controller->vars[$key] = $appVar;
}
});
});
}
public function getAppVars() {
return Cache::remember('essentialvars', now()->addMinutes(1), function() {
$vars = [
'app_url' => url('/'),
'app_logo' => BrandSetting::getLogo() ?? url('/modules/backend/assets/images/october-logo.svg'),
'app_favicon' => BrandSetting::getFavicon() ?? url('/modules/backend/assets/images/favicon.png'),
'app_name' => BrandSetting::get('app_name'),
'app_debug' => Config::get('app.debug', false),
'app_description' => BrandSetting::get('app_tagline'),
'hasCookieGroups' => false
];
if (class_exists('\OFFLINE\GDPR\Models\CookieGroup')) {
$vars['hasCookieGroups'] = \OFFLINE\GDPR\Models\CookieGroup::with('cookies')
->orderBy('sort_order', 'ASC')
->count() > 0;
}
if ($activeTheme = \Cms\Classes\Theme::getActiveTheme()) {
$notInclude = ['theme' => 1, 'id' => 1, 'data' => 1, 'created_at' => 1, 'updated_at' => 1];
$themeVars = array_diff_key($activeTheme->getCustomData()->attributes, $notInclude);
foreach ($themeVars as $key => $value) {
$vars['theme_' . $key] = $value;
}
}
$vars['available_vars'] = $vars;
return $vars;
});
}
}