diff options
author | Andreas Gohr <andi@splitbrain.org> | 2015-05-17 08:15:32 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2015-05-17 08:15:32 +0200 |
commit | aae321f2598674fe5c509cdd2a07327249358938 (patch) | |
tree | e11f889999c8b49d904e7dc3204bdf67bd9ac4cf /lib | |
parent | fb7685fb53589ebe099201297c0e8dbf20d89c59 (diff) | |
download | rpg-aae321f2598674fe5c509cdd2a07327249358938.tar.gz rpg-aae321f2598674fe5c509cdd2a07327249358938.tar.bz2 |
make styler plugin work without javascript as well (partly done)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/plugins/styler/action.php | 94 | ||||
-rw-r--r-- | lib/plugins/styler/admin.php | 106 |
2 files changed, 103 insertions, 97 deletions
diff --git a/lib/plugins/styler/action.php b/lib/plugins/styler/action.php index 88e2d0912..b7dd27cc4 100644 --- a/lib/plugins/styler/action.php +++ b/lib/plugins/styler/action.php @@ -28,6 +28,8 @@ class action_plugin_styler extends DokuWiki_Action_Plugin { public function register(Doku_Event_Handler $controller) { $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax'); $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_action'); + + // FIXME load preview style when on admin page } /** @@ -40,21 +42,12 @@ class action_plugin_styler extends DokuWiki_Action_Plugin { */ public function handle_action(Doku_Event &$event, $param) { if(!auth_isadmin()) return; + if($event->data != 'styler_plugin') return; + $event->data = 'show'; - $event->data = act_clean($event->data); - if($event->data === 'styler_plugin_preview') { - $event->data = 'show'; - $this->preview(); - } elseif($event->data === 'styler_plugin_reset') { - $event->data = 'show'; - $this->reset(); - } elseif($event->data === 'styler_plugin_revert') { - $event->data = 'show'; - $this->revert(); - } elseif($event->data === 'styler_plugin_save') { - $event->data = 'show'; - $this->save(); - } + /** @var admin_plugin_styler $hlp */ + $hlp = plugin_load('admin', 'styler'); + $hlp->handle(); } /** @@ -74,80 +67,9 @@ class action_plugin_styler extends DokuWiki_Action_Plugin { /** @var admin_plugin_styler $hlp */ $hlp = plugin_load('admin', 'styler'); - $hlp->form(); + $hlp->form(true); } - /** - * saves the preview.ini - */ - protected function preview() { - global $conf; - $ini = $conf['cachedir'].'/preview.ini'; - io_saveFile($ini, $this->makeini()); - } - - /** - * deletes the preview.ini - */ - protected function reset() { - global $conf; - $ini = $conf['cachedir'].'/preview.ini'; - io_saveFile($ini, ''); - } - - /** - * deletes the local style.ini replacements - */ - protected function revert() { - $this->replaceini(''); - $this->reset(); - } - - /** - * save the local style.ini replacements - */ - protected function save() { - $this->replaceini($this->makeini()); - $this->reset(); - } - - /** - * create the replacement part of a style.ini from submitted data - * - * @return string - */ - protected function makeini() { - global $INPUT; - - $ini = "[replacements]\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/lib/plugins/styler/admin.php b/lib/plugins/styler/admin.php index 4be2153ab..dfc72373c 100644 --- a/lib/plugins/styler/admin.php +++ b/lib/plugins/styler/admin.php @@ -29,6 +29,11 @@ class admin_plugin_styler extends DokuWiki_Admin_Plugin { * Should carry out any processing required by the plugin. */ public function handle() { + global $INPUT; + $run = $INPUT->extract('run')->str('run'); + if(!$run) return; + $run = "run_$run"; + $this->$run(); } /** @@ -36,46 +41,125 @@ class admin_plugin_styler extends DokuWiki_Admin_Plugin { */ public function html() { echo '<div id="plugin__styler">'; - $this->form(); + $this->form(false); echo '</div>'; } /** * Create the actual editing form */ - public function form() { + public function form($isajax) { global $conf; + global $ID; $tpl = $conf['template']; - define('SIMPLE_TEST',1); // hack, ideally certain functions should be moved out of css.php + 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); + $styleini = css_styleini($conf['template'], true); $replacements = $styleini['replacements']; + if($isajax) { + $target = wl($ID, array('do' => 'styler_plugin')); + } else { + $target = wl($ID, array('do' => 'admin', 'page' => 'styler')); + } + ptln('<h1>'.$this->getLang('menu').'</h1>'); - if (empty($replacements)) { + if(empty($replacements)) { echo '<p class="error">Sorry, this template does not support this functionality.</p>'; } else { echo '<p>Intro blah... for the currently active template ("'.$tpl.'")... not all variables preview...</p>'; - echo '<form class="styler" method="post">'; + echo '<form class="styler" method="post" action="'.$target.'">'; echo '<h2>Template variables</h2>'; echo '<table>'; - foreach($replacements as $key => $value){ + foreach($replacements as $key => $value) { echo '<tr>'; echo '<td>'.$key.'</td>'; echo '<td><input name="tpl['.hsc($key).']" value="'.hsc($value).'" />'; echo '</tr>'; } echo '</table>'; - echo '<input type="submit" name="do[styler_plugin_preview]" value="preview">'; - echo '<input type="submit" name="do[styler_plugin_reset]" value="reset current">'; #FIXME only if preview.ini exists - echo '<input type="submit" name="do[styler_plugin_revert]" value="revert to original">'; #FIXME only if local.ini exists - echo '<input type="submit" name="do[styler_plugin_save]" value="save">'; + echo '<input type="submit" name="run[preview]" value="preview">'; + echo '<input type="submit" name="run[reset]" value="reset current">'; #FIXME only if preview.ini exists + echo '<input type="submit" name="run[revert]" value="revert to original">'; #FIXME only if local.ini exists + echo '<input type="submit" name="run[save]" value="save">'; echo '</form>'; } } + /** + * saves the preview.ini + */ + protected 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 Styler 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:
\ No newline at end of file |