From 123bc813fd93ab5d8dab3cc4a66a09e613a10aa2 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 23 May 2015 15:29:33 +0200 Subject: renamed plugin from styler to styling styler was already taken --- lib/plugins/styling/action.php | 108 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 lib/plugins/styling/action.php (limited to 'lib/plugins/styling/action.php') diff --git a/lib/plugins/styling/action.php b/lib/plugins/styling/action.php new file mode 100644 index 000000000..622c634d6 --- /dev/null +++ b/lib/plugins/styling/action.php @@ -0,0 +1,108 @@ + + */ + +// must be run within Dokuwiki +if(!defined('DOKU_INC')) die(); + +/** + * Class action_plugin_styling + * + * 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_styling extends DokuWiki_Action_Plugin { + + /** + * Registers a callback functions + * + * @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'); + $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') != 'styling') return; + if(!auth_isadmin()) return; + + // 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(); + } + } + } + + /** + * Updates the style.ini settings by passing it on to handle() of the admin component + * + * @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) { + if($event->data != 'styling_plugin') return; + if(!auth_isadmin()) return; + $event->data = 'show'; + + /** @var admin_plugin_styling $hlp */ + $hlp = plugin_load('admin', 'styling'); + $hlp->handle(); + } + + /** + * Create the style form in the floating Dialog + * + * @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_styling') return; + if(!auth_isadmin()) return; + $event->preventDefault(); + $event->stopPropagation(); + + global $ID; + global $INPUT; + $ID = getID(); + + /** @var admin_plugin_styling $hlp */ + $hlp = plugin_load('admin', 'styling'); + if($INPUT->str('run') == 'preview') { + $hlp->run_preview(); + } else { + $hlp->form(true); + } + } + +} + +// vim:ts=4:sw=4:et: -- cgit v1.2.3