|
1
|
|
|
<?php |
|
2
|
|
|
// |
|
3
|
|
|
// ------------------------------------------------------------------------ // |
|
4
|
|
|
// XOOPS - PHP Content Management System // |
|
5
|
|
|
// Copyright (c) 2000-2016 XOOPS.org // |
|
6
|
|
|
// <https://xoops.org/> // |
|
7
|
|
|
// ------------------------------------------------------------------------ // |
|
8
|
|
|
// This program is free software; you can redistribute it and/or modify // |
|
9
|
|
|
// it under the terms of the GNU General Public License as published by // |
|
10
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
|
11
|
|
|
// (at your option) any later version. // |
|
12
|
|
|
// // |
|
13
|
|
|
// You may not change or alter any portion of this comment or credits // |
|
14
|
|
|
// of supporting developers from this source code or any supporting // |
|
15
|
|
|
// source code which is considered copyrighted (c) material of the // |
|
16
|
|
|
// original comment or credit authors. // |
|
17
|
|
|
// // |
|
18
|
|
|
// This program is distributed in the hope that it will be useful, // |
|
19
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
20
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
21
|
|
|
// GNU General Public License for more details. // |
|
22
|
|
|
// // |
|
23
|
|
|
// You should have received a copy of the GNU General Public License // |
|
24
|
|
|
// along with this program; if not, write to the Free Software // |
|
25
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
|
26
|
|
|
// ------------------------------------------------------------------------ // |
|
27
|
|
|
// Author: XOOPS Foundation // |
|
28
|
|
|
// URL: https://xoops.org/ // |
|
29
|
|
|
// Project: XOOPS Project // |
|
30
|
|
|
// ------------------------------------------------------------------------- // |
|
31
|
|
|
|
|
32
|
|
|
use Xmf\Request; |
|
|
|
|
|
|
33
|
|
|
use XoopsModules\Newbb; |
|
34
|
|
|
|
|
35
|
|
|
require_once __DIR__ . '/admin_header.php'; |
|
36
|
|
|
require_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
|
37
|
|
|
if (!class_exists('XoopsGroupPermForm')) { |
|
38
|
|
|
require_once $GLOBALS['xoops']->path('class/xoopsform/grouppermform.php'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* TODO: synchronize cascade permissions for multi-level |
|
43
|
|
|
*/ |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Add category navigation to forum casscade structure |
|
47
|
|
|
* <ol>Special points: |
|
48
|
|
|
* <li> Use negative values for category IDs to avoid conflict between category and forum |
|
49
|
|
|
* <li> Disabled checkbox for categories to avoid unnecessary permission items for categories in forum permission table |
|
50
|
|
|
* </ol> |
|
51
|
|
|
* |
|
52
|
|
|
* Note: this is a __patchy__ solution. We should have a more extensible and flexible group permission management: not only for data architecture but also for management interface |
|
53
|
|
|
*/ |
|
54
|
|
|
|
|
55
|
|
|
//$action = isset($_REQUEST['action']) ? strtolower($_REQUEST['action']) : ""; |
|
|
|
|
|
|
56
|
|
|
$action = strtolower(Request::getCmd('action', '')); |
|
57
|
|
|
$module_id = $xoopsModule->getVar('mid'); |
|
58
|
|
|
/** var Newbb\PermissionHandler $newbbpermHandler */ |
|
59
|
|
|
$newbbpermHandler = Newbb\Helper::getInstance()->getHandler('Permission'); |
|
60
|
|
|
$perms = $newbbpermHandler->getValidForumPerms(); |
|
61
|
|
|
|
|
62
|
|
|
switch ($action) { |
|
63
|
|
|
case 'template': |
|
64
|
|
|
xoops_cp_header(); |
|
|
|
|
|
|
65
|
|
|
$adminObject->displayNavigation(basename(__FILE__)); |
|
66
|
|
|
echo "<legend style='font-weight: bold; color: #900;'>" . _AM_NEWBB_PERM_ACTION . '</legend>'; |
|
67
|
|
|
$opform = new \XoopsSimpleForm(_AM_NEWBB_PERM_ACTION_HELP_TEMPLAT, 'actionform', 'admin_permissions.php', 'get'); |
|
|
|
|
|
|
68
|
|
|
$op_select = new \XoopsFormSelect('', 'action'); |
|
|
|
|
|
|
69
|
|
|
$op_select->setExtra('onchange="document.forms.actionform.submit()"'); |
|
70
|
|
|
$op_select->addOptionArray([ |
|
71
|
|
|
'no' => _SELECT, |
|
|
|
|
|
|
72
|
|
|
'template' => _AM_NEWBB_PERM_TEMPLATE, |
|
73
|
|
|
'apply' => _AM_NEWBB_PERM_TEMPLATEAPP, |
|
74
|
|
|
'default' => _AM_NEWBB_PERM_SETBYGROUP |
|
75
|
|
|
]); |
|
76
|
|
|
$opform->addElement($op_select); |
|
77
|
|
|
$opform->display(); |
|
78
|
|
|
|
|
79
|
|
|
$memberHandler = xoops_getHandler('member'); |
|
|
|
|
|
|
80
|
|
|
$glist = $memberHandler->getGroupList(); |
|
81
|
|
|
$elements = []; |
|
82
|
|
|
$perm_template = $newbbpermHandler->getTemplate(); |
|
83
|
|
|
foreach (array_keys($glist) as $i) { |
|
84
|
|
|
$selected = !empty($perm_template[$i]) ? array_keys($perm_template[$i]) : []; |
|
85
|
|
|
$ret_ele = '<tr align="left" valign="top"><td class="head">' . $glist[$i] . '</td>'; |
|
86
|
|
|
$ret_ele .= '<td class="even">'; |
|
87
|
|
|
$ret_ele .= '<table class="outer"><tr><td class="odd"><table><tr>'; |
|
88
|
|
|
$ii = 0; |
|
89
|
|
|
$option_ids = []; |
|
90
|
|
|
foreach ($perms as $perm) { |
|
91
|
|
|
++$ii; |
|
92
|
|
|
if (0 == $ii % 5) { |
|
93
|
|
|
$ret_ele .= '</tr><tr>'; |
|
94
|
|
|
} |
|
95
|
|
|
$checked = in_array('forum_' . $perm, $selected) ? ' checked' : ''; |
|
96
|
|
|
$option_id = $perm . '_' . $i; |
|
97
|
|
|
$option_ids[] = $option_id; |
|
98
|
|
|
$ret_ele .= '<td><input name="perms[' . $i . '][' . 'forum_' . $perm . ']" id="' . $option_id . '" onclick="" value="1" type="checkbox"' . $checked . '>' . constant('_AM_NEWBB_CAN_' . strtoupper($perm)) . '<br></td>'; |
|
99
|
|
|
} |
|
100
|
|
|
$ret_ele .= '</tr></table></td><td class="even">'; |
|
101
|
|
|
$ret_ele .= _ALL . ' <input id="checkall[' . $i . ']" type="checkbox" value="" onclick="var optionids = new Array(' . implode(', ', $option_ids) . '); xoopsCheckAllElements(optionids, \'checkall[' . $i . ']\')" />'; |
|
|
|
|
|
|
102
|
|
|
$ret_ele .= '</td></tr></table>'; |
|
103
|
|
|
$ret_ele .= '</td></tr>'; |
|
104
|
|
|
$elements[] = $ret_ele; |
|
105
|
|
|
} |
|
106
|
|
|
$tray = new \XoopsFormElementTray(''); |
|
|
|
|
|
|
107
|
|
|
$tray->addElement(new \XoopsFormHidden('action', 'template_save')); |
|
|
|
|
|
|
108
|
|
|
$tray->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
|
|
|
|
|
|
109
|
|
|
$tray->addElement(new \XoopsFormButton('', 'reset', _CANCEL, 'reset')); |
|
|
|
|
|
|
110
|
|
|
$ret = '<br><strong>' . _AM_NEWBB_PERM_TEMPLATE . '</strong><br>' . _AM_NEWBB_PERM_TEMPLATE_DESC . '<br>'; |
|
111
|
|
|
$ret .= "<form name='template' id='template' method='post'>\n<table width='100%' class='outer' cellspacing='1'>\n"; |
|
112
|
|
|
$ret .= implode("\n", $elements); |
|
113
|
|
|
$ret .= '<tr align="left" valign="top"><td class="head"></td><td class="even" style="text-align:center;">'; |
|
114
|
|
|
$ret .= $tray->render(); |
|
115
|
|
|
$ret .= '</td></tr>'; |
|
116
|
|
|
$ret .= '</table></form>'; |
|
117
|
|
|
echo $ret; |
|
118
|
|
|
require_once __DIR__ . '/admin_footer.php'; |
|
119
|
|
|
break; |
|
120
|
|
|
|
|
121
|
|
|
case 'template_save': |
|
122
|
|
|
// $res = $newbbpermHandler->setTemplate($_POST['perms'], $groupid = 0); |
|
|
|
|
|
|
123
|
|
|
$res = $newbbpermHandler->setTemplate(Request::getArray('perms', '', 'POST'), $groupid = 0); |
|
124
|
|
|
if ($res) { |
|
125
|
|
|
redirect_header('admin_permissions.php', 2, _AM_NEWBB_PERM_TEMPLATE_CREATED); |
|
|
|
|
|
|
126
|
|
|
} else { |
|
127
|
|
|
redirect_header('admin_permissions.php?action=template', 2, _AM_NEWBB_PERM_TEMPLATE_ERROR); |
|
128
|
|
|
} |
|
129
|
|
|
break; |
|
130
|
|
|
// exit(); |
|
131
|
|
|
|
|
132
|
|
|
case 'apply': |
|
133
|
|
|
$perm_template = $newbbpermHandler->getTemplate(); |
|
134
|
|
|
if (null === $perm_template) { |
|
135
|
|
|
redirect_header('admin_permissions.php?action=template', 2, _AM_NEWBB_PERM_TEMPLATE); |
|
136
|
|
|
} |
|
137
|
|
|
xoops_cp_header(); |
|
138
|
|
|
$adminObject->displayNavigation(basename(__FILE__)); |
|
139
|
|
|
echo "<legend style='font-weight: bold; color: #900;'>" . _AM_NEWBB_PERM_ACTION . '</legend>'; |
|
140
|
|
|
$opform = new \XoopsSimpleForm(_AM_NEWBB_PERM_ACTION_HELP_APPLY, 'actionform', 'admin_permissions.php', 'get'); |
|
141
|
|
|
$op_select = new \XoopsFormSelect('', 'action'); |
|
142
|
|
|
$op_select->setExtra('onchange="document.forms.actionform.submit()"'); |
|
143
|
|
|
$op_select->addOptionArray([ |
|
144
|
|
|
'no' => _SELECT, |
|
145
|
|
|
'template' => _AM_NEWBB_PERM_TEMPLATE, |
|
146
|
|
|
'apply' => _AM_NEWBB_PERM_TEMPLATEAPP |
|
147
|
|
|
]); |
|
148
|
|
|
$opform->addElement($op_select); |
|
149
|
|
|
$opform->display(); |
|
150
|
|
|
|
|
151
|
|
|
/** @var Newbb\CategoryHandler $categoryHandler */ |
|
152
|
|
|
$categoryHandler = Newbb\Helper::getInstance()->getHandler('Category'); |
|
153
|
|
|
$criteriaCategory = new \CriteriaCompo(new \Criteria('1', 1)); |
|
|
|
|
|
|
154
|
|
|
$criteriaCategory->setSort('cat_order'); |
|
155
|
|
|
$categories = $categoryHandler->getList($criteriaCategory); |
|
156
|
|
|
|
|
157
|
|
|
/** @var Newbb\ForumHandler $forumHandler */ |
|
158
|
|
|
$forumHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
|
159
|
|
|
$forums = $forumHandler->getTree(array_keys($categories), 0, 'all'); |
|
160
|
|
|
foreach (array_keys($forums) as $c) { |
|
161
|
|
|
$fm_options[-1 * $c - 1000] = ' '; |
|
162
|
|
|
$fm_options[-1 * $c] = '[' . $categories[$c] . ']'; |
|
163
|
|
|
foreach (array_keys($forums[$c]) as $f) { |
|
164
|
|
|
$fm_options[$f] = $forums[$c][$f]['prefix'] . $forums[$c][$f]['forum_name']; |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
unset($forums, $categories); |
|
168
|
|
|
|
|
169
|
|
|
$fmform = new \XoopsThemeForm(_AM_NEWBB_PERM_TEMPLATEAPP, 'fmform', 'admin_permissions.php', 'post', true); |
|
|
|
|
|
|
170
|
|
|
$fm_select = new \XoopsFormSelect(_AM_NEWBB_PERM_FORUMS, 'forums', null, 10, true); |
|
171
|
|
|
$fm_select->addOptionArray($fm_options); |
|
172
|
|
|
$fmform->addElement($fm_select); |
|
173
|
|
|
$tray = new \XoopsFormElementTray(''); |
|
174
|
|
|
$tray->addElement(new \XoopsFormHidden('action', 'apply_save')); |
|
175
|
|
|
$tray->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
|
176
|
|
|
$tray->addElement(new \XoopsFormButton('', 'reset', _CANCEL, 'reset')); |
|
177
|
|
|
$fmform->addElement($tray); |
|
178
|
|
|
$fmform->display(); |
|
179
|
|
|
require_once __DIR__ . '/admin_footer.php'; |
|
180
|
|
|
break; |
|
181
|
|
|
|
|
182
|
|
|
case 'apply_save': |
|
183
|
|
|
if (!Request::getArray('forums', '', 'POST')) { |
|
184
|
|
|
break; |
|
185
|
|
|
} |
|
186
|
|
|
foreach (Request::getArray('forums', '', 'POST') as $forum) { |
|
187
|
|
|
if ($forum < 1) { |
|
188
|
|
|
continue; |
|
189
|
|
|
} |
|
190
|
|
|
$newbbpermHandler->applyTemplate($forum, $module_id); |
|
191
|
|
|
} |
|
192
|
|
|
$cacheHelper = Newbb\Utility::cleanCache(); |
|
|
|
|
|
|
193
|
|
|
//$cacheHelper->delete('permission'); |
|
|
|
|
|
|
194
|
|
|
redirect_header('admin_permissions.php', 2, _AM_NEWBB_PERM_TEMPLATE_APPLIED); |
|
195
|
|
|
break; |
|
196
|
|
|
|
|
197
|
|
|
default: |
|
198
|
|
|
xoops_cp_header(); |
|
199
|
|
|
|
|
200
|
|
|
$categoryHandler = Newbb\Helper::getInstance()->getHandler('Category'); |
|
201
|
|
|
$criteriaCategory = new \CriteriaCompo(new \Criteria('1', 1)); |
|
202
|
|
|
$criteriaCategory->setSort('cat_order'); |
|
203
|
|
|
$categories = $categoryHandler->getList($criteriaCategory); |
|
204
|
|
|
|
|
205
|
|
|
if (0 === count($categories)) { |
|
206
|
|
|
redirect_header('admin_cat_manager.php', 2, _AM_NEWBB_CREATENEWCATEGORY); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
$forumHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
|
210
|
|
|
$forums = $forumHandler->getTree(array_keys($categories), 0, 'all'); |
|
211
|
|
|
|
|
212
|
|
|
if (0 === count($forums)) { |
|
213
|
|
|
redirect_header('admin_forum_manager.php', 2, _AM_NEWBB_CREATENEWFORUM); |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
$adminObject->displayNavigation(basename(__FILE__)); |
|
217
|
|
|
echo "<legend style='font-weight: bold; color: #900;'>" . _AM_NEWBB_PERM_ACTION . '</legend>'; |
|
218
|
|
|
$opform = new \XoopsSimpleForm(_AM_NEWBB_PERM_ACTION_HELP, 'actionform', 'admin_permissions.php', 'get'); |
|
219
|
|
|
$op_select = new \XoopsFormSelect('', 'action'); |
|
220
|
|
|
$op_select->setExtra('onchange="document.forms.actionform.submit()"'); |
|
221
|
|
|
$op_select->addOptionArray([ |
|
222
|
|
|
'no' => _SELECT, |
|
223
|
|
|
'template' => _AM_NEWBB_PERM_TEMPLATE, |
|
224
|
|
|
'apply' => _AM_NEWBB_PERM_TEMPLATEAPP, |
|
225
|
|
|
'default' => _AM_NEWBB_PERM_SETBYGROUP |
|
226
|
|
|
]); |
|
227
|
|
|
$opform->addElement($op_select); |
|
228
|
|
|
$opform->display(); |
|
229
|
|
|
|
|
230
|
|
|
$op_options = ['category' => _AM_NEWBB_CAT_ACCESS]; |
|
231
|
|
|
$fm_options = [ |
|
232
|
|
|
'category' => [ |
|
233
|
|
|
'title' => _AM_NEWBB_CAT_ACCESS, |
|
234
|
|
|
'item' => 'category_access', |
|
235
|
|
|
'desc' => '', |
|
236
|
|
|
'anonymous' => true |
|
237
|
|
|
] |
|
238
|
|
|
]; |
|
239
|
|
|
foreach ($perms as $perm) { |
|
240
|
|
|
$op_options[$perm] = constant('_AM_NEWBB_CAN_' . strtoupper($perm)); |
|
241
|
|
|
$fm_options[$perm] = [ |
|
242
|
|
|
'title' => constant('_AM_NEWBB_CAN_' . strtoupper($perm)), |
|
243
|
|
|
'item' => 'forum_' . $perm, |
|
244
|
|
|
'desc' => '', |
|
245
|
|
|
'anonymous' => true |
|
246
|
|
|
]; |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
$op_keys = array_keys($op_options); |
|
250
|
|
|
$op = strtolower(Request::getCmd('op', Request::getCmd('op', '', 'COOKIE'), 'GET')); |
|
251
|
|
|
if (empty($op)) { |
|
252
|
|
|
$op = $op_keys[0]; |
|
253
|
|
|
setcookie('op', isset($op_keys[1]) ? $op_keys[1] : ''); |
|
254
|
|
|
} elseif (false !== ($key = array_search($op, $op_keys))) { |
|
255
|
|
|
setcookie('op', isset($op_keys[$key + 1]) ? $op_keys[$key + 1] : ''); |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
$opform = new \XoopsSimpleForm('', 'opform', 'admin_permissions.php', 'get'); |
|
259
|
|
|
$op_select = new \XoopsFormSelect('', 'op', $op); |
|
260
|
|
|
$op_select->setExtra('onchange="document.forms.opform.submit()"'); |
|
261
|
|
|
$op_select->addOptionArray($op_options); |
|
262
|
|
|
$opform->addElement($op_select); |
|
263
|
|
|
$opform->display(); |
|
264
|
|
|
|
|
265
|
|
|
$perm_desc = ''; |
|
266
|
|
|
|
|
267
|
|
|
$form = new Newbb\GroupPermForm($fm_options[$op]['title'], $module_id, $fm_options[$op]['item'], $fm_options[$op]['desc'], 'admin/admin_permissions.php', $fm_options[$op]['anonymous']); |
|
|
|
|
|
|
268
|
|
|
|
|
269
|
|
|
$categoryHandler = Newbb\Helper::getInstance()->getHandler('Category'); |
|
270
|
|
|
$criteriaCategory = new \CriteriaCompo(new \Criteria('1', 1)); |
|
271
|
|
|
$criteriaCategory->setSort('cat_order'); |
|
272
|
|
|
$categories = $categoryHandler->getList($criteriaCategory); |
|
273
|
|
|
if ('category' === $op) { |
|
274
|
|
|
foreach (array_keys($categories) as $key) { |
|
275
|
|
|
$form->addItem($key, $categories[$key]); |
|
276
|
|
|
} |
|
277
|
|
|
unset($categories); |
|
278
|
|
|
} else { |
|
279
|
|
|
$forumHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
|
280
|
|
|
$forums = $forumHandler->getTree(array_keys($categories), 0, 'all'); |
|
281
|
|
|
if (count($forums) > 0) { |
|
282
|
|
|
foreach (array_keys($forums) as $c) { |
|
283
|
|
|
$key_c = -1 * $c; |
|
284
|
|
|
$form->addItem($key_c, '<strong>[' . $categories[$c] . ']</strong>'); |
|
285
|
|
|
foreach (array_keys($forums[$c]) as $f) { |
|
286
|
|
|
$pid = $forums[$c][$f]['parent_forum'] ?: $key_c; |
|
287
|
|
|
$form->addItem($f, $forums[$c][$f]['prefix'] . $forums[$c][$f]['forum_name'], $pid); |
|
288
|
|
|
} |
|
289
|
|
|
} |
|
290
|
|
|
} |
|
291
|
|
|
unset($forums, $categories); |
|
292
|
|
|
} |
|
293
|
|
|
$form->display(); |
|
294
|
|
|
echo '<fieldset>'; |
|
295
|
|
|
echo '<legend> ' . _MI_NEWBB_ADMENU_PERMISSION . ' </legend>'; |
|
296
|
|
|
echo _AM_NEWBB_HELP_PERMISSION_TAB; |
|
297
|
|
|
echo '</fieldset>'; |
|
298
|
|
|
// Since we can not control the permission update, a trick is used here |
|
299
|
|
|
/** var Newbb\PermissionHandler $permissionHandler */ |
|
300
|
|
|
$permissionHandler = Newbb\Helper::getInstance()->getHandler('Permission'); |
|
301
|
|
|
$permissionHandler->createPermData(); |
|
302
|
|
|
$cacheHelper = Newbb\Utility::cleanCache(); |
|
|
|
|
|
|
303
|
|
|
//$cacheHelper->delete('permission'); |
|
|
|
|
|
|
304
|
|
|
require_once __DIR__ . '/admin_footer.php'; |
|
305
|
|
|
break; |
|
306
|
|
|
} |
|
307
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths