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