aboutsummaryrefslogtreecommitdiffhomepage
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/default_colors/default_colors.css.template2
-rw-r--r--plugins/default_colors/default_colors.php65
2 files changed, 55 insertions, 12 deletions
diff --git a/plugins/default_colors/default_colors.css.template b/plugins/default_colors/default_colors.css.template
index 4b269baf..87e22a08 100644
--- a/plugins/default_colors/default_colors.css.template
+++ b/plugins/default_colors/default_colors.css.template
@@ -1,3 +1,3 @@
1:root { 1:root {
2 %s 2%s
3} 3}
diff --git a/plugins/default_colors/default_colors.php b/plugins/default_colors/default_colors.php
index b898814b..1928cc9f 100644
--- a/plugins/default_colors/default_colors.php
+++ b/plugins/default_colors/default_colors.php
@@ -6,6 +6,7 @@
6 * Allow users to easily overrides colors of the default theme. 6 * Allow users to easily overrides colors of the default theme.
7 */ 7 */
8 8
9use Shaarli\Config\ConfigManager;
9use Shaarli\Plugin\PluginManager; 10use Shaarli\Plugin\PluginManager;
10 11
11const DEFAULT_COLORS_PLACEHOLDERS = [ 12const DEFAULT_COLORS_PLACEHOLDERS = [
@@ -15,7 +16,32 @@ const DEFAULT_COLORS_PLACEHOLDERS = [
15]; 16];
16 17
17/** 18/**
18 * When plugin parameters are saved 19 * Display an error if the plugin is active a no color is configured.
20 *
21 * @param $conf ConfigManager instance
22 *
23 * @return array|null The errors array or null of there is none.
24 */
25function default_colors_init($conf)
26{
27 $params = '';
28 foreach (DEFAULT_COLORS_PLACEHOLDERS as $placeholder) {
29 $params .= trim($conf->get('plugins.'. $placeholder, ''));
30 }
31
32 if (empty($params)) {
33 $error = t('Default colors plugin error: '.
34 'This plugin is active and no custom color is configured.');
35 return array($error);
36 }
37}
38
39/**
40 * When plugin parameters are saved, we regenerate the custom CSS file with provided settings.
41 *
42 * @param array $data $_POST array
43 *
44 * @return array Updated $_POST array
19 */ 45 */
20function hook_default_colors_save_plugin_parameters($data) 46function hook_default_colors_save_plugin_parameters($data)
21{ 47{
@@ -27,16 +53,20 @@ function hook_default_colors_save_plugin_parameters($data)
27 ? default_colors_format_css_rule($data, $rule) .';'. PHP_EOL 53 ? default_colors_format_css_rule($data, $rule) .';'. PHP_EOL
28 : ''; 54 : '';
29 } 55 }
30 file_put_contents($file, sprintf($template, $content)); 56
57 if (! empty($content)) {
58 file_put_contents($file, sprintf($template, $content));
59 }
60
31 return $data; 61 return $data;
32} 62}
33 63
34/** 64/**
35 * When linklist is displayed, include isso CSS file. 65 * When linklist is displayed, include default_colors CSS file.
36 * 66 *
37 * @param array $data - header data. 67 * @param array $data - header data.
38 * 68 *
39 * @return mixed - header data with isso CSS file added. 69 * @return mixed - header data with default_colors CSS file added.
40 */ 70 */
41function hook_default_colors_render_includes($data) 71function hook_default_colors_render_includes($data)
42{ 72{
@@ -49,6 +79,26 @@ function hook_default_colors_render_includes($data)
49} 79}
50 80
51/** 81/**
82 * Create a valid CSS rule from parameters settings and plugin parameter.
83 *
84 * @param array $data $_POST array
85 * @param string $parameter Plugin parameter name
86 *
87 * @return string CSS rules for the provided parameter and its matching value.
88 */
89function default_colors_format_css_rule($data, $parameter)
90{
91 if (empty($data[$parameter])) {
92 return '';
93 }
94
95 $key = str_replace('DEFAULT_COLORS_', '', $parameter);
96 $key = str_replace('_', '-', strtolower($key)) .'-color';
97 return ' --'. $key .': '. $data[$parameter];
98}
99
100
101/**
52 * This function is never called, but contains translation calls for GNU gettext extraction. 102 * This function is never called, but contains translation calls for GNU gettext extraction.
53 */ 103 */
54function default_colors_translation() 104function default_colors_translation()
@@ -59,10 +109,3 @@ function default_colors_translation()
59 t('Background color (light grey)'); 109 t('Background color (light grey)');
60 t('Dark main color (e.g. visited links)'); 110 t('Dark main color (e.g. visited links)');
61} 111}
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}