summaryrefslogtreecommitdiff
path: root/lib/plugins/styler/action.php
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2015-05-16 18:40:21 +0200
committerAndreas Gohr <andi@splitbrain.org>2015-05-16 18:40:21 +0200
commit6ea007c9f8c6830ea4f21ad880e91279e2f4bf10 (patch)
tree8d769608fe260066773457feccb987730459a73e /lib/plugins/styler/action.php
parent4d6524b8916955bf5fa9086042917244751dc03d (diff)
downloadrpg-6ea007c9f8c6830ea4f21ad880e91279e2f4bf10.tar.gz
rpg-6ea007c9f8c6830ea4f21ad880e91279e2f4bf10.tar.bz2
a first very basic implementation of the preview mechanism
Diffstat (limited to 'lib/plugins/styler/action.php')
-rw-r--r--lib/plugins/styler/action.php84
1 files changed, 84 insertions, 0 deletions
diff --git a/lib/plugins/styler/action.php b/lib/plugins/styler/action.php
new file mode 100644
index 000000000..648190a2a
--- /dev/null
+++ b/lib/plugins/styler/action.php
@@ -0,0 +1,84 @@
+<?php
+/**
+ * DokuWiki Plugin styler (Action Component)
+ *
+ * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+
+// must be run within Dokuwiki
+if(!defined('DOKU_INC')) die();
+
+class action_plugin_styler extends DokuWiki_Action_Plugin {
+
+ /**
+ * Registers a callback function for a given event
+ *
+ * @param Doku_Event_Handler $controller DokuWiki's event controller object
+ * @return void
+ */
+ 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');
+
+ }
+
+ /**
+ * [Custom event handler which performs action]
+ *
+ * @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 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') {
+ $event->data = 'show';
+ }
+ }
+
+ protected function preview(){
+ global $conf;
+ $ini = $conf['cachedir'].'/preview.ini';
+ io_saveFile($ini, $this->makeini());
+ }
+
+ protected function makeini() {
+ global $INPUT;
+
+ $ini = "[replacements]\n";
+ foreach($INPUT->arr('tpl') as $key => $val) {
+ $ini .= $key .' = "'.addslashes($val).'"'."\n";
+ }
+
+ return $ini;
+ }
+
+ /**
+ * [Custom event handler which performs action]
+ *
+ * @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 handle_ajax(Doku_Event &$event, $param) {
+ if($event->data != 'plugin_styler') return;
+ $event->preventDefault();
+ $event->stopPropagation();
+
+ /** @var admin_plugin_styler $hlp */
+ $hlp = plugin_load('admin', 'styler');
+ $hlp->html();
+ }
+
+}
+
+// vim:ts=4:sw=4:et: