1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Module: SmartFAQ |
5
|
|
|
* Author: The SmartFactory <www.smartfactory.ca> |
6
|
|
|
* Licence: GNU |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
// ------------------------------------------------------------------------- // |
10
|
|
|
// myblocksadmin.php // |
11
|
|
|
// - XOOPS block admin for each modules - // |
12
|
|
|
// GIJOE <http://www.peak.ne.jp> // |
13
|
|
|
// ------------------------------------------------------------------------- // |
14
|
|
|
|
15
|
|
|
use XoopsModules\Smartfaq; |
16
|
|
|
use XoopsModules\Smartfaq\Constants; |
17
|
|
|
|
18
|
|
|
require_once __DIR__ . '/admin_header.php'; |
19
|
|
|
xoops_cp_header(); |
20
|
|
|
|
21
|
|
|
$helper->loadLanguage('admin'); |
22
|
|
|
|
23
|
|
|
//require_once __DIR__ . '/mygrouppermform.php'; |
24
|
|
|
require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; |
25
|
|
|
//require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/include/functions.php'; |
26
|
|
|
|
27
|
|
|
$xoops_system_path = XOOPS_ROOT_PATH . '/modules/system'; |
28
|
|
|
|
29
|
|
|
// language files |
30
|
|
|
$language = $xoopsConfig['language']; |
31
|
|
|
if (!file_exists("$xoops_system_path/language/$language/admin/blocksadmin.php")) { |
32
|
|
|
$language = 'english'; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
// to prevent from notice that constants already defined |
36
|
|
|
$error_reporting_level = error_reporting(0); |
37
|
|
|
require_once dirname(dirname(__DIR__)) . '/system/constants.php'; |
38
|
|
|
require_once __DIR__ . "/../../language/$language/admin.php"; |
39
|
|
|
require_once __DIR__ . "/../../language/$language/admin/blocksadmin.php"; |
40
|
|
|
//require_once dirname(__DIR__) . '/include/functions.php'; |
41
|
|
|
error_reporting($error_reporting_level); |
42
|
|
|
|
43
|
|
|
$group_defs = file("$xoops_system_path/language/$language/admin/groups.php"); |
44
|
|
|
foreach ($group_defs as $def) { |
45
|
|
|
if (false !== mb_strpos($def, '_AM_ACCESSRIGHTS') || false !== mb_strpos($def, '_AM_ACTIVERIGHTS')) { |
46
|
|
|
eval($def); |
|
|
|
|
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
// check $xoopsModule |
51
|
|
|
if (!is_object($xoopsModule)) { |
52
|
|
|
redirect_header(XOOPS_URL . '/user.php', 1, _NOPERM); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
// set target_module if specified by $_GET['dirname'] |
56
|
|
|
/** @var \XoopsModuleHandler $moduleHandler */ |
57
|
|
|
$moduleHandler = xoops_getHandler('module'); |
58
|
|
|
if (!empty($_GET['dirname'])) { |
59
|
|
|
$target_module = $moduleHandler->getByDirname($_GET['dirname']); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
if (!empty($target_module) && is_object($target_module)) { |
63
|
|
|
// specified by dirname |
64
|
|
|
$target_mid = $target_module->getVar('mid'); |
65
|
|
|
$target_mname = $target_module->getVar('name') . ' ' . sprintf('(%2.2f)', $target_module->getVar('version') / 100.0); |
66
|
|
|
$query4redirect = '?dirname=' . urlencode(strip_tags($_GET['dirname'])); |
67
|
|
|
} elseif (\Xmf\Request::hasVar('mid', 'GET') && 0 == $_GET['mid'] || 'blocksadmin' === $xoopsModule->getVar('dirname')) { |
|
|
|
|
68
|
|
|
$target_mid = 0; |
69
|
|
|
$target_mname = ''; |
70
|
|
|
$query4redirect = '?mid=0'; |
71
|
|
|
} else { |
72
|
|
|
$target_mid = $xoopsModule->getVar('mid'); |
73
|
|
|
$target_mname = $xoopsModule->getVar('name'); |
74
|
|
|
$query4redirect = ''; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
// check access right (needs system_admin of BLOCK) |
78
|
|
|
$grouppermHandler = xoops_getHandler('groupperm'); |
79
|
|
|
if (!$grouppermHandler->checkRight('system_admin', XOOPS_SYSTEM_BLOCK, $xoopsUser->getGroups())) { |
|
|
|
|
80
|
|
|
redirect_header(XOOPS_URL . '/user.php', 1, _NOPERM); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
// get blocks owned by the module (Imported from xoopsblock.php then modified) |
84
|
|
|
$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
85
|
|
|
$sql = 'SELECT * FROM ' . $db->prefix('newblocks') . " WHERE mid='$target_mid' ORDER BY visible DESC,side,weight"; |
86
|
|
|
$result = $db->query($sql); |
87
|
|
|
$block_arr = []; |
88
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
89
|
|
|
$block_arr[] = new \XoopsBlock($myrow); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
function list_blocks() |
93
|
|
|
{ |
94
|
|
|
global $query4redirect, $block_arr; |
95
|
|
|
|
96
|
|
|
// cachetime options |
97
|
|
|
$cachetimes = [ |
98
|
|
|
'0' => _NOCACHE, |
99
|
|
|
'30' => sprintf(_SECONDS, 30), |
100
|
|
|
'60' => _MINUTE, |
101
|
|
|
'300' => sprintf(_MINUTES, 5), |
102
|
|
|
'1800' => sprintf(_MINUTES, 30), |
103
|
|
|
'3600' => _HOUR, |
104
|
|
|
'18000' => sprintf(_HOURS, 5), |
105
|
|
|
'86400' => _DAY, |
106
|
|
|
'259200' => sprintf(_DAYS, 3), |
107
|
|
|
'604800' => _WEEK, |
108
|
|
|
'2592000' => _MONTH, |
109
|
|
|
]; |
110
|
|
|
|
111
|
|
|
// displaying TH |
112
|
|
|
Smartfaq\Utility::collapsableBar('toptable', 'toptableicon'); |
113
|
|
|
echo "<img id='toptableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt=''></a> " . _AM_SF_BLOCKS . '</h3>'; |
|
|
|
|
114
|
|
|
echo "<div id='toptable'>"; |
115
|
|
|
echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . _AM_SF_BLOCKSTXT . '</span>'; |
116
|
|
|
|
117
|
|
|
echo " |
118
|
|
|
<form action='admin.php' name='blockadmin' method='post'> |
119
|
|
|
<table width='100%' class='outer' cellpadding='4' cellspacing='1'> |
120
|
|
|
<tr valign='middle'> |
121
|
|
|
<th>" . _AM_TITLE . "</th> |
122
|
|
|
<th align='center' nowrap='nowrap'>" . _AM_SF_POSITION . "</th> |
123
|
|
|
<th align='center'>" . _AM_WEIGHT . "</th> |
124
|
|
|
<th align='center'>" . _AM_VISIBLEIN . "</th> |
125
|
|
|
<th align='center'>" . _AM_BCACHETIME . "</th> |
126
|
|
|
<th align='center'>" . _AM_ACTION . "</th> |
127
|
|
|
</tr>\n"; |
128
|
|
|
|
129
|
|
|
// blocks displaying loop |
130
|
|
|
$class = 'even'; |
131
|
|
|
$block_configs = get_block_configs(); |
132
|
|
|
foreach (array_keys($block_arr) as $i) { |
133
|
|
|
$sseln = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = $ssel5 = $ssel6 = $ssel7 = ''; |
|
|
|
|
134
|
|
|
$scoln = $scol0 = $scol1 = $scol2 = $scol3 = $scol4 = $ssel5 = $ssel6 = $ssel7 = ''; |
|
|
|
|
135
|
|
|
|
136
|
|
|
$weight = $block_arr[$i]->getVar('weight'); |
137
|
|
|
$title = $block_arr[$i]->getVar('title'); |
138
|
|
|
$name = $block_arr[$i]->getVar('name'); |
139
|
|
|
$bcachetime = $block_arr[$i]->getVar('bcachetime'); |
140
|
|
|
$bid = $block_arr[$i]->getVar('bid'); |
141
|
|
|
|
142
|
|
|
// visible and side |
143
|
|
|
if (1 != $block_arr[$i]->getVar('visible')) { |
144
|
|
|
$sseln = ' checked'; |
145
|
|
|
$scoln = '#FF9966'; |
146
|
|
|
} else { |
147
|
|
|
switch ($block_arr[$i]->getVar('side')) { |
148
|
|
|
default: |
149
|
|
|
case XOOPS_SIDEBLOCK_LEFT: |
150
|
|
|
$ssel0 = ' checked'; |
151
|
|
|
$scol0 = '#00FF00'; |
152
|
|
|
break; |
153
|
|
|
case XOOPS_SIDEBLOCK_RIGHT: |
154
|
|
|
$ssel1 = ' checked'; |
155
|
|
|
$scol1 = '#00FF00'; |
156
|
|
|
break; |
157
|
|
|
case XOOPS_CENTERBLOCK_LEFT: |
158
|
|
|
$ssel2 = ' checked'; |
159
|
|
|
$scol2 = '#00FF00'; |
160
|
|
|
break; |
161
|
|
|
case XOOPS_CENTERBLOCK_RIGHT: |
162
|
|
|
$ssel4 = ' checked'; |
163
|
|
|
$scol4 = '#00FF00'; |
164
|
|
|
break; |
165
|
|
|
case XOOPS_CENTERBLOCK_CENTER: |
166
|
|
|
$ssel3 = ' checked'; |
167
|
|
|
$scol3 = '#00FF00'; |
168
|
|
|
break; |
169
|
|
|
case XOOPS_CENTERBLOCK_BOTTOMLEFT: |
170
|
|
|
$ssel5 = ' checked'; |
171
|
|
|
$scol5 = '#00FF00'; |
|
|
|
|
172
|
|
|
break; |
173
|
|
|
case XOOPS_CENTERBLOCK_BOTTOMRIGHT: |
174
|
|
|
$ssel6 = ' checked'; |
175
|
|
|
$scol6 = '#00FF00'; |
|
|
|
|
176
|
|
|
break; |
177
|
|
|
case XOOPS_CENTERBLOCK_BOTTOM: |
178
|
|
|
$ssel7 = ' checked'; |
179
|
|
|
$scol7 = '#00FF00'; |
|
|
|
|
180
|
|
|
break; |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
// bcachetime |
185
|
|
|
$cachetime_options = ''; |
186
|
|
|
foreach ($cachetimes as $cachetime => $cachetime_name) { |
187
|
|
|
if ($bcachetime == $cachetime) { |
188
|
|
|
$cachetime_options .= "<option value='$cachetime' selected>$cachetime_name</option>\n"; |
189
|
|
|
} else { |
190
|
|
|
$cachetime_options .= "<option value='$cachetime'>$cachetime_name</option>\n"; |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
// target modules |
195
|
|
|
$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
196
|
|
|
$result = $db->query('SELECT module_id FROM ' . $db->prefix('block_module_link') . " WHERE block_id='$bid'"); |
197
|
|
|
$selected_mids = []; |
198
|
|
|
while (list($selected_mid) = $db->fetchRow($result)) { |
199
|
|
|
$selected_mids[] = (int)$selected_mid; |
200
|
|
|
} |
201
|
|
|
/** @var \XoopsModuleHandler $moduleHandler */ |
202
|
|
|
$moduleHandler = xoops_getHandler('module'); |
203
|
|
|
$criteria = new \CriteriaCompo(new \Criteria('hasmain', 1)); |
204
|
|
|
$criteria->add(new \Criteria('isactive', 1)); |
205
|
|
|
$module_list = $moduleHandler->getList($criteria); |
206
|
|
|
$module_list[-1] = _AM_TOPPAGE; |
207
|
|
|
$module_list[0] = _AM_ALLPAGES; |
208
|
|
|
ksort($module_list); |
209
|
|
|
$module_options = ''; |
210
|
|
|
foreach ($module_list as $mid => $mname) { |
211
|
|
|
if (in_array($mid, $selected_mids)) { |
212
|
|
|
$module_options .= "<option value='$mid' selected>$mname</option>\n"; |
213
|
|
|
} else { |
214
|
|
|
$module_options .= "<option value='$mid'>$mname</option>\n"; |
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
// delete link if it is cloned block |
219
|
|
|
if ('D' === $block_arr[$i]->getVar('block_type') || 'C' === $block_arr[$i]->getVar('block_type')) { |
220
|
|
|
$delete_link = "<br><a href='admin.php?fct=blocksadmin&op=delete&bid=$bid'>" . _DELETE . '</a>'; |
221
|
|
|
} else { |
222
|
|
|
$delete_link = ''; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
// clone link if it is marked as cloneable block |
226
|
|
|
// $modversion['blocks'][n]['can_clone'] |
227
|
|
|
if ('D' === $block_arr[$i]->getVar('block_type') || 'C' === $block_arr[$i]->getVar('block_type')) { |
228
|
|
|
$can_clone = true; |
229
|
|
|
} else { |
230
|
|
|
$can_clone = false; |
231
|
|
|
foreach ($block_configs as $bconf) { |
232
|
|
|
if ($block_arr[$i]->getVar('show_func') == $bconf['show_func'] |
233
|
|
|
&& $block_arr[$i]->getVar('func_file') == $bconf['file'] |
234
|
|
|
&& (empty($bconf['template']) |
235
|
|
|
|| $block_arr[$i]->getVar('template') == $bconf['template'])) { |
236
|
|
|
if (!empty($bconf['can_clone'])) { |
237
|
|
|
$can_clone = true; |
238
|
|
|
} |
239
|
|
|
} |
240
|
|
|
} |
241
|
|
|
} |
242
|
|
|
if ($can_clone) { |
243
|
|
|
$clone_link = "<br><a href='admin.php?fct=blocksadmin&op=clone&bid=$bid'>" . _CLONE . '</a>'; |
244
|
|
|
} else { |
245
|
|
|
$clone_link = ''; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
// displaying part |
249
|
|
|
echo " |
250
|
|
|
<tr valign='middle'> |
251
|
|
|
<td class='$class'> |
252
|
|
|
$name |
253
|
|
|
<br> |
254
|
|
|
<input type='text' name='title[$bid]' value='$title' size='20'> |
255
|
|
|
</td> |
256
|
|
|
<td class='$class' align='center' nowrap='nowrap' width='125px'> |
257
|
|
|
<div align='center' > |
258
|
|
|
<input type='radio' name='side[$bid]' value='" . XOOPS_CENTERBLOCK_LEFT . "'$ssel2 > |
259
|
|
|
<input type='radio' name='side[$bid]' value='" . XOOPS_CENTERBLOCK_CENTER . "'$ssel3 > |
260
|
|
|
<input type='radio' name='side[$bid]' value='" . XOOPS_CENTERBLOCK_RIGHT . "'$ssel4 > |
261
|
|
|
</div> |
262
|
|
|
<div> |
263
|
|
|
<span style='float:right;'><input type='radio' name='side[$bid]' value='" . XOOPS_SIDEBLOCK_RIGHT . "'$ssel1 ></span> |
264
|
|
|
<div align='left'><input type='radio' name='side[$bid]' value='" . XOOPS_SIDEBLOCK_LEFT . "'$ssel0 ></div> |
265
|
|
|
</div> |
266
|
|
|
<div align='center'> |
267
|
|
|
<input type='radio' name='side[$bid]' value='" . XOOPS_CENTERBLOCK_BOTTOMLEFT . "'$ssel5 > |
268
|
|
|
<input type='radio' name='side[$bid]' value='" . XOOPS_CENTERBLOCK_BOTTOM . "'$ssel7 > |
269
|
|
|
<input type='radio' name='side[$bid]' value='" . XOOPS_CENTERBLOCK_BOTTOMRIGHT . "'$ssel6 > |
270
|
|
|
</div> |
271
|
|
|
<br> |
272
|
|
|
<div style='float:left;width:30%;'> </div> |
273
|
|
|
<div style='float:left;background-color:$scoln;'> |
274
|
|
|
<input type='radio' name='side[$bid]' value='-1'$sseln> |
275
|
|
|
</div> |
276
|
|
|
<div style='float:left;'>" . _NONE . "</div> |
277
|
|
|
</td> |
278
|
|
|
<td class='$class' align='center'> |
279
|
|
|
<input type='text' name=weight[$bid] value='$weight' size='3' maxlength='5' style='text-align:right;' > |
280
|
|
|
</td> |
281
|
|
|
<td class='$class' align='center'> |
282
|
|
|
<select name='bmodule[$bid][]' size='5' multiple='multiple'> |
283
|
|
|
$module_options |
284
|
|
|
</select> |
285
|
|
|
</td> |
286
|
|
|
<td class='$class' align='center'> |
287
|
|
|
<select name='bcachetime[$bid]' size='1'> |
288
|
|
|
$cachetime_options |
289
|
|
|
</select> |
290
|
|
|
</td> |
291
|
|
|
<td class='$class' align='right'> |
292
|
|
|
<a href='admin.php?fct=blocksadmin&op=edit&bid=$bid'>" . _EDIT . "</a>{$delete_link}{$clone_link} |
293
|
|
|
<input type='hidden' name='bid[$bid]' value='$bid'> |
294
|
|
|
</td> |
295
|
|
|
</tr>\n"; |
296
|
|
|
|
297
|
|
|
$class = ('even' === $class) ? 'odd' : 'even'; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
echo "<tr> |
301
|
|
|
<td class='foot' align='center' colspan='6'> |
302
|
|
|
<input type='hidden' name='query4redirect' value='$query4redirect' > |
303
|
|
|
<input type='hidden' name='fct' value='blocksadmin'> |
304
|
|
|
<input type='hidden' name='op' value='order'> |
305
|
|
|
" . $GLOBALS['xoopsSecurity']->getTokenHTML('myblocksadmin') . " |
306
|
|
|
<input type='submit' name='submit' value='" . _SUBMIT . "'> |
307
|
|
|
</td> |
308
|
|
|
</tr> |
309
|
|
|
</table> |
310
|
|
|
</form>\n"; |
311
|
|
|
echo '</div>'; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* @return array |
316
|
|
|
*/ |
317
|
|
|
function get_block_configs() |
318
|
|
|
{ |
319
|
|
|
$error_reporting_level = error_reporting(0); |
320
|
|
|
if (preg_match('/^[.0-9a-zA-Z_-]+$/', @$_GET['dirname'])) { |
321
|
|
|
require_once dirname(dirname(__DIR__)) . '/' . $_GET['dirname'] . '/xoops_version.php'; |
322
|
|
|
} else { |
323
|
|
|
require_once dirname(__DIR__) . '/xoops_version.php'; |
324
|
|
|
} |
325
|
|
|
error_reporting($error_reporting_level); |
326
|
|
|
if (empty($modversion['blocks'])) { |
|
|
|
|
327
|
|
|
return []; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
return $modversion['blocks']; |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
function list_groups() |
334
|
|
|
{ |
335
|
|
|
global $target_mid, $target_mname, $block_arr; |
336
|
|
|
lx_collapsableBar('groups', 'groupIcon'); |
|
|
|
|
337
|
|
|
echo "<img onclick=\"toggle('groups'); toggleIcon('groupsIcon');\" id='groupsIcon' src='" . XOOPS_URL . "/modules/lexikon/assets/images/close12.gif' alt='' ></a> " . _MD_AM_ADGS . ' <br>'; |
|
|
|
|
338
|
|
|
echo "<div id='groups' style='float:left; width:100%;'>"; |
339
|
|
|
$item_list = []; |
340
|
|
|
foreach (array_keys($block_arr) as $i) { |
341
|
|
|
$item_list[$block_arr[$i]->getVar('bid')] = $block_arr[$i]->getVar('title'); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
$form = new Smartfaq\GroupPermForm(_MD_AM_ADGS, 1, 'block_read', ''); |
345
|
|
|
if ($target_mid > 1) { |
346
|
|
|
$form->addAppendix('module_admin', $target_mid, $target_mname . ' ' . _AM_ACTIVERIGHTS); |
347
|
|
|
$form->addAppendix('module_read', $target_mid, $target_mname . ' ' . _AM_ACCESSRIGHTS); |
348
|
|
|
} |
349
|
|
|
foreach ($item_list as $item_id => $item_name) { |
350
|
|
|
$form->addItem($item_id, $item_name); |
351
|
|
|
} |
352
|
|
|
echo $form->render(); |
353
|
|
|
echo '</div>'; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
if (!empty($_POST['submit'])) { |
357
|
|
|
if (!$GLOBALS['xoopsSecurity']->check(true, $_REQUEST['myblocksadmin'])) { |
358
|
|
|
redirect_header(XOOPS_URL . '/', 3, $GLOBALS['xoopsSecurity']->getErrors()); |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
require_once __DIR__ . '/mygroupperm.php'; |
362
|
|
|
redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/admin/myblocksadmin.php$query4redirect", 1, _MD_AM_DBUPDATED); |
|
|
|
|
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
xoops_cp_header(); |
366
|
|
|
require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/admin/functions.php'; |
367
|
|
|
|
368
|
|
|
if (!empty($block_arr)) { |
369
|
|
|
echo "<h4 style='text-align:left;'>$target_mname : " . _AM_BADMIN . "</h4>\n"; |
370
|
|
|
list_blocks(); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
list_groups(); |
374
|
|
|
xoops_cp_footer(); |
375
|
|
|
|