summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2015-05-16 19:52:26 +0200
committerAndreas Gohr <andi@splitbrain.org>2015-05-16 19:52:26 +0200
commitfb7685fb53589ebe099201297c0e8dbf20d89c59 (patch)
tree34b140d6a1a1ea3922cca14081e9dc3072f300fe /lib
parent0f5e7090beb4c8b8e99aa87454c89b53ed11cc66 (diff)
downloadrpg-fb7685fb53589ebe099201297c0e8dbf20d89c59.tar.gz
rpg-fb7685fb53589ebe099201297c0e8dbf20d89c59.tar.bz2
more improvements
Diffstat (limited to 'lib')
-rw-r--r--lib/plugins/styler/action.php50
-rw-r--r--lib/plugins/styler/admin.php16
-rw-r--r--lib/plugins/styler/script.js11
3 files changed, 46 insertions, 31 deletions
diff --git a/lib/plugins/styler/action.php b/lib/plugins/styler/action.php
index e2385e739..88e2d0912 100644
--- a/lib/plugins/styler/action.php
+++ b/lib/plugins/styler/action.php
@@ -9,6 +9,14 @@
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
+/**
+ * Class action_plugin_styler
+ *
+ * This handles all the save actions and loading the interface
+ *
+ * All this usually would be done within an admin plugin, but we want to have this available outside
+ * the admin interface using our floating dialog.
+ */
class action_plugin_styler extends DokuWiki_Action_Plugin {
/**
@@ -18,10 +26,8 @@ class action_plugin_styler extends DokuWiki_Action_Plugin {
* @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');
-
}
/**
@@ -33,6 +39,8 @@ class action_plugin_styler extends DokuWiki_Action_Plugin {
* @return void
*/
public function handle_action(Doku_Event &$event, $param) {
+ if(!auth_isadmin()) return;
+
$event->data = act_clean($event->data);
if($event->data === 'styler_plugin_preview') {
$event->data = 'show';
@@ -50,6 +58,26 @@ class action_plugin_styler extends DokuWiki_Action_Plugin {
}
/**
+ * [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(!auth_isadmin()) return;
+ if($event->data != 'plugin_styler') return;
+ $event->preventDefault();
+ $event->stopPropagation();
+
+ /** @var admin_plugin_styler $hlp */
+ $hlp = plugin_load('admin', 'styler');
+ $hlp->form();
+ }
+
+ /**
* saves the preview.ini
*/
protected function preview() {
@@ -119,24 +147,6 @@ class action_plugin_styler extends DokuWiki_Action_Plugin {
io_saveFile($ini, "$old\n\n$new");
}
- /**
- * [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();
- }
}
diff --git a/lib/plugins/styler/admin.php b/lib/plugins/styler/admin.php
index 323bf61ec..4be2153ab 100644
--- a/lib/plugins/styler/admin.php
+++ b/lib/plugins/styler/admin.php
@@ -29,13 +29,21 @@ class admin_plugin_styler extends DokuWiki_Admin_Plugin {
* Should carry out any processing required by the plugin.
*/
public function handle() {
- set_doku_pref('styler_plugin', 1);
}
/**
* Render HTML output, e.g. helpful text and a form
*/
public function html() {
+ echo '<div id="plugin__styler">';
+ $this->form();
+ echo '</div>';
+ }
+
+ /**
+ * Create the actual editing form
+ */
+ public function form() {
global $conf;
$tpl = $conf['template'];
define('SIMPLE_TEST',1); // hack, ideally certain functions should be moved out of css.php
@@ -50,7 +58,7 @@ class admin_plugin_styler extends DokuWiki_Admin_Plugin {
} else {
echo '<p>Intro blah... for the currently active template ("'.$tpl.'")... not all variables preview...</p>';
- echo '<form class="styler" id="plugin__styler" method="post">';
+ echo '<form class="styler" method="post">';
echo '<h2>Template variables</h2>';
echo '<table>';
foreach($replacements as $key => $value){
@@ -66,12 +74,8 @@ class admin_plugin_styler extends DokuWiki_Admin_Plugin {
echo '<input type="submit" name="do[styler_plugin_save]" value="save">';
echo '</form>';
}
-
-
-
}
-
}
// vim:ts=4:sw=4:et: \ No newline at end of file
diff --git a/lib/plugins/styler/script.js b/lib/plugins/styler/script.js
index d09a8b8da..b3cadfd5e 100644
--- a/lib/plugins/styler/script.js
+++ b/lib/plugins/styler/script.js
@@ -1,10 +1,12 @@
jQuery(function () {
+ // user openend the admin page, set cookie and redirect
+ if(jQuery('#plugin__styler').length) {
+ DokuCookie.setValue('styler_plugin', 1);
+ document.location.href = DOKU_BASE;
+ }
-
+ // The Styler Dialog is currently enabled, display it here and apply the preview styles
if (DokuCookie.getValue('styler_plugin') == 1) {
-
-
-
// load dialog
var $dialog = jQuery(document.createElement('div'));
jQuery('body').append($dialog);
@@ -35,6 +37,5 @@ jQuery(function () {
});
}
);
-
}
}); \ No newline at end of file