|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Block Class Manager |
|
4
|
|
|
* |
|
5
|
|
|
* You may not change or alter any portion of this comment or credits |
|
6
|
|
|
* of supporting developers from this source code or any supporting source code |
|
7
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
|
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
|
|
|
* @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
|
13
|
|
|
* @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html) |
|
14
|
|
|
* @package system |
|
15
|
|
|
*/ |
|
16
|
|
|
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
|
17
|
|
|
|
|
18
|
|
|
require_once XOOPS_ROOT_PATH . '/kernel/block.php'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* System Block |
|
22
|
|
|
* |
|
23
|
|
|
* @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
|
24
|
|
|
* @package system |
|
25
|
|
|
*/ |
|
26
|
|
|
class SystemBlock extends XoopsBlock |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct() |
|
32
|
|
|
{ |
|
33
|
|
|
parent::__construct(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param string $mode |
|
38
|
|
|
* |
|
39
|
|
|
* @return XoopsThemeForm |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getForm($mode = 'edit') |
|
42
|
|
|
{ |
|
43
|
|
|
if ($this->isNew()) { |
|
44
|
|
|
$title = _AM_SYSTEM_BLOCKS_ADDBLOCK; |
|
45
|
|
|
$modules = array(-1); |
|
46
|
|
|
$groups = array(XOOPS_GROUP_USERS, XOOPS_GROUP_ANONYMOUS, XOOPS_GROUP_ADMIN); |
|
47
|
|
|
$this->setVar('block_type', 'C'); |
|
48
|
|
|
$this->setVar('visible', 1); |
|
49
|
|
|
$op = 'save'; |
|
50
|
|
|
} else { |
|
51
|
|
|
// Search modules |
|
52
|
|
|
/* @var SystemBlockLinkModuleHandler $blocklinkmodule_handler */ |
|
53
|
|
|
$blocklinkmodule_handler = xoops_getModuleHandler('blocklinkmodule'); |
|
54
|
|
|
$criteria = new CriteriaCompo(new Criteria('block_id', $this->getVar('bid'))); |
|
|
|
|
|
|
55
|
|
|
$blocklinkmodule = $blocklinkmodule_handler->getObjects($criteria); |
|
56
|
|
|
foreach ($blocklinkmodule as $link) { |
|
57
|
|
|
/* @var SystemBlockLinkModule $link */ |
|
58
|
|
|
$modules[] = $link->getVar('module_id'); |
|
59
|
|
|
} |
|
60
|
|
|
// Search perms |
|
61
|
|
|
/* @var XoopsGroupPermHandler $groupperm_handler */ |
|
62
|
|
|
$groupperm_handler = xoops_getHandler('groupperm'); |
|
63
|
|
|
$groups = $groupperm_handler->getGroupIds('block_read', $this->getVar('bid')); |
|
64
|
|
|
switch ($mode) { |
|
65
|
|
|
case 'edit': |
|
66
|
|
|
$title = _AM_SYSTEM_BLOCKS_EDITBLOCK; |
|
67
|
|
|
break; |
|
68
|
|
|
case 'clone': |
|
69
|
|
|
$title = _AM_SYSTEM_BLOCKS_CLONEBLOCK; |
|
70
|
|
|
$this->setVar('bid', 0); |
|
71
|
|
|
if ($this->isCustom()) { |
|
72
|
|
|
$this->setVar('block_type', 'C'); |
|
73
|
|
|
} else { |
|
74
|
|
|
$this->setVar('block_type', 'D'); |
|
75
|
|
|
} |
|
76
|
|
|
break; |
|
77
|
|
|
} |
|
78
|
|
|
$op = 'save'; |
|
79
|
|
|
} |
|
80
|
|
|
$form = new XoopsThemeForm($title, 'blockform', 'admin.php', 'post', true); |
|
|
|
|
|
|
81
|
|
|
if (!$this->isNew()) { |
|
82
|
|
|
$form->addElement(new XoopsFormLabel(_AM_SYSTEM_BLOCKS_NAME, $this->getVar('name') . ' [' . $this->getVar('dirname') . ']')); |
|
83
|
|
|
} |
|
84
|
|
|
// Side position |
|
85
|
|
|
$side_select = new XoopsFormSelect(_AM_SYSTEM_BLOCKS_TYPE, 'side', $this->getVar('side')); |
|
86
|
|
|
$side_select->addOptionArray(array( |
|
87
|
|
|
0 => _AM_SYSTEM_BLOCKS_SBLEFT, |
|
88
|
|
|
1 => _AM_SYSTEM_BLOCKS_SBRIGHT, |
|
89
|
|
|
3 => _AM_SYSTEM_BLOCKS_CBLEFT, |
|
90
|
|
|
4 => _AM_SYSTEM_BLOCKS_CBRIGHT, |
|
91
|
|
|
5 => _AM_SYSTEM_BLOCKS_CBCENTER, |
|
92
|
|
|
7 => _AM_SYSTEM_BLOCKS_CBBOTTOMLEFT, |
|
93
|
|
|
8 => _AM_SYSTEM_BLOCKS_CBBOTTOMRIGHT, |
|
94
|
|
|
9 => _AM_SYSTEM_BLOCKS_CBBOTTOM, |
|
95
|
|
|
10 => _AM_SYSTEM_BLOCKS_CBFOOTERLEFT, |
|
96
|
|
|
11 => _AM_SYSTEM_BLOCKS_CBFOOTERRIGHT, |
|
97
|
|
|
12 => _AM_SYSTEM_BLOCKS_CBFOOTERCENTER)); |
|
98
|
|
|
|
|
99
|
|
|
$form->addElement($side_select); |
|
100
|
|
|
// Order |
|
101
|
|
|
$form->addElement(new XoopsFormText(_AM_SYSTEM_BLOCKS_WEIGHT, 'weight', 2, 5, $this->getVar('weight'))); |
|
|
|
|
|
|
102
|
|
|
// Display |
|
103
|
|
|
$form->addElement(new XoopsFormRadioYN(_AM_SYSTEM_BLOCKS_VISIBLE, 'visible', $this->getVar('visible'))); |
|
|
|
|
|
|
104
|
|
|
// Visible In |
|
105
|
|
|
$mod_select = new XoopsFormSelect(_AM_SYSTEM_BLOCKS_VISIBLEIN, 'modules', $modules, 5, true); |
|
|
|
|
|
|
106
|
|
|
/* @var XoopsModuleHandler $module_handler */ |
|
107
|
|
|
$module_handler = xoops_getHandler('module'); |
|
108
|
|
|
$criteria = new CriteriaCompo(new Criteria('hasmain', 1)); |
|
109
|
|
|
$criteria->add(new Criteria('isactive', 1)); |
|
110
|
|
|
$module_list = $module_handler->getList($criteria); |
|
111
|
|
|
$module_list[-1] = _AM_SYSTEM_BLOCKS_TOPPAGE; |
|
112
|
|
|
$module_list[0] = _AM_SYSTEM_BLOCKS_ALLPAGES; |
|
113
|
|
|
ksort($module_list); |
|
114
|
|
|
$mod_select->addOptionArray($module_list); |
|
115
|
|
|
$form->addElement($mod_select); |
|
116
|
|
|
// Title |
|
117
|
|
|
$form->addElement(new XoopsFormText(_AM_SYSTEM_BLOCKS_TITLE, 'title', 50, 255, $this->getVar('title')), false); |
|
118
|
|
|
if ($this->isNew() || $this->isCustom()) { |
|
119
|
|
|
$editor_configs = array(); |
|
120
|
|
|
$editor_configs['name'] = 'content_block'; |
|
121
|
|
|
$editor_configs['value'] = $this->getVar('content', 'e'); |
|
122
|
|
|
$editor_configs['rows'] = 20; |
|
123
|
|
|
$editor_configs['cols'] = 100; |
|
124
|
|
|
$editor_configs['width'] = '100%'; |
|
125
|
|
|
$editor_configs['height'] = '400px'; |
|
126
|
|
|
$editor_configs['editor'] = xoops_getModuleOption('blocks_editor', 'system'); |
|
|
|
|
|
|
127
|
|
|
$form->addElement(new XoopsFormEditor(_AM_SYSTEM_BLOCKS_CONTENT, 'content_block', $editor_configs), true); |
|
128
|
|
|
if (in_array($editor_configs['editor'], array('dhtmltextarea', 'textarea'))) { |
|
129
|
|
|
$ctype_select = new XoopsFormSelect(_AM_SYSTEM_BLOCKS_CTYPE, 'c_type', $this->getVar('c_type')); |
|
130
|
|
|
$ctype_select->addOptionArray(array( |
|
131
|
|
|
'H' => _AM_SYSTEM_BLOCKS_HTML, |
|
132
|
|
|
'P' => _AM_SYSTEM_BLOCKS_PHP, |
|
133
|
|
|
'S' => _AM_SYSTEM_BLOCKS_AFWSMILE, |
|
134
|
|
|
'T' => _AM_SYSTEM_BLOCKS_AFNOSMILE)); |
|
135
|
|
|
$form->addElement($ctype_select); |
|
136
|
|
|
} else { |
|
137
|
|
|
$form->addElement(new XoopsFormHidden('c_type', 'H')); |
|
138
|
|
|
} |
|
139
|
|
|
} else { |
|
140
|
|
|
if ($this->getVar('template') !== '') { |
|
141
|
|
|
$tplfile_handler = xoops_getHandler('tplfile'); |
|
142
|
|
|
$btemplate = $tplfile_handler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $this->getVar('bid')); |
|
|
|
|
|
|
143
|
|
|
if (count($btemplate) > 0) { |
|
144
|
|
|
$form->addElement(new XoopsFormLabel(_AM_SYSTEM_BLOCKS_CONTENT, '<a href="' . XOOPS_URL . '/modules/system/admin.php?fct=tplsets&op=edittpl&id=' . $btemplate[0]->getVar('tpl_id') . '">' . _AM_SYSTEM_BLOCKS_EDITTPL . '</a>')); |
|
145
|
|
|
} else { |
|
146
|
|
|
$btemplate2 = $tplfile_handler->find('default', 'block', $this->getVar('bid')); |
|
147
|
|
|
if (count($btemplate2) > 0) { |
|
148
|
|
|
$form->addElement(new XoopsFormLabel(_AM_SYSTEM_BLOCKS_CONTENT, '<a href="' . XOOPS_URL . '/modules/system/admin.php?fct=tplsets&op=edittpl&id=' . $btemplate2[0]->getVar('tpl_id') . '" rel="external">' . _AM_SYSTEM_BLOCKS_EDITTPL . '</a>')); |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
if ($this->getOptions() !== false) { |
|
153
|
|
|
$form->addElement(new XoopsFormLabel(_AM_SYSTEM_BLOCKS_OPTIONS, $this->getOptions())); |
|
|
|
|
|
|
154
|
|
|
} else { |
|
155
|
|
|
$form->addElement(new XoopsFormHidden('options', $this->getVar('options'))); |
|
|
|
|
|
|
156
|
|
|
} |
|
157
|
|
|
$form->addElement(new XoopsFormHidden('c_type', 'H')); |
|
158
|
|
|
} |
|
159
|
|
|
$cache_select = new XoopsFormSelect(_AM_SYSTEM_BLOCKS_BCACHETIME, 'bcachetime', $this->getVar('bcachetime')); |
|
160
|
|
|
$cache_select->addOptionArray(array( |
|
161
|
|
|
'0' => _NOCACHE, |
|
162
|
|
|
'30' => sprintf(_SECONDS, 30), |
|
163
|
|
|
'60' => _MINUTE, |
|
164
|
|
|
'300' => sprintf(_MINUTES, 5), |
|
165
|
|
|
'1800' => sprintf(_MINUTES, 30), |
|
166
|
|
|
'3600' => _HOUR, |
|
167
|
|
|
'18000' => sprintf(_HOURS, 5), |
|
168
|
|
|
'86400' => _DAY, |
|
169
|
|
|
'259200' => sprintf(_DAYS, 3), |
|
170
|
|
|
'604800' => _WEEK, |
|
171
|
|
|
'2592000' => _MONTH)); |
|
172
|
|
|
$form->addElement($cache_select); |
|
173
|
|
|
// Groups |
|
174
|
|
|
$form->addElement(new XoopsFormSelectGroup(_AM_SYSTEM_BLOCKS_GROUP, 'groups', true, $groups, 5, true)); |
|
175
|
|
|
|
|
176
|
|
|
$form->addElement(new XoopsFormHidden('block_type', $this->getVar('block_type'))); |
|
177
|
|
|
$form->addElement(new XoopsFormHidden('mid', $this->getVar('mid'))); |
|
178
|
|
|
$form->addElement(new XoopsFormHidden('func_num', $this->getVar('func_num'))); |
|
179
|
|
|
$form->addElement(new XoopsFormHidden('func_file', $this->getVar('func_file'))); |
|
180
|
|
|
$form->addElement(new XoopsFormHidden('show_func', $this->getVar('show_func'))); |
|
181
|
|
|
$form->addElement(new XoopsFormHidden('edit_func', $this->getVar('edit_func'))); |
|
182
|
|
|
$form->addElement(new XoopsFormHidden('template', $this->getVar('template'))); |
|
183
|
|
|
$form->addElement(new XoopsFormHidden('dirname', $this->getVar('dirname'))); |
|
184
|
|
|
$form->addElement(new XoopsFormHidden('name', $this->getVar('name'))); |
|
185
|
|
|
$form->addElement(new XoopsFormHidden('bid', $this->getVar('bid'))); |
|
186
|
|
|
$form->addElement(new XoopsFormHidden('op', $op)); |
|
187
|
|
|
$form->addElement(new XoopsFormHidden('fct', 'blocksadmin')); |
|
188
|
|
|
$button_tray = new XoopsFormElementTray('', ' '); |
|
189
|
|
|
if ($this->isNew() || $this->isCustom()) { |
|
190
|
|
|
$preview = new XoopsFormButton('', 'previewblock', _PREVIEW, 'preview'); |
|
191
|
|
|
$preview->setExtra("onclick=\"blocks_preview();\""); |
|
192
|
|
|
$button_tray->addElement($preview); |
|
193
|
|
|
} |
|
194
|
|
|
$button_tray->addElement(new XoopsFormButton('', 'submitblock', _SUBMIT, 'submit')); |
|
195
|
|
|
$form->addElement($button_tray); |
|
196
|
|
|
|
|
197
|
|
|
return $form; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* XoopsBlock::getOptions() |
|
202
|
|
|
* |
|
203
|
|
|
* @return bool|string |
|
204
|
|
|
*/ |
|
205
|
|
|
public function getOptions() |
|
206
|
|
|
{ |
|
207
|
|
|
global $xoopsConfig; |
|
208
|
|
|
if (!$this->isCustom()) { |
|
209
|
|
|
$edit_func = $this->getVar('edit_func'); |
|
210
|
|
|
if (!$edit_func) { |
|
211
|
|
|
return false; |
|
212
|
|
|
} |
|
213
|
|
|
if (file_exists($GLOBALS['xoops']->path('modules/' . $this->getVar('dirname') . '/blocks/' . $this->getVar('func_file')))) { |
|
214
|
|
|
if (file_exists($file = $GLOBALS['xoops']->path('modules/' . $this->getVar('dirname') . '/language/' . $xoopsConfig['language'] . '/blocks.php'))) { |
|
215
|
|
|
include_once $file; |
|
216
|
|
|
} elseif (file_exists($file = $GLOBALS['xoops']->path('modules/' . $this->getVar('dirname') . '/language/english/blocks.php'))) { |
|
217
|
|
|
include_once $file; |
|
218
|
|
|
} |
|
219
|
|
|
include_once $GLOBALS['xoops']->path('modules/' . $this->getVar('dirname') . '/blocks/' . $this->getVar('func_file')); |
|
220
|
|
|
$options = explode('|', $this->getVar('options')); |
|
221
|
|
|
$edit_form = $edit_func($options); |
|
222
|
|
|
if (!$edit_form) { |
|
223
|
|
|
return false; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
return $edit_form; |
|
227
|
|
|
} else { |
|
228
|
|
|
return false; |
|
229
|
|
|
} |
|
230
|
|
|
} else { |
|
231
|
|
|
return false; |
|
232
|
|
|
} |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* @return bool |
|
237
|
|
|
*/ |
|
238
|
|
|
public function isCustom() |
|
239
|
|
|
{ |
|
240
|
|
|
return $this->getVar('block_type') === 'C'; |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
/** |
|
244
|
|
|
* do stripslashes/htmlspecialchars according to the needed output |
|
245
|
|
|
* |
|
246
|
|
|
* @param string $format output use: S for Show and E for Edit |
|
247
|
|
|
* @param string $c_type type of block content |
|
248
|
|
|
* |
|
249
|
|
|
* @returns string |
|
250
|
|
|
*/ |
|
251
|
|
|
public function getContent($format = 's', $c_type = 'T') |
|
252
|
|
|
{ |
|
253
|
|
|
$format = strtolower($format); |
|
254
|
|
|
$c_type = strtoupper($c_type); |
|
255
|
|
|
switch ($format) { |
|
256
|
|
|
case 's': |
|
257
|
|
|
// check the type of content |
|
258
|
|
|
// H : custom HTML block |
|
259
|
|
|
// P : custom PHP block |
|
260
|
|
|
// S : use text sanitizater (smilies enabled) |
|
261
|
|
|
// T : use text sanitizater (smilies disabled) |
|
262
|
|
|
if ($c_type === 'H') { |
|
263
|
|
|
return str_replace('{X_SITEURL}', XOOPS_URL . '/', $this->getVar('content', 'n')); |
|
264
|
|
|
} elseif ($c_type === 'P') { |
|
265
|
|
|
ob_start(); |
|
266
|
|
|
echo eval($this->getVar('content', 'n')); |
|
|
|
|
|
|
267
|
|
|
$content = ob_get_contents(); |
|
268
|
|
|
ob_end_clean(); |
|
269
|
|
|
|
|
270
|
|
|
return str_replace('{X_SITEURL}', XOOPS_URL . '/', $content); |
|
271
|
|
|
} elseif ($c_type === 'S') { |
|
272
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
|
273
|
|
|
$content = str_replace('{X_SITEURL}', XOOPS_URL . '/', $this->getVar('content', 'n')); |
|
274
|
|
|
|
|
275
|
|
|
return $myts->displayTarea($content, 1, 1); |
|
276
|
|
|
} else { |
|
277
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
|
278
|
|
|
$content = str_replace('{X_SITEURL}', XOOPS_URL . '/', $this->getVar('content', 'n')); |
|
279
|
|
|
|
|
280
|
|
|
return $myts->displayTarea($content, 1, 0); |
|
281
|
|
|
} |
|
282
|
|
|
break; |
|
283
|
|
|
case 'e': |
|
284
|
|
|
return $this->getVar('content', 'e'); |
|
285
|
|
|
break; |
|
|
|
|
|
|
286
|
|
|
default: |
|
287
|
|
|
return $this->getVar('content', 'n'); |
|
288
|
|
|
break; |
|
289
|
|
|
} |
|
290
|
|
|
} |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
/** |
|
294
|
|
|
* System block handler class. |
|
295
|
|
|
* |
|
296
|
|
|
* This class is responsible for providing data access mechanisms to the data source |
|
297
|
|
|
* of XOOPS block class objects. |
|
298
|
|
|
* |
|
299
|
|
|
* @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
|
300
|
|
|
* @package system |
|
301
|
|
|
* @subpackage blocks |
|
302
|
|
|
*/ |
|
303
|
|
|
class SystemBlockHandler extends XoopsPersistableObjectHandler |
|
304
|
|
|
{ |
|
305
|
|
|
/** |
|
306
|
|
|
* @param null|XoopsDatabase $db |
|
307
|
|
|
*/ |
|
308
|
|
|
public function __construct(XoopsDatabase $db) |
|
309
|
|
|
{ |
|
310
|
|
|
parent::__construct($db, 'newblocks', 'SystemBlock', 'bid', 'title'); |
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
/** |
|
314
|
|
|
* @param XoopsObject|SystemBlock $obj |
|
315
|
|
|
* |
|
316
|
|
|
* @return int|bool object id on success, otherwise false |
|
317
|
|
|
*/ |
|
318
|
|
|
public function insert(XoopsObject $obj, $force = true) |
|
319
|
|
|
{ |
|
320
|
|
|
if (!($obj instanceof $this->className)) { |
|
321
|
|
|
return false; |
|
322
|
|
|
} |
|
323
|
|
|
$obj->setVar('last_modified', time()); |
|
324
|
|
|
|
|
325
|
|
|
return parent::insert($obj, $force); |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
/** |
|
329
|
|
|
* retrieve array of {@link XoopsBlock}s meeting certain conditions |
|
330
|
|
|
* |
|
331
|
|
|
* @param CriteriaElement|CriteriaCompo $criteria {@link CriteriaElement} with conditions for the blocks |
|
332
|
|
|
* @param bool $id_as_key should the blocks' bid be the key for the returned array? |
|
333
|
|
|
* @param bool $as_object return an array of objects |
|
334
|
|
|
* |
|
335
|
|
|
* @return array {@link XoopsBlock}s matching the conditions |
|
336
|
|
|
**/ |
|
337
|
|
|
public function &getObjects(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true) |
|
338
|
|
|
{ |
|
339
|
|
|
$ret = array(); |
|
340
|
|
|
$limit = $start = 0; |
|
341
|
|
|
$sql = 'SELECT DISTINCT(b.bid), b.* FROM ' . $this->db->prefix('newblocks') . ' b LEFT JOIN ' . $this->db->prefix('block_module_link') . ' l ON b.bid=l.block_id'; |
|
342
|
|
|
if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
343
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
|
|
|
|
|
|
344
|
|
|
$limit = $criteria->getLimit(); |
|
345
|
|
|
$start = $criteria->getStart(); |
|
346
|
|
|
} |
|
347
|
|
|
$result = $this->db->query($sql, $limit, $start); |
|
|
|
|
|
|
348
|
|
|
if (!$this->db->isResultSet($result)) { |
|
349
|
|
|
// \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); |
|
350
|
|
|
return $ret; |
|
351
|
|
|
} |
|
352
|
|
|
|
|
353
|
|
|
if ($as_object) { |
|
354
|
|
|
while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
|
|
|
|
|
355
|
|
|
$object = $this->create(false); |
|
356
|
|
|
$object->assignVars($myrow); |
|
357
|
|
|
if ($id_as_key) { |
|
358
|
|
|
$ret[$myrow[$this->keyName]] = $object; |
|
359
|
|
|
} else { |
|
360
|
|
|
$ret[] = $object; |
|
361
|
|
|
} |
|
362
|
|
|
unset($object); |
|
363
|
|
|
} |
|
364
|
|
|
} else { |
|
365
|
|
|
$object = $this->create(false); |
|
366
|
|
|
while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
367
|
|
|
$object->assignVars($myrow); |
|
368
|
|
|
if ($id_as_key) { |
|
369
|
|
|
$ret[$myrow[$this->keyName]] = $object->getValues(array_keys($myrow)); |
|
370
|
|
|
} else { |
|
371
|
|
|
$ret[] = $object->getValues(array_keys($myrow)); |
|
372
|
|
|
} |
|
373
|
|
|
} |
|
374
|
|
|
unset($object); |
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
return $ret; |
|
378
|
|
|
} |
|
379
|
|
|
|
|
380
|
|
|
/** |
|
381
|
|
|
* get all the blocks that match the supplied parameters |
|
382
|
|
|
* |
|
383
|
|
|
* @param int|int[] $groupid groupid (can be an array) |
|
384
|
|
|
* @param bool $asobject |
|
385
|
|
|
* @param int|string $side |
|
386
|
|
|
* 0: sideblock - left |
|
387
|
|
|
* 1: sideblock - right |
|
388
|
|
|
* 2: sideblock - left and right |
|
389
|
|
|
* 3: centerblock - left |
|
390
|
|
|
* 4: centerblock - right |
|
391
|
|
|
* 5: centerblock - center |
|
392
|
|
|
* 6: centerblock - left, right, center |
|
393
|
|
|
* @param $visible 0: not visible 1: visible |
|
|
|
|
|
|
394
|
|
|
* @param string $orderby order of the blocks |
|
395
|
|
|
* @param int $isactive |
|
396
|
|
|
* |
|
397
|
|
|
* @return array of block objects |
|
398
|
|
|
*/ |
|
399
|
|
|
public function getAllBlocksByGroup($groupid, $asobject = true, $side = null, $visible = null, $orderby = 'b.weight,b.bid', $isactive = 1) |
|
400
|
|
|
{ |
|
401
|
|
|
/* @var XoopsMySQLDatabase $db */ |
|
402
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
|
403
|
|
|
$ret = array(); |
|
404
|
|
|
$sql = 'SELECT b.* '; |
|
405
|
|
|
if (!$asobject) { |
|
406
|
|
|
$sql = 'SELECT b.bid '; |
|
407
|
|
|
} |
|
408
|
|
|
$sql .= 'FROM ' . $db->prefix('newblocks') . ' b LEFT JOIN ' . $db->prefix('group_permission') . " l ON l.gperm_itemid=b.bid WHERE gperm_name = 'block_read' AND gperm_modid = 1"; |
|
409
|
|
|
if (is_array($groupid)) { |
|
410
|
|
|
$sql .= ' AND (l.gperm_groupid=' . $groupid[0] . ''; |
|
411
|
|
|
$size = count($groupid); |
|
412
|
|
|
if ($size > 1) { |
|
413
|
|
|
for ($i = 1; $i < $size; ++$i) { |
|
414
|
|
|
$sql .= ' OR l.gperm_groupid=' . $groupid[$i] . ''; |
|
415
|
|
|
} |
|
416
|
|
|
} |
|
417
|
|
|
$sql .= ')'; |
|
418
|
|
|
} else { |
|
419
|
|
|
$sql .= ' AND l.gperm_groupid=' . $groupid . ''; |
|
420
|
|
|
} |
|
421
|
|
|
$sql .= ' AND b.isactive=' . $isactive; |
|
422
|
|
|
if (isset($side)) { |
|
423
|
|
|
// get both sides in sidebox? (some themes need this) |
|
424
|
|
|
if ($side === XOOPS_SIDEBLOCK_BOTH) { |
|
425
|
|
|
$side = '(b.side=0 OR b.side=1)'; |
|
426
|
|
|
} elseif ($side === XOOPS_CENTERBLOCK_ALL) { |
|
427
|
|
|
$side = '(b.side=3 OR b.side=4 OR b.side=5 OR b.side=7 OR b.side=8 OR b.side=9 )'; |
|
428
|
|
|
} elseif ($side === XOOPS_FOOTERBLOCK_ALL) { |
|
429
|
|
|
$side = '(b.side=10 OR b.side=11 OR b.side=12 )'; |
|
430
|
|
|
} else { |
|
431
|
|
|
$side = 'b.side=' . $side; |
|
432
|
|
|
} |
|
433
|
|
|
$sql .= ' AND ' . $side; |
|
434
|
|
|
} |
|
435
|
|
|
if (isset($visible)) { |
|
436
|
|
|
$sql .= " AND b.visible=$visible"; |
|
437
|
|
|
} |
|
438
|
|
|
$sql .= " ORDER BY $orderby"; |
|
439
|
|
|
$result = $db->query($sql); |
|
440
|
|
|
if (!$db->isResultSet($result)) { |
|
441
|
|
|
\trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR); |
|
442
|
|
|
} |
|
443
|
|
|
$added = array(); |
|
444
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
|
|
|
|
|
|
445
|
|
|
if (!in_array($myrow['bid'], $added)) { |
|
446
|
|
|
if (!$asobject) { |
|
447
|
|
|
$ret[] = $myrow['bid']; |
|
448
|
|
|
} else { |
|
449
|
|
|
$ret[] = new XoopsBlock($myrow); |
|
450
|
|
|
} |
|
451
|
|
|
$added[] = $myrow['bid']; |
|
452
|
|
|
} |
|
453
|
|
|
} |
|
454
|
|
|
|
|
455
|
|
|
return $ret; |
|
456
|
|
|
} |
|
457
|
|
|
|
|
458
|
|
|
/** |
|
459
|
|
|
* @param $groupid |
|
460
|
|
|
* |
|
461
|
|
|
* @return array |
|
462
|
|
|
*/ |
|
463
|
|
|
public function getBlockByPerm($groupid) |
|
464
|
|
|
{ |
|
465
|
|
|
if (isset($groupid)) { |
|
466
|
|
|
$sql = 'SELECT DISTINCT gperm_itemid FROM ' . $this->db->prefix('group_permission') . " WHERE gperm_name = 'block_read' AND gperm_modid = 1"; |
|
467
|
|
|
if (is_array($groupid)) { |
|
468
|
|
|
$sql .= ' AND gperm_groupid IN (' . implode(',', $groupid) . ')'; |
|
469
|
|
|
} else { |
|
470
|
|
|
if ((int)$groupid > 0) { |
|
471
|
|
|
$sql .= ' AND gperm_groupid=' . (int)$groupid; |
|
472
|
|
|
} |
|
473
|
|
|
} |
|
474
|
|
|
$result = $this->db->query($sql); |
|
475
|
|
|
if (!$this->db->isResultSet($result)) { |
|
476
|
|
|
\trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR); |
|
|
|
|
|
|
477
|
|
|
} |
|
478
|
|
|
$blockids = array(); |
|
479
|
|
|
while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
480
|
|
|
$blockids[] = $myrow['gperm_itemid']; |
|
481
|
|
|
} |
|
482
|
|
|
if (empty($blockids)) { |
|
483
|
|
|
return $blockids; |
|
484
|
|
|
} |
|
485
|
|
|
|
|
486
|
|
|
return $blockids; |
|
487
|
|
|
} |
|
488
|
|
|
|
|
489
|
|
|
return null; |
|
490
|
|
|
} |
|
491
|
|
|
|
|
492
|
|
|
/** |
|
493
|
|
|
* @param $groupid |
|
494
|
|
|
* @param int $module_id |
|
495
|
|
|
* @param bool $toponlyblock |
|
496
|
|
|
* @param null $visible |
|
|
|
|
|
|
497
|
|
|
* @param string $orderby |
|
498
|
|
|
* @param int $isactive |
|
499
|
|
|
* |
|
500
|
|
|
* @return array |
|
501
|
|
|
*/ |
|
502
|
|
|
public function getAllByGroupModule($groupid, $module_id = 0, $toponlyblock = false, $visible = null, $orderby = 'b.weight, m.block_id', $isactive = 1) |
|
503
|
|
|
{ |
|
504
|
|
|
$isactive = (int)$isactive; |
|
505
|
|
|
$db = $GLOBALS['xoopsDB']; |
|
506
|
|
|
$ret = array(); |
|
507
|
|
|
if (isset($groupid)) { |
|
508
|
|
|
$sql = 'SELECT DISTINCT gperm_itemid FROM ' . $db->prefix('group_permission') . " WHERE gperm_name = 'block_read' AND gperm_modid = 1"; |
|
509
|
|
|
if (is_array($groupid)) { |
|
510
|
|
|
$sql .= ' AND gperm_groupid IN (' . implode(',', $groupid) . ')'; |
|
511
|
|
|
} else { |
|
512
|
|
|
if ((int)$groupid > 0) { |
|
513
|
|
|
$sql .= ' AND gperm_groupid=' . (int)$groupid; |
|
514
|
|
|
} |
|
515
|
|
|
} |
|
516
|
|
|
$result = $db->query($sql); |
|
517
|
|
|
if (!$db->isResultSet($result)) { |
|
518
|
|
|
\trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR); |
|
519
|
|
|
} |
|
520
|
|
|
$blockids = array(); |
|
521
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
|
522
|
|
|
$blockids[] = $myrow['gperm_itemid']; |
|
523
|
|
|
} |
|
524
|
|
|
if (empty($blockids)) { |
|
525
|
|
|
return $blockids; |
|
526
|
|
|
} |
|
527
|
|
|
} |
|
528
|
|
|
$sql = 'SELECT b.* FROM ' . $db->prefix('newblocks') . ' b, ' . $db->prefix('block_module_link') . ' m WHERE m.block_id=b.bid'; |
|
529
|
|
|
$sql .= ' AND b.isactive=' . $isactive; |
|
530
|
|
|
if (isset($visible)) { |
|
531
|
|
|
$sql .= ' AND b.visible=' . (int)$visible; |
|
532
|
|
|
} |
|
533
|
|
|
if (!isset($module_id)) { |
|
534
|
|
|
} elseif (!empty($module_id)) { |
|
535
|
|
|
$sql .= ' AND m.module_id IN (0,' . (int)$module_id; |
|
536
|
|
|
if ($toponlyblock) { |
|
537
|
|
|
$sql .= ',-1'; |
|
538
|
|
|
} |
|
539
|
|
|
$sql .= ')'; |
|
540
|
|
|
} else { |
|
541
|
|
|
if ($toponlyblock) { |
|
542
|
|
|
$sql .= ' AND m.module_id IN (0,-1)'; |
|
543
|
|
|
} else { |
|
544
|
|
|
$sql .= ' AND m.module_id=0'; |
|
545
|
|
|
} |
|
546
|
|
|
} |
|
547
|
|
|
if (!empty($blockids)) { |
|
548
|
|
|
$sql .= ' AND b.bid IN (' . implode(',', $blockids) . ')'; |
|
549
|
|
|
} |
|
550
|
|
|
$sql .= ' ORDER BY ' . $orderby; |
|
551
|
|
|
$result = $db->query($sql); |
|
552
|
|
|
if (!$db->isResultSet($result)) { |
|
553
|
|
|
\trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR); |
|
554
|
|
|
} |
|
555
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
|
556
|
|
|
$block = new XoopsBlock($myrow); |
|
557
|
|
|
$ret[$myrow['bid']] =& $block; |
|
558
|
|
|
unset($block); |
|
559
|
|
|
} |
|
560
|
|
|
|
|
561
|
|
|
return $ret; |
|
562
|
|
|
} |
|
563
|
|
|
|
|
564
|
|
|
/** |
|
565
|
|
|
* @param int $module_id |
|
566
|
|
|
* @param bool $toponlyblock |
|
567
|
|
|
* @param null $visible |
|
|
|
|
|
|
568
|
|
|
* @param string $orderby |
|
569
|
|
|
* @param int $isactive |
|
570
|
|
|
* |
|
571
|
|
|
* @return array |
|
572
|
|
|
*/ |
|
573
|
|
|
public function getNonGroupedBlocks($module_id = 0, $toponlyblock = false, $visible = null, $orderby = 'b.weight, m.block_id', $isactive = 1) |
|
574
|
|
|
{ |
|
575
|
|
|
$db = $GLOBALS['xoopsDB']; |
|
576
|
|
|
$ret = array(); |
|
577
|
|
|
$bids = array(); |
|
578
|
|
|
$sql = 'SELECT DISTINCT(bid) from ' . $db->prefix('newblocks'); |
|
579
|
|
|
$result = $db->query($sql); |
|
580
|
|
|
if ($db->isResultSet($result)) { |
|
581
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
|
582
|
|
|
$bids[] = $myrow['bid']; |
|
583
|
|
|
} |
|
584
|
|
|
} |
|
585
|
|
|
|
|
586
|
|
|
$sql = 'SELECT DISTINCT(p.gperm_itemid) from ' . $db->prefix('group_permission') . ' p, ' . $db->prefix('groups') . " g WHERE g.groupid=p.gperm_groupid AND p.gperm_name='block_read'"; |
|
587
|
|
|
$grouped = array(); |
|
588
|
|
|
$result = $db->query($sql); |
|
589
|
|
|
if ($db->isResultSet($result)) { |
|
590
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
|
591
|
|
|
$grouped[] = $myrow['gperm_itemid']; |
|
592
|
|
|
} |
|
593
|
|
|
} |
|
594
|
|
|
|
|
595
|
|
|
$non_grouped = array_diff($bids, $grouped); |
|
596
|
|
|
if (!empty($non_grouped)) { |
|
597
|
|
|
$sql = 'SELECT b.* FROM ' . $db->prefix('newblocks') . ' b, ' . $db->prefix('block_module_link') . ' m WHERE m.block_id=b.bid'; |
|
598
|
|
|
$sql .= ' AND b.isactive=' . (int)$isactive; |
|
599
|
|
|
if (isset($visible)) { |
|
600
|
|
|
$sql .= ' AND b.visible=' . (int)$visible; |
|
601
|
|
|
} |
|
602
|
|
|
if (!isset($module_id)) { |
|
603
|
|
|
} elseif (!empty($module_id)) { |
|
604
|
|
|
$sql .= ' AND m.module_id IN (0,' . (int)$module_id; |
|
605
|
|
|
if ($toponlyblock) { |
|
606
|
|
|
$sql .= ',-1'; |
|
607
|
|
|
} |
|
608
|
|
|
$sql .= ')'; |
|
609
|
|
|
} else { |
|
610
|
|
|
if ($toponlyblock) { |
|
611
|
|
|
$sql .= ' AND m.module_id IN (0,-1)'; |
|
612
|
|
|
} else { |
|
613
|
|
|
$sql .= ' AND m.module_id=0'; |
|
614
|
|
|
} |
|
615
|
|
|
} |
|
616
|
|
|
$sql .= ' AND b.bid IN (' . implode(',', $non_grouped) . ')'; |
|
617
|
|
|
$sql .= ' ORDER BY ' . $orderby; |
|
618
|
|
|
$result = $db->query($sql); |
|
619
|
|
|
if (!$db->isResultSet($result)) { |
|
620
|
|
|
\trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR); |
|
621
|
|
|
} |
|
622
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
|
623
|
|
|
$block = new XoopsBlock($myrow); |
|
624
|
|
|
$ret[$myrow['bid']] =& $block; |
|
625
|
|
|
unset($block); |
|
626
|
|
|
} |
|
627
|
|
|
} |
|
628
|
|
|
|
|
629
|
|
|
return $ret; |
|
630
|
|
|
} |
|
631
|
|
|
|
|
632
|
|
|
/** |
|
633
|
|
|
* XoopsBlock::countSimilarBlocks() |
|
634
|
|
|
* |
|
635
|
|
|
* @param mixed $moduleId |
|
636
|
|
|
* @param mixed $funcNum |
|
637
|
|
|
* @param mixed $showFunc |
|
638
|
|
|
* @return int |
|
639
|
|
|
*/ |
|
640
|
|
|
public function countSimilarBlocks($moduleId, $funcNum, $showFunc = null) |
|
641
|
|
|
{ |
|
642
|
|
|
$funcNum = (int)$funcNum; |
|
643
|
|
|
$moduleId = (int)$moduleId; |
|
644
|
|
|
if ($funcNum < 1 || $moduleId < 1) { |
|
645
|
|
|
// invalid query |
|
646
|
|
|
return 0; |
|
647
|
|
|
} |
|
648
|
|
|
/* @var XoopsMySQLDatabase $db */ |
|
649
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
|
650
|
|
|
if (isset($showFunc)) { |
|
651
|
|
|
// showFunc is set for more strict comparison |
|
652
|
|
|
$sql = sprintf('SELECT COUNT(*) FROM %s WHERE mid = %d AND func_num = %d AND show_func = %s', $db->prefix('newblocks'), $moduleId, $funcNum, $db->quoteString(trim($showFunc))); |
|
653
|
|
|
} else { |
|
654
|
|
|
$sql = sprintf('SELECT COUNT(*) FROM %s WHERE mid = %d AND func_num = %d', $db->prefix('newblocks'), $moduleId, $funcNum); |
|
655
|
|
|
} |
|
656
|
|
|
$result = $db->query($sql); |
|
657
|
|
|
if (!$db->isResultSet($result)) { |
|
658
|
|
|
// \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR); |
|
659
|
|
|
return 0; |
|
660
|
|
|
} |
|
661
|
|
|
list($count) = $db->fetchRow($result); |
|
|
|
|
|
|
662
|
|
|
|
|
663
|
|
|
return (int)$count; |
|
664
|
|
|
} |
|
665
|
|
|
} |
|
666
|
|
|
|