]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - plugins/default_colors/default_colors.php
WIP - Plugin to override default template colors
[github/shaarli/Shaarli.git] / plugins / default_colors / default_colors.php
1 <?php
2
3 /**
4 * Plugin default_colors.
5 *
6 * Allow users to easily overrides colors of the default theme.
7 */
8
9 use Shaarli\Plugin\PluginManager;
10
11 const DEFAULT_COLORS_PLACEHOLDERS = [
12 'DEFAULT_COLORS_MAIN',
13 'DEFAULT_COLORS_BACKGROUND',
14 'DEFAULT_COLORS_DARK_MAIN',
15 ];
16
17 /**
18 * When plugin parameters are saved
19 */
20 function hook_default_colors_save_plugin_parameters($data)
21 {
22 $file = PluginManager::$PLUGINS_PATH . '/default_colors/default_colors.css';
23 $template = file_get_contents(PluginManager::$PLUGINS_PATH . '/default_colors/default_colors.css.template');
24 $content = '';
25 foreach (DEFAULT_COLORS_PLACEHOLDERS as $rule) {
26 $content .= ! empty($data[$rule])
27 ? default_colors_format_css_rule($data, $rule) .';'. PHP_EOL
28 : '';
29 }
30 file_put_contents($file, sprintf($template, $content));
31 return $data;
32 }
33
34 /**
35 * When linklist is displayed, include isso CSS file.
36 *
37 * @param array $data - header data.
38 *
39 * @return mixed - header data with isso CSS file added.
40 */
41 function hook_default_colors_render_includes($data)
42 {
43 $file = PluginManager::$PLUGINS_PATH . '/default_colors/default_colors.css';
44 if (file_exists($file )) {
45 $data['css_files'][] = $file ;
46 }
47
48 return $data;
49 }
50
51 /**
52 * This function is never called, but contains translation calls for GNU gettext extraction.
53 */
54 function default_colors_translation()
55 {
56 // meta
57 t('Override default theme colors. Use any CSS valid color.');
58 t('Main color (navbar green)');
59 t('Background color (light grey)');
60 t('Dark main color (e.g. visited links)');
61 }
62
63 function default_colors_format_css_rule($data, $parameter)
64 {
65 $key = str_replace('DEFAULT_COLORS_', '', $parameter);
66 $key = str_replace('_', '-', strtolower($key)) .'-color';
67 return ' --'. $key .': '. $data[$parameter];
68 }