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