1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Publisher\Common; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* You may not change or alter any portion of this comment or credits |
7
|
|
|
* of supporting developers from this source code or any supporting source code |
8
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
9
|
|
|
* |
10
|
|
|
* |
11
|
|
|
* @category Module |
12
|
|
|
* @author XOOPS Development Team |
13
|
|
|
* @copyright XOOPS Project |
14
|
|
|
* @link https://xoops.org |
15
|
|
|
* @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
use Xmf\Request; |
19
|
|
|
|
20
|
|
|
//use XoopsModules\Tag\{ |
21
|
|
|
// Helper |
22
|
|
|
//}; |
23
|
|
|
|
24
|
|
|
//require __DIR__ . '/admin_header.php'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* class Blocksadmin |
28
|
|
|
*/ |
29
|
|
|
class Blocksadmin |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @var \XoopsMySQLDatabase|null |
33
|
|
|
*/ |
34
|
|
|
public $db; |
35
|
|
|
/** |
36
|
|
|
* @var \XoopsModules\Tag\Helper |
37
|
|
|
*/ |
38
|
|
|
public $helper; |
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
public $moduleDirName; |
43
|
|
|
/** |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
public $moduleDirNameUpper; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Blocksadmin constructor. |
50
|
|
|
*/ |
51
|
|
|
public function __construct(?\XoopsDatabase $db, \Xmf\Module\Helper $helper) |
52
|
|
|
{ |
53
|
|
|
if (null === $db) { |
54
|
|
|
$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
55
|
|
|
} |
56
|
|
|
$this->db = $db; |
57
|
|
|
$this->helper = $helper; |
|
|
|
|
58
|
|
|
$this->moduleDirName = \basename(\dirname(__DIR__, 2)); |
59
|
|
|
$this->moduleDirNameUpper = \mb_strtoupper($this->moduleDirName); |
60
|
|
|
\xoops_loadLanguage('admin', 'system'); |
61
|
|
|
\xoops_loadLanguage('admin/blocksadmin', 'system'); |
62
|
|
|
\xoops_loadLanguage('admin/groups', 'system'); |
63
|
|
|
\xoops_loadLanguage('common', $this->moduleDirName); |
64
|
|
|
\xoops_loadLanguage('blocksadmin', $this->moduleDirName); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function listBlocks(): void |
68
|
|
|
{ |
69
|
|
|
global $xoopsModule, $pathIcon16; |
70
|
|
|
require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
71
|
|
|
// xoops_loadLanguage('admin', 'system'); |
72
|
|
|
// xoops_loadLanguage('admin/blocksadmin', 'system'); |
73
|
|
|
// xoops_loadLanguage('admin/groups', 'system'); |
74
|
|
|
// xoops_loadLanguage('common', $moduleDirName); |
75
|
|
|
// xoops_loadLanguage('blocks', $moduleDirName); |
76
|
|
|
|
77
|
|
|
/** @var \XoopsModuleHandler $moduleHandler */ |
78
|
|
|
$moduleHandler = \xoops_getHandler('module'); |
79
|
|
|
/** @var \XoopsMemberHandler $memberHandler */ |
80
|
|
|
$memberHandler = \xoops_getHandler('member'); |
81
|
|
|
/** @var \XoopsGroupPermHandler $grouppermHandler */ |
82
|
|
|
$grouppermHandler = \xoops_getHandler('groupperm'); |
83
|
|
|
$groups = $memberHandler->getGroups(); |
84
|
|
|
$criteria = new \CriteriaCompo(new \Criteria('hasmain', '1')); |
85
|
|
|
$criteria->add(new \Criteria('isactive', '1')); |
86
|
|
|
$moduleList = $moduleHandler->getList($criteria); |
87
|
|
|
$moduleList[-1] = \_AM_SYSTEM_BLOCKS_TOPPAGE; |
88
|
|
|
$moduleList[0] = \_AM_SYSTEM_BLOCKS_ALLPAGES; |
89
|
|
|
\ksort($moduleList); |
90
|
|
|
echo " |
91
|
|
|
<h4 style='text-align:left;'>" . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</h4>'; |
92
|
|
|
echo "<form action='" . $_SERVER['SCRIPT_NAME'] . "' name='blockadmin' method='post'>"; |
93
|
|
|
echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
94
|
|
|
echo "<table width='100%' class='outer' cellpadding='4' cellspacing='1'> |
95
|
|
|
<tr valign='middle'><th align='center'>" |
96
|
|
|
. \_AM_SYSTEM_BLOCKS_TITLE |
97
|
|
|
. "</th><th align='center' nowrap='nowrap'>" |
98
|
|
|
. \constant('CO_' . $this->moduleDirNameUpper . '_' . 'SIDE') |
99
|
|
|
. '<br>' |
100
|
|
|
. _LEFT |
101
|
|
|
. '-' |
102
|
|
|
. _CENTER |
103
|
|
|
. '-' |
104
|
|
|
. _RIGHT |
105
|
|
|
. "</th><th align='center'>" |
106
|
|
|
. \constant( |
107
|
|
|
'CO_' . $this->moduleDirNameUpper . '_' . 'WEIGHT' |
108
|
|
|
) |
109
|
|
|
. "</th><th align='center'>" |
110
|
|
|
. \constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLE') |
111
|
|
|
. "</th><th align='center'>" |
112
|
|
|
. \_AM_SYSTEM_BLOCKS_VISIBLEIN |
113
|
|
|
. "</th><th align='center'>" |
114
|
|
|
. \_AM_SYSTEM_ADGS |
115
|
|
|
. "</th><th align='center'>" |
116
|
|
|
. \_AM_SYSTEM_BLOCKS_BCACHETIME |
117
|
|
|
. "</th><th align='center'>" |
118
|
|
|
. \constant('CO_' . $this->moduleDirNameUpper . '_' . 'ACTION') |
119
|
|
|
. '</th></tr> |
120
|
|
|
'; |
121
|
|
|
$blockArray = \XoopsBlock::getByModule($xoopsModule->mid()); |
|
|
|
|
122
|
|
|
$blockCount = \count($blockArray); |
|
|
|
|
123
|
|
|
$class = 'even'; |
124
|
|
|
$cachetimes = [ |
125
|
|
|
0 => _NOCACHE, |
126
|
|
|
30 => \sprintf(_SECONDS, 30), |
127
|
|
|
60 => _MINUTE, |
128
|
|
|
300 => \sprintf(_MINUTES, 5), |
129
|
|
|
1800 => \sprintf(_MINUTES, 30), |
130
|
|
|
3600 => _HOUR, |
131
|
|
|
18000 => \sprintf(_HOURS, 5), |
132
|
|
|
86400 => _DAY, |
133
|
|
|
259200 => \sprintf(_DAYS, 3), |
134
|
|
|
604800 => _WEEK, |
135
|
|
|
2592000 => _MONTH, |
136
|
|
|
]; |
137
|
|
|
foreach ($blockArray as $i) { |
138
|
|
|
$groupsPermissions = $grouppermHandler->getGroupIds('block_read', $i->getVar('bid')); |
139
|
|
|
$sql = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $i->getVar('bid'); |
|
|
|
|
140
|
|
|
$result = $this->db->query($sql); |
141
|
|
|
$modules = []; |
142
|
|
|
if (!$result instanceof \mysqli_result) { |
143
|
|
|
\trigger_error("Query Failed! SQL: $sql Error: " . $this->db->error(), \E_USER_ERROR); |
144
|
|
|
} |
145
|
|
|
while (false !== ($row = $this->db->fetchArray($result))) { |
|
|
|
|
146
|
|
|
$modules[] = (int)$row['module_id']; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
$cachetimeOptions = ''; |
150
|
|
|
foreach ($cachetimes as $cachetime => $cachetimeName) { |
151
|
|
|
if ($i->getVar('bcachetime') == $cachetime) { |
152
|
|
|
$cachetimeOptions .= "<option value='$cachetime' selected='selected'>$cachetimeName</option>\n"; |
153
|
|
|
} else { |
154
|
|
|
$cachetimeOptions .= "<option value='$cachetime'>$cachetimeName</option>\n"; |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
$ssel7 = ''; |
159
|
|
|
$ssel6 = $ssel7; |
160
|
|
|
$ssel5 = $ssel6; |
161
|
|
|
$ssel4 = $ssel5; |
162
|
|
|
$ssel3 = $ssel4; |
163
|
|
|
$ssel2 = $ssel3; |
164
|
|
|
$ssel1 = $ssel2; |
165
|
|
|
$ssel0 = $ssel1; |
166
|
|
|
$sel1 = $ssel0; |
167
|
|
|
$sel0 = $sel1; |
168
|
|
|
if (1 === $i->getVar('visible')) { |
169
|
|
|
$sel1 = ' checked'; |
170
|
|
|
} else { |
171
|
|
|
$sel0 = ' checked'; |
172
|
|
|
} |
173
|
|
|
if (\XOOPS_SIDEBLOCK_LEFT === $i->getVar('side')) { |
174
|
|
|
$ssel0 = ' checked'; |
175
|
|
|
} elseif (\XOOPS_SIDEBLOCK_RIGHT === $i->getVar('side')) { |
176
|
|
|
$ssel1 = ' checked'; |
177
|
|
|
} elseif (\XOOPS_CENTERBLOCK_LEFT === $i->getVar('side')) { |
178
|
|
|
$ssel2 = ' checked'; |
179
|
|
|
} elseif (\XOOPS_CENTERBLOCK_RIGHT === $i->getVar('side')) { |
180
|
|
|
$ssel4 = ' checked'; |
181
|
|
|
} elseif (\XOOPS_CENTERBLOCK_CENTER === $i->getVar('side')) { |
182
|
|
|
$ssel3 = ' checked'; |
183
|
|
|
} elseif (\XOOPS_CENTERBLOCK_BOTTOMLEFT === $i->getVar('side')) { |
184
|
|
|
$ssel5 = ' checked'; |
185
|
|
|
} elseif (\XOOPS_CENTERBLOCK_BOTTOMRIGHT === $i->getVar('side')) { |
186
|
|
|
$ssel6 = ' checked'; |
187
|
|
|
} elseif (\XOOPS_CENTERBLOCK_BOTTOM === $i->getVar('side')) { |
188
|
|
|
$ssel7 = ' checked'; |
189
|
|
|
} |
190
|
|
|
if ('' === $i->getVar('title')) { |
191
|
|
|
$title = ' '; |
192
|
|
|
} else { |
193
|
|
|
$title = $i->getVar('title'); |
194
|
|
|
} |
195
|
|
|
$name = $i->getVar('name'); |
|
|
|
|
196
|
|
|
echo "<tr valign='top'><td class='$class' align='center'><input type='text' name='title[" |
197
|
|
|
. $i->getVar('bid') |
198
|
|
|
. "]' value='" |
199
|
|
|
. $title |
200
|
|
|
. "'></td><td class='$class' align='center' nowrap='nowrap'> |
201
|
|
|
<div align='center' > |
202
|
|
|
<input type='radio' name='side[" |
203
|
|
|
. $i->getVar('bid') |
204
|
|
|
. "]' value='" |
205
|
|
|
. \XOOPS_CENTERBLOCK_LEFT |
206
|
|
|
. "'$ssel2> |
207
|
|
|
<input type='radio' name='side[" |
208
|
|
|
. $i->getVar('bid') |
209
|
|
|
. "]' value='" |
210
|
|
|
. \XOOPS_CENTERBLOCK_CENTER |
211
|
|
|
. "'$ssel3> |
212
|
|
|
<input type='radio' name='side[" |
213
|
|
|
. $i->getVar('bid') |
214
|
|
|
. "]' value='" |
215
|
|
|
. \XOOPS_CENTERBLOCK_RIGHT |
216
|
|
|
. "'$ssel4> |
217
|
|
|
</div> |
218
|
|
|
<div> |
219
|
|
|
<span style='float:right;'><input type='radio' name='side[" |
220
|
|
|
. $i->getVar('bid') |
221
|
|
|
. "]' value='" |
222
|
|
|
. \XOOPS_SIDEBLOCK_RIGHT |
223
|
|
|
. "'$ssel1></span> |
224
|
|
|
<div align='left'><input type='radio' name='side[" |
225
|
|
|
. $i->getVar('bid') |
226
|
|
|
. "]' value='" |
227
|
|
|
. \XOOPS_SIDEBLOCK_LEFT |
228
|
|
|
. "'$ssel0></div> |
229
|
|
|
</div> |
230
|
|
|
<div align='center'> |
231
|
|
|
<input type='radio' name='side[" |
232
|
|
|
. $i->getVar('bid') |
233
|
|
|
. "]' value='" |
234
|
|
|
. \XOOPS_CENTERBLOCK_BOTTOMLEFT |
235
|
|
|
. "'$ssel5> |
236
|
|
|
<input type='radio' name='side[" |
237
|
|
|
. $i->getVar('bid') |
238
|
|
|
. "]' value='" |
239
|
|
|
. \XOOPS_CENTERBLOCK_BOTTOM |
240
|
|
|
. "'$ssel7> |
241
|
|
|
<input type='radio' name='side[" |
242
|
|
|
. $i->getVar('bid') |
243
|
|
|
. "]' value='" |
244
|
|
|
. \XOOPS_CENTERBLOCK_BOTTOMRIGHT |
245
|
|
|
. "'$ssel6> |
246
|
|
|
</div> |
247
|
|
|
</td><td class='$class' align='center'><input type='text' name='weight[" |
248
|
|
|
. $i->getVar('bid') |
249
|
|
|
. "]' value='" |
250
|
|
|
. $i->getVar('weight') |
251
|
|
|
. "' size='5' maxlength='5'></td><td class='$class' align='center' nowrap><input type='radio' name='visible[" |
252
|
|
|
. $i->getVar('bid') |
253
|
|
|
. "]' value='1'$sel1>" |
254
|
|
|
. _YES |
255
|
|
|
. " <input type='radio' name='visible[" |
256
|
|
|
. $i->getVar('bid') |
257
|
|
|
. "]' value='0'$sel0>" |
258
|
|
|
. _NO |
259
|
|
|
. '</td>'; |
260
|
|
|
|
261
|
|
|
echo "<td class='$class' align='center'><select size='5' name='bmodule[" . $i->getVar('bid') . "][]' id='bmodule[" . $i->getVar('bid') . "][]' multiple='multiple'>"; |
262
|
|
|
foreach ($moduleList as $k => $v) { |
263
|
|
|
echo "<option value='$k'" . (\in_array($k, $modules) ? " selected='selected'" : '') . ">$v</option>"; |
264
|
|
|
} |
265
|
|
|
echo '</select></td>'; |
266
|
|
|
|
267
|
|
|
echo "<td class='$class' align='center'><select size='5' name='groups[" . $i->getVar('bid') . "][]' id='groups[" . $i->getVar('bid') . "][]' multiple='multiple'>"; |
268
|
|
|
foreach ($groups as $grp) { |
269
|
|
|
echo "<option value='" . $grp->getVar('groupid') . "' " . (\in_array($grp->getVar('groupid'), $groupsPermissions) ? " selected='selected'" : '') . '>' . $grp->getVar('name') . '</option>'; |
270
|
|
|
} |
271
|
|
|
echo '</select></td>'; |
272
|
|
|
|
273
|
|
|
// Cache lifetime |
274
|
|
|
echo '<td class="' . $class . '" align="center"> <select name="bcachetime[' . $i->getVar('bid') . ']" size="1">' . $cachetimeOptions . '</select> |
275
|
|
|
</td>'; |
276
|
|
|
|
277
|
|
|
// Actions |
278
|
|
|
|
279
|
|
|
echo "<td class='$class' align='center'> |
280
|
|
|
<a href='blocksadmin.php?op=edit&bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/edit.png' . " alt='" . _EDIT . "' title='" . _EDIT . "'></a> |
281
|
|
|
<a href='blocksadmin.php?op=clone&bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/editcopy.png' . " alt='" . _CLONE . "' title='" . _CLONE . "'></a>"; |
282
|
|
|
// if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) { |
283
|
|
|
// echo " <a href='" . XOOPS_URL . '/modules/system/admin.php?fct=blocksadmin&op=delete&bid=' . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/delete.png' . " alt='" . _DELETE . "' title='" . _DELETE . "'> |
284
|
|
|
// </a>"; |
285
|
|
|
// } |
286
|
|
|
|
287
|
|
|
// if ('S' !== $i->getVar('block_type') && 'M' !== $i->getVar('block_type')) { |
288
|
|
|
if (!\in_array($i->getVar('block_type'), ['M', 'S'])) { |
289
|
|
|
echo " |
290
|
|
|
<a href='blocksadmin.php?op=delete&bid=" . $i->getVar('bid') . "'><img src=" . $pathIcon16 . '/delete.png' . " alt='" . _DELETE . "' title='" . _DELETE . "'> |
291
|
|
|
</a>"; |
292
|
|
|
} |
293
|
|
|
echo " |
294
|
|
|
<input type='hidden' name='oldtitle[" . $i->getVar('bid') . "]' value='" . $i->getVar('title') . "'> |
295
|
|
|
<input type='hidden' name='oldside[" . $i->getVar('bid') . "]' value='" . $i->getVar('side') . "'> |
296
|
|
|
<input type='hidden' name='oldweight[" . $i->getVar('bid') . "]' value='" . $i->getVar('weight') . "'> |
297
|
|
|
<input type='hidden' name='oldvisible[" . $i->getVar('bid') . "]' value='" . $i->getVar('visible') . "'> |
298
|
|
|
<input type='hidden' name='oldgroups[" . $i->getVar('groups') . "]' value='" . $i->getVar('groups') . "'> |
299
|
|
|
<input type='hidden' name='oldbcachetime[" . $i->getVar('bid') . "]' value='" . $i->getVar('bcachetime') . "'> |
300
|
|
|
<input type='hidden' name='bid[" . $i->getVar('bid') . "]' value='" . $i->getVar('bid') . "'> |
301
|
|
|
</td></tr> |
302
|
|
|
"; |
303
|
|
|
$class = ('even' === $class) ? 'odd' : 'even'; |
304
|
|
|
} |
305
|
|
|
echo "<tr><td class='foot' align='center' colspan='8'> |
306
|
|
|
<input type='hidden' name='op' value='order'> |
307
|
|
|
" . $GLOBALS['xoopsSecurity']->getTokenHTML() . " |
308
|
|
|
<input type='submit' name='submit' value='" . _SUBMIT . "'> |
309
|
|
|
</td></tr></table> |
310
|
|
|
</form> |
311
|
|
|
<br><br>"; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
public function deleteBlock(int $bid): void |
315
|
|
|
{ |
316
|
|
|
// \xoops_cp_header(); |
317
|
|
|
|
318
|
|
|
\xoops_loadLanguage('admin', 'system'); |
319
|
|
|
\xoops_loadLanguage('admin/blocksadmin', 'system'); |
320
|
|
|
\xoops_loadLanguage('admin/groups', 'system'); |
321
|
|
|
|
322
|
|
|
$myblock = new \XoopsBlock($bid); |
|
|
|
|
323
|
|
|
|
324
|
|
|
$sql = \sprintf('DELETE FROM %s WHERE bid = %u', $this->db->prefix('newblocks'), $bid); |
325
|
|
|
$this->db->queryF($sql) or \trigger_error($GLOBALS['xoopsDB']->error()); |
326
|
|
|
|
327
|
|
|
$sql = \sprintf('DELETE FROM %s WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid); |
328
|
|
|
$this->db->queryF($sql) or \trigger_error($GLOBALS['xoopsDB']->error()); |
329
|
|
|
|
330
|
|
|
$this->helper->redirect('admin/blocksadmin.php?op=list', 1, _AM_DBUPDATED); |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
public function cloneBlock(int $bid): void |
334
|
|
|
{ |
335
|
|
|
//require __DIR__ . '/admin_header.php'; |
336
|
|
|
// \xoops_cp_header(); |
337
|
|
|
|
338
|
|
|
\xoops_loadLanguage('admin', 'system'); |
339
|
|
|
\xoops_loadLanguage('admin/blocksadmin', 'system'); |
340
|
|
|
\xoops_loadLanguage('admin/groups', 'system'); |
341
|
|
|
|
342
|
|
|
$myblock = new \XoopsBlock($bid); |
343
|
|
|
$sql = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $bid; |
344
|
|
|
$result = $this->db->query($sql); |
345
|
|
|
$modules = []; |
346
|
|
|
if ($result instanceof \mysqli_result) { |
347
|
|
|
while (false !== ($row = $this->db->fetchArray($result))) { |
348
|
|
|
$modules[] = (int)$row['module_id']; |
349
|
|
|
} |
350
|
|
|
} |
351
|
|
|
$isCustom = \in_array($myblock->getVar('block_type'), ['C', 'E']); |
352
|
|
|
$block = [ |
353
|
|
|
'title' => $myblock->getVar('title') . ' Clone', |
354
|
|
|
'form_title' => \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BLOCKS_CLONEBLOCK'), |
355
|
|
|
'name' => $myblock->getVar('name'), |
356
|
|
|
'side' => $myblock->getVar('side'), |
357
|
|
|
'weight' => $myblock->getVar('weight'), |
358
|
|
|
'visible' => $myblock->getVar('visible'), |
359
|
|
|
'content' => $myblock->getVar('content', 'N'), |
360
|
|
|
'modules' => $modules, |
361
|
|
|
'is_custom' => $isCustom, |
362
|
|
|
'ctype' => $myblock->getVar('c_type'), |
363
|
|
|
'bcachetime' => $myblock->getVar('bcachetime'), |
364
|
|
|
'op' => 'clone_ok', |
365
|
|
|
'bid' => $myblock->getVar('bid'), |
366
|
|
|
'edit_form' => $myblock->getOptions(), |
367
|
|
|
'template' => $myblock->getVar('template'), |
368
|
|
|
'options' => $myblock->getVar('options'), |
369
|
|
|
]; |
370
|
|
|
echo '<a href="blocksadmin.php">' . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</a> <span style="font-weight:bold;">»»</span> ' . \_AM_SYSTEM_BLOCKS_CLONEBLOCK . '<br><br>'; |
371
|
|
|
// $form = new Blockform(); |
372
|
|
|
// $form->render(); |
373
|
|
|
|
374
|
|
|
echo $this->render($block); |
|
|
|
|
375
|
|
|
// xoops_cp_footer(); |
376
|
|
|
// require_once __DIR__ . '/admin_footer.php'; |
377
|
|
|
// exit(); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
public function isBlockCloned(int $bid, string $bside, string $bweight, string $bvisible, string $bcachetime, ?array $bmodule, ?array $options, ?array $groups): void |
381
|
|
|
{ |
382
|
|
|
\xoops_loadLanguage('admin', 'system'); |
383
|
|
|
\xoops_loadLanguage('admin/blocksadmin', 'system'); |
384
|
|
|
\xoops_loadLanguage('admin/groups', 'system'); |
385
|
|
|
|
386
|
|
|
$block = new \XoopsBlock($bid); |
387
|
|
|
$clone = $block->xoopsClone(); |
388
|
|
|
if (empty($bmodule)) { |
389
|
|
|
// \xoops_cp_header(); |
390
|
|
|
\xoops_error(\sprintf(_AM_NOTSELNG, _AM_VISIBLEIN)); |
391
|
|
|
\xoops_cp_footer(); |
392
|
|
|
exit(); |
|
|
|
|
393
|
|
|
} |
394
|
|
|
$clone->setVar('side', $bside); |
395
|
|
|
$clone->setVar('weight', $bweight); |
396
|
|
|
$clone->setVar('visible', $bvisible); |
397
|
|
|
//$clone->setVar('content', $_POST['bcontent']); |
398
|
|
|
$clone->setVar('title', Request::getString('btitle', '', 'POST')); |
399
|
|
|
$clone->setVar('bcachetime', $bcachetime); |
400
|
|
|
if (\is_array($options) && (\count($options) > 0)) { |
401
|
|
|
$options = \implode('|', $options); |
402
|
|
|
$clone->setVar('options', $options); |
403
|
|
|
} |
404
|
|
|
$clone->setVar('bid', 0); |
405
|
|
|
if (\in_array($block->getVar('block_type'), ['C', 'E'])) { |
406
|
|
|
$clone->setVar('block_type', 'E'); |
407
|
|
|
} else { |
408
|
|
|
$clone->setVar('block_type', 'D'); |
409
|
|
|
} |
410
|
|
|
// $newid = $clone->store(); //see https://github.com/XOOPS/XoopsCore25/issues/1105 |
411
|
|
|
if ($clone->store()) { |
412
|
|
|
$newid = $clone->id(); //get the id of the cloned block |
413
|
|
|
} |
414
|
|
|
if (!$newid) { |
|
|
|
|
415
|
|
|
// \xoops_cp_header(); |
416
|
|
|
$clone->getHtmlErrors(); |
417
|
|
|
\xoops_cp_footer(); |
418
|
|
|
exit(); |
|
|
|
|
419
|
|
|
} |
420
|
|
|
if ('' !== $clone->getVar('template')) { |
421
|
|
|
/** @var \XoopsTplfileHandler $tplfileHandler */ |
422
|
|
|
$tplfileHandler = \xoops_getHandler('tplfile'); |
423
|
|
|
$btemplate = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', (string)$bid); |
424
|
|
|
if (\count($btemplate) > 0) { |
425
|
|
|
$tplclone = $btemplate[0]->xoopsClone(); |
426
|
|
|
$tplclone->setVar('tpl_id', 0); |
427
|
|
|
$tplclone->setVar('tpl_refid', $newid); |
428
|
|
|
$tplfileHandler->insert($tplclone); |
429
|
|
|
} |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
foreach ($bmodule as $bmid) { |
433
|
|
|
$sql = 'INSERT INTO ' . $this->db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')'; |
434
|
|
|
$this->db->query($sql); |
435
|
|
|
} |
436
|
|
|
//$groups = &$GLOBALS['xoopsUser']->getGroups(); |
437
|
|
|
foreach ($groups as $iValue) { |
438
|
|
|
$sql = 'INSERT INTO ' . $this->db->prefix('group_permission') . ' (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (' . $iValue . ', ' . $newid . ", 1, 'block_read')"; |
439
|
|
|
$this->db->query($sql); |
440
|
|
|
} |
441
|
|
|
$this->helper->redirect('admin/blocksadmin.php?op=list', 1, _AM_DBUPDATED); |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
public function setOrder(string $bid, string $title, string $weight, string $visible, string $side, string $bcachetime, ?array $bmodule = null): void |
|
|
|
|
445
|
|
|
{ |
446
|
|
|
$myblock = new \XoopsBlock($bid); |
447
|
|
|
$myblock->setVar('title', $title); |
448
|
|
|
$myblock->setVar('weight', $weight); |
449
|
|
|
$myblock->setVar('visible', $visible); |
450
|
|
|
$myblock->setVar('side', $side); |
451
|
|
|
$myblock->setVar('bcachetime', $bcachetime); |
452
|
|
|
$myblock->store(); |
|
|
|
|
453
|
|
|
// /** @var \XoopsBlockHandler $blockHandler */ |
454
|
|
|
// $blockHandler = \xoops_getHandler('block'); |
455
|
|
|
// return $blockHandler->insert($myblock); |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
public function editBlock(int $bid): void |
459
|
|
|
{ |
460
|
|
|
// require_once \dirname(__DIR__,2) . '/admin/admin_header.php'; |
461
|
|
|
// \xoops_cp_header(); |
462
|
|
|
\xoops_loadLanguage('admin', 'system'); |
463
|
|
|
\xoops_loadLanguage('admin/blocksadmin', 'system'); |
464
|
|
|
\xoops_loadLanguage('admin/groups', 'system'); |
465
|
|
|
// mpu_adm_menu(); |
466
|
|
|
$myblock = new \XoopsBlock($bid); |
467
|
|
|
$sql = 'SELECT module_id FROM ' . $this->db->prefix('block_module_link') . ' WHERE block_id=' . $bid; |
468
|
|
|
$result = $this->db->query($sql); |
469
|
|
|
$modules = []; |
470
|
|
|
if ($result instanceof \mysqli_result) { |
471
|
|
|
while (false !== ($row = $this->db->fetchArray($result))) { |
472
|
|
|
$modules[] = (int)$row['module_id']; |
473
|
|
|
} |
474
|
|
|
} |
475
|
|
|
$isCustom = \in_array($myblock->getVar('block_type'), ['C', 'E']); |
476
|
|
|
$block = [ |
477
|
|
|
'title' => $myblock->getVar('title'), |
478
|
|
|
'form_title' => \_AM_SYSTEM_BLOCKS_EDITBLOCK, |
479
|
|
|
// 'name' => $myblock->getVar('name'), |
480
|
|
|
'side' => $myblock->getVar('side'), |
481
|
|
|
'weight' => $myblock->getVar('weight'), |
482
|
|
|
'visible' => $myblock->getVar('visible'), |
483
|
|
|
'content' => $myblock->getVar('content', 'N'), |
484
|
|
|
'modules' => $modules, |
485
|
|
|
'is_custom' => $isCustom, |
486
|
|
|
'ctype' => $myblock->getVar('c_type'), |
487
|
|
|
'bcachetime' => $myblock->getVar('bcachetime'), |
488
|
|
|
'op' => 'edit_ok', |
489
|
|
|
'bid' => $myblock->getVar('bid'), |
490
|
|
|
'edit_form' => $myblock->getOptions(), |
491
|
|
|
'template' => $myblock->getVar('template'), |
492
|
|
|
'options' => $myblock->getVar('options'), |
493
|
|
|
]; |
494
|
|
|
echo '<a href="blocksadmin.php">' . \constant('CO_' . $this->moduleDirNameUpper . '_' . 'BADMIN') . '</a> <span style="font-weight:bold;">»»</span> ' . \_AM_SYSTEM_BLOCKS_EDITBLOCK . '<br><br>'; |
495
|
|
|
|
496
|
|
|
echo $this->render($block); |
|
|
|
|
497
|
|
|
} |
498
|
|
|
|
499
|
|
|
public function updateBlock(int $bid, string $btitle, string $bside, string $bweight, string $bvisible, string $bcachetime, ?array $bmodule, ?array $options, ?array $groups): void |
500
|
|
|
{ |
501
|
|
|
$myblock = new \XoopsBlock($bid); |
502
|
|
|
$myblock->setVar('title', $btitle); |
503
|
|
|
$myblock->setVar('weight', $bweight); |
504
|
|
|
$myblock->setVar('visible', $bvisible); |
505
|
|
|
$myblock->setVar('side', $bside); |
506
|
|
|
$myblock->setVar('bcachetime', $bcachetime); |
507
|
|
|
//update block options |
508
|
|
|
if (isset($options)) { |
509
|
|
|
$optionsCount = \count($options); |
510
|
|
|
if ($optionsCount > 0) { |
511
|
|
|
//Convert array values to comma-separated |
512
|
|
|
foreach ($options as $i => $iValue) { |
513
|
|
|
if (\is_array($iValue)) { |
514
|
|
|
$options[$i] = \implode(',', $iValue); |
515
|
|
|
} |
516
|
|
|
} |
517
|
|
|
$options = \implode('|', $options); |
518
|
|
|
$myblock->setVar('options', $options); |
519
|
|
|
} |
520
|
|
|
} |
521
|
|
|
$myblock->store(); |
|
|
|
|
522
|
|
|
// /** @var \XoopsBlockHandler $blockHandler */ |
523
|
|
|
// $blockHandler = \xoops_getHandler('block'); |
524
|
|
|
// $blockHandler->insert($myblock); |
525
|
|
|
|
526
|
|
|
if (!empty($bmodule) && \count($bmodule) > 0) { |
527
|
|
|
$sql = \sprintf('DELETE FROM `%s` WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid); |
528
|
|
|
$this->db->query($sql); |
529
|
|
|
if (\in_array(0, $bmodule)) { |
530
|
|
|
$sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid, 0); |
531
|
|
|
$this->db->query($sql); |
532
|
|
|
} else { |
533
|
|
|
foreach ($bmodule as $bmid) { |
534
|
|
|
$sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid, (int)$bmid); |
535
|
|
|
$this->db->query($sql); |
536
|
|
|
} |
537
|
|
|
} |
538
|
|
|
} |
539
|
|
|
$sql = \sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $this->db->prefix('group_permission'), $bid); |
540
|
|
|
$this->db->query($sql); |
541
|
|
|
if (!empty($groups)) { |
542
|
|
|
foreach ($groups as $grp) { |
543
|
|
|
$sql = \sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $this->db->prefix('group_permission'), $grp, $bid); |
544
|
|
|
$this->db->query($sql); |
545
|
|
|
} |
546
|
|
|
} |
547
|
|
|
$this->helper->redirect('admin/blocksadmin.php', 1, \constant('CO_' . $this->moduleDirNameUpper . '_' . 'UPDATE_SUCCESS')); |
548
|
|
|
} |
549
|
|
|
|
550
|
|
|
public function orderBlock( |
551
|
|
|
array $bid, |
552
|
|
|
array $oldtitle, |
553
|
|
|
array $oldside, |
554
|
|
|
array $oldweight, |
555
|
|
|
array $oldvisible, |
556
|
|
|
array $oldgroups, |
|
|
|
|
557
|
|
|
array $oldbcachetime, |
558
|
|
|
array $oldbmodule, |
559
|
|
|
array $title, |
560
|
|
|
array $weight, |
561
|
|
|
array $visible, |
562
|
|
|
array $side, |
563
|
|
|
array $bcachetime, |
564
|
|
|
array $groups, |
565
|
|
|
array $bmodule |
566
|
|
|
): void { |
567
|
|
|
if (!$GLOBALS['xoopsSecurity']->check()) { |
568
|
|
|
\redirect_header($_SERVER['SCRIPT_NAME'], 3, \implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
569
|
|
|
} |
570
|
|
|
foreach (\array_keys($bid) as $i) { |
571
|
|
|
if ($oldtitle[$i] !== $title[$i] |
572
|
|
|
|| $oldweight[$i] !== $weight[$i] |
573
|
|
|
|| $oldvisible[$i] !== $visible[$i] |
574
|
|
|
|| $oldside[$i] !== $side[$i] |
575
|
|
|
|| $oldbcachetime[$i] !== $bcachetime[$i] |
576
|
|
|
|| $oldbmodule[$i] !== $bmodule[$i]) { |
577
|
|
|
$this->setOrder($bid[$i], $title[$i], $weight[$i], $visible[$i], $side[$i], $bcachetime[$i], $bmodule[$i]); |
578
|
|
|
} |
579
|
|
|
if (!empty($bmodule[$i]) && \count($bmodule[$i]) > 0) { |
580
|
|
|
$sql = \sprintf('DELETE FROM `%s` WHERE block_id = %u', $this->db->prefix('block_module_link'), $bid[$i]); |
581
|
|
|
$this->db->query($sql); |
582
|
|
|
if (\in_array(0, $bmodule[$i], true)) { |
583
|
|
|
$sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid[$i], 0); |
584
|
|
|
$this->db->query($sql); |
585
|
|
|
} else { |
586
|
|
|
foreach ($bmodule[$i] as $bmid) { |
587
|
|
|
$sql = \sprintf('INSERT INTO `%s` (block_id, module_id) VALUES (%u, %d)', $this->db->prefix('block_module_link'), $bid[$i], (int)$bmid); |
588
|
|
|
$this->db->query($sql); |
589
|
|
|
} |
590
|
|
|
} |
591
|
|
|
} |
592
|
|
|
$sql = \sprintf('DELETE FROM `%s` WHERE gperm_itemid = %u', $this->db->prefix('group_permission'), $bid[$i]); |
593
|
|
|
$this->db->query($sql); |
594
|
|
|
if (!empty($groups[$i])) { |
595
|
|
|
foreach ($groups[$i] as $grp) { |
596
|
|
|
$sql = \sprintf("INSERT INTO `%s` (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (%u, %u, 1, 'block_read')", $this->db->prefix('group_permission'), $grp, $bid[$i]); |
597
|
|
|
$this->db->query($sql); |
598
|
|
|
} |
599
|
|
|
} |
600
|
|
|
} |
601
|
|
|
|
602
|
|
|
$this->helper->redirect('admin/blocksadmin.php', 1, \constant('CO_' . $this->moduleDirNameUpper . '_' . 'UPDATE_SUCCESS')); |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
public function render(?array $block = null) |
606
|
|
|
{ |
607
|
|
|
\xoops_load('XoopsFormLoader'); |
608
|
|
|
\xoops_loadLanguage('common', $this->moduleDirNameUpper); |
609
|
|
|
|
610
|
|
|
$form = new \XoopsThemeForm($block['form_title'], 'blockform', 'blocksadmin.php', 'post', true); |
611
|
|
|
if (isset($block['name'])) { |
612
|
|
|
$form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_NAME, $block['name'])); |
613
|
|
|
} |
614
|
|
|
$sideSelect = new \XoopsFormSelect(\_AM_SYSTEM_BLOCKS_TYPE, 'bside', $block['side']); |
615
|
|
|
$sideSelect->addOptionArray([ |
616
|
|
|
0 => \_AM_SYSTEM_BLOCKS_SBLEFT, |
617
|
|
|
1 => \_AM_SYSTEM_BLOCKS_SBRIGHT, |
618
|
|
|
3 => \_AM_SYSTEM_BLOCKS_CBLEFT, |
619
|
|
|
4 => \_AM_SYSTEM_BLOCKS_CBRIGHT, |
620
|
|
|
5 => \_AM_SYSTEM_BLOCKS_CBCENTER, |
621
|
|
|
7 => \_AM_SYSTEM_BLOCKS_CBBOTTOMLEFT, |
622
|
|
|
8 => \_AM_SYSTEM_BLOCKS_CBBOTTOMRIGHT, |
623
|
|
|
9 => \_AM_SYSTEM_BLOCKS_CBBOTTOM, |
624
|
|
|
]); |
625
|
|
|
$form->addElement($sideSelect); |
626
|
|
|
$form->addElement(new \XoopsFormText(\constant('CO_' . $this->moduleDirNameUpper . '_' . 'WEIGHT'), 'bweight', 2, 5, $block['weight'])); |
627
|
|
|
$form->addElement(new \XoopsFormRadioYN(\constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLE'), 'bvisible', $block['visible'])); |
628
|
|
|
$modSelect = new \XoopsFormSelect(\constant('CO_' . $this->moduleDirNameUpper . '_' . 'VISIBLEIN'), 'bmodule', $block['modules'], 5, true); |
629
|
|
|
/** @var \XoopsModuleHandler $moduleHandler */ |
630
|
|
|
$moduleHandler = \xoops_getHandler('module'); |
631
|
|
|
$criteria = new \CriteriaCompo(new \Criteria('hasmain', '1')); |
632
|
|
|
$criteria->add(new \Criteria('isactive', '1')); |
633
|
|
|
$moduleList = $moduleHandler->getList($criteria); |
634
|
|
|
$moduleList[-1] = \_AM_SYSTEM_BLOCKS_TOPPAGE; |
635
|
|
|
$moduleList[0] = \_AM_SYSTEM_BLOCKS_ALLPAGES; |
636
|
|
|
\ksort($moduleList); |
637
|
|
|
$modSelect->addOptionArray($moduleList); |
638
|
|
|
$form->addElement($modSelect); |
639
|
|
|
$form->addElement(new \XoopsFormText(\_AM_SYSTEM_BLOCKS_TITLE, 'btitle', 50, 255, $block['title']), false); |
640
|
|
|
if ($block['is_custom']) { |
641
|
|
|
$textarea = new \XoopsFormDhtmlTextArea(\_AM_SYSTEM_BLOCKS_CONTENT, 'bcontent', $block['content'], 15, 70); |
642
|
|
|
$textarea->setDescription('<span style="font-size:x-small;font-weight:bold;">' . \_AM_SYSTEM_BLOCKS_USEFULTAGS . '</span><br><span style="font-size:x-small;font-weight:normal;">' . \sprintf(_AM_BLOCKTAG1, '{X_SITEURL}', XOOPS_URL . '/') . '</span>'); |
643
|
|
|
$form->addElement($textarea, true); |
644
|
|
|
$ctypeSelect = new \XoopsFormSelect(\_AM_SYSTEM_BLOCKS_CTYPE, 'bctype', $block['ctype']); |
645
|
|
|
$ctypeSelect->addOptionArray([ |
646
|
|
|
'H' => \_AM_SYSTEM_BLOCKS_HTML, |
647
|
|
|
'P' => \_AM_SYSTEM_BLOCKS_PHP, |
648
|
|
|
'S' => \_AM_SYSTEM_BLOCKS_AFWSMILE, |
649
|
|
|
'T' => \_AM_SYSTEM_BLOCKS_AFNOSMILE, |
650
|
|
|
]); |
651
|
|
|
$form->addElement($ctypeSelect); |
652
|
|
|
} else { |
653
|
|
|
if ('' !== $block['template']) { |
654
|
|
|
/** @var \XoopsTplfileHandler $tplfileHandler */ |
655
|
|
|
$tplfileHandler = \xoops_getHandler('tplfile'); |
656
|
|
|
$btemplate = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $block['bid']); |
657
|
|
|
if (\count($btemplate) > 0) { |
658
|
|
|
$form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_CONTENT, '<a href="' . XOOPS_URL . '/modules/system/admin.php?fct=tplsets&op=edittpl&id=' . $btemplate[0]->getVar('tpl_id') . '">' . \_AM_SYSTEM_BLOCKS_EDITTPL . '</a>')); |
659
|
|
|
} else { |
660
|
|
|
$btemplate2 = $tplfileHandler->find('default', 'block', $block['bid']); |
661
|
|
|
if (\count($btemplate2) > 0) { |
662
|
|
|
$form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_CONTENT, '<a href="' . XOOPS_URL . '/modules/system/admin.php?fct=tplsets&op=edittpl&id=' . $btemplate2[0]->getVar('tpl_id') . '" target="_blank">' . \_AM_SYSTEM_BLOCKS_EDITTPL . '</a>')); |
663
|
|
|
} |
664
|
|
|
} |
665
|
|
|
} |
666
|
|
|
if (false !== $block['edit_form']) { |
667
|
|
|
$form->addElement(new \XoopsFormLabel(\_AM_SYSTEM_BLOCKS_OPTIONS, $block['edit_form'])); |
668
|
|
|
} |
669
|
|
|
} |
670
|
|
|
$cache_select = new \XoopsFormSelect(\_AM_SYSTEM_BLOCKS_BCACHETIME, 'bcachetime', $block['bcachetime']); |
671
|
|
|
$cache_select->addOptionArray([ |
672
|
|
|
0 => _NOCACHE, |
673
|
|
|
30 => \sprintf(_SECONDS, 30), |
674
|
|
|
60 => _MINUTE, |
675
|
|
|
300 => \sprintf(_MINUTES, 5), |
676
|
|
|
1800 => \sprintf(_MINUTES, 30), |
677
|
|
|
3600 => _HOUR, |
678
|
|
|
18000 => \sprintf(_HOURS, 5), |
679
|
|
|
86400 => _DAY, |
680
|
|
|
259200 => \sprintf(_DAYS, 3), |
681
|
|
|
604800 => _WEEK, |
682
|
|
|
2592000 => _MONTH, |
683
|
|
|
]); |
684
|
|
|
$form->addElement($cache_select); |
685
|
|
|
|
686
|
|
|
/** @var \XoopsGroupPermHandler $grouppermHandler */ |
687
|
|
|
$grouppermHandler = \xoops_getHandler('groupperm'); |
688
|
|
|
$groups = $grouppermHandler->getGroupIds('block_read', $block['bid']); |
689
|
|
|
|
690
|
|
|
$form->addElement(new \XoopsFormSelectGroup(\_AM_SYSTEM_BLOCKS_GROUP, 'groups', true, $groups, 5, true)); |
691
|
|
|
|
692
|
|
|
if (isset($block['bid'])) { |
693
|
|
|
$form->addElement(new \XoopsFormHidden('bid', $block['bid'])); |
694
|
|
|
} |
695
|
|
|
$form->addElement(new \XoopsFormHidden('op', $block['op'])); |
696
|
|
|
$form->addElement(new \XoopsFormHidden('fct', 'blocksadmin')); |
697
|
|
|
$buttonTray = new \XoopsFormElementTray('', ' '); |
698
|
|
|
if ($block['is_custom']) { |
699
|
|
|
$buttonTray->addElement(new \XoopsFormButton('', 'previewblock', _PREVIEW, 'submit')); |
700
|
|
|
} |
701
|
|
|
|
702
|
|
|
//Submit buttons |
703
|
|
|
$buttonTray = new \XoopsFormElementTray('', ''); |
704
|
|
|
$submitButton = new \XoopsFormButton('', 'submitblock', _SUBMIT, 'submit'); |
705
|
|
|
$buttonTray->addElement($submitButton); |
706
|
|
|
|
707
|
|
|
$cancelButton = new \XoopsFormButton('', '', _CANCEL, 'button'); |
708
|
|
|
$cancelButton->setExtra('onclick="history.go(-1)"'); |
709
|
|
|
$buttonTray->addElement($cancelButton); |
710
|
|
|
|
711
|
|
|
$form->addElement($buttonTray); |
712
|
|
|
$form->display(); |
713
|
|
|
} |
714
|
|
|
} |
715
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.