aboutsummaryrefslogtreecommitdiffhomepage
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/default_colors/default_colors.css.template3
-rw-r--r--plugins/default_colors/default_colors.meta5
-rw-r--r--plugins/default_colors/default_colors.php68
3 files changed, 76 insertions, 0 deletions
diff --git a/plugins/default_colors/default_colors.css.template b/plugins/default_colors/default_colors.css.template
new file mode 100644
index 00000000..4b269baf
--- /dev/null
+++ b/plugins/default_colors/default_colors.css.template
@@ -0,0 +1,3 @@
1:root {
2 %s
3}
diff --git a/plugins/default_colors/default_colors.meta b/plugins/default_colors/default_colors.meta
new file mode 100644
index 00000000..108962c6
--- /dev/null
+++ b/plugins/default_colors/default_colors.meta
@@ -0,0 +1,5 @@
1description="Override default theme colors. Use any CSS valid color."
2parameters="DEFAULT_COLORS_MAIN;DEFAULT_COLORS_BACKGROUND;DEFAULT_COLORS_DARK_MAIN"
3parameter.DEFAULT_COLORS_MAIN="Main color (navbar green)"
4parameter.DEFAULT_COLORS_BACKGROUND="Background color (light grey)"
5parameter.DEFAULT_COLORS_DARK_MAIN="Dark main color (e.g. visited links)"
diff --git a/plugins/default_colors/default_colors.php b/plugins/default_colors/default_colors.php
new file mode 100644
index 00000000..b898814b
--- /dev/null
+++ b/plugins/default_colors/default_colors.php
@@ -0,0 +1,68 @@
1<?php
2
3/**
4 * Plugin default_colors.
5 *
6 * Allow users to easily overrides colors of the default theme.
7 */
8
9use Shaarli\Plugin\PluginManager;
10
11const 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 */
20function 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 */
41function 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 */
54function 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
63function 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}