-
Notifications
You must be signed in to change notification settings - Fork 7
/
action.php
105 lines (89 loc) · 2.71 KB
/
action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
* DokuWiki Action Plugin LoadSkin
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Michael Klier <[email protected]>
*/
// must be run within Dokuwiki
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');
/**
* All DokuWiki plugins to interfere with the event system
* need to inherit from this class
*/
class action_plugin_loadskin extends DokuWiki_Action_Plugin {
function getInfo() {
return array(
'author' => 'Michael Klier',
'email' => '[email protected]',
'date' => @file_get_contents(DOKU_PLUGIN.'loadskin/VERSION'),
'name' => 'loadskin',
'desc' => 'Allows to change the used template for a namespace or certain pages',
'url' => 'http://dokuwiki.org/plugin:loadskin'
);
}
// register hook
function register(&$controller) {
$controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handleMeta');
$controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'handleConf');
}
/**
* Overwrites the $conf['template'] setting
*
* Michael Klier <[email protected]>
*/
function handleConf(&$event, $param) {
global $ID;
global $conf;
$config = DOKU_INC.'conf/loadskin.conf';
if(@file_exists($config)) {
$data = unserialize(io_readFile($config, false));
$tpl = $this->getTpl($data, $ID);
if($tpl && $_REQUEST['do'] != 'admin') {
$conf['template'] = $tpl;
}
}
}
/**
* Replaces the style headers with a different skin if specified in the
* configuration
*
* @author Michael Klier <[email protected]>
*/
function handleMeta(&$event, $param) {
global $ID;
$config = DOKU_INC.'conf/loadskin.conf';
if(@file_exists($config)) {
$data = unserialize(io_readFile($config, false));
$tpl = $this->getTpl($data, $ID);
if($tpl && $_REQUEST['do'] != 'admin') {
$head =& $event->data;
for($i=0; $i<=count($head['link']); $i++) {
if($head['link'][$i]['rel'] == 'stylesheet') {
$head['link'][$i]['href'] = preg_replace('/t=([\w]+$)/', "t=$tpl", $head['link'][$i]['href']);
}
}
}
}
}
/**
* Checks if a given page should use a different template then the default
*
* Michael Klier <[email protected]>
*/
function getTpl($data, $id) {
if($data[$id]) return $data[$id];
$path = explode(':', $id);
$found = false;
while(count($path) > 0) {
$id = implode(':', $path);
if($data[$id]) return $data[$id];
array_pop($path);
}
return false;
}
}
// vim:ts=4:sw=4:enc=utf-8: