-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadmin.php
163 lines (146 loc) · 5.39 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
use dokuwiki\plugin\structpublish\meta\Assignments;
use dokuwiki\plugin\structpublish\meta\Constants;
/**
* DokuWiki Plugin structpublish (Admin Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Anna Dabrowska <[email protected]>
*/
class admin_plugin_structpublish extends DokuWiki_Admin_Plugin
{
/**
* @return int sort number in admin menu
*/
public function getMenuSort()
{
return 555;
}
/**
* @return bool true if only access for superuser, false is for superusers and moderators
*/
public function forAdminOnly()
{
return false;
}
/**
* Based on struct pattern assignments
*/
public function handle()
{
global $INPUT;
global $ID;
try {
$assignments = Assignments::getInstance();
} catch (Exception $e) {
msg($e->getMessage(), -1);
return;
}
if ($INPUT->str('action') && $INPUT->arr('assignment') && checkSecurityToken()) {
$assignment = $INPUT->arr('assignment');
if (!blank($assignment['pattern']) && !blank($assignment['status'])) {
if ($INPUT->str('action') === 'delete') {
$ok = $assignments->removePattern(
$assignment['pattern'],
$assignment['user'],
$assignment['status']
);
if (!$ok) {
msg('failed to remove pattern', -1);
}
} elseif ($INPUT->str('action') === 'add') {
if ($assignment['pattern'][0] == '/') {
if (@preg_match($assignment['pattern'], null) === false) {
msg('Invalid regular expression. Pattern not saved', -1);
} else {
$ok = $assignments->addPattern(
$assignment['pattern'],
$assignment['user'],
$assignment['status']
);
if (!$ok) {
msg('failed to add pattern', -1);
}
}
} else {
$ok = $assignments->addPattern(
$assignment['pattern'],
$assignment['user'],
$assignment['status']
);
if (!$ok) {
msg('failed to add pattern', -1);
}
}
}
}
send_redirect(wl($ID, array('do' => 'admin', 'page' => 'structpublish'), true, '&'));
}
}
/**
* Render HTML output
*/
public function html()
{
ptln('<h1>' . $this->getLang('menu') . '</h1>');
global $ID;
try {
$assignments = Assignments::getInstance();
} catch (Exception $e) {
msg($e->getMessage(), -1);
return;
}
$list = $assignments->getAllPatterns();
echo '<form action="' . wl($ID) . '" action="post">';
echo '<input type="hidden" name="do" value="admin" />';
echo '<input type="hidden" name="page" value="structpublish" />';
echo '<input type="hidden" name="sectok" value="' . getSecurityToken() . '" />';
echo '<table class="inline">';
// header
echo '<tr>';
echo '<th>' . $this->getLang('assign_pattern') . '</th>';
echo '<th>' . $this->getLang('assign_status') . '</th>';
echo '<th>' . $this->getLang('assign_user') . '</th>';
echo '<th></th>';
echo '</tr>';
// existing assignments
foreach ($list as $assignment) {
$pattern = $assignment['pattern'];
$status = $assignment['status'];
$user = $assignment['user'];
$link = wl(
$ID,
[
'do' => 'admin',
'page' => 'structpublish',
'action' => 'delete',
'sectok' => getSecurityToken(),
'assignment[status]' => $status,
'assignment[pattern]' => $pattern,
'assignment[user]' => $user,
]
);
echo '<tr>';
echo '<td>' . hsc($pattern) . '</td>';
echo '<td>' . hsc($status) . '</td>';
echo '<td>' . hsc($user) . '</td>';
echo '<td><a class="deleteSchema" href="' . $link . '">' . $this->getLang('assign_del') . '</a></td>';
echo '</tr>';
}
// new assignment form
echo '<tr>';
echo '<td><input type="text" name="assignment[pattern]" /></td>';
echo '<td>';
echo '<select name="assignment[status]">';
foreach ([Constants::ACTION_APPROVE, Constants::ACTION_PUBLISH] as $status) {
echo '<option value="' . $status . '">' . $status . '</option>';
}
echo '</select>';
echo '</td>';
echo '<td><input type="text" name="assignment[user]" /></td>';
echo '<td><button type="submit" name="action" value="add">' . $this->getLang('assign_add') . '</button></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
}
}