forked from greyaz/ThemeRevision
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
executable file
·165 lines (140 loc) · 5.93 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
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
<?php
namespace Kanboard\Plugin\ThemeRevision;
use Kanboard\Core\Plugin\Base;
use Kanboard\Core\Translator;
use Kanboard\Plugin\ThemeRevision\Model\TaskInfoCSSModel;
class Plugin extends Base
{
public function initialize()
{
// register helper
$this->helper->register('configsDataHelper', '\Kanboard\Plugin\ThemeRevision\Helper\ConfigsDataHelper');
$this->helper->register('modeSwitchHelper', '\Kanboard\Plugin\ThemeRevision\Helper\ModeSwitchHelper');
$this->helper->register('colorSwitchHelper', '\Kanboard\Plugin\ThemeRevision\Helper\ColorSwitchHelper');
// add class "TR" to body
$this->template->setTemplateOverride('layout', 'ThemeRevision:layout');
// add logo to page
$this->template->setTemplateOverride('header/title', 'ThemeRevision:header/title');
$this->template->hook->attach('template:auth:login-form:before', 'ThemeRevision:auth/login_form_before');
// admin config UI
$this->route->addRoute('settings/themerevision', 'PluginConfigsController', 'show', 'ThemeRevision');
$this->template->hook->attach('template:config:sidebar', 'ThemeRevision:settings/sidebar');
// set CSP
$this->setContentSecurityPolicy(array('style-src' => '\'self\' \'unsafe-inline\' fonts.googleapis.com'));
// load configs
global $themeRevisionConfig;
$themeRevisionConfig = $this->loadConfigs();
// init color scheme
$this->initColorScheme($themeRevisionConfig['color_scheme']);
// mode switch
if (isset($themeRevisionConfig['mode']) && $themeRevisionConfig['mode'] == "development") {
$this->helper->modeSwitchHelper->developmentMode();
}
else {
$this->helper->modeSwitchHelper->productionMode();
}
// corner radius
if (!empty($themeRevisionConfig['corner_radius'])){
$this->template->hook->attach('template:layout:head', 'ThemeRevision:layout/head_corner_radius', array('radius' => $themeRevisionConfig['corner_radius']));
}
// icons replacement
if (!isset($themeRevisionConfig['enable_google_material_icons']) || $themeRevisionConfig['enable_google_material_icons']) {
$this->hook->on('template:layout:css', array('template' => 'plugins/ThemeRevision/Asset/material-symbols/index.min.css'));
}
// google fonts
if (isset($themeRevisionConfig['google_fonts'])){
$this->template->hook->attach('template:layout:head', 'ThemeRevision:layout/head_google_fonts', array('configs' => $themeRevisionConfig['google_fonts']));
}
// syntax highlight
$this->hook->on('template:layout:css', array('template' => 'plugins/ThemeRevision/Asset/highlight/style.min.css'));
$this->hook->on('template:layout:js', array('template' => 'plugins/ThemeRevision/Asset/highlight/highlight.min.js'));
// main js
$this->hook->on('template:layout:js', array('template' => 'plugins/ThemeRevision/Asset/main.min.js'));
}
public function onStartup(){
// load translations
Translator::load($this->languageModel->getCurrentLanguage(), __DIR__.'/Locale');
// enable custom task display (the css selectors depend on localized text)
$this->enableCustomTaskDisplay($GLOBALS['themeRevisionConfig']);
}
public function getPluginName() {
return 'ThemeRevision for Kanboard';
}
public function getPluginAuthor() {
return 'greyaz';
}
public function getPluginVersion() {
return '1.1.11';
}
public function getPluginDescription() {
return "A task-first and high quality theme for Kanboard. It's aimed at better mobile experiences, common plugins' compatibilities, and customization friendly.";
}
public function getPluginHomepage() {
return 'https://github.com/greyaz/ThemeRevision';
}
private function loadConfigs() {
$configs;
$defConfigs = $this->helper->configsDataHelper->getDefaultConfigs();
$dbConfigs = $this->helper->configsDataHelper->loadConfigs();
$oldConfigs = $this->helper->configsDataHelper->calcOldConfigs($dbConfigs);
//old user, need update
if (!empty($oldConfigs)){
// check color diffs
$colorDiffs = $this->helper->configsDataHelper->calcColorDiffs($oldConfigs);
if (!empty($colorDiffs)){
$this->helper->configsDataHelper->saveColorDiffs($colorDiffs);
}
// merged configs
$mergedConfigs = $this->helper->configsDataHelper->calcMergedConfigs($oldConfigs, $defConfigs);
// load and save configs
$configs = $mergedConfigs;
$this->helper->configsDataHelper->saveConfigs($configs);
}
//old user, need not update
elseif (!empty($dbConfigs)){
// load configs
$configs = $dbConfigs;
}
//new user
else {
// load and save configs
$configs = $defConfigs;
$this->helper->configsDataHelper->saveConfigs($configs);
}
return $configs;
}
private function initColorScheme($colorScheme) {
if (isset($colorScheme) && $colorScheme == "light") {
$this->helper->colorSwitchHelper->setColor2Light();
}
elseif (isset($colorScheme) && $colorScheme == "dark"){
$this->helper->colorSwitchHelper->setColor2Dark();
}
else {
// user config UI
$this->route->addRoute('user/:user_id/theme', 'UserSettingsController', 'show', 'ThemeRevision');
$this->template->hook->attach('template:user:sidebar:actions', 'ThemeRevision:user/sidebar');
$this->template->hook->attach('template:header:dropdown', 'ThemeRevision:user/header_dropdown');
$this->helper->colorSwitchHelper->setColorByUser();
}
}
private function enableCustomTaskDisplay($config){
// adjust column and task info
$columnList = array();
$taskList = array();
foreach($config['column_header_info'] as $key => $value){
if ($value == false){
$columnList[] = $key;
}
}
foreach($config['board_task_info'] as $key => $value){
if ($value == false){
$taskList[] = $key;
}
}
$this->template->hook->attach('template:layout:head', 'ThemeRevision:layout/head_task_info_display', array(
'styles' => TaskInfoCSSModel::getFullCSS($columnList, $taskList),
'opacity' => $config['task_footer_opacity']
));
}
}