Skip to content
Snippets Groups Projects
Commit 831864db authored by Andreas Gohr's avatar Andreas Gohr
Browse files

make styler work without JS as well

parent aae321f2
No related branches found
No related tags found
No related merge requests found
...@@ -20,7 +20,7 @@ if(!defined('DOKU_INC')) die(); ...@@ -20,7 +20,7 @@ if(!defined('DOKU_INC')) die();
class action_plugin_styler extends DokuWiki_Action_Plugin { class action_plugin_styler extends DokuWiki_Action_Plugin {
/** /**
* Registers a callback function for a given event * Registers a callback functions
* *
* @param Doku_Event_Handler $controller DokuWiki's event controller object * @param Doku_Event_Handler $controller DokuWiki's event controller object
* @return void * @return void
...@@ -28,12 +28,37 @@ class action_plugin_styler extends DokuWiki_Action_Plugin { ...@@ -28,12 +28,37 @@ class action_plugin_styler extends DokuWiki_Action_Plugin {
public function register(Doku_Event_Handler $controller) { public function register(Doku_Event_Handler $controller) {
$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax'); $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax');
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_action'); $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_action');
$controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handle_header');
}
/**
* Adds the preview parameter to the stylesheet loading in non-js mode
*
* @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_header(Doku_Event &$event, $param) {
global $ACT;
global $INPUT;
if($ACT != 'admin' || $INPUT->str('page') != 'styler') return;
if(!auth_isadmin()) return;
// FIXME load preview style when on admin page // set preview
$len = count($event->data['link']);
for($i = 0; $i < $len; $i++) {
if(
$event->data['link'][$i]['rel'] == 'stylesheet' &&
strpos($event->data['link'][$i]['href'], 'lib/exe/css.php') !== false
) {
$event->data['link'][$i]['href'] .= '&preview=1&tseed='.time();
}
}
} }
/** /**
* [Custom event handler which performs action] * Updates the style.ini settings by passing it on to handle() of the admin component
* *
* @param Doku_Event $event event object by reference * @param Doku_Event $event event object by reference
* @param mixed $param [the parameters passed as fifth argument to register_hook() when this * @param mixed $param [the parameters passed as fifth argument to register_hook() when this
...@@ -41,8 +66,8 @@ class action_plugin_styler extends DokuWiki_Action_Plugin { ...@@ -41,8 +66,8 @@ class action_plugin_styler extends DokuWiki_Action_Plugin {
* @return void * @return void
*/ */
public function handle_action(Doku_Event &$event, $param) { public function handle_action(Doku_Event &$event, $param) {
if(!auth_isadmin()) return;
if($event->data != 'styler_plugin') return; if($event->data != 'styler_plugin') return;
if(!auth_isadmin()) return;
$event->data = 'show'; $event->data = 'show';
/** @var admin_plugin_styler $hlp */ /** @var admin_plugin_styler $hlp */
...@@ -51,7 +76,7 @@ class action_plugin_styler extends DokuWiki_Action_Plugin { ...@@ -51,7 +76,7 @@ class action_plugin_styler extends DokuWiki_Action_Plugin {
} }
/** /**
* [Custom event handler which performs action] * Create the style form in the floating Dialog
* *
* @param Doku_Event $event event object by reference * @param Doku_Event $event event object by reference
* @param mixed $param [the parameters passed as fifth argument to register_hook() when this * @param mixed $param [the parameters passed as fifth argument to register_hook() when this
...@@ -60,8 +85,8 @@ class action_plugin_styler extends DokuWiki_Action_Plugin { ...@@ -60,8 +85,8 @@ class action_plugin_styler extends DokuWiki_Action_Plugin {
*/ */
public function handle_ajax(Doku_Event &$event, $param) { public function handle_ajax(Doku_Event &$event, $param) {
if(!auth_isadmin()) return;
if($event->data != 'plugin_styler') return; if($event->data != 'plugin_styler') return;
if(!auth_isadmin()) return;
$event->preventDefault(); $event->preventDefault();
$event->stopPropagation(); $event->stopPropagation();
......
...@@ -26,7 +26,7 @@ class admin_plugin_styler extends DokuWiki_Admin_Plugin { ...@@ -26,7 +26,7 @@ class admin_plugin_styler extends DokuWiki_Admin_Plugin {
} }
/** /**
* Should carry out any processing required by the plugin. * handle the different actions (also called from ajax)
*/ */
public function handle() { public function handle() {
global $INPUT; global $INPUT;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment