1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* XOOPS Kernel Class |
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-2021 XOOPS Project (www.xoops.org) |
13
|
|
|
* @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html) |
14
|
|
|
* @package kernel |
15
|
|
|
* @since 2.0.0 |
16
|
|
|
* @author Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/ |
17
|
|
|
*/ |
18
|
|
|
defined('XOOPS_ROOT_PATH') || exit('Restricted access'); |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* A block |
22
|
|
|
* |
23
|
|
|
* @author Kazumi Ono <[email protected]> |
24
|
|
|
* |
25
|
|
|
* @package kernel |
26
|
|
|
* |
27
|
|
|
* @todo reconcile the two XoopsBlock classes. |
28
|
|
|
* @internal This handler appears to only be loaded by system/class/group.php |
29
|
|
|
* @internal The other, in class/xoopsblock.php is loaded all over |
30
|
|
|
*/ |
31
|
|
|
class XoopsBlock extends XoopsObject |
32
|
|
|
{ |
33
|
|
|
//PHP 8.2 Dynamic properties deprecated |
34
|
|
|
public $bid; |
35
|
|
|
public $mid; |
36
|
|
|
public $func_num; |
37
|
|
|
public $options; |
38
|
|
|
public $name; |
39
|
|
|
//public $position; |
40
|
|
|
public $title; |
41
|
|
|
public $content; |
42
|
|
|
public $side; |
43
|
|
|
public $weight; |
44
|
|
|
public $visible; |
45
|
|
|
public $block_type; |
46
|
|
|
public $c_type; |
47
|
|
|
public $isactive; |
48
|
|
|
public $dirname; |
49
|
|
|
public $func_file; |
50
|
|
|
public $show_func; |
51
|
|
|
public $edit_func; |
52
|
|
|
public $template; |
53
|
|
|
public $bcachetime; |
54
|
|
|
public $last_modified; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* constructor |
58
|
|
|
* |
59
|
|
|
* @param mixed $id |
60
|
|
|
**/ |
61
|
|
|
public function __construct($id = null) |
62
|
|
|
{ |
63
|
|
|
$this->initVar('bid', XOBJ_DTYPE_INT, null, false); |
64
|
|
|
$this->initVar('mid', XOBJ_DTYPE_INT, 0, false); |
65
|
|
|
$this->initVar('func_num', XOBJ_DTYPE_INT, 0, false); |
66
|
|
|
$this->initVar('options', XOBJ_DTYPE_TXTBOX, null, false, 255); |
67
|
|
|
$this->initVar('name', XOBJ_DTYPE_TXTBOX, null, true, 150); |
68
|
|
|
//$this->initVar('position', XOBJ_DTYPE_INT, 0, false); |
69
|
|
|
$this->initVar('title', XOBJ_DTYPE_TXTBOX, null, false, 150); |
70
|
|
|
$this->initVar('content', XOBJ_DTYPE_TXTAREA, null, false); |
71
|
|
|
$this->initVar('side', XOBJ_DTYPE_INT, 0, false); |
72
|
|
|
$this->initVar('weight', XOBJ_DTYPE_INT, 0, false); |
73
|
|
|
$this->initVar('visible', XOBJ_DTYPE_INT, 0, false); |
74
|
|
|
$this->initVar('block_type', XOBJ_DTYPE_OTHER, null, false); |
75
|
|
|
$this->initVar('c_type', XOBJ_DTYPE_OTHER, null, false); |
76
|
|
|
$this->initVar('isactive', XOBJ_DTYPE_INT, null, false); |
77
|
|
|
$this->initVar('dirname', XOBJ_DTYPE_TXTBOX, null, false, 50); |
78
|
|
|
$this->initVar('func_file', XOBJ_DTYPE_TXTBOX, null, false, 50); |
79
|
|
|
$this->initVar('show_func', XOBJ_DTYPE_TXTBOX, null, false, 50); |
80
|
|
|
$this->initVar('edit_func', XOBJ_DTYPE_TXTBOX, null, false, 50); |
81
|
|
|
$this->initVar('template', XOBJ_DTYPE_OTHER, null, false); |
82
|
|
|
$this->initVar('bcachetime', XOBJ_DTYPE_INT, 0, false); |
83
|
|
|
$this->initVar('last_modified', XOBJ_DTYPE_INT, 0, false); |
84
|
|
|
|
85
|
|
|
parent::__construct(); |
86
|
|
|
|
87
|
|
|
// for backward compatibility |
88
|
|
|
if (isset($id)) { |
89
|
|
|
if (is_array($id)) { |
90
|
|
|
$this->assignVars($id); |
91
|
|
|
} else { |
92
|
|
|
$blkhandler = xoops_getHandler('block'); |
93
|
|
|
$obj = $blkhandler->get($id); |
94
|
|
|
foreach (array_keys($obj->getVars()) as $i) { |
95
|
|
|
$this->assignVar($i, $obj->getVar($i, 'n')); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Returns Class Base Variable bid |
103
|
|
|
* @param string $format |
104
|
|
|
* @return mixed |
105
|
|
|
*/ |
106
|
|
|
public function id($format = 'n') |
107
|
|
|
{ |
108
|
|
|
return $this->getVar('bid', $format); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Returns Class Base Variable bid |
113
|
|
|
* @param string $format |
114
|
|
|
* @return mixed |
115
|
|
|
*/ |
116
|
|
|
public function bid($format = '') |
117
|
|
|
{ |
118
|
|
|
return $this->getVar('bid', $format); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Returns Class Base Variable mid |
123
|
|
|
* @param string $format |
124
|
|
|
* @return mixed |
125
|
|
|
*/ |
126
|
|
|
public function mid($format = '') |
127
|
|
|
{ |
128
|
|
|
return $this->getVar('mid', $format); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Returns Class Base Variable func_num |
133
|
|
|
* @param string $format |
134
|
|
|
* @return mixed |
135
|
|
|
*/ |
136
|
|
|
public function func_num($format = '') |
137
|
|
|
{ |
138
|
|
|
return $this->getVar('func_num', $format); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Returns Class Base Variable avatar_id |
143
|
|
|
* @param string $format |
144
|
|
|
* @return mixed |
145
|
|
|
*/ |
146
|
|
|
public function options($format = '') |
147
|
|
|
{ |
148
|
|
|
return $this->getVar('options', $format); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Returns Class Base Variable name |
153
|
|
|
* @param string $format |
154
|
|
|
* @return mixed |
155
|
|
|
*/ |
156
|
|
|
public function name($format = '') |
157
|
|
|
{ |
158
|
|
|
return $this->getVar('name', $format); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Returns Class Base Variable title |
163
|
|
|
* @param string $format |
164
|
|
|
* @return mixed |
165
|
|
|
*/ |
166
|
|
|
public function title($format = '') |
167
|
|
|
{ |
168
|
|
|
return $this->getVar('title', $format); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Returns Class Base Variable content |
173
|
|
|
* @param string $format |
174
|
|
|
* @return mixed |
175
|
|
|
*/ |
176
|
|
|
public function content($format = '') |
177
|
|
|
{ |
178
|
|
|
return $this->getVar('content', $format); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Returns Class Base Variable side |
183
|
|
|
* @param string $format |
184
|
|
|
* @return mixed |
185
|
|
|
*/ |
186
|
|
|
public function side($format = '') |
187
|
|
|
{ |
188
|
|
|
return $this->getVar('side', $format); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Returns Class Base Variable weight |
193
|
|
|
* @param string $format |
194
|
|
|
* @return mixed |
195
|
|
|
*/ |
196
|
|
|
public function weight($format = '') |
197
|
|
|
{ |
198
|
|
|
return $this->getVar('weight', $format); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Returns Class Base Variable visible |
203
|
|
|
* @param string $format |
204
|
|
|
* @return mixed |
205
|
|
|
*/ |
206
|
|
|
public function visible($format = '') |
207
|
|
|
{ |
208
|
|
|
return $this->getVar('visible', $format); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Returns Class Base Variable block_type |
213
|
|
|
* |
214
|
|
|
* Vaild block_type values are: |
215
|
|
|
* S - generated by system module |
216
|
|
|
* M - generated by a non-system module |
217
|
|
|
* C - Custom block |
218
|
|
|
* D - cloned system/module block |
219
|
|
|
* E - cloned custom block, DON'T use it |
220
|
|
|
* |
221
|
|
|
* @param string $format |
222
|
|
|
* |
223
|
|
|
* @return mixed |
224
|
|
|
*/ |
225
|
|
|
public function block_type($format = '') |
226
|
|
|
{ |
227
|
|
|
return $this->getVar('block_type', $format); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Returns Class Base Variable c_type |
232
|
|
|
* @param string $format |
233
|
|
|
* @return mixed |
234
|
|
|
*/ |
235
|
|
|
public function c_type($format = '') |
236
|
|
|
{ |
237
|
|
|
return $this->getVar('c_type', $format); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Returns Class Base Variable isactive |
242
|
|
|
* @param string $format |
243
|
|
|
* @return mixed |
244
|
|
|
*/ |
245
|
|
|
public function isactive($format = '') |
246
|
|
|
{ |
247
|
|
|
return $this->getVar('isactive', $format); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Returns Class Base Variable dirname |
252
|
|
|
* @param string $format |
253
|
|
|
* @return mixed |
254
|
|
|
*/ |
255
|
|
|
public function dirname($format = '') |
256
|
|
|
{ |
257
|
|
|
return $this->getVar('dirname', $format); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Returns Class Base Variable func_file |
262
|
|
|
* @param string $format |
263
|
|
|
* @return mixed |
264
|
|
|
*/ |
265
|
|
|
public function func_file($format = '') |
266
|
|
|
{ |
267
|
|
|
return $this->getVar('func_file', $format); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Returns Class Base Variable show_func |
272
|
|
|
* @param string $format |
273
|
|
|
* @return mixed |
274
|
|
|
*/ |
275
|
|
|
public function show_func($format = '') |
276
|
|
|
{ |
277
|
|
|
return $this->getVar('show_func', $format); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* Returns Class Base Variable edit_func |
282
|
|
|
* @param string $format |
283
|
|
|
* @return mixed |
284
|
|
|
*/ |
285
|
|
|
public function edit_func($format = '') |
286
|
|
|
{ |
287
|
|
|
return $this->getVar('edit_func', $format); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Returns Class Base Variable template |
292
|
|
|
* @param string $format |
293
|
|
|
* @return mixed |
294
|
|
|
*/ |
295
|
|
|
public function template($format = '') |
296
|
|
|
{ |
297
|
|
|
return $this->getVar('template', $format); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* Returns Class Base Variable avatar_id |
302
|
|
|
* @param string $format |
303
|
|
|
* @return mixed |
304
|
|
|
*/ |
305
|
|
|
public function bcachetime($format = '') |
306
|
|
|
{ |
307
|
|
|
return $this->getVar('bcachetime', $format); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* Returns Class Base Variable last_modified |
312
|
|
|
* @param string $format |
313
|
|
|
* @return mixed |
314
|
|
|
*/ |
315
|
|
|
public function last_modified($format = '') |
316
|
|
|
{ |
317
|
|
|
return $this->getVar('last_modified', $format); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* return the content of the block for output |
322
|
|
|
* |
323
|
|
|
* @param string $format |
324
|
|
|
* @param string $c_type type of content |
325
|
|
|
* Valid values for the type of content: |
326
|
|
|
* H : custom HTML block |
327
|
|
|
* P : custom PHP block |
328
|
|
|
* S : use text sanitizer (smilies enabled) |
329
|
|
|
* T : use text sanitizer (smilies disabled)</ul> |
330
|
|
|
* @return string content for output |
331
|
|
|
*/ |
332
|
|
|
public function getContent($format = 's', $c_type = 'T') |
333
|
|
|
{ |
334
|
|
|
$format = strtolower($format); |
335
|
|
|
$c_type = strtoupper($c_type); |
336
|
|
|
switch ($format) { |
337
|
|
|
case 's': |
338
|
|
|
if ($c_type === 'H') { |
339
|
|
|
return str_replace('{X_SITEURL}', XOOPS_URL . '/', $this->getVar('content', 'n')); |
340
|
|
|
} elseif ($c_type === 'P') { |
341
|
|
|
ob_start(); |
342
|
|
|
echo eval($this->getVar('content', 'n')); |
|
|
|
|
343
|
|
|
$content = ob_get_contents(); |
344
|
|
|
ob_end_clean(); |
345
|
|
|
|
346
|
|
|
return str_replace('{X_SITEURL}', XOOPS_URL . '/', $content); |
347
|
|
|
} elseif ($c_type === 'S') { |
348
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
349
|
|
|
$content = str_replace('{X_SITEURL}', XOOPS_URL . '/', $this->getVar('content', 'n')); |
350
|
|
|
|
351
|
|
|
return $myts->displayTarea($content, 0, 1); |
352
|
|
|
} else { |
353
|
|
|
$myts = \MyTextSanitizer::getInstance(); |
354
|
|
|
$content = str_replace('{X_SITEURL}', XOOPS_URL . '/', $this->getVar('content', 'n')); |
355
|
|
|
|
356
|
|
|
return $myts->displayTarea($content, 0, 0); |
357
|
|
|
} |
358
|
|
|
case 'e': |
359
|
|
|
return $this->getVar('content', 'e'); |
|
|
|
|
360
|
|
|
default: |
361
|
|
|
return $this->getVar('content', 'n'); |
|
|
|
|
362
|
|
|
} |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
/** |
366
|
|
|
* (HTML-) form for setting the options of the block |
367
|
|
|
* |
368
|
|
|
* @return string HTML for the form, FALSE if not defined for this block |
369
|
|
|
*/ |
370
|
|
|
public function getOptions() |
371
|
|
|
{ |
372
|
|
|
if (!$this->isCustom()) { |
373
|
|
|
$edit_func = $this->getVar('edit_func'); |
374
|
|
|
if (!$edit_func) { |
375
|
|
|
return false; |
|
|
|
|
376
|
|
|
} |
377
|
|
|
if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $this->getVar('dirname') . '/blocks/' . $this->getVar('func_file'))) { |
378
|
|
|
if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $this->getVar('dirname') . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/blocks.php')) { |
379
|
|
|
include_once XOOPS_ROOT_PATH . '/modules/' . $this->getVar('dirname') . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/blocks.php'; |
380
|
|
|
} elseif (file_exists(XOOPS_ROOT_PATH . '/modules/' . $this->getVar('dirname') . '/language/english/blocks.php')) { |
381
|
|
|
include_once XOOPS_ROOT_PATH . '/modules/' . $this->getVar('dirname') . '/language/english/blocks.php'; |
382
|
|
|
} |
383
|
|
|
include_once XOOPS_ROOT_PATH . '/modules/' . $this->getVar('dirname') . '/blocks/' . $this->getVar('func_file'); |
384
|
|
|
$options = explode('|', $this->getVar('options')); |
385
|
|
|
$edit_form = $edit_func($options); |
386
|
|
|
if (!$edit_form) { |
387
|
|
|
return false; |
|
|
|
|
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
return $edit_form; |
391
|
|
|
} else { |
392
|
|
|
return false; |
|
|
|
|
393
|
|
|
} |
394
|
|
|
} else { |
395
|
|
|
return false; |
|
|
|
|
396
|
|
|
} |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* @return bool |
401
|
|
|
*/ |
402
|
|
|
public function isCustom() |
403
|
|
|
{ |
404
|
|
|
return in_array($this->getVar('block_type'), array( |
405
|
|
|
'C', |
406
|
|
|
'E')); |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* These methods are for compatibility with the pre 2.5.11 class/xoopsblock.php |
411
|
|
|
* class/xoopsblock.php defined its own XoopsBlock class, making it impossible |
412
|
|
|
* to use with anything that used the handler provided in kernel/block.php |
413
|
|
|
* |
414
|
|
|
* In addition to the actual data, the old XoopsBlock contained what should be |
415
|
|
|
* considered handler logic. |
416
|
|
|
* |
417
|
|
|
* It appears that class/xoopsblock.php came first, but a conversion to the kernel |
418
|
|
|
* handler was never completed. |
419
|
|
|
* |
420
|
|
|
* These methods should all be considered deprecated. |
421
|
|
|
*/ |
422
|
|
|
|
423
|
|
|
/** |
424
|
|
|
* Load $id |
425
|
|
|
* |
426
|
|
|
* @param int $id |
427
|
|
|
* |
428
|
|
|
* @deprecated |
429
|
|
|
*/ |
430
|
|
|
public function load($id) |
431
|
|
|
{ |
432
|
|
|
$id = (int)$id; |
433
|
|
|
/** @var XoopsBlockHandler $blkhandler */ |
434
|
|
|
$blkhandler = xoops_getHandler('block'); |
435
|
|
|
$obj = $blkhandler->get($id); |
436
|
|
|
foreach (array_keys($obj->getVars()) as $i) { |
437
|
|
|
$this->assignVar($i, $obj->getVar($i, 'n')); |
438
|
|
|
} |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
/** |
442
|
|
|
* Store Block Data to Database |
443
|
|
|
* |
444
|
|
|
* @return int|false id of inserted block, or false on failure |
445
|
|
|
* |
446
|
|
|
* @deprecated |
447
|
|
|
*/ |
448
|
|
|
public function store() |
449
|
|
|
{ |
450
|
|
|
/** @var XoopsBlockHandler $blkhandler */ |
451
|
|
|
$blkhandler = xoops_getHandler('block'); |
452
|
|
|
if (false === $blkhandler->insert($this)) { |
453
|
|
|
return false; |
454
|
|
|
} |
455
|
|
|
return (int) $this->bid(); |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* Delete an ID from the database |
460
|
|
|
* |
461
|
|
|
* @return bool |
462
|
|
|
* |
463
|
|
|
* @deprecated |
464
|
|
|
*/ |
465
|
|
|
public function delete() |
466
|
|
|
{ |
467
|
|
|
/** @var XoopsBlockHandler $blkhandler */ |
468
|
|
|
$blkhandler = xoops_getHandler('block'); |
469
|
|
|
return $blkhandler->delete($this); |
470
|
|
|
} |
471
|
|
|
|
472
|
|
|
/** |
473
|
|
|
* Build Block |
474
|
|
|
* |
475
|
|
|
* @return mixed |
476
|
|
|
* |
477
|
|
|
* @deprecated |
478
|
|
|
*/ |
479
|
|
|
public function buildBlock() |
480
|
|
|
{ |
481
|
|
|
global $xoopsConfig, $xoopsOption, $xoTheme; |
482
|
|
|
$block = array(); |
483
|
|
|
if (!$this->isCustom()) { |
484
|
|
|
// get block display function |
485
|
|
|
$show_func = $this->getVar('show_func'); |
486
|
|
|
if (!$show_func) { |
487
|
|
|
return false; |
488
|
|
|
} |
489
|
|
|
if (!file_exists($func_file = $GLOBALS['xoops']->path('modules/' . $this->getVar('dirname') . '/blocks/' . $this->getVar('func_file')))) { |
490
|
|
|
return false; |
491
|
|
|
} |
492
|
|
|
// must get lang files b4 including the file |
493
|
|
|
// some modules require it for code that is outside the function |
494
|
|
|
xoops_loadLanguage('blocks', $this->getVar('dirname')); |
|
|
|
|
495
|
|
|
include_once $func_file; |
496
|
|
|
|
497
|
|
|
if (function_exists($show_func)) { |
498
|
|
|
// execute the function |
499
|
|
|
$options = explode('|', $this->getVar('options')); |
500
|
|
|
$block = $show_func($options); |
501
|
|
|
if (!$block) { |
502
|
|
|
return false; |
503
|
|
|
} |
504
|
|
|
} else { |
505
|
|
|
return false; |
506
|
|
|
} |
507
|
|
|
} else { |
508
|
|
|
// it is a custom block, so just return the contents |
509
|
|
|
$block['content'] = $this->getContent('s', $this->getVar('c_type')); |
|
|
|
|
510
|
|
|
if (empty($block['content'])) { |
511
|
|
|
return false; |
512
|
|
|
} |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
return $block; |
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
/* |
519
|
|
|
* Aligns the content of a block |
520
|
|
|
* If position is 0, content in DB is positioned |
521
|
|
|
* before the original content |
522
|
|
|
* If position is 1, content in DB is positioned |
523
|
|
|
* after the original content |
524
|
|
|
*/ |
525
|
|
|
/** |
526
|
|
|
* @param $position |
527
|
|
|
* @param string $content |
528
|
|
|
* @param string $contentdb |
529
|
|
|
* |
530
|
|
|
* @return string |
531
|
|
|
* |
532
|
|
|
* @deprecated |
533
|
|
|
*/ |
534
|
|
|
public function buildContent($position, $content = '', $contentdb = '') |
535
|
|
|
{ |
536
|
|
|
$ret = null; |
537
|
|
|
if ($position == 0) { |
538
|
|
|
$ret = $contentdb . $content; |
539
|
|
|
} elseif ($position == 1) { |
540
|
|
|
$ret = $content . $contentdb; |
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
return $ret; |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
/** |
547
|
|
|
* Enter description here... |
548
|
|
|
* |
549
|
|
|
* @param string $originaltitle |
550
|
|
|
* @param string $newtitle |
551
|
|
|
* @return string title |
552
|
|
|
* |
553
|
|
|
* @deprecated |
554
|
|
|
*/ |
555
|
|
|
public function buildTitle($originaltitle, $newtitle = '') |
556
|
|
|
{ |
557
|
|
|
$ret = $originaltitle; |
558
|
|
|
if ($newtitle != '') { |
559
|
|
|
$ret = $newtitle; |
560
|
|
|
} |
561
|
|
|
|
562
|
|
|
return $ret; |
563
|
|
|
} |
564
|
|
|
|
565
|
|
|
/** |
566
|
|
|
* get all the blocks that match the supplied parameters |
567
|
|
|
* @param int|array $groupid groupid (can be an array) |
568
|
|
|
* @param bool $asobject |
569
|
|
|
* @param null|string $side 0: sideblock - left |
570
|
|
|
* 1: sideblock - right |
571
|
|
|
* 2: sideblock - left and right |
572
|
|
|
* 3: centerblock - left |
573
|
|
|
* 4: centerblock - right |
574
|
|
|
* 5: centerblock - center |
575
|
|
|
* 6: centerblock - left, right, center |
576
|
|
|
* @param $visible 0: not visible 1: visible |
|
|
|
|
577
|
|
|
* @param string $orderby order of the blocks |
578
|
|
|
* @param int $isactive |
579
|
|
|
* @returns array of block objects |
580
|
|
|
* |
581
|
|
|
* @deprecated |
582
|
|
|
*/ |
583
|
|
|
public static function getAllBlocksByGroup($groupid, $asobject = true, $side = null, $visible = null, $orderby = 'b.weight,b.bid', $isactive = 1) |
584
|
|
|
{ |
585
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
586
|
|
|
$ret = array(); |
587
|
|
|
$sql = 'SELECT b.* '; |
588
|
|
|
if (!$asobject) { |
589
|
|
|
$sql = 'SELECT b.bid '; |
590
|
|
|
} |
591
|
|
|
$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"; |
592
|
|
|
if (is_array($groupid)) { |
593
|
|
|
$sql .= ' AND (l.gperm_groupid=' . $groupid[0] . ''; |
594
|
|
|
$size = count($groupid); |
595
|
|
|
if ($size > 1) { |
596
|
|
|
for ($i = 1; $i < $size; ++$i) { |
597
|
|
|
$sql .= ' OR l.gperm_groupid=' . $groupid[$i] . ''; |
598
|
|
|
} |
599
|
|
|
} |
600
|
|
|
$sql .= ')'; |
601
|
|
|
} else { |
602
|
|
|
$sql .= ' AND l.gperm_groupid=' . $groupid . ''; |
603
|
|
|
} |
604
|
|
|
$sql .= ' AND b.isactive=' . $isactive; |
605
|
|
|
if (isset($side)) { |
606
|
|
|
// get both sides in sidebox? (some themes need this) |
607
|
|
|
if ($side == XOOPS_SIDEBLOCK_BOTH) { |
608
|
|
|
$side = '(b.side=0 OR b.side=1)'; |
609
|
|
|
} elseif ($side == XOOPS_CENTERBLOCK_ALL) { |
610
|
|
|
$side = '(b.side=3 OR b.side=4 OR b.side=5 OR b.side=7 OR b.side=8 OR b.side=9 )'; |
611
|
|
|
} elseif ($side == XOOPS_FOOTERBLOCK_ALL) { |
612
|
|
|
$side = '(b.side=10 OR b.side=11 OR b.side=12 )'; |
613
|
|
|
} else { |
614
|
|
|
$side = 'b.side=' . $side; |
615
|
|
|
} |
616
|
|
|
$sql .= ' AND ' . $side; |
617
|
|
|
} |
618
|
|
|
if (isset($visible)) { |
619
|
|
|
$sql .= " AND b.visible=$visible"; |
620
|
|
|
} |
621
|
|
|
$sql .= " ORDER BY $orderby"; |
622
|
|
|
$result = $db->query($sql); |
|
|
|
|
623
|
|
|
if (!$db->isResultSet($result)) { |
624
|
|
|
throw new \RuntimeException( |
625
|
|
|
\sprintf(_DB_QUERY_ERROR, $sql) . $db->error(), E_USER_ERROR |
|
|
|
|
626
|
|
|
); |
627
|
|
|
} |
628
|
|
|
$added = array(); |
629
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
|
|
|
|
630
|
|
|
if (!in_array($myrow['bid'], $added)) { |
631
|
|
|
if (!$asobject) { |
632
|
|
|
$ret[] = $myrow['bid']; |
633
|
|
|
} else { |
634
|
|
|
$ret[] = new XoopsBlock($myrow); |
635
|
|
|
} |
636
|
|
|
$added[] = $myrow['bid']; |
637
|
|
|
} |
638
|
|
|
} |
639
|
|
|
|
640
|
|
|
return $ret; |
641
|
|
|
} |
642
|
|
|
|
643
|
|
|
/** |
644
|
|
|
* XoopsBlock::getAllBlocks() |
645
|
|
|
* |
646
|
|
|
* @param string $rettype |
647
|
|
|
* @param mixed $side |
648
|
|
|
* @param mixed $visible |
649
|
|
|
* @param string $orderby |
650
|
|
|
* @param integer $isactive |
651
|
|
|
* @return array |
652
|
|
|
* |
653
|
|
|
* @deprecated |
654
|
|
|
*/ |
655
|
|
|
public function getAllBlocks($rettype = 'object', $side = null, $visible = null, $orderby = 'side,weight,bid', $isactive = 1) |
656
|
|
|
{ |
657
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
658
|
|
|
$ret = array(); |
659
|
|
|
$where_query = ' WHERE isactive=' . $isactive; |
660
|
|
|
if (isset($side)) { |
661
|
|
|
// get both sides in sidebox? (some themes need this) |
662
|
|
|
if ($side == XOOPS_SIDEBLOCK_BOTH) { |
663
|
|
|
$side = '(side=0 OR side=1)'; |
664
|
|
|
} elseif ($side == XOOPS_CENTERBLOCK_ALL) { |
665
|
|
|
$side = '(side=3 OR side=4 OR side=5 OR side=7 OR side=8 OR side=9)'; |
666
|
|
|
} elseif ($side == XOOPS_FOOTERBLOCK_ALL) { |
667
|
|
|
$side = '(side=10 OR side=11 OR side=12)'; |
668
|
|
|
} else { |
669
|
|
|
$side = 'side=' . $side; |
670
|
|
|
} |
671
|
|
|
$where_query .= ' AND ' . $side; |
672
|
|
|
} |
673
|
|
|
if (isset($visible)) { |
674
|
|
|
$where_query .= ' AND visible=.' . $visible; |
675
|
|
|
} |
676
|
|
|
$where_query .= ' ORDER BY ' . $orderby; |
677
|
|
|
switch ($rettype) { |
678
|
|
|
case 'object': |
679
|
|
|
$sql = 'SELECT * FROM ' . $db->prefix('newblocks') . '' . $where_query; |
680
|
|
|
$result = $db->query($sql); |
681
|
|
|
if (!$db->isResultSet($result)) { |
682
|
|
|
throw new \RuntimeException( |
683
|
|
|
\sprintf(_DB_QUERY_ERROR, $sql) . $db->error(), E_USER_ERROR |
684
|
|
|
); |
685
|
|
|
} |
686
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
687
|
|
|
$ret[] = new XoopsBlock($myrow); |
688
|
|
|
} |
689
|
|
|
break; |
690
|
|
|
case 'list': |
691
|
|
|
$sql = 'SELECT * FROM ' . $db->prefix('newblocks') . '' . $where_query; |
692
|
|
|
$result = $db->query($sql); |
693
|
|
|
if (!$db->isResultSet($result)) { |
694
|
|
|
throw new \RuntimeException( |
695
|
|
|
\sprintf(_DB_QUERY_ERROR, $sql) . $db->error(), E_USER_ERROR |
696
|
|
|
); |
697
|
|
|
} |
698
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
699
|
|
|
$block = new XoopsBlock($myrow); |
700
|
|
|
$title = $block->getVar('title'); |
701
|
|
|
$title = empty($title) ? $block->getVar('name') : $title; |
702
|
|
|
$ret[$block->getVar('bid')] = $title; |
703
|
|
|
} |
704
|
|
|
break; |
705
|
|
|
case 'id': |
706
|
|
|
$sql = 'SELECT bid FROM ' . $db->prefix('newblocks') . '' . $where_query; |
707
|
|
|
$result = $db->query($sql); |
708
|
|
|
if (!$db->isResultSet($result)) { |
709
|
|
|
throw new \RuntimeException( |
710
|
|
|
\sprintf(_DB_QUERY_ERROR, $sql) . $db->error(), E_USER_ERROR |
711
|
|
|
); |
712
|
|
|
} |
713
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
714
|
|
|
$ret[] = $myrow['bid']; |
715
|
|
|
} |
716
|
|
|
break; |
717
|
|
|
} |
718
|
|
|
|
719
|
|
|
return $ret; |
720
|
|
|
} |
721
|
|
|
|
722
|
|
|
/** |
723
|
|
|
* XoopsBlock::getByModule() |
724
|
|
|
* |
725
|
|
|
* @param mixed $moduleid |
726
|
|
|
* @param mixed $asobject |
727
|
|
|
* @return array |
728
|
|
|
*/ |
729
|
|
|
public static function getByModule($moduleid, $asobject = true) |
730
|
|
|
{ |
731
|
|
|
$moduleid = (int)$moduleid; |
732
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
733
|
|
|
if ($asobject == true) { |
734
|
|
|
$sql = $sql = 'SELECT * FROM ' . $db->prefix('newblocks') . ' WHERE mid=' . $moduleid; |
|
|
|
|
735
|
|
|
} else { |
736
|
|
|
$sql = 'SELECT bid FROM ' . $db->prefix('newblocks') . ' WHERE mid=' . $moduleid; |
737
|
|
|
} |
738
|
|
|
$result = $db->query($sql); |
739
|
|
|
if (!$db->isResultSet($result)) { |
740
|
|
|
throw new \RuntimeException( |
741
|
|
|
\sprintf(_DB_QUERY_ERROR, $sql) . $db->error(), E_USER_ERROR |
742
|
|
|
); |
743
|
|
|
} |
744
|
|
|
$ret = array(); |
745
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
746
|
|
|
if ($asobject) { |
747
|
|
|
$ret[] = new XoopsBlock($myrow); |
748
|
|
|
} else { |
749
|
|
|
$ret[] = $myrow['bid']; |
750
|
|
|
} |
751
|
|
|
} |
752
|
|
|
|
753
|
|
|
return $ret; |
754
|
|
|
} |
755
|
|
|
|
756
|
|
|
/** |
757
|
|
|
* XoopsBlock::getAllByGroupModule() |
758
|
|
|
* |
759
|
|
|
* @param mixed $groupid |
760
|
|
|
* @param integer $module_id |
761
|
|
|
* @param mixed $toponlyblock |
762
|
|
|
* @param mixed $visible |
763
|
|
|
* @param string $orderby |
764
|
|
|
* @param integer $isactive |
765
|
|
|
* @return array |
766
|
|
|
* |
767
|
|
|
* @deprecated (This also appears, dead, in XoopsBlockHandler) |
768
|
|
|
*/ |
769
|
|
|
public function getAllByGroupModule($groupid, $module_id = 0, $toponlyblock = false, $visible = null, $orderby = 'b.weight, m.block_id', $isactive = 1) |
770
|
|
|
{ |
771
|
|
|
$isactive = (int)$isactive; |
772
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
773
|
|
|
$ret = array(); |
774
|
|
|
if (isset($groupid)) { |
775
|
|
|
$sql = 'SELECT DISTINCT gperm_itemid FROM ' . $db->prefix('group_permission') . " WHERE gperm_name = 'block_read' AND gperm_modid = 1"; |
776
|
|
|
if (is_array($groupid)) { |
777
|
|
|
$sql .= ' AND gperm_groupid IN (' . implode(',', $groupid) . ')'; |
778
|
|
|
} else { |
779
|
|
|
if ((int)$groupid > 0) { |
780
|
|
|
$sql .= ' AND gperm_groupid=' . (int)$groupid; |
781
|
|
|
} |
782
|
|
|
} |
783
|
|
|
$result = $db->query($sql); |
784
|
|
|
if (!$db->isResultSet($result)) { |
785
|
|
|
throw new \RuntimeException( |
786
|
|
|
\sprintf(_DB_QUERY_ERROR, $sql) . $db->error(), E_USER_ERROR |
787
|
|
|
); |
788
|
|
|
} |
789
|
|
|
$blockids = array(); |
790
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
791
|
|
|
$blockids[] = $myrow['gperm_itemid']; |
792
|
|
|
} |
793
|
|
|
if (empty($blockids)) { |
794
|
|
|
return $blockids; |
795
|
|
|
} |
796
|
|
|
} |
797
|
|
|
$sql = 'SELECT b.* FROM ' . $db->prefix('newblocks') . ' b, ' . $db->prefix('block_module_link') . ' m WHERE m.block_id=b.bid'; |
798
|
|
|
$sql .= ' AND b.isactive=' . $isactive; |
799
|
|
|
if (isset($visible)) { |
800
|
|
|
$sql .= ' AND b.visible=' . (int)$visible; |
801
|
|
|
} |
802
|
|
|
if (!isset($module_id)) { |
803
|
|
|
} elseif (!empty($module_id)) { |
804
|
|
|
$sql .= ' AND m.module_id IN (0,' . (int)$module_id; |
805
|
|
|
if ($toponlyblock) { |
806
|
|
|
$sql .= ',-1'; |
807
|
|
|
} |
808
|
|
|
$sql .= ')'; |
809
|
|
|
} else { |
810
|
|
|
if ($toponlyblock) { |
811
|
|
|
$sql .= ' AND m.module_id IN (0,-1)'; |
812
|
|
|
} else { |
813
|
|
|
$sql .= ' AND m.module_id=0'; |
814
|
|
|
} |
815
|
|
|
} |
816
|
|
|
if (!empty($blockids)) { |
817
|
|
|
$sql .= ' AND b.bid IN (' . implode(',', $blockids) . ')'; |
818
|
|
|
} |
819
|
|
|
$sql .= ' ORDER BY ' . $orderby; |
820
|
|
|
$result = $db->query($sql); |
821
|
|
|
if (!$db->isResultSet($result)) { |
822
|
|
|
throw new \RuntimeException( |
823
|
|
|
\sprintf(_DB_QUERY_ERROR, $sql) . $db->error(), E_USER_ERROR |
824
|
|
|
); |
825
|
|
|
} |
826
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
827
|
|
|
$block = new XoopsBlock($myrow); |
828
|
|
|
$ret[$myrow['bid']] = &$block; |
829
|
|
|
unset($block); |
830
|
|
|
} |
831
|
|
|
|
832
|
|
|
return $ret; |
833
|
|
|
} |
834
|
|
|
|
835
|
|
|
/** |
836
|
|
|
* XoopsBlock::getNonGroupedBlocks() |
837
|
|
|
* |
838
|
|
|
* @param integer $module_id |
839
|
|
|
* @param mixed $toponlyblock |
840
|
|
|
* @param mixed $visible |
841
|
|
|
* @param string $orderby |
842
|
|
|
* @param integer $isactive |
843
|
|
|
* @return array |
844
|
|
|
* |
845
|
|
|
* @deprecated |
846
|
|
|
*/ |
847
|
|
|
public function getNonGroupedBlocks($module_id = 0, $toponlyblock = false, $visible = null, $orderby = 'b.weight, m.block_id', $isactive = 1) |
848
|
|
|
{ |
849
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
850
|
|
|
$ret = array(); |
851
|
|
|
$bids = array(); |
852
|
|
|
$sql = 'SELECT DISTINCT(bid) from ' . $db->prefix('newblocks'); |
853
|
|
|
$result = $db->query($sql); |
854
|
|
|
if ($db->isResultSet($result)) { |
855
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
856
|
|
|
$bids[] = $myrow['bid']; |
857
|
|
|
} |
858
|
|
|
} |
859
|
|
|
|
860
|
|
|
$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'"; |
861
|
|
|
$grouped = array(); |
862
|
|
|
$result = $db->query($sql); |
863
|
|
|
if ($db->isResultSet($result)) { |
864
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
865
|
|
|
$grouped[] = $myrow['gperm_itemid']; |
866
|
|
|
} |
867
|
|
|
} |
868
|
|
|
|
869
|
|
|
|
870
|
|
|
$non_grouped = array_diff($bids, $grouped); |
871
|
|
|
if (!empty($non_grouped)) { |
872
|
|
|
$sql = 'SELECT b.* FROM ' . $db->prefix('newblocks') . ' b, ' . $db->prefix('block_module_link') . ' m WHERE m.block_id=b.bid'; |
873
|
|
|
$sql .= ' AND b.isactive=' . (int)$isactive; |
874
|
|
|
if (isset($visible)) { |
875
|
|
|
$sql .= ' AND b.visible=' . (int)$visible; |
876
|
|
|
} |
877
|
|
|
if (!isset($module_id)) { |
878
|
|
|
} elseif (!empty($module_id)) { |
879
|
|
|
$sql .= ' AND m.module_id IN (0,' . (int)$module_id; |
880
|
|
|
if ($toponlyblock) { |
881
|
|
|
$sql .= ',-1'; |
882
|
|
|
} |
883
|
|
|
$sql .= ')'; |
884
|
|
|
} else { |
885
|
|
|
if ($toponlyblock) { |
886
|
|
|
$sql .= ' AND m.module_id IN (0,-1)'; |
887
|
|
|
} else { |
888
|
|
|
$sql .= ' AND m.module_id=0'; |
889
|
|
|
} |
890
|
|
|
} |
891
|
|
|
$sql .= ' AND b.bid IN (' . implode(',', $non_grouped) . ')'; |
892
|
|
|
$sql .= ' ORDER BY ' . $orderby; |
893
|
|
|
$result = $db->query($sql); |
894
|
|
|
if (!$db->isResultSet($result)) { |
895
|
|
|
throw new \RuntimeException( |
896
|
|
|
\sprintf(_DB_QUERY_ERROR, $sql) . $db->error(), E_USER_ERROR |
897
|
|
|
); |
898
|
|
|
} |
899
|
|
|
while (false !== ($myrow = $db->fetchArray($result))) { |
900
|
|
|
$block = new XoopsBlock($myrow); |
901
|
|
|
$ret[$myrow['bid']] =& $block; |
902
|
|
|
unset($block); |
903
|
|
|
} |
904
|
|
|
} |
905
|
|
|
|
906
|
|
|
return $ret; |
907
|
|
|
} |
908
|
|
|
|
909
|
|
|
/** |
910
|
|
|
* XoopsBlock::countSimilarBlocks() |
911
|
|
|
* |
912
|
|
|
* @param mixed $moduleId |
913
|
|
|
* @param mixed $funcNum |
914
|
|
|
* @param mixed $showFunc |
915
|
|
|
* @return int |
916
|
|
|
* |
917
|
|
|
* @deprecated |
918
|
|
|
*/ |
919
|
|
|
public function countSimilarBlocks($moduleId, $funcNum, $showFunc = null) |
920
|
|
|
{ |
921
|
|
|
$funcNum = (int)$funcNum; |
922
|
|
|
$moduleId = (int)$moduleId; |
923
|
|
|
if ($funcNum < 1 || $moduleId < 1) { |
924
|
|
|
// invalid query |
925
|
|
|
return 0; |
926
|
|
|
} |
927
|
|
|
$db = XoopsDatabaseFactory::getDatabaseConnection(); |
928
|
|
|
if (isset($showFunc)) { |
929
|
|
|
// showFunc is set for more strict comparison |
930
|
|
|
$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))); |
|
|
|
|
931
|
|
|
} else { |
932
|
|
|
$sql = sprintf('SELECT COUNT(*) FROM %s WHERE mid = %d AND func_num = %d', $db->prefix('newblocks'), $moduleId, $funcNum); |
933
|
|
|
} |
934
|
|
|
$result = $db->query($sql); |
935
|
|
|
if (!$db->isResultSet($result)) { |
936
|
|
|
return 0; |
937
|
|
|
} |
938
|
|
|
list($count) = $db->fetchRow($result); |
|
|
|
|
939
|
|
|
|
940
|
|
|
return (int)$count; |
941
|
|
|
} |
942
|
|
|
} |
943
|
|
|
|
944
|
|
|
/** |
945
|
|
|
* XOOPS block handler class. (Singelton) |
946
|
|
|
* |
947
|
|
|
* This class is responsible for providing data access mechanisms to the data source |
948
|
|
|
* of XOOPS block class objects. |
949
|
|
|
* |
950
|
|
|
* @author Kazumi Ono <[email protected]> |
951
|
|
|
* @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
952
|
|
|
* @package kernel |
953
|
|
|
* @subpackage block |
954
|
|
|
* |
955
|
|
|
* @todo Why is this not a XoopsPersistableObjectHandler? |
956
|
|
|
*/ |
957
|
|
|
class XoopsBlockHandler extends XoopsObjectHandler |
958
|
|
|
{ |
959
|
|
|
/** |
960
|
|
|
* create a new block |
961
|
|
|
* |
962
|
|
|
* @see XoopsBlock |
963
|
|
|
* @param bool $isNew is the new block new?? |
964
|
|
|
* @return XoopsBlock XoopsBlock reference to the new block |
965
|
|
|
**/ |
966
|
|
|
public function create($isNew = true) |
967
|
|
|
{ |
968
|
|
|
$block = new XoopsBlock(); |
969
|
|
|
if ($isNew) { |
970
|
|
|
$block->setNew(); |
971
|
|
|
} |
972
|
|
|
|
973
|
|
|
return $block; |
974
|
|
|
} |
975
|
|
|
|
976
|
|
|
/** |
977
|
|
|
* retrieve a specific {@link XoopsBlock} |
978
|
|
|
* |
979
|
|
|
* @see XoopsBlock |
980
|
|
|
* @param int $id bid of the block to retrieve |
981
|
|
|
* @return XoopsBlock reference to the block |
982
|
|
|
**/ |
983
|
|
|
public function get($id) |
984
|
|
|
{ |
985
|
|
|
$block = false; |
986
|
|
|
$id = (int)$id; |
987
|
|
|
if ($id > 0) { |
988
|
|
|
$sql = 'SELECT * FROM ' . $this->db->prefix('newblocks') . ' WHERE bid=' . $id; |
989
|
|
|
$result = $this->db->query($sql); |
990
|
|
|
if ($this->db->isResultSet($result)) { |
991
|
|
|
$numrows = $this->db->getRowsNum($result); |
|
|
|
|
992
|
|
|
if ($numrows == 1) { |
993
|
|
|
$block = new XoopsBlock(); |
994
|
|
|
$block->assignVars($this->db->fetchArray($result)); |
995
|
|
|
} |
996
|
|
|
} |
997
|
|
|
} |
998
|
|
|
|
999
|
|
|
return $block; |
|
|
|
|
1000
|
|
|
} |
1001
|
|
|
|
1002
|
|
|
/** |
1003
|
|
|
* write a new block into the database |
1004
|
|
|
* |
1005
|
|
|
* @param XoopsObject|XoopsBlock $block a XoopsBlock object |
1006
|
|
|
* |
1007
|
|
|
* @return bool true on success, otherwise false |
1008
|
|
|
*/ |
1009
|
|
|
public function insert(XoopsObject $block) |
1010
|
|
|
{ |
1011
|
|
|
$className = 'XoopsBlock'; |
1012
|
|
|
if (!($block instanceof $className)) { |
1013
|
|
|
return false; |
1014
|
|
|
} |
1015
|
|
|
if (!$block->isDirty()) { |
1016
|
|
|
return true; |
1017
|
|
|
} |
1018
|
|
|
if (!$block->cleanVars()) { |
1019
|
|
|
return false; |
1020
|
|
|
} |
1021
|
|
|
|
1022
|
|
|
$bid = $block->getVar('bid', 'n'); |
1023
|
|
|
$mid = $block->getVar('mid', 'n'); |
1024
|
|
|
$func_num = $block->getVar('func_num', 'n'); |
1025
|
|
|
$options = $block->getVar('options', 'n'); |
1026
|
|
|
$name = $block->getVar('name', 'n'); |
1027
|
|
|
$title = $block->getVar('title', 'n'); |
1028
|
|
|
$content = $block->getVar('content', 'n'); |
1029
|
|
|
$side = $block->getVar('side', 'n'); |
1030
|
|
|
$weight = $block->getVar('weight', 'n'); |
1031
|
|
|
$visible = $block->getVar('visible', 'n'); |
1032
|
|
|
$c_type = $block->getVar('c_type', 'n'); |
1033
|
|
|
$isactive = $block->getVar('isactive', 'n'); |
1034
|
|
|
$func_file = $block->getVar('func_file', 'n'); |
1035
|
|
|
$show_func = $block->getVar('show_func', 'n'); |
1036
|
|
|
$edit_func = $block->getVar('edit_func', 'n'); |
1037
|
|
|
$template = $block->getVar('template', 'n'); |
1038
|
|
|
$bcachetime = $block->getVar('bcachetime', 'n'); |
1039
|
|
|
$block_type = $block->getVar('block_type', 'n'); |
1040
|
|
|
$dirname = $block->getVar('dirname', 'n'); |
1041
|
|
|
|
1042
|
|
|
if ($block->isNew()) { |
1043
|
|
|
$bid = $this->db->genId('newblocks_bid_seq'); |
|
|
|
|
1044
|
|
|
$sql = sprintf( |
1045
|
|
|
'INSERT INTO %s (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type,' |
1046
|
|
|
. ' c_type, isactive, dirname, func_file, show_func, edit_func, template, bcachetime, last_modified)' |
1047
|
|
|
. " VALUES (%u, %u, %u, '%s', '%s', '%s', '%s', %u, %u, %u, '%s', '%s', %u, '%s', '%s', '%s', '%s'," |
1048
|
|
|
. " '%s', %u, %u)", |
1049
|
|
|
$this->db->prefix('newblocks'), |
1050
|
|
|
$bid, |
1051
|
|
|
$mid, |
|
|
|
|
1052
|
|
|
$func_num, |
1053
|
|
|
$options, |
1054
|
|
|
$name, |
1055
|
|
|
$title, |
1056
|
|
|
$content, |
1057
|
|
|
$side, |
1058
|
|
|
$weight, |
1059
|
|
|
$visible, |
1060
|
|
|
$block_type, |
1061
|
|
|
$c_type, |
1062
|
|
|
1, |
1063
|
|
|
$dirname, |
1064
|
|
|
$func_file, |
1065
|
|
|
$show_func, |
1066
|
|
|
$edit_func, |
1067
|
|
|
$template, |
1068
|
|
|
$bcachetime, |
1069
|
|
|
time() |
1070
|
|
|
); |
1071
|
|
|
} else { |
1072
|
|
|
$sql = sprintf( |
1073
|
|
|
"UPDATE %s SET func_num = %u, options = '%s', name = '%s', title = '%s', content = '%s', side = %u," |
1074
|
|
|
. " weight = %u, visible = %u, c_type = '%s', isactive = %u, func_file = '%s', show_func = '%s'," |
1075
|
|
|
. " edit_func = '%s', template = '%s', bcachetime = %u, last_modified = %u WHERE bid = %u", |
1076
|
|
|
$this->db->prefix('newblocks'), |
1077
|
|
|
$func_num, |
1078
|
|
|
$options, |
1079
|
|
|
$name, |
1080
|
|
|
$title, |
1081
|
|
|
$content, |
1082
|
|
|
$side, |
1083
|
|
|
$weight, |
1084
|
|
|
$visible, |
1085
|
|
|
$c_type, |
1086
|
|
|
$isactive, |
1087
|
|
|
$func_file, |
1088
|
|
|
$show_func, |
1089
|
|
|
$edit_func, |
1090
|
|
|
$template, |
1091
|
|
|
$bcachetime, |
1092
|
|
|
time(), |
1093
|
|
|
$bid |
1094
|
|
|
); |
1095
|
|
|
} |
1096
|
|
|
if (!$result = $this->db->query($sql)) { |
|
|
|
|
1097
|
|
|
return false; |
1098
|
|
|
} |
1099
|
|
|
if (empty($bid)) { |
1100
|
|
|
$bid = $this->db->getInsertId(); |
|
|
|
|
1101
|
|
|
} |
1102
|
|
|
$block->assignVar('bid', $bid); |
1103
|
|
|
|
1104
|
|
|
return true; |
1105
|
|
|
} |
1106
|
|
|
|
1107
|
|
|
/** |
1108
|
|
|
* delete a block from the database |
1109
|
|
|
* |
1110
|
|
|
* @param XoopsObject|XoopsBlock $block a XoopsBlock object |
1111
|
|
|
* |
1112
|
|
|
* @return bool true on success, otherwise false |
1113
|
|
|
*/ |
1114
|
|
|
public function delete(XoopsObject $block) |
1115
|
|
|
{ |
1116
|
|
|
$className = 'XoopsBlock'; |
1117
|
|
|
if (!($block instanceof $className)) { |
1118
|
|
|
return false; |
1119
|
|
|
} |
1120
|
|
|
$id = $block->getVar('bid'); |
1121
|
|
|
$sql = sprintf('DELETE FROM %s WHERE bid = %u', $this->db->prefix('newblocks'), $id); |
|
|
|
|
1122
|
|
|
if (!$result = $this->db->query($sql)) { |
|
|
|
|
1123
|
|
|
return false; |
1124
|
|
|
} |
1125
|
|
|
$sql = sprintf('DELETE FROM %s WHERE block_id = %u', $this->db->prefix('block_module_link'), $id); |
1126
|
|
|
$this->db->query($sql); |
1127
|
|
|
|
1128
|
|
|
return true; |
1129
|
|
|
} |
1130
|
|
|
|
1131
|
|
|
/** |
1132
|
|
|
* retrieve array of {@link XoopsBlock}s meeting certain conditions |
1133
|
|
|
* @param CriteriaElement|CriteriaCompo $criteria {@link CriteriaElement} with conditions for the blocks |
1134
|
|
|
* @param bool $id_as_key should the blocks' bid be the key for the returned array? |
1135
|
|
|
* @return array {@link XoopsBlock}s matching the conditions |
1136
|
|
|
**/ |
1137
|
|
|
public function getObjects(CriteriaElement $criteria = null, $id_as_key = false) |
1138
|
|
|
{ |
1139
|
|
|
$ret = array(); |
1140
|
|
|
$limit = $start = 0; |
1141
|
|
|
$sql = 'SELECT DISTINCT(b.bid), b.* FROM ' . $this->db->prefix('newblocks') . ' b LEFT JOIN ' |
1142
|
|
|
. $this->db->prefix('block_module_link') . ' l ON b.bid=l.block_id'; |
1143
|
|
|
if (isset($criteria) && \method_exists($criteria, 'renderWhere')) { |
1144
|
|
|
$sql .= ' ' . $criteria->renderWhere(); |
1145
|
|
|
$limit = $criteria->getLimit(); |
1146
|
|
|
$start = $criteria->getStart(); |
1147
|
|
|
} |
1148
|
|
|
$result = $this->db->query($sql, $limit, $start); |
1149
|
|
|
if (!$this->db->isResultSet($result)) { |
1150
|
|
|
return $ret; |
1151
|
|
|
} |
1152
|
|
|
/** @var array $myrow */ |
1153
|
|
|
while (false !== ($myrow = $this->db->fetchArray($result))) { |
1154
|
|
|
$block = new XoopsBlock(); |
1155
|
|
|
$block->assignVars($myrow); |
1156
|
|
|
if (!$id_as_key) { |
1157
|
|
|
$ret[] =& $block; |
1158
|
|
|
} else { |
1159
|
|
|
$ret[$myrow['bid']] = &$block; |
1160
|
|
|
} |
1161
|
|
|
unset($block); |
1162
|
|
|
} |
1163
|
|
|
|
1164
|
|
|
return $ret; |
1165
|
|
|
} |
1166
|
|
|
|
1167
|
|
|
/** |
1168
|
|
|
* get a list of blocks matchich certain conditions |
1169
|
|
|
* |
1170
|
|
|
* @param CriteriaElement $criteria conditions to match |
1171
|
|
|
* @return array array of blocks matching the conditions |
1172
|
|
|
**/ |
1173
|
|
|
public function getList(CriteriaElement $criteria = null) |
1174
|
|
|
{ |
1175
|
|
|
$blocks = $this->getObjects($criteria, true); |
1176
|
|
|
$ret = array(); |
1177
|
|
|
foreach (array_keys($blocks) as $i) { |
1178
|
|
|
$name = (!$blocks[$i]->isCustom()) ? $blocks[$i]->getVar('name') : $blocks[$i]->getVar('title'); |
1179
|
|
|
$ret[$i] = $name; |
1180
|
|
|
} |
1181
|
|
|
|
1182
|
|
|
return $ret; |
1183
|
|
|
} |
1184
|
|
|
|
1185
|
|
|
##################### Deprecated Methods ###################### |
1186
|
|
|
/* These are not deprecated, they are dead and should be removed */ |
1187
|
|
|
/** |
1188
|
|
|
* @deprecated |
1189
|
|
|
* @param $moduleid |
1190
|
|
|
* @param bool $asobject |
1191
|
|
|
* @param bool $id_as_key |
1192
|
|
|
* @return bool |
1193
|
|
|
*/ |
1194
|
|
|
public function getByModule($moduleid, $asobject = true, $id_as_key = false) |
|
|
|
|
1195
|
|
|
{ |
1196
|
|
|
$GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . ' is deprecated'); |
1197
|
|
|
|
1198
|
|
|
return false; |
1199
|
|
|
} |
1200
|
|
|
|
1201
|
|
|
/** |
1202
|
|
|
* @param $groupid |
1203
|
|
|
* @param int $module_id |
1204
|
|
|
* @param bool $toponlyblock |
1205
|
|
|
* @param null $visible |
|
|
|
|
1206
|
|
|
* @param string $orderby |
1207
|
|
|
* @param int $isactive |
1208
|
|
|
* |
1209
|
|
|
* @return bool |
1210
|
|
|
* @deprecated |
1211
|
|
|
*/ |
1212
|
|
|
public function getAllByGroupModule($groupid, $module_id = 0, $toponlyblock = false, $visible = null, $orderby = 'i.weight,i.instanceid', $isactive = 1) |
|
|
|
|
1213
|
|
|
{ |
1214
|
|
|
$GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . ' is deprecated'); |
1215
|
|
|
|
1216
|
|
|
return false; |
1217
|
|
|
} |
1218
|
|
|
|
1219
|
|
|
/** |
1220
|
|
|
* @param $groupid |
1221
|
|
|
* @param string $orderby |
1222
|
|
|
* |
1223
|
|
|
* @return bool |
1224
|
|
|
* @deprecated |
1225
|
|
|
*/ |
1226
|
|
|
public function getAdminBlocks($groupid, $orderby = 'i.weight,i.instanceid') |
|
|
|
|
1227
|
|
|
{ |
1228
|
|
|
$GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . ' is deprecated'); |
1229
|
|
|
|
1230
|
|
|
return false; |
1231
|
|
|
} |
1232
|
|
|
|
1233
|
|
|
/** |
1234
|
|
|
* @return bool |
1235
|
|
|
* @deprecated |
1236
|
|
|
*/ |
1237
|
|
|
public function assignBlocks() |
1238
|
|
|
{ |
1239
|
|
|
$GLOBALS['xoopsLogger']->addDeprecated(__METHOD__ . ' is deprecated'); |
1240
|
|
|
|
1241
|
|
|
return false; |
1242
|
|
|
} |
1243
|
|
|
} |
1244
|
|
|
|