-
Notifications
You must be signed in to change notification settings - Fork 7
/
admin.php
108 lines (95 loc) · 3.04 KB
/
admin.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
106
107
108
<?php
use dokuwiki\Extension\AdminPlugin;
/**
* DokuWiki Plugin farmer (Admin Component)
*
* This is the main admin page. It displays the tabs and then loads the sub components
* according to the selected tab
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Michael Große <[email protected]>
* @author Andreas Gohr <[email protected]>
*/
class admin_plugin_farmer extends AdminPlugin
{
/** @var helper_plugin_farmer */
protected $helper;
/** @var array The available pages for the current user in the current wiki */
protected $pages;
/** @var string The currently selected page */
protected $page;
/** @var AdminPlugin the plugin to use for the current page */
protected $adminplugin;
/**
* @return bool we're available for managers and admins
*/
public function forAdminOnly()
{
return false;
}
/**
* Initialize current page
*/
public function __construct()
{
global $INPUT;
$this->helper = plugin_load('helper', 'farmer');
// set available pages depending on user and animal
$isanimal = (bool) $this->helper->getAnimal();
if ($isanimal || !auth_isadmin()) {
$this->pages = ['info'];
} elseif (!$this->helper->checkFarmSetup()) {
$this->pages = ['setup'];
} else {
$this->pages = ['info', 'config', 'new', 'plugins', 'delete'];
}
// make sure current page requested is available
$this->page = $INPUT->str('sub');
if (!in_array($this->page, $this->pages)) {
$this->page = $this->pages[0];
}
// load the sub component
$this->adminplugin = plugin_load('admin', 'farmer_' . $this->page);
if (!$this->adminplugin) nice_die('Something went wrong loading the plugin component for ' . hsc($this->page));
}
/**
* handle user request
*/
public function handle()
{
$this->adminplugin->handle();
}
/**
* output appropriate tab
*/
public function html()
{
global $ID;
echo '<div id="plugin__farmer_admin">';
echo '<h1>' . $this->getLang('menu') . '</h1>';
echo '<ul class="tabs" id="plugin__farmer_tabs">';
foreach ($this->pages as $page) {
$link = wl($ID, ['do' => 'admin', 'page' => 'farmer', 'sub' => $page]);
$class = ($page == $this->page) ? 'active' : '';
echo '<li class="' . $class . '"><a href="' . $link . '">' . $this->getLang('tab_' . $page) . '</a></li>';
}
echo '</ul>';
echo '<div class="panelHeader">';
echo $this->locale_xhtml('tab_' . $this->page);
echo '</div>';
echo '<div class="panelMain">';
$this->adminplugin->html();
echo '</div>';
echo '<div class="panelFooter">';
echo $this->locale_xhtml('tab_' . $this->page . '_help');
echo '</div>';
echo '</div>';
}
/**
* @return int
*/
public function getMenuSort()
{
return 42;
}
}