1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Module: SmartFAQ |
5
|
|
|
* Author: The SmartFactory <www.smartfactory.ca> |
6
|
|
|
* Licence: GNU |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
// |
10
|
|
|
// ------------------------------------------------------------------------ // |
11
|
|
|
// XOOPS - PHP Content Management System // |
12
|
|
|
// Copyright (c) 2000-2016 XOOPS.org // |
13
|
|
|
// <http://xoops.org/> // |
14
|
|
|
// ------------------------------------------------------------------------ // |
15
|
|
|
// This program is free software; you can redistribute it and/or modify // |
16
|
|
|
// it under the terms of the GNU General Public License as published by // |
17
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
18
|
|
|
// (at your option) any later version. // |
19
|
|
|
// // |
20
|
|
|
// You may not change or alter any portion of this comment or credits // |
21
|
|
|
// of supporting developers from this source code or any supporting // |
22
|
|
|
// source code which is considered copyrighted (c) material of the // |
23
|
|
|
// original comment or credit authors. // |
24
|
|
|
// // |
25
|
|
|
// This program is distributed in the hope that it will be useful, // |
26
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
27
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
28
|
|
|
// GNU General Public License for more details. // |
29
|
|
|
// // |
30
|
|
|
// You should have received a copy of the GNU General Public License // |
31
|
|
|
// along with this program; if not, write to the Free Software // |
32
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
33
|
|
|
// ------------------------------------------------------------------------ // |
34
|
|
|
// Author: Kazumi Ono (AKA onokazu) // |
35
|
|
|
// URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ // |
36
|
|
|
// Project: The XOOPS Project // |
37
|
|
|
// ------------------------------------------------------------------------- // |
38
|
|
|
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
39
|
|
|
|
40
|
|
|
if (!is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid())) { |
41
|
|
|
exit('Access Denied'); |
42
|
|
|
} |
43
|
|
|
include_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; |
44
|
|
|
include XOOPS_ROOT_PATH . '/modules/system/admin/blocksadmin/blocksadmin.php'; |
45
|
|
|
|
46
|
|
|
$op = 'list'; |
47
|
|
|
if (isset($HTTP_POST_VARS)) { |
48
|
|
|
foreach ($HTTP_POST_VARS as $k => $v) { |
49
|
|
|
$$k = $v; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if (isset($HTTP_GET_VARS['op'])) { |
54
|
|
|
if ($HTTP_GET_VARS['op'] === 'edit' || $HTTP_GET_VARS['op'] === 'delete' || $HTTP_GET_VARS['op'] === 'delete_ok' || $HTTP_GET_VARS['op'] === 'clone' || $HTTP_GET_VARS['op'] === 'previewpopup') { |
55
|
|
|
$op = $HTTP_GET_VARS['op']; |
56
|
|
|
$bid = isset($HTTP_GET_VARS['bid']) ? (int)$HTTP_GET_VARS['bid'] : 0; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
if (isset($previewblock)) { |
61
|
|
|
xoops_cp_header(); |
62
|
|
|
include_once XOOPS_ROOT_PATH . '/class/template.php'; |
63
|
|
|
$xoopsTpl = new XoopsTpl(); |
64
|
|
|
$xoopsTpl->xoops_setCaching(0); |
65
|
|
|
if (isset($bid)) { |
66
|
|
|
$block['bid'] = $bid; |
67
|
|
|
$block['form_title'] = _AM_EDITBLOCK; |
68
|
|
|
$myblock = new XoopsBlock($bid); |
69
|
|
|
$block['name'] = $myblock->getVar('name'); |
70
|
|
|
} else { |
71
|
|
|
if ($op === 'save') { |
72
|
|
|
$block['form_title'] = _AM_ADDBLOCK; |
73
|
|
|
} else { |
74
|
|
|
$block['form_title'] = _AM_CLONEBLOCK; |
75
|
|
|
} |
76
|
|
|
$myblock = new XoopsBlock(); |
77
|
|
|
$myblock->setVar('block_type', 'C'); |
78
|
|
|
} |
79
|
|
|
$myts = MyTextSanitizer::getInstance(); |
80
|
|
|
$myblock->setVar('title', $myts->stripSlashesGPC($btitle)); |
81
|
|
|
$myblock->setVar('content', $myts->stripSlashesGPC($bcontent)); |
82
|
|
|
$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>'; |
83
|
|
|
|
84
|
|
|
$dummyfile = '_dummyfile_' . time() . '.html'; |
85
|
|
|
$fp = fopen(XOOPS_CACHE_PATH . '/' . $dummyfile, 'w'); |
86
|
|
|
fwrite($fp, $dummyhtml); |
87
|
|
|
fclose($fp); |
88
|
|
|
$block['edit_form'] = false; |
89
|
|
|
$block['template'] = ''; |
90
|
|
|
$block['op'] = $op; |
91
|
|
|
$block['side'] = $bside; |
92
|
|
|
$block['weight'] = $bweight; |
93
|
|
|
$block['visible'] = $bvisible; |
94
|
|
|
$block['title'] = $myblock->getVar('title', 'E'); |
95
|
|
|
$block['content'] = $myblock->getVar('content', 'E'); |
96
|
|
|
$block['modules'] =& $bmodule; |
97
|
|
|
$block['ctype'] = isset($bctype) ? $bctype : $myblock->getVar('c_type'); |
98
|
|
|
$block['is_custom'] = true; |
99
|
|
|
$block['cachetime'] = (int)$bcachetime; |
100
|
|
|
echo '<a href="admin.php?fct=blocksadmin">' . _AM_BADMIN . '</a> <span style="font-weight:bold;">»»</span> ' . $block['form_title'] . '<br /><br />'; |
101
|
|
|
include XOOPS_ROOT_PATH . '/modules/system/admin/blocksadmin/blockform.php'; |
102
|
|
|
$form->display(); |
103
|
|
|
xoops_cp_footer(); |
104
|
|
|
echo '<script type="text/javascript"> |
105
|
|
|
<!--// |
106
|
|
|
preview_window = openWithSelfMain("' . XOOPS_URL . '/modules/system/admin.php?fct=blocksadmin&op=previewpopup&file=' . $dummyfile . '", "popup", 250, 200); |
107
|
|
|
//--> |
108
|
|
|
</script>'; |
109
|
|
|
exit(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
if ($op === 'previewpopup') { |
113
|
|
|
$file = str_replace('..', '', XOOPS_CACHE_PATH . '/' . trim($HTTP_GET_VARS['file'])); |
114
|
|
|
if (file_exists($file)) { |
115
|
|
|
include $file; |
116
|
|
|
@unlink($file); |
|
|
|
|
117
|
|
|
} |
118
|
|
|
exit(); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
if ($op === 'list') { |
122
|
|
|
xoops_cp_header(); |
123
|
|
|
list_blocks(); |
124
|
|
|
xoops_cp_footer(); |
125
|
|
|
exit(); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
if ($op === 'order') { |
129
|
|
|
foreach (array_keys($bid) as $i) { |
130
|
|
|
if ($side[$i] < 0) { |
131
|
|
|
$visible[$i] = 0; |
132
|
|
|
$side[$i] = -1; |
133
|
|
|
} else { |
134
|
|
|
$visible[$i] = 1; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
$bmodule[$i] = (isset($bmodule[$i]) && is_array($bmodule[$i])) ? $bmodule[$i] : array(-1); |
138
|
|
|
|
139
|
|
|
myblocksadmin_update_block($i, $side[$i], $weight[$i], $visible[$i], $title[$i], '', '', $bcachetime[$i], $bmodule[$i], array()); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
redirect_header('myblocksadmin.php', 1, _AM_DBUPDATED); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
if ($op === 'save') { |
146
|
|
|
save_block($bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bmodule, $bcachetime); |
147
|
|
|
exit(); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
if ($op === 'update') { |
151
|
|
|
$bcachetime = isset($bcachetime) ? (int)$bcachetime : 0; |
152
|
|
|
$options = isset($options) ? $options : array(); |
153
|
|
|
$bcontent = isset($bcontent) ? $bcontent : ''; |
154
|
|
|
$bctype = isset($bctype) ? $bctype : ''; |
155
|
|
|
$bmodule = (isset($bmodule) && is_array($bmodule)) ? $bmodule : array(-1); // GIJ + |
156
|
|
|
$msg = myblocksadmin_update_block($bid, $bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bcachetime, $bmodule, $options); // GIJ c |
157
|
|
|
redirect_header('myblocksadmin.php', 1, $msg); // GIJ + |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
if ($op === 'delete_ok') { |
161
|
|
|
delete_block_ok($bid); |
162
|
|
|
exit(); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
if ($op === 'delete') { |
166
|
|
|
xoops_cp_header(); |
167
|
|
|
delete_block($bid); |
168
|
|
|
xoops_cp_footer(); |
169
|
|
|
exit(); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
if ($op === 'edit') { |
173
|
|
|
xoops_cp_header(); |
174
|
|
|
edit_block($bid); |
175
|
|
|
xoops_cp_footer(); |
176
|
|
|
exit(); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
// import from modules/system/admin/blocksadmin/blocksadmin.php |
180
|
|
|
/** |
181
|
|
|
* @param $bid |
182
|
|
|
* @param $bside |
183
|
|
|
* @param $bweight |
184
|
|
|
* @param $bvisible |
185
|
|
|
* @param $btitle |
186
|
|
|
* @param $bcontent |
187
|
|
|
* @param $bctype |
188
|
|
|
* @param $bcachetime |
189
|
|
|
* @param $bmodule |
190
|
|
|
* @param array $options |
191
|
|
|
* @return string |
192
|
|
|
*/ |
193
|
|
|
function myblocksadmin_update_block($bid, $bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bcachetime, $bmodule, $options = array()) |
194
|
|
|
{ |
195
|
|
|
global $xoopsConfig; |
|
|
|
|
196
|
|
|
if (empty($bmodule)) { |
197
|
|
|
xoops_cp_header(); |
198
|
|
|
xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN)); |
199
|
|
|
xoops_cp_footer(); |
200
|
|
|
exit(); |
|
|
|
|
201
|
|
|
} |
202
|
|
|
$myblock = new XoopsBlock($bid); |
203
|
|
|
// $myblock->setVar('side', $bside); GIJ - |
|
|
|
|
204
|
|
|
if ($bside >= 0) { |
205
|
|
|
$myblock->setVar('side', $bside); |
206
|
|
|
} // GIJ + |
207
|
|
|
$myblock->setVar('weight', $bweight); |
208
|
|
|
$myblock->setVar('visible', $bvisible); |
209
|
|
|
$myblock->setVar('title', $btitle); |
210
|
|
|
$myblock->setVar('content', $bcontent); |
211
|
|
|
$myblock->setVar('bcachetime', $bcachetime); |
212
|
|
|
if (isset($options) && (count($options) > 0)) { |
213
|
|
|
$options = implode('|', $options); |
214
|
|
|
$myblock->setVar('options', $options); |
215
|
|
|
} |
216
|
|
|
if ($myblock->getVar('block_type') === 'C') { |
217
|
|
|
switch ($bctype) { |
218
|
|
|
case 'H': |
219
|
|
|
$name = _AM_CUSTOMHTML; |
220
|
|
|
break; |
221
|
|
|
case 'P': |
222
|
|
|
$name = _AM_CUSTOMPHP; |
223
|
|
|
break; |
224
|
|
|
case 'S': |
225
|
|
|
$name = _AM_CUSTOMSMILE; |
226
|
|
|
break; |
227
|
|
|
default: |
228
|
|
|
$name = _AM_CUSTOMNOSMILE; |
229
|
|
|
break; |
230
|
|
|
} |
231
|
|
|
$myblock->setVar('name', $name); |
232
|
|
|
$myblock->setVar('c_type', $bctype); |
233
|
|
|
} else { |
234
|
|
|
$myblock->setVar('c_type', 'H'); |
235
|
|
|
} |
236
|
|
|
$msg = _AM_DBUPDATED; |
237
|
|
|
if ($myblock->store() != false) { |
238
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
239
|
|
|
$sql = sprintf('DELETE FROM %s WHERE block_id = %u', $db->prefix('block_module_link'), $bid); |
240
|
|
|
$db->query($sql); |
241
|
|
|
foreach ($bmodule as $bmid) { |
242
|
|
|
$sql = sprintf('INSERT INTO %s (block_id, module_id) VALUES (%u, %d)', $db->prefix('block_module_link'), $bid, (int)$bmid); |
243
|
|
|
$db->query($sql); |
244
|
|
|
} |
245
|
|
|
include_once XOOPS_ROOT_PATH . '/class/template.php'; |
246
|
|
|
$xoopsTpl = new XoopsTpl(); |
247
|
|
|
$xoopsTpl->xoops_setCaching(2); |
248
|
|
|
if ($myblock->getVar('template') != '') { |
249
|
|
|
if ($xoopsTpl->is_cached('db:' . $myblock->getVar('template'))) { |
250
|
|
|
if (!$xoopsTpl->clear_cache('db:' . $myblock->getVar('template'))) { |
251
|
|
|
$msg = 'Unable to clear cache for block ID' . $bid; |
252
|
|
|
} |
253
|
|
|
} |
254
|
|
|
} else { |
255
|
|
|
if ($xoopsTpl->is_cached('db:system_dummy.html', 'block' . $bid)) { |
256
|
|
|
if (!$xoopsTpl->clear_cache('db:system_dummy.html', 'block' . $bid)) { |
257
|
|
|
$msg = 'Unable to clear cache for block ID' . $bid; |
258
|
|
|
} |
259
|
|
|
} |
260
|
|
|
} |
261
|
|
|
} else { |
262
|
|
|
$msg = 'Failed update of block. ID:' . $bid; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
return $msg; // GIJ + |
266
|
|
|
} |
267
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.