-
Notifications
You must be signed in to change notification settings - Fork 1
/
Plugin.php
115 lines (101 loc) · 2.78 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
namespace Zaxbux\IubendaPolicy;
use System\Classes\PluginBase;
use Zaxbux\IubendaPolicy\Models\Settings;
use Zaxbux\IubendaPolicy\Classes\PolicyCache;
/**
* Plugin class for Iubenda Policy
* @author zaxbux
*/
class Plugin extends PluginBase {
/**
* @{inheritDoc}
*/
public function pluginDetails() {
return [
'name' => 'zaxbux.iubendapolicy::lang.plugin.name',
'description' => 'zaxbux.iubendapolicy::lang.plugin.description',
'author' => 'Zachary Schneider ',
'icon' => 'icon-shield',
'homepage' => 'https://www.zacharyschneider.ca/'
];
}
/**
* @{inheritDoc}
*/
public function registerComponents() {
return [
'Zaxbux\IubendaPolicy\Components\IubendaPrivacyPolicy' => 'iubendaPrivacyPolicy',
'Zaxbux\IubendaPolicy\Components\IubendaCookiePolicy' => 'iubendaCookiePolicy',
'Zaxbux\IubendaPolicy\Components\IubendaCookieSolution' => 'iubendaCookieSolution',
];
}
/**
* Register static page snippets
*/
public function registerPageSnippets() {
return $this->registerComponents();
}
/**
* @{inheritDoc}
*/
public function registerPermissions() {
return [
'zaxbux.iubendapolicy.access_settings' => [
'tab' => 'zaxbux.iubendapolicy::lang.permissions.tab',
'label' => 'zaxbux.iubendapolicy::lang.permissions.label'
]
];
}
/**
* @{inheritDoc}
*/
public function registerSettings() {
return [
'config' => [
'label' => 'Iubenda Policy',
'icon' => 'icon-shield',
'description' => 'Manage your Iubenda policy configuration.',
'class' => 'Zaxbux\IubendaPolicy\Models\Settings',
'order' => '600',
'permissions' => ['zaxbux.iubendapolicy.access_settings'],
]
];
}
/**
* @{inheritDoc}
*/
public function registerSchedule($schedule) {
// Download and cache the policy on a daily basis
$schedule->call(function() {
$cache = new PolicyCache();
$cache->update();
})->daily();
}
/**
* @{inheritDoc}
*/
public function register() {
$this->registerConsoleCommand('zaxbux.iubendapolicy.update', 'Zaxbux\\IubendaPolicy\\Console\\Update');
$this->registerConsoleCommand('zaxbux.iubendapolicy.forget', 'Zaxbux\\IubendaPolicy\\Console\\Forget');
}
/**
* @{inheritDoc}
*/
public function boot() {
// Include Guzzle
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ . '/vendor/guzzlehttp/guzzle/src');
// Clear the policy cache when settings are saved
// This takes care of policy ID changes, and allows the policy cache to be cleared on demand
Settings::extend(function($model) {
$model->bindEvent('model.beforeSave', function () {
$cache = new PolicyCache();
$cache->forget();
});
$model->bindEvent('model.afterSave', function () {
$cache = new PolicyCache();
$cache->update();
});
});
}
}