-
Notifications
You must be signed in to change notification settings - Fork 1
/
Events.php
205 lines (191 loc) · 6.89 KB
/
Events.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php
namespace olan\websharetarget;
use humhub\modules\admin\permissions\ManageSettings;
use humhub\modules\ui\menu\MenuLink;
use Yii;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
/**
* Event class for Web Share Target Module
*/
class Events
{
/**
* Defines what to do if admin menu is initialized.
*
* @param $event
*/
public static function onAdminMenuInit($event)
{
$event->sender->addItem([
'label' => 'Edit Manifest',
'url' => Url::to(['/websharetarget/manifest']),
'group' => 'manage',
'icon' => '<i class="fa fa-share-alt"></i>',
'isActive' => MenuLink::isActiveState('websharetarget', 'manifest'),
'sortOrder' => 701,
]);
}
public static function onSettingsMenuInit($event)
{
$canEditSettings = Yii::$app->user->can(ManageSettings::class);
$event->sender->addEntry(new MenuLink([
'label' => "Manifest",
'url' => Url::to(['/websharetarget/manifest']),
'sortOrder' => 201,
'isActive' => MenuLink::isActiveState('websharetarget', 'manifest'),
'isVisible' => $canEditSettings
]));
}
/**
* Overwrite Manifest.json file.
*
* @param $event
* @return Json
*/
public static function onManifestControllerInit($event)
{
$theme_color = Yii::$app->view->theme->variable('primary');
$background_color = Yii::$app->view->theme->variable('background-color-main');
if (!empty($_COOKIE['dusk']) && $_COOKIE['dusk'] == 'yes') {
$theme_color = '#0d0f19';
$background_color = '#191e38';
} else if (!empty($_COOKIE['autumn']) && $_COOKIE['autumn'] == 'yes') {
$theme_color = '#B06502';
$background_color = '#DBBD6B';
} else if (!empty($_COOKIE['blossom']) && $_COOKIE['blossom'] == 'yes') {
$theme_color = '#FFCCCD';
$background_color = '#FCEDED';
} else if (!empty($_COOKIE['forest']) && $_COOKIE['forest'] == 'yes') {
$theme_color = '#495630';
$background_color = '#9EB865';
} else if (!empty($_COOKIE['marine']) && $_COOKIE['marine'] == 'yes') {
$theme_color = '#044147';
$background_color = '#DDEBF6';
} else if (!empty($_COOKIE['berry']) && $_COOKIE['berry'] == 'yes') {
$theme_color = '#3E3663';
$background_color = '#8F6DAB';
} else if (!empty($_COOKIE['amaranth']) && $_COOKIE['amaranth'] == 'yes') {
$theme_color = '#5C1120';
$background_color = '#BF5A6E';
}
// unset($event->sender->manifest['theme_color']);
// unset($event->sender->manifest['background_color']);
$shortcuts = [];
if(!Yii::$app->user->isGuest)
{
$shortcuts[] = [
'name' => 'My Profile',
'short_name' => 'My Profile',
'description' => 'Open My Profile page',
'url' => Yii::$app->user->identity->createUrl('/user/profile/home', ['source' => 'pwa'], true),
'icons' => [
'src' => Url::toRoute('/', true) . 'olan-net-chat-192.png',
'sizes' => '192x192'
]
];
}
// echo '<pre>';
// print_r($shortcuts);
// exit;
$manifest = [
'scope' => Url::to(['/'], true),
'description' => 'Sharing, collaborating and workflow service community for Olan members, supporters and groups',
'orientation' => 'portrait',
'dir' => 'ltr',
'lang' => Yii::$app->language,
'theme_color' => $theme_color,
'background_color' => $background_color,
'shortcuts' => ArrayHelper::merge($shortcuts, [
[
'name' => 'Messages',
'short_name' => 'Messages',
'description' => Yii::$app->name . ' messaging app',
'url' => Url::toRoute(['/mail/mail/index', ['source' => 'pwa']], true),
'icons' => [[
'src' => Url::toRoute('/', true) . 'olan-net-chat-192.png',
'sizes' => '192x192'
]]
],
[
'name' => 'Tasks',
'short_name' => 'Tasks',
'description' => 'Overview of my tasks',
'url' => Url::toRoute(['/tasks/global', ['source' => 'pwa']], true),
'icons' => [[
'src' => Url::toRoute('/', true) . 'olan-net-tasks-192.png',
'sizes' => '192x192'
]]
],
[
'name' => 'Calendar',
'short_name' => 'Calendar',
'description' => 'Overview calendar',
'url' => Url::toRoute(['/calendar/global', ['source' => 'pwa']],true),
'icons' => [[
'src' => Url::toRoute('/',true) . 'olan-net-calendar-192.png',
'sizes' => '192x192'
]]
]
]),
'screenshots' => [
[
'src' => Url::toRoute('/',true) . 'screenshot1.png',
'type' => 'image/png',
'sizes' => '360x800'
],
[
'src' => Url::toRoute('/',true) . 'screenshot2.png',
'type' => 'image/jpg',
'sizes' => '960x600'
]
],
'share_target' => [
'action' => Url::toRoute('/websharetarget/index',true),
'enctype' => 'multipart/form-data',
'method' => 'POST',
'params' => [
"title" => "name",
"text" => "description",
"url" => "link",
"message" => "message",
'files' => [
[
'name' => 'media[]',
'accept' => [
'audio/*',
'image/*',
'video/*',
'application/msword', // Doc files
'application/vnd.openxmlformats-officedocument.wordprocessingml.document', // Docx files
'application/vnd.ms-excel', // Xls files
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', // Xlsx files
'application/vnd.ms-powerpoint', // PPT files
'application/vnd.openxmlformats-officedocument.presentationml.presentation' // pptx files
]
]
]
]
],
'prefer_related_applications' => true,
'related_applications' => [
[
'platform' => 'play',
'url' => 'https://play.google.com/store/apps/details?id=net.olan.pwa',
'id' => 'net.olan.pwa',
],
[
'platform' => 'webapp',
'url' => Url::toRoute('/', true) . 'manifest.json',
],
[
"platform" => "Windows App Store",
"url" => "https://www.microsoft.com/store/apps/9P388QPP1RTB"
]
]
];
$manifest = ArrayHelper::merge($event->sender->manifest, $manifest);
// ksort($manifest);
return $event->sender->asJson($manifest);
}
}