1
|
|
|
<?php |
2
|
|
|
// $Id: blocksadmin.inc.php 8344 2011-11-26 02:38:25Z beckmi $ |
3
|
|
|
// ------------------------------------------------------------------------ // |
4
|
|
|
// XOOPS - PHP Content Management System // |
5
|
|
|
// Copyright (c) 2000 XOOPS.org // |
6
|
|
|
// <http://www.xoops.org/> // |
7
|
|
|
// ------------------------------------------------------------------------ // |
8
|
|
|
// This program is free software; you can redistribute it and/or modify // |
9
|
|
|
// it under the terms of the GNU General Public License as published by // |
10
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
11
|
|
|
// (at your option) any later version. // |
12
|
|
|
// // |
13
|
|
|
// You may not change or alter any portion of this comment or credits // |
14
|
|
|
// of supporting developers from this source code or any supporting // |
15
|
|
|
// source code which is considered copyrighted (c) material of the // |
16
|
|
|
// original comment or credit authors. // |
17
|
|
|
// // |
18
|
|
|
// This program is distributed in the hope that it will be useful, // |
19
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
20
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
21
|
|
|
// GNU General Public License for more details. // |
22
|
|
|
// // |
23
|
|
|
// You should have received a copy of the GNU General Public License // |
24
|
|
|
// along with this program; if not, write to the Free Software // |
25
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
26
|
|
|
// ------------------------------------------------------------------------ // |
27
|
|
|
// Author: Kazumi Ono (AKA onokazu) // |
28
|
|
|
// URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ // |
29
|
|
|
// Project: The XOOPS Project // |
30
|
|
|
// ------------------------------------------------------------------------- // |
31
|
|
|
|
32
|
|
|
if (!is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid())) { |
33
|
|
|
exit('Access Denied'); |
34
|
|
|
} |
35
|
|
|
include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; |
36
|
|
|
include XOOPS_ROOT_PATH . '/modules/system/admin/blocksadmin/blocksadmin.php'; |
37
|
|
|
|
38
|
|
|
$op = 'list'; |
39
|
|
|
|
40
|
|
|
if (!empty($_POST['op'])) { |
41
|
|
|
$op = $_POST['op']; |
42
|
|
|
} |
43
|
|
|
if (!empty($_POST['bid'])) { |
44
|
|
|
$bid = (int)$_POST['bid']; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
if (isset($_GET['op'])) { |
48
|
|
|
if ($_GET['op'] == 'edit' || $_GET['op'] == 'delete' || $_GET['op'] == 'delete_ok' |
49
|
|
|
|| $_GET['op'] == 'clone' /* || $_GET['op'] == 'previewpopup'*/ |
50
|
|
|
) { |
51
|
|
|
$op = $_GET['op']; |
52
|
|
|
$bid = isset($_GET['bid']) ? (int)$_GET['bid'] : 0; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
if (isset($_POST['previewblock'])) { |
57
|
|
|
/* |
58
|
|
|
if (!admin_refcheck("/modules/$admin_mydirname/admin/")) { |
59
|
|
|
exit('Invalid Referer'); |
60
|
|
|
} |
61
|
|
|
*/ |
62
|
|
View Code Duplication |
if (!$xoopsGTicket->check(true, 'myblocksadmin')) { |
|
|
|
|
63
|
|
|
redirect_header(XOOPS_URL . '/', 3, $xoopsGTicket->getErrors()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
if (empty($bid)) { |
67
|
|
|
die('Invalid bid.'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$bside = (!empty($_POST['bside'])) ? (int)$_POST['bside'] : 0; |
71
|
|
|
$bweight = (!empty($_POST['bweight'])) ? (int)$_POST['bweight'] : 0; |
72
|
|
|
$bvisible = (!empty($_POST['bvisible'])) ? (int)$_POST['bvisible'] : 0; |
73
|
|
|
$bmodule = (!empty($_POST['bmodule'])) ? $_POST['bmodule'] : array(); |
74
|
|
|
$btitle = (!empty($_POST['btitle'])) ? $_POST['btitle'] : ''; |
75
|
|
|
$bcontent = (!empty($_POST['bcontent'])) ? $_POST['bcontent'] : ''; |
76
|
|
|
$bctype = (!empty($_POST['bctype'])) ? $_POST['bctype'] : ''; |
77
|
|
|
$bcachetime = (!empty($_POST['bcachetime'])) ? (int)$_POST['bcachetime'] : 0; |
78
|
|
|
|
79
|
|
|
xoops_cp_header(); |
80
|
|
|
include_once XOOPS_ROOT_PATH . '/class/template.php'; |
81
|
|
|
$xoopsTpl = new XoopsTpl(); |
82
|
|
|
//$xoopsTpl->xoops_setCaching(0); |
83
|
|
|
$xoopsTpl->caching = 0; |
84
|
|
|
$block['bid'] = $bid; |
85
|
|
|
|
86
|
|
|
if ($op == 'clone_ok') { |
87
|
|
|
$block['form_title'] = _AM_CLONEBLOCK; |
88
|
|
|
$block['submit_button'] = _CLONE; |
89
|
|
|
$myblock = new XoopsBlock(); |
90
|
|
|
$myblock->setVar('block_type', 'C'); |
91
|
|
|
} else { |
92
|
|
|
$op = 'update'; |
93
|
|
|
$block['form_title'] = _AM_EDITBLOCK; |
94
|
|
|
$block['submit_button'] = _SUBMIT; |
95
|
|
|
$myblock = new XoopsBlock($bid); |
96
|
|
|
$block['name'] = $myblock->getVar('name'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
$myts = MyTextSanitizer::getInstance(); |
100
|
|
|
$myblock->setVar('title', $myts->stripSlashesGPC($btitle)); |
101
|
|
|
$myblock->setVar('content', $myts->stripSlashesGPC($bcontent)); |
102
|
|
|
/* |
103
|
|
|
$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>'; |
104
|
|
|
$dummyfile = '_dummyfile_'.time().'.html'; |
105
|
|
|
$fp = fopen(XOOPS_CACHE_PATH.'/'.$dummyfile, 'w'); |
106
|
|
|
fwrite($fp, $dummyhtml); |
107
|
|
|
fclose($fp); |
108
|
|
|
*/ |
109
|
|
|
$block['edit_form'] = false; |
110
|
|
|
$block['template'] = ''; |
111
|
|
|
$block['op'] = $op; |
112
|
|
|
$block['side'] = $bside; |
113
|
|
|
$block['weight'] = $bweight; |
114
|
|
|
$block['visible'] = $bvisible; |
115
|
|
|
$block['title'] = $myblock->getVar('title', 'E'); |
116
|
|
|
$block['content'] = $myblock->getVar('content', 'n'); |
117
|
|
|
$block['modules'] = $bmodule; |
118
|
|
|
$block['ctype'] = isset($bctype) ? $bctype : $myblock->getVar('c_type'); |
119
|
|
|
$block['is_custom'] = true; |
120
|
|
|
$block['cachetime'] = (int)$bcachetime; |
121
|
|
|
echo '<a href="myblocksadmin.php">' . _AM_MYLINKS_BADMIN . '</a> <span style="font-weight:bold;">»»</span> ' . $block['form_title'] . '<br><br>'; |
122
|
|
|
include __DIR__ . '/../admin/myblockform.php'; //GIJ |
123
|
|
|
//echo '<a href="admin.php?fct=blocksadmin">'. _AM_MYLINKS_BADMIN .'</a> <span style="font-weight:bold;">»»</span> '.$block['form_title'].'<br><br>'; |
124
|
|
|
//include XOOPS_ROOT_PATH.'/modules/system/admin/blocksadmin/blockform.php'; |
125
|
|
|
$xoopsGTicket->addTicketXoopsFormElement($form, __LINE__, 1800, 'myblocksadmin'); //GIJ |
126
|
|
|
$form->display(); |
127
|
|
|
|
128
|
|
|
$original_level = error_reporting(E_ALL); |
129
|
|
|
echo "<table width='100%' class='outer' cellspacing='1'>\n" . " <tr>\n" . ' <th>' . $myblock->getVar('title') . "</th>\n" . " </tr>\n" . " <tr>\n" . " <td class='odd'>" . $myblock->getContent('S', $bctype) . "</td>\n" . " </tr>\n" . "</table>\n"; |
130
|
|
|
error_reporting($original_level); |
131
|
|
|
|
132
|
|
|
xoops_cp_footer(); |
133
|
|
|
/* |
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
|
|
|
/* |
142
|
|
|
if ($op == 'previewpopup') { |
143
|
|
|
if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) { |
144
|
|
|
exit('Invalid Referer'); |
145
|
|
|
} |
146
|
|
|
$file = str_replace('..', '', XOOPS_CACHE_PATH.'/'.trim($_GET['file'])); |
147
|
|
|
if (file_exists($file)) { |
148
|
|
|
include $file; |
149
|
|
|
@unlink($file); |
150
|
|
|
} |
151
|
|
|
exit(); |
152
|
|
|
} |
153
|
|
|
*/ |
154
|
|
|
|
155
|
|
|
/* |
156
|
|
|
if ( $op == "list" ) { |
157
|
|
|
xoops_cp_header(); |
158
|
|
|
list_blocks(); |
159
|
|
|
xoops_cp_footer(); |
160
|
|
|
exit(); |
161
|
|
|
} |
162
|
|
|
*/ |
163
|
|
|
|
164
|
|
|
if ($op == 'order') { |
165
|
|
|
//if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) { |
166
|
|
|
// exit('Invalid Referer'); |
167
|
|
|
//} |
168
|
|
View Code Duplication |
if (!$xoopsGTicket->check(true, 'myblocksadmin')) { |
|
|
|
|
169
|
|
|
redirect_header(XOOPS_URL . '/', 3, $xoopsGTicket->getErrors()); |
170
|
|
|
} |
171
|
|
|
if (!empty($_POST['side'])) { |
172
|
|
|
$side = $_POST['side']; |
173
|
|
|
} |
174
|
|
|
// if ( !empty($_POST['weight']) ) { $weight = $_POST['weight']; } |
175
|
|
|
if (!empty($_POST['visible'])) { |
176
|
|
|
$visible = $_POST['visible']; |
177
|
|
|
} |
178
|
|
|
/* |
179
|
|
|
if (!empty($_POST['oldside'])) { |
180
|
|
|
$oldside = $_POST['oldside']; |
181
|
|
|
} |
182
|
|
|
if (!empty($_POST['oldweight'])) { |
183
|
|
|
$oldweight = $_POST['oldweight']; |
184
|
|
|
} |
185
|
|
|
if (!empty($_POST['oldvisible'])) { |
186
|
|
|
$oldvisible = $_POST['oldvisible']; |
187
|
|
|
} |
188
|
|
|
*/ |
189
|
|
|
$bid = (!empty($_POST['bid'])) ? $_POST['bid'] : array(); |
190
|
|
|
// GIJ start |
191
|
|
View Code Duplication |
foreach (array_keys($bid) as $i) { |
|
|
|
|
192
|
|
|
if ($side[$i] < 0) { |
193
|
|
|
$visible[$i] = 0; |
194
|
|
|
$side[$i] = -1; |
195
|
|
|
} else { |
196
|
|
|
$visible[$i] = 1; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
$bmodule = (isset($_POST['bmodule'][$i]) |
200
|
|
|
&& is_array($_POST['bmodule'][$i])) ? $_POST['bmodule'][$i] : array(-1); |
201
|
|
|
myblocksadmin_update_block($i, $side[$i], $_POST['weight'][$i], $visible[$i], $_POST['title'][$i], null, null, $_POST['bcachetime'][$i], $bmodule, array()); |
202
|
|
|
|
203
|
|
|
// if ( $oldweight[$i] != $weight[$i] || $oldvisible[$i] != $visible[$i] || $oldside[$i] != $side[$i] ) |
204
|
|
|
// order_block($bid[$i], $weight[$i], $visible[$i], $side[$i]); |
205
|
|
|
} |
206
|
|
|
$query4redirect = '?dirname=' . urlencode(strip_tags(substr($_POST['query4redirect'], 9))); |
207
|
|
|
redirect_header("myblocksadmin.php$query4redirect", 1, _AM_DBUPDATED); |
208
|
|
|
// GIJ end |
209
|
|
|
exit(); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
if ($op == 'order2') { |
213
|
|
View Code Duplication |
if (!$xoopsGTicket->check(true, 'myblocksadmin')) { |
|
|
|
|
214
|
|
|
redirect_header(XOOPS_URL . '/', 3, $xoopsGTicket->getErrors()); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
if (isset($_POST['addblock']) && is_array($_POST['addblock'])) { |
218
|
|
|
// addblock |
219
|
|
|
foreach ($_POST['addblock'] as $bid => $val) { |
220
|
|
|
myblocksadmin_update_blockinstance(0, 0, 0, 0, '', null, null, 0, array(), array(), (int)$bid); |
221
|
|
|
} |
222
|
|
|
} else { |
223
|
|
|
|
224
|
|
|
// else change order |
225
|
|
|
if (!empty($_POST['side'])) { |
226
|
|
|
$side = $_POST['side']; |
227
|
|
|
} |
228
|
|
|
if (!empty($_POST['visible'])) { |
229
|
|
|
$visible = $_POST['visible']; |
230
|
|
|
} |
231
|
|
|
$id = (!empty($_POST['id'])) ? $_POST['id'] : array(); |
232
|
|
|
|
233
|
|
View Code Duplication |
foreach (array_keys($id) as $i) { |
|
|
|
|
234
|
|
|
// separate side and visible |
235
|
|
|
if ($side[$i] < 0) { |
236
|
|
|
$visible[$i] = 0; |
237
|
|
|
$side[$i] = -1; // for not to destroy the original position |
238
|
|
|
} else { |
239
|
|
|
$visible[$i] = 1; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
$bmodule = (isset($_POST['bmodule'][$i]) |
243
|
|
|
&& is_array($_POST['bmodule'][$i])) ? $_POST['bmodule'][$i] : array(-1); |
244
|
|
|
myblocksadmin_update_blockinstance($i, $side[$i], $_POST['weight'][$i], $visible[$i], $_POST['title'][$i], null, null, $_POST['bcachetime'][$i], $bmodule, array()); |
245
|
|
|
} |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
$query4redirect = '?dirname=' . urlencode(strip_tags(substr($_POST['query4redirect'], 9))); |
249
|
|
|
redirect_header("myblocksadmin.php$query4redirect", 1, _MD_MYLINKS_AM_DBUPDATED); |
250
|
|
|
exit; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/* if ( $op == 'save' ) { |
254
|
|
|
if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) { |
255
|
|
|
exit('Invalid Referer'); |
256
|
|
|
} |
257
|
|
|
if ( ! $xoopsGTicket->check( true , 'myblocksadmin' ) ) { |
258
|
|
|
redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors()); |
259
|
|
|
} |
260
|
|
|
if ( !empty($_POST['bside']) ) { $bside = intval($_POST['bside']); } else { $bside = 0; } |
261
|
|
|
if ( !empty($_POST['bweight']) ) { $bweight = intval($_POST['bweight']); } else { $bweight = 0; } |
262
|
|
|
if ( !empty($_POST['bvisible']) ) { $bvisible = intval($_POST['bvisible']); } else { $bvisible = 0; } |
263
|
|
|
if ( !empty($_POST['bmodule']) ) { $bmodule = $_POST['bmodule']; } else { $bmodule = array(); } |
264
|
|
|
if ( !empty($_POST['btitle']) ) { $btitle = $_POST['btitle']; } else { $btitle = ""; } |
265
|
|
|
if ( !empty($_POST['bcontent']) ) { $bcontent = $_POST['bcontent']; } else { $bcontent = ""; } |
266
|
|
|
if ( !empty($_POST['bctype']) ) { $bctype = $_POST['bctype']; } else { $bctype = ""; } |
267
|
|
|
if ( !empty($_POST['bcachetime']) ) { $bcachetime = intval($_POST['bcachetime']); } else { $bcachetime = 0; } |
268
|
|
|
save_block($bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bmodule, $bcachetime); |
269
|
|
|
exit(); |
270
|
|
|
} */ |
271
|
|
|
|
272
|
|
|
if ('update' == $op) { |
273
|
|
|
/* |
274
|
|
|
if (!admin_refcheck("/modules/$admin_mydirname/admin/")) { |
275
|
|
|
exit('Invalid Referer'); |
276
|
|
|
} |
277
|
|
|
*/ |
278
|
|
View Code Duplication |
if (!$xoopsGTicket->check(true, 'myblocksadmin')) { |
|
|
|
|
279
|
|
|
redirect_header(XOOPS_URL . '/', 3, $xoopsGTicket->getErrors()); |
280
|
|
|
} |
281
|
|
|
/* |
282
|
|
|
if ( !empty($_POST['bside']) ) { $bside = intval($_POST['bside']); } else { $bside = 0; } |
283
|
|
|
if ( !empty($_POST['bweight']) ) { $bweight = intval($_POST['bweight']); } else { $bweight = 0; } |
284
|
|
|
if ( !empty($_POST['bvisible']) ) { $bvisible = intval($_POST['bvisible']); } else { $bvisible = 0; } |
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 = intval($_POST['bcachetime']); } else { $bcachetime = 0; } |
289
|
|
|
if ( !empty($_POST['bmodule']) ) { $bmodule = $_POST['bmodule']; } else { $bmodule = array(); } |
290
|
|
|
if ( !empty($_POST['options']) ) { $options = $_POST['options']; } else { $options = array(); } |
291
|
|
|
update_block($bid, $bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bcachetime, $bmodule, $options); |
292
|
|
|
*/ |
293
|
|
|
|
294
|
|
|
$bcachetime = isset($_POST['bcachetime']) ? (int)$_POST['bcachetime'] : 0; |
295
|
|
|
$options = isset($_POST['options']) ? $_POST['options'] : array(); |
296
|
|
|
$bcontent = isset($_POST['bcontent']) ? $_POST['bcontent'] : ''; |
297
|
|
|
$bctype = isset($_POST['bctype']) ? $_POST['bctype'] : ''; |
298
|
|
|
$bmodule = (isset($_POST['bmodule']) && is_array($_POST['bmodule'])) ? $_POST['bmodule'] : array(-1); // GIJ + |
299
|
|
|
$msg = myblocksadmin_update_block($_POST['bid'], $_POST['bside'], $_POST['bweight'], $_POST['bvisible'], $_POST['btitle'], $bcontent, $bctype, $bcachetime, $bmodule, $options); // GIJ ! |
300
|
|
|
redirect_header('myblocksadmin.php', 1, $msg); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
if ('delete_ok' == $op) { |
304
|
|
|
/* |
305
|
|
|
if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) { |
306
|
|
|
exit('Invalid Referer'); |
307
|
|
|
} |
308
|
|
|
*/ |
309
|
|
View Code Duplication |
if (!$xoopsGTicket->check(true, 'myblocksadmin')) { |
|
|
|
|
310
|
|
|
redirect_header(XOOPS_URL . '/', 3, $xoopsGTicket->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
|
|
|
$tplfileHandler = xoops_getHandler('tplfile'); |
321
|
|
|
$btemplate = $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid); |
322
|
|
|
if (count($btemplate) > 0) { |
323
|
|
|
$tplman->delete($btemplate[0]); |
324
|
|
|
} |
325
|
|
|
} |
326
|
|
|
redirect_header('myblocksadmin.php', 1, _AM_DBUPDATED); |
327
|
|
|
// end of delete_block_ok() GIJ |
328
|
|
|
exit(); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
if ('delete' == $op) { |
332
|
|
|
xoops_cp_header(); |
333
|
|
|
// delete_block($bid); GIJ imported from blocksadmin.php |
334
|
|
|
$myblock = new XoopsBlock($bid); |
335
|
|
|
if ('S' == $myblock->getVar('block_type')) { |
336
|
|
|
$message = _AM_SYSTEMCANT; |
337
|
|
|
redirect_header('admin.php?fct=blocksadmin', 4, $message); |
338
|
|
|
exit(); |
339
|
|
|
} elseif ('M' == $myblock->getVar('block_type')) { |
340
|
|
|
$message = _AM_MODULECANT; |
341
|
|
|
redirect_header('admin.php?fct=blocksadmin', 4, $message); |
342
|
|
|
exit(); |
343
|
|
|
} else { |
344
|
|
|
xoops_confirm(array( |
345
|
|
|
'fct' => 'blocksadmin', |
346
|
|
|
'op' => 'delete_ok', |
347
|
|
|
'bid' => $myblock->getVar('bid') |
348
|
|
|
) + $xoopsGTicket->getTicketArray(__LINE__, 1800, 'myblocksadmin'), 'admin.php', sprintf(_AM_RUSUREDEL, $myblock->getVar('title'))); |
349
|
|
|
} |
350
|
|
|
// end of delete_block() GIJ |
351
|
|
|
xoops_cp_footer(); |
352
|
|
|
exit(); |
353
|
|
|
} |
354
|
|
|
|
355
|
|
View Code Duplication |
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 = array(); |
364
|
|
|
while ($row = $db->fetchArray($result)) { |
365
|
|
|
$modules[] = (int)$row['module_id']; |
366
|
|
|
} |
367
|
|
|
$is_custom = ('C' == $myblock->getVar('block_type') || 'E' == $myblock->getVar('block_type')) ? true : false; |
368
|
|
|
$block = array( |
369
|
|
|
'form_title' => _AM_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_MYLINKS_BADMIN . '</a> <span style="font-weight:bold;">»»</span> ' . _AM_EDITBLOCK . '<br><br>'; |
389
|
|
|
include __DIR__ . '/../admin/myblockform.php'; //GIJ |
390
|
|
|
$xoopsGTicket->addTicketXoopsFormElement($form, __LINE__, 1800, 'myblocksadmin'); //GIJ |
391
|
|
|
$form->display(); |
392
|
|
|
// end of edit_block() GIJ |
393
|
|
|
xoops_cp_footer(); |
394
|
|
|
exit(); |
395
|
|
|
} |
396
|
|
|
|
397
|
|
View Code Duplication |
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 = array(); |
405
|
|
|
while ($row = $db->fetchArray($result)) { |
406
|
|
|
$modules[] = (int)$row['module_id']; |
407
|
|
|
} |
408
|
|
|
$is_custom = ('C' == $myblock->getVar('block_type') || 'E' == $myblock->getVar('block_type')) ? true : false; |
409
|
|
|
$block = array( |
410
|
|
|
'form_title' => _AM_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_MYLINKS_BADMIN . '</a> <span style="font-weight:bold;">»»</span> ' . _AM_CLONEBLOCK . '<br><br>'; |
429
|
|
|
include __DIR__ . '/../admin/myblockform.php'; |
430
|
|
|
$xoopsGTicket->addTicketXoopsFormElement($form, __LINE__, 1800, 'myblocksadmin'); //GIJ |
431
|
|
|
$form->display(); |
432
|
|
|
xoops_cp_footer(); |
433
|
|
|
exit(); |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
if ('clone_ok' == $op) { |
437
|
|
|
// Ticket Check |
438
|
|
View Code Duplication |
if (!$xoopsGTicket->check(true, 'myblocksadmin')) { |
|
|
|
|
439
|
|
|
redirect_header(XOOPS_URL . '/', 3, $xoopsGTicket->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 = array(); |
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
|
|
View Code Duplication |
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', $block_type == 'C' ? '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
|
|
|
/* |
489
|
|
|
if ($cblock->getVar('template') != '') { |
490
|
|
|
$tplfileHandler = xoops_getHandler('tplfile'); |
491
|
|
|
$btemplate =& $tplfileHandler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid); |
492
|
|
|
if (count($btemplate) > 0) { |
493
|
|
|
$tplclone =& $btemplate[0]->clone(); |
494
|
|
|
$tplclone->setVar('tpl_id', 0); |
495
|
|
|
$tplclone->setVar('tpl_refid', $newid); |
496
|
|
|
$tplman->insert($tplclone); |
497
|
|
|
} |
498
|
|
|
} |
499
|
|
|
*/ |
500
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
501
|
|
|
$bmodule = (isset($_POST['bmodule']) && is_array($_POST['bmodule'])) ? $_POST['bmodule'] : array(-1); // GIJ + |
502
|
|
View Code Duplication |
foreach ($bmodule as $bmid) { |
|
|
|
|
503
|
|
|
$sql = 'INSERT INTO ' . $db->prefix('block_module_link') . " (block_id, module_id) VALUES ('{$newid}', '{$bmid}')"; |
504
|
|
|
$db->query($sql); |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
/* global $xoopsUser; |
508
|
|
|
$groups =& $xoopsUser->getGroups(); |
509
|
|
|
$count = count($groups); |
510
|
|
|
for ($i = 0; $i < $count; $i++) { |
511
|
|
|
$sql = "INSERT INTO ".$db->prefix('group_permission')." (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (".$groups[$i].", ".$newid.", 1, 'block_read')"; |
512
|
|
|
$db->query($sql); |
513
|
|
|
} |
514
|
|
|
*/ |
515
|
|
|
|
516
|
|
|
$sql = 'SELECT gperm_groupid FROM ' . $db->prefix('group_permission') . " WHERE gperm_name='block_read' AND gperm_modid='1' AND gperm_itemid='{$bid}'"; |
517
|
|
|
$result = $db->query($sql); |
518
|
|
|
while (list($gid) = $db->fetchRow($result)) { |
519
|
|
|
$sql = 'INSERT INTO ' . $db->prefix('group_permission') . " (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES ({$gid}, {$newid}, 1, 'block_read')"; |
520
|
|
|
$db->query($sql); |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
redirect_header('myblocksadmin.php', 1, _AM_DBUPDATED); |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
// import from modules/system/admin/blocksadmin/blocksadmin.php |
527
|
|
|
/** |
528
|
|
|
* @param $bid |
529
|
|
|
* @param $bside |
530
|
|
|
* @param $bweight |
531
|
|
|
* @param $bvisible |
532
|
|
|
* @param $btitle |
533
|
|
|
* @param $bcontent |
534
|
|
|
* @param $bctype |
535
|
|
|
* @param $bcachetime |
536
|
|
|
* @param $bmodule |
537
|
|
|
* @param array $options |
538
|
|
|
* @return string |
539
|
|
|
*/ |
540
|
|
|
function myblocksadmin_update_block( |
541
|
|
|
$bid, |
542
|
|
|
$bside, |
543
|
|
|
$bweight, |
544
|
|
|
$bvisible, |
545
|
|
|
$btitle, |
546
|
|
|
$bcontent, |
547
|
|
|
$bctype, |
548
|
|
|
$bcachetime, |
549
|
|
|
$bmodule, |
550
|
|
|
$options = array() |
551
|
|
|
) { |
552
|
|
|
global $xoopsConfig; |
553
|
|
|
/* |
554
|
|
|
if (empty($bmodule)) { |
555
|
|
|
xoops_cp_header(); |
556
|
|
|
xoops_error(sprintf(_AM_NOTSELNG, _AM_MYLINKS_VISIBLEIN)); |
557
|
|
|
xoops_cp_footer(); |
558
|
|
|
exit(); |
559
|
|
|
} |
560
|
|
|
*/ |
561
|
|
|
$myblock = new XoopsBlock($bid); |
562
|
|
|
//$myblock->setVar('side', $bside); GIJ - |
563
|
|
|
if ($bside >= 0) { |
564
|
|
|
$myblock->setVar('side', $bside); // GIJ + |
565
|
|
|
} |
566
|
|
|
$myblock->setVar('weight', $bweight); |
567
|
|
|
$myblock->setVar('visible', $bvisible); |
568
|
|
|
$myblock->setVar('title', $btitle); |
569
|
|
|
if (isset($bcontent)) { |
570
|
|
|
$myblock->setVar('content', $bcontent); |
571
|
|
|
} |
572
|
|
|
if (isset($bctype)) { |
573
|
|
|
$myblock->setVar('c_type', $bctype); |
574
|
|
|
} |
575
|
|
|
$myblock->setVar('bcachetime', $bcachetime); |
576
|
|
View Code Duplication |
if (isset($options) && (count($options) > 0)) { |
|
|
|
|
577
|
|
|
$options = implode('|', $options); |
578
|
|
|
$myblock->setVar('options', $options); |
579
|
|
|
} |
580
|
|
|
if ('C' == $myblock->getVar('block_type')) { |
581
|
|
|
switch ($myblock->getVar('c_type')) { |
582
|
|
|
case 'H': |
583
|
|
|
$name = _AM_CUSTOMHTML; |
584
|
|
|
break; |
585
|
|
|
case 'P': |
586
|
|
|
$name = _AM_CUSTOMPHP; |
587
|
|
|
break; |
588
|
|
|
case 'S': |
589
|
|
|
$name = _AM_CUSTOMSMILE; |
590
|
|
|
break; |
591
|
|
|
default: |
592
|
|
|
$name = _AM_CUSTOMNOSMILE; |
593
|
|
|
break; |
594
|
|
|
} |
595
|
|
|
$myblock->setVar('name', $name); |
596
|
|
|
} |
597
|
|
|
$msg = _AM_DBUPDATED; |
598
|
|
|
if (false != $myblock->store()) { |
599
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
600
|
|
|
$sql = sprintf('DELETE FROM %s WHERE block_id = %u', $db->prefix('block_module_link'), $bid); |
601
|
|
|
$db->query($sql); |
602
|
|
View Code Duplication |
foreach ($bmodule as $bmid) { |
|
|
|
|
603
|
|
|
$sql = sprintf('INSERT INTO %s (block_id, module_id) VALUES (%u, %d)', $db->prefix('block_module_link'), $bid, (int)$bmid); |
604
|
|
|
$db->query($sql); |
605
|
|
|
} |
606
|
|
|
include_once XOOPS_ROOT_PATH . '/class/template.php'; |
607
|
|
|
$xoopsTpl = new XoopsTpl(); |
608
|
|
|
//$xoopsTpl->xoops_setCaching(2); |
609
|
|
|
$xoopsTpl->caching = 2; |
610
|
|
|
if ('' != $myblock->getVar('template')) { |
611
|
|
|
if ($xoopsTpl->is_cached('db:' . $myblock->getVar('template'))) { |
612
|
|
|
if (!$xoopsTpl->clear_cache('db:' . $myblock->getVar('template'))) { |
613
|
|
|
$msg = "Unable to clear cache for block ID: {$bid}"; |
614
|
|
|
} |
615
|
|
|
} |
616
|
|
|
} else { |
617
|
|
|
if ($xoopsTpl->is_cached('db:system_dummy.tpl', 'block' . $bid)) { |
618
|
|
|
if (!$xoopsTpl->clear_cache('db:system_dummy.tpl', 'block' . $bid)) { |
619
|
|
|
$msg = 'Unable to clear cache for block ID' . $bid; |
620
|
|
|
} |
621
|
|
|
} |
622
|
|
|
} |
623
|
|
|
} else { |
624
|
|
|
$msg = "Failed update of block. ID: {$bid}"; |
625
|
|
|
} |
626
|
|
|
// redirect_header('admin.php?fct=blocksadmin&t='.time(),1,$msg); |
627
|
|
|
// exit(); GIJ - |
628
|
|
|
return $msg; // GIJ + |
629
|
|
|
} |
630
|
|
|
|
631
|
|
|
// update block instance for 2.2 |
632
|
|
|
/** |
633
|
|
|
* @param $id |
634
|
|
|
* @param $bside |
635
|
|
|
* @param $bweight |
636
|
|
|
* @param $bvisible |
637
|
|
|
* @param $btitle |
638
|
|
|
* @param $bcontent |
639
|
|
|
* @param $bctype |
640
|
|
|
* @param $bcachetime |
641
|
|
|
* @param $bmodule |
642
|
|
|
* @param array $options |
643
|
|
|
* @param null $bid |
644
|
|
|
* @return string |
645
|
|
|
*/ |
646
|
|
|
function myblocksadmin_update_blockinstance( |
647
|
|
|
$id, |
648
|
|
|
$bside, |
649
|
|
|
$bweight, |
650
|
|
|
$bvisible, |
651
|
|
|
$btitle, |
652
|
|
|
$bcontent, |
|
|
|
|
653
|
|
|
$bctype, |
|
|
|
|
654
|
|
|
$bcachetime, |
655
|
|
|
$bmodule, |
656
|
|
|
$options = array(), |
657
|
|
|
$bid = null |
658
|
|
|
) { |
659
|
|
|
global $xoopsDB; |
660
|
|
|
|
661
|
|
|
$instanceHandler = xoops_getHandler('blockinstance'); |
662
|
|
|
$blockHandler = xoops_getHandler('block'); |
663
|
|
|
if ($id > 0) { |
664
|
|
|
// update |
665
|
|
|
$instance = $instanceHandler->get($id); |
666
|
|
|
if ($bside >= 0) { |
667
|
|
|
$instance->setVar('side', $bside); |
668
|
|
|
} |
669
|
|
|
if (!empty($options)) { |
670
|
|
|
$instance->setVar('options', $options); |
671
|
|
|
} |
672
|
|
|
} else { |
673
|
|
|
// insert |
674
|
|
|
$instance = $instanceHandler->create(); |
675
|
|
|
$instance->setVar('bid', $bid); |
676
|
|
|
$instance->setVar('side', $bside); |
677
|
|
|
$block = $blockHandler->get($bid); |
678
|
|
|
$instance->setVar('options', $block->getVar('options')); |
679
|
|
|
if (empty($btitle)) { |
680
|
|
|
$btitle = $block->getVar('name'); |
681
|
|
|
} |
682
|
|
|
} |
683
|
|
|
$instance->setVar('weight', $bweight); |
684
|
|
|
$instance->setVar('visible', $bvisible); |
685
|
|
|
$instance->setVar('title', $btitle); |
686
|
|
|
//if (isset($bcontent)) $instance->setVar('content', $bcontent); |
687
|
|
|
//if (isset($bctype)) $instance->setVar('c_type', $bctype); |
688
|
|
|
$instance->setVar('bcachetime', $bcachetime); |
689
|
|
|
|
690
|
|
|
if ($instanceHandler->insert($instance)) { |
691
|
|
|
$GLOBALS['xoopsDB']->query('DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('block_module_link') . ' WHERE block_id=' . $instance->getVar('instanceid')); |
692
|
|
|
foreach ($bmodule as $mid) { |
693
|
|
|
$page = explode('-', $mid); |
694
|
|
|
$mid = $page[0]; |
695
|
|
|
$pageid = $page[1]; |
696
|
|
|
$GLOBALS['xoopsDB']->query('INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('block_module_link') . ' VALUES (' . $instance->getVar('instanceid') . ', ' . (int)$mid . ', ' . (int)$pageid . ')'); |
697
|
|
|
} |
698
|
|
|
|
699
|
|
|
return _MD_MYLINKS_AM_DBUPDATED; |
700
|
|
|
} |
701
|
|
|
|
702
|
|
|
return "Failed update of block instance. ID: {$id}"; |
703
|
|
|
|
704
|
|
|
/* // NAME for CUSTOM BLOCK |
705
|
|
|
if ( $instance->getVar('block_type') == 'C') { |
706
|
|
|
switch ( $instance->getVar('c_type') ) { |
707
|
|
|
case 'H': |
708
|
|
|
$name = _AM_CUSTOMHTML; |
709
|
|
|
break; |
710
|
|
|
case 'P': |
711
|
|
|
$name = _AM_CUSTOMPHP; |
712
|
|
|
break; |
713
|
|
|
case 'S': |
714
|
|
|
$name = _AM_CUSTOMSMILE; |
715
|
|
|
break; |
716
|
|
|
default: |
717
|
|
|
$name = _AM_CUSTOMNOSMILE; |
718
|
|
|
break; |
719
|
|
|
} |
720
|
|
|
$instance->setVar('name', $name); |
721
|
|
|
} |
722
|
|
|
*/ |
723
|
|
|
/* // CLEAR TEMPLATE CACHE |
724
|
|
|
include_once XOOPS_ROOT_PATH.'/class/template.php'; |
725
|
|
|
$xoopsTpl = new XoopsTpl(); |
726
|
|
|
//$xoopsTpl->xoops_setCaching(2); |
727
|
|
|
$xoopsTpl->caching=2; |
728
|
|
|
if ($instance->getVar('template') != '') { |
729
|
|
|
if ($xoopsTpl->is_cached('db:'.$instance->getVar('template'))) { |
730
|
|
|
if (!$xoopsTpl->clear_cache('db:'.$instance->getVar('template'))) { |
731
|
|
|
$msg = 'Unable to clear cache for block ID'.$bid; |
732
|
|
|
} |
733
|
|
|
} |
734
|
|
|
} else { |
735
|
|
|
if ($xoopsTpl->is_cached('db:system_dummy.tpl', 'block'.$bid)) { |
736
|
|
|
if (!$xoopsTpl->clear_cache('db:system_dummy.tpl', 'block'.$bid)) { |
737
|
|
|
$msg = 'Unable to clear cache for block ID'.$bid; |
738
|
|
|
} |
739
|
|
|
} |
740
|
|
|
} |
741
|
|
|
*/ |
742
|
|
|
} |
743
|
|
|
|
744
|
|
|
// TODO edit2, delete2, customblocks |
745
|
|
|
|
746
|
|
|
|
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.