forked from chimeric/dokuwiki-plugin-loadskin
-
Notifications
You must be signed in to change notification settings - Fork 6
/
helper.php
96 lines (83 loc) · 2.8 KB
/
helper.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
<?php
/**
* DokuWiki Helper Plugin LoadSkin
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Anika Henke <[email protected]>
* @author Michael Klier <[email protected]>
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
class helper_plugin_loadskin extends DokuWiki_Plugin {
public $origTpl;
/**
* Returns an array of available templates to choose from
*
* @author Michael Klier <[email protected]>
*/
public function getTemplates() {
$tpl_dir = DOKU_INC.'lib/tpl/';
if ($dh = @opendir($tpl_dir)) {
while (false !== ($entry = readdir($dh))) {
if ($entry == '.' || $entry == '..') continue;
if (!preg_match('/^[\w-]+$/', $entry)) continue;
$file = (is_link($tpl_dir.$entry)) ? readlink($tpl_dir.$entry) : $entry;
if (is_dir($tpl_dir.$file)) $list[] = $entry;
}
closedir($dh);
sort($list);
}
return $list;
}
/**
* Builds a select box with all available templates
* (unless excluded in 'excludeTemplates')
* or show only two templates for mobile switcher: standard plus mobile template
*
* @author Anika Henke <[email protected]>
*/
public function showTemplateSwitcher() {
global $conf;
global $ID;
global $ACT;
if ($ACT != 'show') return;
$mobileSwitch = $this->getConf('mobileSwitch');
$mobileTpl = $this->getConf('mobileTemplate');
if ($mobileSwitch && $mobileTpl) {
// templates for mobile switcher
$templates = array(
$mobileTpl => $this->getLang('switchMobile'),
$this->origTpl => $this->getLang('switchFull')
);
} else {
// all templates (minus excluded templates)
$excludeTemplates = array_map('trim', explode(",", $this->getConf('excludeTemplates')));
$templates = array_diff($this->getTemplates(),$excludeTemplates);
}
$form = new Doku_Form(array(
'id' => 'tpl__switcher',
'title' => $this->getLang('switchTpl'),
'action' => wl($ID)
));
$form->addHidden('act','select');
$form->addElement(form_makeListboxField(
'tpl',
$templates,
$conf['template'],
$this->getLang('template'),
'',
'',
array('class' => 'quickselect')
));
$form->addElement(form_makeButton(
'submit',
'',
$this->getLang('switch'),
array('name' => 'switch')
));
$out = '<div class="plugin_loadskin">';
$out .= $form->getForm();
$out .= '</div>';
return $out;
}
}