diff --git a/action.php b/action.php new file mode 100644 index 0000000..1413e49 --- /dev/null +++ b/action.php @@ -0,0 +1,47 @@ +register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, '_handleConf'); + //$controller->register_hook('MEDIAMANAGER_STARTED', 'BEFORE', $this, '_handleConf'); + $controller->register_hook('DETAIL_STARTED', 'BEFORE', $this, '_handleConf'); + //$controller->register_hook('TPL_CONTENT_DISPLAY', 'BEFORE', $this, '_handleContent', array()); + // only needed for not yet up-to-date templates: + $controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, '_defineConstants'); + //$controller->register_hook('MEDIAMANAGER_STARTED', 'AFTER', $this, '_defineConstants'); + $controller->register_hook('DETAIL_STARTED', 'AFTER', $this, '_defineConstants'); + } + + public function _defineConstants(Doku_Event $event, $param) { + global $conf; + // define Template baseURL + if(!defined('DOKU_TPL')) + define('DOKU_TPL', DOKU_BASE.'lib/tpl/'.$conf['template'].'/'); + + // define real Template directory + if(!defined('DOKU_TPLINC')) + define('DOKU_TPLINC', DOKU_INC.'lib/tpl/'.$conf['template'].'/'); + } + + public function _handleConf(Doku_Event $event, $param) { + global $ID, $ACT, $conf; + $dataFile = wikiFN(cleanID($ID)); + $fp = fopen($dataFile,"r"); + $firstLine = fgets($fp,512); + fclose($fp); + preg_match('/~~USETHEME:(.*?)~~/', $firstLine, $match); + $template = trim($match[1]); + if($template) { + $conf['template'] = $template; + } + } +} + +// vim:ts=4:sw=4: diff --git a/plugin.info.txt b/plugin.info.txt new file mode 100644 index 0000000..54c2f90 --- /dev/null +++ b/plugin.info.txt @@ -0,0 +1,7 @@ +base usetheme +author Ruediger Marwein +email henryxiv@hotmail.com +date 2021-06-15 +name UseTheme Plugin +desc Switch Theme using a in-page macro +url - diff --git a/syntax.php b/syntax.php new file mode 100644 index 0000000..3025156 --- /dev/null +++ b/syntax.php @@ -0,0 +1,34 @@ +Lexer->addSpecialPattern('~~USETHEME:\w+~~', $mode, 'plugin_usetheme'); + } + + public function handle($match, $state, $pos, Doku_Handler $handler) + { + $match = substr($match, 11, -2); // cut match down to the template name + return array(strtolower($match)); + } + + public function render($format, Doku_Renderer $renderer, $data) + { + return ""; // show nothing, we want to change the template + } +} \ No newline at end of file