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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
|
<?php
namespace Kanboard\Plugin\Customizer\Controller;
require_once __DIR__.'/../vendor/autoload.php';
use Kanboard\Model\ConfigModel;
use Kanboard\Model\LanguageModel;
use Kanboard\Controller\BaseController;
use luizbills\CSS_Generator\Generator as CSS_Generator;
/**
* Config Controller
*
* @package Customizer/Controller
* @author creecros
*/
class CustomizerConfigController extends BaseController
{
/**
* Save settings
*
*/
public function save()
{
if (isset($_POST['remove'])) {
$values = $this->request->getValues();
$this->remove($values['themeSelection']);
} else {
$values = $this->request->getValues();
if (array_key_exists('use_custom_login', $values) === false) { $this->configModel->save(['use_custom_login' => '']); }
if (array_key_exists('enable_cache', $values) === false) { $this->configModel->save(['enable_cache' => '']); }
if ($this->configModel->save($values)) {
$this->languageModel->loadCurrentLanguage();
$this->flash->success(t('Settings saved successfully.'));
} else {
$this->flash->failure(t('Unable to save your settings.'));
}
$this->response->redirect($this->helper->url->to('CustomizerFileController', 'show', array('plugin' => 'Customizer')));
}
}
/**
* Save user theme
*
*/
public function usertheme()
{
$user = $this->getUser();
$values = $this->request->getValues();
if ($this->userMetadataModel->save($user['id'], $values)) {
$this->languageModel->loadCurrentLanguage();
$this->flash->success(t('Settings saved successfully.'));
} else {
$this->flash->failure(t('Unable to save your settings.'));
}
$this->response->redirect($this->helper->url->to('UserViewController', 'show', array('user_id' => $user['id'])), true);
}
/**
* Reset all User themes
*
*/
public function resetUserThemes()
{
$users = $this->userModel->getAll();
foreach ($users as $user) {
$this->userMetadataModel->remove($user['id'], 'themeSelection');
}
$this->response->redirect($this->helper->url->to('CustomizerFileController', 'show', array('plugin' => 'Customizer')));
}
/**
* Toggle User themes
*
*/
public function enableDisableThemes()
{
$status = $this->configModel->get('toggle_user_themes', 'disable');
if ($status == 'disable') { $this->configModel->save(['toggle_user_themes' => 'enable']); } else { $this->configModel->save(['toggle_user_themes' => 'disable']); }
$this->response->redirect($this->helper->url->to('CustomizerFileController', 'show', array('plugin' => 'Customizer')));
}
/**
* Upload css theme
*
*/
public function uploadcss()
{
$target_dir = DATA_DIR . '/files/customizer/themes/';
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if file already exists
if (file_exists($target_file)) {
$this->flash->failure(t('Sorry, file already exists.'));
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 1000000) {
$this->flash->failure(t('Sorry, your file is too large.'));
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "css") {
$this->flash->failure(t('Sorry, only CSS files are allowed.'));
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
$this->flash->failure(t('Sorry, your file was not uploaded.'));
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
$this->flash->success(t('Theme file uploaded successfully.'));
} else {
$this->flash->failure(t('Sorry, there was an error uploading your file.'));
}
}
$this->response->redirect($this->helper->url->to('CustomizerFileController', 'show', array('plugin' => 'Customizer')));
}
public function remove($file)
{
$filename = basename($file);
if (file_exists(DATA_DIR . '/files/customizer/themes/' . $filename)) { unlink(DATA_DIR . '/files/customizer/themes/' . $filename); }
unlink($file);
$this->response->redirect($this->helper->url->to('CustomizerFileController', 'show', array('plugin' => 'Customizer')));
}
public function create_theme()
{
$values = $this->request->getValues();
$options = [
// default values
// 'indentation' => ' ', // 4 spaces
];
$css = new CSS_Generator($options);
// Header
$css->add_rule('header',
[
'background-color' => $values['header_background'],
'background-image' => 'linear-gradient(-180deg, transparent 0%, '.$values['header_shade'].' 90%)'
]
);
$css->add_rule(['header h1', 'header a .fa'],
[
'color' => $values['header_title']
]
);
$css->add_rule('a i.web-notification-icon',
[
'color' => $values['notification_icon']
]
);
// Body
$css->add_rule('body',
[
'background' => $values['background_color'],
'color' => $values['font_main']
]
);
$css->add_rule(['ul.dropdown-submenu-open', '.accordion-title h3'],
[
'background-color' => $values['background_color']
]
);
$css->add_rule('.dropdown-submenu-open a',
[
'color' => $values['font_main']
]
);
$css->add_rule('a:hover',
[
'color' => $values['font_main']
]
);
$css->add_rule('a .fa',
[
'color' => $values['font_main']
]
);
$css->add_rule(['h1', 'h2', 'h3', '.accordion-toggle'],
[
'color' => $values['font_main']
]
);
$css->add_rule('.table-list-header a',
[
'color' => $values['font_main']
]
);
$css->add_rule('.table-list-header .table-list-header-count',
[
'color' => $values['font_main']
]
);
$css->add_rule('.table-list-row .table-list-title a',
[
'color' => $values['font_main']
]
);
$css->add_rule('.table-list-row .table-list-details strong',
[
'color' => $values['font_main']
]
);
$css->add_rule('.dropdown-menu-link-icon',
[
'color' => $values['font_main']
]
);
$css->add_rule('.page-header h2 a',
[
'color' => $values['font_main']
]
);
$css->add_rule('.sidebar>ul a:hover',
[
'color' => $values['font_main']
]
);
$css->add_rule('.sidebar>ul li.active a',
[
'color' => $values['font_main']
]
);
$css->add_rule('.task-list-icons a:hover',
[
'color' => $values['font_main']
]
);
$css->add_rule('.task-list-icons a:hover i',
[
'color' => $values['font_main']
]
);
$css->add_rule('.subtask-cell a',
[
'color' => $values['font_main']
]
);
$css->add_rule('a',
[
'color' => $values['font_link']
]
);
$css->add_rule('.table-list-category a:hover',
[
'color' => $values['font_link']
]
);
$css->add_rule(['.subtask-cell a:hover', '.subtask-cell a:focus'],
[
'color' => $values['font_link']
]
);
$css->add_rule(['a:focus', 'a:hover'],
[
'color' => $values['font_link_focus']
]
);
$css->add_rule(['.table-list-header a:hover', '.table-list-header a:focus', '.task-board a'],
[
'color' => $values['font_secondary']
]
);
$css->add_rule('.table-list-row .table-list-details',
[
'color' => $values['font_secondary']
]
);
$css->add_rule('.input-addon-field',
[
'color' => $values['font_secondary']
]
);
$css->add_rule(['.page-header h2 a:focus', '.page-header h2 a:hover', 'code'],
[
'color' => $values['font_secondary']
]
);
$css->add_rule('.sidebar>ul a',
[
'color' => $values['font_secondary']
]
);
$css->add_rule('.task-list-avatars .task-avatar-assignee',
[
'color' => $values['font_secondary']
]
);
$css->add_rule(['.task-list-icons a', '.task-list-icons span', '.task-list-icons i', '.task-date'],
[
'color' => $values['font_secondary']
]
);
$css->add_rule('span.task-date-overdue',
[
'color' => $values['font_overdue']
]
);
$css->add_rule('.sidebar>ul li.active',
[
'border-left' => '5px solid '.$values['font_main']
]
);
$css->add_rule(['.sidebar>ul li.active a:focus', '.sidebar>ul li.active a:hover'],
[
'color' => $values['font_secondary']
]
);
$css->add_rule('.sidebar>ul li:hover',
[
'border-left' => '5px solid '.$values['font_secondary']
]
);
$css->add_rule('.panel',
[
'color' => $values['font_main']
]
);
$css->add_rule(['td a.dropdown-menu strong', 'td a.dropdown-menu strong i'],
[
'color' => $values['font_main']
]
);
$css->add_raw('
#task-summary h2 {color: unset;}
.comments .comment:hover {background: #efefef40;}
.comments .comment:nth-child(even):not(.comment-highlighted):hover {background: #efefef40;}
.comments .comment:nth-child(even):not(.comment-highlighted) {background: #efefef40;}
table.table-striped tr:nth-child(odd) {background: #efefef40;}
header {box-shadow: 0px -1px 5px 1px;border-bottom: none;}
.project-header {margin-bottom: 8px;margin-top: 8px;}
.panel{background-color: #efefef40;border: 1px solid #efefef40;}
.task-board{border-width: 2px;background: #efefef22!important;}
div.task-board-recent {border-width: 2px;}
table td {border:none;}
table th:first-child {border-top-left-radius:8px;}
table th:last-child {border-top-right-radius:8px;}
.table-list-header{background:#efefef40;border:1px solid #efefef40;border-radius:5px 5px 0 0;line-height:28px;padding-left:3px;padding-right:3px;}
.table-list-row{padding-left:3px;padding-right:3px;border-bottom:1px solid #efefef40;border-right:1px solid #efefef40;}
.table-list-row.table-border-left{border-left:1px solid #efefef40;}
.table-list-row:nth-child(odd){background:#efefef30;}
.table-list-row:hover{background:#efefef32;border-bottom:1px solid #efefef32;border-right:1px solid #efefef32;}
.dropdown-menu-link-icon{text-decoration:none;}
.dropdown-submenu-open li{border-bottom:1px solid #efefef40;}
.page-header h2{margin:0;padding:0;font-weight:bold;border-bottom:1px dotted #efefef40;}
.sidebar>ul li{list-style-type:none;line-height:35px;border-bottom:1px dotted #efefef40;padding-left:13px;}
span.task-icon-age-total{border:1px solid #efefef40;padding:1px 3px 1px 3px;border-top-left-radius:3px;border-bottom-left-radius:3px;}
span.task-icon-age-column{border:1px solid #efefef40;border-left:none;margin-left:-5px;padding:1px 3px 1px 3px;border-top-right-radius:3px;border-bottom-right-radius:3px;}
.subtask-cell{padding:4px 10px;border-top:1px dotted #efefef42;border-left:1px dotted #efefef40;display:table-cell;vertical-align:middle;}
table th {text-align: left;padding: 0.5em 3px;border:none;background: #efefef40;}
.views li {white-space: nowrap;background: #efefef40;border:none;border-right: none;padding: 4px 8px;display: inline;}
');
$minify = true;
$extension = '.css';
$rename = str_replace('.', '', $values['theme_name']);
if (file_exists(DATA_DIR . '/files/customizer/themes')) {
file_put_contents(DATA_DIR . '/files/customizer/themes/' . $rename . $extension, $css->get_output($minify));
} else {
mkdir(DATA_DIR . '/files/customizer/themes', 0755);
file_put_contents(DATA_DIR . '/files/customizer/themes/' . $rename . $extension, $css->get_output($minify));
}
$this->response->redirect($this->helper->url->to('CustomizerFileController', 'show', array('plugin' => 'Customizer')));
}
}
|