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