This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
1 | <?php |
||
2 | // $Id: main.php,v 1.12 2004/01/06 09:36:20 okazu Exp $ |
||
3 | /* |
||
4 | * You may not change or alter any portion of this comment or credits |
||
5 | * of supporting developers from this source code or any supporting source code |
||
6 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||
7 | * |
||
8 | * This program is distributed in the hope that it will be useful, |
||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
11 | */ |
||
12 | |||
13 | /** |
||
14 | * @copyright {@link https://xoops.org/ XOOPS Project} |
||
15 | * @license {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later} |
||
16 | * @author Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, https://xoops.org/, http://jp.xoops.org/ |
||
17 | * @author XOOPS Development Team |
||
18 | */ |
||
19 | |||
20 | use Xmf\Request; |
||
21 | use XoopsModules\Blocksadmin\{ |
||
22 | Helper |
||
23 | }; |
||
24 | /** @var Helper $helper */ |
||
25 | |||
26 | if (!is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid())) { |
||
27 | exit('Access Denied'); |
||
28 | } |
||
29 | require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; |
||
30 | //require XOOPS_ROOT_PATH . '/modules/system/admin/blocksadmin/main.php'; |
||
31 | |||
32 | $helper = Helper::getInstance(); |
||
33 | $helper->loadLanguage('admin'); |
||
34 | $helper->loadLanguage('common'); |
||
35 | |||
36 | $op = 'list'; |
||
37 | |||
38 | if (!empty($_POST['op'])) { |
||
39 | $op = Request::getCmd('op', '', 'POST'); |
||
40 | } |
||
41 | if (!empty($_POST['bid'])) { |
||
42 | $bid = Request::getInt('bid', 0, 'POST'); |
||
43 | } |
||
44 | |||
45 | if (isset($_GET['op'])) { |
||
46 | if (in_array(Request::getCmd('op', '', 'GET'), ['edit', 'delete', 'delete_ok', 'clone'])){ |
||
47 | // if ('edit' === $_GET['op'] || 'delete' === $_GET['op'] || 'delete_ok' === $_GET['op'] || 'clone' === $_GET['op'] /* || $_GET['op'] == 'previewpopup'*/) { |
||
48 | $op = Request::getCmd('op', '', 'GET'); |
||
49 | $bid = Request::getInt('bid', 0, 'GET'); |
||
50 | } |
||
51 | } |
||
52 | |||
53 | if (isset($_POST['previewblock'])) { |
||
54 | //if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) { |
||
55 | // exit('Invalid Referer'); |
||
56 | //} |
||
57 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
58 | redirect_header(XOOPS_URL . '/', 3, $GLOBALS['xoopsSecurity']->getErrors()); |
||
59 | } |
||
60 | |||
61 | if (empty($bid)) { |
||
62 | exit('Invalid bid.'); |
||
63 | } |
||
64 | |||
65 | $bside = Request::getInt('bside', 0, 'POST'); |
||
66 | $bweight = Request::getInt('bweight', 0, 'POST'); |
||
67 | $bvisible = Request::getInt('bvisible', 0, 'POST'); |
||
68 | $bmodule = Request::getArray('bmodule', [], 'POST'); |
||
69 | $btitle = Request::getString('btitle', '', 'POST'); |
||
70 | $bcontent = Request::getString('bcontent', '', 'POST'); |
||
71 | $bctype = Request::getString('bctype', '', 'POST'); |
||
72 | $bcachetime = Request::getInt('bcachetime', 0, 'POST'); |
||
73 | |||
74 | xoops_cp_header(); |
||
75 | require_once XOOPS_ROOT_PATH . '/class/template.php'; |
||
76 | $xoopsTpl = new XoopsTpl(); |
||
77 | $xoopsTpl->caching = 0; |
||
78 | $block['bid'] = $bid; |
||
79 | |||
80 | if ('clone_ok' === $op) { |
||
81 | $block['form_title'] = _AM_SYSTEM_BLOCKS_CLONEBLOCK; |
||
82 | $block['submit_button'] = _CLONE; |
||
83 | $myblock = new XoopsBlock(); |
||
84 | $myblock->setVar('block_type', 'C'); |
||
85 | } else { |
||
86 | $op = 'update'; |
||
87 | $block['form_title'] = _AM_SYSTEM_BLOCKS_EDITBLOCK; |
||
88 | $block['submit_button'] = _SUBMIT; |
||
89 | $myblock = new XoopsBlock($bid); |
||
90 | $block['name'] = $myblock->getVar('name'); |
||
91 | } |
||
92 | |||
93 | $myts = MyTextSanitizer::getInstance(); |
||
94 | $myblock->setVar('title', ($btitle)); |
||
95 | $myblock->setVar('content', ($bcontent)); |
||
96 | // $dummyhtml = '<html><head><meta http-equiv="content-type" content="text/html; charset='._CHARSET.'"><meta http-equiv="content-language" content="'._LANGCODE.'"><title>'.$xoopsConfig['sitename'].'</title><link rel="stylesheet" type="text/css" media="all" href="'.getcss($xoopsConfig['theme_set']).'"></head><body><table><tr><th>'.$myblock->getVar('title').'</th></tr><tr><td>'.$myblock->getContent('S', $bctype).'</td></tr></table></body></html>'; |
||
97 | |||
98 | /* $dummyfile = '_dummyfile_'.time().'.html'; |
||
99 | $fp = fopen(XOOPS_CACHE_PATH.'/'.$dummyfile, 'w'); |
||
100 | fwrite($fp, $dummyhtml); |
||
101 | fclose($fp);*/ |
||
102 | $block['edit_form'] = false; |
||
103 | $block['template'] = ''; |
||
104 | $block['op'] = $op; |
||
105 | $block['side'] = $bside; |
||
106 | $block['weight'] = $bweight; |
||
107 | $block['visible'] = $bvisible; |
||
108 | $block['title'] = $myblock->getVar('title', 'E'); |
||
109 | $block['content'] = $myblock->getVar('content', 'n'); |
||
110 | $block['modules'] = &$bmodule; |
||
111 | $block['ctype'] = $bctype ?? $myblock->getVar('c_type'); |
||
112 | $block['is_custom'] = true; |
||
113 | $block['cachetime'] = $bcachetime; |
||
114 | echo '<a href="myblocksadmin.php">' . _AM_SYSTEM_BLOCKS_ADMIN . '</a> <span style="font-weight:bold;">»»</span> ' . $block['form_title'] . '<br><br>'; |
||
115 | require \dirname(__DIR__) . '/admin/myblockform.php'; //GIJ |
||
116 | //echo '<a href="admin.php?fct=blocksadmin">'. _AM_SYSTEM_BLOCKS_ADMIN .'</a> <span style="font-weight:bold;">»»</span> '.$block['form_title'].'<br><br>'; |
||
117 | //require XOOPS_ROOT_PATH.'/modules/system/admin/blocksadmin/blockform.php'; |
||
118 | $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
119 | $form->display(); |
||
120 | |||
121 | $original_level = error_reporting(E_ALL); |
||
122 | echo " |
||
123 | <table width='100%' class='outer' cellspacing='1'> |
||
124 | <tr> |
||
125 | <th>" . $myblock->getVar('title') . "</th> |
||
126 | </tr> |
||
127 | <tr> |
||
128 | <td class='odd'>" . $myblock->getContent('S', $bctype) . "</td> |
||
129 | </tr> |
||
130 | </table>\n"; |
||
131 | error_reporting($original_level); |
||
132 | |||
133 | xoops_cp_footer(); |
||
134 | /* echo '<script type="text/javascript"> |
||
135 | preview_window = openWithSelfMain("'.XOOPS_URL.'/modules/system/admin.php?fct=blocksadmin&op=previewpopup&file='.$dummyfile.'", "popup", 250, 200); |
||
136 | </script>';*/ |
||
137 | |||
138 | exit(); |
||
139 | } |
||
140 | |||
141 | /* if ($op == 'previewpopup') { |
||
142 | if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) { |
||
143 | exit('Invalid Referer'); |
||
144 | } |
||
145 | $file = str_replace('..', '', XOOPS_CACHE_PATH.'/'.trim($_GET['file'])); |
||
146 | if (file_exists($file)) { |
||
147 | include $file; |
||
148 | @unlink($file); |
||
149 | } |
||
150 | exit(); |
||
151 | } */ |
||
152 | |||
153 | /* if ( $op == "list" ) { |
||
154 | xoops_cp_header(); |
||
155 | list_blocks(); |
||
156 | xoops_cp_footer(); |
||
157 | exit(); |
||
158 | } */ |
||
159 | |||
160 | if ('order' === $op) { |
||
161 | //if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) { |
||
162 | // exit('Invalid Referer'); |
||
163 | //} |
||
164 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
165 | redirect_header(XOOPS_URL . '/', 3, $GLOBALS['xoopsSecurity']->getErrors()); |
||
166 | } |
||
167 | if (!empty($_POST['side'])) { |
||
168 | $side = $_POST['side']; |
||
169 | } |
||
170 | // if ( !empty($_POST['weight']) ) { $weight = $_POST['weight']; } |
||
171 | if (!empty($_POST['visible'])) { |
||
172 | $visible = $_POST['visible']; |
||
173 | } |
||
174 | // if ( !empty($_POST['oldside']) ) { $oldside = $_POST['oldside']; } |
||
175 | // if ( !empty($_POST['oldweight']) ) { $oldweight = $_POST['oldweight']; } |
||
176 | // if ( !empty($_POST['oldvisible']) ) { $oldvisible = $_POST['oldvisible']; } |
||
177 | if (!empty($_POST['bid'])) { |
||
178 | $bid = $_POST['bid']; |
||
179 | } else { |
||
180 | $bid = []; |
||
181 | } |
||
182 | // GIJ start |
||
183 | foreach (array_keys($bid) as $i) { |
||
184 | if ($side[$i] < 0) { |
||
185 | $visible[$i] = 0; |
||
186 | $side[$i] = -1; |
||
187 | } else { |
||
188 | $visible[$i] = 1; |
||
189 | } |
||
190 | |||
191 | $bmodule = (isset($_POST['bmodule'][$i]) && is_array($_POST['bmodule'][$i])) ? $_POST['bmodule'][$i] : [-1]; |
||
192 | |||
193 | myblocksadmin_update_block($i, $side[$i], $_POST['weight'][$i], $visible[$i], $_POST['title'][$i], null, null, $_POST['bcachetime'][$i], $bmodule, []); |
||
194 | |||
195 | // if ( $oldweight[$i] != $weight[$i] || $oldvisible[$i] != $visible[$i] || $oldside[$i] != $side[$i] ) |
||
196 | // order_block($bid[$i], $weight[$i], $visible[$i], $side[$i]); |
||
197 | } |
||
198 | $query4redirect = '?dirname=' . urlencode(strip_tags(mb_substr($_POST['query4redirect'], 9))); |
||
199 | redirect_header("myblocksadmin.php$query4redirect", 1, _AM_SYSTEM_DBUPDATED); |
||
200 | // GIJ end |
||
201 | exit(); |
||
202 | } |
||
203 | |||
204 | if ('order2' === $op) { |
||
205 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
206 | redirect_header(XOOPS_URL . '/', 3, $GLOBALS['xoopsSecurity']->getErrors()); |
||
207 | } |
||
208 | |||
209 | if (isset($_POST['addblock']) && is_array($_POST['addblock'])) { |
||
210 | // addblock |
||
211 | foreach ($_POST['addblock'] as $bid => $val) { |
||
212 | myblocksadmin_update_blockinstance(0, 0, 0, 0, '', null, null, 0, [], [], (int)$bid); |
||
213 | } |
||
214 | } else { |
||
215 | // else change order |
||
216 | if (!empty($_POST['side'])) { |
||
217 | $side = $_POST['side']; |
||
218 | } |
||
219 | if (!empty($_POST['visible'])) { |
||
220 | $visible = $_POST['visible']; |
||
221 | } |
||
222 | if (!empty($_POST['id'])) { |
||
223 | $id = $_POST['id']; |
||
224 | } else { |
||
225 | $id = []; |
||
226 | } |
||
227 | |||
228 | foreach (array_keys($id) as $i) { |
||
229 | // separate side and visible |
||
230 | if ($side[$i] < 0) { |
||
231 | $visible[$i] = 0; |
||
232 | $side[$i] = -1; // for not to destroy the original position |
||
233 | } else { |
||
234 | $visible[$i] = 1; |
||
235 | } |
||
236 | |||
237 | $bmodule = (isset($_POST['bmodule'][$i]) && is_array($_POST['bmodule'][$i])) ? $_POST['bmodule'][$i] : [-1]; |
||
238 | |||
239 | myblocksadmin_update_blockinstance($i, $side[$i], $_POST['weight'][$i], $visible[$i], $_POST['title'][$i], null, null, $_POST['bcachetime'][$i], $bmodule, []); |
||
240 | } |
||
241 | } |
||
242 | |||
243 | $query4redirect = '?dirname=' . urlencode(strip_tags(mb_substr($_POST['query4redirect'], 9))); |
||
244 | redirect_header("myblocksadmin.php$query4redirect", 1, _AM_SYSTEM_DBUPDATED); |
||
245 | exit; |
||
246 | } |
||
247 | |||
248 | /* if ( $op == 'save' ) { |
||
249 | if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) { |
||
250 | exit('Invalid Referer'); |
||
251 | } |
||
252 | if ( ! $xoopsGTicket->check( true , 'myblocksadmin' ) ) { |
||
253 | redirect_header(XOOPS_URL.'/',3,$GLOBALS['xoopsSecurity']->getErrors()); |
||
254 | } |
||
255 | if ( !empty($_POST['bside']) ) { $bside = intval($_POST['bside']); } else { $bside = 0; } |
||
256 | if ( !empty($_POST['bweight']) ) { $bweight = intval($_POST['bweight']); } else { $bweight = 0; } |
||
257 | if ( !empty($_POST['bvisible']) ) { $bvisible = intval($_POST['bvisible']); } else { $bvisible = 0; } |
||
258 | if ( !empty($_POST['bmodule']) ) { $bmodule = $_POST['bmodule']; } else { $bmodule = []; } |
||
259 | if ( !empty($_POST['btitle']) ) { $btitle = $_POST['btitle']; } else { $btitle = ""; } |
||
260 | if ( !empty($_POST['bcontent']) ) { $bcontent = $_POST['bcontent']; } else { $bcontent = ""; } |
||
261 | if ( !empty($_POST['bctype']) ) { $bctype = $_POST['bctype']; } else { $bctype = ""; } |
||
262 | if ( !empty($_POST['bcachetime']) ) { $bcachetime = intval($_POST['bcachetime']); } else { $bcachetime = 0; } |
||
263 | save_block($bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bmodule, $bcachetime); |
||
264 | exit(); |
||
265 | } */ |
||
266 | |||
267 | if ('update' === $op) { |
||
268 | //if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) { |
||
269 | // exit('Invalid Referer'); |
||
270 | //} |
||
271 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
272 | redirect_header(XOOPS_URL . '/', 3, $GLOBALS['xoopsSecurity']->getErrors()); |
||
273 | } |
||
274 | /* if ( !empty($_POST['bside']) ) { $bside = intval($_POST['bside']); } else { $bside = 0; } |
||
275 | if ( !empty($_POST['bweight']) ) { $bweight = intval($_POST['bweight']); } else { $bweight = 0; } |
||
276 | if ( !empty($_POST['bvisible']) ) { $bvisible = intval($_POST['bvisible']); } else { $bvisible = 0; } |
||
277 | if ( !empty($_POST['btitle']) ) { $btitle = $_POST['btitle']; } else { $btitle = ""; } |
||
278 | if ( !empty($_POST['bcontent']) ) { $bcontent = $_POST['bcontent']; } else { $bcontent = ""; } |
||
279 | if ( !empty($_POST['bctype']) ) { $bctype = $_POST['bctype']; } else { $bctype = ""; } |
||
280 | if ( !empty($_POST['bcachetime']) ) { $bcachetime = intval($_POST['bcachetime']); } else { $bcachetime = 0; } |
||
281 | if ( !empty($_POST['bmodule']) ) { $bmodule = $_POST['bmodule']; } else { $bmodule = []; } |
||
282 | if ( !empty($_POST['options']) ) { $options = $_POST['options']; } else { $options = []; } |
||
283 | update_block($bid, $bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bcachetime, $bmodule, $options);*/ |
||
284 | |||
285 | $bcachetime = isset($_POST['bcachetime']) ? (int)$_POST['bcachetime'] : 0; |
||
286 | $options = Request::getArray('options', [], 'POST'); |
||
287 | $bcontent = Request::getString('bcontent', '', 'POST'); |
||
288 | $bctype = Request::getString('bctype', '', 'POST'); |
||
289 | $bmodule = (isset($_POST['bmodule']) && is_array($_POST['bmodule'])) ? $_POST['bmodule'] : [-1]; // GIJ + |
||
290 | $msg = myblocksadmin_update_block( |
||
291 | Request::getInt('bid', 0, 'POST'), |
||
292 | Request::getInt('bside', 0, 'POST'), |
||
293 | Request::getInt('bweight', 0, 'POST'), |
||
294 | Request::getInt('bvisible', 0, 'POST'), |
||
295 | Request::getString('btitle', '', 'POST'), |
||
296 | $bcontent, |
||
297 | $bctype, |
||
298 | $bcachetime, |
||
299 | $bmodule, |
||
300 | $options |
||
301 | ); // GIJ ! |
||
302 | redirect_header('myblocksadmin.php', 1, $msg); |
||
303 | } |
||
304 | |||
305 | if ('delete_ok' === $op) { |
||
306 | //if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) { |
||
307 | // exit('Invalid Referer'); |
||
308 | //} |
||
309 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
310 | redirect_header(XOOPS_URL . '/', 3, $GLOBALS['xoopsSecurity']->getErrors()); |
||
311 | } |
||
312 | // delete_block_ok($bid); GIJ imported from blocksadmin.php |
||
313 | $myblock = new XoopsBlock($bid); |
||
314 | if ('D' !== $myblock->getVar('block_type') && 'C' !== $myblock->getVar('block_type')) { |
||
315 | redirect_header('myblocksadmin.php', 4, 'Invalid block'); |
||
316 | exit(); |
||
317 | } |
||
318 | $myblock->delete(); |
||
319 | if ('' != $myblock->getVar('template') && !defined('XOOPS_ORETEKI')) { |
||
320 | /** @var \XoopsTplfileHandler $tplfileHandler */ |
||
321 | $tplfileHandler = xoops_getHandler('tplfile'); |
||
322 | $btemplate = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid); |
||
323 | if (count($btemplate) > 0) { |
||
324 | $tplman->delete($btemplate[0]); |
||
325 | } |
||
326 | } |
||
327 | redirect_header('myblocksadmin.php', 1, _AM_SYSTEM_DBUPDATED); |
||
328 | exit(); |
||
329 | // end of delete_block_ok() GIJ |
||
330 | exit(); |
||
331 | } |
||
332 | |||
333 | if ('delete' === $op) { |
||
334 | xoops_cp_header(); |
||
335 | // delete_block($bid); GIJ imported from blocksadmin.php |
||
336 | $myblock = new XoopsBlock($bid); |
||
337 | if ('S' === $myblock->getVar('block_type')) { |
||
338 | $message = _AM_SYSTEMCANT; |
||
339 | redirect_header('admin.php?fct=blocksadmin', 4, $message); |
||
340 | exit(); |
||
341 | } |
||
342 | |||
343 | if ('M' === $myblock->getVar('block_type')) { |
||
344 | $message = _AM_MODULECANT; |
||
345 | redirect_header('admin.php?fct=blocksadmin', 4, $message); |
||
346 | exit(); |
||
347 | } |
||
348 | xoops_confirm(['fct' => 'blocksadmin', 'op' => 'delete_ok', 'bid' => $myblock->getVar('bid')], 'admin.php', sprintf(_AM_RUSUREDEL, $myblock->getVar('title'))); |
||
349 | |||
350 | // end of delete_block() GIJ |
||
351 | xoops_cp_footer(); |
||
352 | exit(); |
||
353 | } |
||
354 | |||
355 | if ('edit' === $op) { |
||
356 | xoops_cp_header(); |
||
357 | // edit_block($bid); GIJ imported from blocksadmin.php |
||
358 | $myblock = new XoopsBlock($bid); |
||
359 | |||
360 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
361 | $sql = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid; |
||
362 | $result = $db->query($sql); |
||
363 | $modules = []; |
||
364 | while (false !== ($row = $db->fetchArray($result))) { |
||
365 | $modules[] = (int)$row['module_id']; |
||
366 | } |
||
367 | $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type')); |
||
368 | $block = [ |
||
369 | 'form_title' => _AM_SYSTEM_BLOCKS_EDITBLOCK, |
||
370 | 'name' => $myblock->getVar('name'), |
||
371 | 'side' => $myblock->getVar('side'), |
||
372 | 'weight' => $myblock->getVar('weight'), |
||
373 | 'visible' => $myblock->getVar('visible'), |
||
374 | 'title' => $myblock->getVar('title', 'E'), |
||
375 | 'content' => $myblock->getVar('content', 'n'), |
||
376 | 'modules' => $modules, |
||
377 | 'is_custom' => $is_custom, |
||
378 | 'ctype' => $myblock->getVar('c_type'), |
||
379 | 'cachetime' => $myblock->getVar('bcachetime'), |
||
380 | 'op' => 'update', |
||
381 | 'bid' => $myblock->getVar('bid'), |
||
382 | 'edit_form' => $myblock->getOptions(), |
||
383 | 'template' => $myblock->getVar('template'), |
||
384 | 'options' => $myblock->getVar('options'), |
||
385 | 'submit_button' => _SUBMIT, |
||
386 | ]; |
||
387 | |||
388 | echo '<a href="myblocksadmin.php">' . _AM_SYSTEM_BLOCKS_ADMIN . '</a> <span style="font-weight:bold;">»»</span> ' . _AM_SYSTEM_BLOCKS_EDITBLOCK . '<br><br>'; |
||
389 | require \dirname(__DIR__) . '/admin/myblockform.php'; //GIJ |
||
390 | $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
391 | $form->display(); |
||
392 | // end of edit_block() GIJ |
||
393 | xoops_cp_footer(); |
||
394 | exit(); |
||
395 | } |
||
396 | |||
397 | if ('clone' === $op) { |
||
398 | xoops_cp_header(); |
||
399 | $myblock = new XoopsBlock($bid); |
||
400 | |||
401 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
402 | $sql = 'SELECT module_id FROM ' . $db->prefix('block_module_link') . ' WHERE block_id=' . (int)$bid; |
||
403 | $result = $db->query($sql); |
||
404 | $modules = []; |
||
405 | while (false !== ($row = $db->fetchArray($result))) { |
||
406 | $modules[] = (int)$row['module_id']; |
||
407 | } |
||
408 | $is_custom = ('C' === $myblock->getVar('block_type') || 'E' === $myblock->getVar('block_type')); |
||
409 | $block = [ |
||
410 | 'form_title' => _AM_SYSTEM_BLOCKS_CLONEBLOCK, |
||
411 | 'name' => $myblock->getVar('name'), |
||
412 | 'side' => $myblock->getVar('side'), |
||
413 | 'weight' => $myblock->getVar('weight'), |
||
414 | 'visible' => $myblock->getVar('visible'), |
||
415 | 'content' => $myblock->getVar('content', 'N'), |
||
416 | 'title' => $myblock->getVar('title', 'E'), |
||
417 | 'modules' => $modules, |
||
418 | 'is_custom' => $is_custom, |
||
419 | 'ctype' => $myblock->getVar('c_type'), |
||
420 | 'cachetime' => $myblock->getVar('bcachetime'), |
||
421 | 'op' => 'clone_ok', |
||
422 | 'bid' => $myblock->getVar('bid'), |
||
423 | 'edit_form' => $myblock->getOptions(), |
||
424 | 'template' => $myblock->getVar('template'), |
||
425 | 'options' => $myblock->getVar('options'), |
||
426 | 'submit_button' => _CLONE, |
||
427 | ]; |
||
428 | echo '<a href="myblocksadmin.php">' . _AM_SYSTEM_BLOCKS_ADMIN . '</a> <span style="font-weight:bold;">»»</span> ' . _AM_SYSTEM_BLOCKS_CLONEBLOCK . '<br><br>'; |
||
429 | require \dirname(__DIR__) . '/admin/myblockform.php'; |
||
430 | $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
431 | $form->display(); |
||
432 | xoops_cp_footer(); |
||
433 | exit(); |
||
434 | } |
||
435 | |||
436 | if ('clone_ok' === $op) { |
||
437 | // Ticket Check |
||
438 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
439 | redirect_header(XOOPS_URL . '/', 3, $GLOBALS['xoopsSecurity']->getErrors()); |
||
440 | } |
||
441 | |||
442 | $block = new XoopsBlock($bid); |
||
443 | |||
444 | // block type check |
||
445 | $block_type = $block->getVar('block_type'); |
||
446 | if ('C' !== $block_type && 'M' !== $block_type && 'D' !== $block_type) { |
||
447 | redirect_header('myblocksadmin.php', 4, 'Invalid block'); |
||
448 | } |
||
449 | |||
450 | if (empty($_POST['options'])) { |
||
451 | $options = []; |
||
452 | } elseif (is_array($_POST['options'])) { |
||
453 | $options = $_POST['options']; |
||
454 | } else { |
||
455 | $options = explode('|', $_POST['options']); |
||
456 | } |
||
457 | |||
458 | // for backward compatibility |
||
459 | // $cblock =& $block->clone(); or $cblock =& $block->xoopsClone(); |
||
460 | $cblock = new XoopsBlock(); |
||
461 | foreach ($block->vars as $k => $v) { |
||
462 | $cblock->assignVar($k, $v['value']); |
||
463 | } |
||
464 | $cblock->setNew(); |
||
465 | |||
466 | $myts = MyTextSanitizer::getInstance(); |
||
467 | $cblock->setVar('side', $_POST['bside']); |
||
468 | $cblock->setVar('weight', $_POST['bweight']); |
||
469 | $cblock->setVar('visible', $_POST['bvisible']); |
||
470 | $cblock->setVar('title', $_POST['btitle']); |
||
471 | $cblock->setVar('content', @$_POST['bcontent']); |
||
472 | $cblock->setVar('c_type', @$_POST['bctype']); |
||
473 | $cblock->setVar('bcachetime', $_POST['bcachetime']); |
||
474 | if (isset($options) && (count($options) > 0)) { |
||
475 | $options = implode('|', $options); |
||
476 | $cblock->setVar('options', $options); |
||
477 | } |
||
478 | $cblock->setVar('bid', 0); |
||
479 | $cblock->setVar('block_type', 'C' === $block_type ? 'C' : 'D'); |
||
480 | $cblock->setVar('func_num', 255); |
||
481 | $newid = $cblock->store(); |
||
482 | if (!$newid) { |
||
483 | xoops_cp_header(); |
||
484 | $cblock->getHtmlErrors(); |
||
485 | xoops_cp_footer(); |
||
486 | exit(); |
||
487 | } |
||
488 | /* if ($cblock->getVar('template') != '') { |
||
489 | $tplfileHandler = xoops_getHandler('tplfile'); |
||
490 | $btemplate =& $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid); |
||
491 | if (count($btemplate) > 0) { |
||
492 | $tplclone =& $btemplate[0]->clone(); |
||
493 | $tplclone->setVar('tpl_id', 0); |
||
494 | $tplclone->setVar('tpl_refid', $newid); |
||
495 | $tplman->insert($tplclone); |
||
496 | } |
||
497 | } */ |
||
498 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
499 | $bmodule = (isset($_POST['bmodule']) && is_array($_POST['bmodule'])) ? $_POST['bmodule'] : [-1]; // GIJ + |
||
500 | foreach ($bmodule as $bmid) { |
||
501 | $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . $bmid . ')'; |
||
502 | $db->query($sql); |
||
503 | } |
||
504 | |||
505 | /* global $xoopsUser; |
||
506 | $groups =& $xoopsUser->getGroups(); |
||
507 | $count = count($groups); |
||
508 | for ($i = 0; $i < $count; ++$i) { |
||
509 | $sql = "INSERT INTO ".$db->prefix('group_permission')." (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (".$groups[$i].", ".$newid.", 1, 'block_read')"; |
||
510 | $db->query($sql); |
||
511 | } |
||
512 | */ |
||
513 | |||
514 | $sql = 'SELECT gperm_groupid FROM ' . $db->prefix('group_permission') . " WHERE gperm_name='block_read' AND gperm_modid='1' AND gperm_itemid='$bid'"; |
||
515 | $result = $db->query($sql); |
||
516 | while (list($gid) = $db->fetchRow($result)) { |
||
517 | $sql = 'INSERT INTO ' . $db->prefix('group_permission') . " (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES ($gid, $newid, 1, 'block_read')"; |
||
518 | $db->query($sql); |
||
519 | } |
||
520 | |||
521 | redirect_header('myblocksadmin.php', 1, _AM_SYSTEM_DBUPDATED); |
||
522 | } |
||
523 | |||
524 | // import from modules/system/admin/blocksadmin/blocksadmin.php |
||
525 | /** |
||
526 | * @param $bid |
||
527 | * @param $bside |
||
528 | * @param $bweight |
||
529 | * @param $bvisible |
||
530 | * @param $btitle |
||
531 | * @param $bcontent |
||
532 | * @param $bctype |
||
533 | * @param $bcachetime |
||
534 | * @param $bmodule |
||
535 | * @param array $options |
||
536 | * @return string |
||
537 | */ |
||
538 | function myblocksadmin_update_block($bid, $bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bcachetime, $bmodule, $options = []) |
||
539 | { |
||
540 | global $xoopsConfig; |
||
541 | /* if (empty($bmodule)) { |
||
542 | xoops_cp_header(); |
||
543 | xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN)); |
||
544 | xoops_cp_footer(); |
||
545 | exit(); |
||
546 | } */ |
||
547 | $myblock = new XoopsBlock($bid); |
||
548 | // $myblock->setVar('side', $bside); GIJ - |
||
549 | if ($bside >= 0) { |
||
550 | $myblock->setVar('side', $bside); |
||
551 | } // GIJ + |
||
552 | $myblock->setVar('weight', $bweight); |
||
553 | $myblock->setVar('visible', $bvisible); |
||
554 | $myblock->setVar('title', $btitle); |
||
555 | if (isset($bcontent)) { |
||
556 | $myblock->setVar('content', $bcontent); |
||
557 | } |
||
558 | if (isset($bctype)) { |
||
559 | $myblock->setVar('c_type', $bctype); |
||
560 | } |
||
561 | $myblock->setVar('bcachetime', $bcachetime); |
||
562 | if (isset($options) && (count($options) > 0)) { |
||
563 | $options = implode('|', $options); |
||
564 | $myblock->setVar('options', $options); |
||
565 | } |
||
566 | if ('C' === $myblock->getVar('block_type')) { |
||
567 | switch ($myblock->getVar('c_type')) { |
||
568 | case 'H': |
||
569 | $name = _AM_CUSTOMHTML; |
||
570 | break; |
||
571 | case 'P': |
||
572 | $name = _AM_CUSTOMPHP; |
||
573 | break; |
||
574 | case 'S': |
||
575 | $name = _AM_CUSTOMSMILE; |
||
576 | break; |
||
577 | default: |
||
578 | $name = _AM_CUSTOMNOSMILE; |
||
579 | break; |
||
580 | } |
||
581 | $myblock->setVar('name', $name); |
||
582 | } |
||
583 | $msg = _AM_SYSTEM_DBUPDATED; |
||
584 | if (false !== $myblock->store()) { |
||
585 | $db = XoopsDatabaseFactory::getDatabaseConnection(); |
||
586 | $sql = sprintf('DELETE FROM %s WHERE block_id = %u', $db->prefix('block_module_link'), $bid); |
||
587 | $db->query($sql); |
||
588 | foreach ($bmodule as $bmid) { |
||
589 | $sql = sprintf('INSERT INTO %s (block_id, module_id) VALUES (%u, %d)', $db->prefix('block_module_link'), $bid, (int)$bmid); |
||
590 | $db->query($sql); |
||
591 | } |
||
592 | require_once XOOPS_ROOT_PATH . '/class/template.php'; |
||
593 | $xoopsTpl = new XoopsTpl(); |
||
594 | $xoopsTpl->caching = 2; |
||
595 | if ('' != $myblock->getVar('template')) { |
||
596 | if ($xoopsTpl->is_cached('db:' . $myblock->getVar('template'))) { |
||
597 | if (!$xoopsTpl->clear_cache('db:' . $myblock->getVar('template'))) { |
||
598 | $msg = 'Unable to clear cache for block ID' . $bid; |
||
599 | } |
||
600 | } |
||
601 | } elseif ($xoopsTpl->is_cached('db:system_dummy.html', 'block' . $bid)) { |
||
602 | if (!$xoopsTpl->clear_cache('db:system_dummy.html', 'block' . $bid)) { |
||
603 | $msg = 'Unable to clear cache for block ID' . $bid; |
||
604 | } |
||
605 | } |
||
606 | } else { |
||
607 | $msg = 'Failed update of block. ID:' . $bid; |
||
608 | } |
||
609 | // redirect_header('admin.php?fct=blocksadmin&t='.time(),1,$msg); |
||
610 | // exit(); GIJ - |
||
611 | return $msg; // GIJ + |
||
612 | } |
||
613 | |||
614 | // update block instance for 2.2 |
||
615 | /** |
||
616 | * @param $id |
||
617 | * @param $bside |
||
618 | * @param $bweight |
||
619 | * @param $bvisible |
||
620 | * @param $btitle |
||
621 | * @param $bcontent |
||
622 | * @param $bctype |
||
623 | * @param $bcachetime |
||
624 | * @param $bmodule |
||
625 | * @param array $options |
||
626 | * @param null $bid |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
627 | * @return string |
||
628 | */ |
||
629 | function myblocksadmin_update_blockinstance($id, $bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bcachetime, $bmodule, $options = [], $bid = null) |
||
630 | { |
||
631 | global $xoopsDB; |
||
632 | |||
633 | $instanceHandler = xoops_getHandler('blockinstance'); |
||
634 | $blockHandler = xoops_getHandler('block'); |
||
635 | if ($id > 0) { |
||
636 | // update |
||
637 | $instance = $instanceHandler->get($id); |
||
638 | if ($bside >= 0) { |
||
639 | $instance->setVar('side', $bside); |
||
640 | } |
||
641 | if (!empty($options)) { |
||
642 | $instance->setVar('options', $options); |
||
643 | } |
||
644 | } else { |
||
645 | // insert |
||
646 | $instance = $instanceHandler->create(); |
||
647 | $instance->setVar('bid', $bid); |
||
648 | $instance->setVar('side', $bside); |
||
649 | $block = $blockHandler->get($bid); |
||
650 | $instance->setVar('options', $block->getVar('options')); |
||
651 | if (empty($btitle)) { |
||
652 | $btitle = $block->getVar('name'); |
||
653 | } |
||
654 | } |
||
655 | $instance->setVar('weight', $bweight); |
||
656 | $instance->setVar('visible', $bvisible); |
||
657 | $instance->setVar('title', $btitle); |
||
658 | // if( isset( $bcontent ) ) $instance->setVar('content', $bcontent); |
||
659 | // if( isset( $bctype ) ) $instance->setVar('c_type', $bctype); |
||
660 | $instance->setVar('bcachetime', $bcachetime); |
||
661 | |||
662 | if ($instanceHandler->insert($instance)) { |
||
663 | $GLOBALS['xoopsDB']->query('DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('block_module_link') . ' WHERE block_id=' . $instance->getVar('instanceid')); |
||
664 | foreach ($bmodule as $mid) { |
||
665 | $page = explode('-', $mid); |
||
666 | $mid = $page[0]; |
||
667 | $pageid = $page[1]; |
||
668 | $GLOBALS['xoopsDB']->query('INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('block_module_link') . ' VALUES (' . $instance->getVar('instanceid') . ', ' . (int)$mid . ', ' . (int)$pageid . ')'); |
||
669 | } |
||
670 | |||
671 | return _AM_SYSTEM_DBUPDATED; |
||
672 | } |
||
673 | |||
674 | return 'Failed update of block instance. ID:' . $id; |
||
675 | /* // NAME for CUSTOM BLOCK |
||
676 | if ( $instance->getVar('block_type') == 'C') { |
||
677 | switch ( $instance->getVar('c_type') ) { |
||
678 | case 'H': |
||
679 | $name = _AM_CUSTOMHTML; |
||
680 | break; |
||
681 | case 'P': |
||
682 | $name = _AM_CUSTOMPHP; |
||
683 | break; |
||
684 | case 'S': |
||
685 | $name = _AM_CUSTOMSMILE; |
||
686 | break; |
||
687 | default: |
||
688 | $name = _AM_CUSTOMNOSMILE; |
||
689 | break; |
||
690 | } |
||
691 | $instance->setVar('name', $name); |
||
692 | } |
||
693 | */ |
||
694 | /* // CLEAR TEMPLATE CACHE |
||
695 | require_once XOOPS_ROOT_PATH.'/class/template.php'; |
||
696 | $xoopsTpl = new XoopsTpl(); |
||
697 | $xoopsTpl->caching = 2; |
||
698 | if ($instance->getVar('template') != '') { |
||
699 | if ($xoopsTpl->is_cached('db:'.$instance->getVar('template'))) { |
||
700 | if (!$xoopsTpl->clear_cache('db:'.$instance->getVar('template'))) { |
||
701 | $msg = 'Unable to clear cache for block ID'.$bid; |
||
702 | } |
||
703 | } |
||
704 | } else { |
||
705 | if ($xoopsTpl->is_cached('db:system_dummy.html', 'block'.$bid)) { |
||
706 | if (!$xoopsTpl->clear_cache('db:system_dummy.html', 'block'.$bid)) { |
||
707 | $msg = 'Unable to clear cache for block ID'.$bid; |
||
708 | } |
||
709 | } |
||
710 | } |
||
711 | */ |
||
712 | } |
||
713 | |||
714 | // TODO edit2, delete2, customblocks |
||
715 |