summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2015-05-16 19:27:43 +0200
committerAndreas Gohr <andi@splitbrain.org>2015-05-16 19:27:43 +0200
commit0f5e7090beb4c8b8e99aa87454c89b53ed11cc66 (patch)
tree028e513f274ee0e8faa263facc0b8d48f6d95747 /lib
parent6ea007c9f8c6830ea4f21ad880e91279e2f4bf10 (diff)
downloadrpg-0f5e7090beb4c8b8e99aa87454c89b53ed11cc66.tar.gz
rpg-0f5e7090beb4c8b8e99aa87454c89b53ed11cc66.tar.bz2
we have working save and revert buttons
Diffstat (limited to 'lib')
-rw-r--r--lib/plugins/styler/action.php73
-rw-r--r--lib/plugins/styler/admin.php3
2 files changed, 69 insertions, 7 deletions
diff --git a/lib/plugins/styler/action.php b/lib/plugins/styler/action.php
index 648190a2a..e2385e739 100644
--- a/lib/plugins/styler/action.php
+++ b/lib/plugins/styler/action.php
@@ -19,8 +19,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');
+ $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax');
+ $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_action');
}
@@ -35,32 +35,91 @@ class action_plugin_styler extends DokuWiki_Action_Plugin {
public function handle_action(Doku_Event &$event, $param) {
$event->data = act_clean($event->data);
if($event->data === 'styler_plugin_preview') {
- msg('handle') ;
$event->data = 'show';
$this->preview();
- } elseif ($event->data === 'styler_plugin_save') {
+ } 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();
}
}
- protected function preview(){
+ /**
+ * saves the preview.ini
+ */
+ protected function preview() {
global $conf;
- $ini = $conf['cachedir'].'/preview.ini';
+ $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";
+ $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");
+ }
+
+ /**
* [Custom event handler which performs action]
*
* @param Doku_Event $event event object by reference
diff --git a/lib/plugins/styler/admin.php b/lib/plugins/styler/admin.php
index 8ecbd22a0..323bf61ec 100644
--- a/lib/plugins/styler/admin.php
+++ b/lib/plugins/styler/admin.php
@@ -61,6 +61,9 @@ class admin_plugin_styler extends DokuWiki_Admin_Plugin {
}
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 '</form>';
}