This commit is contained in:
Franke 2021-07-12 18:25:16 +02:00
parent b0a6cddcf0
commit 7ebd5b2528
3 changed files with 88 additions and 0 deletions

47
action.php Normal file

@ -0,0 +1,47 @@
<?php
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/');
if(!defined('DOKU_LF')) define('DOKU_LF', "\n");
require_once(DOKU_PLUGIN.'action.php');
class action_plugin_usetheme extends DokuWiki_Action_Plugin {
// register hook
public function register(Doku_Event_Handler $controller) {
$controller->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:

7
plugin.info.txt Normal file

@ -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 -

34
syntax.php Normal file

@ -0,0 +1,34 @@
<?php
class syntax_plugin_usetheme extends DokuWiki_Syntax_Plugin
{
public function getType()
{
return 'substition';
}
public function getPType()
{
return 'block';
}
public function getSort()
{
return 156;
}
public function connectTo($mode)
{
$this->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
}
}