From 123bc813fd93ab5d8dab3cc4a66a09e613a10aa2 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 23 May 2015 15:29:33 +0200 Subject: renamed plugin from styler to styling styler was already taken --- lib/plugins/styling/admin.php | 215 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 lib/plugins/styling/admin.php (limited to 'lib/plugins/styling/admin.php') diff --git a/lib/plugins/styling/admin.php b/lib/plugins/styling/admin.php new file mode 100644 index 000000000..85d87dd71 --- /dev/null +++ b/lib/plugins/styling/admin.php @@ -0,0 +1,215 @@ + + */ + +// must be run within Dokuwiki +if(!defined('DOKU_INC')) die(); + +class admin_plugin_styling extends DokuWiki_Admin_Plugin { + + /** + * @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; + } + + /** + * @param string $language + * @return string + */ + public function getMenuText($language) { + $js = $this->getLang('js'); + return $js['menu']; + } + + /** + * handle the different actions (also called from ajax) + */ + public function handle() { + global $INPUT; + $run = $INPUT->extract('run')->str('run'); + if(!$run) return; + $run = "run_$run"; + $this->$run(); + } + + /** + * Render HTML output, e.g. helpful text and a form + */ + public function html() { + echo '
'; + ptln('

'.$this->getMenuText('').'

'); + $this->form(false); + echo '
'; + } + + /** + * Create the actual editing form + */ + public function form($isajax) { + global $conf; + global $ID; + define('SIMPLE_TEST', 1); // hack, ideally certain functions should be moved out of css.php + require_once(DOKU_INC.'lib/exe/css.php'); + $styleini = css_styleini($conf['template'], true); + $replacements = $styleini['replacements']; + + if($isajax) { + $target = wl($ID, array('do' => 'styling_plugin')); + } else { + $target = wl($ID, array('do' => 'admin', 'page' => 'styling')); + } + + if(empty($replacements)) { + echo '

'.$this->getLang('error').'

'; + } else { + echo $this->locale_xhtml('intro'); + + echo '
'; + + echo ''; + foreach($replacements as $key => $value) { + $name = tpl_getLang($key); + if(empty($name)) $name = $this->getLang($key); + if(empty($name)) $name = $key; + + echo ''; + echo ''; + echo ''; + } + echo '
'.$name.'colorClass($key).' />'; + echo '
'; + + echo '

'; + echo ''; + echo ''; #FIXME only if preview.ini exists + echo '

'; + + echo '

'; + echo ''; + echo '

'; + + echo '

'; + echo ''; #FIXME only if local.ini exists + echo '

'; + + echo '
'; + + echo tpl_locale_xhtml('style'); + + } + } + + /** + * set the color class attribute + */ + protected function colorClass($key) { + static $colors = array( + 'text', + 'background', + 'text_alt', + 'background_alt', + 'text_neu', + 'background_neu', + 'border', + 'highlight', + 'background_site', + 'link', + 'existing', + 'missing', + ); + + if(preg_match('/colou?r/', $key) || in_array(trim($key,'_'), $colors)) { + return 'class="color"'; + } else { + return ''; + } + } + + /** + * saves the preview.ini (alos called from ajax directly) + */ + public function run_preview() { + global $conf; + $ini = $conf['cachedir'].'/preview.ini'; + io_saveFile($ini, $this->makeini()); + } + + /** + * deletes the preview.ini + */ + protected function run_reset() { + global $conf; + $ini = $conf['cachedir'].'/preview.ini'; + io_saveFile($ini, ''); + } + + /** + * deletes the local style.ini replacements + */ + protected function run_revert() { + $this->replaceini(''); + $this->run_reset(); + } + + /** + * save the local style.ini replacements + */ + protected function run_save() { + $this->replaceini($this->makeini()); + $this->run_reset(); + } + + /** + * 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: -- cgit v1.2.3 From e4632ba4cca90438b3d47594f217a9ed18b980be Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Sat, 23 May 2015 15:37:05 +0000 Subject: Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- lib/plugins/styling/admin.php | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/plugins/styling/admin.php') diff --git a/lib/plugins/styling/admin.php b/lib/plugins/styling/admin.php index 85d87dd71..ab8e5a5f4 100644 --- a/lib/plugins/styling/admin.php +++ b/lib/plugins/styling/admin.php @@ -57,6 +57,7 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { /** * Create the actual editing form + * @param boolean $isajax */ public function form($isajax) { global $conf; -- cgit v1.2.3 From 418cb6171fc2d6d04a505e28c123b22c384db8c5 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 25 May 2015 09:58:54 +0200 Subject: removed unused class --- lib/plugins/styling/admin.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/plugins/styling/admin.php') diff --git a/lib/plugins/styling/admin.php b/lib/plugins/styling/admin.php index ab8e5a5f4..3c2ab577c 100644 --- a/lib/plugins/styling/admin.php +++ b/lib/plugins/styling/admin.php @@ -93,16 +93,16 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { } echo ''; - echo '

'; + echo '

'; echo ''; echo ''; #FIXME only if preview.ini exists echo '

'; - echo '

'; + echo '

'; echo ''; echo '

'; - echo '

'; + echo '

'; echo ''; #FIXME only if local.ini exists echo '

'; -- cgit v1.2.3 From 6667cd8743e57a4492cfbcbe1066ea48d444f7a2 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 26 Jun 2015 12:57:58 +0200 Subject: changed the whole thing to a real popup --- lib/plugins/styling/admin.php | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'lib/plugins/styling/admin.php') diff --git a/lib/plugins/styling/admin.php b/lib/plugins/styling/admin.php index 3c2ab577c..627efbd15 100644 --- a/lib/plugins/styling/admin.php +++ b/lib/plugins/styling/admin.php @@ -11,6 +11,8 @@ if(!defined('DOKU_INC')) die(); class admin_plugin_styling extends DokuWiki_Admin_Plugin { + public $ispopup = false; + /** * @return int sort number in admin menu */ @@ -25,15 +27,6 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { return true; } - /** - * @param string $language - * @return string - */ - public function getMenuText($language) { - $js = $this->getLang('js'); - return $js['menu']; - } - /** * handle the different actions (also called from ajax) */ @@ -49,17 +42,19 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { * Render HTML output, e.g. helpful text and a form */ public function html() { - echo '
'; - ptln('

'.$this->getMenuText('').'

'); - $this->form(false); + $class = 'nopopup'; + if($this->ispopup) $class = 'ispopup'; + + echo '
'; + ptln('

'.$this->getLang('menu').'

'); + $this->form(); echo '
'; } /** * Create the actual editing form - * @param boolean $isajax */ - public function form($isajax) { + public function form() { global $conf; global $ID; define('SIMPLE_TEST', 1); // hack, ideally certain functions should be moved out of css.php @@ -67,8 +62,8 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { $styleini = css_styleini($conf['template'], true); $replacements = $styleini['replacements']; - if($isajax) { - $target = wl($ID, array('do' => 'styling_plugin')); + if($this->ispopup) { + $target = DOKU_BASE.'lib/plugins/styling/popup.php'; } else { $target = wl($ID, array('do' => 'admin', 'page' => 'styling')); } -- cgit v1.2.3 From d634152e42ef1c75d899f021132ce0c2632257ac Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Tue, 7 Jul 2015 12:39:55 +0100 Subject: improved various minor frontend issues in styling plugin * improved spacing of popup * made primary buttons clearer * xhtml and validity fixes * improved some lang strings * moved 'open as popup' after intro * fixed page reload after clicking 'open as popup' button --- lib/plugins/styling/admin.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lib/plugins/styling/admin.php') diff --git a/lib/plugins/styling/admin.php b/lib/plugins/styling/admin.php index 627efbd15..f241e3fed 100644 --- a/lib/plugins/styling/admin.php +++ b/lib/plugins/styling/admin.php @@ -43,7 +43,7 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { */ public function html() { $class = 'nopopup'; - if($this->ispopup) $class = 'ispopup'; + if($this->ispopup) $class = 'ispopup page'; echo '
'; ptln('

'.$this->getLang('menu').'

'); @@ -75,7 +75,7 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { echo '
'; - echo ''; + echo '
'; foreach($replacements as $key => $value) { $name = tpl_getLang($key); if(empty($name)) $name = $this->getLang($key); @@ -83,22 +83,22 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { echo ''; echo ''; - echo ''; echo ''; } - echo '
'.$name.'colorClass($key).' />'; + echo 'colorClass($key).' />
'; + echo ''; echo '

'; - echo ''; - echo ''; #FIXME only if preview.ini exists + echo ' '; + echo ''; #FIXME only if preview.ini exists echo '

'; echo '

'; - echo ''; + echo ''; echo '

'; echo '

'; - echo ''; #FIXME only if local.ini exists + echo ''; #FIXME only if local.ini exists echo '

'; echo '
'; -- cgit v1.2.3 From 147d8f481419c685b5408b7b793fd32a8923f35e Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Tue, 7 Jul 2015 13:04:52 +0100 Subject: added labels to form entries --- lib/plugins/styling/admin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/plugins/styling/admin.php') diff --git a/lib/plugins/styling/admin.php b/lib/plugins/styling/admin.php index f241e3fed..c6c04bb52 100644 --- a/lib/plugins/styling/admin.php +++ b/lib/plugins/styling/admin.php @@ -82,8 +82,8 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { if(empty($name)) $name = $key; echo ''; - echo ''.$name.''; - echo 'colorClass($key).' />'; + echo ''; + echo 'colorClass($key).' />'; echo ''; } echo ''; -- cgit v1.2.3 From cf2c8e759bf06596f9492d090f4dd8dbb76a178c Mon Sep 17 00:00:00 2001 From: Anika Henke Date: Sat, 25 Jul 2015 22:58:51 +0100 Subject: changed input submits to buttons, fixed small RTL issue --- lib/plugins/styling/admin.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/plugins/styling/admin.php') diff --git a/lib/plugins/styling/admin.php b/lib/plugins/styling/admin.php index c6c04bb52..c747c3130 100644 --- a/lib/plugins/styling/admin.php +++ b/lib/plugins/styling/admin.php @@ -83,22 +83,22 @@ class admin_plugin_styling extends DokuWiki_Admin_Plugin { echo ''; echo ''; - echo 'colorClass($key).' />'; + echo 'colorClass($key).' dir="ltr" />'; echo ''; } echo ''; echo '

'; - echo ' '; - echo ''; #FIXME only if preview.ini exists + echo ' '; + echo ''; #FIXME only if preview.ini exists echo '

'; echo '

'; - echo ''; + echo ''; echo '

'; echo '

'; - echo ''; #FIXME only if local.ini exists + echo ''; #FIXME only if local.ini exists echo '

'; echo ''; -- cgit v1.2.3