Rev 819 | Rev 926 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
635 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
819 | daniel-mar | 5 | * Copyright 2019 - 2022 Daniel Marschall, ViaThinkSoft |
635 | daniel-mar | 6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
8 | * you may not use this file except in compliance with the License. |
||
9 | * You may obtain a copy of the License at |
||
10 | * |
||
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
12 | * |
||
13 | * Unless required by applicable law or agreed to in writing, software |
||
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
16 | * See the License for the specific language governing permissions and |
||
17 | * limitations under the License. |
||
18 | */ |
||
19 | |||
20 | if (!defined('INSIDE_OIDPLUS')) die(); |
||
21 | |||
22 | class OIDplusPageAdminColors extends OIDplusPagePluginAdmin { |
||
23 | |||
819 | daniel-mar | 24 | public function htmlHeaderUpdate(&$head_elems) { |
25 | foreach ($head_elems as &$line) { |
||
26 | if (strpos($line,'oidplus.min.css.php') !== false) { |
||
27 | $add_css_args = array(); |
||
28 | $add_css_args[] = 'theme='.urlencode(OIDplus::config()->getValue('design','default')); |
||
29 | $add_css_args[] = 'invert='.urlencode(OIDplus::config()->getValue('color_invert',0)); |
||
30 | $add_css_args[] = 'h_shift='.urlencode(number_format(OIDplus::config()->getValue('color_hue_shift',0)/360,5,'.','')); |
||
31 | $add_css_args[] = 's_shift='.urlencode(number_format(OIDplus::config()->getValue('color_sat_shift',0)/100,5,'.','')); |
||
32 | $add_css_args[] = 'v_shift='.urlencode(number_format(OIDplus::config()->getValue('color_val_shift',0)/100,5,'.','')); |
||
820 | daniel-mar | 33 | if (count($add_css_args) > 0) { |
34 | $line = str_replace('oidplus.min.css.php?', 'oidplus.min.css.php&', $line); |
||
35 | $line = str_replace('oidplus.min.css.php', 'oidplus.min.css.php?'.htmlentities(implode('&',$add_css_args)), $line); |
||
36 | } |
||
819 | daniel-mar | 37 | } |
38 | |||
820 | daniel-mar | 39 | if ((stripos($line,'<meta') !== false) && (stripos($line,'name="theme-color"') !== false)) { |
819 | daniel-mar | 40 | if (preg_match('@content="(.+)"@ismU', $line, $m)) { |
41 | $theme_color = $m[1]; |
||
42 | $hs = OIDplus::config()->getValue('color_hue_shift',0)/360; |
||
43 | $ss = OIDplus::config()->getValue('color_sat_shift',0)/100; |
||
44 | $vs = OIDplus::config()->getValue('color_val_shift',0)/100; |
||
45 | $theme_color = changeHueOfCSS($theme_color, $hs, $ss, $vs); // "changeHueOfCSS" can also change a single color value if it has the form #xxyyzz or #xyz |
||
46 | if (OIDplus::config()->getValue('color_invert',0)) { |
||
47 | $theme_color = invertColorsOfCSS($theme_color); |
||
48 | } |
||
49 | $line = preg_replace('@content="(.+)"@ismU', 'content="'.$theme_color.'"', $line); |
||
50 | |||
51 | } |
||
52 | } |
||
53 | } |
||
54 | } |
||
55 | |||
635 | daniel-mar | 56 | public function action($actionID, $params) { |
57 | if ($actionID == 'color_update') { |
||
58 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
||
59 | throw new OIDplusException(_L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin'))); |
||
60 | } |
||
61 | |||
717 | daniel-mar | 62 | _CheckParamExists($params, 'hue_shift'); |
63 | _CheckParamExists($params, 'sat_shift'); |
||
64 | _CheckParamExists($params, 'val_shift'); |
||
65 | _CheckParamExists($params, 'invcolors'); |
||
66 | _CheckParamExists($params, 'theme'); |
||
635 | daniel-mar | 67 | |
68 | OIDplus::config()->setValue('color_hue_shift', $params['hue_shift']); |
||
69 | OIDplus::config()->setValue('color_sat_shift', $params['sat_shift']); |
||
70 | OIDplus::config()->setValue('color_val_shift', $params['val_shift']); |
||
71 | OIDplus::config()->setValue('color_invert', $params['invcolors']); |
||
72 | OIDplus::config()->setValue('design', $params['theme']); |
||
73 | |||
74 | OIDplus::logger()->log("[OK]A?", "Changed system color theme"); |
||
75 | |||
76 | return array("status" => 0); |
||
77 | } else { |
||
78 | throw new OIDplusException(_L('Unknown action ID')); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | public function init($html=true) { |
||
83 | OIDplus::config()->prepareConfigKey('color_hue_shift', 'HSV Hue shift of CSS colors (-360..360)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
||
84 | if (!is_numeric($value) || ($value < -360) || ($value > 360)) { |
||
85 | throw new OIDplusException(_L('Please enter a valid value.')); |
||
86 | } |
||
87 | }); |
||
88 | OIDplus::config()->prepareConfigKey('color_sat_shift', 'HSV Saturation shift of CSS colors (-100..100)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
||
89 | if (!is_numeric($value) || ($value < -100) || ($value > 100)) { |
||
90 | throw new OIDplusException(_L('Please enter a valid value.')); |
||
91 | } |
||
92 | }); |
||
93 | OIDplus::config()->prepareConfigKey('color_val_shift', 'HSV Value shift of CSS colors (-100..100)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
||
94 | if (!is_numeric($value) || ($value < -100) || ($value > 100)) { |
||
95 | throw new OIDplusException(_L('Please enter a valid value.')); |
||
96 | } |
||
97 | }); |
||
98 | OIDplus::config()->prepareConfigKey('color_invert', 'Invert colors? (0=no, 1=yes)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
||
99 | if (!is_numeric($value) || ($value < 0) || ($value > 1)) { |
||
100 | throw new OIDplusException(_L('Please enter a valid value (0=no, 1=yes).')); |
||
101 | } |
||
102 | }); |
||
103 | OIDplus::config()->prepareConfigKey('design', 'Which design to use (must exist in plugins/[vendorname]/design/)?', 'default', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
||
104 | $good = true; |
||
105 | if (strpos($value,'/') !== false) $good = false; |
||
106 | if (strpos($value,'\\') !== false) $good = false; |
||
107 | if (strpos($value,'..') !== false) $good = false; |
||
108 | if (!$good) { |
||
109 | throw new OIDplusException(_L('Invalid design folder name. Do only enter a folder name, not an absolute or relative path')); |
||
110 | } |
||
111 | |||
112 | if (!rec_is_dir(OIDplus::localpath().'plugins/'.'*'.'/design/'.$value)) { |
||
113 | throw new OIDplusException(_L('The design "%1" does not exist in plugin directory %2',$value,'plugins/[vendorname]/design/')); |
||
114 | } |
||
115 | }); |
||
116 | OIDplus::config()->prepareConfigKey('oobe_colors_done', '"Out Of Box Experience" wizard for OIDplusPageAdminColors done once?', '0', OIDplusConfig::PROTECTION_HIDDEN, function($value) {}); |
||
117 | } |
||
118 | |||
119 | public function gui($id, &$out, &$handled) { |
||
120 | if ($id === 'oidplus:colors') { |
||
121 | $handled = true; |
||
122 | $out['title'] = _L('Design'); |
||
801 | daniel-mar | 123 | $out['icon'] = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png'; |
635 | daniel-mar | 124 | |
125 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
||
800 | daniel-mar | 126 | $out['icon'] = 'img/error.png'; |
635 | daniel-mar | 127 | $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>'; |
128 | return; |
||
129 | } |
||
130 | |||
131 | $out['text'] = '<br><p>'; |
||
132 | $out['text'] .= ' <label for="theme">'._L('Design').':</label>'; |
||
133 | $out['text'] .= ' <select name="theme" id="theme">'; |
||
134 | foreach (OIDplus::getDesignPlugins() as $plugin) { |
||
135 | $folder = basename($plugin->getPluginDirectory()); |
||
136 | $selected = $folder == OIDplus::config()->getValue('design') ? ' selected="true"' : ''; |
||
137 | $out['text'] .= '<option value="'.htmlentities($folder).'"'.$selected.'>'.htmlentities($plugin->getManifest()->getName()).'</option>'; |
||
138 | } |
||
139 | $out['text'] .= ' </select>'; |
||
140 | $out['text'] .= '</p>'; |
||
141 | |||
142 | $out['text'] .= '<br><p>'; |
||
143 | $out['text'] .= ' <label for="amount">'._L('Hue shift').':</label>'; |
||
144 | $out['text'] .= ' <input type="text" id="hshift" readonly style="border:0; background:transparent; font-weight:bold;">'; |
||
145 | $out['text'] .= '</p>'; |
||
146 | $out['text'] .= '<div id="slider-hshift"></div>'; |
||
147 | |||
148 | $out['text'] .= '<br><p>'; |
||
149 | $out['text'] .= ' <label for="amount">'._L('Saturation shift').':</label>'; |
||
150 | $out['text'] .= ' <input type="text" id="sshift" readonly style="border:0; background:transparent; font-weight:bold;">'; |
||
151 | $out['text'] .= '</p>'; |
||
152 | $out['text'] .= '<div id="slider-sshift"></div>'; |
||
153 | |||
154 | $out['text'] .= '<br><p>'; |
||
155 | $out['text'] .= ' <label for="amount">'._L('Value shift').':</label>'; |
||
156 | $out['text'] .= ' <input type="text" id="vshift" readonly style="border:0; background:transparent; font-weight:bold;">'; |
||
157 | $out['text'] .= '</p>'; |
||
158 | $out['text'] .= '<div id="slider-vshift"></div>'; |
||
159 | |||
160 | $out['text'] .= '<br><p>'; |
||
161 | $out['text'] .= ' <label for="amount">'._L('Invert colors').':</label>'; |
||
162 | $out['text'] .= ' <input type="text" id="icolor" readonly style="border:0; background:transparent; font-weight:bold;">'; // TODO: It would be good if that was a checkbox |
||
163 | $out['text'] .= '</p>'; |
||
164 | $out['text'] .= '<div id="slider-icolor"></div>'; |
||
165 | |||
166 | $out['text'] .= '<script>'; |
||
167 | $out['text'] .= 'if (OIDplusPageAdminColors.hue_shift == null) OIDplusPageAdminColors.hue_shift = OIDplusPageAdminColors.hue_shift_saved = '.OIDplus::config()->getValue('color_hue_shift').";\n"; |
||
168 | $out['text'] .= 'if (OIDplusPageAdminColors.sat_shift == null) OIDplusPageAdminColors.sat_shift = OIDplusPageAdminColors.sat_shift_saved = '.OIDplus::config()->getValue('color_sat_shift').";\n"; |
||
169 | $out['text'] .= 'if (OIDplusPageAdminColors.val_shift == null) OIDplusPageAdminColors.val_shift = OIDplusPageAdminColors.val_shift_saved = '.OIDplus::config()->getValue('color_val_shift').";\n"; |
||
170 | $out['text'] .= 'if (OIDplusPageAdminColors.invcolors == null) OIDplusPageAdminColors.invcolors = OIDplusPageAdminColors.invcolors_saved = '.OIDplus::config()->getValue('color_invert').";\n"; |
||
171 | $out['text'] .= 'if (OIDplusPageAdminColors.activetheme == null) OIDplusPageAdminColors.activetheme_saved = '.js_escape(OIDplus::config()->getValue('design')).";\n"; |
||
172 | $out['text'] .= 'OIDplusPageAdminColors.setup_color_sliders();'; |
||
173 | $out['text'] .= '</script>'; |
||
174 | |||
175 | $out['text'] .= '<br>'; |
||
176 | $out['text'] .= '<input type="button" onclick="OIDplusPageAdminColors.color_reset_sliders_cfg()" value="'._L('Reset to last saved config').'">'.str_repeat(' ',5); |
||
177 | $out['text'] .= '<input type="button" onclick="OIDplusPageAdminColors.color_reset_sliders_factory()" value="'._L('Reset default setting').'">'.str_repeat(' ',5); |
||
178 | $out['text'] .= '<input type="button" onclick="OIDplusPageAdminColors.test_color_theme()" value="'._L('Test').'">'.str_repeat(' ',5); |
||
179 | $out['text'] .= '<input type="button" onclick="OIDplusPageAdminColors.crudActionColorUpdate()" value="'._L('Set permanently').'">'; |
||
180 | } |
||
181 | } |
||
182 | |||
183 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
||
184 | if (!OIDplus::authUtils()->isAdminLoggedIn()) return false; |
||
185 | |||
800 | daniel-mar | 186 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
801 | daniel-mar | 187 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
635 | daniel-mar | 188 | } else { |
189 | $tree_icon = null; // default icon (folder) |
||
190 | } |
||
191 | |||
192 | $json[] = array( |
||
193 | 'id' => 'oidplus:colors', |
||
194 | 'icon' => $tree_icon, |
||
195 | 'text' => _L('Design') |
||
196 | ); |
||
197 | |||
198 | return true; |
||
199 | } |
||
200 | |||
201 | public function tree_search($request) { |
||
202 | return false; |
||
203 | } |
||
204 | |||
205 | public function implementsFeature($id) { |
||
206 | if (strtolower($id) == '1.3.6.1.4.1.37476.2.5.2.3.1') return true; // oobeEntry, oobeRequested |
||
207 | return false; |
||
208 | } |
||
209 | |||
210 | public function oobeRequested(): bool { |
||
211 | // Interface 1.3.6.1.4.1.37476.2.5.2.3.1 |
||
212 | |||
213 | return OIDplus::config()->getValue('oobe_colors_done') == '0'; |
||
214 | } |
||
215 | |||
216 | public function oobeEntry($step, $do_edits, &$errors_happened)/*: void*/ { |
||
217 | // Interface 1.3.6.1.4.1.37476.2.5.2.3.1 |
||
218 | |||
219 | echo '<p><u>'._L('Step %1: Color Theme',$step).'</u></p>'; |
||
220 | |||
221 | echo '<input type="checkbox" name="color_invert" id="color_invert"'; |
||
222 | if (isset($_REQUEST['sent'])) { |
||
223 | if ($set_value = isset($_REQUEST['color_invert'])) { |
||
224 | echo ' checked'; |
||
225 | } |
||
226 | } else { |
||
227 | if ($set_value = (OIDplus::config()->getValue('color_invert') == 1)) { |
||
228 | echo ' checked'; |
||
229 | } |
||
230 | } |
||
231 | echo '> <label for="color_invert">'._L('Dark Theme (inverted colors)').'</label><br>'; |
||
232 | |||
233 | $msg = ''; |
||
234 | if ($do_edits) { |
||
235 | try { |
||
236 | OIDplus::config()->setValue('color_invert', $set_value ? 1 : 0); |
||
237 | OIDplus::config()->setValue('oobe_colors_done', '1'); |
||
238 | } catch (Exception $e) { |
||
239 | $msg = $e->getMessage(); |
||
240 | $errors_happened = true; |
||
241 | } |
||
242 | } |
||
243 | |||
244 | echo ' <font color="red"><b>'.$msg.'</b></font>'; |
||
245 | } |
||
246 | |||
247 | } |