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