X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=plugins%2Fdefault_colors%2Fdefault_colors.php;fp=plugins%2Fdefault_colors%2Fdefault_colors.php;h=1928cc9f49b527e8aadddf64ed9796d9628bacc7;hb=d9f6275ebca035fec8331652c677981056793ccc;hp=0000000000000000000000000000000000000000;hpb=38672ba0d1c722e5d6d33a58255ceb55e9410e46;p=github%2Fshaarli%2FShaarli.git diff --git a/plugins/default_colors/default_colors.php b/plugins/default_colors/default_colors.php new file mode 100644 index 00000000..1928cc9f --- /dev/null +++ b/plugins/default_colors/default_colors.php @@ -0,0 +1,111 @@ +get('plugins.'. $placeholder, '')); + } + + if (empty($params)) { + $error = t('Default colors plugin error: '. + 'This plugin is active and no custom color is configured.'); + return array($error); + } +} + +/** + * When plugin parameters are saved, we regenerate the custom CSS file with provided settings. + * + * @param array $data $_POST array + * + * @return array Updated $_POST array + */ +function hook_default_colors_save_plugin_parameters($data) +{ + $file = PluginManager::$PLUGINS_PATH . '/default_colors/default_colors.css'; + $template = file_get_contents(PluginManager::$PLUGINS_PATH . '/default_colors/default_colors.css.template'); + $content = ''; + foreach (DEFAULT_COLORS_PLACEHOLDERS as $rule) { + $content .= ! empty($data[$rule]) + ? default_colors_format_css_rule($data, $rule) .';'. PHP_EOL + : ''; + } + + if (! empty($content)) { + file_put_contents($file, sprintf($template, $content)); + } + + return $data; +} + +/** + * When linklist is displayed, include default_colors CSS file. + * + * @param array $data - header data. + * + * @return mixed - header data with default_colors CSS file added. + */ +function hook_default_colors_render_includes($data) +{ + $file = PluginManager::$PLUGINS_PATH . '/default_colors/default_colors.css'; + if (file_exists($file )) { + $data['css_files'][] = $file ; + } + + return $data; +} + +/** + * Create a valid CSS rule from parameters settings and plugin parameter. + * + * @param array $data $_POST array + * @param string $parameter Plugin parameter name + * + * @return string CSS rules for the provided parameter and its matching value. + */ +function default_colors_format_css_rule($data, $parameter) +{ + if (empty($data[$parameter])) { + return ''; + } + + $key = str_replace('DEFAULT_COLORS_', '', $parameter); + $key = str_replace('_', '-', strtolower($key)) .'-color'; + return ' --'. $key .': '. $data[$parameter]; +} + + +/** + * This function is never called, but contains translation calls for GNU gettext extraction. + */ +function default_colors_translation() +{ + // meta + t('Override default theme colors. Use any CSS valid color.'); + t('Main color (navbar green)'); + t('Background color (light grey)'); + t('Dark main color (e.g. visited links)'); +}