diff options
Diffstat (limited to 'platform/www/lib/plugins/styling')
-rw-r--r-- | platform/www/lib/plugins/styling/README | 27 | ||||
-rw-r--r-- | platform/www/lib/plugins/styling/action.php | 51 | ||||
-rw-r--r-- | platform/www/lib/plugins/styling/admin.php | 224 | ||||
-rw-r--r-- | platform/www/lib/plugins/styling/admin.svg | 1 | ||||
-rw-r--r-- | platform/www/lib/plugins/styling/lang/en/intro.txt | 2 | ||||
-rw-r--r-- | platform/www/lib/plugins/styling/lang/en/lang.php | 35 | ||||
-rw-r--r-- | platform/www/lib/plugins/styling/plugin.info.txt | 7 | ||||
-rw-r--r-- | platform/www/lib/plugins/styling/popup.php | 31 | ||||
-rw-r--r-- | platform/www/lib/plugins/styling/script.js | 92 | ||||
-rw-r--r-- | platform/www/lib/plugins/styling/style.less | 13 |
10 files changed, 483 insertions, 0 deletions
diff --git a/platform/www/lib/plugins/styling/README b/platform/www/lib/plugins/styling/README new file mode 100644 index 0000000..a1a5e89 --- /dev/null +++ b/platform/www/lib/plugins/styling/README @@ -0,0 +1,27 @@ +styling Plugin for DokuWiki + +Allows to edit style.ini replacements + +All documentation for this plugin can be found at +https://www.dokuwiki.org/plugin:styling + +If you install this plugin manually, make sure it is installed in +lib/plugins/styling/ - if the folder is called different it +will not work! + +Please refer to http://www.dokuwiki.org/plugins for additional info +on how to install plugins in DokuWiki. + +---- +Copyright (C) Andreas Gohr <andi@splitbrain.org> + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +See the COPYING file in your DokuWiki folder for details diff --git a/platform/www/lib/plugins/styling/action.php b/platform/www/lib/plugins/styling/action.php new file mode 100644 index 0000000..46245ca --- /dev/null +++ b/platform/www/lib/plugins/styling/action.php @@ -0,0 +1,51 @@ +<?php +/** + * DokuWiki Plugin styling (Action Component) + * + * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html + * @author Andreas Gohr <andi@splitbrain.org> + */ +class action_plugin_styling extends DokuWiki_Action_Plugin +{ + + /** + * Registers a callback functions + * + * @param Doku_Event_Handler $controller DokuWiki's event controller object + * @return void + */ + public function register(Doku_Event_Handler $controller) + { + $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handleHeader'); + } + + /** + * Adds the preview parameter to the stylesheet loading in non-js mode + * + * @param Doku_Event $event event object by reference + * @param mixed $param [the parameters passed as fifth argument to register_hook() when this + * handler was registered] + * @return void + */ + public function handleHeader(Doku_Event &$event, $param) + { + global $ACT; + global $INPUT; + if ($ACT != 'admin' || $INPUT->str('page') != 'styling') return; + /** @var admin_plugin_styling $admin */ + $admin = plugin_load('admin', 'styling'); + if (!$admin->isAccessibleByCurrentUser()) return; + + // set preview + $len = count($event->data['link']); + for ($i = 0; $i < $len; $i++) { + if ($event->data['link'][$i]['rel'] == 'stylesheet' && + strpos($event->data['link'][$i]['href'], 'lib/exe/css.php') !== false + ) { + $event->data['link'][$i]['href'] .= '&preview=1&tseed='.time(); + } + } + } +} + +// vim:ts=4:sw=4:et: diff --git a/platform/www/lib/plugins/styling/admin.php b/platform/www/lib/plugins/styling/admin.php new file mode 100644 index 0000000..d454422 --- /dev/null +++ b/platform/www/lib/plugins/styling/admin.php @@ -0,0 +1,224 @@ +<?php +/** + * DokuWiki Plugin styling (Admin Component) + * + * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html + * @author Andreas Gohr <andi@splitbrain.org> + */ +class admin_plugin_styling extends DokuWiki_Admin_Plugin +{ + + public $ispopup = false; + + /** + * @return int sort number in admin menu + */ + public function getMenuSort() + { + return 1000; + } + + /** + * @return bool true if only access for superuser, false is for superusers and moderators + */ + public function forAdminOnly() + { + return true; + } + + /** + * handle the different actions (also called from ajax) + */ + public function handle() + { + global $INPUT; + $run = $INPUT->extract('run')->str('run'); + if (!$run) return; + $run = 'run'.ucfirst($run); + $this->$run(); + } + + /** + * Render HTML output, e.g. helpful text and a form + */ + public function html() + { + $class = 'nopopup'; + if ($this->ispopup) $class = 'ispopup page'; + + echo '<div id="plugin__styling" class="'.$class.'">'; + ptln('<h1>'.$this->getLang('menu').'</h1>'); + $this->form(); + echo '</div>'; + } + + /** + * Create the actual editing form + */ + public function form() + { + global $conf; + global $ID; + + $styleUtil = new \dokuwiki\StyleUtils($conf['template'], true, true); + $styleini = $styleUtil->cssStyleini(); + $replacements = $styleini['replacements']; + + if ($this->ispopup) { + $target = DOKU_BASE.'lib/plugins/styling/popup.php'; + } else { + $target = wl($ID, array('do' => 'admin', 'page' => 'styling')); + } + + if (empty($replacements)) { + echo '<p class="error">'.$this->getLang('error').'</p>'; + } else { + echo $this->locale_xhtml('intro'); + + echo '<form class="styling" method="post" action="'.$target.'">'; + + echo '<table><tbody>'; + foreach ($replacements as $key => $value) { + $name = tpl_getLang($key); + if (empty($name)) $name = $this->getLang($key); + if (empty($name)) $name = $key; + + echo '<tr>'; + echo '<td><label for="tpl__'.hsc($key).'">'.$name.'</label></td>'; + echo '<td><input type="'.$this->colorType($value).'" name="tpl['.hsc($key).']" id="tpl__'.hsc($key).'" + value="'.hsc($this->colorValue($value)).'" dir="ltr" /></td>'; + echo '</tr>'; + } + echo '</tbody></table>'; + + echo '<p>'; + echo '<button type="submit" name="run[preview]" class="btn_preview primary">'. + $this->getLang('btn_preview').'</button> '; + #FIXME only if preview.ini exists: + echo '<button type="submit" name="run[reset]">'.$this->getLang('btn_reset').'</button>'; + echo '</p>'; + + echo '<p>'; + echo '<button type="submit" name="run[save]" class="primary">'.$this->getLang('btn_save').'</button>'; + echo '</p>'; + + echo '<p>'; + #FIXME only if local.ini exists: + echo '<button type="submit" name="run[revert]">'.$this->getLang('btn_revert').'</button>'; + echo '</p>'; + + echo '</form>'; + + echo tpl_locale_xhtml('style'); + } + } + + /** + * Adjust three char color codes to the 6 char one supported by browser's color input + * + * @param string $value + * @return string + */ + protected function colorValue($value) + { + if (preg_match('/^#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])$/', $value, $match)) { + return '#' . $match[1] . $match[1] . $match[2] . $match[2] . $match[3] . $match[3]; + } + return $value; + } + + /** + * Decide the input type based on the value + * + * @param string $value + * @return string color|text + */ + protected function colorType($value) + { + if (preg_match('/^#([0-9a-fA-F]{3}){1,2}$/', $value)) { + return 'color'; + } else { + return 'text'; + } + } + + /** + * saves the preview.ini (alos called from ajax directly) + */ + public function runPreview() + { + global $conf; + $ini = $conf['cachedir'].'/preview.ini'; + io_saveFile($ini, $this->makeini()); + } + + /** + * deletes the preview.ini + */ + protected function runReset() + { + global $conf; + $ini = $conf['cachedir'].'/preview.ini'; + io_saveFile($ini, ''); + } + + /** + * deletes the local style.ini replacements + */ + protected function runRevert() + { + $this->replaceIni(''); + $this->runReset(); + } + + /** + * save the local style.ini replacements + */ + protected function runSave() + { + $this->replaceIni($this->makeini()); + $this->runReset(); + } + + /** + * create the replacement part of a style.ini from submitted data + * + * @return string + */ + protected function makeini() + { + global $INPUT; + + $ini = "[replacements]\n"; + $ini .= ";These overwrites have been generated from the Template styling Admin interface\n"; + $ini .= ";Any values in this section will be overwritten by that tool again\n"; + foreach ($INPUT->arr('tpl') as $key => $val) { + $ini .= $key.' = "'.addslashes($val).'"'."\n"; + } + + return $ini; + } + + /** + * replaces the replacement parts in the local ini + * + * @param string $new the new ini contents + */ + protected function replaceIni($new) + { + global $conf; + $ini = DOKU_CONF."tpl/".$conf['template']."/style.ini"; + if (file_exists($ini)) { + $old = io_readFile($ini); + $old = preg_replace('/\[replacements\]\n.*?(\n\[.*]|$)/s', '\\1', $old); + $old = trim($old); + } else { + $old = ''; + } + + io_makeFileDir($ini); + io_saveFile($ini, "$old\n\n$new"); + } +} + +// vim:ts=4:sw=4:et: diff --git a/platform/www/lib/plugins/styling/admin.svg b/platform/www/lib/plugins/styling/admin.svg new file mode 100644 index 0000000..5d73870 --- /dev/null +++ b/platform/www/lib/plugins/styling/admin.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M17.5 12a1.5 1.5 0 0 1-1.5-1.5A1.5 1.5 0 0 1 17.5 9a1.5 1.5 0 0 1 1.5 1.5 1.5 1.5 0 0 1-1.5 1.5m-3-4A1.5 1.5 0 0 1 13 6.5 1.5 1.5 0 0 1 14.5 5 1.5 1.5 0 0 1 16 6.5 1.5 1.5 0 0 1 14.5 8m-5 0A1.5 1.5 0 0 1 8 6.5 1.5 1.5 0 0 1 9.5 5 1.5 1.5 0 0 1 11 6.5 1.5 1.5 0 0 1 9.5 8m-3 4A1.5 1.5 0 0 1 5 10.5 1.5 1.5 0 0 1 6.5 9 1.5 1.5 0 0 1 8 10.5 1.5 1.5 0 0 1 6.5 12M12 3a9 9 0 0 0-9 9 9 9 0 0 0 9 9 1.5 1.5 0 0 0 1.5-1.5c0-.39-.15-.74-.39-1-.23-.27-.38-.62-.38-1a1.5 1.5 0 0 1 1.5-1.5H16a5 5 0 0 0 5-5c0-4.42-4.03-8-9-8z"/></svg>
\ No newline at end of file diff --git a/platform/www/lib/plugins/styling/lang/en/intro.txt b/platform/www/lib/plugins/styling/lang/en/intro.txt new file mode 100644 index 0000000..4ea5517 --- /dev/null +++ b/platform/www/lib/plugins/styling/lang/en/intro.txt @@ -0,0 +1,2 @@ +This tool allows you to change certain style settings of your currently selected template. +All changes are stored in a local configuration file and are upgrade safe.
\ No newline at end of file diff --git a/platform/www/lib/plugins/styling/lang/en/lang.php b/platform/www/lib/plugins/styling/lang/en/lang.php new file mode 100644 index 0000000..e0011eb --- /dev/null +++ b/platform/www/lib/plugins/styling/lang/en/lang.php @@ -0,0 +1,35 @@ +<?php +/** + * English language file for styling plugin + * + * @author Andreas Gohr <andi@splitbrain.org> + */ + +// menu entry for admin plugins +$lang['menu'] = 'Template Style Settings'; + +$lang['js']['loader'] = 'Preview is loading...<br />if this does not goes away, your values may be faulty'; +$lang['js']['popup'] = 'Open as a popup'; + +// custom language strings for the plugin +$lang['error'] = 'Sorry, this template does not support this functionality.'; + +$lang['btn_preview'] = 'Preview changes'; +$lang['btn_save'] = 'Save changes'; +$lang['btn_reset'] = 'Reset current changes'; +$lang['btn_revert'] = 'Revert styles back to template\'s default'; + +// default guaranteed placeholders +$lang['__text__'] = 'Main text color'; +$lang['__background__'] = 'Main background color'; +$lang['__text_alt__'] = 'Alternative text color'; +$lang['__background_alt__'] = 'Alternative background color'; +$lang['__text_neu__'] = 'Neutral text color'; +$lang['__background_neu__'] = 'Neutral background color'; +$lang['__border__'] = 'Border color'; +$lang['__highlight__'] = 'Highlight color (for search results mainly)'; + + + + +//Setup VIM: ex: et ts=4 : diff --git a/platform/www/lib/plugins/styling/plugin.info.txt b/platform/www/lib/plugins/styling/plugin.info.txt new file mode 100644 index 0000000..e374eaf --- /dev/null +++ b/platform/www/lib/plugins/styling/plugin.info.txt @@ -0,0 +1,7 @@ +base styling +author Andreas Gohr +email andi@splitbrain.org +date 2020-06-14 +name styling plugin +desc Allows to edit style.ini replacements +url https://www.dokuwiki.org/plugin:styling diff --git a/platform/www/lib/plugins/styling/popup.php b/platform/www/lib/plugins/styling/popup.php new file mode 100644 index 0000000..079062e --- /dev/null +++ b/platform/www/lib/plugins/styling/popup.php @@ -0,0 +1,31 @@ +<?php +// phpcs:disable PSR1.Files.SideEffects +if (!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__) . '/../../../'); +require_once(DOKU_INC . 'inc/init.php'); +//close session +session_write_close(); +header('Content-Type: text/html; charset=utf-8'); +header('X-UA-Compatible: IE=edge,chrome=1'); + +/** @var admin_plugin_styling $plugin */ +$plugin = plugin_load('admin', 'styling'); +if (!$plugin->isAccessibleByCurrentUser()) die('only admins allowed'); +$plugin->ispopup = true; + +// handle posts +$plugin->handle(); + +// output plugin in a very minimal template: +?><!DOCTYPE html> +<html lang="<?php echo $conf['lang'] ?>" dir="<?php echo $lang['direction'] ?>"> +<head> + <meta charset="utf-8" /> + <title><?php echo $plugin->getLang('menu') ?></title> + <?php tpl_metaheaders(false) ?> + <meta name="viewport" content="width=device-width,initial-scale=1" /> + <?php echo tpl_favicon(array('favicon')) ?> +</head> +<body class="dokuwiki"> + <?php $plugin->html() ?> +</body> +</html> diff --git a/platform/www/lib/plugins/styling/script.js b/platform/www/lib/plugins/styling/script.js new file mode 100644 index 0000000..7fa8b25 --- /dev/null +++ b/platform/www/lib/plugins/styling/script.js @@ -0,0 +1,92 @@ +jQuery(function () { + + /** + * Function to reload the preview styles in the main window + * + * @param {Window} target the main window + */ + function applyPreview(target) { + // remove style + var $style = target.jQuery('link[rel=stylesheet][href*="lib/exe/css.php"]'); + $style.attr('href', ''); + + // append the loader screen + var $loader = target.jQuery('#plugin__styling_loader'); + if (!$loader.length) { + $loader = target.jQuery('<div id="plugin__styling_loader">' + LANG.plugins.styling.loader + '</div>'); + $loader.css({ + 'position': 'absolute', + 'width': '100%', + 'height': '100%', + 'top': 0, + 'left': 0, + 'z-index': 5000, + 'background-color': '#fff', + 'opacity': '0.7', + 'color': '#000', + 'font-size': '2.5em', + 'text-align': 'center', + 'line-height': 1.5, + 'padding-top': '2em' + }); + target.jQuery('body').append($loader); + } + + // load preview in main window (timeout works around chrome updating CSS weirdness) + setTimeout(function () { + var now = new Date().getTime(); + $style.attr('href', DOKU_BASE + 'lib/exe/css.php?preview=1&tseed=' + now); + }, 500); + } + + var doreload = 1; + var $styling_plugin = jQuery('#plugin__styling'); + + // if we are not on the plugin page (either main or popup) + if (!$styling_plugin.length) { + // handle the preview cookie + if(DokuCookie.getValue('styling_plugin') == 1) { + applyPreview(window); + } + return; // nothing more to do here + } + + /* ---- from here on we're in the popup or admin page ---- */ + + // add button on main page + if (!$styling_plugin.hasClass('ispopup')) { + var $form = $styling_plugin.find('form.styling').first(); + var $btn = jQuery('<button>' + LANG.plugins.styling.popup + '</button>'); + $form.prepend($btn); + + $btn.on('click', function (e) { + var windowFeatures = "menubar=no,location=no,resizable=yes,scrollbars=yes,status=false,width=500,height=500"; + window.open(DOKU_BASE + 'lib/plugins/styling/popup.php', 'styling_popup', windowFeatures); + e.preventDefault(); + e.stopPropagation(); + }).wrap('<p></p>'); + return; // we exit here if this is not the popup + } + + /* ---- from here on we're in the popup only ---- */ + + // reload the main page on close + window.onunload = function(e) { + if(doreload) { + DokuCookie.setValue('styling_plugin', 0); + if(window.opener) window.opener.document.location.reload(); + } + return null; + }; + + // don't reload on our own buttons + jQuery(':button').click(function(e){ + doreload = false; + }); + + // on first load apply preview + if(window.opener) applyPreview(window.opener); + + // enable the preview cookie + DokuCookie.setValue('styling_plugin', 1); +}); diff --git a/platform/www/lib/plugins/styling/style.less b/platform/www/lib/plugins/styling/style.less new file mode 100644 index 0000000..be0e16a --- /dev/null +++ b/platform/www/lib/plugins/styling/style.less @@ -0,0 +1,13 @@ +#plugin__styling { + button.primary { + font-weight: bold; + } + + [dir=rtl] & table input { + text-align: right; + } +} + +#plugin__styling_loader { + display: none; +} |